blob: 6c3adf1cb2a4ff4d90b09880e6778eb613eabe22 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
|