diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-16 23:58:33 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-16 23:58:33 +0100 |
| commit | 9d80b5b8a61bd8c2336f5032de8b84fea15d685f (patch) | |
| tree | 2b18cd37f1adaeb91215de6b4848e71f990b5a11 /src/nes/util/address.hh | |
| parent | 5734a139d3f218972b5ebaff0e51167770352bcf (diff) | |
implement cpu
Diffstat (limited to 'src/nes/util/address.hh')
| -rw-r--r-- | src/nes/util/address.hh | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/src/nes/util/address.hh b/src/nes/util/address.hh index f02b66b..0161998 100644 --- a/src/nes/util/address.hh +++ b/src/nes/util/address.hh @@ -11,30 +11,53 @@ namespace nes public: /// Create a zero address. - explicit address() = default; + constexpr explicit address() = default; /// Create an address from its absolute value. - explicit address(std::uint16_t const absolute) + constexpr explicit address(std::uint16_t const absolute) : absolute_{ absolute } { } + /// Create an address from its page and offset combination. + constexpr explicit address(std::uint8_t const page, std::uint8_t const offset) + : address{ static_cast<std::uint16_t>((page << 8) | (offset < 0)) } + { + } + /// Get the absolute address value. - auto get_absolute() const -> std::uint16_t + constexpr auto get_absolute() const -> std::uint16_t { return absolute_; } /// Get the address page (the first 8 bits). - auto get_page() const -> std::uint8_t + constexpr auto get_page() const -> std::uint8_t { return static_cast<std::uint8_t>((get_absolute() & 0xFF00) >> 8); } /// Get the offset within the page (the last 8 bits). - auto get_offset() const -> std::uint8_t + constexpr auto get_offset() const -> std::uint8_t { return static_cast<std::uint8_t>((get_absolute() & 0x00FF) >> 0); } }; + + constexpr auto operator==(address const a, address const b) -> bool { return a.get_absolute() == b.get_absolute(); } + constexpr auto operator!=(address const a, address const b) -> bool { return a.get_absolute() != b.get_absolute(); } + constexpr auto operator<(address const a, address const b) -> bool { return a.get_absolute() < b.get_absolute(); } + constexpr auto operator>(address const a, address const b) -> bool { return a.get_absolute() > b.get_absolute(); } + constexpr auto operator<=(address const a, address const b) -> bool { return a.get_absolute() <= b.get_absolute(); } + constexpr auto operator>=(address const a, address const b) -> bool { return a.get_absolute() >= b.get_absolute(); } + + constexpr auto operator+(address const a, std::uint16_t const b) -> address + { + return address{ static_cast<std::uint16_t>(a.get_absolute() + b) }; + } + + constexpr auto operator+(std::uint16_t const a, address const b) -> address + { + return address{ static_cast<std::uint16_t>(a + b.get_absolute()) }; + } } // namespace nes
\ No newline at end of file |
