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,165,205,245,249,250,254
35 uint8 EXPREGS[8]; /* For bootleg games, mostly. */
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"},
61 void (*pwrap)(uint32 A, uint8 V);
62 void (*cwrap)(uint32 A, uint8 V);
63 void (*mwrap)(uint8 V);
65 void GenMMC3Power(void);
66 void FixMMC3PRG(int V);
67 void FixMMC3CHR(int V);
69 void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery);
71 // ----------------------------------------------------------------------
72 // ------------------------- Generic MM3 Code ---------------------------
73 // ----------------------------------------------------------------------
75 void FixMMC3PRG(int V)
79 pwrap(0xC000,DRegBuf[6]);
84 pwrap(0x8000,DRegBuf[6]);
87 pwrap(0xA000,DRegBuf[7]);
91 void FixMMC3CHR(int V)
93 int cbase=(V&0x80)<<5;
95 cwrap((cbase^0x000),DRegBuf[0]&(~1));
96 cwrap((cbase^0x400),DRegBuf[0]|1);
97 cwrap((cbase^0x800),DRegBuf[1]&(~1));
98 cwrap((cbase^0xC00),DRegBuf[1]|1);
100 cwrap(cbase^0x1000,DRegBuf[2]);
101 cwrap(cbase^0x1400,DRegBuf[3]);
102 cwrap(cbase^0x1800,DRegBuf[4]);
103 cwrap(cbase^0x1c00,DRegBuf[5]);
105 if(mwrap) mwrap(A000B);
108 void MMC3RegReset(void)
110 IRQCount=IRQLatch=IRQa=MMC3_cmd=0;
125 DECLFW(MMC3_CMDWrite)
127 // FCEU_printf("bs %04x %02x\n",A,V);
131 if((V&0x40) != (MMC3_cmd&0x40))
133 if((V&0x80) != (MMC3_cmd&0x80))
139 int cbase=(MMC3_cmd&0x80)<<5;
140 DRegBuf[MMC3_cmd&0x7]=V;
141 switch(MMC3_cmd&0x07)
143 case 0: cwrap((cbase^0x000),V&(~1));
144 cwrap((cbase^0x400),V|1);
146 case 1: cwrap((cbase^0x800),V&(~1));
147 cwrap((cbase^0xC00),V|1);
149 case 2: cwrap(cbase^0x1000,V);
151 case 3: cwrap(cbase^0x1400,V);
153 case 4: cwrap(cbase^0x1800,V);
155 case 5: cwrap(cbase^0x1C00,V);
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 FixMMC3PRG(MMC3_cmd);
229 FixMMC3CHR(MMC3_cmd);
232 static void GENCWRAP(uint32 A, uint8 V)
234 setchr1(A,V); // Business Wars NEEDS THIS for 8K CHR-RAM
237 static void GENPWRAP(uint32 A, uint8 V)
239 setprg8(A,V&0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken
242 static void GENMWRAP(uint8 V)
248 static void GENNOMWRAP(uint8 V)
253 static DECLFW(MBWRAMMMC6)
258 static DECLFR(MAWRAMMMC6)
260 return(WRAM[A&0x3ff]);
263 void GenMMC3Power(void)
265 if(UNIFchrrama) setchr8(0);
267 SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite);
268 SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
269 SetReadHandler(0x8000,0xFFFF,CartBR);
276 FCEU_CheatAddRAM(1,0x7000,WRAM);
277 SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);
278 SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);
280 // asm code needs pages to be set again..
281 Page[14]=WRAM-0x7000;
282 Page[15]=WRAM-0x7800;
287 FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM);
288 SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW);
289 SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR);
290 setprg8r(0x10,0x6000,0);
293 FCEU_dwmemset(WRAM,0,wrams);
297 FCEU_dwmemset(CHRRAM,0,CHRRAMSize);
300 static void GenMMC3Close(void)
309 void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery)
317 PRGmask8[0]&=(prg>>13)-1;
318 CHRmask1[0]&=(chr>>10)-1;
319 CHRmask2[0]&=(chr>>11)-1;
324 WRAM=(uint8*)FCEU_gmalloc(wrams);
325 SetupCartPRGMapping(0x10,WRAM,wrams,1);
326 AddExState(WRAM, wrams, 0, "MRAM");
332 info->SaveGame[0]=WRAM;
333 info->SaveGameLen[0]=wrams;
336 AddExState(MMC3_StateRegs, ~0, 0, 0);
338 info->Power=GenMMC3Power;
339 info->Reset=MMC3RegReset;
340 info->Close=GenMMC3Close;
342 if(info->CRC32 == 0x5104833e) // Kick Master
343 GameHBIRQHook = MMC3_hb_KickMasterHack;
344 else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93
345 GameHBIRQHook = MMC3_hb_KickMasterHack;
346 else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master.
347 GameHBIRQHook = MMC3_hb_PALStarWarsHack;
349 GameHBIRQHook=MMC3_hb;
350 GameStateRestore=GenMMC3Restore;
353 // ----------------------------------------------------------------------
354 // -------------------------- MMC3 Based Code ---------------------------
355 // ----------------------------------------------------------------------
357 // ---------------------------- Mapper 4 --------------------------------
359 static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/
361 static void M4Power(void)
368 void Mapper4_Init(CartInfo *info)
372 if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84))
374 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");
377 GenMMC3_Init(info,512,256,ws,info->battery);
382 // ---------------------------- Mapper 12 -------------------------------
384 static void M12CW(uint32 A, uint8 V)
386 setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V);
389 static DECLFW(M12Write)
392 EXPREGS[1]=(V&0x10)>>4;
395 static void M12Power(void)
397 EXPREGS[0]=EXPREGS[1]=0;
399 SetWriteHandler(0x4100,0x5FFF,M12Write);
402 void Mapper12_Init(CartInfo *info)
404 GenMMC3_Init(info, 512, 256, 8, info->battery);
406 info->Power=M12Power;
407 AddExState(EXPREGS, 2, 0, "EXPR");
410 // ---------------------------- Mapper 37 -------------------------------
412 static void M37PW(uint32 A, uint8 V)
422 static void M37CW(uint32 A, uint8 V)
430 static DECLFW(M37Write)
433 FixMMC3PRG(MMC3_cmd);
434 FixMMC3CHR(MMC3_cmd);
437 static void M37Reset(void)
443 static void M37Power(void)
447 SetWriteHandler(0x6000,0x7FFF,M37Write);
450 void Mapper37_Init(CartInfo *info)
452 GenMMC3_Init(info, 512, 256, 8, info->battery);
455 info->Power=M37Power;
456 info->Reset=M37Reset;
457 AddExState(EXPREGS, 1, 0, "EXPR");
460 // ---------------------------- Mapper 44 -------------------------------
462 static void M44PW(uint32 A, uint8 V)
465 if(EXPREGS[0]>=6) NV&=0x1F;
471 static void M44CW(uint32 A, uint8 V)
474 if(EXPREGS[0]<6) NV&=0x7F;
479 static DECLFW(M44Write)
484 FixMMC3PRG(MMC3_cmd);
485 FixMMC3CHR(MMC3_cmd);
491 static void M44Power(void)
495 SetWriteHandler(0xA000,0xBFFF,M44Write);
498 void Mapper44_Init(CartInfo *info)
500 GenMMC3_Init(info, 512, 256, 8, info->battery);
503 info->Power=M44Power;
504 AddExState(EXPREGS, 1, 0, "EXPR");
507 // ---------------------------- Mapper 45 -------------------------------
509 static void M45CW(uint32 A, uint8 V)
515 NV&=(1<<((EXPREGS[2]&7)+1))-1;
518 NV&=0; // hack ;( don't know exactly how it should be
519 NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4);
524 static void M45PW(uint32 A, uint8 V)
526 V&=(EXPREGS[3]&0x3F)^0x3F;
531 static DECLFW(M45Write)
538 EXPREGS[EXPREGS[4]]=V;
539 EXPREGS[4]=(EXPREGS[4]+1)&3;
542 // FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]);
543 // FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n",
544 // (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
545 // (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)),
546 // (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]),
547 // (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]));
549 FixMMC3PRG(MMC3_cmd);
550 FixMMC3CHR(MMC3_cmd);
553 static DECLFR(M45Read)
555 uint32 addr = 1<<(EXPREGS[5]+4);
556 if(A&(addr|(addr-1)))
562 static void M45Reset(void)
564 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0;
570 static void M45Power(void)
574 EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=EXPREGS[5]=0;
575 SetWriteHandler(0x5000,0x7FFF,M45Write);
576 SetReadHandler(0x5000,0x5FFF,M45Read);
579 void Mapper45_Init(CartInfo *info)
581 GenMMC3_Init(info, 512, 256, 8, info->battery);
584 info->Reset=M45Reset;
585 info->Power=M45Power;
586 AddExState(EXPREGS, 5, 0, "EXPR");
589 // ---------------------------- Mapper 47 -------------------------------
591 static void M47PW(uint32 A, uint8 V)
598 static void M47CW(uint32 A, uint8 V)
606 static DECLFW(M47Write)
609 FixMMC3PRG(MMC3_cmd);
610 FixMMC3CHR(MMC3_cmd);
613 static void M47Power(void)
617 SetWriteHandler(0x6000,0x7FFF,M47Write);
618 // SetReadHandler(0x6000,0x7FFF,0);
621 void Mapper47_Init(CartInfo *info)
623 GenMMC3_Init(info, 512, 256, 8, 0);
626 info->Power=M47Power;
627 AddExState(EXPREGS, 1, 0, "EXPR");
630 // ---------------------------- Mapper 49 -------------------------------
632 static void M49PW(uint32 A, uint8 V)
637 V|=(EXPREGS[0]&0xC0)>>2;
641 setprg32(0x8000,(EXPREGS[0]>>4)&3);
644 static void M49CW(uint32 A, uint8 V)
648 NV|=(EXPREGS[0]&0xC0)<<1;
652 static DECLFW(M49Write)
657 FixMMC3PRG(MMC3_cmd);
658 FixMMC3CHR(MMC3_cmd);
662 static void M49Reset(void)
668 static void M49Power(void)
672 SetWriteHandler(0x6000,0x7FFF,M49Write);
673 SetReadHandler(0x6000,0x7FFF,0);
676 void Mapper49_Init(CartInfo *info)
678 GenMMC3_Init(info, 512, 256, 0, 0);
681 info->Reset=M49Reset;
682 info->Power=M49Power;
683 AddExState(EXPREGS, 1, 0, "EXPR");
686 // ---------------------------- Mapper 52 -------------------------------
687 static void M52PW(uint32 A, uint8 V)
689 uint32 mask = 0x1F^((EXPREGS[0]&8)<<1);
690 uint32 bank = ((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4;
691 setprg8(A, bank|(V & mask));
694 static void M52CW(uint32 A, uint8 V)
696 uint32 mask = 0xFF^((EXPREGS[0]&0x40)<<1);
697 // uint32 bank = (((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7;
698 uint32 bank = (((EXPREGS[0]>>4)&2)|(EXPREGS[0]&4)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; // actually 256K CHR banks index bits is inverted!
699 setchr1(A, bank|(V & mask));
702 static DECLFW(M52Write)
711 FixMMC3PRG(MMC3_cmd);
712 FixMMC3CHR(MMC3_cmd);
715 static void M52Reset(void)
717 EXPREGS[0]=EXPREGS[1]=0;
721 static void M52Power(void)
725 SetWriteHandler(0x6000,0x7FFF,M52Write);
728 void Mapper52_Init(CartInfo *info)
730 GenMMC3_Init(info, 256, 256, 8, info->battery);
733 info->Reset=M52Reset;
734 info->Power=M52Power;
735 AddExState(EXPREGS, 2, 0, "EXPR");
738 // ---------------------------- Mapper 74 -------------------------------
740 static void M74CW(uint32 A, uint8 V)
742 if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes
748 void Mapper74_Init(CartInfo *info)
750 GenMMC3_Init(info, 512, 256, 8, info->battery);
753 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
754 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
755 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
758 // ---------------------------- Mapper 114 ------------------------------
761 uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4};
763 static void M114PWRAP(uint32 A, uint8 V)
767 // FCEU_printf("8000-C000:%02X\n",EXPREGS[0]&0xF);
768 setprg16(0x8000,EXPREGS[0]&0xF);
769 setprg16(0xC000,EXPREGS[0]&0xF);
772 // FCEU_printf("%04X:%02X\n",A,V&0x3F);
777 static DECLFW(M114Write)
781 case 0x8001: MMC3_CMDWrite(0xA000,V); break;
782 case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break;
783 case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break;
784 case 0xA001: IRQLatch=V; break;
785 case 0xC001: IRQReload=1; break;
786 case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break;
787 case 0xE001: IRQa=1; break;
791 static DECLFW(M114ExWrite)
796 FixMMC3PRG(MMC3_cmd);
800 static void M114Power(void)
803 SetWriteHandler(0x8000,0xFFFF,M114Write);
804 SetWriteHandler(0x5000,0x7FFF,M114ExWrite);
807 static void M114Reset(void)
813 void Mapper114_Init(CartInfo *info)
816 GenMMC3_Init(info, 256, 256, 0, 0);
818 info->Power=M114Power;
819 info->Reset=M114Reset;
820 AddExState(EXPREGS, 1, 0, "EXPR");
821 AddExState(&cmdin, 1, 0, "CMDI");
824 // ---------------------------- Mapper 115 KN-658 board ------------------------------
826 static void M115PW(uint32 A, uint8 V)
829 setprg32(0x8000,(EXPREGS[0]&7)>>1);
834 static void M115CW(uint32 A, uint8 V)
836 setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8));
839 static DECLFW(M115Write)
841 // FCEU_printf("%04x:%04x\n",A,V);
842 if(A==0x5080) EXPREGS[2]=V;
847 FixMMC3PRG(MMC3_cmd);
850 static DECLFR(M115Read)
855 static void M115Power(void)
858 SetWriteHandler(0x4100,0x7FFF,M115Write);
859 SetReadHandler(0x5000,0x5FFF,M115Read);
862 void Mapper115_Init(CartInfo *info)
864 GenMMC3_Init(info, 128, 512, 0, 0);
867 info->Power=M115Power;
868 AddExState(EXPREGS, 2, 0, "EXPR");
871 // ---------------------------- Mapper 118 ------------------------------
873 static uint8 PPUCHRBus;
874 static uint8 TKSMIR[8];
876 static void FP_FASTAPASS(1) TKSPPU(uint32 A)
881 setmirror(MI_0+TKSMIR[A]);
884 static void TKSWRAP(uint32 A, uint8 V)
888 if(PPUCHRBus==(A>>10))
889 setmirror(MI_0+(V>>7));
892 // ---------------------------- Mapper 119 ------------------------------
894 static void TQWRAP(uint32 A, uint8 V)
896 setchr1r((V&0x40)>>2,A,V&0x3F);
899 void Mapper119_Init(CartInfo *info)
901 GenMMC3_Init(info, 512, 64, 0, 0);
904 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
905 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
908 // ---------------------------- Mapper 134 ------------------------------
910 static void M134PW(uint32 A, uint8 V)
912 setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4));
915 static void M134CW(uint32 A, uint8 V)
917 setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3));
920 static DECLFW(M134Write)
923 FixMMC3CHR(MMC3_cmd);
924 FixMMC3PRG(MMC3_cmd);
927 static void M134Power(void)
931 SetWriteHandler(0x6001,0x6001,M134Write);
934 static void M134Reset(void)
940 void Mapper134_Init(CartInfo *info)
942 GenMMC3_Init(info, 256, 256, 0, 0);
945 info->Power=M134Power;
946 info->Reset=M134Reset;
947 AddExState(EXPREGS, 4, 0, "EXPR");
950 // ---------------------------- Mapper 165 ------------------------------
952 static void M165CW(uint32 A, uint8 V)
960 static void M165PPUFD(void)
964 M165CW(0x0000,DRegBuf[0]);
965 M165CW(0x1000,DRegBuf[2]);
969 static void M165PPUFE(void)
973 M165CW(0x0000,DRegBuf[1]);
974 M165CW(0x1000,DRegBuf[4]);
978 static void M165CWM(uint32 A, uint8 V)
980 if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2))
982 if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4))
986 static void FP_FASTAPASS(1) M165PPU(uint32 A)
988 if((A&0x1FF0)==0x1FD0)
992 } else if((A&0x1FF0)==0x1FE0)
999 static void M165Power(void)
1005 void Mapper165_Init(CartInfo *info)
1007 GenMMC3_Init(info, 512, 128, 8, info->battery);
1010 info->Power=M165Power;
1012 CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize);
1013 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1014 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1015 AddExState(EXPREGS, 4, 0, "EXPR");
1018 // ---------------------------- Mapper 191 ------------------------------
1020 static void M191CW(uint32 A, uint8 V)
1022 setchr1r((V&0x80)>>3,A,V);
1025 void Mapper191_Init(CartInfo *info)
1027 GenMMC3_Init(info, 256, 256, 8, info->battery);
1030 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1031 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1032 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1035 // ---------------------------- Mapper 192 -------------------------------
1037 static void M192CW(uint32 A, uint8 V)
1039 if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese),
1045 void Mapper192_Init(CartInfo *info)
1047 GenMMC3_Init(info, 512, 256, 8, info->battery);
1050 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1051 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1052 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1055 // ---------------------------- Mapper 194 -------------------------------
1057 static void M194CW(uint32 A, uint8 V)
1059 if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes
1065 void Mapper194_Init(CartInfo *info)
1067 GenMMC3_Init(info, 512, 256, 8, info->battery);
1070 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1071 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1072 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1075 // ---------------------------- Mapper 195 -------------------------------
1076 static uint8 *wramtw;
1077 static uint16 wramsize;
1079 static void M195CW(uint32 A, uint8 V)
1081 if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C)
1087 static void M195Power(void)
1090 setprg4r(0x10,0x5000,0);
1091 SetWriteHandler(0x5000,0x5fff,CartBW);
1092 SetReadHandler(0x5000,0x5fff,CartBR);
1095 static void M195Close(void)
1102 void Mapper195_Init(CartInfo *info)
1104 GenMMC3_Init(info, 512, 256, 8, info->battery);
1106 info->Power=M195Power;
1107 info->Close=M195Close;
1109 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1110 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1112 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1113 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1114 AddExState(CHRRAM, CHRRAMSize, 0, "CHRR");
1115 AddExState(wramtw, wramsize, 0, "TRAM");
1118 // ---------------------------- Mapper 196 -------------------------------
1119 // MMC3 board with optional command address line connection, allows to
1120 // make three-four different wirings to IRQ address lines and separately to
1121 // CMD address line, Mali Boss additionally check if wiring are correct for
1124 static void M196PW(uint32 A, uint8 V)
1126 if(EXPREGS[0]) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes
1127 setprg32(0x8000,EXPREGS[1]);
1132 static DECLFW(Mapper196Write)
1135 A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1);
1139 A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1);
1144 static DECLFW(Mapper196WriteLo)
1147 EXPREGS[1]=(V&0xf)|(V>>4);
1148 FixMMC3PRG(MMC3_cmd);
1151 static void Mapper196Power(void)
1154 EXPREGS[0] = EXPREGS[1] = 0;
1155 SetWriteHandler(0x6000,0x6FFF,Mapper196WriteLo);
1156 SetWriteHandler(0x8000,0xFFFF,Mapper196Write);
1159 void Mapper196_Init(CartInfo *info)
1161 GenMMC3_Init(info, 128, 128, 0, 0);
1163 info->Power=Mapper196Power;
1166 // ---------------------------- Mapper 197 -------------------------------
1168 static void M197CW(uint32 A, uint8 V)
1171 setchr4(0x0000,V>>1);
1178 void Mapper197_Init(CartInfo *info)
1180 GenMMC3_Init(info, 128, 512, 8, 0);
1184 // ---------------------------- Mapper 198 -------------------------------
1186 static void M198PW(uint32 A, uint8 V)
1188 if(V>=0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes
1194 void Mapper198_Init(CartInfo *info)
1196 GenMMC3_Init(info, 1024, 256, 8, info->battery);
1198 info->Power=M195Power;
1199 info->Close=M195Close;
1201 wramtw=(uint8*)FCEU_gmalloc(wramsize);
1202 SetupCartPRGMapping(0x10, wramtw, wramsize, 1);
1203 AddExState(wramtw, wramsize, 0, "TRAM");
1206 // ---------------------------- Mapper 205 ------------------------------
1209 static void M205PW(uint32 A, uint8 V)
1211 // GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü 1F + àïïàðàòíûé ïåðåêëþ÷àòåëü íà øèíå àäðåñà
1212 setprg8(A,(V&0x0f)|EXPREGS[0]);
1215 static void M205CW(uint32 A, uint8 V)
1217 // GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü FF
1218 setchr1(A,(V&0x7F)|(EXPREGS[0]<<3));
1221 static DECLFW(M205Write)
1223 if(EXPREGS[2] == 0) {
1224 EXPREGS[0] = A & 0x30;
1225 EXPREGS[2] = A & 0x80;
1226 FixMMC3PRG(MMC3_cmd);
1227 FixMMC3CHR(MMC3_cmd);
1233 static void M205Reset(void)
1235 EXPREGS[0]=EXPREGS[2]=0;
1239 static void M205Power(void)
1242 SetWriteHandler(0x6000,0x6fff,M205Write);
1245 void Mapper205_Init(CartInfo *info)
1247 GenMMC3_Init(info, 256, 256, 8, 0);
1250 info->Power=M205Power;
1251 info->Reset=M205Reset;
1252 AddExState(EXPREGS, 1, 0, "EXPR");
1255 // ---------------------------- Mapper 245 ------------------------------
1257 static void M245CW(uint32 A, uint8 V)
1259 if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart
1262 FixMMC3PRG(MMC3_cmd);
1265 static void M245PW(uint32 A, uint8 V)
1267 setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5));
1270 static void M245Power(void)
1276 void Mapper245_Init(CartInfo *info)
1278 GenMMC3_Init(info, 512, 256, 8, info->battery);
1281 info->Power=M245Power;
1282 AddExState(EXPREGS, 1, 0, "EXPR");
1285 // ---------------------------- Mapper 249 ------------------------------
1287 static void M249PW(uint32 A, uint8 V)
1292 V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10);
1296 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1302 static void M249CW(uint32 A, uint8 V)
1305 V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0);
1309 static DECLFW(M249Write)
1312 FixMMC3PRG(MMC3_cmd);
1313 FixMMC3CHR(MMC3_cmd);
1316 static void M249Power(void)
1320 SetWriteHandler(0x5000,0x5000,M249Write);
1323 void Mapper249_Init(CartInfo *info)
1325 GenMMC3_Init(info, 512, 256, 8, info->battery);
1328 info->Power=M249Power;
1329 AddExState(EXPREGS, 1, 0, "EXPR");
1332 // ---------------------------- Mapper 250 ------------------------------
1334 static DECLFW(M250Write)
1336 MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1339 static DECLFW(M250IRQWrite)
1341 MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
1344 static void M250_Power(void)
1347 SetWriteHandler(0x8000,0xBFFF,M250Write);
1348 SetWriteHandler(0xC000,0xFFFF,M250IRQWrite);
1351 void Mapper250_Init(CartInfo *info)
1353 GenMMC3_Init(info, 512, 256, 8, info->battery);
1354 info->Power=M250_Power;
1357 // ---------------------------- Mapper 254 ------------------------------
1359 static DECLFR(MR254WRAM)
1362 return WRAM[A-0x6000];
1364 return WRAM[A-0x6000]^EXPREGS[1];
1367 static DECLFW(M254Write)
1370 case 0x8000: EXPREGS[0]=0xff;
1372 case 0xA001: EXPREGS[1]=V;
1377 static void M254_Power(void)
1380 SetWriteHandler(0x8000,0xBFFF,M254Write);
1381 SetReadHandler(0x6000,0x7FFF,MR254WRAM);
1383 // hrrr.. can't handle those evil xors here..
1384 Page[12]=Page[13]=Page[14]=Page[15]=WRAM-0x6000;
1388 void Mapper254_Init(CartInfo *info)
1390 GenMMC3_Init(info, 128, 128, 8, info->battery);
1391 info->Power=M254_Power;
1392 AddExState(EXPREGS, 2, 0, "EXPR");
1395 // ---------------------------- UNIF Boards -----------------------------
1397 void TBROM_Init(CartInfo *info)
1399 GenMMC3_Init(info, 64, 64, 0, 0);
1402 void TEROM_Init(CartInfo *info)
1404 GenMMC3_Init(info, 32, 32, 0, 0);
1407 void TFROM_Init(CartInfo *info)
1409 GenMMC3_Init(info, 512, 64, 0, 0);
1412 void TGROM_Init(CartInfo *info)
1414 GenMMC3_Init(info, 512, 0, 0, 0);
1417 void TKROM_Init(CartInfo *info)
1419 GenMMC3_Init(info, 512, 256, 8, info->battery);
1422 void TLROM_Init(CartInfo *info)
1424 GenMMC3_Init(info, 512, 256, 0, 0);
1427 void TSROM_Init(CartInfo *info)
1429 GenMMC3_Init(info, 512, 256, 8, 0);
1432 void TLSROM_Init(CartInfo *info)
1434 GenMMC3_Init(info, 512, 256, 8, 0);
1438 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1441 void TKSROM_Init(CartInfo *info)
1443 GenMMC3_Init(info, 512, 256, 8, info->battery);
1447 AddExState(&PPUCHRBus, 1, 0, "PPUC");
1450 void TQROM_Init(CartInfo *info)
1452 GenMMC3_Init(info, 512, 64, 0, 0);
1455 CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize);
1456 SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1);
1459 void HKROM_Init(CartInfo *info)
1461 GenMMC3_Init(info, 512, 512, 1, info->battery);