From bdb2114b9d2557c6700f3176128a0488a779421e Mon Sep 17 00:00:00 2001 From: Hannes Schulze Date: Thu, 23 Jan 2025 23:18:42 +0100 Subject: some cleanup --- lib/nes/cpu.hh | 4 ++-- lib/nes/nes.cc | 27 ++++++++++++--------------- lib/nes/nes.hh | 3 ++- lib/nes/ppu.cc | 13 ++----------- lib/nes/ppu.hh | 1 - 5 files changed, 18 insertions(+), 30 deletions(-) (limited to 'lib/nes') diff --git a/lib/nes/cpu.hh b/lib/nes/cpu.hh index 9511c09..56ec4b0 100644 --- a/lib/nes/cpu.hh +++ b/lib/nes/cpu.hh @@ -80,8 +80,8 @@ namespace nes public: explicit operand(cpu& cpu, address const address, cycle_count const cycles) : cpu_{ cpu } - , address_{ address } - , cycles_{ cycles } + , address_{ address } + , cycles_{ cycles } { } diff --git a/lib/nes/nes.cc b/lib/nes/nes.cc index cd0c39b..498ecd7 100644 --- a/lib/nes/nes.cc +++ b/lib/nes/nes.cc @@ -30,16 +30,21 @@ namespace nes step(cycle_count::from_duration(delta)); } + auto nes::step() -> void + { + cpu_.step(); + while (ppu_.get_cycles() < cpu_.get_cycles()) + { + ppu_.step(); + } + } + auto nes::step(cycle_count const delta) -> void { current_cycles_ += delta; while (cpu_.get_cycles() < current_cycles_) { - cpu_.step(); - while (ppu_.get_cycles() < cpu_.get_cycles()) - { - ppu_.step(); - } + step(); } } @@ -47,19 +52,11 @@ namespace nes { while (cpu_.is_nmi_pending()) { - cpu_.step(); - while (ppu_.get_cycles() < cpu_.get_cycles()) - { - ppu_.step(); - } + step(); } while (!cpu_.is_nmi_pending()) { - cpu_.step(); - while (ppu_.get_cycles() < cpu_.get_cycles()) - { - ppu_.step(); - } + step(); } } diff --git a/lib/nes/nes.hh b/lib/nes/nes.hh index fe57cd4..79d4a8e 100644 --- a/lib/nes/nes.hh +++ b/lib/nes/nes.hh @@ -37,9 +37,10 @@ namespace nes auto get_controller_2() const -> controller const& { return controller_2_; } auto get_controller_2() -> controller& { return controller_2_; } + auto step() -> void; auto step(std::chrono::microseconds delta) -> void; auto step(cycle_count delta) -> void; - auto step_to_nmi() -> void; // XXX: Debugging + auto step_to_nmi() -> void; auto get_snapshot() -> snapshot; }; diff --git a/lib/nes/ppu.cc b/lib/nes/ppu.cc index 23a41fb..0f56c96 100644 --- a/lib/nes/ppu.cc +++ b/lib/nes/ppu.cc @@ -131,7 +131,7 @@ namespace nes { display_.switch_buffers(); status_.vblank = true; - nmi_change(); + if (control_.vblank_nmi) { cpu_.trigger_nmi(); } } if (pre_line && scanline_cycle_ == 1) { @@ -514,7 +514,7 @@ namespace nes NES_DEBUG_LOG(ppu, "PPUCTRL <- {:#2x}", value); control_.value = value; internal_.t = static_cast((internal_.t & 0xF3FF) | ((value & 0x03) << 10)); - nmi_change(); + if (control_.vblank_nmi && status_.vblank) { cpu_.trigger_nmi(); } } } @@ -598,7 +598,6 @@ namespace nes auto ppu::write_oamdma(std::uint8_t const value) -> void { - // TODO: Do this in CPU::step instead in case there's an NMI? NES_DEBUG_LOG(ppu, "OAMDMA <- {:#2x}", value); auto addr = address{ value, 0x00 }; for (auto i = unsigned{ 0 }; i < 256; ++i) @@ -616,14 +615,6 @@ namespace nes // Helpers // ----------------------------------------------------------------------------------------------------------------- - auto ppu::nmi_change() -> void - { - if (control_.vblank_nmi && status_.vblank) - { - cpu_.trigger_nmi(); - } - } - auto ppu::sprite_height() -> unsigned { switch (control_.sprite_size) diff --git a/lib/nes/ppu.hh b/lib/nes/ppu.hh index d7d9baa..4961964 100644 --- a/lib/nes/ppu.hh +++ b/lib/nes/ppu.hh @@ -199,7 +199,6 @@ namespace nes // Helpers - auto nmi_change() -> void; auto sprite_height() -> unsigned; auto increment_vram() -> void; auto get_color(color_index) -> color&; -- cgit v1.3.1