RTL implementation, functional C++ emulator, and toolchain for LX-GPU — a programmable 16-bit 2D graphics coprocessor for Z80 / MSX-class systems (Aleste LX).
Architecture specification: XiAleste / Aleste LX GPU Documentation.
- 16-bit datapath, 32-bit fixed microinstructions executed on a 3-stage pipeline (
F -> D -> X) with 4096×32 microcode BRAM (core_rom). - Four instruction classes (
[30:29]):- REG-REG (
00):DST = DST op SRC(6-bit operand map0..63) - LDI16 (
01): conditional 16-bit immediate load intoDST, flags untouched - CONTROL (
10):NOP,JMP(immediate or register-indirect),CALL,RET,HALT,IRQ,FLUSH - REG-IMM11 (
11):DST = DST op imm11with sign/zero extension
- REG-REG (
- 16-bit ALU (
core_alu): logic (MOV,MVN,AND,ANDN,OR,ORN,XOR,XNOR), arithmetic (ADD,SUB,ADC,SBC), shifts (ROR,SHR,SAR), and signed16×16 -> 32MUL(upper 16 bits latched toMHI). - Predication & Hardware Loops:
- 4-bit ARM-style condition codes (
AL,EQ,NE,CS,CC,MI,PL,VS,VC,HI,LS,GE,LT,GT,LE). SHADOWregister saves{V, C, N, Z, PC+1}onCALL.- Zero-overhead hardware loops via
LOOP_CNT,LOOP_TGT, and instruction bit[31](L).
- 4-bit ARM-style condition codes (
- 4 Unified Memory Channels (
CH0..CH3):- Each channel has
DATA,IDX,IDXH,STEP, andMODEPAGEregisters, backed by a 1-word write-back cache (ch_cache) and 20-bit fractional pixel address generator (ch_addr_gen). - Cache writes never read memory first: a pixel is merged into the cache word with a bit mask, a dirty mask is kept per nibble, and the write-back uses byte enables (
wb_sel_o, SDRAM DQM), so16 bppand8 bppwrites cost no reads at all. Only a word with a half-written byte (one4 bpppixel of a pair) and no fill is read before its write-back. Reading a partly written word fills it and keeps the written nibbles. - Write-backs go to a one-word posted write buffer shared by the four channels, so the core carries on while the word is written; reads from memory wait until the buffer is empty.
FLUSHwrites the channel's word back and also waits for the buffer: afterFLUSHeverything is in memory. - Writing
MODEPAGEwith the page the channel already has cancels a pending page change (A -> B -> Awith no access in between stays onA). - Supported formats:
16 bpp,8 bpp,4 bpp,2 bpp(read-only) and1 bpp(read-only); 5..7 are reserved. One byte per word (the low or the high byte of each word) is8 bppwithSTEP = 2. - Pixel order, as the Aleste's video reads memory: bytes in address order (little-endian), and within each byte from the high bits.
8 bpp: pixel 0 = bits 7..0, pixel 1 = bits 15..8;4 bpp: 7..4, 3..0, 15..12, 11..8;1 bpp: bit 7 first. - Reading or writing
DATA[ch]automatically advancesIDX[ch]bySTEP[ch]. Out-of-page access (64 KiBboundary) halts the core with error code2.
- Each channel has
- ROM Bootloader:
- Permanently resides in protected ROM words
0..31(boot/bootloader.asm; writes to0..31halt with error code1). - On
GPU_START, hardware preloadsCH0(16 bpp,STEP=1) to the host packet address, copies[SIZE, START, payload...]into microcode ROM viaROMA/ROML/ROMH, and jumps toSTART.
- Permanently resides in protected ROM words
- Host interface (
host_if, 8-bit Wishbone slave):0..2GPU_ADDR(W/R),3COMMAND(1=GPU_START,2=GPU_RESET),4STATUS(R: bit 7 halted, bits 6..0 error code).5IRQ_CODE(R): the 8-bit code of the lastIRQinstruction; reading it acknowledges the interrupt (irq_odrops).GPU_STARTandGPU_RESETalso clear a pending interrupt.
Copying a 16-pixel span in 8 bpp from CH0 (source) to CH1 (destination) using a hardware loop:
.org 0x0020 ; Configure CH0 (source): 8 bpp (mode=1), page 0x00, byte offset 0x0200 LDI MODEPAGE0, 0x0100 LDI STEP0, 1 LDI IDX0, 0x0200 ; Configure CH1 (dest): 8 bpp (mode=1), page 0x00, byte offset 0x0300 LDI MODEPAGE1, 0x0100 LDI STEP1, 1 LDI IDX1, 0x0300 ; Hardware loop: 16 iterations LDI LOOP_CNT, 16 LDI LOOP_TGT, copy_loop copy_loop: MOV R0, DATA0 ; Read pixel from CH0 (IDX0 += STEP0) MOV DATA1, R0 !l ; Write pixel to CH1 (IDX1 += STEP1), loop back FLUSH 1 ; Write back dirty cache word on CH1 HALT 0 ; Stop cleanly
├── rtl/ SystemVerilog RTL (gpu_top, core_fetch, core_alu, core_regfile,
│ core_rom, ch_top, ch_addr_gen, ch_blender, ch_cache, host_if, gpu_fpga)
├── boot/ Microcode bootloader source (bootloader.asm)
├── tools/ Assembler (asm.h / asm.cpp), disassembler (disasm.h / dis.cpp), ISA defs (isa.h)
├── sim/ Verilator top-level testbench (main_top.cpp), PNG I/O (image_io.*), .asm tests
├── emul/ Cycle-free functional C++ emulator matching the RTL behavior
└── images/ Test sprites and backgrounds
Fast instruction-accurate C++ model sharing the same CLI flags, .asm loader, and PNG I/O as the Verilator testbench:
cd emul make sim-alu # Run ALU & loop test make sim-ch-wr # Run channel packing/write test make sim-loop # Run hardware loop test make sim-outer-loop # Run nested loop test make sim-sprite # Run 8bpp sprite blit test (outputs images/output_emu.png)
Cycle-accurate simulation via Verilator (supports -trace for VCD waveform dumps):
make sim-alu make sim-sprite
g++ -std=c++17 -O2 tools/asm.cpp -o asm g++ -std=c++17 -O2 tools/dis.cpp -o disasm
LX-GPU Assembler and Disassembler [EN] LX-GPU Assembler and Disassembler [RU]