From 108a8070172ccd7e5f12aa323b9dfd99a90c52e4 Mon Sep 17 00:00:00 2001 From: stephena Date: Tue, 30 Mar 2010 20:36:13 +0000 Subject: [PATCH] Added debugger patch support for bankswitch schemes CV, DPC, DPC+ and E7. DPC and DPC+ currently do not modify the DPC address space on a patch; more research is required to figure out how to handle this. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1980 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba --- src/emucore/CartCV.cxx | 23 +++++++++++++++++++---- src/emucore/CartDPC.cxx | 18 +++++++++++++----- src/emucore/CartDPCPlus.cxx | 16 ++++++++++++---- src/emucore/CartE7.cxx | 26 ++++++++++++++++++++++++-- src/emucore/CartEFSC.cxx | 8 ++------ src/emucore/CartF4SC.cxx | 8 ++------ src/emucore/CartF6SC.cxx | 8 ++------ src/emucore/CartF8SC.cxx | 8 ++------ src/emucore/CartFA.cxx | 8 ++------ 9 files changed, 78 insertions(+), 45 deletions(-) diff --git a/src/emucore/CartCV.cxx b/src/emucore/CartCV.cxx index 972dfb4cd..40e86dcf8 100644 --- a/src/emucore/CartCV.cxx +++ b/src/emucore/CartCV.cxx @@ -72,6 +72,8 @@ void CartridgeCV::reset() for(uInt32 i = 0; i < 1024; ++i) myRAM[i] = mySystem->randGenerator().next(); } + + myBankChanged = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -139,7 +141,9 @@ uInt8 CartridgeCV::peek(uInt16 address) // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeCV::poke(uInt16, uInt8) { - // This is ROM so poking has no effect :-) + // NOTE: This does not handle accessing RAM, however, this function + // should never be called for RAM because of the way page accessing + // has been setup return false; } @@ -165,9 +169,20 @@ int CartridgeCV::bankCount() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeCV::patch(uInt16 address, uInt8 value) { - // TODO - ROM vs RAM in patching - myImage[address & 0x07FF] = value; - return true; + address &= 0x0FFF; + + if(address < 0x0800) + { + // Normally, a write to the read port won't do anything + // However, the patch command is special in that ignores such + // cart restrictions + // The following will work for both reads and writes + myRAM[address & 0x03FF] = value; + } + else + myImage[address & 0x07FF] = value; + + return myBankChanged = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartDPC.cxx b/src/emucore/CartDPC.cxx index 88e9fec7f..c3b2728be 100644 --- a/src/emucore/CartDPC.cxx +++ b/src/emucore/CartDPC.cxx @@ -346,14 +346,14 @@ bool CartridgeDPC::poke(uInt16 address, uInt8 value) { if((index >= 5) && myMusicMode[index - 5]) { - // Data fecther is in music mode so its low counter value + // Data fetcher is in music mode so its low counter value // should be loaded from the top register not the poked value myCounters[index] = (myCounters[index] & 0x0700) | (uInt16)myTops[index]; } else { - // Data fecther is either not a music mode data fecther or it + // Data fetcher is either not a music mode data fetcher or it // isn't in music mode so it's low counter value should be loaded // with the poked value myCounters[index] = (myCounters[index] & 0x0700) | (uInt16)value; @@ -421,7 +421,7 @@ void CartridgeDPC::bank(uInt16 bank) // Remember what bank we're in myCurrentBank = bank; - uInt16 offset = myCurrentBank * 4096; + uInt16 offset = myCurrentBank << 12; uInt16 shift = mySystem->pageShift(); uInt16 mask = mySystem->pageMask(); @@ -455,8 +455,16 @@ int CartridgeDPC::bankCount() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeDPC::patch(uInt16 address, uInt8 value) { - myProgramImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value; - return true; + address &= 0x0FFF; + + // For now, we ignore attempts to patch the DPC address space + if(address >= 0x0080) + { + myProgramImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value; + return myBankChanged = true; + } + else + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartDPCPlus.cxx b/src/emucore/CartDPCPlus.cxx index 23b49dd00..3c5c27594 100644 --- a/src/emucore/CartDPCPlus.cxx +++ b/src/emucore/CartDPCPlus.cxx @@ -315,7 +315,7 @@ uInt8 CartridgeDPCPlus::peek(uInt16 address) default: break; } - return myProgramImage[myCurrentBank * 4096 + address]; + return myProgramImage[(myCurrentBank << 12) + address]; } } @@ -501,7 +501,7 @@ void CartridgeDPCPlus::bank(uInt16 bank) // Remember what bank we're in myCurrentBank = bank; - uInt16 offset = myCurrentBank * 4096; + uInt16 offset = myCurrentBank << 12; uInt16 shift = mySystem->pageShift(); uInt16 mask = mySystem->pageMask(); @@ -535,8 +535,16 @@ int CartridgeDPCPlus::bankCount() // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - bool CartridgeDPCPlus::patch(uInt16 address, uInt8 value) { - myProgramImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value; - return myBankChanged = true; + address &= 0x0FFF; + + // For now, we ignore attempts to patch the DPC address space + if(address >= 0x0080) + { + myProgramImage[(myCurrentBank << 12) + (address & 0x0FFF)] = value; + return myBankChanged = true; + } + else + return false; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartE7.cxx b/src/emucore/CartE7.cxx index 4af29577b..1237e184f 100644 --- a/src/emucore/CartE7.cxx +++ b/src/emucore/CartE7.cxx @@ -258,8 +258,30 @@ int CartridgeE7::bankCount() bool CartridgeE7::patch(uInt16 address, uInt8 value) { address = address & 0x0FFF; - myImage[(myCurrentSlice[address >> 11] << 11) + (address & 0x07FF)] = value; - return true; + + if(address < 0x0800) + { + if(myCurrentSlice[0] == 7) + { + // Normally, a write to the read port won't do anything + // However, the patch command is special in that ignores such + // cart restrictions + myRAM[address & 0x03FF] = value; + } + else + myImage[(myCurrentSlice[0] << 11) + (address & 0x07FF)] = value; + } + else if(address < 0x0900) + { + // Normally, a write to the read port won't do anything + // However, the patch command is special in that ignores such + // cart restrictions + myRAM[1024 + (myCurrentRAM << 8) + (address & 0x00FF)] = value; + } + else + myImage[(myCurrentSlice[address >> 11] << 11) + (address & 0x07FF)] = value; + + return myBankChanged = true; } // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/emucore/CartEFSC.cxx b/src/emucore/CartEFSC.cxx index 06e1eef82..fc2fd46fe 100644 --- a/src/emucore/CartEFSC.cxx +++ b/src/emucore/CartEFSC.cxx @@ -178,16 +178,12 @@ bool CartridgeEFSC::patch(uInt16 address, uInt8 value) { address &= 0x0FFF; - if(address < 0x0080) - { - myRAM[address] = value; - } - else if(address < 0x0100) + if(address < 0x0100) { // Normally, a write to the read port won't do anything // However, the patch command is special in that ignores such // cart restrictions - myRAM[address - 0x80] = value; + myRAM[address & 0x007F] = value; } else myImage[(myCurrentBank << 12) + address] = value; diff --git a/src/emucore/CartF4SC.cxx b/src/emucore/CartF4SC.cxx index de57c01cd..789c79e60 100644 --- a/src/emucore/CartF4SC.cxx +++ b/src/emucore/CartF4SC.cxx @@ -181,16 +181,12 @@ bool CartridgeF4SC::patch(uInt16 address, uInt8 value) { address &= 0x0FFF; - if(address < 0x0080) - { - myRAM[address] = value; - } - else if(address < 0x0100) + if(address < 0x0100) { // Normally, a write to the read port won't do anything // However, the patch command is special in that ignores such // cart restrictions - myRAM[address - 0x80] = value; + myRAM[address & 0x007F] = value; } else myImage[(myCurrentBank << 12) + address] = value; diff --git a/src/emucore/CartF6SC.cxx b/src/emucore/CartF6SC.cxx index 84c2b0c99..6c1792667 100644 --- a/src/emucore/CartF6SC.cxx +++ b/src/emucore/CartF6SC.cxx @@ -224,16 +224,12 @@ bool CartridgeF6SC::patch(uInt16 address, uInt8 value) { address &= 0x0FFF; - if(address < 0x0080) - { - myRAM[address] = value; - } - else if(address < 0x0100) + if(address < 0x0100) { // Normally, a write to the read port won't do anything // However, the patch command is special in that ignores such // cart restrictions - myRAM[address - 0x80] = value; + myRAM[address & 0x007F] = value; } else myImage[(myCurrentBank << 12) + address] = value; diff --git a/src/emucore/CartF8SC.cxx b/src/emucore/CartF8SC.cxx index f67a6ec5f..d10315c88 100644 --- a/src/emucore/CartF8SC.cxx +++ b/src/emucore/CartF8SC.cxx @@ -204,16 +204,12 @@ bool CartridgeF8SC::patch(uInt16 address, uInt8 value) { address &= 0x0FFF; - if(address < 0x0080) - { - myRAM[address] = value; - } - else if(address < 0x0100) + if(address < 0x0100) { // Normally, a write to the read port won't do anything // However, the patch command is special in that ignores such // cart restrictions - myRAM[address - 0x80] = value; + myRAM[address & 0x007F] = value; } else myImage[(myCurrentBank << 12) + address] = value; diff --git a/src/emucore/CartFA.cxx b/src/emucore/CartFA.cxx index e88d97dc9..29750ad0d 100644 --- a/src/emucore/CartFA.cxx +++ b/src/emucore/CartFA.cxx @@ -214,16 +214,12 @@ bool CartridgeFA::patch(uInt16 address, uInt8 value) { address &= 0x0FFF; - if(address < 0x0100) - { - myRAM[address] = value; - } - else if(address < 0x0200) + if(address < 0x0200) { // Normally, a write to the read port won't do anything // However, the patch command is special in that ignores such // cart restrictions - myRAM[address - 0x100] = value; + myRAM[address & 0x00FF] = value; } else myImage[(myCurrentBank << 12) + address] = value;