/* FCE Ultra - NES/Famicom Emulator\r
*\r
* Copyright notice for this file:\r
- * Copyright (C) 2005 CaH4e3\r
+ * Copyright (C) 2006 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
\r
#include "mapinc.h"\r
\r
-static uint16 addrlatche;\r
+static uint16 latche, latcheinit;\r
+static uint16 addrreg0, addrreg1;\r
+static void(*WSync)(void);\r
+static readfunc defread;\r
\r
-//------------------ UNLCC21 ---------------------------\r
+static DECLFW(LatchWrite)\r
+{\r
+// FCEU_printf("%04x:%02x\n",A,V);\r
+ latche=A;\r
+ WSync();\r
+}\r
+\r
+static void LatchReset(void)\r
+{\r
+ latche=latcheinit;\r
+ WSync();\r
+}\r
\r
-static DECLFW(UNLCC21Write)\r
+static void LatchPower(void)\r
{\r
- addrlatche=A;\r
- setchr8(addrlatche&1);\r
- setmirror(MI_0+((addrlatche&2)>>1));\r
+ latche=latcheinit;\r
+ WSync();\r
+ SetReadHandler(0x8000,0xFFFF,defread);\r
+ SetWriteHandler(addrreg0,addrreg1,LatchWrite);\r
}\r
\r
-static void UNLCC21Power(void)\r
+static void StateRestore(int version)\r
+{\r
+ WSync();\r
+}\r
+\r
+static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 init, uint16 adr0, uint16 adr1)\r
+{\r
+ latcheinit=init;\r
+ addrreg0=adr0;\r
+ addrreg1=adr1;\r
+ WSync=proc;\r
+ if(func)\r
+ defread=func;\r
+ else\r
+ defread=CartBR;\r
+ info->Power=LatchPower;\r
+ info->Reset=LatchReset;\r
+ GameStateRestore=StateRestore;\r
+ AddExState(&latche, 2, 0, "LATC");\r
+}\r
+\r
+//------------------ UNLCC21 ---------------------------\r
+\r
+static void UNLCC21Sync(void)\r
{\r
setprg32(0x8000,0);\r
+ setchr8(latche&1);\r
+ setmirror(MI_0+((latche&2)>>1));\r
+}\r
+\r
+void UNLCC21_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, UNLCC21Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ BMCD1038 ---------------------------\r
+\r
+static uint8 dipswitch;\r
+static void BMCD1038Sync(void)\r
+{\r
+ if(latche&0x80)\r
+ {\r
+ setprg16(0x8000,(latche&0x70)>>4);\r
+ setprg16(0xC000,(latche&0x70)>>4);\r
+ }\r
+ else\r
+ setprg32(0x8000,(latche&0x60)>>5);\r
+ setchr8(latche&7);\r
+ setmirror(((latche&8)>>3)^1);\r
+}\r
+\r
+static DECLFR(BMCD1038Read)\r
+{\r
+ if(latche&0x100)\r
+ return dipswitch;\r
+ else\r
+ return CartBR(A);\r
+}\r
+\r
+static void BMCD1038Reset(void)\r
+{\r
+ dipswitch++;\r
+ dipswitch&=3; \r
+}\r
+\r
+void BMCD1038_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, BMCD1038Sync, BMCD1038Read, 0, 0x8000, 0xFFFF);\r
+ info->Reset=BMCD1038Reset;\r
+ AddExState(&dipswitch, 1, 0, "DIPSW");\r
+}\r
+\r
+\r
+//------------------ UNL43272 ---------------------------\r
+// mapper much complex, including 16K bankswitching \r
+static void UNL43272Sync(void)\r
+{\r
+ if((latche&0x81) == 0x81)\r
+ {\r
+ setprg32(0x8000,(latche&0x38)>>3);\r
+ }\r
+ else\r
+ FCEU_printf("unrecognized command %04x!\n",latche);\r
setchr8(0);\r
- SetReadHandler(0x8000,0xFFFF,CartBR);\r
- SetWriteHandler(0x8000,0xffff,UNLCC21Write);\r
+ setmirror(0);\r
}\r
\r
-static void UNLCC21Restore(int version)\r
+static DECLFR(UNL43272Read)\r
{\r
- setchr8(addrlatche&1);\r
- setmirror(MI_0+((addrlatche&2)>>1));\r
+ if(latche&0x400)\r
+ return CartBR(A & 0xFE);\r
+ else\r
+ return CartBR(A);\r
}\r
\r
-void UNLCC21_Init(CartInfo *info)\r
+static void UNL43272Reset(void)\r
+{\r
+ latche = 0;\r
+ UNL43272Sync();\r
+}\r
+\r
+void UNL43272_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, UNL43272Sync, UNL43272Read, 0x81, 0x8000, 0xFFFF);\r
+ info->Reset=UNL43272Reset;\r
+ AddExState(&dipswitch, 1, 0, "DIPSW");\r
+}\r
+\r
+//------------------ Map 058 ---------------------------\r
+\r
+static void BMCGK192Sync(void)\r
+{\r
+ if(latche&0x40)\r
+ {\r
+ setprg16(0x8000,latche&7);\r
+ setprg16(0xC000,latche&7);\r
+ }\r
+ else\r
+ setprg32(0x8000,(latche>>1)&3);\r
+ setchr8((latche>>3)&7);\r
+ setmirror(((latche&0x80)>>7)^1);\r
+}\r
+\r
+void BMCGK192_Init(CartInfo *info)\r
+{\r
+ Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ Map 092 ---------------------------\r
+// Another two-in-one mapper, two Jaleco carts uses similar\r
+// hardware, but with different wiring.\r
+// Original code provided by LULU\r
+// Additionally, PCB contains DSP extra sound chip, used for voice samples (unemulated)\r
+\r
+static void M92Sync(void)\r
{\r
- info->Power=UNLCC21Power;\r
- GameStateRestore=UNLCC21Restore;\r
- AddExState(&addrlatche, 2, 0, "ALATC");\r
+ uint8 reg = latche & 0xF0;\r
+ setprg16(0x8000,0);\r
+ if(latche>=0x9000)\r
+ {\r
+ switch (reg)\r
+ {\r
+ case 0xD0: setprg16(0xc000, latche & 15); break;\r
+ case 0xE0: setchr8(latche & 15); break;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ switch (reg)\r
+ {\r
+ case 0xB0: setprg16(0xc000, latche & 15); break;\r
+ case 0x70: setchr8(latche & 15); break;\r
+ }\r
+ }\r
+}\r
+\r
+void Mapper92_Init(CartInfo *info)\r
+{\r
+ Latch_Init(info, M92Sync, 0, 0x80B0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ Map 200 ---------------------------\r
+\r
+static void M200Sync(void)\r
+{\r
+// FCEU_printf("A\n");\r
+ setprg16(0x8000,latche&7);\r
+ setprg16(0xC000,latche&7);\r
+ setchr8(latche&7);\r
+ setmirror((latche&8)>>3);\r
+}\r
+\r
+void Mapper200_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF);\r
+}\r
+\r
+//------------------ 190in1 ---------------------------\r
+\r
+static void BMC190in1Sync(void)\r
+{\r
+ setprg16(0x8000,(latche>>2)&0x07);\r
+ setprg16(0xC000,(latche>>2)&0x07);\r
+ setchr8((latche>>2)&0x07);\r
+ setmirror((latche&1)^1);\r
+}\r
+\r
+void BMC190in1_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//-------------- BMC810544-C-A1 ------------------------\r
+\r
+static void BMC810544CA1Sync(void)\r
+{\r
+ uint32 bank = latche>>7;\r
+ if(latche&0x40)\r
+ setprg32(0x8000,bank);\r
+ else\r
+ {\r
+ setprg16(0x8000,(bank<<1)|((latche>>5)&1));\r
+ setprg16(0xC000,(bank<<1)|((latche>>5)&1));\r
+ }\r
+ setchr8(latche&0x0f);\r
+ setmirror(((latche>>4)&1)^1);\r
+}\r
+\r
+void BMC810544CA1_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, BMC810544CA1Sync, 0, 0, 0x8000, 0xFFFF);\r
+}\r
+\r
+//-------------- BMCNTD-03 ------------------------\r
+\r
+static void BMCNTD03Sync(void)\r
+{\r
+ // 1PPP Pmcc spxx xccc\r
+ // 1000 0000 0000 0000 v\r
+ // 1001 1100 0000 0100 h\r
+ // 1011 1010 1100 0100\r
+ uint32 prg = ((latche>>10)&0x1e);\r
+ uint32 chr = ((latche&0x0300)>>5)|(latche&7);\r
+ if(latche&0x80)\r
+ {\r
+ setprg16(0x8000,prg|((latche>>6)&1));\r
+ setprg16(0xC000,prg|((latche>>6)&1));\r
+ }\r
+ else\r
+ setprg32(0x8000,prg>>1);\r
+ setchr8(chr);\r
+ setmirror(((latche>>10)&1)^1);\r
+}\r
+\r
+void BMCNTD03_Init(CartInfo *info)\r
+{ \r
+ Latch_Init(info, BMCNTD03Sync, 0, 0, 0x8000, 0xFFFF);\r
}\r