debugging
This commit is contained in:
parent
8d48c4bc89
commit
c9dafbcb72
@ -45,6 +45,7 @@ impl Console for IoConsole {
|
|||||||
fn write(&mut self, c: u8) {
|
fn write(&mut self, c: u8) {
|
||||||
let buf = [c;1];
|
let buf = [c;1];
|
||||||
let _ = std::io::stdout().write(&buf);
|
let _ = std::io::stdout().write(&buf);
|
||||||
|
let _ = std::io::stdout().flush();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
src/cpu.rs
24
src/cpu.rs
@ -132,7 +132,7 @@ impl Cpu {
|
|||||||
let aidx = self.gr(i.a);
|
let aidx = self.gr(i.a);
|
||||||
let aoff = self.gr(i.b) as usize;
|
let aoff = self.gr(i.b) as usize;
|
||||||
let v = self.gr(i.c);
|
let v = self.gr(i.c);
|
||||||
|
// println!("amd {}[{}]={}", aidx, aoff, v);
|
||||||
if let Some(arr) = self.arr.get_mut(&aidx){
|
if let Some(arr) = self.arr.get_mut(&aidx){
|
||||||
if arr.len() > aoff {
|
if arr.len() > aoff {
|
||||||
arr[aoff] = v;
|
arr[aoff] = v;
|
||||||
@ -173,9 +173,9 @@ impl Cpu {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn handle_nand(&mut self, i:NormalInstruction) -> Result<(), CpuError>{
|
fn handle_nand(&mut self, i:NormalInstruction) -> Result<(), CpuError>{
|
||||||
let b = ! self.gr(i.b);
|
let b = self.gr(i.b);
|
||||||
let c = ! self.gr(i.c);
|
let c = self.gr(i.c);
|
||||||
let a = b & c;
|
let a = !(b & c);
|
||||||
self.sr(i.a, a);
|
self.sr(i.a, a);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -194,6 +194,7 @@ impl Cpu {
|
|||||||
let v = vec![0; c];
|
let v = vec![0; c];
|
||||||
self.arr.insert(aid, v);
|
self.arr.insert(aid, v);
|
||||||
self.sr(i.b, aid);
|
self.sr(i.b, aid);
|
||||||
|
//println!("alc {} -> {}", c, aid);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -224,8 +225,11 @@ impl Cpu {
|
|||||||
let aidx = self.gr(i.b);
|
let aidx = self.gr(i.b);
|
||||||
let aoff = self.gr(i.c);
|
let aoff = self.gr(i.c);
|
||||||
if let Some(arr) = self.arr.get(&aidx){
|
if let Some(arr) = self.arr.get(&aidx){
|
||||||
if arr.len() > aoff as usize {
|
if arr.len() > (aoff as usize) {
|
||||||
self.arr.insert(0, arr.clone());
|
if aidx > 0 {
|
||||||
|
// println!("cloning {}", aidx);
|
||||||
|
self.arr.insert(0, arr.clone());
|
||||||
|
}
|
||||||
self.finger = aoff;
|
self.finger = aoff;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
@ -507,9 +511,9 @@ mod tests{
|
|||||||
fn test_div() -> Result<(), CpuError> {
|
fn test_div() -> Result<(), CpuError> {
|
||||||
let pgm = vec!( ezop(5, 1, 2, 3) );
|
let pgm = vec!( ezop(5, 1, 2, 3) );
|
||||||
let mut c = Cpu::new(pgm);
|
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{})?;
|
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);
|
assert_eq!(c.reg, exp);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -530,9 +534,9 @@ mod tests{
|
|||||||
fn test_nand() -> Result<(), CpuError> {
|
fn test_nand() -> Result<(), CpuError> {
|
||||||
let pgm = vec!( ezop(6, 1, 2, 3) );
|
let pgm = vec!( ezop(6, 1, 2, 3) );
|
||||||
let mut c = Cpu::new(pgm);
|
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{})?;
|
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);
|
assert_eq!(c.reg, exp);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user