Log in

View Full Version : Gameboy ROM architecture



Dead Zed
October 29th, 2004, 12:54
Hey!
Long-time lurker, first-time poster. Hehe.. I was wondering if anyone knows of the structure of the Gameboy ROM (*.gb) files. I already know the opcodes take up 1 byte but what if it needs a parameter? Would that be the closest following byte?
I hope my question was clear, if not just ask!

NOTE: I didn't know really where to post this (Nintendo forum, or the Web & Technology forum), so I apologize if it's totally out of place

Cheers!
/Dead Zed

Denopqrihg
October 31st, 2004, 13:15
Try the Pan docs www.work.de/nocash/pandocs.txt (http://www.work.de/nocash/pandocs.txt). it's an overview of the whole gameboy (I have a html version, but I couldn't find it on the net now).

For more detailed specification of the opcodes, search Google (http://www.google.com) for "gbcpuman.pdf"

These two documents are what I used when I tried to write my own gb emulator :D

Jet Set Willy
October 31st, 2004, 13:39
A Gameboy ROM doesn't have an architecture. It's just a header followed by program instructions and data.

Dead Zed
October 31st, 2004, 16:30
What I meant was the 'form' of the opcodes.I knew the opcodes took 1 byte(00-FF) but what if they needed a parameter(Such as instruction 3E, LD A,parameter) If that was the closest following byte after the opcode. Anyway, I found a GB disassembler and verified my suspicions that way. Thanks anyway!

Denopqrihg: Now thats a comprehensive document!Thanks! :)

Edit:Also, while I'm on the subjet: What is the point of opcodes 7F,6D,64,5B,52,49 and 40? They are all 'LD' instructions but the parameters makes no sense! They all load from A to A or B to B and so forth. Allegedly, no flags are set either, or am I missing something?

Denopqrihg
November 2nd, 2004, 18:38
Perhaps they can be used as NOPs?

Jet Set Willy
November 2nd, 2004, 20:07
They do have a use - all of those operations will still affect the flags.

Jet Set Willy
November 2nd, 2004, 20:58
Originally posted by Dead Zed@Oct 29 2004, 11:54 AM
Hey!
Long-time lurker, first-time poster. Hehe.. I was wondering if anyone knows of the structure of the Gameboy ROM (*.gb) files. I already know the opcodes take up 1 byte but what if it needs a parameter? Would that be the closest following byte?
I hope my question was clear, if not just ask!

NOTE: I didn't know really where to post this (Nintendo forum, or the Web & Technology forum), so I apologize if it's totally out of place

Cheers!
/Dead Zed
When I wrote my VERY minimal GB emulator (never released, it was just a personal experiment) I used a pre-made Z80 core to get everything working, and then replaced it with my own later on. It's a good way to get quick results, and make sure that all emulated hardware is working before you get stuck in with the CPU stuff. Also, when you are programming your own core, you get visual and audible results when there's a bug in your CPU code.

Dead Zed
November 4th, 2004, 20:17
I see.. I guess the Z-flag would be set if the contents of a register was zero when one of those instructions were executed..*Point noted*

I haven't yet gotten to actually programming the thing. I am still gathering data about it, but thanks for the tip!

Jet Set Willy
November 4th, 2004, 23:43
Well, have fun with it :-)

And please post your results, even halfway points. And if you get stuck, come post here. I'd love to help, or even experience frustration with the same problem.

Another handy tip: if the CPU documentation puzzles you, try using NO$GB in step mode. You can then view the instructions being run, and see exactly how they affect RAM and registers.

Denopqrihg
November 5th, 2004, 15:08
I don't think mov affects the flags.

GBCPUMan and the Pandocs don't say anything about that, and mov on a normal computer doesn't affect flags either.

Anyway, in which language are you writing the emulator?

Dead Zed
November 5th, 2004, 20:08
The Z-flag is always set if the result of an instruction is zero, so if A=0 then 'LD A,A' would technically result in a zero. Meh, I'll look deeper into it.

I'll most likely be writing the whole thing in Java, as I am more proficient in that than other languages which might be more suitable.

Jet Set Willy
November 5th, 2004, 21:40
Originally posted by Denopqrihg@Nov 5 2004, 02:08 PM
I don't think mov affects the flags.

GBCPUMan and the Pandocs don't say anything about that, and mov on a normal computer doesn't affect flags either.

Anyway, in which language are you writing the emulator?
Okay, they're there to fill out the architecture and create fill some sort of logical gap. Redundant instrutcions with appropriate effect on flags will still set them, even if it isn't so with LD etc. All that's important is that they're implemented properly.