code cleanup, moved some global/static variables to static/local

This commit is contained in:
ekeeke31 2009-01-14 16:32:35 +00:00
parent cba98b8cd6
commit 7bc7ae83dc
10 changed files with 291 additions and 332 deletions

View File

@ -57,7 +57,7 @@
#define PCDROM 4096 #define PCDROM 4096
#define PMOUSE 8192 #define PMOUSE 8192
int peripherals; uint16 peripherals;
uint16 realchecksum; uint16 realchecksum;
ROMINFO rominfo; ROMINFO rominfo;
@ -161,7 +161,7 @@ PERIPHERALINFO peripheralinfo[14] = {
* softdev - New Checksum Calculation * softdev - New Checksum Calculation
eke-eke: fixed eke-eke: fixed
*/ */
uint16 GetRealChecksum (uint8 *rom, int length) static uint16 GetRealChecksum (uint8 *rom, int length)
{ {
int i; int i;
uint16 checksum = 0; uint16 checksum = 0;
@ -174,56 +174,12 @@ uint16 GetRealChecksum (uint8 *rom, int length)
return checksum; return checksum;
} }
/****************************************************************************
* getcompany
*
* Try to determine which company made this rom
*
* Ok, for some reason there's no standard for this.
* It seems that there can be pretty much anything you like following the
* copyright (C) symbol!
****************************************************************************/
int getcompany ()
{
char *s;
int i;
char company[10];
for (i = 3; i < 8; i++) company[i - 3] = rominfo.copyright[i];
company[5] = 0;
/** OK, first look for a hyphen
* Capcom use T-12 for example
*/
s = strstr (company, "-");
if (s != NULL)
{
s++;
strcpy (company, s);
}
/** Strip any trailing spaces **/
for (i = strlen (company) - 1; i >= 0; i--)
if (company[i] == 32) company[i] = 0;
if (strlen (company) == 0) return MAXCOMPANY - 1;
for (i = 0; i < MAXCOMPANY - 1; i++)
{
if (!(strncmp (company, companyinfo[i].companyid, strlen (company)))) return i;
}
return MAXCOMPANY - 1;
}
/*************************************************************************** /***************************************************************************
* getrominfo * getrominfo
* *
* Pass a pointer to the ROM base address. * Pass a pointer to the ROM base address.
***************************************************************************/ ***************************************************************************/
void getrominfo (char *romheader) static void getrominfo (char *romheader)
{ {
int i,j; int i,j;
@ -289,72 +245,10 @@ void getrominfo (char *romheader)
} }
} }
/* 05/05/2006: new region detection routine (taken from GENS sourcecode) */
void set_region ()
{
/* country codes used to differentiate region */
/* 0001 = japan ntsc (1) */
/* 0010 = japan pal (2) */
/* 0100 = usa (4) */
/* 1000 = europe (8) */
int country = 0;
int i = 0;
char c;
/* reading header to find the country */
if (!strnicmp(rominfo.country, "eur", 3)) country |= 8;
else if (!strnicmp(rominfo.country, "usa", 3)) country |= 4;
else if (!strnicmp(rominfo.country, "jap", 3)) country |= 1;
else for(i = 0; i < 4; i++)
{
c = toupper((int)rominfo.country[i]);
if (c == 'U') country |= 4;
else if (c == 'J') country |= 1;
else if (c == 'E') country |= 8;
else if (c < 16) country |= c;
else if ((c >= '0') && (c <= '9')) country |= c - '0';
else if ((c >= 'A') && (c <= 'F')) country |= c - 'A' + 10;
}
/* automatic detection */
/* setting region */
/* this is used by IO register */
if (country & 4) region_code = REGION_USA;
else if (country & 1) region_code = REGION_JAPAN_NTSC;
else if (country & 8) region_code = REGION_EUROPE;
else if (country & 2) region_code = REGION_JAPAN_PAL;
else region_code = REGION_USA;
/* some games need specific REGION setting */
if (((strstr(rominfo.product,"T-45033") != NULL) && (rominfo.checksum == 0x0F81)) || /* Alisia Dragon (E) */
(strstr(rominfo.product,"T-69046-50") != NULL)) /* On Dal Jang Goon (Korea) */
{
/* need PAL settings */
region_code = REGION_EUROPE;
}
else if ((realchecksum == 0x532e) && (strstr(rominfo.product,"1011-00") != NULL))
{
/* On Dal Jang Goon (Korea) needs JAP region code */
region_code = REGION_JAPAN_NTSC;
}
/* Force region setting */
if (config.region_detect == 1) region_code = REGION_USA;
else if (config.region_detect == 2) region_code = REGION_EUROPE;
else if (config.region_detect == 3) region_code = REGION_JAPAN_NTSC;
else if (config.region_detect == 4) region_code = REGION_JAPAN_PAL;
/* set cpu/vdp speed: PAL or NTSC */
if ((region_code == REGION_EUROPE) || (region_code == REGION_JAPAN_PAL)) vdp_pal = 1;
else vdp_pal = 0;
}
/* SMD (interleaved) rom support */ /* SMD (interleaved) rom support */
static uint8 block[0x4000]; static uint8 block[0x4000];
void deinterleave_block (uint8 * src) static void deinterleave_block (uint8 * src)
{ {
int i; int i;
memcpy (block, src, 0x4000); memcpy (block, src, 0x4000);
@ -434,3 +328,107 @@ int load_rom(char *filename)
return(1); return(1);
} }
/* 05/05/2006: new region detection routine (taken from GENS sourcecode) */
void set_region ()
{
/* country codes used to differentiate region */
/* 0001 = japan ntsc (1) */
/* 0010 = japan pal (2) */
/* 0100 = usa (4) */
/* 1000 = europe (8) */
int country = 0;
int i = 0;
char c;
/* reading header to find the country */
if (!strnicmp(rominfo.country, "eur", 3)) country |= 8;
else if (!strnicmp(rominfo.country, "usa", 3)) country |= 4;
else if (!strnicmp(rominfo.country, "jap", 3)) country |= 1;
else for(i = 0; i < 4; i++)
{
c = toupper((int)rominfo.country[i]);
if (c == 'U') country |= 4;
else if (c == 'J') country |= 1;
else if (c == 'E') country |= 8;
else if (c < 16) country |= c;
else if ((c >= '0') && (c <= '9')) country |= c - '0';
else if ((c >= 'A') && (c <= 'F')) country |= c - 'A' + 10;
}
/* automatic detection */
/* setting region */
/* this is used by IO register */
if (country & 4) region_code = REGION_USA;
else if (country & 1) region_code = REGION_JAPAN_NTSC;
else if (country & 8) region_code = REGION_EUROPE;
else if (country & 2) region_code = REGION_JAPAN_PAL;
else region_code = REGION_USA;
/* some games need specific REGION setting */
if (((strstr(rominfo.product,"T-45033") != NULL) && (rominfo.checksum == 0x0F81)) || /* Alisia Dragon (E) */
(strstr(rominfo.product,"T-69046-50") != NULL)) /* On Dal Jang Goon (Korea) */
{
/* need PAL settings */
region_code = REGION_EUROPE;
}
else if ((realchecksum == 0x532e) && (strstr(rominfo.product,"1011-00") != NULL))
{
/* On Dal Jang Goon (Korea) needs JAP region code */
region_code = REGION_JAPAN_NTSC;
}
/* Force region setting */
if (config.region_detect == 1) region_code = REGION_USA;
else if (config.region_detect == 2) region_code = REGION_EUROPE;
else if (config.region_detect == 3) region_code = REGION_JAPAN_NTSC;
else if (config.region_detect == 4) region_code = REGION_JAPAN_PAL;
/* set cpu/vdp speed: PAL or NTSC */
if ((region_code == REGION_EUROPE) || (region_code == REGION_JAPAN_PAL)) vdp_pal = 1;
else vdp_pal = 0;
}
/****************************************************************************
* getcompany
*
* Try to determine which company made this rom
*
* Ok, for some reason there's no standard for this.
* It seems that there can be pretty much anything you like following the
* copyright (C) symbol!
****************************************************************************/
int getcompany ()
{
char *s;
int i;
char company[10];
for (i = 3; i < 8; i++) company[i - 3] = rominfo.copyright[i];
company[5] = 0;
/** OK, first look for a hyphen
* Capcom use T-12 for example
*/
s = strstr (company, "-");
if (s != NULL)
{
s++;
strcpy (company, s);
}
/** Strip any trailing spaces **/
for (i = strlen (company) - 1; i >= 0; i--)
if (company[i] == 32) company[i] = 0;
if (strlen (company) == 0) return MAXCOMPANY - 1;
for (i = 0; i < MAXCOMPANY - 1; i++)
{
if (!(strncmp (company, companyinfo[i].companyid, strlen (company)))) return i;
}
return MAXCOMPANY - 1;
}

View File

@ -62,9 +62,12 @@ extern ROMINFO rominfo;
extern COMPANYINFO companyinfo[MAXCOMPANY]; extern COMPANYINFO companyinfo[MAXCOMPANY];
extern PERIPHERALINFO peripheralinfo[14]; extern PERIPHERALINFO peripheralinfo[14];
extern uint16 realchecksum; extern uint16 realchecksum;
extern uint16 peripherals;
/* Function prototypes */ /* Function prototypes */
extern int load_rom(char *filename); extern int load_rom(char *filename);
extern int getcompany();
extern void set_region();
#endif /* _LOADROM_H_ */ #endif /* _LOADROM_H_ */

View File

@ -34,10 +34,10 @@
#include <fat.h> #include <fat.h>
int Shutdown = 0;
#ifdef HW_RVL #ifdef HW_RVL
/* Power Button callback */ /* Power Button callback */
u8 Shutdown = 0;
void Power_Off(void) void Power_Off(void)
{ {
Shutdown = 1; Shutdown = 1;
@ -119,8 +119,8 @@ void reloadrom ()
* M A I N * M A I N
* *
***************************************************************************/ ***************************************************************************/
int frameticker = 0; u8 fat_enabled = 0;
bool fat_enabled = 0; u32 frameticker = 0;
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
@ -130,9 +130,9 @@ int main (int argc, char *argv[])
DI_Init(); DI_Init();
#endif #endif
uint32 RenderedFrames; uint32 RenderedFrames = 0;
uint32 TotalFrames; uint32 TotalFrames = 0;
uint32 FramesPerSecond; uint32 FramesPerSecond = 0;
/* initialize OGC subsystems */ /* initialize OGC subsystems */
ogc_video__init(); ogc_video__init();
@ -151,7 +151,7 @@ int main (int argc, char *argv[])
#endif #endif
/* initialize FAT Interface */ /* initialize FAT Interface */
if (fatInitDefault() == true) if (fatInitDefault())
{ {
fat_enabled = 1; fat_enabled = 1;
#ifdef HW_RVL #ifdef HW_RVL
@ -163,16 +163,16 @@ int main (int argc, char *argv[])
#endif #endif
} }
/* default Config */ /* default config */
legal(); legal();
set_config_defaults(); set_config_defaults();
config_load(); config_load();
/* restore recent Files list */ /* restore recent files list */
set_history_defaults(); set_history_defaults();
history_load(); history_load();
/* Initialize Virtual Machine */ /* initialize Virtual Machine */
init_machine (); init_machine ();
/* load any injected rom */ /* load any injected rom */
@ -182,16 +182,16 @@ int main (int argc, char *argv[])
reloadrom (); reloadrom ();
} }
/* Show Menu first */ /* show menu first */
ConfigRequested = 1; ConfigRequested = 1;
/* Emulation Loop */ /* main emulation loop */
while (1) while (1)
{ {
/* Check for Menu request */ /* check for menu request */
if (ConfigRequested) if (ConfigRequested)
{ {
/* stop Audio & Video */ /* stop audio & video */
ogc_audio__stop(); ogc_audio__stop();
ogc_video__stop(); ogc_video__stop();
@ -201,18 +201,20 @@ int main (int argc, char *argv[])
/* reset framesync */ /* reset framesync */
frameticker = 0; frameticker = 0;
/* reset framecounts */
RenderedFrames = 0; RenderedFrames = 0;
TotalFrames = 0; TotalFrames = 0;
FramesPerSecond = vdp_rate; FramesPerSecond = vdp_rate;
/* start Audio & Video */ /* start audio & video */
ogc_audio__start(); ogc_audio__start();
ogc_video__start(); ogc_video__start();
} }
if (frameticker > 1) if (frameticker > 1)
{ {
/* frameskipping */ /* skip frame */
frameticker--; frameticker--;
system_frame (1); system_frame (1);
@ -222,9 +224,9 @@ int main (int argc, char *argv[])
else else
{ {
/* framesync */ /* framesync */
while (!frameticker) usleep(1); while (frameticker < 1) usleep(1);
/* frame rendering */ /* render frame */
system_frame (0); system_frame (0);
/* update video & audio */ /* update video & audio */
@ -233,8 +235,10 @@ int main (int argc, char *argv[])
RenderedFrames++; RenderedFrames++;
} }
/* update framesync */
frameticker--; frameticker--;
/* update framecounts */
TotalFrames++; TotalFrames++;
if (TotalFrames == vdp_rate) if (TotalFrames == vdp_rate)
{ {

View File

@ -33,14 +33,14 @@
u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32);
/* Current work soundbuffer */ /* Current work soundbuffer */
int mixbuffer; u8 mixbuffer;
/* Current DMA length (required to be a factor of 32-bytes) /* Current DMA length (required to be a factor of 32-bytes)
length is calculated regarding current emulation timings: length is calculated regarding current emulation timings:
PAL timings : 50 frames/sec, 48000 samples/sec = 960 samples per frame = 3840 bytes (16 bits stereo samples) PAL timings : 50 frames/sec, 48000 samples/sec = 960 samples per frame = 3840 bytes (16 bits stereo samples)
NTSC timings: 60 frames/sec, 48000 samples/sec = 800 samples per frame = 3200 bytes (16 bits stereo samples) NTSC timings: 60 frames/sec, 48000 samples/sec = 800 samples per frame = 3200 bytes (16 bits stereo samples)
*/ */
static int dma_len = 3200; static u32 dma_len = 3200;
/*** /***
AudioDmaCallback AudioDmaCallback

View File

@ -25,7 +25,7 @@
#define _GC_AUDIO_H_ #define _GC_AUDIO_H_
extern u8 soundbuffer[2][3840]; extern u8 soundbuffer[2][3840];
extern int mixbuffer; extern u8 mixbuffer;
extern void ogc_audio__init(void); extern void ogc_audio__init(void);
extern void ogc_audio__start(void); extern void ogc_audio__start(void);

View File

@ -39,7 +39,7 @@
#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
int ConfigRequested = 1; u8 ConfigRequested = 1;
static const char *keys_name[MAX_KEYS] = static const char *keys_name[MAX_KEYS] =
{ {
@ -744,6 +744,7 @@ u16 ogc_input__getMenuButtons(void)
{ {
#ifdef HW_RVL #ifdef HW_RVL
extern u8 Shutdown;
if (Shutdown) if (Shutdown)
{ {
/* autosave SRAM/State */ /* autosave SRAM/State */

View File

@ -35,14 +35,15 @@
/* number of configurable keys */ /* number of configurable keys */
#define MAX_KEYS 8 #define MAX_KEYS 8
#define update_input() ogc_input__update()
typedef struct typedef struct
{ {
s8 device; s8 device;
u8 port; u8 port;
} t_input_config; } t_input_config;
extern u8 ConfigRequested;
extern int ConfigRequested;
extern void ogc_input__init(void); extern void ogc_input__init(void);
extern void ogc_input__set_defaults(void); extern void ogc_input__set_defaults(void);

View File

@ -21,29 +21,12 @@
* *
***************************************************************************/ ***************************************************************************/
#include "shared.h" #include "shared.h"
#include "font.h" #include "font.h"
#include "gcaram.h" #include "gcaram.h"
#include "md_ntsc.h" #include "md_ntsc.h"
#include "sms_ntsc.h" #include "sms_ntsc.h"
/*** NTSC Filters ***/
md_ntsc_setup_t md_setup;
md_ntsc_t md_ntsc;
sms_ntsc_setup_t sms_setup;
sms_ntsc_t sms_ntsc;
/*** PAL 50hz flag ***/
int gc_pal = 0;
/*** VI ***/
unsigned int *xfb[2]; /*** Double buffered ***/
int whichfb = 0; /*** External framebuffer index ***/
GXRModeObj *vmode; /*** Menu video mode ***/
u8 *texturemem; /*** Texture Data ***/
/*** GX ***/
#define TEX_WIDTH 720 #define TEX_WIDTH 720
#define TEX_HEIGHT 576 #define TEX_HEIGHT 576
#define TEX_SIZE (TEX_WIDTH * TEX_HEIGHT * 2) #define TEX_SIZE (TEX_WIDTH * TEX_HEIGHT * 2)
@ -51,15 +34,26 @@ u8 *texturemem; /*** Texture Data ***/
#define HASPECT 320 #define HASPECT 320
#define VASPECT 240 #define VASPECT 240
/*** VI ***/
unsigned int *xfb[2]; /* External Framebuffers */
int whichfb = 0; /* Current Framebuffer */
GXRModeObj *vmode; /* Default Video Mode */
u8 *texturemem; /* Texture Data */
/*** NTSC Filters ***/
sms_ntsc_t sms_ntsc;
md_ntsc_t md_ntsc;
static sms_ntsc_setup_t sms_setup;
static md_ntsc_setup_t md_setup;
/*** GX FIFO ***/
static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32); static u8 gp_fifo[DEFAULT_FIFO_SIZE] ATTRIBUTE_ALIGN (32);
static GXTexObj texobj;
static Mtx view;
static u32 vwidth, vheight;
/*** custom Video modes ***/ /*** custom Video modes ***/
static GXRModeObj *rmode;
/* 288 lines progressive (PAL 50Hz) */ /* 288 lines progressive (PAL 50Hz) */
GXRModeObj TV50hz_288p = static GXRModeObj TV50hz_288p =
{ {
VI_TVMODE_PAL_DS, // viDisplayMode VI_TVMODE_PAL_DS, // viDisplayMode
640, // fbWidth 640, // fbWidth
@ -94,7 +88,7 @@ GXRModeObj TV50hz_288p =
}; };
/* 288 lines interlaced (PAL 50Hz) */ /* 288 lines interlaced (PAL 50Hz) */
GXRModeObj TV50hz_288i = static GXRModeObj TV50hz_288i =
{ {
VI_TVMODE_PAL_INT, // viDisplayMode VI_TVMODE_PAL_INT, // viDisplayMode
640, // fbWidth 640, // fbWidth
@ -129,7 +123,7 @@ GXRModeObj TV50hz_288i =
}; };
/* 576 lines interlaced (PAL 50Hz, scaled) */ /* 576 lines interlaced (PAL 50Hz, scaled) */
GXRModeObj TV50hz_576i = static GXRModeObj TV50hz_576i =
{ {
VI_TVMODE_PAL_INT, // viDisplayMode VI_TVMODE_PAL_INT, // viDisplayMode
640, // fbWidth 640, // fbWidth
@ -164,7 +158,7 @@ GXRModeObj TV50hz_576i =
}; };
/* 240 lines progressive (NTSC or PAL 60Hz) */ /* 240 lines progressive (NTSC or PAL 60Hz) */
GXRModeObj TV60hz_240p = static GXRModeObj TV60hz_240p =
{ {
VI_TVMODE_EURGB60_DS, // viDisplayMode VI_TVMODE_EURGB60_DS, // viDisplayMode
640, // fbWidth 640, // fbWidth
@ -199,7 +193,7 @@ GXRModeObj TV60hz_240p =
}; };
/* 240 lines interlaced (NTSC or PAL 60Hz) */ /* 240 lines interlaced (NTSC or PAL 60Hz) */
GXRModeObj TV60hz_240i = static GXRModeObj TV60hz_240i =
{ {
VI_TVMODE_EURGB60_INT, // viDisplayMode VI_TVMODE_EURGB60_INT, // viDisplayMode
640, // fbWidth 640, // fbWidth
@ -234,7 +228,7 @@ GXRModeObj TV60hz_240i =
}; };
/* 480 lines interlaced (NTSC or PAL 60Hz) */ /* 480 lines interlaced (NTSC or PAL 60Hz) */
GXRModeObj TV60hz_480i = static GXRModeObj TV60hz_480i =
{ {
VI_TVMODE_EURGB60_INT,// viDisplayMode VI_TVMODE_EURGB60_INT,// viDisplayMode
640, // fbWidth 640, // fbWidth
@ -268,12 +262,23 @@ GXRModeObj TV60hz_480i =
} }
}; };
/* TV Modes table */ /* TV modes pointer table */
GXRModeObj *tvmodes[6] = { static GXRModeObj *tvmodes[6] =
&TV60hz_240p, &TV60hz_240i, &TV60hz_480i, /* 60hz modes */ {
&TV50hz_288p, &TV50hz_288i, &TV50hz_576i /* 50Hz modes */ /* 60hz modes */
&TV60hz_240p,
&TV60hz_240i,
&TV60hz_480i,
/* 50Hz modes */
&TV50hz_288p,
&TV50hz_288i,
&TV50hz_576i
}; };
/* 50/60hz flag */
static u8 gc_pal = 0;
typedef struct tagcamera typedef struct tagcamera
{ {
Vector pos; Vector pos;
@ -303,13 +308,6 @@ static camera cam = {
{0.0F, 0.0F, 0.0F} {0.0F, 0.0F, 0.0F}
}; };
void xfb_swap(u32 cnt)
{
VIDEO_SetNextFramebuffer (xfb[whichfb]);
VIDEO_Flush ();
whichfb ^= 1;
}
/* Rendering Initialization */ /* Rendering Initialization */
static void draw_init(void) static void draw_init(void)
{ {
@ -330,6 +328,7 @@ static void draw_init(void)
GX_SetNumChans(0); GX_SetNumChans(0);
/* Set Modelview */ /* Set Modelview */
Mtx view;
memset (&view, 0, sizeof (Mtx)); memset (&view, 0, sizeof (Mtx));
guLookAt(view, &cam.pos, &cam.up, &cam.view); guLookAt(view, &cam.pos, &cam.up, &cam.view);
GX_LoadPosMtxImm(view, GX_PNMTX0); GX_LoadPosMtxImm(view, GX_PNMTX0);
@ -395,7 +394,7 @@ static void gxStart(void)
} }
/* Reset GX/VI scaler */ /* Reset GX/VI scaler */
static void gxScale(GXRModeObj *rmode) static void gxScale(u32 width, u32 height)
{ {
int temp = 0; int temp = 0;
int xscale, yscale, xshift, yshift; int xscale, yscale, xshift, yshift;
@ -460,7 +459,6 @@ static void gxScale(GXRModeObj *rmode)
{ {
/* filtering (soft or hard) is disabled, let VI handles horizontal scaling */ /* filtering (soft or hard) is disabled, let VI handles horizontal scaling */
/* if possible, let GX simply doubles the width, otherwise disable GX stretching completely */ /* if possible, let GX simply doubles the width, otherwise disable GX stretching completely */
int width = vwidth * 4;
if ((width * 2) <= 640) rmode->fbWidth = width * 2; if ((width * 2) <= 640) rmode->fbWidth = width * 2;
else if (width <= 640) rmode->fbWidth = width; else if (width <= 640) rmode->fbWidth = width;
} }
@ -495,65 +493,16 @@ static void gxScale(GXRModeObj *rmode)
square[0] = square[9] = -xscale + xshift; square[0] = square[9] = -xscale + xshift;
square[4] = square[1] = yscale + yshift; square[4] = square[1] = yscale + yshift;
square[7] = square[10] = -yscale + yshift; square[7] = square[10] = -yscale + yshift;
DCFlushRange(square, 32); DCFlushRange(square, 32);
GX_InvVtxCache(); GX_InvVtxCache();
} }
/* Reset Video Mode */ /* Restore Menu Video mode */
static void gxReset(void)
{
Mtx p;
GXRModeObj *rmode;
/* select TV mode */
if (config.render) rmode = tvmodes[gc_pal*3 + 2];
else rmode = tvmodes[gc_pal*3 + interlaced];
/* reset aspect ratio */
gxScale(rmode);
/* configure GX */
GX_SetViewport (0.0F, 0.0F, rmode->fbWidth, rmode->efbHeight, 0.0F, 1.0F);
GX_SetScissor (0, 0, rmode->fbWidth, rmode->efbHeight);
f32 yScale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
u16 xfbHeight = GX_SetDispCopyYScale (yScale);
GX_SetDispCopySrc (0, 0, rmode->fbWidth, rmode->efbHeight);
GX_SetDispCopyDst (rmode->fbWidth, xfbHeight);
GX_SetCopyFilter (rmode->aa, rmode->sample_pattern, config.render ? GX_TRUE : GX_FALSE, rmode->vfilter);
GX_SetFieldMode (rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
GX_SetPixelFmt (rmode->aa ? GX_PF_RGB565_Z16 : GX_PF_RGB8_Z24, GX_ZC_LINEAR);
guOrtho(p, rmode->efbHeight/2, -(rmode->efbHeight/2), -(rmode->fbWidth/2), rmode->fbWidth/2, 100, 1000);
GX_LoadProjectionMtx (p, GX_ORTHOGRAPHIC);
GX_Flush ();
/* configure VI */
VIDEO_Configure (rmode);
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
else while (VIDEO_GetNextField() != odd_frame) VIDEO_WaitVSync();
/* resynchronize interlaced field */
if (interlaced && !config.render)
{
whichfb = odd_frame;
VIDEO_SetPreRetraceCallback(xfb_swap);
VIDEO_Flush();
VIDEO_WaitVSync();
}
}
/* Set Menu Video mode */
void ogc_video__stop(void) void ogc_video__stop(void)
{ {
/* clear screen */
VIDEO_Configure(vmode); VIDEO_Configure(vmode);
VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[0], COLOR_BLACK);
VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK); VIDEO_ClearFrameBuffer(vmode, xfb[1], COLOR_BLACK);
/* disable VSYNC handler */
VIDEO_SetPreRetraceCallback(NULL);
VIDEO_Flush(); VIDEO_Flush();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
VIDEO_WaitVSync(); VIDEO_WaitVSync();
@ -614,37 +563,66 @@ void ogc_video__start()
/* GX render update */ /* GX render update */
void ogc_video__update() void ogc_video__update()
{ {
/* check if viewport has changed */ /* check if display has changed */
if (bitmap.viewport.changed) if (bitmap.viewport.changed)
{ {
bitmap.viewport.changed = 0; bitmap.viewport.changed = 0;
/* update texture size */ /* update texture size */
vwidth = bitmap.viewport.w + 2 * bitmap.viewport.x; u32 vwidth = bitmap.viewport.w + 2 * bitmap.viewport.x;
vheight = bitmap.viewport.h + 2 * bitmap.viewport.y; u32 vheight = bitmap.viewport.h + 2 * bitmap.viewport.y;
/* special cases */ /* special cases */
if (config.render && interlaced) vheight *= 2; if (config.render && interlaced) vheight *= 2;
if (config.ntsc) vwidth = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(vwidth) : SMS_NTSC_OUT_WIDTH(vwidth); if (config.ntsc) vwidth = (reg[12]&1) ? MD_NTSC_OUT_WIDTH(vwidth) : SMS_NTSC_OUT_WIDTH(vwidth);
/* texels size must be multiple of 4 */ /* texels size must be multiple of 4 */
vwidth = vwidth / 4; vwidth = (vwidth / 4) * 4;
vheight = vheight / 4; vheight = (vheight / 4) * 4;
/* reset Video mode */ /* initialize texture object */
gxReset(); GXTexObj texobj;
GX_InitTexObj(&texobj, texturemem, vwidth, vheight, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE);
/* reinitialize texture */ /* configure texture filtering */
GX_InitTexObj (&texobj, texturemem, vwidth * 4, vheight * 4, GX_TF_RGB565, GX_CLAMP, GX_CLAMP, GX_FALSE);
/* enable/disable bilinear filtering */
if (!config.bilinear) if (!config.bilinear)
{ {
GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,2.5,9.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1); GX_InitTexObjLOD(&texobj,GX_NEAR,GX_NEAR_MIP_NEAR,2.5,9.0,0.0,GX_FALSE,GX_FALSE,GX_ANISO_1);
} }
/* load texture */ /* load texture object */
GX_LoadTexObj(&texobj, GX_TEXMAP0); GX_LoadTexObj(&texobj, GX_TEXMAP0);
/* select TV mode */
if (config.render) rmode = tvmodes[gc_pal*3 + 2];
else rmode = tvmodes[gc_pal*3 + interlaced];
/* reset aspect ratio */
gxScale(vwidth,vheight);
/* configure GX */
GX_SetViewport(0.0F, 0.0F, rmode->fbWidth, rmode->efbHeight, 0.0F, 1.0F);
GX_SetScissor(0, 0, rmode->fbWidth, rmode->efbHeight);
f32 yScale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
u16 xfbHeight = GX_SetDispCopyYScale(yScale);
GX_SetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
GX_SetDispCopyDst(rmode->fbWidth, xfbHeight);
GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, config.render ? GX_TRUE : GX_FALSE, rmode->vfilter);
GX_SetFieldMode(rmode->field_rendering, ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
GX_SetPixelFmt(rmode->aa ? GX_PF_RGB565_Z16 : GX_PF_RGB8_Z24, GX_ZC_LINEAR);
Mtx p;
guOrtho(p, rmode->efbHeight/2, -(rmode->efbHeight/2), -(rmode->fbWidth/2), rmode->fbWidth/2, 100, 1000);
GX_LoadProjectionMtx(p, GX_ORTHOGRAPHIC);
GX_Flush();
/* configure VI */
whichfb = odd_frame;
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush();
VIDEO_WaitVSync();
if (rmode->viTVMode & VI_NON_INTERLACE) VIDEO_WaitVSync();
else while (VIDEO_GetNextField() != odd_frame) VIDEO_WaitVSync();
} }
/* texture is now directly mapped by the line renderer */ /* texture is now directly mapped by the line renderer */
@ -657,34 +635,18 @@ void ogc_video__update()
draw_square(); draw_square();
GX_DrawDone(); GX_DrawDone();
/* single-field interlaced display requires proper sync*/ /* force fields resync in SF interlaced modes*/
if (interlaced && !config.render) if (rmode->field_rendering) odd_frame = whichfb;
{
/* desync */
if (odd_frame == whichfb)
{
/* force field resync */
odd_frame = whichfb ^ 1;
}
else
{
/* copy EFB to proper XFB */
GX_CopyDisp (xfb[whichfb], GX_TRUE);
GX_Flush ();
}
}
else
{
/* swap XFB */ /* swap XFB */
whichfb ^= 1; whichfb ^= 1;
VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_SetNextFramebuffer(xfb[whichfb]);
VIDEO_Flush(); VIDEO_Flush();
/* copy EFB to current XFB */ /* copy EFB to XFB */
GX_CopyDisp(xfb[whichfb], GX_TRUE); GX_CopyDisp(xfb[whichfb], GX_TRUE);
GX_Flush(); GX_Flush();
} }
}
/* Initialize VIDEO subsystem */ /* Initialize VIDEO subsystem */
void ogc_video__init(void) void ogc_video__init(void)
@ -753,7 +715,7 @@ void ogc_video__init(void)
} }
#ifdef HW_RVL #ifdef HW_RVL
/* Widescreen fix */ /* widescreen menu fix */
if (CONF_GetAspectRatio()) if (CONF_GetAspectRatio())
{ {
vmode->viWidth = 678; vmode->viWidth = 678;

View File

@ -26,8 +26,6 @@
extern unsigned int *xfb[2]; extern unsigned int *xfb[2];
extern int whichfb; extern int whichfb;
extern int gc_pal;
extern GXRModeObj *tvmodes[6];
extern GXRModeObj *vmode; extern GXRModeObj *vmode;
extern u8 *texturemem; extern u8 *texturemem;

View File

@ -17,29 +17,21 @@
#include "ogc_video.h" #include "ogc_video.h"
#include "config.h" #include "config.h"
#define update_input() ogc_input__update()
#define DEFAULT_PATH "/genplus" #define DEFAULT_PATH "/genplus"
/* globals */ /* globals */
extern u32 diff_usec(long long start,long long end);
extern long long gettime();
extern void error(char *format, ...); extern void error(char *format, ...);
extern int getcompany();
extern void reloadrom();
extern void ClearGGCodes(); extern void ClearGGCodes();
extern void GetGGEntries(); extern void GetGGEntries();
extern void reloadrom();
extern void legal(); extern void legal();
extern void MainMenu(u32 fps); extern void MainMenu(u32 fps);
extern void set_region();
extern int ManageSRAM(u8 direction, u8 device); extern int ManageSRAM(u8 direction, u8 device);
extern int ManageState(u8 direction, u8 device); extern int ManageState(u8 direction, u8 device);
extern void memfile_autosave(); extern void memfile_autosave();
extern void memfile_autoload(); extern void memfile_autoload();
extern int peripherals; extern u8 fat_enabled;
extern int frameticker; extern u32 frameticker;
extern int Shutdown;
extern bool fat_enabled;
#endif /* _OSD_H_ */ #endif /* _OSD_H_ */