diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-01-30 16:43:06 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-01-31 00:02:26 +0100 |
| commit | 307e07d6513f9524b7fcab5134494bd175465cd1 (patch) | |
| tree | ce025db2ea998bdcd8980a0ed443083f0daf8d35 /lib/nes/app/application.cc | |
| parent | 5959349f341a2380c0c3f41ec40a1e8e0d969d00 (diff) | |
handle input devices in the c++ application
Diffstat (limited to 'lib/nes/app/application.cc')
| -rw-r--r-- | lib/nes/app/application.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/nes/app/application.cc b/lib/nes/app/application.cc new file mode 100644 index 0000000..db43854 --- /dev/null +++ b/lib/nes/app/application.cc @@ -0,0 +1,38 @@ +#include "nes/app/application.hh" +#include "nes/app/input/input-device-keyboard.hh" +#include "nes/app/input/input-device-controller.hh" +#include <iostream> + +namespace nes +{ + namespace + { + constexpr auto file = std::string_view{ "/Users/hannes/Documents/temp/supermario.nes" }; + } // namespace + + application::application(display& display, input_device_keyboard& keyboard) + : display_{ display } + , input_manager_{ keyboard } + , console_{ cartridge::from_file(file), display_ } + { + if (console_.get_status() != status::success) + { + std::cerr << "Unable to load cartridge: " << to_string(console_.get_status()) << std::endl; + std::abort(); + } + } + + auto application::frame(std::chrono::microseconds const elapsed_time) -> void + { + console_.ref_controller_1().set_pressed(input_manager_.get_input_1().read_mask()); + console_.ref_controller_2().set_pressed(input_manager_.get_input_2().read_mask()); + + console_.step(elapsed_time); + + if (console_.get_status() != status::success) + { + std::cerr << "Invalid state: " << to_string(console_.get_status()) << std::endl; + std::abort(); + } + } +} // namespace nes
\ No newline at end of file |
