1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43

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));
    }
}