2016-01-27 09:11:59 +00:00
|
|
|
#include "stdafx.h"
|
2022-10-10 00:22:17 +00:00
|
|
|
|
|
|
|
#include "GFXPlugin.h"
|
2016-01-27 09:11:59 +00:00
|
|
|
#include <Project64-core/N64System/Mips/MemoryVirtualMem.h>
|
2021-04-14 05:34:15 +00:00
|
|
|
#include <Project64-core/N64System/Mips/Register.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/N64System/N64Disk.h>
|
|
|
|
#include <Project64-core/N64System/N64Rom.h>
|
2021-04-14 05:34:15 +00:00
|
|
|
#include <Project64-core/N64System/N64System.h>
|
2022-10-10 00:22:17 +00:00
|
|
|
#include <Project64-core/N64System/SystemGlobals.h>
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
CGfxPlugin::CGfxPlugin() :
|
2022-06-27 10:02:38 +00:00
|
|
|
CaptureScreen(nullptr),
|
|
|
|
ChangeWindow(nullptr),
|
|
|
|
DrawScreen(nullptr),
|
|
|
|
DrawStatus(nullptr),
|
|
|
|
MoveScreen(nullptr),
|
|
|
|
ProcessDList(nullptr),
|
|
|
|
ProcessRDPList(nullptr),
|
|
|
|
ShowCFB(nullptr),
|
|
|
|
UpdateScreen(nullptr),
|
|
|
|
ViStatusChanged(nullptr),
|
|
|
|
ViWidthChanged(nullptr),
|
|
|
|
SoftReset(nullptr),
|
|
|
|
GetRomBrowserMenu(nullptr),
|
|
|
|
OnRomBrowserMenuItem(nullptr),
|
|
|
|
GetDebugInfo(nullptr),
|
|
|
|
InitiateDebugger(nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));
|
|
|
|
}
|
|
|
|
|
|
|
|
CGfxPlugin::~CGfxPlugin()
|
|
|
|
{
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Start");
|
2021-04-12 11:35:39 +00:00
|
|
|
Close(nullptr);
|
2016-01-27 09:11:59 +00:00
|
|
|
UnloadPlugin();
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CGfxPlugin::LoadFunctions(void)
|
|
|
|
{
|
|
|
|
// Find entries for functions in DLL
|
2022-10-10 00:22:17 +00:00
|
|
|
int32_t(CALL * InitiateGFX)(void * Gfx_Info);
|
2016-01-27 09:11:59 +00:00
|
|
|
LoadFunction(InitiateGFX);
|
|
|
|
LoadFunction(ChangeWindow);
|
|
|
|
LoadFunction(DrawScreen);
|
|
|
|
LoadFunction(MoveScreen);
|
|
|
|
LoadFunction(ProcessDList);
|
|
|
|
LoadFunction(UpdateScreen);
|
|
|
|
LoadFunction(ViStatusChanged);
|
|
|
|
LoadFunction(ViWidthChanged);
|
|
|
|
LoadFunction(SoftReset);
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef ANDROID
|
|
|
|
LoadFunction(SurfaceCreated);
|
|
|
|
LoadFunction(SurfaceChanged);
|
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Version 0x104 functions
|
2016-01-27 09:11:59 +00:00
|
|
|
_LoadFunction("DrawFullScreenStatus", DrawStatus);
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// ROM browser
|
2016-01-27 09:11:59 +00:00
|
|
|
LoadFunction(GetRomBrowserMenu);
|
|
|
|
LoadFunction(OnRomBrowserMenuItem);
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Make sure DLL had all needed functions
|
2022-10-10 00:22:17 +00:00
|
|
|
if (ChangeWindow == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (DrawScreen == nullptr)
|
|
|
|
{
|
|
|
|
DrawScreen = DummyDrawScreen;
|
|
|
|
}
|
|
|
|
if (InitiateGFX == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (MoveScreen == nullptr)
|
|
|
|
{
|
|
|
|
MoveScreen = DummyMoveScreen;
|
|
|
|
}
|
|
|
|
if (ProcessDList == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (UpdateScreen == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ViStatusChanged == nullptr)
|
|
|
|
{
|
|
|
|
ViStatusChanged = DummyViStatusChanged;
|
|
|
|
}
|
|
|
|
if (ViWidthChanged == nullptr)
|
|
|
|
{
|
|
|
|
ViWidthChanged = DummyViWidthChanged;
|
|
|
|
}
|
|
|
|
if (SoftReset == nullptr)
|
|
|
|
{
|
|
|
|
SoftReset = DummySoftReset;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
if (m_PluginInfo.Version >= 0x0103)
|
|
|
|
{
|
|
|
|
LoadFunction(ProcessRDPList);
|
|
|
|
LoadFunction(CaptureScreen);
|
|
|
|
LoadFunction(ShowCFB);
|
|
|
|
LoadFunction(GetDebugInfo);
|
|
|
|
_LoadFunction("InitiateGFXDebugger", InitiateDebugger);
|
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
if (ProcessRDPList == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (CaptureScreen == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (ShowCFB == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_PluginInfo.Version >= 0x0104)
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
if (PluginOpened == nullptr)
|
|
|
|
{
|
|
|
|
UnloadPlugin();
|
|
|
|
return false;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (GetDebugInfo != nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
|
|
|
GetDebugInfo(&m_GFXDebug);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CGfxPlugin::Initiate(CN64System * System, RenderWindow * Window)
|
|
|
|
{
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Start");
|
2016-01-27 09:11:59 +00:00
|
|
|
if (m_Initialized)
|
|
|
|
{
|
2016-04-18 09:38:20 +00:00
|
|
|
Close(Window);
|
2017-01-23 06:56:56 +00:00
|
|
|
if (PluginOpened)
|
|
|
|
{
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "Before plugin opened");
|
2017-01-23 06:56:56 +00:00
|
|
|
PluginOpened();
|
2021-05-18 11:51:36 +00:00
|
|
|
WriteTrace(PluginTraceType(), TraceDebug, "After plugin opened");
|
2017-01-23 06:56:56 +00:00
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2022-10-10 00:22:17 +00:00
|
|
|
void * hWnd; // Render window
|
|
|
|
void * hStatusBar; // If render window does not have a status bar then this is NULL
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
int32_t MemoryBswaped; // If this is set to TRUE, then the memory has been pre-bswap'd on a DWORD (32-bit) boundary
|
2016-01-27 09:11:59 +00:00
|
|
|
// eg. the first 8 bytes are stored like this:
|
2021-05-18 11:51:36 +00:00
|
|
|
// 4 3 2 1 8 7 6 5
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
uint8_t * HEADER; // This is the ROM header (first 40h bytes of the ROM)
|
2021-05-18 11:51:36 +00:00
|
|
|
// This will be in the same memory format as the rest of the memory
|
2016-01-27 09:11:59 +00:00
|
|
|
uint8_t * RDRAM;
|
|
|
|
uint8_t * DMEM;
|
|
|
|
uint8_t * IMEM;
|
|
|
|
|
|
|
|
uint32_t * MI__INTR_REG;
|
|
|
|
|
|
|
|
uint32_t * DPC__START_REG;
|
|
|
|
uint32_t * DPC__END_REG;
|
|
|
|
uint32_t * DPC__CURRENT_REG;
|
|
|
|
uint32_t * DPC__STATUS_REG;
|
|
|
|
uint32_t * DPC__CLOCK_REG;
|
|
|
|
uint32_t * DPC__BUFBUSY_REG;
|
|
|
|
uint32_t * DPC__PIPEBUSY_REG;
|
|
|
|
uint32_t * DPC__TMEM_REG;
|
|
|
|
|
|
|
|
uint32_t * VI__STATUS_REG;
|
|
|
|
uint32_t * VI__ORIGIN_REG;
|
|
|
|
uint32_t * VI__WIDTH_REG;
|
|
|
|
uint32_t * VI__INTR_REG;
|
|
|
|
uint32_t * VI__V_CURRENT_LINE_REG;
|
|
|
|
uint32_t * VI__TIMING_REG;
|
|
|
|
uint32_t * VI__V_SYNC_REG;
|
|
|
|
uint32_t * VI__H_SYNC_REG;
|
|
|
|
uint32_t * VI__LEAP_REG;
|
|
|
|
uint32_t * VI__H_START_REG;
|
|
|
|
uint32_t * VI__V_START_REG;
|
|
|
|
uint32_t * VI__V_BURST_REG;
|
|
|
|
uint32_t * VI__X_SCALE_REG;
|
|
|
|
uint32_t * VI__Y_SCALE_REG;
|
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
void(CALL * CheckInterrupts)(void);
|
2016-04-18 09:38:20 +00:00
|
|
|
#ifdef ANDROID
|
2022-10-10 00:22:17 +00:00
|
|
|
void(CALL * SwapBuffers)(void);
|
2016-04-18 09:38:20 +00:00
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
} GFX_INFO;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// Get function from DLL
|
2022-10-10 00:22:17 +00:00
|
|
|
int32_t(CALL * InitiateGFX)(GFX_INFO Gfx_Info);
|
2016-02-01 06:33:19 +00:00
|
|
|
_LoadFunction("InitiateGFX", InitiateGFX);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (InitiateGFX == nullptr)
|
2016-02-01 06:33:19 +00:00
|
|
|
{
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Failed to find InitiateGFX");
|
2016-02-01 06:33:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-01-27 09:11:59 +00:00
|
|
|
|
2022-10-10 00:22:17 +00:00
|
|
|
GFX_INFO Info = {0};
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
Info.MemoryBswaped = true;
|
2016-04-21 04:47:20 +00:00
|
|
|
#if defined(ANDROID) || defined(__ANDROID__)
|
2016-04-18 09:38:20 +00:00
|
|
|
Info.SwapBuffers = SwapBuffers;
|
2016-04-21 04:47:20 +00:00
|
|
|
#endif
|
2021-04-12 11:35:39 +00:00
|
|
|
Info.hWnd = nullptr;
|
|
|
|
Info.hStatusBar = nullptr;
|
2016-04-21 04:47:20 +00:00
|
|
|
#ifdef _WIN32
|
2021-04-12 11:35:39 +00:00
|
|
|
if (Window != nullptr)
|
2016-04-21 04:47:20 +00:00
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
Info.hWnd = Window->GetWindowHandle();
|
2016-04-21 04:47:20 +00:00
|
|
|
Info.hStatusBar = Window->GetStatusBar();
|
|
|
|
}
|
2016-04-18 09:38:20 +00:00
|
|
|
#endif
|
2016-01-27 09:11:59 +00:00
|
|
|
Info.CheckInterrupts = DummyCheckInterrupts;
|
|
|
|
|
2021-05-18 11:51:36 +00:00
|
|
|
// We are initializing the plugin before any ROM is loaded so we do not have any correct
|
|
|
|
// parameters here, it's just needed so we can config the DLL
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "System = %X", System);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (System == nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2016-06-16 10:59:13 +00:00
|
|
|
static uint8_t Buffer[100];
|
|
|
|
static uint32_t Value = 0;
|
2016-01-27 09:11:59 +00:00
|
|
|
|
|
|
|
Info.HEADER = Buffer;
|
|
|
|
Info.RDRAM = Buffer;
|
|
|
|
Info.DMEM = Buffer;
|
|
|
|
Info.IMEM = Buffer;
|
|
|
|
Info.MI__INTR_REG = &Value;
|
|
|
|
Info.VI__STATUS_REG = &Value;
|
|
|
|
Info.VI__ORIGIN_REG = &Value;
|
|
|
|
Info.VI__WIDTH_REG = &Value;
|
|
|
|
Info.VI__INTR_REG = &Value;
|
|
|
|
Info.VI__V_CURRENT_LINE_REG = &Value;
|
|
|
|
Info.VI__TIMING_REG = &Value;
|
|
|
|
Info.VI__V_SYNC_REG = &Value;
|
|
|
|
Info.VI__H_SYNC_REG = &Value;
|
|
|
|
Info.VI__LEAP_REG = &Value;
|
|
|
|
Info.VI__H_START_REG = &Value;
|
|
|
|
Info.VI__V_START_REG = &Value;
|
|
|
|
Info.VI__V_BURST_REG = &Value;
|
|
|
|
Info.VI__X_SCALE_REG = &Value;
|
|
|
|
Info.VI__Y_SCALE_REG = &Value;
|
|
|
|
}
|
|
|
|
// Send initialization information to the DLL
|
|
|
|
else
|
|
|
|
{
|
2016-08-07 08:27:14 +00:00
|
|
|
CMipsMemoryVM & MMU = System->m_MMU_VM;
|
|
|
|
CRegisters & Reg = System->m_Reg;
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
if (g_Rom->IsLoadedRomDDIPL() && g_Disk != nullptr)
|
2019-01-26 13:31:24 +00:00
|
|
|
Info.HEADER = g_Disk->GetDiskHeader();
|
|
|
|
else
|
|
|
|
Info.HEADER = g_Rom->GetRomAddress();
|
2016-08-07 08:27:14 +00:00
|
|
|
Info.RDRAM = MMU.Rdram();
|
|
|
|
Info.DMEM = MMU.Dmem();
|
|
|
|
Info.IMEM = MMU.Imem();
|
|
|
|
Info.MI__INTR_REG = &Reg.m_GfxIntrReg;
|
|
|
|
Info.DPC__START_REG = &Reg.DPC_START_REG;
|
|
|
|
Info.DPC__END_REG = &Reg.DPC_END_REG;
|
|
|
|
Info.DPC__CURRENT_REG = &Reg.DPC_CURRENT_REG;
|
|
|
|
Info.DPC__STATUS_REG = &Reg.DPC_STATUS_REG;
|
|
|
|
Info.DPC__CLOCK_REG = &Reg.DPC_CLOCK_REG;
|
|
|
|
Info.DPC__BUFBUSY_REG = &Reg.DPC_BUFBUSY_REG;
|
|
|
|
Info.DPC__PIPEBUSY_REG = &Reg.DPC_PIPEBUSY_REG;
|
|
|
|
Info.DPC__TMEM_REG = &Reg.DPC_TMEM_REG;
|
|
|
|
Info.VI__STATUS_REG = &Reg.VI_STATUS_REG;
|
|
|
|
Info.VI__ORIGIN_REG = &Reg.VI_ORIGIN_REG;
|
|
|
|
Info.VI__WIDTH_REG = &Reg.VI_WIDTH_REG;
|
|
|
|
Info.VI__INTR_REG = &Reg.VI_INTR_REG;
|
|
|
|
Info.VI__V_CURRENT_LINE_REG = &Reg.VI_CURRENT_REG;
|
|
|
|
Info.VI__TIMING_REG = &Reg.VI_TIMING_REG;
|
|
|
|
Info.VI__V_SYNC_REG = &Reg.VI_V_SYNC_REG;
|
|
|
|
Info.VI__H_SYNC_REG = &Reg.VI_H_SYNC_REG;
|
|
|
|
Info.VI__LEAP_REG = &Reg.VI_LEAP_REG;
|
|
|
|
Info.VI__H_START_REG = &Reg.VI_H_START_REG;
|
|
|
|
Info.VI__V_START_REG = &Reg.VI_V_START_REG;
|
|
|
|
Info.VI__V_BURST_REG = &Reg.VI_V_BURST_REG;
|
|
|
|
Info.VI__X_SCALE_REG = &Reg.VI_X_SCALE_REG;
|
|
|
|
Info.VI__Y_SCALE_REG = &Reg.VI_Y_SCALE_REG;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Calling InitiateGFX");
|
2016-01-27 09:11:59 +00:00
|
|
|
m_Initialized = InitiateGFX(Info) != 0;
|
|
|
|
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Done (res: %s)", m_Initialized ? "true" : "false");
|
2016-01-27 09:11:59 +00:00
|
|
|
return m_Initialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CGfxPlugin::UnloadPluginDetails(void)
|
|
|
|
{
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Start");
|
2021-04-12 11:35:39 +00:00
|
|
|
if (m_LibHandle != nullptr)
|
2016-01-27 09:11:59 +00:00
|
|
|
{
|
2021-04-21 00:33:04 +00:00
|
|
|
DynamicLibraryClose(m_LibHandle);
|
2021-04-12 11:35:39 +00:00
|
|
|
m_LibHandle = nullptr;
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
memset(&m_GFXDebug, 0, sizeof(m_GFXDebug));
|
|
|
|
|
2021-04-12 11:35:39 +00:00
|
|
|
ChangeWindow = nullptr;
|
|
|
|
GetDebugInfo = nullptr;
|
|
|
|
DrawScreen = nullptr;
|
|
|
|
DrawStatus = nullptr;
|
|
|
|
InitiateDebugger = nullptr;
|
|
|
|
MoveScreen = nullptr;
|
|
|
|
ProcessDList = nullptr;
|
|
|
|
ProcessRDPList = nullptr;
|
|
|
|
ShowCFB = nullptr;
|
|
|
|
UpdateScreen = nullptr;
|
|
|
|
ViStatusChanged = nullptr;
|
|
|
|
ViWidthChanged = nullptr;
|
|
|
|
GetRomBrowserMenu = nullptr;
|
|
|
|
OnRomBrowserMenuItem = nullptr;
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Done");
|
2016-01-27 09:11:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CGfxPlugin::ProcessMenuItem(int32_t id)
|
|
|
|
{
|
|
|
|
if (m_GFXDebug.ProcessMenuItem)
|
|
|
|
{
|
|
|
|
m_GFXDebug.ProcessMenuItem(id);
|
|
|
|
}
|
2016-04-18 09:38:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ANDROID
|
|
|
|
void CGfxPlugin::SwapBuffers(void)
|
|
|
|
{
|
2021-04-12 11:35:39 +00:00
|
|
|
RenderWindow * render = g_Plugins ? g_Plugins->MainWindow() : nullptr;
|
2022-10-10 00:22:17 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Start (render: %p)", render);
|
2021-04-12 11:35:39 +00:00
|
|
|
if (render != nullptr)
|
2016-04-18 09:38:20 +00:00
|
|
|
{
|
|
|
|
render->SwapWindow();
|
|
|
|
}
|
2022-06-27 10:02:38 +00:00
|
|
|
WriteTrace(TraceVideoPlugin, TraceDebug, "Done");
|
2016-04-18 09:38:20 +00:00
|
|
|
}
|
|
|
|
#endif
|