Fix some overflows

This commit is contained in:
Kevin Hamacher 2016-06-01 15:02:43 +02:00
parent e8da2e4958
commit 19f31cfbbf
3 changed files with 9 additions and 4 deletions

View File

@ -120,7 +120,7 @@ impl CPU {
self.clear_flag(FLAG_N);
self.set_clear_flag(FLAG_Z, new == 0);
self.set_clear_flag(FLAG_C, ((val + c) > 0 && new < old) || (c == 1 && new == old));
self.set_clear_flag(FLAG_C, (new < old) || (c == 1 && new == old));
self.set_clear_flag(FLAG_H, ((old & 0x0F) + (val & 0x0F) + c) > 0x0F);
}

View File

@ -418,7 +418,7 @@ impl Display {
}
// Draw stuff. We're currently only in monochrome mode
self.set_pixel(x + x_o, render_y, sdl2::pixels::Color::RGB(factor, factor, factor));
self.set_pixel(x.wrapping_add(x_o), render_y, sdl2::pixels::Color::RGB(factor, factor, factor));
}
}

View File

@ -20,7 +20,7 @@ impl NoMBC {
impl MBC for NoMBC {
fn write_byte(&mut self, addr: u16, val: u8) {
panic!("Writing not supported for cartridges without MBC.");
println!("Writing not supported for cartridges without MBC. (Tried to set {:04X} to {:02X})", addr, val);
}
fn read_byte(&self, addr: u16) -> u8 {
@ -30,7 +30,12 @@ impl MBC for NoMBC {
// TODO: Check for ram
let addr = (addr as usize) - 0xA000;
self.ram[addr]
if addr >= self.ram.len() {
println!("Tried to access {:04X}, however the memory is not present.", addr + 0xA000);
0
} else {
self.ram[addr]
}
}
_ => {
panic!("Cartride: Unable to read from {:04X}", addr);