diff --git a/source/hid/hid.c b/source/hid/hid.c index 237bfa1..22ea151 100644 --- a/source/hid/hid.c +++ b/source/hid/hid.c @@ -5,6 +5,8 @@ #include #include #include "../utils/utils.h" +#include "../tegraexplorer/tools.h" +#include static Input_t inputs = {0}; u16 LbaseX = 0, LbaseY = 0, RbaseX = 0, RbaseY = 0; @@ -22,6 +24,11 @@ Input_t *hidRead(){ if (controller->home) RebootToPayloadOrRcm(); + #ifdef TAKESCREENSHOT + if (controller->cap) + TakeScreenshot(); + #endif + inputs.buttons = controller->buttons; u8 btn = btn_read(); diff --git a/source/tegraexplorer/tools.c b/source/tegraexplorer/tools.c index 32c8619..b0676a6 100644 --- a/source/tegraexplorer/tools.c +++ b/source/tegraexplorer/tools.c @@ -196,4 +196,66 @@ void FormatSD(){ free(work); hidWait(); +} + +extern bool sd_mounted; + +void TakeScreenshot(){ + static u32 timer = 0; + + if (!TConf.minervaEnabled || !sd_mounted) + return; + + if (timer + 3 < get_tmr_s()) + timer = get_tmr_s(); + else + return; + + char *name, *path; + const char basepath[] = "sd:/tegraexplorer/screenshots"; + name = malloc(40); + sprintf(name, "Screenshot_%08X.bmp", get_tmr_us()); + + f_mkdir("sd:/tegraexplorer"); + f_mkdir(basepath); + path = CombinePaths(basepath, name); + free(name); + + const u32 file_size = 0x384000 + 0x36; + u8 *bitmap = malloc(file_size); + u32 *fb = malloc(0x384000); + u32 *fb_ptr = gfx_ctxt.fb; + + for (int x = 1279; x >= 0; x--) + { + for (int y = 719; y >= 0; y--) + fb[y * 1280 + x] = *fb_ptr++; + } + + memcpy(bitmap + 0x36, fb, 0x384000); + bmp_t *bmp = (bmp_t *)bitmap; + + bmp->magic = 0x4D42; + bmp->size = file_size; + bmp->rsvd = 0; + bmp->data_off = 0x36; + bmp->hdr_size = 40; + bmp->width = 1280; + bmp->height = 720; + bmp->planes = 1; + bmp->pxl_bits = 32; + bmp->comp = 0; + bmp->img_size = 0x384000; + bmp->res_h = 2834; + bmp->res_v = 2834; + bmp->rsvd2 = 0; + + sd_save_to_file(bitmap, file_size, path); + free(bitmap); + free(fb); + free(path); + + display_backlight_brightness(255, 1000); + msleep(100); + display_backlight_brightness(100, 1000); } \ No newline at end of file diff --git a/source/tegraexplorer/tools.h b/source/tegraexplorer/tools.h index ae09b61..c4e8b2f 100644 --- a/source/tegraexplorer/tools.h +++ b/source/tegraexplorer/tools.h @@ -1,4 +1,24 @@ #pragma once +#include + +typedef struct _bmp_t +{ + u16 magic; + u32 size; + u32 rsvd; + u32 data_off; + u32 hdr_size; + u32 width; + u32 height; + u16 planes; + u16 pxl_bits; + u32 comp; + u32 img_size; + u32 res_h; + u32 res_v; + u64 rsvd2; +} __attribute__((packed)) bmp_t; void DumpSysFw(); -void FormatSD(); \ No newline at end of file +void FormatSD(); +void TakeScreenshot(); \ No newline at end of file