merge mappers from FCEU-mm
[fceu.git] / boards / mmc1.c
index 0eefc59..df7ddf8 100644 (file)
@@ -24,8 +24,8 @@
 static void GenMMC1Power(void);\r
 static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery);\r
 \r
-static uint8 DRegs[4];\r
-static uint8 Buffer,BufferShift;\r
+static uint8 BufferShift,DRegs[4];\r
+static uint8 Buffer;\r
 \r
 static int mmc1opts;\r
 \r
@@ -34,7 +34,7 @@ static void (*MMC1PRGHook16)(uint32 A, uint8 V);
 \r
 static uint8 *WRAM=NULL;\r
 static uint8 *CHRRAM=NULL;\r
-static int is155;\r
+static int is155, is171;\r
 \r
 static DECLFW(MBWRAM)\r
 {\r
@@ -58,6 +58,7 @@ static void MMC1CHR(void)
     else\r
       setprg8r(0x10,0x6000,(DRegs[1]>>3)&1);\r
   }\r
+\r
   if(MMC1CHRHook4)\r
   {\r
     if(DRegs[0]&0x10)\r
@@ -86,7 +87,6 @@ static void MMC1CHR(void)
 static void MMC1PRG(void)\r
 {\r
   uint8 offs=DRegs[1]&0x10;\r
-\r
   if(MMC1PRGHook16)\r
   {\r
     switch(DRegs[0]&0xC)\r
@@ -104,49 +104,54 @@ static void MMC1PRG(void)
                 break;\r
     }\r
   }\r
-  else switch(DRegs[0]&0xC)\r
+  else\r
   {\r
-    case 0xC: setprg16(0x8000,(DRegs[3]+offs));\r
-              setprg16(0xC000,0xF+offs);\r
-              break;\r
-    case 0x8: setprg16(0xC000,(DRegs[3]+offs));\r
-              setprg16(0x8000,offs);\r
-              break;\r
-    case 0x0:\r
-    case 0x4:\r
-              setprg16(0x8000,((DRegs[3]&~1)+offs));\r
-              setprg16(0xc000,((DRegs[3]&~1)+offs+1));\r
-              break;\r
+    switch(DRegs[0]&0xC)\r
+    {\r
+      case 0xC: setprg16(0x8000,(DRegs[3]+offs));\r
+                setprg16(0xC000,0xF+offs);\r
+                break;\r
+      case 0x8: setprg16(0xC000,(DRegs[3]+offs));\r
+                setprg16(0x8000,offs);\r
+                break;\r
+      case 0x0:\r
+      case 0x4:\r
+                setprg16(0x8000,((DRegs[3]&~1)+offs));\r
+                setprg16(0xc000,((DRegs[3]&~1)+offs+1));\r
+                break;\r
+    }\r
   }\r
 }\r
 \r
 static void MMC1MIRROR(void)\r
 {\r
-  switch(DRegs[0]&3)\r
-  {\r
-    case 2: setmirror(MI_V); break;\r
-    case 3: setmirror(MI_H); break;\r
-    case 0: setmirror(MI_0); break;\r
-    case 1: setmirror(MI_1); break;\r
-  }\r
+  if(!is171) \r
+    switch(DRegs[0]&3)\r
+    {\r
+      case 2: setmirror(MI_V); break;\r
+      case 3: setmirror(MI_H); break;\r
+      case 0: setmirror(MI_0); break;\r
+      case 1: setmirror(MI_1); break;\r
+    }\r
 }\r
 \r
-\r
 static uint64 lreset;\r
 static DECLFW(MMC1_write)\r
 {\r
   int n=(A>>13)-4;\r
   //FCEU_DispMessage("%016x",timestampbase+timestamp);\r
-  //printf("$%04x:$%02x, $%04x\n",A,V,X.PC);\r
+//  FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC);\r
   //DumpMem("out",0xe000,0xffff);\r
 \r
   /* The MMC1 is busy so ignore the write. */\r
   /* As of version FCE Ultra 0.81, the timestamp is only\r
      increased before each instruction is executed(in other words\r
      precision isn't that great), but this should still work to\r
-     deal with 2 writes in a row from a single RMW instruction. */\r
-  if((timestampbase+timestamp)<(lreset+2)) return;\r
-\r
+          deal with 2 writes in a row from a single RMW instruction.\r
+       */\r
+  if((timestampbase+timestamp)<(lreset+2))\r
+    return;\r
+//  FCEU_printf("Write %04x:%02x\n",A,V);\r
   if(V&0x80)\r
   {\r
     DRegs[0]|=0xC;\r
@@ -155,9 +160,12 @@ static DECLFW(MMC1_write)
     lreset=timestampbase+timestamp;\r
     return;\r
   }\r
+\r
   Buffer|=(V&1)<<(BufferShift++);\r
+\r
   if(BufferShift==5)\r
   {\r
+//    FCEU_printf("REG[%d]=%02x\n",n,Buffer);\r
     DRegs[n] = Buffer;\r
     BufferShift = Buffer = 0;\r
     switch(n)\r
@@ -175,16 +183,18 @@ static void MMC1_Restore(int version)
   MMC1MIRROR();\r
   MMC1CHR();\r
   MMC1PRG();\r
-  //lreset=0;        /* timestamp(base) is not stored in save states. */ // it is now!\r
+  lreset=0;        /* timestamp(base) is not stored in save states. */\r
 }\r
 \r
 static void MMC1CMReset(void)\r
 {\r
   int i;\r
+\r
   for(i=0;i<4;i++)\r
      DRegs[i]=0;\r
   Buffer = BufferShift = 0;\r
   DRegs[0]=0x1F;\r
+\r
   DRegs[1]=0;\r
   DRegs[2]=0;                  // Should this be something other than 0?\r
   DRegs[3]=0;\r
@@ -203,6 +213,8 @@ static int DetectMMC1WRAMSize(uint32 crc32)
     case 0x4642dda6:       /* Nobunaga's Ambition */\r
     case 0x29449ba9:       /* ""        "" (J) */\r
     case 0x2b11e0b0:       /* ""        "" (J) */\r
+    case 0xb8747abf:       /* Best Play Pro Yakyuu Special (J) */\r
+    case 0xc9556b36:       /* Final Fantasy I & II (J) [!] */\r
          FCEU_printf(" >8KB external WRAM present.  Use UNIF if you hack the ROM image.\n");\r
          return(16);\r
          break;\r
@@ -214,7 +226,7 @@ static uint32 NWCIRQCount;
 static uint8 NWCRec;\r
 #define NWCDIP 0xE\r
 \r
-static void FP_FASTAPASS(1) NWCIRQHook(int a)\r
+static void NWCIRQHook(int a)\r
 {\r
   if(!(NWCRec&0x10))\r
   {\r
@@ -234,6 +246,7 @@ static void NWCCHRHook(uint32 A, uint8 V)
     NWCIRQCount=0;\r
     X6502_IRQEnd(FCEU_IQEXT);\r
   }\r
+\r
   NWCRec=V;\r
   if(V&0x08)\r
     MMC1PRG();\r
@@ -333,8 +346,6 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery)
   info->Power=GenMMC1Power;\r
   GameStateRestore=MMC1_Restore;\r
   AddExState(&lreset, 8, 1, "LRST");\r
-  AddExState(&Buffer, 1, 1, "BFFR");\r
-  AddExState(&BufferShift, 1, 1, "BFRS");\r
 }\r
 \r
 void Mapper1_Init(CartInfo *info)\r
@@ -350,6 +361,14 @@ void Mapper155_Init(CartInfo *info)
   is155=1;\r
 }\r
 \r
+/* Same as mapper 1, with different (or without) mirroring control. */\r
+/* Kaiser KS7058 board, KS203 custom chip */\r
+void Mapper171_Init(CartInfo *info)\r
+{\r
+  GenMMC1Init(info,32,32,0,0);\r
+  is171=1;\r
+}\r
+\r
 void SAROM_Init(CartInfo *info)\r
 {\r
   GenMMC1Init(info, 128, 64, 8, info->battery);\r