Couple bugfixes, integration tests ported

This commit is contained in:
2022-04-17 23:35:48 -05:00
parent df111ce55b
commit 05c1be2e94
16 changed files with 436 additions and 48 deletions
+33 -22
View File
@@ -32,6 +32,12 @@ impl PeekPoke for CPU {
}
}
impl Default for CPU {
fn default() -> Self {
Self::new(Memory::default())
}
}
impl CPU {
pub fn new(memory: Memory) -> Self {
Self {
@@ -270,6 +276,33 @@ impl CPU {
pub fn running(&self) -> bool {
!self.halted
}
pub fn run_to_halt(&mut self) {
self.start();
while !self.halted && self.pc < 1100 {
self.tick()
}
}
pub fn get_stack(&self) -> Vec<Word> {
let mut v = Vec::new();
let mut curr = Word::from(256);
while curr < self.dp {
v.push(self.memory.peek24(curr));
curr += 3
}
v
}
pub fn get_call(&self) -> Vec<Word> {
let mut v = Vec::new();
let mut curr = Word::from(1024);
while curr > self.sp {
curr -= 3;
v.push(self.memory.peek24(curr));
}
v
}
}
impl Opcode {
@@ -305,28 +338,6 @@ mod tests {
use super::*;
use Opcode::*;
impl CPU {
fn get_stack(&self) -> Vec<Word> {
let mut v = Vec::new();
let mut curr = Word::from(256);
while curr < self.dp {
v.push(self.memory.peek24(curr));
curr += 3
}
v
}
fn get_call(&self) -> Vec<Word> {
let mut v = Vec::new();
let mut curr = Word::from(1024);
while curr > self.sp {
curr -= 3;
v.push(self.memory.peek24(curr));
}
v
}
}
fn predicate_opcode_test<P, Q>(opcode: Opcode, given: P, pred: Q)
where
P: FnOnce(&mut CPU),