#include "fsctl/menu.h" #include "fsctl/fugue.h" #include "fsctl/utils/fs_table.h" #include "fsctl/utils/display.h" //--- // internals //--- /* internal information */ static uintptr_t addr_base; static uintptr_t addr_test; /* sector_is_vbr() : check VBR validity */ static int sector_is_vbr(int *color, struct fugue_fat_vbr *vbr) { fugue_fs_t fs; if (fugue_fs_mount(&fs, vbr) == 0) { *color = C_GREEN; fs_table_update(&fs); return 0; } return -1; } /* sector_is_unused() : check if the sector has been erased */ static int sector_is_unused(int *color, uint32_t *addr) { for (int i = 0 ; i < 512 / 4 ; i++) { if (addr[i] != 0xffffffff) return -1; } *color = C_RED; return 0; } /* sector_check() : check various operation on sector */ static int sector_check(void *addr) { int color; if ( sector_is_unused(&color, addr) != 0 && sector_is_vbr(&color, addr) != 0 ) return C_WHITE; return color; } //--- // Public //--- /* rom_menu_init() : init menu */ void rom_menu_init(void) { /* skip first 16Mo (OS stuff) */ addr_base = 0xa1000000; addr_test = 0xa1000000; } /* rom_menu_display() : display menu */ void rom_menu_display(void) { addr_test = addr_base; for (int y = 0 ; y < 18 ; y++) { _printXY(0, y, "%p", addr_test); for (int x = 0 ; x < 25 ; x++) { _rectXY(x, y, sector_check((void *)addr_test)); addr_test += 512; if (addr_test >= 0xa2000000) return; } } } /* rom_menu_keyboard() : handle keyboard */ void rom_menu_keyboard(int key) { switch (key) { case KEY_DOWN: addr_base += 25 * 512; break; case KEY_UP: addr_base -= 25 * 512; break; case KEY_EXIT: addr_base = 0xa0000000; break; case KEY_RIGHT: addr_base += 25 * 18 * 512; break; case KEY_LEFT: addr_base -= 25 * 18 * 512; break; } if (addr_base < 0xa0000000) addr_base = 0xa0000000; }