as i'm getting familar with Z80 Opcodes and using BGB disassembler, i'd like to document the subs and loops found in the game-ROM. It would be a great help, if some experienced user may give me some advice on "how to do it right". I'm sure there are some best-practice rules to follow.
My goal is to compile the generated sourcecode to a new binary ROM file and get this executed. My starting point is address 0x0100, of course ;-)
As well as 0x0100, you should also trace from each of the interrupt vectors, especially VBLANK (0040) and LCDSTAT (0048). In most console games, the main execution loop essentially revolves around the VBLANK interrupt. Interrupts are one of the main differences between the custom GB CPU and a real Z80. The GB has the same software interrupt instructions as a Z80 (RST 0x38
, etc.) but hardware interrupts don't correspond to any of the three Z80 interrupt modes. On the GB each interrupt source has its own, fixed vector.
Remember that GB cartridges are bankswitched. When you see a JP or CALL to an address between 4000 and 7FFF, you have to figure out which ROM bank is switched in to determine where the jump actually goes. I'd start by disassembling the entire fixed bank (0000-3FFF) and looking for writes to ROM addresses (typically 0x2100 on the GB). On 8-bit consoles, figuring out how a particular game manages ROM bankswitching is a good first step to figuring out the overall structure of the program.
I'll just warn you ahead of time that converting a ROM of a commercial game to source code that can be reassembled into the original ROM is a very complex and time-consuming process.
By any chance do you know Python (the programming language)? I've been working on a multi-target disassembler written in Python for the last little while. It's designed to handle common console-game gotchas like bankswitching and inline subroutine arguments (subroutines that pop their own return address off the stack and manipulate it--very common on 8-bit consoles) It's not fully automated, it requires some Python programming to use, but I think it's much more efficient than trying to disassemble an entire game using bgb's built-in disassembler. If you're interested in trying it out, drop me a PM.