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,24 +25,23 @@ PluginConf Ini;
void setLoggingState()
{
if (conf.Log)
{
if (conf.Log) {
FWLog.WriteToConsole = true;
FWLog.WriteToFile = true;
}
else
{
} else {
FWLog.WriteToConsole = false;
FWLog.WriteToFile = false;
}
}
EXPORT_C_(void) FWabout()
EXPORT_C_(void)
FWabout()
{
SysMessage("FWnull: A simple null plugin.");
}
EXPORT_C_(void) FWconfigure()
EXPORT_C_(void)
FWconfigure()
{
LoadConfig();
PluginNullConfigure("Since this is a null plugin, all that is really configurable is logging.", conf.Log);
@ -52,8 +51,7 @@ EXPORT_C_(void) FWconfigure()
void LoadConfig()
{
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());
SaveConfig();
return;
@ -67,8 +65,7 @@ void LoadConfig()
void SaveConfig()
{
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());
return;
}
@ -76,4 +73,3 @@ void SaveConfig()
Ini.WriteInt("logging", conf.Log);
Ini.Close();
}

View File

@ -15,7 +15,7 @@
void SaveConf();
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 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

@ -32,11 +32,11 @@ const u8 build = 7; // increase that with each version
#endif
static char libraryName[256];
string s_strIniPath="inis";
string s_strIniPath = "inis";
string s_strLogPath = "logs";
u8 phyregs[16];
s8 *fwregs;
s8* fwregs;
Config conf;
PluginLog FWLog;
@ -49,33 +49,38 @@ void LogInit()
FWLog.Open(LogFile);
}
EXPORT_C_(void) FWsetLogDir(const char* dir)
EXPORT_C_(void)
FWsetLogDir(const char* dir)
{
// 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
FWLog.Close();
LogInit();
}
EXPORT_C_(u32) PS2EgetLibType()
EXPORT_C_(u32)
PS2EgetLibType()
{
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;
}
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();
LogInit();
@ -84,16 +89,16 @@ EXPORT_C_(s32) FWinit()
memset(phyregs, 0, sizeof(phyregs));
// Initializing our registers.
fwregs = (s8*)calloc(0x10000,1);
if (fwregs == NULL)
{
fwregs = (s8*)calloc(0x10000, 1);
if (fwregs == NULL) {
FWLog.Message("Error allocating Memory");
return -1;
}
return 0;
}
EXPORT_C_(void) FWshutdown()
EXPORT_C_(void)
FWshutdown()
{
// Freeing the registers.
free(fwregs);
@ -102,14 +107,16 @@ EXPORT_C_(void) FWshutdown()
FWLog.Close();
}
EXPORT_C_(s32) FWopen(void *pDsp)
EXPORT_C_(s32)
FWopen(void* pDsp)
{
FWLog.WriteLn("Opening FWnull.");
return 0;
}
EXPORT_C_(void) FWclose()
EXPORT_C_(void)
FWclose()
{
// Close the plugin.
FWLog.WriteLn("Closing FWnull.");
@ -133,18 +140,18 @@ void PHYRead()
PHYACC |= phyregs[reg] | (reg << 8);
if(fwRu32(0x8424) & 0x40000000) //RRx interrupt mask
if (fwRu32(0x8424) & 0x40000000) //RRx interrupt mask
{
fwRu32(0x8420) |= 0x40000000;
FWirq();
}
}
EXPORT_C_(u32) FWread32(u32 addr)
EXPORT_C_(u32)
FWread32(u32 addr)
{
u32 ret = 0;
switch (addr)
{
switch (addr) {
//Node ID Register the top part is default, bottom part i got from my ps2
case 0x1f808400:
ret = /*(0x3ff << 22) | 1;*/ 0xffc00001;
@ -176,30 +183,29 @@ EXPORT_C_(u32) FWread32(u32 addr)
return ret;
}
EXPORT_C_(void) FWwrite32(u32 addr, u32 value)
EXPORT_C_(void)
FWwrite32(u32 addr, u32 value)
{
switch (addr)
{
// Include other memory locations we want to catch here.
// For example:
//
// case 0x1f808400:
// case 0x1f808414:
// case 0x1f808420:
// case 0x1f808428:
// case 0x1f808430:
//
switch (addr) {
// Include other memory locations we want to catch here.
// For example:
//
// case 0x1f808400:
// case 0x1f808414:
// case 0x1f808420:
// case 0x1f808428:
// case 0x1f808430:
//
//PHY access
case 0x1f808414:
//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
fwRu32(addr) = value; //R/W Bit cleaned in underneath function
if(value & 0x40000000) //Writing to PHY
if (value & 0x40000000) //Writing to PHY
{
PHYWrite();
}
else if(value & 0x80000000) //Reading from PHY
} else if (value & 0x80000000) //Reading from PHY
{
PHYRead();
}
@ -225,7 +231,7 @@ EXPORT_C_(void) FWwrite32(u32 addr, u32 value)
fwRu32(addr) &= ~0x800000;
break;
//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
//0x8 is SCLK OK (Ready) which should be set for emulation
fwRu32(addr) = 0x8 /*| value & 0x2*/;
@ -264,24 +270,26 @@ EXPORT_C_(void) FWwrite32(u32 addr, u32 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.
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.
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
// gets suspended, or for savestates.
switch(mode)
{
switch (mode) {
case FREEZE_LOAD:
// Load previously saved data.
break;
@ -295,7 +303,8 @@ EXPORT_C_(s32) FWfreeze(int mode, freezeData *data)
return 0;
}
EXPORT_C_(s32) FWtest()
EXPORT_C_(s32)
FWtest()
{
// 0 if the plugin works, non-0 if it doesn't.
return 0;

View File

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

View File

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

View File

@ -23,33 +23,37 @@
HINSTANCE hInst;
void SysMessage(char *fmt, ...) {
void SysMessage(char* fmt, ...)
{
va_list list;
char tmp[512];
va_start(list,fmt);
vsprintf(tmp,fmt,list);
va_start(list, fmt);
vsprintf(tmp, fmt, list);
va_end(list);
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:
LoadConfig();
if (conf.Log) CheckDlgButton(hW, IDC_LOGGING, TRUE);
if (conf.Log)
CheckDlgButton(hW, IDC_LOGGING, TRUE);
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
switch (LOWORD(wParam)) {
case IDCANCEL:
EndDialog(hW, TRUE);
return TRUE;
case IDOK:
if (IsDlgButtonChecked(hW, IDC_LOGGING))
conf.Log = 1;
else conf.Log = 0;
else
conf.Log = 0;
SaveConfig();
EndDialog(hW, FALSE);
return TRUE;
@ -58,13 +62,14 @@ BOOL CALLBACK ConfigureDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
return FALSE;
}
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
switch(uMsg) {
BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
switch(LOWORD(wParam)) {
switch (LOWORD(wParam)) {
case IDOK:
EndDialog(hW, FALSE);
return TRUE;
@ -73,14 +78,16 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) {
return FALSE;
}
void CALLBACK FWconfigure() {
void CALLBACK FWconfigure()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_CONFIG),
GetActiveWindow(),
(DLGPROC)ConfigureDlgProc);
}
void CALLBACK FWabout() {
void CALLBACK FWabout()
{
DialogBox(hInst,
MAKEINTRESOURCE(IDD_ABOUT),
GetActiveWindow(),
@ -89,8 +96,8 @@ void CALLBACK FWabout() {
BOOL APIENTRY DllMain(HANDLE hModule, // DLL INIT
DWORD dwReason,
LPVOID lpReserved) {
LPVOID lpReserved)
{
hInst = (HINSTANCE)hModule;
return TRUE; // very quick :)
}