2017-06-05 02:02:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Luma3DS
|
2019-02-25 02:04:32 +01:00
|
|
|
* Copyright (C) 2016-2019 Aurora Wright, TuxSH
|
2017-06-05 02:02:04 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
|
|
|
* * Requiring preservation of specified reasonable legal notices or
|
|
|
|
* author attributions in that material or in the Appropriate Legal
|
|
|
|
* Notices displayed by works containing it.
|
|
|
|
* * Prohibiting misrepresentation of the origin of that material,
|
|
|
|
* or requiring that modified versions of such material be marked in
|
|
|
|
* reasonable ways as different from the original version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <3ds.h>
|
|
|
|
#include "menu.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "fmt.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "ifile.h"
|
|
|
|
#include "menus.h"
|
|
|
|
#include "utils.h"
|
2018-11-15 13:38:19 +01:00
|
|
|
#include "plgloader.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
#include "menus/n3ds.h"
|
2017-12-21 18:14:04 +01:00
|
|
|
#include "menus/cheats.h"
|
2017-06-15 17:38:45 +02:00
|
|
|
#include "minisoc.h"
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
u32 waitInputWithTimeout(u32 msec)
|
|
|
|
{
|
|
|
|
bool pressedKey = false;
|
|
|
|
u32 key = 0;
|
|
|
|
u32 n = 0;
|
|
|
|
|
|
|
|
//Wait for no keys to be pressed
|
|
|
|
while(HID_PAD && !terminationRequest && (msec == 0 || n < msec))
|
|
|
|
{
|
|
|
|
svcSleepThread(1 * 1000 * 1000LL);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(terminationRequest || (msec != 0 && n >= msec))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
//Wait for a key to be pressed
|
|
|
|
while(!HID_PAD && !terminationRequest && (msec == 0 || n < msec))
|
|
|
|
{
|
|
|
|
svcSleepThread(1 * 1000 * 1000LL);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(terminationRequest || (msec != 0 && n >= msec))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
key = HID_PAD;
|
|
|
|
|
|
|
|
//Make sure it's pressed
|
|
|
|
for(u32 i = 0x26000; i > 0; i --)
|
|
|
|
{
|
|
|
|
if(key != HID_PAD) break;
|
|
|
|
if(i == 1) pressedKey = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while(!pressedKey);
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 waitInput(void)
|
|
|
|
{
|
|
|
|
return waitInputWithTimeout(0);
|
|
|
|
}
|
|
|
|
|
2017-06-06 01:21:52 +02:00
|
|
|
u32 waitComboWithTimeout(u32 msec)
|
|
|
|
{
|
|
|
|
u32 key = 0;
|
|
|
|
u32 n = 0;
|
|
|
|
|
|
|
|
//Wait for no keys to be pressed
|
|
|
|
while(HID_PAD && !terminationRequest && (msec == 0 || n < msec))
|
|
|
|
{
|
|
|
|
svcSleepThread(1 * 1000 * 1000LL);
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(terminationRequest || (msec != 0 && n >= msec))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
svcSleepThread(1 * 1000 * 1000LL);
|
|
|
|
n++;
|
|
|
|
|
|
|
|
u32 tempKey = HID_PAD;
|
|
|
|
|
|
|
|
for(u32 i = 0x26000; i > 0; i--)
|
|
|
|
{
|
|
|
|
if(tempKey != HID_PAD) break;
|
|
|
|
if(i == 1) key = tempKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while((!key || HID_PAD) && !terminationRequest && (msec == 0 || n < msec));
|
|
|
|
|
|
|
|
if(terminationRequest || (msec != 0 && n >= msec))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return key;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 waitCombo(void)
|
|
|
|
{
|
|
|
|
return waitComboWithTimeout(0);
|
|
|
|
}
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
static MyThread menuThread;
|
2019-02-21 19:47:35 +01:00
|
|
|
static u8 ALIGN(8) menuThreadStack[0x3000];
|
2017-06-05 02:02:04 +02:00
|
|
|
static u8 batteryLevel = 255;
|
2018-11-15 13:38:19 +01:00
|
|
|
static u32 homeBtnPressed = 0;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
MyThread *menuCreateThread(void)
|
|
|
|
{
|
2018-11-15 13:38:19 +01:00
|
|
|
svcKernelSetState(0x10007, &homeBtnPressed);
|
2018-04-15 16:26:20 +02:00
|
|
|
if(R_FAILED(MyThread_Create(&menuThread, menuThreadMain, menuThreadStack, 0x3000, 52, CORE_SYSTEM)))
|
2017-06-05 02:02:04 +02:00
|
|
|
svcBreak(USERBREAK_PANIC);
|
|
|
|
return &menuThread;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern bool isN3DS;
|
2017-06-18 22:31:21 +02:00
|
|
|
u32 menuCombo;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2018-11-15 13:38:19 +01:00
|
|
|
u32 DispWarningOnHome(void);
|
|
|
|
|
|
|
|
void menuThreadMain(void)
|
2017-06-05 02:02:04 +02:00
|
|
|
{
|
|
|
|
if(!isN3DS)
|
|
|
|
{
|
|
|
|
rosalinaMenu.nbItems--;
|
2018-04-05 23:40:18 +02:00
|
|
|
for(u32 i = 0; i <= rosalinaMenu.nbItems; i++)
|
2017-06-05 02:02:04 +02:00
|
|
|
rosalinaMenu.items[i] = rosalinaMenu.items[i+1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
N3DSMenu_UpdateStatus();
|
|
|
|
|
2018-01-18 23:39:47 +01:00
|
|
|
bool isAcURegistered = false;
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
while(!terminationRequest)
|
|
|
|
{
|
|
|
|
if((HID_PAD & menuCombo) == menuCombo)
|
|
|
|
{
|
2018-01-18 23:39:47 +01:00
|
|
|
if (!isAcURegistered)
|
|
|
|
isAcURegistered = R_SUCCEEDED(srvIsServiceRegistered(&isAcURegistered, "ac:u"))
|
|
|
|
&& isAcURegistered;
|
|
|
|
|
2018-11-15 13:38:19 +01:00
|
|
|
else
|
2018-01-18 23:39:47 +01:00
|
|
|
{
|
|
|
|
menuEnter();
|
|
|
|
if(isN3DS) N3DSMenu_UpdateStatus();
|
2018-11-15 13:38:19 +01:00
|
|
|
PluginLoader__UpdateMenu();
|
2018-01-18 23:39:47 +01:00
|
|
|
menuShow(&rosalinaMenu);
|
|
|
|
menuLeave();
|
|
|
|
}
|
2017-06-05 02:02:04 +02:00
|
|
|
}
|
2017-12-21 18:14:04 +01:00
|
|
|
else
|
|
|
|
{
|
2018-08-09 14:21:16 +02:00
|
|
|
Cheat_ApplyCheats();
|
2017-12-21 18:14:04 +01:00
|
|
|
}
|
2018-11-15 13:38:19 +01:00
|
|
|
|
|
|
|
// Check for home button on O3DS Mode3 with plugin loaded
|
|
|
|
if (homeBtnPressed != 0)
|
|
|
|
{
|
|
|
|
if (DispWarningOnHome())
|
|
|
|
svcKernelSetState(7); ///< reboot is fine since exiting a mode3 game reboot anyway
|
|
|
|
|
|
|
|
homeBtnPressed = 0;
|
|
|
|
}
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
svcSleepThread(50 * 1000 * 1000LL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static s32 menuRefCount = 0;
|
|
|
|
void menuEnter(void)
|
|
|
|
{
|
|
|
|
if(AtomicPostIncrement(&menuRefCount) == 0)
|
|
|
|
{
|
|
|
|
svcKernelSetState(0x10000, 1);
|
|
|
|
svcSleepThread(5 * 1000 * 100LL);
|
|
|
|
Draw_SetupFramebuffer();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void menuLeave(void)
|
|
|
|
{
|
|
|
|
svcSleepThread(50 * 1000 * 1000);
|
|
|
|
|
|
|
|
if(AtomicDecrement(&menuRefCount) == 0)
|
|
|
|
{
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
Draw_RestoreFramebuffer();
|
|
|
|
Draw_Unlock();
|
|
|
|
svcKernelSetState(0x10000, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void menuDraw(Menu *menu, u32 selected)
|
|
|
|
{
|
|
|
|
char versionString[16];
|
|
|
|
s64 out;
|
|
|
|
u32 version, commitHash;
|
|
|
|
bool isRelease;
|
2018-01-15 02:52:50 +01:00
|
|
|
bool isMcuHwcRegistered;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
2018-01-15 02:52:50 +01:00
|
|
|
if(R_SUCCEEDED(srvIsServiceRegistered(&isMcuHwcRegistered, "mcu::HWC")) && isMcuHwcRegistered && R_SUCCEEDED(mcuHwcInit()))
|
2017-10-05 18:41:11 +02:00
|
|
|
{
|
2018-01-01 18:05:22 +01:00
|
|
|
if(R_FAILED(MCUHWC_GetBatteryLevel(&batteryLevel)))
|
2017-10-05 18:41:11 +02:00
|
|
|
batteryLevel = 255;
|
|
|
|
mcuHwcExit();
|
|
|
|
}
|
2018-01-15 02:52:50 +01:00
|
|
|
else
|
|
|
|
batteryLevel = 255;
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
svcGetSystemInfo(&out, 0x10000, 0);
|
|
|
|
version = (u32)out;
|
|
|
|
|
|
|
|
svcGetSystemInfo(&out, 0x10000, 1);
|
|
|
|
commitHash = (u32)out;
|
|
|
|
|
2017-06-18 22:31:21 +02:00
|
|
|
svcGetSystemInfo(&out, 0x10000, 0x200);
|
2017-06-05 02:02:04 +02:00
|
|
|
isRelease = (bool)out;
|
|
|
|
|
|
|
|
if(GET_VERSION_REVISION(version) == 0)
|
2018-05-24 00:55:38 +02:00
|
|
|
sprintf(versionString, "v%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version));
|
2017-06-05 02:02:04 +02:00
|
|
|
else
|
2018-05-24 00:55:38 +02:00
|
|
|
sprintf(versionString, "v%lu.%lu.%lu", GET_VERSION_MAJOR(version), GET_VERSION_MINOR(version), GET_VERSION_REVISION(version));
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, menu->title);
|
|
|
|
|
|
|
|
for(u32 i = 0; i < 15; i++)
|
|
|
|
{
|
|
|
|
if(i >= menu->nbItems)
|
|
|
|
break;
|
|
|
|
Draw_DrawString(30, 30 + i * SPACING_Y, COLOR_WHITE, menu->items[i].title);
|
|
|
|
Draw_DrawCharacter(10, 30 + i * SPACING_Y, COLOR_TITLE, i == selected ? '>' : ' ');
|
|
|
|
}
|
|
|
|
|
2017-06-15 17:38:45 +02:00
|
|
|
if(miniSocEnabled)
|
|
|
|
{
|
|
|
|
char ipBuffer[17];
|
|
|
|
u32 ip = gethostid();
|
|
|
|
u8 *addr = (u8 *)&ip;
|
|
|
|
int n = sprintf(ipBuffer, "%hhu.%hhu.%hhu.%hhu", addr[0], addr[1], addr[2], addr[3]);
|
|
|
|
Draw_DrawString(SCREEN_BOT_WIDTH - 10 - SPACING_X * n, 10, COLOR_WHITE, ipBuffer);
|
|
|
|
}
|
|
|
|
|
2017-06-25 00:14:07 +02:00
|
|
|
Draw_DrawFormattedString(SCREEN_BOT_WIDTH - 10 - 4 * SPACING_X, SCREEN_BOT_HEIGHT - 20, COLOR_WHITE, " ");
|
|
|
|
|
2017-06-05 02:02:04 +02:00
|
|
|
if(batteryLevel != 255)
|
|
|
|
Draw_DrawFormattedString(SCREEN_BOT_WIDTH - 10 - 4 * SPACING_X, SCREEN_BOT_HEIGHT - 20, COLOR_WHITE, "%02hhu%%", batteryLevel);
|
|
|
|
else
|
|
|
|
Draw_DrawString(SCREEN_BOT_WIDTH - 10 - 4 * SPACING_X, SCREEN_BOT_HEIGHT - 20, COLOR_WHITE, " ");
|
|
|
|
|
|
|
|
if(isRelease)
|
|
|
|
Draw_DrawFormattedString(10, SCREEN_BOT_HEIGHT - 20, COLOR_TITLE, "Luma3DS %s", versionString);
|
|
|
|
else
|
2018-05-24 00:55:38 +02:00
|
|
|
Draw_DrawFormattedString(10, SCREEN_BOT_HEIGHT - 20, COLOR_TITLE, "Luma3DS %s-%08lx", versionString, commitHash);
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
void menuShow(Menu *root)
|
|
|
|
{
|
|
|
|
u32 selectedItem = 0;
|
|
|
|
Menu *currentMenu = root;
|
|
|
|
u32 nbPreviousMenus = 0;
|
|
|
|
Menu *previousMenus[0x80];
|
2017-08-16 23:46:36 +02:00
|
|
|
u32 previousSelectedItems[0x80];
|
2017-06-05 02:02:04 +02:00
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
menuDraw(currentMenu, selectedItem);
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
u32 pressed = waitInputWithTimeout(1000);
|
|
|
|
|
|
|
|
if(pressed & BUTTON_A)
|
|
|
|
{
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
switch(currentMenu->items[selectedItem].action_type)
|
|
|
|
{
|
|
|
|
case METHOD:
|
|
|
|
if(currentMenu->items[selectedItem].method != NULL)
|
|
|
|
currentMenu->items[selectedItem].method();
|
|
|
|
break;
|
|
|
|
case MENU:
|
2017-08-16 23:46:36 +02:00
|
|
|
previousSelectedItems[nbPreviousMenus] = selectedItem;
|
2017-06-05 02:02:04 +02:00
|
|
|
previousMenus[nbPreviousMenus++] = currentMenu;
|
|
|
|
currentMenu = currentMenu->items[selectedItem].menu;
|
|
|
|
selectedItem = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
Draw_Unlock();
|
|
|
|
}
|
|
|
|
else if(pressed & BUTTON_B)
|
|
|
|
{
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
Draw_Unlock();
|
|
|
|
|
|
|
|
if(nbPreviousMenus > 0)
|
2017-08-16 23:46:36 +02:00
|
|
|
{
|
2017-06-05 02:02:04 +02:00
|
|
|
currentMenu = previousMenus[--nbPreviousMenus];
|
2017-08-16 23:46:36 +02:00
|
|
|
selectedItem = previousSelectedItems[nbPreviousMenus];
|
|
|
|
}
|
2017-06-05 02:02:04 +02:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(pressed & BUTTON_DOWN)
|
|
|
|
{
|
|
|
|
if(++selectedItem >= currentMenu->nbItems)
|
|
|
|
selectedItem = 0;
|
|
|
|
}
|
|
|
|
else if(pressed & BUTTON_UP)
|
|
|
|
{
|
|
|
|
if(selectedItem-- <= 0)
|
|
|
|
selectedItem = currentMenu->nbItems - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
menuDraw(currentMenu, selectedItem);
|
|
|
|
Draw_Unlock();
|
|
|
|
}
|
|
|
|
while(!terminationRequest);
|
|
|
|
}
|
2018-11-15 13:38:19 +01:00
|
|
|
|
|
|
|
static const char *__press_b_to_close = "Press [B] to close";
|
|
|
|
|
|
|
|
void DispMessage(const char *title, const char *message)
|
|
|
|
{
|
|
|
|
menuEnter();
|
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, title);
|
|
|
|
|
|
|
|
Draw_DrawString(30, 30, COLOR_WHITE, message);
|
|
|
|
Draw_DrawString(200, 220, COLOR_TITLE, __press_b_to_close);
|
|
|
|
|
|
|
|
|
|
|
|
u32 keys = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
keys = waitComboWithTimeout(1000);
|
|
|
|
}while (!terminationRequest && !(keys & BUTTON_B));
|
|
|
|
|
|
|
|
Draw_Unlock(); ///< Keep it locked until we exit the message
|
|
|
|
menuLeave();
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 DispErrMessage(const char *title, const char *message, const Result error)
|
|
|
|
{
|
|
|
|
char buf[100];
|
|
|
|
|
2019-06-29 16:26:03 +02:00
|
|
|
sprintf(buf, "Error code: 0x%08X", (unsigned int)error);
|
2018-11-15 13:38:19 +01:00
|
|
|
menuEnter();
|
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, title);
|
|
|
|
|
|
|
|
u32 posY = Draw_DrawString(30, 30, COLOR_WHITE, message);
|
|
|
|
Draw_DrawString(30, posY + 20, COLOR_RED, buf);
|
|
|
|
Draw_DrawString(200, 220, COLOR_TITLE, __press_b_to_close);
|
|
|
|
|
|
|
|
u32 keys = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
keys = waitComboWithTimeout(1000);
|
|
|
|
}while (!terminationRequest && !(keys & BUTTON_B));
|
|
|
|
|
|
|
|
Draw_Unlock(); ///< Keep it locked until we exit the message
|
|
|
|
menuLeave();
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
u32 DispWarningOnHome(void)
|
|
|
|
{
|
|
|
|
menuEnter();
|
|
|
|
|
|
|
|
Draw_Lock();
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, "Warning");
|
|
|
|
|
|
|
|
u32 posY = Draw_DrawString(30, 40, COLOR_WHITE, "Due to memory shortage the home button\nis disabled.");
|
|
|
|
Draw_DrawString(30, posY + 20, COLOR_WHITE, "Press [DPAD UP + B] to exit the application.");
|
|
|
|
Draw_DrawString(200, 220, COLOR_TITLE, __press_b_to_close);
|
|
|
|
|
|
|
|
|
|
|
|
u32 keys = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
keys = waitComboWithTimeout(1000);
|
|
|
|
}while (!terminationRequest && !(keys & BUTTON_B));
|
|
|
|
|
|
|
|
Draw_Unlock(); ///< Keep it locked until we exit the message
|
|
|
|
menuLeave();
|
|
|
|
|
|
|
|
return (keys & BUTTON_UP) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
typedef char string[50];
|
|
|
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
|
|
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
|
|
|
|
|
|
|
void DisplayPluginMenu(u32 *cmdbuf)
|
|
|
|
{
|
|
|
|
u32 cursor = 0;
|
|
|
|
u32 nbItems = cmdbuf[1];
|
|
|
|
u8 *states = (u8 *)cmdbuf[3];
|
|
|
|
char buffer[60];
|
|
|
|
const char *title = (const char *)cmdbuf[5];
|
|
|
|
const string *items = (const string *)cmdbuf[7];
|
|
|
|
const string *hints = (const string *)cmdbuf[9];
|
|
|
|
|
|
|
|
menuEnter();
|
|
|
|
Draw_Lock();
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
// Draw the menu
|
|
|
|
{
|
|
|
|
// Clear screen
|
|
|
|
Draw_ClearFramebuffer();
|
|
|
|
Draw_FlushFramebuffer();
|
|
|
|
|
|
|
|
// Draw title
|
|
|
|
Draw_DrawString(10, 10, COLOR_TITLE, title);
|
|
|
|
|
|
|
|
// Draw items
|
|
|
|
u32 i = MAX(0, (int)cursor - 7);
|
|
|
|
u32 end = MIN(nbItems, i + 16);
|
|
|
|
u32 posY = 30;
|
|
|
|
|
|
|
|
for (; i < end; ++i, posY += 10)
|
|
|
|
{
|
|
|
|
sprintf(buffer, "[ ] %s", items[i]);
|
|
|
|
Draw_DrawString(30, posY, COLOR_WHITE, buffer);
|
|
|
|
|
|
|
|
if (i == cursor) Draw_DrawCharacter(10, posY, COLOR_TITLE, '>');
|
|
|
|
if (states[i]) Draw_DrawCharacter(36, posY, COLOR_LIME, 'x');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw hint
|
|
|
|
if (hints[cursor])
|
|
|
|
Draw_DrawString(10, 200, COLOR_TITLE, hints[cursor]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for input
|
|
|
|
u32 pressed = waitInput();
|
|
|
|
|
|
|
|
if (pressed & BUTTON_A)
|
|
|
|
states[cursor] = !states[cursor];
|
|
|
|
|
|
|
|
if (pressed & BUTTON_B)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (pressed & BUTTON_DOWN)
|
|
|
|
if (++cursor >= nbItems)
|
|
|
|
cursor = 0;
|
|
|
|
|
|
|
|
if (pressed & BUTTON_UP)
|
|
|
|
if (--cursor >= nbItems)
|
|
|
|
cursor = nbItems - 1;
|
|
|
|
|
|
|
|
} while (true);
|
|
|
|
|
|
|
|
Draw_Unlock();
|
|
|
|
menuLeave();
|
|
|
|
}
|