cpu-gbz80

Provides Game Boy LR35902 assembly reference with Zilog mnemonics, opcode encodings, and z88dk coding rules.

1.1k|206|Updated Mar 16, 2016
One-click install
npx skills add https://github.com/z88dk/z88dk --skill cpu-gbz80-z88dk
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cpu-gbz80
Source: https://github.com/z88dk/z88dk/tree/main/.agents/skills/cpu-gbz80
Command: npx skills add https://github.com/z88dk/z88dk --skill cpu-gbz80-z88dk

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Writing or reviewing Game Boy (gbz80/LR35902) assembly for z88dk is error-prone because the CPU differs from the Z80 in encodings, flags, and available instructions, and documentation mixes Nintendo and Zilog mnemonics. This Skill supplies the authoritative opcode map, flag behavior, and house coding conventions so generated assembly assembles correctly with z80asm -mgbz80. ## Core Features & Use Cases - Full opcode reference: Complete gbz80 opcode grid with Zilog mnemonics, byte encodings, cycle timings, and ZNHC flag effects, plus the 11 illegal opcode holes. - Nintendo-to-Zilog translation: Mapping tables convert Pastraiser/GBDK-style mnemonics (LDH, LDI, LDHL) into the Zilog forms z88dk requires. - Synthetic instruction guidance: Documents z80asm synthetics (djnz, pair copies, ex de,hl) and helper calls with their real cycle costs, so hot library code avoids slow expansions. - Use Case: When writing a 32-bit arithmetic routine under libsrc/l/sccz80/8-gbz80/, use this Skill to choose ld hl,sp+* for stack access, preserve carry across it, and avoid nonexistent Z80 ops like ex de,hl. ## Quick Start Ask the AI to write or review a gbz80 assembly routine for the z88dk +gb target using Zilog mnemonics and correct Game Boy flag semantics.

Frequently Asked Questions about cpu-gbz80

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Game Boy assembly for z88dk?

Write Zilog mnemonics and assemble with z80asm using -mgbz80, targeting +gb. Use GB-only native ops like ld hl,sp+*, add sp,*, ld a,(hl+), and ldh for HRAM access, and avoid Z80-only instructions such as ex de,hl, djnz, and in/out.

What is the difference between gbz80 and Z80 instruction sets?

The gbz80 lacks IX/IY, exx, ex de,hl, djnz, in/out, and block instructions, and has no sign or parity flags. It adds GB-only ops like ldh, swap, stop, reti, (hl+)/(hl-) loads, and ld hl,sp+*, with different encodings at many shared byte values.

How do I convert Nintendo mnemonics to Zilog assembly?

Map Nintendo forms to Zilog equivalents: LDH (a8),A becomes ldh (*),a, LDI A,(HL) becomes ld a,(hl+), and LDHL SP,r8 becomes ld hl,sp+*. z80asm accepts the Nintendo aliases but house style requires the Zilog spelling in new sources.

Does the Game Boy CPU have a djnz instruction?

No, byte 0x10 is the stop instruction on gbz80, not djnz. z80asm accepts djnz as a synthetic that expands to dec b followed by jr nz in normal mode, but strict mode rejects it.

Why does my carry flag get lost after ld hl,sp+n on Game Boy?

ld hl,sp+* and add sp,* force Z to 0 and rewrite H and C flags (00HC pattern). Save the carry first with rra before the stack operation and restore it with rla afterward, as done in l_long_div_0.asm.

When should I avoid z80asm synthetic instructions on gbz80?

Avoid synthetics in hot hand-written library code when they expand to slow sequences: ex de,hl costs 56 cycles as a stack swap and ex (sp),hl calls a 148-cycle helper. Prefer pair copies like ld bc,hl and native post-increment loads instead.