1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-07-02 09:03:37 +00:00

Implement MupenPlus2.0 API functions

This commit is contained in:
Sergey Lipskiy 2013-11-27 15:39:53 +07:00
parent 85a743adaf
commit 5d81e4f2f3
2 changed files with 298 additions and 180 deletions

View File

@ -4,12 +4,12 @@
# include <process.h>
#else
# include "winlnxdefs.h"
#include <dlfcn.h>
#endif
#include <GL/gl.h>
#include <GL/glu.h>
#include "GLideN64.h"
#include "Debug.h"
#include "ZilmarGFX_1_3.h"
#include "OpenGL.h"
#include "N64.h"
#include "RSP.h"
@ -19,6 +19,9 @@
#include "Textures.h"
#include "Combiner.h"
#ifndef MUPENPLUSAPI
#include "ZilmarGFX_1_3.h"
#ifndef __LINUX__
HWND hWnd;
HWND hStatusBar;
@ -83,80 +86,6 @@ EXPORT void CALL CaptureScreen ( char * Directory )
#endif
}
EXPORT void CALL ChangeWindow (void)
{
#ifdef RSPTHREAD
// Textures seem to get corrupted when changing video modes (at least on my Radeon), so destroy them
SetEvent( RSP.threadMsg[RSPMSG_DESTROYTEXTURES] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
if (!OGL.fullscreen)
{
DEVMODE fullscreenMode;
memset( &fullscreenMode, 0, sizeof(DEVMODE) );
fullscreenMode.dmSize = sizeof(DEVMODE);
fullscreenMode.dmPelsWidth = OGL.fullscreenWidth;
fullscreenMode.dmPelsHeight = OGL.fullscreenHeight;
fullscreenMode.dmBitsPerPel = OGL.fullscreenBits;
fullscreenMode.dmDisplayFrequency = OGL.fullscreenRefresh;
fullscreenMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
if (ChangeDisplaySettings( &fullscreenMode, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL)
{
MessageBox( NULL, "Failed to change display mode", pluginName, MB_ICONERROR | MB_OK );
return;
}
ShowCursor( FALSE );
windowedMenu = GetMenu( hWnd );
if (windowedMenu)
SetMenu( hWnd, NULL );
if (hStatusBar)
ShowWindow( hStatusBar, SW_HIDE );
windowedExStyle = GetWindowLong( hWnd, GWL_EXSTYLE );
windowedStyle = GetWindowLong( hWnd, GWL_STYLE );
SetWindowLong( hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST );
SetWindowLong( hWnd, GWL_STYLE, WS_POPUP );
GetWindowRect( hWnd, &windowedRect );
OGL.fullscreen = TRUE;
OGL_ResizeWindow();
}
else
{
ChangeDisplaySettings( NULL, 0 );
ShowCursor( TRUE );
if (windowedMenu)
SetMenu( hWnd, windowedMenu );
if (hStatusBar)
ShowWindow( hStatusBar, SW_SHOW );
SetWindowLong( hWnd, GWL_STYLE, windowedStyle );
SetWindowLong( hWnd, GWL_EXSTYLE, windowedExStyle );
SetWindowPos( hWnd, NULL, windowedRect.left, windowedRect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE );
OGL.fullscreen = FALSE;
OGL_ResizeWindow();
}
SetEvent( RSP.threadMsg[RSPMSG_INITTEXTURES] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
#else // RSPTHREAD
# ifdef __LINUX__
SDL_WM_ToggleFullScreen( OGL.hScreen );
# endif // __LINUX__
#endif // !RSPTHREAD
}
EXPORT void CALL CloseDLL (void)
{
}
@ -204,99 +133,6 @@ BOOL CALLBACK FindToolBarProc( HWND hWnd, LPARAM lParam )
}
#endif // !__LINUX__
EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info)
{
#ifndef __LINUX__
hWnd = Gfx_Info.hWnd;
hStatusBar = Gfx_Info.hStatusBar;
hToolBar = NULL;
EnumChildWindows( hWnd, FindToolBarProc,0 );
#else // !__LINUX__
Config_LoadConfig();
OGL.hScreen = NULL;
# ifdef RSPTHREAD
RSP.thread = NULL;
# endif
#endif // __LINUX__
DMEM = Gfx_Info.DMEM;
IMEM = Gfx_Info.IMEM;
RDRAM = Gfx_Info.RDRAM;
REG.MI_INTR = Gfx_Info.MI_INTR_REG;
REG.DPC_START = Gfx_Info.DPC_START_REG;
REG.DPC_END = Gfx_Info.DPC_END_REG;
REG.DPC_CURRENT = Gfx_Info.DPC_CURRENT_REG;
REG.DPC_STATUS = Gfx_Info.DPC_STATUS_REG;
REG.DPC_CLOCK = Gfx_Info.DPC_CLOCK_REG;
REG.DPC_BUFBUSY = Gfx_Info.DPC_BUFBUSY_REG;
REG.DPC_PIPEBUSY = Gfx_Info.DPC_PIPEBUSY_REG;
REG.DPC_TMEM = Gfx_Info.DPC_TMEM_REG;
REG.VI_STATUS = Gfx_Info.VI_STATUS_REG;
REG.VI_ORIGIN = Gfx_Info.VI_ORIGIN_REG;
REG.VI_WIDTH = Gfx_Info.VI_WIDTH_REG;
REG.VI_INTR = Gfx_Info.VI_INTR_REG;
REG.VI_V_CURRENT_LINE = Gfx_Info.VI_V_CURRENT_LINE_REG;
REG.VI_TIMING = Gfx_Info.VI_TIMING_REG;
REG.VI_V_SYNC = Gfx_Info.VI_V_SYNC_REG;
REG.VI_H_SYNC = Gfx_Info.VI_H_SYNC_REG;
REG.VI_LEAP = Gfx_Info.VI_LEAP_REG;
REG.VI_H_START = Gfx_Info.VI_H_START_REG;
REG.VI_V_START = Gfx_Info.VI_V_START_REG;
REG.VI_V_BURST = Gfx_Info.VI_V_BURST_REG;
REG.VI_X_SCALE = Gfx_Info.VI_X_SCALE_REG;
REG.VI_Y_SCALE = Gfx_Info.VI_Y_SCALE_REG;
CheckInterrupts = Gfx_Info.CheckInterrupts;
return TRUE;
}
EXPORT void CALL MoveScreen (int xpos, int ypos)
{
}
EXPORT void CALL ProcessDList(void)
{
#ifdef RSPTHREAD
if (RSP.thread)
{
SetEvent( RSP.threadMsg[RSPMSG_PROCESSDLIST] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
}
#else
RSP_ProcessDList();
#endif
}
EXPORT void CALL ProcessRDPList(void)
{
//*REG.DPC_CURRENT = *REG.DPC_START;
/* RSP.PCi = 0;
RSP.PC[RSP.PCi] = *REG.DPC_CURRENT;
RSP.halt = FALSE;
while (RSP.PC[RSP.PCi] < *REG.DPC_END)
{
RSP.cmd0 = *(DWORD*)&RDRAM[RSP.PC[RSP.PCi]];
RSP.cmd1 = *(DWORD*)&RDRAM[RSP.PC[RSP.PCi] + 4];
RSP.PC[RSP.PCi] += 8;
/* if ((RSP.cmd0 >> 24) == 0xE9)
{
*REG.MI_INTR |= MI_INTR_DP;
CheckInterrupts();
}
if ((RSP.cmd0 >> 24) == 0xCD)
RSP.cmd0 = RSP.cmd0;
GFXOp[RSP.cmd0 >> 24]();*/
//*REG.DPC_CURRENT += 8;
// }
}
EXPORT void CALL RomClosed (void)
{
#ifdef RSPTHREAD
@ -405,3 +241,234 @@ EXPORT void CALL ReadScreen (void **dest, long *width, long *height)
OGL_ReadScreen( dest, width, height );
}
#else // MUPENPLUSAPI
ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath = NULL;
void (*CheckInterrupts)( void );
void (*renderCallback)() = NULL;
extern "C" {
EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handle CoreLibHandle, void *Context, void (*DebugCallback)(void *, int, const char *))
{
ConfigGetSharedDataFilepath = (ptr_ConfigGetSharedDataFilepath) dlsym(CoreLibHandle, "ConfigGetSharedDataFilepath");
return M64ERR_SUCCESS;
}
EXPORT m64p_error CALL PluginShutdown(void)
{
OGL_Stop();
return M64ERR_SUCCESS;
}
EXPORT m64p_error CALL PluginGetVersion(m64p_plugin_type *PluginType,
int *PluginVersion, int *APIVersion, const char **PluginNamePtr,
int *Capabilities)
{
/* set version info */
if (PluginType != NULL)
*PluginType = M64PLUGIN_GFX;
if (PluginVersion != NULL)
*PluginVersion = PLUGIN_VERSION;
if (APIVersion != NULL)
*APIVersion = PLUGIN_API_VERSION;
if (PluginNamePtr != NULL)
*PluginNamePtr = PLUGIN_NAME;
if (Capabilities != NULL)
{
*Capabilities = 0;
}
return M64ERR_SUCCESS;
}
EXPORT void CALL ResizeVideoOutput(int Width, int Height)
{
}
} // extern "C"
#endif // MUPENPLUSAPI
//----------Common-------------------//
extern "C" {
EXPORT void CALL ChangeWindow (void)
{
#ifdef RSPTHREAD
// Textures seem to get corrupted when changing video modes (at least on my Radeon), so destroy them
SetEvent( RSP.threadMsg[RSPMSG_DESTROYTEXTURES] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
if (!OGL.fullscreen)
{
DEVMODE fullscreenMode;
memset( &fullscreenMode, 0, sizeof(DEVMODE) );
fullscreenMode.dmSize = sizeof(DEVMODE);
fullscreenMode.dmPelsWidth = OGL.fullscreenWidth;
fullscreenMode.dmPelsHeight = OGL.fullscreenHeight;
fullscreenMode.dmBitsPerPel = OGL.fullscreenBits;
fullscreenMode.dmDisplayFrequency = OGL.fullscreenRefresh;
fullscreenMode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY;
if (ChangeDisplaySettings( &fullscreenMode, CDS_FULLSCREEN ) != DISP_CHANGE_SUCCESSFUL)
{
MessageBox( NULL, "Failed to change display mode", pluginName, MB_ICONERROR | MB_OK );
return;
}
ShowCursor( FALSE );
windowedMenu = GetMenu( hWnd );
if (windowedMenu)
SetMenu( hWnd, NULL );
if (hStatusBar)
ShowWindow( hStatusBar, SW_HIDE );
windowedExStyle = GetWindowLong( hWnd, GWL_EXSTYLE );
windowedStyle = GetWindowLong( hWnd, GWL_STYLE );
SetWindowLong( hWnd, GWL_EXSTYLE, WS_EX_APPWINDOW | WS_EX_TOPMOST );
SetWindowLong( hWnd, GWL_STYLE, WS_POPUP );
GetWindowRect( hWnd, &windowedRect );
OGL.fullscreen = TRUE;
OGL_ResizeWindow();
}
else
{
ChangeDisplaySettings( NULL, 0 );
ShowCursor( TRUE );
if (windowedMenu)
SetMenu( hWnd, windowedMenu );
if (hStatusBar)
ShowWindow( hStatusBar, SW_SHOW );
SetWindowLong( hWnd, GWL_STYLE, windowedStyle );
SetWindowLong( hWnd, GWL_EXSTYLE, windowedExStyle );
SetWindowPos( hWnd, NULL, windowedRect.left, windowedRect.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE );
OGL.fullscreen = FALSE;
OGL_ResizeWindow();
}
SetEvent( RSP.threadMsg[RSPMSG_INITTEXTURES] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
#else // RSPTHREAD
# ifdef __LINUX__
SDL_WM_ToggleFullScreen( OGL.hScreen );
# endif // __LINUX__
#endif // !RSPTHREAD
}
EXPORT void CALL MoveScreen (int xpos, int ypos)
{
}
EXPORT BOOL CALL InitiateGFX (GFX_INFO Gfx_Info)
{
DMEM = Gfx_Info.DMEM;
IMEM = Gfx_Info.IMEM;
RDRAM = Gfx_Info.RDRAM;
REG.MI_INTR = Gfx_Info.MI_INTR_REG;
REG.DPC_START = Gfx_Info.DPC_START_REG;
REG.DPC_END = Gfx_Info.DPC_END_REG;
REG.DPC_CURRENT = Gfx_Info.DPC_CURRENT_REG;
REG.DPC_STATUS = Gfx_Info.DPC_STATUS_REG;
REG.DPC_CLOCK = Gfx_Info.DPC_CLOCK_REG;
REG.DPC_BUFBUSY = Gfx_Info.DPC_BUFBUSY_REG;
REG.DPC_PIPEBUSY = Gfx_Info.DPC_PIPEBUSY_REG;
REG.DPC_TMEM = Gfx_Info.DPC_TMEM_REG;
REG.VI_STATUS = Gfx_Info.VI_STATUS_REG;
REG.VI_ORIGIN = Gfx_Info.VI_ORIGIN_REG;
REG.VI_WIDTH = Gfx_Info.VI_WIDTH_REG;
REG.VI_INTR = Gfx_Info.VI_INTR_REG;
REG.VI_V_CURRENT_LINE = Gfx_Info.VI_V_CURRENT_LINE_REG;
REG.VI_TIMING = Gfx_Info.VI_TIMING_REG;
REG.VI_V_SYNC = Gfx_Info.VI_V_SYNC_REG;
REG.VI_H_SYNC = Gfx_Info.VI_H_SYNC_REG;
REG.VI_LEAP = Gfx_Info.VI_LEAP_REG;
REG.VI_H_START = Gfx_Info.VI_H_START_REG;
REG.VI_V_START = Gfx_Info.VI_V_START_REG;
REG.VI_V_BURST = Gfx_Info.VI_V_BURST_REG;
REG.VI_X_SCALE = Gfx_Info.VI_X_SCALE_REG;
REG.VI_Y_SCALE = Gfx_Info.VI_Y_SCALE_REG;
CheckInterrupts = Gfx_Info.CheckInterrupts;
#ifndef MUPENPLUSAPI
#ifndef __LINUX__
hWnd = Gfx_Info.hWnd;
hStatusBar = Gfx_Info.hStatusBar;
hToolBar = NULL;
EnumChildWindows( hWnd, FindToolBarProc,0 );
#else // !__LINUX__
Config_LoadConfig();
OGL.hScreen = NULL;
# ifdef RSPTHREAD
RSP.thread = NULL;
# endif
#endif // __LINUX__
#else // MUPENPLUSAPI
Config_LoadConfig();
Config_LoadRomConfig(Gfx_Info.HEADER);
#endif // MUPENPLUSAPI
//OGL_Start();
return TRUE;
}
EXPORT void CALL ProcessDList(void)
{
#ifdef RSPTHREAD
if (RSP.thread)
{
SetEvent( RSP.threadMsg[RSPMSG_PROCESSDLIST] );
WaitForSingleObject( RSP.threadFinished, INFINITE );
}
#else
RSP_ProcessDList();
#endif
}
EXPORT void CALL ProcessRDPList(void)
{
//*REG.DPC_CURRENT = *REG.DPC_START;
/* RSP.PCi = 0;
RSP.PC[RSP.PCi] = *REG.DPC_CURRENT;
RSP.halt = FALSE;
while (RSP.PC[RSP.PCi] < *REG.DPC_END)
{
RSP.cmd0 = *(DWORD*)&RDRAM[RSP.PC[RSP.PCi]];
RSP.cmd1 = *(DWORD*)&RDRAM[RSP.PC[RSP.PCi] + 4];
RSP.PC[RSP.PCi] += 8;
/* if ((RSP.cmd0 >> 24) == 0xE9)
{
*REG.MI_INTR |= MI_INTR_DP;
CheckInterrupts();
}
if ((RSP.cmd0 >> 24) == 0xCD)
RSP.cmd0 = RSP.cmd0;
GFXOp[RSP.cmd0 >> 24]();*/
//*REG.DPC_CURRENT += 8;
// }
}
}

View File

@ -1,9 +1,15 @@
#ifndef GLN64_H
#define GLN64_H
#ifndef GLIDEN64_H
#define GLIDEN64_H
#ifndef MUPENPLUSAPI
#ifndef __LINUX__
#include <windows.h>
//#include <commctrl.h>
extern HWND hWnd;
extern HWND hStatusBar;
//HWND hFullscreen;
extern HWND hToolBar;
extern HINSTANCE hInstance;
#else
# include "winlnxdefs.h"
#endif
@ -11,18 +17,63 @@
//#define DEBUG
//#define RSPTHREAD
#ifndef __LINUX__
extern HWND hWnd;
//extern HWND hFullscreen;
extern HWND hStatusBar;
extern HWND hToolBar;
extern HINSTANCE hInstance;
#endif // !__LINUX__
extern char pluginName[];
extern char pluginName[];
extern void (*CheckInterrupts)( void );
extern char *screenDirectory;
#else // MUPENPLUSAPI
#include <stdio.h>
#include "m64p_config.h"
#include "m64p_vidext.h"
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))
#endif
//#define DEBUG
#define PLUGIN_NAME "GLideN64 alpha"
#define PLUGIN_VERSION 0x020000
#define VIDEO_PLUGIN_API_VERSION 0x020200
#define CONFIG_API_VERSION 0x020000
#define VIDEXT_API_VERSION 0x030000
/* definitions of pointers to Core config functions */
extern ptr_ConfigOpenSection ConfigOpenSection;
extern ptr_ConfigSetParameter ConfigSetParameter;
extern ptr_ConfigGetParameter ConfigGetParameter;
extern ptr_ConfigGetParameterHelp ConfigGetParameterHelp;
extern ptr_ConfigSetDefaultInt ConfigSetDefaultInt;
extern ptr_ConfigSetDefaultFloat ConfigSetDefaultFloat;
extern ptr_ConfigSetDefaultBool ConfigSetDefaultBool;
extern ptr_ConfigSetDefaultString ConfigSetDefaultString;
extern ptr_ConfigGetParamInt ConfigGetParamInt;
extern ptr_ConfigGetParamFloat ConfigGetParamFloat;
extern ptr_ConfigGetParamBool ConfigGetParamBool;
extern ptr_ConfigGetParamString ConfigGetParamString;
extern ptr_ConfigGetSharedDataFilepath ConfigGetSharedDataFilepath;
extern ptr_ConfigGetUserConfigPath ConfigGetUserConfigPath;
extern ptr_ConfigGetUserDataPath ConfigGetUserDataPath;
extern ptr_ConfigGetUserCachePath ConfigGetUserCachePath;
extern ptr_VidExt_Init CoreVideo_Init;
extern ptr_VidExt_Quit CoreVideo_Quit;
extern ptr_VidExt_ListFullscreenModes CoreVideo_ListFullscreenModes;
extern ptr_VidExt_SetVideoMode CoreVideo_SetVideoMode;
extern ptr_VidExt_SetCaption CoreVideo_SetCaption;
extern ptr_VidExt_ToggleFullScreen CoreVideo_ToggleFullScreen;
extern ptr_VidExt_ResizeWindow CoreVideo_ResizeWindow;
extern ptr_VidExt_GL_GetProcAddress CoreVideo_GL_GetProcAddress;
extern ptr_VidExt_GL_SetAttribute CoreVideo_GL_SetAttribute;
extern ptr_VidExt_GL_SwapBuffers CoreVideo_GL_SwapBuffers;
extern void (*CheckInterrupts)( void );
extern void (*renderCallback)();
#endif // MUPENPLUSAPI
#endif // GLIDEN64_H