104 lines
3.2 KiB
Rust
104 lines
3.2 KiB
Rust
// icodes
|
|
pub struct Icode {}
|
|
|
|
impl Icode {
|
|
// Official names
|
|
pub const BRK: u8 = 0x00u8;
|
|
pub const LIT: u8 = 0b10000000; // AKA keep Yes really. Per spec;
|
|
pub const LIT2: u8 = 0b10100000; // AKA keep Yes really. Per spec;
|
|
pub const INC: u8 = 0x01;
|
|
pub const POP: u8 = 0x02;
|
|
pub const NIP: u8 = 0x03;
|
|
pub const SWP: u8 = 0x04;
|
|
pub const ROT: u8 = 0x05;
|
|
pub const DUP: u8 = 0x06;
|
|
pub const OVR: u8 = 0x07;
|
|
pub const EQL: u8 = 0x08;
|
|
pub const NEQ: u8 = 0x09;
|
|
pub const GTH: u8 = 0x0a;
|
|
pub const LTH: u8 = 0x0b;
|
|
pub const JMP: u8 = 0x0c;
|
|
pub const JCN: u8 = 0x0d;
|
|
pub const JSR: u8 = 0x0e;
|
|
pub const STH: u8 = 0x0f;
|
|
pub const LDZ: u8 = 0x10;
|
|
pub const STZ: u8 = 0x11;
|
|
pub const LDR: u8 = 0x12;
|
|
pub const STR: u8 = 0x13;
|
|
pub const LDA: u8 = 0x14;
|
|
pub const STA: u8 = 0x15;
|
|
pub const DEI: u8 = 0x16;
|
|
pub const DEO: u8 = 0x17;
|
|
pub const ADD: u8 = 0x18;
|
|
pub const SUB: u8 = 0x19;
|
|
pub const MUL: u8 = 0x1a;
|
|
pub const DIV: u8 = 0x1b;
|
|
pub const AND: u8 = 0x1c;
|
|
pub const ORA: u8 = 0x1d;
|
|
pub const EOR: u8 = 0x1e;
|
|
pub const SFT: u8 = 0x1f;
|
|
|
|
// Opcode flags
|
|
pub const SHORT: u8 = 0x20;
|
|
pub const RETURN: u8 = 0x40;
|
|
pub const KEEP: u8 = 0x80;
|
|
|
|
// Hacking around the official names for some things
|
|
pub const XOR: u8 = Icode::EOR;
|
|
pub const EQ: u8 = Icode::EQL;
|
|
pub const NE: u8 = Icode::NEQ;
|
|
pub const GT: u8 = Icode::GTH;
|
|
pub const LT: u8 = Icode::LTH;
|
|
pub const OR: u8 = Icode::ORA;
|
|
pub const NOP: u8 = Icode::POP | Icode::KEEP;
|
|
|
|
pub const fn parse(opcode: u8) -> (u8, u8, u8, u8) {
|
|
let kflag: u8 = (opcode >> 7) & 0x1;
|
|
let rflag: u8 = (opcode >> 6) & 0x1;
|
|
let sflag: u8 = (opcode >> 5) & 0x1;
|
|
let icode: u8 = opcode & 0x1F;
|
|
(kflag, rflag, sflag, icode)
|
|
}
|
|
|
|
pub const fn nameof(opcode: u8) -> &'static str {
|
|
match opcode {
|
|
// Nonstandard icodes + extensions
|
|
Icode::LIT | Icode::LIT2 => &"LIT", // AKA keep Yes really. Per spec,
|
|
Icode::NOP => &"NOP",
|
|
// Standard icodes
|
|
Icode::BRK => &"BRK",
|
|
Icode::INC => &"INC",
|
|
Icode::POP => &"POP",
|
|
Icode::NIP => &"NIP",
|
|
Icode::SWP => &"SWP",
|
|
Icode::ROT => &"ROT",
|
|
Icode::DUP => &"DUP",
|
|
Icode::OVR => &"OVR",
|
|
Icode::EQL => &"EQL",
|
|
Icode::NEQ => &"NEQ",
|
|
Icode::GTH => &"GTH",
|
|
Icode::LTH => &"LTH",
|
|
Icode::JMP => &"JMP",
|
|
Icode::JCN => &"JNC",
|
|
Icode::JSR => &"JSR",
|
|
Icode::STH => &"STH",
|
|
Icode::LDZ => &"LDZ",
|
|
Icode::STZ => &"STZ",
|
|
Icode::LDR => &"LDR",
|
|
Icode::STR => &"STR",
|
|
Icode::LDA => &"LDA",
|
|
Icode::STA => &"STA",
|
|
Icode::DEI => &"DEI",
|
|
Icode::DEO => &"DEO",
|
|
Icode::ADD => &"ADD",
|
|
Icode::SUB => &"SUB",
|
|
Icode::MUL => &"MUL",
|
|
Icode::DIV => &"DIV",
|
|
Icode::AND => &"AND",
|
|
Icode::ORA => &"ORA",
|
|
Icode::EOR => &"EOR",
|
|
Icode::SFT => &"SFT",
|
|
_ => Icode::nameof(opcode & 0x1F),
|
|
}
|
|
}
|
|
}
|