Fix some overflows
This commit is contained in:
parent
e8da2e4958
commit
19f31cfbbf
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -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);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user