diff options
Diffstat (limited to 'source/states/menu.c')
| -rw-r--r-- | source/states/menu.c | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/source/states/menu.c b/source/states/menu.c new file mode 100644 index 0000000..15e0b3c --- /dev/null +++ b/source/states/menu.c @@ -0,0 +1,96 @@ +#include <stdio.h> +#include <gccore.h> +#include <wiiuse/wpad.h> +#include <stdlib.h> + +#define EXITEST_STATE_INTERNAL +#include "../state.h" +#include "../term.h" +#include "../test.h" + +static void print_setup_menu(int selected_slot) { + fputs(TERM_CUR_UP(2), stdout); + printf(TERM_CLEARLINE "- [DL/DR] EXI Slot %c\n", selected_slot == 0 ? 'A' : 'B'); + printf(TERM_CLEARLINE "Press A to begin testing.\n"); +} + +static int st_setup_init(const struct et_state *state, void *state_data, et_state_init_data init_data) { + u32 *setup_data = state_data; + + *setup_data = 0; + + printf("\nTest setup menu:\n\n\n\n"); + print_setup_menu(*setup_data); + + return 0; +} + +static int begin_testing(u32 menu_state, struct et_next_state *next_state) { + struct et_test_plan *plan = calloc(1, sizeof(struct et_test_plan)); + if (!plan) { + puts("Failed to allocate new test plan!"); + return -1; + } + + size_t num_tests; + const struct et_test *const *all_tests = et_get_tests(&num_tests); + + struct et_test_plan_entry *plan_entries = calloc(num_tests, sizeof(struct et_test_plan_entry)); + if (!plan_entries) { + puts("Failed to allocate new test plan entries!"); + free(plan); + return -1; + } + + for (size_t i = 0; i < num_tests; ++i) { + plan_entries[i].test = all_tests[i]; + plan_entries[i].status = TEST_PRIMORDIAL; + plan_entries[i].ext_status = NULL; + plan_entries[i].ext_status_free = NULL; + } + + plan->exi_channel = (int)menu_state; + plan->next_state = et_state_summarize_test_plan; + plan->next_state_init.p = plan; + plan->num_tests = num_tests; + plan->current_test = 0; + plan->tests = plan_entries; + + next_state->state = et_state_begin_testing; + next_state->init_data.p = plan; + + return 1; +} + +static int st_setup_tick(const struct et_state *state, void *state_data, struct et_next_state *next_state) { + u32 *setup_data = state_data; + u32 wpad_pressed = WPAD_ButtonsDown(0); + u32 pad_pressed = PAD_ButtonsDown(0); + + if (wpad_pressed & WPAD_BUTTON_LEFT || wpad_pressed & WPAD_BUTTON_RIGHT || pad_pressed & PAD_BUTTON_LEFT || pad_pressed & PAD_BUTTON_RIGHT) { + *setup_data = !*setup_data; + print_setup_menu(*setup_data); + } + + if (wpad_pressed & WPAD_BUTTON_A || pad_pressed & PAD_BUTTON_A) { + /* set up test plan */ + return begin_testing(*setup_data, next_state); + } + + return 0; +} + +static void st_setup_cleanup(const struct et_state *state, void *state_data) { + /* do nothing */ +} + +const et_state_init_data et_init_data_null = { .p = NULL }; + +static struct et_state et__state_setup = { + .init_f = &st_setup_init, + .tick_f = &st_setup_tick, + .cleanup_f = &st_setup_cleanup, + .private_size = sizeof(u32) +}; + +const struct et_state *et_state_setup = &et__state_setup; |
