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);
178 DECLFW(MMC3_IRQWrite)
180 // FCEU_printf("%04x:%04x\n",A,V);
183 case 0xC000:IRQLatch=V;break;
184 case 0xC001:IRQReload=1;break;
185 case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break;
186 case 0xE001:IRQa=1;break;
190 static void ClockMMC3Counter(void)
192 int count = IRQCount;
193 if(!count || IRQReload)
200 if((count|isRevB) && !IRQCount)
204 X6502_IRQBegin(FCEU_IQEXT);
209 static void MMC3_hb(void)
214 static void MMC3_hb_KickMasterHack(void)
216 if(scanline==238) ClockMMC3Counter();
220 static void MMC3_hb_PALStarWarsHack(void)
222 if(scanline==240) ClockMMC3Counter();
226 void GenMMC3Restore(int version)
228 if(mwrap) mwrap(A000B&1);
229 FixMMC3PRG(MMC3_cmd);
230 FixMMC3CHR(MMC3_cmd);
233 static void GENCWRAP(uint32 A, uint8 V)
235 if(!UNIFchrrama) setchr1(A,V);
238 static void GENPWRAP(uint32 A, uint8 V)
243 static void GENMWRAP(uint8 V)
249 static void GENNOMWRAP(uint8 V)
254 static DECLFW(MBWRAM)
259 static DECLFR(MAWRAM)
261 return(WRAM[A-0x6000]);
264 static DECLFW(MBWRAMMMC6)
269 static DECLFR(MAWRAMMMC6)
271 return(WRAM[A&0x3ff]);
274 void GenMMC3Power(void)
276 if(UNIFchrrama) setchr8(0);
278 SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);
279 SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
280 SetReadHandler(0x8000,0xFFFF,CartBR);
287 FCEU_CheatAddRAM(1,0x7000,WRAM);
288 SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);
289 SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);
291 // asm code needs pages to be set again..
292 Page[14]=Page[15]=WRAM-0x7000;
297 FCEU_CheatAddRAM(wrams>>10,0x6000,WRAM);
298 SetReadHandler(0x6000,0x6000+wrams-1,MAWRAM);
299 SetWriteHandler(0x6000,0x6000+wrams-1,MBWRAM);
303 for (addr=0x6000; addr < 0x6000+wrams-0x7ff; addr += 0x800)
305 Page[addr>>11]=WRAM - 0x6000;
311 FCEU_dwmemset(WRAM,0,wrams);
315 FCEU_dwmemset(CHRRAM,0,CHRRAMSize);
318 static void GenMMC3Close(void)
327 //static uint16 _a12;
328 //static void FP_FASTAPASS(1) MMC3_PPU(uint32 A)
330 // if(A&0x2000)return;
331 // if((!_a12)&&(A&0x1000))
332 // ClockMMC3Counter();
336 void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)
344 PRGmask8[0]&=(prg>>13)-1;
345 CHRmask1[0]&=(chr>>10)-1;
346 CHRmask2[0]&=(chr>>11)-1;
351 WRAM=(uint8*)FCEU_gmalloc(wrams);
352 AddExState(WRAM, wrams, 0, "WRAM");
358 info->SaveGame[0]=WRAM;
359 info->SaveGameLen[0]=wrams;
362 // if(!chr) // duplicated CHR RAM set up
364 // CHRRAM=(uint8*)FCEU_gmalloc(8192);
366 // SetupCartCHRMapping(0, CHRRAM, 8192, 1);
367 // AddExState(CHRRAM, 8192, 0, "CHRR");
370 AddExState(MMC3_StateRegs, ~0, 0, 0);
372 info->Power=GenMMC3Power;
373 info->Reset=MMC3RegReset;
374 info->Close=GenMMC3Close;
376 if(info->CRC32 == 0x5104833e) // Kick Master
377 GameHBIRQHook = MMC3_hb_KickMasterHack;
378 else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93
379 GameHBIRQHook = MMC3_hb_KickMasterHack;
380 else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master.
381 GameHBIRQHook = MMC3_hb_PALStarWarsHack;
383 GameHBIRQHook=MMC3_hb;
384 // PPU_hook=MMC3_PPU;
385 GameStateRestore=GenMMC3Restore;
388 // ----------------------------------------------------------------------
389 // -------------------------- MMC3 Based Code ---------------------------
390 // ----------------------------------------------------------------------
392 // ---------------------------- Mapper 4 --------------------------------
394 static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/
396 static void M4Power(void)
403 void Mapper4_Init(CartInfo *info)
407 if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84))
409 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");
412 GenMMC3_Init(info,512,256,ws,info->battery);
417 // ---------------------------- Mapper 12 -------------------------------
419 static void M12CW(uint32 A, uint8 V)
421 setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V);
424 static DECLFW(M12Write)
427 EXPREGS[1]=(V&0x10)>>4;
430 static void M12Power(void)
432 EXPREGS[0]=EXPREGS[1]=0;
434 SetWriteHandler(0x4100,0x5FFF,M12Write);
437 void Mapper12_Init(CartInfo *info)
439 GenMMC3_Init(info, 512, 256, 8, info->battery);
441 info->Power=M12Power;
442 AddExState(EXPREGS, 2, 0, "EXPR");
445 // ---------------------------- Mapper 37 -------------------------------
447 static void M37PW(uint32 A, uint8 V)
457 static void M37CW(uint32 A, uint8 V)
465 static DECLFW(M37Write)
468 FixMMC3PRG(MMC3_cmd);
469 FixMMC3CHR(MMC3_cmd);
472 static void M37Reset(void)
478 static void M37Power(void)
482 SetWriteHandler(0x6000,0x7FFF,M37Write);
485 void Mapper37_Init(CartInfo *info)
487 GenMMC3_Init(info, 512, 256, 8, info->battery);
490 info->Power=M37Power;
491 info->Reset=M37Reset;
492 AddExState(EXPREGS, 1, 0, "EXPR");
495 // ---------------------------- Mapper 44 -------------------------------
497 static void M44PW(uint32 A, uint8 V)
500 if(EXPREGS[0]>=6) NV&=0x1F;
506 static void M44CW(uint32 A, uint8 V)
509 if(EXPREGS[0]<6) NV&=0x7F;
514 static DECLFW(M44Write)
519 FixMMC3PRG(MMC3_cmd);
520 FixMMC3CHR(MMC3_cmd);
526 static void M44Power(void)
530 SetWriteHandler(0xA000,0xBFFF,M44Write);
533 void Mapper44_Init(CartInfo *info)
535 GenMMC3_Init(info, 512, 256, 8, info->battery);
538 info->Power=M44Power;
539 AddExState(EXPREGS, 1, 0, "EXPR");
542 // ---------------------------- Mapper 45 -------------------------------
544 static void M45CW(uint32 A, uint8 V)
550 NV&=(1<<((EXPREGS[2]&7)+1))-1;
553 NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);
558 static void M45PW(uint32 A, uint8 V)
560 V&=(EXPREGS[3]&0x3F)^0x3F;
565 static DECLFW(M45Write)
572 EXPREGS[EXPREGS[4]]=V;
573 EXPREGS[4]=(EXPREGS[4]+1)&3;
576 FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);
577 FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n",
578 (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
579 (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
580 (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]),
581 (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]));
583 FixMMC3PRG(MMC3_cmd);
584 FixMMC3CHR(MMC3_cmd);
587 static void M45Reset(void)
589 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0;
593 static void M45Power(void)
597 SetWriteHandler(0x6000,0x7FFF,M45Write);
600 void Mapper45_Init(CartInfo *info)
602 GenMMC3_Init(info, 512, 256, 8, info->battery);
605 info->Reset=M45Reset;
606 info->Power=M45Power;
607 AddExState(EXPREGS, 5, 0, "EXPR");
610 // ---------------------------- Mapper 47 -------------------------------
612 static void M47PW(uint32 A, uint8 V)
619 static void M47CW(uint32 A, uint8 V)
627 static DECLFW(M47Write)
630 FixMMC3PRG(MMC3_cmd);
631 FixMMC3CHR(MMC3_cmd);
634 static void M47Power(void)
638 SetWriteHandler(0x6000,0x7FFF,M47Write);
639 // SetReadHandler(0x6000,0x7FFF,0);
642 void Mapper47_Init(CartInfo *info)
644 GenMMC3_Init(info, 512, 256, 8, info->battery);
647 info->Power=M47Power;
648 AddExState(EXPREGS, 1, 0, "EXPR");
651 // ---------------------------- Mapper 49 -------------------------------
653 static void M49PW(uint32 A, uint8 V)
658 V|=(EXPREGS[0]&0xC0)>>2;
662 setprg32(0x8000,(EXPREGS[0]>>4)&3);
665 static void M49CW(uint32 A, uint8 V)
669 NV|=(EXPREGS[0]&0xC0)<<1;
673 static DECLFW(M49Write)
678 FixMMC3PRG(MMC3_cmd);
679 FixMMC3CHR(MMC3_cmd);
683 static void M49Reset(void)
689 static void M49Power(void)
693 SetWriteHandler(0x6000,0x7FFF,M49Write);
694 SetReadHandler(0x6000,0x7FFF,0);
697 void Mapper49_Init(CartInfo *info)
699 GenMMC3_Init(info, 512, 256, 0, 0);
702 info->Reset=M49Reset;
703 info->Power=M49Power;
704 AddExState(EXPREGS, 1, 0, "EXPR");
707 // ---------------------------- Mapper 52 -------------------------------
709 static void M52PW(uint32 A, uint8 V)
712 NV&=0x1F^((EXPREGS[0]&8)<<1);
713 NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4;
717 static void M52CW(uint32 A, uint8 V)
720 NV&=0xFF^((EXPREGS[0]&0x40)<<1);
721 NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7;
725 static DECLFW(M52Write)
734 FixMMC3PRG(MMC3_cmd);
735 FixMMC3CHR(MMC3_cmd);
738 static void M52Reset(void)
740 EXPREGS[0]=EXPREGS[1]=0;
744 static void M52Power(void)
748 SetWriteHandler(0x6000,0x7FFF,M52Write);
751 void Mapper52_Init(CartInfo *info)
753 GenMMC3_Init(info, 512, 256, 8, info->battery);
756 info->Reset=M52Reset;
757 info->Power=M52Power;
758 AddExState(EXPREGS, 2, 0, "EXPR");
761 // ---------------------------- Mapper 74 -------------------------------
763 static void M74CW(uint32 A, uint8 V)
765 if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes
771 void Mapper74_Init(CartInfo *info)
773 GenMMC3_Init(info, 512, 256, 8, info->battery);
776 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
777 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
778 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
781 // ---------------------------- Mapper 114 ------------------------------
784 uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};
786 static void M114PWRAP(uint32 A, uint8 V)
790 setprg16(0x8000,EXPREGS[0]&0xF);
791 setprg16(0xC000,EXPREGS[0]&0xF);
797 static DECLFW(M114Write)
808 X6502_IRQEnd(FCEU_IQEXT);
810 else switch(A&0xE000)
812 case 0x8000: setmirror((V&1)^1); break;
813 case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break;
814 case 0xC000: if(!cmdin) break;
815 MMC3_CMDWrite(0x8001,V);
821 static DECLFW(M114ExWrite)
826 FixMMC3PRG(MMC3_cmd);
830 static void M114Power(void)
833 SetWriteHandler(0x8000,0xFFFF,M114Write);
834 SetWriteHandler(0x5000,0x7FFF,M114ExWrite);
837 static void M114Reset(void)
843 void Mapper114_Init(CartInfo *info)
845 GenMMC3_Init(info, 256, 256, 0, 0);
847 info->Power=M114Power;
848 info->Reset=M114Reset;
849 AddExState(EXPREGS, 1, 0, "EXPR");
850 AddExState(&cmdin, 1, 0, "CMDIN");
853 // ---------------------------- Mapper 115 ------------------------------
855 static void M115PW(uint32 A, uint8 V)
858 setprg32(0x8000,(EXPREGS[0]&7)>>1);
863 static void M115CW(uint32 A, uint8 V)
865 setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8));
868 static DECLFW(M115Write)
874 FixMMC3PRG(MMC3_cmd);
877 static void M115Power(void)
880 SetWriteHandler(0x4100,0x7FFF,M115Write);
881 SetReadHandler(0x4100,0x7FFF,0);
884 void Mapper115_Init(CartInfo *info)
886 GenMMC3_Init(info, 128, 512, 0, 0);
889 info->Power=M115Power;
890 AddExState(EXPREGS, 2, 0, "EXPR");
893 // ---------------------------- Mapper 116 ------------------------------
895 static void M116CW(uint32 A, uint8 V)
897 // setchr1(A,V|((EXPREGS[0]&0x4)<<6));
904 static DECLFW(M116Write)
907 FixMMC3CHR(MMC3_cmd);
910 static void M116Power(void)
913 SetWriteHandler(0x4100,0x4100,M116Write);
916 void Mapper116_Init(CartInfo *info)
918 GenMMC3_Init(info, 128, 512, 0, 0);
920 info->Power=M116Power;
921 CHRRAM = (uint8*)FCEU_gmalloc(8192);
922 SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
923 AddExState(EXPREGS, 4, 0, "EXPR");
926 // ---------------------------- Mapper 118 ------------------------------
928 static uint8 PPUCHRBus;
929 static uint8 TKSMIR[8];
931 static void FP_FASTAPASS(1) TKSPPU(uint32 A)
936 setmirror(MI_0+TKSMIR[A]);
939 static void TKSWRAP(uint32 A, uint8 V)
943 if(PPUCHRBus==(A>>10))
944 setmirror(MI_0+(V>>7));
947 void Mapper118_Init(CartInfo *info)
949 GenMMC3_Init(info, 512, 256, 8, info->battery);
953 AddExState(&PPUCHRBus, 1, 0, "PPUC");
956 // ---------------------------- Mapper 119 ------------------------------
958 static void TQWRAP(uint32 A, uint8 V)
960 setchr1r((V&0x40)>>2,A,V&0x3F);
963 void Mapper119_Init(CartInfo *info)
965 GenMMC3_Init(info, 512, 64, 0, 0);
968 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
969 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
972 // ---------------------------- Mapper 165 ------------------------------
974 static void M165CW(uint32 A, uint8 V)
982 static void M165PPUFD(void)
986 M165CW(0x0000,DRegBuf[0]);
987 M165CW(0x1000,DRegBuf[2]);
991 static void M165PPUFE(void)
995 M165CW(0x0000,DRegBuf[1]);
996 M165CW(0x1000,DRegBuf[4]);
1000 static void M165CWM(uint32 A, uint8 V)
1002 if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2))
1004 if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4))
1008 static void FP_FASTAPASS(1) M165PPU(uint32 A)
1010 if((A&0x1FF0)==0x1FD0)
1014 } else if((A&0x1FF0)==0x1FE0)
1021 static void M165Power(void)
1027 void Mapper165_Init(CartInfo *info)
1029 GenMMC3_Init(info, 512, 128, 8, info->battery);
1032 info->Power=M165Power;
1034 CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize);
1035 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1036 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1037 AddExState(EXPREGS, 4, 0, "EXPR");
1040 // ---------------------------- Mapper 182 ------------------------------
1041 // òà áëèöà ïåðìóòà öè à Ãà ëîãè÷Ãà 114 ìà ïïåðó, ðåãèñòðû ìà ïïåðà ãîðà çäî ñëîæÃåå,
1042 // ÷åì èñïîëüçóþòñÿ çäåñü, õîòÿ âñå ïðåêðà ñÃî ðà áîòà åò.
1044 //static uint8 m182_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};
1045 static DECLFW(M182Write)
1049 case 0x8001: setmirror((V&1)^1); break;
1050 case 0xA000: MMC3_CMDWrite(0x8000,m114_perm[V&7]); break;
1051 case 0xC000: MMC3_CMDWrite(0x8001,V); break;
1058 X6502_IRQEnd(FCEU_IQEXT);
1063 static void M182Power(void)
1066 SetWriteHandler(0x8000,0xFFFF,M182Write);
1069 void Mapper182_Init(CartInfo *info)
1071 GenMMC3_Init(info, 256, 256, 0, 0);
1072 info->Power=M182Power;
1075 // ---------------------------- Mapper 191 ------------------------------
1077 static void M191CW(uint32 A, uint8 V)
1079 setchr1r((V&0x80)>>3,A,V);
1082 void Mapper191_Init(CartInfo *info)
1084 GenMMC3_Init(info, 256, 256, 8, info->battery);
1087 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1088 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1089 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1092 // ---------------------------- Mapper 192 -------------------------------
1094 static void M192CW(uint32 A, uint8 V)
1096 if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese),
1102 void Mapper192_Init(CartInfo *info)
1104 GenMMC3_Init(info, 512, 256, 8, info->battery);
1107 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1108 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1109 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1112 // ---------------------------- Mapper 194 -------------------------------
1114 static void M194CW(uint32 A, uint8 V)
1116 if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes
1122 void Mapper194_Init(CartInfo *info)
1124 GenMMC3_Init(info, 512, 256, 8, info->battery);
1127 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1128 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1129 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1132 // ---------------------------- Mapper 198 -------------------------------
1134 static uint8 *wramtw;
1135 static uint16 wramsize;
1136 static void M198CW(uint32 A, uint8 V)
1138 if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C)
1144 static void M198Power(void)
1147 setprg4r(0x10,0x5000,0);
1148 SetWriteHandler(0x5000,0x5fff,CartBW);
1149 SetReadHandler(0x5000,0x5fff,CartBR);
1152 static void M198Close(void)
1159 void Mapper198_Init(CartInfo *info)
1161 GenMMC3_Init(info, 512, 256, 8, info->battery);
1163 info->Power=M198Power;
1164 info->Close=M198Close;
1166 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1167 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1169 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1170 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1171 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1172 AddExState(wramtw, wramsize, 0, "WRAMTW");
1175 // ---------------------------- Mapper 199 -------------------------------
1177 static uint8 *wramtw;
1178 static uint16 wramsize;
1179 static void M199PW(uint32 A, uint8 V)
1187 void Mapper199_Init(CartInfo *info)
1189 GenMMC3_Init(info, 1024, 256, 8, info->battery);
1191 info->Power=M198Power;
1192 info->Close=M198Close;
1194 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1195 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1196 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1197 AddExState(wramtw, wramsize, 0, "WRAMTW");
1200 // ---------------------------- Mapper 205 ------------------------------
1202 static void M205PW(uint32 A, uint8 V)
1205 setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4));
1207 setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4));
1210 static void M205CW(uint32 A, uint8 V)
1212 setchr1(A,V|((EXPREGS[0]&3)<<7));
1215 static DECLFW(M205Write)
1217 if((A&0x6800)==0x6800) EXPREGS[0]= V;
1218 FixMMC3PRG(MMC3_cmd);
1219 FixMMC3CHR(MMC3_cmd);
1222 static void M205Reset(void)
1228 static void M205Power(void)
1231 SetWriteHandler(0x4020,0x7FFF,M205Write);
1234 void Mapper205_Init(CartInfo *info)
1236 GenMMC3_Init(info, 512, 256, 8, 0);
1239 info->Power=M205Power;
1240 info->Reset=M205Reset;
1241 AddExState(EXPREGS, 1, 0, "EXPR");
1244 // ---------------------------- Mapper 215 ------------------------------
1246 static uint8 m215_perm[8] = {0, 2, 5, 3, 6, 1, 7, 4};
1248 static void M215CW(uint32 A, uint8 V)
1253 setchr1(A,(V&0x7F)|((EXPREGS[1]&0x10)<<3));
1256 static void M215PW(uint32 A, uint8 V)
1260 setprg16(0x8000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10));
1261 setprg16(0xC000,(EXPREGS[0]&0x0F)|(EXPREGS[1]&0x10));
1263 else if(EXPREGS[1]&0x08)
1264 setprg8(A,(V&0x1F)|0x20);
1266 setprg8(A,(V&0x0F)|(EXPREGS[1]&0x10));
1269 static DECLFW(M215Write)
1278 else switch(A&0xE001)
1280 case 0xC001: IRQLatch=V; break;
1281 case 0xA001: IRQReload=1; break;
1282 case 0xE001: IRQa=1; break;
1283 case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break;
1284 case 0xC000: setmirror(((V|(V>>7))&1)^1); break;
1285 case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m215_perm[V&7])); cmdin=1; break;
1286 case 0x8001: if(!cmdin) break;
1287 MMC3_CMDWrite(0x8001,V);
1293 static DECLFW(M215ExWrite)
1299 FixMMC3PRG(MMC3_cmd);
1303 FixMMC3CHR(MMC3_cmd);
1312 static void M215Power(void)
1318 SetWriteHandler(0x8000,0xFFFF,M215Write);
1319 SetWriteHandler(0x5000,0x7FFF,M215ExWrite);
1322 void Mapper215_Init(CartInfo *info)
1324 GenMMC3_Init(info, 256, 256, 0, 0);
1327 info->Power=M215Power;
1328 AddExState(EXPREGS, 3, 0, "EXPR");
1329 AddExState(&cmdin, 1, 0, "CMDIN");
1332 // ---------------------------- Mapper 217 ------------------------------
1334 static uint8 m217_perm[8] = {0, 6, 3, 7, 5, 2, 4, 1};
1336 static void M217CW(uint32 A, uint8 V)
1339 setchr1(A,V|((EXPREGS[1]&3)<<8));
1341 setchr1(A,(V&0x7F)|((EXPREGS[1]&3)<<8)|((EXPREGS[1]&0x10)<<3));
1344 static void M217PW(uint32 A, uint8 V)
1348 setprg16(0x8000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4));
1349 setprg16(0xC000,(EXPREGS[0]&0x0F)|((EXPREGS[1]&3)<<4));
1351 else if(EXPREGS[1]&0x08)
1352 setprg8(A,(V&0x1F)|((EXPREGS[1]&3)<<5));
1354 setprg8(A,(V&0x0F)|((EXPREGS[1]&3)<<5)|(EXPREGS[1]&0x10));
1357 static DECLFW(M217Write)
1362 MMC3_IRQWrite(A, V);
1366 else switch(A&0xE001)
1368 case 0x8000: IRQCount=V; break;
1369 case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break;
1370 case 0xC001: IRQa=1; break;
1371 case 0xA001: setmirror((V&1)^1); break;
1372 case 0x8001: MMC3_CMDWrite(0x8000,(V&0xC0)|(m217_perm[V&7])); cmdin=1; break;
1373 case 0xA000: if(!cmdin) break;
1374 MMC3_CMDWrite(0x8001,V);
1380 static DECLFW(M217ExWrite)
1386 FixMMC3PRG(MMC3_cmd);
1390 FixMMC3PRG(MMC3_cmd);
1398 static void M217Power(void)
1404 SetWriteHandler(0x8000,0xFFFF,M217Write);
1405 SetWriteHandler(0x5000,0x7FFF,M217ExWrite);
1408 void Mapper217_Init(CartInfo *info)
1410 GenMMC3_Init(info, 256, 256, 0, 0);
1413 info->Power=M217Power;
1414 AddExState(EXPREGS, 3, 0, "EXPR");
1415 AddExState(&cmdin, 1, 0, "CMDIN");
1418 // ---------------------------- Mapper 245 ------------------------------
1420 static void M245CW(uint32 A, uint8 V)
1424 FixMMC3PRG(MMC3_cmd);
1427 static void M245PW(uint32 A, uint8 V)
1429 setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5));
1432 static void M245Power(void)
1438 void Mapper245_Init(CartInfo *info)
1440 GenMMC3_Init(info, 512, 256, 8, info->battery);
1443 info->Power=M245Power;
1444 AddExState(EXPREGS, 1, 0, "EXPR");
1447 // ---------------------------- Mapper 249 ------------------------------
1449 static void M249PW(uint32 A, uint8 V)
1454 V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10);
1458 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1464 static void M249CW(uint32 A, uint8 V)
1467 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1471 static DECLFW(M249Write)
1474 FixMMC3PRG(MMC3_cmd);
1475 FixMMC3CHR(MMC3_cmd);
1478 static void M249Power(void)
1482 SetWriteHandler(0x5000,0x5000,M249Write);
1485 void Mapper249_Init(CartInfo *info)
1487 GenMMC3_Init(info, 512, 256, 8, info->battery);
1490 info->Power=M249Power;
1491 AddExState(EXPREGS, 1, 0, "EXPR");
1494 // ---------------------------- Mapper 250 ------------------------------
1496 static DECLFW(M250Write)
1498 MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1501 static DECLFW(M250IRQWrite)
1503 MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1506 static void M250_Power(void)
1509 SetWriteHandler(0x8000,0xBFFF,M250Write);
1510 SetWriteHandler(0xC000,0xFFFF,M250IRQWrite);
1513 void Mapper250_Init(CartInfo *info)
1515 GenMMC3_Init(info, 512, 256, 8, info->battery);
1516 info->Power=M250_Power;
1519 // ---------------------------- Mapper 254 ------------------------------
1521 static DECLFR(MR254WRAM)
1524 return WRAM[A-0x6000];
1526 return WRAM[A-0x6000]^EXPREGS[1];
1529 static DECLFW(M254Write)
1532 case 0x8000: EXPREGS[0]=0xff;
1534 case 0xA001: EXPREGS[1]=V;
1539 static void M254_Power(void)
1542 SetWriteHandler(0x8000,0xBFFF,M254Write);
1543 SetReadHandler(0x6000,0x7FFF,MR254WRAM);
1545 // hrrr.. can't handle those evil xors here..
1546 Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000;
1550 void Mapper254_Init(CartInfo *info)
1552 GenMMC3_Init(info, 128, 128, 8, info->battery);
1553 info->Power=M254_Power;
1554 AddExState(EXPREGS, 2, 0, "EXPR");
1557 // ---------------------------- UNIF Boards -----------------------------
1559 void TEROM_Init(CartInfo *info)
1561 GenMMC3_Init(info, 32, 32, 0, 0);
1564 void TFROM_Init(CartInfo *info)
1566 GenMMC3_Init(info, 512, 64, 0, 0);
1569 void TGROM_Init(CartInfo *info)
1571 GenMMC3_Init(info, 512, 0, 0, 0);
1574 void TKROM_Init(CartInfo *info)
1576 GenMMC3_Init(info, 512, 256, 8, info->battery);
1579 void TLROM_Init(CartInfo *info)
1581 GenMMC3_Init(info, 512, 256, 0, 0);
1584 void TSROM_Init(CartInfo *info)
1586 GenMMC3_Init(info, 512, 256, 8, 0);
1589 void TLSROM_Init(CartInfo *info)
1591 GenMMC3_Init(info, 512, 256, 8, 0);
1595 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1598 void TKSROM_Init(CartInfo *info)
1600 GenMMC3_Init(info, 512, 256, 8, info->battery);
1604 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1607 void TQROM_Init(CartInfo *info)
1609 GenMMC3_Init(info, 512, 64, 0, 0);
1612 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1613 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1616 void HKROM_Init(CartInfo *info)
1618 GenMMC3_Init(info, 512, 512, 1, info->battery);