GameBoy Program Counter behaviour
Posted: Sun Jan 08, 2023 4:20 am
I am very new to low level and GameBoy programming and I have a question that I can not seem to find an answer to in any of the documentation about the GameBoy. The user ROM space is in the address range from $0000 to $7FFF and I am wondering what happens when the Program Counter is at position $7FFF and gets incremented to $8000 which marks the first byte of the character data. Or even what would happen if I try to execute a CALL/JP instruction to address $8000. There is various things that could happen at this point but I found no confirmation for a concrete answer:
A) The CPU tries to fetch whatever is at address $8000 and happily executes whatever it finds.
B) The GameBoy has some form of protection that sets the PC at this stage back to $0000.
C) The protection sets it back to $0100 to fetch and execute the JP instruction for the main entry point of the user program.
D) The system locks up (or worse gets damaged) because it is not allowed to fetch instructions from address $8000 or beyond.
E) There is a non-maskable interrupt that indicates a fetch/jump from/to an illegal address. This one is probably less likely since the GameBoy seems to only have maskable interrupts.
The Nintendo GameBoy Programming Manual has no real information on this. Even worse, the examples for the CALL and JP instructions in that manual show a jump to address $8000, which based on the memory layout should be a no no.
Has anyone here ever tried those scenarios on real hardware and knows what would happen? I only have emulators at hand at the moment and I don't really care what these would do. I would like to know how the real hardware would behave in this scenario and thought I'd ask before I have to buy a GameBoy and somehow try this for myself
A) The CPU tries to fetch whatever is at address $8000 and happily executes whatever it finds.
B) The GameBoy has some form of protection that sets the PC at this stage back to $0000.
C) The protection sets it back to $0100 to fetch and execute the JP instruction for the main entry point of the user program.
D) The system locks up (or worse gets damaged) because it is not allowed to fetch instructions from address $8000 or beyond.
E) There is a non-maskable interrupt that indicates a fetch/jump from/to an illegal address. This one is probably less likely since the GameBoy seems to only have maskable interrupts.
The Nintendo GameBoy Programming Manual has no real information on this. Even worse, the examples for the CALL and JP instructions in that manual show a jump to address $8000, which based on the memory layout should be a no no.
Has anyone here ever tried those scenarios on real hardware and knows what would happen? I only have emulators at hand at the moment and I don't really care what these would do. I would like to know how the real hardware would behave in this scenario and thought I'd ask before I have to buy a GameBoy and somehow try this for myself