aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaditya Dhruv <[email protected]>2023-01-03 09:51:51 +0530
committerAaditya Dhruv <[email protected]>2023-01-03 09:51:51 +0530
commitc315bd55cdf81eb826ff253a743d78974b704e99 (patch)
treeb7cb004eee1ddceb74914bf93eeded02b6656adf
parentfc4271c4286568f2001ce46c9a2e0fabf4d6147d (diff)
FIXED 8XY5/7 BUG! 8XYE updated to super-chip
-rw-r--r--src/lib.rs24
1 files changed, 13 insertions, 11 deletions
diff --git a/src/lib.rs b/src/lib.rs
index cf39e2c..7e0bf6b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -115,7 +115,7 @@ impl Chip {
pub fn fetch(&mut self) {
self.instr = ((self.mem[self.pc as usize] as u16) << 8) | self.mem[(self.pc + 1) as usize] as u16;
self.pc += 2;
- //println!("Fetching next instruction: {:#06X}", self.instr);
+ println!("Fetching next instruction: {:#06X}", self.instr);
}
pub fn execute(&mut self) {
@@ -255,36 +255,38 @@ impl Chip {
self.registers[self.x] = self.registers[self.x] ^ self.registers[self.y];
}
fn add_8xy4(&mut self) {
- println!("Checking add");
- self.registers[self.x] = self.registers[self.x].wrapping_add(self.registers[self.y]);
match self.registers[self.x].checked_add(self.registers[self.y]) {
Some(_) => { self.registers[0xF] = 0; }
None => { self.registers[0xF] = 1; }
}
+ self.registers[self.x] = self.registers[self.x].wrapping_add(self.registers[self.y]);
}
fn sub_8xy5(&mut self) {
println!("Checking sub1");
- self.registers[self.x] = self.registers[self.x].wrapping_sub(self.registers[self.y]);
- match self.registers[self.x].checked_sub(self.registers[self.y]) {
- Some(_) => { self.registers[0xF] = 1; }
- None => { self.registers[0xF] = 0; }
+ println!("{}, {}", self.registers[self.x], self.registers[self.y]);
+ if self.registers[self.x] > self.registers[self.y] {
+ self.registers[0xF] = 1;
+ }
+ else {
+ self.registers[0xF] = 0;
}
+ self.registers[self.x] = self.registers[self.x].wrapping_sub(self.registers[self.y]);
}
fn sub_8xy7(&mut self) {
println!("Checking sub2");
- self.registers[self.x] = self.registers[self.y].wrapping_sub(self.registers[self.x]);
match self.registers[self.y].checked_sub(self.registers[self.x]) {
Some(_) => { self.registers[0xF] = 1; }
None => { self.registers[0xF] = 0; }
}
+ self.registers[self.x] = self.registers[self.y].wrapping_sub(self.registers[self.x]);
}
fn shr_8xy6(&mut self) {
- self.registers[self.x] = self.registers[self.y];
- self.registers[0xF] = self.registers[self.x] << 7 & 1;
+// self.registers[self.x] = self.registers[self.y];
+ self.registers[0xF] = self.registers[self.x] << 7 >> 7 & 1;
self.registers[self.x] >>= 1;
}
fn shl_8xye(&mut self) {
- self.registers[self.x] = self.registers[self.y];
+// self.registers[self.x] = self.registers[self.y];
self.registers[0xF] = self.registers[self.x] >> 7 & 1;
self.registers[self.x] <<= 1;
}