Gameboy upgrade

Here it comes. I planned this long time ago.
It took me few days to create good logic for this one, i had many ideas.
In my first idea i tried to use ATmega32, it was supposed to communicate with MMC/SD card, and read files from FAT file system.
That means, it will access file table to gameboy CPU, only to show it up on screen and accept commands to copy game to RAM.
This was not working. ATmega32 at 8MHz was not fast enough to simulate ROM. And as a "bonus", i will have to use tri-state outputs on address lines.
Note: In this idea i planned to keep gameboy cart reader with ability to run game from cart, or dump cart to MMC/SD.

To keep things easier, i dropped suport for external cart reader.
This idea (2nd) was still with ATmega32, but as i noted, it will need tri-state outputs, and also some way to communicate with gameboy CPU.

After some time thinking with logic and tri-state outputs, i had totally different idea, let gameboy CPU directly communicate with MMC/SD card.
But how can i connect MMC/SD card to gameboy CPU?
Well my first ideas,
1) external GPIO - too many external HW needed and it will be slow
2) gameboy link port - yes, it is SPI protocol, but it has wrong polarity settings
But wait, Gameboy does has something like GPIO, it has two outputs and four inputs ... yes, joypad!

After small testing i finally managed to detect insterted card type. After this, using joypad GPIO was my final solution.
This way, it won't be possible to use joypad while accessing card, but no problem, my software waits until all keys are released.
(also thanks to elm-chan.org, i found there good code for AVR to use MMC/SD over SPI)

Well, i had working MMC/SD access, i had some "logic blob", so i started with my own FAT32 parser.
I made simple file menu, with ability to open "infinite" directories and with ability to go back (thanks to '..' entry in FATFS).
But after i tired to copy game to RAM and run it, it just failed. My "logic blob" was not a good idea, MBC1 was not doing exactly what i expected.

After some time and many ideas, i created a good logic. Here are function tables.
MMC/SD !CE
EA0EA1!CE
100
001
X11

MBC/RAM !WR enable selection
!WR enableinputs
RAMMBCEA0EA1P14
01X0X
0111X
01010
10011
And i think remaining logic is obvious. (it is just redirecting RAM/EEPROM !CE based on EA1 state, and MBC/RAM !WR based on result from 2nd table)
This seems to be best option. It is simple to create and working very well. (you need only NAND, 7400 logic)
Of course game can't change EA0/EA1 state, but games can be always patched. Actually i already found 2 games that will need this patch.
Feel free to create app that will patch any game, it can't be hard at all.

Rest was only about software ("BIOS" stored on EEPROM).
I added simple .TXT reader, it will only show first 32 lines of file, with max. 32 characters per line.
Also, i added support for loading and saving dumps of save RAM, so you will not lost game progress (or you can HEX edit, heh).
Note, my FAT32 parser is limited, if you want to save your RAM dump, you will need to have 8kB .SAV file prepared on card.
How to use save game?
1) play your game
2) reset gameboy using reset button, do not turn off and on, that will erase save RAM
3) select your .SAV file (using A), press B and wait
4) now you can turn off your gameboy
5) turn on gameboy
6) select your .SAV file (using A), press A and wait
7) run your game
8) repeat from step 1

What is final result? Well not so bad i guess.
1) FAT32 file system support
2) it can load and run most MBC1 512kB games that uses 8kB save RAM
3) it can load/save DUMP of save RAM
4) it can show TXT files, limited

And might be "bad"?
1) only FAT32 suport, FAT16 or FAT12 is not supported
2) some games have to be patched to run (EA0/EA1 problem)
3) loading game is not too fast (with bigger games its really slow)
4) it removes cart reader, you will be able only to play games form MMC/SD
5) it consumes more power
6) i had to remove battery slot to get free space inside, but it is possible to fit all instead of cart (i had to program EEPROM many times)
7) card is connected to joypad 'B' and 'left', be careful when it access card

Oh, and of course schematics, all files ... and some photos.
Final notes:
1) EEPROM size is 16kB
2) "MKO" part is optional, it is just timer that allows to use custom startup logo, you will also need 32kB EEPROM if you want custom startup logo
3) 8kB RAM is also optional, if you don't need ability to save game