mirror of
https://gitee.com/anod/open_agb_firm.git
synced 2025-05-06 13:54:09 +08:00
190 lines
6.6 KiB
C
190 lines
6.6 KiB
C
#include "arm11/pages.h"
|
||
#include "arm11/drivers/mcu.h"
|
||
|
||
/// @brief base process for helping page
|
||
/// @param table
|
||
/// @param index
|
||
/// @param config
|
||
/// @return
|
||
static atp_error_t display_help( atp_callerdata_t table, atp_counter_t index, atp_linecfg_t *config )
|
||
{
|
||
atp_text_t *list = (atp_text_t*)table;
|
||
config->text_align = ATP_PLACEMENT_CENTER;
|
||
config->text_color = index == 0 ? ATP_COLOR_MAGENTA : ATP_COLOR_LIGHT;
|
||
config->text = list[index];
|
||
return ATP_SUCCESS;
|
||
}
|
||
|
||
/// @brief display a static page for help
|
||
/// @param wording static string array
|
||
/// @param length the size of array
|
||
/// @return
|
||
atp_error_t help_page( atp_text_t *wording, atp_counter_t length )
|
||
{
|
||
atp_text_t current;
|
||
atp_tips( "返回:按A/B", ¤t );
|
||
atp_error_t res = atp_show( length, display_help, (atp_callerdata_t)wording );
|
||
atp_tips( current, NULL );
|
||
return res;
|
||
}
|
||
|
||
// --------------------------
|
||
// code for oaf config page
|
||
// --------------------------
|
||
atp_text_t config_help[] =
|
||
{
|
||
"全局参数编辑操作指引",
|
||
"~ ~ ~ ~ ~ ~ ~",
|
||
"-修改后的全局参数保存在config.ini ",
|
||
"保存修改时,存档方案的修改不会保存",
|
||
"-金手指组合键为下方向+L+R+SELECT",
|
||
" 也可以使用HOME键直接代替组合键 ",
|
||
"~ ~ ~ ~ ~ ~ ~",
|
||
"上下方向键 切换参数项目",
|
||
"左右方向键 翻页",
|
||
"L键和R键 调整当前参数",
|
||
"A键 应用修改退出",
|
||
"B键 放弃修改退出",
|
||
"X键 应用修改保存退出", // X做保存,选中后走A键流程
|
||
};
|
||
atp_text_t CONFIG_OUTPUT = "[general]\n" \
|
||
"backlight=%d\n" \
|
||
"directBoot=%s\n" \
|
||
"useGbaDb=true\n\n" \
|
||
"[video]\n" \
|
||
"scaler=%d\n" \
|
||
"gbaGamma=2.2\n" \
|
||
"lcdGamma=1.54\n" \
|
||
"contrast=1.0\n" \
|
||
"brightness=0.0\n\n" \
|
||
"[advanced]\n" \
|
||
"saveOverride=false\n" \
|
||
"defaultSave=14\n\n" \
|
||
"[boost]\n" \
|
||
"cheatMode=%d\n";
|
||
|
||
typedef struct global_oaf_config OafConfig;
|
||
|
||
static char page_strbuf[512];
|
||
|
||
#define LIGHT_MIN (MCU_getSystemModel() > 3 ? 50 : 20)
|
||
#define LIGHT_MAX (MCU_getSystemModel() > 3 ? 800 : 500)
|
||
#define SCALER_SIZE 4
|
||
static atp_error_t config_item( atp_callerdata_t gblcfg, atp_counter_t index, atp_itemcfg_t *cfg )
|
||
{
|
||
//static char buf[16];
|
||
OafConfig *g_oafConfig = (OafConfig*)gblcfg;
|
||
const char *scaler_val[] = {"上屏无缩放", "上屏GPU放大", "上屏DMA放大", "下屏无缩放"};
|
||
const char *savetype_name[] = {"和卡带序列号一致", "读取ROM的特定标记", "汉化带SRAM补丁", "自行决定"};
|
||
const char *cheatmode_name[] = {"关闭金手指", "全程激活", "组合键单次激活", "组合键激活/关闭"};
|
||
cfg->extra_text_color = ATP_COLOR_GREEN;
|
||
if( index == 0 )
|
||
{
|
||
ee_snprintf(page_strbuf, sizeof(page_strbuf), "%d", g_oafConfig->backlight);
|
||
cfg->text = "屏幕亮度";
|
||
cfg->extra_text = page_strbuf;
|
||
if( g_oafConfig->backlight == LIGHT_MIN || g_oafConfig->backlight == LIGHT_MAX )
|
||
cfg->extra_text_color = ATP_COLOR_RED;
|
||
}
|
||
else if( index == 1 )
|
||
{
|
||
cfg->text = "GAME BOY画面";
|
||
cfg->extra_text = g_oafConfig->directBoot ? "跳过" : "显示";
|
||
}
|
||
else if( index == 2 )
|
||
{
|
||
cfg->text = "画面输出";
|
||
cfg->extra_text = scaler_val[g_oafConfig->scaler];
|
||
}
|
||
else if( index == 3 )
|
||
{
|
||
cfg->text = "存档方案";
|
||
cfg->extra_text = savetype_name[g_oafConfig->savePolicy];
|
||
}
|
||
else if( index == 4 )
|
||
{
|
||
cfg->text = "激活金手指";
|
||
cfg->extra_text = cheatmode_name[g_oafConfig->cheatMode];
|
||
}
|
||
cfg->value = index;
|
||
return ATP_SUCCESS;
|
||
}
|
||
|
||
static atp_pageopt_t config_adjust( atp_callerdata_t gblcfg, atp_counter_t index, atp_boolean_t x, atp_boolean_t, atp_boolean_t l, atp_boolean_t r, atp_boolean_t start, atp_boolean_t )
|
||
{
|
||
OafConfig *g_oafConfig = (OafConfig*)gblcfg;
|
||
if( l || r )
|
||
{
|
||
if( index == 0 )
|
||
{
|
||
u16 light = g_oafConfig->backlight;
|
||
if( l )
|
||
{
|
||
light -= 10;
|
||
if( light % 10 ) light += 10 - light%10;
|
||
}
|
||
else if( r )
|
||
{
|
||
light += 10;
|
||
if( light % 10 ) light -= light % 10;
|
||
}
|
||
if( light > LIGHT_MAX ) light = LIGHT_MAX;
|
||
else if( light < LIGHT_MIN ) light = LIGHT_MIN;
|
||
g_oafConfig->backlight = light;
|
||
}
|
||
else if( index == 1 ) g_oafConfig->directBoot = !g_oafConfig->directBoot;
|
||
else if( index == 2 ) g_oafConfig->scaler = ( SCALER_SIZE + ( g_oafConfig->scaler+(l?-1:1) ) ) % SCALER_SIZE;
|
||
else if( index == 3 ) g_oafConfig->savePolicy = ( SAVE_POLICY_SIZE + ( g_oafConfig->savePolicy+(l?-1:1) ) ) % SAVE_POLICY_SIZE;
|
||
else if( index == 4 ) g_oafConfig->cheatMode = ( CHEAT_MODE_SIZE + (g_oafConfig->cheatMode+(l?-1:1) ) ) % CHEAT_MODE_SIZE;
|
||
}
|
||
else if( start )
|
||
{
|
||
return ATP_POWER_OFF == help_page( config_help, sizeof(config_help)/sizeof(atp_text_t) )
|
||
? ATP_POWER_OFF : ATP_PAGE_REFRESH;
|
||
}
|
||
else if( x )
|
||
{
|
||
int len = strlen(CONFIG_OUTPUT) + 20;
|
||
char *data = malloc( len );
|
||
if( data == NULL ) return ATP_PAGE_DOSELECT; // only ignore this save
|
||
|
||
len = ee_snprintf(
|
||
data, len, CONFIG_OUTPUT,
|
||
g_oafConfig.backlight, g_oafConfig.directBoot ? "true":"false", g_oafConfig.scaler, g_oafConfig.cheatMode
|
||
);
|
||
fsQuickWrite("config.ini", data, len);
|
||
free( data );
|
||
return ATP_PAGE_DOSELECT;
|
||
}
|
||
return ATP_PAGE_UPDATE;
|
||
}
|
||
|
||
atp_error_t use_config_page( OafConfig *g_oafConfig )
|
||
{
|
||
u8 base[sizeof(OafConfig)];
|
||
memcpy( base, g_oafConfig, sizeof(OafConfig) );
|
||
OafConfig *prev = (OafConfig*)&base[0];
|
||
|
||
atp_text_t oldtips;
|
||
atp_tips("保存X/确定A/返回B", &oldtips);
|
||
|
||
ee_snprintf(
|
||
page_strbuf, sizeof(page_strbuf),
|
||
"参数配置 当前电量:%3d%%"
|
||
"每次开机存档方案重置为“和卡带序列号一致”,这个方案会优先使用游戏最后一次启动时设置的存档类型", MCU_getBatteryLevel());
|
||
atp_error_t res = atp_select( page_strbuf, 5, config_item, config_adjust, g_oafConfig, 0, 0, NULL );
|
||
atp_tips( oldtips, NULL );
|
||
if( res == ATP_NO_ACTION )
|
||
{
|
||
memcpy( g_oafConfig, prev, sizeof(OafConfig) );
|
||
return ATP_SUCCESS;
|
||
}
|
||
else if( res == ATP_SUCCESS )
|
||
{
|
||
if( prev->backlight != g_oafConfig->backlight )
|
||
GFX_setBrightness(g_oafConfig->backlight, g_oafConfig->backlight);
|
||
}
|
||
|
||
return res;
|
||
}
|