diff options
| author | kotorifan <kotorifan05@gmail.com> | 2026-01-23 15:15:48 +0100 |
|---|---|---|
| committer | kotorifan <kotorifan05@gmail.com> | 2026-02-04 09:02:16 +0100 |
| commit | 32837712fedf4557ff44df7d5b8ddbd40c5f7990 (patch) | |
| tree | 671d2b82f45d5e6de70ac5d15f59ea94b884d4b6 /src/Main.cpp | |
| download | gameboy-32837712fedf4557ff44df7d5b8ddbd40c5f7990.tar.gz | |
Stupid problems with the old git repo. New one, unfortunately.
Diffstat (limited to 'src/Main.cpp')
| -rw-r--r-- | src/Main.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
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 <SDL2/SDL.h> +#include <SDL2/SDL_ttf.h> +#include <iostream> +#include <cstdlib> +#include <string> + +#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; +} + |
