Disableable link support

Enable separate SRAM and VBA.INI profile for multiple instances
This commit is contained in:
DJRobX 2007-11-12 20:24:38 +00:00
parent c5b5894d19
commit 687152c4ed
11 changed files with 100 additions and 48 deletions

View File

@ -2998,22 +2998,30 @@ void CPUUpdateRegister(u32 address, u16 value)
cpuNextEvent = cpuTotalTicks; cpuNextEvent = cpuTotalTicks;
break; break;
case 0x128: case 0x128:
StartLink(value); // Link if (linkenable)
/* if(value & 0x80) { {
value &= 0xff7f; StartLink(value);
if(value & 1 && (value & 0x4000)) { }
UPDATE_REG(0x12a, 0xFF); else
IF |= 0x80; {
UPDATE_REG(0x202, IF); if(value & 0x80) {
value &= 0x7f7f; value &= 0xff7f;
} if(value & 1 && (value & 0x4000)) {
} UPDATE_REG(0x12a, 0xFF);
UPDATE_REG(0x128, value);*/ IF |= 0x80;
UPDATE_REG(0x202, IF);
value &= 0x7f7f;
}
}
UPDATE_REG(0x128, value);
}
break; break;
case 0x12a: case 0x12a:
if(lspeed) if(linkenable && lspeed)
{
LinkSSend(value); LinkSSend(value);
UPDATE_REG(0x12a, value); UPDATE_REG(0x134, value);
}
break; break;
case 0x130: case 0x130:
P1 |= (value & 0x3FF); P1 |= (value & 0x3FF);
@ -3022,14 +3030,20 @@ void CPUUpdateRegister(u32 address, u16 value)
case 0x132: case 0x132:
UPDATE_REG(0x132, value & 0xC3FF); UPDATE_REG(0x132, value & 0xC3FF);
break; break;
/* breaks sonic games
case 0x134: case 0x134:
StartGPLink(value); if (linkenable)
break;*/ StartGPLink(value);
case 0x140: else
StartJOYLink(value); UPDATE_REG(0x134, value);
break;
break;
case 0x140:
if (linkenable)
StartJOYLink(value);
else
UPDATE_REG(0x140, value);
break;
case 0x200: case 0x200:
IE = value & 0x3FFF; IE = value & 0x3FFF;
UPDATE_REG(0x200, IE); UPDATE_REG(0x200, IE);
@ -3858,7 +3872,7 @@ void CPULoop(int ticks)
int timerOverflow = 0; int timerOverflow = 0;
// variable used by the CPU core // variable used by the CPU core
cpuTotalTicks = 0; cpuTotalTicks = 0;
// if(cpuDmaHack2) if(linkenable && cpuDmaHack2)
cpuNextEvent = 1; cpuNextEvent = 1;
cpuBreakLoop = false; cpuBreakLoop = false;
cpuNextEvent = CPUUpdateTicks(); cpuNextEvent = CPUUpdateTicks();
@ -4323,10 +4337,9 @@ void CPULoop(int ticks)
#endif #endif
ticks -= clockTicks; ticks -= clockTicks;
/* Link
----------------------------------*/ if (linkenable)
LinkUpdate(clockTicks); LinkUpdate(clockTicks);
/* ----------------------------- */
cpuNextEvent = CPUUpdateTicks(); cpuNextEvent = CPUUpdateTicks();
@ -4342,8 +4355,8 @@ void CPULoop(int ticks)
goto updateLoop; goto updateLoop;
} }
// if(cpuDmaHack2) if(linkenable && cpuDmaHack2)
// cpuNextEvent = 1; cpuNextEvent = 1;
if(IF && (IME & 1) && armIrqEnable) { if(IF && (IME & 1) && armIrqEnable) {
int res = IF & IE; int res = IF & IE;

View File

@ -29,6 +29,7 @@ extern bool cpuFlashEnabled;
extern bool cpuEEPROMEnabled; extern bool cpuEEPROMEnabled;
extern bool cpuEEPROMSensorEnabled; extern bool cpuEEPROMSensorEnabled;
extern int lspeed; extern int lspeed;
extern bool linkenable;
extern void LinkSStop(void); extern void LinkSStop(void);
extern bool cpuDmaHack; extern bool cpuDmaHack;
extern bool cpuDmaHack2; extern bool cpuDmaHack2;
@ -93,7 +94,7 @@ static inline u32 CPUReadMemory(u32 address)
value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC])); value = READ32LE(((u32 *)&internalRAM[address & 0x7ffC]));
break; break;
case 4: case 4:
if((address>=0x4000120||address<=0x4000126)&&lspeed) if(linkenable && (address>=0x4000120||address<=0x4000126)&&lspeed)
LinkSStop(); LinkSStop();
if((address < 0x4000400) && ioReadable[address & 0x3fc]) { if((address < 0x4000400) && ioReadable[address & 0x3fc]) {
if(ioReadable[(address & 0x3fc) + 2]) if(ioReadable[(address & 0x3fc) + 2])
@ -218,7 +219,7 @@ static inline u32 CPUReadHalfWord(u32 address)
value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe])); value = READ16LE(((u16 *)&internalRAM[address & 0x7ffe]));
break; break;
case 4: case 4:
if((address>=0x4000120||address<=0x4000126)&&lspeed) if(linkenable && (address>=0x4000120||address<=0x4000126)&&lspeed)
LinkSStop(); LinkSStop();
if((address < 0x4000400) && ioReadable[address & 0x3fe]) if((address < 0x4000400) && ioReadable[address & 0x3fe])
{ {
@ -333,7 +334,7 @@ static inline u8 CPUReadByte(u32 address)
case 3: case 3:
return internalRAM[address & 0x7fff]; return internalRAM[address & 0x7fff];
case 4: case 4:
if((address>=0x4000120||address<=0x4000126)&&lspeed) if(linkenable&&(address>=0x4000120||address<=0x4000126)&&lspeed)
LinkSStop(); LinkSStop();
if((address < 0x4000400) && ioReadable[address & 0x3ff]) if((address < 0x4000400) && ioReadable[address & 0x3ff])
return ioMem[address & 0x3ff]; return ioMem[address & 0x3ff];

View File

@ -37,10 +37,9 @@ int linktime = 0;
u8 tspeed=3; u8 tspeed=3;
u8 transfer=0; u8 transfer=0;
LINKDATA *linkmem=NULL; LINKDATA *linkmem=NULL;
int linkid = 1, vbaid = 1; int linkid = 0, vbaid = 0;
HANDLE linksync[4]; HANDLE linksync[4];
int savedlinktime=0; int savedlinktime=0;
char inifile[] = "vba1.ini";
HANDLE mmf=NULL; HANDLE mmf=NULL;
char linkevent[] = "VBA link event "; char linkevent[] = "VBA link event ";
static int i, j; static int i, j;
@ -54,6 +53,7 @@ lserver ls;
lclient lc; lclient lc;
bool oncewait = false, after = false; bool oncewait = false, after = false;
bool adapter = false; bool adapter = false;
bool linkenable = false;
u8 rfu_cmd, rfu_qsend, rfu_qrecv; u8 rfu_cmd, rfu_qsend, rfu_qrecv;
int rfu_state, rfu_polarity, linktime2, counter, rfu_masterq; int rfu_state, rfu_polarity, linktime2, counter, rfu_masterq;
int transferend, numtransfers = 0; int transferend, numtransfers = 0;
@ -72,6 +72,22 @@ int StartServer(void);
int GetSioMode(u16, u16); int GetSioMode(u16, u16);
u16 StartRFU(u16); u16 StartRFU(u16);
char *MakeInstanceFilename(const char *Input)
{
if (vbaid == 0)
return (char *)Input;
static char *result=NULL;
if (result!=NULL)
free(result);
result = (char *)malloc(strlen(Input)+3);
char *p = strrchr((char *)Input, '.');
sprintf(result, "%.*s-%d.%s", (int)(p-Input), Input, vbaid+1, p+1);
return result;
}
void StartLink(WORD value){ void StartLink(WORD value){
if(ioMem==NULL) return; if(ioMem==NULL) return;
if(adapter){ if(adapter){
@ -160,6 +176,8 @@ void StartGPLink(u16 value){
else if(!adapter) fprintf(linklogfile, "Attempt to use General-purpose mode %04x\n", value); else if(!adapter) fprintf(linklogfile, "Attempt to use General-purpose mode %04x\n", value);
} }
if(adapter) rfu_state = RFU_INIT; if(adapter) rfu_state = RFU_INIT;
// This was not there, but sonic games won't start if it's not here.
UPDATE_REG(0x134, value);
break; break;
case JOYBUS: case JOYBUS:
UPDATE_REG(0x134, value); UPDATE_REG(0x134, value);
@ -549,7 +567,6 @@ int InitLink(void){
BOOL disable = true; BOOL disable = true;
linkid = 0; linkid = 0;
inifile[3]='1';
if(WSAStartup(MAKEWORD(1,1), &wsadata)!=0){ if(WSAStartup(MAKEWORD(1,1), &wsadata)!=0){
WSACleanup(); WSACleanup();
@ -588,7 +605,6 @@ int InitLink(void){
vbaid = 0; vbaid = 0;
if(vbaid==0){ if(vbaid==0){
inifile[3]='1';
linkid = 0; linkid = 0;
if(linkmem->linkflags&LINK_PARENTLOST){ if(linkmem->linkflags&LINK_PARENTLOST){
linkmem->numgbas++; linkmem->numgbas++;
@ -615,6 +631,7 @@ int InitLink(void){
vbaid=linkmem->numgbas; vbaid=linkmem->numgbas;
linkid = vbaid; linkid = vbaid;
linkmem->numgbas++; linkmem->numgbas++;
linklog = 0; linklog = 0;
if(linkmem->numgbas>4){ if(linkmem->numgbas>4){
linkmem->numgbas=4; linkmem->numgbas=4;
@ -625,7 +642,6 @@ int InitLink(void){
CloseHandle(mmf); CloseHandle(mmf);
return 0; return 0;
} }
inifile[3]=(char)linkmem->numgbas+'0';
for(i=0;i<4;i++){ for(i=0;i<4;i++){
linkevent[15]=(char)i+'1'; linkevent[15]=(char)i+'1';
if((linksync[i]=OpenEvent(EVENT_ALL_ACCESS, false, linkevent))==NULL){ if((linksync[i]=OpenEvent(EVENT_ALL_ACCESS, false, linkevent))==NULL){

View File

@ -109,12 +109,14 @@ extern void LinkChildSend(u16);
extern int openLinkLog(void); extern int openLinkLog(void);
extern void closeLinkLog(); extern void closeLinkLog();
extern void CloseLanLink(void); extern void CloseLanLink(void);
extern char *MakeInstanceFilename(const char *Input);
extern LANLINKDATA lanlink; extern LANLINKDATA lanlink;
extern FILE *linklogfile; extern FILE *linklogfile;
extern int vbaid; extern int vbaid;
extern int linklog; extern int linklog;
extern bool adapter; extern bool adapter;
extern bool linkenable;
extern int linktimeout; extern int linktimeout;
extern lclient lc; extern lclient lc;
extern int linkid; extern int linkid;

View File

@ -43,6 +43,7 @@
#include "../RTC.h" #include "../RTC.h"
#include "../Sound.h" #include "../Sound.h"
#include "../Util.h" #include "../Util.h"
#include "../Link.h"
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
@ -386,6 +387,9 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_LOG, OnUpdateOptionsLinkLog) ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_LOG, OnUpdateOptionsLinkLog)
ON_COMMAND(ID_OPTIONS_LINK_WIRELESSADAPTER, OnOptionsLinkRFU) ON_COMMAND(ID_OPTIONS_LINK_WIRELESSADAPTER, OnOptionsLinkRFU)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_WIRELESSADAPTER, OnUpdateOptionsLinkRFU) ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_WIRELESSADAPTER, OnUpdateOptionsLinkRFU)
ON_COMMAND(ID_OPTIONS_LINK_ENABLE, OnOptionsLinkEnable)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_ENABLE, OnUpdateOptionsLinkEnable)
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile) ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile)
ON_COMMAND_EX_RANGE(ID_FILE_LOADGAME_SLOT1, ID_FILE_LOADGAME_SLOT10, OnFileLoadSlot) ON_COMMAND_EX_RANGE(ID_FILE_LOADGAME_SLOT1, ID_FILE_LOADGAME_SLOT10, OnFileLoadSlot)
@ -932,7 +936,7 @@ void MainWnd::writeBatteryFile()
filename.Format("%s\\%s.sav", saveDir, buffer); filename.Format("%s\\%s.sav", saveDir, buffer);
if(theApp.emulator.emuWriteBattery) if(theApp.emulator.emuWriteBattery)
theApp.emulator.emuWriteBattery(filename); theApp.emulator.emuWriteBattery(MakeInstanceFilename((const char *)filename));
} }
@ -971,7 +975,7 @@ void MainWnd::readBatteryFile()
bool res = false; bool res = false;
if(theApp.emulator.emuReadBattery) if(theApp.emulator.emuReadBattery)
res = theApp.emulator.emuReadBattery(filename); res = theApp.emulator.emuReadBattery(MakeInstanceFilename(filename));
if(res) if(res)
systemScreenMessage(winResLoadString(IDS_LOADED_BATTERY)); systemScreenMessage(winResLoadString(IDS_LOADED_BATTERY));

View File

@ -433,12 +433,13 @@ public:
afx_msg void OnOptionsVideoFullscreen1024x768(); afx_msg void OnOptionsVideoFullscreen1024x768();
afx_msg void OnUpdateOptionsVideoFullscreen1024x768(CCmdUI *pCmdUI); afx_msg void OnUpdateOptionsVideoFullscreen1024x768(CCmdUI *pCmdUI);
afx_msg void OnUpdateOptionsVideoFullscreen1280x1024(CCmdUI *pCmdUI); afx_msg void OnUpdateOptionsVideoFullscreen1280x1024(CCmdUI *pCmdUI);
void OnLinkOptions(); afx_msg void OnLinkOptions();
void OnOptionsLinkLog() ; afx_msg void OnOptionsLinkLog() ;
void OnUpdateOptionsLinkLog(CCmdUI* pCmdUI) ; afx_msg void OnUpdateOptionsLinkLog(CCmdUI* pCmdUI) ;
void OnOptionsLinkRFU() ; afx_msg void OnOptionsLinkRFU() ;
void OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI) ; afx_msg void OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI) ;
afx_msg void OnOptionsLinkEnable() ;
afx_msg void OnUpdateOptionsLinkEnable(CCmdUI* pCmdUI) ;
}; };
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

View File

@ -1905,6 +1905,16 @@ void MainWnd::OnOptionsLinkRFU()
} }
} }
void MainWnd::OnUpdateOptionsLinkEnable(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(linkenable);
}
void MainWnd::OnOptionsLinkEnable()
{
linkenable = !linkenable;
}
void MainWnd::OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI) void MainWnd::OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI)
{ {
pCmdUI->SetCheck(adapter); pCmdUI->SetCheck(adapter);

View File

@ -17,6 +17,7 @@
// Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h" #include "stdafx.h"
#include "..\Link.h"
static char buffer[2048]; static char buffer[2048];
static HKEY vbKey = NULL; static HKEY vbKey = NULL;
@ -43,7 +44,7 @@ void regInit(const char *path)
regVbaPath = NULL; regVbaPath = NULL;
} }
regVbaPath = new CString(); regVbaPath = new CString();
regVbaPath->Format("%s\\vba.ini", path); regVbaPath->Format(MakeInstanceFilename("%s\\vba.ini"), path);
} }
void regShutdown() void regShutdown()

View File

@ -482,16 +482,16 @@ BOOL VBA::InitInstance()
systemVerbose = GetPrivateProfileInt("config", systemVerbose = GetPrivateProfileInt("config",
"verbose", "verbose",
0, 0,
"VBA.ini"); MakeInstanceFilename("VBA.ini"));
systemDebug = GetPrivateProfileInt("config", systemDebug = GetPrivateProfileInt("config",
"debug", "debug",
0, 0,
"VBA.ini"); MakeInstanceFilename("VBA.ini"));
ddrawDebug = GetPrivateProfileInt("config", ddrawDebug = GetPrivateProfileInt("config",
"ddrawDebug", "ddrawDebug",
0, 0,
"VBA.ini") ? true : false; MakeInstanceFilename("VBA.ini")) ? true : false;
wndClass = AfxRegisterWndClass(0, LoadCursor(IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(IDI_ICON)); wndClass = AfxRegisterWndClass(0, LoadCursor(IDC_ARROW), (HBRUSH)GetStockObject(BLACK_BRUSH), LoadIcon(IDI_ICON));
@ -1571,6 +1571,7 @@ void VBA::loadSettings()
openLinkLog(); openLinkLog();
adapter = regQueryDwordValue("RFU", false) ? true : false; adapter = regQueryDwordValue("RFU", false) ? true : false;
linkenable = regQueryDwordValue("linkEnabled", false) ? true : false;
lanlink.active = regQueryDwordValue("LAN", 0) ? true : false; lanlink.active = regQueryDwordValue("LAN", 0) ? true : false;
if (autoFrameSkip) if (autoFrameSkip)
@ -2421,6 +2422,7 @@ void VBA::saveSettings()
regSetDwordValue("LinkTimeout", linktimeout); regSetDwordValue("LinkTimeout", linktimeout);
regSetDwordValue("Linklog", linklog); regSetDwordValue("Linklog", linklog);
regSetDwordValue("RFU", adapter); regSetDwordValue("RFU", adapter);
regSetDwordValue("linkEnabled", linkenable);
} }
void winSignal(int, int) void winSignal(int, int)

View File

@ -1799,6 +1799,7 @@ BEGIN
END END
POPUP "Li&nk" POPUP "Li&nk"
BEGIN BEGIN
MENUITEM "Enable GBA Linking", ID_OPTIONS_LINK_ENABLE
MENUITEM "&Wireless Adapter", ID_OPTIONS_LINK_WIRELESSADAPTER MENUITEM "&Wireless Adapter", ID_OPTIONS_LINK_WIRELESSADAPTER
MENUITEM "&Log", ID_OPTIONS_LINK_LOG MENUITEM "&Log", ID_OPTIONS_LINK_LOG
MENUITEM "&Options...", ID_OPTIONS_LINK_OPTIONS MENUITEM "&Options...", ID_OPTIONS_LINK_OPTIONS
@ -1888,7 +1889,7 @@ BEGIN
"N", ID_DEBUG_NEXTFRAME, VIRTKEY, CONTROL, NOINVERT "N", ID_DEBUG_NEXTFRAME, VIRTKEY, CONTROL, NOINVERT
"O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT "O", ID_FILE_OPEN, VIRTKEY, CONTROL, NOINVERT
"P", ID_FILE_PAUSE, VIRTKEY, CONTROL, NOINVERT "P", ID_FILE_PAUSE, VIRTKEY, CONTROL, NOINVERT
VK_PAUSE, ID_FILE_PAUSE, VIRTKEY, NOINVERT VK_PAUSE, ID_FILE_PAUSE, VIRTKEY, NOINVERT
"R", ID_FILE_RESET, VIRTKEY, CONTROL, NOINVERT "R", ID_FILE_RESET, VIRTKEY, CONTROL, NOINVERT
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT "S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
VK_ESCAPE, ID_FILE_TOGGLEMENU, VIRTKEY, NOINVERT VK_ESCAPE, ID_FILE_TOGGLEMENU, VIRTKEY, NOINVERT

View File

@ -796,13 +796,14 @@
#define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40331 #define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40331
#define ID_Menu 40332 #define ID_Menu 40332
#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLANISOTROPIC 40333 #define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLANISOTROPIC 40333
#define ID_OPTIONS_LINK_ENABLE 40335
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 159 #define _APS_NEXT_RESOURCE_VALUE 159
#define _APS_NEXT_COMMAND_VALUE 40334 #define _APS_NEXT_COMMAND_VALUE 40336
#define _APS_NEXT_CONTROL_VALUE 1269 #define _APS_NEXT_CONTROL_VALUE 1269
#define _APS_NEXT_SYMED_VALUE 103 #define _APS_NEXT_SYMED_VALUE 103
#endif #endif