The BSX Homebrew Project is an interest challenge for me, as it involves hardware and software. I’ve been concentrating on the hardware up until now, but there is a reasonable amount of software running on ROM now to assist in further hardware and software developments.
If you want to cut to the quick and go straight to the source, you can find it here on my GitHub.
The Monitor Program
The BSX boots into the monitor program (stored in ROM). This provides a simple command line interface over a serial terminal connection:
- List a block of memory in HEX and ASCII
- Read and write to I/O ports
- Load a binary file over the terminal connection
- Jump to an address
- Disassemble a block of memory
- Enter BBC Basic for Z80 (if loaded in the ROM at address &4000)
For the most part these functions are fairly straightforward to implement. I will cover the BBC Basic interpreter in more detail in future posts, but you can see a demo of it here in my previous post.
Loading binary files
When I first started coding for the BSX, I had no way to load data into RAM. So any changes to the ROM software had to be tested in ROM.
- Writing the code
- Compiling to a BIN file
- Popping the EEPROM out of the board
- Burning the BIN file onto the EEPROM using an EPROM programmer
- Pushing the EEPROM back in the board
Clearly this is quite a tedious process. So very early on I wrote the load functionality. This uses a companion utility (currently written in PowerShell) that opens the COM port and writes the file data, with a header starting with an ASCII ‘L’, and containing the file size and target location, to the STM32. The STM32 relays this information to the Z80 port used for keyboard I/O.
When the Z80 monitor receives the character ‘L’ on the keyboard port, it will then switch to loading the binary stream into RAM, and will switch back to keyboard I/O once all the bytes have been loaded.
I can now quickly compile and test new versions of the Z80 monitor program and BBC Basic in RAM, and burn to ROM when I’m happy with the results.
I’ve always fancied writing a Z80 disassembler and figured it may come in handy when testing the BSX, especially when I start using MSX ROM images.
Whilst I’m pretty sure I could have downloaded the source for a Z80 disassembler online, I figured it would be an interesting exercise to write my own, having never written one before.
If you look at the hex codes for Z80, you can see that they form a pattern. This is even more apparent if you write them out in a 16×16 grid.
This website goes one step further and provides the information required to decode Z80 instructions based upon an opcode.
Armed with that information it took me a couple of hours to get the basic disassembler up and running, and a couple more days to add the shift instruction set and tweak the output.
It currently supports all documented Z80 instructions, and some undocumented instructions (mainly the IXL, IXH, IYL and IYH registers), and will translate relative addresses into an absolute address. It currently only outputs values in HEX and makes no attempt to create a list of labels.
That notwithstanding, I’m very happy with the results.