z80replacement · a Z80 CPU replacement with an FPGA

Memory

the SRAM, flash and the memory modes

Status, 29 November 2026: nobody has built this module yet. The first sample run of 2 boards comes soon. Wait until the project has tested these boards before you send an order or a build request to a factory.

Repository file: docs/memory.md

Amount of RAM

The full version has 2 MB (16 Mbit) of asynchronous SRAM (R10). The decision of 9 November 2026 replaced the 256 MB DDR3L RAM with the SRAM. The DDR3L escape of the FPGA was the main routing block of the PCB, and the SRAM makes the PCB routable.

The Z80 addresses 64 KB. A RomWBW system uses 512 KB of ROM and 512 KB of RAM. Memory mode 2 uses 1 MB of the 2 MB: the physical address has 20 bits, the ROM is at 00000H to 7FFFFH, and the RAM is at 80000H to FFFFFH. The FPGA drives A20 low. The upper 1 MB is not used.

Why an SRAM

The SRAM has no refresh, no calibration, no controller IP and no 1.35 V rail. The FPGA pins of the SRAM are in 3.3 V banks. sram.md describes the part, the controller and the board.

Item Selection
Part ISSI IS61WV20488FBLL-10BLI (Mouser 870-61W20488FBLL10BI)
Size 16 Mbit, 2M × 8
Supply 2.4 V to 3.6 V (3.3 V on the module)
Access time 10 ns
Package 48-ball mini BGA, 6 mm × 8 mm, 0.75 mm pitch
FPGA pins 32 balls in banks 3 and 6: 8 data, 21 address, CE#, WE# and OE#
Controller gateware/sram/z80r_mem2_sram.sv, 164 LUT4 and 383 flip-flops

CAUTION: Find the stock of the part before the PCB order. Compare the ball map in make_lib.py with the official data sheet before the order (sram.md, "The IS61WV20488FBLL-10BLI (10 November 2026)").

History: until 10 November 2026 the part was the ISSI IS62WV20488FBLL-45BLI (LCSC C1352595, 45 ns, 2.2 V to 3.6 V). On 10 November 2026 LCSC, Digi-Key, Mouser, Newark, Avnet and TME had no stock of that part. The IS61WV20488FBLL (10 ns) has the same package and was the fallback (sram.md, "Stock and replacements (10 November 2026)").

The DDR3L design is history. ddr3.md keeps the DDR3L text that was in this file: the reasons for DDR3L, the problems that DDR3L added, and the SDR SDRAM fallback.

Memory modes

The FPGA configuration selects one of these modes. With the boot copy, the USB tool can also change the mode: see "Settings in the flash" below.

Mode Description Lite Full
0, plain CPU Every memory and I/O cycle goes to the bus. The module is a Z80 and nothing more. This is the default. yes yes
1, overlay Address ranges that the user selects come from internal memory. The bus interface does not assert /MREQ for these ranges. All other cycles go to the bus. up to 32 KB yes
2, banked The module contains the banked ROM and RAM of a RomWBW system: 32 KB banks, bank select at ports 78h and 7Ch, as in z80fpga. The system then needs no memory board. no yes

Mode 2 uses the bank scheme of the RomWBW SBC and MBC boards. Other bank schemes, for example the RC2014 512K ROM 512K RAM module, are a later addition.

Mode 1 in the gateware

STATUS: SIMULATION ONLY. gateware/bus/z80r_ovl.sv has the block RAM and the page decode. The pin stage (z80r_pins.sv) keeps the internal cycles off the bus. "Mode 2 in the gateware" below describes mode 2.

Settings

The settings are parameters of z80r_bus and z80r_top. With the boot copy (BOOT at 1), the header of the flash image replaces OVL_MAP, OVL_RO and OVL_ECHO at power-up (see "Settings in the flash" below).

Parameter Function
OVL_MAP One bit for each 4 KB page. Bit p set: page p (p000H to pFFFH) comes from block RAM. 0 gives mode 0. With OVL_MAP at 0 and BOOT at 0, the bitstream has no block RAM for the overlay.
OVL_RO One bit for each page. Bit p set: the CPU cannot write page p. The page is a ROM.
OVL_KB The size of the block RAM: 4, 8, 16, 32 or 64 KB
OVL_INIT A hex file for the start contents of the block RAM, or no file (all 0)
OVL_ECHO 1 (the default): the opcode of an internal fetch goes on the data bus. See below.

Page p uses block RAM page (p mod OVL_KB/4). Thus two pages of OVL_MAP must not have the same remainder. The simulation stops with an error if they do, and z80r_romimg.py makes the same check for a flash image.

The lite version (LFE5U-12F) has 32 block RAMs of 2 KB, and the core uses one block RAM. Thus the lite version has at most 32 KB of overlay. The 85F has 208 block RAMs, and 64 KB of overlay uses 32 of them. Note that nextpnr-ecp5 --12k uses the 25F device with 56 block RAMs. Thus nextpnr places a 64 KB overlay for the 12k, but the real 12F does not have enough block RAM.

The bus during an internal cycle

  • A memory read or a memory write of an internal page has no /MREQ, no /RD and no /WR on the bus. The address is on the bus, as in mode 0.
  • The CPU cannot write a page of OVL_RO. The write does not change the block RAM, and the bus does not see the write.
  • An opcode fetch from an internal page has /M1 and /RD, but no /MREQ. With OVL_ECHO at 1, the module puts the opcode on the data bus from the T2 rise to the T3 fall. The Z80 PIO, CTC and SIO read the opcode of each fetch to find RETI. Thus an interrupt routine in an internal page still ends the interrupt of the peripheral.
  • The refresh of each fetch goes to the bus, as in mode 0.
  • Internal cycles obey /WAIT, as in mode 0.

CAUTION: With OVL_ECHO at 1, the module drives the data bus during an internal fetch while /RD is low and /MREQ is high. If a board on the bus decodes /RD without /MREQ or /IORQ, the board can also drive the data bus. For such a system, set OVL_ECHO to 0. Then the peripherals do not see RETI from an internal page.

The debug unit and the loader

The memory port of the debug unit uses the same decode (debugger.md, item 5). A read or a write of the unit to an internal page uses the block RAM, with no cycle on the bus. The unit can also write a page of OVL_RO. Thus the RAM loader (loader.md) can load a ROM image into the internal pages.

Size and speed

Place and route of z80r_top with the debug unit, seed 1, on the 12k model:

Setting LUT4 Block RAM Highest bus clock
Mode 0 7052 1 17.5 MHz
16 KB: pages 0, 1, E, F, with 0 and 1 read-only 7292 9 17.7 MHz
64 KB: all pages 7265 33 17.0 MHz

routing_study.md has the delays of the pins with the overlay.

Tests

mingw32-make test in gateware/bus runs tb_ovl.sv at 10 MHz and 4 MHz, and with OVL_ECHO at 0. The program ovl_prog.z80 runs from internal ROM in pages 0 and 1. The program uses internal RAM in page E for the stack, and for a routine that the program copies there. The bus memory of the internal pages holds 76H (HALT), so a fetch from the bus stops the program. The bench examines these items:

  1. No /MREQ on the bus for an internal page, except for a refresh.
  2. No /WR without /MREQ or /IORQ. No /RD without /MREQ or /IORQ, except for an internal fetch with OVL_ECHO at 1.
  3. With OVL_ECHO at 1, the opcode on the bus at each internal fetch, and the RETI of the interrupt routine on the bus.
  4. A write to the internal ROM has no effect.
  5. The results of the program, the refresh cycles, and the one interrupt.

mingw32-make test-load in gateware/dbg loads a ROM image into the internal pages with the RAM loader, and then runs a program from the internal ROM (loader.md).

The boot copy

With BOOT at 1, the module copies a ROM image from the configuration flash into the block RAM of the overlay at power-up (gateware/bus/z80r_boot.sv). The header of the image also gives the settings. The core stays in reset until the copy ends. The bus then sees the core in reset, as with a low /RESET.

Parameter Default Function
BOOT 0 1: the boot copy. The bitstream then has the block RAM of the overlay, also with OVL_MAP at 0.
BOOT_OFS 400000H The flash address of the selector

The flash holds a selector and 11 slots. Each slot can hold one ROM image:

Flash address Contents
400000H The selector: the 4 bytes Z80S and the slot number (1 byte).
500000H + n × 100000H Slot n, n = 0 to 10: a header of 16 bytes, then the block RAM, OVL_KB KB, in the order of the block RAM pages.

The copy reads the selector first. With no Z80S, for example in an erased sector, the copy uses slot 0. With a slot number of 11 or more, the copy uses no slot.

Settings in the flash

The header of a slot holds the settings of the image:

Byte Contents
0 to 3 Z80R
4 1, the version of the header
5 The size of the image in 4 KB units. In mode 1 the value must be OVL_KB / 4 of the bitstream, and in mode 2 MEM2_ROM_KB / 4 (128 for 512 KB).
6, 7 The internal pages, as OVL_MAP (low byte first). 0 gives mode 0. Mode 1 only.
8, 9 The read-only pages, as OVL_RO. Mode 1 only.
10 Bit 0: the opcode echo, as OVL_ECHO. Bit 1: the console ACIA on. Bit 2: the control port is hidden from power-up. Bit 3: memory mode 2 is off at reset. Bit 4: memory mode 1 is off at reset. Bit 5: Z80 code may not remove the debug unit. Bits 2 to 5 are 0 in the earlier images. See z80_control.md.
11 The I/O address of the ACIA, as ACIA_BASE
12 The I/O address of the control port. 0 gives the CTL_BASE of the bitstream. See z80_control.md.
13 to 15 0

If the header is correct, the copy reads all of the block RAM. The module then uses the settings of the header in place of the parameters. If the header is not correct, for example in an erased slot, the copy stops after the header. The block RAM then keeps its start contents (OVL_INIT, or 0), the module uses the parameters, and the core starts. The ACIA settings have an effect only if the bitstream has the ACIA (ACIA at 1).

The settings change only at power-up. To change a setting, write a new image, and then load the configuration again or turn the power off and on.

The copy uses the READ command (03H) of the flash in SPI mode, with SCK at 12.5 MHz from the 25 MHz clock. SCK goes out on the CCLK ball through the USRMCLK primitive. A copy of 16 KB takes 10.5 ms, and a copy of 64 KB takes 42 ms.

The USB tool

tools/z80r_romimg.py makes the files, and openFPGALoader writes them through the USB-C port. z80r_romimg.py prints the openFPGALoader command for each file. To put a ROM in slot 0 and select slot 0:

python3 tools/z80r_romimg.py --map C003 --ro 0003 --kb 16 --slot 0 rom.bin@0000 -o slot0.bin
openFPGALoader -c dirtyJtag -f -o 0x500000 slot0.bin
python3 tools/z80r_romimg.py --select 0 -o select.bin
openFPGALoader -c dirtyJtag -f -o 0x400000 select.bin
Option Function
--map The internal pages, in hex. 0000 gives mode 0.
--ro The read-only pages, in hex. Each page must also be in --map.
--kb The OVL_KB of the bitstream
--no-echo No opcode echo
--acia-base, --no-acia The address of the ACIA (hex, even), or the ACIA off
--slot The slot, for the printed command
--select N Make the selector for slot N, or off for no image
--mode2 FILE Make a slot for mode 2 from a raw ROM file, for example a RomWBW .rom. A shorter file gets FFH at the end.
--rom-kb The MEM2_ROM_KB of the bitstream, for --mode2 (default 512)

z80r_romimg.py puts each byte in the correct block RAM page, and stops with an error if a byte is not in a page of --map. The inputs are the same as for the RAM loader: FILE@ADDR for a binary file, or an Intel HEX file. To change only the settings, make the image again with the same inputs and new options.

CAUTION: The selector and the slots must not overlap the bitstream. The uncompressed bitstream of this design is 1948588 bytes on the LFE5U-85F and 603232 bytes on the LFE5U-12F (ecppack, 8 November 2026). The image in the flash is compressed (BITOPT in gateware/top/Makefile): 408529 bytes on the 85F and 227135 bytes on the 12F. Thus 400000H (4 MB) leaves space with a large margin. The load takes 0.09 seconds (see "Load time" in fpga.md). Read the flash back once on the first board, and compare the files, before you trust the openFPGALoader commands above.

BITOPT is only for the file that goes into the flash (build/top-85k.bit). For a load into the SRAM of the FPGA through JTAG, use build/sram-85k.bit, which the Makefile makes with SRAMOPT (fpga.md, "Load time").

Tests of the boot copy

mingw32-make test in gateware/bus also runs tb_ovl.sv with the boot copy. The bench has a model of the flash with the files from z80r_romimg.py, and the block RAM starts empty:

  1. Slot 1 through the selector. The parameters of the bitstream are mode 0, no echo, and the ACIA at 80H. The header gives the internal pages, the echo, and the ACIA at 90H. The core does not start before the copy ends, the copy reads all the image, and the program runs from the copied ROM. The program finds the ACIA at 90H and not at 80H.
  2. Slot 0 with no selector, and a header with no echo and no ACIA. The program runs, the bus sees no echo, and the program finds no ACIA.
  3. An erased flash: the copy stops after the header of slot 0, boot_ok stays 0, the block RAM stays 0, and the core starts.

Place and route of z80r_top with the debug unit, the ACIA, 16 KB of overlay and the boot copy with the settings in the flash, seeds 1 and 2: 7605 LUT4, 1171 flip-flops and 9 block RAMs. The highest bus clock is 17.3 MHz to 17.7 MHz, and the 25 MHz clock reaches 102 MHz to 120 MHz. The critical path of the bus clock is in the core, not in the settings. The settings go from the 25 MHz clock to the bus clock with no synchronizer (about 10 ns). These paths do not limit the bus clock, because the settings change only while the core is in reset.

Not done yet

  • A change of the settings while the module operates. The settings change only at power-up.
  • A board test.

Mode 2 in the gateware

STATUS: SIMULATION ONLY. gateware/bus/z80r_mem2.sv has the bank decode and the cache. gateware/sram/z80r_mem2_sram.sv connects the cache to the SRAM (sram.md). No board test is done yet.

Settings

Parameter Default Function
MEM2 0 1: mode 2. Mode 2 takes the place of the overlay and of the boot copy.
MEM2_LINES 2048 The lines of the cache. A line is 16 bytes, so 2048 lines are 32 KB.
BOOT 0 1: the boot copy writes the ROM image of the flash slot into the ROM of mode 2 (see "The boot copy in mode 2")
MEM2_ROM_KB 512 The size of the ROM image of the boot copy

Mode 2 is only for the full version (the 85F), because the lite version has no SRAM.

Banks

The bank scheme is the scheme of z80_mmu.sv in z80fpga:

  • 32 KB banks. Banks 00H to 0FH are ROM, and banks 80H to 8FH are RAM.
  • A write to port 78H or 7CH selects the bank of the low 32 KB. The high 32 KB is always bank 8FH.
  • After a reset, the low 32 KB is ROM bank 0.

The SRAM holds the ROM at physical address 00000H to 7FFFFH and the RAM at 80000H to FFFFFH. The physical address has 20 bits, and A20 is low. The CPU cannot write a ROM bank. The memory port of the debug unit can write a ROM bank. Thus the RAM loader (loader.md) can load a ROM image in mode 2 too. test_load.py tests the loader and the debug unit on a cosim with mode 2.

The bus in mode 2

  • No memory cycle goes to the bus. The bus sees /MREQ only for a refresh.
  • The I/O cycles of the bank ports 78H and 7CH do not go to the bus.
  • An opcode fetch has /M1 and /RD on the bus, and the opcode echo, as in mode 1.
  • A cache miss inserts wait states. The bus sees the wait states, as for a /WAIT from the bus.

The cache

The cache is direct mapped, with lines of 16 bytes, in block RAM. A line is 16 bytes of the SRAM. A read finds its line in T2. If the line is not in the cache, the read waits until the SRAM side gives the line. A write updates the line if the line is in the cache, and always goes to the SRAM (write-through). One FIFO carries the writes and the line requests to the SRAM side. Thus a read never passes an earlier write.

The SRAM needs no init sequence. The core stays in reset until the reset delay of the SRAM controller ends (ready).

The boot copy in mode 2

With MEM2 and BOOT at 1, the boot copy reads the selected slot of the flash, as in mode 1 (see "The boot copy"). The copy writes the image into the ROM of mode 2, from physical address 00000H. The steps:

  1. The ready signal of the SRAM controller goes high.
  2. The copy reads the selector and the header. The header gives the echo and the ACIA settings. The map and the read-only pages have no effect.
  3. The copy writes each byte through a FIFO to the SRAM side. If the FIFO is full, the copy stops SCK until the FIFO has space.
  4. The core starts when the copy ends.

A copy of 512 KB takes about 0.34 s. To make a slot from a RomWBW ROM:

python3 tools/z80r_romimg.py --mode2 SBC_std.rom --slot 0 -o slot0.bin

Tests

mingw32-make test in gateware/sram runs tb_sram.sv (the controller alone) and tb_mem2.sv. The bench tb_mem2.sv has the core, the cache, the SRAM side and a model of the SRAM (sram_model.sv) that checks the timing of the SRAM. The bench runs at 10 MHz, 4 MHz and 20 MHz, and with a cache of 64 lines (1 KB). The program mem2_prog.z80 runs from ROM bank 0 in the SRAM. The program reads and writes ROM, common RAM, ROM bank 1, and RAM banks 80H to 83H. The banks 82H and 83H use the same cache lines. The bench examines these items:

  1. The results of the program.
  2. No /MREQ on the bus except for a refresh, and no bank port on the bus.
  3. No /RD or /WR on the bus without /MREQ or /IORQ, except the /RD of an opcode fetch.
  4. Each line request comes from T2 of a read, for the line on the pins.
  5. The core does not start before ready.

A run with the boot copy loads the program from a 4 KB slot in a model of the flash. ROM bank 0 holds 76H (HALT) before the copy. The bench examines that the copy waits for ready, and that the program runs from the copy. A run with RD_CYC at 1 must fail. The model of the SRAM then reports a read that is too early. sram.md, "Tests", has the full list.

Size and speed

The full design has the debug unit, the ACIA, mode 2, the boot copy and the SRAM controller. Place and route on the 85F, seed 1, with MEM2 at 1: 8251 TRELLIS_COMB, 1872 flip-flops, 18 block RAMs and 87 I/O. The 25 MHz clock reaches 111 MHz. The highest bus clock is 16.86 MHz. A bus clock of 20 MHz fails. The same design with MEM2 at 0 also fails at 18.06 MHz, so the SRAM does not cause the limit. The controller alone uses 164 LUT4 and 383 flip-flops. The design has no PLL.

The history of the DDR3L builds (bus clock, system clock and margin) is in ddr3.md.

Not done yet

  • A bus master on /BUSREQ cannot reach the memory of mode 2.
  • A constraint or an I/O register on the SRAM pins in nextpnr. The simulation examines the margins only.
  • A board test.

Access time

In mode 1 and mode 2, the internal memory must deliver data before the CPU reads it. An opcode fetch gives about 1.5 T-states from the address to the data read:

Bus clock Time for an opcode fetch
4 MHz about 375 ns
7.3728 MHz about 200 ns
10 MHz about 150 ns
20 MHz about 75 ns

Mode 1 gives the data in time at all of these clocks. In mode 2, a read of a line from the SRAM takes 1360 ns, plus the clock crossing in each direction (see sram.md, "Timing"). That is longer than a fetch, so mode 2 has a cache: a cache hit gives the data in time, and a miss inserts wait states. Two parts make a miss shorter:

  • The reply of the SRAM side crosses into the bus clock with one register on the falling edge and one on the rising edge.
  • On the edge of the fill, the line also goes into a bypass register, so the read does not wait for one more read of the block RAM.

tb_mem2.sv measures the wait states of a miss (9 November 2026). The values are for each line request, and include the FIFO and the synchronizer crossings. The DDR3L values are for comparison.

Bus clock Wait states for each miss Time DDR3L (history)
4 MHz 9.0 2.25 µs 5.1
10 MHz 18.0 1.8 µs 8.8
20 MHz 32.2 1.61 µs 12.3

The SRAM line fill is slower than the DDR3L line fill. The SRAM has an 8-bit data bus, and the controller reads 16 bytes one after the other. The speed of a real program depends on the hit rate of the cache. Measure the hit rate with RomWBW.

Configuration flash

A 128 Mbit QSPI NOR flash holds the FPGA configuration and the ROM images. The LFE5U-85F bitstream is about 1.9 MB (measured, see "The boot copy"). The rest of the flash holds ROM images, for example a 512 KB RomWBW image. At power-up, the FPGA copies the selected ROM image from flash to internal memory. In mode 1 the boot copy does this (see "The boot copy" above).

Source of this page: web/ and docs/ in the z80replacement repository. Hardware: CERN-OHL-S-2.0. Other files: GPL-3.0-or-later.