(Note: by "object-compatible" I mean that the opcodes and their following operands are the same—the assembler produces the same output for equivalant assembler mnemonics. This of course excludes calling conventions, etc., because these are determined by the code one chooses to write.)
The Game Boy uses a Sharp LR35902 CPU (sometimes called a GB-Z80) that's usually said to be similar to an 8080. However, looking at some of the opcodes they don't seem compatible.
For example, on the 8080 and Z-80 opcode 3A
loads the contents of the memory address specified by the next two bytes into the A register: LDA nnnn
in 8080 assembler or LD A,(nnnn)
in Z-80 assembler. On the GBDevWiki opcode 3A
is listed as ldd A,(HL)
, loading into A the address pointed to by HL and then decrementing HL. (This indexed decrement addressing mode doesn't seem to exist at all on the 8080 or Z-80.) This seems confirmed by the WLA DX assembler opcode table, which lists it as LDD A,(HL)
(with alternatives LD A,(HL-)
and LD A,(HLD)
).
The direct load on the LR35902 seems to be opcode FA
(ld A,(nnnn)
), and 16 cycles instead of 13); FA
is a JMP
instruction on the 8080 and Z-80.
Am I looking at things terribly wrong somehow, or is the LR35902 actually a rather different CPU from the 8080/Z-80 that just happens to share the 8080 register set? And perhaps; Z-80 assembly syntax: the freely available assemblers use this though I don't know if the Nintendo dev kits did.
If this is the case, it seems that I should study the LR35902 instruction set carefully before writing code for it because some of the very useful changes (indirect with postdecrement) wouldn't occur to an 8080 or Z-80 programmer.