From fcfd27468d6198fd7623368ecaa0e2185591a731 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 28 Sep 2022 14:45:44 +0200 Subject: [PATCH] Emulator: Change main to become an Inferno application --- src/loader.cpp | 9 --------- src/loader.h | 1 - src/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++------------ 3 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/loader.cpp b/src/loader.cpp index c5d95b5..3dbb304 100644 --- a/src/loader.cpp +++ b/src/loader.cpp @@ -78,15 +78,6 @@ void Loader::init() Emu::the().writeMemory(i, bootrom[i]); } - - update(); -} - -void Loader::update() -{ - while (true) { - Emu::the().update(); - } } void Loader::destroy() diff --git a/src/loader.h b/src/loader.h index 5200a7d..a39a5b4 100644 --- a/src/loader.h +++ b/src/loader.h @@ -22,7 +22,6 @@ public: private: void init(); - void update(); void destroy(); void loadCartridgeHeader(); diff --git a/src/main.cpp b/src/main.cpp index 6d26077..09aac01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,24 +5,53 @@ * SPDX-License-Identifier: MIT */ -#include "loader.h" +#include + +#include "inferno.h" +#include "inferno/entrypoint.h" #include "ruc/argparser.h" #include "ruc/format/print.h" #include "ruc/timer.h" -#include -int main(int argc, const char* argv[]) -{ - std::string_view bootrom_path = "gbc_bios.bin"; - std::string_view rom_path; +#include "emu.h" +#include "loader.h" - ruc::ArgParser argParser; - argParser.addOption(bootrom_path, 'b', "bootrom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes); - argParser.addOption(rom_path, 'r', "rom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes); - argParser.parse(argc, argv); +class GarbAGE final : public Inferno::Application { +public: + GarbAGE(int argc, char* argv[]) + : Application() + { + std::string_view bootrom_path = "gbc_bios.bin"; + std::string_view rom_path; - Loader::the().setBootromPath(bootrom_path); - Loader::the().loadRom(rom_path); + ruc::ArgParser argParser; + argParser.addOption(bootrom_path, 'b', "bootrom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes); + argParser.addOption(rom_path, 'r', "rom", nullptr, nullptr, "", ruc::ArgParser::Required::Yes); + argParser.parse(argc, argv); - return 0; + Loader::the().setBootromPath(bootrom_path); + Loader::the().loadRom(rom_path); + } + + ~GarbAGE() + { + } + + void update() override + { + // 154 scanlines * 456 cycles = 70224 cycles per frame + for (int i = 0; i < (144 * 456 + 10 * 456); ++i) { + Emu::the().update(); + } + } + + void render() override + { + } +}; + +Inferno::Application* Inferno::createApplication(int argc, char* argv[]) +{ + GarbAGE* gameboy = new GarbAGE(argc, argv); + return gameboy; }