Fix LCD on/off issue

This commit is contained in:
Franco Colmenarez 2021-11-09 10:39:26 -05:00
parent b92160dee4
commit 2474cd72b7
2 changed files with 4 additions and 9 deletions

View File

@ -129,7 +129,6 @@ impl Bus {
if BANK_ZERO.in_range(address) || BANK_SWITCHABLE.in_range(address) || EXTERNAL_RAM.in_range(address) { if BANK_ZERO.in_range(address) || BANK_SWITCHABLE.in_range(address) || EXTERNAL_RAM.in_range(address) {
self.game_rom.write(address, data); self.game_rom.write(address, data);
// println!("WRITING TO ROM");
} else if WORK_RAM_1.in_range(address) || WORK_RAM_2.in_range(address) { } else if WORK_RAM_1.in_range(address) || WORK_RAM_2.in_range(address) {
self.data[address as usize] = data; self.data[address as usize] = data;
// Copy to the ECHO RAM // Copy to the ECHO RAM
@ -143,11 +142,10 @@ impl Bus {
self.data[(WORK_RAM_1.begin() + (address - ECHO_RAM.begin())) as usize] = data; // Copy to the working RAM self.data[(WORK_RAM_1.begin() + (address - ECHO_RAM.begin())) as usize] = data; // Copy to the working RAM
} else if address == TIMER_DIVIDER_REGISTER_ADDRESS { } else if address == TIMER_DIVIDER_REGISTER_ADDRESS {
self.reset_timer = true; self.reset_timer = true;
} else if address == LCD_CONTROL_ADDRESS && get_bit(data, BitIndex::I7) { } else if address == LCD_CONTROL_ADDRESS {
self.data[address as usize] = data;
// Check if LCD is being turned on
if get_bit(data, BitIndex::I7) && !get_bit(self.data[address as usize], BitIndex::I7) { if get_bit(data, BitIndex::I7) && !get_bit(self.data[address as usize], BitIndex::I7) {
// LCD is turned on
println!("LCD turned on");
self.data[address as usize] = data;
self.data[LCD_Y_ADDRESS as usize] = 0x00; self.data[LCD_Y_ADDRESS as usize] = 0x00;
} }
} else if address == LCD_Y_ADDRESS { } else if address == LCD_Y_ADDRESS {

View File

@ -164,7 +164,6 @@ impl Sprite {
let pixels = PPU::get_byte_pixels(tile_byte_1, tile_byte_2, palette); let pixels = PPU::get_byte_pixels(tile_byte_1, tile_byte_2, palette);
Some(pixels[pixel_index]) Some(pixels[pixel_index])
} }
} }
@ -208,8 +207,8 @@ impl PPU {
} }
} else if PPU::get_lcd_y(bus) >= 144 && !PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank)) { } else if PPU::get_lcd_y(bus) >= 144 && !PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank)) {
// Mode 1 Vertical blank // Mode 1 Vertical blank
bus.set_interrupt_flag(Interrupt::VBlank, true);
PPU::set_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank), true); PPU::set_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank), true);
bus.set_interrupt_flag(Interrupt::VBlank, true);
self.stat_interrupt(bus); self.stat_interrupt(bus);
} }
@ -249,7 +248,6 @@ impl PPU {
PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank)) PPU::get_lcd_status(bus, LCDStatus::ModeFlag(LCDStatusModeFlag::VBlank))
); );
if self.state && !prev_state { if self.state && !prev_state {
println!("LCDSTAT interrupt");
bus.set_interrupt_flag(Interrupt::LCDSTAT, self.state); bus.set_interrupt_flag(Interrupt::LCDSTAT, self.state);
} }
} }
@ -464,7 +462,6 @@ impl PPU {
} }
let mut lcd_x: u8 = 0; let mut lcd_x: u8 = 0;
while (lcd_x as u32) < LCD_WIDTH { while (lcd_x as u32) < LCD_WIDTH {
let idx = (lcd_x as usize + (lcd_y as usize * LCD_WIDTH as usize)) * 4; let idx = (lcd_x as usize + (lcd_y as usize * LCD_WIDTH as usize)) * 4;
if let Some(background_pixel) = PPU::get_background_pixel(lcd_x, bus) { if let Some(background_pixel) = PPU::get_background_pixel(lcd_x, bus) {