]> Chaos Git - corbenik/corbenik.git/commitdiff
* Added screenshot function - L+R+Start and wait a bit - saves a binary ppm to ...
authorchaoskagami <chaos.kagami@gmail.com>
Sun, 26 Jun 2016 03:25:22 +0000 (23:25 -0400)
committerchaoskagami <chaos.kagami@gmail.com>
Sun, 26 Jun 2016 03:26:45 +0000 (23:26 -0400)
 * Tweaked menu delay some more (it was too slow)

source/menu.c
source/std/draw.c
source/std/draw.h

index 608472244bd5536f9c9b0d5ef56399f364b5b8bf..7d7bf29b29c0268337ac88f947e82822334d8377 100644 (file)
@@ -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;
index 49327a0b5b42a17c3999b32238c9326d46e58f7f..6252551fe8e7b43319fc93b0fd390f6a3c7d6912 100644 (file)
@@ -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);
index 40d9ea7b747cf691dbe4ed4bd7337e313cabf323..f9443ad3545554a5c3fef1120e90a32bfcea1cba 100644 (file)
@@ -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);