Sunday 16 February 2014

Creating the C65GS KickStart ROM

The C65 ROM is 128KB, which is more than I can fit in the internal RAM of the FPGA, so I need to load it externally and store it in the 16MB SDRAM.  This means we need a little ROM to load the ROM from the microSD card.  For Amiga users this will immediately remind them of the kickstart ROM.  Linux also has a similarly named facility for automatic installation, but that isn't really relevant for us.

So I have begun implementing a kickstart ROM for the C65GS.

The idea is that on boot, the C65GS will map a special 8KB ROM @ $E000 - $FFFF, that will stay mapped until $01 gets written to, after which the normal memory mapping rules will apply.

This little ROM needs to look for an SD card, and then look for a FAT32 file system on that card, and then on that file system look for C65GS.ROM, and load that into the right place.

Of course we don't want to waste time on this each time we reset if the ROM is already loaded, so this ROM should also do a checksum on the section of the SDRAM where we intend to place the ROM.  If the checksum is valid, then we can just jump straight into the ROM.

Today I finally got the SD card controller working well enough (although it still has some bugs), that I could begin making sensible progress on the kickstart ROM.

Specifically, I have working:

1. The code working that checksums the SDRAM, and if OK, switches to C64 mode, and starts the C64 kernel.
2. The code that looks for an SD card.
3. The code that reads the master boot record from SD card, finds the first partition, and then checks if that partition is FAT32, and complains if it isn't.
4. The code that can map a FAT32 cluster to an absolute sector, which can be used to load the first cluster of the root directory of the file system.

Here is how it looks right now.

This is without any SD card inserted.

If I then insert an SD card (without needing to reset the machine, because kickstart keeps probing the SD card), then we see something like the following:

I was pretty happy that it worked when I hot-inserted the SD card.  The various hex output will probably be trimmed in due course, but for now provides me with some helpful diagnostics as I make sure I am interpreting the filesystem and partition table correctly.

The block of stuff nearer the bottom is the first 256 bytes of the root directory.  The volume name of the file system can be seen at the beginning (FPGA_BOARD rendered as FPGAMBOARD), and a few file names can be seen in there, such as VGA.BIT (VGA@@@@@BIT), which is an older version of the FPGA program itself.

Next step is to actually copy the ROM onto the SD card, and then get the cluster number of the ROM, and start loading the clusters into the SDRAM.


  1. I was noticing on the nexys hardware, the first time it starts up, it hides the text output from kickstart. It does appear fine though if I perform the reset via holding down restore for 3 seconds.

    Is there any way to make it visible on that first start up too? (Not that this is terribly essential though, just thought it might help out with debugging startup issues :)).

    PS. I'm re-reading your blog posts, past forum + wiki posts too, to gear up my brain for another swing at this project during my xmas break :)

    1. That's a rather strange sounding problem. Not really sure what is going on there. If you can video it happening, and post a link to the video, I can try to take a guess. Which bitstream are you using?


    2. Oh, so it shouldn't behave like this? Hmm, then maybe it's some quirk with my el-cheapo dick-smith tv (perhaps there's some delay before it realises there is a video signal available and misses seeing the kickstart text?). Well, I've sent you a video of what I'm experiencing via skype. I'm using the "bit10071332_cursor_42250be~.bit" bit-stream that Andreas recently shared.