fixed automatic SRAM not being reloaded after Hard Reset

code cleanup & update for use with last libogc (check download section for updated libs)
This commit is contained in:
ekeeke31 2009-09-27 18:08:33 +00:00
parent bc8168948f
commit cccd71e612
6 changed files with 355 additions and 160 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* menu.c
* gui.c
*
* GUI Engine, using GX hardware
* generic GUI Engine, using GX hardware
*
* Eke-Eke (2009)
*
@ -452,6 +452,77 @@ void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out)
}
}
/* Basic menu title slide effect */
void GUI_SlideMenuTitle(gui_menu *m, int title_offset)
{
#ifdef HW_RVL
gui_butn *button;
int i,x,y;
#endif
char title[64];
strcpy(title,m->title);
while (title_offset > 0)
{
/* update title */
strcpy(m->title,title+title_offset);
m->title[strlen(title)-title_offset-1] = 0;
/* draw menu */
GUI_DrawMenu(m);
#ifdef HW_RVL
if (m_input.ir.valid)
{
/* get cursor position */
x = m_input.ir.x;
y = m_input.ir.y;
/* draw wiimote pointer */
gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);
/* check for valid buttons */
m->selected = m->max_buttons + 2;
for (i=0; i<m->max_buttons; i++)
{
button = &m->buttons[i];
if ((button->state & BUTTON_ACTIVE)&&(x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
{
m->selected = i;
break;
}
}
for (i=0; i<2; i++)
{
button = m->arrows[i];
if (button)
{
if (button->state & BUTTON_VISIBLE)
{
if ((x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
{
m->selected = m->max_buttons + i;
break;
}
}
}
}
}
else
{
/* reinitialize selection */
if (m->selected >= m->max_buttons) m->selected = 0;
}
#endif
gxSetScreen();
usleep(6000);
title_offset--;
}
strcpy(m->title,title);
}
/* Update current menu */
int GUI_UpdateMenu(gui_menu *menu)
{
@ -668,9 +739,238 @@ int GUI_RunMenu(gui_menu *menu)
else return -1;
}
/* Window Prompt */
/* window slides in & out then display user choices */
int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items)
#if 0
/* Scrollable Text Window (with configurable text size) */
void GUI_TextWindow(gui_menu *parent, char *title, char *items[], u8 nb_items, u8 fheight)
{
int i, ret, quit = 0;
s32 selected = 0;
s32 old;
s16 p;
#ifdef HW_RVL
int x,y;
#endif
/* initialize arrows */
butn_data arrow[2];
arrow[0].texture[0] = gxTextureOpenPNG(Button_up_png,0);
arrow[0].texture[1] = gxTextureOpenPNG(Button_up_over_png,0);
arrow[1].texture[0] = gxTextureOpenPNG(Button_down_png,0);
arrow[1].texture[1] = gxTextureOpenPNG(Button_down_over_png,0);
/* initialize window */
gx_texture *window = gxTextureOpenPNG(Frame_s1_png,0);
gx_texture *top = gxTextureOpenPNG(Frame_s1_title_png,0);
/* initialize text position */
int offset = 0;
int pagesize = ( window->height - 2*top->height) / fheight;
/* set initial positions */
int xwindow = (640 - window->width)/2;
int ywindow = (480 - window->height)/2;
int ypos = ywindow + top->height + fheight;
int ypos2 = ywindow + window->height - arrow[1].texture[0]->height;
/* set initial vertical offset */
int yoffset = ywindow + window->height;
/* disable helper comment */
if (parent->helpers[1]) parent->helpers[1]->data = 0;
/* slide in */
while (yoffset > 0)
{
/* draw parent menu */
GUI_DrawMenu(parent);
/* draw window */
gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230);
gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255);
/* draw title */
FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE);
/* draw text */
for (i=0; i<max; i++)
{
FONT_writeCenter(items[i],fheight,xwindow,xwindow+window->width,ypos+i*fheight- yoffset,(GXColor)WHITE);
}
/* update display */
gxSetScreen();
/* slide speed */
yoffset -= 60;
}
/* draw menu */
while (quit == 0)
{
/* draw parent menu (should have been initialized first) */
GUI_DrawMenu(parent);
/* draw window */
gxDrawTexture(window,xwindow,ywindow,window->width,window->height,230);
/* draw text */
for (i=0; i<max; i++)
{
FONT_writeCenter(items[offset + i],fheight,xwindow,xwindow+window->width,ypos+i*fheight,(GXColor)WHITE);
}
/* down arrow */
if ((max + offset) < nb_items)
{
if (selected == 1)
gxDrawTexture(arrow[1].texture[1],xwindow,ypos2,arrow[1].texture[1]->width,arrow[1].texture[1]->height,255);
else
gxDrawTexture(arrow[1].texture[0],xwindow,ypos2,arrow[1].texture[0]->width,arrow[1].texture[0]->height,255);
}
/* up arrow */
if (offset > 0)
{
if (selected == 0)
gxDrawTexture(arrow[1].texture[1],xwindow,ywindow,arrow[1].texture[1]->width,arrow[1].texture[1]->height,255);
else
gxDrawTexture(arrow[1].texture[0],xwindow,ywindow,arrow[1].texture[1]->width,arrow[1].texture[1]->height,255);
}
else
{
gxDrawTexture(top,xwindow,ywindow,top->width,top->height,255);
FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20,(GXColor)WHITE);
}
p = m_input.keys;
#ifdef HW_RVL
if (Shutdown)
{
gxTextureClose(&window);
gxTextureClose(&top);
gxTextureClose(&arrow[0].texture[0]);
gxTextureClose(&arrow[0].texture[1]);
gxTextureClose(&arrow[1].texture[0]);
gxTextureClose(&arrow[1].texture[1]);
gxTextureClose(&w_pointer);
GUI_DeleteMenu(parent);
GUI_FadeOut();
shutdown();
SYS_ResetSystem(SYS_POWEROFF, 0, 0);
}
else if (m_input.ir.valid)
{
/* get cursor position */
x = m_input.ir.x;
y = m_input.ir.y;
/* draw wiimote pointer */
gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);
/* check for valid buttons */
selected = -1;
if ((x>=xwindow)&&(x<=(xwindow+window->width))&&(y>=ypos+i*(20 + h))&&(y<=(ypos+i*(20+h)+h)))
{
selected = i;
break;
}
}
}
else
{
/* reinitialize selection */
if (selected == -1) selected = 0;
}
#endif
/* update screen */
gxSetScreen();
/* update selection */
if (p&PAD_BUTTON_UP)
{
if (selected > 0) selected --;
}
else if (p&PAD_BUTTON_DOWN)
{
if (selected < (nb_items -1)) selected ++;
}
/* sound fx */
if (selected != old)
{
if (selected >= 0)
{
ASND_SetVoice(ASND_GetFirstUnusedVoice(),VOICE_MONO_16BIT,22050,0,(u8 *)button_over_pcm,button_over_pcm_size,
((int)config.sfx_volume * 255) / 100,((int)config.sfx_volume * 255) / 100,NULL);
}
}
if (p & PAD_BUTTON_A)
{
if (selected >= 0)
{
quit = 1;
ret = selected;
}
}
else if (p & PAD_BUTTON_B)
{
quit = 1;
ret = -1;
}
}
/* reset initial vertical offset */
yoffset = 0;
/* slide out */
while (yoffset < (ywindow + window->height))
{
/* draw parent menu */
GUI_DrawMenu(parent);
/* draw window + header */
gxDrawTexture(window,xwindow,ywindow-yoffset,window->width,window->height,230);
gxDrawTexture(top,xwindow,ywindow-yoffset,top->width,top->height,255);
/* draw title */
FONT_writeCenter(title,20,xwindow,xwindow+window->width,ywindow+(top->height-20)/2+20-yoffset,(GXColor)WHITE);
/* draw buttons + text */
for (i=0; i<nb_items; i++)
{
gxDrawTexture(button.texture[0],xpos,ypos+i*(20+h)-yoffset,w,h,255);
FONT_writeCenter(items[i],18,xpos,xpos+w,ypos+i*(20+h)+(h+18)/2-yoffset,(GXColor)WHITE);
}
yoffset += 60;
gxSetScreen();
}
/* restore helper comment */
if (parent->helpers[1]) parent->helpers[1]->data = Key_A_png;
/* final position */
GUI_DrawMenu(parent);
gxSetScreen();
/* close textures */
gxTextureClose(&window);
gxTextureClose(&top);
gxTextureClose(&button.texture[0]);
gxTextureClose(&button.texture[1]);
return ret;
}
#endif
/* Option Window (returns selected item) */
int GUI_OptionWindow(gui_menu *parent, char *title, char *items[], u8 nb_items)
{
int i, ret, quit = 0;
s32 selected = 0;
@ -884,7 +1184,7 @@ int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items)
return ret;
}
/* display Option Box */
/* Option Box */
void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *option, float step, float min, float max, u8 type)
{
gx_texture *l_arrow[2];
@ -1123,77 +1423,6 @@ void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *optio
gxTextureClose(&top);
}
/* Basic menu title slide effect */
void GUI_SlideMenuTitle(gui_menu *m, int title_offset)
{
#ifdef HW_RVL
gui_butn *button;
int i,x,y;
#endif
char title[64];
strcpy(title,m->title);
while (title_offset > 0)
{
/* update title */
strcpy(m->title,title+title_offset);
m->title[strlen(title)-title_offset-1] = 0;
/* draw menu */
GUI_DrawMenu(m);
#ifdef HW_RVL
if (m_input.ir.valid)
{
/* get cursor position */
x = m_input.ir.x;
y = m_input.ir.y;
/* draw wiimote pointer */
gxDrawTextureRotate(w_pointer, x-w_pointer->width/2, y-w_pointer->height/2, w_pointer->width, w_pointer->height,m_input.ir.angle,255);
/* check for valid buttons */
m->selected = m->max_buttons + 2;
for (i=0; i<m->max_buttons; i++)
{
button = &m->buttons[i];
if ((button->state & BUTTON_ACTIVE)&&(x>=button->x)&&(x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
{
m->selected = i;
break;
}
}
for (i=0; i<2; i++)
{
button = m->arrows[i];
if (button)
{
if (button->state & BUTTON_VISIBLE)
{
if ((x<=(button->x+button->w))&&(y>=button->y)&&(y<=(button->y+button->h)))
{
m->selected = m->max_buttons + i;
break;
}
}
}
}
}
else
{
/* reinitialize selection */
if (m->selected >= m->max_buttons) m->selected = 0;
}
#endif
gxSetScreen();
usleep(6000);
title_offset--;
}
strcpy(m->title,title);
}
/* Interactive Message Box */
/* Message Box displays a message until a specific action is completed */

View File

@ -1,7 +1,7 @@
/****************************************************************************
* gui.c
*
* GUI engine, using GX hardware
* generic GUI engine, using GX hardware
*
* Eke-Eke (2009)
*
@ -281,11 +281,11 @@ extern void GUI_InitMenu(gui_menu *menu);
extern void GUI_DeleteMenu(gui_menu *menu);
extern void GUI_DrawMenu(gui_menu *menu);
extern void GUI_DrawMenuFX(gui_menu *menu, u8 speed, u8 out);
extern void GUI_SlideMenuTitle(gui_menu *m, int title_offset);
extern int GUI_UpdateMenu(gui_menu *menu);
extern int GUI_RunMenu(gui_menu *menu);
extern int GUI_WindowPrompt(gui_menu *parent, char *title, char *items[], u8 nb_items);
extern int GUI_OptionWindow(gui_menu *parent, char *title, char *items[], u8 nb_items);
extern void GUI_OptionBox(gui_menu *parent, optioncallback cb, char *title, void *option, float step, float min, float max, u8 type);
extern void GUI_SlideMenuTitle(gui_menu *m, int title_offset);
extern void GUI_MsgBoxOpen(char *title, char *msg, bool throbber);
extern void GUI_MsgBoxUpdate(char *title, char *msg);
extern void GUI_MsgBoxClose(void);

View File

@ -2166,9 +2166,9 @@ void MainMenu (void)
quit = 1;
break;
case 0: /*** Quit Emulator ***/
case 0: /*** Exit Menu ***/
{
switch (GUI_WindowPrompt(m, VERSION, items,3))
switch (GUI_OptionWindow(m, VERSION, items,3))
{
case 1:
#ifdef HW_RVL
@ -2213,7 +2213,7 @@ void MainMenu (void)
GUI_InitMenu(m);
break;
case 3: /*** Memory Manager ***/
case 3: /*** Memory Manager (TODO !!!) ***/
if (!cart.romsize) break;
GUI_DeleteMenu(m);
quit = filemenu();
@ -2229,19 +2229,22 @@ void MainMenu (void)
gxSetScreen();
system_init();
system_reset();
memfile_autoload(config.sram_auto,-1);
quit = 1;
break;
case 5: /*** Game Genie ***/
case 5: /*** Game Genie (TODO !!!) ***/
if (!cart.romsize) break;
GUI_DeleteMenu(m);
GetGGEntries();
GUI_InitMenu(m);
break;
case 7: /*** ROM Captrure ***/
case 7: /*** Game Screenshot ***/
if (!cart.romsize) break;
gx_video_Capture();
char filename[MAXPATHLEN];
sprintf(filename,"%s/snaps/%s.png", DEFAULT_PATH, rom_filename);
gxSaveScreenshot(filename);
break;
case 8: /*** ROM Information ***/

View File

@ -307,9 +307,9 @@ static GXRModeObj *tvmodes[6] =
typedef struct tagcamera
{
Vector pos;
Vector up;
Vector view;
guVector pos;
guVector up;
guVector view;
} camera;
/*** Square Matrix
@ -686,7 +686,7 @@ void gxDrawTextureRotate(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, f32 an
/* Modelview rotation */
Mtx m,mv;
Vector axis = (Vector) {0,0,1};
guVector axis = (guVector) {0,0,1};
guLookAt(mv, &cam.pos, &cam.up, &cam.view);
guMtxRotAxisDeg (m, &axis, angle);
guMtxTransApply(m,m, x+w/2,y+h/2,0);
@ -850,6 +850,23 @@ void gxCopyScreenshot(gx_texture *texture)
DCFlushRange(texture->data, texture->width * texture->height * 4);
}
/* Take Screenshot */
void gxSaveScreenshot(char *filename)
{
/* capture screenshot into a texture */
gx_texture texture;
gxCopyScreenshot(&texture);
/* open PNG file */
FILE *f = fopen(filename,"wb");
if (f)
{
/* encode screenshot into PNG file */
gxTextureWritePNG(&texture,f);
fclose(f);
}
}
void gxSetScreen(void)
{
GX_CopyDisp(xfb[whichfb], GX_FALSE);
@ -1222,25 +1239,6 @@ void gxTextureClose(gx_texture **p_texture)
/* VIDEO engine */
/***************************************************************************************/
/* Take Screenshot */
void gx_video_Capture(void)
{
/* capture screenshot into a texture */
gx_texture texture;
gxCopyScreenshot(&texture);
/* open PNG file */
char fname[MAXPATHLEN];
sprintf(fname,"%s/snaps/%s.png", DEFAULT_PATH, rom_filename);
FILE *f = fopen(fname,"wb");
if (f)
{
/* encode screenshot into PNG file */
gxTextureWritePNG(&texture,f);
fclose(f);
}
}
/* Emulation mode -> Menu mode */
void gx_video_Stop(void)
{
@ -1384,6 +1382,10 @@ void gx_video_Update(void)
/* reset GX */
gxResetView(rmode);
/* change VI mode */
VIDEO_Configure(rmode);
VIDEO_Flush();
}
/* texture is now directly mapped by the line renderer */
@ -1403,34 +1405,20 @@ void gx_video_Update(void)
/* swap XFB */
whichfb ^= 1;
/* reconfigure VI */
/* copy EFB to XFB */
GX_CopyDisp(xfb[whichfb], GX_TRUE);
GX_Flush();
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
if (update)
{
bitmap.viewport.changed = 0;
/* change VI mode */
VIDEO_Configure(rmode);
VIDEO_Flush();
/* copy EFB to XFB */
GX_CopyDisp(xfb[whichfb], GX_TRUE);
GX_Flush();
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
/* field synchronizations */
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
else while (VIDEO_GetNextField() != odd_frame) VIDEO_WaitVSync();
if (frameticker > 1) frameticker = 1;
}
else
{
/* copy EFB to XFB */
GX_CopyDisp(xfb[whichfb], GX_TRUE);
GX_Flush();
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
bitmap.viewport.changed = 0;
}
}

View File

@ -54,6 +54,7 @@ extern void gxDrawTextureRepeat(gx_texture *texture, s32 x, s32 y, s32 w, s32 h,
extern void gxDrawTextureRotate(gx_texture *texture, s32 x, s32 y, s32 w, s32 h, f32 angle, u8 alpha);
extern void gxDrawScreenshot(u8 alpha);
extern void gxCopyScreenshot(gx_texture *texture);
extern void gxSaveScreenshot(char *filename);
extern void gxClearScreen(GXColor color);
extern void gxSetScreen(void);
@ -68,6 +69,5 @@ extern void gx_video_Shutdown(void);
extern void gx_video_Start(void);
extern void gx_video_Stop(void);
extern void gx_video_Update(void);
extern void gx_video_Capture(void);
#endif

View File

@ -35,39 +35,14 @@
#define FALSE 0
#endif
typedef unsigned char UINT8;
typedef unsigned short UINT16;
//#ifdef DOS
typedef unsigned char UINT8;
typedef unsigned short UINT16;
typedef unsigned int UINT32;
__extension__ typedef unsigned long long UINT64;
//#endif
typedef signed char INT8;
typedef signed short INT16;
//#ifdef DOS
typedef signed char INT8;
typedef signed short INT16;
typedef signed int INT32;
__extension__ typedef signed long long INT64;
//#endif
/* Combine two 32-bit integers into a 64-bit integer */
#define COMBINE_64_32_32(A,B) ((((UINT64)(A))<<32) | (UINT32)(B))
#define COMBINE_U64_U32_U32(A,B) COMBINE_64_32_32(A,B)
/* Return upper 32 bits of a 64-bit integer */
#define HI32_32_64(A) (((UINT64)(A)) >> 32)
#define HI32_U32_U64(A) HI32_32_64(A)
/* Return lower 32 bits of a 64-bit integer */
#define LO32_32_64(A) ((A) & 0xffffffff)
#define LO32_U32_U64(A) LO32_32_64(A)
#define DIV_64_64_32(A,B) ((A)/(B))
#define DIV_U64_U64_U32(A,B) ((A)/(UINT32)(B))
#define MOD_32_64_32(A,B) ((A)%(B))
#define MOD_U32_U64_U32(A,B) ((A)%(UINT32)(B))
#define MUL_64_32_32(A,B) ((A)*(INT64)(B))
#define MUL_U64_U32_U32(A,B) ((A)*(UINT64)(UINT32)(B))
/******************************************************************************