Search code examples
cconsoleemulationromgameboy

Fetching a game boy ROM image


i've started to develop a very simple emulator for game boy in C, i've already studied hoe work the cpu of the Z80 and the relative OpCodes but there is a question in my mind that i never found answer. When i open the ROM image using fopen(filename,"rb") how can get the instructions to emulate? I've tried to do: fp = fopen(filename,"rb"); fread(buf,sizeof(buf),1,fp);but i don't know how is structured the ROM of Game Boy.. someone can explain me how fetch the instruction from the ROM and their structure?


Solution

  • Cartridge ROM execution always starts at offset 0x100. When writing an emulator you have two ways to implement this:

    1. Execute real gameboy boot ROM, which will finish its execution by jumping to 0x100 in the cartridge ROM
    2. Fill all the registers with values yourself. After boot ROM is finished registers for CPU and various other devices are left with specific values. You can set them manually and start executing cartridge ROM from 0x100 yourself. That way you don't even need boot ROM. You can find the values in Gameboy CPU Manual.