diff --git a/src/boards/01-222.cpp b/src/boards/01-222.cpp index 4307a2cf..ea08ffc8 100644 --- a/src/boards/01-222.cpp +++ b/src/boards/01-222.cpp @@ -16,20 +16,26 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * TXC mappers */ #include "mapinc.h" -static uint8 reg[4]; +static uint8 reg[4], cmd, is172, is173; static SFORMAT StateRegs[]= { {reg, 4, "REGS"}, + {&cmd, 1, "CMD"}, {0} }; static void Sync(void) { setprg32(0x8000,(reg[2]>>2)&1); + if(is172) + setchr8((((cmd^reg[2])>>3)&2)|(((cmd^reg[2])>>5)&1)); // 1991 DU MA Racing probably CHR bank sequence is WRONG, so it is possible to + // rearrange CHR banks for normal UNIF board and mapper 172 is unneccessary + else setchr8(reg[2]&3); } @@ -42,15 +48,17 @@ static DECLFW(UNL22211WriteLo) static DECLFW(UNL22211WriteHi) { // FCEU_printf("bs %04x %02x\n",A,V); + cmd=V; Sync(); } static DECLFR(UNL22211ReadLo) { - if(reg[3]) - return reg[2]; - else - return X.DB; + return (reg[1]^reg[2])|(is173?0x01:0x40); +// if(reg[3]) +// return reg[2]; +// else +// return X.DB; } static void UNL22211Power(void) @@ -69,6 +77,26 @@ static void StateRestore(int version) void UNL22211_Init(CartInfo *info) { + is172=0; + is173=0; + info->Power=UNL22211Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper172_Init(CartInfo *info) +{ + is172=1; + is173=0; + info->Power=UNL22211Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper173_Init(CartInfo *info) +{ + is172=0; + is173=1; info->Power=UNL22211Power; GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); diff --git a/src/boards/103.cpp b/src/boards/103.cpp new file mode 100644 index 00000000..3db051d9 --- /dev/null +++ b/src/boards/103.cpp @@ -0,0 +1,115 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg0, reg1, reg2; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®0, 1, "REG0"}, + {®1, 1, "REG1"}, + {®2, 1, "REG2"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8(0x8000,0xc); + setprg8(0xe000,0xf); + if(reg2&0x10) + { + setprg8(0x6000,reg0); + setprg8(0xa000,0xd); + setprg8(0xc000,0xe); + } + else + { + setprg8r(0x10,0x6000,0); + setprg4(0xa000,(0xd<<1)); + setprg2(0xb000,(0xd<<2)+2); + setprg2r(0x10,0xb800,4); + setprg2r(0x10,0xc000,5); + setprg2r(0x10,0xc800,6); + setprg2r(0x10,0xd000,7); + setprg2(0xd800,(0xe<<2)+3); + } + setmirror(reg1); +} + +static DECLFW(M103Write0) +{ + reg0=V&0xf; + Sync(); +} + +static DECLFW(M103Write1) +{ + reg1=(V>>3)&1; + Sync(); +} + +static DECLFW(M103Write2) +{ + reg2=V; + Sync(); +} + +static void M103Power(void) +{ + reg0=reg1=0; reg2=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0xB800,0xD7FF,CartBW); + SetWriteHandler(0x8000,0x8FFF,M103Write0); + SetWriteHandler(0xE000,0xEFFF,M103Write1); + SetWriteHandler(0xF000,0xFFFF,M103Write2); +} + +static void M103Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper103_Init(CartInfo *info) +{ + info->Power=M103Power; + info->Close=M103Close; + GameStateRestore=StateRestore; + + WRAMSIZE=16384; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/106.cpp b/src/boards/106.cpp new file mode 100644 index 00000000..14012812 --- /dev/null +++ b/src/boards/106.cpp @@ -0,0 +1,119 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[16], IRQa; +static uint32 IRQCount; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQCOUNT"}, + {reg, 16, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr1(0x0000,reg[0]&0xfe); + setchr1(0x0400,reg[1]|1); + setchr1(0x0800,reg[2]&0xfe); + setchr1(0x0c00,reg[3]|1); + setchr1(0x1000,reg[4]); + setchr1(0x1400,reg[5]); + setchr1(0x1800,reg[6]); + setchr1(0x1c00,reg[7]); + setprg8r(0x10,0x6000,0); + setprg8(0x8000,(reg[0x8]&0xf)|0x10); + setprg8(0xA000,(reg[0x9]&0x1f)); + setprg8(0xC000,(reg[0xa]&0x1f)); + setprg8(0xE000,(reg[0xb]&0xf)|0x10); + setmirror((reg[0xc]&1)^1); +} + +static DECLFW(M106Write) +{ + A&=0xF; + switch(A) + { + case 0xD: IRQa=0; IRQCount=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE: IRQCount=(IRQCount&0xFF00)|V; break; + case 0xF: IRQCount=(IRQCount&0x00FF)|(V<<8); IRQa=1; break; + default: reg[A]=V; Sync(); break; + } +} + +static void M106Power(void) +{ + reg[8]=reg[9]=reg[0xa]=reg[0xb]=-1; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M106Write); +} + +static void M106Reset(void) +{ +} + +static void M106Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +void M106CpuHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper106_Init(CartInfo *info) +{ + info->Reset=M106Reset; + info->Power=M106Power; + info->Close=M106Close; + MapIRQHook=M106CpuHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/108.cpp b/src/boards/108.cpp new file mode 100644 index 00000000..67ec8bb1 --- /dev/null +++ b/src/boards/108.cpp @@ -0,0 +1,62 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg); + setprg32(0x8000,~0); + setchr8(0); +} + +static DECLFW(M108Write) +{ + reg=V; + Sync(); +} + +static void M108Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8FFF,0x8FFF,M108Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper108_Init(CartInfo *info) +{ + info->Power=M108Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/112.cpp b/src/boards/112.cpp index c539fb76..ce83c4eb 100644 --- a/src/boards/112.cpp +++ b/src/boards/112.cpp @@ -16,18 +16,20 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * NTDEC, ASDER games */ #include "mapinc.h" static uint8 reg[8]; -static uint8 mirror, cmd; +static uint8 mirror, cmd, bank; static uint8 *WRAM=NULL; static SFORMAT StateRegs[]= { {&cmd, 1, "CMD"}, {&mirror, 1, "MIRR"}, + {&bank, 1, "BANK"}, {reg, 8, "REGS"}, {0} }; @@ -37,23 +39,22 @@ static void Sync(void) setmirror(mirror^1); setprg8(0x8000,reg[0]); setprg8(0xA000,reg[1]); - setchr2(0x0000,reg[2]>>1); - setchr2(0x0800,reg[3]>>1); - setchr1(0x1000,reg[4]); - setchr1(0x1400,reg[5]); - setchr1(0x1800,reg[6]); - setchr1(0x1C00,reg[7]); + setchr2(0x0000,(reg[2]>>1)); + setchr2(0x0800,(reg[3]>>1)); + setchr1(0x1000,((bank&0x10)<<4)|reg[4]); + setchr1(0x1400,((bank&0x20)<<3)|reg[5]); + setchr1(0x1800,((bank&0x40)<<2)|reg[6]); + setchr1(0x1C00,((bank&0x80)<<1)|reg[7]); } static DECLFW(M112Write) { -// FCEU_printf("bs %04x %02x\n",A,V); switch(A) { case 0xe000: mirror=V&1; Sync(); ;break; case 0x8000: cmd=V&7; break; case 0xa000: reg[cmd]=V; Sync(); break; -// default: FCEU_printf("bs %04x %02x\n",A,V); + case 0xc000: bank=V; Sync(); break; } } @@ -66,6 +67,7 @@ static void M112Close(void) static void M112Power(void) { + bank=0; setprg16(0xC000,~0); setprg8r(0x10,0x6000,0); SetReadHandler(0x8000,0xFFFF,CartBR); diff --git a/src/boards/117.cpp b/src/boards/117.cpp index 495284ae..7df9f5ae 100644 --- a/src/boards/117.cpp +++ b/src/boards/117.cpp @@ -20,7 +20,7 @@ #include "mapinc.h" -static uint8 prgreg[4], chrreg[8]; +static uint8 prgreg[4], chrreg[8], mirror; static uint8 IRQa, IRQCount, IRQLatch; static SFORMAT StateRegs[]= @@ -30,6 +30,7 @@ static SFORMAT StateRegs[]= {&IRQLatch, 1, "IRQL"}, {prgreg, 4, "PREGS"}, {chrreg, 8, "CREGS"}, + {&mirror, 1, "MREG"}, {0} }; @@ -42,6 +43,7 @@ static void Sync(void) setprg8(0xe000,prgreg[3]); for(i=0; i<8; i++) setchr1(i<<10,chrreg[i]); + setmirror(mirror^1); } static DECLFW(M117Write) @@ -62,6 +64,7 @@ static DECLFW(M117Write) case 0xc003: IRQCount=IRQLatch; IRQa|=2; break; case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break; case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break; + case 0xd000: mirror=V&1; } } diff --git a/src/boards/120.cpp b/src/boards/120.cpp new file mode 100644 index 00000000..514d5a21 --- /dev/null +++ b/src/boards/120.cpp @@ -0,0 +1,66 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg); + setprg32(0x8000,2); + setchr8(0); +} + +static DECLFW(M120Write) +{ + if(A==0x41FF) + { + reg=V&7; + Sync(); + } +} + +static void M120Power(void) +{ + reg=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4100,0x5FFF,M120Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper120_Init(CartInfo *info) +{ + info->Power=M120Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/121.cpp b/src/boards/121.cpp new file mode 100644 index 00000000..1e5e0152 --- /dev/null +++ b/src/boards/121.cpp @@ -0,0 +1,91 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007-2008 Mad Dumper, CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Panda prince pirate. + * MK4, MK6, A9711 board, MAPPER 187 the same! + * UNL6035052_Init seems to be the same too, but with prot array in reverse + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 readbyte = 0; + +static DECLFW(M121Write) +{ + FCEU_printf("write: %04x:%04x\n",A&0xE003,V); + if((A&0xF003)==0x8003) + { +// FCEU_printf(" prot write"); +// FCEU_printf("write: %04x:%04x\n",A,V); + if (V==0xAB) setprg8(0xE000,7); + else if(V==0x26) setprg8(0xE000,8); +// else if(V==0x26) setprg8(0xE000,1); // MK3 +// else if(V==0x26) setprg8(0xE000,0x15); // sonic 3D blast, 8003 - command (0x26), 8001 - data 0x2A (<<1 = 0x15) + else if(V==0xFF) setprg8(0xE000,9); + else if(V==0x28) setprg8(0xC000,0xC); + else if(V==0xEC) setprg8(0xE000,0xD); +// else if(V==0xEC) setprg8(0xE000,0xC);//MK3 + else if(V==0xEF) setprg8(0xE000,0xD); // damn mess, need real hardware to figure out bankswitching + else if(V==0x2A) setprg8(0xA000,0x0E); +// else if(V==0x2A) setprg8(0xE000,0x0C); // MK3 + else if(V==0x20) setprg8(0xE000,0x13); + else if(V==0x29) setprg8(0xE000,0x1B); + else + { +// FCEU_printf(" unknown"); + FixMMC3PRG(MMC3_cmd); + MMC3_CMDWrite(A,V); + } +// FCEU_printf("\n"); + } + else + { +// FixMMC3PRG(MMC3_cmd); + MMC3_CMDWrite(A,V); + } +} + +static uint8 prot_array[16] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFW(M121LoWrite) +{ + EXPREGS[0] = prot_array[V&3]; // 0x100 bit in address seems to be switch arrays 0, 2, 2, 3 (Contra Fighter) + FCEU_printf("write: %04x:%04x\n",A,V); +} + +static DECLFR(M121Read) +{ + FCEU_printf("read: %04x\n",A); + return EXPREGS[0]; +} + +static void M121Power(void) +{ + GenMMC3Power(); +// Write_IRQFM(0x4017,0x40); + SetReadHandler(0x5000,0x5FFF,M121Read); + SetWriteHandler(0x5000,0x5FFF,M121LoWrite); + SetWriteHandler(0x8000,0x9FFF,M121Write); +} + +void Mapper121_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 8, 0); + info->Power=M121Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/src/boards/15.cpp b/src/boards/15.cpp new file mode 100644 index 00000000..175e8b99 --- /dev/null +++ b/src/boards/15.cpp @@ -0,0 +1,119 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "mapinc.h" + +static uint16 latchea; +static uint8 latched; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static SFORMAT StateRegs[]= +{ + {&latchea, 2, "LATCHEA"}, + {&latched, 1, "LATCHED"}, + {0} +}; + +static void Sync(void) +{ + int i; + setmirror(((latched>>6)&1)^1); + switch(latchea) + { + case 0x8000: + for(i=0;i<4;i++) + setprg8(0x8000+(i<<13),(((latched&0x7F)<<1)+i)^(latched>>7)); + break; + case 0x8002: + for(i=0;i<4;i++) + setprg8(0x8000+(i<<13),((latched&0x7F)<<1)+(latched>>7)); + break; + case 0x8001: + case 0x8003: + for(i=0;i<4;i++) + { + unsigned int b; + b=latched&0x7F; + if(i>=2 && !(latchea&0x2)) + i=0x7F; + setprg8(0x8000+(i<<13),(i&1)+((b<<1)^(latched>>7))); + } + break; + } +} + +static DECLFW(M15Write) +{ + latchea=A; + latched=V; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void M15Power(void) +{ + latchea=0x8000; + latched=0; + setchr8(0); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0xFFFF,M15Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + Sync(); +} + +static void M15Reset(void) +{ + latchea=0x8000; + latched=0; + Sync(); +} + +static void M15Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +void Mapper15_Init(CartInfo *info) +{ + info->Power=M15Power; + info->Reset=M15Reset; + info->Close=M15Close; + GameStateRestore=StateRestore; + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/src/boards/177.cpp b/src/boards/177.cpp new file mode 100644 index 00000000..e8e758e4 --- /dev/null +++ b/src/boards/177.cpp @@ -0,0 +1,87 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,reg&0x1f); + setmirror(((reg&0x20)>>5)^1); +} + +static DECLFW(M177Write) +{ + reg=V; + Sync(); +} + +static void M177Power(void) +{ + reg=0; + Sync(); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M177Write); +} + +static void M177Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper177_Init(CartInfo *info) +{ + info->Power=M177Power; + info->Close=M177Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/178.cpp b/src/boards/178.cpp new file mode 100644 index 00000000..7a58ab6f --- /dev/null +++ b/src/boards/178.cpp @@ -0,0 +1,101 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[3]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 3, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setmirror(reg[0]); + setprg8r(0x10,0x6000,0); + setchr8(0); + setprg32(0x8000,(reg[1]+reg[2])&0xf); +} + +static DECLFW(M178Write0) +{ + reg[0]=(V&1)^1; + Sync(); +} + +static DECLFW(M178Write1) +{ + reg[1]=(V>>1)&0xf; + Sync(); +} + +static DECLFW(M178Write2) +{ + reg[2]=(V<<2)&0xf; + Sync(); +} + +static void M178Power(void) +{ + reg[0]=1; reg[1]=0; reg[2]=0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4800,0x4800,M178Write0); + SetWriteHandler(0x4801,0x4801,M178Write1); + SetWriteHandler(0x4802,0x4802,M178Write2); +} + +static void M178Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper178_Init(CartInfo *info) +{ + info->Power=M178Power; + info->Close=M178Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/179.cpp b/src/boards/179.cpp new file mode 100644 index 00000000..1aa4c7d7 --- /dev/null +++ b/src/boards/179.cpp @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[2]; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REG"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,reg[1]>>1); + setmirror((reg[0]&1)^1); +} + +static DECLFW(M179Write) +{ + if(A==0xa000) reg[0]=V; + Sync(); +} + +static DECLFW(M179WriteLo) +{ + if(A==0x5ff1) reg[1]=V; + Sync(); +} + +static void M179Power(void) +{ + reg[0]=reg[1]=0; + Sync(); + SetWriteHandler(0x4020,0x5fff,M179WriteLo); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M179Write); +} + +static void M179Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper179_Init(CartInfo *info) +{ + info->Power=M179Power; + info->Close=M179Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/183.cpp b/src/boards/183.cpp index e7d4e2fb..b2e87d63 100644 --- a/src/boards/183.cpp +++ b/src/boards/183.cpp @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Gimmick Bootleg + * Gimmick Bootleg (VRC4 mapper) */ #include "mapinc.h" diff --git a/src/boards/187.cpp b/src/boards/187.cpp index e0cab41f..b4531103 100644 --- a/src/boards/187.cpp +++ b/src/boards/187.cpp @@ -20,7 +20,6 @@ #include "mapinc.h" #include "mmc3.h" -#include "../sound.h" static void M187CW(uint32 A, uint8 V) { @@ -87,7 +86,7 @@ static void M187Power(void) { EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; GenMMC3Power(); - Write_IRQFM(0x4017,0x40); +// Write_IRQFM(0x4017,0x40); SetReadHandler(0x5000,0x5FFF,M187Read); SetWriteHandler(0x5000,0x5FFF,M187WriteLo); SetWriteHandler(0x8000,0x8000,M187Write8000); diff --git a/src/boards/222.cpp b/src/boards/222.cpp index c6b0a49d..280b98a7 100644 --- a/src/boards/222.cpp +++ b/src/boards/222.cpp @@ -16,13 +16,12 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * + * (VRC4 mapper) */ #include "mapinc.h" -static uint8 IRQCount; -//static uint8 IRQPre; +static uint8 IRQCount; static uint8 IRQa; static uint8 prg_reg[2]; static uint8 chr_reg[8]; @@ -43,19 +42,19 @@ static void M222IRQ(void) if(IRQa) { IRQCount++; - if(IRQCount>=240) + if(IRQCount>=238) { X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; +// IRQa=0; } } } static void Sync(void) { + int i; setprg8(0x8000,prg_reg[0]); setprg8(0xA000,prg_reg[1]); - int i; for(i=0; i<8; i++) setchr1(i<<10,chr_reg[i]); setmirror(mirr^1); @@ -81,7 +80,7 @@ static DECLFW(M222Write) // case 0xF002: FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; // case 0xD001: IRQa=V; X6502_IRQEnd(FCEU_IQEXT); FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; // case 0xC001: IRQPre=16; FCEU_printf("%04x:%02x %d\n",A,V,scanline); break; - case 0xF000: IRQCount=V; IRQa=V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF000: IRQa=IRQCount=V; if(scanline<240) IRQCount-=8; else IRQCount+=4; X6502_IRQEnd(FCEU_IQEXT); break; } Sync(); } diff --git a/src/boards/23.cpp b/src/boards/23.cpp new file mode 100644 index 00000000..0219a1dc --- /dev/null +++ b/src/boards/23.cpp @@ -0,0 +1,208 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 is23; +static uint16 IRQCount; +static uint8 IRQLatch,IRQa; +static uint8 prgreg[2]; +static uint8 chrreg[8]; +static uint8 regcmd, irqcmd, mirr, big_bank; +static uint16 acount=0; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {prgreg, 2, "PRGREGS"}, + {chrreg, 8, "CHRREGS"}, + {®cmd, 1, "REGCMD"}, + {&irqcmd, 1, "IRQCMD"}, + {&mirr, 1, "MIRR"}, + {&big_bank, 1, "MIRR"}, + {&IRQCount, 2, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void Sync(void) +{ + if(regcmd&2) + { + setprg8(0xC000,prgreg[0]|big_bank); + setprg8(0x8000,((~1)&0x1F)|big_bank); + } + else + { + setprg8(0x8000,prgreg[0]|big_bank); + setprg8(0xC000,((~1)&0x1F)|big_bank); + } + setprg8(0xA000,prgreg[1]|big_bank); + setprg8(0xE000,((~0)&0x1F)|big_bank); + if(UNIFchrrama) + setchr8(0); + else + { + uint8 i; + for(i=0; i<8; i++) + setchr1(i<<10, chrreg[i]); + } + switch(mirr&0x3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(M23Write) +{ +// FCEU_printf("%04x:%04x\n",A,V); + A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); // actually there is many-in-one mapper source, some pirate or + // licensed games use various address bits for registers + A&=0xF003; + if((A>=0xB000)&&(A<=0xE003)) + { + if(UNIFchrrama) + big_bank=(V&8)<<2; // my personally many-in-one feature ;) just for support pirate cart 2-in-1 + else + { + uint16 i=((A>>1)&1)|((A-0xB000)>>11); + chrreg[i]&=(0xF0)>>((A&1)<<2); + chrreg[i]|=(V&0xF)<<((A&1)<<2); + } + Sync(); + } + else + switch(A&0xF003) + { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: if(is23) + prgreg[0]=V&0x1F; + Sync(); + break; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: if(is23) + prgreg[1]=V&0x1F; + else + { + prgreg[0]=(V<<1)&0x1F; + prgreg[1]=((V<<1)&0x1F)|1; + } + Sync(); + break; + case 0x9000: + case 0x9001: if(V!=0xFF) mirr=V; Sync(); break; + case 0x9002: + case 0x9003: regcmd=V; Sync(); break; + case 0xF000: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0xF0; IRQLatch|=V&0xF; break; + case 0xF001: X6502_IRQEnd(FCEU_IQEXT); IRQLatch&=0x0F; IRQLatch|=V<<4; break; + case 0xF002: X6502_IRQEnd(FCEU_IQEXT); acount=0; IRQCount=IRQLatch; IRQa=V&2; irqcmd=V&1; break; + case 0xF003: X6502_IRQEnd(FCEU_IQEXT); IRQa=irqcmd; break; + } +} + +static void M23Power(void) +{ + big_bank=0x20; + Sync(); + setprg8r(0x10,0x6000,0); // another many-in-one code, WRAM actually contain only WaiWaiWorld game + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M23Write); +} + +static void M23Reset(void) +{ +} + +void M23IRQHook(int a) +{ + #define LCYCS 341 + if(IRQa) + { + acount+=a*3; + if(acount>=LCYCS) + { + while(acount>=LCYCS) + { + acount-=LCYCS; + IRQCount++; + if(IRQCount&0x100) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void M23Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); +} + +void Mapper23_Init(CartInfo *info) +{ + is23=1; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} + +void UNLT230_Init(CartInfo *info) +{ + is23=0; + info->Power=M23Power; + info->Close=M23Close; + MapIRQHook=M23IRQHook; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/3d-block.cpp b/src/boards/3d-block.cpp new file mode 100644 index 00000000..0815387b --- /dev/null +++ b/src/boards/3d-block.cpp @@ -0,0 +1,110 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[4], IRQa; +static int16 IRQCount, IRQPause; + +static int16 Count = 0x0000; + +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg32(0x8000,0); + setchr8(0); +} + +//#define Count 0x1800 +#define Pause 0x010 + +static DECLFW(UNL3DBlockWrite) +{ + switch(A) + { +//4800 32 +//4900 37 +//4a00 01 +//4e00 18 + case 0x4800: reg[0]=V; break; + case 0x4900: reg[1]=V; break; + case 0x4a00: reg[2]=V; break; + case 0x4e00: reg[3]=V; IRQCount=Count; IRQPause=Pause; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void UNL3DBlockPower(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4800,0x4E00,UNL3DBlockWrite); +} + +static void UNL3DBlockReset(void) +{ + Count+=0x10; + FCEU_printf("Count=%04x\n",Count); +} + +static void UNL3DBlockIRQHook(int a) +{ + if(IRQa) + { + if(IRQCount>0) + { + IRQCount-=a; + } + else + { + if(IRQPause>0) + { + IRQPause-=a; + X6502_IRQBegin(FCEU_IQEXT); + } + else + { + IRQCount=Count; + IRQPause=Pause; + X6502_IRQEnd(FCEU_IQEXT); + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNL3DBlock_Init(CartInfo *info) +{ + info->Power=UNL3DBlockPower; + info->Reset=UNL3DBlockReset; + MapIRQHook=UNL3DBlockIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/411120-c.cpp b/src/boards/411120-c.cpp new file mode 100644 index 00000000..ab78499d --- /dev/null +++ b/src/boards/411120-c.cpp @@ -0,0 +1,70 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// actually cart ID is 811120-C, sorry ;) K-3094 - another ID + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0; + +static void BMC411120CCW(uint32 A, uint8 V) +{ + setchr1(A,V|((EXPREGS[0]&3)<<7)); +} + +static void BMC411120CPW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&(8|reset_flag)) + setprg32(0x8000,((EXPREGS[0]>>4)&3)|(0x0C)); + else + setprg8(A,(V&0x0F)|((EXPREGS[0]&3)<<4)); +} + +static DECLFW(BMC411120CLoWrite) +{ + EXPREGS[0] = A; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC411120CReset(void) +{ + EXPREGS[0]=0; + reset_flag ^=4; + MMC3RegReset(); +} + +static void BMC411120CPower(void) +{ + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,BMC411120CLoWrite); +} + +void BMC411120C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMC411120CPW; + cwrap=BMC411120CCW; + info->Power=BMC411120CPower; + info->Reset=BMC411120CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/68.cpp b/src/boards/68.cpp new file mode 100644 index 00000000..a2ddf72d --- /dev/null +++ b/src/boards/68.cpp @@ -0,0 +1,178 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 chr_reg[4]; +static uint8 kogame, prg_reg, nt1, nt2, mirr; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE, count; + +static SFORMAT StateRegs[]= +{ + {&nt1, 1, "NT1"}, + {&nt2, 1, "NT2"}, + {&mirr, 1, "MIRR"}, + {&prg_reg, 1, "PRG"}, + {&kogame, 1, "KOGAME"}, + {&count, 4, "COUNT"}, + {chr_reg, 4, "CHR"}, + {0} +}; + +static void M68NTfix(void) +{ + if((!UNIFchrrama)&&(mirr&0x10)) + { + PPUNTARAM = 0; + switch(mirr&3) + { + case 0: vnapage[0]=vnapage[2]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + vnapage[1]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + case 1: vnapage[0]=vnapage[1]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + case 2: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt1|128)&CHRmask1[0])<<10); + break; + case 3: vnapage[0]=vnapage[1]=vnapage[2]=vnapage[3]=CHRptr[0]+(((nt2|128)&CHRmask1[0])<<10); + break; + } + } + else + switch(mirr&3) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static void Sync(void) +{ + setchr2(0x0000,chr_reg[0]); + setchr2(0x0800,chr_reg[1]); + setchr2(0x1000,chr_reg[2]); + setchr2(0x1800,chr_reg[3]); + setprg8r(0x10,0x6000,0); + setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg); + setprg16(0xC000,~0); +} + +static DECLFR(M68Read) +{ + if(!(kogame&8)) + { + count++; + if(count==1784) + setprg16r(0,0x8000,prg_reg); + } + return CartBR(A); +} + +static DECLFW(M68WriteLo) +{ + if(!V) + { + count = 0; + setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg); + } +} + +static DECLFW(M68WriteCHR) +{ + chr_reg[(A>>12)&3]=V; + Sync(); +} + +static DECLFW(M68WriteNT1) +{ + nt1 = V; + M68NTfix(); +} + +static DECLFW(M68WriteNT2) +{ + nt2 = V; + M68NTfix(); +} + +static DECLFW(M68WriteMIR) +{ + mirr = V; + M68NTfix(); +} + +static DECLFW(M68WriteROM) +{ + prg_reg = V&7; + kogame = ((V>>3)&1)^1; + Sync(); +} + +static void M68Power(void) +{ + prg_reg = 0; + kogame = 0; + Sync(); + M68NTfix(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xBFFF,M68Read); + SetReadHandler(0xC000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,M68WriteCHR); + SetWriteHandler(0xC000,0xCFFF,M68WriteNT1); + SetWriteHandler(0xD000,0xDFFF,M68WriteNT2); + SetWriteHandler(0xE000,0xEFFF,M68WriteMIR); + SetWriteHandler(0xF000,0xFFFF,M68WriteROM); + SetWriteHandler(0x6000,0x6000,M68WriteLo); + SetWriteHandler(0x6001,0x7FFF,CartBW); +} + +static void M68Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); + M68NTfix(); +} + +void Mapper68_Init(CartInfo *info) +{ + info->Power=M68Power; + info->Close=M68Close; + GameStateRestore=StateRestore; + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/830118C.cpp b/src/boards/830118C.cpp new file mode 100644 index 00000000..aa82eb48 --- /dev/null +++ b/src/boards/830118C.cpp @@ -0,0 +1,82 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// M-022 MMC3 based 830118C T-106 4M + 4M + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0; + +static void BMC830118CCW(uint32 A, uint8 V) +{ + setchr1(A,(V&0x7F)|((EXPREGS[0]&0x0c)<<5)); +} + +static void BMC830118CPW(uint32 A, uint8 V) +{ + if((EXPREGS[0]&0x0C)==0x0C) + { + if(A==0x8000) + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + setprg8(0xC000,(V&0x0F)|0x32); + } + else if(A==0xA000) + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + setprg8(0xE000,(V&0x0F)|0x32); + } + } + else + { + setprg8(A,(V&0x0F)|((EXPREGS[0]&0x0c)<<2)); + } +} + +static DECLFW(BMC830118CLoWrite) +{ + EXPREGS[0] = V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMC830118CReset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void BMC830118CPower(void) +{ + EXPREGS[0] = 0; + GenMMC3Power(); + SetWriteHandler(0x6800,0x68FF,BMC830118CLoWrite); +} + +void BMC830118C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMC830118CPW; + cwrap=BMC830118CCW; + info->Power=BMC830118CPower; + info->Reset=BMC830118CReset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/__dummy_mapper.cpp b/src/boards/__dummy_mapper.cpp index 0ceb54c9..08769b96 100644 --- a/src/boards/__dummy_mapper.cpp +++ b/src/boards/__dummy_mapper.cpp @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2006 CaH4e3 + * Copyright (C) 2006-2007 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -91,6 +91,11 @@ void MapperNNN_Init(CartInfo *info) WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } */ AddExState(&StateRegs, ~0, 0, 0); } diff --git a/src/boards/a9746.cpp b/src/boards/a9746.cpp new file mode 100644 index 00000000..8ee65957 --- /dev/null +++ b/src/boards/a9746.cpp @@ -0,0 +1,186 @@ + +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* +#include "mapinc.h" + +static uint8 chr_cmd, prg_cmd, mirror; +static uint8 chr_reg[6], prg_reg[4]; + +static SFORMAT StateRegs[]= +{ + {&chr_cmd, 1, "CHRCMD"}, + {&prg_cmd, 1, "PRGCMD"}, + {&mirror, 1, "MIRR"}, + {chr_reg, 6, "CREGS"}, + {prg_reg, 4, "PREGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x8000, prg_reg[0]); + setprg8(0xA000, prg_reg[1]); + setprg8(0xC000, prg_reg[2]); + setprg8(0xE000, prg_reg[3]); + + setchr2(0x0000, chr_reg[0]); + setchr2(0x0800, chr_reg[1]); + setchr1(0x1000, chr_reg[2]); + setchr1(0x1400, chr_reg[3]); + setchr1(0x1800, chr_reg[4]); + setchr1(0x1c00, chr_reg[5]); + + setmirror(mirror); +} + +static DECLFW(UNLA9746Write) +{ + uint8 bits_rev; +// FCEU_printf("write raw %04x:%02x\n",A,V); + switch (A&0xE003) + { +// case 0xA000: mirror = V; break; + case 0x8000: chr_cmd = V; prg_cmd = 0; break; + case 0x8002: prg_cmd = V; chr_cmd = 0; break; + case 0x8001: bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1); +// if(prg_cmd>0x23) +// prg_reg[(0x26-prg_cmd)&3] = bits_rev; + switch(chr_cmd) + { + case 0x08: chr_reg[0] = (V << 3); break; + case 0x09: chr_reg[0] = chr_reg[0]|(V >> 2); break; + case 0x0e: chr_reg[1] = (V << 3); break; + case 0x0d: chr_reg[1] = chr_reg[1]|(V >> 2); break; + case 0x12: chr_reg[2] = (V << 4); break; + case 0x11: chr_reg[2] = chr_reg[2]|(V >> 1); FCEU_printf("Sync CHR 0x1000:%02x\n",chr_reg[2]); break; + case 0x16: chr_reg[3] = (V << 4); break; + case 0x15: chr_reg[3] = chr_reg[3]|(V >> 1); break; + case 0x1a: chr_reg[4] = (V << 4); break; + case 0x19: chr_reg[4] = chr_reg[4]|(V >> 1); break; + case 0x1e: chr_reg[5] = (V << 4); break; + case 0x1d: chr_reg[5] = chr_reg[5]|(V >> 1); break; + } + Sync(); + break; + } +} + +static void UNLA9746Power(void) +{ + prg_reg[2]=~1; + prg_reg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xbfff,UNLA9746Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLA9746_Init(CartInfo *info) +{ + info->Power=UNLA9746Power; + AddExState(&StateRegs, ~0, 0, 0); +} +/**/ + +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +static DECLFW(UNLA9746Write) +{ +// FCEU_printf("write raw %04x:%02x\n",A,V); + switch (A&0xE003) + { + case 0x8000: EXPREGS[1]=V; EXPREGS[0]=0; break; + case 0x8002: EXPREGS[0]=V; EXPREGS[1]=0; break; + case 0x8001: { + uint8 bits_rev = ((V&0x20)>>5)|((V&0x10)>>3)|((V&0x08)>>1)|((V&0x04)<<1); + switch(EXPREGS[0]) + { + case 0x26: setprg8(0x8000, bits_rev); break; + case 0x25: setprg8(0xA000, bits_rev); break; + case 0x24: setprg8(0xC000, bits_rev); break; + case 0x23: setprg8(0xE000, bits_rev); break; + } + switch(EXPREGS[1]) + { + case 0x0a: + case 0x08: EXPREGS[2] = (V << 4); break; + case 0x09: setchr1(0x0000, EXPREGS[2]|(V >> 1)); break; + case 0x0b: setchr1(0x0400, EXPREGS[2]|(V >> 1)|1); break; + case 0x0c: + case 0x0e: EXPREGS[2] = (V << 4); break; + case 0x0d: setchr1(0x0800, EXPREGS[2]|(V >> 1)); break; + case 0x0f: setchr1(0x0c00, EXPREGS[2]|(V >> 1)|1); break; + case 0x10: + case 0x12: EXPREGS[2] = (V << 4); break; + case 0x11: setchr1(0x1000, EXPREGS[2]|(V >> 1)); break; + case 0x14: + case 0x16: EXPREGS[2] = (V << 4); break; + case 0x15: setchr1(0x1400, EXPREGS[2]|(V >> 1)); break; + case 0x18: + case 0x1a: EXPREGS[2] = (V << 4); break; + case 0x19: setchr1(0x1800, EXPREGS[2]|(V >> 1)); break; + case 0x1c: + case 0x1e: EXPREGS[2] = (V << 4); break; + case 0x1d: setchr1(0x1c00, EXPREGS[2]|(V >> 1)); break; + } + } + break; + } +} + +static void UNLA9746Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xbfff,UNLA9746Write); +} + +void UNLA9746_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=UNLA9746Power; + AddExState(EXPREGS, 6, 0, "EXPR"); +} +/**/ diff --git a/src/boards/addrlatch.cpp b/src/boards/addrlatch.cpp index d47b93f4..c5fb9308 100644 --- a/src/boards/addrlatch.cpp +++ b/src/boards/addrlatch.cpp @@ -27,11 +27,17 @@ static readfunc defread; static DECLFW(LatchWrite) { -// FCEU_printf("%04x:%02x\n",A,V); + FCEU_printf("%04x:%02x\n",A,V); latche=A; WSync(); } +static void LatchReset(void) +{ + latche=latcheinit; + WSync(); +} + static void LatchPower(void) { latche=latcheinit; @@ -56,6 +62,7 @@ static void Latch_Init(CartInfo *info, void (*proc)(void), readfunc func, uint16 else defread=CartBR; info->Power=LatchPower; + info->Reset=LatchReset; GameStateRestore=StateRestore; AddExState(&latche, 2, 0, "LATC"); } @@ -67,7 +74,6 @@ static void UNLCC21Sync(void) setprg32(0x8000,0); setchr8(latche&1); setmirror(MI_0+((latche&2)>>1)); - } void UNLCC21_Init(CartInfo *info) @@ -149,3 +155,18 @@ void Mapper200_Init(CartInfo *info) Latch_Init(info, M200Sync, 0, 0xff, 0x8000, 0xFFFF); } +//------------------ 190in1 --------------------------- + +static void BMC190in1Sync(void) +{ + setprg16(0x8000,(latche>>2)&0x07); + setprg16(0xC000,(latche>>2)&0x07); + setchr8((latche>>2)&0x07); + setmirror((latche&1)^1); +} + +void BMC190in1_Init(CartInfo *info) +{ + Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF); +} + diff --git a/src/boards/ax5705.cpp b/src/boards/ax5705.cpp new file mode 100644 index 00000000..4a271e81 --- /dev/null +++ b/src/boards/ax5705.cpp @@ -0,0 +1,122 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Super Bros. Pocker Mali (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 IRQCount;//, IRQPre; +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; +static uint8 mirr; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {prg_reg, 2, "PRG"}, + {chr_reg, 8, "CHR"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +/* +static void UNLAX5705IRQ(void) +{ + if(IRQa) + { + IRQCount++; + if(IRQCount>=238) + { + X6502_IRQBegin(FCEU_IQEXT); +// IRQa=0; + } + } +}*/ + +static void Sync(void) +{ + int i; + setprg8(0x8000,prg_reg[0]); + setprg8(0xA000,prg_reg[1]); + setprg8(0xC000,~1); + setprg8(0xE000,~0); + for(i=0; i<8; i++) + setchr1(i<<10,chr_reg[i]); + setmirror(mirr^1); +} + +static DECLFW(UNLAX5705Write) +{ +// if((A>=0xA008)&&(A<=0xE003)) +// { +// int ind=(((A>>11)-6)|(A&1))&7; +// int sar=((A&2)<<1); +// chr_reg[ind]=(chr_reg[ind]&(0xF0>>sar))|((V&0x0F)<>2)|(V&5); break; // EPROM dump have mixed PRG and CHR banks, data lines to mapper seems to be mixed + case 0x8008: mirr=V&1; break; + case 0xA000: prg_reg[1]=((V&2)<<2)|((V&8)>>2)|(V&5); break; + case 0xA008: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break; + case 0xA009: chr_reg[0]=(chr_reg[0]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xA00A: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break; + case 0xA00B: chr_reg[1]=(chr_reg[1]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break; + case 0xC001: chr_reg[2]=(chr_reg[2]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC002: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break; + case 0xC003: chr_reg[3]=(chr_reg[3]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC008: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break; + case 0xC009: chr_reg[4]=(chr_reg[4]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xC00A: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break; + case 0xC00B: chr_reg[5]=(chr_reg[5]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break; + case 0xE001: chr_reg[6]=(chr_reg[6]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; + case 0xE002: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break; + case 0xE003: chr_reg[7]=(chr_reg[7]&0x0F)|((((V&4)>>1)|((V&2)<<1)|(V&0x09))<<4); break; +// case 0x800A: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; +// case 0xE00B: X6502_IRQEnd(FCEU_IQEXT); IRQa=IRQCount=V; /*if(scanline<240) IRQCount-=8; else IRQCount+=4;*/ break; + } + Sync(); +} + +static void UNLAX5705Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLAX5705Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLAX5705_Init(CartInfo *info) +{ + info->Power=UNLAX5705Power; +// GameHBIRQHook=UNLAX5705IRQ; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bandai.cpp b/src/boards/bandai.cpp new file mode 100644 index 00000000..8604b3cc --- /dev/null +++ b/src/boards/bandai.cpp @@ -0,0 +1,164 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Bandai mappers + * + */ + +#include "mapinc.h" + +static uint8 reg[16], is153; +static uint8 IRQa; +static uint16 IRQCount, IRQLatch; + +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 16, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {&IRQLatch, 2, "IRQL"}, + {0} +}; + +static void BandaiIRQHook(int a) +{ + if(IRQa) + { + IRQCount -= a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa = 0; + IRQCount = 0xFFFF; + } + } +} + +static void BandaiSync(void) +{ + if(is153) + { + int base=(reg[0]&1)<<4; + if(!UNIFchrrama) // SD Gundam Gaiden - Knight Gundam Monogatari 2 - Hikari no Kishi (J) uses WRAM but have CHRROM too + { + int i; + for(i=0; i<8; i++) setchr1(i<<10,reg[i]); + } + else + setchr8(0); + setprg16(0x8000,(reg[8]&0x0F)|base); + setprg16(0xC000,0x0F|base); + } + else + { + int i; + for(i=0; i<8; i++) setchr1(i<<10,reg[i]); + setprg16(0x8000,reg[8]); + setprg16(0xC000,~0); + } + switch(reg[9]) + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(BandaiWrite) +{ + A&=0x0F; + if(A<0x0A) + { + reg[A&0x0F]=V; + BandaiSync(); + } + else + switch(A) + { + case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break; + case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break; + case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break; + case 0x0D: break;// Serial EEPROM control port + } +} + +static void BandaiPower(void) +{ + BandaiSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,BandaiWrite); +} + +static void M153Power(void) +{ + BandaiSync(); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BandaiWrite); +} + + +static void M153Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + BandaiSync(); +} + +void Mapper16_Init(CartInfo *info) +{ + is153=0; + info->Power=BandaiPower; + MapIRQHook=BandaiIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper153_Init(CartInfo *info) +{ + is153=1; + info->Power=M153Power; + info->Close=M153Close; + MapIRQHook=BandaiIRQHook; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/bonza.cpp b/src/boards/bonza.cpp index 5e572f14..812683f4 100644 --- a/src/boards/bonza.cpp +++ b/src/boards/bonza.cpp @@ -24,10 +24,12 @@ static uint8 prg_reg; static uint8 chr_reg; static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt; -static uint16 sim0data; +static uint8 sim0bitw, sim0bytew, sim0parityw, sim0bcntw; + +static uint16 sim0data, sim0dataw, sim0iswrite; static uint8 sim0array[128] = { - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x14, 0x55, 0x45, 0xd3, 0x18, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, @@ -36,6 +38,7 @@ static uint8 sim0array[128] = 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA, }; +static uint8 sim0cmd[16]; static SFORMAT StateRegs[]= { @@ -65,25 +68,64 @@ static DECLFW(M216WriteHi) static DECLFW(M216Write5000) { -// FCEU_printf("WRITE: %04x:%04x\n",A,V); sim0reg=V; if(!sim0reg) { sim0bit=sim0byte=sim0parity=0; + sim0bitw=sim0bytew=sim0parityw=0; sim0data=sim0array[0]; - sim0bcnt=0x80; + sim0bcnt=0x7F; } - else if(sim0reg&0x20) + if(sim0reg&0x20) { - sim0bcnt=0x20; + sim0bcnt=0x1E; + sim0bcntw=4; } + if(sim0reg&0x08) + { + uint8 sim0in=0; + sim0iswrite=0x2C; + if(sim0bitw<8) + { + sim0in=(V&0x10)>>4; + sim0parityw+=sim0in; + sim0dataw|=sim0in<<7; + sim0dataw>>=1; + sim0bitw++; + } + else if(sim0bitw==8) + { + sim0bitw++; + } + else if(sim0bitw==9) + { + sim0parityw=0; + sim0bitw=0; + if(sim0bytew==sim0bcntw) + { + sim0reg=0x60; + sim0iswrite=0; + } + else + { + sim0cmd[sim0bytew++]=sim0dataw; + sim0dataw=0; + } + } + } + + FCEU_printf("WRITE: %04x:%04x (PC=%02x cnt=%02x)\n",A,V,X.PC,sim0bcnt); } static DECLFR(M216Read5000) { if(sim0reg&0x60) { + if(sim0iswrite) + sim0iswrite--; + else sim0reg=(sim0reg^(sim0reg<<1))&0x40; + FCEU_printf("READ: %04x PC=%04x reg=%02x\n",A,X.PC,sim0reg); return sim0reg; } else @@ -91,30 +133,33 @@ static DECLFR(M216Read5000) uint8 sim0out=0; if(sim0bit<8) { -// sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1; - sim0out=(sim0data&1)<<6; - sim0data>>=1; + sim0out=(sim0data&0x80)>>7; + sim0parity+=sim0out; + sim0out<<=6; + sim0data<<=1; sim0bit++; - sim0parity+=sim0data; } else if(sim0bit==8) { sim0bit++; - sim0out=sim0parity&1; + sim0out=(sim0parity&1)<<6; } else if(sim0bit==9) { + sim0parity=0; + sim0bit=0; if(sim0byte==sim0bcnt) + { + sim0reg=0x40; sim0out=0x60; + } else { - sim0bit=0; - sim0byte++; - sim0data=sim0array[sim0byte]; sim0out=0; + sim0data=sim0array[sim0byte++]; } } -// FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte); + FCEU_printf("READ: %04x PC=%04x out=%02x byte=%02x cnt=%02x bit=%02x\n",A,X.PC,sim0out,sim0byte,sim0bcnt,sim0bit); return sim0out; } } diff --git a/src/boards/bs-5.cpp b/src/boards/bs-5.cpp new file mode 100644 index 00000000..fbe3a098 --- /dev/null +++ b/src/boards/bs-5.cpp @@ -0,0 +1,91 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg_prg[4]; +static uint8 reg_chr[4]; +static uint8 dip_switch; + +static SFORMAT StateRegs[]= +{ + {reg_prg, 4, "PREGS"}, + {reg_chr, 4, "CREGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x8000,reg_prg[0]); + setprg8(0xa000,reg_prg[1]); + setprg8(0xc000,reg_prg[2]); + setprg8(0xe000,reg_prg[3]); + setchr2(0x0000,reg_chr[0]); + setchr2(0x0800,reg_chr[1]); + setchr2(0x1000,reg_chr[2]); + setchr2(0x1800,reg_chr[3]); + setmirror(MI_V); +} + +static DECLFW(MBS5Write) +{ + int bank_sel = (A&0xC00)>>10; + switch (A&0xF000) + { + case 0x8000: + reg_chr[bank_sel]=A&0x1F; + break; + case 0xA000: + if(A&(1<<(dip_switch+4))) + reg_prg[bank_sel]=A&0x0F; + break; + } + Sync(); +} + +static void MBS5Reset(void) +{ + dip_switch++; + dip_switch&=3; + reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; + Sync(); +} + +static void MBS5Power(void) +{ + dip_switch=0; + reg_prg[0]=reg_prg[1]=reg_prg[2]=reg_prg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MBS5Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCBS5_Init(CartInfo *info) +{ + info->Power=MBS5Power; + info->Reset=MBS5Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/copyfami_mmc3.cpp b/src/boards/copyfami_mmc3.cpp new file mode 100644 index 00000000..0f23c4dc --- /dev/null +++ b/src/boards/copyfami_mmc3.cpp @@ -0,0 +1,147 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /* +0000 - 1FFF - RAM +2000 - 23FF - PPU +2400 - 27FF - Write: "PAG" / Read: -- +2800 - 2BFF - Write: "BNK" / Read: "STS" +2C00 - 2FFF - Write: "UWR" / Read: "URD" +3000 - 3FFF - Small Flash Page (â ðåãèñòðå BNK) +4000 - 7FFF - Free +8000 - FFFF - Cart/Big Flash Page (ñìîòðè ðåãèñòð PAG) +Áèòû: +Ðåãèñòð [PAG], ïî ñáðîñó äîëæåí áûòü = $00. +D3-D0 - Big Page High Address (D3,D2,D1,D0,A14,A13,A12,A11,A10,A9,A8,A7,A6,A5,A4,A3,A2,A1,A0) + D4 - VMD áèò. Åñëè =0, òî ê PPU ïîäêëþ÷åíî âíóòðåíåå ÎÇó íà 8Êá, åñëè =1 - òî êàðòðèäæ. + D5 - STR áèò. Åñëè =0, òî âìåñòî êàðòà ïî àäðåñàì 8000-FFFF âíóòðåííÿÿ ôëýø, =1 - êàðò. +Ðåãèñòð [BNK], íå ïðåäóñòàíàâëèâàåòñÿ +D6-D0 - Small Page High Address (D6,D5,D4,D3,D2,D1,D0,A11,A10,A9,A8,A7,A6,A5,A4,A3,A2,A1,A0) + D7 - S/W áèò. Óïðàâëÿåò USB ìîñòîì, â ýìóëå ðåàëèçîâûâàòü íå íàäî. +Ðåãèñòðû [UWR]/[URD], íå ïðåäóñòàíàâëèâàþòñÿ, â ýìóëå ðåàëèçîâûâàòü íå íàäî. +[UWR] - Ðåãèñòð çàïèñè äàííûõ â USB ìîñò. +[URD] - Ðåãèñòð ÷òåíèÿ èç USB ìîñòà. + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reg[3]; + +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 3, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg4r(1,0x3000,reg[1]&0x7F); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void MCopyFamiMMC3PW(uint32 A, uint8 V) +{ + if(reg[0]&0x20) + setprg8r(0,A,V); + else + setprg32r(1,0x8000,reg[0]&0x0F); +} + +static void MCopyFamiMMC3CW(uint32 A, uint8 V) +{ + if(reg[0]&0x20) + setchr1r(0,A,V); + else + setchr8r(0x10,0); +} + +static DECLFW(MCopyFamiMMC3WritePAG) +{ + reg[0]=V; + Sync(); +} + +static DECLFW(MCopyFamiMMC3WriteBNK) +{ + reg[1]=V; + Sync(); +} + +static DECLFW(MCopyFamiMMC3WriteUSB) +{ + reg[2]=V; +} + +static void MCopyFamiMMC3Power(void) +{ + reg[0] = 0; + GenMMC3Power(); + Sync(); + SetReadHandler(0x3000,0x3FFF,CartBR); + SetWriteHandler(0x3000,0x3FFF,CartBW); + + SetWriteHandler(0x2400,0x27FF,MCopyFamiMMC3WritePAG); + SetWriteHandler(0x2800,0x2BFF,MCopyFamiMMC3WriteBNK); + SetWriteHandler(0x2C00,0x2FFF,MCopyFamiMMC3WriteUSB); +} + +static void MCopyFamiMMC3Reset(void) +{ + reg[0] = 0; + MMC3RegReset(); + Sync(); +} + +static void MCopyFamiMMC3Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperCopyFamiMMC3_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 0, 0); + + cwrap=MCopyFamiMMC3CW; + pwrap=MCopyFamiMMC3PW; + + info->Reset=MCopyFamiMMC3Reset; + info->Power=MCopyFamiMMC3Power; + info->Close=MCopyFamiMMC3Close; + GameStateRestore=StateRestore; + + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartPRGMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "SRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/datalatch.cpp b/src/boards/datalatch.cpp index 39206c3a..f0824d28 100644 --- a/src/boards/datalatch.cpp +++ b/src/boards/datalatch.cpp @@ -189,7 +189,8 @@ static void M87Sync(void) { setprg16(0x8000,0); setprg16(0xC000,1); - setchr8(latche>>1); + setchr8(((latche>>1)&1)|((latche<<1)&2)); +// setchr8(latche); } void Mapper87_Init(CartInfo *info) @@ -197,6 +198,20 @@ void Mapper87_Init(CartInfo *info) Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF); } +//------------------ Map 101 --------------------------- + +static void M101Sync(void) +{ + setprg16(0x8000,0); + setprg16(0xC000,1); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) +{ + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF); +} + //------------------ Map 11 --------------------------- static void M11Sync(void) @@ -215,6 +230,31 @@ void Mapper144_Init(CartInfo *info) Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF); } +//------------------ Map 38 --------------------------- + +static void M38Sync(void) +{ + setprg32(0x8000,latche&3); + setchr8(latche>>2); +} + +void Mapper38_Init(CartInfo *info) +{ + Latch_Init(info, M38Sync, 0, 0x7000, 0x7FFF); +} + +//------------------ Map 36 --------------------------- + +static void M36Sync(void) +{ + setprg32(0x8000,latche>>4); + setchr8((latche)&0xF); +} + +void Mapper36_Init(CartInfo *info) +{ + Latch_Init(info, M36Sync, 0, 0x8400, 0xfffe); +} //------------------ UNROM --------------------------- static void UNROMSync(void) diff --git a/src/boards/edu2000.cpp b/src/boards/edu2000.cpp index edccb5e2..b59ac0c5 100644 --- a/src/boards/edu2000.cpp +++ b/src/boards/edu2000.cpp @@ -74,8 +74,11 @@ void UNLEDU2000_Init(CartInfo *info) GameStateRestore=UNLEDU2000Restore; WRAM=(uint8*)FCEU_gmalloc(32768); SetupCartPRGMapping(0x10,WRAM,32768,1); + if(info->battery) + { info->SaveGame[0]=WRAM; info->SaveGameLen[0]=32768; + } AddExState(WRAM, 32768, 0, "WRAM"); AddExState(StateRegs, ~0, 0, 0); } diff --git a/src/boards/fk23c.cpp b/src/boards/fk23c.cpp index daca69a6..62eda01d 100644 --- a/src/boards/fk23c.cpp +++ b/src/boards/fk23c.cpp @@ -22,7 +22,7 @@ #include "mmc3.h" static uint8 unromchr; -static uint8 dipswitch; +static uint32 dipswitch; static void BMCFK23CCW(uint32 A, uint8 V) { @@ -42,11 +42,16 @@ static void BMCFK23CCW(uint32 A, uint8 V) static void BMCFK23CPW(uint32 A, uint8 V) { - if(EXPREGS[0]&4) + if((EXPREGS[0]&7)==4) setprg32(0x8000,EXPREGS[1]>>1); + else if ((EXPREGS[0]&7)==3) + { + setprg16(0x8000,EXPREGS[1]); + setprg16(0xC000,EXPREGS[1]); + } else { - if(EXPREGS[0]&2) + if(EXPREGS[0]&3) setprg8(A,(V&(0x3F>>(EXPREGS[0]&3)))|(EXPREGS[1]<<1)); else setprg8(A,V); @@ -62,7 +67,7 @@ static DECLFW(BMCFK23CHiWrite) { if(EXPREGS[0]&0x40) { - if(EXPREGS[0]&0x20) + if(EXPREGS[0]&0x30) unromchr=0; else { @@ -99,7 +104,7 @@ static DECLFW(BMCFK23CWrite) static void BMCFK23CReset(void) { dipswitch++; - dipswitch&=3; + dipswitch&=7; EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; MMC3RegReset(); @@ -110,7 +115,7 @@ static void BMCFK23CPower(void) EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; GenMMC3Power(); - SetWriteHandler(0x5001,0x5fff,BMCFK23CWrite); + SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite); SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite); } diff --git a/src/boards/ghostbusters63in1.cpp b/src/boards/ghostbusters63in1.cpp new file mode 100644 index 00000000..6b541a11 --- /dev/null +++ b/src/boards/ghostbusters63in1.cpp @@ -0,0 +1,106 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * 63in1 ghostbusters + */ + +#include "mapinc.h" + +static uint8 reg[2], bank; +static uint8 banks[4] = {0, 0, 1, 2}; +static uint8 *CHRROM=NULL; +static uint32 CHRROMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REGS"}, + {&bank, 1, "BANK"}, + {0} +}; + +static void Sync(void) +{ + if(reg[0]&0x20) + { + setprg16r(banks[bank],0x8000,reg[0]&0x1F); + setprg16r(banks[bank],0xC000,reg[0]&0x1F); + } + else + setprg32r(banks[bank],0x8000,(reg[0]>>1)&0x0F); + if(reg[1]&2) + setchr8r(0x10,0); + else + setchr8(0); + setmirror((reg[0]&0x40)>>6); +} + +static DECLFW(BMCGhostbusters63in1Write) +{ + reg[A&1]=V; + bank=((reg[0]&0x80)>>7)|((reg[1]&1)<<1); +// FCEU_printf("reg[0]=%02x, reg[1]=%02x, bank=%02x\n",reg[0],reg[1],bank); + Sync(); +} + +static DECLFR(BMCGhostbusters63in1Read) +{ + if(bank==1) + return X.DB; + else + return CartBR(A); +} + +static void BMCGhostbusters63in1Power(void) +{ + reg[0]=reg[1]=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,BMCGhostbusters63in1Read); + SetWriteHandler(0x8000,0xFFFF,BMCGhostbusters63in1Write); +} + +static void BMCGhostbusters63in1Reset(void) +{ + reg[0]=reg[1]=0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void BMCGhostbusters63in1Close(void) +{ + if(CHRROM) + FCEU_gfree(CHRROM); + CHRROM=NULL; +} + +void BMCGhostbusters63in1_Init(CartInfo *info) +{ + info->Reset=BMCGhostbusters63in1Reset; + info->Power=BMCGhostbusters63in1Power; + info->Close=BMCGhostbusters63in1Close; + + CHRROMSIZE=8192; // dummy CHRROM, VRAM disable + CHRROM=(uint8*)FCEU_gmalloc(CHRROMSIZE); + SetupCartPRGMapping(0x10,CHRROM,CHRROMSIZE,0); + AddExState(CHRROM, CHRROMSIZE, 0, "CHRROM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/gs-2004.cpp b/src/boards/gs-2004.cpp new file mode 100644 index 00000000..17a9ef89 --- /dev/null +++ b/src/boards/gs-2004.cpp @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(1,0x6000,0); + setprg32(0x8000,reg); + setchr8(0); +} + +static DECLFW(BMCGS2004Write) +{ + reg=V; + Sync(); +} + +static void BMCGS2004Power(void) +{ + reg=~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMCGS2004Write); +} + +static void BMCGS2004Reset(void) +{ + reg=~0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCGS2004_Init(CartInfo *info) +{ + info->Reset=BMCGS2004Reset; + info->Power=BMCGS2004Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/gs-2013.cpp b/src/boards/gs-2013.cpp new file mode 100644 index 00000000..027d0ac8 --- /dev/null +++ b/src/boards/gs-2013.cpp @@ -0,0 +1,69 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0,0x6000,~0); + setprg32r((reg&8)>>3,0x8000,reg); + setchr8(0); +} + +static DECLFW(BMCGS2013Write) +{ + reg=V; + Sync(); +} + +static void BMCGS2013Power(void) +{ + reg=~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMCGS2013Write); +} + +static void BMCGS2013Reset(void) +{ + reg=~0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMCGS2013_Init(CartInfo *info) +{ + info->Reset=BMCGS2013Reset; + info->Power=BMCGS2013Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/konami-qtai.cpp b/src/boards/konami-qtai.cpp index ff552e10..0e6f9bcf 100644 --- a/src/boards/konami-qtai.cpp +++ b/src/boards/konami-qtai.cpp @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2005 CaH4e3 + * Copyright (C) 2005-2008 CaH4e3 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,80 +22,178 @@ #include "mapinc.h" +static uint8 QTAINTRAM[2048]; +static writefunc old2007wrap; + +static uint16 CHRSIZE = 8192; +static uint16 WRAMSIZE = 8192 + 4096; static uint8 *CHRRAM=NULL; -static uint8 SWRAM[4096]; +static uint8 *WRAM = NULL; + +static uint8 IRQa, K4IRQ; +static uint32 IRQLatch, IRQCount; static uint8 regs[16]; -static uint8 WRAM[4096]; +//static uint8 test[8]; static SFORMAT StateRegs[]= { - {®s, 16, "REGS"}, - {WRAM, 4096, "WRAM"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {&K4IRQ, 1, "K4IRQ"}, + {regs, 16, "REGS"}, {0} }; +static void chrSync(void) +{ + setchr4r(0x10,0x0000,regs[5]&1); + setchr4r(0x10,0x1000,0); +} + static void Sync(void) { - if(regs[5]&0x40) - { - setchr4r(0,0x1000,regs[5]&0x3F); - } + chrSync(); +// if(regs[0xA]&0x10) +// { +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,0); + setchr1r(0x10,0x1400,1); + setchr1r(0x10,0x1800,2); + setchr1r(0x10,0x1c00,3);*/ +/* setchr1r(0x10,0x0000,(((regs[5]&1))<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1))<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1))<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1))<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1)^1)<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1)^1)<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1)^1)<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1)^1)<<2)+7); +*/ +// } +// else +// { +/* + setchr1r(0x10,0x0000,(((regs[5]&1)^1)<<2)+0); + setchr1r(0x10,0x0400,(((regs[5]&1)^1)<<2)+1); + setchr1r(0x10,0x0800,(((regs[5]&1)^1)<<2)+2); + setchr1r(0x10,0x0c00,(((regs[5]&1)^1)<<2)+3); + setchr1r(0x10,0x1000,(((regs[5]&1))<<2)+4); + setchr1r(0x10,0x1400,(((regs[5]&1))<<2)+5); + setchr1r(0x10,0x1800,(((regs[5]&1))<<2)+6); + setchr1r(0x10,0x1c00,(((regs[5]&1))<<2)+7); +// } +//*/ +/* setchr1r(1,0x0000,test[0]); + setchr1r(1,0x0400,test[1]); + setchr1r(1,0x0800,test[2]); + setchr1r(1,0x0c00,test[3]); + setchr1r(1,0x1000,test[4]); + setchr1r(1,0x1400,test[5]); + setchr1r(1,0x1800,test[6]); + setchr1r(1,0x1c00,test[7]); +*/ + setprg4r(0x10,0x6000,regs[0]&1); + if(regs[2]>=0x40) + setprg8r(1,0x8000,(regs[2]-0x40)); else - { - setchr4r(0x10,0x0000,regs[5]); - setchr4r(0x10,0x1000,regs[5]^1); - } - setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F)); - setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F)); - setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F)); + setprg8r(0,0x8000,(regs[2]&0x3F)); + if(regs[3]>=0x40) + setprg8r(1,0xA000,(regs[3]-0x40)); + else + setprg8r(0,0xA000,(regs[3]&0x3F)); + if(regs[4]>=0x40) + setprg8r(1,0xC000,(regs[4]-0x40)); + else + setprg8r(0,0xC000,(regs[4]&0x3F)); + setprg8r(1,0xE000,~0); - setmirror((regs[0xA]&3)); + setmirror(MI_V); } +/*static DECLFW(TestWrite) +{ + test[A&7] = V; + Sync(); +}*/ + static DECLFW(M190Write) { // FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); regs[(A&0x0F00)>>8]=V; + switch(A) + { + case 0xd600:IRQLatch&=0xFF00;IRQLatch|=V;break; + case 0xd700:IRQLatch&=0x00FF;IRQLatch|=V<<8;break; + case 0xd900:IRQCount=IRQLatch;IRQa=V&2;K4IRQ=V&1;X6502_IRQEnd(FCEU_IQEXT);break; + case 0xd800:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; + } Sync(); } static DECLFR(M190Read) { // FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); - return regs[(A&0x0F00)>>8]; + return regs[(A&0x0F00)>>8]+regs[0x0B]; +} +static void VRC5IRQ(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount&0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } } -static DECLFR(AWRAM) +static void Mapper190_PPU(uint32 A) { - return(WRAM[A-0x7000]); -} -static DECLFW(BWRAM) -{ - WRAM[A-0x7000]=V; + if(A<0x2000) + setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1); +// else +// chrSync(); } -static DECLFR(ASWRAM) +static DECLFW(M1902007Wrap) { - return(SWRAM[A-0x6000]); -} -static DECLFW(BSWRAM) -{ - SWRAM[A-0x6000]=V; + if(A>=0x2000) + { + if(regs[0xA]&1) + QTAINTRAM[A&0x1FFF]=V; + else + old2007wrap(A,V); + } } + static void M190Power(void) { - setvram8(CHRRAM); - SetReadHandler(0x8000,0xFFFF,CartBR); +/* test[0]=0; + test[1]=1; + test[2]=2; + test[3]=3; + test[4]=4; + test[5]=5; + test[6]=6; + test[7]=7; +*/ + setprg4r(0x10,0x7000,2); + + old2007wrap=GetWriteHandler(0x2007); + SetWriteHandler(0x2007,0x2007,M1902007Wrap); + + SetReadHandler(0x6000,0xFFFF,CartBR); +// SetWriteHandler(0x5000,0x5007,TestWrite); + SetWriteHandler(0x6000,0x7FFF,CartBW); SetWriteHandler(0x8000,0xFFFF,M190Write); -// SetReadHandler(0xDA00,0xDA00,M190Read); -// SetReadHandler(0xDB00,0xDB00,M190Read); SetReadHandler(0xDC00,0xDC00,M190Read); SetReadHandler(0xDD00,0xDD00,M190Read); - SetReadHandler(0x7000,0x7FFF,AWRAM); - SetWriteHandler(0x7000,0x7FFF,BWRAM); - SetReadHandler(0x6000,0x6FFF,ASWRAM); - SetWriteHandler(0x6000,0x6FFF,BSWRAM); Sync(); } @@ -104,6 +202,9 @@ static void M190Close(void) if(CHRRAM) FCEU_gfree(CHRRAM); CHRRAM=NULL; + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; } static void StateRestore(int version) @@ -115,14 +216,24 @@ void Mapper190_Init(CartInfo *info) { info->Power=M190Power; info->Close=M190Close; + GameStateRestore=StateRestore; + + MapIRQHook=VRC5IRQ; +// PPU_hook=Mapper190_PPU; + + CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1); + AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM"); + + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + if(info->battery) { - info->SaveGame[0]=SWRAM; - info->SaveGameLen[0]=4096; + info->SaveGame[0] = WRAM; + info->SaveGameLen[0] = WRAMSIZE - 4096; } - GameStateRestore=StateRestore; - CHRRAM=(uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10,CHRRAM,8192,1); - AddExState(CHRRAM, 8192, 0, "CHRRAM"); + AddExState(&StateRegs, ~0, 0, 0); } diff --git a/src/boards/ks7032.cpp b/src/boards/ks7032.cpp new file mode 100644 index 00000000..34bd33f8 --- /dev/null +++ b/src/boards/ks7032.cpp @@ -0,0 +1,94 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd, IRQa; +static int32 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {reg, 8, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg[4]); + setprg8(0x8000,reg[1]); + setprg8(0xA000,reg[2]); + setprg8(0xC000,reg[3]); + setprg8(0xE000,~0); + setchr8(0); +} + +static DECLFW(UNLKS7032Write) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + switch(A) + { +// case 0x8FFF: reg[4]=V; Sync(); break; + case 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); break; + case 0xC000: X6502_IRQEnd(FCEU_IQEXT); IRQa=1; break; + case 0xE000: cmd=V&7; break; + case 0xF000: reg[cmd]=V; Sync(); break; + } +} + +static void UNLSMB2JIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0xFFFF) + { + IRQa=0; + IRQCount=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7032Power(void) +{ + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0xFFFF,UNLKS7032Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7032_Init(CartInfo *info) +{ + info->Power=UNLKS7032Power; + MapIRQHook=UNLSMB2JIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/malee.cpp b/src/boards/malee.cpp index b3425121..268911cc 100644 --- a/src/boards/malee.cpp +++ b/src/boards/malee.cpp @@ -28,6 +28,7 @@ static void MALEEPower(void) SetReadHandler(0x8000,0xFFFF,CartBR); SetReadHandler(0x6000,0x67FF,CartBR); SetReadHandler(0x7000,0x77FF,CartBR); + SetWriteHandler(0x7000,0x77FF,CartBW); setprg2r(1,0x6000,0); setprg32(0x8000,0); setchr8(0); diff --git a/src/boards/mmc1.cpp b/src/boards/mmc1.cpp index acbbe550..1a78eb7a 100644 --- a/src/boards/mmc1.cpp +++ b/src/boards/mmc1.cpp @@ -34,7 +34,7 @@ static void (*MMC1PRGHook16)(uint32 A, uint8 V); static uint8 *WRAM=NULL; static uint8 *CHRRAM=NULL; -static int is155; +static int is155, is171; static DECLFW(MBWRAM) { @@ -58,6 +58,7 @@ static void MMC1CHR(void) else setprg8r(0x10,0x6000,(DRegs[1]>>3)&1); } + if(MMC1CHRHook4) { if(DRegs[0]&0x10) @@ -103,7 +104,9 @@ static void MMC1PRG(void) break; } } - else switch(DRegs[0]&0xC) + else + { + switch(DRegs[0]&0xC) { case 0xC: setprg16(0x8000,(DRegs[3]+offs)); setprg16(0xC000,0xF+offs); @@ -118,9 +121,11 @@ static void MMC1PRG(void) break; } } +} static void MMC1MIRROR(void) { + if(!is171) switch(DRegs[0]&3) { case 2: setmirror(MI_V); break; @@ -135,15 +140,18 @@ static DECLFW(MMC1_write) { int n=(A>>13)-4; //FCEU_DispMessage("%016x",timestampbase+timestamp); - //printf("$%04x:$%02x, $%04x\n",A,V,X.PC); +// FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC); //DumpMem("out",0xe000,0xffff); /* The MMC1 is busy so ignore the write. */ /* As of version FCE Ultra 0.81, the timestamp is only increased before each instruction is executed(in other words precision isn't that great), but this should still work to - deal with 2 writes in a row from a single RMW instruction. */ - if((timestampbase+timestamp)<(lreset+2)) return; + deal with 2 writes in a row from a single RMW instruction. + */ + if((timestampbase+timestamp)<(lreset+2)) + return; +// FCEU_printf("Write %04x:%02x\n",A,V); if(V&0x80) { DRegs[0]|=0xC; @@ -152,7 +160,9 @@ static DECLFW(MMC1_write) lreset=timestampbase+timestamp; return; } + Buffer|=(V&1)<<(BufferShift++); + if(BufferShift==5) { DRegs[n] = Buffer; @@ -178,10 +188,12 @@ static void MMC1_Restore(int version) static void MMC1CMReset(void) { int i; + for(i=0;i<4;i++) DRegs[i]=0; Buffer = BufferShift = 0; DRegs[0]=0x1F; + DRegs[1]=0; DRegs[2]=0; // Should this be something other than 0? DRegs[3]=0; @@ -233,6 +245,7 @@ static void NWCCHRHook(uint32 A, uint8 V) NWCIRQCount=0; X6502_IRQEnd(FCEU_IQEXT); } + NWCRec=V; if(V&0x08) MMC1PRG(); @@ -311,7 +324,8 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) { WRAM=(uint8*)FCEU_gmalloc(wram*1024); //mbg 6/17/08 - this shouldve been cleared to re-initialize save ram - memset(WRAM,0,wram*1024); + //ch4 10/12/08 - nope, this souldn't + //memset(WRAM,0,wram*1024); mmc1opts|=1; if(wram>8) mmc1opts|=4; SetupCartPRGMapping(0x10,WRAM,wram*1024,1); @@ -351,6 +365,14 @@ void Mapper155_Init(CartInfo *info) is155=1; } +/* Same as mapper 1, with different (or without) mirroring control. */ +/* Kaiser KS7058 board, KS203 custom chip */ +void Mapper171_Init(CartInfo *info) +{ + GenMMC1Init(info,32,32,0,0); + is171=1; +} + void SAROM_Init(CartInfo *info) { GenMMC1Init(info, 128, 64, 8, info->battery); diff --git a/src/boards/mmc3.cpp b/src/boards/mmc3.cpp index d976c211..9912119c 100644 --- a/src/boards/mmc3.cpp +++ b/src/boards/mmc3.cpp @@ -21,7 +21,7 @@ */ /* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, - 119,148,165,205,214,215,245,249,250,254 + 119,165,205,214,215,245,249,250,254 */ #include "mapinc.h" @@ -128,7 +128,9 @@ DECLFW(MMC3_CMDWrite) { case 0x8000: if((V&0x40) != (MMC3_cmd&0x40)) + { FixMMC3PRG(V); + } if((V&0x80) != (MMC3_cmd&0x80)) FixMMC3CHR(V); MMC3_cmd = V; @@ -170,7 +172,6 @@ DECLFW(MMC3_CMDWrite) break; case 0xA001: A001B=V; - Write_IRQFM(0x4017,0x40); break; } } @@ -232,7 +233,8 @@ void GenMMC3Restore(int version) static void GENCWRAP(uint32 A, uint8 V) { - if(!UNIFchrrama) setchr1(A,V); +// if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS + setchr1(A,V); // Business Wars NEEDS THIS } static void GENPWRAP(uint32 A, uint8 V) @@ -535,8 +537,9 @@ static void M45CW(uint32 A, uint8 V) uint32 NV=V; if(EXPREGS[2]&8) NV&=(1<<((EXPREGS[2]&7)+1))-1; -// else -// NV&=0; + else + if(EXPREGS[2]) + NV&=0; // hack ;( don't know exactly how it should be NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); setchr1(A,NV); } @@ -854,6 +857,8 @@ static void M115CW(uint32 A, uint8 V) static DECLFW(M115Write) { +// FCEU_printf("%04x:%04x\n",A,V); + if(A==0x5080) EXPREGS[2]=V; if(A==0x6000) EXPREGS[0]=V; else if(A==0x6001) @@ -861,11 +866,16 @@ static DECLFW(M115Write) FixMMC3PRG(MMC3_cmd); } +static DECLFR(M115Read) +{ + return EXPREGS[2]; +} + static void M115Power(void) { GenMMC3Power(); SetWriteHandler(0x4100,0x7FFF,M115Write); - SetReadHandler(0x4100,0x7FFF,0); + SetReadHandler(0x5000,0x5FFF,M115Read); } void Mapper115_Init(CartInfo *info) @@ -956,6 +966,48 @@ void Mapper119_Init(CartInfo *info) SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); } +// ---------------------------- Mapper 134 ------------------------------ + +static void M134PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x1F)|((EXPREGS[0]&2)<<4)); +} + +static void M134CW(uint32 A, uint8 V) +{ + setchr1(A,(V&0xFF)|((EXPREGS[0]&0x20)<<3)); +} + +static DECLFW(M134Write) +{ + EXPREGS[0]=V; + FixMMC3CHR(MMC3_cmd); + FixMMC3PRG(MMC3_cmd); +} + +static void M134Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6001,0x6001,M134Write); +} + +static void M134Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper134_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M134PW; + cwrap=M134CW; + info->Power=M134Power; + info->Reset=M134Reset; + AddExState(EXPREGS, 4, 0, "EXPR"); +} + // ---------------------------- Mapper 165 ------------------------------ static void M165CW(uint32 A, uint8 V) @@ -1159,6 +1211,29 @@ void Mapper195_Init(CartInfo *info) AddExState(wramtw, wramsize, 0, "WRAMTW"); } +// ---------------------------- Mapper 196 ------------------------------- + +static DECLFW(Mapper196Write) +{ + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1); + if(A >= 0xC000) + MMC3_IRQWrite(A,V); + else + MMC3_CMDWrite(A,V); +} + +static void Mapper196Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,Mapper196Write); +} + +void Mapper196_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 0, 0); + info->Power=Mapper196Power; +} + // ---------------------------- Mapper 197 ------------------------------- static void M197CW(uint32 A, uint8 V) @@ -1560,6 +1635,11 @@ void Mapper254_Init(CartInfo *info) // ---------------------------- UNIF Boards ----------------------------- +void TBROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 64, 64, 0, 0); +} + void TEROM_Init(CartInfo *info) { GenMMC3_Init(info, 32, 32, 0, 0); diff --git a/src/boards/mmc5.cpp b/src/boards/mmc5.cpp index 31c23610..a2227ad9 100644 --- a/src/boards/mmc5.cpp +++ b/src/boards/mmc5.cpp @@ -1,97 +1,97 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -/* None of this code should use any of the iNES bank switching wrappers. */ - -#include "mapinc.h" - -static void (*sfun)(int P); -static void (*psfun)(void); - -void MMC5RunSound(int Count); -void MMC5RunSoundHQ(void); - -static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) -{ - if(CHRptr[0]) - { - V&=CHRmask1[0]; - MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); - } -} - -static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}} - -static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} -static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} - -static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} -static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} - -static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}} -static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}} - -static uint8 PRGBanks[4]; -static uint8 WRAMPage; -static uint8 CHRBanksA[8], CHRBanksB[4]; -static uint8 WRAMMaskEnable[2]; -uint8 mmc5ABMode; /* A=0, B=1 */ - -static uint8 IRQScanline,IRQEnable; -static uint8 CHRMode, NTAMirroring, NTFill, ATFill; - -static uint8 MMC5IRQR; -static uint8 MMC5LineCounter; -static uint8 mmc5psize, mmc5vsize; -static uint8 mul[2]; - -static uint8 *WRAM=NULL; -static uint8 *MMC5fill=NULL; -static uint8 *ExRAM=NULL; - -static uint8 MMC5WRAMsize; -static uint8 MMC5WRAMIndex[8]; - -static uint8 MMC5ROMWrProtect[4]; -static uint8 MMC5MemIn[5]; - -static void MMC5CHRA(void); -static void MMC5CHRB(void); - -typedef struct __cartdata { - uint32 crc32; - uint8 size; -} cartdata; - -#define Sprite16 (PPU[0]&0x20) //Sprites 8x16/8x8 -//#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] -static inline uint8 * MMC5BGVRAMADR(uint32 A) -{ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +/* None of this code should use any of the iNES bank switching wrappers. */ + +#include "mapinc.h" + +static void (*sfun)(int P); +static void (*psfun)(void); + +void MMC5RunSound(int Count); +void MMC5RunSoundHQ(void); + +static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) +{ + if(CHRptr[0]) + { + V&=CHRmask1[0]; + MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); + } +} + +static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}} + +static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} +static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}} + +static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} +static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}} + +static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}} +static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}} + +static uint8 PRGBanks[4]; +static uint8 WRAMPage; +static uint8 CHRBanksA[8], CHRBanksB[4]; +static uint8 WRAMMaskEnable[2]; +uint8 mmc5ABMode; /* A=0, B=1 */ + +static uint8 IRQScanline,IRQEnable; +static uint8 CHRMode, NTAMirroring, NTFill, ATFill; + +static uint8 MMC5IRQR; +static uint8 MMC5LineCounter; +static uint8 mmc5psize, mmc5vsize; +static uint8 mul[2]; + +static uint8 *WRAM=NULL; +static uint8 *MMC5fill=NULL; +static uint8 *ExRAM=NULL; + +static uint8 MMC5WRAMsize; +static uint8 MMC5WRAMIndex[8]; + +static uint8 MMC5ROMWrProtect[4]; +static uint8 MMC5MemIn[5]; + +static void MMC5CHRA(void); +static void MMC5CHRB(void); + +typedef struct __cartdata { + uint32 crc32; + uint8 size; +} cartdata; + +#define Sprite16 (PPU[0]&0x20) //Sprites 8x16/8x8 +//#define MMC5SPRVRAMADR(V) &MMC5SPRVPage[(V)>>10][(V)] +static inline uint8 * MMC5BGVRAMADR(uint32 A) +{ if(!Sprite16) { if(mmc5ABMode==0) return &MMC5SPRVPage[(A)>>10][(A)]; else return &MMC5BGVPage[(A)>>10][(A)]; - } else return &MMC5BGVPage[(A)>>10][(A)]; -} - + } else return &MMC5BGVPage[(A)>>10][(A)]; +} + static void mmc5_PPUWrite(uint32 A, uint8 V) { uint32 tmp = A; extern uint8 PALRAM[0x20]; @@ -128,778 +128,772 @@ uint8 mmc5_PPURead(uint32 A) { } } - - -// ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB -// EWROM seems to have 32KB of WRAM - -#define MMC5_NOCARTS 14 -cartdata MMC5CartList[MMC5_NOCARTS]= -{ - {0x9c18762b,2}, /* L'Empereur */ - {0x26533405,2}, - {0x6396b988,2}, - - {0xaca15643,2}, /* Uncharted Waters */ - {0xfe3488d1,2}, /* Dai Koukai Jidai */ - - {0x15fe6d0f,2}, /* BKAC */ - {0x39f2ce4b,2}, /* Suikoden */ - - {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ - {0xeee9a682,2}, - - {0x1ced086f,2}, /* Ishin no Arashi */ - - {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ - - {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ - - {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ - {0x184c2124,4}, /* Sangokushi 2 */ -}; - - -int DetectMMC5WRAMSize(uint32 crc32) -{ - int x; - for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(MMC5CartList[x].size*8); - } - } - - //mbg 8/4/08 - previously, this was returning 8KB - //but I changed it to return 64 because unlisted carts are probably homebrews, and they should probably use 64 (why not use it all?) - return 64; -} - -static void BuildWRAMSizeTable(void) -{ - int x; - for(x=0;x<8;x++) - { - switch(MMC5WRAMsize) - { - case 0: MMC5WRAMIndex[x]=255; break; //X,X,X,X,X,X,X,X - case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; //0,0,0,0,X,X,X,X - case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; //0,0,0,0,1,1,1,1 - case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; //0,1,2,3,X,X,X,X - case 8: MMC5WRAMIndex[x]=x; break; //0,1,2,3,4,5,6,7,8 - //mbg 8/6/08 - i added this to support 64KB of wram - //now, I have at least one example (laser invasion) which actually uses size 1 but isnt in the crc list - //so, whereas before my change on 8/4/08 we would have selected size 1, now we select size 8 - //this means that we could have just introduced an emulation bug, in case those games happened to - //address, say, page 3. with size 1 that would resolve to [0] but in size 8 it resolves to [3]. - //so, you know what to do if there are problems. - } - } -} - -static void MMC5CHRA(void) -{ - int x; - switch(mmc5vsize&3) - { - case 0: setchr8(CHRBanksA[7]); - MMC5SPRVROM_BANK8(CHRBanksA[7]); - break; - case 1: setchr4(0x0000,CHRBanksA[3]); - setchr4(0x1000,CHRBanksA[7]); - MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); - MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); - break; - case 2: setchr2(0x0000,CHRBanksA[1]); - setchr2(0x0800,CHRBanksA[3]); - setchr2(0x1000,CHRBanksA[5]); - setchr2(0x1800,CHRBanksA[7]); - MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); - MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); - MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); - MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); - break; - case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksA[x]); - MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); - } - break; - } -} - -static void MMC5CHRB(void) -{ - int x; - switch(mmc5vsize&3) - { - case 0: setchr8(CHRBanksB[3]); - MMC5BGVROM_BANK8(CHRBanksB[3]); - break; - case 1: setchr4(0x0000,CHRBanksB[3]); - setchr4(0x1000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); - break; - case 2: setchr2(0x0000,CHRBanksB[1]); - setchr2(0x0800,CHRBanksB[3]); - setchr2(0x1000,CHRBanksB[1]); - setchr2(0x1800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); - break; - case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksB[x&3]); - MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); - } - break; - } -} - -static void MMC5WRAM(uint32 A, uint32 V) -{ - //printf("%02x\n",V); - V=MMC5WRAMIndex[V&7]; - if(V!=255) - { - setprg8r(0x10,A,V); - MMC5MemIn[(A-0x6000)>>13]=1; - } - else - MMC5MemIn[(A-0x6000)>>13]=0; -} - -static void MMC5PRG(void) -{ - int x; - switch(mmc5psize&3) - { - case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); - for(x=0;x<4;x++) - MMC5MemIn[1+x]=1; - break; - case 1: if(PRGBanks[1]&0x80) - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]>>1)); - MMC5MemIn[1]=MMC5MemIn[2]=1; - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - MMC5MemIn[3]=MMC5MemIn[4]=1; - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); - break; - case 2: if(PRGBanks[1]&0x80) - { - MMC5MemIn[1]=MMC5MemIn[2]=1; - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - if(PRGBanks[2]&0x80) - { - MMC5ROMWrProtect[2]=1; - MMC5MemIn[3]=1; - setprg8(0xC000,PRGBanks[2]&0x7F); - } - else - { - MMC5ROMWrProtect[2]=0; - MMC5WRAM(0xC000,PRGBanks[2]&7); - } - MMC5MemIn[4]=1; - MMC5ROMWrProtect[3]=1; - setprg8(0xE000,PRGBanks[3]&0x7F); - break; - case 3: for(x=0;x<3;x++) - if(PRGBanks[x]&0x80) - { - MMC5ROMWrProtect[x]=1; - setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); - MMC5MemIn[1+x]=1; - } - else - { - MMC5ROMWrProtect[x]=0; - MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); - } - MMC5MemIn[4]=1; - MMC5ROMWrProtect[3]=1; - setprg8(0xE000,PRGBanks[3]&0x7F); - break; - } -} - -static DECLFW(Mapper5_write) -{ - if(A>=0x5120&&A<=0x5127) - { - mmc5ABMode = 0; - CHRBanksA[A&7]=V; - MMC5CHRA(); - } - else switch(A) - { - case 0x5105: { - int x; - for(x=0;x<4;x++) - { - switch((V>>(x<<1))&3) - { - case 0: - PPUNTARAM|=1<>3)&0x1F;break; - case 0x5202: MMC5HackSPPage=V&0x3F;break; - case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break; - case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break; - case 0x5205: mul[0]=V;break; - case 0x5206: mul[1]=V;break; - } -} - -static DECLFR(MMC5_ReadROMRAM) -{ - if(MMC5MemIn[(A-0x6000)>>13]) - return Page[A>>11][A]; - else - return X.DB; -} - -static DECLFW(MMC5_WriteROMRAM) -{ - if(A>=0x8000) - if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; - if(MMC5MemIn[(A-0x6000)>>13]) - if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) - Page[A>>11][A]=V; -} - -static DECLFW(MMC5_ExRAMWr) -{ - if(MMC5HackCHRMode!=3) - ExRAM[A&0x3ff]=V; -} - -static DECLFR(MMC5_ExRAMRd) -{ - /* Not sure if this is correct, so I'll comment it out for now. */ - //if(MMC5HackCHRMode>=2) - return ExRAM[A&0x3ff]; - //else - // return(X.DB); -} - -static DECLFR(MMC5_read) -{ - switch(A) - { - case 0x5204: X6502_IRQEnd(FCEU_IQEXT); - { - uint8 x; - x=MMC5IRQR; - if(!fceuindbg) - MMC5IRQR&=0x40; - return x; - } - case 0x5205: return (mul[0]*mul[1]); - case 0x5206: return ((mul[0]*mul[1])>>8); - } - return(X.DB); -} - -void MMC5Synco(void) -{ - int x; - - MMC5PRG(); - for(x=0;x<4;x++) - { - switch((NTAMirroring>>(x<<1))&3) - { - case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; -} - -static void Do5PCMHQ() -{ - uint32 V; //mbg merge 7/17/06 made uint32 - if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) - for(V=MMC5Sound.BC[2];V>2); - MMC5Sound.env[A>>2]=V; - break; - case 0x2: - case 0x6: if(sfun) sfun(A>>2); - MMC5Sound.wl[A>>2]&=~0x00FF; - MMC5Sound.wl[A>>2]|=V&0xFF; - break; - case 0x3: - case 0x7://printf("%04x:$%02x\n",A,V>>3); - MMC5Sound.wl[A>>2]&=~0x0700; - MMC5Sound.wl[A>>2]|=(V&0x07)<<8; - MMC5Sound.running|=1<<(A>>2); - break; - case 0x15:if(sfun) - { - sfun(0); - sfun(1); - } - MMC5Sound.running&=V; - MMC5Sound.enable=V; - //printf("%02x\n",V); - break; - } -} - -static void Do5SQ(int P) -{ - static int tal[4]={1,2,4,6}; - int32 V,amp,rthresh,wl; - int32 start,end; - - start=MMC5Sound.BC[P]; - end=(SOUNDTS<<16)/soundtsinc; - if(end<=start) return; - MMC5Sound.BC[P]=end; - - wl=MMC5Sound.wl[P]+1; - amp=(MMC5Sound.env[P]&0xF)<<4; - rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; - - if(wl>=8 && (MMC5Sound.running&(P+1))) - { - int dc,vc; - - wl<<=18; - dc=MMC5Sound.dcount[P]; - vc=MMC5Sound.vcount[P]; - - for(V=start;V>4]+=amp; - vc-=nesincsize; - while(vc<=0) - { - vc+=wl; - dc=(dc+1)&7; - } - } - MMC5Sound.dcount[P]=dc; - MMC5Sound.vcount[P]=vc; - } -} - -static void Do5SQHQ(int P) -{ - static int tal[4]={1,2,4,6}; - uint32 V; //mbg merge 7/17/06 made uint32 - int32 amp,rthresh,wl; - - wl=MMC5Sound.wl[P]+1; - amp=((MMC5Sound.env[P]&0xF)<<8); - rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; - - if(wl>=8 && (MMC5Sound.running&(P+1))) - { - int dc,vc; - - wl<<=1; - - dc=MMC5Sound.dcount[P]; - vc=MMC5Sound.vcount[P]; - for(V=MMC5Sound.BC[P];V=1) - { - sfun=Do5SQHQ; - psfun=Do5PCMHQ; - } - else - { - sfun=Do5SQ; - psfun=Do5PCM; - } - } - else - { - sfun=0; - psfun=0; - } - memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC)); - memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount)); - GameExpSound.HiSync=MMC5HiSync; -} - -void NSFMMC5_Init(void) -{ - memset(&MMC5Sound,0,sizeof(MMC5Sound)); - mul[0]=mul[1]=0; - ExRAM=(uint8*)FCEU_gmalloc(1024); - Mapper5_ESI(); - SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr); - SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd); - MMC5HackCHRMode=2; - SetWriteHandler(0x5000,0x5015,Mapper5_SW); - SetWriteHandler(0x5205,0x5206,Mapper5_write); - SetReadHandler(0x5205,0x5206,MMC5_read); -} - -void NSFMMC5_Close(void) -{ - FCEU_gfree(ExRAM); - ExRAM=0; -} - -static void GenMMC5Reset(void) -{ - int x; - - for(x=0;x<4;x++) PRGBanks[x]=~0; - for(x=0;x<8;x++) CHRBanksA[x]=~0; - for(x=0;x<4;x++) CHRBanksB[x]=~0; - WRAMMaskEnable[0]=WRAMMaskEnable[1]=~0; - - mmc5psize=mmc5vsize=3; - CHRMode=0; - - NTAMirroring=NTFill=ATFill=0xFF; - - MMC5Synco(); - - SetWriteHandler(0x4020,0x5bff,Mapper5_write); - SetReadHandler(0x4020,0x5bff,MMC5_read); - - SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr); - SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd); - - SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM); - SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM); - - SetWriteHandler(0x5000,0x5015,Mapper5_SW); - SetWriteHandler(0x5205,0x5206,Mapper5_write); - SetReadHandler(0x5205,0x5206,MMC5_read); - - //GameHBIRQHook=MMC5_hb; - FCEU_CheatAddRAM(8,0x6000,WRAM); - FCEU_CheatAddRAM(1,0x5c00,ExRAM); -} - -static SFORMAT MMC5_StateRegs[]={ - { PRGBanks, 4, "PRGB"}, - { CHRBanksA, 8, "CHRA"}, - { CHRBanksB, 4, "CHRB"}, - { &WRAMPage, 1, "WRMP"}, - { WRAMMaskEnable, 2, "WRME"}, - { &mmc5ABMode, 1, "ABMD"}, - { &IRQScanline, 1, "IRQS"}, - { &IRQEnable, 1, "IRQE"}, - { &CHRMode, 1, "CHRM"}, - { &NTAMirroring, 1, "NTAM"}, - { &NTFill, 1, "NTFL"}, - { &ATFill, 1, "ATFL"}, - - { &MMC5Sound.wl[0], 2|FCEUSTATE_RLSB, "SDW0"}, - { &MMC5Sound.wl[1], 2|FCEUSTATE_RLSB, "SDW1"}, - { MMC5Sound.env, 2, "SDEV"}, - { &MMC5Sound.enable, 1, "SDEN"}, - { &MMC5Sound.running, 1, "SDRU"}, - { &MMC5Sound.raw, 1, "SDRW"}, - { &MMC5Sound.rawcontrol, 1, "SDRC"}, - {0} -}; - -static void GenMMC5_Init(CartInfo *info, int wsize, int battery) -{ - if(wsize) - { - WRAM=(uint8*)FCEU_gmalloc(wsize*1024); - SetupCartPRGMapping(0x10,WRAM,wsize*1024,1); - AddExState(WRAM, wsize*1024, 0, "WRAM"); - } - - MMC5fill=(uint8*)FCEU_gmalloc(1024); - ExRAM=(uint8*)FCEU_gmalloc(1024); - - AddExState(MMC5_StateRegs, ~0, 0, 0); - AddExState(WRAM, wsize*1024, 0, "WRAM"); - AddExState(ExRAM, 1024, 0, "ERAM"); - AddExState(&MMC5HackSPMode, 1, 0, "SPLM"); - AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); - AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); - - MMC5WRAMsize=wsize/8; - BuildWRAMSizeTable(); - GameStateRestore=MMC5_StateRestore; - info->Power=GenMMC5Reset; - - if(battery) - { - info->SaveGame[0]=WRAM; - if(wsize<=16) - info->SaveGameLen[0]=8192; - else - info->SaveGameLen[0]=32768; - } - - MMC5HackVROMMask=CHRmask4[0]; - MMC5HackExNTARAMPtr=ExRAM; - MMC5Hack=1; - MMC5HackVROMPTR=CHRptr[0]; - MMC5HackCHRMode=0; - MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0; - Mapper5_ESI(); - - FFCEUX_PPURead = mmc5_PPURead; - FFCEUX_PPUWrite = mmc5_PPUWrite; -} - -void Mapper5_Init(CartInfo *info) -{ - GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); -} - -// ELROM seems to have 0KB of WRAM -// EKROM seems to have 8KB of WRAM -// ETROM seems to have 16KB of WRAM -// EWROM seems to have 32KB of WRAM - -// ETROM and EWROM are battery-backed, EKROM isn't. - -void ETROM_Init(CartInfo *info) -{ - GenMMC5_Init(info, 16,info->battery); -} - -void ELROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,0,0); -} - -void EWROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,32,info->battery); -} - -void EKROM_Init(CartInfo *info) -{ - GenMMC5_Init(info,8,info->battery); -} + + +// ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB +// EWROM seems to have 32KB of WRAM + + +cartdata MMC5CartList[]= +{ + {0x9c18762b,2}, /* L'Empereur */ + {0x26533405,2}, + {0x6396b988,2}, + {0xaca15643,2}, /* Uncharted Waters */ + {0xfe3488d1,2}, /* Dai Koukai Jidai */ + {0x15fe6d0f,2}, /* BKAC */ + {0x39f2ce4b,2}, /* Suikoden */ + {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ + {0xeee9a682,2}, + {0xf9b4240f,2}, + {0x1ced086f,2}, /* Ishin no Arashi */ + {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ + {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ + {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ + {0x184c2124,4}, /* Sangokushi 2 */ + {0xee8e6553,4}, +}; + +#define MMC5_NOCARTS (sizeof(MMC5CartList)/sizeof(MMC5CartList[0])) +int DetectMMC5WRAMSize(uint32 crc32) +{ + int x; + for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(MMC5CartList[x].size*8); + } + } + + //mbg 8/4/08 - previously, this was returning 8KB + //but I changed it to return 64 because unlisted carts are probably homebrews, and they should probably use 64 (why not use it all?) + //ch4 10/12/08 - then f***ng for what all this shit above? let's give em all this 64k shit! Damn + // homebrew must use it's own emulators or standart features. + return 8; +} + +static void BuildWRAMSizeTable(void) +{ + int x; + for(x=0;x<8;x++) + { + switch(MMC5WRAMsize) + { + case 0: MMC5WRAMIndex[x]=255; break; //X,X,X,X,X,X,X,X + case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; //0,0,0,0,X,X,X,X + case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; //0,0,0,0,1,1,1,1 + case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; //0,1,2,3,X,X,X,X + case 8: MMC5WRAMIndex[x]=x; break; //0,1,2,3,4,5,6,7,8 + //mbg 8/6/08 - i added this to support 64KB of wram + //now, I have at least one example (laser invasion) which actually uses size 1 but isnt in the crc list + //so, whereas before my change on 8/4/08 we would have selected size 1, now we select size 8 + //this means that we could have just introduced an emulation bug, in case those games happened to + //address, say, page 3. with size 1 that would resolve to [0] but in size 8 it resolves to [3]. + //so, you know what to do if there are problems. + } + } +} + +static void MMC5CHRA(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksA[7]); + MMC5SPRVROM_BANK8(CHRBanksA[7]); + break; + case 1: setchr4(0x0000,CHRBanksA[3]); + setchr4(0x1000,CHRBanksA[7]); + MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); + MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); + break; + case 2: setchr2(0x0000,CHRBanksA[1]); + setchr2(0x0800,CHRBanksA[3]); + setchr2(0x1000,CHRBanksA[5]); + setchr2(0x1800,CHRBanksA[7]); + MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); + MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); + MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); + MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksA[x]); + MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); + } + break; + } +} + +static void MMC5CHRB(void) +{ + int x; + switch(mmc5vsize&3) + { + case 0: setchr8(CHRBanksB[3]); + MMC5BGVROM_BANK8(CHRBanksB[3]); + break; + case 1: setchr4(0x0000,CHRBanksB[3]); + setchr4(0x1000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); + break; + case 2: setchr2(0x0000,CHRBanksB[1]); + setchr2(0x0800,CHRBanksB[3]); + setchr2(0x1000,CHRBanksB[1]); + setchr2(0x1800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); + break; + case 3: for(x=0;x<8;x++) + { + setchr1(x<<10,CHRBanksB[x&3]); + MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); + } + break; + } +} + +static void MMC5WRAM(uint32 A, uint32 V) +{ + //printf("%02x\n",V); + V=MMC5WRAMIndex[V&7]; + if(V!=255) + { + setprg8r(0x10,A,V); + MMC5MemIn[(A-0x6000)>>13]=1; + } + else + MMC5MemIn[(A-0x6000)>>13]=0; +} + +static void MMC5PRG(void) +{ + int x; + switch(mmc5psize&3) + { + case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); + for(x=0;x<4;x++) + MMC5MemIn[1+x]=1; + break; + case 1: if(PRGBanks[1]&0x80) + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]>>1)); + MMC5MemIn[1]=MMC5MemIn[2]=1; + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + MMC5MemIn[3]=MMC5MemIn[4]=1; + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); + break; + case 2: if(PRGBanks[1]&0x80) + { + MMC5MemIn[1]=MMC5MemIn[2]=1; + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + if(PRGBanks[2]&0x80) + { + MMC5ROMWrProtect[2]=1; + MMC5MemIn[3]=1; + setprg8(0xC000,PRGBanks[2]&0x7F); + } + else + { + MMC5ROMWrProtect[2]=0; + MMC5WRAM(0xC000,PRGBanks[2]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + case 3: for(x=0;x<3;x++) + if(PRGBanks[x]&0x80) + { + MMC5ROMWrProtect[x]=1; + setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); + MMC5MemIn[1+x]=1; + } + else + { + MMC5ROMWrProtect[x]=0; + MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; + } +} + +static DECLFW(Mapper5_write) +{ + if(A>=0x5120&&A<=0x5127) + { + mmc5ABMode = 0; + CHRBanksA[A&7]=V; + MMC5CHRA(); + } + else switch(A) + { + case 0x5105: { + int x; + for(x=0;x<4;x++) + { + switch((V>>(x<<1))&3) + { + case 0: + PPUNTARAM|=1<>3)&0x1F;break; + case 0x5202: MMC5HackSPPage=V&0x3F;break; + case 0x5203: X6502_IRQEnd(FCEU_IQEXT);IRQScanline=V;break; + case 0x5204: X6502_IRQEnd(FCEU_IQEXT);IRQEnable=V&0x80;break; + case 0x5205: mul[0]=V;break; + case 0x5206: mul[1]=V;break; + } +} + +static DECLFR(MMC5_ReadROMRAM) +{ + if(MMC5MemIn[(A-0x6000)>>13]) + return Page[A>>11][A]; + else + return X.DB; +} + +static DECLFW(MMC5_WriteROMRAM) +{ + if(A>=0x8000) + if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; + if(MMC5MemIn[(A-0x6000)>>13]) + if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) + Page[A>>11][A]=V; +} + +static DECLFW(MMC5_ExRAMWr) +{ + if(MMC5HackCHRMode!=3) + ExRAM[A&0x3ff]=V; +} + +static DECLFR(MMC5_ExRAMRd) +{ + /* Not sure if this is correct, so I'll comment it out for now. */ + //if(MMC5HackCHRMode>=2) + return ExRAM[A&0x3ff]; + //else + // return(X.DB); +} + +static DECLFR(MMC5_read) +{ + switch(A) + { + case 0x5204: X6502_IRQEnd(FCEU_IQEXT); + { + uint8 x; + x=MMC5IRQR; + if(!fceuindbg) + MMC5IRQR&=0x40; + return x; + } + case 0x5205: return (mul[0]*mul[1]); + case 0x5206: return ((mul[0]*mul[1])>>8); + } + return(X.DB); +} + +void MMC5Synco(void) +{ + int x; + + MMC5PRG(); + for(x=0;x<4;x++) + { + switch((NTAMirroring>>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; +} + +static void Do5PCMHQ() +{ + uint32 V; //mbg merge 7/17/06 made uint32 + if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) + for(V=MMC5Sound.BC[2];V>2); + MMC5Sound.env[A>>2]=V; + break; + case 0x2: + case 0x6: if(sfun) sfun(A>>2); + MMC5Sound.wl[A>>2]&=~0x00FF; + MMC5Sound.wl[A>>2]|=V&0xFF; + break; + case 0x3: + case 0x7://printf("%04x:$%02x\n",A,V>>3); + MMC5Sound.wl[A>>2]&=~0x0700; + MMC5Sound.wl[A>>2]|=(V&0x07)<<8; + MMC5Sound.running|=1<<(A>>2); + break; + case 0x15:if(sfun) + { + sfun(0); + sfun(1); + } + MMC5Sound.running&=V; + MMC5Sound.enable=V; + //printf("%02x\n",V); + break; + } +} + +static void Do5SQ(int P) +{ + static int tal[4]={1,2,4,6}; + int32 V,amp,rthresh,wl; + int32 start,end; + + start=MMC5Sound.BC[P]; + end=(SOUNDTS<<16)/soundtsinc; + if(end<=start) return; + MMC5Sound.BC[P]=end; + + wl=MMC5Sound.wl[P]+1; + amp=(MMC5Sound.env[P]&0xF)<<4; + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=18; + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + + for(V=start;V>4]+=amp; + vc-=nesincsize; + while(vc<=0) + { + vc+=wl; + dc=(dc+1)&7; + } + } + MMC5Sound.dcount[P]=dc; + MMC5Sound.vcount[P]=vc; + } +} + +static void Do5SQHQ(int P) +{ + static int tal[4]={1,2,4,6}; + uint32 V; //mbg merge 7/17/06 made uint32 + int32 amp,rthresh,wl; + + wl=MMC5Sound.wl[P]+1; + amp=((MMC5Sound.env[P]&0xF)<<8); + rthresh=tal[(MMC5Sound.env[P]&0xC0)>>6]; + + if(wl>=8 && (MMC5Sound.running&(P+1))) + { + int dc,vc; + + wl<<=1; + + dc=MMC5Sound.dcount[P]; + vc=MMC5Sound.vcount[P]; + for(V=MMC5Sound.BC[P];V=1) + { + sfun=Do5SQHQ; + psfun=Do5PCMHQ; + } + else + { + sfun=Do5SQ; + psfun=Do5PCM; + } + } + else + { + sfun=0; + psfun=0; + } + memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC)); + memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount)); + GameExpSound.HiSync=MMC5HiSync; +} + +void NSFMMC5_Init(void) +{ + memset(&MMC5Sound,0,sizeof(MMC5Sound)); + mul[0]=mul[1]=0; + ExRAM=(uint8*)FCEU_gmalloc(1024); + Mapper5_ESI(); + SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr); + SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd); + MMC5HackCHRMode=2; + SetWriteHandler(0x5000,0x5015,Mapper5_SW); + SetWriteHandler(0x5205,0x5206,Mapper5_write); + SetReadHandler(0x5205,0x5206,MMC5_read); +} + +void NSFMMC5_Close(void) +{ + FCEU_gfree(ExRAM); + ExRAM=0; +} + +static void GenMMC5Reset(void) +{ + int x; + + for(x=0;x<4;x++) PRGBanks[x]=~0; + for(x=0;x<8;x++) CHRBanksA[x]=~0; + for(x=0;x<4;x++) CHRBanksB[x]=~0; + WRAMMaskEnable[0]=WRAMMaskEnable[1]=~0; + + mmc5psize=mmc5vsize=3; + CHRMode=0; + + NTAMirroring=NTFill=ATFill=0xFF; + + MMC5Synco(); + + SetWriteHandler(0x4020,0x5bff,Mapper5_write); + SetReadHandler(0x4020,0x5bff,MMC5_read); + + SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr); + SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd); + + SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM); + SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM); + + SetWriteHandler(0x5000,0x5015,Mapper5_SW); + SetWriteHandler(0x5205,0x5206,Mapper5_write); + SetReadHandler(0x5205,0x5206,MMC5_read); + + //GameHBIRQHook=MMC5_hb; + FCEU_CheatAddRAM(8,0x6000,WRAM); + FCEU_CheatAddRAM(1,0x5c00,ExRAM); +} + +static SFORMAT MMC5_StateRegs[]={ + { PRGBanks, 4, "PRGB"}, + { CHRBanksA, 8, "CHRA"}, + { CHRBanksB, 4, "CHRB"}, + { &WRAMPage, 1, "WRMP"}, + { WRAMMaskEnable, 2, "WRME"}, + { &mmc5ABMode, 1, "ABMD"}, + { &IRQScanline, 1, "IRQS"}, + { &IRQEnable, 1, "IRQE"}, + { &CHRMode, 1, "CHRM"}, + { &NTAMirroring, 1, "NTAM"}, + { &NTFill, 1, "NTFL"}, + { &ATFill, 1, "ATFL"}, + + { &MMC5Sound.wl[0], 2|FCEUSTATE_RLSB, "SDW0"}, + { &MMC5Sound.wl[1], 2|FCEUSTATE_RLSB, "SDW1"}, + { MMC5Sound.env, 2, "SDEV"}, + { &MMC5Sound.enable, 1, "SDEN"}, + { &MMC5Sound.running, 1, "SDRU"}, + { &MMC5Sound.raw, 1, "SDRW"}, + { &MMC5Sound.rawcontrol, 1, "SDRC"}, + {0} +}; + +static void GenMMC5_Init(CartInfo *info, int wsize, int battery) +{ + if(wsize) + { + WRAM=(uint8*)FCEU_gmalloc(wsize*1024); + SetupCartPRGMapping(0x10,WRAM,wsize*1024,1); + AddExState(WRAM, wsize*1024, 0, "WRAM"); + } + + MMC5fill=(uint8*)FCEU_gmalloc(1024); + ExRAM=(uint8*)FCEU_gmalloc(1024); + + AddExState(MMC5_StateRegs, ~0, 0, 0); + AddExState(WRAM, wsize*1024, 0, "WRAM"); + AddExState(ExRAM, 1024, 0, "ERAM"); + AddExState(&MMC5HackSPMode, 1, 0, "SPLM"); + AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); + AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); + + MMC5WRAMsize=wsize/8; + BuildWRAMSizeTable(); + GameStateRestore=MMC5_StateRestore; + info->Power=GenMMC5Reset; + + if(battery) + { + info->SaveGame[0]=WRAM; + if(wsize<=16) + info->SaveGameLen[0]=8192; + else + info->SaveGameLen[0]=32768; + } + + MMC5HackVROMMask=CHRmask4[0]; + MMC5HackExNTARAMPtr=ExRAM; + MMC5Hack=1; + MMC5HackVROMPTR=CHRptr[0]; + MMC5HackCHRMode=0; + MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0; + Mapper5_ESI(); + + FFCEUX_PPURead = mmc5_PPURead; + FFCEUX_PPUWrite = mmc5_PPUWrite; +} + +void Mapper5_Init(CartInfo *info) +{ + GenMMC5_Init(info, DetectMMC5WRAMSize(info->CRC32), info->battery); +} + +// ELROM seems to have 0KB of WRAM +// EKROM seems to have 8KB of WRAM +// ETROM seems to have 16KB of WRAM +// EWROM seems to have 32KB of WRAM + +// ETROM and EWROM are battery-backed, EKROM isn't. + +void ETROM_Init(CartInfo *info) +{ + GenMMC5_Init(info, 16,info->battery); +} + +void ELROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,0,0); +} + +void EWROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,32,info->battery); +} + +void EKROM_Init(CartInfo *info) +{ + GenMMC5_Init(info,8,info->battery); +} diff --git a/src/boards/n-c22m.cpp b/src/boards/n-c22m.cpp index b20c57fe..f10bb78a 100644 --- a/src/boards/n-c22m.cpp +++ b/src/boards/n-c22m.cpp @@ -16,16 +16,10 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ + * Mortal Kombat 2 YOKO */ #include "mapinc.h" - -//mbg merge 7/17/06 - TODO CaH4e3 / does it make sense to #include mmc3.h here? it uses some vars from it.. -//also, CaH4e3, discuss with me whether this implies that 0xA000 and 0xE000 can have their own 8k banks ( #include "mmc3.h" -//mbg merge 7/17/06 we get these externs from mmc3.h -//uint8 IRQCount,IRQLatch,IRQa; -//uint8 IRQReload; static uint8 reg[8]; @@ -54,7 +48,7 @@ static void Sync(void) static DECLFW(MCN22MWrite) { -FCEU_printf("bs %04x %02x\n",A,V); +//FCEU_printf("bs %04x %02x\n",A,V); switch(A) { case 0x8c00: @@ -70,6 +64,7 @@ FCEU_printf("bs %04x %02x\n",A,V); static void MCN22MPower(void) { + reg[0]=reg[1]=reg[2]=0; Sync(); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x8000,0xFFFF,MCN22MWrite); diff --git a/src/boards/n106.cpp b/src/boards/n106.cpp index 2c8cb611..1d84d67b 100644 --- a/src/boards/n106.cpp +++ b/src/boards/n106.cpp @@ -443,7 +443,7 @@ void Mapper19_Init(CartInfo *info) Mapper19_ESI(); AddExState(WRAM, 8192, 0, "WRAM"); - AddExState(IRAM, 128, 0, "WRAM"); + AddExState(IRAM, 128, 0, "IRAM"); AddExState(N106_StateRegs, ~0, 0, 0); if(info->battery) diff --git a/src/boards/n625092.cpp b/src/boards/n625092.cpp new file mode 100644 index 00000000..8f6240ce --- /dev/null +++ b/src/boards/n625092.cpp @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * 700in1 and 400in1 carts + */ + + +#include "mapinc.h" + +static uint16 cmd, bank; + +static SFORMAT StateRegs[]= +{ + {&cmd, 2, "CMD"}, + {&bank, 2, "BANK"}, + {0} +}; + +static void Sync(void) +{ + setmirror((cmd&1)^1); + setchr8(0); + if(cmd&2) + { + if(cmd&0x100) + { + setprg16(0x8000,((cmd&0xe0)>>2)|bank); + setprg16(0xC000,((cmd&0xe0)>>2)|7); + } + else + { + setprg16(0x8000,((cmd&0xe0)>>2)|(bank&6)); + setprg16(0xC000,((cmd&0xe0)>>2)|((bank&6)|1)); + } + } + else + { + setprg16(0x8000,((cmd&0xe0)>>2)|bank); + setprg16(0xC000,((cmd&0xe0)>>2)|bank); + } +} + +static DECLFW(UNLN625092WriteCommand) +{ + cmd=A; + Sync(); +} + +static DECLFW(UNLN625092WriteBank) +{ + bank=A&7; + Sync(); +} + +static void UNLN625092Power(void) +{ + cmd=0; + bank=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,UNLN625092WriteCommand); + SetWriteHandler(0xC000,0xFFFF,UNLN625092WriteBank); +} + +static void UNLN625092Reset(void) +{ + cmd=0; + bank=0; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLN625092_Init(CartInfo *info) +{ + info->Reset=UNLN625092Reset; + info->Power=UNLN625092Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/sachen.cpp b/src/boards/sachen.cpp index a48c6b9f..a2b57415 100644 --- a/src/boards/sachen.cpp +++ b/src/boards/sachen.cpp @@ -20,7 +20,7 @@ #include "mapinc.h" -static uint8 cmd; +static uint8 cmd, dip; static uint8 latch[8]; static void S74LS374MSync(uint8 mirr) @@ -65,7 +65,7 @@ static DECLFR(S74LS374NRead) uint8 ret; if((A&0x4100)==0x4100) // ret=(X.DB&0xC0)|((~cmd)&0x3F); - ret=~cmd&0x3F; + ret=((~cmd)&0x3F)^dip; else ret=X.DB; return ret; @@ -73,6 +73,7 @@ static DECLFR(S74LS374NRead) static void S74LS374NPower(void) { + dip=0; latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; S74LS374NSynco(); SetReadHandler(0x8000,0xFFFF,CartBR); @@ -80,6 +81,13 @@ static void S74LS374NPower(void) SetReadHandler(0x4100,0x5fff,S74LS374NRead); } +static void S74LS374NReset(void) +{ + dip^=1; + latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; + S74LS374NSynco(); +} + static void S74LS374NRestore(int version) { S74LS374NSynco(); @@ -88,9 +96,11 @@ static void S74LS374NRestore(int version) void S74LS374N_Init(CartInfo *info) { info->Power=S74LS374NPower; + info->Reset=S74LS374NReset; GameStateRestore=S74LS374NRestore; AddExState(latch, 5, 0, "LATC"); AddExState(&cmd, 1, 0, "CMD"); + AddExState(&dip, 1, 0, "DIP"); } static void S74LS374NASynco(void) @@ -292,6 +302,12 @@ static void SA72007Synco() setchr8(latch[0]>>7); } +static void SA009Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&1); +} + static void SA72008Synco() { setprg32(0x8000,(latch[0]>>2)&1); @@ -322,6 +338,14 @@ void SA72008_Init(CartInfo *info) AddExState(&latch[0], 1, 0, "LATC"); } +void SA009_Init(CartInfo *info) +{ + WSync=SA009Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); +} + void SA0036_Init(CartInfo *info) { WSync=SA72007Synco; @@ -338,13 +362,15 @@ void SA0037_Init(CartInfo *info) AddExState(&latch[0], 1, 0, "LATC"); } +// ----------------------------------------------- + static void TCU01Synco() { - setprg32(0x8000,(latch[0]>>2)&1); + setprg32(0x8000,((latch[0]&0x80)>>6)|((latch[0]>>2)&1)); setchr8((latch[0]>>3)&0xF); } -static DECLFW(TCWrite) +static DECLFW(TCU01Write) { if((A&0x103)==0x102) { @@ -353,11 +379,11 @@ static DECLFW(TCWrite) } } -static void TCU01Reset(void) +static void TCU01Power(void) { latch[0]=0; SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4100,0xFFFF,TCWrite); + SetWriteHandler(0x4100,0xFFFF,TCU01Write); TCU01Synco(); } @@ -369,10 +395,55 @@ static void TCU01Restore(int version) void TCU01_Init(CartInfo *info) { GameStateRestore=TCU01Restore; - info->Power=TCU01Reset; + info->Power=TCU01Power; AddExState(&latch[0], 1, 0, "LATC"); } +//----------------------------------------------- + +static void TCU02Synco() +{ + setprg32(0x8000,0); + setchr8(latch[0]&3); +} + +static DECLFW(TCU02Write) +{ + if((A&0x103)==0x102) + { + latch[0]=V+3; + TCU02Synco(); + } +} + +static DECLFR(TCU02Read) +{ + return (latch[0]&0x3F)|(X.DB&0xC0); +} + +static void TCU02Power(void) +{ + latch[0]=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4100,0x4100,TCU02Read); + SetWriteHandler(0x4100,0xFFFF,TCU02Write); + TCU02Synco(); +} + +static void TCU02Restore(int version) +{ + TCU02Synco(); +} + +void TCU02_Init(CartInfo *info) +{ + GameStateRestore=TCU02Restore; + info->Power=TCU02Power; + AddExState(&latch[0], 1, 0, "LATC"); +} + +// --------------------------------------------- + static DECLFR(TCA01Read) { uint8 ret; @@ -383,7 +454,7 @@ static DECLFR(TCA01Read) return ret; } -static void TCA01Reset(void) +static void TCA01Power(void) { setprg16(0x8000,0); setprg16(0xC000,1); @@ -394,6 +465,6 @@ static void TCA01Reset(void) void TCA01_Init(CartInfo *info) { - info->Power=TCA01Reset; + info->Power=TCA01Power; } diff --git a/src/boards/sheroes.cpp b/src/boards/sheroes.cpp index e23d2307..3b4a1b36 100644 --- a/src/boards/sheroes.cpp +++ b/src/boards/sheroes.cpp @@ -21,8 +21,7 @@ #include "mapinc.h" #include "mmc3.h" -//mbg 7/23/06 todo CaH4e3 - should this have been declared here? its in mmc3.cpp also -//static uint8 *CHRRAM; +static uint8 *CHRRAM; static uint8 tekker; static void MSHCW(uint32 A, uint8 V) diff --git a/src/boards/sl1632.cpp b/src/boards/sl1632.cpp index fee5552b..bb698466 100644 --- a/src/boards/sl1632.cpp +++ b/src/boards/sl1632.cpp @@ -22,7 +22,7 @@ #include "mmc3.h" // brk is a system call in *nix, and is an illegal variable name - soules -static uint8 chrcmd[8], prg0, prg1, bbrk, latc, mirr; +static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; static SFORMAT StateRegs[]= { {chrcmd, 8, "CHRCMD"}, @@ -30,16 +30,17 @@ static SFORMAT StateRegs[]= {&prg1, 1, "PRG1"}, {&bbrk, 1, "BRK"}, {&mirr, 1, "MIRR"}, + {&swap, 1, "SWAP"}, {0} }; static void Sync(void) { + int i; setprg8(0x8000,prg0); setprg8(0xA000,prg1); setprg8(0xC000,~1); setprg8(0xE000,~0); - int i; for(i=0; i<8; i++) setchr1(i<<10,chrcmd[i]); setmirror(mirr^1); @@ -63,19 +64,16 @@ static void UNLSL1632CW(uint32 A, uint8 V) static DECLFW(UNLSL1632CMDWrite) { - if((A&0xA131)==0xA131) + if(A==0xA131) { bbrk=V; - latc = bbrk; } if(bbrk&2) { FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); if(A<0xC000) - { MMC3_CMDWrite(A,V); - } else MMC3_IRQWrite(A,V); } @@ -113,7 +111,7 @@ static void UNLSL1632Power(void) { GenMMC3Power(); SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,UNLSL1632CMDWrite); + SetWriteHandler(0x4100,0xFFFF,UNLSL1632CMDWrite); } void UNLSL1632_Init(CartInfo *info) diff --git a/src/boards/smb2j.cpp b/src/boards/smb2j.cpp new file mode 100644 index 00000000..83cc30ef --- /dev/null +++ b/src/boards/smb2j.cpp @@ -0,0 +1,96 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2007 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * Super Mario Bros 2 J alt version + * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present + */ + +#include "mapinc.h" + +static uint8 prg, IRQa; +static uint16 IRQCount; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "PRG"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setprg4r(1,0x5000,1); + setprg8r(1,0x6000,1); + setprg32(0x8000,prg); + setchr8(0); +} + +static DECLFW(UNLSMB2JWrite) +{ + if(A==0x4022) + { + prg=V&1; + Sync(); + } + if(A==0x4122) + { + IRQa=V; + IRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } +} + +static void UNLSMB2JPower(void) +{ + prg=~0; + Sync(); + SetReadHandler(0x5000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0xffff,UNLSMB2JWrite); +} + +static void UNLSMB2JReset(void) +{ + prg=~0; + Sync(); +} + +static void UNLSMB2JIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a*3; + if((IRQCount>>12)==IRQa) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLSMB2J_Init(CartInfo *info) +{ + info->Reset=UNLSMB2JReset; + info->Power=UNLSMB2JPower; + MapIRQHook=UNLSMB2JIRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/boards/super24.cpp b/src/boards/super24.cpp index 7d50d754..745e723e 100644 --- a/src/boards/super24.cpp +++ b/src/boards/super24.cpp @@ -21,8 +21,7 @@ #include "mapinc.h" #include "mmc3.h" -//mbg 7/23/06 todo CaH4e3 - should this have been declared here? its in mmc3.cpp also -//static uint8 *CHRRAM = NULL; +static uint8 *CHRRAM = NULL; static int masko8[8]={63,31,15,1,3,0,0,0}; static void Super24PW(uint32 A, uint8 V) diff --git a/src/boards/t-227-1.cpp b/src/boards/t-227-1.cpp new file mode 100644 index 00000000..9cadfd48 --- /dev/null +++ b/src/boards/t-227-1.cpp @@ -0,0 +1,116 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2008 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +// T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 reset_flag = 0x07; + +static void BMCT2271CW(uint32 A, uint8 V) +{ + uint32 va = V; + if(EXPREGS[0]&0x20) + { + va|=0x200; + va|=(EXPREGS[0]&0x10)<<4; + } + else + { + va&=0x7F; + va|=(EXPREGS[0]&0x18)<<4; + } + setchr1(A,va); +} + +static void BMCT2271PW(uint32 A, uint8 V) +{ + uint32 va = V & 0x3F; + if(EXPREGS[0]&0x20) + { + va&=0x1F; + va|=0x40; + va|=(EXPREGS[0]&0x10)<<1; + } + else + { + va&=0x0F; + va|=(EXPREGS[0]&0x18)<<1; + } + switch(EXPREGS[0]&3) + { + case 0x00: setprg8(A,va); break; + case 0x02: + { + va=(va&0xFD)|((EXPREGS[0]&4)>>1); + if(A<0xC000) + { + setprg16(0x8000,va >> 1); + setprg16(0xC000,va >> 1); + } + break; + } + case 0x01: + case 0x03: if(A<0xC000) setprg32(0x8000,va >> 2); break; + } + +} + +static DECLFW(BMCT2271LoWrite) +{ + if(!(EXPREGS[0]&0x80)) + EXPREGS[0] = A & 0xFF; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(BMCT2271HiRead) +{ + uint32 av = A; + if(EXPREGS[0]&0x40) av = (av & 0xFFF0)|reset_flag; + return CartBR(av); +} + +static void BMCT2271Reset(void) +{ + EXPREGS[0] = 0x00; + reset_flag++; + reset_flag&=0x0F; + MMC3RegReset(); +} + +static void BMCT2271Power(void) +{ + EXPREGS[0] = 0x00; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,BMCT2271LoWrite); + SetReadHandler(0x8000,0xFFFF,BMCT2271HiRead); +} + +void BMCT2271_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, 0); + pwrap=BMCT2271PW; + cwrap=BMCT2271CW; + info->Power=BMCT2271Power; + info->Reset=BMCT2271Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} diff --git a/src/boards/tf-1201.cpp b/src/boards/tf-1201.cpp new file mode 100644 index 00000000..fc5c73b1 --- /dev/null +++ b/src/boards/tf-1201.cpp @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2005 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Lethal Weapon (VRC4 mapper) + */ + +#include "mapinc.h" + +static uint8 prg0, prg1, mirr, swap; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[]= +{ + {&prg0, 1, "PRG0"}, + {&prg0, 1, "PRG1"}, + {&mirr, 1, "MIRR"}, + {&swap, 1, "SWAP"}, + {chr, 8, "CHR"}, + {&IRQCount, 1, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void SyncPrg(void) +{ + if(swap&3) + { + setprg8(0x8000,~1); + setprg8(0xC000,prg0); + } + else + { + setprg8(0x8000,prg0); + setprg8(0xC000,~1); + } + setprg8(0xA000,prg1); + setprg8(0xE000,~0); +} + +static void SyncChr(void) +{ + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); + setmirror(mirr^1); +} + +static void StateRestore(int version) +{ + SyncPrg(); + SyncChr(); +} + +static DECLFW(UNLTF1201Write) +{ + A=(A&0xF003)|((A&0xC)>>2); + if((A>=0xB000)&&(A<=0xE003)) + { + int ind=(((A>>11)-6)|(A&1))&7; + int sar=((A&2)<<1); + chr[ind]=(chr[ind]&(0xF0>>sar))|((V&0x0F)<Power=UNLTF1201Power; + GameHBIRQHook=UNLTF1201IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/src/drivers/win/afxres.h b/src/drivers/win/afxres.h new file mode 100644 index 00000000..91e7f495 --- /dev/null +++ b/src/drivers/win/afxres.h @@ -0,0 +1,23 @@ +#ifndef _AFXRES_H +#define _AFXRES_H +#if __GNUC__ >= 3 +#pragma GCC system_header +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _WINDOWS_H +#include +#endif + +/* IDC_STATIC is documented in winuser.h, but not defined. */ +#ifndef IDC_STATIC +#define IDC_STATIC (-1) +#endif + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/fceu.cpp b/src/fceu.cpp index 5bde6692..6ab4c6d9 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -798,9 +798,9 @@ void FCEUI_SetGameGenie(bool a) FSettings.GameGenie = a; } -void FCEUI_SetSnapName(bool a) +void FCEUI_SetSnapName(int a) { - FSettings.SnapName= a; + FSettings.SnapName = a; } int32 FCEUI_GetDesiredFPS(void) diff --git a/src/fceu.h b/src/fceu.h index 9d1bfaa5..d435fe59 100644 --- a/src/fceu.h +++ b/src/fceu.h @@ -87,7 +87,7 @@ typedef struct { int UsrFirstSLine[2]; int UsrLastSLine[2]; - bool SnapName; + int SnapName; uint32 SndRate; int soundq; int lowpass; diff --git a/src/ines-correct.h b/src/ines-correct.h index 1001c5ec..1fa61af7 100644 --- a/src/ines-correct.h +++ b/src/ines-correct.h @@ -1,7 +1,12 @@ {0x9cbadc25,5,8}, /* JustBreed */ {0x6e68e31a,16,8}, /* Dragon Ball 3*/ + {0xbfc7a2e9,16,8}, + {0x33b899c9,16,-1}, /* Dragon Ball - Dai Maou Fukkatsu (J) [!] */ {0x3f15d20d,153,8}, /* Famicom Jump 2 */ +// {0xb049a8c4,153,-1}, /* SD Gundam Gaiden - Knight Gundam Monogatari 2 - Hikari no Kishi (J) [!] */ +// NOT 16, since uses WRAM but 8000-FFFF address range for bankswitching, + {0x983d8175,157,8}, /* Datach Battle Rush */ {0x894efdbc,157,8}, /* Datach Crayon Shin Chan */ {0x19e81461,157,8}, /* Datach DBZ */ @@ -17,16 +22,17 @@ {0x063b1151,209,-1}, /* Power Rangers 4 */ {0xdd8ced31,209,-1}, /* Power Rangers 3 */ - {0x0c47946d,210,-1}, /* Chibi Maruko Chan */ - {0xbd523011,210,-1}, /* Dream Master */ - {0xc247cc80,210,-1}, /* Family Circuit '91 */ - {0x6ec51de5,210,-1}, /* Famista '92 */ - {0xadffd64f,210,-1}, /* Famista '93 */ - {0x429103c9,210,-1}, /* Famista '94 */ - {0x81b7f1a8,210,-1}, /* Heisei Tensai Bakabon */ - {0x2447e03b,210,-1}, /* Top Striker */ - {0x1dc0f740,210,-1}, /* Wagyan Land 2 */ - {0xd323b806,210,-1}, /* Wagyan Land 3 */ + {0x0c47946d,210,1}, /* Chibi Maruko Chan */ + {0xbd523011,210,0}, /* Dream Master */ + {0xc247cc80,210,1}, /* Family Circuit '91 */ + {0x6ec51de5,210,1}, /* Famista '92 */ + {0xadffd64f,210,1}, /* Famista '93 */ + {0x429103c9,210,1}, /* Famista '94 */ + {0x81b7f1a8,210,1}, /* Heisei Tensai Bakabon */ + {0x2447e03b,210,1}, /* Top Striker */ + {0x1dc0f740,210,1}, /* Wagyan Land 2 */ + {0xd323b806,210,1}, /* Wagyan Land 3 */ + {0x07eb2c12,208,-1}, /* Street Fighter IV */ {0x96ce586e,189,8}, /* Street Fighter 2 YOKO */ {0x7678f1d5,207,8}, /* Fudou Myouou Den */ @@ -90,9 +96,9 @@ {0xbb7c5f7a,89,8}, /* Mito Koumon or something similar */ /* Probably a Namco MMC3-workalike */ -{0xa5e6baf9,4,1|4}, /* Dragon Slayer 4 */ -{0xe40b4973,4,1|4}, /* Metro Cross */ -{0xd97c31b0,4,1|4}, /* Rasaaru Ishii no Childs Quest */ +//{0xa5e6baf9,4,1|4}, /* Dragon Slayer 4 */ +//{0xe40b4973,4,1|4}, /* Metro Cross */ +//{0xd97c31b0,4,1|4}, /* Rasaaru Ishii no Childs Quest */ {0x84382231,9,0}, /* Punch Out (J) */ @@ -163,6 +169,7 @@ {0xd26efd78,66,1}, /* SMB Duck Hunt */ {0x811f06d9,66,1}, /* Dragon Power */ {0x3293afea,140,1}, /* Mississippi Satsujin Jiken */ +{0xe46b1c5d,140,1}, /* Mississippi Satsujin Jiken */ {0xe84274c5,66,1}, /* "" "" */ {0x9552e8df,66,1}, /* Dragon Ball */ @@ -206,6 +213,8 @@ {0xd5224fde,195,-1},/* Crystalis (c) */ {0x1bc0be6c,195,-1},/* Captain Tsubasa Vol 2 - Super Striker (C) */ {0x33c5df92,195,-1}, + {0xb616885c,195,0}, /* CHaos WOrld (Ch)*/ + {0x7f3dbf1b,195,0}, {0xdd431ba7,198,-1},/* Tenchi wo kurau 2 (c) */ {0x28192599,198,-1}, {0x700705f4,198,-1}, @@ -216,7 +225,6 @@ {0xed481b7c,199,-1},/* Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) */ {0x44c20420,199,-1},/* San Guo Zhi 2 (C) */ - {0x1f1326d4,218,-1}, {0xa1dc16c0,116,-1}, {0xcc868d4e,149,-1}, /* 16 Mahjong [p1][!] */ @@ -225,11 +233,20 @@ {0xa62b79e1,146,-1}, /* Side Winder (HES) [!] */ {0x73fb55ac,150,-1}, /* 2-in-1 Cosmo Cop + Cyber Monster (Sachen) [!] */ {0xddcbda16,150,-1}, /* 2-in-1 Tough Cop + Super Tough Cop (Sachen) [!] */ + {0x47918d84,150,-1}, /* auto-upturn */ {0x29582ca1,150,-1}, {0x40dbf7a2,150,-1}, {0x5aefbc94,133,-1}, /* Jovial Race (Sachen) [a1][!] */ + {0x58152b42,160,1}, /* Pipe 5 (Sachen) */ {0x22d6d5bd,4,1}, {0x6a03d3f3,114,-1}, + {0x02c41438,179,-1}, /* Xing He Zhan Shi (C) */ + + {0x0da5e32e,101,-1}, /* new Uruusey Yatsura */ + {0x4f2f1846,-1,1}, /* Famista '89 - Kaimaku Han!! (J) */ + {0x6c71feae,45,-1}, /* Kunio 8-in-1 */ +// {0xbdbe3c96,238,-1}, /* Contra Fighter iNES version */ + {0,-1,-1} diff --git a/src/ines.cpp b/src/ines.cpp index 24e2227c..ff50a8c6 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -547,6 +547,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) // ROM_size = head.ROM_size; VROM_size = head.VROM_size; + ROM_size=uppow2(ROM_size); if(VROM_size) @@ -620,9 +621,9 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) ResetExState(0,0); SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0); - SetupCartPRGMapping(1,WRAM,8192,1); +// SetupCartPRGMapping(1,WRAM,8192,1); - FCEU_fread(ROM,0x4000,head.ROM_size,fp); + FCEU_fread(ROM,0x4000,ROM_size,fp); if(VROM_size) FCEU_fread(VROM,0x2000,head.VROM_size,fp); @@ -643,7 +644,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) iNESCart.CRC32=iNESGameCRC32; FCEU_printf(" PRG ROM: %3d x 16KiB\n CHR ROM: %3d x 8KiB\n ROM CRC32: 0x%08lx\n", - head.ROM_size,head.VROM_size,iNESGameCRC32); + ROM_size,head.VROM_size,iNESGameCRC32); { int x; @@ -740,7 +741,7 @@ int iNesSave(){ fwrite(trainerpoo,512,1,fp); } - fwrite(ROM,0x4000,head.ROM_size,fp); + fwrite(ROM,0x4000,ROM_size,fp); if(head.VROM_size)fwrite(VROM,0x2000,head.VROM_size,fp); fclose(fp); @@ -888,15 +889,15 @@ void (*MapInitTab[256])(void)= 0, 0, //Mapper13_init, 0, - Mapper15_init, - Mapper16_init, + 0, //Mapper15_init, + 0, //Mapper16_init, Mapper17_init, Mapper18_init, 0, 0, Mapper21_init, Mapper22_init, - Mapper23_init, + 0, //Mapper23_init, Mapper24_init, Mapper25_init, Mapper26_init, @@ -941,7 +942,7 @@ void (*MapInitTab[256])(void)= Mapper65_init, 0,//Mapper66_init, Mapper67_init, - Mapper68_init, + 0,//Mapper68_init, Mapper69_init, 0,//Mapper70_init, Mapper71_init, @@ -1026,7 +1027,7 @@ void (*MapInitTab[256])(void)= 0, Mapper151_init, 0, //Mapper152_init, - Mapper153_init, + 0, //Mapper153_init, 0, //Mapper154_init, 0, Mapper156_init, @@ -1141,12 +1142,6 @@ static DECLFR(AWRAM) return WRAM[A-0x6000]; } -#ifdef DEBUG_MAPPER -static DECLFW(WriteHandler) -{ - FCEU_printf("$%04x:$%02x\n",A,V); -} -#endif void (*MapStateRestore)(int version); void iNESStateRestore(int version) @@ -1186,21 +1181,18 @@ static void iNESPower(void) MapStateRestore=0; setprg8r(1,0x6000,0); + SetReadHandler(0x6000,0x7FFF,AWRAM); SetWriteHandler(0x6000,0x7FFF,BWRAM); FCEU_CheatAddRAM(8,0x6000,WRAM); - /* - #ifdef DEBUG_MAPPER - if(type==0) SetWriteHandler(0x4020,0xFFFF,WriteHandler); - #endif - */ + /* This statement represents atrocious code. I need to rewrite all of the iNES mapper code... */ IRQCount=IRQLatch=IRQa=0; if(head.ROM_type&2) - memset(GameMemBlock+8192,0,131072-8192); + memset(GameMemBlock+8192,0,sizeof(GameMemBlock)-8192); else - memset(GameMemBlock,0,131072); + memset(GameMemBlock,0,sizeof(GameMemBlock)); NONE_init(); ResetExState(0,0); @@ -1209,7 +1201,6 @@ static void iNESPower(void) AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); AddExState(WRAM, 8192, 0, "WRAM"); - if(type==19 || type==6 || type==69 || type==85 || type==96) AddExState(MapperExRAM, 32768, 0, "MEXR"); if((!VROM_size || type==6 || type==19) && (type!=13 && type!=96)) @@ -1247,70 +1238,7 @@ typedef struct { int number; void (*init)(CartInfo *); } BMAPPING; -/* -static BMAPPING bmap[] = { -{1, Mapper1_Init}, -{2, UNROM_Init}, -{3, CNROM_Init}, -{4, Mapper4_Init}, -{5, Mapper5_Init}, -{12, Mapper12_Init}, -{13, CPROM_Init}, -{19, Mapper19_Init}, -{44, Mapper44_Init}, -{45, Mapper45_Init}, -{47, Mapper47_Init}, -{49, Mapper49_Init}, -{52, Mapper52_Init}, -{74, Mapper74_Init}, -{90, Mapper90_Init}, -{95, Mapper95_Init}, -{105, Mapper105_Init}, -{112, Mapper112_Init}, -{114, Mapper114_Init}, -{115, Mapper115_Init}, -{116, Mapper116_Init}, -{118, Mapper118_Init}, -{119, Mapper119_Init}, -{133, SA72008_Init}, -{137, S8259D_Init}, -{138, S8259B_Init}, -{139, S8259C_Init}, -{141, S8259A_Init}, -{143, TCA01_Init}, -{145, SA72007_Init}, -{146, SA0161M_Init}, -{147, TCU01_Init}, -{148, SA0037_Init}, -{149, SA0036_Init}, -{150, S74LS374N_Init}, -{155, Mapper155_Init}, -{160, Mapper90_Init}, -{163, Mapper163_Init}, -{164, Mapper164_Init}, -{165, Mapper165_Init}, -{182, Mapper182_Init}, -{183, Mapper183_Init}, -{186, Mapper186_Init}, -{187, Mapper187_Init}, -{188, Mapper188_Init}, -{191, Mapper191_Init}, -{205, Mapper205_Init}, -{206, DEIROM_Init}, -{208, Mapper208_Init}, -{209, Mapper209_Init}, -{210, Mapper210_Init}, -{215, Mapper215_Init}, -{216, Mapper216_Init}, -{217, Mapper217_Init}, -{243, S74LS374NA_Init}, -{245, Mapper245_Init}, -{249, Mapper249_Init}, -{250, Mapper250_Init}, -{254, Mapper254_Init}, -{ 0, 0} -}; -*/ + static BMAPPING bmap[] = { {0, NROM_Init}, {1, Mapper1_Init}, @@ -1322,8 +1250,13 @@ static BMAPPING bmap[] = { {11, Mapper11_Init}, {12, Mapper12_Init}, {13, CPROM_Init}, + {15, Mapper15_Init}, + {16, Mapper16_Init}, {19, Mapper19_Init}, + {23, Mapper23_Init}, + {36, Mapper36_Init}, // TXC Policeman {37, Mapper37_Init}, + {38, Mapper38_Init}, // Bit Corp. Crime Busters {43, Mapper43_Init}, {44, Mapper44_Init}, {45, Mapper45_Init}, @@ -1334,6 +1267,7 @@ static BMAPPING bmap[] = { {58, BMCGK192_Init}, {60, BMCD1038_Init}, {66, MHROM_Init}, + {68, Mapper68_Init}, {70, Mapper70_Init}, {74, Mapper74_Init}, {78, Mapper78_Init}, @@ -1343,23 +1277,34 @@ static BMAPPING bmap[] = { {93, SUNSOFT_UNROM_Init}, {94, Mapper94_Init}, {95, Mapper95_Init}, + {101, Mapper101_Init}, + {103, Mapper103_Init}, {105, Mapper105_Init}, + {106, Mapper106_Init}, {107, Mapper107_Init}, + {108, Mapper108_Init}, {112, Mapper112_Init}, {113, Mapper113_Init}, {114, Mapper114_Init}, {115, Mapper115_Init}, {116, Mapper116_Init}, +// {116, UNLSL1632_Init}, {117, Mapper117_Init}, {118, TKSROM_Init}, {119, Mapper119_Init}, + {120, Mapper120_Init}, + {121, Mapper121_Init}, + {123, UNLH2288_Init}, {132, UNL22211_Init}, {133, SA72008_Init}, + {134, Mapper134_Init}, + {136, TCU02_Init}, {137, S8259D_Init}, {138, S8259B_Init}, {139, S8259C_Init}, {140, Mapper140_Init}, {141, S8259A_Init}, + {142, UNLKS7032_Init}, {143, TCA01_Init}, {144, Mapper144_Init}, {145, SA72007_Init}, @@ -1369,12 +1314,20 @@ static BMAPPING bmap[] = { {149, SA0036_Init}, {150, S74LS374N_Init}, {152, Mapper152_Init}, + {153, Mapper153_Init}, {154, Mapper154_Init}, {155, Mapper155_Init}, - {160, Mapper90_Init}, + {160, SA009_Init}, {163, Mapper163_Init}, {164, Mapper164_Init}, {165, Mapper165_Init}, +// {169, Mapper169_Init}, + {171, Mapper171_Init}, + {172, Mapper172_Init}, + {173, Mapper173_Init}, + {177, Mapper177_Init}, + {178, Mapper178_Init}, + {179, Mapper179_Init}, {180, Mapper180_Init}, {181, Mapper181_Init}, {182, Mapper182_Init}, @@ -1389,6 +1342,8 @@ static BMAPPING bmap[] = { {192, Mapper192_Init}, {194, Mapper194_Init}, {195, Mapper195_Init}, + {196, Mapper196_Init}, + {197, Mapper197_Init}, {198, Mapper198_Init}, {199, Mapper199_Init}, {200, Mapper200_Init}, @@ -1401,15 +1356,20 @@ static BMAPPING bmap[] = { {215, Mapper215_Init}, {216, Mapper216_Init}, {217, Mapper217_Init}, + {219, UNLA9746_Init}, - {218, UNLA9711_Init}, - {219, UNLSL1632_Init}, - {220, UNLCN22M_Init}, - {221, BMCFK23C_Init}, - +// {220, BMCFK23C_Init}, +// {220, UNL3DBlock_Init}, +// {220, UNLTF1201_Init}, +// {220, TCU02_Init}, +// {220, UNLCN22M_Init}, + {220, BMCT2271_Init}, + + {221, UNLN625092_Init}, {222, Mapper222_Init}, {226, Mapper226_Init}, {235, Mapper235_Init}, + {238, UNL6035052_Init}, {240, Mapper240_Init}, {243, S74LS374NA_Init}, {245, Mapper245_Init}, diff --git a/src/ines.h b/src/ines.h index 2623c005..fe8e98e8 100644 --- a/src/ines.h +++ b/src/ines.h @@ -142,15 +142,15 @@ void Mapper10_init(void); void Mapper12_init(void); //void Mapper13_init(void); void Mapper14_init(void); -void Mapper15_init(void); -void Mapper16_init(void); +//void Mapper15_init(void); +//void Mapper16_init(void); void Mapper17_init(void); void Mapper18_init(void); void Mapper19_init(void); void Mapper20_init(void); void Mapper21_init(void); void Mapper22_init(void); -void Mapper23_init(void); +//void Mapper23_init(void); void Mapper24_init(void); void Mapper25_init(void); void Mapper26_init(void); @@ -165,8 +165,8 @@ void Mapper34_init(void); void Mapper35_init(void); void Mapper36_init(void); //void Mapper37_init(void); -void Mapper38_init(void); -void Mapper39_init(void); +//void Mapper38_init(void); +//void Mapper39_init(void); void Mapper40_init(void); void Mapper41_init(void); void Mapper42_init(void); @@ -192,7 +192,7 @@ void Mapper64_init(void); void Mapper65_init(void); //void Mapper66_init(void); void Mapper67_init(void); -void Mapper68_init(void); +//void Mapper68_init(void); void Mapper69_init(void); //void Mapper70_init(void); void Mapper71_init(void); @@ -223,12 +223,12 @@ void Mapper97_init(void); void Mapper98_init(void); void Mapper99_init(void); void Mapper100_init(void); -void Mapper101_init(void); -void Mapper103_init(void); +//void Mapper101_init(void); +//void Mapper103_init(void); void Mapper104_init(void); -void Mapper106_init(void); +//void Mapper106_init(void); //void Mapper107_init(void); -void Mapper108_init(void); +//void Mapper108_init(void); void Mapper109_init(void); void Mapper110_init(void); void Mapper111_init(void); @@ -236,8 +236,8 @@ void Mapper111_init(void); void Mapper115_init(void); void Mapper116_init(void); //void Mapper117_init(void); -void Mapper120_init(void); -void Mapper121_init(void); +//void Mapper120_init(void); +//void Mapper121_init(void); void Mapper122_init(void); void Mapper123_init(void); void Mapper124_init(void); @@ -248,20 +248,20 @@ void Mapper129_init(void); void Mapper130_init(void); void Mapper131_init(void); void Mapper132_init(void); -void Mapper134_init(void); +//void Mapper134_init(void); void Mapper135_init(void); void Mapper136_init(void); void Mapper137_init(void); void Mapper139_init(void); //void Mapper140_init(void); void Mapper141_init(void); -void Mapper142_init(void); +//void Mapper142_init(void); void Mapper143_init(void); //void Mapper144_init(void); void Mapper150_init(void); void Mapper151_init(void); //void Mapper152_init(void); -void Mapper153_init(void); +//void Mapper153_init(void); void Mapper154_init(void); void Mapper156_init(void); void Mapper157_init(void); @@ -273,17 +273,17 @@ void Mapper162_init(void); void Mapper166_init(void); void Mapper167_init(void); void Mapper168_init(void); -void Mapper169_init(void); +//void Mapper169_init(void); void Mapper170_init(void); -void Mapper171_init(void); -void Mapper172_init(void); -void Mapper173_init(void); +//void Mapper171_init(void); +//void Mapper172_init(void); +//void Mapper173_init(void); void Mapper174_init(void); void Mapper175_init(void); void Mapper176_init(void); -void Mapper177_init(void); -void Mapper178_init(void); -void Mapper179_init(void); +//void Mapper177_init(void); +//void Mapper178_init(void); +//void Mapper179_init(void); //void Mapper180_init(void); //void Mapper181_init(void); //void Mapper184_init(void); @@ -293,8 +293,8 @@ void Mapper179_init(void); void Mapper193_init(void); //void Mapper194_init(void); //void Mapper195_init(void); -void Mapper196_init(void); -void Mapper197_init(void); +//void Mapper196_init(void); +//void Mapper197_init(void); //void Mapper198_init(void); void Mapper199_init(void); //void Mapper200_init(void); @@ -354,8 +354,13 @@ void Mapper4_Init(CartInfo *); void Mapper5_Init(CartInfo *); void Mapper11_Init(CartInfo *); void Mapper12_Init(CartInfo *); +void Mapper15_Init(CartInfo *); +void Mapper16_Init(CartInfo *); void Mapper19_Init(CartInfo *); +void Mapper23_Init(CartInfo *); +void Mapper36_Init(CartInfo *); void Mapper37_Init(CartInfo *); +void Mapper38_Init(CartInfo *); void Mapper43_Init(CartInfo *); void Mapper44_Init(CartInfo *); void Mapper45_Init(CartInfo *); @@ -364,6 +369,7 @@ void Mapper49_Init(CartInfo *); void Mapper52_Init(CartInfo *); void Mapper57_Init(CartInfo *); //void Mapper58_Init(CartInfo *); +void Mapper68_Init(CartInfo *); void Mapper70_Init(CartInfo *); void Mapper74_Init(CartInfo *); void Mapper78_Init(CartInfo *); @@ -373,8 +379,12 @@ void Mapper90_Init(CartInfo *); void Mapper93_Init(CartInfo *); void Mapper94_Init(CartInfo *); void Mapper95_Init(CartInfo *); +void Mapper101_Init(CartInfo *); +void Mapper103_Init(CartInfo *); void Mapper105_Init(CartInfo *); +void Mapper106_Init(CartInfo *); void Mapper107_Init(CartInfo *); +void Mapper108_Init(CartInfo *); void Mapper112_Init(CartInfo *); void Mapper113_Init(CartInfo *); void Mapper114_Init(CartInfo *); @@ -383,15 +393,26 @@ void Mapper116_Init(CartInfo *); void Mapper117_Init(CartInfo *); void Mapper118_Init(CartInfo *); void Mapper119_Init(CartInfo *); +void Mapper120_Init(CartInfo *); +void Mapper121_Init(CartInfo *); void Mapper125_Init(CartInfo *); +void Mapper134_Init(CartInfo *); void Mapper140_Init(CartInfo *); void Mapper144_Init(CartInfo *); void Mapper152_Init(CartInfo *); +void Mapper153_Init(CartInfo *); void Mapper154_Init(CartInfo *); void Mapper155_Init(CartInfo *); void Mapper163_Init(CartInfo *); void Mapper164_Init(CartInfo *); void Mapper165_Init(CartInfo *); +//void Mapper169_Init(CartInfo *); +void Mapper171_Init(CartInfo *); +void Mapper172_Init(CartInfo *); +void Mapper173_Init(CartInfo *); +void Mapper177_Init(CartInfo *); +void Mapper178_Init(CartInfo *); +void Mapper179_Init(CartInfo *); void Mapper180_Init(CartInfo *); void Mapper181_Init(CartInfo *); void Mapper182_Init(CartInfo *); @@ -406,6 +427,8 @@ void Mapper191_Init(CartInfo *); void Mapper192_Init(CartInfo *); void Mapper194_Init(CartInfo *); void Mapper195_Init(CartInfo *); +void Mapper196_Init(CartInfo *); +void Mapper197_Init(CartInfo *); void Mapper198_Init(CartInfo *); void Mapper199_Init(CartInfo *); void Mapper200_Init(CartInfo *); diff --git a/src/mappers/16.cpp b/src/mappers/16.cpp index 40de4f8e..2e82b9bb 100644 --- a/src/mappers/16.cpp +++ b/src/mappers/16.cpp @@ -70,7 +70,7 @@ static DECLFW(Mapper16_write) // of it a hack(I think the current PRG block would depend on whatever the // lowest bit of the CHR bank switching register that corresponds to the // last CHR address read). - +/* static void PRGO(void) { uint32 base=(mapbyte1[0]&1)<<4; @@ -110,21 +110,21 @@ static DECLFW(Mapper153_write) IRQLatch|=V<<8; break; } -} +}*/ -void Mapper16_init(void) -{ - MapIRQHook=BandaiIRQHook; - SetWriteHandler(0x6000,0xFFFF,Mapper16_write); -} +//void Mapper16_init(void) +//{ +// MapIRQHook=BandaiIRQHook; +//SetWriteHandler(0x6000,0xFFFF,Mapper16_write); +//} -void Mapper153_init(void) -{ - MapIRQHook=BandaiIRQHook; - SetWriteHandler(0x8000,0xFFFF,Mapper153_write); +//void Mapper153_init(void) +//{ +// MapIRQHook=BandaiIRQHook; +// SetWriteHandler(0x8000,0xFFFF,Mapper153_write); /* This mapper/board seems to have WRAM at $6000-$7FFF, so I'll let the main ines code take care of that memory region. */ -} +//} static uint8 BarcodeData[256]; diff --git a/src/mappers/22.cpp b/src/mappers/22.cpp index 4a080946..93351065 100644 --- a/src/mappers/22.cpp +++ b/src/mappers/22.cpp @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) */ #include "mapinc.h" diff --git a/src/mappers/25.cpp b/src/mappers/25.cpp index 11575539..01e7adda 100644 --- a/src/mappers/25.cpp +++ b/src/mappers/25.cpp @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) */ #include "mapinc.h" diff --git a/src/mappers/33.cpp b/src/mappers/33.cpp index f3362c01..150d2692 100644 --- a/src/mappers/33.cpp +++ b/src/mappers/33.cpp @@ -37,6 +37,7 @@ static DECLFW(Mapper33_write) case 0x8001:ROM_BANK8(0xA000,V); break; case 0x8002:VROM_BANK2(0x0000,V);break; case 0x8003:VROM_BANK2(0x0800,V);break; + case 0xe000:MIRROR_SET((V>>6)&1);break; } } @@ -73,7 +74,7 @@ void Mapper33_init(void) void Mapper48_init(void) { - SetWriteHandler(0x8000,0xffff,Mapper33_write); + SetWriteHandler(0x8000,0xbfff,Mapper33_write); SetWriteHandler(0xc000,0xffff,Mapper48_HiWrite); GameHBIRQHook=heho; is48=1; diff --git a/src/mappers/69.cpp b/src/mappers/69.cpp index 4fb73b37..eac931da 100644 --- a/src/mappers/69.cpp +++ b/src/mappers/69.cpp @@ -52,8 +52,6 @@ static DECLFW(Mapper69_SWH) int x; GameExpSound.Fill=AYSound; GameExpSound.HiFill=AYSoundHQ; - //mbg merge 7/17/06 - //TODO cah4e3 - is this an error? if(FSettings.SndRate) switch(sunindex) { diff --git a/src/mappers/79.cpp b/src/mappers/79.cpp index 9148eae6..094592a1 100644 --- a/src/mappers/79.cpp +++ b/src/mappers/79.cpp @@ -16,6 +16,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * TXC mapper variation, F-15 City War */ #include "mapinc.h" diff --git a/src/mappers/83.cpp b/src/mappers/83.cpp index b9c3ab2e..e17f06f2 100644 --- a/src/mappers/83.cpp +++ b/src/mappers/83.cpp @@ -20,6 +20,7 @@ #include "mapinc.h" +static uint8 is2kbank, isnot2kbank, dipreg; /*void Mapper83_init(void) { @@ -50,6 +51,11 @@ static DECLFR(rdlow) return mapbyte4[A&3]; } +static DECLFR(rd5000) +{ + return dipreg; +} + static void m83prg(void) { ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); @@ -58,19 +64,19 @@ static void m83prg(void) static void m83chr(void) { -// if(0) -// { -// VROM_BANK2(0x0000,mapbyte2[0]); -// VROM_BANK2(0x0800,mapbyte2[1]); -// VROM_BANK2(0x1000,mapbyte2[6]); -// VROM_BANK2(0x1800,mapbyte2[7]); -// } -// else -// { + if(is2kbank&&!isnot2kbank) + { + VROM_BANK2(0x0000,mapbyte2[0]); + VROM_BANK2(0x0800,mapbyte2[1]); + VROM_BANK2(0x1000,mapbyte2[6]); + VROM_BANK2(0x1800,mapbyte2[7]); + } + else + { int x; for(x=0;x<8;x++) VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4)); -// } + } } static DECLFW(Mapper83_write) @@ -78,7 +84,7 @@ static DECLFW(Mapper83_write) //printf("$%04x:$%02x\n",A,V); switch(A) { - case 0x8000: + case 0x8000: is2kbank = 1; case 0xB000: case 0xB0FF: case 0xB1FF: @@ -105,10 +111,10 @@ static DECLFW(Mapper83_write) case 0x8302:ROM_BANK8(0xC000,V);break; case 0x8310:mapbyte2[0]=V;m83chr();break; case 0x8311:mapbyte2[1]=V;m83chr();break; - case 0x8312:mapbyte2[2]=V;m83chr();break; - case 0x8313:mapbyte2[3]=V;m83chr();break; - case 0x8314:mapbyte2[4]=V;m83chr();break; - case 0x8315:mapbyte2[5]=V;m83chr();break; + case 0x8312:mapbyte2[2]=V;isnot2kbank = 1;m83chr();break; // 2 mappers in one :) + case 0x8313:mapbyte2[3]=V;isnot2kbank = 1;m83chr();break; + case 0x8314:mapbyte2[4]=V;isnot2kbank = 1;m83chr();break; + case 0x8315:mapbyte2[5]=V;isnot2kbank = 1;m83chr();break; case 0x8316:mapbyte2[6]=V;m83chr();break; case 0x8317:mapbyte2[7]=V;m83chr();break; case 0x8318:mapbyte1[1]=V;m83prg();break; @@ -117,13 +123,23 @@ static DECLFW(Mapper83_write) } +static void m83Reset(void) +{ + dipreg^=1; +} + void Mapper83_init(void) { + is2kbank = 0; + isnot2kbank = 0; + dipreg = 0; ROM_BANK8(0xc000,0x1e); ROM_BANK8(0xe000,0x1f); MapIRQHook=m83IRQHook; + MapperReset=m83Reset; + SetReadHandler(0x5000,0x5000,rd5000); // title scren dip switch SetReadHandler(0x5100,0x5103,rdlow); SetWriteHandler(0x5100,0x5103,wrlow); SetWriteHandler(0x8000,0xffff,Mapper83_write); diff --git a/src/mappers/simple.cpp b/src/mappers/simple.cpp index da04a13f..25b21aa1 100644 --- a/src/mappers/simple.cpp +++ b/src/mappers/simple.cpp @@ -83,6 +83,10 @@ void Mapper96_init(void) GameStateRestore=M96Sync; } +// DIS23C01 Open Soft, Korea +// Metal Force (K) +// Buzz and Waldog (K) + static DECLFW(M156Write) { if(A>=0xc000 && A<=0xC003) diff --git a/src/unif.cpp b/src/unif.cpp index b0336bb7..0d91c2ef 100644 --- a/src/unif.cpp +++ b/src/unif.cpp @@ -324,9 +324,11 @@ static BMAPPING bmap[] = { { "Sachen-8259D", S8259D_Init,0}, { "Sachen-74LS374N", S74LS374N_Init,0}, { "Sachen-74LS374NA", S74LS374NA_Init,0}, //seems to be custom mapper + { "SA-002", TCU02_Init, 0}, { "SA-016-1M", SA0161M_Init,0}, { "SA-72007", SA72007_Init,0}, { "SA-72008", SA72008_Init,0}, + { "SA-009", SA009_Init,0}, { "SA-0036", SA0036_Init,0}, { "SA-0037", SA0037_Init,0}, { "SA-NROM", TCA01_Init,0}, @@ -360,6 +362,7 @@ static BMAPPING bmap[] = { { "TGROM", TGROM_Init,0}, { "TR1ROM", TFROM_Init,BMCFLAG_FORCE4}, + { "TBROM", TBROM_Init,0}, { "TEROM", TEROM_Init,0}, { "TFROM", TFROM_Init,0}, { "TLROM", TLROM_Init,0}, @@ -371,6 +374,8 @@ static BMAPPING bmap[] = { { "TQROM", TQROM_Init,0}, { "TVROM", TLROM_Init,BMCFLAG_FORCE4}, + { "NTBROM", Mapper68_Init,0}, + { "CPROM", CPROM_Init,BMCFLAG_16KCHRR}, { "CNROM", CNROM_Init,0}, { "NROM", NROM_Init,0 }, //NROM256_Init,0 }, @@ -380,9 +385,12 @@ static BMAPPING bmap[] = { { "RROM-128", NROM_Init,0 }, //NROM128_Init,0 }, { "MHROM", MHROM_Init,0}, { "UNROM", UNROM_Init,0}, + { "UOROM", UNROM_Init,0}, { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0}, { "MARIO1-MALEE2", MALEE_Init,0}, - + { "3D-BLOCK", UNL3DBlock_Init, 0}, + { "SMB2J", UNLSMB2J_Init, 0}, + { "AX5705", UNLAX5705_Init, 0}, { "CC-21", UNLCC21_Init,0}, { "H2288", UNLH2288_Init,0}, @@ -397,6 +405,7 @@ static BMAPPING bmap[] = { { "C-N22M", UNLCN22M_Init,0}, { "EDU2000", UNLEDU2000_Init,0}, { "603-5052", UNL6035052_Init,0}, + { "N625092", UNLN625092_Init,0}, { "Supervision16in1", Supervision16_Init,0}, { "NovelDiamond9999999in1", Novel_Init,0}, { "Super24in1SC03", Super24_Init,0}, @@ -409,14 +418,28 @@ static BMAPPING bmap[] = { { "GK-192", BMCGK192_Init, 0}, { "SuperHIK8in1", Mapper45_Init,0}, { "22211", UNL22211_Init,0}, + { "TF1201", UNLTF1201_Init, 0}, + { "GS-2004", BMCGS2004_Init, 0}, + { "GS-2013", BMCGS2013_Init, 0}, + { "KS7032", UNLKS7032_Init, 0}, + { "T-230", UNLT230_Init, 0}, + { "190in1", BMC190in1_Init, 0}, + { "Ghostbusters63in1", BMCGhostbusters63in1_Init, 0}, + { "BS-5",BMCBS5_Init, 0}, + { "411120-C",BMC411120C_Init, 0}, + { "830118C",BMC830118C_Init, 0}, + { "T-227-1",BMCT2271_Init,0}, { "DREAMTECH01", DreamTech01_Init,0}, { "KONAMI-QTAI", Mapper190_Init,0}, { "TEK90", Mapper90_Init,0}, + { "COPYFAMI_MMC3", MapperCopyFamiMMC3_Init,0}, + {0,0,0} }; + static BFMAPPING bfunc[] = { { "CTRL", CTRL }, { "TVCI", TVCI }, diff --git a/src/unif.h b/src/unif.h index e42e09bb..488bf5f0 100644 --- a/src/unif.h +++ b/src/unif.h @@ -46,7 +46,9 @@ void MALEE_Init(CartInfo *info); void CNROM_Init(CartInfo *info); void CPROM_Init(CartInfo *info); void GNROM_Init(CartInfo *info); +void UNL3DBlock_Init(CartInfo *info); +void TBROM_Init(CartInfo *info); void TEROM_Init(CartInfo *info); void TFROM_Init(CartInfo *info); void TGROM_Init(CartInfo *info); @@ -62,6 +64,7 @@ void DEIROM_Init(CartInfo *info); void TCA01_Init(CartInfo *info); void TCU01_Init(CartInfo *info); +void TCU02_Init(CartInfo *info); void S8259A_Init(CartInfo *info); void S8259B_Init(CartInfo *info); void S8259C_Init(CartInfo *info); @@ -72,6 +75,7 @@ void SA0161M_Init(CartInfo *info); void SA72007_Init(CartInfo *info); void SA72008_Init(CartInfo *info); +void SA009_Init(CartInfo *info); void SA0036_Init(CartInfo *info); void SA0037_Init(CartInfo *info); @@ -89,6 +93,11 @@ void BMCFK23C_Init(CartInfo *info); void BMCD1038_Init(CartInfo *info); void BMCA65AS_Init(CartInfo *info); void BMCGK192_Init(CartInfo *info); +void BMCGS2004_Init(CartInfo *info); +void BMCGS2013_Init(CartInfo *info); +void BMC190in1_Init(CartInfo *info); +void BMCGhostbusters63in1_Init(CartInfo *info); +void BMCBS5_Init(CartInfo *info); void DreamTech01_Init(CartInfo *info); void Mapper190_Init(CartInfo *info); @@ -96,15 +105,27 @@ void UNLCC21_Init(CartInfo *info); void UNLCN22M_Init(CartInfo *info); void UNLSL1632_Init(CartInfo *info); void UNLKOF97_Init(CartInfo *info); -void UNLA9711_Init(CartInfo *info); +void UNLA9746_Init(CartInfo *info); void UNLSHeroes_Init(CartInfo *info); void UNLH2288_Init(CartInfo *info); void UNL8237_Init(CartInfo *info); void UNL8157_Init(CartInfo *info); void UNL22211_Init(CartInfo *info); +void UNLTF1201_Init(CartInfo *info); +void UNLKS7032_Init(CartInfo *info); +void UNLT230_Init(CartInfo *info); +void UNLAX5705_Init(CartInfo *info); void UNLEDU2000_Init(CartInfo *info); void UNL6035052_Init(CartInfo *info); +void UNLN625092_Init(CartInfo *info); +void UNLSMB2J_Init(CartInfo *info); +//void UNL09034A_Init(CartInfo *info); +void BMC411120C_Init(CartInfo *info); +void BMC830118C_Init(CartInfo *info); +void BMCT2271_Init(CartInfo *info); + +void MapperCopyFamiMMC3_Init(CartInfo *info); extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM // bank switcherooing with certain boards...