Skip to content
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

Gameboy/Z80 architecture #188

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open

Gameboy/Z80 architecture #188

wants to merge 23 commits into from

Conversation

Prof9
Copy link
Contributor

@Prof9 Prof9 commented Sep 19, 2020

This adds the Z80 architecture and instruction set, as well as the Game Boy (Color) and Nintendo e-Reader instruction sets, which are based on Z80.

The following directives can be used:

  • .z80 - Full Z80 instruction set
  • .gb - Game Boy (Color) instruction set
  • .ereader - Nintendo e-Reader instruction set

The syntax is based on the official Z80 documentation and Pan Docs (for Game Boy), but I've also added some other aliases I've commonly seen. I also made some personal additions:

  • jp hl, jp ix, etc. are accepted as alternatives for jp (hl), jp (ix) etc. Reason: unlike what the official syntax implies, pc is set to the value of the register directly, and no memory access is done.
  • sub a,b, sub a,c etc. are accepted as alternatives for sub b, sub c etc. This also applies for and, xor, or and cp. Reason: add, adc and sbc all have the destination (a) as part of their operand list, so this allows for better consistency with those opcodes.
  • For e-Reader I added a rst 0,n and rst 8,n shorthand for calling the e-Reader API functions more easily, so you don't have to write a .db after every rst.

@Prof9 Prof9 changed the title Gameboy architecture (WIP) Gameboy/Z80 architecture (WIP) Sep 20, 2020
@Prof9 Prof9 marked this pull request as ready for review September 20, 2020 22:19
@Prof9 Prof9 changed the title Gameboy/Z80 architecture (WIP) Gameboy/Z80 architecture Sep 20, 2020
@Infrid
Copy link

Infrid commented May 15, 2021

I love this PR, I know the tool is armips and not armipz80, but still a remarkable patch, what do you think @Kingcom ?

@romh-acking
Copy link

I don't see an issue tab on the fork's page, so I guess I'll report it here. I've been using this fork for quite a while now, and I've gotten a good amount of use with it. However, it unfortunately doesn't seem to support all opcodes, which seems to mostly be indirect addressing related. For example, this line of Z80 code doesn't compile.

ld (0xC115),hl

So I have to substitute it with this.

.db 0x22
.dh 0xC115

It is a valid instruction, per here:
https://baltazarstudios.com/webshare/A-Z80/Z80-Opcode-Tables.pdf

@Prof9
Copy link
Contributor Author

Prof9 commented Mar 12, 2022

For example, this line of Z80 code doesn't compile.

The following compiles fine for me:

.z80
.create "output.bin",0

	ld (0xC115),hl

.close

Which outputs 22 15 C1 as you would expect.

This opcode is also included in the instruction set tests: https://github.com/Prof9/armips/blob/gameboy/Tests/Z80/Z80%20Opcodes/Z80%20Opcodes.asm#L39

Side note: I originally created this fork as I was planning to work on some Game Boy projects, but ended up not going through with that. So I haven't really used this fork much personally.

@romh-acking
Copy link

romh-acking commented Mar 12, 2022

Thanks so much for the timely reply! I was missing the .z80 tag. I had .gb originally. I overlooked the fact the GB has a limited instruction set.

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.

3 participants