From c900a87eaaa74bddee0320b7a27a5659c2c55bcf Mon Sep 17 00:00:00 2001 From: dborth Date: Tue, 21 Oct 2008 07:50:37 +0000 Subject: [PATCH] audio fix, turn off lowpass, add timings (not working) --- source/ngc/common.h | 1 - source/ngc/fceuconfig.c | 2 +- source/ngc/fceuconfig.h | 5 +- source/ngc/{fceugc.c => fceugx.c} | 117 +++++++++++++++++++++++++----- source/ngc/fceuload.c | 2 +- source/ngc/gcaudio.c | 2 +- source/ngc/gcvideo.c | 41 +++++++++-- source/ngc/gcvideo.h | 3 + source/ngc/menu.c | 1 - source/ngc/pad.c | 19 +---- source/ngc/preferences.c | 2 +- 11 files changed, 144 insertions(+), 51 deletions(-) rename source/ngc/{fceugc.c => fceugx.c} (59%) diff --git a/source/ngc/common.h b/source/ngc/common.h index f88a3ea..e5b1258 100644 --- a/source/ngc/common.h +++ b/source/ngc/common.h @@ -16,7 +16,6 @@ extern int NoWaiting; extern FCEUGI *GI; void DSMFix(unsigned int msg); -void StopSound(void); extern int eoptions; diff --git a/source/ngc/fceuconfig.c b/source/ngc/fceuconfig.c index c0fba05..51f02d9 100644 --- a/source/ngc/fceuconfig.c +++ b/source/ngc/fceuconfig.c @@ -23,7 +23,7 @@ void DefaultSettings () { GCSettings.currpal = 0; - GCSettings.timing = 0; + GCSettings.timing = 0; // 0 - NTSC, 1 - PAL GCSettings.FSDisable = 1; GCSettings.zapper = 0; GCSettings.crosshair = 1; diff --git a/source/ngc/fceuconfig.h b/source/ngc/fceuconfig.h index b4849fa..5a109eb 100644 --- a/source/ngc/fceuconfig.h +++ b/source/ngc/fceuconfig.h @@ -15,8 +15,8 @@ void DefaultSettings (); -#define VERSIONNUM "2.0.5" -#define VERSIONSTR "FCE Ultra GX 2.0.5" +#define VERSIONNUM "2.0.6" +#define VERSIONSTR "FCE Ultra GX 2.0.6" #define NOTSILENT 0 #define SILENT 1 @@ -59,5 +59,6 @@ struct SGCSettings{ }; extern struct SGCSettings GCSettings; +extern int ConfigRequested; #endif diff --git a/source/ngc/fceugc.c b/source/ngc/fceugx.c similarity index 59% rename from source/ngc/fceugc.c rename to source/ngc/fceugx.c index 09efb31..6999a9b 100644 --- a/source/ngc/fceugc.c +++ b/source/ngc/fceugx.c @@ -20,32 +20,84 @@ #include "types.h" -#include "gcvideo.h" -#include "pad.h" +#include "fceuconfig.h" #include "fceuload.h" +#include "fceustate.h" +#include "fceuram.h" #include "common.h" #include "menudraw.h" #include "menu.h" -#include "fceuconfig.h" #include "preferences.h" #include "gcaudio.h" +#include "gcvideo.h" +#include "pad.h" #ifdef WII_DVD #include #endif unsigned char * nesrom = NULL; -extern bool romLoaded; +int ConfigRequested = 0; bool isWii; - uint8 *xbsave=NULL; +long long prev; +long long now; + +long long gettime(); +u32 diff_usec(long long start,long long end); + +extern bool romLoaded; + extern int cleanSFMDATA(); extern void ResetNES(void); extern uint8 FDSBIOS[8192]; void FCEUD_Update(uint8 *XBuf, int32 *Buffer, int Count); +/**************************************************************************** + * setFrameTimer() + * change frame timings depending on whether ROM is NTSC or PAL + ***************************************************************************/ + +int normaldiff; + +void setFrameTimer() +{ + if (GCSettings.timing) // PAL + { + if(vmode_60hz == 1) + normaldiff = 20000; // 50hz + else + normaldiff = 16667; // 60hz + } + else + { + if(vmode_60hz == 1) + normaldiff = 16667; // 60hz + else + normaldiff = 20000; // 50hz + } + FrameTimer = 0; + prev = gettime(); +} + +void SyncSpeed() +{ + now = gettime(); + int diff = normaldiff - diff_usec(prev, now); + if (diff > 0) // ahead - take a nap + usleep(diff); + + prev = now; + FrameTimer--; +} + +/**************************************************************************** + * main + * This is where it all happens! + ***************************************************************************/ + int main(int argc, char *argv[]) { @@ -62,6 +114,8 @@ int main(int argc, char *argv[]) WPAD_SetVRes(WPAD_CHAN_ALL,640,480); #endif + PAD_Init(); + initDisplay(); /*** Initialise freetype ***/ @@ -86,8 +140,7 @@ int main(int argc, char *argv[]) return 1; } - FCEUI_SetVidSystem(0); // 0 - NTSC, 1 - PAL - FCEUI_SetGameGenie(0); // 0 - OFF, 1 - ON + FCEUI_SetGameGenie(0); // 0 - OFF, 1 - ON memset(FDSBIOS, 0, sizeof(FDSBIOS)); // clear FDS BIOS memory cleanSFMDATA(); // clear state data @@ -103,31 +156,57 @@ int main(int argc, char *argv[]) selectedMenu = 3; // change to preferences menu } - // Go to main menu - MainMenu (selectedMenu); - - while (1) + while (1) // main loop { - uint8 *gfx; - int32 *sound; - int32 ssize; + MainMenu(selectedMenu); + selectedMenu = 4; // return to game menu from now on - FCEUI_Emulate(&gfx, &sound, &ssize, 0); - xbsave = gfx; - FCEUD_Update(gfx, sound, ssize); + setFrameTimer(); // set frametimer method before emulation + FCEUI_SetVidSystem(GCSettings.timing); + + while(1) // emulation loop + { + uint8 *gfx; + int32 *sound; + int32 ssize; + + FCEUI_Emulate(&gfx, &sound, &ssize, 0); + xbsave = gfx; + FCEUD_Update(gfx, sound, ssize); + + if(ConfigRequested) + { + if (GCSettings.AutoSave == 1) + { + SaveRAM(GCSettings.SaveMethod, SILENT); + } + else if (GCSettings.AutoSave == 2) + { + SaveState(GCSettings.SaveMethod, SILENT); + } + else if(GCSettings.AutoSave == 3) + { + SaveRAM(GCSettings.SaveMethod, SILENT); + SaveState(GCSettings.SaveMethod, SILENT); + } + ConfigRequested = 0; + break; // leave emulation loop + } + + SyncSpeed(); + } } return 0; } /**************************************************************************** - * FCEU Support Functions to be written + * FCEU Support Functions ****************************************************************************/ // File Control FILE *FCEUD_UTF8fopen(const char *n, const char *m) { return NULL; - //return(fopen(n,m)); } // General Logging diff --git a/source/ngc/fceuload.c b/source/ngc/fceuload.c index 9987080..f2bc1fe 100644 --- a/source/ngc/fceuload.c +++ b/source/ngc/fceuload.c @@ -95,7 +95,7 @@ int GCMemROM(int method, int size) FCEUI_Sound(SAMPLERATE); FCEUI_SetSoundVolume(100); // 0-100 FCEUI_SetSoundQuality(1); // 0 - low, 1 - high - FCEUI_SetLowPass(1); + FCEUI_SetLowPass(0); InitialisePads(); diff --git a/source/ngc/gcaudio.c b/source/ngc/gcaudio.c index 02b488f..226b481 100644 --- a/source/ngc/gcaudio.c +++ b/source/ngc/gcaudio.c @@ -93,7 +93,7 @@ void StopAudio() void PlaySound( int *Buffer, int count ) { int i; - s16 sample; + u16 sample; u32 *dst = (u32 *)mixbuffer; for( i = 0; i < count; i++ ) diff --git a/source/ngc/gcvideo.c b/source/ngc/gcvideo.c index 27c6cf0..75a5148 100644 --- a/source/ngc/gcvideo.c +++ b/source/ngc/gcvideo.c @@ -34,6 +34,8 @@ int FDSSwitchRequested; unsigned int *xfb[2]; /*** Framebuffer - used throughout ***/ GXRModeObj *vmode; int screenheight; +int vmode_60hz = 0; +bool progressive = false; /*** Need something to hold the PC palette ***/ struct pcpal { @@ -52,6 +54,7 @@ static Mtx projectionMatrix,modelViewMatrix; void CheesyScale(unsigned char *XBuf); int whichfb = 0; int copynow = GX_FALSE; +u32 FrameTimer = 0; /**************************************************************************** * VideoThreading @@ -104,11 +107,12 @@ static void copy_to_xfb() { if (copynow == GX_TRUE) { - GX_CopyDisp(xfb[whichfb],GX_TRUE); - GX_Flush(); - copynow = GX_FALSE; + GX_CopyDisp(xfb[whichfb],GX_TRUE); + GX_Flush(); + copynow = GX_FALSE; } SMBTimer++; + FrameTimer++; // FDS switch disk requested - need to eject, select, and insert // but not all at once! @@ -292,6 +296,30 @@ void initDisplay() vmode = VIDEO_GetPreferredMode(NULL); + switch (vmode->viTVMode >> 2) + { + case VI_PAL: + // 576 lines (PAL 50Hz) + // display should be centered vertically (borders) + vmode = &TVPal574IntDfScale; + vmode->xfbHeight = 480; + vmode->viYOrigin = (VI_MAX_HEIGHT_PAL - 480)/2; + vmode->viHeight = 480; + + vmode_60hz = 0; + break; + + case VI_NTSC: + // 480 lines (NTSC 60hz) + vmode_60hz = 1; + break; + + default: + // 480 lines (PAL 60Hz) + vmode_60hz = 1; + break; + } + #ifdef HW_DOL /* we have component cables, but the preferred mode is interlaced * why don't we switch into progressive? @@ -300,6 +328,10 @@ void initDisplay() vmode = &TVNtsc480Prog; #endif + // check for progressive scan + if (vmode->viTVMode == VI_TVMODE_NTSC_PROG) + progressive = true; + VIDEO_Configure(vmode); screenheight = vmode->xfbHeight; @@ -307,7 +339,6 @@ void initDisplay() xfb[0] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); xfb[1] = (u32 *) MEM_K0_TO_K1 (SYS_AllocateFramebuffer (vmode)); - VIDEO_SetNextFramebuffer(xfb[0]); VIDEO_ClearFrameBuffer (vmode, xfb[0], COLOR_BLACK); VIDEO_ClearFrameBuffer (vmode, xfb[1], COLOR_BLACK); VIDEO_SetNextFramebuffer (xfb[0]); @@ -322,7 +353,6 @@ void initDisplay() VIDEO_SetPostRetraceCallback((VIRetraceCallback)UpdatePadsCB); VIDEO_SetPreRetraceCallback((VIRetraceCallback)copy_to_xfb); - PAD_Init(); StartGX(); InitVideoThread (); @@ -378,7 +408,6 @@ void RenderFrame(char *XBuf, int style) VIDEO_SetNextFramebuffer(xfb[whichfb]); VIDEO_Flush(); - copynow = GX_TRUE; // Return to caller, don't waste time waiting for vb LWP_ResumeThread (vbthread); diff --git a/source/ngc/gcvideo.h b/source/ngc/gcvideo.h index 1dcc065..0ab403e 100644 --- a/source/ngc/gcvideo.h +++ b/source/ngc/gcvideo.h @@ -27,5 +27,8 @@ struct st_palettes { extern struct st_palettes palettes[]; extern int FDSSwitchRequested; +extern int vmode_60hz; +extern bool progressive; +extern u32 FrameTimer; #endif diff --git a/source/ngc/menu.c b/source/ngc/menu.c index 4db8a43..d625e4b 100644 --- a/source/ngc/menu.c +++ b/source/ngc/menu.c @@ -166,7 +166,6 @@ EmulatorMenu () case 3: // timing GCSettings.timing ^= 1; - FCEUI_SetVidSystem(GCSettings.timing); break; case 4: diff --git a/source/ngc/pad.c b/source/ngc/pad.c index a7e2434..93b76ff 100644 --- a/source/ngc/pad.c +++ b/source/ngc/pad.c @@ -20,8 +20,6 @@ #include "pad.h" #include "gcaudio.h" #include "menu.h" -#include "fceustate.h" -#include "fceuram.h" #include "gcvideo.h" #include "filesel.h" @@ -469,22 +467,7 @@ void GetJoy() ) { StopAudio(); - - if (GCSettings.AutoSave == 1) - { - SaveRAM(GCSettings.SaveMethod, SILENT); - } - else if (GCSettings.AutoSave == 2) - { - SaveState(GCSettings.SaveMethod, SILENT); - } - else if(GCSettings.AutoSave == 3) - { - SaveRAM(GCSettings.SaveMethod, SILENT); - SaveState(GCSettings.SaveMethod, SILENT); - } - - MainMenu(4); + ConfigRequested = 1; } else { diff --git a/source/ngc/preferences.c b/source/ngc/preferences.c index 750f2ef..3ea4c22 100644 --- a/source/ngc/preferences.c +++ b/source/ngc/preferences.c @@ -256,7 +256,7 @@ decodePrefsData (int method) if(verMajor == '2' && verPoint < '3') // less than version 2.0.3 return false; // reset settings - else if(verMajor > '2' || verMinor > '0' || verPoint > '5') // some future version + else if(verMajor > '2' || verMinor > '0' || verPoint > '6') // some future version return false; // reset settings // File Settings