2009-05-02 00:56:56 +00:00
|
|
|
/* FWnull
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2004-2010 PCSX2 Dev Team
|
2009-05-02 00:56:56 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-07-04 22:49:00 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
2009-05-02 00:56:56 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include "FW.h"
|
2013-06-28 10:43:50 +00:00
|
|
|
#include "svnrev.h"
|
2009-05-02 00:56:56 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
const u8 version = PS2E_FW_VERSION;
|
2009-05-21 21:12:01 +00:00
|
|
|
const u8 revision = 0;
|
2016-10-16 19:39:56 +00:00
|
|
|
const u8 build = 7; // increase that with each version
|
2009-05-02 00:56:56 +00:00
|
|
|
|
2013-06-28 17:11:16 +00:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#define snprintf sprintf_s
|
|
|
|
#endif
|
2012-06-18 21:16:25 +00:00
|
|
|
static char libraryName[256];
|
2009-05-15 06:08:35 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
string s_strIniPath = "inis";
|
2011-03-25 01:09:18 +00:00
|
|
|
string s_strLogPath = "logs";
|
2011-03-17 18:39:57 +00:00
|
|
|
|
|
|
|
u8 phyregs[16];
|
2016-08-28 16:14:07 +00:00
|
|
|
s8 *fwregs;
|
2009-05-02 00:56:56 +00:00
|
|
|
Config conf;
|
2010-01-09 05:11:18 +00:00
|
|
|
PluginLog FWLog;
|
2009-05-15 06:08:35 +00:00
|
|
|
|
2009-05-02 00:56:56 +00:00
|
|
|
void (*FWirq)();
|
|
|
|
|
2010-05-29 10:46:48 +00:00
|
|
|
void LogInit()
|
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
const std::string LogFile(s_strLogPath + "/FWnull.log");
|
|
|
|
setLoggingState();
|
|
|
|
FWLog.Open(LogFile);
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
FWsetLogDir(const char *dir)
|
2010-05-29 10:46:48 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir == NULL) ? "logs" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
|
|
|
FWLog.Close();
|
|
|
|
LogInit();
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibType()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
return PS2E_LT_FW;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2017-01-29 09:27:43 +00:00
|
|
|
EXPORT_C_(const char *)
|
2016-08-24 21:14:01 +00:00
|
|
|
PS2EgetLibName()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
snprintf(libraryName, 255, "FWnull Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
|
|
|
|
return libraryName;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibVersion2(u32 type)
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
return (version << 16) | (revision << 8) | build;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
FWinit()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
LoadConfig();
|
|
|
|
LogInit();
|
|
|
|
FWLog.WriteLn("FWnull plugin version %d,%d", revision, build);
|
|
|
|
FWLog.WriteLn("Initializing FWnull");
|
|
|
|
|
|
|
|
memset(phyregs, 0, sizeof(phyregs));
|
|
|
|
// Initializing our registers.
|
2016-08-28 16:14:07 +00:00
|
|
|
fwregs = (s8 *)calloc(0x10000, 1);
|
2016-08-24 21:14:01 +00:00
|
|
|
if (fwregs == NULL) {
|
|
|
|
FWLog.Message("Error allocating Memory");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
FWshutdown()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// Freeing the registers.
|
|
|
|
free(fwregs);
|
|
|
|
fwregs = NULL;
|
2010-05-28 16:54:42 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
FWLog.Close();
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
FWopen(void *pDsp)
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
FWLog.WriteLn("Opening FWnull.");
|
2009-05-02 00:56:56 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
return 0;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
FWclose()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// Close the plugin.
|
|
|
|
FWLog.WriteLn("Closing FWnull.");
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2011-03-17 18:39:57 +00:00
|
|
|
void PHYWrite()
|
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
u8 reg = (PHYACC >> 8) & 0xf;
|
|
|
|
u8 data = PHYACC & 0xff;
|
2011-03-17 18:39:57 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
phyregs[reg] = data;
|
2011-03-17 18:39:57 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
PHYACC &= ~0x4000ffff;
|
2011-03-17 18:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PHYRead()
|
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
u8 reg = (PHYACC >> 24) & 0xf;
|
|
|
|
|
|
|
|
PHYACC &= ~0x80000000;
|
2011-03-17 18:39:57 +00:00
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
PHYACC |= phyregs[reg] | (reg << 8);
|
2011-03-17 18:39:57 +00:00
|
|
|
|
2016-10-16 19:39:56 +00:00
|
|
|
if (fwRu32(0x8424) & 0x40000000) //RRx interrupt mask
|
2016-08-24 21:14:01 +00:00
|
|
|
{
|
|
|
|
fwRu32(0x8420) |= 0x40000000;
|
|
|
|
FWirq();
|
|
|
|
}
|
2011-03-17 18:39:57 +00:00
|
|
|
}
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
FWread32(u32 addr)
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
u32 ret = 0;
|
|
|
|
|
|
|
|
switch (addr) {
|
|
|
|
//Node ID Register the top part is default, bottom part i got from my ps2
|
|
|
|
case 0x1f808400:
|
|
|
|
ret = /*(0x3ff << 22) | 1;*/ 0xffc00001;
|
|
|
|
break;
|
|
|
|
// Control Register 2
|
|
|
|
case 0x1f808410:
|
2016-10-16 19:39:56 +00:00
|
|
|
ret = fwRu32(addr); //SCLK OK (Needs to be set when FW is "Ready"
|
2016-08-24 21:14:01 +00:00
|
|
|
break;
|
|
|
|
//Interrupt 0 Register
|
|
|
|
case 0x1f808420:
|
|
|
|
ret = fwRu32(addr);
|
|
|
|
break;
|
|
|
|
|
|
|
|
//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)
|
|
|
|
case 0x1f80847c:
|
|
|
|
ret = 0x10000001;
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Include other relevant 32 bit addresses we need to catch here.
|
|
|
|
default:
|
|
|
|
// By default, read fwregs.
|
|
|
|
ret = fwRu32(addr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FWLog.WriteLn("FW read mem 0x%x: 0x%x", addr, ret);
|
|
|
|
|
|
|
|
return ret;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
FWwrite32(u32 addr, u32 value)
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
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
|
2016-10-16 19:39:56 +00:00
|
|
|
fwRu32(addr) = value; //R/W Bit cleaned in underneath function
|
|
|
|
if (value & 0x40000000) //Writing to PHY
|
2016-08-24 21:14:01 +00:00
|
|
|
{
|
|
|
|
PHYWrite();
|
2016-10-16 19:39:56 +00:00
|
|
|
} else if (value & 0x80000000) //Reading from PHY
|
2016-08-24 21:14:01 +00:00
|
|
|
{
|
|
|
|
PHYRead();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
//Control Register 0
|
|
|
|
case 0x1f808408:
|
|
|
|
//This enables different functions of the link interface
|
|
|
|
//Just straight writes, should brobably struct these later.
|
|
|
|
//Default written settings (on unreal tournament) are
|
|
|
|
//Urcv M = 1
|
|
|
|
//RSP 0 = 1
|
|
|
|
//Retlim = 0xF
|
|
|
|
//Cyc Tmr En = 1
|
|
|
|
//Bus ID Rst = 1
|
|
|
|
//Rcv Self ID = 1
|
|
|
|
fwRu32(addr) = value;
|
|
|
|
// if((value & 0x800000) && (fwRu32(0x842C) & 0x2))
|
|
|
|
// {
|
|
|
|
// fwRu32(0x8428) |= 0x2;
|
|
|
|
// FWirq();
|
|
|
|
// }
|
|
|
|
fwRu32(addr) &= ~0x800000;
|
|
|
|
break;
|
|
|
|
//Control Register 2
|
2016-10-16 19:39:56 +00:00
|
|
|
case 0x1f808410: // fwRu32(addr) = value; break;
|
2016-08-24 21:14:01 +00:00
|
|
|
//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*/;
|
|
|
|
break;
|
|
|
|
//Interrupt 0 Register
|
|
|
|
case 0x1f808420:
|
|
|
|
//Interrupt 1 Register
|
|
|
|
case 0x1f808428:
|
|
|
|
//Interrupt 2 Register
|
|
|
|
case 0x1f808430:
|
|
|
|
//Writes of 1 clear the corresponding bits
|
|
|
|
fwRu32(addr) &= ~value;
|
|
|
|
break;
|
|
|
|
//Interrupt 0 Register Mask
|
|
|
|
case 0x1f808424:
|
|
|
|
//Interrupt 1 Register Mask
|
|
|
|
case 0x1f80842C:
|
|
|
|
//Interrupt 2 Register Mask
|
|
|
|
case 0x1f808434:
|
|
|
|
//These are direct writes (as it's a mask!)
|
|
|
|
fwRu32(addr) = value;
|
|
|
|
break;
|
|
|
|
//DMA Control and Status Register 0
|
|
|
|
case 0x1f8084B8:
|
|
|
|
fwRu32(addr) = value;
|
|
|
|
break;
|
|
|
|
//DMA Control and Status Register 1
|
|
|
|
case 0x1f808538:
|
|
|
|
fwRu32(addr) = value;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
// By default, just write it to fwregs.
|
|
|
|
fwRu32(addr) = value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
FWLog.WriteLn("FW write mem 0x%x: 0x%x", addr, value);
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
FWirqCallback(void (*callback)())
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// Register FWirq, so we can trigger an interrupt with it later.
|
|
|
|
FWirq = callback;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
FWsetSettingsDir(const char *dir)
|
2009-12-20 13:45:26 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// Find out from pcsx2 where we are supposed to put our ini file.
|
2011-03-25 01:09:18 +00:00
|
|
|
s_strIniPath = (dir == NULL) ? "inis" : dir;
|
2009-12-20 13:45:26 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
FWfreeze(int mode, freezeData *data)
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// This should store or retrieve any information, for if emulation
|
|
|
|
// gets suspended, or for savestates.
|
|
|
|
switch (mode) {
|
|
|
|
case FREEZE_LOAD:
|
|
|
|
// Load previously saved data.
|
|
|
|
break;
|
|
|
|
case FREEZE_SAVE:
|
|
|
|
// Save data.
|
|
|
|
break;
|
|
|
|
case FREEZE_SIZE:
|
|
|
|
// return the size of the data.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:14:01 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
FWtest()
|
2009-05-02 00:56:56 +00:00
|
|
|
{
|
2016-08-24 21:14:01 +00:00
|
|
|
// 0 if the plugin works, non-0 if it doesn't.
|
|
|
|
return 0;
|
2009-05-02 00:56:56 +00:00
|
|
|
}
|