1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 1998 BERO
5 * Copyright (C) 2003 Xodnizel
6 * Mapper 12 code Copyright (C) 2003 CaH4e3
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 /* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118,
24 119,148,165,205,214,215,245,249,250,254
34 uint8 EXPREGS[8]; /* For bootleg games, mostly. */
36 static uint8 A000B,A001B;
37 static uint8 DRegBuf[8];
42 uint8 IRQCount,IRQLatch,IRQa;
45 static SFORMAT MMC3_StateRegs[]=
48 {&MMC3_cmd, 1, "CMD"},
51 {&IRQReload, 1, "IRQR"},
52 {&IRQCount, 1, "IRQC"},
53 {&IRQLatch, 1, "IRQL"},
58 static int mmc3opts=0;
62 void (*pwrap)(uint32 A, uint8 V);
63 void (*cwrap)(uint32 A, uint8 V);
64 void (*mwrap)(uint8 V);
66 void GenMMC3Power(void);
67 void FixMMC3PRG(int V);
68 void FixMMC3CHR(int V);
70 void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery);
72 // ----------------------------------------------------------------------
73 // ------------------------- Generic MM3 Code ---------------------------
74 // ----------------------------------------------------------------------
76 void FixMMC3PRG(int V)
80 pwrap(0xC000,DRegBuf[6]);
85 pwrap(0x8000,DRegBuf[6]);
88 pwrap(0xA000,DRegBuf[7]);
92 void FixMMC3CHR(int V)
94 int cbase=(V&0x80)<<5;
96 cwrap((cbase^0x000),DRegBuf[0]&(~1));
97 cwrap((cbase^0x400),DRegBuf[0]|1);
98 cwrap((cbase^0x800),DRegBuf[1]&(~1));
99 cwrap((cbase^0xC00),DRegBuf[1]|1);
101 cwrap(cbase^0x1000,DRegBuf[2]);
102 cwrap(cbase^0x1400,DRegBuf[3]);
103 cwrap(cbase^0x1800,DRegBuf[4]);
104 cwrap(cbase^0x1c00,DRegBuf[5]);
107 void MMC3RegReset(void)
109 IRQCount=IRQLatch=IRQa=MMC3_cmd=0;
124 DECLFW(MMC3_CMDWrite)
126 // FCEU_printf("%04x:%04x\n",A,V);
130 if((V&0x40) != (MMC3_cmd&0x40))
132 if((V&0x80) != (MMC3_cmd&0x80))
138 int cbase=(MMC3_cmd&0x80)<<5;
139 DRegBuf[MMC3_cmd&0x7]=V;
140 switch(MMC3_cmd&0x07)
142 case 0: cwrap((cbase^0x000),V&(~1));
143 cwrap((cbase^0x400),V|1);
145 case 1: cwrap((cbase^0x800),V&(~1));
146 cwrap((cbase^0xC00),V|1);
148 case 2: cwrap(cbase^0x1000,V);
150 case 3: cwrap(cbase^0x1400,V);
152 case 4: cwrap(cbase^0x1800,V);
154 case 5: cwrap(cbase^0x1C00,V);
169 if(mwrap) mwrap(V&1);
173 //Write_IRQFM(0x4017,0x40);
175 writefunc f = GetWriteHandler(0x4017);
182 DECLFW(MMC3_IRQWrite)
184 // FCEU_printf("%04x:%04x\n",A,V);
187 case 0xC000:IRQLatch=V;break;
188 case 0xC001:IRQReload=1;break;
189 case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break;
190 case 0xE001:IRQa=1;break;
194 static void ClockMMC3Counter(void)
196 int count = IRQCount;
197 if(!count || IRQReload)
204 if((count|isRevB) && !IRQCount)
208 X6502_IRQBegin(FCEU_IQEXT);
213 static void MMC3_hb(void)
218 static void MMC3_hb_KickMasterHack(void)
220 if(scanline==238) ClockMMC3Counter();
224 static void MMC3_hb_PALStarWarsHack(void)
226 if(scanline==240) ClockMMC3Counter();
230 void GenMMC3Restore(int version)
232 if(mwrap) mwrap(A000B&1);
233 FixMMC3PRG(MMC3_cmd);
234 FixMMC3CHR(MMC3_cmd);
237 static void GENCWRAP(uint32 A, uint8 V)
239 if(!UNIFchrrama) setchr1(A,V);
242 static void GENPWRAP(uint32 A, uint8 V)
247 static void GENMWRAP(uint8 V)
253 static void GENNOMWRAP(uint8 V)
258 static DECLFW(MBWRAM)
263 static DECLFR(MAWRAM)
265 return(WRAM[A-0x6000]);
268 static DECLFW(MBWRAMMMC6)
273 static DECLFR(MAWRAMMMC6)
275 return(WRAM[A&0x3ff]);
278 void GenMMC3Power(void)
280 if(UNIFchrrama) setchr8(0);
282 SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);
283 SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
284 SetReadHandler(0x8000,0xFFFF,CartBR);
291 FCEU_CheatAddRAM(1,0x7000,WRAM);
292 SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);
293 SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);
295 // asm code needs pages to be set again..
296 Page[14]=Page[15]=WRAM-0x7000;
301 FCEU_CheatAddRAM(wrams>>10,0x6000,WRAM);
302 SetReadHandler(0x6000,0x6000+wrams-1,MAWRAM);
303 SetWriteHandler(0x6000,0x6000+wrams-1,MBWRAM);
307 for (addr=0x6000; addr < 0x6000+wrams-0x7ff; addr += 0x800)
309 Page[addr>>11]=WRAM - 0x6000;
315 FCEU_dwmemset(WRAM,0,wrams);
319 FCEU_dwmemset(CHRRAM,0,CHRRAMSize);
322 static void GenMMC3Close(void)
331 //static uint16 _a12;
332 //static void FP_FASTAPASS(1) MMC3_PPU(uint32 A)
334 // if(A&0x2000)return;
335 // if((!_a12)&&(A&0x1000))
336 // ClockMMC3Counter();
340 void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)
348 PRGmask8[0]&=(prg>>13)-1;
349 CHRmask1[0]&=(chr>>10)-1;
350 CHRmask2[0]&=(chr>>11)-1;
355 WRAM=(uint8*)FCEU_gmalloc(wrams);
356 AddExState(WRAM, wrams, 0, "WRAM");
362 info->SaveGame[0]=WRAM;
363 info->SaveGameLen[0]=wrams;
366 // if(!chr) // duplicated CHR RAM set up
368 // CHRRAM=(uint8*)FCEU_gmalloc(8192);
370 // SetupCartCHRMapping(0, CHRRAM, 8192, 1);
371 // AddExState(CHRRAM, 8192, 0, "CHRR");
374 AddExState(MMC3_StateRegs, ~0, 0, 0);
376 info->Power=GenMMC3Power;
377 info->Reset=MMC3RegReset;
378 info->Close=GenMMC3Close;
380 if(info->CRC32 == 0x5104833e) // Kick Master
381 GameHBIRQHook = MMC3_hb_KickMasterHack;
382 else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93
383 GameHBIRQHook = MMC3_hb_KickMasterHack;
384 else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master.
385 GameHBIRQHook = MMC3_hb_PALStarWarsHack;
387 GameHBIRQHook=MMC3_hb;
388 // PPU_hook=MMC3_PPU;
389 GameStateRestore=GenMMC3Restore;
392 // ----------------------------------------------------------------------
393 // -------------------------- MMC3 Based Code ---------------------------
394 // ----------------------------------------------------------------------
396 // ---------------------------- Mapper 4 --------------------------------
398 static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/
400 static void M4Power(void)
407 void Mapper4_Init(CartInfo *info)
411 if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84))
413 FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n");
416 GenMMC3_Init(info,512,256,ws,info->battery);
421 // ---------------------------- Mapper 12 -------------------------------
423 static void M12CW(uint32 A, uint8 V)
425 setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V);
428 static DECLFW(M12Write)
431 EXPREGS[1]=(V&0x10)>>4;
434 static void M12Power(void)
436 EXPREGS[0]=EXPREGS[1]=0;
438 SetWriteHandler(0x4100,0x5FFF,M12Write);
441 void Mapper12_Init(CartInfo *info)
443 GenMMC3_Init(info, 512, 256, 8, info->battery);
445 info->Power=M12Power;
446 AddExState(EXPREGS, 2, 0, "EXPR");
449 // ---------------------------- Mapper 37 -------------------------------
451 static void M37PW(uint32 A, uint8 V)
461 static void M37CW(uint32 A, uint8 V)
469 static DECLFW(M37Write)
472 FixMMC3PRG(MMC3_cmd);
473 FixMMC3CHR(MMC3_cmd);
476 static void M37Reset(void)
482 static void M37Power(void)
486 SetWriteHandler(0x6000,0x7FFF,M37Write);
489 void Mapper37_Init(CartInfo *info)
491 GenMMC3_Init(info, 512, 256, 8, info->battery);
494 info->Power=M37Power;
495 info->Reset=M37Reset;
496 AddExState(EXPREGS, 1, 0, "EXPR");
499 // ---------------------------- Mapper 44 -------------------------------
501 static void M44PW(uint32 A, uint8 V)
504 if(EXPREGS[0]>=6) NV&=0x1F;
510 static void M44CW(uint32 A, uint8 V)
513 if(EXPREGS[0]<6) NV&=0x7F;
518 static DECLFW(M44Write)
523 FixMMC3PRG(MMC3_cmd);
524 FixMMC3CHR(MMC3_cmd);
530 static void M44Power(void)
534 SetWriteHandler(0xA000,0xBFFF,M44Write);
537 void Mapper44_Init(CartInfo *info)
539 GenMMC3_Init(info, 512, 256, 8, info->battery);
542 info->Power=M44Power;
543 AddExState(EXPREGS, 1, 0, "EXPR");
546 // ---------------------------- Mapper 45 -------------------------------
548 static void M45CW(uint32 A, uint8 V)
554 NV&=(1<<((EXPREGS[2]&7)+1))-1;
557 NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);
562 static void M45PW(uint32 A, uint8 V)
564 V&=(EXPREGS[3]&0x3F)^0x3F;
569 static DECLFW(M45Write)
576 EXPREGS[EXPREGS[4]]=V;
577 EXPREGS[4]=(EXPREGS[4]+1)&3;
580 FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);
581 FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n",
582 (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
583 (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
584 (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]),
585 (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]));
587 FixMMC3PRG(MMC3_cmd);
588 FixMMC3CHR(MMC3_cmd);
591 static void M45Reset(void)
593 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0;
597 static void M45Power(void)
601 SetWriteHandler(0x6000,0x7FFF,M45Write);
604 void Mapper45_Init(CartInfo *info)
606 GenMMC3_Init(info, 512, 256, 8, info->battery);
609 info->Reset=M45Reset;
610 info->Power=M45Power;
611 AddExState(EXPREGS, 5, 0, "EXPR");
614 // ---------------------------- Mapper 47 -------------------------------
616 static void M47PW(uint32 A, uint8 V)
623 static void M47CW(uint32 A, uint8 V)
631 static DECLFW(M47Write)
634 FixMMC3PRG(MMC3_cmd);
635 FixMMC3CHR(MMC3_cmd);
638 static void M47Power(void)
642 SetWriteHandler(0x6000,0x7FFF,M47Write);
643 // SetReadHandler(0x6000,0x7FFF,0);
646 void Mapper47_Init(CartInfo *info)
648 GenMMC3_Init(info, 512, 256, 8, info->battery);
651 info->Power=M47Power;
652 AddExState(EXPREGS, 1, 0, "EXPR");
655 // ---------------------------- Mapper 49 -------------------------------
657 static void M49PW(uint32 A, uint8 V)
662 V|=(EXPREGS[0]&0xC0)>>2;
666 setprg32(0x8000,(EXPREGS[0]>>4)&3);
669 static void M49CW(uint32 A, uint8 V)
673 NV|=(EXPREGS[0]&0xC0)<<1;
677 static DECLFW(M49Write)
682 FixMMC3PRG(MMC3_cmd);
683 FixMMC3CHR(MMC3_cmd);
687 static void M49Reset(void)
693 static void M49Power(void)
697 SetWriteHandler(0x6000,0x7FFF,M49Write);
698 SetReadHandler(0x6000,0x7FFF,0);
701 void Mapper49_Init(CartInfo *info)
703 GenMMC3_Init(info, 512, 256, 0, 0);
706 info->Reset=M49Reset;
707 info->Power=M49Power;
708 AddExState(EXPREGS, 1, 0, "EXPR");
711 // ---------------------------- Mapper 52 -------------------------------
713 static void M52PW(uint32 A, uint8 V)
716 NV&=0x1F^((EXPREGS[0]&8)<<1);
717 NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4;
721 static void M52CW(uint32 A, uint8 V)
724 NV&=0xFF^((EXPREGS[0]&0x40)<<1);
725 NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7;
729 static DECLFW(M52Write)
738 FixMMC3PRG(MMC3_cmd);
739 FixMMC3CHR(MMC3_cmd);
742 static void M52Reset(void)
744 EXPREGS[0]=EXPREGS[1]=0;
748 static void M52Power(void)
752 SetWriteHandler(0x6000,0x7FFF,M52Write);
755 void Mapper52_Init(CartInfo *info)
757 GenMMC3_Init(info, 512, 256, 8, info->battery);
760 info->Reset=M52Reset;
761 info->Power=M52Power;
762 AddExState(EXPREGS, 2, 0, "EXPR");
765 // ---------------------------- Mapper 74 -------------------------------
767 static void M74CW(uint32 A, uint8 V)
769 if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes
775 void Mapper74_Init(CartInfo *info)
777 GenMMC3_Init(info, 512, 256, 8, info->battery);
780 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
781 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
782 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
785 // ---------------------------- Mapper 114 ------------------------------
788 uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};
790 static void M114PWRAP(uint32 A, uint8 V)
794 setprg16(0x8000,EXPREGS[0]&0xF);
795 setprg16(0xC000,EXPREGS[0]&0xF);
801 static DECLFW(M114Write)
812 X6502_IRQEnd(FCEU_IQEXT);
814 else switch(A&0xE000)
816 case 0x8000: setmirror((V&1)^1); break;
817 case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break;
818 case 0xC000: if(!cmdin) break;
819 MMC3_CMDWrite(0x8001,V);
825 static DECLFW(M114ExWrite)
830 FixMMC3PRG(MMC3_cmd);
834 static void M114Power(void)
837 SetWriteHandler(0x8000,0xFFFF,M114Write);
838 SetWriteHandler(0x5000,0x7FFF,M114ExWrite);
841 static void M114Reset(void)
847 void Mapper114_Init(CartInfo *info)
849 GenMMC3_Init(info, 256, 256, 0, 0);
851 info->Power=M114Power;
852 info->Reset=M114Reset;
853 AddExState(EXPREGS, 1, 0, "EXPR");
854 AddExState(&cmdin, 1, 0, "CMDIN");
857 // ---------------------------- Mapper 115 ------------------------------
859 static void M115PW(uint32 A, uint8 V)
862 setprg32(0x8000,(EXPREGS[0]&7)>>1);
867 static void M115CW(uint32 A, uint8 V)
869 setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8));
872 static DECLFW(M115Write)
878 FixMMC3PRG(MMC3_cmd);
881 static void M115Power(void)
884 SetWriteHandler(0x4100,0x7FFF,M115Write);
885 SetReadHandler(0x4100,0x7FFF,0);
888 void Mapper115_Init(CartInfo *info)
890 GenMMC3_Init(info, 128, 512, 0, 0);
893 info->Power=M115Power;
894 AddExState(EXPREGS, 2, 0, "EXPR");
897 // ---------------------------- Mapper 116 ------------------------------
899 static void M116CW(uint32 A, uint8 V)
901 // setchr1(A,V|((EXPREGS[0]&0x4)<<6));
908 static DECLFW(M116Write)
911 FixMMC3CHR(MMC3_cmd);
914 static void M116Power(void)
917 SetWriteHandler(0x4100,0x4100,M116Write);
920 void Mapper116_Init(CartInfo *info)
922 GenMMC3_Init(info, 128, 512, 0, 0);
924 info->Power=M116Power;
925 CHRRAM = (uint8*)FCEU_gmalloc(8192);
926 SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
927 AddExState(EXPREGS, 4, 0, "EXPR");
930 // ---------------------------- Mapper 118 ------------------------------
932 static uint8 PPUCHRBus;
933 static uint8 TKSMIR[8];
935 static void FP_FASTAPASS(1) TKSPPU(uint32 A)
940 setmirror(MI_0+TKSMIR[A]);
943 static void TKSWRAP(uint32 A, uint8 V)
947 if(PPUCHRBus==(A>>10))
948 setmirror(MI_0+(V>>7));
951 void Mapper118_Init(CartInfo *info)
953 GenMMC3_Init(info, 512, 256, 8, info->battery);
957 AddExState(&PPUCHRBus, 1, 0, "PPUC");
960 // ---------------------------- Mapper 119 ------------------------------
962 static void TQWRAP(uint32 A, uint8 V)
964 setchr1r((V&0x40)>>2,A,V&0x3F);
967 void Mapper119_Init(CartInfo *info)
969 GenMMC3_Init(info, 512, 64, 0, 0);
972 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
973 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
976 // ---------------------------- Mapper 165 ------------------------------
978 static void M165CW(uint32 A, uint8 V)
986 static void M165PPUFD(void)
990 M165CW(0x0000,DRegBuf[0]);
991 M165CW(0x1000,DRegBuf[2]);
995 static void M165PPUFE(void)
999 M165CW(0x0000,DRegBuf[1]);
1000 M165CW(0x1000,DRegBuf[4]);
1004 static void M165CWM(uint32 A, uint8 V)
1006 if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2))
1008 if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4))
1012 static void FP_FASTAPASS(1) M165PPU(uint32 A)
1014 if((A&0x1FF0)==0x1FD0)
1018 } else if((A&0x1FF0)==0x1FE0)
1025 static void M165Power(void)
1031 void Mapper165_Init(CartInfo *info)
1033 GenMMC3_Init(info, 512, 128, 8, info->battery);
1036 info->Power=M165Power;
1038 CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize);
1039 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1040 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1041 AddExState(EXPREGS, 4, 0, "EXPR");
1044 // ---------------------------- Mapper 182 ------------------------------
1045 // òà áëèöà ïåðìóòà öè à Ãà ëîãè÷Ãà 114 ìà ïïåðó, ðåãèñòðû ìà ïïåðà ãîðà çäî ñëîæÃåå,
1046 // ÷åì èñïîëüçóþòñÿ çäåñü, õîòÿ âñå ïðåêðà ñÃî ðà áîòà åò.
1048 //static uint8 m182_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};
1049 static DECLFW(M182Write)
1053 case 0x8001: setmirror((V&1)^1); break;
1054 case 0xA000: MMC3_CMDWrite(0x8000,m114_perm[V&7]); break;
1055 case 0xC000: MMC3_CMDWrite(0x8001,V); break;
1062 X6502_IRQEnd(FCEU_IQEXT);
1067 static void M182Power(void)
1070 SetWriteHandler(0x8000,0xFFFF,M182Write);
1073 void Mapper182_Init(CartInfo *info)
1075 GenMMC3_Init(info, 256, 256, 0, 0);
1076 info->Power=M182Power;
1079 // ---------------------------- Mapper 191 ------------------------------
1081 static void M191CW(uint32 A, uint8 V)
1083 setchr1r((V&0x80)>>3,A,V);
1086 void Mapper191_Init(CartInfo *info)
1088 GenMMC3_Init(info, 256, 256, 8, info->battery);
1091 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1092 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1093 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1096 // ---------------------------- Mapper 192 -------------------------------
1098 static void M192CW(uint32 A, uint8 V)
1100 if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese),
1106 void Mapper192_Init(CartInfo *info)
1108 GenMMC3_Init(info, 512, 256, 8, info->battery);
1111 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1112 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1113 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1116 // ---------------------------- Mapper 194 -------------------------------
1118 static void M194CW(uint32 A, uint8 V)
1120 if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes
1126 void Mapper194_Init(CartInfo *info)
1128 GenMMC3_Init(info, 512, 256, 8, info->battery);
1131 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1132 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1133 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1136 // ---------------------------- Mapper 198 -------------------------------
1138 static uint8 *wramtw;
1139 static uint16 wramsize;
1140 static void M198CW(uint32 A, uint8 V)
1142 if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C)
1148 static void M198Power(void)
1151 setprg4r(0x10,0x5000,0);
1152 SetWriteHandler(0x5000,0x5fff,CartBW);
1153 SetReadHandler(0x5000,0x5fff,CartBR);
1156 static void M198Close(void)
1163 void Mapper198_Init(CartInfo *info)
1165 GenMMC3_Init(info, 512, 256, 8, info->battery);
1167 info->Power=M198Power;
1168 info->Close=M198Close;
1170 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1171 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1173 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1174 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1175 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1176 AddExState(wramtw, wramsize, 0, "WRAMTW");
1179 // ---------------------------- Mapper 199 -------------------------------
1181 static uint8 *wramtw;
1182 static uint16 wramsize;
1183 static void M199PW(uint32 A, uint8 V)
1191 void Mapper199_Init(CartInfo *info)
1193 GenMMC3_Init(info, 1024, 256, 8, info->battery);
1195 info->Power=M198Power;
1196 info->Close=M198Close;
1198 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1199 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1200 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1201 AddExState(wramtw, wramsize, 0, "WRAMTW");
1204 // ---------------------------- Mapper 205 ------------------------------
1206 static void M205PW(uint32 A, uint8 V)
1209 setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4));
1211 setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4));
1214 static void M205CW(uint32 A, uint8 V)
1216 setchr1(A,V|((EXPREGS[0]&3)<<7));
1219 static DECLFW(M205Write)
1221 if((A&0x6800)==0x6800) EXPREGS[0]= V;
1222 FixMMC3PRG(MMC3_cmd);
1223 FixMMC3CHR(MMC3_cmd);
1226 static void M205Reset(void)
1232 static void M205Power(void)
1235 SetWriteHandler(0x4020,0x7FFF,M205Write);
1238 void Mapper205_Init(CartInfo *info)
1240 GenMMC3_Init(info, 512, 256, 8, 0);
1243 info->Power=M205Power;
1244 info->Reset=M205Reset;
1245 AddExState(EXPREGS, 1, 0, "EXPR");
1248 // ---------------------------- Mapper 215 ------------------------------
1250 static uint8 m215_perm[8] = {0, 2, 5, 3, 6, 1, 7, 4};
1252 static void M215CW(uint32 A, uint8 V)
1257 setchr1(A,(V&0x7F)|((EXPREGS[1]&0x10)<<3));
1260 static void M215PW(uint32 A, uint8 V)
1264 setprg16(0x8000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10));
1265 setprg16(0xC000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10));
1267 else if(EXPREGS[1]&0x08)
1268 setprg8(A,(V&0x1F)|0x20);
1270 setprg8(A,(V&0x0F)|(EXPREGS[1]&0x10));
1273 static DECLFW(M215Write)
1282 else switch(A&0xE001)
1284 case 0xC001: IRQLatch=V; break;
1285 case 0xA001: IRQReload=1; break;
1286 case 0xE001: IRQa=1; break;
1287 case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;
1288 case 0xC000: setmirror(((V|(V>>7))&1)^1); break;
1289 case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m215_perm[V&7])); cmdin=1; break;
1290 case 0x8001: if(!cmdin) break;
1291 MMC3_CMDWrite(0x8001,V);
1297 static DECLFW(M215ExWrite)
1303 FixMMC3PRG(MMC3_cmd);
1307 FixMMC3CHR(MMC3_cmd);
1316 static void M215Power(void)
1322 SetWriteHandler(0x8000,0xFFFF,M215Write);
1323 SetWriteHandler(0x5000,0x7FFF,M215ExWrite);
1326 void Mapper215_Init(CartInfo *info)
1328 GenMMC3_Init(info, 256, 256, 0, 0);
1331 info->Power=M215Power;
1332 AddExState(EXPREGS, 3, 0, "EXPR");
1333 AddExState(&cmdin, 1, 0, "CMDIN");
1336 // ---------------------------- Mapper 217 ------------------------------
1338 static uint8 m217_perm[8] = {0, 6, 3, 7, 5, 2, 4, 1};
1340 static void M217CW(uint32 A, uint8 V)
1343 setchr1(A,V|((EXPREGS[1]&3)<<8));
1345 setchr1(A,(V&0x7F)|((EXPREGS[1]&3)<<8)|((EXPREGS[1]&0x10)<<3));
1348 static void M217PW(uint32 A, uint8 V)
1352 setprg16(0x8000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4));
1353 setprg16(0xC000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4));
1355 else if(EXPREGS[1]&0x08)
1356 setprg8(A,(V&0x1F)|((EXPREGS[1]&3)<<5));
1358 setprg8(A,(V&0x0F)|((EXPREGS[1]&3)<<5)|(EXPREGS[1]&0x10));
1361 static DECLFW(M217Write)
1366 MMC3_IRQWrite(A, V);
1370 else switch(A&0xE001)
1372 case 0x8000: IRQCount=V; break;
1373 case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break;
1374 case 0xC001: IRQa=1; break;
1375 case 0xA001: setmirror((V&1)^1); break;
1376 case 0x8001: MMC3_CMDWrite(0x8000,(V&0xC0)|(m217_perm[V&7])); cmdin=1; break;
1377 case 0xA000: if(!cmdin) break;
1378 MMC3_CMDWrite(0x8001,V);
1384 static DECLFW(M217ExWrite)
1390 FixMMC3PRG(MMC3_cmd);
1394 FixMMC3PRG(MMC3_cmd);
1402 static void M217Power(void)
1408 SetWriteHandler(0x8000,0xFFFF,M217Write);
1409 SetWriteHandler(0x5000,0x7FFF,M217ExWrite);
1412 void Mapper217_Init(CartInfo *info)
1414 GenMMC3_Init(info, 256, 256, 0, 0);
1417 info->Power=M217Power;
1418 AddExState(EXPREGS, 3, 0, "EXPR");
1419 AddExState(&cmdin, 1, 0, "CMDIN");
1422 // ---------------------------- Mapper 245 ------------------------------
1424 static void M245CW(uint32 A, uint8 V)
1428 FixMMC3PRG(MMC3_cmd);
1431 static void M245PW(uint32 A, uint8 V)
1433 setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5));
1436 static void M245Power(void)
1442 void Mapper245_Init(CartInfo *info)
1444 GenMMC3_Init(info, 512, 256, 8, info->battery);
1447 info->Power=M245Power;
1448 AddExState(EXPREGS, 1, 0, "EXPR");
1451 // ---------------------------- Mapper 249 ------------------------------
1453 static void M249PW(uint32 A, uint8 V)
1458 V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10);
1462 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1468 static void M249CW(uint32 A, uint8 V)
1471 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1475 static DECLFW(M249Write)
1478 FixMMC3PRG(MMC3_cmd);
1479 FixMMC3CHR(MMC3_cmd);
1482 static void M249Power(void)
1486 SetWriteHandler(0x5000,0x5000,M249Write);
1489 void Mapper249_Init(CartInfo *info)
1491 GenMMC3_Init(info, 512, 256, 8, info->battery);
1494 info->Power=M249Power;
1495 AddExState(EXPREGS, 1, 0, "EXPR");
1498 // ---------------------------- Mapper 250 ------------------------------
1500 static DECLFW(M250Write)
1502 MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1505 static DECLFW(M250IRQWrite)
1507 MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1510 static void M250_Power(void)
1513 SetWriteHandler(0x8000,0xBFFF,M250Write);
1514 SetWriteHandler(0xC000,0xFFFF,M250IRQWrite);
1517 void Mapper250_Init(CartInfo *info)
1519 GenMMC3_Init(info, 512, 256, 8, info->battery);
1520 info->Power=M250_Power;
1523 // ---------------------------- Mapper 254 ------------------------------
1525 static DECLFR(MR254WRAM)
1528 return WRAM[A-0x6000];
1530 return WRAM[A-0x6000]^EXPREGS[1];
1533 static DECLFW(M254Write)
1536 case 0x8000: EXPREGS[0]=0xff;
1538 case 0xA001: EXPREGS[1]=V;
1543 static void M254_Power(void)
1546 SetWriteHandler(0x8000,0xBFFF,M254Write);
1547 SetReadHandler(0x6000,0x7FFF,MR254WRAM);
1549 // hrrr.. can't handle those evil xors here..
1550 Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000;
1554 void Mapper254_Init(CartInfo *info)
1556 GenMMC3_Init(info, 128, 128, 8, info->battery);
1557 info->Power=M254_Power;
1558 AddExState(EXPREGS, 2, 0, "EXPR");
1561 // ---------------------------- UNIF Boards -----------------------------
1563 void TEROM_Init(CartInfo *info)
1565 GenMMC3_Init(info, 32, 32, 0, 0);
1568 void TFROM_Init(CartInfo *info)
1570 GenMMC3_Init(info, 512, 64, 0, 0);
1573 void TGROM_Init(CartInfo *info)
1575 GenMMC3_Init(info, 512, 0, 0, 0);
1578 void TKROM_Init(CartInfo *info)
1580 GenMMC3_Init(info, 512, 256, 8, info->battery);
1583 void TLROM_Init(CartInfo *info)
1585 GenMMC3_Init(info, 512, 256, 0, 0);
1588 void TSROM_Init(CartInfo *info)
1590 GenMMC3_Init(info, 512, 256, 8, 0);
1593 void TLSROM_Init(CartInfo *info)
1595 GenMMC3_Init(info, 512, 256, 8, 0);
1599 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1602 void TKSROM_Init(CartInfo *info)
1604 GenMMC3_Init(info, 512, 256, 8, info->battery);
1608 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1611 void TQROM_Init(CartInfo *info)
1613 GenMMC3_Init(info, 512, 64, 0, 0);
1616 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1617 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1620 void HKROM_Init(CartInfo *info)
1622 GenMMC3_Init(info, 512, 512, 1, info->battery);