Could anything with a Z80 processor run Gameboy games?
Asked Answered
S

1

7

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.

Storer answered 24/8, 2018 at 17:8 Comment(3)
This question is probably better suited for RetrocomputingSimply
I'd expect that the hard part is the I/O devices, like graphics and sound hardware. And available timer chips and so on. These would be totally different on a TI84 vs. a Gameboy.Harass
I'm not too familiar with the LR35902 instruction set, but when I did read up on it, there were some instructions that are not available on the Z80. As a consequence, emulation is non-trivial. That said, there exists a pretty good emulator for the TI-84+ series (as well as the color models). Check ticalc.org, omnimaga.org, and cemetech.netFutrell
P
12

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.

Periphrastic answered 25/8, 2018 at 18:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.