diff --git a/source/draw.c b/source/draw.c index 22de0dd..14d8e4e 100644 --- a/source/draw.c +++ b/source/draw.c @@ -83,46 +83,6 @@ void DrawStringF(bool use_top, int x, int y, int color, int bgcolor, const char } } -/*void Screenshot(const char* path) -{ - u8* buffer = (u8*) 0x21000000; // careful, this area is used by other functions in Decrypt9 - u8* buffer_t = buffer + (400 * 240 * 3); - u8 bmp_header[54] = { - 0x42, 0x4D, 0x36, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, - 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xCA, 0x08, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 - }; - static u32 n = 0; - - if (path == NULL) { - for (; n < 1000; n++) { - char filename[16]; - snprintf(filename, 16, "snap%03i.bmp", (int) n); - if (!FileOpen(filename)) { - FileCreate(filename, true); - break; - } - FileClose(); - } - if (n >= 1000) - return; - } else { - FileCreate(path, true); - } - - memset(buffer, 0x1F, 400 * 240 * 3 * 2); - for (u32 x = 0; x < 400; x++) - for (u32 y = 0; y < 240; y++) - memcpy(buffer_t + (y*400 + x) * 3, TOP_SCREEN0 + (x*240 + y) * 3, 3); - for (u32 x = 0; x < 320; x++) - for (u32 y = 0; y < 240; y++) - memcpy(buffer + (y*400 + x + 40) * 3, BOT_SCREEN0 + (x*240 + y) * 3, 3); - FileWrite(bmp_header, 54, 0); - FileWrite(buffer, 400 * 240 * 3 * 2, 54); - FileClose(); -}*/ - void ShowError(const char *format, ...) { char str[128] = {}; // 128 should be more than enough diff --git a/source/draw.h b/source/draw.h index 321037b..d387c49 100644 --- a/source/draw.h +++ b/source/draw.h @@ -39,7 +39,5 @@ void DrawCharacter(unsigned char *screen, int character, int x, int y, int color void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor); void DrawStringF(bool use_top, int x, int y, int color, int bgcolor, const char *format, ...); -void Screenshot(const char* path); - void ShowError(const char *format, ...); void ShowProgress(u64 current, u64 total); diff --git a/source/fatfs/diskio.c b/source/fatfs/diskio.c index 7617f93..ffd7dfd 100644 --- a/source/fatfs/diskio.c +++ b/source/fatfs/diskio.c @@ -122,7 +122,7 @@ DRESULT disk_read ( /*-----------------------------------------------------------------------*/ /* Write Sector(s) */ /*-----------------------------------------------------------------------*/ -#undef _USE_WRITE + #if _USE_WRITE DRESULT disk_write ( __attribute__((unused)) diff --git a/source/fatfs/ffconf.h b/source/fatfs/ffconf.h index 283b195..cc64648 100644 --- a/source/fatfs/ffconf.h +++ b/source/fatfs/ffconf.h @@ -16,7 +16,7 @@ / data transfer. */ -#define _FS_READONLY 1 +#define _FS_READONLY 0 /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) / Read-only configuration removes writing API functions, f_write(), f_sync(), / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() diff --git a/source/fs.c b/source/fs.c index e94e9a1..cd0b5e4 100644 --- a/source/fs.c +++ b/source/fs.c @@ -8,7 +8,7 @@ static FATFS* fs = (FATFS*)0x20316000; // reserve one MB for this, just to be safe static DirStruct* curdir_contents = (DirStruct*)0x21000000; // this is the main buffer -// static u8* main_buffer = (u8*)0x21100000; +static u8* main_buffer = (u8*)0x21100000; // number of currently open file systems static u32 numfs = 0; @@ -44,8 +44,51 @@ void DeinitFS() numfs = 0; } -bool GetRootDirContentsWorker(DirStruct* contents) +bool FileExists(const char* path) { + return (f_stat(path, NULL) == FR_OK); +} + +bool FileCreate(const char* path, u8* data, u32 size) { + FIL file; + UINT bytes_written = 0; + if (f_open(&file, path, FA_READ | FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) + return false; + f_write(&file, data, size, &bytes_written); + f_close(&file); + return (bytes_written == size); +} + +void Screenshot() { + const u8 bmp_header[54] = { + 0x42, 0x4D, 0x36, 0xCA, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, + 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0xE0, 0x01, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xCA, 0x08, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }; + u8* buffer = main_buffer + 54; + u8* buffer_t = buffer + (400 * 240 * 3); + char filename[16]; + static u32 n = 0; + + for (; n < 1000; n++) { + snprintf(filename, 16, "0:/snap%03i.bmp", (int) n); + if (!FileExists(filename)) break; + } + if (n >= 1000) return; + + memcpy(main_buffer, bmp_header, 54); + memset(buffer, 0x1F, 400 * 240 * 3 * 2); + for (u32 x = 0; x < 400; x++) + for (u32 y = 0; y < 240; y++) + memcpy(buffer_t + (y*400 + x) * 3, TOP_SCREEN0 + (x*240 + y) * 3, 3); + for (u32 x = 0; x < 320; x++) + for (u32 y = 0; y < 240; y++) + memcpy(buffer + (y*400 + x + 40) * 3, BOT_SCREEN0 + (x*240 + y) * 3, 3); + FileCreate(filename, main_buffer, 54 + (400 * 240 * 3 * 2)); +} + +bool GetRootDirContentsWorker(DirStruct* contents) { static const char* drvname[16] = { "SDCARD", "SYSCTRN", "SYSTWLN", "SYSTWLP", @@ -68,8 +111,7 @@ bool GetRootDirContentsWorker(DirStruct* contents) return contents->n_entries; } -bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recursive) -{ +bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recursive) { DIR pdir; FILINFO fno; char* fname = fpath + strnlen(fpath, fsize - 1); @@ -114,8 +156,7 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recu return ret; } -DirStruct* GetDirContents(const char* path) -{ +DirStruct* GetDirContents(const char* path) { curdir_contents->n_entries = 0; if (strncmp(path, "", 256) == 0) { // root directory if (!GetRootDirContentsWorker(curdir_contents)) diff --git a/source/fs.h b/source/fs.h index fa92060..f5411d0 100644 --- a/source/fs.h +++ b/source/fs.h @@ -27,6 +27,15 @@ typedef struct { bool InitFS(); void DeinitFS(); +/** Check if file exists **/ +bool FileExists(const char* path); + +/** Create / overwrite file and write the provided data to it **/ +bool FileCreate(const char* path, u8* data, u32 size); + +/** Create a screenshot of the current framebuffer **/ +void Screenshot(); + /** Get directory content under a given path **/ DirStruct* GetDirContents(const char* path); diff --git a/source/godmode.c b/source/godmode.c index fcfe9b2..c760213 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -64,6 +64,8 @@ u32 GodMode() { else *current_path = '\0'; contents = GetDirContents(current_path); cursor = offset_disp = 0; + } else if (pad_state & BUTTON_X) { + Screenshot(); } if (pad_state & BUTTON_START) { exit_mode = (pad_state & BUTTON_LEFT) ? GODMODE_EXIT_POWEROFF : GODMODE_EXIT_REBOOT;