merge mapper code from FCEUX
[fceu.git] / boards / ax5705.c
diff --git a/boards/ax5705.c b/boards/ax5705.c
new file mode 100644 (file)
index 0000000..66f1498
--- /dev/null
@@ -0,0 +1,122 @@
+/* FCE Ultra - NES/Famicom Emulator\r
+ *\r
+ * Copyright notice for this file:\r
+ *  Copyright (C) 2007 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
+ *\r
+ * Super Bros. Pocker Mali (VRC4 mapper)\r
+ */\r
+\r
+#include "mapinc.h"\r
+\r
+static uint8 IRQCount;//, IRQPre;\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
+/*\r
+static void UNLAX5705IRQ(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
+  setprg8(0xC000,~1);\r
+  setprg8(0xE000,~0);\r
+  for(i=0; i<8; i++)\r
+     setchr1(i<<10,chr_reg[i]);     \r
+  setmirror(mirr^1);   \r
+}\r
+\r
+static DECLFW(UNLAX5705Write)\r
+{\r
+//  if((A>=0xA008)&&(A<=0xE003))\r
+//  {\r
+//    int ind=(((A>>11)-6)|(A&1))&7;\r
+//    int sar=((A&2)<<1);\r
+//    chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<<sar);\r
+//    SyncChr();\r
+//  }\r
+//  else \r
+  switch(A&0xF00F)\r
+  {\r
+    case 0x8000: prg_reg[0]=((V&2)<<2)|((V&8)>>2)|(V&5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed\r
+    case 0x8008: mirr=V&1; break;\r
+    case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break;\r
+    case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break;\r
+    case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break;\r
+    case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break;\r
+    case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break;\r
+    case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break;\r
+    case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break;\r
+    case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break;\r
+    case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+    case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break;\r
+    case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break;\r
+//    case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;\r
+//    case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/  break;\r
+  }\r
+  Sync();\r
+}\r
+\r
+static void UNLAX5705Power(void)\r
+{\r
+  Sync();\r
+  SetReadHandler(0x8000,0xFFFF,CartBR);\r
+  SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write);\r
+}\r
+\r
+static void StateRestore(int version)\r
+{\r
+  Sync();\r
+}\r
+\r
+void UNLAX5705_Init(CartInfo *info)\r
+{\r
+  info->Power=UNLAX5705Power;\r
+//  GameHBIRQHook=UNLAX5705IRQ;\r
+  GameStateRestore=StateRestore;\r
+  AddExState(&StateRegs, ~0, 0, 0);\r
+}\r