izik1 / gbops

The most accurate Game Boy opcode table
https://izik1.github.io/gbops/
MIT License
46 stars 3 forks source link

`stop` is 1 byte instruction, not 2 #3

Closed binji closed 2 years ago

izik1 commented 5 years ago

I can't remember if it's supposed to be 2, mostly because I don't think anything uses it. EDIT: supplementary information: I remember seeing somewhere that the 'official' opcode is 0x10 0x00, but once again nothing uses it, so I can't seem to verify it.

jverkoey commented 3 years ago

FWIW, RGBDS appears to always encode STOP as a two byte instruction:

https://github.com/gbdev/rgbds/blob/77279984a53054436450ea251343515bfdbf25b1/src/asm/parser.y#L1865-L1868

z80_stop    : T_Z80_STOP {
            out_AbsByte(0x10);
            out_AbsByte(0x00);
        }
wordandahalf commented 3 years ago

According to the official Gameboy Programming Manual from Nintendo (https://ia803208.us.archive.org/9/items/GameBoyProgManVer1.1/GameBoyProgManVer1.1.pdf, page 124), STOP is encoded as 0x10 followed by 0x00.

izik1 commented 2 years ago

I was about to close this as "unless anyone has evidence to the contrary", but then I remembered something (also helped that I looked at other documentation, including my own emulators). Like HALT has the halt bug (a failure to increment PC for one instruction(? cycle?) after not halting, STOP has its own bug, which is poetically the inverse, it skips a byte, which means that it is technically one byte, errata are weird.

izik1 commented 2 years ago

(fixed)

Lokathor commented 2 years ago

I was told recently that STOP, despite being 1 byte itself, will cause the very next byte to be executed or not depending on various factors. So, while it's true that STOP is 1 byte, it should always be followed by the 0x00, in case the second byte ends up being executed.

image