10
votes

Hello I'm writing an emulator for Game Boy.

I use this reference : Gameboy CPU (LR35902) instruction set

This document states that opcodes :

0xE2 LD (C),A

and

0xF2 LD A,(C)

have a length of 2.

The Game Boy CPU Manual says that these instructions respectively :

Put value at address $FF00 + register C into A.

and

Put A into address $FF00 + register C.

I think it has length of 1 because the opcode is self sufficient, it doesn't need another value to be interpreted. If it has a length of 2, what's the purpose of the second byte ?

1
Why do you think that?Blorgbeard
The diagram states that the instructions are 8-bit. I don't see any reason to disbelieve.Malcolm McLean
Try this gameboy cpu reference .rcgldr
I may have badly understood the question, but I've never seen 0xE2 and 0xF2 use a second byte. Here's an example of 0xE2 in GBC: datacrystal.romhacking.net/wiki/…Méga Lag
Given the example given by @MégaLag and what pandocs says, I'll consider it a 1 byte instruction.Demeter Purjon

1 Answers

14
votes

You are absolutely right. LD (C),A and LD A,(C) are 1 byte long.

I have even emailed the responsible (Pastraiser) asking for clarification (or if he could fixed the website) but I got no answer.

Another thing that bothers me is the fact that prefix CB is considered to be 1 byte long and consume 4 cycles. And all the extended instructions are considered to be 2 bytes long and consume 8 cycles (16 if they access (HL)). It would make more sense to me to leave blank the space below Prefix CB so it is clear that all extended instructions already include the size and processing cycles of their prefix.

And the other thing that bothers me is the fact that STOP length is 2. It is actually just one byte long. There is a hardware bug on Gameboy Classic that causes the instruction following a STOP to be skipped. So Nintendo started to tell developers to add a NOP always after a STOP. So, to be 100% correct I would consider STOP to be (1,4) instead of (2,4). This issue does not exist on Gameboy Color.