summaryrefslogtreecommitdiff
path: root/src/nes/util
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-01-13 23:04:30 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-01-13 23:04:50 +0100
commita2edbedb520f2ada936c00308cc6dfd75717b0d8 (patch)
tree65a387b92abaa3105a7090e59c562fd15ef3b636 /src/nes/util
parent02f963a4bab95b3a328b6a792c9a7e027ade0e26 (diff)
read cartridges
Diffstat (limited to 'src/nes/util')
-rw-r--r--src/nes/util/CMakeLists.txt1
-rw-r--r--src/nes/util/address.hh40
2 files changed, 41 insertions, 0 deletions
diff --git a/src/nes/util/CMakeLists.txt b/src/nes/util/CMakeLists.txt
index c2255dd..1d30125 100644
--- a/src/nes/util/CMakeLists.txt
+++ b/src/nes/util/CMakeLists.txt
@@ -1,4 +1,5 @@
target_sources(
nes
PRIVATE
+ address.hh
rgb.hh) \ No newline at end of file
diff --git a/src/nes/util/address.hh b/src/nes/util/address.hh
new file mode 100644
index 0000000..f02b66b
--- /dev/null
+++ b/src/nes/util/address.hh
@@ -0,0 +1,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 \ No newline at end of file