diff --git a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs index 88dc14b7dd..e1ef907823 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/N64/N64.cs @@ -22,6 +22,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 public int[] frameBuffer = new int[800 * 600]; public int[] GetVideoBuffer() { + /* for (int row = 0; row < 600; row++) { for (int col = 0; col < 800; col++) @@ -30,6 +31,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 frameBuffer[(599 - row) * 800 + col] = (m64p_FrameBuffer[(i * 3)] << 16) + (m64p_FrameBuffer[(i * 3) + 1] << 8) + (m64p_FrameBuffer[(i * 3) + 2]); } } + */ return frameBuffer; } public int VirtualWidth { get { return 800; } } @@ -301,7 +303,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 // Graphics plugin specific [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - private delegate void ReadScreen2(byte[] framebuffer, ref int width, ref int height, int buffer); + private delegate void ReadScreen2(int[] framebuffer, ref int width, ref int height, int buffer); ReadScreen2 GFXReadScreen2; // Audio plugin specific @@ -343,13 +345,17 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 [UnmanagedFunctionPointer(CallingConvention.Cdecl)] public delegate void FrameCallback(); FrameCallback m64pFrameCallback; - - byte[] m64p_FrameBuffer = new byte[800 * 600 * 3]; + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void StartupCallback(); + + //byte[] m64p_FrameBuffer = new byte[800 * 600 * 3]; public void Getm64pFrameBuffer() { int width = 0; int height = 0; - GFXReadScreen2(m64p_FrameBuffer, ref width, ref height, 0); + //GFXReadScreen2(m64p_FrameBuffer, ref width, ref height, 0); + GFXReadScreen2(frameBuffer, ref width, ref height, 0); //m64pFrameComplete = true; } @@ -392,6 +398,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 AutoResetEvent m64pFrameComplete = new AutoResetEvent(false); + ManualResetEvent m64pStartupComplete = new ManualResetEvent(false); + public N64(CoreComm comm, GameInfo game, byte[] rom) { if (AttachedCore != null) @@ -496,6 +504,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 } while (state != (int)m64p_emu_state.M64EMU_PAUSED); */ //m64pFrameComplete.WaitOne(); + m64pStartupComplete.WaitOne(); // because of when we're doing this, we can't call this yet m64pSamplingRate = 32000; // (uint)AudGetAudioRate(); @@ -510,7 +519,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo.N64 public void ExecuteEmulator() { emulator_running = true; - m64pCoreDoCommandPtr(m64p_command.M64CMD_EXECUTE, 0, IntPtr.Zero); + m64pCoreDoCommandPtr(m64p_command.M64CMD_EXECUTE, 0, + Marshal.GetFunctionPointerForDelegate(new StartupCallback(() => m64pStartupComplete.Set()))); emulator_running = false; } diff --git a/BizHawk.MultiClient/output/dll/mupen64plus-video-rice.dll b/BizHawk.MultiClient/output/dll/mupen64plus-video-rice.dll index d3824cb967..a573f5a3c0 100644 Binary files a/BizHawk.MultiClient/output/dll/mupen64plus-video-rice.dll and b/BizHawk.MultiClient/output/dll/mupen64plus-video-rice.dll differ diff --git a/BizHawk.MultiClient/output/dll/mupen64plus.dll b/BizHawk.MultiClient/output/dll/mupen64plus.dll index 29d2896618..18ebd5151b 100644 Binary files a/BizHawk.MultiClient/output/dll/mupen64plus.dll and b/BizHawk.MultiClient/output/dll/mupen64plus.dll differ diff --git a/libmupen64plus/mupen64plus-core/src/api/frontend.c b/libmupen64plus/mupen64plus-core/src/api/frontend.c index 9a59ee1790..f7540e474c 100644 --- a/libmupen64plus/mupen64plus-core/src/api/frontend.c +++ b/libmupen64plus/mupen64plus-core/src/api/frontend.c @@ -211,7 +211,7 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P /* print out plugin-related warning messages */ plugin_check(); /* the main_run() function will not return until the player has quit the game */ - rval = main_run(); + rval = main_run((void (*)(void))ParamPtr); return rval; case M64CMD_STOP: if (!g_EmulatorRunning) diff --git a/libmupen64plus/mupen64plus-core/src/main/main.c b/libmupen64plus/mupen64plus-core/src/main/main.c index 643213d70a..b8bb3dc330 100644 --- a/libmupen64plus/mupen64plus-core/src/main/main.c +++ b/libmupen64plus/mupen64plus-core/src/main/main.c @@ -722,7 +722,7 @@ void new_vi(void) /********************************************************************************************************* * emulation thread - runs the core */ -m64p_error main_run(void) +m64p_error main_run(void (*startcb)(void)) { /* take the r4300 emulator mode from the config file at this point and cache it in a global variable */ r4300emu = ConfigGetParamInt(g_CoreConfig, "R4300Emulator"); @@ -790,7 +790,7 @@ m64p_error main_run(void) /* call r4300 CPU core and run the game */ r4300_reset_hard(); r4300_reset_soft(); - r4300_execute(); + r4300_execute(startcb); /* now begin to shut down */ #ifdef WITH_LIRC diff --git a/libmupen64plus/mupen64plus-core/src/main/main.h b/libmupen64plus/mupen64plus-core/src/main/main.h index 295c8e5fc4..d585319a36 100644 --- a/libmupen64plus/mupen64plus-core/src/main/main.h +++ b/libmupen64plus/mupen64plus-core/src/main/main.h @@ -43,7 +43,7 @@ void new_vi(void); int main_set_core_defaults(void); void main_message(m64p_msg_level level, unsigned int osd_corner, const char *format, ...); -m64p_error main_run(void); +m64p_error main_run(void (*startcb)(void)); void main_stop(void); void main_toggle_pause(void); void main_advance_one(void); diff --git a/libmupen64plus/mupen64plus-core/src/r4300/r4300.c b/libmupen64plus/mupen64plus-core/src/r4300/r4300.c index 88bd347b5a..7d1ae69e80 100644 --- a/libmupen64plus/mupen64plus-core/src/r4300/r4300.c +++ b/libmupen64plus/mupen64plus-core/src/r4300/r4300.c @@ -975,7 +975,7 @@ static void dynarec_setup_code(void) } #endif -void r4300_execute(void) +void r4300_execute(void (*startcb)(void)) { #if defined(COUNT_INSTR) || (defined(DYNAREC) && defined(PROFILE_R4300)) unsigned int i; @@ -999,6 +999,9 @@ void r4300_execute(void) next_interupt = 624999; init_interupt(); + if (startcb) + startcb(); + // now that everything has been set up, we stop here to wait for the first frame WaitForSingleObject(rompausesem, INFINITE); diff --git a/libmupen64plus/mupen64plus-core/src/r4300/r4300.h b/libmupen64plus/mupen64plus-core/src/r4300/r4300.h index b06564b66e..154de76fa7 100644 --- a/libmupen64plus/mupen64plus-core/src/r4300/r4300.h +++ b/libmupen64plus/mupen64plus-core/src/r4300/r4300.h @@ -56,7 +56,7 @@ void init_blocks(void); void free_blocks(void); void r4300_reset_hard(void); void r4300_reset_soft(void); -void r4300_execute(void); +void r4300_execute(void (*startcb)(void)); void pure_interpreter(void); void compare_core(void); void jump_to_func(void); diff --git a/libmupen64plus/mupen64plus-video-rice/src/Video.cpp b/libmupen64plus/mupen64plus-video-rice/src/Video.cpp index 0ba70237de..da0c1aaa15 100644 --- a/libmupen64plus/mupen64plus-video-rice/src/Video.cpp +++ b/libmupen64plus/mupen64plus-video-rice/src/Video.cpp @@ -936,7 +936,7 @@ EXPORT void CALL ReadScreen2(void *dest, int *width, int *height, int bFront) else glReadBuffer( GL_BACK ); glReadPixels( 0, 0, windowSetting.uDisplayWidth, windowSetting.uDisplayHeight, - GL_RGB, GL_UNSIGNED_BYTE, dest ); + GL_BGRA, GL_UNSIGNED_BYTE, dest ); glReadBuffer( oldMode ); #endif }