From 7f6bc707fbbc7bb87fb957eb200f13fa0c32424d Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 26 Feb 2016 18:52:30 +0100 Subject: [PATCH] This is now in proof-of-concept-stage --- source/draw.c | 3 +++ source/fatfs/diskio.c | 2 +- source/fs.c | 9 ++++----- source/godmode.c | 41 ++++++++++++++++++++++++++++++++--------- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/source/draw.c b/source/draw.c index ca2b83d..22de0dd 100644 --- a/source/draw.c +++ b/source/draw.c @@ -10,6 +10,7 @@ #include "font.h" #include "draw.h" // #include "fs.h" +#include "hid.h" void ClearScreen(u8* screen, int width, int color) { @@ -133,6 +134,8 @@ void ShowError(const char *format, ...) ClearScreenFull(true, false, COLOR_BLACK); DrawStringF(true, 80, 80, COLOR_WHITE, COLOR_BLACK, str); + + // InputWait(); } /*void ShowProgress(u64 current, u64 total) diff --git a/source/fatfs/diskio.c b/source/fatfs/diskio.c index 130efc7..7617f93 100644 --- a/source/fatfs/diskio.c +++ b/source/fatfs/diskio.c @@ -18,8 +18,8 @@ typedef struct { DWORD offset; - DWORD subtype; BYTE type; + DWORD subtype; } FATpartition; FATpartition DriveInfo[28] = { diff --git a/source/fs.c b/source/fs.c index 0bb8fad..e94e9a1 100644 --- a/source/fs.c +++ b/source/fs.c @@ -19,7 +19,6 @@ bool InitFS() *(u32*)0x10000020 = 0; *(u32*)0x10000020 = 0x340; #endif - u32 emunand_state = CheckEmuNand(); for (numfs = 0; numfs < 16; numfs++) { char fsname[8]; snprintf(fsname, 8, "%lu:", numfs); @@ -59,10 +58,10 @@ bool GetRootDirContentsWorker(DirStruct* contents) for (u32 pdrv = 0; (pdrv < numfs) && (pdrv < MAX_ENTRIES); pdrv++) { memset(contents->entry[pdrv].path, 0x00, 16); snprintf(contents->entry[pdrv].path + 0, 4, "%lu:", pdrv); - snprintf(contents->entry[pdrv].path + 4, 16, "[%lu:] (%s)", pdrv, drvname[pdrv]); + snprintf(contents->entry[pdrv].path + 4, 16, "[%lu:] %s", pdrv, drvname[pdrv]); contents->entry[pdrv].name = contents->entry[pdrv].path + 4; contents->entry[pdrv].size = 0; - contents->entry[pdrv].type = T_FAT_ROOT; + contents->entry[pdrv].type = T_FAT_DIR; } contents->n_entries = numfs; @@ -92,8 +91,8 @@ bool GetDirContentsWorker(DirStruct* contents, char* fpath, int fsize, bool recu break; } else { DirEntry* entry = &(contents->entry[contents->n_entries]); - snprintf(entry->path, 256, "%s", fpath); - entry->name = entry->path + (fpath - fname); + strncpy(entry->path, fpath, 256); + entry->name = entry->path + (fname - fpath); if (fno.fattrib & AM_DIR) { entry->type = T_FAT_DIR; entry->size = 0; diff --git a/source/godmode.c b/source/godmode.c index f455a83..fcfe9b2 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -3,7 +3,7 @@ #include "hid.h" #include "fs.h" -void DrawDirContents(DirStruct* contents, u32 offset, u32 cursor) { +void DrawDirContents(DirStruct* contents, u32* offset, u32 cursor) { const int str_width = 40; const u32 stp_y = 12; const u32 pos_x = 0; @@ -11,7 +11,7 @@ void DrawDirContents(DirStruct* contents, u32 offset, u32 cursor) { for (u32 i = 0; pos_y < SCREEN_HEIGHT; i++) { char tempstr[str_width + 1]; - u32 offset_i = offset + i; + u32 offset_i = *offset + i; u32 color_font; u32 color_bg; if (offset_i < contents->n_entries) { @@ -35,18 +35,41 @@ void DrawDirContents(DirStruct* contents, u32 offset, u32 cursor) { u32 GodMode() { u32 exit_mode = GODMODE_EXIT_REBOOT; + char current_path[256] = { 0x00 }; DirStruct* contents; + u32 cursor = 0; + u32 offset_disp = 0; ClearScreenFull(true, true, COLOR_BLACK); - if (!InitFS()) { - // ShowError("Could not initialize fs!"); - InputWait(); - return exit_mode; - } + if (!InitFS()) return exit_mode; contents = GetDirContents(""); - DrawDirContents(contents, 0, 0); - InputWait(); + while (true) { // this is the main loop + DrawDirContents(contents, &offset_disp, cursor); + u32 pad_state = InputWait(); + if (pad_state & BUTTON_DOWN) { + cursor++; + if (cursor >= contents->n_entries) + cursor = contents->n_entries - 1; + } else if ((pad_state & BUTTON_UP) && cursor) { + cursor--; + } else if ((pad_state & BUTTON_A) && (contents->entry[cursor].type == T_FAT_DIR)) { + strncpy(current_path, contents->entry[cursor].path, 256); + contents = GetDirContents(current_path); + cursor = offset_disp = 0; + ShowError(current_path); + } else if (pad_state & BUTTON_B) { + char* last_slash = strrchr(current_path, '/'); + if (last_slash) *last_slash = '\0'; + else *current_path = '\0'; + contents = GetDirContents(current_path); + cursor = offset_disp = 0; + } + if (pad_state & BUTTON_START) { + exit_mode = (pad_state & BUTTON_LEFT) ? GODMODE_EXIT_POWEROFF : GODMODE_EXIT_REBOOT; + break; + } + } DeinitFS();