Adjustments to make emu core run faster when not paused

This commit is contained in:
2023-07-08 23:44:24 -05:00
parent b9f0079854
commit a68a4b1764
3 changed files with 17 additions and 6 deletions
+7 -3
View File
@@ -7,7 +7,6 @@ pub struct Emulator {
pub cpu: CPU, pub cpu: CPU,
pub bus: Bus, pub bus: Bus,
pub rom: Box<dyn ROM>, pub rom: Box<dyn ROM>,
pub is_frame_ending: bool,
} }
impl Emulator { impl Emulator {
@@ -16,7 +15,6 @@ impl Emulator {
cpu: CPU::new(), cpu: CPU::new(),
bus: Bus::new(), bus: Bus::new(),
rom: Box::new(LoROM::new()), rom: Box::new(LoROM::new()),
is_frame_ending: false,
} }
} }
@@ -25,8 +23,14 @@ impl Emulator {
self.bus.ppu.tick(self.cpu.cycles); self.bus.ppu.tick(self.cpu.cycles);
self.cpu.cycles = 0; self.cpu.cycles = 0;
}
self.is_frame_ending = true; pub fn is_frame_ending(&self) -> bool {
self.bus.ppu.registers.v_count == 0
}
pub fn is_frame_starting(&self) -> bool {
self.bus.ppu.registers.v_count == 1
} }
pub fn reset(&mut self) { pub fn reset(&mut self) {
+5 -3
View File
@@ -452,11 +452,13 @@ fn main() {
if !state.emulation.is_paused { if !state.emulation.is_paused {
// We want to keep the emulator running // We want to keep the emulator running
// as long as we are not at the end of the frame // as long as we are not at the end of the frame
while !emulator.is_frame_ending { while !emulator.is_frame_ending() {
emulator.tick()
}
// It takes some amount of cycles to get out of 0 v-count
while !emulator.is_frame_starting() {
emulator.tick() emulator.tick()
} }
// Reset the flag because otherwise the emulator will never continue running
emulator.is_frame_ending = false
} }
// Render emulator framebuffer // Render emulator framebuffer
+5
View File
@@ -129,6 +129,11 @@ pub fn registers_window(ppu_registers: &PPURegisters, show_registers: &mut bool,
.size([230.0, 310.0], imgui::Condition::FirstUseEver) .size([230.0, 310.0], imgui::Condition::FirstUseEver)
.opened(show_registers) .opened(show_registers)
.build(ui, || { .build(ui, || {
ui.text("H/V Counters:");
ui.text(format!("V: {}", ppu_registers.v_count));
ui.text(format!("H: {}", ppu_registers.h_count));
ui.text(format!("VBlanking: {}", ppu_registers.is_vblanking()));
ui.separator();
ui.text("Registers:"); ui.text("Registers:");
for (index, register_value) in ppu_registers.registers().iter().enumerate() { for (index, register_value) in ppu_registers.registers().iter().enumerate() {
let register = (index as u16) + 0x2100; let register = (index as u16) + 0x2100;