diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 19:54:38 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-02-06 19:54:38 +0100 |
| commit | 64ebfde8bcd6408e3b6925624e8680c314db6efc (patch) | |
| tree | b969314f909f7f16ef5acc63f90dca317a40850a /lib/nes/sys | |
| parent | d060e3a50c987d10799ccc739bdbf9d7d7a13c10 (diff) | |
get rid of nasty stdlib
Diffstat (limited to 'lib/nes/sys')
| -rw-r--r-- | lib/nes/sys/cartridge.cc | 8 | ||||
| -rw-r--r-- | lib/nes/sys/cpu.cc | 4 | ||||
| -rw-r--r-- | lib/nes/sys/cpu.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/nes.cc | 8 | ||||
| -rw-r--r-- | lib/nes/sys/nes.hh | 6 | ||||
| -rw-r--r-- | lib/nes/sys/ppu.cc | 7 | ||||
| -rw-r--r-- | lib/nes/sys/ppu.hh | 4 | ||||
| -rw-r--r-- | lib/nes/sys/types/cycle-count.hh | 9 | ||||
| -rw-r--r-- | lib/nes/sys/types/snapshot.hh | 6 |
9 files changed, 32 insertions, 24 deletions
diff --git a/lib/nes/sys/cartridge.cc b/lib/nes/sys/cartridge.cc index 0729107..b6670a3 100644 --- a/lib/nes/sys/cartridge.cc +++ b/lib/nes/sys/cartridge.cc @@ -1,6 +1,6 @@ #include "nes/sys/cartridge.hh" #include "nes/common/status.hh" -#include <algorithm> +#include "nes/common/utils.hh" namespace nes::sys { @@ -27,16 +27,16 @@ namespace nes::sys prg_rom_size_ = h.get_prg_rom_banks() * prg_rom_bank_size; if (data.get_length() < offset + prg_rom_size_) { return; } if (prg_rom_size_ > max_prg_rom_size) { return; } - std::copy_n(&data[offset], prg_rom_size_, prg_rom_); + copy(&data[offset], prg_rom_, prg_rom_size_); offset += prg_rom_size_; chr_rom_size_ = h.get_chr_rom_banks() * chr_rom_bank_size; if (data.get_length() < offset + chr_rom_size_) { return; } if (chr_rom_size_ > max_chr_rom_size) { return; } - std::copy_n(&data[offset], chr_rom_size_, chr_rom_); + copy(&data[offset], chr_rom_, chr_rom_size_); - ram_size_ = std::max(h.get_ram_banks(), 1u) * ram_bank_size; + ram_size_ = max(h.get_ram_banks(), u32{ 1 }) * ram_bank_size; if (ram_size_ > max_ram_size) { return; } status_ = get_mapper().validate(*this); diff --git a/lib/nes/sys/cpu.cc b/lib/nes/sys/cpu.cc index 09e2094..55bbb21 100644 --- a/lib/nes/sys/cpu.cc +++ b/lib/nes/sys/cpu.cc @@ -15,6 +15,7 @@ namespace nes::sys registers_.pc = read16(address{ 0xFFFC }); } +#ifdef NES_ENABLE_SNAPSHOTS auto cpu::build_snapshot(snapshot& snapshot) -> void { snapshot.cpu_cycle = current_cycles_; @@ -33,6 +34,7 @@ namespace nes::sys snapshot.registers.v = registers_.p.get_v(); snapshot.registers.n = registers_.p.get_n(); } +#endif auto cpu::stall_cycles(cycle_count const count) -> void { @@ -1236,7 +1238,7 @@ namespace nes::sys } case addressing_mode::relative: { - auto const offset = static_cast<std::int8_t>(advance_pc8()); + auto const offset = static_cast<i8>(advance_pc8()); auto const base = address{ registers_.pc }; addr = address{ static_cast<u16>(registers_.pc + offset) }; auto const page_crossing = diff --git a/lib/nes/sys/cpu.hh b/lib/nes/sys/cpu.hh index 99753a7..795039c 100644 --- a/lib/nes/sys/cpu.hh +++ b/lib/nes/sys/cpu.hh @@ -2,6 +2,7 @@ #include "nes/sys/types/cycle-count.hh" #include "nes/sys/types/address.hh" +#include "nes/sys/types/snapshot.hh" #include "nes/common/status.hh" #include "nes/common/types.hh" @@ -10,7 +11,6 @@ namespace nes::sys class ppu; class controller; class cartridge; - struct snapshot; class cpu { @@ -138,7 +138,9 @@ namespace nes::sys auto operator=(cpu&&) -> cpu& = delete; auto get_cycles() const -> cycle_count { return current_cycles_; } +#ifdef NES_ENABLE_SNAPSHOTS auto build_snapshot(snapshot&) -> void; +#endif auto stall_cycles(cycle_count) -> void; auto trigger_nmi() -> void; auto step() -> status; diff --git a/lib/nes/sys/nes.cc b/lib/nes/sys/nes.cc index 5cc47a4..ca12190 100644 --- a/lib/nes/sys/nes.cc +++ b/lib/nes/sys/nes.cc @@ -1,5 +1,4 @@ #include "nes/sys/nes.hh" -#include "nes/sys/types/snapshot.hh" namespace nes::sys { @@ -12,11 +11,6 @@ namespace nes::sys { } - auto nes::step(std::chrono::microseconds const delta) -> void - { - step(cycle_count::from_duration(delta)); - } - auto nes::step() -> void { if (get_status() != status::success) { return; } @@ -49,6 +43,7 @@ namespace nes::sys } } +#ifdef NES_ENABLE_SNAPSHOTS auto nes::get_snapshot() -> snapshot { auto res = snapshot{}; @@ -57,4 +52,5 @@ namespace nes::sys ppu_.build_snapshot(res); return res; } +#endif } // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/nes.hh b/lib/nes/sys/nes.hh index 2533cbb..8d03dd7 100644 --- a/lib/nes/sys/nes.hh +++ b/lib/nes/sys/nes.hh @@ -1,6 +1,7 @@ #pragma once #include "nes/sys/types/cycle-count.hh" +#include "nes/sys/types/snapshot.hh" #include "nes/sys/cartridge.hh" #include "nes/sys/controller.hh" #include "nes/sys/cpu.hh" @@ -14,8 +15,6 @@ namespace nes namespace nes::sys { - struct snapshot; - /// The main console abstraction. class nes { @@ -43,10 +42,11 @@ namespace nes::sys auto ref_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; +#ifdef NES_ENABLE_SNAPSHOTS auto get_snapshot() -> snapshot; +#endif }; } // namespace nes::sys
\ No newline at end of file diff --git a/lib/nes/sys/ppu.cc b/lib/nes/sys/ppu.cc index 2419030..ce145d5 100644 --- a/lib/nes/sys/ppu.cc +++ b/lib/nes/sys/ppu.cc @@ -6,6 +6,7 @@ #include "nes/common/display.hh" #include "nes/common/rgb.hh" #include "nes/common/debug.hh" +#include "nes/common/utils.hh" namespace nes::sys { @@ -16,11 +17,13 @@ namespace nes::sys { } +#ifdef NES_ENABLE_SNAPSHOTS auto ppu::build_snapshot(snapshot& snapshot) -> void { snapshot.vram = std::vector(std::begin(vram_), std::end(vram_)); snapshot.oam = std::vector(std::begin(oam_), std::end(oam_)); } +#endif auto ppu::step() -> void { @@ -291,7 +294,7 @@ namespace nes::sys { for (auto i = u32{ 0 }; i < tile_size / 2; ++i) { - std::swap(res.colors[i], res.colors[tile_size - 1 - i]); + swap(res.colors[i], res.colors[tile_size - 1 - i]); } } @@ -382,7 +385,7 @@ namespace nes::sys if (addr % 0x4000 <= address{ 0x3EFF }) { - std::swap(res, ppudata_read_buffer_); + swap(res, ppudata_read_buffer_); } else { diff --git a/lib/nes/sys/ppu.hh b/lib/nes/sys/ppu.hh index 5697081..898ddd3 100644 --- a/lib/nes/sys/ppu.hh +++ b/lib/nes/sys/ppu.hh @@ -1,6 +1,7 @@ #pragma once #include "nes/sys/types/cycle-count.hh" +#include "nes/sys/types/snapshot.hh" #include "nes/common/containers/span.hh" #include "nes/common/types.hh" @@ -15,7 +16,6 @@ namespace nes::sys class address; class cpu; class cartridge; - struct snapshot; class ppu { @@ -239,7 +239,9 @@ namespace nes::sys auto operator=(ppu&&) -> ppu& = delete; auto get_cycles() const -> cycle_count { return current_cycles_; } +#ifdef NES_ENABLE_SNAPSHOTS auto build_snapshot(snapshot&) -> void; +#endif auto step() -> void; // Memory access diff --git a/lib/nes/sys/types/cycle-count.hh b/lib/nes/sys/types/cycle-count.hh index c977d1d..2368008 100644 --- a/lib/nes/sys/types/cycle-count.hh +++ b/lib/nes/sys/types/cycle-count.hh @@ -1,7 +1,6 @@ #pragma once #include "nes/common/types.hh" -#include <chrono> namespace nes::sys { @@ -34,9 +33,9 @@ namespace nes::sys return cycle_count{ units }; } - static constexpr auto from_duration(std::chrono::microseconds const duration) -> cycle_count + static constexpr auto from_microseconds(u64 const microseconds) -> cycle_count { - return from_units(static_cast<u64>(duration.count()) * second().get_units() / (1000 * 1000)); + return from_units(microseconds * second().get_units() / (1000 * 1000)); } static constexpr auto from_cpu(u64 const cpu_cycles) -> cycle_count @@ -52,9 +51,9 @@ namespace nes::sys /// Value in implementation-defined units. constexpr auto get_units() const -> u64 { return units_; } - constexpr auto to_duration() const -> std::chrono::microseconds + constexpr auto to_microseconds() const -> u64 { - return std::chrono::microseconds{ get_units() * 1000 * 1000 / second().get_units() }; + return get_units() * 1000 * 1000 / second().get_units(); } constexpr auto to_cpu() const -> u64 diff --git a/lib/nes/sys/types/snapshot.hh b/lib/nes/sys/types/snapshot.hh index c057aeb..ff3f6a6 100644 --- a/lib/nes/sys/types/snapshot.hh +++ b/lib/nes/sys/types/snapshot.hh @@ -1,5 +1,7 @@ #pragma once +#ifdef NES_ENABLE_SNAPSHOTS + #include "nes/sys/types/cycle-count.hh" #include "nes/common/types.hh" #include <vector> @@ -60,4 +62,6 @@ namespace nes::sys } inline auto operator!=(snapshot const& a, snapshot const& b) -> bool { return !(a == b); } -} // namespace nes::sys
\ No newline at end of file +} // namespace nes::sys + +#endif
\ No newline at end of file |
