pub struct Processor<'a> {
reg: [u16;32],
flags: [bool;2], //flag A, then B
itr_toggle: bool,
pub memory: &'a mut [u16],
pub disk: &'a mut [u16],
}
pub fn new<'a>(memory: &'a mut [u16], disk: &'a mut [u16]) -> Processor<'a> {
Processor {
reg: [0;32],
flags: [false;2],
itr_toggle: false,
memory,
disk
}
}
impl <'a> Processor<'a> {
///Runs the processor through one instruction.
pub fn run(&mut self) {
let instruction: (u16,u16) = (self.disk[self.reg[31] as usize],self.disk[self.reg[31] as usize +1]);
let conditions: ((bool,bool),(bool,bool)) = (( //.0.x is activations, .1.x is conditions
(instruction.0 & 0x80) != 0,
(instruction.0 & 0x40) != 0),(
(instruction.0 & 0x20) != 0,
(instruction.0 & 0x10) != 0)
);
if (conditions.0.0 && (conditions.1.0 != self.flags[0])) || (conditions.0.1 && (conditions.1.1 != self.flags[1])) {
self.reg[31] += 2; //update the program counter at the end of the instruction
//execution.
return; //if the conditions are not met, perform no further calculations.
}
}
}