diff --git a/source/err.c b/source/err.c new file mode 100644 index 0000000..f45cebb --- /dev/null +++ b/source/err.c @@ -0,0 +1,53 @@ +#include "err.h" +#include "gfx/gfx.h" +#include "hid/hid.h" +#include "gfx/gfxutils.h" + +const char *fatfsErrors[] = { + "I/O ERROR", + "NO DISK", + "NOT READY", + "NO FILE", + "NO PATH", + "PATH INVALID", + "ACCESS DENIED", + "ACCESS DENIED", + "INVALID PTR", + "PROTECTED", + "INVALID DRIVE", + "NO MEM", + "NO FAT", + "MKFS ABORT" +}; + +const char *TEErrors[] = { + "Unimplemented" +}; + +const char *GetErrStr(u32 err){ + --err; // obv error codes cannot be 0 + if (err >= 0 && err < ARRAY_SIZE(fatfsErrors)) + return fatfsErrors[err]; + + if (err >= 20 && err < ARRAY_SIZE(TEErrors) + 20) + return TEErrors[err - 20]; + + return "(Unknown)"; +} + +#define lx 256 +#define ly 240 +#define lenx 768 +#define leny 240 + +void DrawError(ErrCode_t err){ + SETCOLOR(COLOR_ORANGE, COLOR_DARKGREY); + gfx_box(lx, ly, lx + lenx, ly + leny, COLOR_ORANGE); + gfx_boxGrey(lx + 16, ly + 16, lx + lenx - 16, ly + leny - 16, 0x33); + gfx_con_setpos(lx + ((lenx - 17 * 16) / 2), ly + 32); + gfx_printf("An error occured!\n\n%bErr : %d\nLine: %d\nFile: %s\nDesc: %s%b", lx + 48, err.err, err.loc, err.file, GetErrStr(err.err), 0); + gfx_con_setpos(lx + ((lenx - 19 * 16) / 2), ly + leny - 48); + gfx_printf("Press A to continue"); + + hidWaitMask((JoyA | JoyB)); +} \ No newline at end of file diff --git a/source/err.h b/source/err.h new file mode 100644 index 0000000..8a7eaf9 --- /dev/null +++ b/source/err.h @@ -0,0 +1,15 @@ +#pragma once +#include + +typedef struct { + u16 err; + u16 loc; + char* file; +} ErrCode_t; + +enum { + TE_ERR_UNIMPLEMENTED = 21, +}; + +#define newErrCode(err) (ErrCode_t) {err, __LINE__, __FILE__} +void DrawError(ErrCode_t err); \ No newline at end of file diff --git a/source/fs/fstypes.h b/source/fs/fstypes.h new file mode 100644 index 0000000..9dcb250 --- /dev/null +++ b/source/fs/fstypes.h @@ -0,0 +1,25 @@ +#pragma once +#include + +typedef struct { + char *name; + union { + struct { + u8 readOnly:1; + u8 hidden:1; + u8 system:1; + u8 volume:1; + u8 isDir:1; + u8 archive:1; + }; + u8 optionUnion; + }; + union { + struct { + u16 size:12; + u16 showSize:1; + u16 sizeDef:3; + }; + u16 sizeUnion; + }; +} FSEntry_t; \ No newline at end of file diff --git a/source/fs/fsutils.c b/source/fs/fsutils.c index e95e109..909a665 100644 --- a/source/fs/fsutils.c +++ b/source/fs/fsutils.c @@ -4,6 +4,7 @@ #include "../utils/utils.h" #include #include +#include "readers/folderReader.h" char *CombinePaths(const char *current, const char *add){ char *ret; @@ -35,4 +36,10 @@ u64 GetFileSize(char *path){ FILINFO fno; f_stat(path, &fno); return fno.fsize; +} + +char *GetFileAttribs(FSEntry_t entry){ + char *ret = CpyStr("RHSVDA"); + MaskIn(ret, entry.optionUnion, '-'); + return ret; } \ No newline at end of file diff --git a/source/fs/fsutils.h b/source/fs/fsutils.h index 28d7fec..b6fab80 100644 --- a/source/fs/fsutils.h +++ b/source/fs/fsutils.h @@ -1,6 +1,8 @@ #pragma once #include +#include "fstypes.h" u64 GetFileSize(char *path); char *EscapeFolder(char *current); -char *CombinePaths(const char *current, const char *add); \ No newline at end of file +char *CombinePaths(const char *current, const char *add); +char *GetFileAttribs(FSEntry_t entry); \ No newline at end of file diff --git a/source/fs/menus/explorer.c b/source/fs/menus/explorer.c index 14210d9..41a0e9e 100644 --- a/source/fs/menus/explorer.c +++ b/source/fs/menus/explorer.c @@ -6,6 +6,7 @@ #include "../../gfx/gfx.h" #include "../../gfx/gfxutils.h" #include "../../utils/utils.h" +#include "filemenu.h" #include #include @@ -55,6 +56,10 @@ void FileExplorer(char *path){ gfx_con_setpos(144, 16); gfx_boxGrey(0, 16, 160, 31, 0x1B); + + if (res >= fileVec.count + ARR_LEN(topEntries)) + res = 0; + res = newMenu(&entries, res, 60, 42, ENABLEB | ENABLEPAGECOUNT, (int)fileVec.count); if (res < ARR_LEN(topEntries)) { @@ -66,14 +71,19 @@ void FileExplorer(char *path){ char *copy = CpyStr(storedPath); storedPath = EscapeFolder(copy); free(copy); + res = 0; } else if (fsEntries[res - ARR_LEN(topEntries)].isDir) { char *copy = CpyStr(storedPath); storedPath = CombinePaths(copy, fsEntries[res - ARR_LEN(topEntries)].name); free(copy); + res = 0; + } + else { + FileMenu(fsEntries[res - ARR_LEN(topEntries)]); } - res = 0; + clearFileVector(&fileVec); } } \ No newline at end of file diff --git a/source/fs/menus/filemenu.c b/source/fs/menus/filemenu.c index e69de29..a4588b4 100644 --- a/source/fs/menus/filemenu.c +++ b/source/fs/menus/filemenu.c @@ -0,0 +1,11 @@ +#include "filemenu.h" +#include "../../err.h" +#include "../../gfx/menu.h" + +MenuEntry_t FileMenuEntries[] = { + // Still have to think up the options +}; + +void FileMenu(FSEntry_t entry){ + DrawError(newErrCode(TE_ERR_UNIMPLEMENTED)); +} \ No newline at end of file diff --git a/source/fs/menus/filemenu.h b/source/fs/menus/filemenu.h index e69de29..db2ca6e 100644 --- a/source/fs/menus/filemenu.h +++ b/source/fs/menus/filemenu.h @@ -0,0 +1,4 @@ +#pragma once +#include "../fstypes.h" + +void FileMenu(FSEntry_t entry); \ No newline at end of file diff --git a/source/fs/readers/folderReader.c b/source/fs/readers/folderReader.c index 5b3d0ae..b6096e0 100644 --- a/source/fs/readers/folderReader.c +++ b/source/fs/readers/folderReader.c @@ -14,7 +14,8 @@ Vector_t /* of type FSEntry_t */ ReadFolder(char *path){ } while (!f_readdir(&dir, &fno) && fno.fname[0]) { - FSEntry_t newEntry = {.isDir = (fno.fattrib & AM_DIR) ? 1 : 0, .name = CpyStr(fno.fname)}; + FSEntry_t newEntry = {.optionUnion = fno.fattrib, .name = CpyStr(fno.fname)}; + if (!newEntry.isDir){ u64 total = fno.fsize; u8 type = 0; @@ -33,5 +34,7 @@ Vector_t /* of type FSEntry_t */ ReadFolder(char *path){ vecAddElem(&out, newEntry); } + f_closedir(&dir); + return out; } diff --git a/source/fs/readers/folderReader.h b/source/fs/readers/folderReader.h index 174a1c5..ff722cc 100644 --- a/source/fs/readers/folderReader.h +++ b/source/fs/readers/folderReader.h @@ -1,23 +1,6 @@ #pragma once #include #include "../../utils/vector.h" - -typedef struct { - char *name; - union { - struct { - u8 isDir:1; - }; - u8 optionUnion; - }; - union { - struct { - u16 size:12; - u16 showSize:1; - u16 sizeDef:3; - }; - u16 sizeUnion; - }; -} FSEntry_t; +#include "../fstypes.h" Vector_t /* of type FSEntry_t */ ReadFolder(char *path); \ No newline at end of file diff --git a/source/gfx/gfx.c b/source/gfx/gfx.c index 5104e9f..9db9f82 100644 --- a/source/gfx/gfx.c +++ b/source/gfx/gfx.c @@ -123,6 +123,8 @@ static const u8 _gfx_font[] = { 0x00, 0x0E, 0x12, 0x22, 0x22, 0x22, 0x3E, 0x00, // Char 128 (file) }; +u32 YLeftConfig = YLEFT; + void gfx_clear_grey(u8 color) { memset(gfx_ctxt.fb, color, gfx_ctxt.width * gfx_ctxt.height * 4); @@ -240,13 +242,13 @@ void gfx_putc(char c) gfx_con.y -= 16; if (gfx_con.y < 16){ - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; gfx_con.x += 16; } } else if (c == '\n') { - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; gfx_con.x += 16; if (gfx_con.x > gfx_ctxt.width - 16) gfx_con.x = 0; @@ -256,7 +258,7 @@ void gfx_putc(char c) else if (c == '\a') gfx_con.y = 639; else if (c == '\r') - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; break; case 8: @@ -282,14 +284,14 @@ void gfx_putc(char c) gfx_con.y -= 8; if (gfx_con.y < 8){ - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; gfx_con.x += 8; } } else if (c == '\n') { - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; gfx_con.x += 8; if (gfx_con.x > gfx_ctxt.width - 8) gfx_con.x = 0; @@ -299,7 +301,7 @@ void gfx_putc(char c) else if (c == '\a') gfx_con.y = 639; else if (c == '\r') - gfx_con.y = YLEFT; + gfx_con.y = YLeftConfig; break; } @@ -449,6 +451,11 @@ void gfx_vprintf(const char *fmt, va_list ap) gfx_con.bgcol = va_arg(ap, u32); gfx_con.fillbg = 1; break; + case 'b':; + u32 b = YLEFT - va_arg(ap, u32); + gfx_con.y = b; + YLeftConfig = gfx_con.y; + break; case '%': gfx_putc('%'); break; diff --git a/source/gfx/gfxutils.h b/source/gfx/gfxutils.h index 84d22a7..0e3d0a4 100644 --- a/source/gfx/gfxutils.h +++ b/source/gfx/gfxutils.h @@ -4,6 +4,7 @@ #define COLOR_WHITE 0xFFFFFFFF #define COLOR_DEFAULT 0xFF1B1B1B #define COLOR_GREY 0xFF888888 +#define COLOR_DARKGREY 0xFF333333 #define COLORTORGB(color) (color & 0x00FFFFFF) #define SETCOLOR(fg, bg) gfx_con_setcol(fg, 1, bg) diff --git a/source/gfx/menu.c b/source/gfx/menu.c index c7f8f1e..7690b00 100644 --- a/source/gfx/menu.c +++ b/source/gfx/menu.c @@ -129,7 +129,7 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 op else if (input->b && options & ENABLEB) return 0; else if (input->down || input->rDown || input->right){ //Rdown should probs not trigger a page change. Same for RUp - u32 temp = (input->right) ? screenLenY : 1; + u32 temp = (input->right && !(input->down || input->rDown)) ? screenLenY : 1; if (vec->count > selected + temp){ selected += temp; @@ -141,7 +141,7 @@ int newMenu(Vector_t* vec, int startIndex, int screenLenX, int screenLenY, u8 op } } else if (input->up || input->rUp || input->left){ - u32 temp = (input->left) ? screenLenY : 1; + u32 temp = (input->left && !(input->up || input->rUp)) ? screenLenY : 1; if (selected >= temp){ selected -= temp; break; diff --git a/source/main.c b/source/main.c index fc0da49..8f3ba10 100644 --- a/source/main.c +++ b/source/main.c @@ -47,6 +47,7 @@ #include "gfx/gfxutils.h" #include "tegraexplorer/mainmenu.h" #include "tegraexplorer/tconf.h" +#include "err.h" hekate_config h_cfg; @@ -209,6 +210,7 @@ void ipl_main() //u32 res = newMenu(&a, 0, 40, 5, testAdd, NULL); //gfx_clearscreen(); + //DrawError(newErrCode(1)); EnterMainMenu(); diff --git a/source/utils/utils.c b/source/utils/utils.c index a8956f3..042fa74 100644 --- a/source/utils/utils.c +++ b/source/utils/utils.c @@ -1,5 +1,6 @@ #include "utils.h" #include +#include #include char *CpyStr(const char* in){ @@ -8,4 +9,15 @@ char *CpyStr(const char* in){ out[len] = 0; memcpy(out, in, len); return out; +} + +void MaskIn(char *mod, u32 bitstream, char mask){ + u32 len = strlen(mod); + for (int i = 0; i < len; i++){ + if (bitstream & 1) + *mod = mask; + + bitstream >>= 1; + mod++; + } } \ No newline at end of file diff --git a/source/utils/utils.h b/source/utils/utils.h index 87382d1..2f91525 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -1,3 +1,5 @@ #pragma once +#include -char *CpyStr(const char* in); \ No newline at end of file +char *CpyStr(const char* in); +void MaskIn(char *mod, u32 bitstream, char mask); \ No newline at end of file