From: notaz Date: Sun, 30 Sep 2012 00:28:18 +0000 (+0300) Subject: merge mappers from FCEU-mm X-Git-Tag: r2~5 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=fceu.git;a=commitdiff_plain;h=43725da7349c85fa13e828fdbf20cc7ac8d298d6 merge mappers from FCEU-mm the CaH4e3's FCEU Ultra fork --- diff --git a/boards/01-222.c b/boards/01-222.c index c0e7320..1ad4080 100644 --- a/boards/01-222.c +++ b/boards/01-222.c @@ -15,8 +15,21 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * TXC mappers + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * TXC mappers, originally much complex banksitching + * + * 01-22111-000 (05-00002-010) (132, 22211) - MGC-001 Qi Wang + * 01-22110-000 (52S ) - MGC-002 2-in-1 Gun + * 01-22111-100 (02-00002-010) (173 ) - MGC-008 Mahjong Block + * (079 ) - MGC-012 Poke Block + * 01-22110-200 (05-00002-010) (036 ) - MGC-014 Strike Wolf + * 01-22000-400 (05-00002-010) (036 ) - MGC-015 Policeman + * 01-22017-000 (05-PT017-080) (189 ) - MGC-017 Thunder Warrior + * 01-22270-000 (05-00002-010) (132, 22211) - MGC-xxx Creatom + * 01-22200-400 (------------) (079 ) - ET.03 F-15 City War + * (172 ) - 1991 Du Ma Racing + * */ #include "mapinc.h" diff --git a/boards/103.c b/boards/103.c index e25f5fc..16eb551 100644 --- a/boards/103.c +++ b/boards/103.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" diff --git a/boards/106.c b/boards/106.c index 638dda9..8958d60 100644 --- a/boards/106.c +++ b/boards/106.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -28,7 +28,7 @@ static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { {&IRQa, 1, "IRQA"}, - {&IRQCount, 4, "IRQCOUNT"}, + {&IRQCount, 4, "IRQC"}, {reg, 16, "REGS"}, {0} }; @@ -84,7 +84,7 @@ static void M106Close(void) WRAM=NULL; } -void M106CpuHook(int a) +void FP_FASTAPASS(1) M106CpuHook(int a) { if(IRQa) { diff --git a/boards/108.c b/boards/108.c index fc3aebd..59d91f2 100644 --- a/boards/108.c +++ b/boards/108.c @@ -15,7 +15,13 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * + * Meikyuu Jin Dababa + * Bubble Bobble Kaiser + * */ #include "mapinc.h" @@ -37,8 +43,8 @@ static void Sync(void) static DECLFW(M108Write) { - reg=V; - Sync(); + reg=V; + Sync(); } static void M108Power(void) @@ -46,7 +52,8 @@ static void M108Power(void) Sync(); SetReadHandler(0x6000,0x7FFF,CartBR); SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8FFF,0x8FFF,M108Write); + SetWriteHandler(0x8000,0x8FFF,M108Write); // regular 108 + SetWriteHandler(0xF000,0xFFFF,M108Write); // simplified Kaiser BB Hack } static void StateRestore(int version) diff --git a/boards/112.c b/boards/112.c index ccfd4f4..daf65ce 100644 --- a/boards/112.c +++ b/boards/112.c @@ -15,8 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * * NTDEC, ASDER games + * */ #include "mapinc.h" diff --git a/boards/116.c b/boards/116.c index 3a21668..09d2a27 100644 --- a/boards/116.c +++ b/boards/116.c @@ -15,8 +15,8 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) * the same as 603-5052 board (TODO: add reading registers, merge) * SL1632 2-in-1 protected board, similar to SL12 (TODO: find difference) @@ -27,38 +27,37 @@ * Kart Fighter (008, Huang-1, GAL dip: W conf.) * Somari (008, C5052-13, GAL dip: P conf., GK2-P/GK2-V maskroms) * Somari (008, Huang-1, GAL dip: W conf., GK1-P/GK1-V maskroms) - * AV Mei Shao Nv Zhan Shi () + * AV Mei Shao Nv Zhan Shi (aka AV Pretty Girl Fighting) (SL-12 PCB, Hunag-1, GAL dip: unk conf. SL-11A/SL-11B maskroms) * Samurai Spirits (Full version) (Huang-1, GAL dip: unk conf. GS-2A/GS-4A maskroms) - * Contra Fighter (603-5052 board, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) + * Contra Fighter (603-5052 PCB, C5052-3, GAL dip: unk conf. SC603-A/SCB603-B maskroms) * */ #include "mapinc.h" -#include "mmc3.h" static uint8 mode; static uint8 vrc2_chr[8], vrc2_prg[2], vrc2_mirr; static uint8 mmc3_regs[10], mmc3_ctrl, mmc3_mirr; -extern uint8 IRQCount,IRQLatch,IRQa; -extern uint8 IRQReload; +static uint8 IRQCount,IRQLatch,IRQa; +static uint8 IRQReload; static uint8 mmc1_regs[4], mmc1_buffer, mmc1_shift; static SFORMAT StateRegs[]= { {&mode, 1, "MODE"}, - {vrc2_chr, 8, "vrch"}, - {vrc2_prg, 2, "vrpr"}, - {&vrc2_mirr, 1, "vrmi"}, - {mmc3_regs, 10, "m3re"}, - {&mmc3_ctrl, 1, "m3ct"}, - {&mmc3_mirr, 1, "m3mi"}, + {vrc2_chr, 8, "VRCC"}, + {vrc2_prg, 2, "VRCP"}, + {&vrc2_mirr, 1, "VRCM"}, + {mmc3_regs, 10, "M3RG"}, + {&mmc3_ctrl, 1, "M3CT"}, + {&mmc3_mirr, 1, "M3MR"}, {&IRQReload, 1, "IRQR"}, {&IRQCount, 1, "IRQC"}, {&IRQLatch, 1, "IRQL"}, {&IRQa, 1, "IRQA"}, - {mmc1_regs, 4, "m1r"}, - {&mmc1_buffer, 1, "m1bf"}, - {&mmc1_shift, 1, "m1mi"}, + {mmc1_regs, 4, "M1RG"}, + {&mmc1_buffer, 1, "M1BF"}, + {&mmc1_shift, 1, "M1MR"}, {0} }; @@ -174,7 +173,7 @@ static void Sync(void) static DECLFW(UNLSL12ModeWrite) { - printf("%04X:%02X\n",A,V); +// FCEU_printf("%04X:%02X\n",A,V); if((A & 0x4100) == 0x4100) { mode = V; if(A&1) { // hacky hacky, there are two configuration modes on SOMARI HUANG-1 PCBs @@ -194,11 +193,7 @@ static DECLFW(UNLSL12ModeWrite) static DECLFW(UNLSL12Write) { - printf("%04X:%02X\n",A,V); - if(A==0xA123) - { - int zzz=9; - } +// FCEU_printf("%04X:%02X\n",A,V); switch(mode & 3) { case 0: { if((A>=0xB000)&&(A<=0xE003)) @@ -272,7 +267,7 @@ static DECLFW(UNLSL12Write) mmc1_buffer = mmc1_shift = 0; switch(n) { case 0: SyncMIR(); - case 2: SyncCHR(); + case 2: SyncCHR(); case 3: case 1: SyncPRG(); } @@ -352,8 +347,3 @@ void UNLSL12_Init(CartInfo *info) GameStateRestore = StateRestore; AddExState(&StateRegs, ~0, 0, 0); } - -void Mapper116_Init(CartInfo *info) -{ - UNLSL12_Init(info); -} diff --git a/boards/117.c b/boards/117.c index b2348f0..61d9519 100644 --- a/boards/117.c +++ b/boards/117.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -28,19 +28,19 @@ static SFORMAT StateRegs[]= {&IRQa, 1, "IRQA"}, {&IRQCount, 1, "IRQC"}, {&IRQLatch, 1, "IRQL"}, - {prgreg, 4, "PREGS"}, - {chrreg, 8, "CREGS"}, + {prgreg, 4, "PREG"}, + {chrreg, 8, "CREG"}, {&mirror, 1, "MREG"}, {0} }; static void Sync(void) { - int i; setprg8(0x8000,prgreg[0]); setprg8(0xa000,prgreg[1]); setprg8(0xc000,prgreg[2]); setprg8(0xe000,prgreg[3]); + int i; for(i=0; i<8; i++) setchr1(i<<10,chrreg[i]); setmirror(mirror^1); diff --git a/boards/120.c b/boards/120.c index ed681b9..cacd122 100644 --- a/boards/120.c +++ b/boards/120.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" @@ -48,8 +51,7 @@ static void M120Power(void) { reg=0; Sync(); - SetReadHandler(0x6000,0x7FFF,CartBR); - SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x6000,0xFFFF,CartBR); SetWriteHandler(0x4100,0x5FFF,M120Write); } diff --git a/boards/121.c b/boards/121.c index 63784f9..eed3007 100644 --- a/boards/121.c +++ b/boards/121.c @@ -15,69 +15,104 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * 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 + * MK4, MK6, A9711 board + * 6035052 seems to be the same too, but with prot array in reverse + * A9746 seems to be the same too, check + * 187 seems to be the same too, check (A98402 board) + * */ #include "mapinc.h" #include "mmc3.h" -static uint8 readbyte = 0; - -static DECLFW(M121Write) +static void Sync() { -// FCEU_printf("write: %04x:%04x\n",A&0xE003,V); - if((A&0xF003)==0x8003) + switch(EXPREGS[5]&0x3F) { -// 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"); + case 0x20: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x29: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x26: EXPREGS[7] = 0; EXPREGS[0]=EXPREGS[6]; break; + case 0x2B: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x2C: EXPREGS[7] = 1; if(EXPREGS[6]) EXPREGS[0]=EXPREGS[6]; break; + case 0x3F: EXPREGS[7] = 1; EXPREGS[0]=EXPREGS[6]; break; + case 0x28: EXPREGS[7] = 0; EXPREGS[1]=EXPREGS[6]; break; + case 0x2A: EXPREGS[7] = 0; EXPREGS[2]=EXPREGS[6]; break; + case 0x2F: break; + default: EXPREGS[5] = 0; break; } +} + +static void M121CW(uint32 A, uint8 V) +{ + if((A&0x1000)==((MMC3_cmd&0x80)<<5)) + setchr1(A,V|0x100); + else + setchr1(A,V); +} + +static void M121PW(uint32 A, uint8 V) +{ + if(EXPREGS[5]&0x3F) + { +// FCEU_printf("prot banks: %02x %02x %02x %02x\n",V,EXPREGS[2],EXPREGS[1],EXPREGS[0]); + setprg8(A,V&0x3F); + setprg8(0xE000,EXPREGS[0]); + setprg8(0xC000,EXPREGS[1]); + setprg8(0xA000,EXPREGS[2]); + } else { -// FixMMC3PRG(MMC3_cmd); - MMC3_CMDWrite(A,V); +// FCEU_printf("gen banks: %04x %02x\n",A,V); + setprg8(A,V&0x3F); + } +} + +static DECLFW(M121Write) +{ +// FCEU_printf("write: %04x:%04x\n",A&0xE003,V); + switch(A&0xE003) + { + case 0x8000: //EXPREGS[5] = 0; +// FCEU_printf("gen: %02x\n",V); + MMC3_CMDWrite(A,V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8001: EXPREGS[6] = ((V&1)<<5)|((V&2)<<3)|((V&4)<<1)|((V&8)>>1)|((V&0x10)>>3)|((V&0x20)>>5); +// FCEU_printf("bank: %02x (%02x)\n",V,EXPREGS[6]); + if(!EXPREGS[7]) Sync(); + MMC3_CMDWrite(A,V); + FixMMC3PRG(MMC3_cmd); + break; + case 0x8003: EXPREGS[5] = V; +// EXPREGS[7] = 0; +// FCEU_printf("prot: %02x\n",EXPREGS[5]); + Sync(); + MMC3_CMDWrite(0x8000,V); + FixMMC3PRG(MMC3_cmd); + break; } } 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) + EXPREGS[4] = 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]; +// FCEU_printf("read: %04x->\n",A,EXPREGS[0]); + return EXPREGS[4]; } static void M121Power(void) { + EXPREGS[5] = 0; GenMMC3Power(); -// Write_IRQFM(0x4017,0x40); SetReadHandler(0x5000,0x5FFF,M121Read); SetWriteHandler(0x5000,0x5FFF,M121LoWrite); SetWriteHandler(0x8000,0x9FFF,M121Write); @@ -86,6 +121,8 @@ static void M121Power(void) void Mapper121_Init(CartInfo *info) { GenMMC3_Init(info, 128, 256, 8, 0); + pwrap=M121PW; + cwrap=M121CW; info->Power=M121Power; - AddExState(EXPREGS, 2, 0, "EXPR"); + AddExState(EXPREGS, 8, 0, "EXPR"); } diff --git a/boards/12in1.c b/boards/12in1.c new file mode 100644 index 0000000..4a10a42 --- /dev/null +++ b/boards/12in1.c @@ -0,0 +1,79 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * 7-in-1 Darkwing Duck, Snake, MagicBlock (PCB marked as "12 in 1") + */ + +#include "mapinc.h" + +static uint8 reg[4]; +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + uint8 bank = (reg[3]&3)<<3; + setchr4(0x0000, (reg[1]>>3)|(bank<<2)); + setchr4(0x1000, (reg[2]>>3)|(bank<<2)); + if(reg[3]&8) + { + setprg32(0x8000,((reg[2]&7)>>1)|bank); + } + else + { + setprg16(0x8000, (reg[1]&7)|bank); + setprg16(0xc000, 7|bank); + } + setmirror(((reg[3]&4)>>2)^1); +} + +static DECLFW(BMC12IN1Write) +{ + switch(A) + { + case 0xafff: reg[0] = V; break; + case 0xbfff: reg[1] = V; break; + case 0xdfff: reg[2] = V; break; + case 0xefff: reg[3] = V; break; + } + Sync(); +} + +static void BMC12IN1Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,BMC12IN1Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC12IN1_Init(CartInfo *info) +{ + info->Power=BMC12IN1Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/15.c b/boards/15.c index 6405afa..b720cee 100644 --- a/boards/15.c +++ b/boards/15.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ @@ -64,7 +64,6 @@ static DECLFW(M15Write) { latchea=A; latched=V; - printf("%04X = %02X\n",A,V); Sync(); } diff --git a/boards/151.c b/boards/151.c new file mode 100644 index 0000000..b4d2fb3 --- /dev/null +++ b/boards/151.c @@ -0,0 +1,64 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 regs[8]; + +static SFORMAT StateRegs[]= +{ + {regs, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x8000,regs[0]); + setprg8(0xA000,regs[2]); + setprg8(0xC000,regs[4]); + setprg8(0xE000,~0); + setchr4(0x0000,regs[6]); + setchr4(0x1000,regs[7]); +} + +static DECLFW(M151Write) +{ + regs[(A >> 12)&7] = V; + Sync(); +} + +static void M151Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M151Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper151_Init(CartInfo *info) +{ + info->Power=M151Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/mappers/156.c b/boards/156.c similarity index 88% rename from mappers/156.c rename to boards/156.c index 8e40a19..06c57c6 100644 --- a/mappers/156.c +++ b/boards/156.c @@ -27,14 +27,14 @@ #include "mapinc.h" static uint8 chrlo[8], chrhi[8], prg, mirr, mirrisused = 0; -// uint8 *WRAM=NULL; +static uint8 *WRAM=NULL; static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { {&prg, 1, "PREG"}, - {chrlo, 8, "CRLO"}, - {chrhi, 8, "CRHI"}, + {chrlo, 8, "CRGL"}, + {chrhi, 8, "CRGH"}, {&mirr, 1, "MIRR"}, {0} }; @@ -77,26 +77,12 @@ static DECLFW(M156Write) } } -static void M1566Reset() -{ - for(int i=0;i<8;i++) - { - chrlo[i]=0; - chrhi[i]=0; - } - prg=0; - mirr=0; - mirrisused = 0; -} - static void M156Power(void) { Sync(); SetReadHandler(0x6000,0xFFFF,CartBR); SetWriteHandler(0x6000,0x7FFF,CartBW); SetWriteHandler(0xC000,0xCFFF,M156Write); - - M1566Reset(); } static void M156Close(void) diff --git a/boards/164.c b/boards/164.c index 22589ec..26cb8bc 100644 --- a/boards/164.c +++ b/boards/164.c @@ -15,55 +15,392 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * It seems that 162/163/164 mappers are the same mapper with just different + * mapper modes enabled or disabled in software or hardware, need more nanjing + * carts */ #include "mapinc.h" -static uint8 cmd, laststrobe, trigger; -static uint8 DRegs[8]; +static uint8 laststrobe, trigger; +static uint8 reg[8]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static void(*WSync)(void); + static SFORMAT StateRegs[]= { - {&cmd, 1, "CMD"}, {&laststrobe, 1, "STB"}, {&trigger, 1, "TRG"}, - {DRegs, 8, "DREG"}, + {reg, 8, "REGS"}, {0} }; +/* +const EEPROM_interface eeprom_interface. = +{ + 9, // address bits 9 + 8, // data bits 8 + "*110", // read 1 10 aaaaaaaaa + "*101", // write 1 01 aaaaaaaaa dddddddd +. "*10000xxxxxxx", // lock 1 00 00xxxxxxx + "*10011xxxxxxx", // unlock 1 00 11xxxxxxx + 1, + 5 +}; + +static const EEPROM_interface *intf; + +static int serial_count = 0; +static u8 serial_buffer[SERIAL_BUFFER_LENGTH]; + +static int eeprom_data_bits; +static int eeprom_clock_count; +static int eeprom_read_address; +static u8 *eeprom_data; + +static int latch = 0; +static int locked = 1; +static int sending = 0; +static int reset_line = ASSERT_LINE; +static int clock_line = ASSERT_LINE; +static int reset_delay; + +void EEPROM_Init(u8 *data, u8 bit) +{ + eeprom_data = data; + if(bit == 8) + intf = &eeprom_interface_93C46_8; + else + intf = &eeprom_interface_93C46_16; +} + +u8 *EEPROM_GetData() +{ + return eeprom_data; +} + +static int EEPROM_command_match(const char *buf, const char *cmd, int len) +{ + if ( cmd == 0 ) return 0; + if ( len == 0 ) return 0; + + for (;len>0;) + { + char b = *buf; + char c = *cmd; + + if ((b==0) || (c==0)) + return (b==c); + + switch ( c ) + { + case '0': + case '1': + if (b != c) return 0; + case 'X': + case 'x': + buf++; + len--; + cmd++; + break; + + case '*': + c = cmd[1]; + switch( c ) + { + case '0': + case '1': + if (b == c) { cmd++; } + else { buf++; len--; } + break; + default: return 0; + } + } + } + return (*cmd==0); +} + +static void EEPROM_write(int bit) +{ + if (serial_count >= SERIAL_BUFFER_LENGTH-1) + { + return; + } + + serial_buffer[serial_count++] = (bit ? '1' : '0'); + serial_buffer[serial_count] = 0; + + if ( (serial_count > intf->address_bits) && + EEPROM_command_match((char*)serial_buffer,intf->cmd_read,(int)strlen((char*)serial_buffer)-intf->address_bits) ) + { + int i,address; + + address = 0; + for (i = serial_count-intf->address_bits;i < serial_count;i++) + { + address <<= 1; + if (serial_buffer[i] == '1') address |= 1; + } + if (intf->data_bits == 16) + eeprom_data_bits = (eeprom_data[2*address+0] << 8) + eeprom_data[2*address+1]; + else + eeprom_data_bits = eeprom_data[address]; + eeprom_read_address = address; + eeprom_clock_count = 0; + sending = 1; + serial_count = 0; + } + else if ( (serial_count > intf->address_bits) && + EEPROM_command_match((char*)serial_buffer,intf->cmd_erase,(int)strlen((char*)serial_buffer)-intf->address_bits) ) + { + int i,address; + + address = 0; + for (i = serial_count-intf->address_bits;i < serial_count;i++) + { + address <<= 1; + if (serial_buffer[i] == '1') address |= 1; + } + + if (locked == 0) + { + if (intf->data_bits == 16) + { + eeprom_data[2*address+0] = 0x00; + eeprom_data[2*address+1] = 0x00; + } + else + eeprom_data[address] = 0x00; + } + else + serial_count = 0; + } + else if ( (serial_count > (intf->address_bits + intf->data_bits)) && + EEPROM_command_match((char*)serial_buffer,intf->cmd_write,(int)strlen((char*)serial_buffer)-(intf->address_bits + intf->data_bits)) ) + { + int i,address,data; + + address = 0; + for (i = serial_count-intf->data_bits-intf->address_bits;i < (serial_count-intf->data_bits);i++) + { + address <<= 1; + if (serial_buffer[i] == '1') address |= 1; + } + data = 0; + for (i = serial_count-intf->data_bits;i < serial_count;i++) + { + data <<= 1; + if (serial_buffer[i] == '1') data |= 1; + } + if (locked == 0) + { + if (intf->data_bits == 16) + { + eeprom_data[2*address+0] = data >> 8; + eeprom_data[2*address+1] = data & 0xff; + } + else + eeprom_data[address] = data; + } + else + serial_count = 0; + } + else if ( EEPROM_command_match((char*)serial_buffer,intf->cmd_lock,(int)strlen((char*)serial_buffer)) ) + { + locked = 1; + serial_count = 0; + } + else if ( EEPROM_command_match((char*)serial_buffer,intf->cmd_unlock,(int)strlen((char*)serial_buffer)) ) + { + locked = 0; + serial_count = 0; + } +} + +static void EEPROM_reset() +{ + serial_count = 0; + sending = 0; + reset_delay = intf->reset_delay; +} + +void EEPROM_set_cs_line(int state) +{ + reset_line = state; + + if (reset_line != CLEAR_LINE) + EEPROM_reset(); +} + +void EEPROM_set_clock_line(int state) +{ + if (state == PULSE_LINE || (clock_line == CLEAR_LINE && state != CLEAR_LINE)) + { + if (reset_line == CLEAR_LINE) + { + if (sending) + { + if (eeprom_clock_count == intf->data_bits) + { + if(intf->enable_multi_read) + { + eeprom_read_address = (eeprom_read_address + 1) & ((1 << intf->address_bits) - 1); + if (intf->data_bits == 16) + eeprom_data_bits = (eeprom_data[2*eeprom_read_address+0] << 8) + eeprom_data[2*eeprom_read_address+1]; + else + eeprom_data_bits = eeprom_data[eeprom_read_address]; + eeprom_clock_count = 0; + } + else + { + sending = 0; + } + } + eeprom_data_bits = (eeprom_data_bits << 1) | 1; + eeprom_clock_count++; + } + else + EEPROM_write(latch); + } + } + + clock_line = state; +} + + +void EEPROM_write_bit(int bit) +{ + latch = bit; +} + +int EEPROM_read_bit(void) +{ + int res; + + if (sending) + res = (eeprom_data_bits >> intf->data_bits) & 1; + else + { + if (reset_delay > 0) + { + reset_delay--; + res = 0; + } + else + res = 1; + } + + return res; +} +*/ + static void Sync(void) { - setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF)); + setprg8r(0x10,0x6000,0); + setprg32(0x8000,(reg[0]<<4)|(reg[1]&0xF)); + setchr8(0); } static void StateRestore(int version) { - Sync(); + WSync(); } static DECLFR(ReadLow) { switch (A&0x7700) { - case 0x5100: return DRegs[2]; break; + case 0x5100: return reg[2]|reg[0]|reg[1]|reg[3]^0xff; break; case 0x5500: if(trigger) - return DRegs[2]; + return reg[2]|reg[1]; // Lei Dian Huang Bi Ka Qiu Chuan Shuo (NJ046) may broke other games else return 0; } return 4; } +static void M163HB(void) +{ + if(reg[1]&0x80) + { + if(scanline==239) + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } + else if(scanline==127) + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } +/* + if(scanline>=127) // Hu Lu Jin Gang (NJ039) (Ch) [!] don't like it + { + setchr4(0x0000,1); + setchr4(0x1000,1); + } + else + { + setchr4(0x0000,0); + setchr4(0x1000,0); + } +*/ + } +} + static DECLFW(Write) { switch (A&0x7300) { - case 0x5100: DRegs[0]=V; Sync(); break; - case 0x5000: DRegs[1]=V; Sync(); break; - case 0x5300: DRegs[2]=V; break; + case 0x5100: reg[0]=V; WSync(); break; + case 0x5000: reg[1]=V; WSync(); break; + case 0x5300: reg[2]=V; break; + case 0x5200: reg[3]=V; WSync(); break; } } +static void Power(void) +{ + memset(reg,0,8); + reg[1]=0xFF; + SetWriteHandler(0x5000,0x5FFF,Write); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); +} + +static void Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +void Mapper164_Init(CartInfo *info) +{ + info->Power=Power; + info->Close=Close; + WSync = Sync; + + 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); +} + static DECLFW(Write2) { if(A==0x5101) @@ -78,83 +415,97 @@ static DECLFW(Write2) else switch (A&0x7300) { - case 0x5200: DRegs[0]=V; Sync(); break; - case 0x5000: DRegs[1]=V; Sync(); if(!(DRegs[1]&0x80)&&(scanline<128)) setchr8(0); break; - case 0x5300: DRegs[2]=V; break; + case 0x5200: reg[0]=V; WSync(); break; + case 0x5000: reg[1]=V; WSync(); if(!(reg[1]&0x80)&&(scanline<128)) setchr8(0); /* setchr8(0); */ break; + case 0x5300: reg[2]=V; break; + case 0x5100: reg[3]=V; WSync(); break; } } -static uint8 WRAM[8192]; -static DECLFR(AWRAM) +static void Power2(void) { - return(WRAM[A-0x6000]); + memset(reg,0,8); + laststrobe=1; + SetReadHandler(0x5000,0x5FFF,ReadLow); + SetWriteHandler(0x5000,0x5FFF,Write2); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); } -static DECLFW(BWRAM) +void Mapper163_Init(CartInfo *info) { - WRAM[A-0x6000]=V; + info->Power=Power2; + info->Close=Close; + WSync = Sync; + GameHBIRQHook=M163HB; + + 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); } -static void Power(void) +static void Sync3(void) { - memset(DRegs,0,8); - DRegs[1]=0xFF; - cmd=0; - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4020,0x5FFF,Write); - SetReadHandler(0x6000,0x7FFF,AWRAM); - SetWriteHandler(0x6000,0x7FFF,BWRAM); setchr8(0); - Sync(); + setprg8r(0x10,0x6000,0); + switch(reg[3]&7){ + case 0: + case 2: setprg32(0x8000,(reg[0]&0xc)|(reg[1]&2)|((reg[2]&0xf)<<4)); break; + case 1: + case 3: setprg32(0x8000,(reg[0]&0xc)|(reg[2]&0xf)<<4); break; + case 4: + case 6: setprg32(0x8000,(reg[0]&0xe)|((reg[1]>>1)&1)|((reg[2]&0xf)<<4)); break; + case 5: + case 7: setprg32(0x8000,(reg[0]&0xf)|((reg[2]&0xf)<<4)); break; + } } -static void M163HB(void) +static DECLFW(Write3) { - if(DRegs[1]&0x80) - { - if(scanline==239) - { - setchr4(0x0000,0); - setchr4(0x1000,0); - } - else if(scanline==127) - { - setchr4(0x0000,1); - setchr4(0x1000,1); - } - } +// FCEU_printf("bs %04x %02x\n",A,V); + reg[(A>>8)&3]=V; + WSync(); } -static void Power2(void) +static void Power3(void) { - memset(DRegs,0,8); - DRegs[1]=0xFF; - laststrobe=1; - cmd=0; - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x4020,0x5FFF,Write2); - SetReadHandler(0x6000,0x7FFF,AWRAM); - SetWriteHandler(0x6000,0x7FFF,BWRAM); - SetReadHandler(0x5000,0x5FFF,ReadLow); - setchr8(0); - Sync(); + reg[0]=3; + reg[1]=0; + reg[2]=0; + reg[3]=7; + SetWriteHandler(0x5000,0x5FFF,Write3); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + WSync(); } -void Mapper164_Init(CartInfo *info) +void UNLFS304_Init(CartInfo *info) { - info->Power=Power; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); - AddExState(WRAM, 8192, 0, "WRAM"); - info->SaveGame[0]=WRAM; - info->SaveGameLen[0]=8192; -} + info->Power=Power3; + info->Close=Close; + WSync = Sync3; + + WRAMSIZE = 8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); -void Mapper163_Init(CartInfo *info) -{ - info->Power=Power2; - GameHBIRQHook=M163HB; + if(info->battery) + { + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=WRAMSIZE; + } + GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); - AddExState(WRAM, 8192, 0, "WRAM"); } diff --git a/boards/168.c b/boards/168.c new file mode 100644 index 0000000..170521a --- /dev/null +++ b/boards/168.c @@ -0,0 +1,89 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * RacerMate Chalenge II + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr4r(0x10,0x0000,0); + setchr4r(0x10,0x1000,reg&0x0f); + setprg16(0x8000,reg>>6); + setprg16(0xc000,~0); +} + +static DECLFW(M168Write) +{ + reg=V; + Sync(); +} + +static DECLFW(M168Dummy) +{ +} + +static void M168Power(void) +{ + reg=0; + Sync(); + SetWriteHandler(0x4020,0x7fff,M168Dummy); + SetWriteHandler(0xB000,0xB000,M168Write); + SetWriteHandler(0xF000,0xF000,M168Dummy); + SetWriteHandler(0xF080,0xF080,M168Dummy); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void MNNNClose(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper168_Init(CartInfo *info) +{ + info->Power=M168Power; + info->Close=MNNNClose; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); + + CHRRAMSIZE=8192*8; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + +} diff --git a/boards/17.c b/boards/17.c new file mode 100644 index 0000000..a08caaa --- /dev/null +++ b/boards/17.c @@ -0,0 +1,122 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FFE Copier Mapper + * + */ + +#include "mapinc.h" + +static uint8 preg[4], creg[8]; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; + +static SFORMAT StateRegs[]= +{ + {preg, 4, "PREG"}, + {creg, 8, "CREG"}, + {&mirr, 1, "MIRR"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {&IRQLatch, 4, "IRQL"}, + {0} +}; + +static void Sync(void) +{ + int i; + for(i=0; i<8; i++) setchr1(i<<10,creg[i]); + setprg8(0x8000,preg[0]); + setprg8(0xA000,preg[1]); + setprg8(0xC000,preg[2]); + setprg8(0xE000,preg[3]); + switch(mirr) { + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + case 2: setmirror(MI_H); break; + case 3: setmirror(MI_V); break; + } +} + +static DECLFW(M17WriteMirr) +{ + mirr = ((A << 1) & 2)|((V >> 4) & 1); + Sync(); +} + +static DECLFW(M17WriteIRQ) +{ + switch(A) { + case 0x4501: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x4502: IRQCount&=0xFF00; IRQCount|=V; break; + case 0x4503: IRQCount&=0x00FF; IRQCount|=V<<8; IRQa=1; break; + } +} + +static DECLFW(M17WritePrg) +{ + preg[A & 3] = V; + Sync(); +} + +static DECLFW(M17WriteChr) +{ + creg[A & 7] = V; + Sync(); +} + +static void M17Power(void) +{ + preg[3] = ~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x42FE,0x42FF,M17WriteMirr); + SetWriteHandler(0x4500,0x4503,M17WriteIRQ); + SetWriteHandler(0x4504,0x4507,M17WritePrg); + SetWriteHandler(0x4510,0x4517,M17WriteChr); +} + +static void FP_FASTAPASS(1) M17IRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper17_Init(CartInfo *info) +{ + info->Power=M17Power; + GameHBIRQHook=M17IRQHook; + GameStateRestore=StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/boards/170.c b/boards/170.c new file mode 100644 index 0000000..7694fe0 --- /dev/null +++ b/boards/170.c @@ -0,0 +1,68 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000, 0); + setprg16(0xc000,~0); + setchr8(0); +} + +static DECLFW(M170ProtW) +{ + reg = V << 1 & 0x80; +} + +static DECLFR(M170ProtR) +{ + return reg | (X.DB & 0x7F); +} + +static void M170Power(void) +{ + Sync(); + SetWriteHandler(0x6502,0x6502,M170ProtW); + SetWriteHandler(0x7000,0x7000,M170ProtW); + SetReadHandler(0x7001,0x7001,M170ProtR); + SetReadHandler(0x7777,0x7777,M170ProtR); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper170_Init(CartInfo *info) +{ + info->Power=M170Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/175.c b/boards/175.c index 2830584..13bbddd 100644 --- a/boards/175.c +++ b/boards/175.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/176.c b/boards/176.c deleted file mode 100644 index 0830df8..0000000 --- a/boards/176.c +++ /dev/null @@ -1,158 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2007 CaH4e3 - * Copyright (C) 2012 FCEUX team - * - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -extern uint32 ROM_size; - -static uint8 prg[4], chr, sbw, we_sram; -static uint8 *WRAM=NULL; -static uint32 WRAMSIZE; - -static SFORMAT StateRegs[]= -{ - {prg, 4, "PRG"}, - {&chr, 1, "CHR"}, - {&sbw, 1, "SBW"}, - {0} -}; - -static void Sync(void) -{ - setprg8r(0x10,0x6000,0); - setprg8(0x8000,prg[0]); - setprg8(0xA000,prg[1]); - setprg8(0xC000,prg[2]); - setprg8(0xE000,prg[3]); - - setchr8(chr); -} - -static DECLFW(M176Write_5001) -{ - printf("%04X = $%02X\n",A,V); - if(sbw) - { - prg[0] = V*4; - prg[1] = V*4+1; - prg[2] = V*4+2; - prg[3] = V*4+3; - } - Sync(); -} - -static DECLFW(M176Write_5010) -{ - printf("%04X = $%02X\n",A,V); - if(V == 0x24) sbw = 1; - Sync(); -} - -static DECLFW(M176Write_5011) -{ - printf("%04X = $%02X\n",A,V); - V >>= 1; - if(sbw) - { - prg[0] = V*4; - prg[1] = V*4+1; - prg[2] = V*4+2; - prg[3] = V*4+3; - } - Sync(); -} - -static DECLFW(M176Write_5FF1) -{ - printf("%04X = $%02X\n",A,V); - V >>= 1; - prg[0] = V*4; - prg[1] = V*4+1; - prg[2] = V*4+2; - prg[3] = V*4+3; - Sync(); -} - -static DECLFW(M176Write_5FF2) -{ - printf("%04X = $%02X\n",A,V); - chr = V; - Sync(); -} - -static DECLFW(M176Write_A001) -{ - we_sram = V & 0x03; -} - -static DECLFW(M176Write_WriteSRAM) -{ -// if(we_sram) - CartBW(A,V); -} - -static void M176Power(void) -{ - SetReadHandler(0x6000,0x7fff,CartBR); - SetWriteHandler(0x6000,0x7fff,M176Write_WriteSRAM); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0xA001,0xA001,M176Write_A001); - SetWriteHandler(0x5001,0x5001,M176Write_5001); - SetWriteHandler(0x5010,0x5010,M176Write_5010); - SetWriteHandler(0x5011,0x5011,M176Write_5011); - SetWriteHandler(0x5ff1,0x5ff1,M176Write_5FF1); - SetWriteHandler(0x5ff2,0x5ff2,M176Write_5FF2); - - we_sram = 0; - sbw = 0; - prg[0] = 0; - prg[1] = 1; - prg[2] = (ROM_size-2)&63; - prg[3] = (ROM_size-1)&63; - Sync(); -} - - -static void M176Close(void) -{ - if(WRAM) - FCEU_gfree(WRAM); - WRAM=NULL; -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper176_Init(CartInfo *info) -{ - info->Power=M176Power; - info->Close=M176Close; - - 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/boards/177.c b/boards/177.c index 6bc81b9..e8e758e 100644 --- a/boards/177.c +++ b/boards/177.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/178.c b/boards/178.c index 19e1b8d..0c6892f 100644 --- a/boards/178.c +++ b/boards/178.c @@ -15,57 +15,60 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * San Guo Zhong Lie Zhuan (Ch) + * win200, etc + * */ #include "mapinc.h" -static uint8 reg[3]; +static uint8 reg[4]; static uint8 *WRAM=NULL; static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { - {reg, 3, "REGS"}, + {reg, 4, "REGS"}, {0} }; static void Sync(void) { - setmirror(reg[0]); + uint8 bank = (reg[2]&3)<<3; + setmirror((reg[0]&1)^1); setprg8r(0x10,0x6000,0); setchr8(0); - setprg32(0x8000,(reg[1]+reg[2])); -} - -static DECLFW(M178Write0) -{ - reg[0]=(V&1)^1; - Sync(); -} - -static DECLFW(M178Write1) -{ - reg[1]=(V>>1)&0xf; - Sync(); + if(reg[0]&2) + { + setprg16(0x8000,(reg[1]&7)|bank); + setprg16(0xC000,((~0)&7)|bank); + } + else + { + setprg16(0x8000,(reg[1]&6)|bank); + setprg16(0xC000,(reg[1]&6)|bank|1); + } } -static DECLFW(M178Write2) +static DECLFW(M178Write) { - reg[2]=(V<<2); + reg[A&3]=V; Sync(); } static void M178Power(void) { - reg[0]=1; reg[1]=0; reg[2]=0; + reg[0]=1; + reg[1]=0; + reg[2]=0; + reg[3]=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); + SetWriteHandler(0x4800,0x4803,M178Write); } static void M178Close(void) diff --git a/boards/18.c b/boards/18.c new file mode 100644 index 0000000..4b07474 --- /dev/null +++ b/boards/18.c @@ -0,0 +1,121 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 preg[4], creg[8]; +static uint8 IRQa, mirr; +static int32 IRQCount, IRQLatch; + +static SFORMAT StateRegs[]= +{ + {preg, 4, "PREG"}, + {creg, 8, "CREG"}, + {&mirr, 1, "MIRR"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {&IRQLatch, 4, "IRQL"}, + {0} +}; + +static void Sync(void) +{ + int i; + for(i=0; i<8; i++) setchr1(i<<10,creg[i]); + setprg8(0x8000,preg[0]); + setprg8(0xA000,preg[1]); + setprg8(0xC000,preg[2]); + setprg8(0xE000,~0); + if(mirr & 2) + setmirror(MI_0); + else + setmirror(mirr & 1); +} + +static DECLFW(M18WriteIRQ) +{ + switch(A & 0xF003) { + case 0xE000: IRQLatch&=0xFFF0; IRQLatch|=(V&0x0f)<<0x0;break; + case 0xE001: IRQLatch&=0xFF0F; IRQLatch|=(V&0x0f)<<0x4; break; + case 0xE002: IRQLatch&=0xF0FF; IRQLatch|=(V&0x0f)<<0x8; break; + case 0xE003: IRQLatch&=0x0FFF; IRQLatch|=(V&0x0f)<<0xC; break; + case 0xF000: IRQCount=IRQLatch; break; + case 0xF001: IRQa=V&1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF002: mirr = V&3; Sync(); break; + } +} + +static DECLFW(M18WritePrg) +{ + uint32 i = ((A >> 1) & 1)|((A - 0x8000) >> 11); + preg[i] &= (0xF0) >> ((A & 1) << 2); + preg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static DECLFW(M18WriteChr) +{ + uint32 i = ((A >> 1) & 1)|((A - 0xA000) >> 11); + creg[i] &= (0xF0) >> ((A & 1) << 2); + creg[i] |= (V & 0xF) << ((A & 1) << 2); + Sync(); +} + +static void M18Power(void) +{ + preg[0] = 0; + preg[1] = 1; + preg[2] = ~1; + preg[3] = ~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0x9FFF,M18WritePrg); + SetWriteHandler(0xA000,0xDFFF,M18WriteChr); + SetWriteHandler(0xE000,0xFFFF,M18WriteIRQ); +} + +static void FP_FASTAPASS(1) M18IRQHook(int a) +{ + if(IRQa && IRQCount) + { + IRQCount-=a; + if(IRQCount<=0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=0; + IRQa=0; + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper18_Init(CartInfo *info) +{ + info->Power=M18Power; + MapIRQHook=M18IRQHook; + GameStateRestore=StateRestore; + + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/boards/183.c b/boards/183.c index bf0b7c0..8d4f79b 100644 --- a/boards/183.c +++ b/boards/183.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Gimmick Bootleg (VRC4 mapper) */ @@ -32,8 +32,8 @@ static SFORMAT StateRegs[]= { {prg, 4, "PRG"}, {chr, 8, "CHR"}, - {&IRQCount, 1, "IRQCOUNT"}, - {&IRQPre, 1, "IRQPRE"}, + {&IRQCount, 1, "IRQC"}, + {&IRQPre, 1, "IRQP"}, {&IRQa, 1, "IRQA"}, {0} }; @@ -64,7 +64,7 @@ static DECLFW(M183Write) { if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) { - uint8 index=(((A>>11)-6)|(A>>3))&7; + int index=(((A>>11)-6)|(A>>3))&7; chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4)); SyncChr(); } diff --git a/boards/185.c b/boards/185.c index b865a8f..7ea86bb 100644 --- a/boards/185.c +++ b/boards/185.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ @@ -88,12 +88,12 @@ static void MRestore(int version) void Mapper185_Init(CartInfo *info) { - int x; Sync=Sync185; info->Power=MPower; info->Close=MClose; GameStateRestore=MRestore; DummyCHR=(uint8*)FCEU_gmalloc(8192); + int x; for(x=0;x<8192;x++) DummyCHR[x]=0xff; SetupCartCHRMapping(0x10,DummyCHR,8192,0); @@ -102,12 +102,12 @@ void Mapper185_Init(CartInfo *info) void Mapper181_Init(CartInfo *info) { - int x; Sync=Sync181; info->Power=MPower; info->Close=MClose; GameStateRestore=MRestore; DummyCHR=(uint8*)FCEU_gmalloc(8192); + int x; for(x=0;x<8192;x++) DummyCHR[x]=0xff; SetupCartCHRMapping(0x10,DummyCHR,8192,0); diff --git a/boards/186.c b/boards/186.c index 4976265..1713050 100644 --- a/boards/186.c +++ b/boards/186.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Family Study Box by Fukutake Shoten */ @@ -29,7 +29,7 @@ static uint8 regs[4]; static SFORMAT StateRegs[]= { {regs, 4, "DREG"}, - {SWRAM, 2816, "SWRAM"}, + {SWRAM, 2816, "SWRM"}, {0} }; diff --git a/boards/187.c b/boards/187.c index 0f49748..0852cba 100644 --- a/boards/187.c +++ b/boards/187.c @@ -15,7 +15,11 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * A98402 board, A9711, A9746 similar + * King of Fighters 96, The (Unl), Street Fighter Zero 2 (Unl) + * */ #include "mapinc.h" @@ -35,7 +39,12 @@ static void M187PW(uint32 A, uint8 V) { uint8 bank=EXPREGS[0]&0x1F; if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>2); + { + if(EXPREGS[0]&0x40) + setprg32(0x8000,bank>>2); + else + setprg32(0x8000,bank>>1); // hacky hacky! two mappers in one! need real hw carts to test + } else { setprg16(0x8000,bank); @@ -48,28 +57,19 @@ static void M187PW(uint32 A, uint8 V) static DECLFW(M187Write8000) { - EXPREGS[2]=1; + EXPREGS[1]=1; MMC3_CMDWrite(A,V); } static DECLFW(M187Write8001) { - if(EXPREGS[2]) + if(EXPREGS[1]) MMC3_CMDWrite(A,V); } -static DECLFW(M187Write8003) -{ - EXPREGS[2]=0; - if(V==0x28)setprg8(0xC000,0x17); - else if(V==0x2A)setprg8(0xA000,0x0F); -} - - static DECLFW(M187WriteLo) { - EXPREGS[1]=V; - if(A==0x5000) + if((A==0x5000)||(A==0x6000)) { EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); @@ -84,13 +84,12 @@ static DECLFR(M187Read) static void M187Power(void) { - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; + EXPREGS[0]=EXPREGS[1]=0; GenMMC3Power(); SetReadHandler(0x5000,0x5FFF,M187Read); - SetWriteHandler(0x5000,0x5FFF,M187WriteLo); + SetWriteHandler(0x5000,0x6FFF,M187WriteLo); SetWriteHandler(0x8000,0x8000,M187Write8000); SetWriteHandler(0x8001,0x8001,M187Write8001); - SetWriteHandler(0x8003,0x8003,M187Write8003); } void Mapper187_Init(CartInfo *info) diff --git a/boards/189.c b/boards/189.c index ff045a5..48393f9 100644 --- a/boards/189.c +++ b/boards/189.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -23,7 +23,7 @@ static void M189PW(uint32 A, uint8 V) { - setprg32(0x8000,EXPREGS[0]&3); + setprg32(0x8000,EXPREGS[0]&7); } static DECLFW(M189Write) diff --git a/boards/193.c b/boards/193.c new file mode 100644 index 0000000..e17323a --- /dev/null +++ b/boards/193.c @@ -0,0 +1,80 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * MEGA-SOFT WAR IN THE GULF + * + */ + +#include "mapinc.h" + +static uint8 reg[8]; +static uint8 mirror, cmd, bank; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {&mirror, 1, "MIRR"}, + {&bank, 1, "BANK"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setmirror(mirror^1); + setprg8(0x8000,reg[3]); + setprg8(0xA000,0xD); + setprg8(0xC000,0xE); + setprg8(0xE000,0xF); + setchr4(0x0000,reg[0]>>2); + setchr2(0x1000,reg[1]>>1); + setchr2(0x1800,reg[2]>>1); +} + +static DECLFW(M193Write) +{ + reg[A&3]=V; + Sync(); +} + +static void M193Power(void) +{ + bank=0; + Sync(); + SetWriteHandler(0x6000,0x6003,M193Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,CartBW); +} + +static void M193Reset(void) +{ +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper193_Init(CartInfo *info) +{ + info->Reset=M193Reset; + info->Power=M193Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/199.c b/boards/199.c index ed21278..3302dc6 100644 --- a/boards/199.c +++ b/boards/199.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Dragon Ball Z 2 - Gekishin Freeza! (C) * Dragon Ball Z Gaiden - Saiya Jin Zetsumetsu Keikaku (C) @@ -26,7 +26,8 @@ #include "mapinc.h" #include "mmc3.h" -static uint8 *CHRRAM=NULL; // and here too +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; static void M199PW(uint32 A, uint8 V) { @@ -60,7 +61,6 @@ static DECLFW(M199Write) { if((A==0x8001)&&(MMC3_cmd&8)) { -// FCEU_printf("%02x=>%02x\n",MMC3_cmd,V); EXPREGS[MMC3_cmd&3]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); @@ -82,16 +82,26 @@ static void M199Power(void) SetWriteHandler(0x8000,0xFFFF,M199Write); } +static void M199Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; +} + void Mapper199_Init(CartInfo *info) { - int CHRRAMSize=1024*8; GenMMC3_Init(info, 512, 256, 8, info->battery); cwrap=M199CW; pwrap=M199PW; mwrap=M199MW; info->Power=M199Power; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + info->Close=M199Close; + + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSIZE, 1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); } diff --git a/boards/208.c b/boards/208.c index 3bbb34d..a7c8ac9 100644 --- a/boards/208.c +++ b/boards/208.c @@ -15,29 +15,29 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #include "mmc3.h" static uint8 lut[256]={ - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, - 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, - 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, - 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59,0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x51, 0x41, 0x11, 0x01, 0x51, 0x41, 0x11, 0x01, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x10, 0x40, 0x50, 0x00, 0x10, 0x40, 0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x08, 0x18, 0x48, 0x58, 0x08, 0x18, 0x48, 0x58, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x58, 0x48, 0x18, 0x08, 0x58, 0x48, 0x18, 0x08, + 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x50, 0x40, 0x10, 0x00, 0x50, 0x40, 0x10, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x11, 0x41, 0x51, 0x01, 0x11, 0x41, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x09, 0x19, 0x49, 0x59, 0x09, 0x19, 0x49, 0x59, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }; static void M208PW(uint32 A, uint8 V) diff --git a/boards/222.c b/boards/222.c index e230751..a1da139 100644 --- a/boards/222.c +++ b/boards/222.c @@ -15,13 +15,15 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * * (VRC4 mapper) + * */ #include "mapinc.h" -static uint8 IRQCount; +static uint8 IRQCount;//, IRQPre; static uint8 IRQa; static uint8 prg_reg[2]; static uint8 chr_reg[8]; @@ -52,12 +54,12 @@ static void M222IRQ(void) 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); + setchr1(i<<10,chr_reg[i]); + setmirror(mirr^1); } static DECLFW(M222Write) diff --git a/boards/225.c b/boards/225.c new file mode 100644 index 0000000..0c86edf --- /dev/null +++ b/boards/225.c @@ -0,0 +1,99 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * PCB-018 board, discrete multigame cart 110-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prot[4], prg, mode, chr, mirr; + +static SFORMAT StateRegs[]= +{ + {prot, 4, "PROT"}, + {&prg, 1, "PRG"}, + {&chr, 1, "CHR"}, + {&mode, 1, "MODE"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + if(mode) + { + setprg16(0x8000,prg); + setprg16(0xC000,prg); + } + else + setprg32(0x8000,prg>>1); + setchr8(chr); + setmirror(mirr); +} + +static DECLFW(M225Write) +{ + uint32 bank = (A >> 14) & 1; + mirr = (A >> 13) & 1; + mode = (A >> 12) & 1; + chr = (A & 0x3f) | (bank << 6); + prg = ((A >> 6) & 0x3f) | (bank << 6); + Sync(); +} + +static DECLFW(M225LoWrite) +{ +} + +static DECLFR(M225LoRead) +{ + return 0; +} + +static void M225Power(void) +{ + prg = 0; + mode = 0; + Sync(); + SetReadHandler(0x5000,0x5fff,M225LoRead); + SetWriteHandler(0x5000,0x5fff,M225LoWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M225Write); +} + +static void M225Reset(void) +{ + prg = 0; + mode = 0; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper225_Init(CartInfo *info) +{ + info->Reset=M225Reset; + info->Power=M225Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/23.c b/boards/23.c index 8760d50..5e596fc 100644 --- a/boards/23.c +++ b/boards/23.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-2/VRC-4 Konami + * VRC-4 Pirate */ #include "mapinc.h" @@ -33,13 +36,13 @@ static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { - {prgreg, 2, "PRGREGS"}, - {chrreg, 8, "CHRREGS"}, - {®cmd, 1, "REGCMD"}, - {&irqcmd, 1, "IRQCMD"}, + {prgreg, 2, "PREG"}, + {chrreg, 8, "CREG"}, + {®cmd, 1, "CMDR"}, + {&irqcmd, 1, "CMDI"}, {&mirr, 1, "MIRR"}, {&big_bank, 1, "BIGB"}, - {&IRQCount, 2, "IRCN"}, + {&IRQCount, 2, "IRQC"}, {&IRQLatch, 1, "IRQL"}, {&IRQa, 1, "IRQA"}, {0} @@ -87,7 +90,7 @@ static DECLFW(M23Write) 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); @@ -97,18 +100,18 @@ static DECLFW(M23Write) else switch(A&0xF003) { - case 0x8000: - case 0x8001: - case 0x8002: - case 0x8003: if(is23) - prgreg[0]=V&0x1F; - Sync(); + 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; + case 0xA000: + case 0xA001: + case 0xA002: + case 0xA003: if(is23) + prgreg[1]=V&0x1F; else { prgreg[0]=(V<<1)&0x1F; @@ -118,7 +121,7 @@ static DECLFW(M23Write) break; case 0x9000: case 0x9001: if(V!=0xFF) mirr=V; Sync(); break; - case 0x9002: + 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; @@ -129,7 +132,7 @@ static DECLFW(M23Write) static void M23Power(void) { - big_bank=0x20; + big_bank=0x20; Sync(); setprg8r(0x10,0x6000,0); // another many-in-one code, WRAM actually contain only WaiWaiWorld game SetReadHandler(0x6000,0x7FFF,CartBR); @@ -138,11 +141,7 @@ static void M23Power(void) SetWriteHandler(0x8000,0xFFFF,M23Write); } -static void M23Reset(void) -{ -} - -void M23IRQHook(int a) +void FP_FASTAPASS(1) M23IRQHook(int a) { #define LCYCS 341 if(IRQa) @@ -154,7 +153,7 @@ void M23IRQHook(int a) { acount-=LCYCS; IRQCount++; - if(IRQCount&0x100) + if(IRQCount&0x100) { X6502_IRQBegin(FCEU_IQEXT); IRQCount=IRQLatch; diff --git a/boards/235.c b/boards/235.c index 4cae946..f6d927c 100644 --- a/boards/235.c +++ b/boards/235.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -23,7 +23,7 @@ static uint16 cmdreg; static SFORMAT StateRegs[]= { - {&cmdreg, 2, "CMDREG"}, + {&cmdreg, 2, "CREG"}, {0} }; diff --git a/boards/253.c b/boards/253.c index 6e3b569..908897a 100644 --- a/boards/253.c +++ b/boards/253.c @@ -15,13 +15,15 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * TODO: cram disable cases! (Shen Hua Jian Yun III cannot boot with CRAM enabled) */ #include "mapinc.h" -static uint8 chrlo[8], chrhi[8], prg[2], mirr, vlock; -static int32 IRQa, IRQCount, IRQLatch, IRQClock; +static uint8 chrlo[8], chrhi[8], prg[2], mirr; +static int32 IRQa, IRQCount, IRQLatch, IRQClock; static uint8 *WRAM=NULL; static uint32 WRAMSIZE; static uint8 *CHRRAM=NULL; @@ -29,11 +31,10 @@ static uint32 CHRRAMSIZE; static SFORMAT StateRegs[]= { - {chrlo, 8, "CHRLO"}, - {chrhi, 8, "CHRHI"}, + {chrlo, 8, "CHRL"}, + {chrhi, 8, "CHRH"}, {prg, 2, "PRGR"}, {&mirr, 1, "MIRR"}, - {&vlock, 1, "VLOCK"}, {&IRQa, 4, "IRQA"}, {&IRQCount, 4, "IRQC"}, {&IRQLatch, 4, "IRQL"}, @@ -52,17 +53,7 @@ static void Sync(void) for(i=0; i<8; i++) { uint32 chr = chrlo[i]|(chrhi[i]<<8); - if(chrlo[i]==0xc8) - { - vlock = 0; - continue; - } - else if(chrlo[i]==0x88) - { - vlock = 1; - continue; - } - if(((chrlo[i]==4)||(chrlo[i]==5))&&!vlock) + if((chr==4)||(chr==5)) setchr1r(0x10,i<<10,chr&1); else setchr1(i<<10,chr); @@ -127,18 +118,18 @@ static void M253Close(void) static void M253IRQ(int cycles) { - if(IRQa&2) + if(IRQa&2) { - if((IRQClock+=cycles)>=0x72) + if((IRQClock+=cycles)>=0x71) { - IRQClock -= 0x72; - if(IRQCount==0xFF) + IRQClock -= 0x71; + if(IRQCount==0xFF) { IRQCount = IRQLatch; IRQa = IRQa|((IRQa&1)<<1); X6502_IRQBegin(FCEU_IQEXT); } - else + else IRQCount++; } } diff --git a/boards/34.c b/boards/34.c new file mode 100644 index 0000000..a357506 --- /dev/null +++ b/boards/34.c @@ -0,0 +1,98 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * Many-in-one hacked mapper crap. + * + * Original BNROM is actually AxROM variations without mirroring control, + * and haven't SRAM on-board, so it must be removed from here + * + * Difficult banking is what NINA board doing, most hacks for 34 mapper are + * NINA hacks, so this is actually 34 mapper + * + */ + +#include "mapinc.h" + +static uint8 regs[3]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {regs, 3, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,0); + setprg32(0x8000,regs[0]); + setchr4(0x0000,regs[1]); + setchr4(0x1000,regs[2]); +} + +static DECLFW(M34Write) +{ + if(A>=0x8000) + regs[0] = V; + else + switch(A) + { + case 0x7ffd: regs[0] = V; break; + case 0x7ffe: regs[1] = V; break; + case 0x7fff: regs[2] = V; break; + } + Sync(); +} + +static void M34Power(void) +{ + regs[0] = 0; + Sync(); + SetReadHandler(0x6000,0x7ffc,CartBR); + SetWriteHandler(0x6000,0x7ffc,CartBW); + SetReadHandler(0x8000,0xffff,CartBR); + SetWriteHandler(0x7ffd,0xffff,M34Write); +} + +static void M34Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper34_Init(CartInfo *info) +{ + info->Power=M34Power; + info->Close=M34Close; + 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/boards/3d-block.c b/boards/3d-block.c index 24572a4..0f71c27 100644 --- a/boards/3d-block.c +++ b/boards/3d-block.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -70,7 +70,7 @@ static void UNL3DBlockReset(void) FCEU_printf("Count=%04x\n",Count); } -static void UNL3DBlockIRQHook(int a) +static void FP_FASTAPASS(1) UNL3DBlockIRQHook(int a) { if(IRQa) { diff --git a/boards/411120-c.c b/boards/411120-c.c index 479a9bf..ab78499 100644 --- a/boards/411120-c.c +++ b/boards/411120-c.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // actually cart ID is 811120-C, sorry ;) K-3094 - another ID diff --git a/boards/43.c b/boards/43.c index ee12dec..94aa7b6 100644 --- a/boards/43.c +++ b/boards/43.c @@ -15,16 +15,16 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ -//ccording to nestopia, BTL_SMB2_C, otherwise known as UNL-SMB2J - #include "mapinc.h" static uint8 reg; -static uint8 IRQa; -static uint32 IRQCount; +static uint32 IRQCount, IRQa; static SFORMAT StateRegs[]= { @@ -36,7 +36,7 @@ static SFORMAT StateRegs[]= static void Sync(void) { - setprg4(0x5000,16); + setprg4(0x5000,16); // Only YS-612 advdnced version setprg8(0x6000,2); setprg8(0x8000,1); setprg8(0xa000,0); @@ -47,11 +47,13 @@ static void Sync(void) static DECLFW(M43Write) { - int transo[8]={4,3,4,4,4,7,5,6}; +// int transo[8]={4,3,4,4,4,7,5,6}; + int transo[8]={4,3,5,3,6,3,7,3}; // According to hardware tests switch(A&0xf1ff) { case 0x4022: reg=transo[V&7]; Sync(); break; - case 0x8122: IRQa=V&1; IRQCount=0; break; + case 0x8122: // hacked version + case 0x4122: IRQa=V&1; X6502_IRQEnd(FCEU_IQEXT); IRQCount=0; break; // original version } } @@ -59,7 +61,6 @@ static void M43Power(void) { reg=0; Sync(); -// SetReadHandler(0x5000,0x5fff,CartBR); SetReadHandler(0x5000,0xffff,CartBR); SetWriteHandler(0x4020,0xffff,M43Write); } @@ -68,15 +69,15 @@ static void M43Reset(void) { } -static void M43IRQHook(int a) +static void FP_FASTAPASS(1) M43IRQHook(int a) { - IRQCount+=a; - if(IRQa) - if(IRQCount>=4096) - { - IRQa=0; - X6502_IRQBegin(FCEU_IQEXT); - } + IRQCount+=a; + if(IRQa) + if(IRQCount>=4096) + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } } static void StateRestore(int version) diff --git a/boards/57.c b/boards/57.c index ba5de0b..71cee43 100644 --- a/boards/57.c +++ b/boards/57.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ @@ -27,7 +27,7 @@ static uint8 hrd_flag; static SFORMAT StateRegs[]= { - {&hrd_flag, 1, "DIPSW"}, + {&hrd_flag, 1, "DPSW"}, {&prg_reg, 1, "PRG"}, {&chr_reg, 1, "CHR"}, {0} diff --git a/boards/603-5052.c b/boards/603-5052.c index 43b4e0a..439c026 100644 --- a/boards/603-5052.c +++ b/boards/603-5052.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * SL12 Protected 3-in-1 mapper hardware (VRC2, MMC3, MMC1) + * the same as 603-5052 board (TODO: add reading registers, merge) + * + * Contra Fighter prot board */ #include "mapinc.h" diff --git a/boards/68.c b/boards/68.c index 6a9420c..08dfa8c 100644 --- a/boards/68.c +++ b/boards/68.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -32,8 +32,8 @@ static SFORMAT StateRegs[]= {&nt2, 1, "NT2"}, {&mirr, 1, "MIRR"}, {&prg_reg, 1, "PRG"}, - {&kogame, 1, "KOGAME"}, - {&count, 4, "COUNT"}, + {&kogame, 1, "KGME"}, + {&count, 4, "CNT"}, {chr_reg, 4, "CHR"}, {0} }; @@ -96,6 +96,7 @@ static DECLFW(M68WriteLo) count = 0; setprg16r((PRGptr[1])?kogame:0,0x8000,prg_reg); } + CartBW(A,V); } static DECLFW(M68WriteCHR) diff --git a/boards/8157.c b/boards/8157.c index 1b23023..ef42558 100644 --- a/boards/8157.c +++ b/boards/8157.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -25,7 +25,7 @@ static uint8 invalid_data; static SFORMAT StateRegs[]= { {&invalid_data, 1, "INVD"}, - {&cmdreg, 2, "CMDREG"}, + {&cmdreg, 2, "CREG"}, {0} }; diff --git a/boards/82.c b/boards/82.c new file mode 100644 index 0000000..7dfd276 --- /dev/null +++ b/boards/82.c @@ -0,0 +1,105 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * Taito X1-017 board, battery backed + * + */ + +#include "mapinc.h" + +static uint8 regs[9], ctrl; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {regs, 9, "REGS"}, + {&ctrl, 1, "CTRL"}, + {0} +}; + +static void Sync(void) +{ + uint32 swap = ((ctrl & 2) << 11); + setchr2(0x0000^swap,regs[0]>>1); + setchr2(0x0800^swap,regs[1]>>1); + setchr1(0x1000^swap,regs[2]); + setchr1(0x1400^swap,regs[3]); + setchr1(0x1800^swap,regs[4]); + setchr1(0x1c00^swap,regs[5]); + setprg8r(0x10,0x6000,0); + setprg8(0x8000,regs[6]); + setprg8(0xA000,regs[7]); + setprg8(0xC000,regs[8]); + setprg8(0xE000,~0); + setmirror(ctrl & 1); +} + +static DECLFW(M82Write) +{ + if(A <= 0x7ef5) + regs[A & 7] = V; + else + switch(A) + { + case 0x7ef6: ctrl = V & 3; break; + case 0x7efa: regs[6] = V >> 2; break; + case 0x7efb: regs[7] = V >> 2; break; + case 0x7efc: regs[8] = V >> 2; break; + } + Sync(); +} + +static void M82Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xffff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); + SetWriteHandler(0x7ef0,0x7efc,M82Write); // external WRAM might end at $73FF +} + +static void M82Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper82_Init(CartInfo *info) +{ + info->Power=M82Power; + info->Power=M82Close; + + 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/boards/8237.c b/boards/8237.c index 0415338..3c401e6 100644 --- a/boards/8237.c +++ b/boards/8237.c @@ -1,195 +1,205 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2005-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Super Game (Sugar Softec) protected mapper - * Pocahontas 2 (Unl) [U][!], etc. - * TODO: 9in1 LION KING HANGS! - */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 cmdin; - -static uint8 regperm[8][8] = - { - {0, 1, 2, 3, 4, 5, 6, 7}, - {0, 2, 6, 1, 7, 3, 4, 5}, - {0, 5, 4, 1, 7, 2, 6, 3}, // unused - {0, 6, 3, 7, 5, 2, 4, 1}, - {0, 2, 5, 3, 6, 1, 7, 4}, - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - }; - -static uint8 adrperm[8][8] = - { - {0, 1, 2, 3, 4, 5, 6, 7}, - {3, 2, 0, 4, 1, 5, 6, 7}, - {0, 1, 2, 3, 4, 5, 6, 7}, // unused - {5, 0, 1, 2, 3, 7, 6, 4}, - {3, 1, 0, 5, 2, 4, 6, 7}, - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - {0, 1, 2, 3, 4, 5, 6, 7}, // empty - }; - -static void UNL8237CW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); - else - setchr1(A,((EXPREGS[1]&0xc)<<6)|V); -} - -static void UNL8237PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - { - uint8 sbank = (EXPREGS[1]&0x10); - if(EXPREGS[0]&0x80) - { - uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1); - if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank); - } - else - { - if(EXPREGS[0]&0x80) - { - uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF); - if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F)); - } -} - -static void UNL8237ACW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); - else - setchr1(A,((EXPREGS[1]&0xE)<<7)|V); -} - -static void UNL8237APW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - { - uint8 sbank = (EXPREGS[1]&0x10); - if(EXPREGS[0]&0x80) - { - uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1); - if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); - } - else - { - if(EXPREGS[0]&0x80) - { - uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF); - if(EXPREGS[0]&0x20) - setprg32(0x8000,bank>>1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F)); - } -} -static DECLFW(UNL8237Write) -{ - uint8 dat = V; - uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)]; - uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000; - if(adr < 4) - { - if(!adr) - dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]); - MMC3_CMDWrite(addr,dat); - } - else - MMC3_IRQWrite(addr,dat); -} - -static DECLFW(UNL8237ExWrite) -{ - switch(A) - { - case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; - case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; - case 0x5007: EXPREGS[2]=V; break; - } -} - -static void UNL8237Power(void) -{ - EXPREGS[0]=EXPREGS[2]=0; - EXPREGS[1]=3; - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,UNL8237Write); - SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); -} - -void UNL8237_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - cwrap=UNL8237CW; - pwrap=UNL8237PW; - info->Power=UNL8237Power; - AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} - -void UNL8237A_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - cwrap=UNL8237ACW; - pwrap=UNL8237APW; - info->Power=UNL8237Power; - AddExState(EXPREGS, 3, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 Game (Sugar Softec) protected mapper + * Pocahontas 2 (Unl) [U][!], etc. + * TODO: 9in1 LION KING HANGS! + */ + +#include "mapinc.h" +#include "mmc3.h" + +static uint8 cmdin; + +static uint8 regperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {0, 2, 6, 1, 7, 3, 4, 5}, + {0, 5, 4, 1, 7, 2, 6, 3}, // unused + {0, 6, 3, 7, 5, 2, 4, 1}, + {0, 2, 5, 3, 6, 1, 7, 4}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; + +static uint8 adrperm[8][8] = + { + {0, 1, 2, 3, 4, 5, 6, 7}, + {3, 2, 0, 4, 1, 5, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // unused + {5, 0, 1, 2, 3, 7, 6, 4}, + {3, 1, 0, 5, 2, 4, 6, 7}, + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + {0, 1, 2, 3, 4, 5, 6, 7}, // empty + }; + +static void UNL8237CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xc)<<6)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xc)<<6)|V); +} + +static void UNL8237PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x0F)|sbank); + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,((EXPREGS[1]&3)<<5)|(V&0x1F)); + } +} + +static void UNL8237ACW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr1(A,((EXPREGS[1]&0xE)<<7)|(V&0x7F)|((EXPREGS[1]&0x20)<<2)); + else + setchr1(A,((EXPREGS[1]&0xE)<<7)|V); +} + +static void UNL8237APW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 sbank = (EXPREGS[1]&0x10); + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0x7)|(sbank>>1); + if(EXPREGS[0]&0x20) { +// FCEU_printf("8000:%02X\n",bank>>1); + setprg32(0x8000,bank>>1); + } + else + { +// FCEU_printf("8000-C000:%02X\n",bank); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { +// FCEU_printf("%04x:%02X\n",A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x0F)|sbank); + } + } + else + { + if(EXPREGS[0]&0x80) + { + uint8 bank = ((EXPREGS[1]&3)<<4)|((EXPREGS[1]&8)<<3)|(EXPREGS[0]&0xF); + if(EXPREGS[0]&0x20) { +// FCEU_printf("8000:%02X\n",(bank>>1)&0x07); + setprg32(0x8000,bank>>1); + } + else + { +// FCEU_printf("8000-C000:%02X\n",bank&0x0F); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else { +// FCEU_printf("%04X:%02X\n",A,(((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F))&0x1F); + setprg8(A,((EXPREGS[1]&3)<<5)|((EXPREGS[1]&8)<<4)|(V&0x1F)); + } + } +} +static DECLFW(UNL8237Write) +{ + uint8 dat = V; + uint8 adr = adrperm[EXPREGS[2]][((A>>12)&6)|(A&1)]; + uint16 addr = (adr & 1)|((adr & 6)<<12)|0x8000; + if(adr < 4) + { + if(!adr) + dat = (dat & 0xC0)|(regperm[EXPREGS[2]][dat & 7]); + MMC3_CMDWrite(addr,dat); + } + else + MMC3_IRQWrite(addr,dat); +} + +static DECLFW(UNL8237ExWrite) +{ + switch(A) + { + case 0x5000: EXPREGS[0]=V; FixMMC3PRG(MMC3_cmd); break; + case 0x5001: EXPREGS[1]=V; FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); break; + case 0x5007: EXPREGS[2]=V; break; + } +} + +static void UNL8237Power(void) +{ + EXPREGS[0]=EXPREGS[2]=0; + EXPREGS[1]=3; + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,UNL8237Write); + SetWriteHandler(0x5000,0x7FFF,UNL8237ExWrite); +} + +void UNL8237_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237CW; + pwrap=UNL8237PW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} + +void UNL8237A_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + cwrap=UNL8237ACW; + pwrap=UNL8237APW; + info->Power=UNL8237Power; + AddExState(EXPREGS, 3, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} diff --git a/boards/830118C.c b/boards/830118C.c index 8b6ce60..bdfb56d 100644 --- a/boards/830118C.c +++ b/boards/830118C.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // M-022 MMC3 based 830118C T-106 4M + 4M @@ -23,8 +23,6 @@ #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)); diff --git a/boards/88.c b/boards/88.c index 88d45ce..03fbf5b 100644 --- a/boards/88.c +++ b/boards/88.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/90.c b/boards/90.c index caccc09..074f560 100644 --- a/boards/90.c +++ b/boards/90.c @@ -16,7 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -52,15 +52,15 @@ static uint8 tekker; static SFORMAT Tek_StateRegs[]={ {&IRQMode, 1, "IRQM"}, {&IRQPre, 1, "IRQP"}, - {&IRQPreSize, 1, "IRQS"}, + {&IRQPreSize, 1, "IRQR"}, {&IRQCount, 1, "IRQC"}, {&IRQXOR, 1, "IRQX"}, - {&IRQa, 1, "IRQa"}, + {&IRQa, 1, "IRQA"}, {mul, 2, "MUL"}, {®ie, 1, "REGI"}, {tkcom, 4, "TKCO"}, {prgb, 4, "PRGB"}, - {chr, 2, "CHRA"}, + {chr, 2, "CLTC"}, {chrlow, 4, "CHRL"}, {chrhigh, 8, "CHRH"}, {&names[0], 2|FCEUSTATE_RLSB, "NMS0"}, @@ -104,27 +104,30 @@ static void mira(void) } } -static void tekprom(void) +static void tekprom(void) // TODO: verify for single, small multi and large multi { uint32 bankmode=((tkcom[3]&6)<<5); switch(tkcom[0]&7) { case 00: if(tkcom[0]&0x80) setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); - setprg32(0x8000,0x0F|((tkcom[3]&6)<<3)); + setprg32(0x8000,(prgb[3]&7)|((tkcom[3]&7)<<3)); break; case 01: if(tkcom[0]&0x80) setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); - setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4)); - setprg16(0xC000,0x1F|((tkcom[3]&6)<<4)); + setprg16(0x8000,(prgb[1]&0x0F)|((tkcom[3]&7)<<4)); + setprg16(0xC000,0x0F|((tkcom[3]&7)<<4)); break; case 03: // bit reversion - case 02: if(tkcom[0]&0x80) - setprg8(0x6000,(prgb[3]&0x3F)|bankmode); - setprg8(0x8000,(prgb[0]&0x3F)|bankmode); - setprg8(0xa000,(prgb[1]&0x3F)|bankmode); - setprg8(0xc000,(prgb[2]&0x3F)|bankmode); - setprg8(0xe000,0x3F|bankmode); + case 02: + if(tkcom[0]&0x80) + setprg8(0x6000,(prgb[3]&0x1F)|((tkcom[3]&7)<<5)); // 45in1 multy has different bits, seems board was hacked to support big data banks + setprg8(0x8000,(prgb[0]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xa000,(prgb[1]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xc000,(prgb[2]&0x1F)|((tkcom[3]&7)<<5)); + setprg8(0xe000,0x1F|((tkcom[3]&7)<<5)); +// setprg8(0xe000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3)); +// setprg32(0x8000,((prgb[0]&0x0F)>>2)|((tkcom[3]&6)<<3)); break; case 04: if(tkcom[0]&0x80) setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); @@ -253,19 +256,19 @@ static DECLFW(M90IRQWrite) case 03: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline); IRQa=1;break; case 01: IRQMode=V; - // FCEU_printf("IRQ Count method: "); - // switch (IRQMode&3) - // { - // case 00: FCEU_printf("M2 cycles\n");break; - // case 01: FCEU_printf("PPU A12 toggles\n");break; - // case 02: FCEU_printf("PPU reads\n");break; - // case 03: FCEU_printf("Writes to CPU space\n");break; - // } - // FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); - // FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); - // if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); - // else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); - // else FCEU_printf("Counter Stopped\n"); + /*FCEU_printf("IRQ Count method: "); + switch (IRQMode&3) + { + case 00: FCEU_printf("M2 cycles\n");break; + case 01: FCEU_printf("PPU A12 toggles\n");break; + case 02: FCEU_printf("PPU reads\n");break; + case 03: FCEU_printf("Writes to CPU space\n");break; + } + FCEU_printf("Counter prescaler size: %s\n",(IRQMode&4)?"3 bits":"8 bits"); + FCEU_printf("Counter prescaler size adjust: %s\n",(IRQMode&8)?"Used C007":"Normal Operation"); + if((IRQMode>>6)==2) FCEU_printf("Counter Down\n"); + else if((IRQMode>>6)==1) FCEU_printf("Counter Up\n"); + else FCEU_printf("Counter Stopped\n");*/ break; case 04: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); IRQPre=V^IRQXOR;break; @@ -366,7 +369,7 @@ static void ClockCounter(void) } } -void CPUWrap(int a) +void FP_FASTAPASS(1) CPUWrap(int a) { int x; if((IRQMode&3)==0) for(x=0;x=8) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper91_Init(CartInfo *info) +{ + info->Power=M91Power; + GameHBIRQHook=M91IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/95.c b/boards/95.c index 0a5d9dd..7b69435 100644 --- a/boards/95.c +++ b/boards/95.c @@ -15,11 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" -#include "../ines.h" static uint8 lastA; static uint8 DRegs[8]; @@ -79,7 +78,7 @@ static DECLFW(Mapper95_write) } } -static void dragonbust_ppu(uint32 A) +static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A) { static int last=-1; static uint8 z; diff --git a/boards/96.c b/boards/96.c new file mode 100644 index 0000000..aa9d8a7 --- /dev/null +++ b/boards/96.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2002 Xodnizel + * Copyright (C) 2012 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 + * + * Oeka-kids board + * + * I might want to add some code to the mapper 96 PPU hook function + * to not change CHR banks if the attribute table is being accessed, + * if I make emulation a little more accurate in the future. + * + */ + +#include "mapinc.h" + +static uint8 reg, ppulatch; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&ppulatch, 1, "PPUL"}, + {0} +}; + +static void Sync(void) +{ + setmirror(MI_0); + setprg32(0x8000,reg & 3); + setchr4(0x0000,(reg & 4) | ppulatch); + setchr4(0x1000,(reg & 4) | 3); +} + +static DECLFW(M96Write) +{ + reg = V; + Sync(); +} + +static void FP_FASTAPASS(1) M96Hook(uint32 A) +{ + if((A & 0x3000) == 0x2000) + { + ppulatch = (A>>8) & 3; + Sync(); + } +} + +static void M96Power(void) +{ + reg = ppulatch = 0; + Sync(); + SetReadHandler(0x8000,0xffff,CartBR); + SetWriteHandler(0x8000,0xffff,M96Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper96_Init(CartInfo *info) +{ + info->Power=M96Power; + PPU_hook=M96Hook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/boards/99.c b/boards/99.c new file mode 100644 index 0000000..826af3e --- /dev/null +++ b/boards/99.c @@ -0,0 +1,67 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * VS Super Mario Bros has a problem, FCEUX doesn't! + */ + +#include "mapinc.h" + +static uint8 latch; +static writefunc old4016; + +static SFORMAT StateRegs[]= +{ + {&latch, 1, "LATC"}, + {0} +}; + +static void Sync(void) +{ + setchr8((latch >> 2) & 1); + setprg32(0x8000,0); + setprg8(0x8000,latch & 4); /* Special for VS Gumshoe */ +} + +static DECLFW(M99Write) +{ + latch = V; + Sync(); + old4016(A,V); +} + +static void M99Power(void) +{ + latch = 0; + Sync(); + old4016=GetWriteHandler(0x4016); + SetWriteHandler(0x4016,0x4016,M99Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper99_Init(CartInfo *info) +{ + info->Power=M99Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/179.c b/boards/KS7012.c similarity index 62% rename from boards/179.c rename to boards/KS7012.c index 91a530f..b764ff8 100644 --- a/boards/179.c +++ b/boards/KS7012.c @@ -15,80 +15,80 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" -static uint8 reg[2]; - +static uint8 reg; static uint8 *WRAM=NULL; static uint32 WRAMSIZE; static SFORMAT StateRegs[]= { - {reg, 2, "REG"}, + {®, 1, "REGS"}, {0} }; static void Sync(void) { - setchr8(0); setprg8r(0x10,0x6000,0); - setprg32(0x8000,reg[1]>>1); - setmirror((reg[0]&1)^1); + setprg32(0x8000,reg&1); + setchr8(0); +} + +static DECLFW(UNLKS7012Write) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + switch(A) + { + case 0xE0A0: reg=0; Sync(); break; + case 0xEE36: reg=1; Sync(); break; + } } -static DECLFW(M179Write) +static void UNLKS7012Power(void) { - if(A==0xa000) reg[0]=V; + reg = ~0; Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7012Write); } -static DECLFW(M179WriteLo) +static void UNLKS7012Reset(void) { - if(A==0x5ff1) reg[1]=V; + reg = ~0; Sync(); } -static void M179Power(void) +static void StateRestore(int version) { - 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); + Sync(); } -static void M179Close(void) +static void UNLKS7012Close(void) { if(WRAM) FCEU_gfree(WRAM); WRAM=NULL; } -static void StateRestore(int version) +void UNLKS7012_Init(CartInfo *info) { - Sync(); -} - -void Mapper179_Init(CartInfo *info) -{ - info->Power=M179Power; - info->Close=M179Close; - GameStateRestore=StateRestore; + info->Power=UNLKS7012Power; + info->Reset=UNLKS7012Reset; + info->Close=UNLKS7012Close; 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/boards/KS7013.c b/boards/KS7013.c new file mode 100644 index 0000000..8476003 --- /dev/null +++ b/boards/KS7013.c @@ -0,0 +1,84 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * Just another pirate cart with pirate mapper, instead of original MMC1 + * Kaiser Highway Star + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000,reg); + setprg16(0xc000,~0); + setmirror(mirr); + setchr8(0); +} + +static DECLFW(UNLKS7013BLoWrite) +{ + reg = V; + Sync(); +} + +static DECLFW(UNLKS7013BHiWrite) +{ + mirr = (V & 1) ^ 1; + Sync(); +} + +static void UNLKS7013BPower(void) +{ + reg = 0; + mirr = 0; + Sync(); + SetWriteHandler(0x6000,0x7FFF,UNLKS7013BLoWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7013BHiWrite); +} + +static void UNLKS7013BReset(void) +{ + reg = 0; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7013B_Init(CartInfo *info) +{ + info->Power=UNLKS7013BPower; + info->Reset=UNLKS7013BReset; + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/KS7017.c b/boards/KS7017.c new file mode 100644 index 0000000..9402f99 --- /dev/null +++ b/boards/KS7017.c @@ -0,0 +1,134 @@ +/* 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; +static int32 IRQa, IRQCount, IRQLatch; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&mirr, 1, "MIRR"}, + {®, 1, "REGS"}, + {&IRQa, 4, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {&IRQLatch, 4, "IRQL"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000,reg); + setprg16(0xC000,2); + setmirror(mirr); +} + +static DECLFW(UNLKS7017Write) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + if((A & 0xFF00) == 0x4A00) + { + reg = ((A >> 2) & 3)|((A >> 4) & 4); + } + else if ((A & 0xFF00) == 0x5100) + { + Sync(); + } + else if (A == 0x4020) + { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount&=0xFF00; + IRQCount|=V; + } + else if (A == 0x4021) + { + X6502_IRQEnd(FCEU_IQEXT); + IRQCount&=0xFF; + IRQCount|=V<<8; + IRQa = 1; + } + else if (A == 0x4025) + { + mirr = ((V & 8) >> 3) ^ 1; + } +} + +static DECLFR(FDSRead4030) +{ + X6502_IRQEnd(FCEU_IQEXT); + return X.IRQlow&FCEU_IQEXT?1:0; +} + +static void FP_FASTAPASS(1) UNL7017IRQ(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<=0) + { + IRQa=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void UNLKS7017Power(void) +{ + Sync(); + setchr8(0); + setprg8r(0x10,0x6000,0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x4030,0x4030,FDSRead4030); + SetWriteHandler(0x4020,0x5FFF,UNLKS7017Write); +} + +static void UNLKS7017Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7017_Init(CartInfo *info) +{ + info->Power=UNLKS7017Power; + info->Close=UNLKS7017Close; + MapIRQHook=UNL7017IRQ; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/KS7030.c b/boards/KS7030.c new file mode 100644 index 0000000..58abf0e --- /dev/null +++ b/boards/KS7030.c @@ -0,0 +1,151 @@ +/* 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 + * + * FDS Conversion + * + * Logical bank layot 32 K BANK 0, 64K BANK 1, 32K ~0 hardwired, 8K is missing + * need redump from MASKROM! + * probably need refix mapper after hard dump + * + */ + +#include "mapinc.h" + +static uint8 reg0, reg1; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®0, 1, "REG0"}, + {®1, 1, "REG1"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg32(0x8000,~0); + setprg4(0xb800,reg0); + setprg4(0xc800,8+reg1); +} + +// 6000 - 6BFF - RAM +// 6C00 - 6FFF - BANK 1K REG1 +// 7000 - 7FFF - BANK 4K REG0 + +static DECLFW(UNLKS7030RamWrite0) +{ + if((A >= 0x6000) && A <= 0x6BFF) { + WRAM[A-0x6000]=V; + } else if((A >= 0x6C00) && A <= 0x6FFF) { + CartBW(0xC800 + (A - 0x6C00), V); + } else if((A >= 0x7000) && A <= 0x7FFF) { + CartBW(0xB800 + (A - 0x7000), V); + } +} + +static DECLFR(UNLKS7030RamRead0) +{ + if((A >= 0x6000) && A <= 0x6BFF) { + return WRAM[A-0x6000]; + } else if((A >= 0x6C00) && A <= 0x6FFF) { + return CartBR(0xC800 + (A - 0x6C00)); + } else if((A >= 0x7000) && A <= 0x7FFF) { + return CartBR(0xB800 + (A - 0x7000)); + } + return 0; +} + +// B800 - BFFF - RAM +// C000 - CBFF - BANK 3K +// CC00 - D7FF - RAM + +static DECLFW(UNLKS7030RamWrite1) +{ + if((A >= 0xB800) && A <= 0xBFFF) { + WRAM[0x0C00+(A-0xB800)]=V; + } else if((A >= 0xC000) && A <= 0xCBFF) { + CartBW(0xCC00 + (A - 0xC000), V); + } else if((A >= 0xCC00) && A <= 0xD7FF) { + WRAM[0x1400+(A-0xCC00)]=V; + } +} + +static DECLFR(UNLKS7030RamRead1) +{ + if((A >= 0xB800) && A <= 0xBFFF) { + return WRAM[0x0C00+(A-0xB800)]; + } else if((A >= 0xC000) && A <= 0xCBFF) { + return CartBR(0xCC00 + (A - 0xC000)); + } else if((A >= 0xCC00) && A <= 0xD7FF) { + return WRAM[0x1400+(A-0xCC00)]; + } + return 0; +} + +static DECLFW(UNLKS7030Write0) +{ + reg0=A&7; + Sync(); +} + +static DECLFW(UNLKS7030Write1) +{ + reg1=A&15; + Sync(); +} + +static void UNLKS7030Power(void) +{ + reg0=reg1=~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,UNLKS7030RamRead0); + SetWriteHandler(0x6000,0x7FFF,UNLKS7030RamWrite0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0x8FFF,UNLKS7030Write0); + SetWriteHandler(0x9000,0x9FFF,UNLKS7030Write1); + SetReadHandler(0xB800,0xD7FF,UNLKS7030RamRead1); + SetWriteHandler(0xB800,0xD7FF,UNLKS7030RamWrite1); +} + +static void UNLKS7030Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7030_Init(CartInfo *info) +{ + info->Power=UNLKS7030Power; + info->Close=UNLKS7030Close; + GameStateRestore=StateRestore; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/KS7031.c b/boards/KS7031.c new file mode 100644 index 0000000..e2b8769 --- /dev/null +++ b/boards/KS7031.c @@ -0,0 +1,85 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[4]; + +static SFORMAT StateRegs[]= +{ + {reg, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg2(0x6000,reg[0]); + setprg2(0x6800,reg[1]); + setprg2(0x7000,reg[2]); + setprg2(0x7800,reg[3]); + + setprg2(0x8000,15); + setprg2(0x8800,14); + setprg2(0x9000,13); + setprg2(0x9800,12); + setprg2(0xa000,11); + setprg2(0xa800,10); + setprg2(0xb000,9); + setprg2(0xb800,8); + + setprg2(0xc000,7); + setprg2(0xc800,6); + setprg2(0xd000,5); + setprg2(0xd800,4); + setprg2(0xe000,3); + setprg2(0xe800,2); + setprg2(0xf000,1); + setprg2(0xf800,0); + + setchr8(0); +} + +static DECLFW(UNLKS7031Write) +{ + reg[(A >> 11) & 3] = V; + Sync(); +} + +static void UNLKS7031Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xffff,UNLKS7031Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLKS7031_Init(CartInfo *info) +{ + info->Power=UNLKS7031Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/ks7032.c b/boards/KS7032.c similarity index 78% rename from boards/ks7032.c rename to boards/KS7032.c index fcb0eb5..c93fc15 100644 --- a/boards/ks7032.c +++ b/boards/KS7032.c @@ -15,12 +15,15 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" -static uint8 reg[8], cmd, IRQa; +static uint8 reg[8], cmd, IRQa = 0, isirqused = 0; static int32 IRQCount; static SFORMAT StateRegs[]= @@ -45,20 +48,20 @@ static void Sync(void) static DECLFW(UNLKS7032Write) { // FCEU_printf("bs %04x %02x\n",A,V); - switch(A) + switch(A&0xF000) { // 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 0x8000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x000F)|(V&0x0F); isirqused = 1; break; + case 0x9000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x00F0)|((V&0x0F)<<4); isirqused = 1; break; + case 0xA000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0x0F00)|((V&0x0F)<<8); isirqused = 1; break; + case 0xB000: X6502_IRQEnd(FCEU_IQEXT); IRQCount=(IRQCount&0xF000)|(V<<12); isirqused = 1; break; + case 0xC000: if(isirqused) { 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) +static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { if(IRQa) { diff --git a/boards/KS7037.c b/boards/KS7037.c new file mode 100644 index 0000000..d980a6f --- /dev/null +++ b/boards/KS7037.c @@ -0,0 +1,135 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], cmd; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static void(*WSync)(void); + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {reg, 8, "REGS"}, + {0} +}; + +static void SyncKS7037(void) +{ + setprg4r(0x10,0x6000,0); + setprg4(0x7000,15); + setprg8(0x8000,reg[6]); + setprg4(0xA000,~3); + setprg4r(0x10,0xB000,1); + setprg8(0xC000,reg[7]); + setprg8(0xE000,~0); + setchr8(0); + setmirrorw(reg[2]&1,reg[4]&1,reg[3]&1,reg[5]&1); +} + +static void SyncLH10(void) +{ + setprg8(0x6000,~1); + setprg8(0x8000,reg[6]); + setprg8(0xA000,reg[7]); + setprg8r(0x10,0xC000,0); + setprg8(0xE000,~0); + setchr8(0); + setmirror(0); +} + +static DECLFW(UNLKS7037Write) +{ + switch(A & 0xE001) + { + case 0x8000: cmd = V & 7; break; + case 0x8001: reg[cmd] = V; WSync(); break; + } +} + +static void UNLKS7037Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x8000,0x9FFF,UNLKS7037Write); + SetWriteHandler(0xA000,0xBFFF,CartBW); + SetWriteHandler(0xC000,0xFFFF,UNLKS7037Write); +} + +static void LH10Power(void) +{ + reg[0]=reg[1]=reg[2]=reg[3]=reg[4]=reg[5]=reg[6]=reg[7]=0; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,UNLKS7037Write); + SetWriteHandler(0xC000,0xDFFF,CartBW); + SetWriteHandler(0xE000,0xFFFF,UNLKS7037Write); +} + +static void Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + WSync(); +} + +void UNLKS7037_Init(CartInfo *info) +{ + info->Power=UNLKS7037Power; + info->Close=Close; + + WSync = SyncKS7037; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void LH10_Init(CartInfo *info) +{ + info->Power=LH10Power; + info->Close=Close; + + WSync = SyncLH10; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/KS7057.c b/boards/KS7057.c new file mode 100644 index 0000000..8dd3caa --- /dev/null +++ b/boards/KS7057.c @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg[8], mirror; +static SFORMAT StateRegs[]= +{ + {reg, 8, "PRG"}, + {&mirror, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg2(0x6000,reg[4]); + setprg2(0x6800,reg[5]); + setprg2(0x7000,reg[6]); + setprg2(0x7800,reg[7]); + setprg2(0x8000,reg[0]); + setprg2(0x8800,reg[1]); + setprg2(0x9000,reg[2]); + setprg2(0x9800,reg[3]); + setprg8(0xA000,0xd); + setprg16(0xC000,7); + setchr8(0); + setmirror(mirror); +} + +static DECLFW(UNLKS7057Write) +{ + switch(A&0xF003) { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: + case 0x9000: + case 0x9001: + case 0x9002: + case 0x9003: mirror = V & 1; Sync(); break; + case 0xB000: reg[0] = (reg[0] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB001: reg[0] = (reg[0] & 0x0F) | (V << 4); Sync(); break; + case 0xB002: reg[1] = (reg[1] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xB003: reg[1] = (reg[1] & 0x0F) | (V << 4); Sync(); break; + case 0xC000: reg[2] = (reg[2] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC001: reg[2] = (reg[2] & 0x0F) | (V << 4); Sync(); break; + case 0xC002: reg[3] = (reg[3] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xC003: reg[3] = (reg[3] & 0x0F) | (V << 4); Sync(); break; + case 0xD000: reg[4] = (reg[4] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD001: reg[4] = (reg[4] & 0x0F) | (V << 4); Sync(); break; + case 0xD002: reg[5] = (reg[5] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xD003: reg[5] = (reg[5] & 0x0F) | (V << 4); Sync(); break; + case 0xE000: reg[6] = (reg[6] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE001: reg[6] = (reg[6] & 0x0F) | (V << 4); Sync(); break; + case 0xE002: reg[7] = (reg[7] & 0xF0) | (V & 0x0F); Sync(); break; + case 0xE003: reg[7] = (reg[7] & 0x0F) | (V << 4); Sync(); break; + } +} + +static void UNLKS7057Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLKS7057Write); +} + +static void UNLKS7057Reset(void) +{ + Sync(); +} + +void UNLKS7057_Init(CartInfo *info) +{ + info->Power=UNLKS7057Power; + info->Reset=UNLKS7057Reset; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/Makefile b/boards/Makefile index b14ee56..33f1c5f 100644 --- a/boards/Makefile +++ b/boards/Makefile @@ -10,10 +10,8 @@ B_C += boards/121.c B_C += boards/15.c B_C += boards/164.c B_C += boards/175.c -B_C += boards/176.c B_C += boards/177.c B_C += boards/178.c -B_C += boards/179.c B_C += boards/183.c B_C += boards/185.c B_C += boards/186.c @@ -37,7 +35,6 @@ B_C += boards/830118C.c B_C += boards/88.c B_C += boards/90.c B_C += boards/95.c -B_C += boards/a9711.c B_C += boards/a9746.c B_C += boards/addrlatch.c B_C += boards/ax5705.c @@ -61,12 +58,10 @@ B_C += boards/h2288.c B_C += boards/karaoke.c B_C += boards/kof97.c B_C += boards/konami-qtai.c -B_C += boards/ks7032.c B_C += boards/malee.c B_C += boards/mmc1.c B_C += boards/mmc3.c B_C += boards/mmc5.c -B_C += boards/n-c22m.c B_C += boards/n106.c B_C += boards/n625092.c B_C += boards/novel.c @@ -84,5 +79,44 @@ B_C += boards/t-262.c B_C += boards/tengen.c B_C += boards/tf-1201.c +B_C += boards/12in1.c +B_C += boards/151.c +B_C += boards/156.c +B_C += boards/168.c +B_C += boards/17.c +B_C += boards/170.c +B_C += boards/18.c +B_C += boards/193.c +B_C += boards/225.c +B_C += boards/34.c +B_C += boards/82.c +B_C += boards/91.c +B_C += boards/96.c +B_C += boards/99.c +B_C += boards/KS7012.c +B_C += boards/KS7013.c +B_C += boards/KS7017.c +B_C += boards/KS7030.c +B_C += boards/KS7031.c +B_C += boards/KS7032.c +B_C += boards/KS7037.c +B_C += boards/KS7057.c +B_C += boards/SA-9602B.c +B_C += boards/__serial.c +B_C += boards/ac-08.c +B_C += boards/bb.c +B_C += boards/cityfighter.c +B_C += boards/copyfami_emu.c +B_C += boards/copyfami_hwi.c +B_C += boards/dance2000.c +B_C += boards/famicombox.c +B_C += boards/le05.c +B_C += boards/lh32.c +B_C += boards/lh53.c +B_C += boards/pec-586.c +B_C += boards/transformer.c +B_C += boards/vrc7.c +B_C += boards/yoko.c + MUOBJS += $(patsubst %.c,%.o,$(B_C)) diff --git a/boards/SA-9602B.c b/boards/SA-9602B.c new file mode 100644 index 0000000..c39fdac --- /dev/null +++ b/boards/SA-9602B.c @@ -0,0 +1,67 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2012 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 void SA9602BPW(uint32 A, uint8 V) +{ + setprg8r(EXPREGS[1],A,V&0x3F); + if(MMC3_cmd&0x40) + setprg8r(0,0x8000,~(1)); + else + setprg8r(0,0xc000,~(1)); + setprg8r(0,0xe000,~(0)); +} + +static DECLFW(SA9602BWrite) +{ + switch(A & 0xe001) + { + case 0x8000: EXPREGS[0] = V; break; + case 0x8001: + if((EXPREGS[0] & 7) < 6) + { + EXPREGS[1] = V >> 6; + FixMMC3PRG(MMC3_cmd); + } + break; + } + MMC3_CMDWrite(A, V); +} + +static void SA9602BPower(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xBFFF,SA9602BWrite); +} + +void SA9602B_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 0, 0, 0); + pwrap=SA9602BPW; + mmc3opts|=2; + info->SaveGame[0]=UNIFchrrama; + info->SaveGameLen[0]=32 * 1024; + info->Power=SA9602BPower; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/boards/__dummy_mapper.c b/boards/__dummy_mapper.c index f56736d..eaa40f9 100644 --- a/boards/__dummy_mapper.c +++ b/boards/__dummy_mapper.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2009 CaH4e3 + * Copyright (C) 2012 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 @@ -15,12 +15,14 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" static uint8 reg[8]; +static uint8 IRQa; +static int16 IRQCount, IRQLatch; /* static uint8 *WRAM=NULL; static uint32 WRAMSIZE; @@ -31,6 +33,9 @@ static uint32 CHRRAMSIZE; static SFORMAT StateRegs[]= { {reg, 8, "REGS"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 2, "IRQC"}, + {&IRQLatch, 2, "IRQL"}, {0} }; @@ -65,7 +70,7 @@ static void MNNNClose(void) } */ -static void MNNNIRQHook(void) +static void MNNNIRQHook() { X6502_IRQBegin(FCEU_IQEXT); } diff --git a/boards/__serial.c b/boards/__serial.c new file mode 100644 index 0000000..3b48240 --- /dev/null +++ b/boards/__serial.c @@ -0,0 +1,124 @@ + +#include "__serial.h" + +HANDLE SerialPort = NULL; // Handle of SerialPort itself. + +BOOL SerialOpen(int port, int baud) +{ + HANDLE Comport; + DCB myDCB; + COMMTIMEOUTS CTout; + char str[100]; + + if (port > 9) + sprintf(str, "\\\\.\\COM%d", port); + else + sprintf(str, "COM%d", port); + + // Open the serial port + if ((Comport = CreateFile(str, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL)) == INVALID_HANDLE_VALUE) + return FALSE; + + // Configure Serial port (Setup Comm) + + // Buffer sizes + if (!SetupComm(Comport, 128, 128)) + return FALSE; + + // Setup DCB using current values + if (!GetCommState(Comport, &myDCB)) + return FALSE; + + myDCB.fInX = FALSE; // Turn off xon/xoff handler + myDCB.fOutX = FALSE; + myDCB.fOutxDsrFlow = FALSE; + myDCB.fOutxCtsFlow = FALSE; // no hardware flow control. + myDCB.BaudRate = baud; + myDCB.DCBlength = sizeof(DCB); + myDCB.fBinary = 1; + myDCB.fParity = 0; + myDCB.fDtrControl = DTR_CONTROL_DISABLE; + myDCB.fDsrSensitivity = 0; + myDCB.fTXContinueOnXoff = 1; + myDCB.fNull = 0; + myDCB.fRtsControl = RTS_CONTROL_DISABLE; + myDCB.fDummy2 = 0; + myDCB.wReserved = 0; + myDCB.Parity = NOPARITY; + myDCB.StopBits = ONESTOPBIT; + myDCB.wReserved1 = 0; + myDCB.ByteSize = 8; + + if (!SetCommState(Comport, &myDCB)) + return FALSE; + + // Set timeouts + CTout.ReadIntervalTimeout = 0xffffffff; + CTout.ReadTotalTimeoutMultiplier = 0; + CTout.ReadTotalTimeoutConstant = 0; + CTout.WriteTotalTimeoutMultiplier = 0; + CTout.WriteTotalTimeoutConstant = 5000; // don't hang if CTS is locked, for example + + SetCommTimeouts(Comport, &CTout); + EscapeCommFunction(Comport, SETDTR); + PurgeComm(Comport, PURGE_TXCLEAR | PURGE_RXCLEAR); + + SerialPort = Comport; + + return TRUE; +} + +void SerialClose(void) +{ + if (SerialPort == NULL) return; + + PurgeComm(SerialPort, PURGE_TXCLEAR | PURGE_RXCLEAR); + CloseHandle(SerialPort); + + SerialPort = NULL; +} + +BOOL SerialSendChar(int c) +{ + DWORD cr; + if(WriteFile(SerialPort, &c, 1, (LPDWORD)&cr, NULL) && cr) + return TRUE; + else + return FALSE; +} + +int SerialIsOpen(void) +{ + return (SerialPort != NULL); +} + +int SerialGetChar(void) +{ + uint8 ch; + DWORD cr; + if (SerialPort != NULL) { + if (ReadFile(SerialPort, &ch, 1, (LPDWORD)&cr, NULL) && cr) + return (int)ch; + } + return EOF; +} + +void SendCmd(uint8 *cmd, int size) +{ + int i; + for(i=0; i +#include +#include "../types.h" + +void SendCmd(uint8 *cmd, int size); +int ReadResp(uint8 *resp, int size); + +#define SEND(cmd) SendCmd((uint8 *)&cmd[0], sizeof(cmd)) +#define GET(buf, size) ReadResp((uint8 *)&buf, size) +#define SENDGET(cmd, buf, size) SEND(cmd); GET(buf, size) + +BOOL SerialOpen(int port, int baud); +void SerialClose(void); +BOOL SerialSendChar(int c); +int SerialIsOpen(void); +int SerialGetChar(void); + +#endif diff --git a/boards/a9711.c b/boards/a9711.c deleted file mode 100644 index 3fb5460..0000000 --- a/boards/a9711.c +++ /dev/null @@ -1,78 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" -#include "mmc3.h" - -//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7}; - -static void UNLA9711PW(uint32 A, uint8 V) -{ - if((EXPREGS[0]&0xFF) == 0x37) - { - setprg8(0x8000, 0x13); - setprg8(0xA000, 0x13); - setprg8(0xC000, 0x13); - setprg8(0xE000, 0x0); -// uint8 bank=EXPREGS[0]&0x1F; -// if(EXPREGS[0]&0x20) -// setprg32(0x8000,bank>>2); -// else -// { -// setprg16(0x8000,bank); -// setprg16(0xC000,bank); -// } - } - else - setprg8(A,V&0x3F); -} - -//static DECLFW(UNLA9711Write8000) -//{ -// FCEU_printf("bs %04x %02x\n",A,V); -// if(V&0x80) -// MMC3_CMDWrite(A,V); -// else -// MMC3_CMDWrite(A,m_perm[V&7]); -// if(V!=0x86) MMC3_CMDWrite(A,V); -//} - -static DECLFW(UNLA9711WriteLo) -{ - FCEU_printf("bs %04x %02x\n",A,V); - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); -} - -static void UNLA9711Power(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; - GenMMC3Power(); - SetWriteHandler(0x5000,0x5FFF,UNLA9711WriteLo); -// SetWriteHandler(0x8000,0xbfff,UNLA9711Write8000); -} - -void UNLA9711_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap=UNLA9711PW; - info->Power=UNLA9711Power; - AddExState(EXPREGS, 3, 0, "EXPR"); -} diff --git a/boards/a9746.c b/boards/a9746.c index 3522336..1030cad 100644 --- a/boards/a9746.c +++ b/boards/a9746.c @@ -1,4 +1,3 @@ - /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: @@ -16,112 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -183,4 +77,4 @@ void UNLA9746_Init(CartInfo *info) info->Power=UNLA9746Power; AddExState(EXPREGS, 6, 0, "EXPR"); } -/**/ + diff --git a/boards/ac-08.c b/boards/ac-08.c new file mode 100644 index 0000000..906bbb1 --- /dev/null +++ b/boards/ac-08.c @@ -0,0 +1,77 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, mirr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&mirr, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000, reg); + setprg32r(1, 0x8000, 0); + setchr8(0); + setmirror(mirr); +} + +static DECLFW(AC08Mirr) +{ + mirr = ((V&8)>>3)^1; + Sync(); +} + +static DECLFW(AC08Write) +{ + if(A == 0x8001) // Green Berret bank switching is only 100x xxxx xxxx xxx1 mask + reg = (V >> 1) & 0xf; + else + reg = V & 0xf; // Sad But True, 2-in-1 mapper, Green Berret need value shifted left one byte, Castlevania doesn't + Sync(); +} + +static void AC08Power(void) +{ + reg = 0; + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x4025,0x4025,AC08Mirr); + SetWriteHandler(0x8000,0xFFFF,AC08Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void AC08_Init(CartInfo *info) +{ + info->Power=AC08Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/addrlatch.c b/boards/addrlatch.c index 4b70d6e..afd0919 100644 --- a/boards/addrlatch.c +++ b/boards/addrlatch.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -27,7 +27,7 @@ static readfunc defread; static DECLFW(LatchWrite) { - FCEU_printf("%04x:%02x\n",A,V); +// FCEU_printf("%04x:%02x\n",A,V); latche=A; WSync(); } @@ -119,6 +119,41 @@ void BMCD1038_Init(CartInfo *info) } +//------------------ UNL43272 --------------------------- +// mapper much complex, including 16K bankswitching +static void UNL43272Sync(void) +{ + if((latche&0x81) == 0x81) + { + setprg32(0x8000,(latche&0x38)>>3); + } + else + FCEU_printf("unrecognized command %04!\n",latche); + setchr8(0); + setmirror(0); +} + +static DECLFR(UNL43272Read) +{ + if(latche&0x400) + return CartBR(A & 0xFE); + else + return CartBR(A); +} + +static void UNL43272Reset(void) +{ + latche = 0; + UNL43272Sync(); +} + +void UNL43272_Init(CartInfo *info) +{ + Latch_Init(info, UNL43272Sync, UNL43272Read, 0x81, 0x8000, 0xFFFF); + info->Reset=UNL43272Reset; + AddExState(&dipswitch, 1, 0, "DIPSW"); +} + //------------------ Map 058 --------------------------- static void BMCGK192Sync(void) @@ -139,6 +174,39 @@ void BMCGK192_Init(CartInfo *info) Latch_Init(info, BMCGK192Sync, 0, 0, 0x8000, 0xFFFF); } +//------------------ Map 092 --------------------------- +// Another two-in-one mapper, two Jaleco carts uses similar +// hardware, but with different wiring. +// Original code provided by LULU +// Additionally, PCB contains DSP extra sound chip, used for voice samples (unemulated) + +static void M92Sync(void) +{ + uint8 reg = latche & 0xF0; + setprg16(0x8000,0); + if(latche>=0x9000) + { + switch (reg) + { + case 0xD0: setprg16(0xc000, latche & 15); break; + case 0xE0: setchr8(latche & 15); break; + } + } + else + { + switch (reg) + { + case 0xB0: setprg16(0xc000, latche & 15); break; + case 0x70: setchr8(latche & 15); break; + } + } +} + +void Mapper92_Init(CartInfo *info) +{ + Latch_Init(info, M92Sync, 0, 0x80B0, 0x8000, 0xFFFF); +} + //------------------ Map 200 --------------------------- static void M200Sync(void) @@ -170,3 +238,49 @@ void BMC190in1_Init(CartInfo *info) Latch_Init(info, BMC190in1Sync, 0, 0, 0x8000, 0xFFFF); } +//-------------- BMC810544-C-A1 ------------------------ + +static void BMC810544CA1Sync(void) +{ + uint32 bank = latche>>7; + if(latche&0x40) + setprg32(0x8000,bank); + else + { + setprg16(0x8000,(bank<<1)|((latche>>5)&1)); + setprg16(0xC000,(bank<<1)|((latche>>5)&1)); + } + setchr8(latche&0x0f); + setmirror(((latche>>4)&1)^1); +} + +void BMC810544CA1_Init(CartInfo *info) +{ + Latch_Init(info, BMC810544CA1Sync, 0, 0, 0x8000, 0xFFFF); +} + +//-------------- BMCNTD-03 ------------------------ + +static void BMCNTD03Sync(void) +{ + // 1PPP Pmcc spxx xccc + // 1000 0000 0000 0000 v + // 1001 1100 0000 0100 h + // 1011 1010 1100 0100 + uint32 prg = ((latche>>10)&0x1e); + uint32 chr = ((latche&0x0300)>>5)|(latche&7); + if(latche&0x80) + { + setprg16(0x8000,prg|((latche>>6)&1)); + setprg16(0xC000,prg|((latche>>6)&1)); + } + else + setprg32(0x8000,prg>>1); + setchr8(chr); + setmirror(((latche>>10)&1)^1); +} + +void BMCNTD03_Init(CartInfo *info) +{ + Latch_Init(info, BMCNTD03Sync, 0, 0, 0x8000, 0xFFFF); +} diff --git a/boards/ax5705.c b/boards/ax5705.c index 66f1498..823381a 100644 --- a/boards/ax5705.c +++ b/boards/ax5705.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Super Bros. Pocker Mali (VRC4 mapper) */ @@ -54,11 +54,11 @@ static void UNLAX5705IRQ(void) static void Sync(void) { - int i; setprg8(0x8000,prg_reg[0]); setprg8(0xA000,prg_reg[1]); setprg8(0xC000,~1); setprg8(0xE000,~0); + int i; for(i=0; i<8; i++) setchr1(i<<10,chr_reg[i]); setmirror(mirr^1); diff --git a/boards/bandai.c b/boards/bandai.c index 8468aad..8928bfb 100644 --- a/boards/bandai.c +++ b/boards/bandai.c @@ -2,7 +2,6 @@ * * Copyright notice for this file: * Copyright (C) 2007 CaH4e3 - * Copyright (C) 2011 FCEUX team * * 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 @@ -16,17 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Bandai mappers * */ -//Famicom Jump 2 should get transformed to m153 -//All other games are not supporting EEPROM saving right now. -//We may need to distinguish between 16 and 159 in order to know the EEPROM configuration. -//Until then, we just return 0x00 from the EEPROM read - #include "mapinc.h" static uint8 reg[16], is153; @@ -45,33 +39,37 @@ static SFORMAT StateRegs[]= {0} }; -static void BandaiIRQHook(int a) +static void FP_FASTAPASS(1) BandaiIRQHook(int a) { if(IRQa) { - IRQCount -= a; + IRQCount-=a; if(IRQCount<0) { X6502_IRQBegin(FCEU_IQEXT); - IRQa = 0; - IRQCount = -1; + IRQa=0; + IRQCount=0xFFFF; } } } static void BandaiSync(void) { + if(!UNIFchrrama) + { + int i; + for(i=0; i<8; i++) setchr1(i<<10,reg[i]); + } + else + setchr8(0); if(is153) { int base=(reg[0]&1)<<4; - 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); } @@ -96,41 +94,17 @@ static DECLFW(BandaiWrite) switch(A) { case 0x0A: X6502_IRQEnd(FCEU_IQEXT); IRQa=V&1; IRQCount=IRQLatch; break; - case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break; + case 0x0B: IRQLatch&=0xFF00; IRQLatch|=V; break; case 0x0C: IRQLatch&=0xFF; IRQLatch|=V<<8; break; case 0x0D: break;// Serial EEPROM control port } } -DECLFR(BandaiRead) -{ - return 0; -} - static void BandaiPower(void) { BandaiSync(); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x6000,0xFFFF,BandaiWrite); - SetReadHandler(0x6000,0x7FFF,BandaiRead); -} - -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) @@ -147,12 +121,31 @@ void Mapper16_Init(CartInfo *info) AddExState(&StateRegs, ~0, 0, 0); } -void Mapper159_Init(CartInfo *info) +// Famicom jump 2: +// 0-7: Lower bit of data selects which 256KB PRG block is in use. +// This seems to be a hack on the developers' part, so I'll make emulation +// 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 M153Power(void) { - Mapper16_Init(info); + 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; +} + void Mapper153_Init(CartInfo *info) { is153=1; @@ -174,3 +167,190 @@ void Mapper153_Init(CartInfo *info) GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); } + +// Datach Barcode Battler + +static uint8 BarcodeData[256]; +static int BarcodeReadPos; +static int BarcodeCycleCount; +static uint32 BarcodeOut; + +int FCEUI_DatachSet(const uint8 *rcode) +{ + int prefix_parity_type[10][6] = { + {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0}, + {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1}, + {0,1,0,1,1,0}, {0,1,1,0,1,0} + }; + int data_left_odd[10][7] = { + {0,0,0,1,1,0,1}, {0,0,1,1,0,0,1}, {0,0,1,0,0,1,1}, {0,1,1,1,1,0,1}, + {0,1,0,0,0,1,1}, {0,1,1,0,0,0,1}, {0,1,0,1,1,1,1}, {0,1,1,1,0,1,1}, + {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1} + }; + int data_left_even[10][7] = { + {0,1,0,0,1,1,1}, {0,1,1,0,0,1,1}, {0,0,1,1,0,1,1}, {0,1,0,0,0,0,1}, + {0,0,1,1,1,0,1}, {0,1,1,1,0,0,1}, {0,0,0,0,1,0,1}, {0,0,1,0,0,0,1}, + {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1} + }; + int data_right[10][7] = { + {1,1,1,0,0,1,0}, {1,1,0,0,1,1,0}, {1,1,0,1,1,0,0}, {1,0,0,0,0,1,0}, + {1,0,1,1,1,0,0}, {1,0,0,1,1,1,0}, {1,0,1,0,0,0,0}, {1,0,0,0,1,0,0}, + {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0} + }; + uint8 code[13+1]; + uint32 tmp_p=0; + int i, j; + int len; + + for(i=len=0;i<13;i++) + { + if(!rcode[i]) break; + if((code[i]=rcode[i]-'0') > 9) + return(0); + len++; + } + if(len!=13 && len!=12 && len!=8 && len!=7) return(0); + + #define BS(x) BarcodeData[tmp_p]=x;tmp_p++ + + for(j=0;j<32;j++) + { + BS(0x00); + } + + /* Left guard bars */ + BS(1); BS(0); BS(1); + + if(len==13 || len==12) + { + uint32 csum; + + for(i=0;i<6;i++) + if(prefix_parity_type[code[0]][i]) + { + for(j=0;j<7;j++) + { + BS(data_left_even[code[i+1]][j]); + } + } + else + for(j=0;j<7;j++) + { + BS(data_left_odd[code[i+1]][j]); + } + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for(i=7;i<12;i++) + for(j=0;j<7;j++) + { + BS(data_right[code[i]][j]); + } + csum=0; + for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1); + csum=(10-(csum%10))%10; + for(j=0;j<7;j++) + { + BS(data_right[csum][j]); + } + + } + else if(len==8 || len==7) + { + uint32 csum=0; + + for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3); + + csum=(10-(csum%10))%10; + + for(i=0;i<4;i++) + for(j=0;j<7;j++) + { + BS(data_left_odd[code[i]][j]); + } + + + /* Center guard bars */ + BS(0); BS(1); BS(0); BS(1); BS(0); + + for(i=4;i<7;i++) + for(j=0;j<7;j++) + { + BS(data_right[code[i]][j]); + } + + for(j=0;j<7;j++) + { BS(data_right[csum][j]);} + + } + + /* Right guard bars */ + BS(1); BS(0); BS(1); + + for(j=0;j<32;j++) + { + BS(0x00); + } + + BS(0xFF); + + #undef BS + + BarcodeReadPos=0; + BarcodeOut=0x8; + BarcodeCycleCount=0; + return(1); +} + +static void FP_FASTAPASS(1) BarcodeIRQHook(int a) +{ + BandaiIRQHook(a); + + BarcodeCycleCount+=a; + + if(BarcodeCycleCount >= 1000) + { + BarcodeCycleCount -= 1000; + if(BarcodeData[BarcodeReadPos]==0xFF) + { + BarcodeOut=0; + } + else + { + BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3; + BarcodeReadPos++; + } + } +} + +static DECLFR(BarcodeRead) +{ + return BarcodeOut; +} + +static void M157Power(void) +{ + BarcodeData[0]=0xFF; + BarcodeReadPos=0; + BarcodeOut=0; + BarcodeCycleCount=0; + + BandaiSync(); + + SetWriteHandler(0x6000,0xFFFF,BandaiWrite); + SetReadHandler(0x6000,0x7FFF,BarcodeRead); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +void Mapper157_Init(CartInfo *info) +{ + is153=0; + info->Power=M157Power; + MapIRQHook=BarcodeIRQHook; + + FCEUGameInfo->cspecial = SIS_DATACH; + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/bb.c b/boards/bb.c new file mode 100644 index 0000000..4cc0974 --- /dev/null +++ b/boards/bb.c @@ -0,0 +1,73 @@ +/* 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 + * + * FDS Conversion + * + * Bubble Bobble CHR-ROM version + * + */ + +#include "mapinc.h" + +static uint8 reg, chr; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&chr, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg&3); + setprg32(0x8000,~0); + setchr8(chr&3); +} + +static DECLFW(UNLBBWrite) +{ + if((A & 0x9000) == 0x8000) + reg=chr=V; + else + chr=V&1; // hacky hacky, ProWres simplified FDS conversion 2-in-1 mapper + Sync(); +} + +static void UNLBBPower(void) +{ + chr = 0; + reg = ~0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLBBWrite); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLBB_Init(CartInfo *info) +{ + info->Power=UNLBBPower; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/bmc13in1jy110.c b/boards/bmc13in1jy110.c index 89aa4fb..b7d9d7e 100644 --- a/boards/bmc13in1jy110.c +++ b/boards/bmc13in1jy110.c @@ -15,9 +15,9 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * BMC 42-in-1 reset switch + * BMC 42-in-1 "reset switch" type */ #include "mapinc.h" diff --git a/boards/bmc42in1r.c b/boards/bmc42in1r.c index bcbdfc1..6c1f209 100644 --- a/boards/bmc42in1r.c +++ b/boards/bmc42in1r.c @@ -16,27 +16,30 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * BMC 42-in-1 - * it seems now, mapper not reset-based, - * tested on real hardware and it does menus switch by pressing just Select, not Reset - * new registers behaviour proven this too + * BMC 42-in-1 "reset switch" + "select switch" * */ #include "mapinc.h" -static uint8 latche[2]; +static uint8 isresetbased = 0; +static uint8 latche[2], reset; static SFORMAT StateRegs[]= { - {&latche, sizeof(latche), "LATCHE"}, + {&reset, 1, "RST"}, + {latche, 2, "LATC"}, {0} }; static void Sync(void) { - uint8 bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1))<<6; + uint8 bank; + if(isresetbased) + bank = (latche[0]&0x1f)|(reset<<5)|((latche[1]&1)<<6); + else + bank = (latche[0]&0x1f)|((latche[0]&0x80)>>2)|((latche[1]&1)<<6); if(!(latche[0] & 0x20)) setprg32(0x8000,bank >> 1); else @@ -56,7 +59,7 @@ static DECLFW(M226Write) static void M226Power(void) { - latche[0] = latche[1] = 0; + latche[0] = latche[1] = reset = 0; Sync(); SetWriteHandler(0x8000,0xFFFF,M226Write); SetReadHandler(0x8000,0xFFFF,CartBR); @@ -69,8 +72,23 @@ static void StateRestore(int version) void Mapper226_Init(CartInfo *info) { + isresetbased = 0; info->Power=M226Power; AddExState(&StateRegs, ~0, 0, 0); GameStateRestore=StateRestore; } +static void BMC42in1Reset(void) +{ + reset ^= 1; + Sync(); +} + +void BMC42in1r_Init(CartInfo *info) +{ + isresetbased = 1; + info->Power=M226Power; + info->Reset=BMC42in1Reset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} diff --git a/boards/bmc64in1nr.c b/boards/bmc64in1nr.c index 4f90c9f..a8dd291 100644 --- a/boards/bmc64in1nr.c +++ b/boards/bmc64in1nr.c @@ -15,9 +15,9 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * BMC 42-in-1 reset switch + * BMC 42-in-1 "reset switch" type */ #include "mapinc.h" diff --git a/boards/bmc70in1.c b/boards/bmc70in1.c index 75baaa5..7970c08 100644 --- a/boards/bmc70in1.c +++ b/boards/bmc70in1.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -29,7 +29,7 @@ static uint8 mirroring; static SFORMAT StateRegs[]= { {&large_bank, 1, "LB"}, - {&hw_switch, 1, "DIPSW"}, + {&hw_switch, 1, "DPSW"}, {&prg_bank, 1, "PRG"}, {&chr_bank, 1, "CHR"}, {&bank_mode, 1, "BM"}, diff --git a/boards/bonza.c b/boards/bonza.c index a618f90..20fc10d 100644 --- a/boards/bonza.c +++ b/boards/bonza.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -33,6 +33,12 @@ static SFORMAT StateRegs[]= /* +cmd[0] = response on/off + 0x00 - on + 0x80 - off +cmd[1] = cmd + + _GET_CHALLENGE: .BYTE 0,$B4, 0, 0,$62 _SELECT_FILE_1_0200: .BYTE 0,$A4, 1, 0, 2, 2, 0 @@ -81,7 +87,7 @@ byte_8CC6: .BYTE 0,$78, 0, 0,$12 static uint8 sim0reset[0x1F] = { 0x3B, 0xE9, 0x00, 0xFF, 0xC1, 0x10, 0x31, 0xFE, 0x55, 0xC8, 0x10, 0x20, 0x55, 0x47, 0x4F, 0x53, 0x56, 0x53, 0x43, 0xAD, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 }; static void Sync(void) { diff --git a/boards/bs-5.c b/boards/bs-5.c index ad7a82a..85c74df 100644 --- a/boards/bs-5.c +++ b/boards/bs-5.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -26,8 +26,8 @@ static uint8 dip_switch; static SFORMAT StateRegs[]= { - {reg_prg, 4, "PREGS"}, - {reg_chr, 4, "CREGS"}, + {reg_prg, 4, "PREG"}, + {reg_chr, 4, "CREG"}, {0} }; diff --git a/boards/cityfighter.c b/boards/cityfighter.c new file mode 100644 index 0000000..11eb859 --- /dev/null +++ b/boards/cityfighter.c @@ -0,0 +1,134 @@ +/* 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 + * + * City Fighter IV sith Sound VRC4 hacked + */ + +#include "mapinc.h" + +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; +static uint8 prg_reg, prg_mode, mirr; +static uint8 chr_reg[8]; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 1, "IRQC"}, + {&IRQPre, 1, "IRQP"}, + {&IRQa, 1, "IRQA"}, + {&prg_reg, 1, "PREG"}, + {&prg_mode, 1, "PMOD"}, + {&mirr, 1, "MIRR"}, + {chr_reg, 8, "CREG"}, + {0} +}; + +static void Sync(void) +{ + setprg32(0x8000,prg_reg>>2); + if(!prg_mode) + setprg8(0xC000,prg_reg); + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr_reg[i]); + switch (mirr) + { + 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(UNLCITYFIGHTWrite) +{ + switch(A&0xF00C) + { + case 0x9000: prg_reg=V&0xC; mirr=V&3; break; + case 0x9004: + case 0x9008: + case 0x900C: prg_reg=V&0xC; break; + case 0xC000: + case 0xC004: + case 0xC008: + case 0xC00C: prg_mode=V&1; break; + case 0xD000: chr_reg[0]=(chr_reg[0]&0xF0)|(V&0x0F); break; + case 0xD004: chr_reg[0]=(chr_reg[0]&0x0F)|(V<<4); break; + case 0xD008: chr_reg[1]=(chr_reg[1]&0xF0)|(V&0x0F); break; + case 0xD00C: chr_reg[1]=(chr_reg[1]&0x0F)|(V<<4); break; + case 0xA000: chr_reg[2]=(chr_reg[2]&0xF0)|(V&0x0F); break; + case 0xA004: chr_reg[2]=(chr_reg[2]&0x0F)|(V<<4); break; + case 0xA008: chr_reg[3]=(chr_reg[3]&0xF0)|(V&0x0F); break; + case 0xA00C: chr_reg[3]=(chr_reg[3]&0x0F)|(V<<4); break; + case 0xB000: chr_reg[4]=(chr_reg[4]&0xF0)|(V&0x0F); break; + case 0xB004: chr_reg[4]=(chr_reg[4]&0x0F)|(V<<4); break; + case 0xB008: chr_reg[5]=(chr_reg[5]&0xF0)|(V&0x0F); break; + case 0xB00C: chr_reg[5]=(chr_reg[5]&0x0F)|(V<<4); break; + case 0xE000: chr_reg[6]=(chr_reg[6]&0xF0)|(V&0x0F); break; + case 0xE004: chr_reg[6]=(chr_reg[6]&0x0F)|(V<<4); break; + case 0xE008: chr_reg[7]=(chr_reg[7]&0xF0)|(V&0x0F); break; + case 0xE00C: chr_reg[7]=(chr_reg[7]&0x0F)|(V<<4); break; +// case 0xF004: IRQCount=((IRQCount&0xF0)|(V&0xF)); break; +// case 0xF000: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break; + case 0xF008: IRQa=V&2; X6502_IRQEnd(FCEU_IQEXT); break; +// case 0xF00C: IRQPre=16; break; + default: + FCEU_printf("bs %04x %02x\n",A,V); + } + Sync(); +} + +static DECLFW(UNLCITYFIGHTWriteLo) +{ + FCEU_printf("bs %04x %02x\n",A,V); +} + +static void UNLCITYFIGHTIRQ(void) +{ + //if(IRQa) + { +// IRQCount--; +// if((IRQCount>>1)==0) +// X6502_IRQBegin(FCEU_IQEXT); +// if(scanline==100) X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void UNLCITYFIGHTPower(void) +{ + prg_reg = 0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x4020,0x7FFF,UNLCITYFIGHTWriteLo); + SetWriteHandler(0x8000,0xFFFF,UNLCITYFIGHTWrite); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLCITYFIGHT_Init(CartInfo *info) +{ + info->Power=UNLCITYFIGHTPower; + GameHBIRQHook=UNLCITYFIGHTIRQ; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/copyfami_emu.c b/boards/copyfami_emu.c new file mode 100644 index 0000000..353d78b --- /dev/null +++ b/boards/copyfami_emu.c @@ -0,0 +1,380 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + */ + +#ifdef COPYFAMI + +#include "__serial.h" +#include "mapinc.h" +#include "mmc3.h" + +//#define DEBUG_SERIAL + +// *** COPY FAMICOM EMULATION *** + +/* +Êàðòà ïàìÿòè + + $0000-$1FFF Îñíîâíîå ÎÇÓ + $2000-$200F Ðåãèñòðû PPU + $2010-$3FFB Ñèñòåìíîå ÎÇÓ + $3FFC-$3FFF Ñèñòåìíûå ðåãèñòðû + $4000-$7FFF APU ðåãèñòðû/ñâîáîäíî + $8000-$FFF9 CART/ROM + $FFFA-$FFFB CART/Âåêòîð NMI + $FFFE-$FFFF CART/Âåêòîð IRQ + +Ðåãèñòðû + + CTRL R/W $3FFC ---aenic ($00 at reset) + + c - Ðåæèì êàðòðèäæà + 0 - âûêëþ÷åí + 1 - âêëþ÷åí + i - Ðåæèì IRQ âåêòîðà + 0 - îðèãèíàëüíûé âåêòîð + 1 - âåêòîð ïåðåõâà÷åí + n - Ðåæèì NMI âåêòîðà + 0 - îðèãèíàëüíûé âåêòîð + 1 - âåêòîð ïåðåõâà÷åí + e - Çàïðåò NMI + 0 - çàïðåùåí + 1 - ðàçðåøåí + a - Ðåæèì AROM + 0 - âûêëþ÷åí + 1 - âêëþ÷åí + + BANK R/W $3FFD ---mbbbb + + b - Íîìåð áàíêà âíóòðåííåîãî ÏÇÓ + m - Ìèððîðèíã â ðåæèìå ÀROM + + USBDATA R/W $3FFE dddddddd + + d - Áàéò äàííûõ ïðèåìà/ïåðåäà÷è + + STATUS R $3FFF vmnicptr + + r - Ñòàòóñ äàííûõ äëÿ ÷òåíèÿ èç USB + 0 - Åñòü äàííûå + 1 - Íåò äàííûõ + t - Ñòàòóñ áóôåðà äëÿ çàïèñè â USB + 0 - Åñòü ìåñòî + 1 - Íåò ìåñòà + p - Ñòàòóñ ïîäêëþ÷åíèÿ USB êàáåëÿ + 0 - Ïîäêëþ÷åí + 1 - Îòêëþ÷åí + c - Íàëè÷èå êàðòðèäæà â ñëîòå + 0 - Ïðèñóòñòâóåò + 1 - Îòñóòñòâóåò + i - Ñîñòîÿíèå ñèãíàëà IRQ êàðòðèäæà + 0 - Àêòèâåí + 1 - Íåàêòèâåí + n - Ñîñòîÿíèå ñèãíàëà NMI êàðòðèäæà + 0 - Àêòèâåí + 1 - Íåàêòèâåí + m - Ñîñòîÿíèå àäðåñíîé øèíû À10 VRAM (ìèððîðèíã) + v - Ñîñòîÿíèå VRAM + 0 - Âûáðàíà + 1 - Íå âûáðàíà + +Ðåæèì AROM + + Àêòèâèðóåòñÿ âíóòðåííÿÿ VRAM + Ðåãèñòðû áàíêîâ è ìèððîðèíãà íà 8000-FFFF +*/ + +#define CTRL 0x00 +#define CCART 0x01 +#define CVIRQ 0x02 +#define CVNMI 0x04 +#define CDNMI 0x08 +#define CAROM 0x10 +#define BANK 0x01 +#define BMIRR 0x10 +#define USB 0x02 +#define STATUS 0x03 +#define SRX 0x01 +#define STX 0x02 +#define SPEN 0x04 +#define SCART 0x08 +#define SIRQ 0x10 +#define SNMI 0x20 +#define SA10 0x40 +#define SVRAM 0x80 + +#ifdef DEBUG_SERIAL +static uint8 debug_serial_data[] = { + 0xDE, 0xAD, 0xBE, 0xEF, 0x00, + 0xDE, 0xAD, 0xBE, 0xEF, 0x01, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, + + 0x14, 0x50, 0xB0, + + 0x02, + + }; +static uint32 debug_serial_data_size = sizeof(debug_serial_data); +static uint32 debug_serial_data_pos; +#endif + +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; + +static uint8 regs[4]; + +static readfunc def_read_ram, def_read_rom; +static writefunc def_write_ram; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "CREGS"}, + {0} +}; + +static void Sync() +{ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void MCopyFamiMMC3PW(uint32 A, uint8 V) +{ + if(regs[CTRL] & CCART) + setprg8(A,V); + else + setprg32r(1,0x8000,(regs[BANK]&0x0F)^0x08); +} + +static void MCopyFamiMMC3CW(uint32 A, uint8 V) +{ + if((regs[STATUS] & SCART) && (regs[CTRL] & CAROM)) + setchr8r(0x10,0); + else + setchr1r(0,A,V); +} + +static void MCopyFamiMMC3MW(uint8 V) +{ + if(regs[CTRL] & CAROM) + { + setmirror(MI_0+((regs[BANK]>>4)&1)); + } + else + { + A000B=V; + setmirror((V&1)^1); + } +} + +static uint32 direction = 0xffffffff; +static uint32 bytes_count = 0; + +static DECLFW(MCopyFamiWriteReg) +{ + if(((A&3) == USB)&&!fceuindbg) { + if(direction != 0) { + direction = 0; + bytes_count = 0; + FCEU_printf(" >"); + } +#ifndef DEBUG_SERIAL + while (!SerialSendChar(V)) {}; +#endif + bytes_count++; +// FCEU_printf(" %02X",V); + } + else + { + regs[A&3]=V; + Sync(); + } +} + +static DECLFR(MCopyFamiReadReg) +{ +#ifdef DEBUG_SERIAL + if(debug_serial_data_pos == debug_serial_data_size) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; +#endif + if (!fceuindbg) + { +#ifndef DEBUG_SERIAL + if((A&3) == STATUS) + { + int data; + if((data = SerialGetChar()) == EOF) + regs[STATUS] |= SRX; + else + regs[STATUS] &= ~SRX; + regs[USB] = data & 0xff; + } else +#endif + if((A&3) == USB) + { +#ifdef DEBUG_SERIAL + regs[USB] = debug_serial_data[debug_serial_data_pos++]; +#endif + if(direction != 1) { + if(direction != 0xffffffff) FCEU_printf(" bytes sent: %08x",bytes_count); + direction = 1; + bytes_count = 0; + FCEU_printf("\n<"); + } + FCEU_printf(" %02X",regs[USB]); + } + } + return regs[A&3]; +} + +static DECLFW(MCopyFamiMMC3Write) +{ + if(regs[CTRL] & CAROM) + { + regs[BANK] = V & 0x1F; + Sync(); + } + else + { + if(A >= 0xC000) + MMC3_IRQWrite(A,V); + else + MMC3_CMDWrite(A,V); + } +} + +static DECLFW(MCopyFamiMMC3WriteNMI) +{ + if(regs[CTRL] & CVNMI) + def_write_ram(0x3FFC + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFW(MCopyFamiMMC3WriteIRQ) +{ + if(regs[CTRL] & CVIRQ) + def_write_ram(0x3FFE + (A & 1), V); + else + MCopyFamiMMC3Write(A, V); +} + +static DECLFR(MCopyFamiReadNMI) +{ + if(regs[CTRL] & CVNMI) + return def_read_ram(0x3FFC + (A & 1)); + else + return def_read_rom(A); +} + +static DECLFR(MCopyFamiReadIRQ) +{ + if(regs[CTRL] & CVIRQ) + return def_read_ram(0x3FFE + (A & 1)); + else + return def_read_rom(A); +} + +static void MCopyFamiMMC3Power(void) +{ + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + GenMMC3Power(); + Sync(); + + def_write_ram = GetWriteHandler(0x3FFC); + SetWriteHandler(0x3FFC,0x3FFF,MCopyFamiWriteReg); + def_read_ram = GetReadHandler(0x3FFC); + SetReadHandler(0x3FFC,0x3FFF,MCopyFamiReadReg); + + SetWriteHandler(0x8000,0xFFF9,MCopyFamiMMC3Write); + SetWriteHandler(0xFFFA,0xFFFB,MCopyFamiMMC3WriteNMI); + SetWriteHandler(0xFFFE,0xFFFF,MCopyFamiMMC3WriteIRQ); + + def_read_rom = GetReadHandler(0xFFFA); + SetReadHandler(0xFFFA,0xFFFB,MCopyFamiReadNMI); + SetReadHandler(0xFFFE,0xFFFF,MCopyFamiReadIRQ); +} + +static void MCopyFamiMMC3Reset(void) +{ + regs[CTRL] = regs[USB] = 0; + regs[STATUS] = SIRQ | SNMI | SVRAM; + regs[BANK] = 0x08; +#ifdef DEBUG_SERIAL + debug_serial_data_pos = 0; +#endif + MMC3RegReset(); + Sync(); +} + +static void MCopyFamiClose(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; + SerialClose(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperCopyFamiMMC3_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 8, 0); + + cwrap=MCopyFamiMMC3CW; + pwrap=MCopyFamiMMC3PW; + mwrap=MCopyFamiMMC3MW; + + info->Reset=MCopyFamiMMC3Reset; + info->Power=MCopyFamiMMC3Power; + info->Close=MCopyFamiClose; + GameStateRestore=StateRestore; + + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartCHRMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "CRAM"); + +#ifndef DEBUG_SERIAL + FCEU_printf("WAITING FOR PORT...\n"); + + while(!SerialOpen(20, 921600)) {} + + FCEU_printf("PORT READY.\n"); +#endif + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/boards/copyfami_hwi.c b/boards/copyfami_hwi.c new file mode 100644 index 0000000..fb9dad4 --- /dev/null +++ b/boards/copyfami_hwi.c @@ -0,0 +1,601 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + */ + +// *** COPY FAMICOM HARDWARE INTERFACE *** + +#ifdef COPYFAMI + +#define MESSAGE_LOG +#define NO_CACHE +#define NO_RAM + +#include "__serial.h" +#include "mapinc.h" + +#define FNV_32_PRIME ((uint32)0x01000193) + +#define CHR_CACHE_SIZE (1024 * 4) +#define WRAM_CACHE_SIZE (1024 / 2) +#define PRG_CACHE_SIZE (1024 / 4) +#define CMD_CACHE_SIZE (1024 * 128) + +#define CMD_MAX_SIZE (5) +#define CMD_MAX_RETEST (16) +#define CMD_MAX_VERIFY (16) + +static uint8 *WRAM = NULL; + +uint8 InitVector[] = {0xDE, 0xAD, 0xBE, 0xEF}; // args none, return DE AD BE EF +uint8 ResetCmd[] = {0x00}; // args none, return none +uint8 StateCmd[] = {0x01}; // args none, return 7 bytes status +uint8 StatusCmd[] = {0x02}; // args none, return 32 bytes status +uint8 LoadPlugCmd[] = {0x03, 0x00, 0x00}; // args 2b size, Nb data return none +uint8 RunPlugCmd[] = {0x04}; // args none, return none +uint8 RunGameCmd[] = {0x05}; // args none, return none +uint8 NROMSave[] = {0x06}; // args none, return 16b + 32kb + 8kb + +uint8 PRGWBCmd[] = {0x08, 0x00, 0x00, 0x00}; // args 2b addr, 1b data return none +uint8 PRGRBCmd[] = {0x09, 0x00, 0x00}; // args 2b addr return 1b data +uint8 CHRWBCmd[] = {0x0A, 0x00, 0x00, 0x00}; // args 2b addr, 1b data return none +uint8 CHRRBCmd[] = {0x0B, 0x00, 0x00}; // args 2b addr, return 1b data + +uint8 PRGSUMCmd[] = {0x10, 0x00, 0x00}; // args 1b addr, 1b size return (256 * N)b +uint8 PRG32KSUMCmd[] = {0x10, 0x80, 0x80}; // args 1b addr, 1b size return 32kb +uint8 PRG16KSUMCmd[] = {0x10, 0x00, 0x40}; // args 1b addr, 1b size return 16kb +uint8 PRG8KSUMCmd[] = {0x10, 0x00, 0x20}; // args 1b addr, 1b size return 8kb +uint8 PRG4KSUMCmd[] = {0x10, 0x00, 0x10}; // args 1b addr, 1b size return 4kb + +uint8 CHRSUMCmd[] = {0x11, 0x00, 0x00}; // args 1b addr, 1b size return (256 * N)b +uint8 CHR8KSUMCmd[] = {0x11, 0x00, 0x20}; // args 1b addr, 1b size return 8kb +uint8 CHR4KSUMCmd[] = {0x11, 0x00, 0x10}; // args 1b addr, 1b size return 4kb +uint8 CHR2KSUMCmd[] = {0x11, 0x00, 0x08}; // args 1b addr, 1b size return 2kb +uint8 CHR1KSUMCmd[] = {0x11, 0x00, 0x04}; // args 1b addr, 1b size return 1kb + +uint8 PRGGetCmd[] = {0x12, 0x00, 0x00}; // args 1b addr, 1b size return (256 * N)b +uint8 PRG32KGetCmd[] = {0x12, 0x80, 0x80}; // args 1b addr, 1b size return 32kb +uint8 PRG16KGetCmd[] = {0x12, 0x00, 0x40}; // args 1b addr, 1b size return 16kb +uint8 PRG8KGetCmd[] = {0x12, 0x00, 0x20}; // args 1b addr, 1b size return 8kb +uint8 PRG4KGetCmd[] = {0x12, 0x00, 0x10}; // args 1b addr, 1b size return 4kb + +uint8 CHRGetCmd[] = {0x13, 0x00, 0x00}; // args 1b addr, 1b size return (256 * N)b +uint8 CHR8KGetCmd[] = {0x13, 0x00, 0x20}; // args 1b addr, 1b size return 8kb +uint8 CHR4KGetCmd[] = {0x13, 0x00, 0x10}; // args 1b addr, 1b size return 4kb +uint8 CHR2KGetCmd[] = {0x13, 0x00, 0x08}; // args 1b addr, 1b size return 2kb +uint8 CHR1KGetCmd[] = {0x13, 0x00, 0x04}; // args 1b addr, 1b size return 1kb + +uint8 CPUTestCmd[] = {0x14, 0x00, 0x00}; // args 1b addr, 1b size return (2b + 1b) * N + 3b + +typedef struct { + int32 mirror; + int32 chrsum[8]; + int32 prgsum[4]; +} SYNC_STATE; + +static SYNC_STATE state_cur, state_new, state_def; + +typedef struct { + uint8 *buf; + int32 count; +} DATA_BANKS; + +static DATA_BANKS chr_data; +static int32 chr_bank[0x10000]; +static DATA_BANKS prg_data; +static int32 prg_bank[0x10000]; + +typedef struct { + SYNC_STATE states[CMD_CACHE_SIZE]; + int32 seqs[CMD_CACHE_SIZE][CMD_MAX_SIZE]; + int32 count; +} SYNC_CMDS; + +typedef struct { + int32 seq[CMD_MAX_SIZE]; + int32 size; + int32 found; + uint32 hash; + uint16 hashf; +} SYNC_CMD; + +static SYNC_CMD cmd; +static SYNC_CMDS cmds; + +typedef struct { + int32 index; + int32 size; + int32 retest; + int32 verify; +} CMD_CACHE; + +static CMD_CACHE cmd_cache[0x10000]; + +static SFORMAT StateRegs[]= +{ + {state_cur.chrsum, sizeof(state_cur.chrsum), "CHRREG"}, + {state_cur.prgsum, sizeof(state_cur.prgsum), "ROMREG"}, + {&state_cur.mirror, sizeof(state_cur.mirror), "MIRREG"}, + {0} +}; + +#define MI_U 4 + +static char *mirror_names[5] = {"Horizontal", "Vertical", "Mirror 0", "Mirror 1", "Unknown mirror"}; +static int32 mirror_modes[16] = { + MI_0, MI_U, MI_U, MI_H, MI_U, MI_V, MI_U, MI_U, + MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_U, MI_1 }; + +#define CHRDEF(slot) (chr_bank[state_def.chrsum[slot]]) +#define PRGDEF(slot) (prg_bank[state_def.prgsum[slot]]) +#define CHRCUR(slot) (chr_bank[state_cur.chrsum[slot]]) +#define PRGCUR(slot) (prg_bank[state_cur.prgsum[slot]]) +#define CHRNEW(slot) (chr_bank[state_new.chrsum[slot]]) +#define PRGNEW(slot) (prg_bank[state_new.prgsum[slot]]) + +static void GetStatus(SYNC_STATE *state) +{ + uint8 resp0; + uint16 resp1, i; + SEND(StatusCmd); + GET(resp0, 1); + state->mirror = resp0; + GET(resp0, 1); + for(i=0; i<8; i++) { + GET(resp1, 2); + state->chrsum[i] = resp1; + } + for(i=0; i<4; i++) { + GET(resp1, 2); + state->prgsum[i] = resp1; + } +} + +static int32 FetchNewCHRBank(int32 slot) +{ + FILE *ofile; + char name[256]; + int32 bank = chr_data.count++; + CHR1KGetCmd[1] = slot << 2; + SENDGET(CHR1KGetCmd, chr_data.buf[bank * 1024], 1024); + sprintf(name,"%04x.chr",bank); + ofile=fopen(name,"wb"); + fwrite((void *)&chr_data.buf[bank * 1024], 1, 1024, ofile); + fclose(ofile); + return bank; +} + +static int32 FetchNewPRGBank(int32 slot) +{ + FILE *ofile; + char name[256]; + int32 bank = prg_data.count++; + PRG8KGetCmd[1] = 0x80 + (slot << 5); + SENDGET(PRG8KGetCmd, prg_data.buf[bank * 8192], 8192); + sprintf(name,"%04x.prg",bank); + ofile=fopen(name,"wb"); + fwrite((void *)&prg_data.buf[bank * 8192], 1, 8192, ofile); + fclose(ofile); + return bank; +} + +static int CheckStatus(void) +{ + int32 i, ischanged = 0; + GetStatus(&state_new); + if(state_cur.mirror != state_new.mirror) { + state_cur.mirror = state_new.mirror; +#ifdef MESSAGE_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + ischanged = 1; + } else { + state_new.mirror = -1; + } + for(i=0; i<8; i++) { + if(state_cur.chrsum[i] != state_new.chrsum[i]) { + state_cur.chrsum[i] = state_new.chrsum[i]; + if(CHRCUR(i) == -1) { + CHRCUR(i) = FetchNewCHRBank(i); +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d loaded\n", i, CHRCUR(i)); +#endif + } +#ifdef MESSAGE_LOG + else + FCEU_printf(">> chr[%d] bank %d switched\n", i, CHRCUR(i)); +#endif + ischanged = 1; + } else { + state_new.chrsum[i] = -1; + } + } + for(i=0; i<4; i++) { + if(state_cur.prgsum[i] != state_new.prgsum[i]) { + state_cur.prgsum[i] = state_new.prgsum[i]; + if(PRGCUR(i) == -1) { + PRGCUR(i) = FetchNewPRGBank(i); +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d loaded\n", i, PRGCUR(i)); +#endif + } +#ifdef MESSAGE_LOG + else + FCEU_printf(">> prg[%d] bank %d switched\n", i, PRGCUR(i)); +#endif + ischanged = 1; + } else { + state_new.prgsum[i] = -1; + } + } + return ischanged; +} + +#ifndef NO_CACHE +static void ApplyStatus() +{ + int32 i; + if ((cmds.states[cmd.found].mirror != -1) && (cmds.states[cmd.found].mirror != state_cur.mirror)) { + state_cur.mirror = cmds.states[cmd.found].mirror; + setmirror(mirror_modes[state_cur.mirror]); +#ifdef MESSAGE_LOG + FCEU_printf(">> mirror changed to %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); +#endif + } + for(i=0; i<8; i++) { + int32 sum = cmds.states[cmd.found].chrsum[i]; + if (sum != -1) { + if (sum != state_cur.chrsum[i]) { + state_cur.chrsum[i] = sum; + setchr1r(1, i * 1024, CHRCUR(i)); +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d switched\n", i, chr_bank[sum]); +#endif + } + else +#ifdef MESSAGE_LOG + FCEU_printf(">> chr[%d] bank %d switched the same\n", i, chr_bank[sum]); + } +#endif + } + for(i=0; i<4; i++) { + int32 sum = cmds.states[cmd.found].prgsum[i]; + if (sum != -1) { + if (sum != state_cur.prgsum[i]) { + state_cur.prgsum[i] = sum; + setprg8r(2, 0x8000 + (i * 8192), PRGCUR(i)); +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d switched\n", i, prg_bank[sum]); +#endif + } + else +#ifdef MESSAGE_LOG + FCEU_printf(">> prg[%d] bank %d switched the same\n", i, prg_bank[sum]); + } +#endif + } +} + +static void LogCmd() +{ + int32 i; + FCEU_printf(">> new cmd size %d [", cmd_cache[cmd.hashf].size); + for(i=0; i> 16) ^ (cmd.hash & 0xffff); + cmd.found = cmd_cache[cmd.hashf].index; + } +#endif + +static DECLFW(MCopyFamiWrite) +{ +#ifndef NO_CACHE + int32 i; +#endif + +#ifdef MESSAGE_LOG + FCEU_printf("> WRITE %04X:%02X\n",A,V); +#endif + + PRGWBCmd[1] = A & 0xFF; + PRGWBCmd[2] = A >> 8; + PRGWBCmd[3] = V & 0xFF; + SEND(PRGWBCmd); +#ifdef NO_CACHE + CheckStatus(); + Sync(); +#else + UpdateCmd((A << 8) | V); + // èùåì êîìàíäó â êåøå + if(cmd.found == -1) { + // íå íàéäåíà, ïðîâåðÿåì, èçìåíèëîñü ëè ñîñòîÿíèå áàíêîâ + // ëèáî íå ïðåäåëüíîé ëè îíà äëèíû äëÿ êîìàíäû + cmd_cache[cmd.hashf].index = cmd.found = cmds.count++; + cmd_cache[cmd.hashf].retest = 0; + cmd_cache[cmd.hashf].verify = 0; + for(i=0; i> 8; + SENDGET(PRGRBCmd, result, 1); +#ifdef MESSAGE_LOG + FCEU_printf("> READ %04X:%02X\n",A,result); +#endif + return result; +} + +static void MCopyFamiReset(void) +{ + state_cur = state_def; + Sync(); +} + +static void MCopyFamiPower(void) +{ +// uint32 resp, presp; + + FCEU_printf("NOW POWERING... "); + + Sync(); + + SetWriteHandler(0x4018, 0x7fff, MCopyFamiWrite); + SetReadHandler(0x4018, 0x7fff, MCopyFamiRead); +#ifndef NO_RAM + SetWriteHandler(0x6000, 0x7fff, CartBW); + SetReadHandler(0x6000, 0x7fff, CartBR); +#endif + +/* + FCEU_printf("READING MEMORY MAP...\n"); + CPUTestCmd[1] = 0x50; + CPUTestCmd[2] = 0x30; + SEND(CPUTestCmd); + resp = 0; + presp = 0xffffffff; + while (presp != 0x00ff0000) { + GET(resp, 3); + if(presp != 0xffffffff) { + switch(presp & 0x00FF0000) { + case 0x00000000: // BUS + FCEU_printf(" %04X-%04X OPEN BUS\n",presp & 0x7fff, (resp - 1) & 0x7fff); + break; + case 0x00010000: // RAM + FCEU_printf(" %04X-%04X RAM\n",presp & 0x7fff, (resp - 1) & 0x7fff); + SetWriteHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBW); + SetReadHandler(presp & 0x7fff, (resp - 1) & 0x7fff, CartBR); + break; + } + } + presp = resp; + } +*/ + SetWriteHandler(0x8000, 0xffff, MCopyFamiWrite); + SetReadHandler(0x8000, 0xffff, CartBR); + + FCEU_printf("DONE!\nNOW COLLECTING DATA...\n"); +} + +static void MCopyFamiClose(void) +{ + if(chr_data.buf) + FCEU_gfree(chr_data.buf); + chr_data.buf=NULL; + if(prg_data.buf) + FCEU_gfree(prg_data.buf); + prg_data.buf=NULL; + if(WRAM) + FCEU_gfree(WRAM); + WRAM = NULL; + + SerialClose(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperCopyFami_Init(CartInfo *info) +{ + uint32 resp = 0, i, size; + + memset(chr_bank, -1, sizeof(chr_bank)); + memset(prg_bank, -1, sizeof(chr_bank)); + memset(cmd_cache, -1, sizeof(cmd_cache)); + memset(&cmds, 0, sizeof(cmds)); + memset(&cmd, 0, sizeof(cmd)); + + info->Reset=MCopyFamiReset; + info->Power=MCopyFamiPower; + info->Close=MCopyFamiClose; + GameStateRestore=StateRestore; + + size = 1024 * CHR_CACHE_SIZE; // ðàçìåð ñòðàíèöû 1êá + chr_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartCHRMapping(1, chr_data.buf, size, 1); // ïðîâåðÿòü ïïó ðàì, èíà÷å èãðà ìîæåò ïîðòèòü äàííûå + AddExState(chr_data.buf, size, 0, "CCHR"); + + size = 8192; // ðàçìåð ñòðàíèöû 8êá + WRAM = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(1, WRAM, size, 1); + AddExState(WRAM, size, 0, "CPRM"); + + size = 8192 * PRG_CACHE_SIZE; // ðàçìåð ñòðàíèöû 8êá + prg_data.buf = (uint8*)FCEU_gmalloc(size); + SetupCartPRGMapping(2, prg_data.buf, size, 0); + AddExState(prg_data.buf, size, 0, "CPPR"); + + + FCEU_printf("WAITING FOR SERIAL PORT... "); + while(!SerialOpen(19, 921600)) { Sleep(500); } + FCEU_printf("READY!\n"); + + FCEU_printf("WAITING FOR DEVICE... "); + + while(resp != *(uint32 *)&InitVector[0]) { + SEND(ResetCmd); + SENDGET(InitVector, resp, 4); + Sleep(500); + } + + FCEU_printf("READY!\n"); + FCEU_printf("READING STATUS...\n"); + GetStatus(&state_cur); + FCEU_printf("MIRRORING IS %s (%02X)\n",mirror_names[mirror_modes[state_cur.mirror]], state_cur.mirror); + FCEU_printf("READING CHR...\n INITIAL STATE:"); + + for(i=0; i<8; i++) { + if(CHRCUR(i) == -1) + CHRCUR(i) = FetchNewCHRBank(i); + FCEU_printf(" CHR%d=%02X", i, CHRCUR(i)); + } + FCEU_printf("\n"); + + FCEU_printf("READING PRG...\n INITIAL STATE:"); + for(i=0; i<4; i++) { + if(PRGCUR(i) == -1) + PRGCUR(i) = FetchNewPRGBank(i); + FCEU_printf(" PRG%d=%02X", i, PRGCUR(i)); + } + FCEU_printf("\nDONE!\n"); + + state_def = state_cur; + + AddExState(&StateRegs, ~0, 0, 0); +} + +#endif diff --git a/boards/dance2000.c b/boards/dance2000.c new file mode 100644 index 0000000..8089270 --- /dev/null +++ b/boards/dance2000.c @@ -0,0 +1,111 @@ +/* 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 + * + * Dance 2000 12-in-1 + * + */ + +#include "mapinc.h" + +static uint8 prg, mirr, prgmode; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {&prg, 1, "REGS"}, + {&mirr, 1, "MIRR"}, + {&prgmode, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + setmirror(mirr); + setprg8r(0x10,0x6000,0); + setchr8(0); + if(prgmode) + setprg32(0x8000,prg&7); + else { + setprg16(0x8000,prg&0x0f); + setprg16(0xC000,0); + } +} + +static DECLFW(UNLD2000Write) +{ +// FCEU_printf("write %04x:%04x\n",A,V); + switch(A) { + case 0x5000: prg = V; Sync(); break; + case 0x5200: mirr = (V & 1)^1; prgmode = V & 4; Sync(); break; +// default: FCEU_printf("write %04x:%04x\n",A,V); + } +} + +static DECLFR(UNLD2000Read) +{ + if(prg & 0x40) + return X.DB; + else + return CartBR(A); +} + +static void UNLD2000Power(void) +{ + prg = prgmode = 0; + Sync(); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,UNLD2000Read); + SetWriteHandler(0x4020,0x5FFF,UNLD2000Write); +} + +static void UNLAX5705IRQ(void) +{ + if(scanline > 174) setchr4(0x0000,1); + else setchr4(0x0000,0); +} + +static void UNLD2000Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLD2000_Init(CartInfo *info) +{ + info->Power=UNLD2000Power; + info->Close=UNLD2000Close; + GameHBIRQHook=UNLAX5705IRQ; + 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/boards/datalatch.c b/boards/datalatch.c index 4a61f04..cf486ae 100644 --- a/boards/datalatch.c +++ b/boards/datalatch.c @@ -1,446 +1,503 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" -#include "../ines.h" - -static uint8 latche, latcheinit, bus_conflict; -static uint16 addrreg0, addrreg1; -static uint8 *WRAM=NULL; -static uint32 WRAMSIZE; -static void(*WSync)(void); - -static DECLFW(LatchWrite) -{ -// FCEU_printf("bs %04x %02x\n",A,V); - if(bus_conflict) - latche=V&CartBR(A); - else - latche=V; - WSync(); -} - -static void LatchPower(void) -{ - latche=latcheinit; - WSync(); - if(WRAM) - { - SetReadHandler(0x6000,0xFFFF,CartBR); - SetWriteHandler(0x6000,0x7FFF,CartBW); - } - else - { - SetReadHandler(0x8000,0xFFFF,CartBR); - } - SetWriteHandler(addrreg0,addrreg1,LatchWrite); -} - -static void LatchClose(void) -{ - if(WRAM) - FCEU_gfree(WRAM); - WRAM=NULL; -} - -static void StateRestore(int version) -{ - WSync(); -} - -static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) -{ - bus_conflict = busc; - latcheinit=init; - addrreg0=adr0; - addrreg1=adr1; - WSync=proc; - info->Power=LatchPower; - info->Close=LatchClose; - GameStateRestore=StateRestore; - if(wram) - { - 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(&latche, 1, 0, "LATC"); -} - -//------------------ CPROM --------------------------- - -static void CPROMSync(void) -{ - setchr4(0x0000,0); - setchr4(0x1000,latche&3); - setprg16(0x8000,0); - setprg16(0xC000,1); -} - -void CPROM_Init(CartInfo *info) -{ - Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 184 --------------------------- - -static void M184Sync(void) -{ - setchr4(0x0000,latche); - setchr4(0x1000,latche>>4); - setprg16(0x8000,0); - setprg16(0xC000,1); -} - -void Mapper184_Init(CartInfo *info) -{ - Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); -} - -//------------------ CNROM --------------------------- - -static void CNROMSync(void) -{ - //mbg 8/10/08 - fixed this so that large homebrew roms would work. - //setchr8(latche&3); - setchr8(latche); - setprg16(0x8000,0); - setprg16(0xC000,1); - setprg8r(0x10,0x6000,0); // Hayauchy IGO uses 2Kb or RAM -} - -void CNROM_Init(CartInfo *info) -{ - bool busc = MasterRomInfoParams.ContainsKey("busc"); - Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, busc?1:0); -} - -//------------------ ANROM --------------------------- - -static void ANROMSync() -{ - setprg32(0x8000,latche&0xf); - setmirror(MI_0+((latche>>4)&1)); - setchr8(0); -} - -void ANROM_Init(CartInfo *info) -{ - Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 70 --------------------------- - -static void M70Sync() -{ - setprg16(0x8000,latche>>4); - setprg16(0xc000,~0); - setchr8(latche&0xf); -} - -void Mapper70_Init(CartInfo *info) -{ - Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 152 --------------------------- - -static void M152Sync() -{ - setprg16(0x8000,(latche>>4)&7); - setprg16(0xc000,~0); - setchr8(latche&0xf); - setmirror(MI_0+((latche>>7)&1)); /* Saint Seiya...hmm. */ -} - -void Mapper152_Init(CartInfo *info) -{ - Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 78 --------------------------- -/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ -static void M78Sync() -{ - setprg16(0x8000,(latche&7)); - setprg16(0xc000,~0); - setchr8(latche>>4); - setmirror(MI_0+((latche>>3)&1)); -} - -void Mapper78_Init(CartInfo *info) -{ - Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ MHROM --------------------------- - -static void MHROMSync(void) -{ - setprg32(0x8000,latche>>4); - setchr8(latche&0xf); -} - -void MHROM_Init(CartInfo *info) -{ - Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -void Mapper140_Init(CartInfo *info) -{ - Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); -} - -void Mapper240_Init(CartInfo *info) -{ - Latch_Init(info, MHROMSync, 0, 0x4020, 0x5FFF, 0, 0); - // need SRAM. -} - -//------------------ Map 87 --------------------------- - -static void M87Sync(void) -{ - setprg16(0x8000,0); - setprg16(0xC000,1); - setchr8(((latche>>1)&1)|((latche<<1)&2)); -// setchr8(latche); -} - -void Mapper87_Init(CartInfo *info) -{ - Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); -} - -//------------------ 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, 0, 0); -} - -//------------------ Map 11 --------------------------- - -static void M11Sync(void) -{ - setprg32(0x8000,latche&0xf); - setchr8(latche>>4); -} - -void Mapper11_Init(CartInfo *info) -{ - Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -void Mapper144_Init(CartInfo *info) -{ - Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); -} - -//------------------ 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, 0, 0); -} - -//------------------ 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, 0, 0); -} -//------------------ UNROM --------------------------- - -static void UNROMSync(void) -{ - setprg16(0x8000,latche); - setprg16(0xc000,~0); - setchr8(0); -} - -void UNROM_Init(CartInfo *info) -{ - Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1); -} - -//------------------ Map 93 --------------------------- - -static void SSUNROMSync(void) -{ - setprg16(0x8000,latche>>4); - setprg16(0xc000,~0); - setchr8(0); -} - -void SUNSOFT_UNROM_Init(CartInfo *info) -{ - Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 94 --------------------------- - -static void M94Sync(void) -{ - setprg16(0x8000,latche>>2); - setprg16(0xc000,~0); - setchr8(0); -} - -void Mapper94_Init(CartInfo *info) -{ - Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 180 --------------------------- - -static void M180Sync(void) -{ - setprg16(0x8000,0); - setprg16(0xc000,latche); - setchr8(0); -} - -void Mapper180_Init(CartInfo *info) -{ - Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 107 --------------------------- - -static void M107Sync(void) -{ - setprg32(0x8000,(latche>>1)&3); - setchr8(latche&7); -} - -void Mapper107_Init(CartInfo *info) -{ - Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ Map 113 --------------------------- - -static void M113Sync(void) -{ - setprg32(0x8000,(latche>>3)&7); - setchr8(((latche>>3)&8)|(latche&7)); -// setmirror(latche>>7); // only for HES 6in1 -} - -void Mapper113_Init(CartInfo *info) -{ - Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); -} - -//------------------ A65AS --------------------------- - -// actually, there is two cart in one... First have extra mirroring -// mode (one screen) and 32K bankswitching, second one have only -// 16 bankswitching mode and normal mirroring... But there is no any -// correlations between modes and they can be used in one mapper code. - -static void BMCA65ASSync(void) -{ - if(latche&0x40) - setprg32(0x8000,(latche>>1)&0x0F); - else - { - setprg16(0x8000,((latche&0x30)>>1)|(latche&7)); - setprg16(0xC000,((latche&0x30)>>1)|7); - } - setchr8(0); - if(latche&0x80) - setmirror(MI_0+(((latche>>5)&1))); - else - setmirror(((latche>>3)&1)^1); -} - -void BMCA65AS_Init(CartInfo *info) -{ - Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); -} - -//------------------ NROM --------------------------- - -#ifdef DEBUG_MAPPER -static DECLFW(WriteHandler) -{ - FCEU_printf("bs %04x %02x\n",A,V); - CartBW(A,V); -} -#endif - -static void NROMPower(void) -{ - setprg8r(0x10,0x6000,0); // Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB - setprg16(0x8000,0); - setprg16(0xC000,~0); - setchr8(0); - - SetReadHandler(0x6000,0x7FFF,CartBR); - SetWriteHandler(0x6000,0x7FFF,CartBW); - SetReadHandler(0x8000,0xFFFF,CartBR); - - #ifdef DEBUG_MAPPER - SetWriteHandler(0x4020,0xFFFF,WriteHandler); - #endif -} - -void NROM_Init(CartInfo *info) -{ - info->Power=NROMPower; - info->Close=LatchClose; - - 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"); -} +/* 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 + */ + +#include "mapinc.h" + +static uint8 latche, latcheinit, bus_conflict; +static uint16 addrreg0, addrreg1; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static void(*WSync)(void); + +static DECLFW(LatchWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + if(bus_conflict) + latche=V&CartBR(A); + else + latche=V; + WSync(); +} + +static void LatchPower(void) +{ + latche=latcheinit; + WSync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(addrreg0,addrreg1,LatchWrite); +} + +static void LatchClose(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + WSync(); +} + +static void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1, uint8 wram, uint8 busc) +{ + bus_conflict = busc; + latcheinit=init; + addrreg0=adr0; + addrreg1=adr1; + WSync=proc; + info->Power=LatchPower; + info->Close=LatchClose; + GameStateRestore=StateRestore; + if(wram) + { + 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(&latche, 1, 0, "LATC"); +} + +//------------------ Map 0 --------------------------- + +#ifdef DEBUG_MAPPER +static DECLFW(NROMWrite) +{ + FCEU_printf("bs %04x %02x\n",A,V); + CartBW(A,V); +} +#endif + +static void NROMPower(void) +{ + setprg8r(0x10,0x6000,0); // Famili BASIC (v3.0) need it (uses only 4KB), FP-BASIC uses 8KB + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); + + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + + #ifdef DEBUG_MAPPER + SetWriteHandler(0x4020,0xFFFF,NROMWrite); + #endif +} + +void NROM_Init(CartInfo *info) +{ + info->Power=NROMPower; + info->Close=LatchClose; + + 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"); +} + +//------------------ Map 2 --------------------------- + +static void UNROMSync(void) +{ + static uint32 mirror_in_use = 0; + setprg16(0x8000,latche&7); + if(latche&8) mirror_in_use = 1; + if(mirror_in_use) + setmirror(((latche >> 3)&1)^1); // Higway Star Hacked mapper + setprg16(0xc000,~0); + setchr8(0); +} + +void UNROM_Init(CartInfo *info) +{ + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF, 0, 1); +} + +//------------------ Map 3 --------------------------- + +static void CNROMSync(void) +{ + setchr8(latche); + setprg32(0x8000,0); + setprg8r(0x10,0x6000,0); // Hayauchy IGO uses 2Kb or RAM +} + +void CNROM_Init(CartInfo *info) +{ + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF, 1, 0); +} + +//------------------ Map 7 --------------------------- + +static void ANROMSync() +{ + setprg32(0x8000,latche&0xf); + setmirror(MI_0+((latche>>4)&1)); + setchr8(0); +} + +void ANROM_Init(CartInfo *info) +{ + Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 8 --------------------------- + +static void M8Sync() +{ + setprg16(0x8000,latche>>3); + setprg16(0xc000,1); + setchr8(latche&3); +} + +void Mapper8_Init(CartInfo *info) +{ + Latch_Init(info, M8Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 11 --------------------------- + +static void M11Sync(void) +{ + setprg32(0x8000,latche&0xf); + setchr8(latche>>4); +} + +void Mapper11_Init(CartInfo *info) +{ + Latch_Init(info, M11Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +void Mapper144_Init(CartInfo *info) +{ + Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF, 0, 0); +} + +//------------------ Map 13 --------------------------- + +static void CPROMSync(void) +{ + setchr4(0x0000,0); + setchr4(0x1000,latche&3); + setprg32(0x8000,0); +} + +void CPROM_Init(CartInfo *info) +{ + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ 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, 0, 0); +} + +//------------------ 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, 0, 0); +} + +//------------------ Map 66 --------------------------- + +static void MHROMSync(void) +{ + setprg32(0x8000,latche>>4); + setchr8(latche&0xf); +} + +void MHROM_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 70 --------------------------- + +static void M70Sync() +{ + setprg16(0x8000,latche>>4); + setprg16(0xc000,~0); + setchr8(latche&0xf); +} + +void Mapper70_Init(CartInfo *info) +{ + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 78 --------------------------- +/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ +static void M78Sync() +{ + setprg16(0x8000,(latche&7)); + setprg16(0xc000,~0); + setchr8(latche>>4); + setmirror(MI_0+((latche>>3)&1)); +} + +void Mapper78_Init(CartInfo *info) +{ + Latch_Init(info, M78Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 86 --------------------------- + +static void M86Sync(void) +{ + setprg32(0x8000,(latche >> 4) & 3); + setchr8((latche & 3) | ((latche >> 4) & 4)); +} + +void Mapper86_Init(CartInfo *info) +{ + Latch_Init(info, M86Sync, ~0, 0x6000, 0x6FFF, 0, 0); +} + +//------------------ Map 87 --------------------------- + +static void M87Sync(void) +{ + setprg32(0x8000,0); + setchr8(((latche>>1)&1)|((latche<<1)&2)); +} + +void Mapper87_Init(CartInfo *info) +{ + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF, 0, 0); +} + +//------------------ Map 89 --------------------------- + +static void M89Sync(void) +{ + setprg16(0x8000,(latche >> 4) & 7); + setprg16(0xc000, ~0); + setchr8((latche & 7) | ((latche >> 4) & 8)); + setmirror(MI_0 + ((latche >> 3) & 1)); +} + +void Mapper89_Init(CartInfo *info) +{ + Latch_Init(info, M89Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 93 --------------------------- + +static void SSUNROMSync(void) +{ + setprg16(0x8000,latche>>4); + setprg16(0xc000,~0); + setchr8(0); +} + +void SUNSOFT_UNROM_Init(CartInfo *info) +{ + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 94 --------------------------- + +static void M94Sync(void) +{ + setprg16(0x8000,latche>>2); + setprg16(0xc000,~0); + setchr8(0); +} + +void Mapper94_Init(CartInfo *info) +{ + Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 97 --------------------------- + +static void M97Sync(void) +{ + setchr8(0); + setprg16(0x8000,~0); + setprg16(0xc000,latche & 15); + switch(latche >> 6) + { + case 0: break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_V); break; + case 3: break; + } + setchr8(((latche>>1)&1)|((latche<<1)&2)); +} + +void Mapper97_Init(CartInfo *info) +{ + Latch_Init(info, M97Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 101 --------------------------- + +static void M101Sync(void) +{ + setprg32(0x8000,0); + setchr8(latche); +} + +void Mapper101_Init(CartInfo *info) +{ + Latch_Init(info, M101Sync, ~0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 107 --------------------------- + +static void M107Sync(void) +{ + setprg32(0x8000,(latche>>1)&3); + setchr8(latche&7); +} + +void Mapper107_Init(CartInfo *info) +{ + Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 113 --------------------------- + +static void M113Sync(void) +{ + setprg32(0x8000,(latche>>3)&7); + setchr8(((latche>>3)&8)|(latche&7)); +// setmirror(latche>>7); // only for HES 6in1 +} + +void Mapper113_Init(CartInfo *info) +{ + Latch_Init(info, M113Sync, 0, 0x4100, 0x7FFF, 0, 0); +} + +//------------------ Map 140 --------------------------- + +void Mapper140_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 152 --------------------------- + +static void M152Sync() +{ + setprg16(0x8000,(latche>>4)&7); + setprg16(0xc000,~0); + setchr8(latche&0xf); + setmirror(MI_0+((latche>>7)&1)); /* Saint Seiya...hmm. */ +} + +void Mapper152_Init(CartInfo *info) +{ + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 180 --------------------------- + +static void M180Sync(void) +{ + setprg16(0x8000,0); + setprg16(0xc000,latche); + setchr8(0); +} + +void Mapper180_Init(CartInfo *info) +{ + Latch_Init(info, M180Sync, 0, 0x8000, 0xFFFF, 0, 0); +} + +//------------------ Map 184 --------------------------- + +static void M184Sync(void) +{ + setchr4(0x0000,latche); + setchr4(0x1000,latche>>4); + setprg32(0x8000,0); +} + +void Mapper184_Init(CartInfo *info) +{ + Latch_Init(info, M184Sync, 0, 0x6000, 0x7FFF, 0, 0); +} + +//------------------ Map 240 --------------------------- + +void Mapper240_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x4020, 0x5FFF, 0, 0); + // need SRAM. +} + +//------------------ A65AS --------------------------- + +// actually, there is two cart in one... First have extra mirroring +// mode (one screen) and 32K bankswitching, second one have only +// 16 bankswitching mode and normal mirroring... But there is no any +// correlations between modes and they can be used in one mapper code. + +static void BMCA65ASSync(void) +{ + if(latche&0x40) + setprg32(0x8000,(latche>>1)&0x0F); + else + { + setprg16(0x8000,((latche&0x30)>>1)|(latche&7)); + setprg16(0xC000,((latche&0x30)>>1)|7); + } + setchr8(0); + if(latche&0x80) + setmirror(MI_0+(((latche>>5)&1))); + else + setmirror(((latche>>3)&1)^1); +} + +void BMCA65AS_Init(CartInfo *info) +{ + Latch_Init(info, BMCA65ASSync, 0, 0x8000, 0xFFFF, 0, 0); +} + diff --git a/boards/deirom.c b/boards/deirom.c index 2d28bd0..7a1ed43 100644 --- a/boards/deirom.c +++ b/boards/deirom.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -32,9 +32,9 @@ static SFORMAT DEI_StateRegs[]= static void Sync(void) { - int x; setchr2(0x0000,DRegs[0]); setchr2(0x0800,DRegs[1]); + int x; for(x=0;x<4;x++) setchr1(0x1000+(x<<10),DRegs[2+x]); setprg8(0x8000,DRegs[6]); diff --git a/boards/dream.c b/boards/dream.c index d2a9cb8..624c4f4 100644 --- a/boards/dream.c +++ b/boards/dream.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -52,5 +52,5 @@ void DreamTech01_Init(CartInfo *info) { GameStateRestore=Restore; info->Power=DREAMPower; - AddExState(&latche, 1, 0, "LATCH"); + AddExState(&latche, 1, 0, "LATC"); } diff --git a/boards/edu2000.c b/boards/edu2000.c index 36dcb5d..215b962 100644 --- a/boards/edu2000.c +++ b/boards/edu2000.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ @@ -76,8 +76,8 @@ void UNLEDU2000_Init(CartInfo *info) SetupCartPRGMapping(0x10,WRAM,32768,1); if(info->battery) { - info->SaveGame[0]=WRAM; - info->SaveGameLen[0]=32768; + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=32768; } AddExState(WRAM, 32768, 0, "WRAM"); AddExState(StateRegs, ~0, 0, 0); diff --git a/boards/famicombox.c b/boards/famicombox.c new file mode 100644 index 0000000..2bc8a4f --- /dev/null +++ b/boards/famicombox.c @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 regs[8]; +static uint8 *WRAM = NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {regs, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setprg2r(0x10,0x0800,0); + setprg2r(0x10,0x1000,1); + setprg2r(0x10,0x1800,2); + setprg8r(0x10,0x6000,1); + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); +} + +//static DECLFW(SSSNROMWrite) +//{ +// CartBW(A,V); +//} + +static DECLFW(SSSNROMWrite) +{ + //FCEU_printf("write %04x %02x\n",A,V); + //regs[A&7] = V; +} + +static DECLFR(SSSNROMRead) +{ + //FCEU_printf("read %04x\n",A); + switch(A&7) { + case 0: return regs[0]=0xff; // clear all exceptions + case 2: return 0xc0; // DIP selftest + freeplay + case 3: return 0x00; // 0, 1 - attract + // 2 + // 4 - menu + // 8 - self check and game casette check + // 10 - lock? + // 20 - game title & count display + case 7: return 0x22; // TV type, key not turned, relay B + default: return 0; + } +} + +static void SSSNROMPower(void) +{ + regs[0]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; + regs[7]=0xff; + Sync(); + memset(WRAM,0x00,WRAMSIZE); +// SetWriteHandler(0x0000,0x1FFF,SSSNROMRamWrite); + SetReadHandler(0x0800,0x1FFF,CartBR); + SetWriteHandler(0x0800,0x1FFF,CartBW); + SetReadHandler(0x5000,0x5FFF,SSSNROMRead); + SetWriteHandler(0x5000,0x5FFF,SSSNROMWrite); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void SSSNROMReset(void) +{ + regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; +} + +static void SSSNROMClose(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void SSSNROMIRQHook(void) +{ +// X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void SSSNROM_Init(CartInfo *info) +{ + info->Reset=SSSNROMReset; + info->Power=SSSNROMPower; + info->Close=SSSNROMClose; + GameHBIRQHook=SSSNROMIRQHook; + 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/boards/fk23c.c b/boards/fk23c.c index c869680..ca6c134 100644 --- a/boards/fk23c.c +++ b/boards/fk23c.c @@ -1,4 +1,4 @@ -/* FCE Ultra - NES/Famicom Emulator +/* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: * Copyright (C) 2006 CaH4e3 @@ -15,16 +15,14 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #include "mmc3.h" -#include "../ines.h" -static bool is_BMCFK23CA; static uint8 unromchr; -static uint32 dipswitch; +static uint32 dipswitch = 0; static uint8 *CHRRAM=NULL; static uint32 CHRRAMSize; @@ -52,96 +50,64 @@ static void BMCFK23CCW(uint32 A, uint8 V) } } -//some games are wired differently, and this will need to be changed. -//all the WXN games require prg_bonus = 1, and cah4e3's multicarts require prg_bonus = 0 -//we'll populate this from a game database -static int prg_bonus; -static int prg_mask; - -//prg_bonus = 0 -//4-in-1 (FK23C8021)[p1][!].nes -//4-in-1 (FK23C8033)[p1][!].nes -//4-in-1 (FK23C8043)[p1][!].nes -//4-in-1 (FK23Cxxxx, S-0210A PCB)[p1][!].nes - -//prg_bonus = 1 -//[m176]大富翁2-上海大亨.wxn.nes -//[m176]宠物翡翠.fix.nes -//[m176]格兰帝亚.wxn.nes -//[m176]梦幻之星.wxn.nes -//[m176]水浒神兽.fix.nes -//[m176]西楚霸王.fix.nes -//[m176]超级大富翁.wxn.nes -//[m176]雄霸天下.wxn.nes - -//works as-is under virtuanes m176 -//[m176]三侠五义.wxn.nes -//[m176]口袋金.fix.nes -//[m176]爆笑三国.fix.nes - -//needs other tweaks -//[m176]三国忠烈传.wxn.nes -//[m176]破釜沉舟.fix.nes - -//PRG wrapper static void BMCFK23CPW(uint32 A, uint8 V) { uint32 bank = (EXPREGS[1] & 0x1F); uint32 hiblock = ((EXPREGS[0] & 8) << 4)|((EXPREGS[0] & 0x80) << 1)|(UNIFchrrama?((EXPREGS[2] & 0x40)<<3):0); uint32 block = (EXPREGS[1] & 0x60) | hiblock; uint32 extra = (EXPREGS[3] & 2); - - if((EXPREGS[0]&7)==4) - setprg32(0x8000,EXPREGS[1]>>1); - else if ((EXPREGS[0]&7)==3) + switch(EXPREGS[0]&7) { - setprg16(0x8000,EXPREGS[1]); - setprg16(0xC000,EXPREGS[1]); - } - else - { - if(EXPREGS[0]&3) - { - uint32 blocksize = (6)-(EXPREGS[0]&3); - uint32 mask = (1<> 1); + break; } - setprg8r(0x10,0x6000,A001B&3); + setprg8r(0x10,0x6000,A001B&3); } -//PRG handler ($8000-$FFFF) static DECLFW(BMCFK23CHiWrite) { - if(EXPREGS[0]&0x40) - { - if(EXPREGS[0]&0x30) - unromchr=0; - else - { - unromchr=V&3; - FixMMC3CHR(MMC3_cmd); - } - } - else - { - if((A==0x8001)&&(EXPREGS[3]&2&&MMC3_cmd&8)) - { - EXPREGS[4|(MMC3_cmd&3)]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } + if(EXPREGS[0]&0x40) + { + if(EXPREGS[0]&0x30) + unromchr=0; + else + { + unromchr=V&3; + FixMMC3CHR(MMC3_cmd); + } + } + else + { + if((A==0x8001)&&(EXPREGS[3]&2)&&(MMC3_cmd&8)) + { + EXPREGS[4|(MMC3_cmd&3)]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } else if(A<0xC000) { if(UNIFchrrama) { // hacky... strange behaviour, must be bit scramble due to pcb layot restrictions @@ -159,51 +125,35 @@ static DECLFW(BMCFK23CHiWrite) } } -//EXP handler ($5000-$5FFF) static DECLFW(BMCFK23CWrite) { - if(A&(1<<(dipswitch+4))) + //FCEU_printf("lo %04x:%02x\n",A,V); + if(dipswitch) // íóëåâîé äèï áåðåò ëþáûå çàïèñè ïî äåôîëòó, äàëüøå èäåò âûáîð + { + if(A&(1<<(dipswitch+3))) { + EXPREGS[A&3]=V; +// FCEU_printf(" reg %d set!\n",A&3); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + } + else { - //printf("+ "); EXPREGS[A&3]=V; - - bool remap = false; - - //sometimes writing to reg0 causes remappings to occur. we think the 2 signifies this. - //if not, 0x24 is a value that is known to work - //however, the low 4 bits are known to control the mapping mode, so 0x20 is more likely to be the immediate remap flag - remap |= ((EXPREGS[0]&0xF0)==0x20); - - //this is an actual mapping reg. i think reg0 controls what happens when reg1 is written. anyway, we have to immediately remap these - remap |= (A&3)==1; - //this too. - remap |= (A&3)==2; - - if(remap) - { - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } +// FCEU_printf(" reg %d set!\n",A&3); + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); } - - if(is_BMCFK23CA) - { - if(EXPREGS[3]&2) - EXPREGS[0] &= ~7; // hacky hacky! if someone wants extra banking, then for sure doesn't want mode 4 for it! (allow to run A version boards on normal mapper) - } - - //printf("%04X = $%02X\n",A,V); - //printf("%02X %02X %02X %02X\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]); + if(EXPREGS[3]&2) + EXPREGS[0] &= ~7; // hacky hacky! if someone wants extra banking, then for sure doesn't want mode 4 for it! (allow to run A version boards on normal mapper) } static void BMCFK23CReset(void) { - //NOT NECESSARY ANYMORE - //this little hack makes sure that we try all the dip switch settings eventually, if we reset enough - // dipswitch++; - // dipswitch&=7; - //printf("BMCFK23C dipswitch set to %d\n",dipswitch); - + if(dipswitch<=8) + dipswitch++; + else + dipswitch=0; EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; MMC3RegReset(); @@ -213,11 +163,12 @@ static void BMCFK23CReset(void) static void BMCFK23CPower(void) { - dipswitch = 0; GenMMC3Power(); - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; + EXPREGS[0]=4; + EXPREGS[1]=0xFF; + EXPREGS[2]=EXPREGS[3]=0; + dipswitch = 0; EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; - GenMMC3Power(); SetWriteHandler(0x5000,0x5fff,BMCFK23CWrite); SetWriteHandler(0x8000,0xFFFF,BMCFK23CHiWrite); FixMMC3PRG(MMC3_cmd); @@ -245,46 +196,31 @@ static void BMCFK23CAClose(void) void BMCFK23C_Init(CartInfo *info) { - is_BMCFK23CA = false; - - GenMMC3_Init(info, 512, 256, 8, 0); + GenMMC3_Init(info, 512, 256, 128, 0); cwrap=BMCFK23CCW; pwrap=BMCFK23CPW; info->Power=BMCFK23CPower; info->Reset=BMCFK23CReset; AddExState(EXPREGS, 8, 0, "EXPR"); - AddExState(&unromchr, 1, 0, "UNCHR"); - AddExState(&dipswitch, 1, 0, "DIPSW"); - - prg_bonus = 1; - if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) - prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); - - prg_mask = 0x7F>>(prg_bonus); + AddExState(&unromchr, 1, 0, "UCHR"); + AddExState(&dipswitch, 1, 0, "DPSW"); } void BMCFK23CA_Init(CartInfo *info) { - is_BMCFK23CA = true; - - GenMMC3_Init(info, 512, 256, 8, 0); + GenMMC3_Init(info, 512, 256, 128, 0); cwrap=BMCFK23CCW; pwrap=BMCFK23CPW; info->Power=BMCFK23CAPower; info->Reset=BMCFK23CReset; info->Close=BMCFK23CAClose; - - CHRRAMSize=8192; + + CHRRAMSize=8192; CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); AddExState(CHRRAM, CHRRAMSize, 0, "CRAM"); AddExState(EXPREGS, 8, 0, "EXPR"); - AddExState(&unromchr, 1, 0, "UNCHR"); - AddExState(&dipswitch, 1, 0, "DIPSW"); - - prg_bonus = 1; - if(MasterRomInfoParams.find("bonus") != MasterRomInfoParams.end()) - prg_bonus = atoi(MasterRomInfoParams["bonus"].c_str()); - prg_mask = 0x7F>>(prg_bonus); + AddExState(&unromchr, 1, 0, "UCHR"); + AddExState(&dipswitch, 1, 0, "DPSW"); } diff --git a/boards/ghostbusters63in1.c b/boards/ghostbusters63in1.c index 627f16d..38db79f 100644 --- a/boards/ghostbusters63in1.c +++ b/boards/ghostbusters63in1.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * 63in1 ghostbusters */ @@ -99,7 +99,7 @@ void BMCGhostbusters63in1_Init(CartInfo *info) CHRROMSIZE=8192; // dummy CHRROM, VRAM disable CHRROM=(uint8*)FCEU_gmalloc(CHRROMSIZE); SetupCartPRGMapping(0x10,CHRROM,CHRROMSIZE,0); - AddExState(CHRROM, CHRROMSIZE, 0, "CHRROM"); + AddExState(CHRROM, CHRROMSIZE, 0, "CROM"); GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); diff --git a/boards/gs-2004.c b/boards/gs-2004.c index 574ed97..17a9ef8 100644 --- a/boards/gs-2004.c +++ b/boards/gs-2004.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/gs-2013.c b/boards/gs-2013.c index 1b4d37b..027d0ac 100644 --- a/boards/gs-2013.c +++ b/boards/gs-2013.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/h2288.c b/boards/h2288.c index 7786daf..a3b5a0b 100644 --- a/boards/h2288.c +++ b/boards/h2288.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -61,23 +61,14 @@ static DECLFW(H2288WriteLo) } } -static DECLFR(H2288Read) -{ - int bit; - bit=(A&1)^1; - bit&=((A>>8)&1); - bit^=1; - return((X.DB&0xFE)|bit); -} - static void H2288Power(void) { EXPREGS[0]=EXPREGS[1]=0; GenMMC3Power(); - SetReadHandler(0x5000,0x5FFF,H2288Read); +// SetReadHandler(0x5000,0x5FFF,H2288Read); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); - SetWriteHandler(0x8000,0x8FFF,H2288WriteHi); + SetWriteHandler(0x8000,0x9FFF,H2288WriteHi); } void UNLH2288_Init(CartInfo *info) diff --git a/boards/karaoke.c b/boards/karaoke.c index dfb4cc8..fe1c542 100644 --- a/boards/karaoke.c +++ b/boards/karaoke.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -67,5 +67,5 @@ void Mapper188_Init(CartInfo *info) { info->Power=Power; GameStateRestore=StateRestore; - AddExState(&latche, 1, 0, "LATCH"); + AddExState(&latche, 1, 0, "LATC"); } diff --git a/boards/kof97.c b/boards/kof97.c index 7bb63ee..e40f4cf 100644 --- a/boards/kof97.c +++ b/boards/kof97.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/konami-qtai.c b/boards/konami-qtai.c index 83630a6..ab62e09 100644 --- a/boards/konami-qtai.c +++ b/boards/konami-qtai.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2005-2008 CaH4e3 + * 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 @@ -15,9 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-5 (CAI Shogakko no Sansu) * - * CAI Shogakko no Sansu */ #include "mapinc.h" @@ -27,7 +28,7 @@ static writefunc old2007wrap; static uint16 CHRSIZE = 8192; static uint16 WRAMSIZE = 8192 + 4096; -static uint8 *CHRRAM=NULL; +static uint8 *CHRRAM = NULL; static uint8 *WRAM = NULL; static uint8 IRQa, K4IRQ; @@ -40,7 +41,7 @@ static SFORMAT StateRegs[]= {&IRQCount, 1, "IRQC"}, {&IRQLatch, 1, "IRQL"}, {&IRQa, 1, "IRQA"}, - {&K4IRQ, 1, "K4IRQ"}, + {&K4IRQ, 1, "KIRQ"}, {regs, 16, "REGS"}, {0} }; @@ -136,10 +137,10 @@ static DECLFW(M190Write) static DECLFR(M190Read) { -// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); +// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); return regs[(A&0x0F00)>>8]+regs[0x0B]; } -static void VRC5IRQ(int a) +static void FP_FASTAPASS(1) VRC5IRQ(int a) { if(IRQa) { @@ -147,21 +148,18 @@ static void VRC5IRQ(int a) if(IRQCount&0x10000) { X6502_IRQBegin(FCEU_IQEXT); -// IRQCount=IRQLatch; + IRQCount=IRQLatch; } } } -static void Mapper190_PPU(uint32 A) -{ - if(A>=0x2000) - { - setchr4r(0x10,0x0000,QTAINTRAM[A&0x1FFF]&1); - setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1); - } +//static void FP_FASTAPASS(1) Mapper190_PPU(uint32 A) +//{ +// if(A<0x2000) +// setchr4r(0x10,0x1000,QTAINTRAM[A&0x1FFF]&1); // else // chrSync(); -} +//} static DECLFW(M1902007Wrap) { @@ -222,11 +220,11 @@ void Mapper190_Init(CartInfo *info) GameStateRestore=StateRestore; MapIRQHook=VRC5IRQ; - //PPU_hook=Mapper190_PPU; +// PPU_hook=Mapper190_PPU; CHRRAM=(uint8*)FCEU_gmalloc(CHRSIZE); SetupCartCHRMapping(0x10,CHRRAM,CHRSIZE,1); - AddExState(CHRRAM, CHRSIZE, 0, "CHRRAM"); + AddExState(CHRRAM, CHRSIZE, 0, "CRAM"); WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); diff --git a/boards/le05.c b/boards/le05.c new file mode 100644 index 0000000..a76d787 --- /dev/null +++ b/boards/le05.c @@ -0,0 +1,66 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2011 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 chr; +static SFORMAT StateRegs[]= +{ + {&chr, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + setprg2r(0,0xE000,0); + setprg2r(0,0xE800,0); + setprg2r(0,0xF000,0); + setprg2r(0,0xF800,0); + + setprg8r(1,0x6000,3); + setprg8r(1,0x8000,0); + setprg8r(1,0xA000,1); + setprg8r(1,0xC000,2); + + setchr8(chr & 1); + setmirror(MI_V); +} + +static DECLFW(LE05Write) +{ + chr = V; + Sync(); +} + +static void LE05Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,LE05Write); +} + +void LE05_Init(CartInfo *info) +{ + info->Power=LE05Power; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/lh32.c b/boards/lh32.c new file mode 100644 index 0000000..7ad2d92 --- /dev/null +++ b/boards/lh32.c @@ -0,0 +1,84 @@ +/* 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {0} +}; + +static void Sync(void) +{ + setprg8(0x6000,reg); + setprg8(0x8000,~3); + setprg8(0xa000,~2); + setprg8r(0x10,0xc000,0); + setprg8(0xe000,~0); + setchr8(0); +} + +static DECLFW(LH32Write) +{ + reg=V; + Sync(); +} + +static void LH32Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0xC000,0xDFFF,CartBW); + SetWriteHandler(0x6000,0x6000,LH32Write); +} + +static void LH32Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void LH32_Init(CartInfo *info) +{ + info->Power=LH32Power; + info->Close=LH32Close; + + WRAMSIZE=8192; + WRAM=(uint8*)FCEU_gmalloc(WRAMSIZE); + SetupCartPRGMapping(0x10,WRAM,WRAMSIZE,1); + AddExState(WRAM, WRAMSIZE, 0, "WRAM"); + + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/lh53.c b/boards/lh53.c new file mode 100644 index 0000000..b91c9dd --- /dev/null +++ b/boards/lh53.c @@ -0,0 +1,117 @@ +/* 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 + * + * FDS Conversion + * + */ + +#include "mapinc.h" + +static uint8 reg, IRQa; +static int32 IRQCount; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {®, 1, "REG"}, + {&IRQa, 1, "IRQA"}, + {&IRQCount, 4, "IRQC"}, + {0} +}; + +static void Sync(void) +{ + setchr8(0); + setprg8(0x6000,reg); + setprg8(0x8000,0xc); + 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); + setprg8(0xe000,0xf); +} + +static DECLFW(LH53RamWrite) +{ + WRAM[(A-0xB800)&0x1FFF]=V; +} + +static DECLFW(LH53Write) +{ + reg=V; + Sync(); +} + +static DECLFW(LH53IRQaWrite) +{ + IRQa = V&2; + IRQCount = 0; + if(!IRQa) + X6502_IRQEnd(FCEU_IQEXT); +} + +static void FP_FASTAPASS(1) LH53IRQ(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>7560) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void LH53Power(void) +{ + Sync(); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0xB800,0xD7FF,LH53RamWrite); + SetWriteHandler(0xE000,0xEFFF,LH53IRQaWrite); + SetWriteHandler(0xF000,0xFFFF,LH53Write); +} + +static void LH53Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void LH53_Init(CartInfo *info) +{ + info->Power=LH53Power; + info->Close=LH53Close; + MapIRQHook=LH53IRQ; + 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/boards/malee.c b/boards/malee.c index 8c30182..83f2621 100644 --- a/boards/malee.c +++ b/boards/malee.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" @@ -38,5 +41,5 @@ void MALEE_Init(CartInfo *info) { info->Power=MALEEPower; SetupCartPRGMapping(0x10, WRAM, 2048, 1); - AddExState(WRAM, 2048, 0,"RAM"); + AddExState(WRAM, 2048, 0,"WRAM"); } diff --git a/boards/mapinc.h b/boards/mapinc.h index 8fa46f4..e305e30 100644 --- a/boards/mapinc.h +++ b/boards/mapinc.h @@ -1,12 +1,11 @@ #include "../types.h" -#include "../utils/memory.h" #include "../x6502.h" -#include "../fceu.h" +#include "../fce.h" #include "../ppu.h" +#include "../memory.h" #include "../sound.h" #include "../state.h" #include "../cart.h" #include "../cheat.h" #include "../unif.h" -#include #include diff --git a/boards/mmc1.c b/boards/mmc1.c index 24a07bc..df7ddf8 100644 --- a/boards/mmc1.c +++ b/boards/mmc1.c @@ -16,7 +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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -24,8 +24,8 @@ static void GenMMC1Power(void); static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); -static uint8 DRegs[4]; -static uint8 Buffer,BufferShift; +static uint8 BufferShift,DRegs[4]; +static uint8 Buffer; static int mmc1opts; @@ -107,39 +107,39 @@ static void MMC1PRG(void) else { switch(DRegs[0]&0xC) - { - case 0xC: setprg16(0x8000,(DRegs[3]+offs)); - setprg16(0xC000,0xF+offs); - break; - case 0x8: setprg16(0xC000,(DRegs[3]+offs)); - setprg16(0x8000,offs); - break; - case 0x0: - case 0x4: - setprg16(0x8000,((DRegs[3]&~1)+offs)); - setprg16(0xc000,((DRegs[3]&~1)+offs+1)); - break; + { + case 0xC: setprg16(0x8000,(DRegs[3]+offs)); + setprg16(0xC000,0xF+offs); + break; + case 0x8: setprg16(0xC000,(DRegs[3]+offs)); + setprg16(0x8000,offs); + break; + case 0x0: + case 0x4: + setprg16(0x8000,((DRegs[3]&~1)+offs)); + setprg16(0xc000,((DRegs[3]&~1)+offs+1)); + break; + } } } -} static void MMC1MIRROR(void) { if(!is171) - switch(DRegs[0]&3) - { - case 2: setmirror(MI_V); break; - case 3: setmirror(MI_H); break; - case 0: setmirror(MI_0); break; - case 1: setmirror(MI_1); break; - } + switch(DRegs[0]&3) + { + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + } } static uint64 lreset; static DECLFW(MMC1_write) { int n=(A>>13)-4; - //FCEU_DispMessage("%016x",0,timestampbase+timestamp); + //FCEU_DispMessage("%016x",timestampbase+timestamp); // FCEU_printf("$%04x:$%02x, $%04x\n",A,V,X.PC); //DumpMem("out",0xe000,0xffff); @@ -165,6 +165,7 @@ static DECLFW(MMC1_write) if(BufferShift==5) { +// FCEU_printf("REG[%d]=%02x\n",n,Buffer); DRegs[n] = Buffer; BufferShift = Buffer = 0; switch(n) @@ -323,11 +324,6 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) if(wram) { WRAM=(uint8*)FCEU_gmalloc(wram*1024); - //mbg 17-jun-08 - this shouldve been cleared to re-initialize save ram - //ch4 10-dec-08 - nope, this souldn't - //mbg 29-mar-09 - no time to debate this, we need to keep from breaking some old stuff. - //we really need to make up a policy for how compatibility and accuracy can be resolved. - memset(WRAM,0,wram*1024); mmc1opts|=1; if(wram>8) mmc1opts|=4; SetupCartPRGMapping(0x10,WRAM,wram*1024,1); @@ -350,8 +346,6 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) info->Power=GenMMC1Power; GameStateRestore=MMC1_Restore; AddExState(&lreset, 8, 1, "LRST"); - AddExState(&Buffer, 1, 1, "BFFR"); - AddExState(&BufferShift, 1, 1, "BFRS"); } void Mapper1_Init(CartInfo *info) diff --git a/boards/mmc3.c b/boards/mmc3.c index 2618db4..6d3af95 100644 --- a/boards/mmc3.c +++ b/boards/mmc3.c @@ -1,1411 +1,1453 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * Copyright (C) 2003 Xodnizel - * Mapper 12 code Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, - 119,165,205,214,215,245,249,250,254 -*/ - -#include "mapinc.h" -#include "mmc3.h" - -uint8 MMC3_cmd; -uint8 *WRAM; -uint8 *CHRRAM; -uint32 CHRRAMSize; -uint8 DRegBuf[8]; -uint8 EXPREGS[8]; /* For bootleg games, mostly. */ -uint8 A000B,A001B; - -#undef IRQCount -#undef IRQLatch -#undef IRQa -uint8 IRQCount,IRQLatch,IRQa; -uint8 IRQReload; - -static SFORMAT MMC3_StateRegs[]= -{ - {DRegBuf, 8, "REGS"}, - {&MMC3_cmd, 1, "CMD"}, - {&A000B, 1, "A000"}, - {&A001B, 1, "A001"}, - {&IRQReload, 1, "IRQR"}, - {&IRQCount, 1, "IRQC"}, - {&IRQLatch, 1, "IRQL"}, - {&IRQa, 1, "IRQA"}, - {0} -}; - -static int mmc3opts=0; -static int wrams; -static int isRevB=1; - -void (*pwrap)(uint32 A, uint8 V); -void (*cwrap)(uint32 A, uint8 V); -void (*mwrap)(uint8 V); - -void GenMMC3Power(void); -void FixMMC3PRG(int V); -void FixMMC3CHR(int V); - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); - -// ---------------------------------------------------------------------- -// ------------------------- Generic MM3 Code --------------------------- -// ---------------------------------------------------------------------- - -void FixMMC3PRG(int V) -{ - if(V&0x40) - { - pwrap(0xC000,DRegBuf[6]); - pwrap(0x8000,~1); - } - else - { - pwrap(0x8000,DRegBuf[6]); - pwrap(0xC000,~1); - } - pwrap(0xA000,DRegBuf[7]); - pwrap(0xE000,~0); -} - -void FixMMC3CHR(int V) -{ - int cbase=(V&0x80)<<5; - - cwrap((cbase^0x000),DRegBuf[0]&(~1)); - cwrap((cbase^0x400),DRegBuf[0]|1); - cwrap((cbase^0x800),DRegBuf[1]&(~1)); - cwrap((cbase^0xC00),DRegBuf[1]|1); - - cwrap(cbase^0x1000,DRegBuf[2]); - cwrap(cbase^0x1400,DRegBuf[3]); - cwrap(cbase^0x1800,DRegBuf[4]); - cwrap(cbase^0x1c00,DRegBuf[5]); - - if(mwrap) mwrap(A000B); -} - -void MMC3RegReset(void) -{ - IRQCount=IRQLatch=IRQa=MMC3_cmd=0; - - DRegBuf[0]=0; - DRegBuf[1]=2; - DRegBuf[2]=4; - DRegBuf[3]=5; - DRegBuf[4]=6; - DRegBuf[5]=7; - DRegBuf[6]=0; - DRegBuf[7]=1; - - FixMMC3PRG(0); - FixMMC3CHR(0); -} - -DECLFW(MMC3_CMDWrite) -{ -// FCEU_printf("bs %04x %02x\n",A,V); - switch(A&0xE001) - { - case 0x8000: - if((V&0x40) != (MMC3_cmd&0x40)) - FixMMC3PRG(V); - if((V&0x80) != (MMC3_cmd&0x80)) - FixMMC3CHR(V); - MMC3_cmd = V; - break; - case 0x8001: - { - int cbase=(MMC3_cmd&0x80)<<5; - DRegBuf[MMC3_cmd&0x7]=V; - switch(MMC3_cmd&0x07) - { - case 0: cwrap((cbase^0x000),V&(~1)); - cwrap((cbase^0x400),V|1); - break; - case 1: cwrap((cbase^0x800),V&(~1)); - cwrap((cbase^0xC00),V|1); - break; - case 2: cwrap(cbase^0x1000,V); - break; - case 3: cwrap(cbase^0x1400,V); - break; - case 4: cwrap(cbase^0x1800,V); - break; - case 5: cwrap(cbase^0x1C00,V); - break; - case 6: - if(MMC3_cmd&0x40) - pwrap(0xC000,V); - else - pwrap(0x8000,V); - break; - case 7: - pwrap(0xA000,V); - break; - } - } - break; - case 0xA000: - if(mwrap) mwrap(V); - break; - case 0xA001: - A001B=V; - break; - } -} - -DECLFW(MMC3_IRQWrite) -{ -// FCEU_printf("%04x:%04x\n",A,V); - switch(A&0xE001) - { - case 0xC000:IRQLatch=V;break; - case 0xC001:IRQReload=1;break; - case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break; - case 0xE001:IRQa=1;break; - } -} - -static void ClockMMC3Counter(void) -{ - int count = IRQCount; - if(!count || IRQReload) - { - IRQCount = IRQLatch; - IRQReload = 0; - } - else - IRQCount--; - if((count|isRevB) && !IRQCount) - { - if(IRQa) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void MMC3_hb(void) -{ - ClockMMC3Counter(); -} - -static void MMC3_hb_KickMasterHack(void) -{ - if(scanline==238) ClockMMC3Counter(); - ClockMMC3Counter(); -} - -static void MMC3_hb_PALStarWarsHack(void) -{ - if(scanline==240) ClockMMC3Counter(); - ClockMMC3Counter(); -} - -void GenMMC3Restore(int version) -{ - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void GENCWRAP(uint32 A, uint8 V) -{ - setchr1(A,V); // Business Wars NEEDS THIS for 8K CHR-RAM -} - -static void GENPWRAP(uint32 A, uint8 V) -{ - setprg8(A,V&0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken -} - -static void GENMWRAP(uint8 V) -{ - A000B=V; - setmirror((V&1)^1); -} - -static void GENNOMWRAP(uint8 V) -{ - A000B=V; -} - -static DECLFW(MBWRAMMMC6) -{ - WRAM[A&0x3ff]=V; -} - -static DECLFR(MAWRAMMMC6) -{ - return(WRAM[A&0x3ff]); -} - -void GenMMC3Power(void) -{ - if(UNIFchrrama) setchr8(0); - - SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); - SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); - SetReadHandler(0x8000,0xFFFF,CartBR); - A001B=A000B=0; - setmirror(1); - if(mmc3opts&1) - { - if(wrams==1024) - { - FCEU_CheatAddRAM(1,0x7000,WRAM); - SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6); - SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6); - } - else - { - FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM); - SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW); - SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR); - setprg8r(0x10,0x6000,0); - } - if(!(mmc3opts&2)) - FCEU_dwmemset(WRAM,0,wrams); - } - MMC3RegReset(); - if(CHRRAM) - FCEU_dwmemset(CHRRAM,0,CHRRAMSize); -} - -static void GenMMC3Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - if(WRAM) - FCEU_gfree(WRAM); - CHRRAM=WRAM=NULL; -} - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) -{ - pwrap=GENPWRAP; - cwrap=GENCWRAP; - mwrap=GENMWRAP; - - wrams=wram<<10; - - PRGmask8[0]&=(prg>>13)-1; - CHRmask1[0]&=(chr>>10)-1; - CHRmask2[0]&=(chr>>11)-1; - - if(wram) - { - mmc3opts|=1; - WRAM=(uint8*)FCEU_gmalloc(wrams); - SetupCartPRGMapping(0x10,WRAM,wrams,1); - AddExState(WRAM, wrams, 0, "MMC3WRAM"); - } - - if(battery) - { - mmc3opts|=2; - info->SaveGame[0]=WRAM; - info->SaveGameLen[0]=wrams; - } - - AddExState(MMC3_StateRegs, ~0, 0, 0); - - info->Power=GenMMC3Power; - info->Reset=MMC3RegReset; - info->Close=GenMMC3Close; - - if(info->CRC32 == 0x5104833e) // Kick Master - GameHBIRQHook = MMC3_hb_KickMasterHack; - else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93 - GameHBIRQHook = MMC3_hb_KickMasterHack; - else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. - GameHBIRQHook = MMC3_hb_PALStarWarsHack; - else - GameHBIRQHook=MMC3_hb; - GameStateRestore=GenMMC3Restore; -} - -// ---------------------------------------------------------------------- -// -------------------------- MMC3 Based Code --------------------------- -// ---------------------------------------------------------------------- - -// ---------------------------- Mapper 4 -------------------------------- - -static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/ - -static void M4Power(void) -{ - GenMMC3Power(); - A000B=(hackm4^1)&1; - setmirror(hackm4); -} - -void Mapper4_Init(CartInfo *info) -{ - int ws=8; - - if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84)) - { - FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); - ws=0; - } - GenMMC3_Init(info,512,256,ws,info->battery); - info->Power=M4Power; - hackm4=info->mirror; -} - -// ---------------------------- Mapper 12 ------------------------------- - -static void M12CW(uint32 A, uint8 V) -{ - setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V); -} - -static DECLFW(M12Write) -{ - EXPREGS[0]=V&0x01; - EXPREGS[1]=(V&0x10)>>4; -} - -static void M12Power(void) -{ - EXPREGS[0]=EXPREGS[1]=0; - GenMMC3Power(); - SetWriteHandler(0x4100,0x5FFF,M12Write); -} - -void Mapper12_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M12CW; - isRevB=0; - - info->Power=M12Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 37 ------------------------------- - -static void M37PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]!=2) - V&=0x7; - else - V&=0xF; - V|=EXPREGS[0]<<3; - setprg8(A,V); -} - -static void M37CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=EXPREGS[0]<<6; - setchr1(A,NV); -} - -static DECLFW(M37Write) -{ - EXPREGS[0]=(V&6)>>1; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M37Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M37Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M37Write); -} - -void Mapper37_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - pwrap=M37PW; - cwrap=M37CW; - info->Power=M37Power; - info->Reset=M37Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 44 ------------------------------- - -static void M44PW(uint32 A, uint8 V) -{ - uint32 NV=V; - if(EXPREGS[0]>=6) NV&=0x1F; - else NV&=0x0F; - NV|=EXPREGS[0]<<4; - setprg8(A,NV); -} - -static void M44CW(uint32 A, uint8 V) -{ - uint32 NV=V; - if(EXPREGS[0]<6) NV&=0x7F; - NV|=EXPREGS[0]<<7; - setchr1(A,NV); -} - -static DECLFW(M44Write) -{ - if(A&1) - { - EXPREGS[0]=V&7; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } - else - MMC3_CMDWrite(A,V); -} - -static void M44Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0xA000,0xBFFF,M44Write); -} - -void Mapper44_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M44CW; - pwrap=M44PW; - info->Power=M44Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 45 ------------------------------- - -static void M45CW(uint32 A, uint8 V) -{ - if(!UNIFchrrama) - { - uint32 NV=V; - if(EXPREGS[2]&8) - NV&=(1<<((EXPREGS[2]&7)+1))-1; - 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); - } -} - -static void M45PW(uint32 A, uint8 V) -{ - V&=(EXPREGS[3]&0x3F)^0x3F; - V|=EXPREGS[1]; - setprg8(A,V); -} - -static DECLFW(M45Write) -{ - if(EXPREGS[3]&0x40) - { - WRAM[A-0x6000]=V; - return; - } - EXPREGS[EXPREGS[4]]=V; - EXPREGS[4]=(EXPREGS[4]+1)&3; -// if(!EXPREGS[4]) -// { -// FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]); -// FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n", -// (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), -// (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), -// (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]), -// (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1])); -// } - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M45Reset(void) -{ - EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; - MMC3RegReset(); -} - -static void M45Power(void) -{ - setchr8(0); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M45Write); -} - -void Mapper45_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M45CW; - pwrap=M45PW; - info->Reset=M45Reset; - info->Power=M45Power; - AddExState(EXPREGS, 5, 0, "EXPR"); -} - -// ---------------------------- Mapper 47 ------------------------------- - -static void M47PW(uint32 A, uint8 V) -{ - V&=0xF; - V|=EXPREGS[0]<<4; - setprg8(A,V); -} - -static void M47CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=EXPREGS[0]<<7; - setchr1(A,NV); -} - -static DECLFW(M47Write) -{ - EXPREGS[0]=V&1; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M47Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M47Write); -// SetReadHandler(0x6000,0x7FFF,0); -} - -void Mapper47_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - pwrap=M47PW; - cwrap=M47CW; - info->Power=M47Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 49 ------------------------------- - -static void M49PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&1) - { - V&=0xF; - V|=(EXPREGS[0]&0xC0)>>2; - setprg8(A,V); - } - else - setprg32(0x8000,(EXPREGS[0]>>4)&3); -} - -static void M49CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x7F; - NV|=(EXPREGS[0]&0xC0)<<1; - setchr1(A,NV); -} - -static DECLFW(M49Write) -{ - if(A001B&0x80) - { - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - } -} - -static void M49Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M49Power(void) -{ - M49Reset(); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M49Write); - SetReadHandler(0x6000,0x7FFF,0); -} - -void Mapper49_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 0, 0); - cwrap=M49CW; - pwrap=M49PW; - info->Reset=M49Reset; - info->Power=M49Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 52 ------------------------------- - -static void M52PW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0x1F^((EXPREGS[0]&8)<<1); - NV|=((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4; - setprg8(A,NV); -} - -static void M52CW(uint32 A, uint8 V) -{ - uint32 NV=V; - NV&=0xFF^((EXPREGS[0]&0x40)<<1); - NV|=(((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; - setchr1(A,NV); -} - -static DECLFW(M52Write) -{ - if(EXPREGS[1]) - { - WRAM[A-0x6000]=V; - return; - } - EXPREGS[1]=1; - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M52Reset(void) -{ - EXPREGS[0]=EXPREGS[1]=0; - MMC3RegReset(); -} - -static void M52Power(void) -{ - M52Reset(); - GenMMC3Power(); - SetWriteHandler(0x6000,0x7FFF,M52Write); -} - -void Mapper52_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M52CW; - pwrap=M52PW; - info->Reset=M52Reset; - info->Power=M52Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 74 ------------------------------- - -static void M74CW(uint32 A, uint8 V) -{ - if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper74_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M74CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 114 ------------------------------ - -static uint8 cmdin; -uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; - -static void M114PWRAP(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x80) - { - setprg16(0x8000,EXPREGS[0]&0xF); - setprg16(0xC000,EXPREGS[0]&0xF); - } - else - setprg8(A,V&0x3F); -} - -static DECLFW(M114Write) -{ - switch(A&0xE001) - { - case 0x8001: MMC3_CMDWrite(0xA000,V); break; - case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break; - case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break; - case 0xA001: IRQLatch=V; break; - case 0xC001: IRQReload=1; break; - case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; - case 0xE001: IRQa=1; break; - } -} - -static DECLFW(M114ExWrite) -{ - if(A<=0x7FFF) - { - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - } -} - -static void M114Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xFFFF,M114Write); - SetWriteHandler(0x5000,0x7FFF,M114ExWrite); -} - -static void M114Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -void Mapper114_Init(CartInfo *info) -{ - isRevB=0; - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap=M114PWRAP; - info->Power=M114Power; - info->Reset=M114Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); - AddExState(&cmdin, 1, 0, "CMDIN"); -} - -// ---------------------------- Mapper 115 ------------------------------ - -static void M115PW(uint32 A, uint8 V) -{ - //zero 09-apr-2012 - #3515357 - changed to support Bao Qing Tian (mapper 248) which was missing BG gfx. 115 game(s?) seem still to work OK. - GENPWRAP(A,V); - if(A==0x8000 && EXPREGS[0]&0x80) - setprg16(0x8000,(EXPREGS[0]&0xF)); -} - -static void M115CW(uint32 A, uint8 V) -{ - setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); -} - -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) - EXPREGS[1]=V; - FixMMC3PRG(MMC3_cmd); -} - -static DECLFR(M115Read) -{ - return EXPREGS[2]; -} - -static void M115Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x4100,0x7FFF,M115Write); - SetReadHandler(0x5000,0x5FFF,M115Read); -} - -void Mapper115_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 512, 0, 0); - cwrap=M115CW; - pwrap=M115PW; - info->Power=M115Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- Mapper 118 ------------------------------ - -static uint8 PPUCHRBus; -static uint8 TKSMIR[8]; - -static void TKSPPU(uint32 A) -{ - A&=0x1FFF; - A>>=10; - PPUCHRBus=A; - setmirror(MI_0+TKSMIR[A]); -} - -static void TKSWRAP(uint32 A, uint8 V) -{ - TKSMIR[A>>10]=V>>7; - setchr1(A,V&0x7F); - if(PPUCHRBus==(A>>10)) - setmirror(MI_0+(V>>7)); -} - -// ---------------------------- Mapper 119 ------------------------------ - -static void TQWRAP(uint32 A, uint8 V) -{ - setchr1r((V&0x40)>>2,A,V&0x3F); -} - -void Mapper119_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); - cwrap=TQWRAP; - CHRRAMSize=8192; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - 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) -{ - if(V==0) - setchr4r(0x10,A,0); - else - setchr4(A,V>>2); -} - -static void M165PPUFD(void) -{ - if(EXPREGS[0]==0xFD) - { - M165CW(0x0000,DRegBuf[0]); - M165CW(0x1000,DRegBuf[2]); - } -} - -static void M165PPUFE(void) -{ - if(EXPREGS[0]==0xFE) - { - M165CW(0x0000,DRegBuf[1]); - M165CW(0x1000,DRegBuf[4]); - } -} - -static void M165CWM(uint32 A, uint8 V) -{ - if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2)) - M165PPUFD(); - if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4)) - M165PPUFE(); -} - -static void M165PPU(uint32 A) -{ - if((A&0x1FF0)==0x1FD0) - { - EXPREGS[0]=0xFD; - M165PPUFD(); - } else if((A&0x1FF0)==0x1FE0) - { - EXPREGS[0]=0xFE; - M165PPUFE(); - } -} - -static void M165Power(void) -{ - EXPREGS[0]=0xFD; - GenMMC3Power(); -} - -void Mapper165_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 128, 8, info->battery); - cwrap=M165CWM; - PPU_hook=M165PPU; - info->Power=M165Power; - CHRRAMSize = 4096; - CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); - AddExState(EXPREGS, 4, 0, "EXPR"); -} - -// ---------------------------- Mapper 191 ------------------------------ - -static void M191CW(uint32 A, uint8 V) -{ - setchr1r((V&0x80)>>3,A,V); -} - -void Mapper191_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 8, info->battery); - cwrap=M191CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 192 ------------------------------- - -static void M192CW(uint32 A, uint8 V) -{ - if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese), - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper192_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M192CW; - CHRRAMSize=4096; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 194 ------------------------------- - -static void M194CW(uint32 A, uint8 V) -{ - if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -void Mapper194_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M194CW; - CHRRAMSize=2048; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); -} - -// ---------------------------- Mapper 195 ------------------------------- -static uint8 *wramtw; -static uint16 wramsize; - -static void M195CW(uint32 A, uint8 V) -{ - if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C) - setchr1r(0x10,A,V); - else - setchr1r(0,A,V); -} - -static void M195Power(void) -{ - GenMMC3Power(); - setprg4r(0x10,0x5000,0); - SetWriteHandler(0x5000,0x5fff,CartBW); - SetReadHandler(0x5000,0x5fff,CartBR); -} - -static void M195Close(void) -{ - if(wramtw) - FCEU_gfree(wramtw); - wramtw=NULL; -} - -void Mapper195_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M195CW; - info->Power=M195Power; - info->Close=M195Close; - CHRRAMSize=4096; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); - wramsize=4096; - wramtw=(uint8*)FCEU_gmalloc(wramsize); - SetupCartPRGMapping(0x10, wramtw, wramsize, 1); - AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); - 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) -{ - if(A==0x0000) - setchr4(0x0000,V>>1); - else if(A==0x1000) - setchr2(0x1000,V); - else if(A==0x1400) - setchr2(0x1800,V); -} - -void Mapper197_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 512, 8, 0); - cwrap=M197CW; -} - -// ---------------------------- Mapper 198 ------------------------------- - -static void M198PW(uint32 A, uint8 V) -{ - if(V>=0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes - setprg8(A,V&0x4F); - else - setprg8(A,V); -} - -void Mapper198_Init(CartInfo *info) -{ - GenMMC3_Init(info, 1024, 256, 8, info->battery); - pwrap=M198PW; - info->Power=M195Power; - info->Close=M195Close; - wramsize=4096; - wramtw=(uint8*)FCEU_gmalloc(wramsize); - SetupCartPRGMapping(0x10, wramtw, wramsize, 1); - AddExState(wramtw, wramsize, 0, "WRAMTW"); -} - -// ---------------------------- Mapper 205 ------------------------------ - -static void M205PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&2) - setprg8(A,(V&0x0f)|((EXPREGS[0]&3)<<4)); - else - setprg8(A,(V&0x1f)|((EXPREGS[0]&3)<<4)); -} - -static void M205CW(uint32 A, uint8 V) -{ - setchr1(A,V|((EXPREGS[0]&3)<<7)); -} - -static DECLFW(M205Write) -{ - if((A&0x6800)==0x6800) EXPREGS[0]= V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M205Reset(void) -{ - EXPREGS[0]=0; - MMC3RegReset(); -} - -static void M205Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x4020,0x7FFF,M205Write); -} - -void Mapper205_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - pwrap=M205PW; - cwrap=M205CW; - info->Power=M205Power; - info->Reset=M205Reset; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 245 ------------------------------ - -static void M245CW(uint32 A, uint8 V) -{ - if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart - setchr1(A,V&7); - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); -} - -static void M245PW(uint32 A, uint8 V) -{ - setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5)); -} - -static void M245Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); -} - -void Mapper245_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M245CW; - pwrap=M245PW; - info->Power=M245Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 249 ------------------------------ - -static void M249PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x2) - { - if(V<0x20) - V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10); - else - { - V-=0x20; - V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); - } - } - setprg8(A,V); -} - -static void M249CW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x2) - V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); - setchr1(A,V); -} - -static DECLFW(M249Write) -{ - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); -} - -static void M249Power(void) -{ - EXPREGS[0]=0; - GenMMC3Power(); - SetWriteHandler(0x5000,0x5000,M249Write); -} - -void Mapper249_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=M249CW; - pwrap=M249PW; - info->Power=M249Power; - AddExState(EXPREGS, 1, 0, "EXPR"); -} - -// ---------------------------- Mapper 250 ------------------------------ - -static DECLFW(M250Write) -{ - MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); -} - -static DECLFW(M250IRQWrite) -{ - MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); -} - -static void M250_Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xBFFF,M250Write); - SetWriteHandler(0xC000,0xFFFF,M250IRQWrite); -} - -void Mapper250_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - info->Power=M250_Power; -} - -// ---------------------------- Mapper 254 ------------------------------ - -static DECLFR(MR254WRAM) -{ - if(EXPREGS[0]) - return WRAM[A-0x6000]; - else - return WRAM[A-0x6000]^EXPREGS[1]; -} - -static DECLFW(M254Write) -{ - switch (A) { - case 0x8000: EXPREGS[0]=0xff; - break; - case 0xA001: EXPREGS[1]=V; - } - MMC3_CMDWrite(A,V); -} - -static void M254_Power(void) -{ - GenMMC3Power(); - SetWriteHandler(0x8000,0xBFFF,M254Write); - SetReadHandler(0x6000,0x7FFF,MR254WRAM); -} - -void Mapper254_Init(CartInfo *info) -{ - GenMMC3_Init(info, 128, 128, 8, info->battery); - info->Power=M254_Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} - -// ---------------------------- 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); -} - -void TFROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); -} - -void TGROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 0, 0, 0); -} - -void TKROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); -} - -void TLROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 0, 0); -} - -void TSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); -} - -void TLSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, 0); - cwrap=TKSWRAP; - mwrap=GENNOMWRAP; - PPU_hook=TKSPPU; - AddExState(&PPUCHRBus, 1, 0, "PPUC"); -} - -void TKSROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 256, 8, info->battery); - cwrap=TKSWRAP; - mwrap=GENNOMWRAP; - PPU_hook=TKSPPU; - AddExState(&PPUCHRBus, 1, 0, "PPUC"); -} - -void TQROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 64, 0, 0); - cwrap=TQWRAP; - CHRRAMSize=8192; - CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); - SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); -} - -void HKROM_Init(CartInfo *info) -{ - GenMMC3_Init(info, 512, 512, 1, info->battery); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 1998 BERO + * Copyright (C) 2003 Xodnizel + * Mapper 12 code Copyright (C) 2003 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 + */ + +/* Code for emulating iNES mappers 4,12,44,45,47,49,52,74,114,115,116,118, + 119,165,205,245,249,250,254 +*/ + +#include "mapinc.h" +#include "mmc3.h" + +uint8 MMC3_cmd; +uint8 *WRAM; +uint8 *CHRRAM; +uint32 CHRRAMSize; +uint8 DRegBuf[8]; +uint8 EXPREGS[8]; /* For bootleg games, mostly. */ +uint8 A000B,A001B; +int mmc3opts=0; + +#undef IRQCount +#undef IRQLatch +#undef IRQa +uint8 IRQCount,IRQLatch,IRQa; +uint8 IRQReload; + +static SFORMAT MMC3_StateRegs[]= +{ + {DRegBuf, 8, "REGS"}, + {&MMC3_cmd, 1, "CMD"}, + {&A000B, 1, "A000"}, + {&A001B, 1, "A001"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static int wrams; +static int isRevB=1; + +void (*pwrap)(uint32 A, uint8 V); +void (*cwrap)(uint32 A, uint8 V); +void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); + +// ---------------------------------------------------------------------- +// ------------------------- Generic MM3 Code --------------------------- +// ---------------------------------------------------------------------- + +void FixMMC3PRG(int V) +{ + if(V&0x40) + { + pwrap(0xC000,DRegBuf[6]); + pwrap(0x8000,~1); + } + else + { + pwrap(0x8000,DRegBuf[6]); + pwrap(0xC000,~1); + } + pwrap(0xA000,DRegBuf[7]); + pwrap(0xE000,~0); +} + +void FixMMC3CHR(int V) +{ + int cbase=(V&0x80)<<5; + + cwrap((cbase^0x000),DRegBuf[0]&(~1)); + cwrap((cbase^0x400),DRegBuf[0]|1); + cwrap((cbase^0x800),DRegBuf[1]&(~1)); + cwrap((cbase^0xC00),DRegBuf[1]|1); + + cwrap(cbase^0x1000,DRegBuf[2]); + cwrap(cbase^0x1400,DRegBuf[3]); + cwrap(cbase^0x1800,DRegBuf[4]); + cwrap(cbase^0x1c00,DRegBuf[5]); + + if(mwrap) mwrap(A000B); +} + +void MMC3RegReset(void) +{ + IRQCount=IRQLatch=IRQa=MMC3_cmd=0; + + DRegBuf[0]=0; + DRegBuf[1]=2; + DRegBuf[2]=4; + DRegBuf[3]=5; + DRegBuf[4]=6; + DRegBuf[5]=7; + DRegBuf[6]=0; + DRegBuf[7]=1; + + FixMMC3PRG(0); + FixMMC3CHR(0); +} + +DECLFW(MMC3_CMDWrite) +{ +// FCEU_printf("bs %04x %02x\n",A,V); + switch(A&0xE001) + { + case 0x8000: + if((V&0x40) != (MMC3_cmd&0x40)) + FixMMC3PRG(V); + if((V&0x80) != (MMC3_cmd&0x80)) + FixMMC3CHR(V); + MMC3_cmd = V; + break; + case 0x8001: + { + int cbase=(MMC3_cmd&0x80)<<5; + DRegBuf[MMC3_cmd&0x7]=V; + switch(MMC3_cmd&0x07) + { + case 0: cwrap((cbase^0x000),V&(~1)); + cwrap((cbase^0x400),V|1); + break; + case 1: cwrap((cbase^0x800),V&(~1)); + cwrap((cbase^0xC00),V|1); + break; + case 2: cwrap(cbase^0x1000,V); + break; + case 3: cwrap(cbase^0x1400,V); + break; + case 4: cwrap(cbase^0x1800,V); + break; + case 5: cwrap(cbase^0x1C00,V); + break; + case 6: + if(MMC3_cmd&0x40) + pwrap(0xC000,V); + else + pwrap(0x8000,V); + break; + case 7: + pwrap(0xA000,V); + break; + } + } + break; + case 0xA000: + if(mwrap) mwrap(V); + break; + case 0xA001: + A001B=V; + break; + } +} + +DECLFW(MMC3_IRQWrite) +{ +// FCEU_printf("%04x:%04x\n",A,V); + switch(A&0xE001) + { + case 0xC000:IRQLatch=V;break; + case 0xC001:IRQReload=1;break; + case 0xE000:X6502_IRQEnd(FCEU_IQEXT);IRQa=0;break; + case 0xE001:IRQa=1;break; + } +} + +static void ClockMMC3Counter(void) +{ + int count = IRQCount; + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if((count|isRevB) && !IRQCount) + { + if(IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void MMC3_hb(void) +{ + ClockMMC3Counter(); +} + +static void MMC3_hb_KickMasterHack(void) +{ + if(scanline==238) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +static void MMC3_hb_PALStarWarsHack(void) +{ + if(scanline==240) ClockMMC3Counter(); + ClockMMC3Counter(); +} + +void GenMMC3Restore(int version) +{ + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void GENCWRAP(uint32 A, uint8 V) +{ + setchr1(A,V); // Business Wars NEEDS THIS for 8K CHR-RAM +} + +static void GENPWRAP(uint32 A, uint8 V) +{ + setprg8(A,V&0x7F); // [NJ102] Mo Dao Jie (C) has 1024Mb MMC3 BOARD, maybe something other will be broken +} + +static void GENMWRAP(uint8 V) +{ + A000B=V; + setmirror((V&1)^1); +} + +static void GENNOMWRAP(uint8 V) +{ + A000B=V; +} + +static DECLFW(MBWRAMMMC6) +{ + WRAM[A&0x3ff]=V; +} + +static DECLFR(MAWRAMMMC6) +{ + return(WRAM[A&0x3ff]); +} + +void GenMMC3Power(void) +{ + if(UNIFchrrama) setchr8(0); + + SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); + SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); + A001B=A000B=0; + setmirror(1); + if(mmc3opts&1) + { + if(wrams==1024) + { + FCEU_CheatAddRAM(1,0x7000,WRAM); + SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6); + SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6); + } + else + { + FCEU_CheatAddRAM((wrams&0x1fff)>>10,0x6000,WRAM); + SetWriteHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBW); + SetReadHandler(0x6000,0x6000 + ((wrams - 1) & 0x1fff),CartBR); + setprg8r(0x10,0x6000,0); + } + if(!(mmc3opts&2)) + FCEU_dwmemset(WRAM,0,wrams); + } + MMC3RegReset(); + if(CHRRAM) + FCEU_dwmemset(CHRRAM,0,CHRRAMSize); +} + +static void GenMMC3Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + if(WRAM) + FCEU_gfree(WRAM); + CHRRAM=WRAM=NULL; +} + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) +{ + pwrap=GENPWRAP; + cwrap=GENCWRAP; + mwrap=GENMWRAP; + + wrams=wram<<10; + + PRGmask8[0]&=(prg>>13)-1; + CHRmask1[0]&=(chr>>10)-1; + CHRmask2[0]&=(chr>>11)-1; + + if(wram) + { + mmc3opts|=1; + WRAM=(uint8*)FCEU_gmalloc(wrams); + SetupCartPRGMapping(0x10,WRAM,wrams,1); + AddExState(WRAM, wrams, 0, "MRAM"); + } + + if(battery) + { + mmc3opts|=2; + info->SaveGame[0]=WRAM; + info->SaveGameLen[0]=wrams; + } + + AddExState(MMC3_StateRegs, ~0, 0, 0); + + info->Power=GenMMC3Power; + info->Reset=MMC3RegReset; + info->Close=GenMMC3Close; + + if(info->CRC32 == 0x5104833e) // Kick Master + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0x5a6860f1 || info->CRC32 == 0xae280e20) // Shougi Meikan '92/'93 + GameHBIRQHook = MMC3_hb_KickMasterHack; + else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. + GameHBIRQHook = MMC3_hb_PALStarWarsHack; + else + GameHBIRQHook=MMC3_hb; + GameStateRestore=GenMMC3Restore; +} + +// ---------------------------------------------------------------------- +// -------------------------- MMC3 Based Code --------------------------- +// ---------------------------------------------------------------------- + +// ---------------------------- Mapper 4 -------------------------------- + +static int hackm4=0;/* For Karnov, maybe others. BLAH. Stupid iNES format.*/ + +static void M4Power(void) +{ + GenMMC3Power(); + A000B=(hackm4^1)&1; + setmirror(hackm4); +} + +void Mapper4_Init(CartInfo *info) +{ + int ws=8; + + if((info->CRC32==0x93991433 || info->CRC32==0xaf65aa84)) + { + FCEU_printf("Low-G-Man can not work normally in the iNES format.\nThis game has been recognized by its CRC32 value, and the appropriate changes will be made so it will run.\nIf you wish to hack this game, you should use the UNIF format for your hack.\n\n"); + ws=0; + } + GenMMC3_Init(info,512,256,ws,info->battery); + info->Power=M4Power; + hackm4=info->mirror; +} + +// ---------------------------- Mapper 12 ------------------------------- + +static void M12CW(uint32 A, uint8 V) +{ + setchr1(A,(EXPREGS[(A&0x1000)>>12]<<8)+V); +} + +static DECLFW(M12Write) +{ + EXPREGS[0]=V&0x01; + EXPREGS[1]=(V&0x10)>>4; +} + +static void M12Power(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetWriteHandler(0x4100,0x5FFF,M12Write); +} + +void Mapper12_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M12CW; + info->Power=M12Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 37 ------------------------------- + +static void M37PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]!=2) + V&=0x7; + else + V&=0xF; + V|=EXPREGS[0]<<3; + setprg8(A,V); +} + +static void M37CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<6; + setchr1(A,NV); +} + +static DECLFW(M37Write) +{ + EXPREGS[0]=(V&6)>>1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M37Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M37Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M37Write); +} + +void Mapper37_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + pwrap=M37PW; + cwrap=M37CW; + info->Power=M37Power; + info->Reset=M37Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 44 ------------------------------- + +static void M44PW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]>=6) NV&=0x1F; + else NV&=0x0F; + NV|=EXPREGS[0]<<4; + setprg8(A,NV); +} + +static void M44CW(uint32 A, uint8 V) +{ + uint32 NV=V; + if(EXPREGS[0]<6) NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M44Write) +{ + if(A&1) + { + EXPREGS[0]=V&7; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + MMC3_CMDWrite(A,V); +} + +static void M44Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0xA000,0xBFFF,M44Write); +} + +void Mapper44_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M44CW; + pwrap=M44PW; + info->Power=M44Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 45 ------------------------------- + +static void M45CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) + { + uint32 NV=V; + if(EXPREGS[2]&8) + NV&=(1<<((EXPREGS[2]&7)+1))-1; + 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); + } +} + +static void M45PW(uint32 A, uint8 V) +{ + V&=(EXPREGS[3]&0x3F)^0x3F; + V|=EXPREGS[1]; + setprg8(A,V); +} + +static DECLFW(M45Write) +{ + if(EXPREGS[3]&0x40) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[EXPREGS[4]]=V; + EXPREGS[4]=(EXPREGS[4]+1)&3; +// if(!EXPREGS[4]) +// { +// FCEU_printf("CHROR %02x, PRGOR %02x, CHRAND %02x, PRGAND %02x\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3]); +// FCEU_printf("CHR0 %03x, CHR1 %03x, PRG0 %03x, PRG1 %03x\n", +// (0x00&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), +// (0xFF&((1<<((EXPREGS[2]&7)+1))-1))|(EXPREGS[0]|((EXPREGS[2]&0xF0)<<4)), +// (0x00&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1]), +// (0xFF&((EXPREGS[3]&0x3F)^0x3F))|(EXPREGS[1])); +// } + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(M45Read) +{ + uint32 addr = 1<<(EXPREGS[5]+4); + if(A&(addr|(addr-1))) + return X.DB | 1; + else + return X.DB; +} + +static void M45Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; + EXPREGS[5]++; + EXPREGS[5] &= 7; + MMC3RegReset(); +} + +static void M45Power(void) +{ + setchr8(0); + GenMMC3Power(); + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=EXPREGS[5]=0; + SetWriteHandler(0x5000,0x7FFF,M45Write); + SetReadHandler(0x5000,0x5FFF,M45Read); +} + +void Mapper45_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M45CW; + pwrap=M45PW; + info->Reset=M45Reset; + info->Power=M45Power; + AddExState(EXPREGS, 5, 0, "EXPR"); +} + +// ---------------------------- Mapper 47 ------------------------------- + +static void M47PW(uint32 A, uint8 V) +{ + V&=0xF; + V|=EXPREGS[0]<<4; + setprg8(A,V); +} + +static void M47CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=EXPREGS[0]<<7; + setchr1(A,NV); +} + +static DECLFW(M47Write) +{ + EXPREGS[0]=V&1; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M47Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M47Write); +// SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper47_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + pwrap=M47PW; + cwrap=M47CW; + info->Power=M47Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 49 ------------------------------- + +static void M49PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&1) + { + V&=0xF; + V|=(EXPREGS[0]&0xC0)>>2; + setprg8(A,V); + } + else + setprg32(0x8000,(EXPREGS[0]>>4)&3); +} + +static void M49CW(uint32 A, uint8 V) +{ + uint32 NV=V; + NV&=0x7F; + NV|=(EXPREGS[0]&0xC0)<<1; + setchr1(A,NV); +} + +static DECLFW(M49Write) +{ + if(A001B&0x80) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } +} + +static void M49Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +static void M49Power(void) +{ + M49Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M49Write); + SetReadHandler(0x6000,0x7FFF,0); +} + +void Mapper49_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); + cwrap=M49CW; + pwrap=M49PW; + info->Reset=M49Reset; + info->Power=M49Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 52 ------------------------------- +static void M52PW(uint32 A, uint8 V) +{ + uint32 mask = 0x1F^((EXPREGS[0]&8)<<1); + uint32 bank = ((EXPREGS[0]&6)|((EXPREGS[0]>>3)&EXPREGS[0]&1))<<4; + setprg8(A, bank|(V & mask)); +} + +static void M52CW(uint32 A, uint8 V) +{ + uint32 mask = 0xFF^((EXPREGS[0]&0x40)<<1); +// uint32 bank = (((EXPREGS[0]>>3)&4)|((EXPREGS[0]>>1)&2)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; + uint32 bank = (((EXPREGS[0]>>4)&2)|(EXPREGS[0]&4)|((EXPREGS[0]>>6)&(EXPREGS[0]>>4)&1))<<7; // actually 256K CHR banks index bits is inverted! + setchr1(A, bank|(V & mask)); +} + +static DECLFW(M52Write) +{ + if(EXPREGS[1]) + { + WRAM[A-0x6000]=V; + return; + } + EXPREGS[1]=V&0x80; + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M52Reset(void) +{ + EXPREGS[0]=EXPREGS[1]=0; + MMC3RegReset(); +} + +static void M52Power(void) +{ + M52Reset(); + GenMMC3Power(); + SetWriteHandler(0x6000,0x7FFF,M52Write); +} + +void Mapper52_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap=M52CW; + pwrap=M52PW; + info->Reset=M52Reset; + info->Power=M52Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 74 ------------------------------- + +static void M74CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes, Ji Jia Zhan Shi (As).nes + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper74_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M74CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 114 ------------------------------ + +static uint8 cmdin; +uint8 m114_perm[8] = {0, 3, 1, 5, 6, 7, 2, 4}; + +static void M114PWRAP(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { +// FCEU_printf("8000-C000:%02X\n",EXPREGS[0]&0xF); + setprg16(0x8000,EXPREGS[0]&0xF); + setprg16(0xC000,EXPREGS[0]&0xF); + } + else { +// FCEU_printf("%04X:%02X\n",A,V&0x3F); + setprg8(A,V&0x3F); + } +} + +static DECLFW(M114Write) +{ + switch(A&0xE001) + { + case 0x8001: MMC3_CMDWrite(0xA000,V); break; + case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); cmdin=1; break; + case 0xC000: if(!cmdin) break; MMC3_CMDWrite(0x8001,V); cmdin=0; break; + case 0xA001: IRQLatch=V; break; + case 0xC001: IRQReload=1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; + case 0xE001: IRQa=1; break; + } +} + +static DECLFW(M114ExWrite) +{ + if(A<=0x7FFF) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static void M114Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xFFFF,M114Write); + SetWriteHandler(0x5000,0x7FFF,M114ExWrite); +} + +static void M114Reset(void) +{ + EXPREGS[0]=0; + MMC3RegReset(); +} + +void Mapper114_Init(CartInfo *info) +{ + isRevB=0; + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M114PWRAP; + info->Power=M114Power; + info->Reset=M114Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); + AddExState(&cmdin, 1, 0, "CMDI"); +} + +// ---------------------------- Mapper 115 KN-658 board ------------------------------ + +static void M115PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + setprg32(0x8000,(EXPREGS[0]&7)>>1); + else + setprg8(A,V); +} + +static void M115CW(uint32 A, uint8 V) +{ + setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); +} + +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) + EXPREGS[1]=V; + FixMMC3PRG(MMC3_cmd); +} + +static DECLFR(M115Read) +{ + return EXPREGS[2]; +} + +static void M115Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x4100,0x7FFF,M115Write); + SetReadHandler(0x5000,0x5FFF,M115Read); +} + +void Mapper115_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 0, 0); + cwrap=M115CW; + pwrap=M115PW; + info->Power=M115Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- Mapper 118 ------------------------------ + +static uint8 PPUCHRBus; +static uint8 TKSMIR[8]; + +static void FP_FASTAPASS(1) TKSPPU(uint32 A) +{ + A&=0x1FFF; + A>>=10; + PPUCHRBus=A; + setmirror(MI_0+TKSMIR[A]); +} + +static void TKSWRAP(uint32 A, uint8 V) +{ + TKSMIR[A>>10]=V>>7; + setchr1(A,V&0x7F); + if(PPUCHRBus==(A>>10)) + setmirror(MI_0+(V>>7)); +} + +// ---------------------------- Mapper 119 ------------------------------ + +static void TQWRAP(uint32 A, uint8 V) +{ + setchr1r((V&0x40)>>2,A,V&0x3F); +} + +void Mapper119_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + 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) +{ + if(V==0) + setchr4r(0x10,A,0); + else + setchr4(A,V>>2); +} + +static void M165PPUFD(void) +{ + if(EXPREGS[0]==0xFD) + { + M165CW(0x0000,DRegBuf[0]); + M165CW(0x1000,DRegBuf[2]); + } +} + +static void M165PPUFE(void) +{ + if(EXPREGS[0]==0xFE) + { + M165CW(0x0000,DRegBuf[1]); + M165CW(0x1000,DRegBuf[4]); + } +} + +static void M165CWM(uint32 A, uint8 V) +{ + if(((MMC3_cmd&0x7)==0)||((MMC3_cmd&0x7)==2)) + M165PPUFD(); + if(((MMC3_cmd&0x7)==1)||((MMC3_cmd&0x7)==4)) + M165PPUFE(); +} + +static void FP_FASTAPASS(1) M165PPU(uint32 A) +{ + if((A&0x1FF0)==0x1FD0) + { + EXPREGS[0]=0xFD; + M165PPUFD(); + } else if((A&0x1FF0)==0x1FE0) + { + EXPREGS[0]=0xFE; + M165PPUFE(); + } +} + +static void M165Power(void) +{ + EXPREGS[0]=0xFD; + GenMMC3Power(); +} + +void Mapper165_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 128, 8, info->battery); + cwrap=M165CWM; + PPU_hook=M165PPU; + info->Power=M165Power; + CHRRAMSize = 4096; + CHRRAM = (uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(EXPREGS, 4, 0, "EXPR"); +} + +// ---------------------------- Mapper 191 ------------------------------ + +static void M191CW(uint32 A, uint8 V) +{ + setchr1r((V&0x80)>>3,A,V); +} + +void Mapper191_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, info->battery); + cwrap=M191CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 192 ------------------------------- + +static void M192CW(uint32 A, uint8 V) +{ + if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese), + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper192_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M192CW; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 194 ------------------------------- + +static void M194CW(uint32 A, uint8 V) +{ + if(V<=1) //Dai-2-Ji - Super Robot Taisen (As).nes + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +void Mapper194_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M194CW; + CHRRAMSize=2048; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); +} + +// ---------------------------- Mapper 195 ------------------------------- +static uint8 *wramtw; +static uint16 wramsize; + +static void M195CW(uint32 A, uint8 V) +{ + if(V<=3) // Crystalis (c).nes, Captain Tsubasa Vol 2 - Super Striker (C) + setchr1r(0x10,A,V); + else + setchr1r(0,A,V); +} + +static void M195Power(void) +{ + GenMMC3Power(); + setprg4r(0x10,0x5000,0); + SetWriteHandler(0x5000,0x5fff,CartBW); + SetReadHandler(0x5000,0x5fff,CartBR); +} + +static void M195Close(void) +{ + if(wramtw) + FCEU_gfree(wramtw); + wramtw=NULL; +} + +void Mapper195_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M195CW; + info->Power=M195Power; + info->Close=M195Close; + CHRRAMSize=4096; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(wramtw, wramsize, 0, "TRAM"); +} + +// ---------------------------- Mapper 196 ------------------------------- +// MMC3 board with optional command address line connection, allows to +// make three-four different wirings to IRQ address lines and separately to +// CMD address line, Mali Boss additionally check if wiring are correct for +// game + +static void M196PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes + setprg32(0x8000,EXPREGS[1]); + else + setprg8(A,V); +} + +static DECLFW(Mapper196Write) +{ + if(A >= 0xC000) { + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1); + MMC3_IRQWrite(A,V); + } + else { + A=(A&0xFFFE)|((A>>2)&1)|((A>>3)&1)|((A>>1)&1); + MMC3_CMDWrite(A,V); + } +} + +static DECLFW(Mapper196WriteLo) +{ + EXPREGS[0]=1; + EXPREGS[1]=(V&0xf)|(V>>4); + FixMMC3PRG(MMC3_cmd); +} + +static void Mapper196Power(void) +{ + GenMMC3Power(); + EXPREGS[0] = EXPREGS[1] = 0; + SetWriteHandler(0x6000,0x6FFF,Mapper196WriteLo); + SetWriteHandler(0x8000,0xFFFF,Mapper196Write); +} + +void Mapper196_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 0, 0); + pwrap=M196PW; + info->Power=Mapper196Power; +} + +// ---------------------------- Mapper 197 ------------------------------- + +static void M197CW(uint32 A, uint8 V) +{ + if(A==0x0000) + setchr4(0x0000,V>>1); + else if(A==0x1000) + setchr2(0x1000,V); + else if(A==0x1400) + setchr2(0x1800,V); +} + +void Mapper197_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 512, 8, 0); + cwrap=M197CW; +} + +// ---------------------------- Mapper 198 ------------------------------- + +static void M198PW(uint32 A, uint8 V) +{ + if(V>=0x50) // Tenchi o Kurau II - Shokatsu Koumei Den (J) (C).nes + setprg8(A,V&0x4F); + else + setprg8(A,V); +} + +void Mapper198_Init(CartInfo *info) +{ + GenMMC3_Init(info, 1024, 256, 8, info->battery); + pwrap=M198PW; + info->Power=M195Power; + info->Close=M195Close; + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(wramtw, wramsize, 0, "TRAM"); +} + +// ---------------------------- Mapper 205 ------------------------------ +// GN-45 BOARD + +static void M205PW(uint32 A, uint8 V) +{ +// GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü 1F + àïïàðàòíûé ïåðåêëþ÷àòåëü íà øèíå àäðåñà + setprg8(A,(V&0x0f)|EXPREGS[0]); +} + +static void M205CW(uint32 A, uint8 V) +{ +// GN-30A - íà÷àëüíàÿ ìàñêà äîëæíà áûòü FF + setchr1(A,(V&0x7F)|(EXPREGS[0]<<3)); +} + +static DECLFW(M205Write) +{ + if(EXPREGS[2] == 0) { + EXPREGS[0] = A & 0x30; + EXPREGS[2] = A & 0x80; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + } + else + CartBW(A,V); +} + +static void M205Reset(void) +{ + EXPREGS[0]=EXPREGS[2]=0; + MMC3RegReset(); +} + +static void M205Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x6000,0x6fff,M205Write); +} + +void Mapper205_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 8, 0); + pwrap=M205PW; + cwrap=M205CW; + info->Power=M205Power; + info->Reset=M205Reset; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 245 ------------------------------ + +static void M245CW(uint32 A, uint8 V) +{ + if(!UNIFchrrama) // Yong Zhe Dou E Long - Dragon Quest VI (As).nes NEEDS THIS for RAM cart + setchr1(A,V&7); + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); +} + +static void M245PW(uint32 A, uint8 V) +{ + setprg8(A,(V&0x3F)|((EXPREGS[0]&2)<<5)); +} + +static void M245Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); +} + +void Mapper245_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M245CW; + pwrap=M245PW; + info->Power=M245Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 249 ------------------------------ + +static void M249PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + { + if(V<0x20) + V=(V&1)|((V>>3)&2)|((V>>1)&4)|((V<<2)&8)|((V<<2)&0x10); + else + { + V-=0x20; + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + } + } + setprg8(A,V); +} + +static void M249CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x2) + V=(V&3)|((V>>1)&4)|((V>>4)&8)|((V>>2)&0x10)|((V<<3)&0x20)|((V<<2)&0xC0); + setchr1(A,V); +} + +static DECLFW(M249Write) +{ + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void M249Power(void) +{ + EXPREGS[0]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x5000,M249Write); +} + +void Mapper249_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M249CW; + pwrap=M249PW; + info->Power=M249Power; + AddExState(EXPREGS, 1, 0, "EXPR"); +} + +// ---------------------------- Mapper 250 ------------------------------ + +static DECLFW(M250Write) +{ + MMC3_CMDWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static DECLFW(M250IRQWrite) +{ + MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF); +} + +static void M250_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M250Write); + SetWriteHandler(0xC000,0xFFFF,M250IRQWrite); +} + +void Mapper250_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + info->Power=M250_Power; +} + +// ---------------------------- Mapper 254 ------------------------------ + +static DECLFR(MR254WRAM) +{ + if(EXPREGS[0]) + return WRAM[A-0x6000]; + else + return WRAM[A-0x6000]^EXPREGS[1]; +} + +static DECLFW(M254Write) +{ + switch (A) { + case 0x8000: EXPREGS[0]=0xff; + break; + case 0xA001: EXPREGS[1]=V; + } + MMC3_CMDWrite(A,V); +} + +static void M254_Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xBFFF,M254Write); + SetReadHandler(0x6000,0x7FFF,MR254WRAM); +} + +void Mapper254_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 128, 8, info->battery); + info->Power=M254_Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} + +// ---------------------------- 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); +} + +void TFROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); +} + +void TGROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 0, 0, 0); +} + +void TKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); +} + +void TLROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 0, 0); +} + +void TSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); +} + +void TLSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TKSROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=TKSWRAP; + mwrap=GENNOMWRAP; + PPU_hook=TKSPPU; + AddExState(&PPUCHRBus, 1, 0, "PPUC"); +} + +void TQROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 64, 0, 0); + cwrap=TQWRAP; + CHRRAMSize=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); + SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); +} + +void HKROM_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 512, 1, info->battery); +} diff --git a/boards/mmc3.h b/boards/mmc3.h index a5e03cd..df3f0b9 100644 --- a/boards/mmc3.h +++ b/boards/mmc3.h @@ -1,4 +1,5 @@ extern uint8 MMC3_cmd; +extern int mmc3opts; extern uint8 A000B; extern uint8 A001B; extern uint8 EXPREGS[8]; diff --git a/boards/mmc5.c b/boards/mmc5.c index 1916df9..daf973f 100644 --- a/boards/mmc5.c +++ b/boards/mmc5.c @@ -1,908 +1,837 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 uint16 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)]; -} - -static void mmc5_PPUWrite(uint32 A, uint8 V) { - uint32 tmp = A; - extern uint8 PALRAM[0x20]; - - if(tmp>=0x3F00) - { - // hmmm.... - if(!(tmp&0xf)) - PALRAM[0x00]=PALRAM[0x04]=PALRAM[0x08]=PALRAM[0x0C]=V&0x3F; - else if(tmp&3) PALRAM[(tmp&0x1f)]=V&0x3f; - } - else if(tmp<0x2000) - { - if(PPUCHRRAM&(1<<(tmp>>10))) - VPage[tmp>>10][tmp]=V; - } - else - { - if(PPUNTARAM&(1<<((tmp&0xF00)>>10))) - vnapage[((tmp&0xF00)>>10)][tmp&0x3FF]=V; - } -} - -uint8 FASTCALL mmc5_PPURead(uint32 A) { - if(A<0x2000) - { - if(ppuphase == PPUPHASE_BG) - return *MMC5BGVRAMADR(A); - else return MMC5SPRVPage[(A)>>10][(A)]; - } - else - { - return vnapage[(A>>10)&0x3][A&0x3FF]; - } -} - - - -// ELROM seems to have 8KB of RAM -// ETROM seems to have 16KB of WRAM -// 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 04-aug-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-dec-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. - //adelikat 20-dec-08 - reverting back to return 64, sounds like it was changed back to 8 simply on principle. FCEUX is all encompassing, and that include - //rom-hacking. We want it to be the best emulator for such purposes. So unless return 64 harms compatibility with anything else, I see now reason not to have it - //mbg 29-mar-09 - I should note that mmc5 is in principle capable of 64KB, even if no real carts ever supported it. - //This does not in principle break any games which share this mapper, and it should be OK for homebrew. - //if there are games which need 8KB instead of 64KB default then lets add them to the list - 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 | ((MMC50x5130&0x3)<<8); //if we had a test case for this then we could test this, but it hasnt been verified - //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, 16, "CHRA"}, - { CHRBanksB, 8, "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"); - AddExState(&MMC50x5130, 1, 0, "5130"); - - 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); -} +/* 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]; +static uint8 ABMode; /* 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; + + +// 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); + } + return(8); +} + +static void BuildWRAMSizeTable(void) +{ + int x; + for(x=0;x<8;x++) + { + switch(MMC5WRAMsize) + { + case 0: MMC5WRAMIndex[x]=255; break; + case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; + case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; + case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; + } + } +} + +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 FASTAPASS(2) 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) + { + ABMode = 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; + #ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) + #endif + 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() +{ + int32 V; + 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}; + int32 V,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"}, + { &ABMode, 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(); +} + +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/boards/n-c22m.c b/boards/n-c22m.c deleted file mode 100644 index 49f965f..0000000 --- a/boards/n-c22m.c +++ /dev/null @@ -1,103 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * Mortal Kombat 2 YOKO */ - -#include "mapinc.h" -#include "mmc3.h" - -static uint8 reg[8]; - -static SFORMAT StateRegs[]= -{ - {reg, 8, "REGS"}, - {0} -}; - -static void Sync(void) -{ -// FCEU_printf("(%02x, %02x)\n",reg[3],reg[4]); - setprg8(0x8000,reg[0]); - setprg8(0xA000,reg[1]); - setprg8(0xC000,reg[2]); - setprg8(0xE000,~0); -// setchr2(0x0000,reg[3]); -// setchr2(0x0800,reg[4]); -// setchr2(0x1000,reg[5]); -// setchr2(0x1800,reg[6]); - setchr2(0x0000,reg[3]); - setchr2(0x0800,reg[4]); - setchr2(0x1000,reg[5]); - setchr2(0x1800,reg[6]); -} - -static DECLFW(MCN22MWrite) -{ -//FCEU_printf("bs %04x %02x\n",A,V); - switch(A) - { - case 0x8c00: - case 0x8c01: - case 0x8c02: reg[A&3]=V; break; - case 0x8d10: reg[3]=V; break; - case 0x8d11: reg[4]=V; break; - case 0x8d16: reg[5]=V; break; - case 0x8d17: reg[6]=V; break; - } - Sync(); -} - -static void MCN22MPower(void) -{ - reg[0]=reg[1]=reg[2]=0; - Sync(); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,MCN22MWrite); -} -/* -static void MCN22MIRQHook(void) -{ - int count = IRQCount; - if(!count || IRQReload) - { - IRQCount = IRQLatch; - IRQReload = 0; - } - else - IRQCount--; - if(!IRQCount) - { - if(IRQa) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} -*/ -static void StateRestore(int version) -{ - Sync(); -} - -void UNLCN22M_Init(CartInfo *info) -{ - info->Power=MCN22MPower; -// GameHBIRQHook=MCN22MIRQHook; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} diff --git a/boards/n106.c b/boards/n106.c index 880a296..0b14ccf 100644 --- a/boards/n106.c +++ b/boards/n106.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -70,7 +70,7 @@ static void SyncPRG(void) setprg8(0xe000,0x3F); } -static void NamcoIRQHook(int a) +static void FP_FASTAPASS(1) NamcoIRQHook(int a) { if(IRQa) { @@ -88,7 +88,9 @@ static DECLFR(Namco_Read4800) { uint8 ret=IRAM[dopol&0x7f]; /* Maybe I should call NamcoSoundHack() here? */ + #ifdef FCEUDEF_DEBUGGER if(!fceuindbg) + #endif if(dopol&0x80) dopol=(dopol&0x80)|((dopol+1)&0x7f); return ret; @@ -104,7 +106,7 @@ static DECLFR(Namco_Read5800) return(IRQCount>>8); } -static void DoNTARAMROM(int w, uint8 V) +static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V) { NTAPage[w]=V; if(V>=0xE0) @@ -123,7 +125,7 @@ static void FixNTAR(void) DoNTARAMROM(x,NTAPage[x]); } -static void DoCHRRAMROM(int x, uint8 V) +static void FASTAPASS(2) DoCHRRAMROM(int x, uint8 V) { CHR[x]=V; if(!is210 && !((gorfus>>((x>>2)+6))&1) && (V>=0xE0)) @@ -274,8 +276,7 @@ static INLINE uint32 FetchDuff(uint32 P, uint32 envelope) static void DoNamcoSoundHQ(void) { - uint32 V; //mbg merge 7/17/06 made uint32 - int32 P; + int32 P,V; int32 cyclesuck=(((IRAM[0x7F]>>4)&7)+1)*15; for(P=7;P>=(7-((IRAM[0x7F]>>4)&7));P--) @@ -364,10 +365,10 @@ static void DoNamcoSound(int32 *Wave, int Count) static void Mapper19_StateRestore(int version) { - int x; SyncPRG(); FixNTAR(); FixCRR(); + int x; for(x=0x40;x<0x80;x++) FixCache(x,IRAM[x]); } diff --git a/boards/n625092.c b/boards/n625092.c index 30d8298..34c4c9c 100644 --- a/boards/n625092.c +++ b/boards/n625092.c @@ -15,8 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * * 700in1 and 400in1 carts + * */ @@ -39,26 +41,36 @@ static void Sync(void) { if(cmd&0x100) { - setprg16(0x8000,((cmd&0xe0)>>2)|bank); - setprg16(0xC000,((cmd&0xe0)>>2)|7); + setprg16(0x8000,((cmd&0xfc)>>2)|bank); + setprg16(0xC000,((cmd&0xfc)>>2)|7); } else { - setprg16(0x8000,((cmd&0xe0)>>2)|(bank&6)); - setprg16(0xC000,((cmd&0xe0)>>2)|((bank&6)|1)); + setprg16(0x8000,((cmd&0xfc)>>2)|(bank&6)); + setprg16(0xC000,((cmd&0xfc)>>2)|((bank&6)|1)); } } else { - setprg16(0x8000,((cmd&0xe0)>>2)|bank); - setprg16(0xC000,((cmd&0xe0)>>2)|bank); + setprg16(0x8000,((cmd&0xfc)>>2)|bank); + setprg16(0xC000,((cmd&0xfc)>>2)|bank); } } +static uint16 ass = 0; + static DECLFW(UNLN625092WriteCommand) { cmd=A; - Sync(); + if(A==0x80F8) + { + setprg16(0x8000,ass); + setprg16(0xC000,ass); + } + else + { + Sync(); + } } static DECLFW(UNLN625092WriteBank) @@ -81,6 +93,8 @@ static void UNLN625092Reset(void) { cmd=0; bank=0; + ass++; + FCEU_printf("%04x\n",ass); } static void StateRestore(int version) diff --git a/boards/novel.c b/boards/novel.c index 1918abf..26e70ec 100644 --- a/boards/novel.c +++ b/boards/novel.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/onebus.c b/boards/onebus.c index a09b488..3f2b994 100644 --- a/boards/onebus.c +++ b/boards/onebus.c @@ -15,142 +15,163 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VR02/VT03 Console and OneBus System * - * OneBus system * Street Dance (Dance pad) (Unl) * 101-in-1 Arcade Action II - * DreamGEAR 75-in-1 + * DreamGEAR 75-in-1, etc. + * */ #include "mapinc.h" -static uint8 isDance; -static uint8 regs[16],regc[6]; -static uint8 IRQCount,IRQLatch,IRQa, IRQReload, pcm_enable = 0, pcm_irq = 0; +// General Purpose Registers +static uint8 cpu410x[16], ppu201x[16], apu40xx[64]; + +// IRQ Registers +static uint8 IRQCount, IRQa, IRQReload; +#define IRQLatch cpu410x[0x1] + +// MMC3 Registers +static uint8 inv_hack = 0; // some OneBus Systems have swapped PRG reg commans in MMC3 inplementation, + // trying to autodetect unusual behavior, due not to add a new mapper. +#define mmc3cmd cpu410x[0x5] +#define mirror cpu410x[0x6] + +// APU Registers +static uint8 pcm_enable = 0, pcm_irq = 0; static int16 pcm_addr, pcm_size, pcm_latch, pcm_clock = 0xF6; -static writefunc old4011write, old4012write, old4013write, old4015write; -static readfunc old4015read; + +static writefunc defapuwrite[64]; +static readfunc defapuread[64]; static SFORMAT StateRegs[]= { - {regc, 6, "REGC"}, - {regs, 16, "REGS"}, + {cpu410x, 16, "REGC"}, + {ppu201x, 16, "REGS"}, + {apu40xx, 64, "REGA"}, {&IRQReload, 1, "IRQR"}, {&IRQCount, 1, "IRQC"}, - {&IRQLatch, 1, "IRQL"}, {&IRQa, 1, "IRQA"}, {&pcm_enable, 1, "PCME"}, - {&pcm_irq, 1, "PCMIRQ"}, - {&pcm_addr, 2, "PCMADDR"}, - {&pcm_size, 2, "PCMSIZE"}, - {&pcm_latch, 2, "PCMLATCH"}, - {&pcm_clock, 2, "PCMCLOCK"}, + {&pcm_irq, 1, "PCMI"}, + {&pcm_addr, 2, "PCMA"}, + {&pcm_size, 2, "PCMS"}, + {&pcm_latch, 2, "PCML"}, + {&pcm_clock, 2, "PCMC"}, {0} }; -static void Sync(void) +static void PSync(void) { - uint16 cswap = (regs[0xf] & 0x80) << 5; - uint16 pswap = (regs[0xd]&1)?((regs[0xf] & 0x40) << 8):0; - uint16 pbase = (regs[0]&0xf0)<<4; - uint16 cbase = (((regs[0]&0x0f)<<8)|(regs[0xc]<<1)|((regs[0xd]&0xf8)>>3))<<3; - uint16 pmask = 0x3f>>(regs[0xb]&0xf); - - setchr1(cswap^0x0000,cbase|(regc[0]&(~1))); - setchr1(cswap^0x0400,cbase|(regc[0]|1)); - setchr1(cswap^0x0800,cbase|(regc[1]&(-1))); - setchr1(cswap^0x0c00,cbase|(regc[1]|1)); - setchr1(cswap^0x1000,cbase|(regc[2])); - setchr1(cswap^0x1400,cbase|(regc[3])); - setchr1(cswap^0x1800,cbase|(regc[4])); - setchr1(cswap^0x1c00,cbase|(regc[5])); - - if(regs[0xd]&2) - { - setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); - setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); - setprg8(pswap^0xC000, pbase|(regs[0x9]&pmask)|(regs[0xa]&(~pmask))); - setprg8( 0xE000, pbase|regs[0xa]); - } - else - { - setprg8(pswap^0x8000, pbase|(regs[0x7]&pmask)|(regs[0xa]&(~pmask))); - setprg8( 0xA000, pbase|(regs[0x8]&pmask)|(regs[0xa]&(~pmask))); - setprg8(pswap^0xC000, pbase|((~1)&pmask)|(regs[0xa]&(~pmask))); - setprg8( 0xE000, pbase|((~0)&pmask)|(regs[0xa]&(~pmask))); - } + uint8 bankmode = cpu410x[0xb] & 7; + uint8 mask = (bankmode == 0x7)?(0xff):(0x3f >> bankmode); + uint32 block = ((cpu410x[0x0] & 0xf0) << 4) + (cpu410x[0xa] & (~mask)); + uint32 pswap = (mmc3cmd & 0x40) << 8; + +// uint8 bank0 = (cpu410x[0xb] & 0x40)?(~1):(cpu410x[0x7]); +// uint8 bank1 = cpu410x[0x8]; +// uint8 bank2 = (cpu410x[0xb] & 0x40)?(cpu410x[0x9]):(~1); +// uint8 bank3 = ~0; + uint8 bank0 = cpu410x[0x7^inv_hack]; + uint8 bank1 = cpu410x[0x8^inv_hack]; + uint8 bank2 = (cpu410x[0xb] & 0x40)?(cpu410x[0x9]):(~1); + uint8 bank3 = ~0; - setmirror(regs[0xe]); +// FCEU_printf(" PRG: %04x [%02x]",0x8000^pswap,block | (bank0 & mask)); + setprg8(0x8000^pswap, block | (bank0 & mask)); +// FCEU_printf(" %04x [%02x]",0xa000^pswap,block | (bank1 & mask)); + setprg8(0xa000, block | (bank1 & mask)); +// FCEU_printf(" %04x [%02x]",0xc000^pswap,block | (bank2 & mask)); + setprg8(0xc000^pswap, block | (bank2 & mask)); +// FCEU_printf(" %04x [%02x]\n",0xe000^pswap,block | (bank3 & mask)); + setprg8(0xe000, block | (bank3 & mask)); } -static DECLFW(UNLOneBusWrite20XX) +static void CSync(void) { -// FCEU_printf("PPU %04x:%04x\n",A,V); - if(A == 0x201A) - regs[0xd] = V; - else if(A == 0x2018) - regs[0xc] = V; - Sync(); + static const uint8 midx[8] = {0, 1, 2, 0, 3, 4, 5, 0 }; + uint8 mask = 0xff >> midx[ppu201x[0xa] & 7]; + uint32 block = ((cpu410x[0x0] & 0x0f) << 11) + ((ppu201x[0x8] & 0x70) << 4) + (ppu201x[0xa] & (~mask)); + uint32 cswap = (mmc3cmd & 0x80) << 5; + + uint8 bank0 = ppu201x[0x6]&(~1); + uint8 bank1 = ppu201x[0x6]|1; + uint8 bank2 = ppu201x[0x7]&(~1); + uint8 bank3 = ppu201x[0x7]|1; + uint8 bank4 = ppu201x[0x2]; + uint8 bank5 = ppu201x[0x3]; + uint8 bank6 = ppu201x[0x4]; + uint8 bank7 = ppu201x[0x5]; + + setchr1(0x0000^cswap, block | (bank0 & mask)); + setchr1(0x0400^cswap, block | (bank1 & mask)); + setchr1(0x0800^cswap, block | (bank2 & mask)); + setchr1(0x0c00^cswap, block | (bank3 & mask)); + setchr1(0x1000^cswap, block | (bank4 & mask)); + setchr1(0x1400^cswap, block | (bank5 & mask)); + setchr1(0x1800^cswap, block | (bank6 & mask)); + setchr1(0x1c00^cswap, block | (bank7 & mask)); + + setmirror((mirror & 1) ^ 1); } -static DECLFW(UNLOneBusWriteExp) +static void Sync(void) { -// FCEU_printf("EXP %04x:%04x\n",A,V); -// switch(A & 0x0F) -// { -// case 2: pcm_latch = pcm_clock; FCEU_printf("write %04x:%04x\n",A,V); break; -// case 3: pcm_irqa = 0; X6502_IRQEnd(FCEU_IQEXT); pcm_irq = 0; FCEU_printf("write %04x:%04x\n",A,V); break; -// case 4: pcm_irqa = 1; FCEU_printf("write %04x:%04x\n",A,V); break; -// default: - regs[A & 0x0F] = V; - Sync(); -// } + PSync(); + CSync(); } -static DECLFW(UNLOneBusWriteDebug) +static DECLFW(UNLOneBusWriteCPU410X) { -// FCEU_printf("write %04x:%04x\n",A,V); +// FCEU_printf("CPU %04x:%04x\n",A,V); + switch(A & 0xf) + { + case 0x1: IRQLatch = V & 0xfe; break; + case 0x2: IRQReload = 1; break; + case 0x3: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0x4: IRQa = 1; break; + default: + cpu410x[A & 0xf] = V; + Sync(); + } } -static DECLFW(UNLOneBusWriteMMC) +static DECLFW(UNLOneBusWritePPU201X) +{ +// FCEU_printf("PPU %04x:%04x\n",A,V); + ppu201x[A & 0x0f] = V; + Sync(); +} + +static DECLFW(UNLOneBusWriteMMC3) { // FCEU_printf("MMC %04x:%04x\n",A,V); - switch(A&0xE001) + switch(A&0xe001) { - case 0x8000: regs[0xf] = V; Sync(); break; + case 0x8000: mmc3cmd = (mmc3cmd & 0x38) | (V & 0xc7); Sync(); break; case 0x8001: { - uint8 mask = 0xff, mmc3cmd = regs[0xf]&7; - switch(mmc3cmd) + switch(mmc3cmd & 7) { - case 0: - case 1: - case 2: - case 3: - case 4: - case 5: - if(regs[0xd]&4) - mask = 0x0f; - else - mask >>= ((regs[0xb]&0xf0)>>4); - regc[mmc3cmd] = V&mask; - break; - case 6: - case 7: - mask = (mask&0x3f)>>(regs[0xb]&0xf); - regs[mmc3cmd+1] = (regs[mmc3cmd+1]&(~mask))|(V&mask); - break; + case 0: ppu201x[0x6] = V; CSync(); break; + case 1: ppu201x[0x7] = V; CSync(); break; + case 2: ppu201x[0x2] = V; CSync(); break; + case 3: ppu201x[0x3] = V; CSync(); break; + case 4: ppu201x[0x4] = V; CSync(); break; + case 5: ppu201x[0x5] = V; CSync(); break; + case 6: cpu410x[0x7] = V; PSync(); break; + case 7: cpu410x[0x8] = V; PSync(); break; } - - Sync(); break; } - case 0xA000: regs[0xe] = (V & 1)^1; Sync(); break; - case 0xC000: IRQLatch = V&0xfe; break; - case 0xC001: IRQReload = 1; break; - case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; - case 0xE001: IRQa = 1; break; + case 0xa000: mirror = V; CSync(); break; + case 0xc000: IRQLatch = V & 0xfe; break; + case 0xc001: IRQReload = 1; break; + case 0xe000: X6502_IRQEnd(FCEU_IQEXT); IRQa = 0; break; + case 0xe001: IRQa = 1; break; } } @@ -171,44 +192,51 @@ static void UNLOneBusIRQHook(void) } } -static DECLFW(UNLOneBusWriteAPU2) -{ -// FCEU_printf("APU2 %04x:%04x\n",A,V); - CartBW(A&0xffdf,V); -} - -static DECLFW(UNLOneBusWrite4012) -{ -// FCEU_printf("write %04x:%04x\n",A,V); - pcm_addr = V << 6; - old4012write(A,V); -} - -static DECLFW(UNLOneBusWrite4013) +static DECLFW(UNLOneBusWriteAPU40XX) { -// FCEU_printf("write %04x:%04x\n",A,V); - pcm_size = (V << 4) + 1; - old4013write(A,V); -} - -static DECLFW(UNLOneBusWrite4015) -{ -// FCEU_printf("write %04x:%04x\n",A,V); - pcm_enable = V&0x10; - if(pcm_irq) +// FCEU_printf("APU %04x:%04x\n",A,V); + apu40xx[A & 0x3f] = V; + switch(A & 0x3f) { - X6502_IRQEnd(FCEU_IQEXT); - pcm_irq = 0; + case 0x12: + if(apu40xx[0x30] & 0x10) + { + pcm_addr = V << 6; + } + case 0x13: + if(apu40xx[0x30] & 0x10) + { + pcm_size = (V << 4) + 1; + } + case 0x15: + if(apu40xx[0x30] & 0x10) + { + pcm_enable = V&0x10; + if(pcm_irq) + { + X6502_IRQEnd(FCEU_IQEXT); + pcm_irq = 0; + } + if(pcm_enable) + pcm_latch = pcm_clock; + V &= 0xef; + } } - if(pcm_enable) - pcm_latch = pcm_clock; - old4015write(A,V&0xEF); + defapuwrite[A & 0x3f](A, V); } -static DECLFR(UNLOneBusRead4015) +static DECLFR(UNLOneBusReadAPU40XX) { - uint8 result = (old4015read(A) & 0x7F)|pcm_irq; + uint8 result = defapuread[A & 0x3f](A); // FCEU_printf("read %04x, %02x\n",A,result); + switch(A & 0x3f) + { + case 0x15: + if(apu40xx[0x30] & 0x10) + { + result = (result & 0x7f) | pcm_irq; + } + } return result; } @@ -230,7 +258,7 @@ static void UNLOneBusCpuHook(int a) else { uint8 raw_pcm = ARead[pcm_addr](pcm_addr) >> 1; - old4011write(0x4011,raw_pcm); + defapuwrite[0x11](0x4011,raw_pcm); pcm_addr++; pcm_addr&=0x7FFF; } @@ -240,43 +268,39 @@ static void UNLOneBusCpuHook(int a) static void UNLOneBusPower(void) { - IRQCount=IRQLatch=IRQa==0; - regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; - regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; - regs[0x09]=0x3E; - regs[0x0A]=0x3F; + uint32 i; + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); - SetupCartCHRMapping(0,PRGptr[0],4096 * 1024,0); + SetupCartCHRMapping(0, PRGptr[0], PRGsize[0], 0); - if(isDance) // quick workaround, TODO: figure out how it works together + for(i=0; i<64; i++) { - old4015read=GetReadHandler(0x4015); - SetReadHandler(0x4015,0x4015,UNLOneBusRead4015); - old4011write=GetWriteHandler(0x4011); - old4012write=GetWriteHandler(0x4012); - SetWriteHandler(0x4012,0x4012,UNLOneBusWrite4012); - old4013write=GetWriteHandler(0x4013); - SetWriteHandler(0x4013,0x4013,UNLOneBusWrite4013); - old4015write=GetWriteHandler(0x4015); - SetWriteHandler(0x4015,0x4015,UNLOneBusWrite4015); + defapuread[i] = GetReadHandler(0x4000|i); + defapuwrite[i] = GetWriteHandler(0x4000|i); } + SetReadHandler(0x4000,0x403f,UNLOneBusReadAPU40XX); + SetWriteHandler(0x4000,0x403f,UNLOneBusWriteAPU40XX); SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x2009,0x2fff,UNLOneBusWrite20XX); -// SetWriteHandler(0x4020,0xffff,UNLOneBusWriteDebug); -// SetWriteHandler(0x4020,0x4040,UNLOneBusWriteAPU2); - SetWriteHandler(0x4100,0x410f,UNLOneBusWriteExp); - SetWriteHandler(0x8000,0xefff,UNLOneBusWriteMMC); + SetWriteHandler(0x2010,0x201f,UNLOneBusWritePPU201X); + SetWriteHandler(0x4100,0x410f,UNLOneBusWriteCPU410X); + SetWriteHandler(0x8000,0xffff,UNLOneBusWriteMMC3); + Sync(); } static void UNLOneBusReset(void) { - IRQCount=IRQLatch=IRQa=0; - regs[0]=regs[1]=regs[1]=regs[2]=regs[3]=regs[4]=regs[5]=regs[6]=0; - regs[7]=regs[8]=regs[11]=regs[12]=regs[13]=regs[14]=regs[15]=0; - regs[0x09]=0x3E; - regs[0x0A]=0x3F; + IRQReload = IRQCount = IRQa = 0; + + memset(cpu410x, 0x00, sizeof(cpu410x)); + memset(ppu201x, 0x00, sizeof(ppu201x)); + memset(apu40xx, 0x00, sizeof(apu40xx)); + Sync(); } @@ -287,20 +311,13 @@ static void StateRestore(int version) void UNLOneBus_Init(CartInfo *info) { - isDance = 0; info->Power=UNLOneBusPower; info->Reset=UNLOneBusReset; - GameHBIRQHook=UNLOneBusIRQHook; -// MapIRQHook=UNLOneBusCpuHook; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} -void UNLDANCE_Init(CartInfo *info) -{ - isDance = 1; - info->Power=UNLOneBusPower; - info->Reset=UNLOneBusReset; + if(((*(uint32*)&(info->MD5)) == 0x305fcdc3) || // PowerJoy Supermax Carts + ((*(uint32*)&(info->MD5)) == 0x6abfce8e) ) + inv_hack = 0xf; + GameHBIRQHook=UNLOneBusIRQHook; MapIRQHook=UNLOneBusCpuHook; GameStateRestore=StateRestore; diff --git a/boards/pec-586.c b/boards/pec-586.c new file mode 100644 index 0000000..a810197 --- /dev/null +++ b/boards/pec-586.c @@ -0,0 +1,124 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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[7]; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static SFORMAT StateRegs[]= +{ + {reg, 2, "REG"}, + {0} +}; + +static uint8 bs_tbl[128] = { + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, 0x03, 0x13, 0x23, 0x33, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, + 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, 0x45, 0x67, + 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x02, 0x12, 0x22, 0x32, 0x00, 0x10, 0x20, 0x30, + 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, 0x47, 0x67, +}; + +static uint8 br_tbl[16] = { + 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, +}; + +static void Sync(void) +{ +// setchr4(0x0000,(reg[0]&0x80) >> 7); +// setchr4(0x1000,(reg[0]&0x80) >> 7); + setchr8(0); + setprg8r(0x10,0x6000,0); + setprg16(0x8000,bs_tbl[reg[0]&0x7f]>>4); + setprg16(0xc000,bs_tbl[reg[0]&0x7f]&0xf); + setmirror(MI_V); +} + +static DECLFW(UNLPEC586Write) +{ + reg[(A&0x700)>>8]=V; + FCEU_printf("bs %04x %02x\n",A,V); + Sync(); +} + +static DECLFR(UNLPEC586Read) +{ + FCEU_printf("read %04x\n",A); + return (X.DB & 0xD8) | br_tbl[reg[4]>>4]; +} + +static void UNLPEC586Power(void) +{ + reg[0]=0x0E; + Sync(); + setchr8(0); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0x5fff,UNLPEC586Write); + SetReadHandler(0x5000,0x5fff,UNLPEC586Read); +} + +static void UNLPEC586IRQ(void) +{ +// if(reg[0]&0x80) + { + if(scanline==128) { + setchr4(0x0000,1); + setchr4(0x1000,0); + } + else { + setchr4(0x0000,0); + setchr4(0x1000,1); + } + } +} + +static void UNLPEC586Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLPEC586Init(CartInfo *info) +{ + info->Power=UNLPEC586Power; + info->Close=UNLPEC586Close; + GameHBIRQHook=UNLPEC586IRQ; + 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/boards/sachen.c b/boards/sachen.c index ab57f3c..a2b5741 100644 --- a/boards/sachen.c +++ b/boards/sachen.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/sc-127.c b/boards/sc-127.c index a2c29ff..a36894b 100644 --- a/boards/sc-127.c +++ b/boards/sc-127.c @@ -15,9 +15,9 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * Wario Land II (Kirby hack) + * Wario Land II (Kirby hack) VRC4 */ #include "mapinc.h" diff --git a/boards/sheroes.c b/boards/sheroes.c index 8bea1f7..3b4a1b3 100644 --- a/boards/sheroes.c +++ b/boards/sheroes.c @@ -15,14 +15,13 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #include "mmc3.h" -static uint8 *CHRRAM; // there is no more extern CHRRAM in mmc3.h - // I need chrram here and local static == local +static uint8 *CHRRAM; static uint8 tekker; static void MSHCW(uint32 A, uint8 V) diff --git a/boards/sl1632.c b/boards/sl1632.c index 18895fb..14ead33 100644 --- a/boards/sl1632.c +++ b/boards/sl1632.c @@ -15,17 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * SL1632 2-in-1 protected board, similar to SL12 + * Samurai Spirits Rex (Full) + * */ #include "mapinc.h" #include "mmc3.h" -// brk is a system call in *nix, and is an illegal variable name - soules static uint8 chrcmd[8], prg0, prg1, bbrk, mirr, swap; static SFORMAT StateRegs[]= { - {chrcmd, 8, "CHRCMD"}, + {chrcmd, 8, "CHRC"}, {&prg0, 1, "PRG0"}, {&prg1, 1, "PRG1"}, {&bbrk, 1, "BRK"}, @@ -110,7 +113,6 @@ static void StateRestore(int version) static void UNLSL1632Power(void) { GenMMC3Power(); - SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x4100,0xFFFF,UNLSL1632CMDWrite); } diff --git a/boards/smb2j.c b/boards/smb2j.c index 15655a7..286f3dc 100644 --- a/boards/smb2j.c +++ b/boards/smb2j.c @@ -15,9 +15,14 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversions + * * Super Mario Bros 2 J alt version * as well as "Voleyball" FDS conversion, bank layot is similar but no bankswitching and CHR ROM present + * + * mapper seems wrong researched by me ;( it should be mapper 43 modification */ #include "mapinc.h" @@ -71,7 +76,7 @@ static void UNLSMB2JReset(void) Sync(); } -static void UNLSMB2JIRQHook(int a) +static void FP_FASTAPASS(1) UNLSMB2JIRQHook(int a) { if(IRQa) { diff --git a/boards/subor.c b/boards/subor.c index 9f0386d..8edf323 100644 --- a/boards/subor.c +++ b/boards/subor.c @@ -1,3 +1,23 @@ +/* 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 + */ + #include "mapinc.h" static uint8 mode; diff --git a/boards/super24.c b/boards/super24.c index 4ccc766..745e723 100644 --- a/boards/super24.c +++ b/boards/super24.c @@ -15,14 +15,13 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" #include "mmc3.h" -static uint8 *CHRRAM = NULL; // there is no more extern CHRRAM in mmc3.h - // I need chrram here and local static == local +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/boards/supervision.c b/boards/supervision.c index e405c75..61a373d 100644 --- a/boards/supervision.c +++ b/boards/supervision.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/boards/t-227-1.c b/boards/t-227-1.c index 25d64af..9cadfd4 100644 --- a/boards/t-227-1.c +++ b/boards/t-227-1.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ // T-227-1, 820632, MMC3 based, multimenu, 60000in1 (0010) dip switches diff --git a/boards/t-262.c b/boards/t-262.c index 15e94ea..1b3e857 100644 --- a/boards/t-262.c +++ b/boards/t-262.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -25,8 +25,8 @@ static uint8 datareg; static uint8 busy; static SFORMAT StateRegs[]= { - {&addrreg, 2, "ADDRREG"}, - {&datareg, 1, "DATAREG"}, + {&addrreg, 2, "AREG"}, + {&datareg, 1, "DREG"}, {&busy, 1, "BUSY"}, {0} }; diff --git a/boards/tengen.c b/boards/tengen.c index 3881622..510f909 100644 --- a/boards/tengen.c +++ b/boards/tengen.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -36,10 +36,10 @@ static SFORMAT Rambo_StateRegs[]={ {0} }; -static void (*setchr1wrap)(unsigned int A, unsigned int V); +static void FP_FASTAPASS(2) (*setchr1wrap)(unsigned int A, unsigned int V); //static int nomirror; -static void RAMBO1_IRQHook(int a) +static void FP_FASTAPASS(1) RAMBO1_IRQHook(int a) { static int smallcount; if(!IRQmode) return; @@ -158,7 +158,7 @@ static void RAMBO1_init(void) AddExState(Rambo_StateRegs, ~0, 0, 0); } -static void CHRWrap(unsigned int A, unsigned int V) +static void FP_FASTAPASS(2) CHRWrap(unsigned int A, unsigned int V) { setchr1(A,V); } @@ -173,7 +173,7 @@ void Mapper64_init(void) static int MirCache[8]; static unsigned int PPUCHRBus; -static void MirWrap(unsigned int A, unsigned int V) +static void FP_FASTAPASS(2) MirWrap(unsigned int A, unsigned int V) { MirCache[A>>10]=(V>>7)&1; if(PPUCHRBus==(A>>10)) @@ -181,7 +181,7 @@ static void MirWrap(unsigned int A, unsigned int V) setchr1(A,V); } -static void MirrorFear(uint32 A) +static void FP_FASTAPASS(1) MirrorFear(uint32 A) { A&=0x1FFF; A>>=10; @@ -197,4 +197,3 @@ void Mapper158_init(void) RAMBO1_init(); } */ - diff --git a/boards/tf-1201.c b/boards/tf-1201.c index d40cb5f..3c7dbd9 100644 --- a/boards/tf-1201.c +++ b/boards/tf-1201.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * Lethal Weapon (VRC4 mapper) */ @@ -35,8 +35,8 @@ static SFORMAT StateRegs[]= {&mirr, 1, "MIRR"}, {&swap, 1, "SWAP"}, {chr, 8, "CHR"}, - {&IRQCount, 1, "IRQCOUNT"}, - {&IRQPre, 1, "IRQPRE"}, + {&IRQCount, 1, "IRQC"}, + {&IRQPre, 1, "IRQP"}, {&IRQa, 1, "IRQA"}, {0} }; diff --git a/boards/transformer.c b/boards/transformer.c new file mode 100644 index 0000000..0ac2a1c --- /dev/null +++ b/boards/transformer.c @@ -0,0 +1,103 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 *WRAM=NULL; +static uint32 WRAMSIZE; + +char *GetKeyboard(void); + +static char *TransformerKeys, oldkeys[256]; +static int TransformerCycleCount, TransformerChar = 0; + +static void FP_FASTAPASS(1) TransformerIRQHook(int a) +{ + TransformerCycleCount+=a; + if(TransformerCycleCount >= 1000) + { + uint32 i; + TransformerCycleCount -= 1000; + TransformerKeys = GetKeyboard(); + + for(i=0; i<256; i++) { + if(oldkeys[i] != TransformerKeys[i]) { + if(oldkeys[i] == 0) + TransformerChar = i; + else + TransformerChar = i | 0x80; + X6502_IRQBegin(FCEU_IQEXT); + memcpy((void *)&oldkeys[0], (void *)TransformerKeys, 256); + break; + } + } + } +} + +static DECLFR(TransformerRead) +{ + uint8 ret = 0; + switch(A&3) { + case 0: ret = TransformerChar & 15; break; + case 1: ret = (TransformerChar >> 4); break; + case 2: break; + case 4: break; + } + X6502_IRQEnd(FCEU_IQEXT); + return ret; +} + +static void TransformerPower(void) +{ + setprg8r(0x10,0x6000,0); + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); + + SetReadHandler(0x5000,0x5004,TransformerRead); + SetReadHandler(0x6000,0x7FFF,CartBR); + SetWriteHandler(0x6000,0x7FFF,CartBW); + SetReadHandler(0x8000,0xFFFF,CartBR); + + MapIRQHook=TransformerIRQHook; +} + +static void TransformerClose(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +void Transformer_Init(CartInfo *info) +{ + info->Power=TransformerPower; + info->Close=TransformerClose; + + 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"); +} diff --git a/boards/vrc7.c b/boards/vrc7.c new file mode 100644 index 0000000..67936dd --- /dev/null +++ b/boards/vrc7.c @@ -0,0 +1,134 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2009 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 + * + * YOKO Mortal Kombat V Pro, VRC7 pirate clone + */ + +#include "mapinc.h" + +static uint8 prg[3], chr[8], mirr; +static uint8 IRQLatch, IRQa, IRQd; +static uint32 IRQCount, CycleCount; + +static SFORMAT StateRegs[]= +{ + {prg, 3, "PRG"}, + {chr, 8, "CHR"}, + {&mirr, 1, "MIRR"}, + {&IRQa, 1, "IRQA"}, + {&IRQd, 1, "IRQD"}, + {&IRQLatch, 1, "IRQC"}, + {&IRQCount, 4, "IRQC"}, + {&CycleCount, 4, "CYCC"}, + {0} +}; + +static void Sync(void) +{ + uint8 i; + setprg8(0x8000,prg[0]); + setprg8(0xa000,prg[1]); + setprg8(0xc000,prg[2]); + setprg8(0xe000,~0); + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); + 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 DECLFW(UNLVRC7Write) +{ + switch(A&0xF008) + { + case 0x8000: prg[0]=V; Sync(); break; + case 0x8008: prg[1]=V; Sync(); break; + case 0x9000: prg[2]=V; Sync(); break; + case 0xa000: chr[0]=V; Sync(); break; + case 0xa008: chr[1]=V; Sync(); break; + case 0xb000: chr[2]=V; Sync(); break; + case 0xb008: chr[3]=V; Sync(); break; + case 0xc000: chr[4]=V; Sync(); break; + case 0xc008: chr[5]=V; Sync(); break; + case 0xd000: chr[6]=V; Sync(); break; + case 0xd008: chr[7]=V; Sync(); break; + case 0xe000: mirr=V; Sync(); break; + case 0xe008: + IRQLatch=V; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf000: + IRQa=V&2; + IRQd=V&1; + if(V&2) + IRQCount=IRQLatch; + CycleCount=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xf008: + if(IRQd) + IRQa=1; + else + IRQa=0; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +} + +static void UNLVRC7Power(void) +{ + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLVRC7Write); +} + +static void UNLVRC7IRQHook(int a) +{ + if(IRQa) + { + CycleCount+=a*3; + while(CycleCount>=341) + { + CycleCount-=341; + IRQCount++; + if(IRQCount==248) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch; + } + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void UNLVRC7_Init(CartInfo *info) +{ + info->Power=UNLVRC7Power; + MapIRQHook=UNLVRC7IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/yoko.c b/boards/yoko.c new file mode 100644 index 0000000..a83e871 --- /dev/null +++ b/boards/yoko.c @@ -0,0 +1,269 @@ +/* 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 + * + * + * YOKO mapper, almost the same as 83, TODO: figure out difference + * Mapper 83 - 30-in-1 mapper, two modes for single game carts, one mode for + * multigame Dragon Ball Z Party + * + * Mortal Kombat 2 YOKO + * N-CXX(M), XX - ðàçìåðû PRG+CHR, 12 - 128+256, 22 - 256+256, 14 - 128+512 + * + */ + +#include "mapinc.h" + +static uint8 mode, bank, reg[11], low[4], dip, IRQa; +static int32 IRQCount; +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; + +static uint8 is2kbank, isnot2kbank; + +static SFORMAT StateRegs[]= +{ + {&mode, 1, "MODE"}, + {&bank, 1, "BANK"}, + {&IRQCount, 4, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {reg, 11, "REGS"}, + {low, 4, "LOWR"}, + {&is2kbank, 1, "IS2K"}, + {&isnot2kbank, 1, "NT2K"}, + {0} +}; + +static void UNLYOKOSync(void) +{ + setmirror((mode & 1)^1); + setchr2(0x0000,reg[3]); + setchr2(0x0800,reg[4]); + setchr2(0x1000,reg[5]); + setchr2(0x1800,reg[6]); + if(mode & 0x10) + { + uint32 base = (bank & 8) << 1; + setprg8(0x8000,(reg[0]&0x0f)|base); + setprg8(0xA000,(reg[1]&0x0f)|base); + setprg8(0xC000,(reg[2]&0x0f)|base); + setprg8(0xE000,0x0f|base); + } + else + { + if(mode & 8) + setprg32(0x8000,bank >> 1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,~0); + } + } +} + +static void M83Sync(void) +{ + switch(mode & 3) // check if it is truth + { + case 0: setmirror(MI_V); break; + case 1: setmirror(MI_H); break; + case 2: setmirror(MI_0); break; + case 3: setmirror(MI_1); break; + } + if(is2kbank&&!isnot2kbank) + { + setchr2(0x0000,reg[0]); + setchr2(0x0800,reg[1]); + setchr2(0x1000,reg[6]); + setchr2(0x1800,reg[7]); + } + else + { + int x; + for(x=0;x<8;x++) + setchr1(x<<10, reg[x] | ((bank&0x30)<<4)); + } + setprg8r(0x10,0x6000,0); + if(mode & 0x40) + { + setprg16(0x8000,(bank&0x3F)); // DBZ Party [p1] + setprg16(0xC000,(bank&0x30)|0xF); + } + else + { + setprg8(0x8000,reg[8]); + setprg8(0xA000,reg[9]); + setprg8(0xC000,reg[10]); + setprg8(0xE000,~0); + } +} + +static DECLFW(UNLYOKOWrite) +{ + switch(A & 0x8C17) + { + case 0x8000: bank=V; UNLYOKOSync(); break; + case 0x8400: mode=V; UNLYOKOSync(); break; + case 0x8800: IRQCount&=0xFF00; IRQCount|=V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8801: IRQa=mode&0x80; IRQCount&=0xFF; IRQCount|=V<<8; break; + case 0x8c00: reg[0]=V; UNLYOKOSync(); break; + case 0x8c01: reg[1]=V; UNLYOKOSync(); break; + case 0x8c02: reg[2]=V; UNLYOKOSync(); break; + case 0x8c10: reg[3]=V; UNLYOKOSync(); break; + case 0x8c11: reg[4]=V; UNLYOKOSync(); break; + case 0x8c16: reg[5]=V; UNLYOKOSync(); break; + case 0x8c17: reg[6]=V; UNLYOKOSync(); break; + } +} + +static DECLFW(M83Write) +{ + switch(A) + { + case 0x8000: is2kbank = 1; + case 0xB000: // Dragon Ball Z Party [p1] BMC + case 0xB0FF: // Dragon Ball Z Party [p1] BMC + case 0xB1FF: bank=V; mode |= 0x40; M83Sync(); break; // Dragon Ball Z Party [p1] BMC + case 0x8100: mode=V|(mode&0x40); M83Sync(); break; + case 0x8200: IRQCount&=0xFF00; IRQCount|=V; X6502_IRQEnd(FCEU_IQEXT); break; + case 0x8201: IRQa=mode&0x80; IRQCount&=0xFF; IRQCount|=V<<8; break; + case 0x8300: reg[8]=V; mode &= 0xBF; M83Sync(); break; + case 0x8301: reg[9]=V; mode &= 0xBF; M83Sync(); break; + case 0x8302: reg[10]=V; mode &= 0xBF; M83Sync(); break; + case 0x8310: reg[0]=V; M83Sync(); break; + case 0x8311: reg[1]=V; M83Sync(); break; + case 0x8312: reg[2]=V; isnot2kbank = 1; M83Sync(); break; + case 0x8313: reg[3]=V; isnot2kbank = 1; M83Sync(); break; + case 0x8314: reg[4]=V; isnot2kbank = 1; M83Sync(); break; + case 0x8315: reg[5]=V; isnot2kbank = 1; M83Sync(); break; + case 0x8316: reg[6]=V; M83Sync(); break; + case 0x8317: reg[7]=V; M83Sync(); break; + } +} + +static DECLFR(UNLYOKOReadDip) +{ + return (X.DB&0xFC)|dip; +} + +static DECLFR(UNLYOKOReadLow) +{ + return low[A & 3]; +} + +static DECLFW(UNLYOKOWriteLow) +{ + low[A & 3] = V; +} + +static void UNLYOKOPower(void) +{ + mode = bank = 0; + dip = 3; + UNLYOKOSync(); + SetReadHandler(0x5000,0x53FF,UNLYOKOReadDip); + SetReadHandler(0x5400,0x5FFF,UNLYOKOReadLow); + SetWriteHandler(0x5400,0x5FFF,UNLYOKOWriteLow); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLYOKOWrite); +} + +static void M83Power(void) +{ + is2kbank = 0; + isnot2kbank = 0; + mode = bank = 0; + dip = 0; + M83Sync(); + SetReadHandler(0x5000,0x5000,UNLYOKOReadDip); + SetReadHandler(0x5100,0x5103,UNLYOKOReadLow); + SetWriteHandler(0x5100,0x5103,UNLYOKOWriteLow); + SetReadHandler(0x6000,0x7fff,CartBR); + SetWriteHandler(0x6000,0x7fff,CartBW); // Pirate Dragon Ball Z Party [p1] used if for saves instead of seraial EEPROM + SetReadHandler(0x8000,0xffff,CartBR); + SetWriteHandler(0x8000,0xffff,M83Write); +} + +static void UNLYOKOReset(void) +{ + dip = (dip + 1) & 3; + mode = bank = 0; + UNLYOKOSync(); +} + +static void M83Reset(void) +{ + dip ^= 1; + M83Sync(); +} + +static void M83Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void FP_FASTAPASS(1) UNLYOKOIRQHook(int a) +{ + if(IRQa) + { + IRQCount-=a; + if(IRQCount<0) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0xFFFF; + } + } +} + +static void UNLYOKOStateRestore(int version) +{ + UNLYOKOSync(); +} + +static void M83StateRestore(int version) +{ + M83Sync(); +} + +void UNLYOKO_Init(CartInfo *info) +{ + info->Power=UNLYOKOPower; + info->Reset=UNLYOKOReset; + MapIRQHook=UNLYOKOIRQHook; + GameStateRestore=UNLYOKOStateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper83_Init(CartInfo *info) +{ + info->Power=M83Power; + info->Reset=M83Reset; + info->Close=M83Close; + MapIRQHook=UNLYOKOIRQHook; + GameStateRestore=M83StateRestore; + + 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/ines.c b/ines.c index 042dad2..a3a23f6 100644 --- a/ines.c +++ b/ines.c @@ -555,59 +555,136 @@ static BMAPPINGLocal bmap[] = { {"CNROM", 3, CNROM_Init}, {"MMC3", 4, Mapper4_Init}, {"MMC5", 5, Mapper5_Init}, +// {6, Mapper6_Init}, {"ANROM", 7, ANROM_Init}, + {"", 8, Mapper8_Init}, // Nogaems, it's worthless +// {9, Mapper9_Init}, +// {10, Mapper10_Init}, {"Color Dreams", 11, Mapper11_Init}, {"", 12, Mapper12_Init}, {"CPROM", 13, CPROM_Init}, +// {14, Mapper14_Init}, {"100-in1", 15, Mapper15_Init}, {"Bandai", 16, Mapper16_Init}, + {"", 17, Mapper17_Init}, + {"", 18, Mapper18_Init}, {"Namcot 106", 19, Mapper19_Init}, +// {20, Mapper20_Init}, +// {21, Mapper21_Init}, +// {22, Mapper22_Init}, {"Konami VRC2 type B", 23, Mapper23_Init}, +// {24, Mapper24_Init}, +// {25, Mapper25_Init}, +// {26, Mapper26_Init}, +// {27, Mapper27_Init}, +// {28, Mapper28_Init}, +// {29, Mapper29_Init}, +// {30, Mapper30_Init}, +// {31, Mapper31_Init}, +// {32, Mapper32_Init}, +// {33, Mapper33_Init}, + {"", 34, Mapper34_Init}, {"Wario Land 2", 35, UNLSC127_Init}, // Wario Land 2 {"TXC Policeman", 36, Mapper36_Init}, // TXC Policeman {"", 37, Mapper37_Init}, {"Bit Corp. Crime Busters", 38, Mapper38_Init}, // Bit Corp. Crime Busters +// {39, Mapper39_Init}, +// {40, Mapper40_Init}, +// {41, Mapper41_Init}, +// {42, Mapper42_Init}, {"", 43, Mapper43_Init}, {"", 44, Mapper44_Init}, {"", 45, Mapper45_Init}, +// {46, Mapper46_Init}, {"", 47, Mapper47_Init}, +// {48, Mapper48_Init}, {"", 49, Mapper49_Init}, +// {50, Mapper50_Init}, +// {51, Mapper51_Init}, {"", 52, Mapper52_Init}, +// {53, Mapper53_Init}, +// {54, Mapper54_Init}, +// {55, Mapper55_Init}, +// {56, Mapper56_Init}, {"", 57, Mapper57_Init}, {"", 58, BMCGK192_Init}, +// {59, Mapper59_Init}, {"", 60, BMCD1038_Init}, +// {61, Mapper61_Init}, +// {62, Mapper62_Init}, +// {63, Mapper63_Init}, +// {64, Mapper64_Init}, +// {65, Mapper65_Init}, {"MHROM", 66, MHROM_Init}, +// {67, Mapper67_Init}, {"Sunsoft Mapper #4", 68, Mapper68_Init}, +// {69, Mapper69_Init}, {"", 70, Mapper70_Init}, +// {71, Mapper71_Init}, +// {72, Mapper72_Init}, +// {73, Mapper73_Init}, {"", 74, Mapper74_Init}, +// {75, Mapper75_Init}, +// {76, Mapper76_Init}, +// {77, Mapper77_Init}, {"Irem 74HC161/32", 78, Mapper78_Init}, +// {79, Mapper79_Init}, +// {80, Mapper80_Init}, +// {81, Mapper81_Init}, + {"", 82, Mapper82_Init}, + {"", 83, Mapper83_Init}, +// {84, Mapper84_Init}, +// {85, Mapper85_Init}, + {"", 86, Mapper86_Init}, {"", 87, Mapper87_Init}, {"", 88, Mapper88_Init}, + {"", 89, Mapper89_Init}, {"", 90, Mapper90_Init}, + {"", 91, Mapper91_Init}, + {"", 92, Mapper92_Init}, {"Sunsoft UNROM", 93, SUNSOFT_UNROM_Init}, {"", 94, Mapper94_Init}, {"", 95, Mapper95_Init}, + {"", 96, Mapper96_Init}, + {"", 97, Mapper97_Init}, +// {98, Mapper98_Init}, + {"", 99, Mapper99_Init}, +// {100, Mapper100_Init}, {"", 101, Mapper101_Init}, +// {102, Mapper102_Init}, {"", 103, Mapper103_Init}, +// {104, Mapper104_Init}, {"", 105, Mapper105_Init}, {"", 106, Mapper106_Init}, {"", 107, Mapper107_Init}, {"", 108, Mapper108_Init}, +// {109, Mapper109_Init}, +// {110, Mapper110_Init}, +// {111, Mapper111_Init}, {"", 112, Mapper112_Init}, {"", 113, Mapper113_Init}, {"", 114, Mapper114_Init}, {"", 115, Mapper115_Init}, - {"", 116, Mapper116_Init}, -// {116, UNLSL1632_Init}, + {"UNLSL12", 116, UNLSL12_Init}, {"", 117, Mapper117_Init}, {"TSKROM", 118, TKSROM_Init}, {"", 119, Mapper119_Init}, {"", 120, Mapper120_Init}, {"", 121, Mapper121_Init}, +// {122, Mapper122_Init}, {"UNLH2288", 123, UNLH2288_Init}, +// {124, Mapper124_Init}, +// {125, Mapper125_Init}, +// {126, Mapper126_Init}, +// {127, Mapper127_Init}, +// {128, Mapper128_Init}, +// {129, Mapper129_Init}, +// {130, Mapper130_Init}, +// {131, Mapper131_Init}, {"UNL22211", 132, UNL22211_Init}, {"SA72008", 133, SA72008_Init}, {"", 134, Mapper134_Init}, +// {135, Mapper135_Init}, {"TCU02", 136, TCU02_Init}, {"S8259D", 137, S8259D_Init}, {"S8259B", 138, S8259B_Init}, @@ -623,25 +700,35 @@ static BMAPPINGLocal bmap[] = { {"SA0037", 148, SA0037_Init}, {"SA0036", 149, SA0036_Init}, {"S74LS374N", 150, S74LS374N_Init}, + {"", 151, Mapper151_Init}, {"", 152, Mapper152_Init}, {"", 153, Mapper153_Init}, {"", 154, Mapper154_Init}, {"", 155, Mapper155_Init}, {"", 156, Mapper156_Init}, - {"", 159, Mapper159_Init}, + {"", 157, Mapper157_Init}, +// {158, Mapper158_Init}, +// {159, Mapper159_Init}, {"SA009", 160, SA009_Init}, +// {161, Mapper161_Init}, + {"", 162, UNLFS304_Init}, {"", 163, Mapper163_Init}, {"", 164, Mapper164_Init}, {"", 165, Mapper165_Init}, -// {169, Mapper169_Init}, +// {166, Mapper166_Init}, +// {167, Mapper167_Init}, + {"", 168, Mapper168_Init}, +// {169, Mapper169_Init}, {"", 171, Mapper171_Init}, {"", 172, Mapper172_Init}, {"", 173, Mapper173_Init}, {"", 175, Mapper175_Init}, - {"BMCFK23C", 176, BMCFK23C_Init}, //zero 26-may-2012 - well, i have some WXN junk games that use 176 for instance 水浒神兽. i dont know what game uses this BMCFK23C as mapper 176. we'll have to make a note when we find it. - //{"BMCFK23C", 176, Mapper176_Init}, +// {174, Mapper174_Init}, + {"", 175, Mapper175_Init}, + {"BMCFK23C", 176, BMCFK23C_Init}, {"", 177, Mapper177_Init}, {"", 178, Mapper178_Init}, +// {179, Mapper179_Init}, {"", 180, Mapper180_Init}, {"", 181, Mapper181_Init}, // {"", 182, Mapper182_Init}, // identical to 114 @@ -652,8 +739,10 @@ static BMAPPINGLocal bmap[] = { {"", 187, Mapper187_Init}, {"", 188, Mapper188_Init}, {"", 189, Mapper189_Init}, +// {190, Mapper190_Init}, {"", 191, Mapper191_Init}, {"", 192, Mapper192_Init}, + {"", 193, Mapper193_Init}, {"", 194, Mapper194_Init}, {"", 195, Mapper195_Init}, {"", 196, Mapper196_Init}, @@ -661,38 +750,61 @@ static BMAPPINGLocal bmap[] = { {"", 198, Mapper198_Init}, {"", 199, Mapper199_Init}, {"", 200, Mapper200_Init}, +// {201, Mapper201_Init}, +// {202, Mapper202_Init}, +// {203, Mapper203_Init}, +// {204, Mapper204_Init}, {"", 205, Mapper205_Init}, {"DEIROM", 206, DEIROM_Init}, +// {207, Mapper207_Init}, {"", 208, Mapper208_Init}, {"", 209, Mapper209_Init}, {"", 210, Mapper210_Init}, {"", 211, Mapper211_Init}, +// {212, Mapper212_Init}, +// {213, Mapper213_Init}, +// {214, Mapper214_Init}, {"", 215, UNL8237_Init}, {"", 216, Mapper216_Init}, // {"", 217, Mapper217_Init}, +// {218, Mapper218_Init}, {"UNLA9746", 219, UNLA9746_Init}, - {"OneBus", 220, UNLOneBus_Init}, - -// {220, BMCFK23C_Init}, -// {220, UNL3DBlock_Init}, -// {220, UNLTF1201_Init}, -// {220, TCU02_Init}, -// {220, UNLCN22M_Init}, -// {220, BMCT2271_Init}, -// {220, UNLDANCE_Init}, - + {"", 220, UNLKS7057_Init}, // DEBUG mapper {"UNLN625092", 221, UNLN625092_Init}, {"", 222, Mapper222_Init}, +// {223, Mapper223_Init}, +// {224, Mapper224_Init}, + {"", 225, Mapper225_Init}, {"", 226, Mapper226_Init}, +// {227, Mapper227_Init}, +// {228, Mapper228_Init}, +// {229, Mapper229_Init}, +// {230, Mapper230_Init}, +// {231, Mapper231_Init}, +// {232, Mapper232_Init}, + {"BMC42in1r", 233, BMC42in1r_Init}, +// {234, Mapper234_Init}, {"", 235, Mapper235_Init}, +// {236, Mapper236_Init}, +// {237, Mapper237_Init}, {"UNL6035052", 238, UNL6035052_Init}, +// {239, Mapper239_Init}, {"", 240, Mapper240_Init}, +// {241, Mapper241_Init}, +// {242, Mapper242_Init}, {"S74LS374NA", 243, S74LS374NA_Init}, +// {244, Mapper244_Init}, {"", 245, Mapper245_Init}, +// {246, Mapper246_Init}, +// {247, Mapper247_Init}, +// {248, Mapper248_Init}, {"", 249, Mapper249_Init}, {"", 250, Mapper250_Init}, +// {251, Mapper251_Init}, +// {252, Mapper252_Init}, {"", 253, Mapper253_Init}, {"", 254, Mapper254_Init}, +// {255, Mapper255_Init}, {"", 0, 0} }; @@ -1105,264 +1217,265 @@ static void NONE_init(void) else setvram8(CHRRAM); } + void (*MapInitTab[256])(void)= { - 0, - 0, - 0, //Mapper2_init, - 0, //Mapper3_init, - 0, - 0, - Mapper6_init, - 0,//Mapper7_init, - Mapper8_init, - Mapper9_init, - Mapper10_init, - 0, //Mapper11_init, - 0, - 0, //Mapper13_init, - 0, + 0, + 0, + 0, //Mapper2_init, + 0, //Mapper3_init, + 0, + 0, + Mapper6_init, + 0, //Mapper7_init, + 0, //Mapper8_init, + Mapper9_init, + Mapper10_init, + 0, //Mapper11_init, + 0, + 0, //Mapper13_init, + 0, 0, //Mapper15_init, 0, //Mapper16_init, - Mapper17_init, - Mapper18_init, - 0, - 0, - Mapper21_init, - Mapper22_init, + 0, //Mapper17_init, + 0, //Mapper18_init, + 0, + 0, + Mapper21_init, + Mapper22_init, 0, //Mapper23_init, - Mapper24_init, - Mapper25_init, - Mapper26_init, - Mapper27_init, - 0, - 0, - 0, - 0, - Mapper32_init, - Mapper33_init, - Mapper34_init, - 0, - 0, - 0, - 0, - 0, - Mapper40_init, - Mapper41_init, - Mapper42_init, - 0, //Mapper43_init, - 0, - 0, - Mapper46_init, - 0, - Mapper48_init, - 0, - Mapper50_init, - Mapper51_init, - 0, - 0, - 0, - 0, - 0, - 0,// Mapper57_init, - 0,// Mapper58_init, - Mapper59_init, - 0,// Mapper60_init, - Mapper61_init, - Mapper62_init, - 0, - Mapper64_init, - Mapper65_init, - 0,//Mapper66_init, - Mapper67_init, - 0,//Mapper68_init, - Mapper69_init, - 0,//Mapper70_init, - Mapper71_init, - Mapper72_init, - Mapper73_init, - 0, - Mapper75_init, - Mapper76_init, - Mapper77_init, - 0, //Mapper78_init, - Mapper79_init, - Mapper80_init, - 0, - Mapper82_init, - Mapper83_init, - 0, - Mapper85_init, - Mapper86_init, - 0, //Mapper87_init, - 0, //Mapper88_init, - Mapper89_init, - 0, - Mapper91_init, - Mapper92_init, - 0, //Mapper93_init, - 0, //Mapper94_init, - 0, - Mapper96_init, - Mapper97_init, - 0, - Mapper99_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper107_init, - 0, - 0, - 0, - 0, - 0, - 0, // Mapper113_init, - 0, - 0, - 0, //Mapper116_init, - 0, //Mapper117_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper140_init, - 0, - 0, - 0, - 0, //Mapper144_init, - 0, - 0, - 0, - 0, - 0, - 0, - Mapper151_init, - 0, //Mapper152_init, + Mapper24_init, + Mapper25_init, + Mapper26_init, + Mapper27_init, + 0, + 0, + 0, + 0, + Mapper32_init, + Mapper33_init, + 0, //Mapper34_init, + 0, + 0, + 0, + 0, + 0, + Mapper40_init, + Mapper41_init, + Mapper42_init, + 0, //Mapper43_init, + 0, + 0, + Mapper46_init, + 0, + Mapper48_init, + 0, + Mapper50_init, + Mapper51_init, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper57_init, + 0, //Mapper58_init, + Mapper59_init, + 0, //Mapper60_init, + Mapper61_init, + Mapper62_init, + 0, + Mapper64_init, + Mapper65_init, + 0, //Mapper66_init, + Mapper67_init, + 0, //Mapper68_init, + Mapper69_init, + 0, //Mapper70_init, + Mapper71_init, + Mapper72_init, + Mapper73_init, + 0, + Mapper75_init, + Mapper76_init, + Mapper77_init, + 0, //Mapper78_init, + Mapper79_init, + Mapper80_init, + 0, + 0, //Mapper82_init, + 0, //Mapper83_init, + 0, + Mapper85_init, + 0, //Mapper86_init, + 0, //Mapper87_init, + 0, //Mapper88_init, + 0, //Mapper89_init, + 0, + 0, //Mapper91_init, + 0, //Mapper92_init, + 0, //Mapper93_init, + 0, //Mapper94_init, + 0, + 0, //Mapper96_init, + 0, //Mapper97_init, + 0, + 0, //Mapper99_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper107_init, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper113_init, + 0, + 0, + 0, //Mapper116_init, + 0, //Mapper117_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper140_init, + 0, + 0, + 0, + 0, //Mapper144_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper151_init, + 0, //Mapper152_init, 0, //Mapper153_init, - 0, //Mapper154_init, - 0, - 0, - Mapper157_init, - 0, //Mapper158_init, removed - 0, - 0, - 0, - 0, - 0, - 0, - 0, - Mapper166_init, - Mapper167_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper180_init, - 0, - 0, - 0, - 0, //Mapper184_init, - 0, //Mapper185_init, - 0, - 0, - 0, - 0, //Mapper189_init, - 0, - 0, //Mapper191_init, - 0, - Mapper193_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper200_init, - Mapper201_init, - Mapper202_init, - Mapper203_init, - Mapper204_init, - 0, - 0, - Mapper207_init, - 0, - 0, - 0, - 0, //Mapper211_init, - Mapper212_init, - Mapper213_init, - Mapper214_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - Mapper225_init, - 0, //Mapper226_init, - Mapper227_init, - Mapper228_init, - Mapper229_init, - Mapper230_init, - Mapper231_init, - Mapper232_init, - 0, - Mapper234_init, - 0, //Mapper235_init, - 0, - 0, - 0, - 0, - 0, //Mapper240_init, - Mapper241_init, - Mapper242_init, - 0, - Mapper244_init, - 0, - Mapper246_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - Mapper255_init + 0, //Mapper154_init, + 0, + 0, //Mapper156_init, + 0, //Mapper157_init, + 0, //Mapper158_init, removed + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper166_init, + Mapper167_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper180_init, + 0, + 0, + 0, + 0, //Mapper184_init, + 0, //Mapper185_init, + 0, + 0, + 0, + 0, //Mapper189_init, + 0, + 0, //Mapper191_init, + 0, + 0, //Mapper193_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper200_init, + Mapper201_init, + Mapper202_init, + Mapper203_init, + Mapper204_init, + 0, + 0, + Mapper207_init, + 0, + 0, + 0, + 0, //Mapper211_init, + Mapper212_init, + Mapper213_init, + Mapper214_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, //Mapper225_init, + 0, //Mapper226_init, + Mapper227_init, + Mapper228_init, + Mapper229_init, + Mapper230_init, + Mapper231_init, + Mapper232_init, + 0, + Mapper234_init, + 0, //Mapper235_init, + 0, + 0, + 0, + 0, + 0, //Mapper240_init, + Mapper241_init, + Mapper242_init, + 0, + Mapper244_init, + 0, + Mapper246_init, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Mapper255_init }; static DECLFW(BWRAM) diff --git a/ines.h b/ines.h index d18002c..cb424a3 100644 --- a/ines.h +++ b/ines.h @@ -135,7 +135,7 @@ void Mapper1_init(void); //void Mapper3_init(void); void Mapper6_init(void); //void Mapper7_init(void); -void Mapper8_init(void); +//void Mapper8_init(void); void Mapper9_init(void); void Mapper10_init(void); //void Mapper11_init(void); @@ -144,8 +144,8 @@ void Mapper12_init(void); void Mapper14_init(void); //void Mapper15_init(void); //void Mapper16_init(void); -void Mapper17_init(void); -void Mapper18_init(void); +//void Mapper17_init(void); +//void Mapper18_init(void); void Mapper19_init(void); void Mapper20_init(void); void Mapper21_init(void); @@ -161,7 +161,7 @@ void Mapper30_init(void); void Mapper31_init(void); void Mapper32_init(void); void Mapper33_init(void); -void Mapper34_init(void); +//void Mapper34_init(void); void Mapper35_init(void); void Mapper36_init(void); //void Mapper37_init(void); @@ -206,22 +206,22 @@ void Mapper77_init(void); void Mapper79_init(void); void Mapper80_init(void); void Mapper81_init(void); -void Mapper82_init(void); +//void Mapper82_init(void); void Mapper83_init(void); void Mapper84_init(void); void Mapper85_init(void); -void Mapper86_init(void); +//void Mapper86_init(void); //void Mapper87_init(void); void Mapper88_init(void); -void Mapper89_init(void); -void Mapper91_init(void); -void Mapper92_init(void); +//void Mapper89_init(void); +//void Mapper91_init(void); +//void Mapper92_init(void); //void Mapper93_init(void); //void Mapper94_init(void); -void Mapper96_init(void); -void Mapper97_init(void); +//void Mapper96_init(void); +//void Mapper97_init(void); void Mapper98_init(void); -void Mapper99_init(void); +//void Mapper99_init(void); void Mapper100_init(void); //void Mapper101_init(void); //void Mapper103_init(void); @@ -231,10 +231,10 @@ void Mapper104_init(void); //void Mapper108_init(void); void Mapper109_init(void); void Mapper110_init(void); -void Mapper111_init(void); +//void Mapper111_init(void); //void Mapper113_init(void); void Mapper115_init(void); -void Mapper116_init(void); +//void Mapper116_init(void); //void Mapper117_init(void); //void Mapper120_init(void); //void Mapper121_init(void); @@ -259,13 +259,14 @@ void Mapper141_init(void); void Mapper143_init(void); //void Mapper144_init(void); void Mapper150_init(void); -void Mapper151_init(void); +//void Mapper151_init(void); //void Mapper152_init(void); //void Mapper153_init(void); void Mapper154_init(void); -void Mapper157_init(void); +//void Mapper156_init(void); +//void Mapper157_init(void); //void Mapper158_init(void); -void Mapper159_init(void); +//void Mapper159_init(void); void Mapper160_init(void); void Mapper161_init(void); void Mapper162_init(void); @@ -283,13 +284,13 @@ void Mapper176_init(void); //void Mapper177_init(void); //void Mapper178_init(void); //void Mapper179_init(void); -//void Mapper180_init(void); +void Mapper180_init(void); //void Mapper181_init(void); //void Mapper184_init(void); //void Mapper185_init(void); //void Mapper189_init(void); //void Mapper192_init(void); -void Mapper193_init(void); +//void Mapper193_init(void); //void Mapper194_init(void); //void Mapper195_init(void); //void Mapper196_init(void); @@ -313,7 +314,7 @@ void Mapper221_init(void); //void Mapper222_init(void); void Mapper223_init(void); void Mapper224_init(void); -void Mapper225_init(void); +//void Mapper225_init(void); //void Mapper226_init(void); void Mapper227_init(void); void Mapper228_init(void); @@ -321,7 +322,7 @@ void Mapper229_init(void); void Mapper230_init(void); void Mapper231_init(void); void Mapper232_init(void); -void Mapper233_init(void); +//void Mapper233_init(void); void Mapper234_init(void); //void Mapper235_init(void); void Mapper236_init(void); @@ -351,12 +352,16 @@ void Mapper19_ESI(void); void Mapper1_Init(CartInfo *); void Mapper4_Init(CartInfo *); void Mapper5_Init(CartInfo *); +void Mapper8_Init(CartInfo *); void Mapper11_Init(CartInfo *); void Mapper12_Init(CartInfo *); void Mapper15_Init(CartInfo *); void Mapper16_Init(CartInfo *); +void Mapper17_Init(CartInfo *); +void Mapper18_Init(CartInfo *); void Mapper19_Init(CartInfo *); void Mapper23_Init(CartInfo *); +void Mapper34_Init(CartInfo *); void Mapper36_Init(CartInfo *); void Mapper37_Init(CartInfo *); void Mapper38_Init(CartInfo *); @@ -372,12 +377,21 @@ void Mapper68_Init(CartInfo *); void Mapper70_Init(CartInfo *); void Mapper74_Init(CartInfo *); void Mapper78_Init(CartInfo *); +void Mapper82_Init(CartInfo *); +void Mapper83_Init(CartInfo *); +void Mapper86_Init(CartInfo *); void Mapper87_Init(CartInfo *); void Mapper88_Init(CartInfo *); +void Mapper89_Init(CartInfo *); void Mapper90_Init(CartInfo *); +void Mapper91_Init(CartInfo *); +void Mapper92_Init(CartInfo *); void Mapper93_Init(CartInfo *); void Mapper94_Init(CartInfo *); void Mapper95_Init(CartInfo *); +void Mapper96_Init(CartInfo *); +void Mapper97_Init(CartInfo *); +void Mapper99_Init(CartInfo *); void Mapper101_Init(CartInfo *); void Mapper103_Init(CartInfo *); void Mapper105_Init(CartInfo *); @@ -388,9 +402,7 @@ void Mapper112_Init(CartInfo *); void Mapper113_Init(CartInfo *); void Mapper114_Init(CartInfo *); void Mapper115_Init(CartInfo *); -void Mapper116_Init(CartInfo *); void Mapper117_Init(CartInfo *); -void Mapper118_Init(CartInfo *); void Mapper119_Init(CartInfo *); void Mapper120_Init(CartInfo *); void Mapper121_Init(CartInfo *); @@ -398,26 +410,26 @@ void Mapper125_Init(CartInfo *); void Mapper134_Init(CartInfo *); void Mapper140_Init(CartInfo *); void Mapper144_Init(CartInfo *); +void Mapper151_Init(CartInfo *); void Mapper152_Init(CartInfo *); void Mapper153_Init(CartInfo *); void Mapper154_Init(CartInfo *); void Mapper155_Init(CartInfo *); void Mapper156_Init(CartInfo *); -void Mapper159_Init(CartInfo *); +void Mapper157_Init(CartInfo *); void Mapper163_Init(CartInfo *); void Mapper164_Init(CartInfo *); void Mapper165_Init(CartInfo *); -//void Mapper169_Init(CartInfo *); +void Mapper168_Init(CartInfo *); +void Mapper170_Init(CartInfo *); void Mapper171_Init(CartInfo *); void Mapper172_Init(CartInfo *); void Mapper173_Init(CartInfo *); void Mapper175_Init(CartInfo *); -void Mapper176_Init(CartInfo *); void Mapper177_Init(CartInfo *); void Mapper178_Init(CartInfo *); void Mapper180_Init(CartInfo *); void Mapper181_Init(CartInfo *); -//void Mapper182_Init(CartInfo *); void Mapper183_Init(CartInfo *); void Mapper184_Init(CartInfo *); void Mapper185_Init(CartInfo *); @@ -427,6 +439,7 @@ void Mapper188_Init(CartInfo *); void Mapper189_Init(CartInfo *); void Mapper191_Init(CartInfo *); void Mapper192_Init(CartInfo *); +void Mapper193_Init(CartInfo *); void Mapper194_Init(CartInfo *); void Mapper195_Init(CartInfo *); void Mapper196_Init(CartInfo *); @@ -439,11 +452,10 @@ void Mapper208_Init(CartInfo *); void Mapper209_Init(CartInfo *); void Mapper210_Init(CartInfo *); void Mapper211_Init(CartInfo *); -//void Mapper215_Init(CartInfo *); void Mapper216_Init(CartInfo *); -//void Mapper217_Init(CartInfo *); void Mapper220_Init(CartInfo *); void Mapper222_Init(CartInfo *); +void Mapper225_Init(CartInfo *); void Mapper226_Init(CartInfo *); void Mapper235_Init(CartInfo *); void Mapper236_Init(CartInfo *); diff --git a/mappers/151.c b/mappers/151.c deleted file mode 100644 index 91938d5..0000000 --- a/mappers/151.c +++ /dev/null @@ -1,41 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - - -DECLFW(Mapper151_write) -{ - switch(A&0xF000) - { - case 0x8000:ROM_BANK8(0x8000,V);break; - case 0xA000:ROM_BANK8(0xA000,V);break; - case 0xC000:ROM_BANK8(0xC000,V);break; - case 0xe000:VROM_BANK4(0x0000,V);break; - case 0xf000:VROM_BANK4(0x1000,V);break; - } -} - -void Mapper151_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper151_write); -} - diff --git a/mappers/16.c b/mappers/16.c deleted file mode 100644 index 002d3cb..0000000 --- a/mappers/16.c +++ /dev/null @@ -1,303 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static void BandaiIRQHook(int a) -{ - if(IRQa) - { - IRQCount-=a; - if(IRQCount<0) - { - X6502_IRQBegin(FCEU_IQEXT); - //printf("IRQ: %d, %d\n",scanline,timestamp); - IRQa=0; - IRQCount=0xFFFF; - } - } -} - -static DECLFW(Mapper16_write) -{ - A&=0xF; - - if(A<=0x7) - VROM_BANK1(A<<10,V); - else if(A==0x8) - ROM_BANK16(0x8000,V); - else switch(A) { - case 0x9: switch(V&3) { - case 0x00:MIRROR_SET2(1);break; - case 0x01:MIRROR_SET2(0);break; - case 0x02:onemir(0);break; - case 0x03:onemir(1);break; - } - break; - case 0xA:X6502_IRQEnd(FCEU_IQEXT); - IRQa=V&1; - IRQCount=IRQLatch; - break; - case 0xB:IRQLatch&=0xFF00; IRQLatch|=V; - break; - case 0xC:IRQLatch&=0xFF; IRQLatch|=V<<8; - break; - case 0xD: break;/* Serial EEPROM control port */ - } -} - -// Famicom jump 2: -// 0-7: Lower bit of data selects which 256KB PRG block is in use. -// This seems to be a hack on the developers' part, so I'll make emulation -// 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; - ROM_BANK16(0x8000,(mapbyte2[0]&0xF)|base); - ROM_BANK16(0xC000,base|0xF); -} - -static DECLFW(Mapper153_write) -{ - A&=0xF; - if(A<=0x7) - { - mapbyte1[A&7]=V; - PRGO(); - } - else if(A==0x8) - { - mapbyte2[0]=V; - PRGO(); - } - else switch(A) { - case 0x9: switch(V&3) { - case 0x00:MIRROR_SET2(1);break; - case 0x01:MIRROR_SET2(0);break; - case 0x02:onemir(0);break; - case 0x03:onemir(1);break; - } - break; - case 0xA:X6502_IRQEnd(FCEU_IQEXT); - IRQa=V&1; - IRQCount=IRQLatch; - break; - case 0xB:IRQLatch&=0xFF00; - IRQLatch|=V; - break; - case 0xC:IRQLatch&=0xFF; - IRQLatch|=V<<8; - break; - } -}*/ - -//void Mapper16_init(void) -//{ -// MapIRQHook=BandaiIRQHook; -//SetWriteHandler(0x6000,0xFFFF,Mapper16_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]; -static int BarcodeReadPos; -static int BarcodeCycleCount; -static uint32 BarcodeOut; - -int FCEUI_DatachSet(const uint8 *rcode) -{ - int prefix_parity_type[10][6] = { - {0,0,0,0,0,0}, {0,0,1,0,1,1}, {0,0,1,1,0,1}, {0,0,1,1,1,0}, - {0,1,0,0,1,1}, {0,1,1,0,0,1}, {0,1,1,1,0,0}, {0,1,0,1,0,1}, - {0,1,0,1,1,0}, {0,1,1,0,1,0} - }; - int data_left_odd[10][7] = { - {0,0,0,1,1,0,1}, {0,0,1,1,0,0,1}, {0,0,1,0,0,1,1}, {0,1,1,1,1,0,1}, - {0,1,0,0,0,1,1}, {0,1,1,0,0,0,1}, {0,1,0,1,1,1,1}, {0,1,1,1,0,1,1}, - {0,1,1,0,1,1,1}, {0,0,0,1,0,1,1} - }; - int data_left_even[10][7] = { - {0,1,0,0,1,1,1}, {0,1,1,0,0,1,1}, {0,0,1,1,0,1,1}, {0,1,0,0,0,0,1}, - {0,0,1,1,1,0,1}, {0,1,1,1,0,0,1}, {0,0,0,0,1,0,1}, {0,0,1,0,0,0,1}, - {0,0,0,1,0,0,1}, {0,0,1,0,1,1,1} - }; - int data_right[10][7] = { - {1,1,1,0,0,1,0}, {1,1,0,0,1,1,0}, {1,1,0,1,1,0,0}, {1,0,0,0,0,1,0}, - {1,0,1,1,1,0,0}, {1,0,0,1,1,1,0}, {1,0,1,0,0,0,0}, {1,0,0,0,1,0,0}, - {1,0,0,1,0,0,0}, {1,1,1,0,1,0,0} - }; - uint8 code[13+1]; - uint32 tmp_p=0; - int i, j; - int len; - - for(i=len=0;i<13;i++) - { - if(!rcode[i]) break; - - if((code[i]=rcode[i]-'0') > 9) - return(0); - len++; - } - if(len!=13 && len!=12 && len!=8 && len!=7) return(0); - - #define BS(x) BarcodeData[tmp_p]=x;tmp_p++ - - for(j=0;j<32;j++) - { - BS(0x00); - } - - /* Left guard bars */ - BS(1); BS(0); BS(1); - - if(len==13 || len==12) - { - uint32 csum; - - for(i=0;i<6;i++) - if(prefix_parity_type[code[0]][i]) - { - for(j=0;j<7;j++) - { - BS(data_left_even[code[i+1]][j]); - } - } - else - for(j=0;j<7;j++) - { - BS(data_left_odd[code[i+1]][j]); - } - - /* Center guard bars */ - BS(0); BS(1); BS(0); BS(1); BS(0); - - for(i=7;i<12;i++) - for(j=0;j<7;j++) - { - BS(data_right[code[i]][j]); - } - csum=0; - for(i=0;i<12;i++) csum+=code[i]*((i&1)?3:1); - csum=(10-(csum%10))%10; - //printf("%d\n",csum); - for(j=0;j<7;j++) - { - BS(data_right[csum][j]); - } - - } - else if(len==8 || len==7) - { - uint32 csum=0; - - for(i=0;i<7;i++) csum+=(i&1)?code[i]:(code[i]*3); - - csum=(10-(csum%10))%10; - - for(i=0;i<4;i++) - for(j=0;j<7;j++) - { - BS(data_left_odd[code[i]][j]); - } - - - /* Center guard bars */ - BS(0); BS(1); BS(0); BS(1); BS(0); - - for(i=4;i<7;i++) - for(j=0;j<7;j++) - { - BS(data_right[code[i]][j]); - } - - for(j=0;j<7;j++) - { BS(data_right[csum][j]);} - - } - - /* Right guard bars */ - BS(1); BS(0); BS(1); - - for(j=0;j<32;j++) - { - BS(0x00); - } - - BS(0xFF); - #undef BS - BarcodeReadPos=0; - BarcodeOut=0x8; - BarcodeCycleCount=0; - return(1); -} - -static void BarcodeIRQHook(int a) -{ - BandaiIRQHook(a); - - BarcodeCycleCount+=a; - - if(BarcodeCycleCount >= 1000) - { - BarcodeCycleCount -= 1000; - if(BarcodeData[BarcodeReadPos]==0xFF) - { - BarcodeOut=0; - } - else - { - BarcodeOut=(BarcodeData[BarcodeReadPos]^1)<<3; - BarcodeReadPos++; - } - } -} - -static DECLFR(Mapper157_read) -{ - uint8 ret; - - ret=BarcodeOut; - return(ret); -} - -void Mapper157_init(void) -{ - GameInfo->cspecial = SIS_DATACH; - MapIRQHook=BarcodeIRQHook; - SetWriteHandler(0x6000,0xFFFF,Mapper16_write); - SetReadHandler(0x6000,0x7FFF,Mapper157_read); - - BarcodeData[0]=0xFF; - BarcodeReadPos=0; - BarcodeOut=0; - BarcodeCycleCount=0; -} diff --git a/mappers/17.c b/mappers/17.c deleted file mode 100644 index c20bc28..0000000 --- a/mappers/17.c +++ /dev/null @@ -1,73 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - - -static void FFEIRQHook(int a) -{ - if(IRQa) - { - IRQCount+=a; - if(IRQCount>=0x10000) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - IRQCount=0; - } - } -} - - -DECLFW(Mapper17_write) -{ - switch(A){ - default: - break; - case 0x42FE: - onemir((V>>4)&1); - break; - case 0x42FF: - MIRROR_SET((V>>4)&1); - break; - case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; - case 0x4503:IRQCount&=0x00FF;IRQCount|=V<<8;IRQa=1;break; - case 0x4504: ROM_BANK8(0x8000,V);break; - case 0x4505: ROM_BANK8(0xA000,V);break; - case 0x4506: ROM_BANK8(0xC000,V);break; - case 0x4507: ROM_BANK8(0xE000,V);break; - case 0x4510: VROM_BANK1(0x0000,V);break; - case 0x4511: VROM_BANK1(0x0400,V);break; - case 0x4512: VROM_BANK1(0x0800,V);break; - case 0x4513: VROM_BANK1(0x0C00,V);break; - case 0x4514: VROM_BANK1(0x1000,V);break; - case 0x4515: VROM_BANK1(0x1400,V);break; - case 0x4516: VROM_BANK1(0x1800,V);break; - case 0x4517: VROM_BANK1(0x1C00,V);break; - } -} - -void Mapper17_init(void) -{ -MapIRQHook=FFEIRQHook; -SetWriteHandler(0x4020,0x5fff,Mapper17_write); -} diff --git a/mappers/18.c b/mappers/18.c deleted file mode 100644 index 030c055..0000000 --- a/mappers/18.c +++ /dev/null @@ -1,80 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -#define K4buf mapbyte2 -#define K4buf2 mapbyte3 - -void JalecoIRQHook(int a) -{ - if(IRQa && IRQCount) - { - IRQCount-=a; - if(IRQCount<=0) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQCount=0; - IRQa=0; - } - } -} - -DECLFW(Mapper18_write) -{ - A&=0xF003; - if(A>=0x8000 && A<=0x9001) - { - int x=((A>>1)&1)|((A-0x8000)>>11); - - K4buf2[x]&=(0xF0)>>((A&1)<<2); - K4buf2[x]|=(V&0xF)<<((A&1)<<2); - ROM_BANK8(0x8000+(x<<13),K4buf2[x]); - } - else if(A>=0xa000 && A<=0xd003) - { - int x=((A>>1)&1)|((A-0xA000)>>11); - - K4buf[x]&=(0xF0)>>((A&1)<<2); - K4buf[x]|=(V&0xF)<<((A&1)<<2); - VROM_BANK1(x<<10,K4buf[x]); - } - else switch(A) - { - case 0xe000:IRQLatch&=0xFFF0;IRQLatch|=(V&0x0f);break; - case 0xe001:IRQLatch&=0xFF0F;IRQLatch|=(V&0x0f)<<4;break; - case 0xe002:IRQLatch&=0xF0FF;IRQLatch|=(V&0x0f)<<8;break; - case 0xe003:IRQLatch&=0x0FFF;IRQLatch|=(V&0x0f)<<12;break; - case 0xf000:IRQCount=IRQLatch; - break; - case 0xf001:IRQa=V&1; - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xf002:MIRROR_SET2(V&1); - if(V&2) onemir(0); - break; - } -} - -void Mapper18_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper18_write); - MapIRQHook=JalecoIRQHook; -} diff --git a/mappers/193.c b/mappers/193.c deleted file mode 100644 index 0afa247..0000000 --- a/mappers/193.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "mapinc.h" - -static DECLFW(m193w) -{ - //printf("$%04x:$%02x\n",A,V); - switch(A&3) - { - case 0:VROM_BANK4(0x0000,V>>2);break; - case 1:VROM_BANK2(0x1000,V>>1);break; - case 2:VROM_BANK2(0x1800,V>>1);break; - case 3:ROM_BANK8(0x8000,V);break; - } -} - -void Mapper193_init(void) -{ - ROM_BANK32(~0); - SetWriteHandler(0x4018,0x7fff,m193w); - SetReadHandler(0x4018,0x7fff,0); -} diff --git a/mappers/201.c b/mappers/201.c index d566470..748d488 100644 --- a/mappers/201.c +++ b/mappers/201.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/202.c b/mappers/202.c index 7c02f97..cac2a88 100644 --- a/mappers/202.c +++ b/mappers/202.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/203.c b/mappers/203.c index 0187b8a..6ab5d52 100644 --- a/mappers/203.c +++ b/mappers/203.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/204.c b/mappers/204.c index 543364b..3d79918 100644 --- a/mappers/204.c +++ b/mappers/204.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/21.c b/mappers/21.c index c8b8cd9..8d60d4c 100644 --- a/mappers/21.c +++ b/mappers/21.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -82,7 +82,7 @@ DECLFW(Mapper21_write) case 0xf006:IRQa=K4IRQ;X6502_IRQEnd(FCEU_IQEXT);break; } } -static void KonamiIRQHook(int a) +static void FP_FASTAPASS(1) KonamiIRQHook(int a) { #define LCYCS ((227*2)+1) //#define LCYCS 341 diff --git a/mappers/217.c b/mappers/217.c index 1bf4cbd..6f7a251 100644 --- a/mappers/217.c +++ b/mappers/217.c @@ -93,4 +93,4 @@ void Mapper217_init(void) DoPRG217(); DoCHR217(); } -*/ +*/ \ No newline at end of file diff --git a/mappers/22.c b/mappers/22.c index eee5365..9335106 100644 --- a/mappers/22.c +++ b/mappers/22.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * (VRC4 mapper) */ diff --git a/mappers/225.c b/mappers/225.c deleted file mode 100644 index 60c97c8..0000000 --- a/mappers/225.c +++ /dev/null @@ -1,87 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - -#define reg1 mapbyte1[0] -#define reg2 mapbyte1[1] -#define reg3 mapbyte1[2] -#define reg4 mapbyte1[3] - -DECLFR(A110in1read) -{ -switch(A&0x3) - { - case 0:return reg1;break; - case 1:return reg2;break; - case 2:return reg3;break; - case 3:return reg4;break; - } -return 0xF; -} -DECLFW(A110in1regwr) -{ -switch(A&0x3) - { - case 0:reg1=V&0xF;break; - case 1:reg2=V&0xF;break; - case 2:reg3=V&0xF;break; - case 3:reg4=V&0xF;break; - } -} - -DECLFW(Mapper225_write) -{ - int banks=0; - - MIRROR_SET((A>>13)&1); - if(A&0x4000) - banks=1; - else - banks=0; - - VROM_BANK8(((A&0x003f)+(banks<<6))); - if(A&0x1000) - { - if(A&0x40) - { - ROM_BANK16(0x8000,((((((A>>7)&0x1F)+(banks<<5)))<<1)+1)); - ROM_BANK16(0xC000,((((((A>>7)&0x1F)+(banks<<5)))<<1)+1)); - } - else - { - ROM_BANK16(0x8000,(((((A>>7)&0x1F)+(banks<<5)))<<1)); - ROM_BANK16(0xC000,(((((A>>7)&0x1F)+(banks<<5)))<<1)); - } - } - else - { - ROM_BANK32(((((A>>7)&0x1F)+(banks<<5)))); - } -} - -void Mapper225_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper225_write); - SetReadHandler(0x5800,0x5fff,A110in1read); - SetWriteHandler(0x5800,0x5fff,A110in1regwr); -} - diff --git a/mappers/227.c b/mappers/227.c index 8b5cff9..e88649b 100644 --- a/mappers/227.c +++ b/mappers/227.c @@ -15,44 +15,41 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" -//zero 14-apr-2012 - redid this entirely to match bizhawk - #define rg mapbyte1 static void DoSync(uint32 A) { - int S = A & 1; - int M_horz = (A>>1)&1; - int p = (A >> 2) & 0x1F; + uint32 S = A & 1; + uint32 p = (A >> 2) & 0x1F; p += (A&0x100) ? 0x20 : 0; - bool o = (A>>7)&1; - bool L = (A>>9)&1; + uint32 o = (A>>7)&1; + uint32 L = (A>>9)&1; if (o && !S ) - { + { ROM_BANK16(0x8000,p); ROM_BANK16(0xC000,p); - } + } if (o && S ) - { + { ROM_BANK16(0x8000,p); ROM_BANK16(0xC000,p+1); - } + } if (!o && !S && !L ) - { + { ROM_BANK16(0x8000,p); ROM_BANK16(0xC000,p&0x38); - } + } if (!o && S && !L ) - { + { ROM_BANK16(0x8000,p&0x3E); ROM_BANK16(0xC000,p&0x38); - } + } if (!o && !S && L) { ROM_BANK16(0x8000,p); @@ -64,31 +61,31 @@ static void DoSync(uint32 A) ROM_BANK16(0xC000,p|7); } - rg[0]=A; - rg[1]=A>>8; + rg[0]=A; + rg[1]=A>>8; - MIRROR_SET((A>>1)&1); + MIRROR_SET((A>>1)&1); } static DECLFW(Mapper227_write) { - DoSync(A); + DoSync(A); } static void M227Reset(void) { - DoSync(0); + DoSync(0); } static void M227Restore(int version) { - DoSync(rg[0]|(rg[1]<<8)); + DoSync(rg[0]|(rg[1]<<8)); } void Mapper227_init(void) { - SetWriteHandler(0x8000,0xffff,Mapper227_write); - MapperReset=M227Reset; - GameStateRestore=M227Restore; - M227Reset(); + SetWriteHandler(0x8000,0xffff,Mapper227_write); + MapperReset=M227Reset; + GameStateRestore=M227Restore; + M227Reset(); } diff --git a/mappers/228.c b/mappers/228.c index a63218e..d08485a 100644 --- a/mappers/228.c +++ b/mappers/228.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -24,12 +24,6 @@ //only use bottom 4 bits as ram though static uint8 mapper228_ram[4]; -static SFORMAT StateRegs[]= -{ - { mapper228_ram, 4, "MAPPER_RAM" }, - { 0 } -}; - static DECLFR(Mapper228_read) { return mapper228_ram[A & 3] & 0xF; @@ -37,7 +31,7 @@ static DECLFR(Mapper228_read) static DECLFW(Mapper228_write) { - uint32 page, pagel, pageh; + uint32 page,pagel,pageh; //write to ram if (A < 0x6000) @@ -45,18 +39,18 @@ static DECLFW(Mapper228_write) mapper228_ram[A & 3] = V; return; } - MIRROR_SET((A >> 13) & 1); - page = (A >> 7) & 0x3F; + MIRROR_SET((A>>13)&1); + page=(A>>7)&0x3F; - if( (page & 0x30) == 0x30) - page -= 0x10; + if((page&0x30)==0x30) + page-=0x10; + + pagel=pageh=(page<<1) + (((A>>6)&1)&((A>>5)&1)); + pageh+=((A>>5)&1)^1; - pagel = pageh = (page << 1) + (((A >> 6) & 1) & ((A >> 5) & 1)); - pageh += ((A >> 5) & 1) ^ 1; - - ROM_BANK16(0x8000,pagel); - ROM_BANK16(0xC000,pageh); - VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); + ROM_BANK16(0x8000,pagel); + ROM_BANK16(0xC000,pageh); + VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); } static void A52Reset(void) @@ -66,11 +60,11 @@ static void A52Reset(void) void Mapper228_init(void) { - MapperReset=A52Reset; - A52Reset(); + MapperReset=A52Reset; + A52Reset(); SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); SetReadHandler (0x4020, 0x5FFF, Mapper228_read); - AddExState(StateRegs, ~0, 0, 0); + AddExState(mapper228_ram, 4, 0, "MRAM"); } diff --git a/mappers/229.c b/mappers/229.c index acc31a3..a78dd73 100644 --- a/mappers/229.c +++ b/mappers/229.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/230.c b/mappers/230.c index 32550e5..cbf1fbe 100644 --- a/mappers/230.c +++ b/mappers/230.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/231.c b/mappers/231.c index 0f467ec..9b8d1fc 100644 --- a/mappers/231.c +++ b/mappers/231.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/232.c b/mappers/232.c index 6beafb2..548db8c 100644 --- a/mappers/232.c +++ b/mappers/232.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/234.c b/mappers/234.c index 1835d57..d8ca53f 100644 --- a/mappers/234.c +++ b/mappers/234.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/242.c b/mappers/242.c index 72c0be5..9636f0a 100644 --- a/mappers/242.c +++ b/mappers/242.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/244.c b/mappers/244.c index 68a7563..889f13b 100644 --- a/mappers/244.c +++ b/mappers/244.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2003 CaH4e3 + * Copyright (C) 2011 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 @@ -15,24 +15,39 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" -static DECLFW(Mapper244_write_1) -{ - ROM_BANK32((A-0x8065)&0x03); -} +static uint8 prg_perm[4][4] = { + {0, 1, 2, 3,}, + {3, 2, 1, 0,}, + {0, 2, 1, 3,}, + {3, 1, 2, 0,}, +}; + +static uint8 chr_perm[8][8] = { + {0, 1, 2, 3, 4, 5, 6, 7,}, + {0, 2, 1, 3, 4, 6, 5, 7,}, + {0, 1, 4, 5, 2, 3, 6, 7,}, + {0, 4, 1, 5, 2, 6, 3, 7,}, + {0, 4, 2, 6, 1, 5, 3, 7,}, + {0, 2, 4, 6, 1, 3, 5, 7,}, + {7, 6, 5, 4, 3, 2, 1, 0,}, + {7, 6, 5, 4, 3, 2, 1, 0,}, +}; -static DECLFW(Mapper244_write_2) +static DECLFW(Mapper244_write) { - VROM_BANK8((A-0x80A5)&0x07); + if(V&8) + VROM_BANK8(chr_perm[(V>>4)&7][V&7]); + else + ROM_BANK32(prg_perm[(V>>4)&3][V&3]); } void Mapper244_init(void) { ROM_BANK32(0); - SetWriteHandler(0x8065,0x80a4,Mapper244_write_1); - SetWriteHandler(0x80a5,0x80e4,Mapper244_write_2); + SetWriteHandler(0x8000,0xffff,Mapper244_write); } diff --git a/mappers/246.c b/mappers/246.c index 4ae017e..8623233 100644 --- a/mappers/246.c +++ b/mappers/246.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/24and26.c b/mappers/24and26.c index 115ead0..71fb139 100644 --- a/mappers/24and26.c +++ b/mappers/24and26.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-6 + * */ #include "mapinc.h" @@ -34,7 +37,7 @@ static int swaparoo; static int acount=0; -static void KonamiIRQHook(int a) +static void FP_FASTAPASS(1) KonamiIRQHook(int a) { #define LCYCS 341 // #define LCYCS ((227*2)+1) @@ -224,7 +227,7 @@ static void DoSawV(void) static INLINE void DoSQVHQ(int x) { - uint32 V; //mbg merge 7/17/06 made uint + int32 V; int32 amp=((VPSG[x<<2]&15)<<8)*6/8; if(VPSG[(x<<2)|0x2]&0x80) @@ -267,7 +270,7 @@ static void DoSawVHQ(void) { static uint8 b3=0; static int32 phaseacc=0; - uint32 V; //mbg merge 7/17/06 made uint32 + int32 V; if(VPSG2[2]&0x80) { diff --git a/mappers/25.c b/mappers/25.c index e099cc9..37e2742 100644 --- a/mappers/25.c +++ b/mappers/25.c @@ -15,8 +15,8 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * (VRCII mapper) + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * (VRC4 mapper) */ #include "mapinc.h" @@ -37,10 +37,9 @@ static DECLFW(Mapper25_write) VROM_BANK1(0x0000,0xFC); VROM_BANK1(0x0400,0xFD); VROM_BANK1(0x0800,0xFF); - VROM_BANK1(0x0c00,0xCF); } - A=(A&0xF003)|((A&0xC)>>2); + A=(A&0xF003)|((A&0xC)>>2); if((A&0xF000)==0xA000) ROM_BANK8(0xA000,V); @@ -51,9 +50,9 @@ static DECLFW(Mapper25_write) K4buf[x]&=(0xF0)>>((A&2)<<1); K4buf[x]|=(V&0xF)<<((A&2)<<1); if(weirdo) - weirdo--; + weirdo--; else - VROM_BANK1(x<<10,K4buf[x]); + VROM_BANK1(x<<10,K4buf[x]); } else if((A&0xF000)==0x8000) { @@ -88,7 +87,7 @@ static DECLFW(Mapper25_write) } } -static void KonamiIRQHook(int a) +static void FP_FASTAPASS(1) KonamiIRQHook(int a) { // #define LCYCS ((227*2)) #define LCYCS 341 diff --git a/mappers/255.c b/mappers/255.c index 405340e..d65f18d 100644 --- a/mappers/255.c +++ b/mappers/255.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/27.c b/mappers/27.c index e1afc22..c3b6b36 100644 --- a/mappers/27.c +++ b/mappers/27.c @@ -4,8 +4,8 @@ static uint32 regchr[9]; static DECLFW(Mapper27_write) { - int regnum; A&=0xF00F; + int regnum; if((A>=0xB000) && (A<=0xE003)) { regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); if(A&1) diff --git a/mappers/32.c b/mappers/32.c index b538947..13e4bba 100644 --- a/mappers/32.c +++ b/mappers/32.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/33.c b/mappers/33.c index 1324663..af7fcb8 100644 --- a/mappers/33.c +++ b/mappers/33.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -37,7 +37,6 @@ 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; } } diff --git a/mappers/40.c b/mappers/40.c index 9cdc24c..431dac9 100644 --- a/mappers/40.c +++ b/mappers/40.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" @@ -31,7 +34,7 @@ static DECLFW(Mapper40_write) } } -static void Mapper40IRQ(int a) +static void FP_FASTAPASS(1) Mapper40IRQ(int a) { if(IRQa) { diff --git a/mappers/41.c b/mappers/41.c index 84aed5d..dfb6908 100644 --- a/mappers/41.c +++ b/mappers/41.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/42.c b/mappers/42.c index 10774bd..0687807 100644 --- a/mappers/42.c +++ b/mappers/42.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" @@ -33,7 +36,7 @@ static DECLFW(Mapper42_write) } } -static void Mapper42IRQ(int a) +static void FP_FASTAPASS(1) Mapper42IRQ(int a) { if(IRQa) { diff --git a/mappers/46.c b/mappers/46.c index 7e1a907..8c4ef6d 100644 --- a/mappers/46.c +++ b/mappers/46.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/50.c b/mappers/50.c index 629d86d..563a59a 100644 --- a/mappers/50.c +++ b/mappers/50.c @@ -15,13 +15,16 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FDS Conversion + * */ #include "mapinc.h" -static void Mapper50IRQ(int a) +static void FP_FASTAPASS(1) Mapper50IRQ(int a) { if(IRQa) { diff --git a/mappers/51.c b/mappers/51.c index c2c723e..cc1fbbd 100644 --- a/mappers/51.c +++ b/mappers/51.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/59.c b/mappers/59.c index 4dd9e95..30ddb8b 100644 --- a/mappers/59.c +++ b/mappers/59.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/6.c b/mappers/6.c index 35fd900..cbb5111 100644 --- a/mappers/6.c +++ b/mappers/6.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * FFE + * */ #include "mapinc.h" @@ -24,7 +27,7 @@ static uint8 FFEmode; #define FVRAM_BANK8(A,V) {VPage[0]=VPage[1]=VPage[2]=VPage[3]=VPage[4]=VPage[5]=VPage[6]=VPage[7]=V?&MapperExRAM[(V)<<13]-(A):&CHRRAM[(V)<<13]-(A);CHRBankList[0]=((V)<<3);CHRBankList[1]=((V)<<3)+1;CHRBankList[2]=((V)<<3)+2;CHRBankList[3]=((V)<<3)+3;CHRBankList[4]=((V)<<3)+4;CHRBankList[5]=((V)<<3)+5;CHRBankList[6]=((V)<<3)+6;CHRBankList[7]=((V)<<3)+7;PPUCHRRAM=0xFF;} -static void FFEIRQHook(int a) +static void FP_FASTAPASS(1) FFEIRQHook(int a) { if(IRQa) { diff --git a/mappers/60.c b/mappers/60.c deleted file mode 100644 index a2b2ee1..0000000 --- a/mappers/60.c +++ /dev/null @@ -1,41 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ -/* -#include "mapinc.h" - -static DECLFW(Mapper60_write) -{ - if(A&0x80) { - ROM_BANK16(0x8000,(A&0x70)>>4); - ROM_BANK16(0xC000,(A&0x70)>>4); - } - else - ROM_BANK32((A&0x70)>>5); - VROM_BANK8(A&7); - MIRROR_SET((A&8)>>3); -} - -void Mapper60_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x8000,0xffff, Mapper60_write); -} -*/ - diff --git a/mappers/61.c b/mappers/61.c index 10b9e6d..4303932 100644 --- a/mappers/61.c +++ b/mappers/61.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/62.c b/mappers/62.c index 6da991c..4d03c88 100644 --- a/mappers/62.c +++ b/mappers/62.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/65.c b/mappers/65.c index 1a8cb8b..d817694 100644 --- a/mappers/65.c +++ b/mappers/65.c @@ -15,13 +15,13 @@ * * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" -void IREMIRQHook(int a) +void FP_FASTAPASS(1) IREMIRQHook(int a) { if(IRQa) { diff --git a/mappers/67.c b/mappers/67.c index ee2390a..9d560f9 100644 --- a/mappers/67.c +++ b/mappers/67.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -58,7 +58,7 @@ static DECLFW(Mapper67_write) case 0xf800:ROM_BANK16(0x8000,V);break; } } -static void SunIRQHook(int a) +static void FP_FASTAPASS(1) SunIRQHook(int a) { if(IRQa) { diff --git a/mappers/69.c b/mappers/69.c index 5d15243..b204a54 100644 --- a/mappers/69.c +++ b/mappers/69.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -52,7 +52,7 @@ static DECLFW(Mapper69_SWH) int x; GameExpSound.Fill=AYSound; GameExpSound.HiFill=AYSoundHQ; - if(FSettings.SndRate) + if(FSettings.SndRate); switch(sunindex) { case 0: @@ -148,7 +148,7 @@ static void DoAYSQ(int x) static void DoAYSQHQ(int x) { - uint32 V; //mbg merge 7/17/06 made uitn32 + int32 V; int32 freq=((MapperExRAM[x<<1]|((MapperExRAM[(x<<1)+1]&15)<<8))+1)<<4; int32 amp=(MapperExRAM[0x8+x]&15)<<6; @@ -196,7 +196,7 @@ static void AYHiSync(int32 ts) CAYBC[x]=ts; } -static void SunIRQHook(int a) +static void FP_FASTAPASS(1) SunIRQHook(int a) { if(IRQa) { diff --git a/mappers/71.c b/mappers/71.c index 05b46a3..9b1a99d 100644 --- a/mappers/71.c +++ b/mappers/71.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/72.c b/mappers/72.c index 857f800..480a035 100644 --- a/mappers/72.c +++ b/mappers/72.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/73.c b/mappers/73.c index dc87fed..2632902 100644 --- a/mappers/73.c +++ b/mappers/73.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-3 + * */ #include "mapinc.h" @@ -38,7 +41,7 @@ static DECLFW(Mapper73_write) } } -static void Mapper73IRQHook(int a) +static void FP_FASTAPASS(1) Mapper73IRQHook(int a) { if(IRQa) { diff --git a/mappers/75.c b/mappers/75.c index 9b5a31c..5751cd2 100644 --- a/mappers/75.c +++ b/mappers/75.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-1 + * */ #include "mapinc.h" diff --git a/mappers/76.c b/mappers/76.c index 8dd75d8..a59ef1e 100644 --- a/mappers/76.c +++ b/mappers/76.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/77.c b/mappers/77.c index be6cd36..06f15cc 100644 --- a/mappers/77.c +++ b/mappers/77.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" diff --git a/mappers/79.c b/mappers/79.c index 9e8412a..094592a 100644 --- a/mappers/79.c +++ b/mappers/79.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * TXC mapper variation, F-15 City War */ diff --git a/mappers/8.c b/mappers/8.c deleted file mode 100644 index a8f9cb8..0000000 --- a/mappers/8.c +++ /dev/null @@ -1,34 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static DECLFW(Mapper8_write) -{ - ROM_BANK16(0x8000,V>>3); - VROM_BANK8(V&7); -} - -void Mapper8_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x8000,0xFFFF,Mapper8_write); -} - diff --git a/mappers/80.c b/mappers/80.c index d569fa0..ca89170 100644 --- a/mappers/80.c +++ b/mappers/80.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -24,7 +24,7 @@ static uint32 lastA; static int isfu; static uint8 CCache[8]; -static void Fudou_PPU(uint32 A) +static void FP_FASTAPASS(1) Fudou_PPU(uint32 A) { static int last=-1; static uint8 z; @@ -87,8 +87,8 @@ static void booga(int version) void Mapper80_init(void) { - SetWriteHandler(0x4020,0x7eff,Mapper80_write);// 7f00-7fff battery backed ram inside mapper chip, - // controlled by 7ef8 register, A8 - enable, FF - disable (?) + SetWriteHandler(0x4020,0x7eff,Mapper80_write);// 7f00-7fff battery backed ram inside mapper chip, + // controlled by 7ef8 register, A8 - enable, FF - disable (?) MapStateRestore=booga; isfu=0; } diff --git a/mappers/82.c b/mappers/82.c deleted file mode 100644 index 674b677..0000000 --- a/mappers/82.c +++ /dev/null @@ -1,62 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -#define ctrl mapbyte1[6] - -static void DoCHR(void) -{ - int x; - - for(x=0;x<2;x++) - VROM_BANK2((x<<11)|((ctrl&2)<<11),mapbyte1[x]>>1); - for(x=0;x<4;x++) - VROM_BANK1((x<<10) | (((ctrl&2)^2)<<11),mapbyte1[2+x]); -} - -static DECLFW(Mapper82_write) -{ - if(A<=0x7EF5) - { - mapbyte1[A&7]=V; - DoCHR(); - } - else - switch(A) - { - case 0x7ef6:ctrl=V&3; - MIRROR_SET2(V&1); - DoCHR(); - break; - case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break; - case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break; - case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break; - } -} - -void Mapper82_init(void) -{ - ROM_BANK8(0xE000,~0); - - /* external WRAM might end at $73FF */ - SetWriteHandler(0x7ef0,0x7efc,Mapper82_write); -} - diff --git a/mappers/83.c b/mappers/83.c deleted file mode 100644 index ca26388..0000000 --- a/mappers/83.c +++ /dev/null @@ -1,147 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static uint8 is2kbank, isnot2kbank, dipreg; - -/*void Mapper83_init(void) -{ - -} -*/ -static void m83IRQHook(int a) -{ - if(IRQa) - { - IRQCount-=a; - if(IRQCount<0) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - IRQCount=0xFFFF; - } - } -} - -static DECLFW(wrlow) -{ - mapbyte4[A&3]=V; -} - -static DECLFR(rdlow) -{ - return mapbyte4[A&3]; -} - -static DECLFR(rd5000) -{ - return dipreg; -} - -static void m83prg(void) -{ - ROM_BANK16(0x8000,(mapbyte1[0]&0x3F)); - ROM_BANK16(0xC000,(mapbyte1[0]&0x30)|0xF); -} - -static void m83chr(void) -{ - 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) -{ - //printf("$%04x:$%02x\n",A,V); - switch(A) - { - case 0x8000: is2kbank = 1; - case 0xB000: - case 0xB0FF: - case 0xB1FF: - { - mapbyte1[0]=V; - m83prg(); - m83chr(); - } - break; - case 0x8100: - mapbyte3[0]=V&0x80; - switch(V&0x3) - { - case 0x00:MIRROR_SET2(1);break; - case 0x01:MIRROR_SET2(0);break; - case 0x02:onemir(0);break; - case 0x03:onemir(1);break; - } - break; - case 0x8200:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; - case 0x8201:IRQa=mapbyte3[0];IRQCount&=0xFF;IRQCount|=V<<8;break; - case 0x8300:ROM_BANK8(0x8000,V);break; - case 0x8301:ROM_BANK8(0xA000,V);break; - 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;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; - } -// printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W); - -} - -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); - mapbyte1[1]=0xF; -} diff --git a/mappers/85.c b/mappers/85.c index dfe6434..e7edd59 100644 --- a/mappers/85.c +++ b/mappers/85.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * VRC-7 + * */ #include "mapinc.h" @@ -113,7 +116,7 @@ DECLFW(Mapper85_write) } } -static void KonamiIRQHook(int a) +static void FP_FASTAPASS(1) KonamiIRQHook(int a) { #define ACBOO 341 // #define ACBOO ((227*2)+1) diff --git a/mappers/86.c b/mappers/86.c deleted file mode 100644 index f95b639..0000000 --- a/mappers/86.c +++ /dev/null @@ -1,38 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -DECLFW(Mapper86_write) -{ - if(A>=0x6000 && A<=0x6fFF) - { - VROM_BANK8((V&3)|((V>>4)&4)); - ROM_BANK32((V>>4)&3); - } - //else - //if(A!=0x6000) - // printf("$%04x:$%02x\n",A,V); -} -void Mapper86_init(void) -{ - SetWriteHandler(0x6000,0x6fff,Mapper86_write); - SetWriteHandler(0x4020,0xffff,Mapper86_write); -} diff --git a/mappers/89.c b/mappers/89.c deleted file mode 100644 index e742735..0000000 --- a/mappers/89.c +++ /dev/null @@ -1,34 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -DECLFW(Mapper89_write) -{ - VROM_BANK8((V&7)|((V>>4)&8)); - ROM_BANK16(0x8000,(V>>4)&7); - onemir((V>>3)&1); -} - -void Mapper89_init(void) -{ - Mirroring=0; - SetWriteHandler(0x8000,0xffff,Mapper89_write); -} diff --git a/mappers/91.c b/mappers/91.c deleted file mode 100644 index 6dc7fc9..0000000 --- a/mappers/91.c +++ /dev/null @@ -1,59 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static DECLFW(Mapper91_write) -{ -//if(A>=0x7001) -//printf("$%04x:$%02x, %d\n",A,V,scanline); - A&=0xF007; - - if(A>=0x6000 && A<=0x6003) VROM_BANK2((A&3)*2048,V); - else switch(A&0xF003) - { - case 0x7000: - case 0x7001:ROM_BANK8(0x8000+(A&1)*8192,V);break; - case 0x7002:IRQa=IRQCount=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0x7003:IRQa=1;X6502_IRQEnd(FCEU_IQEXT);break; -// default: printf("Iyee: $%04x:$%02x\n",A,V);break; - } - //if(A>=0x7000) - // printf("$%04x:$%02x, %d\n",A,V,scanline); -} - -static void Mapper91_hb(void) -{ - if(IRQCount<8 && IRQa) - { - IRQCount++; - if(IRQCount>=8) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -void Mapper91_init(void) -{ - SetWriteHandler(0x4020,0xFFFF,Mapper91_write); - GameHBIRQHook=Mapper91_hb; -} - diff --git a/mappers/92.c b/mappers/92.c deleted file mode 100644 index 1230836..0000000 --- a/mappers/92.c +++ /dev/null @@ -1,45 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -/* Original code provided by LULU */ - -static DECLFW(Mapper92_write) -{ - uint8 reg=(A&0xF0)>>4; - uint8 bank=A&0xF; - - if(A>=0x9000) - { - if(reg==0xD) ROM_BANK16(0xc000,bank); - else if(reg==0xE) VROM_BANK8(bank); - } - else - { - if(reg==0xB) ROM_BANK16(0xc000,bank); - else if(reg==0x7) VROM_BANK8(bank); - } -} - -void Mapper92_init(void) -{ - SetWriteHandler(0x8000,0xFFFF,Mapper92_write); -} diff --git a/mappers/97.c b/mappers/97.c deleted file mode 100644 index f0e7beb..0000000 --- a/mappers/97.c +++ /dev/null @@ -1,42 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - - - -DECLFW(Mapper97_write) -{ -ROM_BANK16(0xC000,V&15); -switch(V>>6) - { - case 0:break; - case 1:MIRROR_SET2(0);break; - case 2:MIRROR_SET2(1);break; - case 3:break; - } -} - -void Mapper97_init(void) -{ - ROM_BANK16(0x8000,~0); - SetWriteHandler(0x8000,0xffff,Mapper97_write); -} - diff --git a/mappers/99.c b/mappers/99.c deleted file mode 100644 index 6f3081f..0000000 --- a/mappers/99.c +++ /dev/null @@ -1,37 +0,0 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static writefunc oldmorko; - -static DECLFW(morko) -{ - VROM_BANK8((V>>2)&1); - oldmorko(A,V); - setprg8(0x8000,V&0x4); /* Special for VS Gumshoe */ -} - -void Mapper99_init(void) -{ - ROM_BANK32(0); - oldmorko=GetWriteHandler(0x4016); - SetWriteHandler(0x4016,0x4016,morko); -} diff --git a/mappers/Makefile b/mappers/Makefile index 242915a..a1c8084 100644 --- a/mappers/Makefile +++ b/mappers/Makefile @@ -1,8 +1,3 @@ -MM_C += mappers/151.c -MM_C += mappers/16.c -MM_C += mappers/17.c -MM_C += mappers/18.c -MM_C += mappers/193.c MM_C += mappers/201.c MM_C += mappers/202.c MM_C += mappers/203.c @@ -13,7 +8,6 @@ MM_C += mappers/214.c MM_C += mappers/215.c MM_C += mappers/217.c MM_C += mappers/21.c -MM_C += mappers/225.c MM_C += mappers/227.c MM_C += mappers/228.c MM_C += mappers/229.c @@ -39,7 +33,6 @@ MM_C += mappers/46.c MM_C += mappers/50.c MM_C += mappers/51.c MM_C += mappers/59.c -MM_C += mappers/60.c MM_C += mappers/61.c MM_C += mappers/62.c MM_C += mappers/65.c @@ -54,20 +47,9 @@ MM_C += mappers/76.c MM_C += mappers/77.c MM_C += mappers/79.c MM_C += mappers/80.c -MM_C += mappers/82.c -MM_C += mappers/83.c MM_C += mappers/85.c -MM_C += mappers/86.c -MM_C += mappers/89.c -MM_C += mappers/8.c -MM_C += mappers/91.c -MM_C += mappers/92.c -MM_C += mappers/97.c -MM_C += mappers/99.c MM_C += mappers/emu2413.c MM_C += mappers/mmc2and4.c -MM_C += mappers/simple.c -MM_C += mappers/156.c MOBJS += $(patsubst %.c,%.o,$(MM_C)) diff --git a/mappers/mapinc.h b/mappers/mapinc.h index 7e2f5e3..2c7acf0 100644 --- a/mappers/mapinc.h +++ b/mappers/mapinc.h @@ -8,5 +8,4 @@ #include "../memory.h" #include "../sound.h" #include "../state.h" -#include "../svga.h" #include diff --git a/mappers/mmc2and4.c b/mappers/mmc2and4.c index d34cc6b..022d736 100644 --- a/mappers/mmc2and4.c +++ b/mappers/mmc2and4.c @@ -15,7 +15,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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "mapinc.h" @@ -25,7 +25,7 @@ #define latcha2 mapbyte2[1] -static void latchcheck(uint32 VAddr) +static void FP_FASTAPASS(1) latchcheck(uint32 VAddr) { uint8 l,h; diff --git a/mappers/simple.c b/mappers/simple.c deleted file mode 100644 index 8310fbb..0000000 --- a/mappers/simple.c +++ /dev/null @@ -1,88 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 1998 BERO - * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#include "mapinc.h" - -static uint8 latche; - -static DECLFW(Mapper34_write) -{ - switch(A) - { - case 0x7FFD:ROM_BANK32(V);break; - case 0x7FFE:VROM_BANK4(0x0000,V);break; - case 0x7fff:VROM_BANK4(0x1000,V);break; - } - if(A>=0x8000) - ROM_BANK32(V); -} - -void Mapper34_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x7ffd,0xffff,Mapper34_write); -} - -/* I might want to add some code to the mapper 96 PPU hook function - to not change CHR banks if the attribute table is being accessed, - if I make emulation a little more accurate in the future. -*/ - -static uint8 M96LA; -static DECLFW(Mapper96_write) -{ - latche=V; - setprg32(0x8000,V&3); - setchr4r(0x10,0x0000,(latche&4)|M96LA); - setchr4r(0x10,0x1000,(latche&4)|3); -} - -static void M96Hook(uint32 A) -{ - if((A&0x3000)!=0x2000) return; - //if((A&0x3ff)>=0x3c0) return; - M96LA=(A>>8)&3; - setchr4r(0x10,0x0000,(latche&4)|M96LA); -} - -static void M96Sync(int v) -{ - setprg32(0x8000,latche&3); - setchr4r(0x10,0x0000,(latche&4)|M96LA); - setchr4r(0x10,0x1000,(latche&4)|3); -} - -void Mapper96_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper96_write); - PPU_hook=M96Hook; - AddExState(&latche, 1, 0, "LATC"); - AddExState(&M96LA, 1, 0, "LAVA"); - SetupCartCHRMapping(0x10, MapperExRAM, 32768, 1); - latche=M96LA=0; - M96Sync(0); - setmirror(MI_0); - GameStateRestore=M96Sync; -} - -// DIS23C01 Open Soft, Korea -// Metal Force (K) -// Buzz and Waldog (K) diff --git a/unif.c b/unif.c index 6354131..362ec92 100644 --- a/unif.c +++ b/unif.c @@ -318,132 +318,163 @@ static int LoadCHR(int fp) static BMAPPING bmap[] = { - /* Sachen Carts */ - { "TC-U01-1.5M", TCU01_Init,0}, - { "Sachen-8259A", S8259A_Init,0}, - { "Sachen-8259B", S8259B_Init,0}, - { "Sachen-8259C", S8259C_Init,0}, - { "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}, - - // /* AVE carts. */ - // { "MB-91", MB91_Init,0}, // DeathBots - // { "NINA-06", NINA06_Init,0}, // F-15 City War - // { "NINA-03", NINA03_Init,0}, // Tiles of Fate - // { "NINA-001", NINA001_Init,0}, // Impossible Mission 2 - - { "ANROM", ANROM_Init,0}, - - { "HKROM", HKROM_Init,0}, - - { "EWROM", EWROM_Init,0}, - { "EKROM", EKROM_Init,0}, - { "ELROM", ELROM_Init,0}, - { "ETROM", ETROM_Init,0}, - - { "SAROM", SAROM_Init,0}, - { "SBROM", SBROM_Init,0}, - { "SCROM", SCROM_Init,0}, - { "SEROM", SEROM_Init,0}, - { "SGROM", SGROM_Init,0}, - { "SKROM", SKROM_Init,0}, - { "SLROM", SLROM_Init,0}, - { "SL1ROM", SL1ROM_Init,0}, - { "SNROM", SNROM_Init,0}, - { "SOROM", SOROM_Init,0}, - - { "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}, - { "TKROM", TKROM_Init,0}, - { "TSROM", TSROM_Init,0}, - - { "TLSROM", TLSROM_Init,0}, - { "TKSROM", TKSROM_Init,0}, - { "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 }, - { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 }, - { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 }, - { "RROM", NROM_Init,0 }, //NROM128_Init,0 }, - { "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}, - { "KOF97", UNLKOF97_Init,0}, - { "SL1632", UNLSL1632_Init,0}, - { "SHERO", UNLSHeroes_Init,0}, - { "8237", UNL8237_Init,0}, - { "8237A", UNL8237A_Init,0}, - { "8157", UNL8157_Init,0}, - { "T-262", BMCT262_Init,0}, - { "FK23C", BMCFK23C_Init,0}, - { "A65AS", BMCA65AS_Init,0}, - { "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}, - { "64in1NoRepeat", BMC64in1nr_Init, 0}, - { "13in1JY110", BMC13in1JY110_Init, 0}, - { "70in1", BMC70in1_Init, 0}, - { "70in1B", BMC70in1B_Init, 0}, - { "D1038", BMCD1038_Init, 0}, - { "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}, - - { "DANCE", UNLDANCE_Init,0}, - { "OneBus", UNLOneBus_Init,0}, - { "SC-127", UNLSC127_Init,0}, - - { "TEK90", Mapper90_Init,0}, - +/* Sachen Carts */ + { "TC-U01-1.5M", TCU01_Init,0}, + { "Sachen-8259A", S8259A_Init,0}, + { "Sachen-8259B", S8259B_Init,0}, + { "Sachen-8259C", S8259C_Init,0}, + { "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}, + { "SA-9602B", SA9602B_Init, BMCFLAG_32KCHRR}, + +// /* AVE carts. */ +// { "MB-91", MB91_Init,0}, // DeathBots +// { "NINA-06", NINA06_Init,0}, // F-15 City War +// { "NINA-03", NINA03_Init,0}, // Tiles of Fate +// { "NINA-001", NINA001_Init,0}, // Impossible Mission 2 + + { "ANROM", ANROM_Init,0}, + + { "HKROM", HKROM_Init,0}, + + { "EWROM", EWROM_Init,0}, + { "EKROM", EKROM_Init,0}, + { "ELROM", ELROM_Init,0}, + { "ETROM", ETROM_Init,0}, + + { "SAROM", SAROM_Init,0}, + { "SBROM", SBROM_Init,0}, + { "SCROM", SCROM_Init,0}, + { "SEROM", SEROM_Init,0}, + { "SGROM", SGROM_Init,0}, + { "SKROM", SKROM_Init,0}, + { "SLROM", SLROM_Init,0}, + { "SL1ROM", SL1ROM_Init,0}, + { "SNROM", SNROM_Init,0}, + { "SOROM", SOROM_Init,0}, + + { "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}, + { "TKROM", TKROM_Init,0}, + { "TSROM", TSROM_Init,0}, + + { "TLSROM", TLSROM_Init,0}, + { "TKSROM", TKSROM_Init,0}, + { "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 }, + { "NROM-128", NROM_Init,0 }, //NROM128_Init,0 }, + { "NROM-256", NROM_Init,0 }, //NROM256_Init,0 }, + { "SSS-NROM-256", SSSNROM_Init,0 }, + { "RROM", NROM_Init,0 }, //NROM128_Init,0 }, + { "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}, + { "LE05", LE05_Init,0}, + { "AC08", AC08_Init,0}, + { "LH10", LH10_Init,0}, + { "LH32", LH32_Init,0}, + { "LH53", LH53_Init,0}, + { "BB", UNLBB_Init,0}, + + { "H2288", UNLH2288_Init,0}, + { "KOF97", UNLKOF97_Init,0}, + { "SL1632", UNLSL1632_Init,0}, + { "SL12", UNLSL12_Init,0}, + { "SHERO", UNLSHeroes_Init,0}, + { "8237", UNL8237_Init,0}, + { "8237A", UNL8237A_Init,0}, + { "8157", UNL8157_Init,0}, + { "T-262", BMCT262_Init,0}, { "FK23C", BMCFK23C_Init,BMCFLAG_EXPCHRR}, { "FK23CA", BMCFK23CA_Init,BMCFLAG_EXPCHRR}, - - {0,0,0} + { "A65AS", BMCA65AS_Init,0}, + { "YOKO", UNLYOKO_Init,0}, + { "FS304", UNLFS304_Init,0}, + { "43272", UNL43272_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}, + { "64in1NoRepeat", BMC64in1nr_Init, 0}, + { "42in1ResetSwitch", Mapper226_Init, 0}, + { "13in1JY110", BMC13in1JY110_Init, 0}, + { "70in1", BMC70in1_Init, 0}, + { "70in1B", BMC70in1B_Init, 0}, + { "D1038", BMCD1038_Init, 0}, + { "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}, + { "KS7057", UNLKS7057_Init, 0}, + { "KS7037", UNLKS7037_Init, 0}, + { "KS7030", UNLKS7030_Init, 0}, + { "KS7031", UNLKS7031_Init, 0}, + { "KS7032", UNLKS7032_Init, 0}, + { "KS7017", UNLKS7017_Init, 0}, + { "KS7012", UNLKS7012_Init, 0}, + { "KS7013B", UNLKS7013B_Init, 0}, + { "T-230", UNLT230_Init, 0}, + { "CITYFIGHT", UNLCITYFIGHT_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}, + { "PEC-586",UNLPEC586Init,0}, + { "12-IN-1",BMC12IN1_Init,0}, + { "VRC7", UNLVRC7_Init,0}, + { "810544-C-A1", BMC810544CA1_Init,0}, + { "NTD-03", BMCNTD03_Init,0}, + + { "DREAMTECH01", DreamTech01_Init,0}, + { "KONAMI-QTAI", Mapper190_Init,0}, + + { "DANCE", UNLOneBus_Init,0}, // redundant + { "OneBus", UNLOneBus_Init,0}, + { "SC-127", UNLSC127_Init,0}, + { "DANCE2000", UNLD2000_Init,0}, + { "Transformer", Transformer_Init, 0}, + + { "TEK90", Mapper90_Init,0}, + +#ifdef COPYFAMI + { "COPYFAMI_MMC3", MapperCopyFamiMMC3_Init,0}, + { "COPYFAMI", MapperCopyFami_Init,0}, +#endif + + {0,0,0} }; static BFMAPPING bfunc[] = { diff --git a/unif.h b/unif.h index 2a179ea..65a0afd 100644 --- a/unif.h +++ b/unif.h @@ -1,133 +1,165 @@ -/* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ - -void ANROM_Init(CartInfo *info); - -void HKROM_Init(CartInfo *info); - -void ETROM_Init(CartInfo *info); -void EKROM_Init(CartInfo *info); -void ELROM_Init(CartInfo *info); -void EWROM_Init(CartInfo *info); - -void SAROM_Init(CartInfo *info); -void SBROM_Init(CartInfo *info); -void SCROM_Init(CartInfo *info); -void SEROM_Init(CartInfo *info); -void SGROM_Init(CartInfo *info); -void SKROM_Init(CartInfo *info); -void SLROM_Init(CartInfo *info); -void SL1ROM_Init(CartInfo *info); -void SNROM_Init(CartInfo *info); -void SOROM_Init(CartInfo *info); - -void NROM_Init(CartInfo *info); -void MHROM_Init(CartInfo *info); -void UNROM_Init(CartInfo *info); -void SUNSOFT_UNROM_Init(CartInfo *info); // "Shanghi" original version mapper -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); -void TKROM_Init(CartInfo *info); -void TSROM_Init(CartInfo *info); -void TLROM_Init(CartInfo *info); -void TLSROM_Init(CartInfo *info); -void TKSROM_Init(CartInfo *info); -void TQROM_Init(CartInfo *info); -void TQROM_Init(CartInfo *info); - -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); -void S8259D_Init(CartInfo *info); -void S74LS374N_Init(CartInfo *info); -void S74LS374NA_Init(CartInfo *info); -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); - -void Supervision16_Init(CartInfo *info); -void Super24_Init(CartInfo *info); -void Novel_Init(CartInfo *info); - -void BMC64in1nr_Init(CartInfo *info); -void BMC70in1_Init(CartInfo *info); -void BMC70in1B_Init(CartInfo *info); -void BMC13in1JY110_Init(CartInfo *info); -void BMCT262_Init(CartInfo *info); -void BMCFK23C_Init(CartInfo *info); -void BMCFK23CA_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); -void UNLCC21_Init(CartInfo *info); -void UNLCN22M_Init(CartInfo *info); -void UNLSL1632_Init(CartInfo *info); -void UNLKOF97_Init(CartInfo *info); -void UNLA9746_Init(CartInfo *info); -void UNLSHeroes_Init(CartInfo *info); -void UNLH2288_Init(CartInfo *info); -void UNL8237_Init(CartInfo *info); -void UNL8237A_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 UNLDANCE_Init(CartInfo *info); -void UNLOneBus_Init(CartInfo *info); -void UNLSC127_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); - -extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM - // bank switcherooing with certain boards... +/* 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 + */ + +void ANROM_Init(CartInfo *info); + +void HKROM_Init(CartInfo *info); + +void ETROM_Init(CartInfo *info); +void EKROM_Init(CartInfo *info); +void ELROM_Init(CartInfo *info); +void EWROM_Init(CartInfo *info); + +void SAROM_Init(CartInfo *info); +void SBROM_Init(CartInfo *info); +void SCROM_Init(CartInfo *info); +void SEROM_Init(CartInfo *info); +void SGROM_Init(CartInfo *info); +void SKROM_Init(CartInfo *info); +void SLROM_Init(CartInfo *info); +void SL1ROM_Init(CartInfo *info); +void SNROM_Init(CartInfo *info); +void SOROM_Init(CartInfo *info); + +void NROM_Init(CartInfo *info); +void SSSNROM_Init(CartInfo *info); +void MHROM_Init(CartInfo *info); +void UNROM_Init(CartInfo *info); +void SUNSOFT_UNROM_Init(CartInfo *info); // "Shanghi" original version mapper +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); +void TKROM_Init(CartInfo *info); +void TSROM_Init(CartInfo *info); +void TLROM_Init(CartInfo *info); +void TLSROM_Init(CartInfo *info); +void TKSROM_Init(CartInfo *info); +void TQROM_Init(CartInfo *info); +void TQROM_Init(CartInfo *info); + +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); +void S8259D_Init(CartInfo *info); +void S74LS374N_Init(CartInfo *info); +void S74LS374NA_Init(CartInfo *info); +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); +void SA9602B_Init(CartInfo *info); + +void Supervision16_Init(CartInfo *info); +void Super24_Init(CartInfo *info); +void Novel_Init(CartInfo *info); + +void BMC64in1nr_Init(CartInfo *info); +void BMC70in1_Init(CartInfo *info); +void BMC70in1B_Init(CartInfo *info); +void BMC13in1JY110_Init(CartInfo *info); +void BMCT262_Init(CartInfo *info); +void BMCFK23C_Init(CartInfo *info); +void BMCFK23CA_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); +void UNLCC21_Init(CartInfo *info); +void UNLYOKO_Init(CartInfo *info); +void UNLFS304_Init(CartInfo *info); +void UNL43272_Init(CartInfo *info); +void UNLSL1632_Init(CartInfo *info); +void UNLSL12_Init(CartInfo *info); +void UNLKOF97_Init(CartInfo *info); +void UNLA9746_Init(CartInfo *info); +void UNLSHeroes_Init(CartInfo *info); +void UNLH2288_Init(CartInfo *info); +void UNL8237_Init(CartInfo *info); +void UNL8237A_Init(CartInfo *info); +void UNL8157_Init(CartInfo *info); +void UNL22211_Init(CartInfo *info); +void UNLTF1201_Init(CartInfo *info); +void UNLKS7057_Init(CartInfo *info); +void UNLKS7037_Init(CartInfo *info); +void UNLKS7032_Init(CartInfo *info); +void UNLKS7031_Init(CartInfo *info); +void UNLKS7030_Init(CartInfo *info); +void UNLKS7017_Init(CartInfo *info); +void UNLKS7012_Init(CartInfo *info); +void UNLKS7013B_Init(CartInfo *info); +void UNLT230_Init(CartInfo *info); +void UNLCITYFIGHT_Init(CartInfo *info); +void UNLAX5705_Init(CartInfo *info); +void UNLDANCE_Init(CartInfo *info); +void UNLOneBus_Init(CartInfo *info); +void UNLSC127_Init(CartInfo *info); +void UNLPEC586Init(CartInfo *info); +void UNLVRC7_Init(CartInfo *info); +void UNLD2000_Init(CartInfo *info); +void BMC810544CA1_Init(CartInfo *info); +void BMCNTD03_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 BMC12IN1_Init(CartInfo *info); +void BMC42in1r_Init(CartInfo *info); +void Transformer_Init(CartInfo *info); +void LE05_Init(CartInfo *info); +void AC08_Init(CartInfo *info); +void LH10_Init(CartInfo *info); +void LH32_Init(CartInfo *info); +void LH53_Init(CartInfo *info); +void UNLBB_Init(CartInfo *info); + +#ifdef COPYFAMI +void MapperCopyFamiMMC3_Init(CartInfo *info); +void MapperCopyFami_Init(CartInfo *info); +#endif + +extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM + // bank switcherooing with certain boards...