This is now in proof-of-concept-stage

This commit is contained in:
d0k3 2016-02-26 18:52:30 +01:00
parent f13a89d809
commit 7f6bc707fb
4 changed files with 40 additions and 15 deletions

View File

@ -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)

View File

@ -18,8 +18,8 @@
typedef struct {
DWORD offset;
DWORD subtype;
BYTE type;
DWORD subtype;
} FATpartition;
FATpartition DriveInfo[28] = {

View File

@ -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;

View File

@ -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();