From 0e86a15c093a6a3874934cd3010d29f932888c83 Mon Sep 17 00:00:00 2001 From: ekeeke31 Date: Sat, 20 Dec 2008 20:36:37 +0000 Subject: [PATCH] fixed crash issue --- history.txt | 9 +++++++++ source/ngc/ngc.c | 38 +++++++++++++++++++++++++------------- source/ngc/ogc_audio.c | 7 ++++--- source/ngc/ogc_audio.h | 2 +- source/ngc/ogc_video.c | 2 +- source/ngc/ogc_video.h | 2 +- source/sound/sound.c | 4 ++-- source/system.c | 2 +- 8 files changed, 44 insertions(+), 22 deletions(-) diff --git a/history.txt b/history.txt index 291c144..cb23fc6 100644 --- a/history.txt +++ b/history.txt @@ -1,6 +1,15 @@ Genesis Plus for Gamecube ------------------------------ + +1.3.1 (20/12/2008): +------------------- +[NGC/Wii] +- improved sound engine +- modified frame synchronization (now use audio DMA interrupt) + + + 1.3.0 (14/12/2008): ------------------- [Genesis] diff --git a/source/ngc/ngc.c b/source/ngc/ngc.c index e7931e5..74f6b42 100644 --- a/source/ngc/ngc.c +++ b/source/ngc/ngc.c @@ -131,6 +131,7 @@ int main (int argc, char *argv[]) DI_Init(); #endif + long long now, prev; int RenderedFrameCount = 0; int FrameCount = 0; @@ -189,27 +190,37 @@ int main (int argc, char *argv[]) /* Emulation Loop */ while (1) { - /* audio DMA starting point */ ogc_audio__start(); - - if (frameticker > 1) + + if (gc_pal < 0) { - /* frameskipping */ - frameticker--; - system_frame (1); + /* this code is NEVER executed */ + /* strangely, when removing it, this makes the program crashing (why ?) */ + prev = now = gettime(); + while (diff_usec(prev, now) < 1) now = gettime(); + prev = now; } else { - /* frame sync */ - while (!frameticker) usleep(10); + if (frameticker > 1) + { + /* frameskipping */ + frameticker--; + system_frame (1); + } + else + { + /* frame sync */ + while (!frameticker) usleep(1); - /* frame rendering */ - system_frame (0); - RenderedFrameCount++; + /* frame rendering */ + system_frame (0); + RenderedFrameCount++; + } + + frameticker--; } - frameticker--; - /* update video & audio */ ogc_audio__update(); ogc_video__update(); @@ -237,6 +248,7 @@ int main (int argc, char *argv[]) frameticker = 0; FrameCount = 0; RenderedFrameCount = 0; + } } return 0; diff --git a/source/ngc/ogc_audio.c b/source/ngc/ogc_audio.c index 8491454..eb26987 100644 --- a/source/ngc/ogc_audio.c +++ b/source/ngc/ogc_audio.c @@ -33,7 +33,7 @@ u8 soundbuffer[2][3840] ATTRIBUTE_ALIGN(32); /* Current work soundbuffer */ -u8 mixbuffer = 1; +int mixbuffer; /* Current DMA status (1: DMA in progress, 0: DMA stopped) */ static int IsPlaying = 0; @@ -102,9 +102,12 @@ void ogc_audio__start(void) if (!IsPlaying) { dma_len = vdp_pal ? 3840 : 3200; + memset(soundbuffer[0], 0, dma_len); AUDIO_InitDMA((u32) soundbuffer[0], dma_len); + DCFlushRange(soundbuffer[0], dma_len); AUDIO_StartDMA(); IsPlaying = 1; + mixbuffer = 1; } } @@ -119,6 +122,4 @@ void ogc_audio__stop(void) { AUDIO_StopDMA (); IsPlaying = 0; - mixbuffer = 1; - memset(soundbuffer, 0, 2 * 3840); } diff --git a/source/ngc/ogc_audio.h b/source/ngc/ogc_audio.h index 2c7575f..3dd8ad8 100644 --- a/source/ngc/ogc_audio.h +++ b/source/ngc/ogc_audio.h @@ -25,7 +25,7 @@ #define _GC_AUDIO_H_ extern u8 soundbuffer[2][3840]; -extern u8 mixbuffer; +extern int mixbuffer; extern void ogc_audio__init(void); extern void ogc_audio__stop(void); diff --git a/source/ngc/ogc_video.c b/source/ngc/ogc_video.c index 43d725d..c39938e 100644 --- a/source/ngc/ogc_video.c +++ b/source/ngc/ogc_video.c @@ -35,7 +35,7 @@ sms_ntsc_setup_t sms_setup; sms_ntsc_t sms_ntsc; /*** PAL 50hz flag ***/ -BOOL gc_pal = 0; +int gc_pal = 0; /*** VI ***/ unsigned int *xfb[2]; /*** Double buffered ***/ diff --git a/source/ngc/ogc_video.h b/source/ngc/ogc_video.h index fd98674..b231286 100644 --- a/source/ngc/ogc_video.h +++ b/source/ngc/ogc_video.h @@ -28,7 +28,7 @@ extern void ogc_video__init(void); extern void ogc_video__update(void); extern void ogc_video__reset(); -extern BOOL gc_pal; +extern int gc_pal; extern unsigned int *xfb[2]; extern int whichfb; extern GXRModeObj *tvmodes[6]; diff --git a/source/sound/sound.c b/source/sound/sound.c index 56cca23..fc3b474 100644 --- a/source/sound/sound.c +++ b/source/sound/sound.c @@ -61,7 +61,7 @@ static inline uint32 psg_sample_cnt(uint8 is_z80) /* update FM samples */ static inline void fm_update() { - if(snd.fm.curStage - snd.fm.lastStage > 1) + if(snd.fm.curStage - snd.fm.lastStage > 0) { int *tempBuffer[2]; @@ -84,7 +84,7 @@ static inline void fm_update() /* update PSG samples */ static inline void psg_update() { - if(snd.psg.curStage - snd.psg.lastStage > 1) + if(snd.psg.curStage - snd.psg.lastStage > 0) { int16 *tempBuffer = snd.psg.buffer + snd.psg.lastStage; SN76489_Update (0, tempBuffer, snd.psg.curStage - snd.psg.lastStage); diff --git a/source/system.c b/source/system.c index e6ee51e..bc22f86 100644 --- a/source/system.c +++ b/source/system.c @@ -170,7 +170,7 @@ int system_frame (int do_skip) { #ifdef NGC /* wait for RESET button to be released */ - if (!SYS_ResetButtonDown()) + while (SYS_ResetButtonDown()); #endif gen_reset(0); }