Get rid of unnecessary second framebuffer

This commit is contained in:
d0k3 2016-05-18 23:46:22 +02:00
parent ceca36fdc7
commit f4622d5bff
4 changed files with 66 additions and 97 deletions

View File

@ -666,10 +666,10 @@ void CreateScreenshot() {
memset(buffer, 0x1F, 400 * 240 * 3 * 2); memset(buffer, 0x1F, 400 * 240 * 3 * 2);
for (u32 x = 0; x < 400; x++) for (u32 x = 0; x < 400; x++)
for (u32 y = 0; y < 240; y++) for (u32 y = 0; y < 240; y++)
memcpy(buffer_t + (y*400 + x) * 3, TOP_SCREEN0 + (x*240 + y) * 3, 3); memcpy(buffer_t + (y*400 + x) * 3, TOP_SCREEN + (x*240 + y) * 3, 3);
for (u32 x = 0; x < 320; x++) for (u32 x = 0; x < 320; x++)
for (u32 y = 0; y < 240; y++) for (u32 y = 0; y < 240; y++)
memcpy(buffer + (y*400 + x + 40) * 3, BOT_SCREEN0 + (x*240 + y) * 3, 3); memcpy(buffer + (y*400 + x + 40) * 3, BOT_SCREEN + (x*240 + y) * 3, 3);
FileCreateData(filename, MAIN_BUFFER, 54 + (400 * 240 * 3 * 2)); FileCreateData(filename, MAIN_BUFFER, 54 + (400 * 240 * 3 * 2));
} }

View File

@ -52,30 +52,30 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
} }
// top bar - current path & free/total storage // top bar - current path & free/total storage
DrawRectangleF(true, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_TOP_BAR); DrawRectangle(TOP_SCREEN, 0, 0, SCREEN_WIDTH_TOP, 12, COLOR_TOP_BAR);
if (strncmp(curr_path, "", 256) != 0) { if (strncmp(curr_path, "", 256) != 0) {
char bytestr0[32]; char bytestr0[32];
char bytestr1[32]; char bytestr1[32];
TruncateString(tempstr, curr_path, 30, 8); TruncateString(tempstr, curr_path, 30, 8);
DrawStringF(true, 2, 2, COLOR_STD_BG, COLOR_TOP_BAR, tempstr); DrawStringF(TOP_SCREEN, 2, 2, COLOR_STD_BG, COLOR_TOP_BAR, tempstr);
DrawStringF(true, 30 * 8 + 4, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", "LOADING..."); DrawStringF(TOP_SCREEN, 30 * 8 + 4, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", "LOADING...");
FormatBytes(bytestr0, GetFreeSpace(curr_path)); FormatBytes(bytestr0, GetFreeSpace(curr_path));
FormatBytes(bytestr1, GetTotalSpace(curr_path)); FormatBytes(bytestr1, GetTotalSpace(curr_path));
snprintf(tempstr, 64, "%s/%s", bytestr0, bytestr1); snprintf(tempstr, 64, "%s/%s", bytestr0, bytestr1);
DrawStringF(true, 30 * 8 + 4, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", tempstr); DrawStringF(TOP_SCREEN, 30 * 8 + 4, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", tempstr);
} else { } else {
DrawStringF(true, 2, 2, COLOR_STD_BG, COLOR_TOP_BAR, "[root]"); DrawStringF(TOP_SCREEN, 2, 2, COLOR_STD_BG, COLOR_TOP_BAR, "[root]");
DrawStringF(true, 30 * 8 + 6, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", "GodMode9"); DrawStringF(TOP_SCREEN, 30 * 8 + 6, 2, COLOR_STD_BG, COLOR_TOP_BAR, "%19.19s", "GodMode9");
} }
// left top - current file info // left top - current file info
if (curr_pane) snprintf(tempstr, 63, "PANE #%lu", curr_pane); if (curr_pane) snprintf(tempstr, 63, "PANE #%lu", curr_pane);
else snprintf(tempstr, 63, "CURRENT"); else snprintf(tempstr, 63, "CURRENT");
DrawStringF(true, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[%s]", tempstr); DrawStringF(TOP_SCREEN, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[%s]", tempstr);
// file / entry name // file / entry name
ResizeString(tempstr, curr_entry->name, 20, 8, false); ResizeString(tempstr, curr_entry->name, 20, 8, false);
u32 color_current = COLOR_ENTRY(curr_entry); u32 color_current = COLOR_ENTRY(curr_entry);
DrawStringF(true, 4, info_start + 12, color_current, COLOR_STD_BG, "%s", tempstr); DrawStringF(TOP_SCREEN, 4, info_start + 12, color_current, COLOR_STD_BG, "%s", tempstr);
// size (in Byte) or type desc // size (in Byte) or type desc
if (curr_entry->type == T_DIR) { if (curr_entry->type == T_DIR) {
ResizeString(tempstr, "(dir)", 20, 8, false); ResizeString(tempstr, "(dir)", 20, 8, false);
@ -88,18 +88,18 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
snprintf(bytestr, 31, "%s Byte", numstr); snprintf(bytestr, 31, "%s Byte", numstr);
ResizeString(tempstr, bytestr, 20, 8, false); ResizeString(tempstr, bytestr, 20, 8, false);
} }
DrawStringF(true, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr); DrawStringF(TOP_SCREEN, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
// right top - clipboard // right top - clipboard
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : ""); DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : "");
for (u32 c = 0; c < n_cb_show; c++) { for (u32 c = 0; c < n_cb_show; c++) {
u32 color_cb = COLOR_ENTRY(&(clipboard->entry[c])); u32 color_cb = COLOR_ENTRY(&(clipboard->entry[c]));
ResizeString(tempstr, (clipboard->n_entries > c) ? clipboard->entry[c].name : "", 20, 8, true); ResizeString(tempstr, (clipboard->n_entries > c) ? clipboard->entry[c].name : "", 20, 8, true);
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (c*10), color_cb, COLOR_STD_BG, tempstr); DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (c*10), color_cb, COLOR_STD_BG, tempstr);
} }
*tempstr = '\0'; *tempstr = '\0';
if (clipboard->n_entries > n_cb_show) snprintf(tempstr, 60, "+ %lu more", clipboard->n_entries - n_cb_show); if (clipboard->n_entries > n_cb_show) snprintf(tempstr, 60, "+ %lu more", clipboard->n_entries - n_cb_show);
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (n_cb_show*10), COLOR_DARKGREY, COLOR_STD_BG, "%20s", tempstr); DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (n_cb_show*10), COLOR_DARKGREY, COLOR_STD_BG, "%20s", tempstr);
// bottom: inctruction block // bottom: inctruction block
char instr[256]; char instr[256];
@ -116,7 +116,7 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* c
"R+\x1B\x1A - Switch to prev/next pane\n", "R+\x1B\x1A - Switch to prev/next pane\n",
(clipboard->n_entries) ? "SELECT - Clear Clipboard\n" : "SELECT - Restore Clipboard\n", // only if clipboard is full (clipboard->n_entries) ? "SELECT - Clear Clipboard\n" : "SELECT - Restore Clipboard\n", // only if clipboard is full
"START - Reboot / [+R] Poweroff"); // generic end part "START - Reboot / [+R] Poweroff"); // generic end part
DrawStringF(true, instr_x, SCREEN_HEIGHT - 4 - GetDrawStringHeight(instr), COLOR_STD_FONT, COLOR_STD_BG, instr); DrawStringF(TOP_SCREEN, instr_x, SCREEN_HEIGHT - 4 - GetDrawStringHeight(instr), COLOR_STD_FONT, COLOR_STD_BG, instr);
} }
void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) { void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
@ -146,7 +146,7 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
snprintf(tempstr, str_width + 1, "%s%10.10s", namestr, snprintf(tempstr, str_width + 1, "%s%10.10s", namestr,
(curr_entry->type == T_DIR) ? "(dir)" : (curr_entry->type == T_DOTDOT) ? "(..)" : bytestr); (curr_entry->type == T_DIR) ? "(dir)" : (curr_entry->type == T_DOTDOT) ? "(..)" : bytestr);
} else snprintf(tempstr, str_width + 1, "%-*.*s", str_width, str_width, ""); } else snprintf(tempstr, str_width + 1, "%-*.*s", str_width, str_width, "");
DrawStringF(false, pos_x, pos_y, color_font, COLOR_STD_BG, tempstr); DrawStringF(BOT_SCREEN, pos_x, pos_y, color_font, COLOR_STD_BG, tempstr);
pos_y += stp_y; pos_y += stp_y;
} }
@ -155,10 +155,10 @@ void DrawDirContents(DirStruct* contents, u32 cursor, u32* scroll) {
if (bar_height < bar_height_min) bar_height = bar_height_min; if (bar_height < bar_height_min) bar_height = bar_height_min;
u32 bar_pos = ((u64) *scroll * (SCREEN_HEIGHT - bar_height)) / (contents->n_entries - lines); u32 bar_pos = ((u64) *scroll * (SCREEN_HEIGHT - bar_height)) / (contents->n_entries - lines);
DrawRectangleF(false, SCREEN_WIDTH_BOT - bar_width, 0, bar_width, bar_pos, COLOR_STD_BG); DrawRectangle(BOT_SCREEN, SCREEN_WIDTH_BOT - bar_width, 0, bar_width, bar_pos, COLOR_STD_BG);
DrawRectangleF(false, SCREEN_WIDTH_BOT - bar_width, bar_pos + bar_height, bar_width, SCREEN_WIDTH_BOT - (bar_pos + bar_height), COLOR_STD_BG); DrawRectangle(BOT_SCREEN, SCREEN_WIDTH_BOT - bar_width, bar_pos + bar_height, bar_width, SCREEN_WIDTH_BOT - (bar_pos + bar_height), COLOR_STD_BG);
DrawRectangleF(false, SCREEN_WIDTH_BOT - bar_width, bar_pos, bar_width, bar_height, COLOR_SIDE_BAR); DrawRectangle(BOT_SCREEN, SCREEN_WIDTH_BOT - bar_width, bar_pos, bar_width, bar_height, COLOR_SIDE_BAR);
} else DrawRectangleF(false, SCREEN_WIDTH_BOT - bar_width, 0, bar_width, SCREEN_HEIGHT, COLOR_STD_BG); } else DrawRectangle(BOT_SCREEN, SCREEN_WIDTH_BOT - bar_width, 0, bar_width, SCREEN_HEIGHT, COLOR_STD_BG);
} }
u32 HexViewer(const char* path) { u32 HexViewer(const char* path) {
@ -175,9 +175,10 @@ u32 HexViewer(const char* path) {
u32 total_data; u32 total_data;
u32 last_mode = 0xFF; u32 last_mode = 0xFF;
u32 last_offset = (u32) -1;
u32 offset = 0; u32 offset = 0;
memcpy(bottom_cpy, BOT_SCREEN0, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3)); memcpy(bottom_cpy, BOT_SCREEN, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
while (true) { while (true) {
if (mode != last_mode) { if (mode != last_mode) {
@ -222,10 +223,7 @@ u32 HexViewer(const char* path) {
if (offset % cols) offset -= (offset % cols); // fix offset (align to cols) if (offset % cols) offset -= (offset % cols); // fix offset (align to cols)
last_mode = mode; last_mode = mode;
ClearScreenF(true, dual_screen, COLOR_STD_BG); ClearScreenF(true, dual_screen, COLOR_STD_BG);
if (!dual_screen) { if (!dual_screen) memcpy(BOT_SCREEN, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
memcpy(BOT_SCREEN0, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
memcpy(BOT_SCREEN1, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
}
} }
// fix offset (if required) // fix offset (if required)
if (offset + total_shown > fsize + cols) if (offset + total_shown > fsize + cols)
@ -238,28 +236,31 @@ u32 HexViewer(const char* path) {
u32 y = row * (8 + (2*vpad)) + vpad; u32 y = row * (8 + (2*vpad)) + vpad;
u32 curr_pos = row * cols; u32 curr_pos = row * cols;
u32 cutoff = (curr_pos >= total_data) ? 0 : (total_data >= curr_pos + cols) ? cols : total_data - curr_pos; u32 cutoff = (curr_pos >= total_data) ? 0 : (total_data >= curr_pos + cols) ? cols : total_data - curr_pos;
bool top = (y < SCREEN_HEIGHT); u8* screen = TOP_SCREEN;
u32 x0 = (top ? 0 : 40); u32 x0 = 0;
if (!top) y -= SCREEN_HEIGHT;
if (y >= SCREEN_HEIGHT) { // switch to bottom screen
y -= SCREEN_HEIGHT;
screen = BOT_SCREEN;
x0 = 40;
}
memcpy(ascii, data + curr_pos, cols); memcpy(ascii, data + curr_pos, cols);
for (u32 col = 0; col < cols; col++) for (u32 col = 0; col < cols; col++)
if ((col >= cutoff) || (ascii[col] == 0x00)) ascii[col] = ' '; if ((col >= cutoff) || (ascii[col] == 0x00)) ascii[col] = ' ';
// draw offset / ASCII representation // draw offset / ASCII representation
if (x_off >= 0) DrawStringF(top, x_off - x0, y, cutoff ? COLOR_HVOFFS : COLOR_HVOFFSI, if (x_off >= 0) DrawStringF(screen, x_off - x0, y, cutoff ? COLOR_HVOFFS : COLOR_HVOFFSI,
COLOR_STD_BG, "%08X", (unsigned int) offset + curr_pos); COLOR_STD_BG, "%08X", (unsigned int) offset + curr_pos);
if (x_ascii >= 0) { if (x_ascii >= 0)
DrawString(top ? TOP_SCREEN0 : BOT_SCREEN0, ascii, x_ascii - x0, y, COLOR_HVASCII, COLOR_STD_BG); DrawString(screen, ascii, x_ascii - x0, y, COLOR_HVASCII, COLOR_STD_BG);
DrawString(top ? TOP_SCREEN1 : BOT_SCREEN1, ascii, x_ascii - x0, y, COLOR_HVASCII, COLOR_STD_BG);
}
// draw HEX values // draw HEX values
for (u32 col = 0; (col < cols) && (x_hex >= 0); col++) { for (u32 col = 0; (col < cols) && (x_hex >= 0); col++) {
u32 x = (x_hex + hlpad) + ((16 + hrpad + hlpad) * col) - x0; u32 x = (x_hex + hlpad) + ((16 + hrpad + hlpad) * col) - x0;
if (col < cutoff) if (col < cutoff)
DrawStringF(top, x, y, COLOR_HVHEX(col), COLOR_STD_BG, "%02X", (unsigned int) data[curr_pos + col]); DrawStringF(screen, x, y, COLOR_HVHEX(col), COLOR_STD_BG, "%02X", (unsigned int) data[curr_pos + col]);
else DrawStringF(top, x, y, COLOR_HVHEX(col), COLOR_STD_BG, " "); else DrawStringF(screen, x, y, COLOR_HVHEX(col), COLOR_STD_BG, " ");
} }
} }
@ -277,8 +278,7 @@ u32 HexViewer(const char* path) {
} }
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
memcpy(BOT_SCREEN0, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3)); memcpy(BOT_SCREEN, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
memcpy(BOT_SCREEN1, bottom_cpy, (SCREEN_HEIGHT * SCREEN_WIDTH_BOT * 3));
return 0; return 0;
} }

View File

@ -11,8 +11,9 @@
#include "ui.h" #include "ui.h"
#include "hid.h" #include "hid.h"
void ClearScreen(u8* screen, int width, int color) void ClearScreen(u8* screen, int color)
{ {
int width = (screen == TOP_SCREEN) ? SCREEN_WIDTH_TOP : SCREEN_WIDTH_BOT;
if (color == COLOR_TRANSPARENT) color = COLOR_BLACK; if (color == COLOR_TRANSPARENT) color = COLOR_BLACK;
for (int i = 0; i < (width * SCREEN_HEIGHT); i++) { for (int i = 0; i < (width * SCREEN_HEIGHT); i++) {
*(screen++) = color >> 16; // B *(screen++) = color >> 16; // B
@ -23,14 +24,8 @@ void ClearScreen(u8* screen, int width, int color)
void ClearScreenF(bool clear_top, bool clear_bottom, int color) void ClearScreenF(bool clear_top, bool clear_bottom, int color)
{ {
if (clear_top) { if (clear_top) ClearScreen(TOP_SCREEN, color);
ClearScreen(TOP_SCREEN0, SCREEN_WIDTH_TOP, color); if (clear_bottom) ClearScreen(BOT_SCREEN, color);
ClearScreen(TOP_SCREEN1, SCREEN_WIDTH_TOP, color);
}
if (clear_bottom) {
ClearScreen(BOT_SCREEN0, SCREEN_WIDTH_BOT, color);
ClearScreen(BOT_SCREEN1, SCREEN_WIDTH_BOT, color);
}
} }
void DrawRectangle(u8* screen, int x, int y, int width, int height, int color) void DrawRectangle(u8* screen, int x, int y, int width, int height, int color)
@ -48,17 +43,6 @@ void DrawRectangle(u8* screen, int x, int y, int width, int height, int color)
} }
} }
void DrawRectangleF(bool use_top, int x, int y, int width, int height, int color)
{
if (use_top) {
DrawRectangle(TOP_SCREEN0, x, y, width, height, color);
DrawRectangle(TOP_SCREEN1, x, y, width, height, color);
} else {
DrawRectangle(BOT_SCREEN0, x, y, width, height, color);
DrawRectangle(BOT_SCREEN1, x, y, width, height, color);
}
}
void DrawCharacter(u8* screen, int character, int x, int y, int color, int bgcolor) void DrawCharacter(u8* screen, int character, int x, int y, int color, int bgcolor)
{ {
for (int yy = 0; yy < 8; yy++) { for (int yy = 0; yy < 8; yy++) {
@ -88,7 +72,7 @@ void DrawString(u8* screen, const char *str, int x, int y, int color, int bgcolo
DrawCharacter(screen, str[i], x + i * 8, y, color, bgcolor); DrawCharacter(screen, str[i], x + i * 8, y, color, bgcolor);
} }
void DrawStringF(bool use_top, int x, int y, int color, int bgcolor, const char *format, ...) void DrawStringF(u8* screen, int x, int y, int color, int bgcolor, const char *format, ...)
{ {
char str[512] = { 0 }; // 512 should be more than enough char str[512] = { 0 }; // 512 should be more than enough
va_list va; va_list va;
@ -97,15 +81,8 @@ void DrawStringF(bool use_top, int x, int y, int color, int bgcolor, const char
vsnprintf(str, 512, format, va); vsnprintf(str, 512, format, va);
va_end(va); va_end(va);
for (char* text = strtok(str, "\n"); text != NULL; text = strtok(NULL, "\n"), y += 10) { for (char* text = strtok(str, "\n"); text != NULL; text = strtok(NULL, "\n"), y += 10)
if (use_top) { DrawString(screen, text, x, y, color, bgcolor);
DrawString(TOP_SCREEN0, text, x, y, color, bgcolor);
DrawString(TOP_SCREEN1, text, x, y, color, bgcolor);
} else {
DrawString(BOT_SCREEN0, text, x, y, color, bgcolor);
DrawString(BOT_SCREEN1, text, x, y, color, bgcolor);
}
}
} }
u32 GetDrawStringHeight(const char* str) { u32 GetDrawStringHeight(const char* str) {
@ -197,8 +174,8 @@ bool ShowPrompt(bool ask, const char *format, ...)
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2; y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(true, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); DrawStringF(TOP_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(true, x, y + str_height - (1*10), COLOR_STD_FONT, COLOR_STD_BG, (ask) ? "(<A> yes, <B> no)" : "(<A> to continue)"); DrawStringF(TOP_SCREEN, x, y + str_height - (1*10), COLOR_STD_FONT, COLOR_STD_BG, (ask) ? "(<A> yes, <B> no)" : "(<A> to continue)");
while (true) { while (true) {
u32 pad_state = InputWait(); u32 pad_state = InputWait();
@ -248,12 +225,12 @@ bool ShowUnlockSequence(u32 seqlvl, const char *format, ...) {
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2; y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(true, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); DrawStringF(TOP_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(true, x, y + str_height - 28, COLOR_STD_FONT, COLOR_STD_BG, "To proceed, enter this:"); DrawStringF(TOP_SCREEN, x, y + str_height - 28, COLOR_STD_FONT, COLOR_STD_BG, "To proceed, enter this:");
while (true) { while (true) {
for (u32 n = 0; n < len; n++) { for (u32 n = 0; n < len; n++) {
DrawStringF(true, x + (n*4*8), y + str_height - 18, DrawStringF(TOP_SCREEN, x + (n*4*8), y + str_height - 18,
(lvl > n) ? seqcolors[seqlvl] : COLOR_GREY, COLOR_STD_BG, "<%c>", seqsymbols[seqlvl][n]); (lvl > n) ? seqcolors[seqlvl] : COLOR_GREY, COLOR_STD_BG, "<%c>", seqsymbols[seqlvl][n]);
} }
if (lvl == len) if (lvl == len)
@ -297,11 +274,11 @@ u32 ShowSelectPrompt(u32 n, const char** options, const char *format, ...) {
yopt = y + GetDrawStringHeight(str) + 8; yopt = y + GetDrawStringHeight(str) + 8;
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(true, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); DrawStringF(TOP_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(true, x, yopt + (n*12) + 10, COLOR_STD_FONT, COLOR_STD_BG, "(<A> select, <B> cancel)"); DrawStringF(TOP_SCREEN, x, yopt + (n*12) + 10, COLOR_STD_FONT, COLOR_STD_BG, "(<A> select, <B> cancel)");
while (true) { while (true) {
for (u32 i = 0; i < n; i++) { for (u32 i = 0; i < n; i++) {
DrawStringF(true, x, yopt + (12*i), (sel == i) ? COLOR_STD_FONT : COLOR_LIGHTGREY, COLOR_STD_BG, "%2.2s %s", DrawStringF(TOP_SCREEN, x, yopt + (12*i), (sel == i) ? COLOR_STD_FONT : COLOR_LIGHTGREY, COLOR_STD_BG, "%2.2s %s",
(sel == i) ? "->" : "", options[i]); (sel == i) ? "->" : "", options[i]);
} }
u32 pad_state = InputWait(); u32 pad_state = InputWait();
@ -346,8 +323,8 @@ bool ShowInputPrompt(char* inputstr, u32 max_size, const char *format, ...) {
y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2; y = (str_height >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - str_height) / 2;
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
DrawStringF(true, x, y, COLOR_STD_FONT, COLOR_STD_BG, str); DrawStringF(TOP_SCREEN, x, y, COLOR_STD_FONT, COLOR_STD_BG, str);
DrawStringF(true, x + 8, y + str_height - 38, COLOR_STD_FONT, COLOR_STD_BG, "R - (\x18\x19) fast scroll\nL - clear string\nX - remove char\nY - insert char"); DrawStringF(TOP_SCREEN, x + 8, y + str_height - 38, COLOR_STD_FONT, COLOR_STD_BG, "R - (\x18\x19) fast scroll\nL - clear string\nX - remove char\nY - insert char");
int cursor_a = -1; int cursor_a = -1;
u32 cursor_s = 0; u32 cursor_s = 0;
@ -359,7 +336,7 @@ bool ShowInputPrompt(char* inputstr, u32 max_size, const char *format, ...) {
if (cursor_s < scroll) scroll = cursor_s; if (cursor_s < scroll) scroll = cursor_s;
else if (cursor_s - scroll >= input_shown) scroll = cursor_s - input_shown + 1; else if (cursor_s - scroll >= input_shown) scroll = cursor_s - input_shown + 1;
while (scroll && (inputstr_size - scroll < input_shown)) scroll--; while (scroll && (inputstr_size - scroll < input_shown)) scroll--;
DrawStringF(true, x, y + str_height - 68, COLOR_STD_FONT, COLOR_STD_BG, "%c%-*.*s%c%-*.*s\n%-*.*s^%-*.*s", DrawStringF(TOP_SCREEN, x, y + str_height - 68, COLOR_STD_FONT, COLOR_STD_BG, "%c%-*.*s%c%-*.*s\n%-*.*s^%-*.*s",
(scroll) ? '<' : '|', (scroll) ? '<' : '|',
(inputstr_size > input_shown) ? input_shown : inputstr_size, (inputstr_size > input_shown) ? input_shown : inputstr_size,
(inputstr_size > input_shown) ? input_shown : inputstr_size, (inputstr_size > input_shown) ? input_shown : inputstr_size,
@ -446,16 +423,14 @@ bool ShowProgress(u64 current, u64 total, const char* opstr)
if (!current || last_prog_width > prog_width) { if (!current || last_prog_width > prog_width) {
ClearScreenF(true, false, COLOR_STD_BG); ClearScreenF(true, false, COLOR_STD_BG);
DrawRectangleF(true, bar_pos_x, bar_pos_y, bar_width, bar_height, COLOR_STD_FONT); DrawRectangle(TOP_SCREEN, bar_pos_x, bar_pos_y, bar_width, bar_height, COLOR_STD_FONT);
DrawRectangleF(true, bar_pos_x + 1, bar_pos_y + 1, bar_width - 2, bar_height - 2, COLOR_STD_BG); DrawRectangle(TOP_SCREEN, bar_pos_x + 1, bar_pos_y + 1, bar_width - 2, bar_height - 2, COLOR_STD_BG);
} }
DrawRectangleF(true, bar_pos_x + 2, bar_pos_y + 2, prog_width, bar_height - 4, COLOR_STD_FONT); DrawRectangle(TOP_SCREEN, bar_pos_x + 2, bar_pos_y + 2, prog_width, bar_height - 4, COLOR_STD_FONT);
ResizeString(tempstr, opstr, 28, 8, false); ResizeString(tempstr, opstr, 28, 8, false);
DrawString(TOP_SCREEN0, tempstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG); DrawString(TOP_SCREEN, tempstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG);
DrawString(TOP_SCREEN1, tempstr, bar_pos_x, text_pos_y, COLOR_STD_FONT, COLOR_STD_BG); DrawString(TOP_SCREEN, "(hold B to cancel)", bar_pos_x + 2, text_pos_y + 14, COLOR_STD_FONT, COLOR_STD_BG);
DrawString(TOP_SCREEN0, "(hold B to cancel)", bar_pos_x + 2, text_pos_y + 14, COLOR_STD_FONT, COLOR_STD_BG);
DrawString(TOP_SCREEN1, "(hold B to cancel)", bar_pos_x + 2, text_pos_y + 14, COLOR_STD_FONT, COLOR_STD_BG);
last_prog_width = prog_width; last_prog_width = prog_width;

View File

@ -40,28 +40,22 @@
#define COLOR_STD_FONT COLOR_WHITE #define COLOR_STD_FONT COLOR_WHITE
#ifdef EXEC_GATEWAY #ifdef EXEC_GATEWAY
#define TOP_SCREEN0 (u8*)(*(u32*)((uint32_t)0x080FFFC0 + 4 * (*(u32*)0x080FFFD8 & 1))) #define TOP_SCREEN (u8*)(*(u32*)((uint32_t)0x080FFFC0 + 4 * (*(u32*)0x080FFFD8 & 1)))
#define BOT_SCREEN0 (u8*)(*(u32*)((uint32_t)0x080FFFD0 + 4 * (*(u32*)0x080FFFDC & 1))) #define BOT_SCREEN (u8*)(*(u32*)((uint32_t)0x080FFFD0 + 4 * (*(u32*)0x080FFFDC & 1)))
#define TOP_SCREEN1 TOP_SCREEN0
#define BOT_SCREEN1 BOT_SCREEN0
#elif defined(EXEC_A9LH) #elif defined(EXEC_A9LH)
#define TOP_SCREEN0 (u8*)(*(u32*)0x23FFFE00) #define TOP_SCREEN (u8*)(*(u32*)0x23FFFE00)
#define TOP_SCREEN1 (u8*)(*(u32*)0x23FFFE00) #define BOT_SCREEN (u8*)(*(u32*)0x23FFFE08)
#define BOT_SCREEN0 (u8*)(*(u32*)0x23FFFE08)
#define BOT_SCREEN1 (u8*)(*(u32*)0x23FFFE08)
#else #else
#error "Unknown execution method" #error "Unknown execution method"
#endif #endif
void ClearScreen(unsigned char *screen, int width, int color); void ClearScreen(unsigned char *screen, int color);
void ClearScreenF(bool clear_top, bool clear_bottom, int color); void ClearScreenF(bool clear_top, bool clear_bottom, int color);
void DrawRectangle(u8* screen, int x, int y, int width, int height, int color); void DrawRectangle(u8* screen, int x, int y, int width, int height, int color);
void DrawRectangleF(bool use_top, int x, int y, int width, int height, int color);
void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor); void DrawCharacter(unsigned char *screen, int character, int x, int y, int color, int bgcolor);
void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor); void DrawString(unsigned char *screen, const char *str, int x, int y, int color, int bgcolor);
void DrawStringF(bool use_top, int x, int y, int color, int bgcolor, const char *format, ...); void DrawStringF(unsigned char *screen, int x, int y, int color, int bgcolor, const char *format, ...);
u32 GetDrawStringHeight(const char* str); u32 GetDrawStringHeight(const char* str);
u32 GetDrawStringWidth(char* str); u32 GetDrawStringWidth(char* str);