Gameboy Emulation System

Goal: Create a device smaller than the original gameboy with the ability to emulate multiple games stored as ROMs on a microSD card. I figure a (fairly complicated) Arduino setup could do the job as the specs of the original gameboy are as follows:

Processor Speed: 4.19MHz RAM: 8kB + 8kB VRAM = 16 kB total ROM: Up to 8mb (stored on game cartridge, or in my case, a microSD card) LCD Resolution: 160 x 144 Pixels

According to Wikipedia.

I know for emulation you usually need much higher specs than the original device, so I'd guess I would need a chip with at least 2x if not 4x or 5x the clock speed of the original, and some RAM overhead, as my emulation software would not be 100% efficient. At DigiKey, they have 16MHz and 20MHz Microcontrollers such as this one that has 16Kx8 (128K) RAM and 128KB program memory.

I've also found four open-source gameboy emulators written in C, which (if I am not mistaken) is possible to port to a microcontroller-friendly format: dmgemu gbemulator RealBoy zBoy

So, is this even possible?

EDIT: Considering that the original gameboy's processor used multiple chips in order to outsource some of the work (graphics, audio, etc.), would it be possible to spread the workload out similarly in my setup with multiple connected microcontrollers?

You might want to look into the Raspberry Pi. Even though the Arduino runs faster than an old Gameboy, the Gameboy had many other chips that assisted in its ability to play games. There were different audio and graphics processors involved. Its probably feasible if you're a hardware engineer and your budget is a few million dollars.

although it says 64K x 16, which should make 1024K

1 Mbit == 128kbytes.

wizdum: You might want to look into the Raspberry Pi. Even though the Arduino runs faster than an old Gameboy, the Gameboy had many other chips that assisted in its ability to play games. There were different audio and graphics processors involved. Its probably feasible if you're a hardware engineer and your budget is a few million dollars.

Thanks for the tip. I'd use Raspberry Pi (probably wouldn't have to write much or any of the emulator that way) but if you've seen one that's been done before, they tend to take up the same amount of space as the original gameboy (while my intent was to make it smaller) even though they do have much more power and versatility.

As you said, the original gameboy did have other chips, such as dedicated graphics and audio chips... would it be possible to do something similar in Arduino using multiple connected microcontrollers?

AWOL: 1 Mbit == 128kbytes.

Ah, I knew I was forgetting something. Thanks.

If I used multiple microcontrollers hooked together, what kind of interface could be used to connect the multiple microcontrollers? It would have to be fairly fast and able to keep synced with everything else. SPI? I2C?

I cleaned up the OP so it is more understandable now.

Anyone know what kind of connection to use between the chips? Although this is a long-term project (read: I don’t plan on actually doing it anytime soon), I’m trying to get a pretty good picture of if it will work and how so I don’t start and find it’s too difficult/impossible part way through.

Nelsyv: Anyone know what kind of connection to use between the chips? Although this is a long-term project (read: I don't plan on actually doing it anytime soon), I'm trying to get a pretty good picture of if it will work and how so I don't start and find it's too difficult/impossible part way through.

To answer your question, SPI will be what you want to use (IIRC, this is what SD cards use).

That said - forget about trying to do emulation; for one thing, it is likely to be impossible with the Harvard architecture used in the ATMega328.

Instead - you might want to attempt to focus on a custom handheld console instead, using multiple 328s, or something similar.

For instance, there does exist a bootloader that can load a binary from an SD card; so put your binary on that, along with data. Use the SD card libraries to read/write to the card. Different cards for different games.

Use an ATMega644 (Sanguino) for the "main CPU"; or use the 1284 - both are available in DIP packages, and feature larger amounts of flash and SRAM (and more pins). Have it be the SPI "master". Use 328s (SPI slaves) for LCD control, sound playback, and dpad input. Or - use dual 644s or 1284s (one for main game, the other for "everything else").

Emulation isn't easy (hard to do right and requires a surprising amount of processing power). I doubt you'll get an emulator running. Here's an interesting article about why emulation (esp. accurate emulation) is hard: http://arstechnica.com/gaming/2011/08/accuracy-takes-power-one-mans-3ghz-quest-to-build-a-perfect-snes-emulator/

cr0sh:

Nelsyv: Anyone know what kind of connection to use between the chips? Although this is a long-term project (read: I don't plan on actually doing it anytime soon), I'm trying to get a pretty good picture of if it will work and how so I don't start and find it's too difficult/impossible part way through.

To answer your question, SPI will be what you want to use (IIRC, this is what SD cards use).

That said - forget about trying to do emulation; for one thing, it is likely to be impossible with the Harvard architecture used in the ATMega328.

Instead - you might want to attempt to focus on a custom handheld console instead, using multiple 328s, or something similar.

For instance, there does exist a bootloader that can load a binary from an SD card; so put your binary on that, along with data. Use the SD card libraries to read/write to the card. Different cards for different games.

Use an ATMega644 (Sanguino) for the "main CPU"; or use the 1284 - both are available in DIP packages, and feature larger amounts of flash and SRAM (and more pins). Have it be the SPI "master". Use 328s (SPI slaves) for LCD control, sound playback, and dpad input. Or - use dual 644s or 1284s (one for main game, the other for "everything else").

Thanks for the info! This will definitely come in handy. However, you said that you can run a binary from an SD card, so couldn't one write their emulation code as a binary and then store on an SD card? I realize that such a thing would take a ton of work, but it would be possible, yes?

raacampbell: Emulation isn't easy (hard to do right and requires a surprising amount of processing power). I doubt you'll get an emulator running. Here's an interesting article about why emulation (esp. accurate emulation) is hard: http://arstechnica.com/gaming/2011/08/accuracy-takes-power-one-mans-3ghz-quest-to-build-a-perfect-snes-emulator/

Thanks for the article! It was a very interesting read. As you said, emulation does require a fair amount of processing power, certainly a lot more than the original hardware.

Thanks to both of you for your constructive and insightful criticism. :)

Here's a github repo with an NES emulator that runs on a $15 board that is Arduino compatible (mostly, its still a work in progress as the chip is relatively young). I know it isn't a gameboy, but its something if you are interested.

https://github.com/espressif/esp32-nesemu

You will need the following development board with the ESP32 processor: https://www.adafruit.com/products/3269

And then a screen something like this: https://www.adafruit.com/products/1947

And any ps1/2 remote to control the emulator, or you can write your own code to make a ps1/2 controller for an arduino chip. I have built a controller from scratch and hooked it up to the above two products with the above github code flashed to the device and it works pretty great! Frame rate isn't perfect on the graphics display, but tbh, its a standard 4 wire spi trying to run a screen at ~30 fps, that's asking a lot!

As mentioned above, emulation on a typical Arduino device will be hard, most of their hardware is rather old/weak. The ESP32 packs a serious, dual core punch with a dual wifi+bluetooth radio and all the software to back it up (not to mention ram+flash). With some of the newer microcontroller architectures/chips, emulation of older hardware isn't that difficult assuming you have the time to invest. The display is always interesting because none of these little chips are meant to output HD graphics or anything crazy like that (although there are exceptions to this) so don't expect to have flawless graphics out of the box on a micro without a peripheral geared towards graphics.

Feel free to PM me if you have any other questions. Emulation is really cool and if its something you enjoy I suggest you go for it! Good luck!

I was going to say, but I think someone has already mentioned it, there espressif chips would sort out a lot of problems because they are arduino compatible, and faster and more powerful than most (if not all arduino boards). The esp12e (esp8266) would be possible with support from other chips like a chip dedicated to control the buttons though a mux or an i2c bus, but your best bet would be the esp32. If a NES emulator could be ported onto it, I think a gbc emulator could be possible too.

Have you been able to get anywhere with this project? I'm really interested to seeing how this goes.

how do you control the games i don’t see any button commands