Part 1: This should be easy, right?
Some months back I was introduced to OneChipMSX by a keen user of the Turbo Chameleon 64 and various other FPGA boards, in the hope that I’d be able to port the project to the Chameleon.
At the time it was a more complicated proposition than I was capable of tackling, but I’ve learned a great deal since then, so recently decided to look again.
At a first glance OneChipMSX seems to be a good fit for the Chameleon: source is available, and apart from the designated OneChipMSX hardware it’s been ported to the Altera DE0 and DE1 boards. The project doesn’t use SRAM, and will only half-fill the EP3C25 on the Chameleon 64. All in all it looks like an easy port, except for one inconvenient little detail: there’s a BIOS file which needs to be stored in flash. The existing ports of the project all have one thing in common; rather than storing the BIOS in separate flash, they store it in the very same flash chip that contains the FPGA bitstream; the EPCS4. This makes porting the project to a board that doesn’t use this configuration chip a little tricky, since the Initial Program Loader which loads the BIOS from the EPCS is (a) a tiny Z80 assembly language program, and (b) lacking source code!
Having grown up on a C64 and then an Amiga, I’ve never been exposed to Z80 machine language, so there was quite a learning curve involved. I have to say, though, having read up on the subject that I’m impressed with the Z80 instruction set – the instruction set is elegant and the code density is excellent.
The IPL is, in theory, capable of loading the BIOS image from an SD card, but I have yet to get this working; it apparently requires that the card be freshly formatted, regular SD rather than SDHC, and for the BIOS to be the first file copied to the newly-formatted card.
I did manage to find source code for one version of the Initial Program Loader, but soon realized that it expects the BIOS to be raw, whereas the version supplied with the DE1 port expects a packed BIOS image (supplied in hex form).
It soon became clear that my choices were to (a) rewrite the initial program loader to deal with the Chameleon64’s flash chip, or bypass the Initial Program Loader, forget about flash and use a more sophisticated bootloader to read the BIOS from SD card. Since the Chameleon has no switches, and the switch functions are quite important I also need to implement some kind of OSD menu system, so I elected to add an extra CPU to the project to handle both duties – booting and OSD handling. If you’re a regular reader you’ll probably have no trouble at all guessing which CPU I chose!