debugging

This commit is contained in:
Richard 2025-08-30 21:05:56 +02:00
parent 8d48c4bc89
commit c9dafbcb72
2 changed files with 15 additions and 10 deletions

View File

@ -45,6 +45,7 @@ impl Console for IoConsole {
fn write(&mut self, c: u8) {
let buf = [c;1];
let _ = std::io::stdout().write(&buf);
let _ = std::io::stdout().flush();
}
}

View File

@ -132,7 +132,7 @@ impl Cpu {
let aidx = self.gr(i.a);
let aoff = self.gr(i.b) as usize;
let v = self.gr(i.c);
// println!("amd {}[{}]={}", aidx, aoff, v);
if let Some(arr) = self.arr.get_mut(&aidx){
if arr.len() > aoff {
arr[aoff] = v;
@ -173,9 +173,9 @@ impl Cpu {
}
fn handle_nand(&mut self, i:NormalInstruction) -> Result<(), CpuError>{
let b = ! self.gr(i.b);
let c = ! self.gr(i.c);
let a = b & c;
let b = self.gr(i.b);
let c = self.gr(i.c);
let a = !(b & c);
self.sr(i.a, a);
Ok(())
}
@ -194,6 +194,7 @@ impl Cpu {
let v = vec![0; c];
self.arr.insert(aid, v);
self.sr(i.b, aid);
//println!("alc {} -> {}", c, aid);
Ok(())
}
@ -224,8 +225,11 @@ impl Cpu {
let aidx = self.gr(i.b);
let aoff = self.gr(i.c);
if let Some(arr) = self.arr.get(&aidx){
if arr.len() > aoff as usize {
self.arr.insert(0, arr.clone());
if arr.len() > (aoff as usize) {
if aidx > 0 {
// println!("cloning {}", aidx);
self.arr.insert(0, arr.clone());
}
self.finger = aoff;
Ok(())
} else {
@ -507,9 +511,9 @@ mod tests{
fn test_div() -> Result<(), CpuError> {
let pgm = vec!( ezop(5, 1, 2, 3) );
let mut c = Cpu::new(pgm);
c.reg = [0, 0, 2048, 2, 0, 0, 0, 0];
c.reg = [0, 0, 2048, 1024, 0, 0, 0, 0];
c.run(&mut NoConsole{})?;
let exp = [0, 1024, 2048, 2, 0, 0, 0, 0];
let exp = [0, 2, 2048, 1024, 0, 0, 0, 0];
assert_eq!(c.reg, exp);
Ok(())
}
@ -530,9 +534,9 @@ mod tests{
fn test_nand() -> Result<(), CpuError> {
let pgm = vec!( ezop(6, 1, 2, 3) );
let mut c = Cpu::new(pgm);
c.reg = [0, 0, 0x5a5a00ff, 0xdede00ff, 0, 0, 0, 0];
c.reg = [0, 0, 0xff00ff00, 0xffff0000, 0, 0, 0, 0];
c.run(&mut NoConsole{})?;
let exp = [0, 0x2121ff00, 0x5a5a00ff, 0xdede00ff, 0, 0, 0, 0];
let exp = [0, 0x00ffff00, 0xff00ff00, 0xffff0000, 0, 0, 0, 0];
assert_eq!(c.reg, exp);
Ok(())
}