Gameboy Emulator

Screen Shot 2012-08-13 at 22.41.30 1Recently I had the urge to play Pokemon Red, however my Gameboy is no longer working, a problem I have yet to diagnose, as replacing the RAM didn’t solve the problem.

So I decided without falling back on buying a new Gameboy, I’ll make one.

Having written an operating system in assembly before, and my playing around with microcontrollers, the concept is simple.

All I required was some informations on the clock timings, and when the vertical sync happens.

Screen Shot 2012-08-15 at 01.50.55

There is plenty of documentation on the GB, my favourite of which is the Gameboy CPU Manual since it had a breakdown of the opcodes and registers as well as memory addresses.

After setting up a large switch statement to handle the opcodes, I began by running Pokemon Red, which gave me the initial NINTENDO logo before getting stuck in a loop. After a bit of debugging, it turned out one of my opcodes was functioning wrong (I should have wrote a unit test for all of them).

Screen Shot 2012-08-16 at 20.31.34

Using GLUT I was able to read the part of memory where the LCD output gets drawn to and render it.

After some tweaking around with sprites, I finally got the Pokemon to show on the title image. I have yet to setup input so I cannot progress beyond this screen.

I’m starting to wonder if I can make an attachment to my iPhone for the cartridge to plug into so I can play it and other games.