diff --git a/source/gx/config.c b/source/gx/config.c index 055e1c1..e0f8914 100644 --- a/source/gx/config.c +++ b/source/gx/config.c @@ -95,7 +95,7 @@ void config_setDefault(void) config.bilinear = 1; /* controllers options */ - gx_input_setDefault(); + gx_input_SetDefault(); config.gun_cursor = 1; config.invert_mouse = 0; diff --git a/source/gx/gui/filesel.c b/source/gx/gui/filesel.c index e54a57e..a2db9d4 100644 --- a/source/gx/gui/filesel.c +++ b/source/gx/gui/filesel.c @@ -68,8 +68,8 @@ static butn_data arrow_down_data = /* GUI Arrows button */ /*****************************************************************************/ -static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,14,76,360,32}; -static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,14,368,360,32}; +static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{0,0},14,76,360,32}; +static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{0,0},14,368,360,32}; /*****************************************************************************/ /* GUI helpers */ @@ -114,9 +114,8 @@ static gui_image bg_filesel[9] = static gui_menu menu_browser = { "ROM Selection", - -1,0, + -1,-1, 0,0,9, - {0,0}, NULL, NULL, bg_filesel, diff --git a/source/gx/gui/menu.c b/source/gx/gui/menu.c index 2aa0ad5..7998588 100644 --- a/source/gx/gui/menu.c +++ b/source/gx/gui/menu.c @@ -179,11 +179,11 @@ static gui_item items_load[3] = static gui_item items_options[5] = { - {NULL,Option_system_png,"","System options", 114,142,80,92}, - {NULL,Option_video_png ,"","Video options", 288,150,64,84}, - {NULL,Option_sound_png ,"","Audio options", 464,154,44,80}, - {NULL,Option_ctrl_png ,"","Input options", 192,286,88,92}, - {NULL,Option_menu_png ,"","Menu options", 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 ,"","Input settings", 192,286,88,92}, + {NULL,Option_menu_png ,"","Menu settings", 370,286,60,92} }; /* Audio options menu */ @@ -233,29 +233,29 @@ static gui_item items_prefs[5] = /*****************************************************************************/ /* Generic Buttons for list menu */ -static gui_butn arrow_up = {&arrow_up_data,BUTTON_OVER_SFX,14,76,360,32}; -static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,14,368,360,32}; +static gui_butn arrow_up = {&arrow_up_data,BUTTON_OVER_SFX,{0,0},14,76,360,32}; +static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{0,0},14,368,360,32}; /* Generic list menu */ static gui_butn buttons_list[4] = { - {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,132,276,48}, - {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,188,276,48}, - {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,244,276,48}, - {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,300,276,48} + {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},52,132,276,48}, + {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},52,188,276,48}, + {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},52,244,276,48}, + {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},52,300,276,48} }; /* Main menu */ static gui_butn buttons_main[8] = { - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX ,80, 50,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,246, 50,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,412, 50,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX, 80,194,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 246,194,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,412,194,148,132}, - {NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX, 0,360, 88, 48}, - {NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,552,360, 88, 48} + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,3}, 80, 50,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,3},246, 50,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,3},412, 50,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{3,3}, 80,194,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX ,{3,3},246,194,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{3,2},412,194,148,132}, + {NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX ,{3,0}, 0,360, 88, 48}, + {NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{3,0},552,360, 88, 48} }; @@ -263,28 +263,28 @@ static gui_butn buttons_main[8] = #ifdef HW_RVL static gui_butn buttons_load[4] = { - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,246,102,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX, 80,248,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,246,248,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,412,248,148,132} + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,2},246,102,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{1,0}, 80,248,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{2,0},246,248,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{3,0},412,248,148,132} }; #else static gui_butn buttons_load[3] = { - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX, 80,180,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,246,180,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,412,180,148,132} + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,0}, 80,180,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,0},246,180,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,0},412,180,148,132} }; #endif /* Options menu */ static gui_butn buttons_options[5] = { - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX, 80,120,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,246,120,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,412,120,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,162,264,148,132}, - {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,330,264,148,132} + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,3}, 80,120,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,3},246,120,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{0,2},412,120,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{3,0},162,264,148,132}, + {&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,{2,0},330,264,148,132} }; /*****************************************************************************/ @@ -297,7 +297,6 @@ static gui_menu menu_main = "", 0,0, 8,8,4, - {3,3}, items_main, buttons_main, bg_main, @@ -313,10 +312,8 @@ static gui_menu menu_load = 0,0, #ifdef HW_RVL 4,4,5, - {1,3}, #else 3,3,5, - {3,0}, #endif items_load, buttons_load, @@ -332,7 +329,6 @@ static gui_menu menu_options = "Settings", 0,0, 5,5,5, - {3,2}, items_options, buttons_options, bg_misc, @@ -344,25 +340,23 @@ static gui_menu menu_options = /* System Options menu */ static gui_menu menu_system = { - "System Options", + "System Settings", 0,0, 4,4,6, - {1,1}, items_system, buttons_list, bg_list, {&action_cancel, &action_select}, - {&arrow_up,&arrow_down}, + {NULL,NULL}, FALSE }; /* Video Options menu */ static gui_menu menu_video = { - "Video Options", + "Video Settings", 0,0, 8,4,6, - {1,1}, items_video, buttons_list, bg_list, @@ -374,10 +368,9 @@ static gui_menu menu_video = /* Sound Options menu */ static gui_menu menu_audio = { - "Sound Options", + "Sound Settings", 0,0, 5,4,6, - {1,1}, items_audio, buttons_list, bg_list, @@ -389,10 +382,9 @@ static gui_menu menu_audio = /* Sound Options menu */ static gui_menu menu_prefs = { - "Sound Options", + "Menu Settings", 0,0, 5,4,6, - {1,1}, items_prefs, buttons_list, bg_list, @@ -434,6 +426,14 @@ void GUI_InitMenu(gui_menu *menu) { if (!button->data->texture[0]) button->data->texture[0] = gxTextureOpenPNG(button->data->image[0]); if (!button->data->texture[1]) button->data->texture[1] = gxTextureOpenPNG(button->data->image[1]); + + /* initial state */ + button->state &= ~BUTTON_VISIBLE; + if (((i==0) && (abs(menu->offset) > 0)) || + ((i==1) && (menu->offset + menu->max_buttons) < menu->max_items)) + { + button->state |= BUTTON_VISIBLE; + } } } @@ -746,7 +746,6 @@ void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out) GUI_DeleteMenu(menu); } - /* Window Prompt */ /* prompt window slides in & out */ int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items) @@ -962,7 +961,6 @@ int GUI_RunMenu(gui_menu *menu) u16 p; u16 max_buttons = menu->max_buttons; u16 max_items = menu->max_items; - u16 shift[2] = {menu->shift[0],menu->shift[1]}; #ifdef HW_RVL int i,x,y; @@ -1040,27 +1038,53 @@ int GUI_RunMenu(gui_menu *menu) { if (p & PAD_BUTTON_UP) { - if (selected == 0) + button = &menu->buttons[selected]; + if (button->shift[0]) { - if (menu->offset) menu->offset --; - } - else if (selected >= shift[0]) - { - selected -= shift[1]; - if (selected < 0) selected = 0; + selected -= button->shift[0]; + if (selected < 0) + { + selected = 0; + if (menu->offset) menu->offset --; + } } } else if (p & PAD_BUTTON_DOWN) { - if (selected == (max_buttons - 1)) + button = &menu->buttons[selected]; + if (button->shift[1]) { - if ((menu->offset + selected < (max_items - 1))) menu->offset ++; + selected += button->shift[1]; + if (selected >= max_buttons) + { + selected = max_buttons - 1; + if ((menu->offset + selected < (max_items - 1))) menu->offset ++; + } } - else if ((shift[1] == 1) || (selected < shift[0])) + } + else if (p & PAD_BUTTON_LEFT) + { + if (max_buttons == max_items) { - selected += shift[0]; + selected --; + if (selected < 0) selected = 0; + } + else + { + quit = -1; + } + } + else if (p & PAD_BUTTON_RIGHT) + { + if (max_buttons == max_items) + { + selected ++; if (selected >= max_buttons) selected = max_buttons - 1; } + else + { + quit = 1; + } } else if (p & PAD_BUTTON_LEFT) { @@ -1164,6 +1188,24 @@ int GUI_RunMenu(gui_menu *menu) return -1; } +/* basic slide effect for option menus */ +static void GUI_SlideMenuTitle(gui_menu *m, int title_offset) +{ + char title[64]; + strcpy(title,m->title); + + while (title_offset > 0) + { + strcpy(m->title,title+title_offset); + m->title[strlen(title)-title_offset-1] = 0; + GUI_DrawMenu(m); + gxSetScreen (); + usleep(6000); + title_offset--; + } + strcpy(m->title,title); +} + /*************************************************************************** * drawmenu (deprecated) * @@ -1297,6 +1339,7 @@ static void prefmenu () gui_item *items = m->items; GUI_InitMenu(m); + GUI_SlideMenuTitle(m,strlen("Menu ")); while (quit == 0) { @@ -1307,9 +1350,9 @@ static void prefmenu () if (config.state_auto == 0) sprintf (items[1].text, "Savestate Auto: FAT"); else if (config.state_auto == 1) sprintf (items[1].text, "Savestate Auto: MCARD A"); else if (config.state_auto == 2) sprintf (items[1].text, "Savestate Auto: MCARD B"); - else sprintf (items[3].text, "Savestate Auto: OFF"); - sprintf (items[2].text, "SFX Volume: %1.2f", config.sfx_volume); - sprintf (items[3].text, "BGM Volume: %1.2f", config.bgm_volume); + else sprintf (items[1].text, "Savestate Auto: OFF"); + sprintf (items[2].text, "SFX Volume: %1.1f", config.sfx_volume); + sprintf (items[3].text, "BGM Volume: %1.1f", config.bgm_volume); if (config.bg_color) sprintf (items[4].text, "BG Color: Type %d", config.bg_color); else sprintf (items[4].text, "BG Color: DEFAULT"); @@ -1329,16 +1372,16 @@ static void prefmenu () case 2: /*** Sound effects volume ***/ case -4: - if (ret < 0) config.sfx_volume --; - else config.sfx_volume ++; + if (ret < 0) config.sfx_volume -=10; + else config.sfx_volume +=10; if (config.sfx_volume < 0) config.sfx_volume = 100.0; else if (config.sfx_volume > 100) config.sfx_volume = 0.0; break; case 3: /*** Background music volume ***/ case -5: - if (ret < 0) config.bgm_volume --; - else config.bgm_volume ++; + if (ret < 0) config.bgm_volume -=10; + else config.bgm_volume +=10; if (config.bgm_volume < 0) config.bgm_volume = 100.0; else if (config.bgm_volume > 100) config.bgm_volume = 0.0; SetVolumeOgg(((int)config.bgm_volume * 255) / 100); @@ -1372,6 +1415,7 @@ static void soundmenu () gui_item *items = m->items; GUI_InitMenu(m); + GUI_SlideMenuTitle(m,strlen("Sound ")); while (quit == 0) { @@ -1449,6 +1493,7 @@ static void systemmenu () gui_item *items = m->items; GUI_InitMenu(m); + GUI_SlideMenuTitle(m,strlen("System ")); while (quit == 0) { @@ -1530,6 +1575,7 @@ static void videomenu () gui_item *items = m->items; GUI_InitMenu(m); + GUI_SlideMenuTitle(m,strlen("Video ")); while (quit == 0) { @@ -1910,11 +1956,11 @@ static void inputsmenu(void) case 7: if (config.input[player].device < 0) break; if (input.padtype[player] == DEVICE_3BUTTON) /* 3-buttons */ - gx_input_config(config.input[player].port, config.input[player].device, 4); + gx_input_Config(config.input[player].port, config.input[player].device, 4); else if (config.input[player].device == 0) /* 6-buttons w/o MODE */ - gx_input_config(config.input[player].port, 0, 7); + gx_input_Config(config.input[player].port, 0, 7); else /* 6-buttons */ - gx_input_config(config.input[player].port, config.input[player].device, 8); + gx_input_Config(config.input[player].port, config.input[player].device, 8); break; case -1: @@ -2289,8 +2335,10 @@ void MainMenu (void) m->max_items = 8; m->max_buttons = 8; m->buttons[3].state |= BUTTON_SELECT_SFX; - m->buttons[4].state |= BUTTON_SELECT_SFX; m->buttons[5].state |= BUTTON_SELECT_SFX; + m->buttons[3].shift[1] = 3; + m->buttons[4].shift[1] = 3; + m->buttons[5].shift[1] = 2; } else { @@ -2298,8 +2346,10 @@ void MainMenu (void) m->max_items = 6; m->max_buttons = 6; m->buttons[3].state &= ~BUTTON_SELECT_SFX; - m->buttons[4].state &= ~BUTTON_SELECT_SFX; m->buttons[5].state &= ~BUTTON_SELECT_SFX; + m->buttons[3].shift[1] = 0; + m->buttons[4].shift[1] = 0; + m->buttons[5].shift[1] = 0; } GUI_DrawMenuFX(m,10,0); diff --git a/source/gx/gui/menu.h b/source/gx/gui/menu.h index 99269e0..18ca97d 100644 --- a/source/gx/gui/menu.h +++ b/source/gx/gui/menu.h @@ -167,6 +167,7 @@ typedef struct { butn_data *data; /* pointer to button image/texture data */ u8 state; /* button state (ACTIVE,VISIBLE,SELECTED...) */ + u8 shift[2]; /* up & down direction offsets */ u16 x; /* button image X position (upper left corner) */ u16 y; /* button image Y position (upper left corner) */ u16 w; /* button image pixels width */ @@ -193,11 +194,10 @@ typedef struct { char title[64]; /* menu title */ s8 selected; /* index of selected item */ - u8 offset; /* items list offset */ + s8 offset; /* items list offset */ u8 max_items; /* total number of items */ u8 max_buttons; /* total number of buttons */ u8 max_images; /* total number of background images */ - u8 shift[2]; /* number of buttons per line */ gui_item *items; /* menu items */ gui_butn *buttons; /* menu buttons */ gui_image *bg_images; /* background images */ diff --git a/source/gx/gx_audio.c b/source/gx/gx_audio.c index b4d2394..f66448f 100644 --- a/source/gx/gx_audio.c +++ b/source/gx/gx_audio.c @@ -26,9 +26,6 @@ #include #include -extern u8 *Bg_music_ogg; -extern u32 Bg_music_ogg_size; - /* DMA soundbuffers (required to be 32-bytes aligned) Length is dimensionned for one frame of emulation (see below) To prevent audio clashes, we use double buffering technique: @@ -53,6 +50,10 @@ static u32 dma_sync; /* audio DMA status */ static u8 audioStarted = 0; +/* Background music */ +static u8 *Bg_music_ogg = NULL; +static u32 Bg_music_ogg_size = 0; + /*** AudioDmaCallback @@ -72,10 +73,29 @@ static void AudioDmaCallback(void) This function initializes the Audio Interface Default samplerate is set to 48khZ ***/ -void gx_audio_init(void) +void gx_audio_Init(void) { AUDIO_Init (NULL); AUDIO_SetDSPSampleRate (AI_SAMPLERATE_48KHZ); + + /* load background music from FAT device */ + char fname[MAXPATHLEN]; + sprintf(fname,"%s/Bg_music.ogg",DEFAULT_PATH); + FILE *f = fopen(fname,"rb"); + if (f) + { + struct stat filestat; + stat(fname, &filestat); + Bg_music_ogg_size = filestat.st_size; + Bg_music_ogg = memalign(32,Bg_music_ogg_size); + if (Bg_music_ogg) fread(Bg_music_ogg,1,Bg_music_ogg_size,f); + fclose(f); + } +} + +void gx_audio_Shutdown(void) +{ + if (Bg_music_ogg) free(Bg_music_ogg); } /*** @@ -87,7 +107,7 @@ void gx_audio_init(void) This function retrieves samples for the frame then set the next DMA parameters Parameters will be taken in account only when current DMA operation is over ***/ -void gx_audio_update(void) +void gx_audio_Update(void) { u32 size = dma_len; @@ -127,7 +147,7 @@ void gx_audio_update(void) This function resets the audio engine This is called when coming back from Main Menu ***/ -void gx_audio_start(void) +void gx_audio_Start(void) { /* shutdown menu audio */ PauseOgg(1); @@ -167,7 +187,7 @@ void gx_audio_start(void) This is called when going back to Main Menu DMA need to be restarted when going back to the game (see above) ***/ -void gx_audio_stop(void) +void gx_audio_Stop(void) { /* stop emulator audio */ AUDIO_StopDMA (); diff --git a/source/gx/gx_audio.h b/source/gx/gx_audio.h index 38aeacb..efd0f22 100644 --- a/source/gx/gx_audio.h +++ b/source/gx/gx_audio.h @@ -27,9 +27,10 @@ extern u8 soundbuffer[2][3840]; extern u8 mixbuffer; -extern void gx_audio_init(void); -extern void gx_audio_start(void); -extern void gx_audio_stop(void); -extern void gx_audio_update(void); +extern void gx_audio_Init(void); +extern void gx_audio_Shutdown(void); +extern void gx_audio_Start(void); +extern void gx_audio_Stop(void); +extern void gx_audio_Update(void); #endif diff --git a/source/gx/gx_input.c b/source/gx/gx_input.c index 757f7f3..79a7183 100644 --- a/source/gx/gx_input.c +++ b/source/gx/gx_input.c @@ -25,50 +25,58 @@ #include "font.h" #include "menu.h" -/* analog sensitivity */ +/* Analog sticks sensitivity */ #define ANALOG_SENSITIVITY 30 +/* Delay before held keys triggering */ +#define HELD_DELAY 18 + +/* Direction & selection update speed when a key is being held */ +/* the less is the value, faster is the key update */ +#define HELD_SPEED 4 + /* Menu request flag */ u8 ConfigRequested = 0; -/* configurable Genesis keys */ -#define KEY_BUTTONA 0 +/* Configurable Genesis keys */ +#define KEY_BUTTONA 0 #define KEY_BUTTONB 1 #define KEY_BUTTONC 2 #define KEY_START 3 -#define KEY_BUTTONX 5 // 6-buttons only -#define KEY_BUTTONY 6 // 6-buttons only -#define KEY_BUTTONZ 7 // 6-buttons only -#define KEY_MODE 8 // 6-buttons only +#define KEY_BUTTONX 5 /* 6-buttons only */ +#define KEY_BUTTONY 6 /* 6-buttons only */ +#define KEY_BUTTONZ 7 /* 6-buttons only */ +#define KEY_MODE 8 /* 6-buttons only */ static const char *keys_name[MAX_KEYS] = { "Button A", "Button B", "Button C", - "Button START ", + "START Button", "Button X", "Button Y", "Button Z", + "MODE Button" }; +static int held_cnt = 0; + + #ifdef HW_RVL -/* default directionnal buttons map */ #define PAD_UP 0 #define PAD_DOWN 1 #define PAD_LEFT 2 #define PAD_RIGHT 3 +/* default directions mapping */ static u32 wpad_dirmap[3][4] = { {WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_DOWN}, /* WIIMOTE */ {WPAD_BUTTON_UP, WPAD_BUTTON_DOWN, WPAD_BUTTON_LEFT, WPAD_BUTTON_RIGHT}, /* WIIMOTE + NUNCHUK */ {WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT} /* CLASSIC */ }; - -static int held_cnt = 0; - #endif @@ -89,6 +97,7 @@ static void pad_config(int chan, int max_keys) return; } + /* disable inputs update callback */ VIDEO_SetPostRetraceCallback(NULL); VIDEO_Flush(); @@ -132,7 +141,8 @@ static void pad_config(int chan, int max_keys) if (key !=0xff) config.pad_keymap[chan][i] = key; } - VIDEO_SetPostRetraceCallback(gx_input_updateMenu); + /* restore inputs update callback */ + VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } @@ -314,6 +324,7 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys) return; } + /* disable inputs update callback */ VIDEO_SetPostRetraceCallback(NULL); VIDEO_Flush(); @@ -344,7 +355,7 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys) switch (exp) { - /* Wiimote (TODO: add motion sensor) */ + /* Wiimote (TODO: add motion sensing !) */ case WPAD_EXP_NONE: if (p & WPAD_BUTTON_HOME) key = 0xff; else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; @@ -355,7 +366,7 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys) else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS; break; - /* Wiimote + Nunchuk */ + /* Wiimote + Nunchuk (TODO: add motion sensing !) */ case WPAD_EXP_NUNCHUK: if (p & WPAD_BUTTON_HOME) key = 0xff; else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; @@ -393,7 +404,8 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys) if (key != 0xff) config.wpad_keymap[exp + (chan * 3)][i] = key; } - VIDEO_SetPostRetraceCallback(gx_input_updateMenu); + /* restore inputs update callback */ + VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } @@ -554,7 +566,7 @@ static void wpad_update(s8 chan, u8 i, u32 exp) /***************************************************************************************/ /* GX Input interface */ /***************************************************************************************/ -void gx_input_init(void) +void gx_input_Init(void) { PAD_Init (); @@ -565,11 +577,11 @@ void gx_input_init(void) WPAD_SetVRes(WPAD_CHAN_ALL,640,480); #endif - VIDEO_SetPostRetraceCallback(gx_input_updateMenu); + VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); VIDEO_Flush(); } -void gx_input_setDefault(void) +void gx_input_SetDefault(void) { int i; @@ -583,7 +595,7 @@ void gx_input_setDefault(void) config.pad_keymap[i][KEY_BUTTONX] = PAD_TRIGGER_L; config.pad_keymap[i][KEY_BUTTONY] = PAD_BUTTON_Y; config.pad_keymap[i][KEY_BUTTONZ] = PAD_TRIGGER_R; - config.pad_keymap[i][KEY_MODE] = PAD_TRIGGER_R; + config.pad_keymap[i][KEY_MODE] = 0; } #ifdef HW_RVL @@ -621,10 +633,10 @@ void gx_input_setDefault(void) } #endif - /* Set default device assignation */ + /* Default device assignation */ for (i=0; i 70) p |= PAD_BUTTON_RIGHT; - else if (x < -70) p |= PAD_BUTTON_LEFT; - if (y > 60) p |= PAD_BUTTON_UP; - else if (y < -60) p |= PAD_BUTTON_DOWN; + if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT; + else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT; + else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP; + else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN; #ifdef HW_RVL - /* WPAD status */ + /* WPAD status update */ WPAD_ScanPads(); WPADData *data = WPAD_Data(0); - u32 q = data->btns_d; - u32 h = data->btns_h; - /* fast scrolling/selection */ - h &= (WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT|WPAD_BUTTON_A); - - /* wait for the key to be held for a short period */ - if (h) held_cnt++; + /* WPAD pressed keys */ + u32 pw = data->btns_d; + + /* WPAD held keys (direction/selection) */ + u32 hw = data->btns_h & (WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT|WPAD_BUTTON_A|WPAD_BUTTON_2); + + /* WPAD analog sticks (handled as PAD held direction keys) */ + x = WPAD_StickX(data, 0); + y = WPAD_StickY(data, 0); + if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT; + else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT; + else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP; + else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN; +#endif + + /* check if any direction/selection key is being held or just being pressed/released */ +#ifdef HW_RVL + if (pp||pw) held_cnt = 0; + else if (hp||hw) held_cnt++; else held_cnt = 0; - if (held_cnt > 14) +#else + if (pp) held_cnt = 0; + else if (hp) held_cnt++; + else held_cnt = 0; +#endif + + /* initial delay (prevents triggering to start immediately) */ + if (held_cnt > HELD_DELAY) { - /* update pressed status */ - held_cnt = 0; - q |= h; + /* key triggering */ + pp |= hp; +#ifdef HW_RVL + pw |= hw; +#endif + + /* delay until next triggering (adjusts direction/selection update speed) */ + held_cnt -= HELD_SPEED; } - /* Wiimote orientation */ +#ifdef HW_RVL + /* Wiimote direction keys */ WPAD_IR(0, &m_input.ir); if (m_input.ir.valid) { - if (q & WPAD_BUTTON_UP) p |= PAD_BUTTON_UP; - else if (q & WPAD_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; - else if (q & WPAD_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; - else if (q & WPAD_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; + /* Wiimote is handled vertically */ + if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_UP; + else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN; + else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT; + else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT; } else { - if (q & WPAD_BUTTON_UP) p |= PAD_BUTTON_LEFT; - else if (q & WPAD_BUTTON_DOWN) p |= PAD_BUTTON_RIGHT; - else if (q & WPAD_BUTTON_LEFT) p |= PAD_BUTTON_DOWN; - else if (q & WPAD_BUTTON_RIGHT) p |= PAD_BUTTON_UP; + /* Wiimote is handled horizontally */ + if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_LEFT; + else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_RIGHT; + else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_DOWN; + else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_UP; } - /* Analog sticks */ - x = WPAD_StickX(data, 0); - y = WPAD_StickY(data, 0); - if (y > 70) p |= PAD_BUTTON_UP; - else if (y < -70) p |= PAD_BUTTON_DOWN; - if (x < -60) p |= PAD_BUTTON_LEFT; - else if (x > 60) p |= PAD_BUTTON_RIGHT; + /* Classic Controller direction keys */ + if (pw & WPAD_CLASSIC_BUTTON_UP) pp |= PAD_BUTTON_UP; + else if (pw & WPAD_CLASSIC_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN; + else if (pw & WPAD_CLASSIC_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT; + else if (pw & WPAD_CLASSIC_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT; - /* Classic controller */ - if (q & WPAD_CLASSIC_BUTTON_UP) p |= PAD_BUTTON_UP; - else if (q & WPAD_CLASSIC_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; - if (q & WPAD_CLASSIC_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; - else if (q & WPAD_CLASSIC_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; - - /* Supported keys */ - if (q & WPAD_BUTTON_MINUS) p |= PAD_TRIGGER_L; - if (q & WPAD_BUTTON_PLUS) p |= PAD_TRIGGER_R; - if (q & WPAD_BUTTON_A) p |= PAD_BUTTON_A; - if (q & WPAD_BUTTON_B) p |= PAD_BUTTON_B; - if (q & WPAD_BUTTON_2) p |= PAD_BUTTON_A; - if (q & WPAD_BUTTON_1) p |= PAD_BUTTON_B; - if (q & WPAD_BUTTON_HOME) p |= PAD_TRIGGER_Z; - if (q & WPAD_CLASSIC_BUTTON_FULL_L) p |= PAD_TRIGGER_L; - if (q & WPAD_CLASSIC_BUTTON_FULL_R) p |= PAD_TRIGGER_R; - if (q & WPAD_CLASSIC_BUTTON_A) p |= PAD_BUTTON_A; - if (q & WPAD_CLASSIC_BUTTON_B) p |= PAD_BUTTON_B; - if (q & WPAD_CLASSIC_BUTTON_HOME) p |= PAD_TRIGGER_Z; + /* WPAD buttons */ + if (pw & WPAD_BUTTON_MINUS) pp |= PAD_TRIGGER_L; + if (pw & WPAD_BUTTON_PLUS) pp |= PAD_TRIGGER_R; + if (pw & WPAD_BUTTON_A) pp |= PAD_BUTTON_A; + if (pw & WPAD_BUTTON_B) pp |= PAD_BUTTON_B; + if (pw & WPAD_BUTTON_2) pp |= PAD_BUTTON_A; + if (pw & WPAD_BUTTON_1) pp |= PAD_BUTTON_B; + if (pw & WPAD_BUTTON_HOME) pp |= PAD_TRIGGER_Z; + if (pw & WPAD_CLASSIC_BUTTON_FULL_L) pp |= PAD_TRIGGER_L; + if (pw & WPAD_CLASSIC_BUTTON_FULL_R) pp |= PAD_TRIGGER_R; + if (pw & WPAD_CLASSIC_BUTTON_A) pp |= PAD_BUTTON_A; + if (pw & WPAD_CLASSIC_BUTTON_B) pp |= PAD_BUTTON_B; + if (pw & WPAD_CLASSIC_BUTTON_HOME) pp |= PAD_TRIGGER_Z; #endif /* Update menu inputs */ - m_input.keys = p; + m_input.keys = pp; } diff --git a/source/gx/gx_input.h b/source/gx/gx_input.h index 8c99cdc..3739aa1 100644 --- a/source/gx/gx_input.h +++ b/source/gx/gx_input.h @@ -35,7 +35,7 @@ #define MAX_KEYS 8 /* Genesis Plus wrapper */ -#define update_input() gx_input_updateEmu() +#define update_input() gx_input_UpdateEmu() /* Key configuration structure */ typedef struct @@ -45,11 +45,11 @@ typedef struct } t_input_config; -extern void gx_input_init(void); -extern void gx_input_setDefault(void); -extern void gx_input_config(u8 num, u8 type, u8 max_keys); -extern void gx_input_updateEmu(void); -extern void gx_input_updateMenu(u32 cnt); +extern void gx_input_Init(void); +extern void gx_input_SetDefault(void); +extern void gx_input_Config(u8 num, u8 type, u8 max_keys); +extern void gx_input_UpdateEmu(void); +extern void gx_input_UpdateMenu(u32 cnt); extern u8 ConfigRequested; diff --git a/source/gx/gx_video.c b/source/gx/gx_video.c index 0c4c2d6..84d2483 100644 --- a/source/gx/gx_video.c +++ b/source/gx/gx_video.c @@ -944,7 +944,7 @@ void gxClearScreen (GXColor color) } /* Restore Menu Video mode */ -void gx_video_stop(void) +void gx_video_Stop(void) { /* lightgun textures */ if (crosshair[0]) @@ -968,12 +968,12 @@ void gx_video_stop(void) gxDrawScreenshot(0xff); VIDEO_Configure(vmode); VIDEO_SetPreRetraceCallback(NULL); - VIDEO_SetPostRetraceCallback(gx_input_updateMenu); + VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu); gxSetScreen (); } /* Update Video settings */ -void gx_video_start(void) +void gx_video_Start(void) { /* 50Hz/60Hz mode */ if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal)) gc_pal = 1; @@ -1039,7 +1039,7 @@ void gx_video_start(void) /* GX render update */ -void gx_video_update(void) +void gx_video_Update(void) { /* check if display has changed */ if (bitmap.viewport.changed) @@ -1129,7 +1129,7 @@ void gx_video_update(void) } /* Initialize VIDEO subsystem */ -void gx_video_init(void) +void gx_video_Init(void) { /* * Before doing anything else under libogc, @@ -1233,6 +1233,17 @@ void gx_video_init(void) gxResetRendering(1); gxResetView(vmode); + /* initialize FONT */ + if (!FONT_Init()) + { +#ifdef HW_RVL + DI_Close(); + SYS_ResetSystem(SYS_RESTART,0,0); +#else + SYS_ResetSystem(SYS_HOTRESET,0,0); +#endif + } + /* Initialize texture data */ texturemem = memalign(32, TEX_SIZE); if (!texturemem) @@ -1240,8 +1251,6 @@ void gx_video_init(void) WaitPrompt("Failed to allocate texture buffer... Rebooting"); #ifdef HW_RVL DI_Close(); -#endif -#ifdef HW_RVL SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); @@ -1249,3 +1258,12 @@ void gx_video_init(void) } memset (texturemem, 0, TEX_SIZE); } + +void gx_video_Shutdown(void) +{ + if (texturemem) free(texturemem); + FONT_Shutdown(); + VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); + VIDEO_Flush(); + VIDEO_WaitVSync(); +} diff --git a/source/gx/gx_video.h b/source/gx/gx_video.h index 6574f44..01f0fc3 100644 --- a/source/gx/gx_video.h +++ b/source/gx/gx_video.h @@ -46,10 +46,11 @@ extern u8 *texturemem; extern u8 gc_pal; /* GX video emulation functions */ -extern void gx_video_init(void); -extern void gx_video_start(void); -extern void gx_video_stop(void); -extern void gx_video_update(void); +extern void gx_video_Init(void); +extern void gx_video_Shutdown(void); +extern void gx_video_Start(void); +extern void gx_video_Stop(void); +extern void gx_video_Update(void); /* GX draw functions */ extern gx_texture *gxTextureOpenPNG(const u8 *buffer); diff --git a/source/gx/main.c b/source/gx/main.c index 6715be6..e67ab07 100644 --- a/source/gx/main.c +++ b/source/gx/main.c @@ -36,6 +36,7 @@ #endif #ifdef HW_RVL + /* Power Button callback */ u8 Shutdown = 0; static void Power_Off(void) @@ -43,10 +44,8 @@ static void Power_Off(void) Shutdown = 1; ConfigRequested = 1; } -#endif -u8 *Bg_music_ogg = NULL; -u32 Bg_music_ogg_size = 0;; +#endif /*************************************************************************** * Genesis Plus Virtual Machine @@ -86,12 +85,10 @@ static void init_machine(void) if (!cart_rom) { WaitPrompt("Failed to allocate ROM buffer... Rebooting"); - free(texturemem); - FONT_Shutdown(); + gx_audio_Shutdown(); + gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); -#endif -#ifdef HW_RVL SYS_ResetSystem(SYS_RESTART,0,0); #else SYS_ResetSystem(SYS_HOTRESET,0,0); @@ -142,12 +139,8 @@ void shutdown(void) system_shutdown(); audio_shutdown(); free(cart_rom); - free(texturemem); - if (Bg_music_ogg) free(Bg_music_ogg); - FONT_Shutdown(); - VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK); - VIDEO_Flush(); - VIDEO_WaitVSync(); + gx_audio_Shutdown(); + gx_video_Shutdown(); #ifdef HW_RVL DI_Close(); #endif @@ -172,38 +165,16 @@ int main (int argc, char *argv[]) uint32 TotalFrames = 0; uint32 FramesPerSecond = 0; - /* initialize harwdare */ - gx_video_init(); - gx_input_init(); - gx_audio_init(); - - /* initialize font */ - if (!FONT_Init()) - { - WaitPrompt("Failed to allocate ROM buffer... Rebooting"); - free(texturemem); -#ifdef HW_RVL - DI_Close(); -#endif -#ifdef HW_RVL - SYS_ResetSystem(SYS_RESTART,0,0); -#else - SYS_ResetSystem(SYS_HOTRESET,0,0); -#endif - } - + /* initialize hardware */ + gx_video_Init(); + gx_input_Init(); + gx_audio_Init(); #ifdef HW_DOL - /* initialize GC DVD interface */ DVD_Init (); dvd_drive_detect(); #endif -#ifdef HW_RVL - /* Power button callback */ - SYS_SetPowerCallback(Power_Off); -#endif - - /* initialize FAT Interface */ + /* initialize FAT devices */ if (fatInitDefault()) { fat_enabled = 1; @@ -216,27 +187,15 @@ int main (int argc, char *argv[]) #endif } - /* background music */ - char fname[MAXPATHLEN]; - sprintf(fname,"%s/Bg_music.ogg",DEFAULT_PATH); - FILE *f = fopen(fname,"rb"); - if (f) - { - struct stat filestat; - stat(fname, &filestat); - Bg_music_ogg_size = filestat.st_size; - Bg_music_ogg = memalign(32,Bg_music_ogg_size); - if (Bg_music_ogg) fread(Bg_music_ogg,1,Bg_music_ogg_size,f); - fclose(f); - } - + /* Initialize sound engine */ + gx_audio_Init(); /* default config */ legal(); config_setDefault(); config_load(); - /* restore recent files list */ + /* recent ROM files list */ history_setDefault(); history_load(); @@ -248,8 +207,8 @@ int main (int argc, char *argv[]) { ARAMFetch((char *)cart_rom, (void *)0x8000, genromsize); reloadrom (genromsize,"INJECT.bin"); - gx_video_start(); - gx_audio_start(); + gx_video_Start(); + gx_audio_Start(); frameticker = 1; } else @@ -258,6 +217,11 @@ int main (int argc, char *argv[]) ConfigRequested = 1; } +#ifdef HW_RVL + /* Power button callback */ + SYS_SetPowerCallback(Power_Off); +#endif + /* main emulation loop */ while (1) { @@ -265,8 +229,8 @@ int main (int argc, char *argv[]) if (ConfigRequested) { /* stop audio & video */ - gx_video_stop(); - gx_audio_stop(); + gx_video_Stop(); + gx_audio_Stop(); /* go to menu */ MainMenu (); @@ -278,8 +242,8 @@ int main (int argc, char *argv[]) FramesPerSecond = vdp_rate; /* start audio & video */ - gx_video_start(); - gx_audio_start(); + gx_video_Start(); + gx_audio_Start(); /* reset framesync */ frameticker = 1; @@ -292,7 +256,7 @@ int main (int argc, char *argv[]) system_frame (1); /* update audio only */ - gx_audio_update(); + gx_audio_Update(); } else { @@ -304,8 +268,8 @@ int main (int argc, char *argv[]) system_frame (0); /* update video & audio */ - gx_video_update(); - gx_audio_update(); + gx_video_Update(); + gx_audio_Update(); RenderedFrames++; }