The FPGA and Its Cores: How a Blank Chip Becomes a Next
Switch a Spectrum on, and its ULA is a ULA from the first microsecond: the chip was made that way at the factory and will never be anything else. Switch a Next on, and for a short moment there is no ULA, no Z80N, no Copper and no sprites. There is a large blank chip, waiting to be told what to be. A fraction of a second later it is a ZX Spectrum Next, and it can be told to become a different machine, or a newer version of itself, from a file on the SD card. So where does the machine come from at every power-on, who decides which machine it becomes, and how can you replace it without turning your Next into a doorstop?
I think this is the part of the Next that most owners use without ever looking at it, and the part that scares them most when they must. Every core update, every “please update your core” message, every extra core for another computer goes through the mechanisms in this chapter. Know them, and an update stops being a ritual of held keys and crossed fingers: you will know what each step does, which steps can go wrong, and why the machine can almost always be rescued when one does.
You should know two chapters first. The ZX Spectrum Next Core and the FPGA explains that the Next’s hardware is a design for an FPGA, and Memory, Ports and NextRegs: How the Z80N Reaches the Machine explains the boot ROM, the config bank and the SRAM map, which come back here as the start-up’s working tools.
The road ahead
We start with the FPGA itself, what a core is and what the chip is made of, then the flash chip that keeps the cores, slot by slot, on the
two generations of boards. Then we follow a power-on from the first instant: the anti-brick core that always
comes first, the jump to the Next core, the boot ROM that reads the firmware from the SD card, and the
firmware that builds the machine you chose and steps aside. The heart of the chapter is the mechanism behind
all of it, a NextReg write that makes the FPGA forget what it is and load another core; if you read only one
section, make it “Changing its mind”. After that come the updates: the TBBLUE.TBU file, what the updater
checks and writes, and how the anti-brick core gets you out of trouble. Last come the extra cores that turn
the Next into other machines.
The facts are for core 3.02.01 and the system distribution’s firmware 1.44, which shipped together. Board facts are for the Issue 2 board (the first Kickstarter’s, often called KS1), the Issue 4 board (the second Kickstarter’s, KS2) and the Issue 5 board (the third Kickstarter’s, KS3), which needs core 3.02.03 or later and comes with firmware 1.45. Every fact was checked against the Next’s hardware design and the firmware’s own code.
Two numberings meet here. The machines are sold as the ZX Spectrum Next Issue 1, 2 and 3, one per
Kickstarter; the boards inside are numbered by the board itself, and NextReg $0F reports those: Issue 2
(or 3) for the first machine, Issue 4 for the second and Issue 5 for the third. This chapter always
means the board.
A chip that forgets
An FPGA, a field-programmable gate array, is a chip full of small logic blocks, memories and wires whose connections are not fixed. A long string of bits, the bitstream, says how to connect them: which block computes what, which wire goes where. Load one bitstream and the chip is a Spectrum Next; load another and the same chip is an Amiga, or a test pattern generator. Nobody writes a bitstream by hand: the vendor’s tools make it from a design written in a hardware description language, as the next section explains.
The bitstream lives in the FPGA’s configuration memory, and that memory is volatile: when the power goes, the chip forgets everything and is blank again. So every power-on starts with the FPGA reading a bitstream from somewhere and configuring itself from it. In the Next’s world a bitstream that makes a whole machine is a core, and “the Next core” is the bitstream of the ZX Spectrum Next.
The two board generations use two FPGA families:
- Issue 2 and Issue 3: a Xilinx Spartan-6 (XC6SLX16) with a 16 MB flash chip.
- Issue 4: a Xilinx Artix-7 (XC7A15T) with a 32 MB flash chip.
- Issue 5: a larger Artix-7 (XC7A35T) with the same 32 MB flash chip, and 4 MB of SRAM instead of 2 MB.
The Board ID register, NextReg $0F, tells a program which board it runs on: 0 for Issue 2, 1 for Issue 3,
2 for Issue 4, 3 for Issue 5. The same design is built for each board separately, because a bitstream fits only the chip it
was made for. That is the first rule of updates, and we will see the updater enforce it.
What the blank chip is made of
Most of an FPGA is a sea of small, identical cells, each far too simple to be interesting on its own. The trick is that there are thousands of them, and that the wires between them can be joined almost any way. Here is the cast, from the smallest part up:
- The look-up table, LUT for short, is the cell that computes. In all of the Next’s FPGAs it has six inputs and one output, and it holds 64 bits: one answer for each of the 64 combinations of its inputs. It does not know what function it computes; it only looks the answer up. Load the right 64 bits, and the same LUT is an AND gate, a check that six address lines match a port, the parity of six bits, or a 4-to-1 multiplexer, whose four data inputs and two select inputs are exactly six. A function of more inputs takes several LUTs, one feeding the next.
- The flip-flop is the cell that remembers: one bit, taken on a clock edge and held until the next. LUTs compute, flip-flops remember, and every register, counter and state machine is LUTs feeding flip-flops feeding LUTs again. Every value the Next keeps from one tick of its clock to the next, the CPU’s registers, the NextRegs, the beam’s counters, sits in flip-flops.
- The slice groups four LUTs and eight flip-flops, with a carry chain: a fast, fixed wire from one slice to the next that makes adders and counters quick, because a carry does not have to wander through the general wiring. Some slices can also use their LUTs as small memories or shift registers, called distributed RAM.
- Block RAM is memory built into the chip as memory: blocks of 18 kilobits on the Spartan-6 (each usable as two of 9) and 36 kilobits on the Artix-7 (each usable as two of 18). A block has two ports, so two parts of a design can read and write it at the same time. The Next keeps the ULA’s banks 5 and 7, the sprites’ patterns, the palettes and the Copper’s list in memories inside the FPGA, and the two ports are why the CPU and the ULA can share bank 5 without taking turns.
- DSP slices, named after digital signal processing, the multiply-and-add work of filters, audio and video they were made for, are hard-wired multipliers with an adder and an accumulator: 18 × 18 bits on the Spartan-6, 25 × 18 with a pre-adder on the Artix-7. A multiplier made of LUTs would be many times larger and slower.
- Clock managers multiply and divide a clock. All the boards give the FPGA a 50 MHz clock, and a clock
manager makes the 28 MHz master clock and its relatives from it; the VGA settings of the Video Timing
register, NextReg
$11, retune it to between 28 and 33 MHz. - I/O blocks around the edge connect the logic to the chip’s pins: the SRAM, the flash, the SD card, the keyboard, the video outputs and the expansion bus.
- The routing, a mesh of wires and programmable switches, joins all of these. Most of the bitstream sets those switches. If you ask me, the routing is the real FPGA; the cells are only what it connects.
The three chips have these resources:
| Resource | Spartan-6 XC6SLX16 (Issue 2 and 3) | Artix-7 XC7A15T (Issue 4) | Artix-7 XC7A35T (Issue 5) |
|---|---|---|---|
| Slices | 2,278 | 2,600 | 5,200 |
| 6-input LUTs | 9,112 | 10,400 | 20,800 |
| Flip-flops | 18,224 | 20,800 | 41,600 |
| Block RAM | 576 Kb (32 blocks of 18 Kb) | 900 Kb (25 blocks of 36 Kb) | 1,800 Kb (50 blocks of 36 Kb) |
| Distributed RAM, at most | 136 Kb | 200 Kb | 400 Kb |
| DSP slices | 32 | 45 | 90 |
| Clock management tiles | 2 | 5 | 5 |
About ten thousand look-up tables on the first two boards: that is what a Z80N, a ULA, Layer 2, a tilemap, 128 sprites, a Copper, a DMA, three AY chips and all the rest have to fit in. The Issue 5 board’s chip has twice as much of nearly everything, while the Next core is the same design on all of them; I read that as room to grow, for the Next and for the other machines its slots can hold.
Nobody draws those connections by hand. A design is written in a hardware description language, HDL for
short: text that looks like a program but describes a circuit. VHDL and Verilog are the two most widely
used (SystemVerilog extends Verilog). A line such as q <= a and b; does not run once, one step after the
other, as a statement in a program would; it says that the wire q is always the AND of a and b, and a
block clocked by the 28 MHz clock says what a register takes at every clock edge. The Next is written almost
entirely in VHDL, with a few parts in Verilog: the set-up of the clock managers, the PS/2 mouse and the HDMI
encoder. The vendor’s tools turn that text into a bitstream in two steps. Synthesis turns it into LUTs, flip-flops and memories, and place and route
decides which cell does which job and which wires join them, until every signal arrives within one tick of its
clock. The second step is the slow one, and it is why a core build takes the vendor’s tools a long while and
why the result fits only the chip it was placed on. Even the boot ROM’s 8K is part of the bitstream: the
starting contents of a memory inside the chip.
Here is the idea I find most important. In a computer built from chips, a Spectrum say, the ULA and the CPU are separate parts that happen to share a clock. In an FPGA, every cell works at every clock edge, all at once: the CPU’s logic, the ULA’s counters, the sprite engine and the sound chips do not take turns, they are all wired up and running. That is why a machine rebuilt in an FPGA can keep the original’s timing to the cycle, and why the Next can add so much without slowing anything else down.
The flash and its slots
The bitstreams are kept in a flash chip beside the FPGA, a memory that keeps its contents without power, talked to over SPI. The flash is divided into equal slots, one core each, and the slot size depends on the board:
- Issue 2 and Issue 3: 32 slots of 512K each, 16 MB in all.
- Issue 4 and Issue 5: 15 slots of 2,176K each, almost all of the 32 MB. The Artix-7’s bitstream is bigger.
- Slot 0 holds the anti-brick core, slot 1 the Next core, on every board.
- Slots 2 to 7 are reserved, and on the Issue 2 board slots 8 to 31 hold extra cores.
Slot 0 is the one the FPGA reads by itself at power-on: it is the start of the flash, where the chip looks for a bitstream when it wakes up. Every other slot is reached only when a running core asks for it, and that is the mechanism of this chapter.
I like this layout because it keeps the dangerous part small. Updating the Next core rewrites slot 1 and nothing else. If that goes wrong, slot 0 is still intact, and slot 0 is what the chip loads first.
The doorman: the anti-brick core
The anti-brick core is a Next core of its own, built with a few differences: the Machine ID register,
NextReg $00, reads $FA instead of the Next’s $0A; it has its own boot ROM; and its function keys are
almost all off, so F1 (hard reset), F4 (soft reset), the CPU speed key and the NMI buttons’ keys do nothing.
Only F2 and F3, the scan doubler and the 50/60 Hz switch, still work, so you can get a picture out of it.
I call it the doorman. It greets every power-on, and almost always it only waves you through: its boot ROM looks at the two buttons on the side of the machine, DRIVE and M1, and when they are not both held, it starts slot 1. You never see it. When you power on with DRIVE and M1 held, the doorman takes you to the repair room instead: it loads the updater from the SD card, as we will see in “Repairing a broken slot 1”.
Its job explains why it is meant never to change. A Next with a broken slot 1 can be repaired as long as slot 0 works; a Next with a broken slot 0 cannot start at all without a programmer cable on its JTAG port.
Changing its mind
Here is the mechanism behind everything else: a running core can make the FPGA reconfigure itself from any slot of the flash. The FPGA has an internal configuration port through which logic inside the chip can give it commands. The Next’s design keeps a short command list for it: synchronise, set the start address in the flash, and reboot from there. When the list runs, the FPGA throws its whole design away, the CPU, the video, every register, and loads the bitstream at that address, exactly as it does at power-on but from a different place.
Two things start that list:
- The Core Boot register, NextReg
$10: bits 4 to 0 choose a slot, and writing bit 7 starts it. The slot number can be changed only in config mode (more about that below); outside it, a write of bit 7 restarts the slot that is already selected. A write of a slot number that does not exist is ignored, which is the recommended way to find the largest one; the Issue 4 and Issue 5 boards accept 0 to 14. - A hard reset: F1, or bit 1 of the Reset register, NextReg
$02. On the Next core this reloads slot 1, the Next core, from the flash. That is why the memory chapter could say that a hard reset is like switching off and on: in the FPGA’s eyes it is a fresh start from the flash, only without the doorman.
When the anti-brick core waves you through, it does nothing more than write $80 to NextReg $10: start the
selected slot, which after a power-on is slot 1.
What survives a reconfiguration? Not the FPGA’s contents: those are replaced. But the SRAM, the 2 MB (4 MB on Issue 5) of memory chips beside the FPGA, keeps its power and its contents. That is how one core leaves a message for the next: it writes it into the SRAM and starts the other slot. The firmware uses that channel to pass settings to extra cores, and to ask itself to boot one. One caveat from the hardware’s own notes: on the Issue 2 board, data at an even multiple of 256K in the SRAM is not reliable across the change.
I find this the most elegant idea on the board. A machine that can rebuild itself from a NextReg write needs no separate boot loader chip, no switch, no jumper. It boots into a small, safe core, and the small core decides what the real machine is.
From power-on to the prompt
Now let’s follow a normal start, from the power switch to NextZXOS’s menu:
- The FPGA loads slot 0, the anti-brick core, by itself.
- The doorman checks the buttons and, normally, writes NextReg
$10: the FPGA loads slot 1. - The Next core starts in config mode with its boot ROM in the bottom 16K. The CPU runs the boot ROM,
which initialises the SD card, finds a FAT16 or FAT32 file system, and reads
TBBLUE.FWfrom the root folder. - The boot ROM loads one module of the firmware into RAM at
$6000and jumps to it. Which module depends on the keys held at that moment, as the next section shows; normally it is the boot module. - The firmware takes over. It switches to 28 MHz, switches the boot ROM off, reads
/machines/next/config.ini(your settings) and the menu of machines, and shows the start-up screen with its prompts for a while. - It builds the machine. It loads the keyboard map, the DivMMC’s ROM, the Multiface’s ROM and the Spectrum
ROMs of the chosen machine from
/machines/next/into the SRAM, and writes your settings into the peripheral NextRegs. - It leaves config mode by writing the machine type and the display timing to NextReg
$03. - It soft-resets with NextReg
$02, and the CPU starts at$0000in the ROM it has just loaded. For the standard menu entry that is NextZXOS.
Who runs all this code? Not a second processor: the board has no microcontroller that starts the machine,
and the only step no program takes is the first one, the FPGA loading slot 0 by itself. From then on every
step is Z80 code, run by the Z80N inside the core that has just been loaded. The boot ROM is part of the
bitstream, so when the FPGA has configured itself and the reset ends, the CPU does what every Z80 does after a
reset: it starts fetching at $0000, where the boot ROM answers. The anti-brick core’s own Z80N runs the
doorman’s boot ROM; after the change to slot 1, the Next core’s Z80N, the same CPU that will later run
NextZXOS, runs the Next core’s boot ROM and then the firmware. Both boot ROMs open with DI, IM 1 and a
jump, as plain Z80 programs do. They run at 3.5 MHz, the speed every reset sets, and the firmware’s boot
module switches to 28 MHz as its first act. The boot ROMs and the firmware are written in C and compiled for
the Z80; the firmware’s modules run from RAM at $6000.
I like how little this needs. The machine that boots the Next is the Next: one CPU, which first plays stagehand, then firmware, then the computer you asked for.
Notice who does what. The FPGA design knows nothing about files, menus or config.ini; it provides only a boot
ROM of 8K and the switches of config mode. Everything with a user interface is Z80 code on the SD card. That
is why the firmware can be updated by copying a file, without touching the flash at all.
The firmware file
TBBLUE.FW is not one program but a small library of them. Its first 512-byte block is a map: for each
module, the block it starts at and how many blocks it is long. The boot ROM reads the map and loads only the
module it needs. The modules are the boot module, the updater, the settings editor, the extra
cores module, a video test card, and a module that resets config.ini to its defaults; one more
entry is not a program but a block of data, the screens, with the test card’s picture and the start-up
screen’s text. A module that needs another one loads it the same way and jumps to it. Every module is loaded
at $6000 and runs from there.
The map has two curious entries, the second and the fourth, which point at the boot module again. That is
on purpose: they are where the editor and the extra cores module used to be, and an old loader that still
starts them gets the boot module instead of something unexpected. And the map keeps growing: firmware 1.46,
in System/Next 26.11a, has seventeen entries, eight of which no published source names yet. You can look at
all of them yourself: open TBBLUE.FW in Klive, or choose Machine › SD Card › Show TBBLUE.FW, and the
firmware viewer lists the modules, the keys that start them and each one’s code.
The keys you hold decide the module, and when you hold them matters. Keys are read at two moments:
- As the machine starts: hold the key before you switch on, or before you press F1 for a hard reset, and keep holding it until the screen changes. The boot ROM looks at the keyboard as soon as it begins, before the start-up screen appears, so a key pressed a moment later is too late for this chance.
- While the start-up screen is showing, with its flashing “Press SPACEBAR for menu” and “Press C for extra cores” prompts: the boot module keeps checking the keys until it starts the machine, so you can also press them then.
A soft reset (F4, or the reset button) gives you neither chance: it restarts the chosen ROM without running the boot ROM or the firmware at all. And the doorman’s buttons, DRIVE and M1, count only when held from power-on, because a hard reset starts from slot 1 and never meets the anti-brick core.
Here is what each key does:
- Nothing: the boot module, and the machine starts after the start-up screen.
- Space (at either moment): the settings editor, where you choose the machine from the menu and change
config.ini. - U (at either moment): the updater, if a
TBBLUE.TBUis on the card. Let go of U when the updater’s screen appears. - C (at either moment): the extra cores module.
- A, D, V or R on the start-up screen: the video test card for all modes, digital (HDMI), VGA or RGB, which lets you choose a video mode your monitor can show.
- N and X together on the start-up screen:
config.iniback to its defaults.
The firmware also checks the core it runs on. If the Next core is older than the oldest one it supports (3.01.10 for firmware 1.44), it refuses to start the machine and tells you to update the core, with U to enter the updater.
Config mode
Config mode is the state the Next core starts in, and it is what makes the firmware’s job possible. The
Machine Type register, NextReg $03, says it: machine type 0 is config mode. While it lasts:
- The boot ROM answers reads of
$0000–$3FFF, until the first write to NextReg$03switches it off. - The Config Mapping register, NextReg
$04, maps any 16K bank of the SRAM to$0000–$3FFF. The firmware uses it to write the ROM images into the banks where the machine will look for them: the Spectrum ROMs in the first 64K, then the DivMMC’s ROM, the Multiface’s ROM and RAM, and the alternate ROMs, 128K in all. On the Issue 5 board it keeps all 8 bits, so it reaches the whole 4 MB; on the other boards bit 7 is ignored. - The flash can be selected on the SPI bus (
$7Fon port$E7), which the storage chapter’s The flash and the Pi describes. The firmware reads a core’s header and writes a core this way. - The slot number of NextReg
$10and the video timing of NextReg$11can be changed. - The soft reset key F4 does nothing.
The firmware leaves config mode with one write to NextReg $03: the machine type (48K, 128K, +3 or
Pentagon), the display timing, and bit 7 to allow the timing to change. From that moment the machine type is
fixed, the boot ROM is gone, and the flash and the slot number are locked away.
There is one way back, and the register list does not mention it: writing 7 (111) to bits 2 to 0 of
NextReg $03 puts the machine back into config mode, from any program. The boot ROM does not return at once,
but a soft reset in config mode switches it back on, and the CPU starts the boot ROM again. So the lock is
not a wall; it is a door that opens only to a program that knows the exact knock. I find that a fair
compromise: no stray write can do it, and a system program that must reach the flash or another slot still
can. A hard reset, of course, always starts the whole chain over.
Updating the core
A core update replaces the bitstream in slot 1. It arrives as TBBLUE.TBU, a file you copy to the root
of the SD card, and it is written by the firmware’s updater. You start it by holding U from before you
switch on or press F1 until its screen appears, or by pressing U on the start-up screen; then answer Y
(or press DRIVE) to go ahead. Here is what the updater does:
- It reads the file’s header, the first 512 bytes, and checks its magic word.
- It picks the core for your board. The current files carry several cores, one per board, each with its
own record; the updater takes the records whose board ID matches NextReg
$0Fand ignores the rest. A file with no core for your board updates nothing. - It shows the board, the slot and the version it is about to write, and asks.
- It checks the image’s checksum by reading the whole image from the card, before it touches the flash. A damaged file stops here, and slot 1 is still the old core.
- It erases the slot in blocks of 32K, then writes the image, 256 bytes at a time.
- It asks you to switch off and on. On the Issue 2 board it also asks you to unplug the HDMI cable while the power is off.
The header has a fixed layout:
Older files start with the same magic word, TBUFILE, but have no ZX SPECTRUM NEXT after it: they
carry one core with a simpler checksum, and the updater checks their machine ID and their exact size
instead. Both kinds end the same way: in slot 1.
You can see all of this for yourself. Open a TBBLUE.TBU in Klive and the
TBU viewer lists its records, checks every image’s checksum the way the
updater does, and lists the configuration packets of each core’s bitstream.
Let me warn you about the one moment that matters. Between the erase and the end of the writing, slot 1 holds half a core. Switch off then, and the Next core is gone. That is not the end of the machine, because of the doorman, but it is the end of an ordinary start-up until you repair it, as “Repairing a broken slot 1” below shows. So my advice is the boring one: a good power supply, no cats near the cable, and no hurry.
Why switch off after the update, and not only press F1? The updater does not say. My guess is the plain one: a hard reset would load the new slot 1 but skip the doorman, while a real power-on runs the whole chain from slot 0, exactly as it will every day from now on. If you ask me, that is the honest test of an update.
A record can also name slot 0, to update the anti-brick core itself. The updater then shows a red warning that this can brick the machine, and goes ahead only if you hold A and B together. I have never needed it, and I hope you never do.
The current system release, 26.11a, puts core 3.03.03 into slot 1 on all three boards and comes with firmware 1.46. One change matters for the update itself: from core 3.03.00 on, the Issue 2 board’s core is split in two, one for HDMI and one for VGA. An Issue 2 machine must therefore update its core first and the rest of the system after it; done the other way round, the new firmware looks for a test card core that is not there yet, and the machine looks bricked although it is not. The Issue 5 board, which has two SD card readers, an internal one and an external one, updates both cards through a new updater program that the release installs first. My advice for any board: read the release’s notes for your board before you press U.
Repairing a broken slot 1
If slot 1 does not start, because an update was interrupted or a core is faulty, the doorman is still there.
Power on with DRIVE and M1 held, and the anti-brick core does not start slot 1: its own boot ROM loads the
updater module from TBBLUE.FW, and the updater runs on the anti-brick core, at 3.5 MHz and with default
settings. It reads TBBLUE.TBU and writes slot 1 exactly as an ordinary update does. Nothing of the broken
core is used, which is the whole point.
You will know you need this when the Next’s start-up screen no longer appears after a power-on, usually after an update that was cut short. Here is the repair, step by step:
- Prepare the SD card on another computer. It must have a FAT16 or FAT32 file system, and its root folder
must hold
TBBLUE.FWand aTBBLUE.TBUwith a core for your board. Take both from the same release of the Next’s system distribution, so that the firmware and the core belong together. The anti-brick core’s boot ROM needs nothing else from the card. - Find a picture. On the anti-brick core the machine may show a picture on VGA only, so connect a VGA monitor if you have one. F2 (the scan doubler) and F3 (50/60 Hz) still work on the anti-brick core, and they are worth a press if the screen stays dark.
- Switch off completely: unplug the power, and on the Issue 2 board the HDMI cable too.
- Hold DRIVE and M1, and switch on. Keep both held until the updater’s screen appears, titled Anti-Brick in red, then let go: the updater waits until both buttons are released before it goes on.
- Check what it shows: the board, the slot (01, the Next core) and the version it is about to write. Then answer Y, or press DRIVE, to go ahead; N or M1 cancels.
- Wait. The updater checks the image’s checksum, erases slot 1 and writes it, a little more slowly than usual at 3.5 MHz. Do not switch off while it works: this is the same window of risk as before.
- When it says “Updated!”, switch off, unplug the HDMI cable on the Issue 2 board, and switch on normally, with no buttons held. The doorman waves you on to the repaired slot 1.
The anti-brick core’s boot ROM and the updater stop with a message when something is wrong. These are the ones you may meet, and what to do about each:
- “Error Mounting SD Card”: the card cannot be read, or it has no FAT16 or FAT32 file system. Try another card, formatted on a computer.
- “TBBLUE.FW Not Found”, “TBBLUE.TBU Not Found”: a file is missing from the card’s root folder.
- “Error Reading TBBLUE.FW”, “Error Loading UPDATE Module”: the firmware file is damaged or does not belong to this release. Copy it again.
- “Wrong Magic!”, “Wrong image size”: the update file is not a
TBBLUE.TBU, or it is incomplete. - “Wrong board id”: the update file is for another board. An older file with one core inside is for the Issue 2 board only; an Issue 4 or Issue 5 board needs a file that has a record for it.
- “FAIL” followed by two numbers: the checksum does not match, so the file is damaged. Nothing has been erased yet, so copy the file again and repeat.
None of these messages has touched the flash: every check comes before the erase. The only way to make things worse is to cut the power during the writing, and even then you can start again from step 3.
When even the doorman cannot help. All of this needs a working slot 0. If slot 0 itself is damaged, for example because an update of the anti-brick core was interrupted, the FPGA has nothing to start from, and no key or button can help. The flash must then be written from outside, with a programmer cable on the board’s JTAG connector and a programming file that holds both the anti-brick core and the Next core. That does not need a working Next at all, but it does need the cable and the know-how, and I would leave it to someone who has done it before. Which is the best argument I know for never updating slot 0 without a very good reason.
This is why the updater module keeps its place in the firmware file, and why the anti-brick core keeps its own boot ROM: both are part of a rescue path that must work when everything else does not.
Extra cores
The flash has room for more than the Next. An extra core is a bitstream for another machine, built for
the Next’s board, kept in a folder of its own on the SD card: /machines/<name>/core.bit, often with a
core.cfg that lists the files the core wants. Press C at start-up, and the extra cores module lists the
slots and the folders:
- It recognises a slot’s core by reading the bitstream’s header from the flash, the design name, the date
and the time the core was built, and matching it with the
core.bitfiles on the card. - It writes a core into a slot you choose, from slot 8 up, with the same erase and write as the updater. Slots 0 to 7 are never offered.
- It starts a core by writing your basic settings (timing, scan doubler, 50/60 Hz, scanlines, and a few
more), the folder name and any files you chose into the SRAM, dropping to 3.5 MHz, and writing
$80plus the slot number to NextReg$10. The FPGA becomes the other machine, and the other machine finds its settings in the SRAM, which survived the change.
A core can also be started without the menu. At every start the boot module looks for a 128-byte core boot
request in the SRAM: the magic word COREBOOT, the core’s folder and a file name, protected by a checksum.
When it finds a valid one, it starts that core at once. Since the SRAM survives a hard reset, a program can
write the request and hard-reset, and the firmware does the rest.
Firmware 1.44’s extra cores module runs only on the Issue 2 board; on the other boards it stops with a message
saying so. The Issue 4 and Issue 5 boards have fewer, larger slots, and the hardware is ready for them:
NextReg $10 takes slots 0 to 14 there. Firmware 1.45, which comes with the Issue 5 board, knows that board
by name, and the message that kept extra cores to the Issue 2 board is gone from it.
The Next core is not tied to the Next’s board either. NextReg $00 has values for the Next core running on
other FPGA boards, such as $DA on a MiSTer, and $08 for emulators. A program that reads it learns where it
runs, and the firmware does exactly that.
What to take home
The Next is a blank FPGA until a bitstream tells it what to be, and the bitstreams live in a flash chip of
slots: 32 slots of 512K on the Issue 2 board, 15 of 2,176K on the Issue 4 and Issue 5. Slot 0 is the anti-brick core, the
doorman that the chip loads at every power-on and that normally waves you on to slot 1, the Next core. One
NextReg makes it possible: writing bit 7 of NextReg $10 makes the FPGA reload itself from the selected slot,
and only config mode may choose the slot. A hard reset does the same for slot 1. The SRAM survives the change,
which is how one core leaves messages for the next.
The Next core starts in config mode, with an 8K boot ROM that loads one module of TBBLUE.FW from the SD card:
normally the boot module, which reads config.ini, loads the ROMs into the SRAM through NextReg $04, sets the
peripherals, writes NextReg $03 to leave config mode, and soft-resets into NextZXOS. Space opens the
settings, U the updater, C the extra cores.
The updater reads TBBLUE.TBU, picks the core for the board NextReg $0F reports, checks its checksum before
erasing anything, and writes slot 1. If that ever leaves slot 1 broken, power on with DRIVE and M1 held, and
the doorman runs the updater for you. A machine that rebuilds itself from a file, and keeps a small, unchanging
copy of itself to rebuild from: I cannot think of a better way to make a computer you can update without fear.