[−][src]Module dez80::instruction
Contains models and functions to define, decode, and format Z80 instructions and their components.
Examples
use std::io::Read; use dez80::Instruction; // Initialize a buffer containing raw Z80 opcodes. let mut data: &[u8] = &[0x00, 0x04, 0x05]; // NOP, INC B, DEC B // Decode a single instruction from the raw bytes. if let Ok(instruction) = Instruction::decode_one(&mut data) { // Convert the instruction to a string, in its symbolic format. assert_eq!("NOP", instruction.to_string()); } else { panic!("Could not decode an instruction!"); } // Decode a sequence of instructions from the remaining bytes. let instructions = Instruction::decode_all(&mut data); assert_eq!(2, instructions.len()); // bytes are consumed as they are decoded for instruction in instructions { println!("Decoded {}.", instruction); }
use dez80::{Instruction, InstructionDecoder}; // Initialize a stateful instruction decoder. let mut decoder = InstructionDecoder::new(); // Decode a single byte with the decoder. decoder.push_byte(0x00); // NOP let result = decoder.try_decode(); // This is a single-byte instruction, so we can verify // that a valid instruction was returned. assert!(result.is_ok()); assert_eq!("NOP", result.unwrap().to_string()); // Decode the first byte of a multi-byte instruction. decoder.push_byte(0xED); // extended instruction let result = decoder.try_decode(); // No instruction can be decoded from this byte alone. assert!(result.is_err()); // Decode the second byte of the instruction. // This time, the instruction can finish decoding. decoder.push_byte(0x44); // NEG let result = decoder.try_decode(); assert!(result.is_ok()); assert_eq!("NEG", result.unwrap().to_string());
Structs
Instruction | Represents a single Z80 instruction. |
Opcode | Represents an instruction opcode, including prefixes but excluding operands. |
Enums
Condition | Represents a prerequisite condition for an instruction. |
DecodingState | Represents a state in the decoding process, defined as a combination of the current opcode table, and the role of the next byte to decode. This corresponds to a decoding state that the decoder has yet to perform. |
InstructionType | Represents a type of instruction, categorized by mnemonic. |
OpcodePrefix | Represents a set of one or two bytes modifying an instruction's opcode. |
Operand | Represents a target for data operations. Variants are closely related to Z80 addressing modes. |