From: chaoskagami Date: Sun, 26 Jun 2016 03:25:22 +0000 (-0400) Subject: * Added screenshot function - L+R+Start and wait a bit - saves a binary ppm to ... X-Git-Tag: v0.2.0~56 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=da10c87f3153eb74097aec6cb3dc7ee2cc2dd65a;p=corbenik%2Fcorbenik.git * Added screenshot function - L+R+Start and wait a bit - saves a binary ppm to /corbenik/cache/screenshot.ppm * Tweaked menu delay some more (it was too slow) --- diff --git a/source/menu.c b/source/menu.c index 6084722..7d7bf29 100644 --- a/source/menu.c +++ b/source/menu.c @@ -1,6 +1,7 @@ #include "common.h" #include "firm/firm.h" #include "firm/headers.h" +#include "std/unused.h" #define MAX_PATCHES ((FCRAM_SPACING / 2) / sizeof(struct options_s)) struct options_s *patches = (struct options_s *)FCRAM_MENU_LOC; @@ -58,10 +59,11 @@ static struct options_s options[] = { extern void waitcycles(uint32_t cycles); uint32_t -wait_key(int sleep) +wait_key(_UNUSED int sleep) { + // If your dpad has issues, please add this to the makefile. if (sleep) { - #define ARM9_APPROX_DELAY_MAX 134058675 / 85 + #define ARM9_APPROX_DELAY_MAX 134058675 / 95 waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) } @@ -69,7 +71,10 @@ wait_key(int sleep) while (ret == 0) { get = HID_PAD; - if (get & BUTTON_UP) + if ((get & (BUTTON_L | BUTTON_R | BUTTON_STA)) == (BUTTON_L | BUTTON_R | BUTTON_STA)) { + screenshot(); + waitcycles(ARM9_APPROX_DELAY_MAX); // Approximately what a human can input - fine tuning needed (sorry, TASers!) + } else if (get & BUTTON_UP) ret = BUTTON_UP; else if (get & BUTTON_DOWN) ret = BUTTON_DOWN; diff --git a/source/std/draw.c b/source/std/draw.c index 49327a0..6252551 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -30,6 +30,54 @@ static unsigned int text_bottom_height = 10; uint8_t top_bg[TOP_SIZE]; uint8_t bottom_bg[BOTTOM_SIZE]; +// This is (roughly) the screenshot specs as used by smeas scrtool. +void screenshot() { + f_unlink(PATH_TEMP "/screenshot.ppm"); + + // Open the screenshot blob used by hbmenu et al + FILE* f = fopen(PATH_TEMP "/screenshot.ppm", "w"); + + if (!f) return; + + fwrite("P6 400 480 255 ", 1, 15, f); + + for(int y = 0; y < 240; y++) { + for(int x = 0; x < 400; x++) { + int xDisplacement = (x * SCREEN_DEPTH * 240); + int yDisplacement = ((240 - y - 1) * SCREEN_DEPTH); + int pos = xDisplacement + yDisplacement; + + fwrite(& framebuffers->top_left[pos + 2], 1, 1, f); + fwrite(& framebuffers->top_left[pos + 1], 1, 1, f); + fwrite(& framebuffers->top_left[pos], 1, 1, f); + } + } + + uint8_t zero = 0; + + for(int y = 0; y < 240; y++) { + for (int i = 0; i < 40 * 3; i++) + fwrite(& zero, 1, 1, f); + + for (int x = 0; x < 320; x++) { + int xDisplacement = (x * SCREEN_DEPTH * 240); + int yDisplacement = ((240 - y - 1) * SCREEN_DEPTH); + int pos = xDisplacement + yDisplacement; + + fwrite(& framebuffers->bottom[pos + 2], 1, 1, f); + fwrite(& framebuffers->bottom[pos + 1], 1, 1, f); + fwrite(& framebuffers->bottom[pos], 1, 1, f); + } + + for (int i = 0; i < 40 * 3; i++) + fwrite(& zero, 1, 1, f); + } + + fclose(f); + + fprintf(stderr, "Screenshot: %s\n", PATH_TEMP "/screenshot.ppm"); +} + void clear_bg() { memset(top_bg, 0, TOP_SIZE); memset(bottom_bg, 0, BOTTOM_SIZE); diff --git a/source/std/draw.h b/source/std/draw.h index 40d9ea7..f9443ad 100644 --- a/source/std/draw.h +++ b/source/std/draw.h @@ -37,6 +37,8 @@ _UNUSED static struct framebuffers #define TOP_FB framebuffers->top_left #define BOTTOM_FB framebuffers->bottom +void screenshot(); + void clear_bg(); void load_bg_top(char* fname_top); void load_bg_bottom(char* fname_bottom);