int main(void) { char key; timerInitTOD(); screenInit(); progressInit(); g_strFileName[0] = '\0'; g_nDrive = *(uint8_t*)0xba; if (g_nDrive < 8) g_nDrive = 8; internalCartType = INTERNAL_CART_TYPE_NONE; g_bFastLoaderEnabled = 1; updateFastLoaderText(); refreshMainScreen(); showAbout(); refreshMainScreen(); screenBing(); // this also makes visible 16kByte of flash memory checkFlashType(); checkRAM(); for (;;) { setStatus("Ready. Press <m> for Menu."); key = cgetc(); switch (key) { case 'm': execMenu(&menuMain); break; case 'o': execMenu(&menuOptions); break; case 'e': execMenu(&menuExpert); break; case 'h': execMenu(&menuHelp); break; } } return 0; }
/** * Check if the RAM at $DF00 is okay. * If it is not okay, print an error message. */ static void checkRAM(void) { if (!tortureTestCheckRAM()) { screenPrintSimpleDialog(apStrBadRAM); refreshMainScreen(); } }
/** * Return the string entered. The maximal length of the string is * FILENAME_MAX, i.e. 16+1. */ const char* __fastcall__ screenReadInput(const char* pStrTitle, const char* pStrDefault) { uint8_t len; static char strInput[FILENAME_MAX]; char c; screenBing(); strcpy(strInput, pStrDefault); len = strlen(strInput); screenPrintBox(2, 6, 36, 12); screenPrintSepLine(2, 37, 8); cputsxy(3, 7, pStrTitle); // the input field textcolor(COLOR_LIGHTFRAME); screenPrintBox(4, 10, 32, 3); textcolor(COLOR_FOREGROUND); screenPrintButton(30, 14, "Enter"); cursor(1); do { cputsxy(5, 11, strInput); cputc(' '); gotox(5 + len); c = cgetc(); if (len < sizeof(strInput) - 1 && ((c >= 32 && c < 128) || (c >= 192 && c < 224)) ) { strInput[len++] = c; strInput[len] = '\0'; } else if (c == CH_DEL) { if (len) strInput[--len] = '\0'; } } while (c != CH_ENTER); cursor(0); refreshMainScreen(); return strInput; }
/** * Show and handle the menu and execute the menu item is one was selected. */ void __fastcall__ screenDoMenu(ScreenMenu* pMenu) { uint8_t nEntry, nEntries; uint8_t nSelected; char key; ScreenMenuEntry* pEntries; ScreenMenuEntry* pEntry; pCurrentMenu = pMenu; nSelected = 0; do { pCurrentMenu->nSelected = nSelected; pEntries = pCurrentMenu->entries; nEntries = screenPrintCurrentMenu(); key = cgetc(); switch (key) { case CH_CURS_UP: if (nSelected) --nSelected; else nSelected = nEntries - 1; break; case CH_CURS_DOWN: if (++nSelected == nEntries) nSelected = 0; break; case CH_CURS_RIGHT: if (pCurrentMenu->pNextMenu) { pCurrentMenu = pCurrentMenu->pNextMenu; refreshMainScreen(); nEntries = screenPrintCurrentMenu(); nSelected = 0; } break; case CH_CURS_LEFT: if (pCurrentMenu->pPrevMenu) { pCurrentMenu = pCurrentMenu->pPrevMenu; refreshMainScreen(); nEntries = screenPrintCurrentMenu(); nSelected = 0; } break; case CH_ENTER: case ' ': pEntry = pEntries + nSelected; if (pEntry->pCheckFunction()) { pEntry->pFunction(); if (pEntry->flags & SCREEN_MENU_ENTRY_FLAG_KEEP) { // refresh, because the length may have changed refreshMainScreen(); screenPrintCurrentMenu(); } else return; } break; default: /* all other keys may be shortcuts */ for (nEntry = 0; nEntry != nEntries; ++nEntry) { if (screenMenuEntryHasShortcut(pCurrentMenu->entries + nEntry, key) && pEntries[nEntry].pCheckFunction()) { pCurrentMenu->nSelected = nEntry; // update immediately to show the effect to the user screenPrintCurrentMenu(); pEntries[nEntry].pFunction(); return; } } } } while (key != CH_STOP && key != CH_BTEE); }
/** * Execute an action according to the given menu ID. */ static void __fastcall__ execMenu(ScreenMenu* pMenu) { screenDoMenu(pMenu); refreshMainScreen(); }
/** * Read Flash manufacturer and device IDs, print then on the screen. * If they are not okay, print an error message and return 0. * If everything is okay, return 1. */ uint8_t checkFlashType(void) { uint8_t* pDriver; uint8_t bDriverFound = 0; pDriver = aEAPIDrivers[0]; while (*pDriver) { memcpy(EAPI_LOAD_TO, pDriver, EAPI_SIZE); nBanks = eapiInit(&nManufacturerId, &nDeviceId); if (nBanks > 0) { bDriverFound = 1; break; } /* if we are here, there is an error */ switch (nDeviceId) { case EAPI_ERR_RAM: screenPrintSimpleDialog(apStrBadRAM); goto failed; case EAPI_ERR_ROML_PROTECTED: screenPrintSimpleDialog(apStrROMLProtected); goto failed; case EAPI_ERR_ROMH_PROTECTED: screenPrintSimpleDialog(apStrROMHProtected); goto failed; } pDriver += EAPI_SIZE; } if (bDriverFound) { pStrFlashDriver = EAPI_DRIVER_NAME; nSlots = 1; if (nBanks < 64) { nSlots = nBanks; nBanks = 64; } updateMemSizeText(); refreshMainScreen(); if (nSlots > 1) selectSlot(nSlots); return 1; } else { screenPrintSimpleDialog(apStrWrongFlash); } failed: pStrFlashDriver = "(failed)"; refreshMainScreen(); nManufacturerId = nDeviceId = 0; return 0; }