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

View File

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

View File

@ -37,10 +37,9 @@ int linktime = 0;
u8 tspeed=3;
u8 transfer=0;
LINKDATA *linkmem=NULL;
int linkid = 1, vbaid = 1;
int linkid = 0, vbaid = 0;
HANDLE linksync[4];
int savedlinktime=0;
char inifile[] = "vba1.ini";
HANDLE mmf=NULL;
char linkevent[] = "VBA link event ";
static int i, j;
@ -54,6 +53,7 @@ lserver ls;
lclient lc;
bool oncewait = false, after = false;
bool adapter = false;
bool linkenable = false;
u8 rfu_cmd, rfu_qsend, rfu_qrecv;
int rfu_state, rfu_polarity, linktime2, counter, rfu_masterq;
int transferend, numtransfers = 0;
@ -72,6 +72,22 @@ int StartServer(void);
int GetSioMode(u16, 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){
if(ioMem==NULL) return;
if(adapter){
@ -160,6 +176,8 @@ void StartGPLink(u16 value){
else if(!adapter) fprintf(linklogfile, "Attempt to use General-purpose mode %04x\n", value);
}
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;
case JOYBUS:
UPDATE_REG(0x134, value);
@ -549,7 +567,6 @@ int InitLink(void){
BOOL disable = true;
linkid = 0;
inifile[3]='1';
if(WSAStartup(MAKEWORD(1,1), &wsadata)!=0){
WSACleanup();
@ -588,7 +605,6 @@ int InitLink(void){
vbaid = 0;
if(vbaid==0){
inifile[3]='1';
linkid = 0;
if(linkmem->linkflags&LINK_PARENTLOST){
linkmem->numgbas++;
@ -615,6 +631,7 @@ int InitLink(void){
vbaid=linkmem->numgbas;
linkid = vbaid;
linkmem->numgbas++;
linklog = 0;
if(linkmem->numgbas>4){
linkmem->numgbas=4;
@ -625,7 +642,6 @@ int InitLink(void){
CloseHandle(mmf);
return 0;
}
inifile[3]=(char)linkmem->numgbas+'0';
for(i=0;i<4;i++){
linkevent[15]=(char)i+'1';
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 void closeLinkLog();
extern void CloseLanLink(void);
extern char *MakeInstanceFilename(const char *Input);
extern LANLINKDATA lanlink;
extern FILE *linklogfile;
extern int vbaid;
extern int linklog;
extern bool adapter;
extern bool linkenable;
extern int linktimeout;
extern lclient lc;
extern int linkid;

View File

@ -43,6 +43,7 @@
#include "../RTC.h"
#include "../Sound.h"
#include "../Util.h"
#include "../Link.h"
#ifdef _DEBUG
#define new DEBUG_NEW
@ -386,6 +387,9 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_LOG, OnUpdateOptionsLinkLog)
ON_COMMAND(ID_OPTIONS_LINK_WIRELESSADAPTER, OnOptionsLinkRFU)
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
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)
@ -932,7 +936,7 @@ void MainWnd::writeBatteryFile()
filename.Format("%s\\%s.sav", saveDir, buffer);
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;
if(theApp.emulator.emuReadBattery)
res = theApp.emulator.emuReadBattery(filename);
res = theApp.emulator.emuReadBattery(MakeInstanceFilename(filename));
if(res)
systemScreenMessage(winResLoadString(IDS_LOADED_BATTERY));

View File

@ -433,12 +433,13 @@ public:
afx_msg void OnOptionsVideoFullscreen1024x768();
afx_msg void OnUpdateOptionsVideoFullscreen1024x768(CCmdUI *pCmdUI);
afx_msg void OnUpdateOptionsVideoFullscreen1280x1024(CCmdUI *pCmdUI);
void OnLinkOptions();
void OnOptionsLinkLog() ;
void OnUpdateOptionsLinkLog(CCmdUI* pCmdUI) ;
void OnOptionsLinkRFU() ;
void OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI) ;
afx_msg void OnLinkOptions();
afx_msg void OnOptionsLinkLog() ;
afx_msg void OnUpdateOptionsLinkLog(CCmdUI* pCmdUI) ;
afx_msg void OnOptionsLinkRFU() ;
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)
{
pCmdUI->SetCheck(adapter);

View File

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

View File

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

View File

@ -1799,6 +1799,7 @@ BEGIN
END
POPUP "Li&nk"
BEGIN
MENUITEM "Enable GBA Linking", ID_OPTIONS_LINK_ENABLE
MENUITEM "&Wireless Adapter", ID_OPTIONS_LINK_WIRELESSADAPTER
MENUITEM "&Log", ID_OPTIONS_LINK_LOG
MENUITEM "&Options...", ID_OPTIONS_LINK_OPTIONS
@ -1888,7 +1889,7 @@ BEGIN
"N", ID_DEBUG_NEXTFRAME, VIRTKEY, CONTROL, NOINVERT
"O", ID_FILE_OPEN, 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
"S", ID_FILE_SAVE, VIRTKEY, CONTROL, NOINVERT
VK_ESCAPE, ID_FILE_TOGGLEMENU, VIRTKEY, NOINVERT

View File

@ -796,13 +796,14 @@
#define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40331
#define ID_Menu 40332
#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLANISOTROPIC 40333
#define ID_OPTIONS_LINK_ENABLE 40335
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#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_SYMED_VALUE 103
#endif