From 65f28dab6a006732bfeddeae61c45038575e4b26 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Mon, 9 May 2016 15:10:05 -0400 Subject: [PATCH] Add menu file? --- copy.sh | 4 ++++ source/menu.c | 40 ++++++++++++++++++++++++++++++++-------- source/std/README.txt | 1 + 3 files changed, 37 insertions(+), 8 deletions(-) create mode 100644 copy.sh create mode 100644 source/std/README.txt diff --git a/copy.sh b/copy.sh new file mode 100644 index 0000000..2ae94e8 --- /dev/null +++ b/copy.sh @@ -0,0 +1,4 @@ +#!/bin/bash +mount /dev/sdb1 /media/sd +cp out/arm9loaderhax.bin /media/sd/anim/boot/a.bin +umount /media/sd diff --git a/source/menu.c b/source/menu.c index 7113280..1c153a6 100644 --- a/source/menu.c +++ b/source/menu.c @@ -13,6 +13,7 @@ static int cursor_y = 0; static int which_menu = 1; +static int need_redraw = 1; uint32_t wait_key() { uint32_t get = 0; @@ -37,8 +38,6 @@ void header() { int menu_patches() { return MENU_MAIN; } int menu_options() { - clear_screen(TOP_SCREEN); - set_cursor(TOP_SCREEN, 0, 0); const char *list[] = { @@ -67,9 +66,20 @@ int menu_options() { else fprintf(TOP_SCREEN, " "); - fprintf(TOP_SCREEN, "[%c] %s\n", (config.options[i] ? 'X' : ' '), list[i]); + if (need_redraw) + fprintf(TOP_SCREEN, "[%c] %s\n", (config.options[i] ? 'X' : ' '), list[i]); + else { + // Yes, this is weird. printf does a large number of extra things we don't + // want computed at the moment; this is faster. + putc(TOP_SCREEN, '['); + putc(TOP_SCREEN, (config.options[i] ? 'X' : ' ')); + putc(TOP_SCREEN, ']'); + putc(TOP_SCREEN, '\n'); + } } + need_redraw = 0; + uint32_t key = wait_key(); switch(key) { @@ -84,6 +94,9 @@ int menu_options() { config.options[cursor_y] = !config.options[cursor_y]; break; case BUTTON_B: + need_redraw = 1; + clear_screen(TOP_SCREEN); + cursor_y = 0; return MENU_MAIN; break; } @@ -126,11 +139,15 @@ int menu_help() { "\n" " \n" "\n"); + while (1) { if (wait_key() & BUTTON_ANY) break; } + need_redraw = 1; + clear_screen(TOP_SCREEN); + return MENU_MAIN; } @@ -153,8 +170,6 @@ int menu_poweroff() { } int menu_main() { - clear_screen(TOP_SCREEN); - set_cursor(TOP_SCREEN, 0, 0); const char *list[] = { @@ -176,12 +191,20 @@ int menu_main() { fprintf(TOP_SCREEN, "\x1b[32m>>\x1b[0m "); else fprintf(TOP_SCREEN, " "); - fprintf(TOP_SCREEN, "%s\n", list[i]); + + if (need_redraw) + fprintf(TOP_SCREEN, "%s\n", list[i]); + else + putc(TOP_SCREEN, '\n'); } } + need_redraw = 0; + uint32_t key = wait_key(); + int ret = cursor_y+2; + switch(key) { case BUTTON_UP: cursor_y -= 1; @@ -194,8 +217,9 @@ int menu_main() { cursor_y += 1; // Disable help. break; case BUTTON_A: - return cursor_y+2; - break; + need_redraw = 1; + cursor_y = 0; + return ret; } // Loop around the cursor. diff --git a/source/std/README.txt b/source/std/README.txt new file mode 100644 index 0000000..3dc3d2e --- /dev/null +++ b/source/std/README.txt @@ -0,0 +1 @@ +This is (sort of) an implementation of C99 std. It is pathetically uncompliant but may be of interest to people wishing to have a usable 16-color printf function. -- 2.39.5