Close

VGA Graphics On The 6502 With An FPGA

A project log for Herring 6502 Computer

Modular 8-bit computer system based on the WDC 65C02 and a mix of modern hardware.

Colin MaykishColin Maykish 08/18/2022 at 21:130 Comments

As much fun as it is to talk to an old CPU over a serial port, it's hard to beat graphics on a screen. I've had this VGA board built up for a while, but after getting it to the proof-of-concept stage, I got distracted and didn't do much else with it.

Since getting the v2 PCBs, I've dusted it off and made some updates to get it running again. It's just an Upduino 3.0 FPGA connected straight to the system bus.

Prototype "video card" for Herring

Currently, I am maintaining two different Verilog modules: one for a double-buffered framebuffer mode where the CPU can write directly into video RAM and send a command to swap the buffers when it's ready and another that's text mode only. The text mode version has a built-in font in a character ROM and it behaves somewhat like a serial terminal. The CPU sends one character at a time over the data bus to a single memory-mapped address. The FPGA adds the character to its screen buffer and moves the cursor appropriately.

Both versions run at 640x480@60Hz, but the actual size of the framebuffer is only 64x48 with 8 colors. This could be improved, but there are tradeoffs. The Upduino does not have a huge amount of block RAM and even if it did, it would be hard to map all of it into the CPU address space. It's also fairly short on pins. I'm already maxed out with just the address and data buses plus the control signals and the VGA outputs. Using more video RAM would require a different interface, command based and not straight memory mapping. This is something I'll explore further.

Text mode displays a grid of 80x48 characters. Each character is 8x8 pixels. In comparison to framebuffer mode, text mode uses only two memory-mapped registers: one for data, and one for commands (e.g. clear screen). There is also no double buffering in this mode and it is currently limited to two colors (green and not green). It's also missing a few font characters, but the basics are there!

Herring v2 using text mode graphics

I was able to get printf() outputting directly to the text mode card so as soon as I build some kind of input device, Herring can be a run as a standalone system without being tethered to a PC by the serial port.

One thing you may have noticed is the "3.3v only" sticker on the card. Herring runs at 5v and the Upduino (like most FPGAs) runs at 3.3v, but all of the components on Herring seem to run well enough at 3.3v if you keep the clock speeds down. For now, this is easier than adding buffers or level-shifters to all the FPGA lines. When I get this video card more polished, I'll add those buffers into the design and bump back up to 5v.

My (questionable) Verilog code for both modes is in the Github repo: https://github.com/crmaykish/herring-6502/tree/vga-updates/hardware. If you have suggestions, I'm all ears.

Finally, here's a demo video of Herring running Conway's Game of Life in framebuffer mode. This is C code running on the 6502 and using the framebuffer as its output. No other processing is being done on the FPGA.

Discussions