USB MegaDrive DevKit
Posted: Mon Jun 16, 2014 10:49 pm
What is it?
The USB MegaDrive DevKit is a project I started several years ago aiming to build a 100% open-source hardware/software development cartridge that aims to make it easy to write and debug homebrew code on a real MegaDrive, as cheaply as possible. And now it's pretty much "finished".
Video Part 1: Introduction
Video Part 2: Hacking a Commercial Game: Give Sonic Infinite Lives (watch fullscreen in at least 1080p)
Video Part 3: Source-Level Debugging an SGDK Application (watch fullscreen in at least 1080p)
Code & VHDL
FPGA PCB
Bridge PCB
It consists of an FPGA, 16MiB of SDRAM, 512KiB of flash, a fast (~42MiB/s) USB interface and an SD-card slot. With some patience and some soldering skills, you can make one at home for about $40.
When you plug in the cart and turn the machine on, the FPGA initialises itself from the bottom 75% of the flash chip, and then boots the MegaDrive by loading a machine-code monitor and a menu program from the top 25% of the flash chip. The menu program was written using SGDK, and just displays a menu of all the ROM images on the (FAT32-formatted) SD-card. So when you're not using it for development you can get a 2GB SD-card and install several hundred ROM images on it and play them without having to switch carts.
The machine-code monitor allows you to connect a PC via USB and using the GNU debugger GDB break into any code that is running, examine registers and memory, set breakpoints, single-step through code, etc.
You can also set up tracing, which will dump a trace-log to your PC containing details of every single bus-cycle executed by the MegaDrive as it runs. The trace-log includes a 20ns-resolution timestamp, and details of whether the access was made by the 68000 or some kind of DMA, whether it's a read or a write, the address, and the data that was read or written. The trace-log is written direct to disk, so if you have a typical 2TB hard disk, you can trace all day long without problems - useful for finding out what was happening just before an intermittent failure in your new blockbuster game cart.
How does it work?
At its heart is a Xilinx Spartan-6 LX9 FPGA. It implements a custom low-latency SDRAM-controller capable of arbitrating interleaved access to the 16MiB of SDRAM by both the MegaDrive and the host PC. The machine-code monitor and the host software collaborate in a kind of RPC arrangement, where a region of the shared SDRAM is reserved for sending arbitrary messages back and forth over USB, orchestrated by a simple semaphore.
This arrangement is used to implement a proxy for the GDB remote debug protocol, so whenever GDB asks for the value of a register or a bit of memory, that request is marshalled over the USB link to the MegaDrive, where the monitor fulfils the request and sends the results back to the proxy, and thence to GDB. It's over in quite a lot less than the blink of an eye.
The FPGA also implements an SPI master unit capable of reading from the flash chip and the SD-card.
Will you build me one if I pay you?
No sorry, I've got a full-time job building robot spacecraft, and it leaves me with no spare time! Besides, I did this to learn, not to make money. But you're welcome to build a UMDK cart yourself, or if you're not too hot with a soldering iron you could pay someone else to build one for you. You're also welcome to make several and sell them, if you think you can make money that way (if by some miracle you do get rich that way, don't send money to me, send it to Kaneda to pay for the SpritesMind hosting)!
The software, firmware, VHDL, schematics and PCB layout are all published under copyleft-style licenses so you're free to use it all however you see fit, provided you abide by the various licenses (mostly GPLv3 or LGPLv3 for software & VHDL, and CERN OHLv1.2 for the PCB).
The USB MegaDrive DevKit is a project I started several years ago aiming to build a 100% open-source hardware/software development cartridge that aims to make it easy to write and debug homebrew code on a real MegaDrive, as cheaply as possible. And now it's pretty much "finished".
Video Part 1: Introduction
Video Part 2: Hacking a Commercial Game: Give Sonic Infinite Lives (watch fullscreen in at least 1080p)
Video Part 3: Source-Level Debugging an SGDK Application (watch fullscreen in at least 1080p)
Code & VHDL
FPGA PCB
Bridge PCB
It consists of an FPGA, 16MiB of SDRAM, 512KiB of flash, a fast (~42MiB/s) USB interface and an SD-card slot. With some patience and some soldering skills, you can make one at home for about $40.
When you plug in the cart and turn the machine on, the FPGA initialises itself from the bottom 75% of the flash chip, and then boots the MegaDrive by loading a machine-code monitor and a menu program from the top 25% of the flash chip. The menu program was written using SGDK, and just displays a menu of all the ROM images on the (FAT32-formatted) SD-card. So when you're not using it for development you can get a 2GB SD-card and install several hundred ROM images on it and play them without having to switch carts.
The machine-code monitor allows you to connect a PC via USB and using the GNU debugger GDB break into any code that is running, examine registers and memory, set breakpoints, single-step through code, etc.
You can also set up tracing, which will dump a trace-log to your PC containing details of every single bus-cycle executed by the MegaDrive as it runs. The trace-log includes a 20ns-resolution timestamp, and details of whether the access was made by the 68000 or some kind of DMA, whether it's a read or a write, the address, and the data that was read or written. The trace-log is written direct to disk, so if you have a typical 2TB hard disk, you can trace all day long without problems - useful for finding out what was happening just before an intermittent failure in your new blockbuster game cart.
How does it work?
At its heart is a Xilinx Spartan-6 LX9 FPGA. It implements a custom low-latency SDRAM-controller capable of arbitrating interleaved access to the 16MiB of SDRAM by both the MegaDrive and the host PC. The machine-code monitor and the host software collaborate in a kind of RPC arrangement, where a region of the shared SDRAM is reserved for sending arbitrary messages back and forth over USB, orchestrated by a simple semaphore.
This arrangement is used to implement a proxy for the GDB remote debug protocol, so whenever GDB asks for the value of a register or a bit of memory, that request is marshalled over the USB link to the MegaDrive, where the monitor fulfils the request and sends the results back to the proxy, and thence to GDB. It's over in quite a lot less than the blink of an eye.
The FPGA also implements an SPI master unit capable of reading from the flash chip and the SD-card.
Will you build me one if I pay you?
No sorry, I've got a full-time job building robot spacecraft, and it leaves me with no spare time! Besides, I did this to learn, not to make money. But you're welcome to build a UMDK cart yourself, or if you're not too hot with a soldering iron you could pay someone else to build one for you. You're also welcome to make several and sell them, if you think you can make money that way (if by some miracle you do get rich that way, don't send money to me, send it to Kaneda to pay for the SpritesMind hosting)!
The software, firmware, VHDL, schematics and PCB layout are all published under copyleft-style licenses so you're free to use it all however you see fit, provided you abide by the various licenses (mostly GPLv3 or LGPLv3 for software & VHDL, and CERN OHLv1.2 for the PCB).