#include #include #include #include #include #include #include #include "main.h" #include "detect.h" #define MENU_ROWS_COUNT 10 uint8_t menu(void) { uint8_t index_selected = 0; uint8_t index_first = 0; uint8_t index_pastlast; uint8_t index_count = detected_levels_count; uint8_t i, y, key_pressed; for (;;) { os_ClrHome(); asm("\tSET 3, (iy + 5)\n"); /* 5 == TextFlags, 3 == TextInverse */ print_text(0, y = 0, " BOULDASH v1.0 "); print_text(0, (MENU_ROWS_COUNT-1), " Made by Nathan MESNARD "); asm("\tRES 3, (iy + 5)\n"); /* 5 == TextFlags, 3 == TextInverse */ index_pastlast = index_first + (MENU_ROWS_COUNT-2); if (index_pastlast > index_count) index_pastlast = index_count; for (i = index_first; i < index_pastlast; ++i) { detect_level_description(i); print_text(1, ++y, &detected_level_description[0]); } for (;;) { print_text(0, index_selected - index_first + 1, "\xDF"); /* => */ while (!(key_pressed = os_GetCSC())); print_text(0, index_selected - index_first + 1, " "); if (key_pressed == sk_Down) { if (index_selected+1 < index_count) { if (++index_selected == index_pastlast) { index_first = index_selected; break; } } } else if (key_pressed == sk_Up) { if (index_selected) { if (--index_selected < index_first) { index_first -= (MENU_ROWS_COUNT-2); break; } } } else if (key_pressed == sk_Enter) { confirm: return index_selected; } else if (key_pressed == sk_Clear) { cancel: return 255; } } } }