summaryrefslogtreecommitdiff
path: root/app/test
diff options
context:
space:
mode:
authorHannes Schulze <haschu0103@outlook.de>2025-01-23 22:02:11 +0100
committerHannes Schulze <haschu0103@outlook.de>2025-01-23 22:02:11 +0100
commitb1d1573702f21e3104606d6ade5f5d39ec86a33a (patch)
treed703be130a5d6f9ff2626313d3380ed34de44dd7 /app/test
parent6512dd599d13035f6a90b2009344e02c488f5aae (diff)
restructure project
Diffstat (limited to 'app/test')
-rw-r--r--app/test/CMakeLists.txt14
-rw-r--r--app/test/main.cc76
2 files changed, 90 insertions, 0 deletions
diff --git a/app/test/CMakeLists.txt b/app/test/CMakeLists.txt
new file mode 100644
index 0000000..b88acc2
--- /dev/null
+++ b/app/test/CMakeLists.txt
@@ -0,0 +1,14 @@
+add_executable(nes_test)
+
+target_include_directories(nes_test PRIVATE .)
+target_link_libraries(
+ nes_test
+ PRIVATE
+ nes::options
+ nes::nes
+ nes::ref)
+
+target_sources(
+ nes_test
+ PRIVATE
+ main.cc) \ No newline at end of file
diff --git a/app/test/main.cc b/app/test/main.cc
new file mode 100644
index 0000000..3bb785f
--- /dev/null
+++ b/app/test/main.cc
@@ -0,0 +1,76 @@
+#include "nes/display.hh"
+#include "nes/nes.hh"
+#include "nes/util/rgb.hh"
+#include "nes/util/snapshot.hh"
+#include <iostream>
+
+namespace
+{
+ class dummy_display final : public nes::display
+ {
+ std::uint8_t buffer_a_[width * height * 3]{};
+ std::uint8_t buffer_b_[width * height * 3]{};
+ std::uint8_t* front_buffer_{ buffer_a_ };
+ std::uint8_t* back_buffer_{ buffer_b_ };
+
+ public:
+ explicit dummy_display() = default;
+
+ auto get(unsigned const x, unsigned const y) const -> nes::rgb override
+ {
+ auto const offset = ((y * width) + x) * 3;
+ return nes::rgb{ back_buffer_[offset + 0], back_buffer_[offset + 1], back_buffer_[offset + 2] };
+ }
+
+ auto set(unsigned const x, unsigned const y, nes::rgb const value) -> void override
+ {
+ auto const offset = ((y * width) + x) * 3;
+ back_buffer_[offset + 0] = value.r;
+ back_buffer_[offset + 1] = value.g;
+ back_buffer_[offset + 2] = value.b;
+ }
+
+ auto switch_buffers() -> void override
+ {
+ std::swap(front_buffer_, back_buffer_);
+ }
+ };
+} // namespace
+
+int main()
+{
+ auto const path = "/Users/hannes/Documents/temp/supermario.nes";
+
+ auto cartridge = nes::cartridge::from_file(path);
+ if (!cartridge.is_valid())
+ {
+ std::cerr << "Could not load cartridge!" << std::endl;
+ std::abort();
+ }
+
+ // Initialize the system to be tested.
+ auto display_a = std::make_unique<dummy_display>();
+ auto sys_a = nes::nes{ cartridge, *display_a };
+
+ // Initialize the (assumed to be working) reference implementation.
+ auto display_b = std::make_unique<dummy_display>();
+ auto sys_b = nes::nes{ cartridge, *display_b };
+
+ // Run.
+ while (true)
+ {
+ auto const status_a = sys_a.get_snapshot();
+ auto const status_b = sys_b.get_snapshot();
+
+ if (status_a != status_b)
+ {
+ std::cout << "Different snapshot!\n";
+ return 1;
+ }
+
+ std::cout << "Cycle: " << status_a.cpu_cycle.to_cpu() << ", " << status_b.cpu_cycle.to_cpu() << '\n';
+
+ sys_a.step_to_nmi();
+ sys_b.step_to_nmi();
+ }
+} \ No newline at end of file