+ improved menu navigation

+ improved menu transitions
+ GX code cleanup
This commit is contained in:
ekeeke31 2009-04-23 23:24:40 +00:00
parent d1b4f1b109
commit 3e82e4f058
11 changed files with 338 additions and 247 deletions

View File

@ -95,7 +95,7 @@ void config_setDefault(void)
config.bilinear = 1; config.bilinear = 1;
/* controllers options */ /* controllers options */
gx_input_setDefault(); gx_input_SetDefault();
config.gun_cursor = 1; config.gun_cursor = 1;
config.invert_mouse = 0; config.invert_mouse = 0;

View File

@ -68,8 +68,8 @@ static butn_data arrow_down_data =
/* GUI Arrows button */ /* GUI Arrows button */
/*****************************************************************************/ /*****************************************************************************/
static gui_butn arrow_up = {&arrow_up_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,14,76,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,14,368,360,32}; static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{0,0},14,368,360,32};
/*****************************************************************************/ /*****************************************************************************/
/* GUI helpers */ /* GUI helpers */
@ -114,9 +114,8 @@ static gui_image bg_filesel[9] =
static gui_menu menu_browser = static gui_menu menu_browser =
{ {
"ROM Selection", "ROM Selection",
-1,0, -1,-1,
0,0,9, 0,0,9,
{0,0},
NULL, NULL,
NULL, NULL,
bg_filesel, bg_filesel,

View File

@ -179,11 +179,11 @@ static gui_item items_load[3] =
static gui_item items_options[5] = static gui_item items_options[5] =
{ {
{NULL,Option_system_png,"","System options", 114,142,80,92}, {NULL,Option_system_png,"","System settings", 114,142,80,92},
{NULL,Option_video_png ,"","Video options", 288,150,64,84}, {NULL,Option_video_png ,"","Video settings", 288,150,64,84},
{NULL,Option_sound_png ,"","Audio options", 464,154,44,80}, {NULL,Option_sound_png ,"","Audio settings", 464,154,44,80},
{NULL,Option_ctrl_png ,"","Input options", 192,286,88,92}, {NULL,Option_ctrl_png ,"","Input settings", 192,286,88,92},
{NULL,Option_menu_png ,"","Menu options", 370,286,60,92} {NULL,Option_menu_png ,"","Menu settings", 370,286,60,92}
}; };
/* Audio options menu */ /* Audio options menu */
@ -233,29 +233,29 @@ static gui_item items_prefs[5] =
/*****************************************************************************/ /*****************************************************************************/
/* Generic Buttons for list menu */ /* Generic Buttons for list menu */
static gui_butn arrow_up = {&arrow_up_data,BUTTON_OVER_SFX,14,76,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,14,368,360,32}; static gui_butn arrow_down = {&arrow_down_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{0,0},14,368,360,32};
/* Generic list menu */ /* Generic list menu */
static gui_butn buttons_list[4] = 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,{1,1},52,132,276,48},
{&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,188,276,48}, {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},52,188,276,48},
{&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 52,244,276,48}, {&button_text_data,BUTTON_VISIBLE|BUTTON_OVER_SFX,{1,1},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,300,276,48}
}; };
/* Main menu */ /* Main menu */
static gui_butn buttons_main[8] = 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,{0,3}, 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,{0,3},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,{0,3},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|BUTTON_SELECT_SFX,{3,3}, 80,194,148,132},
{&button_icon_data,BUTTON_VISIBLE|BUTTON_OVER_SFX, 246,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,412,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, 0,360, 88, 48}, {NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX ,{3,0}, 0,360, 88, 48},
{NULL ,BUTTON_VISIBLE|BUTTON_OVER_SFX|BUTTON_SELECT_SFX,552,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 #ifdef HW_RVL
static gui_butn buttons_load[4] = 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,{0,2},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,{1,0}, 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,{2,0},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,{3,0},412,248,148,132}
}; };
#else #else
static gui_butn buttons_load[3] = 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,{0,0}, 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,{0,0},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},412,180,148,132}
}; };
#endif #endif
/* Options menu */ /* Options menu */
static gui_butn buttons_options[5] = 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,{0,3}, 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,{0,3},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,{0,2},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,{3,0},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,{2,0},330,264,148,132}
}; };
/*****************************************************************************/ /*****************************************************************************/
@ -297,7 +297,6 @@ static gui_menu menu_main =
"", "",
0,0, 0,0,
8,8,4, 8,8,4,
{3,3},
items_main, items_main,
buttons_main, buttons_main,
bg_main, bg_main,
@ -313,10 +312,8 @@ static gui_menu menu_load =
0,0, 0,0,
#ifdef HW_RVL #ifdef HW_RVL
4,4,5, 4,4,5,
{1,3},
#else #else
3,3,5, 3,3,5,
{3,0},
#endif #endif
items_load, items_load,
buttons_load, buttons_load,
@ -332,7 +329,6 @@ static gui_menu menu_options =
"Settings", "Settings",
0,0, 0,0,
5,5,5, 5,5,5,
{3,2},
items_options, items_options,
buttons_options, buttons_options,
bg_misc, bg_misc,
@ -344,25 +340,23 @@ static gui_menu menu_options =
/* System Options menu */ /* System Options menu */
static gui_menu menu_system = static gui_menu menu_system =
{ {
"System Options", "System Settings",
0,0, 0,0,
4,4,6, 4,4,6,
{1,1},
items_system, items_system,
buttons_list, buttons_list,
bg_list, bg_list,
{&action_cancel, &action_select}, {&action_cancel, &action_select},
{&arrow_up,&arrow_down}, {NULL,NULL},
FALSE FALSE
}; };
/* Video Options menu */ /* Video Options menu */
static gui_menu menu_video = static gui_menu menu_video =
{ {
"Video Options", "Video Settings",
0,0, 0,0,
8,4,6, 8,4,6,
{1,1},
items_video, items_video,
buttons_list, buttons_list,
bg_list, bg_list,
@ -374,10 +368,9 @@ static gui_menu menu_video =
/* Sound Options menu */ /* Sound Options menu */
static gui_menu menu_audio = static gui_menu menu_audio =
{ {
"Sound Options", "Sound Settings",
0,0, 0,0,
5,4,6, 5,4,6,
{1,1},
items_audio, items_audio,
buttons_list, buttons_list,
bg_list, bg_list,
@ -389,10 +382,9 @@ static gui_menu menu_audio =
/* Sound Options menu */ /* Sound Options menu */
static gui_menu menu_prefs = static gui_menu menu_prefs =
{ {
"Sound Options", "Menu Settings",
0,0, 0,0,
5,4,6, 5,4,6,
{1,1},
items_prefs, items_prefs,
buttons_list, buttons_list,
bg_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[0]) button->data->texture[0] = gxTextureOpenPNG(button->data->image[0]);
if (!button->data->texture[1]) button->data->texture[1] = gxTextureOpenPNG(button->data->image[1]); 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); GUI_DeleteMenu(menu);
} }
/* Window Prompt */ /* Window Prompt */
/* prompt window slides in & out */ /* prompt window slides in & out */
int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items) 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 p;
u16 max_buttons = menu->max_buttons; u16 max_buttons = menu->max_buttons;
u16 max_items = menu->max_items; u16 max_items = menu->max_items;
u16 shift[2] = {menu->shift[0],menu->shift[1]};
#ifdef HW_RVL #ifdef HW_RVL
int i,x,y; int i,x,y;
@ -1040,27 +1038,53 @@ int GUI_RunMenu(gui_menu *menu)
{ {
if (p & PAD_BUTTON_UP) if (p & PAD_BUTTON_UP)
{ {
if (selected == 0) button = &menu->buttons[selected];
if (button->shift[0])
{ {
if (menu->offset) menu->offset --; selected -= button->shift[0];
} if (selected < 0)
else if (selected >= shift[0]) {
{ selected = 0;
selected -= shift[1]; if (menu->offset) menu->offset --;
if (selected < 0) selected = 0; }
} }
} }
else if (p & PAD_BUTTON_DOWN) 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; if (selected >= max_buttons) selected = max_buttons - 1;
} }
else
{
quit = 1;
}
} }
else if (p & PAD_BUTTON_LEFT) else if (p & PAD_BUTTON_LEFT)
{ {
@ -1164,6 +1188,24 @@ int GUI_RunMenu(gui_menu *menu)
return -1; 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) * drawmenu (deprecated)
* *
@ -1297,6 +1339,7 @@ static void prefmenu ()
gui_item *items = m->items; gui_item *items = m->items;
GUI_InitMenu(m); GUI_InitMenu(m);
GUI_SlideMenuTitle(m,strlen("Menu "));
while (quit == 0) while (quit == 0)
{ {
@ -1307,9 +1350,9 @@ static void prefmenu ()
if (config.state_auto == 0) sprintf (items[1].text, "Savestate Auto: FAT"); 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 == 1) sprintf (items[1].text, "Savestate Auto: MCARD A");
else if (config.state_auto == 2) sprintf (items[1].text, "Savestate Auto: MCARD B"); else if (config.state_auto == 2) sprintf (items[1].text, "Savestate Auto: MCARD B");
else sprintf (items[3].text, "Savestate Auto: OFF"); else sprintf (items[1].text, "Savestate Auto: OFF");
sprintf (items[2].text, "SFX Volume: %1.2f", config.sfx_volume); sprintf (items[2].text, "SFX Volume: %1.1f", config.sfx_volume);
sprintf (items[3].text, "BGM Volume: %1.2f", config.bgm_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); if (config.bg_color) sprintf (items[4].text, "BG Color: Type %d", config.bg_color);
else sprintf (items[4].text, "BG Color: DEFAULT"); else sprintf (items[4].text, "BG Color: DEFAULT");
@ -1329,16 +1372,16 @@ static void prefmenu ()
case 2: /*** Sound effects volume ***/ case 2: /*** Sound effects volume ***/
case -4: case -4:
if (ret < 0) config.sfx_volume --; if (ret < 0) config.sfx_volume -=10;
else config.sfx_volume ++; else config.sfx_volume +=10;
if (config.sfx_volume < 0) config.sfx_volume = 100.0; if (config.sfx_volume < 0) config.sfx_volume = 100.0;
else if (config.sfx_volume > 100) config.sfx_volume = 0.0; else if (config.sfx_volume > 100) config.sfx_volume = 0.0;
break; break;
case 3: /*** Background music volume ***/ case 3: /*** Background music volume ***/
case -5: case -5:
if (ret < 0) config.bgm_volume --; if (ret < 0) config.bgm_volume -=10;
else config.bgm_volume ++; else config.bgm_volume +=10;
if (config.bgm_volume < 0) config.bgm_volume = 100.0; if (config.bgm_volume < 0) config.bgm_volume = 100.0;
else if (config.bgm_volume > 100) config.bgm_volume = 0.0; else if (config.bgm_volume > 100) config.bgm_volume = 0.0;
SetVolumeOgg(((int)config.bgm_volume * 255) / 100); SetVolumeOgg(((int)config.bgm_volume * 255) / 100);
@ -1372,6 +1415,7 @@ static void soundmenu ()
gui_item *items = m->items; gui_item *items = m->items;
GUI_InitMenu(m); GUI_InitMenu(m);
GUI_SlideMenuTitle(m,strlen("Sound "));
while (quit == 0) while (quit == 0)
{ {
@ -1449,6 +1493,7 @@ static void systemmenu ()
gui_item *items = m->items; gui_item *items = m->items;
GUI_InitMenu(m); GUI_InitMenu(m);
GUI_SlideMenuTitle(m,strlen("System "));
while (quit == 0) while (quit == 0)
{ {
@ -1530,6 +1575,7 @@ static void videomenu ()
gui_item *items = m->items; gui_item *items = m->items;
GUI_InitMenu(m); GUI_InitMenu(m);
GUI_SlideMenuTitle(m,strlen("Video "));
while (quit == 0) while (quit == 0)
{ {
@ -1910,11 +1956,11 @@ static void inputsmenu(void)
case 7: case 7:
if (config.input[player].device < 0) break; if (config.input[player].device < 0) break;
if (input.padtype[player] == DEVICE_3BUTTON) /* 3-buttons */ 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 */ 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 */ 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; break;
case -1: case -1:
@ -2289,8 +2335,10 @@ void MainMenu (void)
m->max_items = 8; m->max_items = 8;
m->max_buttons = 8; m->max_buttons = 8;
m->buttons[3].state |= BUTTON_SELECT_SFX; m->buttons[3].state |= BUTTON_SELECT_SFX;
m->buttons[4].state |= BUTTON_SELECT_SFX;
m->buttons[5].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 else
{ {
@ -2298,8 +2346,10 @@ void MainMenu (void)
m->max_items = 6; m->max_items = 6;
m->max_buttons = 6; m->max_buttons = 6;
m->buttons[3].state &= ~BUTTON_SELECT_SFX; m->buttons[3].state &= ~BUTTON_SELECT_SFX;
m->buttons[4].state &= ~BUTTON_SELECT_SFX;
m->buttons[5].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); GUI_DrawMenuFX(m,10,0);

View File

@ -167,6 +167,7 @@ typedef struct
{ {
butn_data *data; /* pointer to button image/texture data */ butn_data *data; /* pointer to button image/texture data */
u8 state; /* button state (ACTIVE,VISIBLE,SELECTED...) */ u8 state; /* button state (ACTIVE,VISIBLE,SELECTED...) */
u8 shift[2]; /* up & down direction offsets */
u16 x; /* button image X position (upper left corner) */ u16 x; /* button image X position (upper left corner) */
u16 y; /* button image Y position (upper left corner) */ u16 y; /* button image Y position (upper left corner) */
u16 w; /* button image pixels width */ u16 w; /* button image pixels width */
@ -193,11 +194,10 @@ typedef struct
{ {
char title[64]; /* menu title */ char title[64]; /* menu title */
s8 selected; /* index of selected item */ 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_items; /* total number of items */
u8 max_buttons; /* total number of buttons */ u8 max_buttons; /* total number of buttons */
u8 max_images; /* total number of background images */ u8 max_images; /* total number of background images */
u8 shift[2]; /* number of buttons per line */
gui_item *items; /* menu items */ gui_item *items; /* menu items */
gui_butn *buttons; /* menu buttons */ gui_butn *buttons; /* menu buttons */
gui_image *bg_images; /* background images */ gui_image *bg_images; /* background images */

View File

@ -26,9 +26,6 @@
#include <asndlib.h> #include <asndlib.h>
#include <oggplayer.h> #include <oggplayer.h>
extern u8 *Bg_music_ogg;
extern u32 Bg_music_ogg_size;
/* DMA soundbuffers (required to be 32-bytes aligned) /* DMA soundbuffers (required to be 32-bytes aligned)
Length is dimensionned for one frame of emulation (see below) Length is dimensionned for one frame of emulation (see below)
To prevent audio clashes, we use double buffering technique: To prevent audio clashes, we use double buffering technique:
@ -53,6 +50,10 @@ static u32 dma_sync;
/* audio DMA status */ /* audio DMA status */
static u8 audioStarted = 0; static u8 audioStarted = 0;
/* Background music */
static u8 *Bg_music_ogg = NULL;
static u32 Bg_music_ogg_size = 0;
/*** /***
AudioDmaCallback AudioDmaCallback
@ -72,10 +73,29 @@ static void AudioDmaCallback(void)
This function initializes the Audio Interface This function initializes the Audio Interface
Default samplerate is set to 48khZ Default samplerate is set to 48khZ
***/ ***/
void gx_audio_init(void) void gx_audio_Init(void)
{ {
AUDIO_Init (NULL); AUDIO_Init (NULL);
AUDIO_SetDSPSampleRate (AI_SAMPLERATE_48KHZ); 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 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 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; u32 size = dma_len;
@ -127,7 +147,7 @@ void gx_audio_update(void)
This function resets the audio engine This function resets the audio engine
This is called when coming back from Main Menu This is called when coming back from Main Menu
***/ ***/
void gx_audio_start(void) void gx_audio_Start(void)
{ {
/* shutdown menu audio */ /* shutdown menu audio */
PauseOgg(1); PauseOgg(1);
@ -167,7 +187,7 @@ void gx_audio_start(void)
This is called when going back to Main Menu This is called when going back to Main Menu
DMA need to be restarted when going back to the game (see above) 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 */ /* stop emulator audio */
AUDIO_StopDMA (); AUDIO_StopDMA ();

View File

@ -27,9 +27,10 @@
extern u8 soundbuffer[2][3840]; extern u8 soundbuffer[2][3840];
extern u8 mixbuffer; extern u8 mixbuffer;
extern void gx_audio_init(void); extern void gx_audio_Init(void);
extern void gx_audio_start(void); extern void gx_audio_Shutdown(void);
extern void gx_audio_stop(void); extern void gx_audio_Start(void);
extern void gx_audio_update(void); extern void gx_audio_Stop(void);
extern void gx_audio_Update(void);
#endif #endif

View File

@ -25,50 +25,58 @@
#include "font.h" #include "font.h"
#include "menu.h" #include "menu.h"
/* analog sensitivity */ /* Analog sticks sensitivity */
#define ANALOG_SENSITIVITY 30 #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 */ /* Menu request flag */
u8 ConfigRequested = 0; u8 ConfigRequested = 0;
/* configurable Genesis keys */ /* Configurable Genesis keys */
#define KEY_BUTTONA 0 #define KEY_BUTTONA 0
#define KEY_BUTTONB 1 #define KEY_BUTTONB 1
#define KEY_BUTTONC 2 #define KEY_BUTTONC 2
#define KEY_START 3 #define KEY_START 3
#define KEY_BUTTONX 5 // 6-buttons only #define KEY_BUTTONX 5 /* 6-buttons only */
#define KEY_BUTTONY 6 // 6-buttons only #define KEY_BUTTONY 6 /* 6-buttons only */
#define KEY_BUTTONZ 7 // 6-buttons only #define KEY_BUTTONZ 7 /* 6-buttons only */
#define KEY_MODE 8 // 6-buttons only #define KEY_MODE 8 /* 6-buttons only */
static const char *keys_name[MAX_KEYS] = static const char *keys_name[MAX_KEYS] =
{ {
"Button A", "Button A",
"Button B", "Button B",
"Button C", "Button C",
"Button START ", "START Button",
"Button X", "Button X",
"Button Y", "Button Y",
"Button Z", "Button Z",
"MODE Button"
}; };
static int held_cnt = 0;
#ifdef HW_RVL #ifdef HW_RVL
/* default directionnal buttons map */
#define PAD_UP 0 #define PAD_UP 0
#define PAD_DOWN 1 #define PAD_DOWN 1
#define PAD_LEFT 2 #define PAD_LEFT 2
#define PAD_RIGHT 3 #define PAD_RIGHT 3
/* default directions mapping */
static u32 wpad_dirmap[3][4] = static u32 wpad_dirmap[3][4] =
{ {
{WPAD_BUTTON_RIGHT, WPAD_BUTTON_LEFT, WPAD_BUTTON_UP, WPAD_BUTTON_DOWN}, /* WIIMOTE */ {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_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 */ {WPAD_CLASSIC_BUTTON_UP, WPAD_CLASSIC_BUTTON_DOWN, WPAD_CLASSIC_BUTTON_LEFT, WPAD_CLASSIC_BUTTON_RIGHT} /* CLASSIC */
}; };
static int held_cnt = 0;
#endif #endif
@ -89,6 +97,7 @@ static void pad_config(int chan, int max_keys)
return; return;
} }
/* disable inputs update callback */
VIDEO_SetPostRetraceCallback(NULL); VIDEO_SetPostRetraceCallback(NULL);
VIDEO_Flush(); VIDEO_Flush();
@ -132,7 +141,8 @@ static void pad_config(int chan, int max_keys)
if (key !=0xff) config.pad_keymap[chan][i] = key; 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(); VIDEO_Flush();
} }
@ -314,6 +324,7 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys)
return; return;
} }
/* disable inputs update callback */
VIDEO_SetPostRetraceCallback(NULL); VIDEO_SetPostRetraceCallback(NULL);
VIDEO_Flush(); VIDEO_Flush();
@ -344,7 +355,7 @@ static void wpad_config(u8 chan, u8 exp, u8 max_keys)
switch (exp) switch (exp)
{ {
/* Wiimote (TODO: add motion sensor) */ /* Wiimote (TODO: add motion sensing !) */
case WPAD_EXP_NONE: case WPAD_EXP_NONE:
if (p & WPAD_BUTTON_HOME) key = 0xff; if (p & WPAD_BUTTON_HOME) key = 0xff;
else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; 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; else if (p & WPAD_BUTTON_MINUS) key = WPAD_BUTTON_MINUS;
break; break;
/* Wiimote + Nunchuk */ /* Wiimote + Nunchuk (TODO: add motion sensing !) */
case WPAD_EXP_NUNCHUK: case WPAD_EXP_NUNCHUK:
if (p & WPAD_BUTTON_HOME) key = 0xff; if (p & WPAD_BUTTON_HOME) key = 0xff;
else if (p & WPAD_BUTTON_2) key = WPAD_BUTTON_2; 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; 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(); VIDEO_Flush();
} }
@ -554,7 +566,7 @@ static void wpad_update(s8 chan, u8 i, u32 exp)
/***************************************************************************************/ /***************************************************************************************/
/* GX Input interface */ /* GX Input interface */
/***************************************************************************************/ /***************************************************************************************/
void gx_input_init(void) void gx_input_Init(void)
{ {
PAD_Init (); PAD_Init ();
@ -565,11 +577,11 @@ void gx_input_init(void)
WPAD_SetVRes(WPAD_CHAN_ALL,640,480); WPAD_SetVRes(WPAD_CHAN_ALL,640,480);
#endif #endif
VIDEO_SetPostRetraceCallback(gx_input_updateMenu); VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
VIDEO_Flush(); VIDEO_Flush();
} }
void gx_input_setDefault(void) void gx_input_SetDefault(void)
{ {
int i; 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_BUTTONX] = PAD_TRIGGER_L;
config.pad_keymap[i][KEY_BUTTONY] = PAD_BUTTON_Y; config.pad_keymap[i][KEY_BUTTONY] = PAD_BUTTON_Y;
config.pad_keymap[i][KEY_BUTTONZ] = PAD_TRIGGER_R; 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 #ifdef HW_RVL
@ -621,10 +633,10 @@ void gx_input_setDefault(void)
} }
#endif #endif
/* Set default device assignation */ /* Default device assignation */
for (i=0; i<MAX_DEVICES; i++) for (i=0; i<MAX_DEVICES; i++)
{ {
/* gamepad as default */ /* set gamepad by default */
config.input[i].device = (i < 4) ? 0 : -1; config.input[i].device = (i < 4) ? 0 : -1;
config.input[i].port = i%4; config.input[i].port = i%4;
} }
@ -668,7 +680,7 @@ void gx_input_setDefault(void)
#endif #endif
} }
void gx_input_config(u8 chan, u8 type, u8 max) void gx_input_Config(u8 chan, u8 type, u8 max)
{ {
switch (type) switch (type)
{ {
@ -684,7 +696,7 @@ void gx_input_config(u8 chan, u8 type, u8 max)
} }
} }
void gx_input_updateEmu(void) void gx_input_UpdateEmu(void)
{ {
int i; int i;
int player = 0; int player = 0;
@ -716,84 +728,110 @@ void gx_input_updateEmu(void)
} }
/* Menu inputs update function (done by Video Interrupt callback) */ /* Menu inputs update function (done by Video Interrupt callback) */
void gx_input_updateMenu(u32 cnt) void gx_input_UpdateMenu(u32 cnt)
{ {
/* PAD status */ /* PAD status update */
PAD_ScanPads(); PAD_ScanPads();
s16 p = PAD_ButtonsDown(0);
/* PAD pressed keys */
s16 pp = PAD_ButtonsDown(0);
/* PAD held keys (direction/selection) */
s16 hp = PAD_ButtonsHeld(0) & (PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_LEFT|PAD_BUTTON_RIGHT|PAD_BUTTON_A);
/* PAD analog sticks (handled as PAD held direction keys) */
s8 x = PAD_StickX(0); s8 x = PAD_StickX(0);
s8 y = PAD_StickY(0); s8 y = PAD_StickY(0);
if (x > 70) p |= PAD_BUTTON_RIGHT; if (x > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_RIGHT;
else if (x < -70) p |= PAD_BUTTON_LEFT; else if (x < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_LEFT;
if (y > 60) p |= PAD_BUTTON_UP; else if (y > ANALOG_SENSITIVITY) hp |= PAD_BUTTON_UP;
else if (y < -60) p |= PAD_BUTTON_DOWN; else if (y < -ANALOG_SENSITIVITY) hp |= PAD_BUTTON_DOWN;
#ifdef HW_RVL #ifdef HW_RVL
/* WPAD status */ /* WPAD status update */
WPAD_ScanPads(); WPAD_ScanPads();
WPADData *data = WPAD_Data(0); WPADData *data = WPAD_Data(0);
u32 q = data->btns_d;
u32 h = data->btns_h;
/* fast scrolling/selection */ /* WPAD pressed keys */
h &= (WPAD_BUTTON_UP|WPAD_BUTTON_DOWN|WPAD_BUTTON_LEFT|WPAD_BUTTON_RIGHT|WPAD_BUTTON_A); u32 pw = data->btns_d;
/* wait for the key to be held for a short period */ /* WPAD held keys (direction/selection) */
if (h) held_cnt++; 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; 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 */ /* key triggering */
held_cnt = 0; pp |= hp;
q |= h; #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); WPAD_IR(0, &m_input.ir);
if (m_input.ir.valid) if (m_input.ir.valid)
{ {
if (q & WPAD_BUTTON_UP) p |= PAD_BUTTON_UP; /* Wiimote is handled vertically */
else if (q & WPAD_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_UP;
else if (q & WPAD_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN;
else if (q & WPAD_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT;
else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT;
} }
else else
{ {
if (q & WPAD_BUTTON_UP) p |= PAD_BUTTON_LEFT; /* Wiimote is handled horizontally */
else if (q & WPAD_BUTTON_DOWN) p |= PAD_BUTTON_RIGHT; if (pw & WPAD_BUTTON_UP) pp |= PAD_BUTTON_LEFT;
else if (q & WPAD_BUTTON_LEFT) p |= PAD_BUTTON_DOWN; else if (pw & WPAD_BUTTON_DOWN) pp |= PAD_BUTTON_RIGHT;
else if (q & WPAD_BUTTON_RIGHT) p |= PAD_BUTTON_UP; else if (pw & WPAD_BUTTON_LEFT) pp |= PAD_BUTTON_DOWN;
else if (pw & WPAD_BUTTON_RIGHT) pp |= PAD_BUTTON_UP;
} }
/* Analog sticks */ /* Classic Controller direction keys */
x = WPAD_StickX(data, 0); if (pw & WPAD_CLASSIC_BUTTON_UP) pp |= PAD_BUTTON_UP;
y = WPAD_StickY(data, 0); else if (pw & WPAD_CLASSIC_BUTTON_DOWN) pp |= PAD_BUTTON_DOWN;
if (y > 70) p |= PAD_BUTTON_UP; else if (pw & WPAD_CLASSIC_BUTTON_LEFT) pp |= PAD_BUTTON_LEFT;
else if (y < -70) p |= PAD_BUTTON_DOWN; else if (pw & WPAD_CLASSIC_BUTTON_RIGHT) pp |= PAD_BUTTON_RIGHT;
if (x < -60) p |= PAD_BUTTON_LEFT;
else if (x > 60) p |= PAD_BUTTON_RIGHT;
/* Classic controller */ /* WPAD buttons */
if (q & WPAD_CLASSIC_BUTTON_UP) p |= PAD_BUTTON_UP; if (pw & WPAD_BUTTON_MINUS) pp |= PAD_TRIGGER_L;
else if (q & WPAD_CLASSIC_BUTTON_DOWN) p |= PAD_BUTTON_DOWN; if (pw & WPAD_BUTTON_PLUS) pp |= PAD_TRIGGER_R;
if (q & WPAD_CLASSIC_BUTTON_LEFT) p |= PAD_BUTTON_LEFT; if (pw & WPAD_BUTTON_A) pp |= PAD_BUTTON_A;
else if (q & WPAD_CLASSIC_BUTTON_RIGHT) p |= PAD_BUTTON_RIGHT; if (pw & WPAD_BUTTON_B) pp |= PAD_BUTTON_B;
if (pw & WPAD_BUTTON_2) pp |= PAD_BUTTON_A;
/* Supported keys */ if (pw & WPAD_BUTTON_1) pp |= PAD_BUTTON_B;
if (q & WPAD_BUTTON_MINUS) p |= PAD_TRIGGER_L; if (pw & WPAD_BUTTON_HOME) pp |= PAD_TRIGGER_Z;
if (q & WPAD_BUTTON_PLUS) p |= PAD_TRIGGER_R; if (pw & WPAD_CLASSIC_BUTTON_FULL_L) pp |= PAD_TRIGGER_L;
if (q & WPAD_BUTTON_A) p |= PAD_BUTTON_A; if (pw & WPAD_CLASSIC_BUTTON_FULL_R) pp |= PAD_TRIGGER_R;
if (q & WPAD_BUTTON_B) p |= PAD_BUTTON_B; if (pw & WPAD_CLASSIC_BUTTON_A) pp |= PAD_BUTTON_A;
if (q & WPAD_BUTTON_2) p |= PAD_BUTTON_A; if (pw & WPAD_CLASSIC_BUTTON_B) pp |= PAD_BUTTON_B;
if (q & WPAD_BUTTON_1) p |= PAD_BUTTON_B; if (pw & WPAD_CLASSIC_BUTTON_HOME) pp |= PAD_TRIGGER_Z;
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;
#endif #endif
/* Update menu inputs */ /* Update menu inputs */
m_input.keys = p; m_input.keys = pp;
} }

View File

@ -35,7 +35,7 @@
#define MAX_KEYS 8 #define MAX_KEYS 8
/* Genesis Plus wrapper */ /* Genesis Plus wrapper */
#define update_input() gx_input_updateEmu() #define update_input() gx_input_UpdateEmu()
/* Key configuration structure */ /* Key configuration structure */
typedef struct typedef struct
@ -45,11 +45,11 @@ typedef struct
} t_input_config; } t_input_config;
extern void gx_input_init(void); extern void gx_input_Init(void);
extern void gx_input_setDefault(void); extern void gx_input_SetDefault(void);
extern void gx_input_config(u8 num, u8 type, u8 max_keys); extern void gx_input_Config(u8 num, u8 type, u8 max_keys);
extern void gx_input_updateEmu(void); extern void gx_input_UpdateEmu(void);
extern void gx_input_updateMenu(u32 cnt); extern void gx_input_UpdateMenu(u32 cnt);
extern u8 ConfigRequested; extern u8 ConfigRequested;

View File

@ -944,7 +944,7 @@ void gxClearScreen (GXColor color)
} }
/* Restore Menu Video mode */ /* Restore Menu Video mode */
void gx_video_stop(void) void gx_video_Stop(void)
{ {
/* lightgun textures */ /* lightgun textures */
if (crosshair[0]) if (crosshair[0])
@ -968,12 +968,12 @@ void gx_video_stop(void)
gxDrawScreenshot(0xff); gxDrawScreenshot(0xff);
VIDEO_Configure(vmode); VIDEO_Configure(vmode);
VIDEO_SetPreRetraceCallback(NULL); VIDEO_SetPreRetraceCallback(NULL);
VIDEO_SetPostRetraceCallback(gx_input_updateMenu); VIDEO_SetPostRetraceCallback(gx_input_UpdateMenu);
gxSetScreen (); gxSetScreen ();
} }
/* Update Video settings */ /* Update Video settings */
void gx_video_start(void) void gx_video_Start(void)
{ {
/* 50Hz/60Hz mode */ /* 50Hz/60Hz mode */
if ((config.tv_mode == 1) || ((config.tv_mode == 2) && vdp_pal)) gc_pal = 1; 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 */ /* GX render update */
void gx_video_update(void) void gx_video_Update(void)
{ {
/* check if display has changed */ /* check if display has changed */
if (bitmap.viewport.changed) if (bitmap.viewport.changed)
@ -1129,7 +1129,7 @@ void gx_video_update(void)
} }
/* Initialize VIDEO subsystem */ /* Initialize VIDEO subsystem */
void gx_video_init(void) void gx_video_Init(void)
{ {
/* /*
* Before doing anything else under libogc, * Before doing anything else under libogc,
@ -1233,6 +1233,17 @@ void gx_video_init(void)
gxResetRendering(1); gxResetRendering(1);
gxResetView(vmode); 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 */ /* Initialize texture data */
texturemem = memalign(32, TEX_SIZE); texturemem = memalign(32, TEX_SIZE);
if (!texturemem) if (!texturemem)
@ -1240,8 +1251,6 @@ void gx_video_init(void)
WaitPrompt("Failed to allocate texture buffer... Rebooting"); WaitPrompt("Failed to allocate texture buffer... Rebooting");
#ifdef HW_RVL #ifdef HW_RVL
DI_Close(); DI_Close();
#endif
#ifdef HW_RVL
SYS_ResetSystem(SYS_RESTART,0,0); SYS_ResetSystem(SYS_RESTART,0,0);
#else #else
SYS_ResetSystem(SYS_HOTRESET,0,0); SYS_ResetSystem(SYS_HOTRESET,0,0);
@ -1249,3 +1258,12 @@ void gx_video_init(void)
} }
memset (texturemem, 0, TEX_SIZE); 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();
}

View File

@ -46,10 +46,11 @@ extern u8 *texturemem;
extern u8 gc_pal; extern u8 gc_pal;
/* GX video emulation functions */ /* GX video emulation functions */
extern void gx_video_init(void); extern void gx_video_Init(void);
extern void gx_video_start(void); extern void gx_video_Shutdown(void);
extern void gx_video_stop(void); extern void gx_video_Start(void);
extern void gx_video_update(void); extern void gx_video_Stop(void);
extern void gx_video_Update(void);
/* GX draw functions */ /* GX draw functions */
extern gx_texture *gxTextureOpenPNG(const u8 *buffer); extern gx_texture *gxTextureOpenPNG(const u8 *buffer);

View File

@ -36,6 +36,7 @@
#endif #endif
#ifdef HW_RVL #ifdef HW_RVL
/* Power Button callback */ /* Power Button callback */
u8 Shutdown = 0; u8 Shutdown = 0;
static void Power_Off(void) static void Power_Off(void)
@ -43,10 +44,8 @@ static void Power_Off(void)
Shutdown = 1; Shutdown = 1;
ConfigRequested = 1; ConfigRequested = 1;
} }
#endif
u8 *Bg_music_ogg = NULL; #endif
u32 Bg_music_ogg_size = 0;;
/*************************************************************************** /***************************************************************************
* Genesis Plus Virtual Machine * Genesis Plus Virtual Machine
@ -86,12 +85,10 @@ static void init_machine(void)
if (!cart_rom) if (!cart_rom)
{ {
WaitPrompt("Failed to allocate ROM buffer... Rebooting"); WaitPrompt("Failed to allocate ROM buffer... Rebooting");
free(texturemem); gx_audio_Shutdown();
FONT_Shutdown(); gx_video_Shutdown();
#ifdef HW_RVL #ifdef HW_RVL
DI_Close(); DI_Close();
#endif
#ifdef HW_RVL
SYS_ResetSystem(SYS_RESTART,0,0); SYS_ResetSystem(SYS_RESTART,0,0);
#else #else
SYS_ResetSystem(SYS_HOTRESET,0,0); SYS_ResetSystem(SYS_HOTRESET,0,0);
@ -142,12 +139,8 @@ void shutdown(void)
system_shutdown(); system_shutdown();
audio_shutdown(); audio_shutdown();
free(cart_rom); free(cart_rom);
free(texturemem); gx_audio_Shutdown();
if (Bg_music_ogg) free(Bg_music_ogg); gx_video_Shutdown();
FONT_Shutdown();
VIDEO_ClearFrameBuffer(vmode, xfb[whichfb], COLOR_BLACK);
VIDEO_Flush();
VIDEO_WaitVSync();
#ifdef HW_RVL #ifdef HW_RVL
DI_Close(); DI_Close();
#endif #endif
@ -172,38 +165,16 @@ int main (int argc, char *argv[])
uint32 TotalFrames = 0; uint32 TotalFrames = 0;
uint32 FramesPerSecond = 0; uint32 FramesPerSecond = 0;
/* initialize harwdare */ /* initialize hardware */
gx_video_init(); gx_video_Init();
gx_input_init(); gx_input_Init();
gx_audio_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
}
#ifdef HW_DOL #ifdef HW_DOL
/* initialize GC DVD interface */
DVD_Init (); DVD_Init ();
dvd_drive_detect(); dvd_drive_detect();
#endif #endif
#ifdef HW_RVL /* initialize FAT devices */
/* Power button callback */
SYS_SetPowerCallback(Power_Off);
#endif
/* initialize FAT Interface */
if (fatInitDefault()) if (fatInitDefault())
{ {
fat_enabled = 1; fat_enabled = 1;
@ -216,27 +187,15 @@ int main (int argc, char *argv[])
#endif #endif
} }
/* background music */ /* Initialize sound engine */
char fname[MAXPATHLEN]; gx_audio_Init();
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);
}
/* default config */ /* default config */
legal(); legal();
config_setDefault(); config_setDefault();
config_load(); config_load();
/* restore recent files list */ /* recent ROM files list */
history_setDefault(); history_setDefault();
history_load(); history_load();
@ -248,8 +207,8 @@ int main (int argc, char *argv[])
{ {
ARAMFetch((char *)cart_rom, (void *)0x8000, genromsize); ARAMFetch((char *)cart_rom, (void *)0x8000, genromsize);
reloadrom (genromsize,"INJECT.bin"); reloadrom (genromsize,"INJECT.bin");
gx_video_start(); gx_video_Start();
gx_audio_start(); gx_audio_Start();
frameticker = 1; frameticker = 1;
} }
else else
@ -258,6 +217,11 @@ int main (int argc, char *argv[])
ConfigRequested = 1; ConfigRequested = 1;
} }
#ifdef HW_RVL
/* Power button callback */
SYS_SetPowerCallback(Power_Off);
#endif
/* main emulation loop */ /* main emulation loop */
while (1) while (1)
{ {
@ -265,8 +229,8 @@ int main (int argc, char *argv[])
if (ConfigRequested) if (ConfigRequested)
{ {
/* stop audio & video */ /* stop audio & video */
gx_video_stop(); gx_video_Stop();
gx_audio_stop(); gx_audio_Stop();
/* go to menu */ /* go to menu */
MainMenu (); MainMenu ();
@ -278,8 +242,8 @@ int main (int argc, char *argv[])
FramesPerSecond = vdp_rate; FramesPerSecond = vdp_rate;
/* start audio & video */ /* start audio & video */
gx_video_start(); gx_video_Start();
gx_audio_start(); gx_audio_Start();
/* reset framesync */ /* reset framesync */
frameticker = 1; frameticker = 1;
@ -292,7 +256,7 @@ int main (int argc, char *argv[])
system_frame (1); system_frame (1);
/* update audio only */ /* update audio only */
gx_audio_update(); gx_audio_Update();
} }
else else
{ {
@ -304,8 +268,8 @@ int main (int argc, char *argv[])
system_frame (0); system_frame (0);
/* update video & audio */ /* update video & audio */
gx_video_update(); gx_video_Update();
gx_audio_update(); gx_audio_Update();
RenderedFrames++; RenderedFrames++;
} }