From 8951fdff1aada126257e07699ea6f132cb8d2e65 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 18 Dec 2012 00:02:49 -0500 Subject: Remove various explicit delays and reduce screen tearing when drawing emulated screens. --- source/nds/entry.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index d3dbae3..c14902c 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -172,12 +172,7 @@ bool8 S9xDeinitUpdate (int Width, int Height, bool8 /*sixteen_bit*/) break; } - -// memcpy(up_screen_addr, GFX.Screen, 256*192*2); -// memcpy(down_screen_addr, GFX.Screen+256*192*2, 256*(224-192)*2); - - ds2_flipScreen(UP_SCREEN, 0); -// ds2_flipScreen(DOWN_SCREEN, 0); + ds2_flipScreen(UP_SCREEN, 1); // synchronise to vblank to avoid tearing return (TRUE); } @@ -454,12 +449,12 @@ int load_gamepak(char* file) CPU.Flags = 0; S9xReset (); - mdelay(50); + // mdelay(50); // Delete this delay if (!Memory.LoadROM (file)) return -1; Memory.LoadSRAM (S9xGetFilename (".srm")); - mdelay(50); + // mdelay(50); // Delete this delay //S9xLoadCheatFile (S9xGetFilename (".cht")); S9xCheat_Disable(); @@ -507,7 +502,7 @@ int load_gamepak(char* file) } */ - mdelay(50); + // mdelay(50); // Delete this delay if (!Settings.APUEnabled) S9xSetSoundMute (FALSE); @@ -602,7 +597,7 @@ int sfc_main (int argc, char **argv) if (Settings.Paused) { S9xSetSoundMute (TRUE); - mdelay(50); + // mdelay(50); // Delete this delay unsigned short screen[256*192]; copy_screen((void*)screen, up_screen_addr, 0, 0, 256, 192); @@ -996,7 +991,7 @@ const unsigned int keymap[12] = { unsigned int S9xReadJoypad (int which1) { - struct key_buf inputdata; + struct key_buf inputdata; ds2_getrawInput(&inputdata); if(inputdata.key & KEY_TOUCH) //Active menu -- cgit v1.2.3 From 286bfd58050a13e2e0e30bb35a7a1d189ec7edd1 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 18 Dec 2012 00:40:18 -0500 Subject: Sync sound. In addition to having less sound skipping going on, certain platformer games (I'm looking at you, Super Mario World) are helped by having more synchronised controls. In other words, synchronising the audio also synchronises the controls a bit more. --- source/nds/entry.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index c14902c..24c0e03 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -385,6 +385,7 @@ void init_sfc_setting(void) Settings.NetPlay = FALSE; Settings.ServerName [0] = 0; Settings.ThreadSound = FALSE; + Settings.SoundSync = TRUE; Settings.AutoSaveDelay = 0; #ifdef _NETPLAY_SUPPORT Settings.Port = NP_DEFAULT_PORT; -- cgit v1.2.3 From a0d0c5e7a5bdc396b4c370a750273b6e3b963bb0 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Fri, 21 Dec 2012 03:50:10 -0500 Subject: Eliminate the latency of button press recognition, which was bad enough to lose keys entirely sometimes, and could otherwise delay a button press or release by 200 ms. This was the entire reason I created the fork, and I finally did it! It syncs the controls every scanline of a frame, which costs about 60,000 MIPS instructions per frame to deal with. Luckily, the processor runs at 396 MHz, which means the cost of checking the controls is 1% of the CPU's power. --- source/nds/entry.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index 24c0e03..467461b 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -90,6 +90,7 @@ void S9xParseDisplayArg (char **argv, int &ind, int) void S9xExit () { + ds2_setCPUclocklevel(13); // Crank it up to exit quickly if(Settings.SPC7110) (*CleanUp7110)(); @@ -382,15 +383,15 @@ void init_sfc_setting(void) Settings.SixteenBit = TRUE; Settings.SupportHiRes = FALSE; - Settings.NetPlay = FALSE; - Settings.ServerName [0] = 0; Settings.ThreadSound = FALSE; Settings.SoundSync = TRUE; Settings.AutoSaveDelay = 0; #ifdef _NETPLAY_SUPPORT + Settings.NetPlay = FALSE; + Settings.ServerName [0] = 0; Settings.Port = NP_DEFAULT_PORT; #endif - Settings.ApplyCheats =FALSE; + Settings.ApplyCheats = FALSE; Settings.TurboMode = FALSE; Settings.TurboSkipFrames = 40; Settings.StretchScreenshots = 1; @@ -1009,7 +1010,8 @@ unsigned int S9xReadJoypad (int which1) key |= (inputdata.key & (1< 679, though.) --- source/nds/entry.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index 467461b..ea5f6ce 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -97,7 +97,8 @@ void S9xExit () S9xSetSoundMute (TRUE); S9xDeinitDisplay (); Memory.SaveSRAM (S9xGetFilename (".srm")); - S9xSaveCheatFile (S9xGetFilename (".cht")); + // S9xSaveCheatFile (S9xGetFilename (".chb")); // cheat binary file + // Do this when loading a cheat file! Memory.Deinit (); S9xDeinitAPU (); @@ -258,7 +259,6 @@ const char *S9xGetSnapshotDirectory () return ((const char*)DEFAULT_RTS_DIR); } - const char *S9xGetFilename (const char *ex) { static char filename [PATH_MAX + 1]; @@ -391,7 +391,7 @@ void init_sfc_setting(void) Settings.ServerName [0] = 0; Settings.Port = NP_DEFAULT_PORT; #endif - Settings.ApplyCheats = FALSE; + Settings.ApplyCheats = TRUE; Settings.TurboMode = FALSE; Settings.TurboSkipFrames = 40; Settings.StretchScreenshots = 1; @@ -457,8 +457,7 @@ int load_gamepak(char* file) Memory.LoadSRAM (S9xGetFilename (".srm")); // mdelay(50); // Delete this delay - //S9xLoadCheatFile (S9xGetFilename (".cht")); - S9xCheat_Disable(); + S9xLoadCheatFile (S9xGetFilename (".chb")); // cheat binary file, as opposed to text #ifdef _NETPLAY_SUPPORT if (strlen (Settings.ServerName) == 0) -- cgit v1.2.3 From 9c1742f6cb2043d0ed6a61ab6de3bef0aad6dc56 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 25 Dec 2012 16:00:34 -0500 Subject: Universally use update method 2 for the lower screen and 0 for the upper screen. Method 1 causes problems after about 15 minutes; despite the double-buffering, screen updates start to tear in the middle consistently. --- source/nds/entry.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index ea5f6ce..ce8d732 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -174,7 +174,10 @@ bool8 S9xDeinitUpdate (int Width, int Height, bool8 /*sixteen_bit*/) break; } - ds2_flipScreen(UP_SCREEN, 1); // synchronise to vblank to avoid tearing + ds2_flipScreen(UP_SCREEN, 0); + // A problem with update method 1 (wait, double buffer) means that, after + // about 15 minutes of play time, the screen starts to half-redraw every + // frame. With update method 0, this is mitigated. (Method 2 is too slow.) return (TRUE); } @@ -598,7 +601,6 @@ int sfc_main (int argc, char **argv) if (Settings.Paused) { S9xSetSoundMute (TRUE); - // mdelay(50); // Delete this delay unsigned short screen[256*192]; copy_screen((void*)screen, up_screen_addr, 0, 0, 256, 192); -- cgit v1.2.3 From 139c793b584a76acd42d72ec019d2cabab7d3ee7 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Tue, 25 Dec 2012 22:44:39 -0500 Subject: Smoother sound. Raise the sound sampling frequency to 48000 Hz. --- source/nds/entry.cpp | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index ce8d732..a8e2217 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -20,6 +20,7 @@ #include "draw.h" #include "gui.h" +#include "ds2sound.h" void S9xProcessSound (unsigned int); @@ -359,9 +360,9 @@ void init_sfc_setting(void) Settings.JoystickEnabled = FALSE; #endif - Settings.SoundPlaybackRate = 4; //2 = 11025, 4 = 22050, 6 = 44100 + Settings.SoundPlaybackRate = SNES9X_SRATE_ID; // -> ds2sound.h for defs Settings.Stereo = TRUE; - Settings.SoundBufferSize = 0; + Settings.SoundBufferSize = DS2_BUFFER_SIZE; Settings.CyclesPercentage = 100; Settings.DisableSoundEcho = FALSE; //sound settings @@ -767,28 +768,15 @@ void S9xSyncSpeed () #endif } -/* -* Open sound device -*/ -static int Rates[8] = -{ - 0, 8000, 11025, 16000, 22050, 32000, 44100, 48000 -}; - -static int BufferSizes [8] = -{ - 0, 256, 256, 256, 512, 512, 1024, 1024 -}; - bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) { so.sixteen_bit = TRUE; so.stereo = stereo; - so.playback_rate = Rates[mode & 0x07]; + so.playback_rate = SND_SAMPLE_RATE; S9xSetPlaybackRate (so.playback_rate); if (buffer_size == 0) - buffer_size = BufferSizes [mode & 7]; + buffer_size = DS2_BUFFER_SIZE; if (buffer_size > MAX_BUFFER_SIZE / 4) buffer_size = MAX_BUFFER_SIZE / 4; @@ -936,7 +924,7 @@ void S9xProcessSound (unsigned int) // block_generate_sound = FALSE; unsigned short *dst_pt = audiobuff; - unsigned short *dst_pt1 = dst_pt + 512; + unsigned short *dst_pt1 = dst_pt + DS2_BUFFER_SIZE; /* Feed the samples to the soundcard until nothing is left */ for(;;) -- cgit v1.2.3 From 0f60f047f5146c76a73c8a299b4405929bf3909f Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Wed, 26 Dec 2012 15:40:35 -0500 Subject: Add the update methods for the upper and lower screen into defines. --- source/nds/entry.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index a8e2217..9d0f0bc 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -175,7 +175,7 @@ bool8 S9xDeinitUpdate (int Width, int Height, bool8 /*sixteen_bit*/) break; } - ds2_flipScreen(UP_SCREEN, 0); + ds2_flipScreen(UP_SCREEN, UP_SCREEN_UPDATE_METHOD); // A problem with update method 1 (wait, double buffer) means that, after // about 15 minutes of play time, the screen starts to half-redraw every // frame. With update method 0, this is mitigated. (Method 2 is too slow.) @@ -586,9 +586,9 @@ int sfc_main (int argc, char **argv) { if (!Settings.Paused #ifdef DEBUGGER - || (CPU.Flags & (DEBUG_MODE_FLAG | SINGLE_STEP_FLAG)) + || (CPU.Flags & (DEBUG_MODE_FLAG | SINGLE_STEP_FLAG) #endif - ) + ) S9xMainLoop (); -- cgit v1.2.3 From 6b36e79013d4c9273a96a9783a2bccdb516f174a Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Thu, 27 Dec 2012 18:02:03 -0500 Subject: Speed up rendering by an unknown amount. gfx.cpp, others: Avoid always checking for Settings.SixteenBit if FOREVER_16_BIT is defined. port.h: Define FOREVER_16_BIT below PIXEL_FORMAT. --- source/nds/entry.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index 9d0f0bc..1589c21 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -384,7 +384,9 @@ void init_sfc_setting(void) Settings.ControllerOption = SNES_JOYPAD; Settings.Transparency = TRUE; +#ifndef FOREVER_16_BIT Settings.SixteenBit = TRUE; +#endif Settings.SupportHiRes = FALSE; Settings.ThreadSound = FALSE; @@ -792,6 +794,7 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) void S9xGenerateSound () { +#if 0 int bytes_so_far = so.sixteen_bit ? (so.samples_mixed_so_far << 1) : so.samples_mixed_so_far; @@ -853,10 +856,12 @@ void S9xGenerateSound () S9xProcessSound (0); pending_signal = FALSE; } +#endif } void S9xProcessSound (unsigned int) { +#if 0 unsigned short *audiobuff; if (!Settings.APUEnabled || so.mute_sound ) @@ -957,6 +962,7 @@ void S9xProcessSound (unsigned int) } so.samples_mixed_so_far -= sample_count; +#endif } void Init_Timer (void) -- cgit v1.2.3 From 963c3459e51264ccf0cc501a41e45de6e71eeea3 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Thu, 27 Dec 2012 18:10:31 -0500 Subject: Accidentally committed the previous revision with sound functions emptied. --- source/nds/entry.cpp | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index 1589c21..b4467a1 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -794,7 +794,6 @@ bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size) void S9xGenerateSound () { -#if 0 int bytes_so_far = so.sixteen_bit ? (so.samples_mixed_so_far << 1) : so.samples_mixed_so_far; @@ -856,12 +855,10 @@ void S9xGenerateSound () S9xProcessSound (0); pending_signal = FALSE; } -#endif } void S9xProcessSound (unsigned int) { -#if 0 unsigned short *audiobuff; if (!Settings.APUEnabled || so.mute_sound ) @@ -962,7 +959,6 @@ void S9xProcessSound (unsigned int) } so.samples_mixed_so_far -= sample_count; -#endif } void Init_Timer (void) -- cgit v1.2.3 From c01a2a42168695233ecc69c4a60ed918e7701fb9 Mon Sep 17 00:00:00 2001 From: Nebuleon Fumika Date: Fri, 28 Dec 2012 01:45:40 -0500 Subject: Keep the audio processing unit (APU) enabled even when the user disabled the audio for a game. This allows some games that synchronise on the APU's actions to continue working. --- source/nds/entry.cpp | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'source/nds/entry.cpp') diff --git a/source/nds/entry.cpp b/source/nds/entry.cpp index b4467a1..33566d5 100644 --- a/source/nds/entry.cpp +++ b/source/nds/entry.cpp @@ -341,12 +341,10 @@ void game_disableAudio() { if( game_enable_audio == 1) { - Settings.APUEnabled = Settings.NextAPUEnabled = TRUE; S9xSetSoundMute (FALSE); } else { - Settings.APUEnabled = Settings.NextAPUEnabled = FALSE; S9xSetSoundMute (TRUE); } } @@ -510,8 +508,6 @@ int load_gamepak(char* file) */ // mdelay(50); // Delete this delay - if (!Settings.APUEnabled) - S9xSetSoundMute (FALSE); return 0; } @@ -535,9 +531,6 @@ int sfc_main (int argc, char **argv) S9xInitSound (Settings.SoundPlaybackRate, Settings.Stereo, Settings.SoundBufferSize); - if (!Settings.APUEnabled) - S9xSetSoundMute (TRUE); - #ifdef GFX_MULTI_FORMAT // S9xSetRenderPixelFormat (RGB565); S9xSetRenderPixelFormat (BGR555); @@ -861,7 +854,7 @@ void S9xProcessSound (unsigned int) { unsigned short *audiobuff; - if (!Settings.APUEnabled || so.mute_sound ) + if (so.mute_sound || !game_enable_audio) return; if(ds2_checkAudiobuff() > 4) -- cgit v1.2.3