n64: screw things up some more. use a semaphore to handle stoppage in r4300 interrupt. blah. it's faster

This commit is contained in:
goyuken 2013-05-04 00:23:52 +00:00
parent 415d749be9
commit 147c77c124
10 changed files with 57 additions and 35 deletions

View File

@ -360,22 +360,26 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
VICallback m64pVICallback; VICallback m64pVICallback;
public void FrameComplete() public void FrameComplete()
{ {
uint s = (uint)AudGetAudioRate(); if (resampler != null)
if (s != m64pSamplingRate)
{ {
m64pSamplingRate = s; // the way i've fubared up the core, a first framecomplete callback happens in init, before everything is set up
resampler.ChangeRate(s, 44100, s, 44100); uint s = (uint)AudGetAudioRate();
//Console.WriteLine("N64 ARate Change {0}", s); if (s != m64pSamplingRate)
} {
m64pSamplingRate = s;
resampler.ChangeRate(s, 44100, s, 44100);
//Console.WriteLine("N64 ARate Change {0}", s);
}
int m64pAudioBufferSize = AudGetBufferSize(); int m64pAudioBufferSize = AudGetBufferSize();
if (m64pAudioBuffer.Length < m64pAudioBufferSize) if (m64pAudioBuffer.Length < m64pAudioBufferSize)
m64pAudioBuffer = new short[m64pAudioBufferSize]; m64pAudioBuffer = new short[m64pAudioBufferSize];
if (m64pAudioBufferSize > 0) if (m64pAudioBufferSize > 0)
{ {
AudReadAudioBuffer(m64pAudioBuffer); AudReadAudioBuffer(m64pAudioBuffer);
resampler.EnqueueSamples(m64pAudioBuffer, m64pAudioBufferSize / 2); resampler.EnqueueSamples(m64pAudioBuffer, m64pAudioBufferSize / 2);
}
} }
m64pFrameComplete = true; m64pFrameComplete = true;
} }
@ -487,10 +491,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64
m64pEmulator.Start(); m64pEmulator.Start();
int state = -1; int state = -1;
/*
do do
{ {
m64pCoreDoCommandRefInt(m64p_command.M64CMD_CORE_STATE_QUERY, 1, ref state); m64pCoreDoCommandRefInt(m64p_command.M64CMD_CORE_STATE_QUERY, 1, ref state);
} while (state != (int)m64p_emu_state.M64EMU_PAUSED); } while (state != (int)m64p_emu_state.M64EMU_PAUSED);
*/
m64pFrameComplete = false;
while (!m64pFrameComplete) { }
m64pSamplingRate = (uint)AudGetAudioRate(); m64pSamplingRate = (uint)AudGetAudioRate();

View File

@ -289,11 +289,13 @@ static void main_set_speedlimiter(int enable)
static int main_is_paused(void) static int main_is_paused(void)
{ {
return (g_EmulatorRunning && rompause); return (g_EmulatorRunning);// && rompause);
} }
void main_toggle_pause(void) void main_toggle_pause(void)
{ {
MessageBox(NULL, "This wasn't supposed to happen!", "Call Spooky", 0);
/*
if (!g_EmulatorRunning) if (!g_EmulatorRunning)
return; return;
@ -321,12 +323,14 @@ void main_toggle_pause(void)
rompause = !rompause; rompause = !rompause;
l_FrameAdvance = 0; l_FrameAdvance = 0;
*/
} }
void main_advance_one(void) void main_advance_one(void)
{ {
l_FrameAdvance = 1; l_FrameAdvance = 1;
rompause = 0; //rompause = 0;
ReleaseSemaphore(rompausesem, 1, NULL);
StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING);
} }
@ -413,8 +417,8 @@ m64p_error main_core_state_query(m64p_core_param param, int *rval)
case M64CORE_EMU_STATE: case M64CORE_EMU_STATE:
if (!g_EmulatorRunning) if (!g_EmulatorRunning)
*rval = M64EMU_STOPPED; *rval = M64EMU_STOPPED;
else if (rompause) //else if (rompause)
*rval = M64EMU_PAUSED; // *rval = M64EMU_PAUSED;
else else
*rval = M64EMU_RUNNING; *rval = M64EMU_RUNNING;
break; break;
@ -667,14 +671,14 @@ void new_vi(void)
double VILimitMilliseconds = 1000.0 / ROM_PARAMS.vilimit; double VILimitMilliseconds = 1000.0 / ROM_PARAMS.vilimit;
double AdjustedLimit = VILimitMilliseconds * 100.0 / l_SpeedFactor; // adjust for selected emulator speed double AdjustedLimit = VILimitMilliseconds * 100.0 / l_SpeedFactor; // adjust for selected emulator speed
int time; int time;
start_section(IDLE_SECTION); start_section(IDLE_SECTION);
VI_Counter++; VI_Counter++;
#ifdef DBG #ifdef DBG
if(g_DebuggerActive) DebuggerCallback(DEBUG_UI_VI, 0); if(g_DebuggerActive) DebuggerCallback(DEBUG_UI_VI, 0);
#endif #endif
/*
if(LastFPSTime == 0) if(LastFPSTime == 0)
{ {
LastFPSTime = CounterTime = SDL_GetTicks(); LastFPSTime = CounterTime = SDL_GetTicks();
@ -703,12 +707,13 @@ void new_vi(void)
} }
LastFPSTime = CurrentFPSTime ; LastFPSTime = CurrentFPSTime ;
*/
end_section(IDLE_SECTION); end_section(IDLE_SECTION);
if (g_VICallback != NULL) if (g_VICallback != NULL)
(*g_VICallback)(); (*g_VICallback)();
if (l_FrameAdvance) { if (l_FrameAdvance) {
rompause = 1; //rompause = 1;
l_FrameAdvance = 0; l_FrameAdvance = 0;
StateChanged(M64CORE_EMU_STATE, M64EMU_PAUSED); StateChanged(M64CORE_EMU_STATE, M64EMU_PAUSED);
} }
@ -838,12 +843,13 @@ void main_stop(void)
osd_delete_message(l_msgVol); osd_delete_message(l_msgVol);
l_msgVol = NULL; l_msgVol = NULL;
} }
if (rompause) stop = 1;
{ //if (rompause)
rompause = 0; //{
// rompause = 0;
ReleaseSemaphore(rompausesem, 1, NULL);
StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING); StateChanged(M64CORE_EMU_STATE, M64EMU_RUNNING);
} //}
stop = 1;
#ifdef DBG #ifdef DBG
if(g_DebuggerActive) if(g_DebuggerActive)
{ {

View File

@ -388,21 +388,23 @@ void gen_interupt(void)
refresh_stat(); refresh_stat();
// if paused, poll for input events // if paused, poll for input events
if(rompause) //if(rompause)
{ //{
osd_render(); // draw Paused message in case gfx.updateScreen didn't do it osd_render(); // draw Paused message in case gfx.updateScreen didn't do it
VidExt_GL_SwapBuffers(); VidExt_GL_SwapBuffers();
while(rompause) // while(rompause)
{ // {
SDL_Delay(10); //SDL_Delay(10);
SDL_PumpEvents(); SDL_PumpEvents();
#ifdef WITH_LIRC #ifdef WITH_LIRC
lircCheckInput(); lircCheckInput();
#endif //WITH_LIRC #endif //WITH_LIRC
} // }
} //}
new_vi(); new_vi();
WaitForSingleObject(rompausesem, INFINITE);
if (vi_register.vi_v_sync == 0) vi_register.vi_delay = 500000; if (vi_register.vi_v_sync == 0) vi_register.vi_delay = 500000;
else vi_register.vi_delay = ((vi_register.vi_v_sync + 1)*1500); else vi_register.vi_delay = ((vi_register.vi_v_sync + 1)*1500);
next_vi += vi_register.vi_delay; next_vi += vi_register.vi_delay;

View File

@ -45,7 +45,8 @@
unsigned int r4300emu = 0; unsigned int r4300emu = 0;
int no_compiled_jump = 0; int no_compiled_jump = 0;
int llbit, rompause; int llbit; //, rompause;
HANDLE rompausesem;
#if NEW_DYNAREC != NEW_DYNAREC_ARM #if NEW_DYNAREC != NEW_DYNAREC_ARM
int stop; int stop;
long long int reg[32], hi, lo; long long int reg[32], hi, lo;
@ -985,7 +986,8 @@ void r4300_execute(void)
debug_count = 0; debug_count = 0;
delay_slot=0; delay_slot=0;
stop = 0; stop = 0;
rompause = 1; //rompause = 1;
rompausesem = CreateSemaphore(NULL, 0, 1, NULL);
/* clear instruction counters */ /* clear instruction counters */
#if defined(COUNT_INSTR) #if defined(COUNT_INSTR)

View File

@ -22,6 +22,9 @@
#ifndef R4300_H #ifndef R4300_H
#define R4300_H #define R4300_H
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#include "recomp.h" #include "recomp.h"
#include "memory/tlb.h" #include "memory/tlb.h"
@ -29,7 +32,8 @@ extern precomp_instr *PC;
extern precomp_block *blocks[0x100000], *actual; extern precomp_block *blocks[0x100000], *actual;
extern int stop, llbit, rompause; extern int stop, llbit; //, rompause;
extern HANDLE rompausesem;
extern long long int reg[32], hi, lo; extern long long int reg[32], hi, lo;
extern long long int local_rs; extern long long int local_rs;
extern unsigned int reg_cop0[32]; extern unsigned int reg_cop0[32];