The GBZ80 (Sharp SM83) is the CPU that powers the original Nintendo Gameboy and Gameboy Color handheld consoles. It is kind of an in-between the [[Intel 8080]] and [[Z80]]. [https://gbdev.io/resources.html Awesome Gameboy resources] [https://gbdev.gg8.se/wiki/ GBDev wiki] [https://emudev.de/ Emudev (q00.gb)]
The GBZ80 lacks the alternate register set, the dedicated I/O bus, the R register(thus no M1), the index registers (thus no DD and FD prefixed opcodes), the ED prefixed opcodes (including block transfer), the sign and parity/overflow flags (and all conditional instructions that used them), the undocumented flags (thus no leaking of WZ and Q internal registers). [https://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html GBZ80 opcodes]
The GBZ80 also lacks the NMI pin (thus no IFF2 and no RETN), the IM instructions and the I register. It has a different interrupt system than the Z80. [https://gbdev.io/pandocs/Interrupts.html Source]
* CALL nn takes 6 cycles on the GBZ80, but 5 NOPs on the Z80
* ADD HL,ss takes 2 cycles on the GBZ80, but 3 NOPs on the Z80
* JP cc,nn has different timings depending on whether the jump is taken. This is not the case on Z80.
Flags can differ too:
* DAA clears HF in the GBZ80, but not in the Z80
Fun fact: Way more GBZ80 cores were produced for Gameboy hardware (118 million Gameboys and 81 million GBA) than all the Z80 chips produced for home computers and game consoles. [https://www.chibiakumas.com/z80/Gameboy.php Learn GBZ80 Assembly Programming with ChibiAkumas]
<br>
== RegistersRegister File ==
{| class="wikitable" style="white-space: nowrap;"
| srl (hl) || CB 00111110 || 4 || cf := (hl).0, (hl) := (hl) >> 1
|-
| swap r || CB 00110rrr || 2 || rowspan=2|+ || rowspan=2|0 || rowspan=2|0 || rowspan=2|0 || r := ([[r and 0x0f] << 4) ] + ([r >> 4) ] ||rowspan=2|Swap nibbles
|-
| swap (hl) || CB 00110110 || 4 || (hl) := ([[(hl) and 0x0f] << 4) ] + ([(hl) >> 4)]
|}
== Opcodes ==
Opcode differences with Z80 are in bold. The unused ('''—''') opcodes will lock up the Game Boy CPU when used. The asssembler assembler syntax is from the official Nintendo [https://archive.org/details/GameBoyProgManVer1.1/ Gameboy programming manual].
=== Standard opcodes ===
* PUSH and POP instructions utilize a 16-bit operand and the high-order byte is always pushed first and popped last. PUSH HL is PUSH H then L. POP HL is POP L then H.
* ADD SP,e takes 4 cycles, while LDHL SP,e takes only 3 cycles.
<br>
== Weblinks ==
*[https://www.chibiakumas.com/z80/Gameboy.php Learn GBZ80 Assembly Programming with ChibiAkumas]
*[https://gbdev.io/resources.html Awesome Gameboy resources]
*[https://gbdev.gg8.se/wiki/ GBDev wiki]
*[https://emudev.de/ Emudev (q00.gb)]
*[https://gekkio.fi/files/gb-docs/gbctr.pdf Game Boy Complete Technical Reference]
*[https://github.com/SingleStepTests Tom Harte's SingleStepTests]
<br>