FWnull reformat

This commit is contained in:
Clang Format 2016-08-24 23:14:01 +02:00 committed by Gregory Hainaut
parent b246d13bae
commit 67e7d63f0f
6 changed files with 328 additions and 317 deletions

View File

@ -25,55 +25,51 @@ PluginConf Ini;
void setLoggingState() void setLoggingState()
{ {
if (conf.Log) if (conf.Log) {
{ FWLog.WriteToConsole = true;
FWLog.WriteToConsole = true; FWLog.WriteToFile = true;
FWLog.WriteToFile = true; } else {
} FWLog.WriteToConsole = false;
else FWLog.WriteToFile = false;
{ }
FWLog.WriteToConsole = false;
FWLog.WriteToFile = false;
}
} }
EXPORT_C_(void) FWabout() EXPORT_C_(void)
FWabout()
{ {
SysMessage("FWnull: A simple null plugin."); SysMessage("FWnull: A simple null plugin.");
} }
EXPORT_C_(void) FWconfigure() EXPORT_C_(void)
FWconfigure()
{ {
LoadConfig(); LoadConfig();
PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log); PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log);
SaveConfig(); SaveConfig();
} }
void LoadConfig() void LoadConfig()
{ {
string IniPath = s_strIniPath + "/FWnull.ini"; string IniPath = s_strIniPath + "/FWnull.ini";
if (!Ini.Open(IniPath, READ_FILE)) if (!Ini.Open(IniPath, READ_FILE)) {
{ FWLog.WriteLn("Failed to open %s", IniPath.c_str());
FWLog.WriteLn("Failed to open %s", IniPath.c_str()); SaveConfig();
SaveConfig(); return;
return; }
}
conf.Log = Ini.ReadInt("logging", 0); conf.Log = Ini.ReadInt("logging", 0);
setLoggingState(); setLoggingState();
Ini.Close(); Ini.Close();
} }
void SaveConfig() void SaveConfig()
{ {
string IniPath = s_strIniPath + "/FWnull.ini"; string IniPath = s_strIniPath + "/FWnull.ini";
if (!Ini.Open(IniPath, WRITE_FILE)) if (!Ini.Open(IniPath, WRITE_FILE)) {
{ FWLog.WriteLn("Failed to open %s\n", IniPath.c_str());
FWLog.WriteLn("Failed to open %s\n", IniPath.c_str()); return;
return; }
}
Ini.WriteInt("logging", conf.Log); Ini.WriteInt("logging", conf.Log);
Ini.Close(); Ini.Close();
} }

View File

@ -15,7 +15,7 @@
void SaveConf(); void SaveConf();
void LoadConf(); void LoadConf();
void SysMessage(const char *fmt, ...); void SysMessage(const char* fmt, ...);
#define is_checked(main_widget, widget_name) (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)))) #define is_checked(main_widget, widget_name) (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name))))
#define set_checked(main_widget,widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state) #define set_checked(main_widget, widget_name, state) gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(lookup_widget(main_widget, widget_name)), state)

View File

@ -23,20 +23,20 @@ using namespace std;
#include "FW.h" #include "FW.h"
#include "svnrev.h" #include "svnrev.h"
const u8 version = PS2E_FW_VERSION; const u8 version = PS2E_FW_VERSION;
const u8 revision = 0; const u8 revision = 0;
const u8 build = 7; // increase that with each version const u8 build = 7; // increase that with each version
#ifdef _MSC_VER #ifdef _MSC_VER
#define snprintf sprintf_s #define snprintf sprintf_s
#endif #endif
static char libraryName[256]; static char libraryName[256];
string s_strIniPath="inis"; string s_strIniPath = "inis";
string s_strLogPath = "logs"; string s_strLogPath = "logs";
u8 phyregs[16]; u8 phyregs[16];
s8 *fwregs; s8* fwregs;
Config conf; Config conf;
PluginLog FWLog; PluginLog FWLog;
@ -44,259 +44,268 @@ void (*FWirq)();
void LogInit() void LogInit()
{ {
const std::string LogFile(s_strLogPath + "/FWnull.log"); const std::string LogFile(s_strLogPath + "/FWnull.log");
setLoggingState(); setLoggingState();
FWLog.Open(LogFile); FWLog.Open(LogFile);
} }
EXPORT_C_(void) FWsetLogDir(const char* dir) EXPORT_C_(void)
FWsetLogDir(const char* dir)
{ {
// Get the path to the log directory. // Get the path to the log directory.
s_strLogPath = (dir==NULL) ? "logs" : dir; s_strLogPath = (dir == NULL) ? "logs" : dir;
// Reload the log file after updated the path // Reload the log file after updated the path
FWLog.Close(); FWLog.Close();
LogInit(); LogInit();
} }
EXPORT_C_(u32) PS2EgetLibType() EXPORT_C_(u32)
PS2EgetLibType()
{ {
return PS2E_LT_FW; return PS2E_LT_FW;
} }
EXPORT_C_(char*) PS2EgetLibName() EXPORT_C_(char*)
PS2EgetLibName()
{ {
snprintf( libraryName, 255, "FWnull Driver %lld%s",SVN_REV, SVN_MODS ? "m" : ""); snprintf(libraryName, 255, "FWnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
return libraryName; return libraryName;
} }
EXPORT_C_(u32) PS2EgetLibVersion2(u32 type) EXPORT_C_(u32)
PS2EgetLibVersion2(u32 type)
{ {
return (version<<16) | (revision<<8) | build; return (version << 16) | (revision << 8) | build;
} }
EXPORT_C_(s32) FWinit() EXPORT_C_(s32)
FWinit()
{ {
LoadConfig(); LoadConfig();
LogInit(); LogInit();
FWLog.WriteLn("FWnull plugin version %d,%d", revision, build); FWLog.WriteLn("FWnull plugin version %d,%d", revision, build);
FWLog.WriteLn("Initializing FWnull"); FWLog.WriteLn("Initializing FWnull");
memset(phyregs, 0, sizeof(phyregs)); memset(phyregs, 0, sizeof(phyregs));
// Initializing our registers. // Initializing our registers.
fwregs = (s8*)calloc(0x10000,1); fwregs = (s8*)calloc(0x10000, 1);
if (fwregs == NULL) if (fwregs == NULL) {
{ FWLog.Message("Error allocating Memory");
FWLog.Message("Error allocating Memory"); return -1;
return -1; }
} return 0;
return 0;
} }
EXPORT_C_(void) FWshutdown() EXPORT_C_(void)
FWshutdown()
{ {
// Freeing the registers. // Freeing the registers.
free(fwregs); free(fwregs);
fwregs = NULL; fwregs = NULL;
FWLog.Close(); FWLog.Close();
} }
EXPORT_C_(s32) FWopen(void *pDsp) EXPORT_C_(s32)
FWopen(void* pDsp)
{ {
FWLog.WriteLn("Opening FWnull."); FWLog.WriteLn("Opening FWnull.");
return 0; return 0;
} }
EXPORT_C_(void) FWclose() EXPORT_C_(void)
FWclose()
{ {
// Close the plugin. // Close the plugin.
FWLog.WriteLn("Closing FWnull."); FWLog.WriteLn("Closing FWnull.");
} }
void PHYWrite() void PHYWrite()
{ {
u8 reg = (PHYACC >> 8) & 0xf; u8 reg = (PHYACC >> 8) & 0xf;
u8 data = PHYACC & 0xff; u8 data = PHYACC & 0xff;
phyregs[reg] = data; phyregs[reg] = data;
PHYACC &= ~0x4000ffff; PHYACC &= ~0x4000ffff;
} }
void PHYRead() void PHYRead()
{ {
u8 reg = (PHYACC >> 24) & 0xf; u8 reg = (PHYACC >> 24) & 0xf;
PHYACC &= ~0x80000000; PHYACC &= ~0x80000000;
PHYACC |= phyregs[reg] | (reg << 8); PHYACC |= phyregs[reg] | (reg << 8);
if(fwRu32(0x8424) & 0x40000000) //RRx interrupt mask if (fwRu32(0x8424) & 0x40000000) //RRx interrupt mask
{ {
fwRu32(0x8420) |= 0x40000000; fwRu32(0x8420) |= 0x40000000;
FWirq(); FWirq();
} }
} }
EXPORT_C_(u32) FWread32(u32 addr) EXPORT_C_(u32)
FWread32(u32 addr)
{ {
u32 ret = 0; u32 ret = 0;
switch (addr) switch (addr) {
{ //Node ID Register the top part is default, bottom part i got from my ps2
//Node ID Register the top part is default, bottom part i got from my ps2 case 0x1f808400:
case 0x1f808400: ret = /*(0x3ff << 22) | 1;*/ 0xffc00001;
ret = /*(0x3ff << 22) | 1;*/ 0xffc00001; break;
break; // Control Register 2
// Control Register 2 case 0x1f808410:
case 0x1f808410: ret = fwRu32(addr); //SCLK OK (Needs to be set when FW is "Ready"
ret = fwRu32(addr); //SCLK OK (Needs to be set when FW is "Ready" break;
break; //Interrupt 0 Register
//Interrupt 0 Register case 0x1f808420:
case 0x1f808420: ret = fwRu32(addr);
ret = fwRu32(addr); break;
break;
//Dunno what this is, but my home console always returns this value 0x10000001 //Dunno what this is, but my home console always returns this value 0x10000001
//Seems to be related to the Node ID however (does some sort of compare/check) //Seems to be related to the Node ID however (does some sort of compare/check)
case 0x1f80847c: case 0x1f80847c:
ret = 0x10000001; ret = 0x10000001;
break; break;
// Include other relevant 32 bit addresses we need to catch here. // Include other relevant 32 bit addresses we need to catch here.
default: default:
// By default, read fwregs. // By default, read fwregs.
ret = fwRu32(addr); ret = fwRu32(addr);
break; break;
} }
FWLog.WriteLn("FW read mem 0x%x: 0x%x", addr, ret); FWLog.WriteLn("FW read mem 0x%x: 0x%x", addr, ret);
return ret; return ret;
} }
EXPORT_C_(void) FWwrite32(u32 addr, u32 value) EXPORT_C_(void)
FWwrite32(u32 addr, u32 value)
{ {
switch (addr) switch (addr) {
{ // Include other memory locations we want to catch here.
// Include other memory locations we want to catch here. // For example:
// For example: //
// // case 0x1f808400:
// case 0x1f808400: // case 0x1f808414:
// case 0x1f808414: // case 0x1f808420:
// case 0x1f808420: // case 0x1f808428:
// case 0x1f808428: // case 0x1f808430:
// case 0x1f808430: //
//
//PHY access //PHY access
case 0x1f808414: case 0x1f808414:
//If in read mode (top bit set) we read the PHY register requested then set the RRx interrupt if it's enabled //If in read mode (top bit set) we read the PHY register requested then set the RRx interrupt if it's enabled
//Im presuming we send that back to pcsx2 then. This register stores the result, plus whatever was written (minus the read/write flag //Im presuming we send that back to pcsx2 then. This register stores the result, plus whatever was written (minus the read/write flag
fwRu32(addr) = value; //R/W Bit cleaned in underneath function fwRu32(addr) = value; //R/W Bit cleaned in underneath function
if(value & 0x40000000) //Writing to PHY if (value & 0x40000000) //Writing to PHY
{ {
PHYWrite(); PHYWrite();
} } else if (value & 0x80000000) //Reading from PHY
else if(value & 0x80000000) //Reading from PHY {
{ PHYRead();
PHYRead(); }
} break;
break;
//Control Register 0 //Control Register 0
case 0x1f808408: case 0x1f808408:
//This enables different functions of the link interface //This enables different functions of the link interface
//Just straight writes, should brobably struct these later. //Just straight writes, should brobably struct these later.
//Default written settings (on unreal tournament) are //Default written settings (on unreal tournament) are
//Urcv M = 1 //Urcv M = 1
//RSP 0 = 1 //RSP 0 = 1
//Retlim = 0xF //Retlim = 0xF
//Cyc Tmr En = 1 //Cyc Tmr En = 1
//Bus ID Rst = 1 //Bus ID Rst = 1
//Rcv Self ID = 1 //Rcv Self ID = 1
fwRu32(addr) = value; fwRu32(addr) = value;
// if((value & 0x800000) && (fwRu32(0x842C) & 0x2)) // if((value & 0x800000) && (fwRu32(0x842C) & 0x2))
// { // {
// fwRu32(0x8428) |= 0x2; // fwRu32(0x8428) |= 0x2;
// FWirq(); // FWirq();
// } // }
fwRu32(addr) &= ~0x800000; fwRu32(addr) &= ~0x800000;
break; break;
//Control Register 2 //Control Register 2
case 0x1f808410:// fwRu32(addr) = value; break; case 0x1f808410: // fwRu32(addr) = value; break;
//Ignore writes to this for now, apart from 0x2 which is Link Power Enable //Ignore writes to this for now, apart from 0x2 which is Link Power Enable
//0x8 is SCLK OK (Ready) which should be set for emulation //0x8 is SCLK OK (Ready) which should be set for emulation
fwRu32(addr) = 0x8 /*| value & 0x2*/; fwRu32(addr) = 0x8 /*| value & 0x2*/;
break; break;
//Interrupt 0 Register //Interrupt 0 Register
case 0x1f808420: case 0x1f808420:
//Interrupt 1 Register //Interrupt 1 Register
case 0x1f808428: case 0x1f808428:
//Interrupt 2 Register //Interrupt 2 Register
case 0x1f808430: case 0x1f808430:
//Writes of 1 clear the corresponding bits //Writes of 1 clear the corresponding bits
fwRu32(addr) &= ~value; fwRu32(addr) &= ~value;
break; break;
//Interrupt 0 Register Mask //Interrupt 0 Register Mask
case 0x1f808424: case 0x1f808424:
//Interrupt 1 Register Mask //Interrupt 1 Register Mask
case 0x1f80842C: case 0x1f80842C:
//Interrupt 2 Register Mask //Interrupt 2 Register Mask
case 0x1f808434: case 0x1f808434:
//These are direct writes (as it's a mask!) //These are direct writes (as it's a mask!)
fwRu32(addr) = value; fwRu32(addr) = value;
break; break;
//DMA Control and Status Register 0 //DMA Control and Status Register 0
case 0x1f8084B8: case 0x1f8084B8:
fwRu32(addr) = value; fwRu32(addr) = value;
break; break;
//DMA Control and Status Register 1 //DMA Control and Status Register 1
case 0x1f808538: case 0x1f808538:
fwRu32(addr) = value; fwRu32(addr) = value;
break; break;
default: default:
// By default, just write it to fwregs. // By default, just write it to fwregs.
fwRu32(addr) = value; fwRu32(addr) = value;
break; break;
} }
FWLog.WriteLn("FW write mem 0x%x: 0x%x", addr, value); FWLog.WriteLn("FW write mem 0x%x: 0x%x", addr, value);
} }
EXPORT_C_(void) FWirqCallback(void (*callback)()) EXPORT_C_(void)
FWirqCallback(void (*callback)())
{ {
// Register FWirq, so we can trigger an interrupt with it later. // Register FWirq, so we can trigger an interrupt with it later.
FWirq = callback; FWirq = callback;
} }
EXPORT_C_(void) FWsetSettingsDir(const char* dir) EXPORT_C_(void)
FWsetSettingsDir(const char* dir)
{ {
// Find out from pcsx2 where we are supposed to put our ini file. // Find out from pcsx2 where we are supposed to put our ini file.
s_strIniPath = (dir == NULL) ? "inis" : dir; s_strIniPath = (dir == NULL) ? "inis" : dir;
} }
EXPORT_C_(s32) FWfreeze(int mode, freezeData *data) EXPORT_C_(s32)
FWfreeze(int mode, freezeData* data)
{ {
// This should store or retrieve any information, for if emulation // This should store or retrieve any information, for if emulation
// gets suspended, or for savestates. // gets suspended, or for savestates.
switch(mode) switch (mode) {
{ case FREEZE_LOAD:
case FREEZE_LOAD: // Load previously saved data.
// Load previously saved data. break;
break; case FREEZE_SAVE:
case FREEZE_SAVE: // Save data.
// Save data. break;
break; case FREEZE_SIZE:
case FREEZE_SIZE: // return the size of the data.
// return the size of the data. break;
break; }
} return 0;
return 0;
} }
EXPORT_C_(s32) FWtest() EXPORT_C_(s32)
FWtest()
{ {
// 0 if the plugin works, non-0 if it doesn't. // 0 if the plugin works, non-0 if it doesn't.
return 0; return 0;
} }

View File

@ -23,16 +23,16 @@
#include "PS2Eext.h" #include "PS2Eext.h"
// Our main memory storage, and defines for accessing it. // Our main memory storage, and defines for accessing it.
extern s8 *fwregs; extern s8* fwregs;
#define fwRs32(mem) (*(s32*)&fwregs[(mem) & 0xffff]) #define fwRs32(mem) (*(s32*)&fwregs[(mem)&0xffff])
#define fwRu32(mem) (*(u32*)&fwregs[(mem) & 0xffff]) #define fwRu32(mem) (*(u32*)&fwregs[(mem)&0xffff])
//PHY Access Address for ease of use :P //PHY Access Address for ease of use :P
#define PHYACC fwRu32(0x8414) #define PHYACC fwRu32(0x8414)
typedef struct typedef struct
{ {
s32 Log; s32 Log;
} Config; } Config;
extern Config conf; extern Config conf;

View File

@ -21,46 +21,45 @@ extern HINSTANCE hInst;
void SaveConfig() void SaveConfig()
{ {
Config *Conf1 = &conf; Config* Conf1 = &conf;
char *szTemp; char* szTemp;
char szIniFile[256], szValue[256]; char szIniFile[256], szValue[256];
GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256);
szTemp = strrchr(szIniFile, '\\'); szTemp = strrchr(szIniFile, '\\');
if(!szTemp) return;
strcpy(szTemp, "\\inis\\fwnull.ini");
sprintf(szValue,"%u",Conf1->Log);
WritePrivateProfileString("Interface", "Logging",szValue,szIniFile);
if (!szTemp)
return;
strcpy(szTemp, "\\inis\\fwnull.ini");
sprintf(szValue, "%u", Conf1->Log);
WritePrivateProfileString("Interface", "Logging", szValue, szIniFile);
} }
void LoadConfig() { void LoadConfig()
FILE *fp; {
FILE* fp;
Config *Conf1 = &conf; Config* Conf1 = &conf;
char *szTemp; char* szTemp;
char szIniFile[256], szValue[256]; char szIniFile[256], szValue[256];
GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256); GetModuleFileName(GetModuleHandle((LPCSTR)hInst), szIniFile, 256);
szTemp = strrchr(szIniFile, '\\'); szTemp = strrchr(szIniFile, '\\');
if(!szTemp) return ; if (!szTemp)
strcpy(szTemp, "\\inis\\fwnull.ini"); return;
fp=fopen("inis\\fwnull.ini","rt");//check if firewirenull.ini really exists strcpy(szTemp, "\\inis\\fwnull.ini");
if (!fp) fp = fopen("inis\\fwnull.ini", "rt"); //check if firewirenull.ini really exists
{ if (!fp) {
CreateDirectory("inis",NULL); CreateDirectory("inis", NULL);
memset(&conf, 0, sizeof(conf)); memset(&conf, 0, sizeof(conf));
conf.Log = 0;//default value conf.Log = 0; //default value
SaveConfig();//save and return SaveConfig(); //save and return
return ; return;
} }
fclose(fp); fclose(fp);
GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile); GetPrivateProfileString("Interface", "Logging", NULL, szValue, 20, szIniFile);
Conf1->Log = strtoul(szValue, NULL, 10); Conf1->Log = strtoul(szValue, NULL, 10);
return ; return;
} }

View File

@ -23,74 +23,81 @@
HINSTANCE hInst; HINSTANCE hInst;
void SysMessage(char *fmt, ...) { void SysMessage(char* fmt, ...)
va_list list; {
char tmp[512]; va_list list;
char tmp[512];
va_start(list,fmt); va_start(list, fmt);
vsprintf(tmp,fmt,list); vsprintf(tmp, fmt, list);
va_end(list); va_end(list);
MessageBox(GetActiveWindow(), tmp, "FW Plugin Msg", MB_SETFOREGROUND | MB_OK); MessageBox(GetActiveWindow(), tmp, "FW Plugin Msg", MB_SETFOREGROUND | MB_OK);
} }
BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg) { switch (uMsg) {
case WM_INITDIALOG: case WM_INITDIALOG:
LoadConfig(); LoadConfig();
if (conf.Log) CheckDlgButton(hW, IDC_LOGGING, TRUE); if (conf.Log)
return TRUE; CheckDlgButton(hW, IDC_LOGGING, TRUE);
return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch(LOWORD(wParam)) { switch (LOWORD(wParam)) {
case IDCANCEL: case IDCANCEL:
EndDialog(hW, TRUE); EndDialog(hW, TRUE);
return TRUE; return TRUE;
case IDOK: case IDOK:
if (IsDlgButtonChecked(hW, IDC_LOGGING)) if (IsDlgButtonChecked(hW, IDC_LOGGING))
conf.Log = 1; conf.Log = 1;
else conf.Log = 0; else
SaveConfig(); conf.Log = 0;
EndDialog(hW, FALSE); SaveConfig();
return TRUE; EndDialog(hW, FALSE);
} return TRUE;
} }
return FALSE; }
return FALSE;
} }
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
switch(uMsg) { {
case WM_INITDIALOG: switch (uMsg) {
return TRUE; case WM_INITDIALOG:
return TRUE;
case WM_COMMAND: case WM_COMMAND:
switch(LOWORD(wParam)) { switch (LOWORD(wParam)) {
case IDOK: case IDOK:
EndDialog(hW, FALSE); EndDialog(hW, FALSE);
return TRUE; return TRUE;
} }
} }
return FALSE; return FALSE;
} }
void CALLBACK FWconfigure() { void CALLBACK FWconfigure()
{
DialogBox(hInst, DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG), MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(), GetActiveWindow(),
(DLGPROC)ConfigureDlgProc); (DLGPROC)ConfigureDlgProc);
} }
void CALLBACK FWabout() { void CALLBACK FWabout()
{
DialogBox(hInst, DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT), MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(), GetActiveWindow(),
(DLGPROC)AboutDlgProc); (DLGPROC)AboutDlgProc);
} }
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason, DWORD dwReason,
LPVOID lpReserved) { LPVOID lpReserved)
hInst = (HINSTANCE)hModule; {
return TRUE; // very quick :) hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
} }