blob: f02b66b296626f6c2bf4570243a0b79eabeb7bff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#pragma once
#include <cstdint>
namespace nes
{
/// An address on the NES.
class address
{
std::uint16_t absolute_{ 0 };
public:
/// Create a zero address.
explicit address() = default;
/// Create an address from its absolute value.
explicit address(std::uint16_t const absolute)
: absolute_{ absolute }
{
}
/// Get the absolute address value.
auto get_absolute() const -> std::uint16_t
{
return absolute_;
}
/// Get the address page (the first 8 bits).
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
{
return static_cast<std::uint8_t>((get_absolute() & 0x00FF) >> 0);
}
};
} // namespace nes
|