BackgroundThe first time I saw a Commodore 64 emulator running on a PC was 17 years ago. Immediately when I saw it, I have wondered how it worked and had the desire to write my own.
This desire slumbered for years, until late 2015 when I scarped together the courage to write one in Java.
I finished off the Android emulator in January 2017 and since then months has past since I played with 8-bit emulators.
Seven months later, though, I started contemplating with a new idea: A complete C64 system on a FPGA.
Before I continue the story, let just stand still a moment at the term FPGA, for those that is not quite familiar the term.
FPGA is the acronym for Field Programmable Gate Array. It is basically a chip containing a bank of logic gates and/or functional blocks which you can connect together to form a function you desire. Typical functions that you can implement in an FPGA include graphic acceleration and digital signal processing.
The nice thing about an FPGA is that you can reconfigure it.
Anyway, back to the main story.
I had a look on the net to see if there is any current C64 on FPGA implementations and couldn't really find any. The closest I could find was 6502 oriented systems, connected via a serial interface.
These serial interface implementations is nice if you want to play around with legacy BASIC, but without fancy graphics!
This was one of the main reasons I wanted to start writing my own C64 implementation on a FPGA.
Which FPGA Development Board?The big question is which FPGA Development board will be most fit for the purpose of a complete C64 System?
Probably the most important feature for this is having some kind of video output for the graphics.
One FPGA development board that fits this need is the Basys 3 board from Digilent, which features a VGA port:
I had a lot of fun with this board until I read more on how LCD VGA monitors work. I ended up with the question on how to interface a PAL/NTSC signal with a LCD monitor with an odd resolution of 1366x768 and maintaining the aspect ratio. Not an easy question to answer, at least not with some kind of framebuffering.
The only resource the Basys 3 have available for framebuffering is on FPGA Block-RAM, which will give you a couple of screen line buffering. Then you would also need to reserve some Block RAM space for 64KB of C64 RAM, and the three ROMS of the C64 system.
This all adds up to a very tight Block RAM budget, and this board doesn't provide us with the luxury of a couple of Megs of SDRAM.
I needed a board that would give me some more breathing space.
After some more research, I found the ZYBO board, also from Diligent:
This board features an FPGA with similar capabilities as the Basys 3, and a 512MB of onboard SDRAM.
The added SDRAM will surely provide some helping should we be running out of Block RAM resources.
The ZYBO board will be indeed be the board I will be using through this BLOG series.
More on the ZYBO boardThe most interesting part of the ZYBO board is the FPGA chip itself.
The FPGA chip is a ZYNQ. This is basically a dual ARM Cortex core, together with the FPGA as shown in the following block diagram from the Diligent website:
The FPGA part is represented via the yellow block at the bottom.
As you can see from the diagram, the FPGA also have access to the diagram via AXI ports, which is a protocol defined ARM Holdings.
When you write a program to run on the ARM Cortex processor, you also have access to design in the FPGA fabric via memory mapped registers. I will discuss this in more detail in a future post.
The fact that you the ARM core can "see" your FPGA design, means that you can also harness the ARM core to assist in debugging your FPGA core. This makes live a bit simpler by not having you to add extra debugging cores in FPGA design.
ApproachThis Blog series I will also approach in an incremental fashion. Starting with something simple and gradually evolving it.
I will be building on the 6502 core written by Arlet Ottens, available on Github.
Arlet Ottens have done some excellent work on writing a 6502 core that can run on an FPGA having Block RAMS.
Block RAMS work a bit different than the RAM you used to get in a C64. In C64 when you asserted the Read line and address on the memory bus, there was a small time period when the data on the databus was in a uncertain state.
Granted that this uncertain period was a disadvantage, on the other hand if you keep your clock period longer than this uncertain period, it can actually simplify your CPU design! I mean, if you a assert your lines now, you can have your data in the next clock transition!
With Block RAM however, you need to wait an extra full clock cycle for your data, from asserting the lines on the bus before you get your data.
This extra cycle in between causes that you cannot use a direct 6502 implementation as is.
Arlet had to jump through a couple of hoops to get a 6502 implementation working with Block RAMS.
Another 6502 project I will be leveraging from, is the 6502 Test Suite developed by Klaus Dormann to verify that my FPGA implementation is sound.
The Test Suite developed by Klaus Dormann is very comprehensive. Should a 6502 device or emulator pass all the tests, you are almost guaranteed that you have a sound 6502 implementation.
So in short. In the next post I will be running Arlet Ottens's core in simulation with the 6502 Test Suite developed by Klaus Dormann.
Once convinced that Klaus Dormann's 6502 Test Suite ran successfully, I will be adding parts to the FPGA on the way to a full C64 implementation.
In SummaryThis post was an introduction to my new series of Blog posts regarding the creation of a Complete C64 system on an FPGA.
The FPGA board I will be using throughout the series will be a ZYBO from Digilent.
In the next post I will be running Klaus Dormann's 6502 Test Suite on Arlet Otten's 6502 core in a Verilog simulation.
Till next time!