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

View File

@@ -7,7 +7,6 @@ pub struct Emulator {
pub cpu: CPU,
pub bus: Bus,
pub rom: Box<dyn ROM>,
pub is_frame_ending: bool,
}
impl Emulator {
@@ -16,7 +15,6 @@ impl Emulator {
cpu: CPU::new(),
bus: Bus::new(),
rom: Box::new(LoROM::new()),
is_frame_ending: false,
}
}
@@ -25,8 +23,14 @@ impl Emulator {
self.bus.ppu.tick(self.cpu.cycles);
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) {

View File

@@ -452,11 +452,13 @@ fn main() {
if !state.emulation.is_paused {
// We want to keep the emulator running
// 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()
}
// Reset the flag because otherwise the emulator will never continue running
emulator.is_frame_ending = false
}
// Render emulator framebuffer

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)
.opened(show_registers)
.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:");
for (index, register_value) in ppu_registers.registers().iter().enumerate() {
let register = (index as u16) + 0x2100;