72 lines
1.5 KiB
Rust
72 lines
1.5 KiB
Rust
#[derive(Clone, Copy)]
|
|
pub struct Instruction(pub u32);
|
|
|
|
pub enum Operator {
|
|
NOP,
|
|
INC,
|
|
DEC,
|
|
RLCA,
|
|
RRCA,
|
|
RLA
|
|
RRA,
|
|
JR_NZ,
|
|
JR,
|
|
JR_NC,
|
|
JR_Z,
|
|
CPL,
|
|
CCF,
|
|
HALT,
|
|
LD,
|
|
ADD,
|
|
ADC,
|
|
SUB,
|
|
SBC,
|
|
AND,
|
|
XOR,
|
|
OR,
|
|
CP,
|
|
RET
|
|
}
|
|
|
|
impl Instruction {
|
|
pub fn operand(&self) -> Operator {
|
|
match self.0 {
|
|
// 0x00 - 0x0F
|
|
0x00: Operator::NOP,
|
|
0x01..0x02: Operator::LD,
|
|
0x03..0x04: Operator::INC,
|
|
0x05: Operator::DEC,
|
|
0x06: Operator::LD,
|
|
0x07: Operator::RLCA,
|
|
0x08: Operator::LD,
|
|
0x09: Operator::ADD,
|
|
0x0A: Operator::LD,
|
|
0x0B: Operator::DEC,
|
|
0x0C: Operator::INC,
|
|
0x0D: Operator::DEC,
|
|
0x0E: Operator::LD,
|
|
0x0F: Operator::RRCA,
|
|
// 0x10 - 0x1F
|
|
|
|
// 0x20 - 0x2F
|
|
|
|
// 0x30 - 0x3F
|
|
0x30: Operator::JR_NC,
|
|
0x31: Operator::LD,
|
|
|
|
// Higher instructions seem to be grouped better
|
|
0x40..0x75: Operator::LD,
|
|
0x76: Operator::HALT,
|
|
0x77..0x7F: Operator::LD,
|
|
0x80..0x87: Operator::ADD,
|
|
0x88..0x8F: Operator::ADC,
|
|
0x90..0x97: Operator::SUB,
|
|
0x98..0x9F: Operator::SBC,
|
|
0xA0..0xA7: Operator::AND,
|
|
0xA8..0xAF: Operator::XOR,
|
|
0xB0..0xB7: Operator::OR,
|
|
0xB8..0xBF: Operator::CP,
|
|
}
|
|
}
|
|
}
|