• A non-volatile 8 Megabyte Flash
memory module provides space for both the boot-up menu, and a 4 Megabyte partition for game images. The boot menu can be updated.
• A standard size SD card socket
allows the use of SD cards (tested up to 2 GB, may work with larger!).
• A PIC24 MCU
handles communication with the SD card, Flash module and cartridge state logic.
• A hardwired Logic Section
provides rapid signal decoding for high software compatibility mimicking a Mask ROM cartridge.
• Three level-shifting transceivers
interface the 5V Mega Drive chipset to the high-speed, low-power internal 3.3V Game Raccoon components.
• A register
enables bidirectional communication between the Mega Drive and PIC processor to control the Game Raccoon hardware from the Mega Drive, allowing the user to select game images to be reprogrammed from the Mega Drive itself.
• A 5-pin PICKIT header
allows the PIC MCU to be reprogrammed by enthusiasts.
There are three 16-bit dual supply transceivers at the lower edge of the board. The leftmost two are collectively the 'Address/Signals Bus' transceivers, and the rightmost transceiver is the 'Data Bus' transceiver.
The dual supply transceivers perform the function of translating between the Game Raccoon's internal 3.3V signalling and the 5V signalling expected by the Mega Drive. No 5V signal from the Mega Drive is connected to any other component on the board in any way, with the exception of a pull-up on D0 described below. (I've been told that the Mega Drive
is compatible with a 3.3V high logic level - the 68000 processor datasheet claims a VIH minumum of 2.0V - and several (unofficial) Mega Drive devices communicate in this way, but I didn't want to chance it. I didn't have any information about the custom chips on the motherboard, and their capacitances, etc.) The dual supply transceivers use both the 5V and internal 3.3V supplies.
The dual supply transceivers are also used to control the directionality and tri-statedness of the communicaton between the Game Raccoon PCB and the Mega Drive's buses.
The directionality of the Address/Signals Bus transceivers are set to 5V -> 3.3V. The Game Raccoon never attempts to put a value onto the Mega Drive's address or signals buses. The MCU signal !68000
(pulled low) is used to indicate that the Game Raccoon should be entirely isolated from the Mega Drive's buses. When the !68000
signal is high, the Address/Signals Bus transceivers isolate the address and signals buses from those of the Mega Drive. This allows the PIC to use the internal address and signals buses to communicate with the Flash for reading or writing. When !68000
is set low, the Game Raccoon attempts to implement the behaviour of a standard 4 megabyte mask ROM: it will only drive the data bus when a valid read operation is directed at the cart's address space (respecting the remapping that takes place if a Mega CD is installed). In addition, the 16-bit register can also be read and is mapped into the !TIME
Isolation should only be engaged when the Mega Drive should be currently executing from code in Mega Drive RAM since the contents of the Flash ROM will be inaccessible. To allow the Mega Drive to determine whether isolation is currently active or not, a pull-up resistor is attached to the D0 signal on the Mega Drive-facing data bus causing the least significant bit of any word in cartridge address space to be read as a 1 when isolation is in effect. In the Mega Drive ROM header, the least significant bit of a longword or word value is known to be 0 at many fixed locations in a valid game ROM image: specifically, anywhere in the Mega Drive header where a word-aligned address value is stored, such as the stack pointer initial value stored in longword $00
and the cartridge entry point address stored in longword $04
. With a valid Mega Drive ROM installed in a Flash partition, longword $00
(or word $02
) will have D0 == 0 when the cartridge is connected and D0 == 1 when the cartridge is isolated.
The directionality and enable of the Data Bus transceiver are determined by the logic section using the (post-transceiver) signals from the Mega Drive. The transceiver is only enabled if isolation is not in effect and a valid action is directed at address spaces handled by the Game Raccoon. The Game Raccoon responds to three actions: a ROM read action, a !TIME
write action and a !TIME
A valid ROM read action occurs when the Mega Drive is reading data or instructions from the currently selected Flash partition as if it were an ordinary cartridge game. It is determined by FLASH!EXTERNALOE = CART!C_CE + CART!C_OE
. When this occurs, the Data Bus directionality is set to 3.3V -> 5V and is enabled. This places the 16-bit data value output by the Flash IC onto the EDGE
data output bus to be read by the Mega Drive.
The 16-bit register is used to allow two-way communication from the Mega Drive to the Game Raccoon board. The register is written to when a write to the !TIME
address space is performed by the 68000 processor in the Mega Drive. Both the PIC and 68000 processor can read and write the contents of the register.
A valid !TIME
write occurs when the Game Raccoon boot firmware running from the Mega Drive's RAM communicates with the Game Raccoon board. It is determined by REGISTEREXTERNALCLK = CART!TIME + CART!LDS
. When the write finishes (the strobe ends and the register stores the value), the PIC detects the change in the D-type register's clock signal, allowing the PIC to awaken and isolate the Game Raccoon from the bus, making the bus available for the PIC to read the value. This exchange is necessary since the PIC would almost certainly not be able to react in time to read the value from the data bus itself when the 68000 performs the write: the register allows the written value to be replayed and read back slower by the PIC. All external !TIME
write actions cause the Game Raccoon to isolate itself from the bus (since this is necessary to allow the register to be read using the internal data bus). The 68000-side menu firmware polls the cartridge to detect the end of isolation.
PIC microcontroller and SD card:
The PIC24FJ64GA006 microcontroller provides all the 'intelligence' of the Game Raccoon cartridge. The PIC responds to commands from the Mega Drive, and can isolate the Game Raccoon from the Mega Drive to allow it to read ROM images from the SD card and write them to the Flash. It also reads the full directory structure of the SD card and writes this to the directory cache in the BOOT
The PIC firmware provides the functional brains of the Game Raccoon. It is written in C and compiled using xc16 in Microchip MPLAB.
The SD card socket provides storage of game or firmware images to be installed onto the Game Raccoon's Flash partitions. The PIC communicates with the SD card using SPI channel 2. The part number is WURTH 693063020911 (it took some searching to find this!) and is wired as shown. The 10R resistor is to prevent large inrush currents (as I was told, at least) during power-on (or if you're gutsy enough to remove the SD card while power is on?!?).
I used FatFs - Generic FAT Filesystem Module R0.14
with the PIC24 SPI reference driver to communicate with the SD card. It's necessary to modify several constants and functions in FatFs to get it to work with the Game Raccoon board - specifically, it needs to be set to SPI2, have the card insertion detection and write protection detection functions forced, and the correct internal tick timer interrupt supplied. Surprisingly, it all seemed to work first time! (There is a lot about this in Adventure 0.
As the Mega Drive system supports a 4 megabyte address space for game cartridges, an 8 megabyte Flash IC is used to store a 4 megabyte BOOT
partition which is bankswitched in on boot containing the menu firmware, and a 4 megabyte GAME
partition into which the game images are written. The Flash IC provides 8 megabytes of non-volatile storage with a 16-bit wide data bus, and is conceptually divided two 4 megabyte halves, controlled by the highest address line A21. (There are 22 address lines A0-A21 on the Flash, providing 4 megawords of storage.) The partitions are simply flat 4 megabyte regions of the Flash memory, not filesystems.
At any time, either the lower BOOT
or upper GAME
partition is active: the A21 line of the Flash is referred to as !BOOT/GAME
, and it acts as a flag enabling one partition or the other. This signal is pulled down by a resistor, which means that when the Mega Drive is powered on, the BOOT
partition is immediately activated, and remains this way until the PIC changes its FLASH!GAME/BOOT
signal from input to output to override this value.
The Flash firmware provides the user-facing interactive part of the Game Raccoon. It is written in 68000 assembly language and assembled using Bruce Tomlin's asmx and a Python makefile-like system. This firmware provides the menu system allowing the user to select a game to install, and boot the currently installed game. When the Mega Drive is turned on, the Game Raccoon's signalling acts as a 4 megabyte ROM cartridge providing the contents of the BOOT
partition at the $000000
address range, allowing the Mega Drive to boot into the Game Raccoon's Flash-resident firmware. (Since !C_CE
is used to chip select the Flash, this range should automatically migrate to $400000
if a Mega CD is installed, but I haven't tested this.)
All devices on the board are powered by a LM1117 3.3V linear voltage regulator, converting the 5V power supplied by the Mega Drive into 3.3V used by all the components on the Game Raccoon PCB, as well as the SD card socket. Internally, the Game Raccoon uses 3.3V signalling (LVC logic family) between all its components. Adjacent to the voltage regulator are two pads connected to the 5V and Ground nets. These allow an auxiliary 5V power supply (such as a USB-compatible wall wart) to be connected to the Game Raccoon, allowing it to be externally fully powered when not installed within a Mega Drive during programming or debugging.
At the top of the Game Raccoon PCB are pads to mount a five pin 0.1 inch header. These pins correspond with pins 1-5 of a PICKIT 2 programmer/debugger: !MCLR
. Pin 1 is closest to the SD card socket and is marked on the silkscreen. To program or debug the Game Raccoon's PIC, connect a PICKIT 2 to these pins using DuPont jump leads. And in turn, program the BOOT
partition of the Flash by uploading a debug firmware that does nothing but immediately isolate the bus and write the contents of some binary file on the SD card to the BOOT
partition. When you do this, don't forget to reupload the normal reactive Game Raccoon PIC firmware when you're done. :D I wouldn't recommend using the PICKIT 2 when external 5V power is not supplied - this would entail operating the dual supply transceivers with only a 3.3V supply connected.
Two surface mounted indicator LEDs are controlled by the Game Raccoon PIC firmware to provide generic signalling back to the user/programmer. Various blink sequences can be defined to communicate the current condition when the Game Raccoon is used in a Mega Drive and therefore it wouldn't be safe to have the debugger also connected. The values of the series resistors are chosen to reduce the active current to approximately 5mA per LED during operation (using the forward voltage/current graphs in the LED datasheets). As it happens, the mega bright blue LED consumes 2mA, while the somewhat dull green LED consumes 7mA (tested by grounding the MCU-facing side of the resistor through an ammeter).