I'm trying to write an emulator for the z80, and am wondering if there is any specific opcode layout (i.e. do all the ld
instructions have a specific bit set). I've looked here but if there's an indication of a pattern, I haven't found it yet.
Is there? If there is, please give me a few examples.
You are right, there's a pattern. This page:
http://www.z80.info/decoding.htm
explains the encoding of various Z80 instructions, both documented and undocumented ones.
The ld c, d
instruction, for example, is encoded as LD r[y], r[z]
with the x
field (the two most significant bits) of the op-code set to 1 and three-bit fields y
and z
(bits 3-5 and 0-2 respectively) set to 1 and 2.
To give you an example of how that can be implemented in an emulator, here's a link to my implementation of the decoder: z80.h.