assemblyz80gameboy

I can't read the LY register of the gameboy


Recently I started learning how can I create games for gameboy in z80 asm, I know that there is a register in the memory ($ff44) the LY register, I tried to read that register using the instruction "ld a, ($ff44)" in hexadecimal "3a 44 ff" but when I run the game in the gameboy emulator it close the game.

If I use the intructions: "ld hl, $ff44 ld a, (hl)", I think that it works, but why it doesn't work when I use the other instruction?

(I'm sorry, I don't speak english, so this text may be bad wrote.)


Solution

  • The GameBoy processors is not a z80. It's also not an Intel 8080. It has strong similarities with both of those, of course.

    The 3A opcode does not mean ld a, (nn) on the GameBoy z80-like processor, it means ld a, (hl-) also denoted ldd a, (hl), however you write it it's an instruction that uses the address from hl and then decrements hl, it doesn't take two extra code bytes as address. The 44 and FF would be seen as extra instructions, with the FF meaning rst 7. ld a, (nn) can be directly encoded but with a different opcode, namely FA.

    The GameBoy processor has something else (which the z80 doesn't have) that you may be able to use: ld a, (0xFF00 + n) encoded as F0 n. It would save space and time compared to the plain ld a, (nn).

    Sources: