u32 ScrollOutput() { u32 log_start = LogWrite(NULL); // careful, these areas are used by other functions in Decrypt9 char** logptr = (char**) 0x20316000; char* logtext = (char*) 0x20400000; u32 log_size = 0; // log size u32 l_total = 0; // total lines u32 l_curr = 0; // current line if (!FileOpen(LOG_FILE)) return 0; log_size = FileGetSize(); if ((log_size <= log_start) || (log_size - log_start >= 1024 * 1024)) { FileClose(); return 0; // allow 1MB of text max } log_size -= log_start; if (!FileRead(logtext, log_size, log_start)) { FileClose(); return 0; } FileClose(); // read lines logtext[log_size - 1] = '\0'; logptr[l_total++] = logtext; for (char* line = strchr(logtext, '\n'); line != NULL && l_total < 4000; line = strchr(line, '\n')) { *line = '\0'; logptr[l_total++] = ++line; } if (l_total >= 4000) // allow 4000 lines of text max return 0; for (; l_total < DBG_N_CHARS_Y; logptr[l_total++] = logtext + log_size - 1); // here, the actual output starts l_curr = l_total - DBG_N_CHARS_Y ; if (l_curr > 0) l_curr--; // start at the line before the last while (true) { DebugSet((const char**) logptr + l_curr); u32 pad_state = InputWait(); if (pad_state & BUTTON_X) { Screenshot(NULL); } else if ((pad_state & BUTTON_UP) && (l_curr > 0)) { l_curr--; } else if ((pad_state & BUTTON_DOWN) && (l_curr < l_total - DBG_N_CHARS_Y)) { l_curr++; } else if (pad_state & (BUTTON_B | BUTTON_START)) { return pad_state; } } return 0; }
u32 ScrollOutput() { u32 log_start = LogWrite(NULL); // careful, these areas are used by other functions in Decrypt9 char** logptr = (char**) 0x21100000; char* logtext = (char*) 0x21200000; u32 log_size = FileGetData(LOG_FILE, logtext, 1024 * 1024, log_start); // log size u32 l_total = 0; // total lines u32 l_curr = 0; // current line // read log file (second time) log_size = FileGetData(LOG_FILE, logtext, 1024 * 1024, log_start); // allow 1MB of text max if ((log_size == 0) || (log_size >= 1024 * 1024)) return 0; // organize lines logtext[log_size - 1] = '\0'; logptr[l_total++] = logtext; for (char* line = strchr(logtext, '\n'); line != NULL && l_total < 4000; line = strchr(line, '\n')) { *line = '\0'; logptr[l_total++] = ++line; } if (l_total >= 4000) // allow 4000 lines of text max return 0; for (; l_total < DBG_N_CHARS_Y; logptr[l_total++] = logtext + log_size - 1); // fill up with empty lines // here, the actual output starts l_curr = l_total - DBG_N_CHARS_Y; if (l_curr > 0) l_curr--; // start at the line before the last while (true) { DebugSet((const char**) logptr + l_curr); u32 pad_state = InputWait(); if (pad_state & BUTTON_X) { Screenshot(NULL); } else if ((pad_state & BUTTON_UP) && (l_curr > 0)) { l_curr--; } else if ((pad_state & BUTTON_DOWN) && (l_curr < l_total - DBG_N_CHARS_Y)) { l_curr++; } else if (pad_state & (BUTTON_B | BUTTON_START)) { return pad_state; } } return 0; }