I'm working on implementing the instructions of the z80 chip inside a gameboy for an emulator. I'm starting with the instructions in the boot rom that sets everything up.
I've implemented the first 3 instructions but the 4th one is throwing me for a loop with it's assembly notation and what I'm seeing in the opcode decoding chart I'm referencing.
The instruction, according to that wiki's disassembled code, is:
LD (HL-), A
If it were LD HL, A
then I'd know that means "load register A's value in HL" (I know it's not valid because A is a byte while HL is 2 bytes, but I'm mostly talking about the notation). If it were LD (HL), A
then, if I'm correct, that would mean "load register A's value into the memory address at the location stored in HL." I'm have no idea what the -
of (HL-)
means.
With that confusion, I decided to try working backwards. Location $0007 in the boot rom contains the single byte of 0x32
that is the instruction. 0x32 = 0b00110010
breaks down to x = 00, y = 110 (p = 11, q = 0), and z = 010 with no prefix, which the opcode chart indicates means LD (nn), A
which doesn't contain HL
at all and from the looks of it, there's not 2 immediate bytes after the instruction in the boot rom. This seems odd because I feel I can decode using this site pretty accurately. Is the site wrong?
I'm wrong about something somewhere but I'm not sure what. How do I reconcile these two observations and what's the right way to move forward?
EDIT: According to this site, LD (HL-), A
means "load A into the memory address that HL points to, then decrement HL" which makes sense with what the wiki describes this program does. A
was just cleared in the previous XOR A
instruction and then it'll iterate through VRAM setting all of it to the value of zero. Now my concern is that I'm reading the instruction decoding site incorrectly as I don't see anything about decrementing a register after use.