Skip to content
Snippets Groups Projects
Verified Commit 19babd32 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

fix half carry in sub

parent 1c99b69a
No related branches found
No related tags found
No related merge requests found
...@@ -538,6 +538,13 @@ impl Cpu { ...@@ -538,6 +538,13 @@ impl Cpu {
println!("GOING TO PLAY BOOT SOUND"); println!("GOING TO PLAY BOOT SOUND");
} }
if pc == 0x008f {
println!("GOING TO PLAY BOOT 0x00e0");
}
// calls the current instruction and increments the number of
// cycles executed by the instruction time of the instruction
// that has just been executed
instruction_fn(self); instruction_fn(self);
self.ticks = self.ticks.wrapping_add(*instruction_time as u32); self.ticks = self.ticks.wrapping_add(*instruction_time as u32);
...@@ -738,11 +745,12 @@ fn inc_b(cpu: &mut Cpu) { ...@@ -738,11 +745,12 @@ fn inc_b(cpu: &mut Cpu) {
} }
fn dec_b(cpu: &mut Cpu) { fn dec_b(cpu: &mut Cpu) {
let value = cpu.b.wrapping_sub(1); let b = cpu.b;
let value = b.wrapping_sub(1);
cpu.set_sub(true); cpu.set_sub(true);
cpu.set_zero(value == 0); cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf); cpu.set_half_carry((b & 0xf) == 0xf);
cpu.b = value; cpu.b = value;
} }
...@@ -785,11 +793,12 @@ fn inc_c(cpu: &mut Cpu) { ...@@ -785,11 +793,12 @@ fn inc_c(cpu: &mut Cpu) {
} }
fn dec_c(cpu: &mut Cpu) { fn dec_c(cpu: &mut Cpu) {
let value = cpu.c.wrapping_sub(1); let c = cpu.c;
let value = c.wrapping_sub(1);
cpu.set_sub(true); cpu.set_sub(true);
cpu.set_zero(value == 0); cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf); cpu.set_half_carry((c & 0xf) == 0xf);
cpu.c = value; cpu.c = value;
} }
...@@ -809,11 +818,12 @@ fn inc_de(cpu: &mut Cpu) { ...@@ -809,11 +818,12 @@ fn inc_de(cpu: &mut Cpu) {
} }
fn dec_d(cpu: &mut Cpu) { fn dec_d(cpu: &mut Cpu) {
let value = cpu.d.wrapping_sub(1); let d = cpu.d;
let value = d.wrapping_sub(1);
cpu.set_sub(true); cpu.set_sub(true);
cpu.set_zero(value == 0); cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf); cpu.set_half_carry((d & 0xf) == 0xf);
cpu.d = value; cpu.d = value;
} }
...@@ -841,11 +851,12 @@ fn ld_a_mde(cpu: &mut Cpu) { ...@@ -841,11 +851,12 @@ fn ld_a_mde(cpu: &mut Cpu) {
} }
fn dec_e(cpu: &mut Cpu) { fn dec_e(cpu: &mut Cpu) {
let value = cpu.e.wrapping_sub(1); let e = cpu.e;
let value = e.wrapping_sub(1);
cpu.set_sub(true); cpu.set_sub(true);
cpu.set_zero(value == 0); cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf); cpu.set_half_carry((e & 0xf) == 0xf);
cpu.e = value; cpu.e = value;
} }
...@@ -916,11 +927,12 @@ fn ld_mhld_a(cpu: &mut Cpu) { ...@@ -916,11 +927,12 @@ fn ld_mhld_a(cpu: &mut Cpu) {
} }
fn dec_a(cpu: &mut Cpu) { fn dec_a(cpu: &mut Cpu) {
let value = cpu.a.wrapping_sub(1); let a = cpu.a;
let value = a.wrapping_sub(1);
cpu.set_sub(true); cpu.set_sub(true);
cpu.set_zero(value == 0); cpu.set_zero(value == 0);
cpu.set_half_carry((value & 0xf) == 0xf); cpu.set_half_carry((a & 0xf) == 0xf);
cpu.a = value; cpu.a = value;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment