diff --git a/source/fs/menus/filemenu.c b/source/fs/menus/filemenu.c index e0d6b3d..74b6f77 100644 --- a/source/fs/menus/filemenu.c +++ b/source/fs/menus/filemenu.c @@ -109,12 +109,62 @@ void RenameFile(char *path, FSEntry_t entry){ free(renameTo); } +// This is from the original TE and it's bad but uhh i'm too lazy to fix it +void HexView(char *path, FSEntry_t entry){ + char *filePath = CombinePaths(path, entry.name); + + FIL in; + u8 *print; + u32 size; + QWORD offset = 0; + int res; + Input_t *input = hidRead(); + + while (input->buttons & (BtnPow | JoyB)) + hidRead(); + + gfx_clearscreen(); + print = malloc(2048); + + if ((res = f_open(&in, filePath, FA_READ | FA_OPEN_EXISTING))){ + DrawError(newErrCode(res)); + return; + } + + while (1){ + f_lseek(&in, offset * 32); + + if ((res = f_read(&in, print, 2048, &size))){ + DrawError(newErrCode(res)); + return; + } + + gfx_con_setpos(0, 31); + gfx_hexdump(offset * 32, print, size); + + input = hidRead(); + + if (!(input->buttons)) + input = hidWait(); + + if (input->down && 2048 == size) + offset += 2; + if (input->up && offset > 0) + offset -= 2; + if (input->buttons & (BtnPow | JoyB)) + break; + } + f_close(&in); + free(print); + free(filePath); +} + fileMenuPath FileMenuPaths[] = { CopyClipboard, MoveClipboard, RenameFile, DeleteFile, - UnimplementedException, + HexView, LaunchPayload, RunScript }; diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index ad05859..d7a1ef7 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -492,6 +492,8 @@ void gfx_putc_small(char c){ gfx_con.fntsz = 16; } +#define hexDumpLen 0x20 + void gfx_hexdump(u32 base, const u8 *buf, u32 len) { if (gfx_con.mute) @@ -501,14 +503,14 @@ void gfx_hexdump(u32 base, const u8 *buf, u32 len) gfx_con.fntsz = 8; for(u32 i = 0; i < len; i++) { - if(i % 0x10 == 0) + if(i % hexDumpLen == 0) { if(i != 0) { gfx_puts("| "); - for(u32 j = 0; j < 0x10; j++) + for(u32 j = 0; j < hexDumpLen; j++) { - u8 c = buf[i - 0x10 + j]; + u8 c = buf[i - hexDumpLen + j]; if(c >= 32 && c <= 126) gfx_putc(c); else @@ -521,12 +523,12 @@ void gfx_hexdump(u32 base, const u8 *buf, u32 len) gfx_printf("%02x ", buf[i]); if (i == len - 1) { - int ln = len % 0x10 != 0; - u32 k = 0x10 - 1; + int ln = len % hexDumpLen != 0; + u32 k = hexDumpLen - 1; if (ln) { k = (len & 0xF) - 1; - for (u32 j = 0; j < 0x10 - k; j++) + for (u32 j = 0; j < hexDumpLen - k; j++) gfx_puts(" "); } gfx_puts("| "); diff --git a/source/hid/hid.h b/source/hid/hid.h index 285c3d7..c4d441d 100644 --- a/source/hid/hid.h +++ b/source/hid/hid.h @@ -14,6 +14,7 @@ #define JoyLRight BIT(18) #define JoyLLeft BIT(19) #define JoyLB BIT(22) +#define BtnPow BIT(24) #define BtnVolP BIT(25) #define BtnVolM BIT(26) #define JoyRDown BIT(27)