diff --git a/source/gx/config.c b/source/gx/config.c index b8a3ea1..4918eba 100644 --- a/source/gx/config.c +++ b/source/gx/config.c @@ -21,24 +21,11 @@ * ***************************************************************************/ #include "shared.h" +#include "gui.h" #include "menu.h" #include "file_load.h" -void config_save(void) -{ - /* open configuration file */ - char fname[MAXPATHLEN]; - sprintf (fname, "%s/config.ini", DEFAULT_PATH); - FILE *fp = fopen(fname, "wb"); - if (fp) - { - /* write file */ - fwrite(&config, sizeof(config), 1, fp); - fclose(fp); - } -} - -void config_load(void) +static int config_load(void) { /* open configuration file */ char fname[MAXPATHLEN]; @@ -51,7 +38,7 @@ void config_load(void) fread(version, 16, 1, fp); fclose(fp); if (strncmp(version,CONFIG_VERSION,16)) - return; + return 0; /* read file */ fp = fopen(fname, "rb"); @@ -59,8 +46,24 @@ void config_load(void) { fread(&config, sizeof(config), 1, fp); fclose(fp); + return 1; } } + return 0; +} + +void config_save(void) +{ + /* open configuration file */ + char fname[MAXPATHLEN]; + sprintf (fname, "%s/config.ini", DEFAULT_PATH); + FILE *fp = fopen(fname, "wb"); + if (fp) + { + /* write file */ + fwrite(&config, sizeof(config), 1, fp); + fclose(fp); + } } void config_default(void) @@ -129,6 +132,7 @@ void config_default(void) /* menu options */ config.autoload = 0; + config.autocheat = 0; #ifdef HW_RVL config.s_auto = 1; #else @@ -152,11 +156,13 @@ void config_default(void) sprintf (config.lastdir[TYPE_DVD], "dvd:%s/roms/", DEFAULT_PATH); #endif - /* restore from config file */ - config_load(); - io_init(); + /* try to restore settings from config file */ + if (!config_load()) GUI_WaitPrompt("Info","Default Settings restored"); - /* default menu settings */ + /* restore inputs */ + input_init(); + + /* restore menu settings */ menu_configure(); } diff --git a/source/gx/config.h b/source/gx/config.h index 4520e7b..695fd77 100644 --- a/source/gx/config.h +++ b/source/gx/config.h @@ -24,7 +24,7 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ -#define CONFIG_VERSION "GENPLUS-GX 1.4.0" +#define CONFIG_VERSION "GENPLUS-GX 1.4.1" /**************************************************************************** * Config Option @@ -75,9 +75,11 @@ typedef struct uint32 wpad_keymap[4*3][MAX_KEYS]; #endif uint8 autoload; + uint8 autocheat; uint8 s_auto; uint8 s_default; uint8 s_device; + uint8 autocheats; int8 bg_type; int8 bg_overlay; int16 screen_w; @@ -95,7 +97,6 @@ t_config config; extern void config_save(void); -extern void config_load(void); extern void config_default(void); diff --git a/source/gx/gui/cheats.c b/source/gx/gui/cheats.c index 0da8361..f769f98 100644 --- a/source/gx/gui/cheats.c +++ b/source/gx/gui/cheats.c @@ -34,6 +34,9 @@ #define BG_COLOR_1 {0x49,0x49,0x49,0xff} #define BG_COLOR_2 {0x66,0x66,0x66,0xff} +#define MAX_CHEATS (250) +#define MAX_DESC_LENGTH (63) + #ifdef HW_RVL extern const u8 Key_Minus_wii_png[]; extern const u8 Key_Plus_wii_png[]; @@ -46,8 +49,8 @@ extern const u8 Key_DPAD_png[]; typedef struct { char code[12]; - char text[36]; - u16 enable; + char text[MAX_DESC_LENGTH]; + u8 enable; u16 data; u16 old; u32 address; @@ -59,23 +62,44 @@ static void clear_cheats(void); static void cheatmenu_cb(void); static void switch_chars(void); -static int selection = 0; -static int maxcheats = 0; static int string_offset = 0; +static int selection = 0; +static int offset = 0; static int type = 0; -static int patchRAM =0; +static int maxcheats = 0; +static int maxRAMcheats = 0; -static CHEATENTRY cheatlist[10]; +static CHEATENTRY cheatlist[MAX_CHEATS]; +static u8 RAMcheatlist[MAX_CHEATS]; /*****************************************************************************/ /* GUI Buttons data */ /*****************************************************************************/ +static butn_data arrow_up_data = +{ + {NULL,NULL}, + {Button_up_png,Button_up_over_png} +}; + +static butn_data arrow_down_data = +{ + {NULL,NULL}, + {Button_down_png,Button_down_over_png} +}; static butn_data button_digit_data = { {NULL,NULL}, {Button_digit_png,Button_digit_over_png} }; +/*****************************************************************************/ +/* GUI Arrows button */ +/*****************************************************************************/ + +static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,76,360,32}; +static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_OVER_SFX,{0,0,0,0},14,368,360,32}; + + /*****************************************************************************/ /* GUI helpers */ /*****************************************************************************/ @@ -145,7 +169,7 @@ static gui_item items_cheats[30] = /*****************************************************************************/ static gui_butn buttons_cheats[30] = { - {NULL, BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{0,0,0,0},15,108,358,26}, + {NULL, BUTTON_VISIBLE|BUTTON_ACTIVE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,108,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,134,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,160,358,26}, {NULL, BUTTON_VISIBLE|BUTTON_SELECT_SFX|BUTTON_OVER_SFX,{1,0,0,0},15,186,358,26}, @@ -189,7 +213,7 @@ static gui_menu menu_cheats = buttons_cheats, bg_cheats, {&action_cancel, &action_select}, - {NULL,NULL}, + {&arrow_up,&arrow_down}, cheatmenu_cb }; @@ -290,8 +314,8 @@ static u32 decode_cheat(char *string, u32 *address, u32 *data) static void apply_cheats(void) { - /* clear RAM patch flag */ - patchRAM = 0; + /* clear RAM patches counter */ + maxRAMcheats = 0; int i; for (i = 0; i < maxcheats; i++) @@ -307,7 +331,7 @@ static void apply_cheats(void) else if (cheatlist[i].address >= 0xFF0000) { /* patch RAM data */ - patchRAM = 1; + RAMcheatlist[maxRAMcheats++] = i; } } } @@ -450,7 +474,7 @@ static void cheatmenu_cb(void) int yoffset = 108; gui_image bar_over; gui_image star; - char temp[36]; + char temp[MAX_DESC_LENGTH]; /* Initialize textures */ bar_over.texture = gxTextureOpenPNG(Overlay_bar_png,0); @@ -469,7 +493,7 @@ static void cheatmenu_cb(void) gxDrawRectangle(15, 342, 358, 26, 127, (GXColor)BG_COLOR_2); /* Draw Cheat list */ - for (i=0; i= strlen(cheatlist[i].text)) + if ((string_offset/10) >= strlen(cheatlist[offset + i].text)) { string_offset = 0; } if (string_offset) { - sprintf(temp,"%s ",cheatlist[i].text+string_offset/10); - strncat(temp, cheatlist[i].text, string_offset/10); + sprintf(temp,"%s ",cheatlist[offset + i].text+string_offset/10); + strncat(temp, cheatlist[offset + i].text, string_offset/10); } else { - strcpy(temp, cheatlist[i].text); + strcpy(temp, cheatlist[offset + i].text); } if (FONT_writeCenter(temp,16,40,366,yoffset+21,(GXColor)WHITE)) @@ -512,23 +536,23 @@ static void cheatmenu_cb(void) } else { - FONT_writeCenter(cheatlist[i].code,18,40,366,yoffset+22,(GXColor)WHITE); + FONT_writeCenter(cheatlist[offset + i].code,18,40,366,yoffset+22,(GXColor)WHITE); } } else { if (type) { - FONT_writeCenter(cheatlist[i].text,16,40,366,yoffset+21,(GXColor)WHITE); + FONT_writeCenter(cheatlist[offset + i].text,16,40,366,yoffset+21,(GXColor)WHITE); } else { - FONT_writeCenter(cheatlist[i].code,18,40,366,yoffset+22,(GXColor)WHITE); + FONT_writeCenter(cheatlist[offset + i].code,18,40,366,yoffset+22,(GXColor)WHITE); } } /* draw cheat enable mark */ - if (cheatlist[i].enable) + if (cheatlist[offset + i].enable) { gxDrawTexture(star.texture,20,yoffset+5,16,16,255); } @@ -537,9 +561,9 @@ static void cheatmenu_cb(void) } /* New Entry */ - if (maxcheats < 10) + if (i < 10) { - if (maxcheats == selection) + if (i == selection) { /* selection bar */ gxDrawTexture(bar_over.texture,16,yoffset+1,356,24,255); @@ -547,7 +571,7 @@ static void cheatmenu_cb(void) /* check if new code is being edited */ if (menu_cheats.bg_images[6].state & IMAGE_VISIBLE) { - FONT_writeCenter(cheatlist[selection].code,18,40,366,yoffset+22,(GXColor)WHITE); + FONT_writeCenter(cheatlist[offset + selection].code,18,40,366,yoffset+22,(GXColor)WHITE); } else { @@ -561,6 +585,7 @@ static void cheatmenu_cb(void) } gxTextureClose(&bar_over.texture); + gxTextureClose(&star.texture); /* Extra helpers */ if (maxcheats && !(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) @@ -578,7 +603,7 @@ static void cheatmenu_cb(void) gxTextureClose(&key_switch.texture); /* delete & enable cheats */ - if (menu_cheats.selected < maxcheats) + if ((offset + selection) < maxcheats) { gui_image key_enable; gui_image key_delete; @@ -588,14 +613,14 @@ static void cheatmenu_cb(void) gxDrawTexture(key_delete.texture,152,424,24,24,255); gxDrawTexture(key_enable.texture,372,424,24,24,255); FONT_write("Delete\nCheat",16,184,436,640,(GXColor)WHITE); - FONT_write(cheatlist[selection].enable ? "Disable\nCheat":"Enable\nCheat",16,404,436,640,(GXColor)WHITE); + FONT_write(cheatlist[offset + selection].enable ? "Disable\nCheat":"Enable\nCheat",16,404,436,640,(GXColor)WHITE); #else - key_enable.texture = gxTextureOpenPNG(Key_L_gcn_png,0); - key_delete.texture = gxTextureOpenPNG(Key_R_gcn_png,0); + key_delete.texture = gxTextureOpenPNG(Key_L_gcn_png,0); + key_enable.texture = gxTextureOpenPNG(Key_R_gcn_png,0); gxDrawTexture(key_delete.texture,136,426,44,20,255); gxDrawTexture(key_enable.texture,368,426,44,20,255); FONT_write("Delete\nCheat",16,188,436,640,(GXColor)WHITE); - FONT_write(cheatlist[selection].enable ? "Disable\nCheat":"Enable\nCheat",16,420,436,640,(GXColor)WHITE); + FONT_write(cheatlist[offset + selection].enable ? "Disable\nCheat":"Enable\nCheat",16,420,436,640,(GXColor)WHITE); #endif gxTextureClose(&key_enable.texture); gxTextureClose(&key_delete.texture); @@ -613,7 +638,7 @@ static void cheatmenu_cb(void) void CheatMenu(void) { int i, update = 0; - int offset = 0; + int digit_cnt = 0; int max = 0; char temp[256]; char *str = NULL; @@ -623,6 +648,9 @@ void CheatMenu(void) /* clear existing ROM patches */ clear_cheats(); + /* reset scrolling */ + string_offset = 0; + /* background type */ if (config.bg_type > 0) { @@ -668,13 +696,35 @@ void CheatMenu(void) while (update != -1) { + /* update arrows buttons */ + if (offset > 0) m->arrows[0]->state |= BUTTON_VISIBLE; + else m->arrows[0]->state &= ~BUTTON_VISIBLE; + if ((offset + 10) < (maxcheats + 1)) m->arrows[1]->state |= BUTTON_VISIBLE; + else m->arrows[1]->state &= ~BUTTON_VISIBLE; + /* draw menu */ GUI_DrawMenu(m); + /* restore cheats offset */ + if (!(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) + { + m->offset = offset; + m->max_items = maxcheats + 1; + m->max_buttons = 10; + } + /* update menu */ update = GUI_UpdateMenu(m); - /* update selection */ + /* save offset then restore default */ + if (!(menu_cheats.bg_images[6].state & IMAGE_VISIBLE)) + { + offset = m->offset; + m->offset = 0; + m->max_items = m->max_buttons = 30; + } + + /* update selected cheat */ if ((m->selected < 10) && (selection != m->selected)) { selection = m->selected; @@ -697,17 +747,17 @@ void CheatMenu(void) case 8: case 9: /* Edit cheat */ { - if (type && (selection != maxcheats)) + if (type && ((selection + offset) != maxcheats)) { /* cheat description */ - str = cheatlist[selection].text; + str = cheatlist[offset + selection].text; strcpy(temp, str); - max = 34; - offset = strlen(str); - if (offset <= max) + max = MAX_DESC_LENGTH - 2; + digit_cnt = strlen(str); + if (digit_cnt <= max) { - str[offset] = '*'; - str[offset+1] = 0; + str[digit_cnt] = '*'; + str[digit_cnt+1] = 0; } /* init specific characters */ @@ -719,13 +769,13 @@ void CheatMenu(void) else { /* cheat code */ - str = cheatlist[selection].code; + str = cheatlist[offset + selection].code; strcpy(temp, str); - if (selection == maxcheats) + if ((offset + selection) == maxcheats) { /* initialize code */ max = 0; - offset = 0; + digit_cnt = 0; str[0] = '*'; str[1] = 0; } @@ -742,7 +792,7 @@ void CheatMenu(void) /* AR code */ max = 10; } - offset = max + 1; + digit_cnt = max + 1; } /* init specific characters */ @@ -760,7 +810,11 @@ void CheatMenu(void) /* disable left buttons */ for (i=0; i<10; i++) m->buttons[i].state &= ~BUTTON_ACTIVE; - + + /* disable arrow buttons */ + m->arrows[0]->state &= ~BUTTON_ACTIVE; + m->arrows[1]->state &= ~BUTTON_ACTIVE; + /* slide in right window */ GUI_DrawMenuFX(m,20,0); @@ -777,20 +831,20 @@ void CheatMenu(void) case 26: /* Backspace */ { - if (offset > 0) + if (digit_cnt > 0) { /* delete last character */ - str[offset--] = 0; + str[digit_cnt--] = 0; /* code separator is being deleted */ - if ((str[offset] == ':') || (str[offset] == '-')) + if ((str[digit_cnt] == ':') || (str[digit_cnt] == '-')) { /* reset detected code type */ max = 0; } /* edit mark */ - str[offset] = '*'; + str[digit_cnt] = '*'; /* update scroll value if necessary */ if (string_offset > 0) string_offset--; @@ -800,17 +854,17 @@ void CheatMenu(void) case 27: { - if (type && (selection != maxcheats)) + if (type && ((offset + selection) != maxcheats)) { /* SPACE character */ - if (offset <= max) + if (digit_cnt <= max) { - str[offset++] = ' '; - str[offset] = 0; - if (offset <= max) + str[digit_cnt++] = ' '; + str[digit_cnt] = 0; + if (digit_cnt <= max) { - str[offset] = '*'; - str[offset+1] = 0; + str[digit_cnt] = '*'; + str[digit_cnt+1] = 0; } } } @@ -819,23 +873,23 @@ void CheatMenu(void) /* Separator character (only if code type has not yet been determined) */ if (max == 0) { - if (offset == 4) + if (digit_cnt == 4) { /* GG code */ max = 8; str[4] = '-'; str[5] = '*'; str[6] = 0; - offset++; + digit_cnt++; } - else if (offset == 6) + else if (digit_cnt == 6) { /* AR code */ max = 10; str[6] = ':'; str[7] = '*'; str[8] = 0; - offset++; + digit_cnt++; } } } @@ -853,31 +907,31 @@ void CheatMenu(void) case 29: /* Validate entry */ { /* check if entry is valid */ - if (type && (selection != maxcheats)) + if (type && ((offset + selection) != maxcheats)) { - str[offset] = 0; + str[digit_cnt] = 0; update = -1; } - else if (max && (offset > max)) + else if (max && (digit_cnt > max)) { address = data = 0; - if (decode_cheat(cheatlist[selection].code, &address, &data)) + if (decode_cheat(cheatlist[offset + selection].code, &address, &data)) { /* update cheat address & data values */ - cheatlist[selection].address = address; - cheatlist[selection].data = data; + cheatlist[offset + selection].address = address; + cheatlist[offset + selection].data = data; /* new cheat ? */ - if (selection == maxcheats) + if ((offset + selection) == maxcheats) { /* increase cheat count */ maxcheats++; /* enable cheat by default */ - cheatlist[selection].enable = 1; + cheatlist[offset + selection].enable = 1; /* no description by default */ - strcpy(cheatlist[selection].text,"No Description"); + strcpy(cheatlist[offset + selection].text,"No Description"); } /* return to cheat selection */ @@ -894,17 +948,17 @@ void CheatMenu(void) default: /* Add Character */ { /* force code separator if none has been set yet */ - if ((max == 0) && (offset == 6)) break; + if ((max == 0) && (digit_cnt == 6)) break; /* add character */ - if ((offset <= max) || (max == 0)) + if ((digit_cnt <= max) || (max == 0)) { - str[offset++] = m->items[m->selected].text[0]; - str[offset] = 0; - if ((offset <= max) || (max == 0)) + str[digit_cnt++] = m->items[m->selected].text[0]; + str[digit_cnt] = 0; + if ((digit_cnt <= max) || (max == 0)) { - str[offset] = '*'; - str[offset+1] = 0; + str[digit_cnt] = '*'; + str[digit_cnt+1] = 0; } if (string_offset > 0) string_offset ++; } @@ -933,13 +987,13 @@ void CheatMenu(void) string_offset = 0; } - if (selection < maxcheats) + if ((offset + selection) < maxcheats) { /* Special inputs */ if (m_input.keys & PAD_TRIGGER_L) { /* sort cheat list */ - for (i = selection + 1; i < maxcheats; i++) + for (i = offset + selection + 1; i < maxcheats; i++) { strcpy(cheatlist[i-1].text,cheatlist[i].text); strcpy(cheatlist[i-1].code,cheatlist[i].code); @@ -956,10 +1010,10 @@ void CheatMenu(void) cheatlist[maxcheats-1].enable = 0; /* disable last button */ - if (maxcheats < 10) + if ((maxcheats - offset) < 10) { - m->buttons[maxcheats].state &= ~BUTTON_ACTIVE; - m->buttons[maxcheats - 1].shift[1] = 0; + m->buttons[maxcheats - offset].state &= ~BUTTON_ACTIVE; + m->buttons[maxcheats - offset - 1].shift[1] = 0; } /* decrease cheat count */ @@ -971,7 +1025,7 @@ void CheatMenu(void) else if (m_input.keys & PAD_TRIGGER_R) { /* cheat ON/OFF */ - cheatlist[selection].enable ^= 1; + cheatlist[offset + selection].enable ^= 1; } } } @@ -990,22 +1044,29 @@ void CheatMenu(void) /* hide right window */ m->bg_images[6].state &= ~IMAGE_VISIBLE; - /* enable left buttons */ - for (i=0; ibuttons[i].state |= BUTTON_ACTIVE; - m->buttons[i].shift[1] = 1; + if ((offset + i) < maxcheats) + { + m->buttons[i].state |= BUTTON_ACTIVE; + m->buttons[i].shift[1] = 1; + } + else if ((offset + i) == maxcheats) + { + m->buttons[i].state |= BUTTON_ACTIVE; + m->buttons[i].shift[1] = 0; + } + else + { + m->buttons[i].state &= ~BUTTON_ACTIVE; + m->buttons[i].shift[1] = 0; + } } - if (maxcheats < 10) - { - m->buttons[maxcheats].state |= BUTTON_ACTIVE; - m->buttons[maxcheats].shift[1] = 0; - } - else - { - m->buttons[9].shift[1] = 0; - } + /* enable arrow buttons */ + m->arrows[0]->state |= BUTTON_ACTIVE; + m->arrows[1]->state |= BUTTON_ACTIVE; /* restore helper */ strcpy(action_cancel.comment,"Back"); @@ -1075,7 +1136,7 @@ void CheatLoad(void) char temp[256]; /* reset cheat count */ - selection = maxcheats = 0; + maxcheats = 0; /* make cheat filename */ sprintf(temp, "%s/cheats/%s.pat", DEFAULT_PATH, rom_filename); @@ -1088,7 +1149,7 @@ void CheatLoad(void) memset(temp, 0, 256); /* read cheats from file (one line per cheat) */ - while (fgets(temp, 256, f) && (maxcheats < 10) && (cnt < 10)) + while (fgets(temp, 256, f) && (maxcheats < MAX_CHEATS) && (cnt < MAX_CHEATS)) { /* remove CR & EOL chars */ if ((temp[strlen(temp) - 2] == 0x0d) || (temp[strlen(temp) - 2] == 0x0a)) temp[strlen(temp) - 2] = 0; @@ -1113,18 +1174,18 @@ void CheatLoad(void) while ((temp[len] == 0x20) || (temp[len] == 0x09)) len++; /* copy cheat description */ - strncpy(cheatlist[maxcheats].text, &temp[len], 35); - cheatlist[maxcheats].text[35] = 0; + strncpy(cheatlist[maxcheats].text, &temp[len], MAX_DESC_LENGTH - 1); + cheatlist[maxcheats].text[MAX_DESC_LENGTH - 1] = 0; /* increment cheat count */ maxcheats++; } - else if (!strncmp(temp,"ON",2)) + else if (!strcmp(temp,"ON") && config.autocheat) { /* enable flag */ cheatlist[cnt++].enable = 1; } - else if (!strncmp(temp,"OFF",3)) + else if (!strcmp(temp,"OFF") && config.autocheat) { /* disable flag */ cheatlist[cnt++].enable = 0; @@ -1142,20 +1203,27 @@ void CheatLoad(void) apply_cheats(); /* adjust menu buttons */ - for (cnt=0; cnt= 0xFF0000)) - { - if (cheatlist[i].data & 0xFF00) - { - /* word patch */ - *(u16 *)(work_ram + (cheatlist[i].address & 0xFFFE)) = cheatlist[i].data; - } - else - { - /* byte patch */ - work_ram[cheatlist[i].address & 0xFFFF] = cheatlist[i].data; - } - } + /* word patch */ + *(u16 *)(work_ram + (cheatlist[index].address & 0xFFFE)) = cheatlist[index].data; + } + else + { + /* byte patch */ + work_ram[cheatlist[index].address & 0xFFFF] = cheatlist[index].data; } } } \ No newline at end of file diff --git a/source/gx/gui/gui.c b/source/gx/gui/gui.c index 427ad4f..2f9950a 100644 --- a/source/gx/gui/gui.c +++ b/source/gx/gui/gui.c @@ -743,7 +743,7 @@ int GUI_UpdateMenu(gui_menu *menu) if (selected >= max_buttons) { selected = max_buttons - 1; - if ((menu->offset + selected < (max_items - 1))) + if ((menu->offset + selected) < (max_items - 1)) menu->offset ++; } } @@ -763,7 +763,7 @@ int GUI_UpdateMenu(gui_menu *menu) if (selected >= max_buttons) { selected = max_buttons - 1; - if ((menu->offset + selected < (max_items - 1))) + if ((menu->offset + selected) < (max_items - 1)) menu->offset ++; } } @@ -826,24 +826,6 @@ int GUI_UpdateMenu(gui_menu *menu) } } - /* update arrows buttons status (items list) */ - button = menu->arrows[0]; - if (button) - { - if (menu->offset > 0) - button->state |= BUTTON_VISIBLE; - else - button->state &= ~BUTTON_VISIBLE; - } - button = menu->arrows[1]; - if (button) - { - if ((menu->offset + max_buttons) < max_items) - button->state |= BUTTON_VISIBLE; - else - button->state &= ~BUTTON_VISIBLE; - } - if (ret > 0) { if (selected < max_buttons) @@ -871,6 +853,23 @@ int GUI_RunMenu(gui_menu *menu) { GUI_DrawMenu(menu); update = GUI_UpdateMenu(menu); + + /* update arrows buttons status (items list) */ + if (menu->arrows[0]) + { + if (menu->offset > 0) + menu->arrows[0]->state |= BUTTON_VISIBLE; + else + menu->arrows[0]->state &= ~BUTTON_VISIBLE; + } + + if (menu->arrows[1]) + { + if ((menu->offset + menu->max_buttons) < menu->max_items) + menu->arrows[1]->state |= BUTTON_VISIBLE; + else + menu->arrows[1]->state &= ~BUTTON_VISIBLE; + } } if (update == 2) @@ -1739,7 +1738,14 @@ static void *MsgBox_Thread(gui_message *message_box) while (message_box->refresh) { /* draw parent menu */ - GUI_DrawMenu(message_box->parent); + if (message_box->parent) + { + GUI_DrawMenu(message_box->parent); + } + else + { + gxClearScreen(bg_color); + } /* draw window */ gxDrawTexture(message_box->window,166,160,message_box->window->width,message_box->window->height,230); @@ -1810,17 +1816,27 @@ void GUI_MsgBoxOpen(char *title, char *msg, bool throbber) int ypos = 248; /* disable helper comments */ - if (message_box.parent->helpers[0]) - message_box.parent->helpers[0]->data = 0; - if (message_box.parent->helpers[1]) - message_box.parent->helpers[1]->data = 0; + if (message_box.parent) + { + if (message_box.parent->helpers[0]) + message_box.parent->helpers[0]->data = 0; + if (message_box.parent->helpers[1]) + message_box.parent->helpers[1]->data = 0; + } /* slide in */ int yoffset = ywindow + message_box.window->height; while (yoffset > 0) { /* draw parent menu */ - GUI_DrawMenu(message_box.parent); + if (message_box.parent) + { + GUI_DrawMenu(message_box.parent); + } + else + { + gxClearScreen(bg_color); + } /* draw window */ gxDrawTexture(message_box.window,xwindow,ywindow-yoffset,message_box.window->width,message_box.window->height,230); @@ -1866,7 +1882,14 @@ void GUI_MsgBoxClose(void) while (yoffset < (ywindow + message_box.window->height)) { /* draw parent menu */ - GUI_DrawMenu(message_box.parent); + if (message_box.parent) + { + GUI_DrawMenu(message_box.parent); + } + else + { + gxClearScreen(bg_color); + } /* draw window */ gxDrawTexture(message_box.window,xwindow,ywindow-yoffset,message_box.window->width,message_box.window->height,230); @@ -1887,14 +1910,22 @@ void GUI_MsgBoxClose(void) yoffset += 60; } - /* restore helper comment */ - if (message_box.parent->helpers[0]) - message_box.parent->helpers[0]->data = Key_B_png; - if (message_box.parent->helpers[1]) - message_box.parent->helpers[1]->data = Key_A_png; - - /* final position */ - GUI_DrawMenu(message_box.parent); + if (message_box.parent) + { + /* restore helper comment */ + if (message_box.parent->helpers[0]) + message_box.parent->helpers[0]->data = Key_B_png; + if (message_box.parent->helpers[1]) + message_box.parent->helpers[1]->data = Key_A_png; + + /* final position */ + GUI_DrawMenu(message_box.parent); + } + else + { + gxClearScreen(bg_color); + } + gxSetScreen(); /* clear all textures */ diff --git a/source/gx/gui/menu.c b/source/gx/gui/menu.c index 5028bc0..ef6915a 100644 --- a/source/gx/gui/menu.c +++ b/source/gx/gui/menu.c @@ -303,11 +303,11 @@ static gui_item items_load[4] = /* Option menu */ static gui_item items_options[5] = { - {NULL,Option_system_png,"","System settings", 114,142,80,92}, - {NULL,Option_video_png ,"","Video settings", 288,150,64,84}, - {NULL,Option_sound_png ,"","Audio settings", 464,154,44,80}, - {NULL,Option_ctrl_png ,"","Input settings", 192,286,88,92}, - {NULL,Option_menu_png ,"","Menu settings", 370,286,60,92} + {NULL,Option_system_png,"","System settings", 114,142,80,92}, + {NULL,Option_video_png ,"","Video settings", 288,150,64,84}, + {NULL,Option_sound_png ,"","Audio settings", 464,154,44,80}, + {NULL,Option_ctrl_png ,"","Controllers settings", 192,286,88,92}, + {NULL,Option_menu_png ,"","Menu settings", 370,286,60,92} }; /* Audio options */ @@ -361,16 +361,17 @@ static gui_item items_video[8] = }; /* Menu options */ -static gui_item items_prefs[8] = +static gui_item items_prefs[9] = { - {NULL,NULL,"Load ROM Auto: OFF","Enable/Disable automatic ROM loading on startup", 56,132,276,48}, - {NULL,NULL,"Auto Saves: OFF", "Enable/Disable automatic saves", 56,132,276,48}, - {NULL,NULL,"Saves Device: FAT", "Configure default device for saves", 56,132,276,48}, - {NULL,NULL,"SFX Volume: 100", "Adjust sound effects volume", 56,132,276,48}, - {NULL,NULL,"BGM Volume: 100", "Adjust background music volume", 56,132,276,48}, - {NULL,NULL,"BG Color: DEFAULT", "Select background color", 56,132,276,48}, - {NULL,NULL,"BG Overlay: ON", "Enable/disable background overlay", 56,132,276,48}, - {NULL,NULL,"Screen Width: 658", "Adjust menu screen width in pixels", 56,132,276,48}, + {NULL,NULL,"Auto ROM Load: OFF","Enable/Disable automatic ROM loading on startup", 56,132,276,48}, + {NULL,NULL,"Auto Cheats: OFF", "Enable/Disable automatic cheats activation", 56,132,276,48}, + {NULL,NULL,"Auto Saves: OFF", "Enable/Disable automatic saves", 56,132,276,48}, + {NULL,NULL,"Saves Device: FAT", "Configure default device for saves", 56,132,276,48}, + {NULL,NULL,"SFX Volume: 100", "Adjust sound effects volume", 56,132,276,48}, + {NULL,NULL,"BGM Volume: 100", "Adjust background music volume", 56,132,276,48}, + {NULL,NULL,"BG Color: DEFAULT", "Select background color", 56,132,276,48}, + {NULL,NULL,"BG Overlay: ON", "Enable/disable background overlay", 56,132,276,48}, + {NULL,NULL,"Screen Width: 658", "Adjust menu screen width in pixels", 56,132,276,48}, }; /* Save Manager */ @@ -587,7 +588,7 @@ static gui_menu menu_prefs = { "Menu Settings", 0,0, - 8,4,6,0, + 9,4,6,0, items_prefs, buttons_list, bg_list, @@ -634,20 +635,21 @@ static void prefmenu () gui_menu *m = &menu_prefs; gui_item *items = m->items; - sprintf (items[0].text, "Load ROM Auto: %s", config.autoload ? "ON":"OFF"); - if (config.s_auto == 3) sprintf (items[1].text, "Auto Saves: ALL"); - else if (config.s_auto == 2) sprintf (items[1].text, "Auto Saves: STATE ONLY"); - else if (config.s_auto == 1) sprintf (items[1].text, "Auto Saves: SRAM ONLY"); - else sprintf (items[1].text, "Auto Saves: NONE"); - if (config.s_device == 1) sprintf (items[2].text, "Saves Device: MCARD A"); - else if (config.s_device == 2) sprintf (items[2].text, "Saves Device: MCARD B"); - else sprintf (items[2].text, "Saves Device: FAT"); - sprintf (items[3].text, "SFX Volume: %1.1f", config.sfx_volume); - sprintf (items[4].text, "BGM Volume: %1.1f", config.bgm_volume); - if (config.bg_type) sprintf (items[5].text, "BG Type: COLOR %d", config.bg_type - 1); - else sprintf (items[5].text, "BG Type: DEFAULT"); - sprintf (items[6].text, "BG Overlay: %s", config.bg_overlay ? "ON":"OFF"); - sprintf (items[7].text, "Screen Width: %d", config.screen_w); + sprintf (items[0].text, "Auto ROM Load: %s", config.autoload ? "ON":"OFF"); + sprintf (items[1].text, "Auto Cheats: %s", config.autocheat ? "ON":"OFF"); + if (config.s_auto == 3) sprintf (items[2].text, "Auto Saves: ALL"); + else if (config.s_auto == 2) sprintf (items[2].text, "Auto Saves: STATE ONLY"); + else if (config.s_auto == 1) sprintf (items[2].text, "Auto Saves: SRAM ONLY"); + else sprintf (items[2].text, "Auto Saves: NONE"); + if (config.s_device == 1) sprintf (items[3].text, "Saves Device: MCARD A"); + else if (config.s_device == 2) sprintf (items[3].text, "Saves Device: MCARD B"); + else sprintf (items[3].text, "Saves Device: FAT"); + sprintf (items[4].text, "SFX Volume: %1.1f", config.sfx_volume); + sprintf (items[5].text, "BGM Volume: %1.1f", config.bgm_volume); + if (config.bg_type) sprintf (items[6].text, "BG Type: COLOR %d", config.bg_type - 1); + else sprintf (items[6].text, "BG Type: DEFAULT"); + sprintf (items[7].text, "BG Overlay: %s", config.bg_overlay ? "ON":"OFF"); + sprintf (items[8].text, "Screen Width: %d", config.screen_w); GUI_InitMenu(m); GUI_SlideMenuTitle(m,strlen("Menu ")); @@ -658,57 +660,62 @@ static void prefmenu () switch (ret) { - case 0: /* Auto load last ROM file */ + case 0: /* Auto load last ROM file on startup */ config.autoload ^= 1; - sprintf (items[ret].text, "Load ROM Auto: %s", config.autoload ? "ON":"OFF"); + sprintf (items[0].text, "Auto ROM Load: %s", config.autoload ? "ON":"OFF"); break; - case 1: /*** Auto load/save STATE & SRAM files ***/ + case 1: /* Cheats automatic activation */ + config.autocheat ^= 1; + sprintf (items[1].text, "Auto Cheats: %s", config.autocheat ? "ON":"OFF"); + break; + + case 2: /*** Auto load/save STATE & SRAM files ***/ config.s_auto = (config.s_auto + 1) % 4; - if (config.s_auto == 3) sprintf (items[ret].text, "Auto Saves: ALL"); - else if (config.s_auto == 2) sprintf (items[ret].text, "Auto Saves: STATE ONLY"); - else if (config.s_auto == 1) sprintf (items[ret].text, "Auto Saves: SRAM ONLY"); - else sprintf (items[ret].text, "Auto Saves: NONE"); + if (config.s_auto == 3) sprintf (items[2].text, "Auto Saves: ALL"); + else if (config.s_auto == 2) sprintf (items[2].text, "Auto Saves: STATE ONLY"); + else if (config.s_auto == 1) sprintf (items[2].text, "Auto Saves: SRAM ONLY"); + else sprintf (items[2].text, "Auto Saves: NONE"); break; - case 2: /*** Default saves device ***/ + case 3: /*** Default saves device ***/ config.s_device = (config.s_device + 1) % 3; - if (config.s_device == 1) sprintf (items[ret].text, "Saves Device: MCARD A"); - else if (config.s_device == 2) sprintf (items[ret].text, "Saves Device: MCARD B"); - else sprintf (items[ret].text, "Saves Device: FAT"); + if (config.s_device == 1) sprintf (items[3].text, "Saves Device: MCARD A"); + else if (config.s_device == 2) sprintf (items[3].text, "Saves Device: MCARD B"); + else sprintf (items[3].text, "Saves Device: FAT"); break; - case 3: /*** Sound effects volume ***/ + case 4: /*** Sound effects volume ***/ GUI_OptionBox(m,0,"SFX Volume",(void *)&config.sfx_volume,10.0,0.0,100.0,0); - sprintf (items[ret].text, "SFX Volume: %1.1f", config.sfx_volume); + sprintf (items[4].text, "SFX Volume: %1.1f", config.sfx_volume); break; - case 4: /*** Background music volume ***/ + case 5: /*** Background music volume ***/ GUI_OptionBox(m,update_bgm,"BGM Volume",(void *)&config.bgm_volume,10.0,0.0,100.0,0); - sprintf (items[ret].text, "BGM Volume: %1.1f", config.bgm_volume); + sprintf (items[5].text, "BGM Volume: %1.1f", config.bgm_volume); break; - case 5: /*** Background type ***/ + case 6: /*** Background type ***/ if (ret < 0) config.bg_type --; else config.bg_type++; if (config.bg_type < 0) config.bg_type = BG_COLOR_MAX; else if (config.bg_type > BG_COLOR_MAX) config.bg_type = 0; - if (config.bg_type) sprintf (items[5].text, "BG Type: COLOR %d", config.bg_type - 1); - else sprintf (items[5].text, "BG Type: DEFAULT"); + if (config.bg_type) sprintf (items[6].text, "BG Type: COLOR %d", config.bg_type - 1); + else sprintf (items[6].text, "BG Type: DEFAULT"); GUI_DeleteMenu(m); menu_configure(); GUI_InitMenu(m); break; - case 6: /*** Background overlay ***/ + case 7: /*** Background overlay ***/ config.bg_overlay ^= 1; - sprintf (items[6].text, "BG Overlay: %s", config.bg_overlay ? "ON":"OFF"); + sprintf (items[7].text, "BG Overlay: %s", config.bg_overlay ? "ON":"OFF"); menu_configure(); break; - case 7: /*** Screen Width ***/ + case 8: /*** Screen Width ***/ GUI_OptionBox(m,update_screen_w,"Screen Width",(void *)&config.screen_w,2,640,VI_MAX_WIDTH_NTSC,1); - sprintf (items[7].text, "Screen Width: %d", config.screen_w); + sprintf (items[8].text, "Screen Width: %d", config.screen_w); break; case -1: @@ -827,7 +834,6 @@ static void soundmenu () ret = 255; if (cart.romsize) { - /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) { @@ -858,20 +864,17 @@ static void soundmenu () if (cart.romsize) { - /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) { + /* save YM2612 context */ memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); - } - /* reinitialize audio timings */ - audio_init(snd.sample_rate,snd.frame_rate); - sound_init(); + /* reinitialize audio timings */ + audio_init(snd.sample_rate,snd.frame_rate); + sound_init(); - /* restore YM2612 context */ - if (temp) - { + /* restore YM2612 context */ YM2612Restore(temp); free(temp); } @@ -889,21 +892,18 @@ static void soundmenu () if (cart.romsize) { - /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) { + /* save YM2612 context */ memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); - } - /* reinitialize audio timings */ - audio_init(snd.sample_rate,snd.frame_rate); - sound_init(); + /* reinitialize audio timings */ + audio_init(snd.sample_rate,snd.frame_rate); + sound_init(); - /* restore YM2612 context */ - if (temp) - { - //YM2612Restore(temp); + /* restore YM2612 context */ + YM2612Restore(temp); free(temp); } } @@ -1081,17 +1081,15 @@ static void systemmenu () /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) + { memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); + } /* reinitialize all timings */ framerate = vdp_pal ? 50.0 : ((config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0))); audio_init(snd.sample_rate, framerate); system_init(); - /* restore SRAM */ - if (config.s_auto & 1) - slot_autoload(0,config.s_device); - /* restore YM2612 context */ if (temp) { @@ -1099,13 +1097,18 @@ static void systemmenu () free(temp); } - /* reinitialize HVC tables */ - vctab = vdp_pal ? ((reg[1] & 8) ? vc_pal_240 : vc_pal_224) : vc_ntsc_224; - hctab = (reg[12] & 1) ? cycle2hc40 : cycle2hc32; + /* restore SRAM */ + if (config.s_auto & 1) + { + slot_autoload(0,config.s_device); + } - /* reinitialize overscan area */ - bitmap.viewport.x = (config.overscan & 2) ? ((reg[12] & 1) ? 16 : 12) : 0; - bitmap.viewport.y = (config.overscan & 1) ? (((reg[1] & 8) ? 0 : 8) + (vdp_pal ? 24 : 0)) : 0; + /* reinitialize VC max value */ + vc_max = 0xEA + 24*vdp_pal; + if (reg[1] & 8) + { + vc_max += (28 - 20*vdp_pal); + } } break; @@ -1126,10 +1129,15 @@ static void systemmenu () sprintf (items[3].text, "System TMSS: %s", (config.tmss & 1) ? "ON":"OFF"); if (cart.romsize) { + /* restart emulation */ system_init(); system_reset(); + + /* restore SRAM */ if (config.s_auto & 1) + { slot_autoload(0,config.s_device); + } } break; @@ -1148,8 +1156,11 @@ static void systemmenu () if (cart.romsize) { + /* restart emulation */ system_init(); system_reset(); + + /* restore SRAM */ if (config.s_auto & 1) { slot_autoload(0,config.s_device); @@ -1310,7 +1321,9 @@ static void videomenu () /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) + { memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); + } /* reinitialize audio timings */ framerate = (config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0)); @@ -1343,7 +1356,9 @@ static void videomenu () /* save YM2612 context */ temp = memalign(32,YM2612GetContextSize()); if (temp) + { memcpy(temp, YM2612GetContextPtr(), YM2612GetContextSize()); + } /* reinitialize audio timings */ framerate = (config.tv_mode == 1) ? 60.0 : ((config.render || interlaced) ? 59.94 : (1000000.0/16715.0)); @@ -1950,7 +1965,8 @@ static void ctrlmenu(void) /* remove duplicate assigned inputs */ for (i=0; i= 4) { #ifdef HW_RVL - /* no gamecube controller found, try wiimote */ + /* test wiimote */ config.input[player].port = 0; config.input[player].device = 1; #else @@ -2095,56 +2113,60 @@ static void ctrlmenu(void) /* autodetect connected wiimotes (without nunchuk) */ if (config.input[player].device == 1) { - exp = 4; - if (config.input[player].port<4) + /* test current port */ + exp = 255; + if (config.input[player].port < 4) { WPAD_Probe(config.input[player].port,&exp); - if (exp == WPAD_EXP_NUNCHUK) exp = 4; } - while ((config.input[player].port<4) && (exp == 4)) + /* find first connected controller */ + while ((config.input[player].port < 4) && (exp == 255)) { /* try next port */ config.input[player].port ++; - if (config.input[player].port<4) + if (config.input[player].port < 4) { - exp = 4; + exp = 255; WPAD_Probe(config.input[player].port,&exp); - if (exp == WPAD_EXP_NUNCHUK) exp = 4; } } + /* no more wiimote */ if (config.input[player].port >= 4) { - /* no wiimote (without nunchuk) found, try wiimote+nunchuks */ + /* test wiimote+nunchuk */ config.input[player].port = 0; config.input[player].device = 2; } } - /* autodetect connected wiimote+nunchuks */ + /* autodetect connected wiimote+nunchuk */ if (config.input[player].device == 2) { - exp = 4; - if (config.input[player].port<4) + /* test current port */ + exp = 255; + if (config.input[player].port < 4) { WPAD_Probe(config.input[player].port,&exp); } - while ((config.input[player].port<4) && (exp != WPAD_EXP_NUNCHUK)) + /* find first connected controller */ + while ((config.input[player].port < 4) && (exp != WPAD_EXP_NUNCHUK)) { /* try next port */ config.input[player].port ++; - if (config.input[player].port<4) + if (config.input[player].port < 4) { - exp = 4; + exp = 255; WPAD_Probe(config.input[player].port,&exp); } } + /* no more wiimote+nunchuk */ if (config.input[player].port >= 4) { - /* no wiimote+nunchuk found, try classic controllers */ + /* test classic controllers */ config.input[player].port = 0; config.input[player].device = 3; } @@ -2153,19 +2175,21 @@ static void ctrlmenu(void) /* autodetect connected classic controllers */ if (config.input[player].device == 3) { - exp = 4; - if (config.input[player].port<4) + /* test current port */ + exp = 255; + if (config.input[player].port < 4) { WPAD_Probe(config.input[player].port,&exp); } + /* find first connected controller */ while ((config.input[player].port<4) && (exp != WPAD_EXP_CLASSIC)) { /* try next port */ config.input[player].port ++; - if (config.input[player].port<4) + if (config.input[player].port < 4) { - exp = 4; + exp = 255; WPAD_Probe(config.input[player].port,&exp); } } @@ -2289,7 +2313,8 @@ static void ctrlmenu(void) /* remove duplicate assigned inputs before leaving */ for (i=0; i