updated bords/mappers/stuff to 0.98.15, lots of them got broken, asmcore support...
[fceu.git] / boards / 183.c
diff --git a/boards/183.c b/boards/183.c
new file mode 100644 (file)
index 0000000..94cf072
--- /dev/null
@@ -0,0 +1,117 @@
+/* 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+ *\r
+ * Gimmick Bootleg\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 prg[4];\r
+static uint8 chr[8];\r
+static uint8 IRQCount;\r
+static uint8 IRQPre;\r
+static uint8 IRQa;\r
+\r
+static SFORMAT StateRegs[]=\r
+{\r
+  {prg, 4, "PRG"},\r
+  {chr, 8, "CHR"},\r
+  {&IRQCount, 1, "IRQCOUNT"},\r
+  {&IRQPre, 1, "IRQPRE"},\r
+  {&IRQa, 1, "IRQA"},\r
+  {0}\r
+};\r
+\r
+static void SyncPrg(void)\r
+{\r
+  setprg8(0x6000,0);\r
+  setprg8(0x8000,prg[0]);\r
+  setprg8(0xA000,prg[1]);\r
+  setprg8(0xC000,prg[2]);\r
+  setprg8(0xE000,~0);\r
+}\r
+\r
+static void SyncChr(void)\r
+{\r
+  int i;\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr[i]);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+static DECLFW(M183Write)\r
+{\r
+  if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C))\r
+  {\r
+    uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3);\r
+    chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4));\r
+    SyncChr();\r
+  }\r
+  else switch (A&0xF80C)\r
+  {\r
+    case 0x8800: prg[0]=V; SyncPrg(); break;\r
+    case 0xA800: prg[1]=V; SyncPrg(); break;\r
+    case 0xA000: prg[2]=V; SyncPrg(); break;\r
+    case 0x9800: switch (V&3)\r
+                 {\r
+                   case 0: setmirror(MI_V); break;\r
+                   case 1: setmirror(MI_H); break;\r
+                   case 2: setmirror(MI_0); break;\r
+                   case 3: setmirror(MI_1); break;\r
+                 }\r
+                 break;\r
+    case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break;\r
+    case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break;\r
+    case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break;\r
+    case 0xF00C: IRQPre=16; break;\r
+  }\r
+}\r
+\r
+static void M183IRQCounter(void)\r
+{\r
+  if(IRQa)\r
+  {\r
+    IRQCount++;\r
+    if((IRQCount-IRQPre)==238)\r
+      X6502_IRQBegin(FCEU_IQEXT);\r
+  }\r
+}\r
+\r
+static void M183Power(void)\r
+{\r
+  IRQPre=IRQCount=IRQa=0;\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,M183Write);\r
+  SetReadHandler(0x6000,0x7FFF,CartBR);\r
+  SyncPrg();\r
+  SyncChr();\r
+}\r
+\r
+void Mapper183_Init(CartInfo *info)\r
+{\r
+  info->Power=M183Power;\r
+  GameHBIRQHook=M183IRQCounter;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r