pub mod register;
pub mod operation;
pub mod processor;
#[cfg(test)]
mod tests {
use std::cell::RefCell;
use std::rc::Rc;
use osiris_data::data::atomic::Word;
use osiris_data::memory::Memory;
use crate::operation::{Instruction, Operation, OperationSet};
use crate::operation::scheme::{ArgumentType, OperationId};
use crate::processor::Cpu;
#[test]
fn test_creation() {
let instr = Instruction::new(0);
assert_eq!(instr.to_u64(), 0);
}
#[test]
fn test_operation() {
const OPID: OperationId = OperationId::new(0x7357);
let operation = Operation::new(
OPID, "SET R:$1 = 1".to_string(),
true, ArgumentType::NoArgument,
|cpu, scheme| {
cpu.bank_set(scheme.target, Word::new(1));
Ok(())
},
);
let mut cpu = Cpu::new(RefCell::new(Memory::new()), Rc::new(OperationSet::new()));
let instr = Instruction::new(0x7357_0000_0000_0000);
let scheme = instr.scheme(ArgumentType::NoArgument);
operation.call(&mut cpu, scheme).unwrap();
assert_eq!(cpu.bank_get(scheme.target), Word::new(1));
}
}