From 32837712fedf4557ff44df7d5b8ddbd40c5f7990 Mon Sep 17 00:00:00 2001 From: kotorifan Date: Fri, 23 Jan 2026 15:15:48 +0100 Subject: Stupid problems with the old git repo. New one, unfortunately. --- src/Main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/Main.cpp (limited to 'src/Main.cpp') diff --git a/src/Main.cpp b/src/Main.cpp new file mode 100644 index 0000000..6c3adf1 --- /dev/null +++ b/src/Main.cpp @@ -0,0 +1,54 @@ +#include +#include +#include +#include +#include + +#include "SDL_stuff.hpp" +#include "Debugger.hpp" +#include "Processor.hpp" +#include "Memory.hpp" +#include "Common.hpp" + +static inline void show_help() +{ + std::cout << "Usage: ./PROGRAM_NAME [EXECUTABLE] [OPTIONS]\n"; + std::cout << "Emulate a given DMG-01 ROM/executable.\n"; + std::cout << "The first argument is always the file to be executed\n"; +} + + +int main(int argc, char* argv[]) +{ + if(argc < 2) { + show_help(); + return EXIT_FAILURE; + } + DMG01::SM83 sm83; + DMG01::Memory memory; + std::string exec_file(argv[1]); + sm83.load_bin(exec_file, memory); + DMG01::Generic_SDL_Window debugger_window(800, 600); + debugger_window.create_window(); + debugger_window.update_text("Debugger started."); + static bool should_display = true; + sm83.stop_state = false; + while((sm83.pc < DMG01::MEMORY_SIZE) && should_display) { + char buffer[256]; + if(!sm83.stop_state) { + const uint8_t opcode = memory.space[sm83.pc]; + sm83.pc++; + sm83.process_opcodes(opcode, memory, sm83); + } + should_display = debugger_window.check_polling_event(); + snprintf(buffer, sizeof(buffer), + "PC: 0x%04X SP: 0x%04X 0x%04X BC: 0x%04X DE: 0x%04X HL: 0x%04X", + sm83.pc, sm83.sp, sm83.af.word, sm83.bc.word, sm83.de.word, sm83.hl.word); + debugger_window.update_text(buffer); + debugger_window.render_text(); + + SDL_Delay(1); + } + return EXIT_SUCCESS; +} + -- cgit v1.3