Wednesday 16 January 2013

Virtual MSX disk drive


When I was a kid I had an MSX, a SVI-728 to be more precise, it's just a Z80 based computer with 64Kb of RAM. Mine used cassette tapes to load games and the loading times were eternal not to mentioned all the loading errors that required restarting the load from the beginning.

Other friends of mine had an MSX with a disk drive but I got still stuck with the tapes :-(

So... Revenge! I decided to build my own disk unit :-)

MSX's with a disk drive come with a disk BIOS that handles all the disk operations, from the lowest level (i.e.: read sector 23) to extending BASIC with new commands to list the available files in the disk, formating, deleting and creating files, and so on.

My first step was to get a disk BIOS from a MSX with a disk unit and patch the sector reading/writing routine so instead of talking to a disk unit, it would talk to another device, an Arduino.

Unfortunately I can't fit an 720Kb disk in an Arduino but since it has a USB connection it can ask my PC to get that sector form an certain disk image in my PC's hard's disk and send it thought the USB cable.

For that I need some gluing hardware between the MSX and the Arduino, here is the pic of the setup

Breadboard with arduino-msx gluing logic

And here are the schematics of the interface:


Schematics

The trick of the trade

It all works thanks to the Z80's /WAIT pin, when an IN or an OUT instruction happens for an port below 31 the logic gates put this pin to a low sate making the Z80 wait, the Arduino notices that and can fetch the data from the computer and put it onto the 74245 buffer, then the Arduino will raise the /WAIT pin to make the Z80 resume the execution so the OUT instruction gets the data from the buffer.

The software bit on the MSX side...

My computer didn't have a disk BIOS so I had to get one, fortunately Arjen Zeilemaker had disassembled some and put the asm code in sourceforge. All I had to do was to write the DSKIO function to talk with my arduino, the code was so simple that I just used notepad and worked on the second run. I took a game cartridge and replaced the game's ROM with an 16Kb EEPROM I got from EBAY. As for writing the EEPROM I used a reader/writer I built once as a quick hack, I used for that a ATMEGA128 since it has enough pins to driver teh 28 pins you need to set in order to write or read an EEPROM.

Simple flash memory reader on the top, game cartridge on the bottom

The two white cables sticking out of the Atmega128 are the serial port, I wont tell what are the black and red ones :-)

..and on the PC side

I just used Python to read the commands coming from them MSX, the script will take the 512 bytes sector and will send it to the arduino and 1Mbit per second. The Arduino will send byte by byte to the Z80 at a similar speed.


Here is the video, sorry for the shaky hand :-) On the left you have the python script, on the right VLC media player.



Source code! :)


Ok here are the sources, sorry I didn't document the code so much, please let me know if you have any questions.
https://docs.google.com/file/d/0B4IJZPdCtzO0OGJvcnB3U0xnY1U/edit?usp=sharing