This page is a mirror of Tepples' nesdev forum mirror (URL TBD).
Last updated on Oct-18-2019 Download

Writing the interpreter -- zero page problems

Writing the interpreter -- zero page problems
by on (#39191)
Hey guys i'm writing a basic intepreter for my NES emulator and I was wondering how to handle addresses that are referenced in the zero-page. Basically, my intepreter looks for the opcode followed by the two bytes after it, but what happens if there is only one byte after it (zero-page?) How do I detect this? My interpreter would be getting confused since it only looks in 3 byte pairs (opcode, byte, byte) as opposed to zero-page crap (opcode, byte).

by on (#39197)
Well, you better find a way to handle that crap, because there are more instructions that use 2 bytes, or even 1. All branches are 2 bytes (opcode, relative displacement), and instructions like SEC and RTS which use "implied addressing" are only 1 byte.

You should probably be reading only the opcode, and then, based on it, deciding how many bytes to read next (2, 1 or none).