Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could anything with a Z80 processor run Gameboy games?

Since the Gameboy's processor, the LR35902, is a hybrid of the Z80 and the Intel 8080, keeping in mind that the Z80 and the Intel 8080 were designed to be mostly cross-compatible anyways, could anything that has a Z80 processor run opcodes that were meant for the LR35902? I was wondering not because I was hoping to use my TI84 to play Pokemon in study hall.

EDIT: I am aware that I would have to reprogram the controls, and probably the way that the game accesses RAM, but I'd rather just do that than port the whole game over.

like image 323
Rachel McMann Avatar asked Aug 24 '18 17:08

Rachel McMann


1 Answers

The Z-80 instruction set is a superset of the 8080 instruction set. The LR35902 shares much in common with the 8080 but replaces some 8080 instructions with different ones and extends the instruction set in some different directions than the Z-80. The LR35902 is not compatible with the Z-80 nor is it compatible with the 8080.

You would have to find all uses of incompatible instructions and replace them with patches that provide the same functionality. Since the TI84 is much faster than the original GameBoy CPU the extra time taken will not be a problem and it will be easy to code replacements for the instructions themselves. The disassembly of the ROM and separating code from data will be time consuming.

However, you could take an existing GameBoy emulator and instrument it to record the locations of instructions it executes that are different on the Z-80. Playing the game extensively should find most of the places where the code must be patched.

For a quick overview see this chart of LR35902 instructions and compare with the Z-80. You'll also need this description of LR35902 instructions.

Here's a brief rundown instruction opcode differences between the LR35902 and the Z-80.

Opcode  LR35902            Z-80
------  --------------     ----------
F2      LD   A,(C)         JP  P,nn
E2      LD   (C),A         JP  NV,nn
EA      LD   (nn),A        JP  V,nn
FA      LD   A,(nn)        JP  M,nn
3A      LDD  A,(HL)        LD  A,(nn)
32      LDD  (HL),A        LD  (nn),A
2A      LDI  A,(HL)        LD  HL,(nn)
22      LDI  (HL),A        LD  (nn),HL
08      LD   (nn),SP       EX  AF,AF'
E0      LDH  (n),A         RET NV
F0      LDH  A,(n)         RET P
F8      LD   HL,(SP+e)     RET M
E8      ADD  SP,e          RET V
CB 3x   SWAP r             SL1 r (undocumented)
10      STOP               DJNZ
D9      RETI               EXX

It is a small help that LD A,(nn) and LD (nn),A are available on both and simply use different opcodes.

like image 85
George Phillips Avatar answered Sep 18 '22 18:09

George Phillips