merge mappers from FCEU-mm
[fceu.git] / boards / 199.c
index ed21278..3302dc6 100644 (file)
@@ -15,7 +15,7 @@
  *\r
  * You should have received a copy of the GNU General Public License\r
  * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\r
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
  *\r
  * Dragon Ball Z 2 - Gekishin Freeza! (C)\r
  * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C)\r
@@ -26,7 +26,8 @@
 #include "mapinc.h"\r
 #include "mmc3.h"\r
 \r
-static uint8 *CHRRAM=NULL; // and here too\r
+static uint8 *CHRRAM=NULL;\r
+static uint32 CHRRAMSIZE;\r
 \r
 static void M199PW(uint32 A, uint8 V)\r
 {\r
@@ -60,7 +61,6 @@ static DECLFW(M199Write)
 {\r
   if((A==0x8001)&&(MMC3_cmd&8))\r
   {\r
-//    FCEU_printf("%02x=>%02x\n",MMC3_cmd,V);\r
     EXPREGS[MMC3_cmd&3]=V;\r
     FixMMC3PRG(MMC3_cmd);\r
     FixMMC3CHR(MMC3_cmd);\r
@@ -82,16 +82,26 @@ static void M199Power(void)
   SetWriteHandler(0x8000,0xFFFF,M199Write);\r
 }\r
 \r
+static void M199Close(void)\r
+{\r
+  if(CHRRAM)\r
+    FCEU_gfree(CHRRAM);\r
+  CHRRAM=NULL;\r
+}\r
+\r
 void Mapper199_Init(CartInfo *info)\r
 {\r
-  int CHRRAMSize=1024*8;\r
   GenMMC3_Init(info, 512, 256, 8, info->battery);\r
   cwrap=M199CW;\r
   pwrap=M199PW;\r
   mwrap=M199MW;\r
   info->Power=M199Power;\r
-  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);\r
-  SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);\r
-  AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");\r
+  info->Close=M199Close;\r
+\r
+  CHRRAMSIZE=8192;\r
+  CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE);\r
+  SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1);\r
+  AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR");\r
+\r
   AddExState(EXPREGS, 4, 0, "EXPR");\r
 }\r