Enabled Screenshot feature (Button X)

This commit is contained in:
d0k3 2016-02-26 19:43:30 +01:00
parent 7f6bc707fb
commit ec5213255d
7 changed files with 60 additions and 50 deletions

View File

@ -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, ...) void ShowError(const char *format, ...)
{ {
char str[128] = {}; // 128 should be more than enough char str[128] = {}; // 128 should be more than enough

View File

@ -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 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 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 ShowError(const char *format, ...);
void ShowProgress(u64 current, u64 total); void ShowProgress(u64 current, u64 total);

View File

@ -122,7 +122,7 @@ DRESULT disk_read (
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
/* Write Sector(s) */ /* Write Sector(s) */
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
#undef _USE_WRITE
#if _USE_WRITE #if _USE_WRITE
DRESULT disk_write ( DRESULT disk_write (
__attribute__((unused)) __attribute__((unused))

View File

@ -16,7 +16,7 @@
/ data transfer. */ / data transfer. */
#define _FS_READONLY 1 #define _FS_READONLY 0
/* This option switches read-only configuration. (0:Read/Write or 1:Read-only) /* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
/ Read-only configuration removes writing API functions, f_write(), f_sync(), / Read-only configuration removes writing API functions, f_write(), f_sync(),
/ f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()

View File

@ -8,7 +8,7 @@ static FATFS* fs = (FATFS*)0x20316000;
// reserve one MB for this, just to be safe // reserve one MB for this, just to be safe
static DirStruct* curdir_contents = (DirStruct*)0x21000000; static DirStruct* curdir_contents = (DirStruct*)0x21000000;
// this is the main buffer // this is the main buffer
// static u8* main_buffer = (u8*)0x21100000; static u8* main_buffer = (u8*)0x21100000;
// number of currently open file systems // number of currently open file systems
static u32 numfs = 0; static u32 numfs = 0;
@ -44,8 +44,51 @@ void DeinitFS()
numfs = 0; 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] = { static const char* drvname[16] = {
"SDCARD", "SDCARD",
"SYSCTRN", "SYSTWLN", "SYSTWLP", "SYSCTRN", "SYSTWLN", "SYSTWLP",
@ -68,8 +111,7 @@ bool GetRootDirContentsWorker(DirStruct* contents)
return contents->n_entries; 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; DIR pdir;
FILINFO fno; FILINFO fno;
char* fname = fpath + strnlen(fpath, fsize - 1); char* fname = fpath + strnlen(fpath, fsize - 1);
@ -114,8 +156,7 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recu
return ret; return ret;
} }
DirStruct* GetDirContents(const char* path) DirStruct* GetDirContents(const char* path) {
{
curdir_contents->n_entries = 0; curdir_contents->n_entries = 0;
if (strncmp(path, "", 256) == 0) { // root directory if (strncmp(path, "", 256) == 0) { // root directory
if (!GetRootDirContentsWorker(curdir_contents)) if (!GetRootDirContentsWorker(curdir_contents))

View File

@ -27,6 +27,15 @@ typedef struct {
bool InitFS(); bool InitFS();
void DeinitFS(); 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 **/ /** Get directory content under a given path **/
DirStruct* GetDirContents(const char* path); DirStruct* GetDirContents(const char* path);

View File

@ -64,6 +64,8 @@ u32 GodMode() {
else *current_path = '\0'; else *current_path = '\0';
contents = GetDirContents(current_path); contents = GetDirContents(current_path);
cursor = offset_disp = 0; cursor = offset_disp = 0;
} else if (pad_state & BUTTON_X) {
Screenshot();
} }
if (pad_state & BUTTON_START) { if (pad_state & BUTTON_START) {
exit_mode = (pad_state & BUTTON_LEFT) ? GODMODE_EXIT_POWEROFF : GODMODE_EXIT_REBOOT; exit_mode = (pad_state & BUTTON_LEFT) ? GODMODE_EXIT_POWEROFF : GODMODE_EXIT_REBOOT;