merge mapper code from FCEUX
[fceu.git] / boards / 222.c
index fd3cc8a..e230751 100644 (file)
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2005 CaH4e3
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- *
- */
-
-#include "mapinc.h"
-
-static uint16 IRQCount;
-static uint8 IRQa;
-static uint8 prg_reg[2];
-static uint8 chr_reg[8];
-
-static SFORMAT StateRegs[]=
-{
-  {&IRQCount, 2, "IRQC"},
-  {&IRQa, 2, "IRQA"},
-  {prg_reg, 2, "PRG"},
-  {chr_reg, 8, "CHR"},
-  {0}
-};
-
-static void M222IRQ(void)
-{
-  if(IRQa)
-  {
-    IRQCount++;
-    if(IRQCount>=240)
-    {
-      X6502_IRQBegin(FCEU_IQEXT);
-      IRQa=0;
-    }
-  }
-}
-
-static void Sync(void)
-{
-  setprg8(0x8000,prg_reg[0]);
-  setprg8(0xA000,prg_reg[1]);
-  int i;
-  for(i=0; i<8; i++)
-     setchr1(i<<10,chr_reg[i]);     
-}
-
-static DECLFW(M222Write)
-{
-  switch(A&0xF003)
-  {
-    case 0x8000: prg_reg[0]=V; break;
-    case 0xA000: prg_reg[1]=V; break;
-    case 0xB000: chr_reg[0]=V; break;
-    case 0xB002: chr_reg[1]=V; break;
-    case 0xC000: chr_reg[2]=V; break;
-    case 0xC002: chr_reg[3]=V; break;
-    case 0xD000: chr_reg[4]=V; break;
-    case 0xD002: chr_reg[5]=V; break;
-    case 0xE000: chr_reg[6]=V; break;
-    case 0xE002: chr_reg[7]=V; break;
-    case 0xF000: IRQCount=IRQa=V;
-                 X6502_IRQEnd(FCEU_IQEXT);
-                 break;
-  }
-  Sync();
-}
-
-static void M222Power(void)
-{
-  setprg16(0xC000,~0);
-  SetReadHandler(0x8000,0xFFFF,CartBR);
-  SetWriteHandler(0x8000,0xFFFF,M222Write);
-}
-
-static void StateRestore(int version)
-{
-  Sync();
-}
-
-void Mapper222_Init(CartInfo *info)
-{
-  info->Power=M222Power;
-  GameHBIRQHook=M222IRQ;
-  GameStateRestore=StateRestore;
-  AddExState(&StateRegs, ~0, 0, 0);
-}
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2005 CaH4e3\r
+ *\r
+ * This program is free software; you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation; either version 2 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\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
+ * (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 IRQCount;\r
+static uint8 IRQa;\r
+static uint8 prg_reg[2];\r
+static uint8 chr_reg[8];\r
+static uint8 mirr;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {&IRQCount, 1, "IRQC"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {prg_reg, 2, "PRG"},\r
+  {chr_reg, 8, "CHR"},\r
+  {&mirr, 1, "MIRR"},\r
+  {0}\r
+};\r
+\r
+static void M222IRQ(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if(IRQCount>=238)\r
+    {\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+//      IRQa=0;\r
+    }\r
+  }\r
+}\r
+\r
+static void Sync(void)\r
+{\r
+  int i;\r
+  setprg8(0x8000,prg_reg[0]);\r
+  setprg8(0xA000,prg_reg[1]);\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr_reg[i]);\r
+  setmirror(mirr^1);\r
+}\r
+\r
+static DECLFW(M222Write)\r
+{\r
+  switch(A&0xF003)\r
+  {\r
+    case 0x8000: prg_reg[0]=V; break;\r
+    case 0x9000: mirr=V&1;     break;\r
+    case 0xA000: prg_reg[1]=V; break;\r
+    case 0xB000: chr_reg[0]=V; break;\r
+    case 0xB002: chr_reg[1]=V; break;\r
+    case 0xC000: chr_reg[2]=V; break;\r
+    case 0xC002: chr_reg[3]=V; break;\r
+    case 0xD000: chr_reg[4]=V; break;\r
+    case 0xD002: chr_reg[5]=V; break;\r
+    case 0xE000: chr_reg[6]=V; break;\r
+    case 0xE002: chr_reg[7]=V; break;\r
+//    case 0xF000: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+//  /  case 0xF001: FCEU_printf("%04x:%02x %d\n",A,V,scanline); IRQCount=V; break;\r
+//    case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+//    case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+//    case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break;\r
+    case 0xF000: IRQa=IRQCount=V; if(scanline<240) IRQCount-=8; else IRQCount+=4; X6502_IRQEnd(FCEU_IQEXT); break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void M222Power(void)\r
+{\r
+  setprg16(0xC000,~0);\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M222Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void Mapper222_Init(CartInfo *info)\r
+{\r
+  info->Power=M222Power;\r
+  GameHBIRQHook=M222IRQ;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r