diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 14:49:20 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-29 14:49:20 +0100 |
| commit | 5959349f341a2380c0c3f41ec40a1e8e0d969d00 (patch) | |
| tree | 8b36ba3f8cade68562af1dfdcea8b42160619975 /lib/nes/util/cycle-count.hh | |
| parent | 1d32f7561305d6c86b1c80858bc73d55b1c6c402 (diff) | |
refactor: move emulation logic into sys
Diffstat (limited to 'lib/nes/util/cycle-count.hh')
| -rw-r--r-- | lib/nes/util/cycle-count.hh | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/lib/nes/util/cycle-count.hh b/lib/nes/util/cycle-count.hh deleted file mode 100644 index f1a4a7e..0000000 --- a/lib/nes/util/cycle-count.hh +++ /dev/null @@ -1,87 +0,0 @@ -#pragma once - -#include <chrono> - -namespace nes -{ - /// A cycle count that can be used for multiple components. - /// - /// Each component can have a different clock frequency and this structure offers conversions between different - /// cycle counts. - class cycle_count - { - friend constexpr auto operator+(cycle_count, cycle_count) -> cycle_count; - friend constexpr auto operator-(cycle_count, cycle_count) -> cycle_count; - friend constexpr auto operator*(std::uint64_t, cycle_count) -> cycle_count; - friend constexpr auto operator*(cycle_count, std::uint64_t) -> cycle_count; - friend constexpr auto operator/(cycle_count, cycle_count) -> std::uint64_t; - - std::uint64_t units_{ 0 }; // The most fine-granular cycle count (here: PPU cycles). - - static constexpr auto ppu_cycle() -> cycle_count { return cycle_count{ 1 }; } - static constexpr auto cpu_cycle() -> cycle_count { return cycle_count{ 3 }; } - static constexpr auto second() -> cycle_count { return 1789773 * cpu_cycle(); } - - public: - constexpr explicit cycle_count() = default; - - constexpr auto operator+=(cycle_count const other) -> cycle_count& { return *this = *this + other; } - constexpr auto operator*=(std::uint64_t const other) -> cycle_count& { return *this = *this * other; } - - static constexpr auto from_units(std::uint64_t const units) -> cycle_count - { - return cycle_count{ units }; - } - - static constexpr auto from_duration(std::chrono::microseconds const duration) -> cycle_count - { - return from_units(static_cast<std::uint64_t>(duration.count()) * second().get_units() / (1000 * 1000)); - } - - static constexpr auto from_cpu(std::uint64_t const cpu_cycles) -> cycle_count - { - return cpu_cycles * cpu_cycle(); - } - - static constexpr auto from_ppu(std::uint64_t const ppu_cycles) -> cycle_count - { - return ppu_cycles * ppu_cycle(); - } - - /// Value in implementation-defined units. - constexpr auto get_units() const -> std::uint64_t { return units_; } - - constexpr auto to_duration() const -> std::chrono::microseconds - { - return std::chrono::microseconds{ get_units() * 1000 * 1000 / second().get_units() }; - } - - constexpr auto to_cpu() const -> std::uint64_t - { - return *this / cpu_cycle(); - } - - constexpr auto to_ppu() const -> std::uint64_t - { - return *this / ppu_cycle(); - } - - private: - constexpr explicit cycle_count(std::uint64_t const units) - : units_{ units } - { - } - }; - - constexpr auto operator==(cycle_count const a, cycle_count const b) -> bool { return a.get_units() == b.get_units(); } - constexpr auto operator!=(cycle_count const a, cycle_count const b) -> bool { return a.get_units() != b.get_units(); } - constexpr auto operator<(cycle_count const a, cycle_count const b) -> bool { return a.get_units() < b.get_units(); } - constexpr auto operator>(cycle_count const a, cycle_count const b) -> bool { return a.get_units() > b.get_units(); } - constexpr auto operator<=(cycle_count const a, cycle_count const b) -> bool { return a.get_units() <= b.get_units(); } - constexpr auto operator>=(cycle_count const a, cycle_count const b) -> bool { return a.get_units() >= b.get_units(); } - constexpr auto operator+(cycle_count const a, cycle_count const b) -> cycle_count { return cycle_count{ a.get_units() + b.get_units() }; } - constexpr auto operator-(cycle_count const a, cycle_count const b) -> cycle_count { return cycle_count{ a.get_units() - b.get_units() }; } - constexpr auto operator*(std::uint64_t const a, cycle_count const b) -> cycle_count { return cycle_count{ a * b.get_units() }; } - constexpr auto operator*(cycle_count const a, std::uint64_t const b) -> cycle_count { return cycle_count{ a.get_units() * b }; } - constexpr auto operator/(cycle_count const a, cycle_count const b) -> std::uint64_t { return a.get_units() / b.get_units(); } -} // namespace nes
\ No newline at end of file |
