Skip to content

Add gameboy (SM83) ruledefs, platform, and example #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MineRobber9000
Copy link
Contributor

What it says on the tin. The GameBoy's SM83 CPU is kinda like a Z80... if you vaguely described a Z80 to someone over a bad phone line. A lot of things that work on a Z80 do not work on a SM83, but there are some shared features; however, I just took the SM83 opcode table, found the patterns in instruction encoding, and translated them into ruledefs.

The constants in platform/gameboy/constants.asm come from hardware.inc, a well-worn definitions file that pretty much every GameBoy homebrew project uses (though it has been known under other names too) for register locations, bit flags, and other magic values that you need in order to write a GameBoy game.

The cart_rom.asm file doesn't actually output a header; this is because unlike the NES' iNES header, the GameBoy header actually includes data that someone making a ROM might want to control (things like GBC or SGB compatibility, game title (which some emulators display), revision number, etc.). Instead, it defines the ROM bank, puts you in it, and gets out of your way.

The common_banks.asm file sets up banks for things that don't change no matter what MBC you use; this is VRAM, SRAM, WRAM, HRAM, and OAM.

Finally, the example ROM is a simple Hello World. Unfortunately, customasm isn't powerful enough to generate the right header checksum, but fortunately, most emulators don't care (and tooling does exist to fix that if you feel like fixing that is necessary). It uses ibmpc1.bin, a binary representation of the classic IBM PC font, as its font of choice.

NOTE: I'm currently (5/19/2025) on a loaner laptop due to hardware issues, so I can't actually test if this builds correctly within the repo, but my local working copy of the ASM built, and the only thing I changed was paths (<std> rather than using .. to get back to top level).

What it says on the tin. The GameBoy's SM83 CPU is kinda like a Z80...
if you vaguely described a Z80 to someone over a bad phone line. A lot
of things that work on a Z80 do not work on a SM83, but there are some
shared features; however, I just took the SM83 opcode table, found the
patterns in instruction encoding, and translated them into ruledefs.

The constants in platform/gameboy/constants.asm come from hardware.inc,
a well-worn definitions file that pretty much every GameBoy homebrew
project uses (though it has been known under other names too) for
register locations, bit flags, and other magic values that you need in
order to write a GameBoy game.

The cart_rom.asm file doesn't actually output a header; this is because
unlike the NES' iNES header, the GameBoy header actually includes data
that someone making a ROM might want to control (things like GBC or SGB
compatibility, game title (which some emulators display), revision
number, etc.). Instead, it defines the ROM bank, puts you in it, and
gets out of your way.

The common_banks.asm file sets up banks for things that don't change
no matter what MBC you use; this is VRAM, SRAM, WRAM, HRAM, and OAM.

Finally, the example ROM is a simple Hello World. Unfortunately,
customasm isn't powerful enough to generate the right header checksum,
but fortunately, most emulators don't care (and tooling does exist to
fix that if you feel like fixing that is necessary). It uses
ibmpc1.bin, a binary representation of the classic IBM PC font, as its
font of choice.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant