Fix crashing bug

This commit is contained in:
Franco Colmenarez 2021-11-15 13:15:31 -05:00
parent 0aa6e56fc1
commit e2959abfaf
3 changed files with 6 additions and 8 deletions

View File

@ -156,9 +156,8 @@ impl Bus {
let source = (data as u16) * 0x100;
let mut count: u16 = 0;
let oam_addr = SPRITE_ATTRIBUTE_TABLE.min().unwrap();
let mut ppu = self.ppu.borrow_mut();
while count < 160 {
ppu.write_oam(oam_addr + count, self.data[(source + count) as usize]);
self.ppu.borrow_mut().write_oam(oam_addr + count, self.data[(source + count) as usize]);
count += 1;
}
} else {

View File

@ -107,13 +107,11 @@ impl Emulator {
pub fn run(&mut self, cpu_cycles: Cycles, frame_buffer: &mut [u8]) {
self.cpu.reset_cycles();
let mut ppu = self.ppu.borrow_mut();
let mut timer = self.timer.borrow_mut();
while self.cpu.get_cycles().to_t().0 <= cpu_cycles.0 {
self.cpu.run(&mut self.bus);
let cycles = self.cpu.get_last_op_cycles().to_t();
ppu.do_cycles(&mut self.bus, cycles, frame_buffer);
timer.do_cycles(&mut self.bus, cycles);
self.ppu.borrow_mut().do_cycles(&mut self.bus, cycles, frame_buffer);
self.timer.borrow_mut().do_cycles(&mut self.bus, cycles);
// 1 CPU cycle = 238.42ns
// thread::sleep(time::Duration::from_nanos((self.cpu.get_last_op_cycles().0 * 238).try_into().unwrap()));

View File

@ -184,8 +184,9 @@ impl Sprite {
let tile_line = y.rem_euclid(height) * 2;
let addr = 0x8000 + (tile_number as u16 * 16) + tile_line as u16;
let tile_byte_1 = vram[addr as usize - 0x2000];
let tile_byte_2 = vram[addr as usize - 0x2000 + 1];
let vram_start = VIDEO_RAM.min().unwrap();
let tile_byte_1 = vram[(addr - vram_start) as usize];
let tile_byte_2 = vram[(addr - vram_start + 1) as usize];
let bit_pixels_array = PPU::get_byte_pixels(tile_byte_1, tile_byte_2);
self.bit_pixels = Some(bit_pixels_array);