diff --git a/cpp/src/args.cpp b/cpp/src/args.cpp index 39a8e49..cc343db 100644 --- a/cpp/src/args.cpp +++ b/cpp/src/args.cpp @@ -13,6 +13,7 @@ Args::Args(int argc, char *argv[]) { args::Flag debug_ram(parser, "debug-ram", "Debug RAM", {'a', "debug-ram"}); args::ValueFlag frames(parser, "frames", "Exit after N frames", {'f', "frames"}); args::ValueFlag profile(parser, "profile", "Exit after N seconds", {'p', "profile"}); + args::ValueFlag screenshot(parser, "screenshot", "Write a BMP to this file on exit", {'s', "screenshot"}); args::Flag turbo(parser, "turbo", "No sleep between frames", {'t', "turbo"}); args::Flag version(parser, "version", "Show build info", {'v', "version"}); args::Positional rom(parser, "rom", "Path to a .gb file"); @@ -48,6 +49,7 @@ Args::Args(int argc, char *argv[]) { this->debug_ram = debug_ram; this->frames = frames ? args::get(frames) : 0; this->profile = profile ? args::get(profile) : 0; + this->screenshot = screenshot ? args::get(screenshot) : ""; this->turbo = turbo; this->rom = args::get(rom); } diff --git a/cpp/src/args.h b/cpp/src/args.h index ace5fcc..acaa6be 100644 --- a/cpp/src/args.h +++ b/cpp/src/args.h @@ -15,6 +15,7 @@ class Args { bool debug_ram; int frames; int profile; + std::string screenshot; bool turbo; std::string rom; }; diff --git a/cpp/src/gameboy.cpp b/cpp/src/gameboy.cpp index 2745764..4ad9c52 100644 --- a/cpp/src/gameboy.cpp +++ b/cpp/src/gameboy.cpp @@ -4,7 +4,7 @@ GameBoy::GameBoy(Args *args) { this->cart = new Cart(args->rom); this->ram = new RAM(this->cart, args->debug_ram); this->cpu = new CPU(this->ram, args->debug_cpu); - this->gpu = new GPU(this->cpu, cart->name, args->headless, args->debug_gpu); + this->gpu = new GPU(this->cpu, cart->name, args->screenshot, args->headless, args->debug_gpu); this->buttons = new Buttons(this->cpu, args->headless); if(!args->silent) new APU(this->cpu, args->debug_apu); this->clock = new Clock(this->buttons, args->frames, args->profile, args->turbo); diff --git a/cpp/src/gpu.cpp b/cpp/src/gpu.cpp index af5deab..0c897ca 100644 --- a/cpp/src/gpu.cpp +++ b/cpp/src/gpu.cpp @@ -18,7 +18,8 @@ u32 bmask = 0x00ff0000; u32 amask = 0xff000000; #endif -GPU::GPU(CPU *cpu, char *title, bool headless, bool debug) { +GPU::GPU(CPU *cpu, char *title, std::string screenshot, bool headless, bool debug) { + this->screenshot = screenshot; this->cpu = cpu; this->debug = debug; @@ -62,6 +63,10 @@ GPU::GPU(CPU *cpu, char *title, bool headless, bool debug) { }; GPU::~GPU() { + std::cout << "Screenshot " << this->screenshot << "\n"; + if(this->screenshot.length() > 0) { + SDL_SaveBMP(this->buffer, this->screenshot.c_str()); + } SDL_FreeSurface(this->buffer); if(this->hw_window) SDL_DestroyWindow(this->hw_window); SDL_Quit(); @@ -355,4 +360,4 @@ SDL_Color gen_hue(u8 n) { } } -bool Sprite::is_live() { return x > 0 && x < 168 && y > 0 && y < 160; } \ No newline at end of file +bool Sprite::is_live() { return x > 0 && x < 168 && y > 0 && y < 160; } diff --git a/cpp/src/gpu.h b/cpp/src/gpu.h index 0dc88b3..2faced6 100644 --- a/cpp/src/gpu.h +++ b/cpp/src/gpu.h @@ -51,6 +51,7 @@ struct Sprite { class GPU { private: bool debug; + std::string screenshot; SDL_Window *hw_window; SDL_Texture *hw_buffer; SDL_Renderer *hw_renderer; @@ -62,7 +63,7 @@ class GPU { CPU *cpu; public: - GPU(CPU *cpu, char *title, bool headless, bool debug); + GPU(CPU *cpu, char *title, std::string screenshot, bool headless, bool debug); ~GPU(); void tick();