2009-05-02 04:39:05 +00:00
|
|
|
/* DEV9null
|
2010-01-09 02:04:07 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 16:39:37 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* PCSX2 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 PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2009-05-02 04:39:05 +00:00
|
|
|
|
2010-01-09 02:04:07 +00:00
|
|
|
// Note: I was using MegaDev9, dev9ghzdrk, and dev9linuz for reference on memory locations.
|
|
|
|
// The ones I included were just some of the more important ones, so you may want to look
|
|
|
|
// at the plugins I mentioned if trying to create your own dev9 plugin.
|
|
|
|
|
2010-04-25 00:31:27 +00:00
|
|
|
// Additionally, there is a lot of information in the ps2drv drivers by Marcus R. Brown, so
|
2010-01-09 02:04:07 +00:00
|
|
|
// looking through its code would be a good starting point.
|
|
|
|
|
|
|
|
// Look under tags/plugins in svn for any older plugins that aren't included in pcsx2 any more.
|
|
|
|
// --arcum42
|
|
|
|
|
|
|
|
|
2009-05-15 07:02:51 +00:00
|
|
|
#include <stdlib.h>
|
2009-05-02 04:39:05 +00:00
|
|
|
#include <string.h>
|
2009-05-15 07:02:51 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <string>
|
|
|
|
using namespace std;
|
|
|
|
|
2009-05-02 04:39:05 +00:00
|
|
|
#include "DEV9.h"
|
2013-06-28 10:43:50 +00:00
|
|
|
#include "svnrev.h"
|
2009-05-02 04:39:05 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
const unsigned char version = PS2E_DEV9_VERSION;
|
2009-05-02 04:39:05 +00:00
|
|
|
const unsigned char revision = 0;
|
2016-08-24 21:16:38 +00:00
|
|
|
const unsigned char build = 5; // increase that with each version
|
2009-05-02 04:39:05 +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-02 04:39:05 +00:00
|
|
|
|
2010-01-09 02:04:07 +00:00
|
|
|
// Our IRQ call.
|
2009-05-15 07:02:51 +00:00
|
|
|
void (*DEV9irq)(int);
|
2010-01-09 02:04:07 +00:00
|
|
|
|
|
|
|
__aligned16 s8 dev9regs[0x10000];
|
|
|
|
|
2011-03-25 01:09:18 +00:00
|
|
|
string s_strIniPath = "inis";
|
2016-08-24 21:16:38 +00:00
|
|
|
string s_strLogPath = "logs";
|
2010-05-29 10:46:48 +00:00
|
|
|
|
2010-01-09 02:04:07 +00:00
|
|
|
PluginLog Dev9Log;
|
2009-05-15 07:02:51 +00:00
|
|
|
Config conf;
|
2009-05-02 04:39:05 +00:00
|
|
|
|
2010-05-29 10:46:48 +00:00
|
|
|
void LogInit()
|
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
const std::string LogFile(s_strLogPath + "/dev9null.log");
|
|
|
|
setLoggingState();
|
|
|
|
Dev9Log.Open(LogFile);
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9setLogDir(const char *dir)
|
2010-05-29 10:46:48 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// Get the path to the log directory.
|
|
|
|
s_strLogPath = (dir == NULL) ? "logs" : dir;
|
|
|
|
|
|
|
|
// Reload the log file after updated the path
|
|
|
|
Dev9Log.Close();
|
|
|
|
LogInit();
|
2010-05-29 10:46:48 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibType()
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
return PS2E_LT_DEV9;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-28 16:14:07 +00:00
|
|
|
EXPORT_C_(char *)
|
2016-08-24 21:16:38 +00:00
|
|
|
PS2EgetLibName()
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
snprintf(libraryName, 255, "DEV9null Driver %lld%s", SVN_REV, SVN_MODS ? "m" : "");
|
|
|
|
return libraryName;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
PS2EgetLibVersion2(u32 type)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
return (version << 16) | (revision << 8) | build;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
DEV9init()
|
2010-04-25 00:31:27 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
LoadConfig();
|
|
|
|
setLoggingState();
|
|
|
|
LogInit();
|
|
|
|
Dev9Log.WriteLn("dev9null plugin version %d,%d", revision, build);
|
|
|
|
Dev9Log.WriteLn("Initializing dev9null");
|
|
|
|
// Initialize anything that needs to be initialized.
|
|
|
|
memset(dev9regs, 0, sizeof(dev9regs));
|
|
|
|
return 0;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9shutdown()
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("Shutting down Dev9null.");
|
|
|
|
Dev9Log.Close();
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9open(void *pDsp)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("Opening Dev9null.");
|
|
|
|
// Get anything ready we need to. Opening and creating hard
|
|
|
|
// drive files, for example.
|
|
|
|
return 0;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9close()
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("Closing Dev9null.");
|
|
|
|
// Close files opened.
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(u8)
|
|
|
|
DEV9read8(u32 addr)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2010-01-09 02:04:07 +00:00
|
|
|
u8 value = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
// case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay)
|
|
|
|
case 0x10000038: /*value = dev9Ru8(addr);*/
|
|
|
|
break; // We need to have at least one case to avoid warnings.
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
|
|
|
//value = dev9Ru8(addr);
|
2010-01-09 02:04:07 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 8 bit read at address %lx", addr);
|
|
|
|
break;
|
|
|
|
}
|
2016-08-24 21:16:38 +00:00
|
|
|
return value;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(u16)
|
|
|
|
DEV9read16(u32 addr)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2010-01-09 02:04:07 +00:00
|
|
|
u16 value = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
// Addresses you may want to catch here include:
|
|
|
|
// case 0x1F80146E: // DEV9 hardware type (0x32 for an expansion bay)
|
|
|
|
// case 0x10000002: // The Smart Chip revision. Should be 0x11
|
|
|
|
// case 0x10000004: // More type info: bit 0 - smap; bit 1 - hd; bit 5 - flash
|
|
|
|
// case 0x1000000E: // Similar to the last; bit 1 should be set if a hd is hooked up.
|
|
|
|
// case 0x10000028: // intr_stat
|
|
|
|
// case 0x10000038: // hard drives seem to like reading and writing the max dma size per transfer here.
|
|
|
|
// case 0x1000002A: // intr_mask
|
|
|
|
// case 0x10000040: // pio_data
|
|
|
|
// case 0x10000044: // nsector
|
|
|
|
// case 0x10000046: // sector
|
|
|
|
// case 0x10000048: // lcyl
|
|
|
|
// case 0x1000004A: // hcyl
|
|
|
|
// case 0x1000004C: // select
|
|
|
|
// case 0x1000004E: // status
|
|
|
|
// case 0x1000005C: // status
|
|
|
|
// case 0x10000064: // if_ctrl
|
|
|
|
case 0x10000038: /*value = dev9Ru16(addr);*/
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
|
|
|
//value = dev9Ru16(addr);
|
2010-01-09 02:04:07 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 16 bit read at address %lx", addr);
|
|
|
|
break;
|
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
return value;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(u32)
|
|
|
|
DEV9read32(u32 addr)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2010-01-09 02:04:07 +00:00
|
|
|
u32 value = 0;
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
case 0x10000038: /*value = dev9Ru32(addr);*/
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
|
|
|
//value = dev9Ru32(addr);
|
2010-01-09 02:04:07 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 32 bit read at address %lx", addr);
|
2016-08-24 21:16:38 +00:00
|
|
|
break;
|
2010-01-09 02:04:07 +00:00
|
|
|
}
|
2010-04-25 00:31:27 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
return value;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9write8(u32 addr, u8 value)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
case 0x10000038: /*dev9Ru8(addr) = value;*/
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 8 bit write; address %lx = %x", addr, value);
|
|
|
|
//dev9Ru8(addr) = value;
|
|
|
|
break;
|
2010-01-09 02:04:07 +00:00
|
|
|
}
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9write16(u32 addr, u16 value)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
// Remember that list on DEV9read16? You'll want to write to a
|
|
|
|
// lot of them, too.
|
|
|
|
case 0x10000038: /*dev9Ru16(addr) = value;*/
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 16 bit write; address %lx = %x", addr, value);
|
2010-01-16 12:29:24 +00:00
|
|
|
//dev9Ru16(addr) = value;
|
2016-08-24 21:16:38 +00:00
|
|
|
break;
|
2010-01-09 02:04:07 +00:00
|
|
|
}
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9write32(u32 addr, u32 value)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
switch (addr) {
|
|
|
|
case 0x10000038: /*dev9Ru32(addr) = value;*/
|
|
|
|
break;
|
2010-04-25 00:31:27 +00:00
|
|
|
default:
|
2016-08-24 21:16:38 +00:00
|
|
|
Dev9Log.WriteLn("*Unknown 32 bit write; address %lx = %x", addr, value);
|
2010-01-16 12:29:24 +00:00
|
|
|
//dev9Ru32(addr) = value;
|
2016-08-24 21:16:38 +00:00
|
|
|
break;
|
2010-01-09 02:04:07 +00:00
|
|
|
}
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2010-02-06 22:33:45 +00:00
|
|
|
//#ifdef ENABLE_NEW_IOPDMA_DEV9
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9dmaRead(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed)
|
2010-02-06 22:33:45 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// You'll want to put your own DMA8 reading code here.
|
|
|
|
// Time to interact with your fake (or real) hardware.
|
|
|
|
Dev9Log.WriteLn("Reading DMA8 Mem.");
|
|
|
|
*bytesProcessed = bytesLeft;
|
|
|
|
return 0;
|
2010-02-06 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9dmaWrite(s32 channel, u32 *data, u32 bytesLeft, u32 *bytesProcessed)
|
2010-02-06 22:33:45 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// See above.
|
|
|
|
Dev9Log.WriteLn("Writing DMA8 Mem.");
|
|
|
|
*bytesProcessed = bytesLeft;
|
|
|
|
return 0;
|
2010-02-06 22:33:45 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9dmaInterrupt(s32 channel)
|
2010-02-06 22:33:45 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// See above.
|
2010-02-06 22:33:45 +00:00
|
|
|
}
|
|
|
|
//#else
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9readDMA8Mem(u32 *pMem, int size)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// You'll want to put your own DMA8 reading code here.
|
|
|
|
// Time to interact with your fake (or real) hardware.
|
|
|
|
Dev9Log.WriteLn("Reading DMA8 Mem.");
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9writeDMA8Mem(u32 *pMem, int size)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// See above.
|
|
|
|
Dev9Log.WriteLn("Writing DMA8 Mem.");
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
2010-02-06 22:33:45 +00:00
|
|
|
//#endif
|
2009-05-02 04:39:05 +00:00
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
|
|
|
DEV9irqCallback(DEV9callback callback)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// Setting our callback. You will call it with DEV9irq(cycles),
|
|
|
|
// Where cycles is the number of cycles till the irq is triggered.
|
|
|
|
DEV9irq = callback;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2010-01-09 02:04:07 +00:00
|
|
|
int _DEV9irqHandler(void)
|
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// And this gets called when the irq is triggered.
|
|
|
|
return 0;
|
2010-01-09 02:04:07 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(DEV9handler)
|
|
|
|
DEV9irqHandler(void)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// Pass it to pcsx2.
|
|
|
|
return (DEV9handler)_DEV9irqHandler;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(void)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9setSettingsDir(const char *dir)
|
2009-12-20 13:45:26 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
// Grab the ini directory.
|
2011-03-25 01:09:18 +00:00
|
|
|
s_strIniPath = (dir == NULL) ? "inis" : dir;
|
2009-12-20 13:45:26 +00:00
|
|
|
}
|
|
|
|
|
2009-05-02 04:39:05 +00:00
|
|
|
// extended funcs
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
|
|
|
DEV9test()
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +00:00
|
|
|
return 0;
|
2009-05-02 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2016-08-24 21:16:38 +00:00
|
|
|
EXPORT_C_(s32)
|
2016-08-28 16:14:07 +00:00
|
|
|
DEV9freeze(int mode, freezeData *data)
|
2009-05-02 04:39:05 +00:00
|
|
|
{
|
2016-08-24 21:16:38 +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 04:39:05 +00:00
|
|
|
}
|
|
|
|
|
2010-01-09 02:04:07 +00:00
|
|
|
/* For operating systems that need an entry point for a dll/library, here it is. Defined in PS2Eext.h. */
|
|
|
|
ENTRY_POINT;
|