From e2d0dd92bfad989cce4270fc0ac5a712476c7c50 Mon Sep 17 00:00:00 2001 From: notaz Date: Thu, 24 May 2007 21:10:39 +0000 Subject: [PATCH] mappers updated to 0.98.16 git-svn-id: file:///home/notaz/opt/svn/fceu@135 be3aeb3a-fb24-0410-a615-afba39da0efa --- Makefile.beos | 23 - Makefile.dos | 23 - Makefile.gp2x | 2 +- Makefile.linuxvga | 22 - Makefile.unixsdl | 25 - Makefile.win | 22 - boards/112.c | 3 +- boards/117.c | 101 ++++ boards/164.c | 12 +- boards/183.c | 234 ++++---- boards/185.c | 116 ++++ boards/186.c | 208 +++---- boards/187.c | 104 ++++ mappers/57.c => boards/189.c | 41 +- {mappers => boards}/208.c | 110 +--- boards/222.c | 99 ++++ boards/235.c | 70 +++ boards/57.c | 93 ++++ boards/8157.c | 157 +++--- boards/88.c | 87 +++ boards/90.c | 308 ++++++----- boards/95.c | 124 +++++ boards/Makefile | 55 +- boards/__dummy_mapper.c | 97 ++++ boards/bmc13in1jy110.c | 103 ++++ boards/bmc42in1r.c | 87 +++ boards/bmc64in1nr.c | 93 ++++ boards/bmc70in1.c | 116 ++++ mappers/235.c => boards/bmcgk192.c | 61 ++- boards/bonza.c | 278 +++++----- boards/{addrlatch.c => cc21.c} | 109 ++-- boards/datalatch.c | 253 +++++---- boards/dream.c | 112 ++-- boards/fk23c.c | 112 ++++ boards/h2288.c | 178 +++--- boards/karaoke.c | 43 +- mappers/58.c => boards/kof97.c | 39 +- boards/konami-qtai.c | 256 ++++----- boards/malee.c | 2 +- boards/mapinc.h | 1 + boards/mmc1.c | 849 ++++++++++++++--------------- boards/mmc3.c | 368 ++++++++++--- boards/mmc3.h | 45 +- boards/sachen.c | 127 +++-- boards/sheroes.c | 86 +++ boards/sl1632.c | 159 ++++++ boards/sonic5.c | 73 +++ boards/subor.c | 158 +++--- boards/super24.c | 240 ++++---- boards/supervision.c | 34 +- boards/t-262.c | 83 +++ boards/tengen.c | 186 +++---- drivers/gp2x/main.c | 2 +- ines-correct.h | 63 ++- ines.c | 124 +++-- ines.h | 110 ++-- mappers/117.c | 70 --- mappers/16.c | 6 +- mappers/187.c | 170 ------ mappers/189.c | 55 -- mappers/204.c | 76 +-- mappers/211.c | 146 ----- mappers/212.c | 46 +- mappers/213.c | 28 +- mappers/214.c | 34 +- mappers/255.c | 2 +- mappers/27.c | 148 ++--- mappers/6.c | 160 +++--- mappers/62.c | 2 +- mappers/68.c | 1 + mappers/83.c | 19 +- mappers/88.c | 62 --- mappers/95.c | 136 ----- mappers/Makefile | 94 +++- mappers/mapinc.h | 1 - mappers/simple.c | 242 -------- sound.h | 2 + unif.c | 34 +- unif.h | 62 ++- 79 files changed, 4784 insertions(+), 3498 deletions(-) delete mode 100644 Makefile.beos delete mode 100644 Makefile.dos delete mode 100644 Makefile.linuxvga delete mode 100644 Makefile.unixsdl delete mode 100644 Makefile.win create mode 100644 boards/117.c create mode 100644 boards/185.c create mode 100644 boards/187.c rename mappers/57.c => boards/189.c (59%) rename {mappers => boards}/208.c (62%) create mode 100644 boards/222.c create mode 100644 boards/235.c create mode 100644 boards/57.c create mode 100644 boards/88.c create mode 100644 boards/95.c create mode 100644 boards/__dummy_mapper.c create mode 100644 boards/bmc13in1jy110.c create mode 100644 boards/bmc42in1r.c create mode 100644 boards/bmc64in1nr.c create mode 100644 boards/bmc70in1.c rename mappers/235.c => boards/bmcgk192.c (51%) rename boards/{addrlatch.c => cc21.c} (91%) create mode 100644 boards/fk23c.c rename mappers/58.c => boards/kof97.c (56%) create mode 100644 boards/sheroes.c create mode 100644 boards/sl1632.c create mode 100644 boards/sonic5.c create mode 100644 boards/t-262.c delete mode 100644 mappers/117.c delete mode 100644 mappers/187.c delete mode 100644 mappers/189.c delete mode 100644 mappers/211.c delete mode 100644 mappers/88.c delete mode 100644 mappers/95.c diff --git a/Makefile.beos b/Makefile.beos deleted file mode 100644 index 0537114..0000000 --- a/Makefile.beos +++ /dev/null @@ -1,23 +0,0 @@ -CC = gcc -TFLAGS = -no-fpic -DC80x86 -DNETWORK -DFPS `sdl-config --cflags` -mcpu=i686 -O2 -Izlib -fomit-frame-pointer -DLSB_FIRST -DSDL -DUNIX -DPSS_STYLE=1 -DZLIB -RM = rm -f -B = drivers/cli/ - -all: fceu - -include zlib/Makefile - -OBJDRIVER = ${B}sdl.o ${B}main.o ${B}throttle.o ${B}sdl-netplay.o ${B}sdl-sound.o ${B}sdl-video.o ${B}sdl-joystick.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o drivers/common/vidblit.o ${UNZIPOBJS} -LDRIVER = -static `sdl-config --libs` -lz -lSDL_net - -include Makefile.base - -${B}sdl-joystick.o: ${B}sdl-joystick.c -${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c ${B}keyscan.h -${B}sdl.o: ${B}sdl.c ${B}sdl.h -${B}sdl-video.o: ${B}sdl-video.c -${B}sdl-sound.o: ${B}sdl-sound.c -${B}sdl-netplay.o: ${B}sdl-netplay.c -${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h - -include Makefile.common diff --git a/Makefile.dos b/Makefile.dos deleted file mode 100644 index bef31aa..0000000 --- a/Makefile.dos +++ /dev/null @@ -1,23 +0,0 @@ -CC = gcc -TFLAGS = -O2 -mcpu=i686 -Izlib -fomit-frame-pointer -DC80x86 -DLSB_FIRST -DDOS -DPSS_STYLE=2 -DZLIB -D_USE_LIBM_MATH_H -RM = del -B = drivers/cli/ - -all: fceu - -include zlib/Makefile - -OBJDRIVER = ${B}main.o ${B}dos.o ${B}throttle.o ${B}dos-joystick.o ${B}dos-keyboard.o ${B}dos-mouse.o ${B}dos-sound.o ${B}dos-video.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o ${ZLIBOBJS} ${UNZIPOBJS} -LDRIVER = -lm - -include Makefile.base - -${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c -${B}dos.o: ${B}dos.c ${B}dos.h -${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h -${B}dos-joystick.o: ${B}dos-joystick.c ${B}dos.h ${B}dos-joystick.h -${B}dos-keyboard.o: ${B}dos-keyboard.c ${B}keyscan.h -${B}dos-mouse.o: ${B}dos-mouse.c -${B}dos-sound.o: ${B}dos-sound.c ${B}dos.h ${B}dos-sound.h ${B}dos-joystick.h -${B}dos-video.o: ${B}dos-video.c ${B}dos.h ${B}dos-video.h -include Makefile.common diff --git a/Makefile.gp2x b/Makefile.gp2x index 40d3c4f..0b17061 100644 --- a/Makefile.gp2x +++ b/Makefile.gp2x @@ -72,7 +72,7 @@ ${B}rev.h: FORCE include Makefile.common up: fceu - cp -v fceu /mnt/gp2x/mnt/sd/emus/Gpfce_v02/gpfce + cp -v fceu /mnt/gp2x/mnt/sd/emus/gpfce/gpfce # ----------- release ----------- ifneq ($(findstring rel,$(MAKECMDGOALS)),) diff --git a/Makefile.linuxvga b/Makefile.linuxvga deleted file mode 100644 index a123168..0000000 --- a/Makefile.linuxvga +++ /dev/null @@ -1,22 +0,0 @@ -CC = gcc -TFLAGS = -DFPS -mcpu=i686 -O2 -Izlib -fomit-frame-pointer -DC80x86 -DLSB_FIRST -DSVGALIB -DUNIX -DLINUX -DNETWORK -DPSS_STYLE=1 -DZLIB -RM = rm -f -B = drivers/cli/ - -all: fceu - -include zlib/Makefile - -OBJDRIVER = ${B}svgalib.o ${B}main.o ${B}throttle.o ${B}svga-video.o ${B}unix-netplay.o ${B}lnx-joystick.o drivers/common/unixdsp.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o ${ZLIBOBJS} ${UNZIPOBJS} -LDRIVER = -lm -lvga - -include Makefile.base - -${B}lnx-joystick.o: ${B}lnx-joystick.c -${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c -${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h -${B}svgalib.o: ${B}svgalib.c ${B}svgalib.h -${B}svga-video.o: ${B}svga-video.c ${B}svga-video.h ${B}vgatweak.c -${B}unix-netplay.o: ${B}unix-netplay.c - -include Makefile.common diff --git a/Makefile.unixsdl b/Makefile.unixsdl deleted file mode 100644 index d8122d9..0000000 --- a/Makefile.unixsdl +++ /dev/null @@ -1,25 +0,0 @@ -CC = gcc -TFLAGS = -DNETWORK -DFPS `sdl-config --cflags` -mcpu=i686 -O2 -Izlib -fomit-frame-pointer -DC80x86 -DLSB_FIRST -DSDL -DUNIX -DPSS_STYLE=1 -DZLIB - -RM = rm -f -B = drivers/cli/ - -all: fceu - -include zlib/Makefile - -OBJDRIVER = ${B}sdl.o ${B}main.o ${B}throttle.o ${B}unix-netplay.o ${B}sdl-sound.o ${B}sdl-video.o ${B}sdl-joystick.o drivers/common/cheat.o drivers/common/config.o drivers/common/args.o drivers/common/vidblit.o ${UNZIPOBJS} -LDRIVER = -lm `sdl-config --libs` -lz - -include Makefile.base - -${B}sdl-joystick.o: ${B}sdl-joystick.c -${B}main.o: ${B}main.c ${B}main.h ${B}usage.h ${B}input.c ${B}keyscan.h -${B}sdl.o: ${B}sdl.c ${B}sdl.h -${B}sdl-video.o: ${B}sdl-video.c -${B}sdl-sound.o: ${B}sdl-sound.c -#${B}sdl-netplay.o: ${B}sdl-netplay.c -${B}unix-netplay.o: ${B}unix-netplay.c -${B}throttle.o: ${B}throttle.c ${B}main.h ${B}throttle.h - -include Makefile.common diff --git a/Makefile.win b/Makefile.win deleted file mode 100644 index 1767c71..0000000 --- a/Makefile.win +++ /dev/null @@ -1,22 +0,0 @@ -CC = gcc -TFLAGS = -mcpu=i686 -O2 -Izlib -fomit-frame-pointer -DNOSTDOUT -DC80x86 -DLSB_FIRST -DWINDOWS -DNETWORK -DPSS_STYLE=2 -DZLIB -RM = del -B = drivers/win/ -all: fceu - -include zlib/Makefile - -LDRIVER = -mwindows -lddraw -ldinput -ldsound -lgdi32 -ldxguid -lwinmm -lshell32 -lwsock32 -lcomdlg32 -lole32 -OBJDRIVER = ${B}main.o ${B}input.o ${B}joystick.o ${B}keyboard.o ${B}cheat.o ${B}res.o ${ZLIBOBJS} ${UNZIPOBJS} drivers/common/config.o - -include Makefile.base - -${B}main.o: ${B}main.c drivers/win/netplay.c ${B}config.c ${B}throttle.c ${B}video.c drivers/win/window.c drivers/win/sound.c drivers/win/wave.c -${B}cheat.o: ${B}common.h ${B}cheat.h -${B}input.o: ${B}common.h ${B}input.h ${B}joystick.h ${B}keyboard.h -${B}joystick.o: ${B}common.h ${B}joystick.h ${B}input.h -${B}keyboard.o: ${B}common.h ${B}keyboard.h ${B}input.h -drivers/win/res.o: drivers/win/res.res - windres -o drivers/win/res.o drivers/win/res.res - -include Makefile.common diff --git a/boards/112.c b/boards/112.c index a58cf5c..2bb1e4b 100644 --- a/boards/112.c +++ b/boards/112.c @@ -23,6 +23,7 @@ static uint8 reg[8]; static uint8 mirror, cmd; static uint8 *WRAM=NULL; + static SFORMAT StateRegs[]= { {&cmd, 1, "CMD"}, @@ -52,6 +53,7 @@ static DECLFW(M112Write) case 0x8000: cmd=V&7; break; case 0xa000: reg[cmd]=V; Sync(); break; } +FCEU_printf("%04x:%04x %d\n",A,V,scanline); } static void M112Close(void) @@ -63,7 +65,6 @@ static void M112Close(void) static void M112Power(void) { - Sync(); setprg16(0xC000,~0); setprg8r(0x10,0x6000,0); SetReadHandler(0x8000,0xFFFF,CartBR); diff --git a/boards/117.c b/boards/117.c new file mode 100644 index 0000000..6746015 --- /dev/null +++ b/boards/117.c @@ -0,0 +1,101 @@ +/* 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 prgreg[4], chrreg[8]; +static uint8 IRQa, IRQCount, IRQLatch; + +static SFORMAT StateRegs[]= +{ + {&IRQa, 1, "IRQA"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {prgreg, 4, "PREGS"}, + {chrreg, 8, "CREGS"}, + {0} +}; + +static void Sync(void) +{ + 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]); +} + +static DECLFW(M117Write) +{ + if(A<0x8004) + { + prgreg[A&3]=V; + Sync(); + } + else if((A>=0xA000)&&(A<=0xA007)) + { + chrreg[A&7]=V; + Sync(); + } + else switch(A) + { + case 0xc001: IRQLatch=V; break; + case 0xc003: IRQCount=IRQLatch; IRQa|=2; break; + case 0xe000: IRQa&=~1; IRQa|=V&1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xc002: X6502_IRQEnd(FCEU_IQEXT); break; + } +} + +static void M117Power(void) +{ + prgreg[0]=~3; prgreg[1]=~2; prgreg[2]=~1; prgreg[3]=~0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M117Write); +} + +static void M117IRQHook(void) +{ + if(IRQa==3&&IRQCount) + { + IRQCount--; + if(!IRQCount) + { + IRQa&=1; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper117_Init(CartInfo *info) +{ + info->Power=M117Power; + GameHBIRQHook=M117IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + diff --git a/boards/164.c b/boards/164.c index 5b4bf05..0bb85b3 100644 --- a/boards/164.c +++ b/boards/164.c @@ -22,7 +22,6 @@ static uint8 cmd; static uint8 DRegs[8]; - static SFORMAT StateRegs[]= { {&cmd, 1, "CMD"}, @@ -33,6 +32,7 @@ static SFORMAT StateRegs[]= static void Sync(void) { setprg32(0x8000,(DRegs[0]<<4)|(DRegs[1]&0xF)); + setchr8(0); } static void StateRestore(int version) @@ -73,7 +73,6 @@ static void Power(void) { memset(DRegs,0,8); DRegs[1]=0xFF; - setchr8(0); cmd=0; SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x4020,0xFFFF,Write); @@ -82,11 +81,17 @@ static void Power(void) Sync(); } +static void M163HB(void) +{ + if(scanline==127&&DRegs[1]&0x80) + setchr4(0x0000,1); +} + + static void Power2(void) { memset(DRegs,0,8); DRegs[1]=0xFF; - setchr8(0); cmd=0; SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x4020,0xFFFF,Write2); @@ -105,6 +110,7 @@ void Mapper164_Init(CartInfo *info) void Mapper163_Init(CartInfo *info) { info->Power=Power2; + GameHBIRQHook=M163HB; GameStateRestore=StateRestore; AddExState(&StateRegs, ~0, 0, 0); } diff --git a/boards/183.c b/boards/183.c index 94cf072..5e80a6b 100644 --- a/boards/183.c +++ b/boards/183.c @@ -1,117 +1,117 @@ -/* 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 - * - * Gimmick Bootleg - */ - -#include "mapinc.h" - -static uint8 prg[4]; -static uint8 chr[8]; -static uint8 IRQCount; -static uint8 IRQPre; -static uint8 IRQa; - -static SFORMAT StateRegs[]= -{ - {prg, 4, "PRG"}, - {chr, 8, "CHR"}, - {&IRQCount, 1, "IRQCOUNT"}, - {&IRQPre, 1, "IRQPRE"}, - {&IRQa, 1, "IRQA"}, - {0} -}; - -static void SyncPrg(void) -{ - setprg8(0x6000,0); - setprg8(0x8000,prg[0]); - setprg8(0xA000,prg[1]); - setprg8(0xC000,prg[2]); - setprg8(0xE000,~0); -} - -static void SyncChr(void) -{ - int i; - for(i=0; i<8; i++) - setchr1(i<<10,chr[i]); -} - -static void StateRestore(int version) -{ - SyncPrg(); - SyncChr(); -} - -static DECLFW(M183Write) -{ - if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) - { - uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3); - chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4)); - SyncChr(); - } - else switch (A&0xF80C) - { - case 0x8800: prg[0]=V; SyncPrg(); break; - case 0xA800: prg[1]=V; SyncPrg(); break; - case 0xA000: prg[2]=V; SyncPrg(); break; - case 0x9800: switch (V&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; - } - break; - case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break; - case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break; - case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; - case 0xF00C: IRQPre=16; break; - } -} - -static void M183IRQCounter(void) -{ - if(IRQa) - { - IRQCount++; - if((IRQCount-IRQPre)==238) - X6502_IRQBegin(FCEU_IQEXT); - } -} - -static void M183Power(void) -{ - IRQPre=IRQCount=IRQa=0; - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M183Write); - SetReadHandler(0x6000,0x7FFF,CartBR); - SyncPrg(); - SyncChr(); -} - -void Mapper183_Init(CartInfo *info) -{ - info->Power=M183Power; - GameHBIRQHook=M183IRQCounter; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Gimmick Bootleg + */ + +#include "mapinc.h" + +static uint8 prg[4]; +static uint8 chr[8]; +static uint8 IRQCount; +static uint8 IRQPre; +static uint8 IRQa; + +static SFORMAT StateRegs[]= +{ + {prg, 4, "PRG"}, + {chr, 8, "CHR"}, + {&IRQCount, 1, "IRQCOUNT"}, + {&IRQPre, 1, "IRQPRE"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void SyncPrg(void) +{ + setprg8(0x6000,0); + setprg8(0x8000,prg[0]); + setprg8(0xA000,prg[1]); + setprg8(0xC000,prg[2]); + setprg8(0xE000,~0); +} + +static void SyncChr(void) +{ + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr[i]); +} + +static void StateRestore(int version) +{ + SyncPrg(); + SyncChr(); +} + +static DECLFW(M183Write) +{ + if(((A&0xF80C)>=0xB000)&&((A&0xF80C)<=0xE00C)) + { + uint8 index=(((A&0x7000)>>11)-6)|((A&8)>>3); + chr[index]=(chr[index]&(0xF0>>(A&4)))|((V&0x0F)<<(A&4)); + SyncChr(); + } + else switch (A&0xF80C) + { + case 0x8800: prg[0]=V; SyncPrg(); break; + case 0xA800: prg[1]=V; SyncPrg(); break; + case 0xA000: prg[2]=V; SyncPrg(); break; + case 0x9800: switch (V&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; + } + break; + case 0xF000: IRQCount=((IRQCount&0xF0)|(V&0xF)); break; + case 0xF004: IRQCount=((IRQCount&0x0F)|((V&0xF)<<4)); break; + case 0xF008: IRQa=V; if(!V)IRQPre=0; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xF00C: IRQPre=16; break; + } +} + +static void M183IRQCounter(void) +{ + if(IRQa) + { + IRQCount++; + if((IRQCount-IRQPre)==238) + X6502_IRQBegin(FCEU_IQEXT); + } +} + +static void M183Power(void) +{ + IRQPre=IRQCount=IRQa=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M183Write); + SetReadHandler(0x6000,0x7FFF,CartBR); + SyncPrg(); + SyncChr(); +} + +void Mapper183_Init(CartInfo *info) +{ + info->Power=M183Power; + GameHBIRQHook=M183IRQCounter; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/185.c b/boards/185.c new file mode 100644 index 0000000..49b63dc --- /dev/null +++ b/boards/185.c @@ -0,0 +1,116 @@ +/* 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 + * + * Family Study Box by Fukutake Shoten + */ + +#include "mapinc.h" + +static uint8 *DummyCHR=NULL; +static uint8 datareg; +static void(*Sync)(void); + + +static SFORMAT StateRegs[]= +{ + {&datareg, 1, "DREG"}, + {0} +}; + +// on off +//1 0x0F, 0xF0 - Bird Week +//2 0x33, 0x00 - B-Wings +//3 0x11, 0x00 - Mighty Bomb Jack +//4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen +//5 0xFF, 0x00 - Sansuu 3 Nen +//6 0x21, 0x13 - Spy vs Spy +//7 0x20, 0x21 - Seicross + +static void Sync185(void) +{ + // little dirty eh? ;_) + if((datareg&3)&&(datareg!=0x13)) // 1, 2, 3, 4, 5, 6 + setchr8(0); + else + setchr8r(0x10,0); +} + +static void Sync181(void) +{ + if(!(datareg&1)) // 7 + setchr8(0); + else + setchr8r(0x10,0); +} + +static DECLFW(MWrite) +{ + datareg=V; + Sync(); +} + +static void MPower(void) +{ + datareg=0; + Sync(); + setprg16(0x8000,0); + setprg16(0xC000,~0); + SetWriteHandler(0x8000,0xFFFF,MWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void MClose(void) +{ + if(DummyCHR) + FCEU_gfree(DummyCHR); + DummyCHR=NULL; +} + +static void MRestore(int version) +{ + Sync(); +} + +void Mapper185_Init(CartInfo *info) +{ + 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); + AddExState(StateRegs, ~0, 0, 0); +} + +void Mapper181_Init(CartInfo *info) +{ + 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); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/boards/186.c b/boards/186.c index 3698c6c..80b39d8 100644 --- a/boards/186.c +++ b/boards/186.c @@ -1,104 +1,104 @@ -/* 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 - * - * Family Study Box by Fukutake Shoten - */ - -#include "mapinc.h" - -static uint8 SWRAM[2816]; -static uint8 *WRAM=NULL; -static uint8 regs[4]; - -static SFORMAT StateRegs[]= -{ - {regs, 4, "DREG"}, - {SWRAM, 2816, "SWRAM"}, - {0} -}; - -static void Sync(void) -{ - setprg8r(0x10,0x6000,regs[0]>>6); - setprg16(0x8000,regs[1]); - setprg16(0xc000,0); -} - -static DECLFW(M186Write) -{ - if(A&0x4203) regs[A&3]=V; - Sync(); -} - -static DECLFR(M186Read) -{ - switch(A) - { - case 0x4200: return 0x00; break; - case 0x4201: return 0x00; break; - case 0x4202: return 0x40; break; - case 0x4203: return 0x00; break; - } - return 0xFF; -} - -static DECLFR(ASWRAM) -{ - return(SWRAM[A-0x4400]); -} -static DECLFW(BSWRAM) -{ - SWRAM[A-0x4400]=V; -} - -static void M186Power(void) -{ - setchr8(0); - SetReadHandler(0x6000,0xFFFF,CartBR); - SetWriteHandler(0x6000,0xFFFF,CartBW); - SetReadHandler(0x4200,0x43FF,M186Read); - SetWriteHandler(0x4200,0x43FF,M186Write); - SetReadHandler(0x4400,0x4EFF,ASWRAM); - SetWriteHandler(0x4400,0x4EFF,BSWRAM); - regs[0]=regs[1]=regs[2]=regs[3]; - Sync(); -} - -static void M186Close(void) -{ - if(WRAM) - FCEU_gfree(WRAM); - WRAM=NULL; -} - -static void M186Restore(int version) -{ - Sync(); -} - -void Mapper186_Init(CartInfo *info) -{ - info->Power=M186Power; - info->Close=M186Close; - GameStateRestore=M186Restore; - WRAM=(uint8*)FCEU_gmalloc(32384); - SetupCartPRGMapping(0x10,WRAM,32384,1); - AddExState(WRAM, 32384, 0, "WRAM"); - AddExState(StateRegs, ~0, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Family Study Box by Fukutake Shoten + */ + +#include "mapinc.h" + +static uint8 SWRAM[2816]; +static uint8 *WRAM=NULL; +static uint8 regs[4]; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "DREG"}, + {SWRAM, 2816, "SWRAM"}, + {0} +}; + +static void Sync(void) +{ + setprg8r(0x10,0x6000,regs[0]>>6); + setprg16(0x8000,regs[1]); + setprg16(0xc000,0); +} + +static DECLFW(M186Write) +{ + if(A&0x4203) regs[A&3]=V; + Sync(); +} + +static DECLFR(M186Read) +{ + switch(A) + { + case 0x4200: return 0x00; break; + case 0x4201: return 0x00; break; + case 0x4202: return 0x40; break; + case 0x4203: return 0x00; break; + } + return 0xFF; +} + +static DECLFR(ASWRAM) +{ + return(SWRAM[A-0x4400]); +} +static DECLFW(BSWRAM) +{ + SWRAM[A-0x4400]=V; +} + +static void M186Power(void) +{ + setchr8(0); + SetReadHandler(0x6000,0xFFFF,CartBR); + SetWriteHandler(0x6000,0xFFFF,CartBW); + SetReadHandler(0x4200,0x43FF,M186Read); + SetWriteHandler(0x4200,0x43FF,M186Write); + SetReadHandler(0x4400,0x4EFF,ASWRAM); + SetWriteHandler(0x4400,0x4EFF,BSWRAM); + regs[0]=regs[1]=regs[2]=regs[3]; + Sync(); +} + +static void M186Close(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + WRAM=NULL; +} + +static void M186Restore(int version) +{ + Sync(); +} + +void Mapper186_Init(CartInfo *info) +{ + info->Power=M186Power; + info->Close=M186Close; + GameStateRestore=M186Restore; + WRAM=(uint8*)FCEU_gmalloc(32384); + SetupCartPRGMapping(0x10,WRAM,32384,1); + AddExState(WRAM, 32384, 0, "WRAM"); + AddExState(StateRegs, ~0, 0, 0); +} diff --git a/boards/187.c b/boards/187.c new file mode 100644 index 0000000..0fa4a15 --- /dev/null +++ b/boards/187.c @@ -0,0 +1,104 @@ +/* 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" +#include "mmc3.h" + +static void M187CW(uint32 A, uint8 V) +{ + if((A&0x1000)==((MMC3_cmd&0x80)<<5)) + setchr1(A,V|0x100); + else + setchr1(A,V); +} + +static void M187PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { + 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(M187Write8000) +{ + EXPREGS[2]=1; + MMC3_CMDWrite(A,V); +} + +static DECLFW(M187Write8001) +{ + if(EXPREGS[2]) + 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) + { + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +static uint8 prot_data[4] = { 0x83, 0x83, 0x42, 0x00 }; +static DECLFR(M187Read) +{ + return prot_data[EXPREGS[1]&3]; +} + +static void M187Power(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; + GenMMC3Power(); + Write_IRQFM(0x4017,0x40); + SetReadHandler(0x5000,0x5FFF,M187Read); + SetWriteHandler(0x5000,0x5FFF,M187WriteLo); + SetWriteHandler(0x8000,0x8000,M187Write8000); + SetWriteHandler(0x8001,0x8001,M187Write8001); + SetWriteHandler(0x8003,0x8003,M187Write8003); +} + +void Mapper187_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M187PW; + cwrap=M187CW; + info->Power=M187Power; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/mappers/57.c b/boards/189.c similarity index 59% rename from mappers/57.c rename to boards/189.c index b64d270..23be63a 100644 --- a/mappers/57.c +++ b/boards/189.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel + * 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 @@ -19,31 +19,30 @@ */ #include "mapinc.h" +#include "mmc3.h" +static void M189PW(uint32 A, uint8 V) +{ + setprg32(0x8000,EXPREGS[0]&3); +} +static DECLFW(M189Write) +{ + EXPREGS[0]=V|(V>>4); //actually, there is a two versions of 189 mapper with hi or lo bits bankswitching. + FixMMC3PRG(MMC3_cmd); +} -static DECLFW(Mapper57_write) +static void M189Power(void) { - A&=0x8800; - if(A==0x8800) - { - mapbyte1[0]=V; - if(V&0x80) - ROM_BANK32(2|(V>>6)); - else - { - ROM_BANK16(0x8000,(V>>5)&3); - ROM_BANK16(0xc000,(V>>5)&3); - } - MIRROR_SET((V&0x8)>>3); - } - else - mapbyte1[1]=V; - VROM_BANK8((mapbyte1[1]&3)|(mapbyte1[0]&7)|((mapbyte1[0]&0x10)>>1)); - //printf("$%04x:$%02x\n",A,V); + EXPREGS[0]=EXPREGS[1]=0; + GenMMC3Power(); + SetWriteHandler(0x4120,0x7FFF,M189Write); } -void Mapper57_init(void) +void Mapper189_Init(CartInfo *info) { - SetWriteHandler(0x8000,0xffff,Mapper57_write); + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=M189PW; + info->Power=M189Power; + AddExState(EXPREGS, 2, 0, "EXPR"); } diff --git a/mappers/208.c b/boards/208.c similarity index 62% rename from mappers/208.c rename to boards/208.c index 29b7efe..9ccf8e7 100644 --- a/mappers/208.c +++ b/boards/208.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2003 Xodnizel + * 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 @@ -19,23 +19,9 @@ */ #include "mapinc.h" +#include "mmc3.h" -static uint8 PRGSel; -static uint8 PBuf[4],PSel; -static uint8 cmd; -static uint8 DRegs[8]; -static uint32 count=0; -static uint32 last=0; - -static DECLFW(M208Write1) -{ - PRGSel=(V&0x1)|((V>>3)&0x2); - setprg32(0x8000,PRGSel); -} - -static DECLFW(M208Write2) -{ - static uint8 lut[256]={ +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, @@ -52,88 +38,46 @@ static DECLFW(M208Write2) 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 +}; - }; - if(A<=0x57FF) PSel=V; - else - PBuf[(A&0x03)]=V^lut[PSel]; -} - -static DECLFR(M208Read) +static void M208PW(uint32 A, uint8 V) { - return(PBuf[(A&0x3)]); + setprg32(0x8000,EXPREGS[5]); } -static void Sync(void) +static DECLFW(M208Write) { - int x; - - setchr2(0x0000,DRegs[0]>>1); - setchr2(0x0800,DRegs[1]>>1); - for(x=0;x<4;x++) - setchr1(0x1000+x*0x400,DRegs[2+x]); + EXPREGS[5]=(V&0x1)|((V>>3)&0x2); + FixMMC3PRG(MMC3_cmd); } -static DECLFW(M208HWrite) +static DECLFW(M208ProtWrite) { - switch(A&0xe001) - { - case 0xc000:IRQLatch=IRQCount=V;break; - case 0xc001:IRQCount=IRQLatch;last=count=0;break; - case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xe001:IRQa=1;break; - case 0x8000:cmd=V;break; - case 0x8001:DRegs[cmd&7]=V; - Sync(); - break; - - } + if(A<=0x57FF) + EXPREGS[4]=V; + else + EXPREGS[(A&0x03)]=V^lut[EXPREGS[4]]; } -static void M208Power(void) +static DECLFR(M208ProtRead) { - PRGSel=3; - setprg32(0x8000,3); - SetWriteHandler(0x4800,0x4FFF,M208Write1); - SetWriteHandler(0x5000,0x5fff,M208Write2); - SetWriteHandler(0x8000,0xFFFF,M208HWrite); - SetReadHandler(0x5800,0x5FFF,M208Read); - SetReadHandler(0x8000,0xffff,CartBR); + return(EXPREGS[(A&0x3)]); } -static void sl(void) -{ - if(IRQa) - { - if(IRQCount>=0) - { - IRQCount--; - if(IRQCount<0) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void FP_FASTAPASS(1) foo(uint32 A) +static void M208Power(void) { - if((A&0x2000) && !(last&0x2000)) - { - count++; - if(count==42) - { - sl(); - count=0; - } - } - last=A; + EXPREGS[5]=3; + GenMMC3Power(); + SetWriteHandler(0x4800,0x4FFF,M208Write); + SetWriteHandler(0x5000,0x5fff,M208ProtWrite); + SetReadHandler(0x5800,0x5FFF,M208ProtRead); + SetReadHandler(0x8000,0xffff,CartBR); } void Mapper208_Init(CartInfo *info) { - info->Power=M208Power; - //GameHBIRQHook=sl; - PPU_hook=foo; + GenMMC3_Init(info, 128, 256, 0, 0); + pwrap=M208PW; + info->Power=M208Power; + AddExState(EXPREGS, 6, 0, "EXPR"); } - diff --git a/boards/222.c b/boards/222.c new file mode 100644 index 0000000..fd3cc8a --- /dev/null +++ b/boards/222.c @@ -0,0 +1,99 @@ +/* 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 uint16 IRQCount; +static uint8 IRQa; +static uint8 prg_reg[2]; +static uint8 chr_reg[8]; + +static SFORMAT StateRegs[]= +{ + {&IRQCount, 2, "IRQC"}, + {&IRQa, 2, "IRQA"}, + {prg_reg, 2, "PRG"}, + {chr_reg, 8, "CHR"}, + {0} +}; + +static void M222IRQ(void) +{ + if(IRQa) + { + IRQCount++; + if(IRQCount>=240) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + } + } +} + +static void Sync(void) +{ + setprg8(0x8000,prg_reg[0]); + setprg8(0xA000,prg_reg[1]); + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chr_reg[i]); +} + +static DECLFW(M222Write) +{ + switch(A&0xF003) + { + case 0x8000: prg_reg[0]=V; break; + case 0xA000: prg_reg[1]=V; break; + case 0xB000: chr_reg[0]=V; break; + case 0xB002: chr_reg[1]=V; break; + case 0xC000: chr_reg[2]=V; break; + case 0xC002: chr_reg[3]=V; break; + case 0xD000: chr_reg[4]=V; break; + case 0xD002: chr_reg[5]=V; break; + case 0xE000: chr_reg[6]=V; break; + case 0xE002: chr_reg[7]=V; break; + case 0xF000: IRQCount=IRQa=V; + X6502_IRQEnd(FCEU_IQEXT); + break; + } + Sync(); +} + +static void M222Power(void) +{ + setprg16(0xC000,~0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M222Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper222_Init(CartInfo *info) +{ + info->Power=M222Power; + GameHBIRQHook=M222IRQ; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/235.c b/boards/235.c new file mode 100644 index 0000000..34bbc0f --- /dev/null +++ b/boards/235.c @@ -0,0 +1,70 @@ +/* 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 uint16 cmdreg; +static SFORMAT StateRegs[]= +{ + {&cmdreg, 2, "CMDREG"}, + {0} +}; + +static void Sync(void) +{ + if(cmdreg&0x400) + setmirror(MI_0); + else + setmirror(((cmdreg>>13)&1)^1); + if(cmdreg&0x800) + { + setprg16(0x8000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1)); + setprg16(0xC000,((cmdreg&0x300)>>3)|((cmdreg&0x1F)<<1)|((cmdreg>>12)&1)); + } + else + setprg32(0x8000,((cmdreg&0x300)>>4)|(cmdreg&0x1F)); +} + +static DECLFW(M235Write) +{ + cmdreg=A; + Sync(); +} + +static void M235Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,M235Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + cmdreg=0; + Sync(); +} + +static void M235Restore(int version) +{ + Sync(); +} + +void Mapper235_Init(CartInfo *info) +{ + info->Power=M235Power; + GameStateRestore=M235Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/57.c b/boards/57.c new file mode 100644 index 0000000..693677d --- /dev/null +++ b/boards/57.c @@ -0,0 +1,93 @@ +/* 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 prg_reg; +static uint8 chr_reg; +static uint8 hrd_flag; + +static SFORMAT StateRegs[]= +{ + {&prg_reg, 1, "PRG"}, + {&chr_reg, 1, "CHR"}, + {0} +}; + +static void Sync(void) +{ + if(prg_reg&0x80) + setprg32(0x8000,prg_reg>>6); + else + { + setprg16(0x8000,(prg_reg>>5)&3); + setprg16(0xC000,(prg_reg>>5)&3); + } + setmirror((prg_reg&8)>>3); + setchr8((chr_reg&3)|(prg_reg&7)|((prg_reg&0x10)>>1)); +} + +static DECLFR(M57Read) +{ + return hrd_flag; +} + +static DECLFW(M57Write) +{ + if((A&0x8800)==0x8800) + prg_reg=V; + else + chr_reg=V; + Sync(); +} + +static void M57Power(void) +{ + prg_reg=0; + chr_reg=0; + hrd_flag=0; + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M57Write); + SetReadHandler(0x6000,0x6000,M57Read); + Sync(); +} + +static void M57Reset() +{ + if(hrd_flag==3) + hrd_flag=0; + else + hrd_flag++; + FCEU_printf("Select Register = %02x\n",hrd_flag); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper57_Init(CartInfo *info) +{ + info->Power=M57Power; + info->Reset=M57Reset; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/8157.c b/boards/8157.c index 3c4a4fb..2aa3f4e 100644 --- a/boards/8157.c +++ b/boards/8157.c @@ -1,77 +1,80 @@ -/* 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 uint16 cmdreg; -static SFORMAT StateRegs[]= -{ - {&cmdreg, 2, "CMDREG"}, - {0} -}; - -static void Sync(void) -{ - setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2); - setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0); - setmirror(((cmdreg&2)>>1)^1); -} - -static DECLFR(UNL8157Read) -{ - if(cmdreg&0x100) - return 0xFF; - else - return CartBR(A); -} - -static DECLFW(UNL8157Write) -{ - cmdreg=A; - Sync(); -} - -static void UNL8157Power(void) -{ - setchr8(0); - SetWriteHandler(0x8000,0xFFFF,UNL8157Write); - SetReadHandler(0x8000,0xFFFF,UNL8157Read); - cmdreg=0; - Sync(); -} - -static void UNL8157Reset(void) -{ - cmdreg=0; - Sync(); -} - -static void UNL8157Restore(int version) -{ - Sync(); -} - -void UNL8157_Init(CartInfo *info) -{ - info->Power=UNL8157Power; - info->Reset=UNL8157Reset; - GameStateRestore=UNL8157Restore; - AddExState(&StateRegs, ~0, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint16 cmdreg; +static uint8 invalid_data; +static SFORMAT StateRegs[]= +{ + {&cmdreg, 2, "CMDREG"}, + {0} +}; + +static void Sync(void) +{ + setprg16r((cmdreg&0x060)>>5,0x8000,(cmdreg&0x01C)>>2); + setprg16r((cmdreg&0x060)>>5,0xC000,(cmdreg&0x200)?(~0):0); + setmirror(((cmdreg&2)>>1)^1); +} + +static DECLFR(UNL8157Read) +{ + if(invalid_data&&cmdreg&0x100) + return 0xFF; + else + return CartBR(A); +} + +static DECLFW(UNL8157Write) +{ + cmdreg=A; + Sync(); +} + +static void UNL8157Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,UNL8157Write); + SetReadHandler(0x8000,0xFFFF,UNL8157Read); + cmdreg=0x200; + invalid_data=1; + Sync(); +} + +static void UNL8157Reset(void) +{ + cmdreg=0; + invalid_data^=1; + Sync(); +} + +static void UNL8157Restore(int version) +{ + Sync(); +} + +void UNL8157_Init(CartInfo *info) +{ + info->Power=UNL8157Power; + info->Reset=UNL8157Reset; + GameStateRestore=UNL8157Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/88.c b/boards/88.c new file mode 100644 index 0000000..03fbf5b --- /dev/null +++ b/boards/88.c @@ -0,0 +1,87 @@ +/* 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 reg[8]; +static uint8 mirror, cmd, is154; + +static SFORMAT StateRegs[]= +{ + {&cmd, 1, "CMD"}, + {&mirror, 1, "MIRR"}, + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ + setchr2(0x0000,reg[0]>>1); + setchr2(0x0800,reg[1]>>1); + setchr1(0x1000,reg[2]|0x40); + setchr1(0x1400,reg[3]|0x40); + setchr1(0x1800,reg[4]|0x40); + setchr1(0x1C00,reg[5]|0x40); + setprg8(0x8000,reg[6]); + setprg8(0xA000,reg[7]); +} + +static void MSync(void) +{ + if(is154)setmirror(MI_0+(mirror&1)); +} + +static DECLFW(M88Write) +{ + switch(A&0x8001) + { + case 0x8000: cmd=V&7; mirror=V>>6; MSync(); break; + case 0x8001: reg[cmd]=V; Sync(); break; + } +} + +static void M88Power(void) +{ + setprg16(0xC000,~0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M88Write); +} + +static void StateRestore(int version) +{ + Sync(); + MSync(); +} + +void Mapper88_Init(CartInfo *info) +{ + is154=0; + info->Power=M88Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper154_Init(CartInfo *info) +{ + is154=1; + info->Power=M88Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/90.c b/boards/90.c index 489a540..994910d 100644 --- a/boards/90.c +++ b/boards/90.c @@ -2,6 +2,7 @@ * * Copyright notice for this file: * Copyright (C) 2002 Xodnizel + * 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 @@ -19,8 +20,10 @@ */ #include "mapinc.h" +//#define DEBUG90 static int is209; +static int is211; static uint8 IRQMode; // from $c001 static uint8 IRQPre; // from $c004 @@ -61,20 +64,9 @@ static SFORMAT Tek_StateRegs[]={ {0} }; -static DECLFR(M90Read) -{ - switch(A) - { - case 0x5800: return (mul[0]*mul[1]); - case 0x5801: return((mul[0]*mul[1])>>8); - case 0x5803: return (regie); - default: return(tekker); - } -} - static void mira(void) { - if(tkcom[0]&0x20 && is209) + if((tkcom[0]&0x20&&is209)||is211) { int x; if(tkcom[0]&0x40) // Name tables are ROM-only @@ -86,7 +78,7 @@ static void mira(void) { for(x=0;x<4;x++) { - if((tkcom[2]&0x80)==(names[x]&0x80)) // RAM selected. + if((tkcom[1]&0x80)==(names[x]&0x80)) // RAM selected. setntamem(NTARAM+((names[x]&0x1)<<10),1,x); else setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10),0,x); @@ -108,37 +100,42 @@ static void mira(void) static void tekprom(void) { uint32 bankmode=((tkcom[3]&6)<<5); - switch(tkcom[0]&3) + switch(tkcom[0]&7) { - case 1: // 16 KB - setprg16(0x8000,(prgb[0]&0x1F)|((tkcom[3]&6)<<4)); - setprg16(0xC000,(prgb[2]&0x1F)|((tkcom[3]&6)<<4)); - break; - case 2: //2 = 8 KB ?? - if(tkcom[0]&0x4) - { - setprg8(0x8000,(prgb[0]&0x3F)|bankmode); - setprg8(0xa000,(prgb[1]&0x3F)|bankmode); - setprg8(0xc000,(prgb[2]&0x3F)|bankmode); - setprg8(0xe000,(prgb[3]&0x3F)|bankmode); - } - else - { - 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,((~0)&0x3F)|bankmode); - } - break; - case 0: - case 3: - setprg8(0x8000,(prgb[0]&0x3F)|bankmode); - setprg8(0xa000,(prgb[1]&0x3F)|bankmode); - setprg8(0xc000,(prgb[2]&0x3F)|bankmode); - setprg8(0xe000,(prgb[3]&0x3F)|bankmode); - break; + case 00: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,0x0F|((tkcom[3]&6)<<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)); + 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); + break; + case 04: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<2)+3)&0x3F)|bankmode); + setprg32(0x8000,(prgb[3]&0x0F)|((tkcom[3]&6)<<3)); + break; + case 05: if(tkcom[0]&0x80) + setprg8(0x6000,(((prgb[3]<<1)+1)&0x3F)|bankmode); + setprg16(0x8000,(prgb[1]&0x1F)|((tkcom[3]&6)<<4)); + setprg16(0xC000,(prgb[3]&0x1F)|((tkcom[3]&6)<<4)); + break; + case 07: // bit reversion + case 06: 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,(prgb[3]&0x3F)|bankmode); + break; } } @@ -176,49 +173,106 @@ static void tekvrom(void) } } -static DECLFW(M90Write) +static DECLFW(M90TekWrite) { - if(A==0x5800) mul[0]=V; - else if(A==0x5801) mul[1]=V; - else if(A==0x5803) regie=V; - - A&=0xF007; - if(A>=0x8000 && A<=0x8003) + switch(A) { - prgb[A&3]=V; - tekprom(); + case 0x5800: mul[0]=V; break; + case 0x5801: mul[1]=V; break; + case 0x5803: regie=V; break; } - else if(A>=0x9000 && A<=0x9007) +} + +static DECLFR(M90TekRead) +{ + switch(A) { - chrlow[A&7]=V; - tekvrom(); + case 0x5800: return (mul[0]*mul[1]); + case 0x5801: return((mul[0]*mul[1])>>8); + case 0x5803: return (regie); } - else if(A>=0xa000 && A<=0xa007) + return(tekker); +} + +static DECLFW(M90PRGWrite) +{ + prgb[A&3]=V; + tekprom(); +} + +static DECLFW(M90CHRlowWrite) +{ + chrlow[A&7]=V; + tekvrom(); +} + +static DECLFW(M90CHRhiWrite) +{ + chrhigh[A&7]=V; + tekvrom(); +} + +static DECLFW(M90NTWrite) +{ + if(A&4) { - chrhigh[A&7]=V; - tekvrom(); + names[A&3]&=0x00FF; + names[A&3]|=V<<8; } - else if(A>=0xb000 && A<=0xb007) + else { - if(A&4) - { - names[A&3]&=0x00FF; - names[A&3]|=V<<8; - } - else - { - names[A&3]&=0xFF00; - names[A&3]|=V; - } - mira(); + names[A&3]&=0xFF00; + names[A&3]|=V; } - else if(A>=0xd000 && A<=0xdfff) + mira(); +} + +static DECLFW(M90IRQWrite) +{ + switch(A&7) { + case 00: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable"); + IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break; + case 02: //FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline); + IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + 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"); +*/ break; + case 04: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); + IRQPre=V^IRQXOR;break; + case 05: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); + IRQCount=V^IRQXOR;break; + case 06: //FCEU_printf("Xor Value: %d\n",V); + IRQXOR=V;break; + case 07: //if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n"); + // else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n"); + // else FCEU_printf("Counter Stopped\n"); + IRQPreSize=V;break; + } +} + +static DECLFW(M90ModeWrite) +{ tkcom[A&3]=V; tekprom(); tekvrom(); mira(); -/* + +#ifdef DEBUG90 switch (A&3) { case 00: FCEU_printf("Main Control Register:\n"); @@ -232,10 +286,10 @@ static DECLFW(M90Write) case 01: FCEU_printf("Mirroring mode: "); switch (V&3) { - case 00: FCEU_printf("Vertical\n");break; - case 01: FCEU_printf("Horizontal\n");break; - case 02: FCEU_printf("Nametable 0 only\n");break; - case 03: FCEU_printf("Nametable 1 only\n");break; + case 0: FCEU_printf("Vertical\n");break; + case 1: FCEU_printf("Horizontal\n");break; + case 2: FCEU_printf("Nametable 0 only\n");break; + case 3: FCEU_printf("Nametable 1 only\n");break; } FCEU_printf("Mirroring flag: %s\n",(V&0x80)?"On":"Off"); break; @@ -248,42 +302,7 @@ static DECLFW(M90Write) FCEU_printf("512K PRG bank number: %d\n",(V&6)>>1); FCEU_printf("CHR Bank mirroring: %s\n",(V&0x80)?"Swapped":"Normal operate"); } -*/ - } - else switch(A) - { - case 0xc000: //FCEU_printf("%s IRQ (C000)\n",V&1?"Enable":"Disable"); - IRQa=V&1;if(!(V&1)) X6502_IRQEnd(FCEU_IQEXT);break; - case 0xc002: //FCEU_printf("Disable IRQ (C002) scanline=%d\n", scanline); - IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xc003: //FCEU_printf("Enable IRQ (C003) scanline=%d\n", scanline); - IRQa=1;break; - case 0xc001: 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"); -*/ break; - case 0xc004: //FCEU_printf("Pre Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); - IRQPre=V^IRQXOR;break; - case 0xc005: //FCEU_printf("Main Counter Loaded and Xored wiht C006: %d\n",V^IRQXOR); - IRQCount=V^IRQXOR;break; - case 0xc006: //FCEU_printf("Xor Value: %d\n",V); - IRQXOR=V;break; - case 0xc007: //if(!(IRQMode&8)) FCEU_printf("C001 is clear, no effect applied\n"); - // else if(V==0xFF) FCEU_printf("Prescaler is changed for 12bits\n"); - // else FCEU_printf("Counter Stopped\n"); - IRQPreSize=V;break; - } +#endif } static void CCL(void) @@ -292,13 +311,17 @@ static void CCL(void) { IRQCount++; if((IRQCount == 0) && IRQa) + { X6502_IRQBegin(FCEU_IQEXT); + } } else if((IRQMode>>6) == 2) // Count down { IRQCount--; if((IRQCount == 0xFF) && IRQa) + { X6502_IRQBegin(FCEU_IQEXT); + } } } @@ -322,24 +345,37 @@ static void ClockCounter(void) } } +void FP_FASTAPASS(1) CPUWrap(int a) +{ + int x; + if((IRQMode&3)==0) for(x=0;xReset=togglie; info->Power=M90Power; - PPU_hook = M90PPU; - GameHBIRQHook2 = SLWrap; + PPU_hook=M90PPU; + GameHBIRQHook2=SLWrap; + MapIRQHook=CPUWrap; GameStateRestore=M90Restore; AddExState(Tek_StateRegs, ~0, 0, 0); } void Mapper209_Init(CartInfo *info) { + is211=0; is209=1; info->Reset=togglie; info->Power=M90Power; - PPU_hook = M90PPU; - GameHBIRQHook2 = SLWrap; + GameHBIRQHook2=SLWrap; + GameStateRestore=M90Restore; + AddExState(Tek_StateRegs, ~0, 0, 0); +} + +void Mapper211_Init(CartInfo *info) +{ + is211=1; + info->Reset=togglie; + info->Power=M90Power; + GameHBIRQHook2=SLWrap; GameStateRestore=M90Restore; AddExState(Tek_StateRegs, ~0, 0, 0); } diff --git a/boards/95.c b/boards/95.c new file mode 100644 index 0000000..7b69435 --- /dev/null +++ b/boards/95.c @@ -0,0 +1,124 @@ +/* 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 lastA; +static uint8 DRegs[8]; +static uint8 cmd; +static uint8 MirCache[8]; + +static SFORMAT DB_StateRegs[]={ + {DRegs, 8, "DREG"}, + {&cmd, 1, "CMD"}, + {&lastA, 1, "LAST"}, + {0} +}; + +static void toot(void) +{ + int x; + + MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1; + MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1; + + for(x=0;x<4;x++) + MirCache[4+x]=(DRegs[2+x]>>5)&1; + onemir(MirCache[lastA]); +} + +static void Sync() +{ + setchr2(0x0000,DRegs[0]&0x1F); + setchr2(0x0800,DRegs[1]&0x1F); + setchr1(0x1000,DRegs[2]&0x1F); + setchr1(0x1400,DRegs[3]&0x1F); + setchr1(0x1800,DRegs[4]&0x1F); + setchr1(0x1C00,DRegs[5]&0x1F); + setprg8(0x8000,DRegs[6]&0x1F); + setprg8(0xa000,DRegs[7]&0x1F); + toot(); +} + +static DECLFW(Mapper95_write) +{ + switch(A&0xF001) + { + case 0x8000: cmd = V; break; + case 0x8001: + switch(cmd&0x07) + { + case 0: DRegs[0]=(V&0x3F)>>1; break; + case 1: DRegs[1]=(V&0x3F)>>1; break; + case 2: DRegs[2]=V&0x3F; break; + case 3: DRegs[3]=V&0x3F; break; + case 4: DRegs[4]=V&0x3F; break; + case 5: DRegs[5]=V&0x3F; break; + case 6: DRegs[6]=V&0x3F; break; + case 7: DRegs[7]=V&0x3F; break; + } + Sync(); + } +} + +static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A) +{ + static int last=-1; + static uint8 z; + + if(A>=0x2000) return; + + A>>=10; + lastA=A; + z=MirCache[A]; + if(z!=last) + { + onemir(z); + last=z; + } +} + +static void DBPower(void) +{ + memset(DRegs,0x3F,8); + DRegs[0]=DRegs[1]=0x1F; + + Sync(); + + setprg8(0xc000,0x3E); + setprg8(0xe000,0x3F); + + SetReadHandler(0x8000,0xffff,CartBR); + SetWriteHandler(0x8000,0xffff,Mapper95_write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper95_Init(CartInfo *info) +{ + info->Power=DBPower; + AddExState(DB_StateRegs, ~0, 0, 0); + PPU_hook=dragonbust_ppu; + GameStateRestore=StateRestore; +} + diff --git a/boards/Makefile b/boards/Makefile index b63f897..7af1889 100644 --- a/boards/Makefile +++ b/boards/Makefile @@ -1,6 +1,51 @@ -MUOBJS += boards/mmc5.o boards/mmc3.o boards/mmc1.o boards/tengen.o boards/bonza.o boards/deirom.o -MUOBJS += boards/dream.o boards/konami-qtai.o boards/n106.o boards/karaoke.o boards/90.o boards/112.o -MUOBJS += boards/164.o boards/183.o boards/186.o boards/8237.o boards/8157.o boards/addrlatch.o -MUOBJS += boards/datalatch.o boards/h2288.o boards/malee.o boards/novel.o boards/sachen.o -MUOBJS += boards/subor.o boards/super24.o boards/supervision.o +B_C += boards/112.c +B_C += boards/117.c +B_C += boards/164.c +B_C += boards/183.c +B_C += boards/185.c +B_C += boards/186.c +B_C += boards/187.c +B_C += boards/189.c +B_C += boards/208.c +B_C += boards/222.c +B_C += boards/235.c +B_C += boards/57.c +B_C += boards/8157.c +B_C += boards/8237.c +B_C += boards/88.c +B_C += boards/90.c +B_C += boards/95.c +B_C += boards/bmc13in1jy110.c +B_C += boards/bmc42in1r.c +B_C += boards/bmc64in1nr.c +B_C += boards/bmc70in1.c +B_C += boards/bmcgk192.c +B_C += boards/bonza.c +B_C += boards/cc21.c +B_C += boards/datalatch.c +B_C += boards/deirom.c +B_C += boards/dream.c +B_C += boards/fk23c.c +B_C += boards/h2288.c +B_C += boards/karaoke.c +B_C += boards/kof97.c +B_C += boards/konami-qtai.c +B_C += boards/malee.c +B_C += boards/mmc1.c +B_C += boards/mmc3.c +B_C += boards/mmc5.c +B_C += boards/n106.c +B_C += boards/novel.c +B_C += boards/sachen.c +B_C += boards/sheroes.c +B_C += boards/sl1632.c +B_C += boards/sonic5.c +B_C += boards/subor.c +B_C += boards/super24.c +B_C += boards/supervision.c +B_C += boards/t-262.c +B_C += boards/tengen.c +B_C += boards/__dummy_mapper.c + +MUOBJS += $(patsubst %.c,%.o,$(B_C)) diff --git a/boards/__dummy_mapper.c b/boards/__dummy_mapper.c new file mode 100644 index 0000000..6bb703c --- /dev/null +++ b/boards/__dummy_mapper.c @@ -0,0 +1,97 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static uint8 reg[8]; +/* +static uint8 *WRAM=NULL; +static uint32 WRAMSIZE; +static uint8 *CHRRAM=NULL; +static uint32 CHRRAMSIZE; +*/ + +static SFORMAT StateRegs[]= +{ + {reg, 8, "REGS"}, + {0} +}; + +static void Sync(void) +{ +} + +static DECLFW(MNNNWrite) +{ +} + +static void MNNNPower(void) +{ + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,MNNNWrite); +} + +static void MNNNReset(void) +{ +} + +/* +static void MNNNClose(void) +{ + if(WRAM) + FCEU_gfree(WRAM); + if(CHRRAM) + FCEU_gfree(CHRRAM); + WRAM=CHRRAM=NULL; +} +*/ + +static void MNNNIRQHook(void) +{ + X6502_IRQBegin(FCEU_IQEXT); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void MapperNNN_Init(CartInfo *info) +{ + info->Reset=MNNNReset; + info->Power=MNNNPower; +// info->Close=MNNNClose; + GameHBIRQHook=MNNNIRQHook; + GameStateRestore=StateRestore; +/* + CHRRAMSIZE=8192; + CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSIZE); + SetupCartPRGMapping(0x10,CHRRAM,CHRRAMSIZE,1); + AddExState(CHRRAM, CHRRAMSIZE, 0, "WRAM"); +*/ +/* + 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/bmc13in1jy110.c b/boards/bmc13in1jy110.c new file mode 100644 index 0000000..6f11f8a --- /dev/null +++ b/boards/bmc13in1jy110.c @@ -0,0 +1,103 @@ +/* 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 + * + * BMC 42-in-1 reset switch + */ + +#include "mapinc.h" + +static uint8 bank_mode; +static uint8 bank_value; +static uint8 prgb[4]; +static SFORMAT StateRegs[]= +{ + {0} +}; + +static void Sync(void) +{ + FCEU_printf("%02x: %02x %02x\n", bank_mode, bank_value, prgb[0]); + switch(bank_mode&7) + { + case 0: + setprg32(0x8000,bank_value&7); break; + case 1: + setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]); + setprg16(0xC000,(bank_value&7)>>1); + case 4: + setprg32(0x8000,8+(bank_value&7)); break; + case 5: + setprg16(0x8000,((8+(bank_value&7))>>1)+prgb[1]); + setprg16(0xC000,((8+(bank_value&7))>>1)+prgb[3]); + case 2: + setprg8(0x8000,prgb[0]>>2); + setprg8(0xa000,prgb[1]); + setprg8(0xc000,prgb[2]); + setprg8(0xe000,~0); + break; + case 3: + setprg8(0x8000,prgb[0]); + setprg8(0xa000,prgb[1]); + setprg8(0xc000,prgb[2]); + setprg8(0xe000,prgb[3]); + break; + } +} + +static DECLFW(BMC13in1JY110Write) +{ + FCEU_printf("%04x:%04x\n",A,V); + switch(A) + { + case 0x8000: + case 0x8001: + case 0x8002: + case 0x8003: prgb[A&3]=V; break; + case 0xD000: bank_mode=V; break; + case 0xD001: setmirror(V&3); + case 0xD002: break; + case 0xD003: bank_value=V; break; + } + Sync(); +} + +static void BMC13in1JY110Power(void) +{ + prgb[0]=prgb[1]=prgb[2]=prgb[3]=0; + bank_mode=0; + bank_value=0; + setprg32(0x8000,0); + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,BMC13in1JY110Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC13in1JY110_Init(CartInfo *info) +{ + info->Power=BMC13in1JY110Power; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + + diff --git a/boards/bmc42in1r.c b/boards/bmc42in1r.c new file mode 100644 index 0000000..8084847 --- /dev/null +++ b/boards/bmc42in1r.c @@ -0,0 +1,87 @@ +/* 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 + * + * BMC 42-in-1 reset switch + */ + +#include "mapinc.h" + +static uint8 hrd_sw; +static uint8 latche; +static SFORMAT StateRegs[]= +{ + {&latche, 1, "LATCHE"}, + {&hrd_sw, 1, "HRDSW"}, + {0} +}; + +static void Sync(void) +{ + if(!(latche&0x20)) + setprg32r(hrd_sw,0x8000,(latche>>1)&0x0f); + else + { + setprg16r(hrd_sw,0x8000,latche&0x1f); + setprg16r(hrd_sw,0xC000,latche&0x1f); + } + switch((latche>>6)&3) + { + case 0: setmirrorw(0,0,0,1); break; + case 1: setmirror(MI_V); break; + case 2: setmirror(MI_H); break; + case 3: setmirror(MI_1); break; + } +} + +static DECLFW(BMC42in1rWrite) +{ + latche=V; + Sync(); +} + +static void BMC42in1rReset(void) +{ + hrd_sw^=1; + Sync(); +} + +static void BMC42in1rPower(void) +{ + latche=0x00; + hrd_sw=0; + setchr8(0); + Sync(); + SetWriteHandler(0x8000,0xFFFF,BMC42in1rWrite); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC42in1r_Init(CartInfo *info) +{ + info->Power=BMC42in1rPower; + info->Reset=BMC42in1rReset; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + + diff --git a/boards/bmc64in1nr.c b/boards/bmc64in1nr.c new file mode 100644 index 0000000..af663ba --- /dev/null +++ b/boards/bmc64in1nr.c @@ -0,0 +1,93 @@ +/* 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 + * + * BMC 42-in-1 reset switch + */ + +#include "mapinc.h" + +static uint8 regs[4]; + +static SFORMAT StateRegs[]= +{ + {regs, 4, "REGS"}, + {0} +}; + +static void Sync(void) +{ + if(regs[0]&0x80) + { + if(regs[1]&0x80) + setprg32(0x8000,regs[1]&0x1F); + else + { + int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1); + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + { + int bank=((regs[1]&0x1f)<<1)|((regs[1]>>6)&1); + setprg16(0xC000,bank); + } + if(regs[0]&0x20) + setmirror(MI_H); + else + setmirror(MI_V); + setchr8((regs[2]<<2)|((regs[0]>>1)&3)); +} + +static DECLFW(BMC64in1nrWriteLo) +{ + regs[A&3]=V; + Sync(); +} + +static DECLFW(BMC64in1nrWriteHi) +{ + regs[3]=V; + Sync(); +} + +static void BMC64in1nrPower(void) +{ + regs[0]=0x80; + regs[1]=0x43; + regs[2]=regs[3]=0; + Sync(); + SetWriteHandler(0x5000,0x5003,BMC64in1nrWriteLo); + SetWriteHandler(0x8000,0xFFFF,BMC64in1nrWriteHi); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC64in1nr_Init(CartInfo *info) +{ + info->Power=BMC64in1nrPower; + AddExState(&StateRegs, ~0, 0, 0); + GameStateRestore=StateRestore; +} + + diff --git a/boards/bmc70in1.c b/boards/bmc70in1.c new file mode 100644 index 0000000..9d4eb28 --- /dev/null +++ b/boards/bmc70in1.c @@ -0,0 +1,116 @@ +/* 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 is_large_banks; +static uint8 large_bank; +static uint8 prg_bank; +static uint8 chr_bank; +static uint8 bank_mode; +static uint8 mirroring; +static SFORMAT StateRegs[]= +{ + {&large_bank, 1, "LB"}, + {&prg_bank, 1, "PRG"}, + {&chr_bank, 1, "CHR"}, + {&bank_mode, 1, "BM"}, + {&mirroring, 1, "MIRR"}, + {0} +}; + +static void Sync(void) +{ + switch (bank_mode) + { + case 0x00: + case 0x10: setprg16(0x8000,large_bank|prg_bank); + setprg16(0xC000,large_bank|7); + break; + case 0x20: setprg32(0x8000,(large_bank|prg_bank)>>1); + break; + case 0x30: setprg16(0x8000,large_bank|prg_bank); + setprg16(0xC000,large_bank|prg_bank); + break; + } + setmirror(mirroring); + if(!is_large_banks) + setchr8(chr_bank); +} + +static DECLFR(BMC70in1Read) +{ + if(bank_mode==0x10) + if(is_large_banks) + return CartBR((A&0xFFF0)|0x06); + else + return CartBR((A&0xFFF0)|0x0d); + else + return CartBR(A); +} + +static DECLFW(BMC70in1Write) +{ + if(A&0x4000) + { + bank_mode=A&0x30; + prg_bank=A&7; + } + else + { + mirroring=((A&0x20)>>5)^1; + if(is_large_banks) + large_bank=(A&3)<<3; + else + chr_bank=A&7; + } + Sync(); +} + +static void BMC70in1Power(void) +{ + setchr8(0); + bank_mode=0; + large_bank=0; + Sync(); + SetReadHandler(0x8000,0xFFFF,BMC70in1Read); + SetWriteHandler(0x8000,0xffff,BMC70in1Write); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void BMC70in1_Init(CartInfo *info) +{ + is_large_banks=0; + info->Power=BMC70in1Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void BMC70in1B_Init(CartInfo *info) +{ + is_large_banks=1; + info->Power=BMC70in1Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/mappers/235.c b/boards/bmcgk192.c similarity index 51% rename from mappers/235.c rename to boards/bmcgk192.c index e54907e..b66d831 100644 --- a/mappers/235.c +++ b/boards/bmcgk192.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel + * 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 @@ -20,35 +20,48 @@ #include "mapinc.h" -static DECLFW(Mapper235_write) -{ - uint32 m; - int z; +static uint16 addrlatche; - if(A&0x400) - onemir(0); +static void Sync(void) +{ + if(addrlatche&0x40) + { + setprg16(0x8000,addrlatche&7); + setprg16(0xC000,addrlatche&7); + } else - setmirror(((A>>13)&1)^1); - m=A&0x1f; + setprg32(0x8000,(addrlatche>>1)&3); + setchr8((addrlatche>>3)&7); + setmirror(((addrlatche&0x80)>>7)^1); +} - z=(A>>8)&3; +static DECLFW(BMCGK192Write) +{ + addrlatche=A; + Sync(); +} - if(A&0x800) - { - setprg16r(0x10|z,0x8000,(m<<1)|((A>>12)&1)); - setprg16r(0x10|z,0xC000,(m<<1)|((A>>12)&1)); +static void BMCGK192Reset(void) +{ + setprg32(0x8000,0); +} - } - else - setprg32r(0x10|z,0x8000,m); +static void BMCGK192Power(void) +{ + setprg32(0x8000,0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xffff,BMCGK192Write); +} + +static void StateRestore(int version) +{ + Sync(); } -void Mapper235_init(void) +void Mapper58_Init(CartInfo *info) { - /* Fixme: Possible crashy bug if header is bad. */ - SetupCartPRGMapping(0x10,PRGptr[0],1024*1024,0); - SetupCartPRGMapping(0x12,PRGptr[0]+1024*1024,1024,0); - setprg32r(0x10,0x8000,0); - SetReadHandler(0x8000,0xffff,CartBROB); - SetWriteHandler(0x8000,0xffff,Mapper235_write); + info->Power=BMCGK192Power; + info->Reset=BMCGK192Reset; + GameStateRestore=StateRestore; + AddExState(&addrlatche, 2, 0, "ALATC"); } diff --git a/boards/bonza.c b/boards/bonza.c index 5e572f1..ba390e6 100644 --- a/boards/bonza.c +++ b/boards/bonza.c @@ -1,139 +1,139 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2002 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 prg_reg; -static uint8 chr_reg; - -static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt; -static uint16 sim0data; -static uint8 sim0array[128] = -{ - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, - 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA, -}; - -static SFORMAT StateRegs[]= -{ - {&prg_reg, 1, "PREG"}, - {&chr_reg, 1, "CREG"}, - {0} -}; - -static void Sync(void) -{ - setprg32(0x8000, prg_reg); - setchr8(chr_reg); -} - -static void StateRestore(int version) -{ - Sync(); -} - -static DECLFW(M216WriteHi) -{ -// FCEU_printf("%04x:%04x\n",A,V); - prg_reg=A&1; - chr_reg=(A&0x0E)>>1; - Sync(); -} - -static DECLFW(M216Write5000) -{ -// FCEU_printf("WRITE: %04x:%04x\n",A,V); - sim0reg=V; - if(!sim0reg) - { - sim0bit=sim0byte=sim0parity=0; - sim0data=sim0array[0]; - sim0bcnt=0x80; - } - else if(sim0reg&0x20) - { - sim0bcnt=0x20; - } -} - -static DECLFR(M216Read5000) -{ - if(sim0reg&0x60) - { - sim0reg=(sim0reg^(sim0reg<<1))&0x40; - return sim0reg; - } - else - { - uint8 sim0out=0; - if(sim0bit<8) - { -// sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1; - sim0out=(sim0data&1)<<6; - sim0data>>=1; - sim0bit++; - sim0parity+=sim0data; - } - else if(sim0bit==8) - { - sim0bit++; - sim0out=sim0parity&1; - } - else if(sim0bit==9) - { - if(sim0byte==sim0bcnt) - sim0out=0x60; - else - { - sim0bit=0; - sim0byte++; - sim0data=sim0array[sim0byte]; - sim0out=0; - } - } -// FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte); - return sim0out; - } -} - -static void Power(void) -{ - prg_reg = 0; - chr_reg = 0; - Sync(); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M216WriteHi); - SetWriteHandler(0x5000,0x5000,M216Write5000); - SetReadHandler(0x5000,0x5000,M216Read5000); -} - - -void Mapper216_Init(CartInfo *info) -{ - info->Power=Power; - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2002 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 prg_reg; +static uint8 chr_reg; + +static uint8 sim0reg, sim0bit, sim0byte, sim0parity, sim0bcnt; +static uint16 sim0data; +static uint8 sim0array[128] = +{ + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, + 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0xAA, +}; + +static SFORMAT StateRegs[]= +{ + {&prg_reg, 1, "PREG"}, + {&chr_reg, 1, "CREG"}, + {0} +}; + +static void Sync(void) +{ + setprg32(0x8000, prg_reg); + setchr8(chr_reg); +} + +static void StateRestore(int version) +{ + Sync(); +} + +static DECLFW(M216WriteHi) +{ +// FCEU_printf("%04x:%04x\n",A,V); + prg_reg=A&1; + chr_reg=(A&0x0E)>>1; + Sync(); +} + +static DECLFW(M216Write5000) +{ +// FCEU_printf("WRITE: %04x:%04x\n",A,V); + sim0reg=V; + if(!sim0reg) + { + sim0bit=sim0byte=sim0parity=0; + sim0data=sim0array[0]; + sim0bcnt=0x80; + } + else if(sim0reg&0x20) + { + sim0bcnt=0x20; + } +} + +static DECLFR(M216Read5000) +{ + if(sim0reg&0x60) + { + sim0reg=(sim0reg^(sim0reg<<1))&0x40; + return sim0reg; + } + else + { + uint8 sim0out=0; + if(sim0bit<8) + { +// sim0data=((sim0array[sim0byte]<<(sim0bit))&0x80)>>1; + sim0out=(sim0data&1)<<6; + sim0data>>=1; + sim0bit++; + sim0parity+=sim0data; + } + else if(sim0bit==8) + { + sim0bit++; + sim0out=sim0parity&1; + } + else if(sim0bit==9) + { + if(sim0byte==sim0bcnt) + sim0out=0x60; + else + { + sim0bit=0; + sim0byte++; + sim0data=sim0array[sim0byte]; + sim0out=0; + } + } +// FCEU_printf("READ: %04x (%04x-%02x,%04x)\n",A,X.PC,sim0out,sim0byte); + return sim0out; + } +} + +static void Power(void) +{ + prg_reg = 0; + chr_reg = 0; + Sync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M216WriteHi); + SetWriteHandler(0x5000,0x5000,M216Write5000); + SetReadHandler(0x5000,0x5000,M216Read5000); +} + + +void Mapper216_Init(CartInfo *info) +{ + info->Power=Power; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/addrlatch.c b/boards/cc21.c similarity index 91% rename from boards/addrlatch.c rename to boards/cc21.c index 37be90a..0e2cbe6 100644 --- a/boards/addrlatch.c +++ b/boards/cc21.c @@ -1,53 +1,56 @@ -/* 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 uint16 addrlatche; - -//------------------ UNLCC21 --------------------------- - -static DECLFW(UNLCC21Write) -{ - addrlatche=A; - setchr8(addrlatche&1); - setmirror(MI_0+((addrlatche&2)>>1)); -} - -static void UNLCC21Power(void) -{ - setprg32(0x8000,0); - setchr8(0); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xffff,UNLCC21Write); -} - -static void UNLCC21Restore(int version) -{ - setchr8(addrlatche&1); - setmirror(MI_0+((addrlatche&2)>>1)); -} - -void UNLCC21_Init(CartInfo *info) -{ - info->Power=UNLCC21Power; - GameStateRestore=UNLCC21Restore; - AddExState(&addrlatche, 2, 0, "ALATC"); -} +/* 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 uint16 addrlatche; + +//------------------ UNLCC21 --------------------------- + +static void UNLCC21Sync(void) +{ + setchr8(addrlatche&1); + setmirror(MI_0+((addrlatche&2)>>1)); +} + +static DECLFW(UNLCC21Write) +{ + addrlatche=A; + UNLCC21Sync(); +} + +static void UNLCC21Power(void) +{ + setprg32(0x8000,0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xffff,UNLCC21Write); +} + +static void UNLCC21Restore(int version) +{ + UNLCC21Sync(); +} + +void UNLCC21_Init(CartInfo *info) +{ + info->Power=UNLCC21Power; + GameStateRestore=UNLCC21Restore; + AddExState(&addrlatche, 2, 0, "ALATC"); +} diff --git a/boards/datalatch.c b/boards/datalatch.c index 217adb4..b3452fe 100644 --- a/boards/datalatch.c +++ b/boards/datalatch.c @@ -20,188 +20,253 @@ #include "mapinc.h" -static uint8 latche; +static uint8 latche, latcheinit; +static uint16 addrreg0, addrreg1; +static void(*WSync)(void); -//------------------ CPROM --------------------------- - -static DECLFW(CPROMWrite) +static DECLFW(LatchWrite) { - latche=V&3; - setchr4(0x1000,latche); + latche=V; + WSync(); } -static void CPROMReset(void) +static void LatchPower(void) { - setprg32(0x8000,0); - setchr8(0); + latche=latcheinit; + WSync(); SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xffff,CPROMWrite); + SetWriteHandler(addrreg0,addrreg1,LatchWrite); } -static void CPROMRestore(int version) +static void StateRestore(int version) { - setchr4(0x1000,latche); + WSync(); } -void CPROM_Init(CartInfo *info) +void Latch_Init(CartInfo *info, void (*proc)(void), uint8 init, uint16 adr0, uint16 adr1) { - info->Power=CPROMReset; - GameStateRestore=CPROMRestore; + latcheinit=init; + addrreg0=adr0; + addrreg1=adr1; + WSync=proc; + info->Power=LatchPower; + GameStateRestore=StateRestore; AddExState(&latche, 1, 0, "LATC"); } -//------------------ CNROM --------------------------- +//------------------ CPROM --------------------------- -DECLFW(CNROMWrite) +static void CPROMSync(void) { - latche=V&3; - setchr8(latche); + setchr4(0x0000,0); + setchr4(0x1000,latche&3); + setprg16(0x8000,0); + setprg16(0xC000,1); } -static void CNROMReset(void) +void CPROM_Init(CartInfo *info) { - setprg16(0x8000,0); - setprg16(0xC000,1); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xffff,CNROMWrite); + Latch_Init(info, CPROMSync, 0, 0x8000, 0xFFFF); } -static void CNROMRestore(int version) +//------------------ CNROM --------------------------- + +static void CNROMSync(void) { - setchr8(latche); + setchr8(latche&3); + setprg16(0x8000,0); + setprg16(0xC000,1); } void CNROM_Init(CartInfo *info) { - info->Power=CNROMReset; - GameStateRestore=CNROMRestore; - AddExState(&latche, 1, 0, "LATC"); + Latch_Init(info, CNROMSync, 0, 0x8000, 0xFFFF); } -//------------------ NROM128 --------------------------- +//------------------ ANROM --------------------------- -static void NROM128Reset(void) +static void ANROMSync() { - setprg16(0x8000,0); - setprg16(0xC000,0); + setprg32(0x8000,latche&0xf); + setmirror(MI_0+((latche>>4)&1)); setchr8(0); - SetReadHandler(0x8000,0xFFFF,CartBR); } -void NROM128_Init(CartInfo *info) +void ANROM_Init(CartInfo *info) { - info->Power=NROM128Reset; + Latch_Init(info, ANROMSync, 0, 0x8000, 0xFFFF); } -//------------------ NROM256 --------------------------- +//------------------ Map 70 --------------------------- -static void NROM256Reset(void) +static void M70Sync() { - setprg16(0x8000,0); - setprg16(0xC000,1); - setchr8(0); - SetReadHandler(0x8000,0xFFFF,CartBR); + setprg16(0x8000,latche>>4); + setprg16(0xc000,~0); + setchr8(latche&0xf); } -void NROM256_Init(CartInfo *info) +void Mapper70_Init(CartInfo *info) { - info->Power=NROM256Reset; + Latch_Init(info, M70Sync, 0, 0x8000, 0xFFFF); } -//------------------ MHROM --------------------------- +//------------------ Map 152 --------------------------- -static DECLFW(MHROMWrite) +static void M152Sync() { - setprg32(0x8000,V>>4); - setchr8(V); - latche=V; + setprg16(0x8000,(latche>>4)&7); + setprg16(0xc000,~0); + setchr8(latche&0xf); + setmirror(MI_0+((latche>>7)&1)); /* Saint Seiya...hmm. */ } -static void MHROMReset(void) +void Mapper152_Init(CartInfo *info) { - setprg32(0x8000,0); - setchr8(0); - latche=0; - SetReadHandler(0x8000,0xFFFF,CartBR); + Latch_Init(info, M152Sync, 0, 0x8000, 0xFFFF); } -static void MHROMRestore(int version) +//------------------ Map 78 --------------------------- +/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ +static void M78Sync() { - setprg32(0x8000,latche); - setchr8(latche); - SetWriteHandler(0x8000,0xffff,MHROMWrite); + 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); +} + +//------------------ MHROM --------------------------- + +static void MHROMSync(void) +{ + setprg32(0x8000,latche>>4); + setchr8(latche&0xf); } void MHROM_Init(CartInfo *info) { - info->Power=MHROMReset; - AddExState(&latche, 1, 0,"LATC"); - PRGmask32[0]&=1; - CHRmask8[0]&=1; - GameStateRestore=MHROMRestore; + Latch_Init(info, MHROMSync, 0, 0x8000, 0xFFFF); +} + +void Mapper140_Init(CartInfo *info) +{ + Latch_Init(info, MHROMSync, 0, 0x6000, 0x7FFF); +} + +//------------------ Map 87 --------------------------- + +static void M87Sync(void) +{ + setprg16(0x8000,0); + setprg16(0xC000,1); + setchr8(latche>>1); +} + +void Mapper87_Init(CartInfo *info) +{ + Latch_Init(info, M87Sync, ~0, 0x6000, 0xFFFF); +} + +//------------------ 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); +} + +void Mapper144_Init(CartInfo *info) +{ + Latch_Init(info, M11Sync, 0, 0x8001, 0xFFFF); } //------------------ UNROM --------------------------- -static void UNROMRestore(int version) +static void UNROMSync(void) { setprg16(0x8000,latche); + setprg16(0xc000,~0); + setchr8(0); } -static DECLFW(UNROMWrite) +void UNROM_Init(CartInfo *info) { - setprg16(0x8000,V); - latche=V; + Latch_Init(info, UNROMSync, 0, 0x8000, 0xFFFF); } -static void UNROMReset(void) +//------------------ Map 93 --------------------------- + +static void SSUNROMSync(void) { - setprg16(0x8000,0); + setprg16(0x8000,latche>>4); setprg16(0xc000,~0); setchr8(0); - SetWriteHandler(0x8000,0xffff,UNROMWrite); - SetReadHandler(0x8000,0xFFFF,CartBR); - latche=0; } -void UNROM_Init(CartInfo *info) +void SUNSOFT_UNROM_Init(CartInfo *info) { - info->Power=UNROMReset; - PRGmask16[0]&=7; - AddExState(&latche, 1, 0, "LATC"); - GameStateRestore=UNROMRestore; + Latch_Init(info, SSUNROMSync, 0, 0x8000, 0xFFFF); } -//------------------ GNROM --------------------------- +//------------------ Map 94 --------------------------- -static void GNROMSync() +static void M94Sync(void) { - setchr8(latche&3); - setprg32(0x8000,(latche>>4)&3); + setprg16(0x8000,latche>>2); + setprg16(0xc000,~0); + setchr8(0); } -static DECLFW(GNROMWrite) +void Mapper94_Init(CartInfo *info) { - latche=V&0x33; - GNROMSync(); + Latch_Init(info, M94Sync, 0, 0x8000, 0xFFFF); } -static void GNROMStateRestore(int version) +//------------------ Map 107 --------------------------- + +static void M107Sync(void) { - GNROMSync(); + setprg32(0x8000,(latche>>1)&3); + setchr8(latche&7); } -static void GNROMReset(void) +void Mapper107_Init(CartInfo *info) { - latche=0; - GNROMSync(); - SetWriteHandler(0x8000,0xffff,GNROMWrite); + Latch_Init(info, M107Sync, ~0, 0x8000, 0xFFFF); +} + +//------------------ NROM --------------------------- + +#ifdef DEBUG_MAPPER +static DECLFW(WriteHandler) +{ + FCEU_printf("$%04x:$%02x\n",A,V); +} +#endif + +static void NROMPower(void) +{ + setprg16(0x8000,0); + setprg16(0xC000,~0); + setchr8(0); SetReadHandler(0x8000,0xFFFF,CartBR); + #ifdef DEBUG_MAPPER + SetWriteHandler(0x4020,0xFFFF,WriteHandler); + #endif } -void GNROM_Init(CartInfo *info) +void NROM_Init(CartInfo *info) { - info->Power=GNROMReset; - AddExState(&latche, 1, 0, "LATC"); - GameStateRestore=GNROMStateRestore; + info->Power=NROMPower; } diff --git a/boards/dream.c b/boards/dream.c index 16214f7..7e1d563 100644 --- a/boards/dream.c +++ b/boards/dream.c @@ -1,56 +1,56 @@ -/* 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 latch; - -static void DoPRG(void) -{ - setprg16(0x8000,latch); - setprg16(0xC000,8); -} - -static DECLFW(DREAMWrite) -{ - latch=V&7; - DoPRG(); -} - -static void DREAMPower(void) -{ - latch=0; - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x5020,0x5020,DREAMWrite); - setchr8(0); - DoPRG(); -} - -static void Restore(int version) -{ - DoPRG(); -} - -void DreamTech01_Init(CartInfo *info) -{ - GameStateRestore=Restore; - info->Power=DREAMPower; - AddExState(&latch, 1, 0, "LATCH"); -} +/* 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 latche; + +static void Sync(void) +{ + setprg16(0x8000,latche); + setprg16(0xC000,8); +} + +static DECLFW(DREAMWrite) +{ + latche=V&7; + Sync(); +} + +static void DREAMPower(void) +{ + latche=0; + Sync(); + setchr8(0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5020,0x5020,DREAMWrite); +} + +static void Restore(int version) +{ + Sync(); +} + +void DreamTech01_Init(CartInfo *info) +{ + GameStateRestore=Restore; + info->Power=DREAMPower; + AddExState(&latche, 1, 0, "LATCH"); +} diff --git a/boards/fk23c.c b/boards/fk23c.c new file mode 100644 index 0000000..abf0859 --- /dev/null +++ b/boards/fk23c.c @@ -0,0 +1,112 @@ +/* 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" +#include "mmc3.h" + +static uint8 unromchr; + +static void BMCFK23CCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8((EXPREGS[2]&0xFC)|unromchr); + else + { + uint16 base=(EXPREGS[2]&0x7F)<<3; + setchr1(A,V|base); + if(EXPREGS[3]&2) + { + setchr1(0x0400,EXPREGS[6]|base); + setchr1(0x0C00,EXPREGS[7]|base); + } + } +} + +static void BMCFK23CPW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&4) + setprg32(0x8000,EXPREGS[1]>>1); + else + { + if(EXPREGS[0]&2) + setprg8(A,(V&(0x3F>>(EXPREGS[0]&3)))|(EXPREGS[1]<<1)); + else + setprg8(A,V); + if(EXPREGS[3]&2) + { + setprg8(0xC000,EXPREGS[4]); + setprg8(0xE000,EXPREGS[5]); + } + } +} + +static DECLFW(BMCFK23C8003Write) +{ + if(EXPREGS[0]&0x40) + { + 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 + MMC3_CMDWrite(A,V); + } +} + +static DECLFW(BMCFK23CWrite) +{ + EXPREGS[A&3]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); +} + +static void BMCFK23CReset(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; + EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; + MMC3RegReset(); +} + +static void BMCFK23CPower(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=0; + EXPREGS[4]=EXPREGS[5]=EXPREGS[6]=EXPREGS[7]=0xFF; + GenMMC3Power(); + SetWriteHandler(0x5ff0,0x5fff,BMCFK23CWrite); + SetWriteHandler(0x8000,0x8003,BMCFK23C8003Write); +} + +void BMCFK23C_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, 0); + cwrap=BMCFK23CCW; + pwrap=BMCFK23CPW; + info->Power=BMCFK23CPower; + info->Reset=BMCFK23CReset; + AddExState(EXPREGS, 8, 0, "EXPR"); + AddExState(&unromchr, 1, 0, "UNCHR"); +} diff --git a/boards/h2288.c b/boards/h2288.c index c2c6621..22bc7c2 100644 --- a/boards/h2288.c +++ b/boards/h2288.c @@ -1,89 +1,89 @@ -/* 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" -#include "mmc3.h" - -extern uint8 m114_perm[8]; - -static void H2288PW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x40) - { - uint8 bank=(EXPREGS[0]&5)|((EXPREGS[0]&8)>>2)|((EXPREGS[0]&0x20)>>2); - if(EXPREGS[0]&2) - setprg32(0x8000,bank>>1); - else - { - setprg16(0x8000,bank); - setprg16(0xC000,bank); - } - } - else - setprg8(A,V&0x3F); -} - -static DECLFW(H2288WriteHi) -{ - switch (A&0x8001) - { - case 0x8000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); break; - case 0x8001: MMC3_CMDWrite(0x8001,V); break; - } -} - -static DECLFW(H2288WriteLo) -{ - if(A&0x800) - { - if(A&1) - EXPREGS[1]=V; - else - EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - } -} - -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(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); - SetWriteHandler(0x8000,0x8FFF,H2288WriteHi); -} - -void UNLH2288_Init(CartInfo *info) -{ - GenMMC3_Init(info, 256, 256, 0, 0); - pwrap=H2288PW; - info->Power=H2288Power; - AddExState(EXPREGS, 2, 0, "EXPR"); -} +/* 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" +#include "mmc3.h" + +extern uint8 m114_perm[8]; + +static void H2288PW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + { + uint8 bank=(EXPREGS[0]&5)|((EXPREGS[0]&8)>>2)|((EXPREGS[0]&0x20)>>2); + if(EXPREGS[0]&2) + setprg32(0x8000,bank>>1); + else + { + setprg16(0x8000,bank); + setprg16(0xC000,bank); + } + } + else + setprg8(A,V&0x3F); +} + +static DECLFW(H2288WriteHi) +{ + switch (A&0x8001) + { + case 0x8000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m114_perm[V&7])); break; + case 0x8001: MMC3_CMDWrite(0x8001,V); break; + } +} + +static DECLFW(H2288WriteLo) +{ + if(A&0x800) + { + if(A&1) + EXPREGS[1]=V; + else + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + } +} + +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(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x5000,0x5FFF,H2288WriteLo); + SetWriteHandler(0x8000,0x8FFF,H2288WriteHi); +} + +void UNLH2288_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=H2288PW; + info->Power=H2288Power; + AddExState(EXPREGS, 2, 0, "EXPR"); +} diff --git a/boards/karaoke.c b/boards/karaoke.c index eccf9c2..e089cda 100644 --- a/boards/karaoke.c +++ b/boards/karaoke.c @@ -20,59 +20,52 @@ #include "mapinc.h" -static uint8 DReg; -static SFORMAT StateRegs[]= -{ - {&DReg, 1, "DREG"}, - {0} -}; +extern uint32 ROM_size; +static uint8 latche; static void Sync(void) { - if(DReg) + if(latche) { - if(DReg & 0x10) - setprg16(0x8000,(DReg&7)); + if(latche&0x10) + setprg16(0x8000,(latche&7)); else - setprg16(0x8000,(DReg&7)|8); + setprg16(0x8000,(latche&7)|8); } else - setprg16(0x8000,7); -} - -static void StateRestore(int version) -{ - Sync(); + setprg16(0x8000,7+(ROM_size>>4)); } static DECLFW(M188Write) { - DReg=V; + latche=V; Sync(); } -static DECLFR(testr) +static DECLFR(ExtDev) { return(3); } - static void Power(void) { - setchr8(0); - setprg8(0xc000,0xE); - setprg8(0xe000,0xF); - DReg = 0; + latche=0; Sync(); - SetReadHandler(0x6000,0x7FFF,testr); + setchr8(0); + setprg16(0xc000,0x7); + SetReadHandler(0x6000,0x7FFF,ExtDev); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x8000,0xFFFF,M188Write); } +static void StateRestore(int version) +{ + Sync(); +} void Mapper188_Init(CartInfo *info) { info->Power=Power; GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); + AddExState(&latche, 1, 0, "LATCH"); } diff --git a/mappers/58.c b/boards/kof97.c similarity index 56% rename from mappers/58.c rename to boards/kof97.c index d3cc505..4e477d3 100644 --- a/mappers/58.c +++ b/boards/kof97.c @@ -1,7 +1,7 @@ /* FCE Ultra - NES/Famicom Emulator * * Copyright notice for this file: - * Copyright (C) 2002 Xodnizel + * 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 @@ -19,25 +19,32 @@ */ #include "mapinc.h" +#include "mmc3.h" -static DECLFW(M58Write) +static DECLFW(UNLKOF97CMDWrite) { - //printf("$%04x:$%02x\n",A,V); - if(A&0x40) - { - ROM_BANK16(0x8000,(A&0x07)); - ROM_BANK16(0xc000,(A&0x07)); - } - else - ROM_BANK32((A&0x06)>>1); + V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2); //76143502 + if(A==0x9000) A=0x8001; + MMC3_CMDWrite(A,V); +} - VROM_BANK8((A&0x38)>>3); - MIRROR_SET2((V&2)>>1); +static DECLFW(UNLKOF97IRQWrite) +{ + V=(V&0xD8)|((V&0x20)>>4)|((V&4)<<3)|((V&2)>>1)|((V&1)<<2); + if(A==0xD000) A=0xC001; + else if(A==0xF000) A=0xE001; + MMC3_IRQWrite(A,V); +} + +static void UNLKOF97Power(void) +{ + GenMMC3Power(); + SetWriteHandler(0x8000,0xA000,UNLKOF97CMDWrite); + SetWriteHandler(0xC000,0xF000,UNLKOF97IRQWrite); } -void Mapper58_init(void) +void UNLKOF97_Init(CartInfo *info) { - ROM_BANK32(0); - VROM_BANK8(0); - SetWriteHandler(0x8000,0xFFFF,M58Write); + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=UNLKOF97Power; } diff --git a/boards/konami-qtai.c b/boards/konami-qtai.c index ff552e1..d42ff0b 100644 --- a/boards/konami-qtai.c +++ b/boards/konami-qtai.c @@ -1,128 +1,128 @@ -/* 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 - * - * CAI Shogakko no Sansu - */ - -#include "mapinc.h" - -static uint8 *CHRRAM=NULL; -static uint8 SWRAM[4096]; - -static uint8 regs[16]; -static uint8 WRAM[4096]; -static SFORMAT StateRegs[]= -{ - {®s, 16, "REGS"}, - {WRAM, 4096, "WRAM"}, - {0} -}; - -static void Sync(void) -{ - if(regs[5]&0x40) - { - setchr4r(0,0x1000,regs[5]&0x3F); - } - else - { - setchr4r(0x10,0x0000,regs[5]); - setchr4r(0x10,0x1000,regs[5]^1); - } - setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F)); - setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F)); - setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F)); - setprg8r(1,0xE000,~0); - setmirror((regs[0xA]&3)); -} - -static DECLFW(M190Write) -{ -// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); - regs[(A&0x0F00)>>8]=V; - Sync(); -} - -static DECLFR(M190Read) -{ -// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); - return regs[(A&0x0F00)>>8]; -} - -static DECLFR(AWRAM) -{ - return(WRAM[A-0x7000]); -} -static DECLFW(BWRAM) -{ - WRAM[A-0x7000]=V; -} - -static DECLFR(ASWRAM) -{ - return(SWRAM[A-0x6000]); -} -static DECLFW(BSWRAM) -{ - SWRAM[A-0x6000]=V; -} - -static void M190Power(void) -{ - setvram8(CHRRAM); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,M190Write); -// SetReadHandler(0xDA00,0xDA00,M190Read); -// SetReadHandler(0xDB00,0xDB00,M190Read); - SetReadHandler(0xDC00,0xDC00,M190Read); - SetReadHandler(0xDD00,0xDD00,M190Read); - SetReadHandler(0x7000,0x7FFF,AWRAM); - SetWriteHandler(0x7000,0x7FFF,BWRAM); - SetReadHandler(0x6000,0x6FFF,ASWRAM); - SetWriteHandler(0x6000,0x6FFF,BSWRAM); - Sync(); -} - -static void M190Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM=NULL; -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper190_Init(CartInfo *info) -{ - info->Power=M190Power; - info->Close=M190Close; - if(info->battery) - { - info->SaveGame[0]=SWRAM; - info->SaveGameLen[0]=4096; - } - GameStateRestore=StateRestore; - CHRRAM=(uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10,CHRRAM,8192,1); - AddExState(CHRRAM, 8192, 0, "CHRRAM"); - AddExState(&StateRegs, ~0, 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * CAI Shogakko no Sansu + */ + +#include "mapinc.h" + +static uint8 *CHRRAM=NULL; +static uint8 SWRAM[4096]; + +static uint8 regs[16]; +static uint8 WRAM[4096]; +static SFORMAT StateRegs[]= +{ + {®s, 16, "REGS"}, + {WRAM, 4096, "WRAM"}, + {0} +}; + +static void Sync(void) +{ + if(regs[5]&0x40) + { + setchr4r(0,0x1000,regs[5]&0x3F); + } + else + { + setchr4r(0x10,0x0000,regs[5]); + setchr4r(0x10,0x1000,regs[5]^1); + } + setprg8r((regs[2]>>6)&1,0x8000,(regs[2]&0x3F)); + setprg8r((regs[3]>>6)&1,0xA000,(regs[3]&0x3F)); + setprg8r((regs[4]>>6)&1,0xC000,(regs[4]&0x3F)); + setprg8r(1,0xE000,~0); + setmirror((regs[0xA]&3)); +} + +static DECLFW(M190Write) +{ +// FCEU_printf("write %04x:%04x %d, %d\n",A,V,scanline,timestamp); + regs[(A&0x0F00)>>8]=V; + Sync(); +} + +static DECLFR(M190Read) +{ +// FCEU_printf("read %04x:%04x %d, %d\n",A,regs[(A&0x0F00)>>8],scanline,timestamp); + return regs[(A&0x0F00)>>8]; +} + +static DECLFR(AWRAM) +{ + return(WRAM[A-0x7000]); +} +static DECLFW(BWRAM) +{ + WRAM[A-0x7000]=V; +} + +static DECLFR(ASWRAM) +{ + return(SWRAM[A-0x6000]); +} +static DECLFW(BSWRAM) +{ + SWRAM[A-0x6000]=V; +} + +static void M190Power(void) +{ + setvram8(CHRRAM); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,M190Write); +// SetReadHandler(0xDA00,0xDA00,M190Read); +// SetReadHandler(0xDB00,0xDB00,M190Read); + SetReadHandler(0xDC00,0xDC00,M190Read); + SetReadHandler(0xDD00,0xDD00,M190Read); + SetReadHandler(0x7000,0x7FFF,AWRAM); + SetWriteHandler(0x7000,0x7FFF,BWRAM); + SetReadHandler(0x6000,0x6FFF,ASWRAM); + SetWriteHandler(0x6000,0x6FFF,BSWRAM); + Sync(); +} + +static void M190Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper190_Init(CartInfo *info) +{ + info->Power=M190Power; + info->Close=M190Close; + if(info->battery) + { + info->SaveGame[0]=SWRAM; + info->SaveGameLen[0]=4096; + } + GameStateRestore=StateRestore; + CHRRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10,CHRRAM,8192,1); + AddExState(CHRRAM, 8192, 0, "CHRRAM"); + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/malee.c b/boards/malee.c index b0f194e..7feb95e 100644 --- a/boards/malee.c +++ b/boards/malee.c @@ -26,7 +26,7 @@ static void MALEEReset(void) { setprg2r(0x10,0x7000,0); SetReadHandler(0x8000,0xFFFF,CartBR); - SetReadHandler(0x6000,0x67ff,CartBR); + SetReadHandler(0x6000,0x67FF,CartBR); SetReadHandler(0x7000,0x77FF,CartBR); setprg2r(1,0x6000,0); setprg32(0x8000,0); diff --git a/boards/mapinc.h b/boards/mapinc.h index 7c2b042..81d4edb 100644 --- a/boards/mapinc.h +++ b/boards/mapinc.h @@ -6,6 +6,7 @@ #include "../sound.h" #include "../state.h" #include "../cart.h" +#include "../ines.h" #include "../cheat.h" #include "../unif.h" #include "../svga.h" diff --git a/boards/mmc1.c b/boards/mmc1.c index 0eefc59..816a1ed 100644 --- a/boards/mmc1.c +++ b/boards/mmc1.c @@ -1,426 +1,423 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -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 int mmc1opts; - -static void (*MMC1CHRHook4)(uint32 A, uint8 V); -static void (*MMC1PRGHook16)(uint32 A, uint8 V); - -static uint8 *WRAM=NULL; -static uint8 *CHRRAM=NULL; -static int is155; - -static DECLFW(MBWRAM) -{ - if(!(DRegs[3]&0x10)||is155) - Page[A>>11][A]=V; // WRAM is enabled. -} - -static DECLFR(MAWRAM) -{ - if((DRegs[3]&0x10)&&!is155) - return X.DB; // WRAM is disabled - return(Page[A>>11][A]); -} - -static void MMC1CHR(void) -{ - if(mmc1opts&4) - { - if(DRegs[0]&0x10) - setprg8r(0x10,0x6000,(DRegs[1]>>4)&1); - else - setprg8r(0x10,0x6000,(DRegs[1]>>3)&1); - } - if(MMC1CHRHook4) - { - if(DRegs[0]&0x10) - { - MMC1CHRHook4(0x0000,DRegs[1]); - MMC1CHRHook4(0x1000,DRegs[2]); - } - else - { - MMC1CHRHook4(0x0000,(DRegs[1]&0xFE)); - MMC1CHRHook4(0x1000,DRegs[1]|1); - } - } - else - { - if(DRegs[0]&0x10) - { - setchr4(0x0000,DRegs[1]); - setchr4(0x1000,DRegs[2]); - } - else - setchr8(DRegs[1]>>1); - } -} - -static void MMC1PRG(void) -{ - uint8 offs=DRegs[1]&0x10; - - if(MMC1PRGHook16) - { - switch(DRegs[0]&0xC) - { - case 0xC: MMC1PRGHook16(0x8000,(DRegs[3]+offs)); - MMC1PRGHook16(0xC000,0xF+offs); - break; - case 0x8: MMC1PRGHook16(0xC000,(DRegs[3]+offs)); - MMC1PRGHook16(0x8000,offs); - break; - case 0x0: - case 0x4: - MMC1PRGHook16(0x8000,((DRegs[3]&~1)+offs)); - MMC1PRGHook16(0xc000,((DRegs[3]&~1)+offs+1)); - break; - } - } - 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; - } -} - -static void MMC1MIRROR(void) -{ - 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",timestampbase+timestamp); - //printf("$%04x:$%02x, $%04x\n",A,V,X.PC); - //DumpMem("out",0xe000,0xffff); - - /* The MMC1 is busy so ignore the write. */ - /* As of version FCE Ultra 0.81, the timestamp is only - increased before each instruction is executed(in other words - precision isn't that great), but this should still work to - deal with 2 writes in a row from a single RMW instruction. */ - if((timestampbase+timestamp)<(lreset+2)) return; - - if(V&0x80) - { - DRegs[0]|=0xC; - BufferShift=Buffer=0; - MMC1PRG(); - lreset=timestampbase+timestamp; - return; - } - Buffer|=(V&1)<<(BufferShift++); - if(BufferShift==5) - { - DRegs[n] = Buffer; - BufferShift = Buffer = 0; - switch(n) - { - case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; - case 1: MMC1CHR(); MMC1PRG(); break; - case 2: MMC1CHR(); break; - case 3: MMC1PRG(); break; - } - } -} - -static void MMC1_Restore(int version) -{ - MMC1MIRROR(); - MMC1CHR(); - MMC1PRG(); - //lreset=0; /* timestamp(base) is not stored in save states. */ // it is now! -} - -static void MMC1CMReset(void) -{ - int i; - for(i=0;i<4;i++) - DRegs[i]=0; - Buffer = BufferShift = 0; - DRegs[0]=0x1F; - DRegs[1]=0; - DRegs[2]=0; // Should this be something other than 0? - DRegs[3]=0; - - MMC1MIRROR(); - MMC1CHR(); - MMC1PRG(); -} - -static int DetectMMC1WRAMSize(uint32 crc32) -{ - switch(crc32) - { - case 0xc6182024: /* Romance of the 3 Kingdoms */ - case 0x2225c20f: /* Genghis Khan */ - case 0x4642dda6: /* Nobunaga's Ambition */ - case 0x29449ba9: /* "" "" (J) */ - case 0x2b11e0b0: /* "" "" (J) */ - FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(16); - break; - default:return(8); - } -} - -static uint32 NWCIRQCount; -static uint8 NWCRec; -#define NWCDIP 0xE - -static void FP_FASTAPASS(1) NWCIRQHook(int a) -{ - if(!(NWCRec&0x10)) - { - NWCIRQCount+=a; - if((NWCIRQCount|(NWCDIP<<25))>=0x3e000000) - { - NWCIRQCount=0; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -static void NWCCHRHook(uint32 A, uint8 V) -{ - if((V&0x10)) // && !(NWCRec&0x10)) - { - NWCIRQCount=0; - X6502_IRQEnd(FCEU_IQEXT); - } - NWCRec=V; - if(V&0x08) - MMC1PRG(); - else - setprg32(0x8000,(V>>1)&3); -} - -static void NWCPRGHook(uint32 A, uint8 V) -{ - if(NWCRec&0x8) - setprg16(A,8|(V&0x7)); - else - setprg32(0x8000,(NWCRec>>1)&3); -} - -static void NWCPower(void) -{ - GenMMC1Power(); - setchr8r(0,0); -} - -void Mapper105_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 256, 8, 0); - MMC1CHRHook4=NWCCHRHook; - MMC1PRGHook16=NWCPRGHook; - MapIRQHook=NWCIRQHook; - info->Power=NWCPower; -} - -static void GenMMC1Power(void) -{ - lreset=0; - if(mmc1opts&1) - { - FCEU_CheatAddRAM(8,0x6000,WRAM); - if(mmc1opts&4) - FCEU_dwmemset(WRAM,0,8192) - else if(!(mmc1opts&2)) - FCEU_dwmemset(WRAM,0,8192); - } - SetWriteHandler(0x8000,0xFFFF,MMC1_write); - SetReadHandler(0x8000,0xFFFF,CartBR); - - if(mmc1opts&1) - { - SetReadHandler(0x6000,0x7FFF,MAWRAM); - SetWriteHandler(0x6000,0x7FFF,MBWRAM); - setprg8r(0x10,0x6000,0); - } - - MMC1CMReset(); -} - -static void GenMMC1Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - if(WRAM) - FCEU_gfree(WRAM); - CHRRAM=WRAM=NULL; -} - -static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) -{ - is155=0; - - info->Close=GenMMC1Close; - MMC1PRGHook16=MMC1CHRHook4=0; - mmc1opts=0; - PRGmask16[0]&=(prg>>14)-1; - CHRmask4[0]&=(chr>>12)-1; - CHRmask8[0]&=(chr>>13)-1; - - if(wram) - { - WRAM=(uint8*)FCEU_gmalloc(wram*1024); - mmc1opts|=1; - if(wram>8) mmc1opts|=4; - SetupCartPRGMapping(0x10,WRAM,wram*1024,1); - AddExState(WRAM, wram*1024, 0, "WRAM"); - if(battery) - { - mmc1opts|=2; - info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0); - info->SaveGameLen[0]=8192; - } - } - if(!chr) - { - CHRRAM=(uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0, CHRRAM, 8192, 1); - AddExState(CHRRAM, 8192, 0, "CHRR"); - } - AddExState(DRegs, 4, 0, "DREG"); - - 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) -{ - int ws=DetectMMC1WRAMSize(info->CRC32); - GenMMC1Init(info, 512, 256, ws, info->battery); -} - -/* Same as mapper 1, without respect for WRAM enable bit. */ -void Mapper155_Init(CartInfo *info) -{ - GenMMC1Init(info,512,256,8,info->battery); - is155=1; -} - -void SAROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 128, 64, 8, info->battery); -} - -void SBROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 128, 64, 0, 0); -} - -void SCROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 128, 128, 0, 0); -} - -void SEROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 32, 64, 0, 0); -} - -void SGROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 0, 0, 0); -} - -void SKROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 64, 8, info->battery); -} - -void SLROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 128, 0, 0); -} - -void SL1ROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 128, 128, 0, 0); -} - -/* Begin unknown - may be wrong - perhaps they use different MMC1s from the - similarly functioning boards? -*/ - -void SL2ROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 256, 0, 0); -} - -void SFROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 256, 0, 0); -} - -void SHROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 256, 0, 0); -} - -/* End unknown */ -/* */ -/* */ - -void SNROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 0, 8, info->battery); -} - -void SOROM_Init(CartInfo *info) -{ - GenMMC1Init(info, 256, 0, 16, info->battery); -} - - +/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +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 int mmc1opts; + +static void (*MMC1CHRHook4)(uint32 A, uint8 V); +static void (*MMC1PRGHook16)(uint32 A, uint8 V); + +static uint8 *WRAM=NULL; +static uint8 *CHRRAM=NULL; +static int is155; + +static DECLFW(MBWRAM) +{ + if(!(DRegs[3]&0x10)||is155) + Page[A>>11][A]=V; // WRAM is enabled. +} + +static DECLFR(MAWRAM) +{ + if((DRegs[3]&0x10)&&!is155) + return X.DB; // WRAM is disabled + return(Page[A>>11][A]); +} + +static void MMC1CHR(void) +{ + if(mmc1opts&4) + { + if(DRegs[0]&0x10) + setprg8r(0x10,0x6000,(DRegs[1]>>4)&1); + else + setprg8r(0x10,0x6000,(DRegs[1]>>3)&1); + } + if(MMC1CHRHook4) + { + if(DRegs[0]&0x10) + { + MMC1CHRHook4(0x0000,DRegs[1]); + MMC1CHRHook4(0x1000,DRegs[2]); + } + else + { + MMC1CHRHook4(0x0000,(DRegs[1]&0xFE)); + MMC1CHRHook4(0x1000,DRegs[1]|1); + } + } + else + { + if(DRegs[0]&0x10) + { + setchr4(0x0000,DRegs[1]); + setchr4(0x1000,DRegs[2]); + } + else + setchr8(DRegs[1]>>1); + } +} + +static void MMC1PRG(void) +{ + uint8 offs=DRegs[1]&0x10; + if(MMC1PRGHook16) + { + switch(DRegs[0]&0xC) + { + case 0xC: MMC1PRGHook16(0x8000,(DRegs[3]+offs)); + MMC1PRGHook16(0xC000,0xF+offs); + break; + case 0x8: MMC1PRGHook16(0xC000,(DRegs[3]+offs)); + MMC1PRGHook16(0x8000,offs); + break; + case 0x0: + case 0x4: + MMC1PRGHook16(0x8000,((DRegs[3]&~1)+offs)); + MMC1PRGHook16(0xc000,((DRegs[3]&~1)+offs+1)); + break; + } + } + 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; + } +} + +static void MMC1MIRROR(void) +{ + 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",timestampbase+timestamp); + //printf("$%04x:$%02x, $%04x\n",A,V,X.PC); + //DumpMem("out",0xe000,0xffff); + + /* The MMC1 is busy so ignore the write. */ + /* As of version FCE Ultra 0.81, the timestamp is only + increased before each instruction is executed(in other words + precision isn't that great), but this should still work to + deal with 2 writes in a row from a single RMW instruction. */ + if((timestampbase+timestamp)<(lreset+2)) return; + if(V&0x80) + { + DRegs[0]|=0xC; + BufferShift=Buffer=0; + MMC1PRG(); + lreset=timestampbase+timestamp; + return; + } + Buffer|=(V&1)<<(BufferShift++); + if(BufferShift==5) + { + DRegs[n] = Buffer; + BufferShift = Buffer = 0; + switch(n) + { + case 0: MMC1MIRROR(); MMC1CHR(); MMC1PRG(); break; + case 1: MMC1CHR(); MMC1PRG(); break; + case 2: MMC1CHR(); break; + case 3: MMC1PRG(); break; + } + } +} + +static void MMC1_Restore(int version) +{ + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); + lreset=0; /* timestamp(base) is not stored in save states. */ +} + +static void MMC1CMReset(void) +{ + int i; + for(i=0;i<4;i++) + DRegs[i]=0; + Buffer = BufferShift = 0; + DRegs[0]=0x1F; + DRegs[1]=0; + DRegs[2]=0; // Should this be something other than 0? + DRegs[3]=0; + + MMC1MIRROR(); + MMC1CHR(); + MMC1PRG(); +} + +static int DetectMMC1WRAMSize(uint32 crc32) +{ + switch(crc32) + { + case 0xc6182024: /* Romance of the 3 Kingdoms */ + case 0x2225c20f: /* Genghis Khan */ + case 0x4642dda6: /* Nobunaga's Ambition */ + case 0x29449ba9: /* "" "" (J) */ + case 0x2b11e0b0: /* "" "" (J) */ + case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */ + case 0xc9556b36: /* Final Fantasy I & II (J) [!] */ + FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(16); + break; + default:return(8); + } +} + +static uint32 NWCIRQCount; +static uint8 NWCRec; +#define NWCDIP 0xE + +static void FP_FASTAPASS(1) NWCIRQHook(int a) +{ + if(!(NWCRec&0x10)) + { + NWCIRQCount+=a; + if((NWCIRQCount|(NWCDIP<<25))>=0x3e000000) + { + NWCIRQCount=0; + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void NWCCHRHook(uint32 A, uint8 V) +{ + if((V&0x10)) // && !(NWCRec&0x10)) + { + NWCIRQCount=0; + X6502_IRQEnd(FCEU_IQEXT); + } + NWCRec=V; + if(V&0x08) + MMC1PRG(); + else + setprg32(0x8000,(V>>1)&3); +} + +static void NWCPRGHook(uint32 A, uint8 V) +{ + if(NWCRec&0x8) + setprg16(A,8|(V&0x7)); + else + setprg32(0x8000,(NWCRec>>1)&3); +} + +static void NWCPower(void) +{ + GenMMC1Power(); + setchr8r(0,0); +} + +void Mapper105_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 8, 0); + MMC1CHRHook4=NWCCHRHook; + MMC1PRGHook16=NWCPRGHook; + MapIRQHook=NWCIRQHook; + info->Power=NWCPower; +} + +static void GenMMC1Power(void) +{ + lreset=0; + if(mmc1opts&1) + { + FCEU_CheatAddRAM(8,0x6000,WRAM); + if(mmc1opts&4) + FCEU_dwmemset(WRAM,0,8192) + else if(!(mmc1opts&2)) + FCEU_dwmemset(WRAM,0,8192); + } + SetWriteHandler(0x8000,0xFFFF,MMC1_write); + SetReadHandler(0x8000,0xFFFF,CartBR); + + if(mmc1opts&1) + { + SetReadHandler(0x6000,0x7FFF,MAWRAM); + SetWriteHandler(0x6000,0x7FFF,MBWRAM); + setprg8r(0x10,0x6000,0); + } + + MMC1CMReset(); +} + +static void GenMMC1Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + if(WRAM) + FCEU_gfree(WRAM); + CHRRAM=WRAM=NULL; +} + +static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) +{ + is155=0; + + info->Close=GenMMC1Close; + MMC1PRGHook16=MMC1CHRHook4=0; + mmc1opts=0; + PRGmask16[0]&=(prg>>14)-1; + CHRmask4[0]&=(chr>>12)-1; + CHRmask8[0]&=(chr>>13)-1; + + if(wram) + { + WRAM=(uint8*)FCEU_gmalloc(wram*1024); + mmc1opts|=1; + if(wram>8) mmc1opts|=4; + SetupCartPRGMapping(0x10,WRAM,wram*1024,1); + AddExState(WRAM, wram*1024, 0, "WRAM"); + if(battery) + { + mmc1opts|=2; + info->SaveGame[0]=WRAM+((mmc1opts&4)?8192:0); + info->SaveGameLen[0]=8192; + } + } + if(!chr) + { + CHRRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + } + AddExState(DRegs, 4, 0, "DREG"); + + info->Power=GenMMC1Power; + GameStateRestore=MMC1_Restore; + AddExState(&lreset, 8, 1, "LRST"); +} + +void Mapper1_Init(CartInfo *info) +{ + int ws=DetectMMC1WRAMSize(info->CRC32); + GenMMC1Init(info, 512, 256, ws, info->battery); +} + +/* Same as mapper 1, without respect for WRAM enable bit. */ +void Mapper155_Init(CartInfo *info) +{ + GenMMC1Init(info,512,256,8,info->battery); + is155=1; +} + +void SAROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 64, 8, info->battery); +} + +void SBROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 64, 0, 0); +} + +void SCROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 128, 0, 0); +} + +void SEROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 32, 64, 0, 0); +} + +void SGROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 0, 0); +} + +void SKROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 64, 8, info->battery); +} + +void SLROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 128, 0, 0); +} + +void SL1ROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 128, 128, 0, 0); +} + +/* Begin unknown - may be wrong - perhaps they use different MMC1s from the + similarly functioning boards? +*/ + +void SL2ROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SFROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +void SHROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 256, 0, 0); +} + +/* End unknown */ +/* */ +/* */ + +void SNROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 8, info->battery); +} + +void SOROM_Init(CartInfo *info) +{ + GenMMC1Init(info, 256, 0, 16, info->battery); +} + + diff --git a/boards/mmc3.c b/boards/mmc3.c index 14ce5cb..6345910 100644 --- a/boards/mmc3.c +++ b/boards/mmc3.c @@ -27,20 +27,20 @@ #include "mapinc.h" #include "mmc3.h" -uint8 MMC3_cmd=0; -uint8 *WRAM=0; -uint8 *CHRRAM=0; -uint32 CHRRAMSize=0; -uint8 EXPREGS[8]={0,0,0,0,0,0,0,0}; /* For bootleg games, mostly. */ +uint8 MMC3_cmd; +uint8 *WRAM; +uint8 *CHRRAM; +uint32 CHRRAMSize; +uint8 EXPREGS[8]; /* For bootleg games, mostly. */ -static uint8 A000B=0,A001B=0; -static uint8 DRegBuf[8]={0,0,0,0,0,0,0,0}; +static uint8 A000B,A001B; +static uint8 DRegBuf[8]; #undef IRQCount #undef IRQLatch #undef IRQa -uint8 IRQCount=0,IRQLatch=0,IRQa=0; -uint8 IRQReload=0; +uint8 IRQCount,IRQLatch,IRQa; +uint8 IRQReload; static SFORMAT MMC3_StateRegs[]= { @@ -56,7 +56,8 @@ static SFORMAT MMC3_StateRegs[]= }; static int mmc3opts=0; -static int wrams=0; +static int wrams; +static int isRevB=1; void (*pwrap)(uint32 A, uint8 V); void (*cwrap)(uint32 A, uint8 V); @@ -122,6 +123,7 @@ void MMC3RegReset(void) DECLFW(MMC3_CMDWrite) { +// FCEU_printf("%04x:%04x\n",A,V); switch(A&0xE001) { case 0x8000: @@ -168,12 +170,14 @@ DECLFW(MMC3_CMDWrite) break; case 0xA001: A001B=V; + Write_IRQFM(0x4017,0x40); break; } } DECLFW(MMC3_IRQWrite) { +// FCEU_printf("%04x:%04x\n",A,V); switch(A&0xE001) { case 0xC000:IRQLatch=V;break; @@ -193,7 +197,7 @@ static void ClockMMC3Counter(void) } else IRQCount--; - if(count && !IRQCount) + if((count|isRevB) && !IRQCount) { if(IRQa) { @@ -219,7 +223,7 @@ static void MMC3_hb_PALStarWarsHack(void) ClockMMC3Counter(); } -static void genmmc3restore(int version) +void GenMMC3Restore(int version) { if(mwrap) mwrap(A000B&1); FixMMC3PRG(MMC3_cmd); @@ -228,7 +232,7 @@ static void genmmc3restore(int version) static void GENCWRAP(uint32 A, uint8 V) { - setchr1(A,V); + if(!UNIFchrrama) setchr1(A,V); } static void GENPWRAP(uint32 A, uint8 V) @@ -269,6 +273,8 @@ static DECLFR(MAWRAMMMC6) void GenMMC3Power(void) { + if(UNIFchrrama) setchr8(0); + SetWriteHandler(0x8000,0xBFFF,MMC3_CMDWrite); SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite); SetReadHandler(0x8000,0xFFFF,CartBR); @@ -305,9 +311,18 @@ static void GenMMC3Close(void) CHRRAM=WRAM=NULL; } +//static uint16 _a12; +//static void FP_FASTAPASS(1) MMC3_PPU(uint32 A) +//{ +// if(A&0x2000)return; +// if((!_a12)&&(A&0x1000)) +// ClockMMC3Counter(); +// _a12=A&0x1000; +//} + void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery) { -pwrap=GENPWRAP; + pwrap=GENPWRAP; cwrap=GENCWRAP; mwrap=GENMWRAP; @@ -331,13 +346,13 @@ pwrap=GENPWRAP; info->SaveGameLen[0]=wrams; } - if(!chr) - { - CHRRAM=(uint8*)FCEU_gmalloc(8192); - CHRRAMSize=8192; - SetupCartCHRMapping(0, CHRRAM, 8192, 1); - AddExState(CHRRAM, 8192, 0, "CHRR"); - } +// if(!chr) // duplicated CHR RAM set up +// { +// CHRRAM=(uint8*)FCEU_gmalloc(8192); +// CHRRAMSize=8192; +// SetupCartCHRMapping(0, CHRRAM, 8192, 1); +// AddExState(CHRRAM, 8192, 0, "CHRR"); +// } AddExState(MMC3_StateRegs, ~0, 0, 0); @@ -352,8 +367,9 @@ pwrap=GENPWRAP; else if(info->CRC32 == 0xfcd772eb) // PAL Star Wars, similar problem as Kick Master. GameHBIRQHook = MMC3_hb_PALStarWarsHack; else - GameHBIRQHook=MMC3_hb; - GameStateRestore=genmmc3restore; + GameHBIRQHook=MMC3_hb; +// PPU_hook=MMC3_PPU; + GameStateRestore=GenMMC3Restore; } // ---------------------------------------------------------------------- @@ -413,6 +429,56 @@ void Mapper12_Init(CartInfo *info) 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) @@ -464,16 +530,16 @@ void Mapper44_Init(CartInfo *info) static void M45CW(uint32 A, uint8 V) { - uint32 NV=V; - if(EXPREGS[2]&8) - NV&=(1<<((EXPREGS[2]&7)+1))-1; - else - NV&=0; - NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); - // &0x10(not 0xf0) is valid given the original - // description of mapper 45 by kevtris, - // but this fixes Super 8 in 1. - setchr1(A,NV); + if(!UNIFchrrama) + { + uint32 NV=V; + if(EXPREGS[2]&8) + NV&=(1<<((EXPREGS[2]&7)+1))-1; +// else +// NV&=0; + NV|=EXPREGS[0]|((EXPREGS[2]&0xF0)<<4); + setchr1(A,NV); + } } static void M45PW(uint32 A, uint8 V) @@ -492,20 +558,28 @@ static DECLFW(M45Write) } EXPREGS[EXPREGS[4]]=V; EXPREGS[4]=(EXPREGS[4]+1)&3; -// FCEU_printf("write 0=%04x 1=%04x 2=%04x 3=%04x (%04x:%04x)\n",EXPREGS[0],EXPREGS[1],EXPREGS[2],EXPREGS[3],A,V); + 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) { - FCEU_dwmemset(EXPREGS,0,5); + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=EXPREGS[3]=EXPREGS[4]=0; MMC3RegReset(); } static void M45Power(void) { - M45Reset(); + setchr8(0); GenMMC3Power(); SetWriteHandler(0x6000,0x7FFF,M45Write); } @@ -549,7 +623,7 @@ static void M47Power(void) EXPREGS[0]=0; GenMMC3Power(); SetWriteHandler(0x6000,0x7FFF,M47Write); - SetReadHandler(0x6000,0x7FFF,0); +// SetReadHandler(0x6000,0x7FFF,0); } void Mapper47_Init(CartInfo *info) @@ -675,22 +749,17 @@ void Mapper52_Init(CartInfo *info) static void M74CW(uint32 A, uint8 V) { -// FCEU_printf("%04x:%04x\n",A,V); -// if((V==0)||(V==1)) //Dai-2-Ji - Super Robot Taisen (As).nes - if((V==0)||(V==1)||(V==2)||(V==3)) //Ying Lie Qun Xia Zhuan (Chinese).nes, 4096 CHR RAM -// if((V==8)||(V==9)) //Di 4 Ci - Ji Qi Ren Dai Zhan (As).nes -// if((V==8)||(V==9)||(V==0xA)||(V==0xB)) //Ying Lie Qun Xia Zhuan (Chinese).nes, 4096 CHR RAM - setchr1r(0x10,A,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(0x0,A,V); + setchr1r(0,A,V); } void Mapper74_Init(CartInfo *info) { GenMMC3_Init(info, 512, 256, 8, info->battery); cwrap=M74CW; -// CHRRAMSize=2048; - CHRRAMSize=4096; + CHRRAMSize=2048; CHRRAM=(uint8*)FCEU_gmalloc(CHRRAMSize); SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); @@ -717,7 +786,8 @@ static DECLFW(M114Write) if(A==0xE003) { IRQa=1; - IRQCount=V; + IRQLatch=V; + IRQReload=1; } else if(A==0xE002) { @@ -771,14 +841,15 @@ void Mapper114_Init(CartInfo *info) static void M115PW(uint32 A, uint8 V) { - setprg8(A,V); - if(EXPREGS[0]&0x80) - setprg16(0x8000,EXPREGS[0]&7); + 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)); + setchr1(A,(uint32)V|((EXPREGS[1]&1)<<8)); } static DECLFW(M115Write) @@ -810,13 +881,16 @@ void Mapper115_Init(CartInfo *info) static void M116CW(uint32 A, uint8 V) { - setchr1(A,V|((EXPREGS[0]&0x4)<<6)); +// setchr1(A,V|((EXPREGS[0]&0x4)<<6)); + if(EXPREGS[0]&2) + setchr8r(0x10,0); + else + setchr1(A,V); } static DECLFW(M116Write) { EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); FixMMC3CHR(MMC3_cmd); } @@ -831,6 +905,8 @@ void Mapper116_Init(CartInfo *info) GenMMC3_Init(info, 128, 512, 0, 0); cwrap=M116CW; info->Power=M116Power; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); AddExState(EXPREGS, 4, 0, "EXPR"); } @@ -880,23 +956,6 @@ void Mapper119_Init(CartInfo *info) SetupCartCHRMapping(0x10, CHRRAM, CHRRAMSize, 1); } -// ---------------------------- 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 165 ------------------------------ static void M165CW(uint32 A, uint8 V) @@ -927,8 +986,10 @@ static void M165PPUFE(void) 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(); + 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) @@ -975,7 +1036,14 @@ static DECLFW(M182Write) case 0x8001: setmirror((V&1)^1); break; case 0xA000: MMC3_CMDWrite(0x8000,m114_perm[V&7]); break; case 0xC000: MMC3_CMDWrite(0x8001,V); break; - case 0xE003: IRQCount=V; IRQa=1; X6502_IRQEnd(FCEU_IQEXT); break; + case 0xE003: if(V) + { + IRQLatch=V; + IRQReload=1; + IRQa=1; + } + X6502_IRQEnd(FCEU_IQEXT); + break; } } @@ -991,6 +1059,131 @@ void Mapper182_Init(CartInfo *info) info->Power=M182Power; } +// ---------------------------- 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 198 ------------------------------- + +static uint8 *wramtw; +static uint16 wramsize; +static void M198CW(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 M198Power(void) +{ + GenMMC3Power(); + setprg4r(0x10,0x5000,0); + SetWriteHandler(0x5000,0x5fff,CartBW); + SetReadHandler(0x5000,0x5fff,CartBR); +} + +static void M198Close(void) +{ + if(wramtw) + FCEU_gfree(wramtw); + wramtw=NULL; +} + +void Mapper198_Init(CartInfo *info) +{ + GenMMC3_Init(info, 512, 256, 8, info->battery); + cwrap=M198CW; + info->Power=M198Power; + info->Close=M198Close; + 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 199 ------------------------------- + +static uint8 *wramtw; +static uint16 wramsize; +static void M199PW(uint32 A, uint8 V) +{ + if(V>=0x50) + setprg8(A,V&0x4F); + else + setprg8(A,V); +} + +void Mapper199_Init(CartInfo *info) +{ + GenMMC3_Init(info, 1024, 256, 8, info->battery); + pwrap=M199PW; + info->Power=M198Power; + info->Close=M198Close; + wramsize=4096; + wramtw=(uint8*)FCEU_gmalloc(wramsize); + SetupCartPRGMapping(0x10, wramtw, wramsize, 1); + AddExState(CHRRAM, CHRRAMSize, 0, "CHRR"); + AddExState(wramtw, wramsize, 0, "WRAMTW"); +} + // ---------------------------- Mapper 205 ------------------------------ static void M205PW(uint32 A, uint8 V) @@ -1003,7 +1196,7 @@ static void M205PW(uint32 A, uint8 V) static void M205CW(uint32 A, uint8 V) { - setchr1(A,V|((EXPREGS[0]&3)*128)); + setchr1(A,V|((EXPREGS[0]&3)<<7)); } static DECLFW(M205Write) @@ -1071,9 +1264,10 @@ static DECLFW(M215Write) } else switch(A&0xE001) { + case 0xC001: IRQLatch=V; break; + case 0xA001: IRQReload=1; break; + case 0xE001: IRQa=1; break; case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; - case 0xE001: IRQCount=V; break; - case 0xC001: IRQa=1; break; case 0xC000: setmirror(((V|(V>>7))&1)^1); break; case 0xA000: MMC3_CMDWrite(0x8000,(V&0xC0)|(m215_perm[V&7])); cmdin=1; break; case 0x8001: if(!cmdin) break; @@ -1152,21 +1346,21 @@ static DECLFW(M217Write) if(!EXPREGS[2]) { if(A >= 0xc000) - MMC3_IRQWrite(A, V); + MMC3_IRQWrite(A, V); else - MMC3_CMDWrite(A,V); + MMC3_CMDWrite(A,V); } else switch(A&0xE001) { - case 0x8000: IRQCount=V; break; - case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; - case 0xC001: IRQa=1; break; - case 0xA001: setmirror((V&1)^1); break; - case 0x8001: MMC3_CMDWrite(0x8000,(V&0xC0)|(m217_perm[V&7])); cmdin=1; break; - case 0xA000: if(!cmdin) break; - MMC3_CMDWrite(0x8001,V); - cmdin=0; - break; + case 0x8000: IRQCount=V; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT);IRQa=0; break; + case 0xC001: IRQa=1; break; + case 0xA001: setmirror((V&1)^1); break; + case 0x8001: MMC3_CMDWrite(0x8000,(V&0xC0)|(m217_perm[V&7])); cmdin=1; break; + case 0xA000: if(!cmdin) break; + MMC3_CMDWrite(0x8001,V); + cmdin=0; + break; } } diff --git a/boards/mmc3.h b/boards/mmc3.h index e2c7149..6692dd4 100644 --- a/boards/mmc3.h +++ b/boards/mmc3.h @@ -1,22 +1,23 @@ -extern uint8 MMC3_cmd; -extern uint8 *WRAM; -//extern uint8 *CHRRAM; -extern uint8 EXPREGS[8]; -#undef IRQCount -#undef IRQLatch -#undef IRQa -extern uint8 IRQCount,IRQLatch,IRQa; -extern uint8 IRQReload; - -extern void (*pwrap)(uint32 A, uint8 V); -extern void (*cwrap)(uint32 A, uint8 V); -extern void (*mwrap)(uint8 V); - -void GenMMC3Power(void); -void MMC3RegReset(void); -void FixMMC3PRG(int V); -void FixMMC3CHR(int V); -DECLFW(MMC3_CMDWrite); -DECLFW(MMC3_IRQWrite); - -void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); +extern uint8 MMC3_cmd; +extern uint8 *WRAM; +extern uint8 *CHRRAM; +extern uint8 EXPREGS[8]; +#undef IRQCount +#undef IRQLatch +#undef IRQa +extern uint8 IRQCount,IRQLatch,IRQa; +extern uint8 IRQReload; + +extern void (*pwrap)(uint32 A, uint8 V); +extern void (*cwrap)(uint32 A, uint8 V); +extern void (*mwrap)(uint8 V); + +void GenMMC3Power(void); +void GenMMC3Restore(int version); +void MMC3RegReset(void); +void FixMMC3PRG(int V); +void FixMMC3CHR(int V); +DECLFW(MMC3_CMDWrite); +DECLFW(MMC3_IRQWrite); + +void GenMMC3_Init(CartInfo *info, int prg, int chr, int wram, int battery); diff --git a/boards/sachen.c b/boards/sachen.c index bcec3a9..64ad5f6 100644 --- a/boards/sachen.c +++ b/boards/sachen.c @@ -23,7 +23,7 @@ static uint8 cmd; static uint8 latch[8]; -static void MSync(uint8 mirr) +static void S74LS374MSync(uint8 mirr) { switch(mirr&3) { @@ -38,7 +38,7 @@ static void S74LS374NSynco(void) { setprg32(0x8000,latch[0]); setchr8(latch[1]|latch[3]|latch[4]); - MSync(latch[2]); + S74LS374MSync(latch[2]); } static DECLFW(S74LS374NWrite) @@ -50,9 +50,9 @@ static DECLFW(S74LS374NWrite) { switch(cmd) { - case 2:latch[3]=(V&1)<<3;break; + case 2:latch[0]=V&1; latch[3]=(V&1)<<3;break; case 4:latch[4]=(V&1)<<2;break; - case 5:latch[0]=V&0x7;break; + case 5:latch[0]=V&7;break; case 6:latch[1]=V&3;break; case 7:latch[2]=V>>1;break; } @@ -60,12 +60,23 @@ static DECLFW(S74LS374NWrite) } } +static DECLFR(S74LS374NRead) +{ + uint8 ret; + if((A&0x4100)==0x4100) + ret=(X.DB&0xC0)|((~cmd)&0x3F); + else + ret=X.DB; + return ret; +} + static void S74LS374NPower(void) { latch[0]=latch[1]=latch[2]=latch[3]=latch[4]=0; S74LS374NSynco(); SetReadHandler(0x8000,0xFFFF,CartBR); SetWriteHandler(0x4100,0x7FFF,S74LS374NWrite); + SetReadHandler(0x4100,0x5fff,S74LS374NRead); } static void S74LS374NRestore(int version) @@ -85,7 +96,7 @@ static void S74LS374NASynco(void) { setprg32(0x8000,latch[0]); setchr8(latch[1]); - MSync(latch[2]); + S74LS374MSync(latch[2]); } static DECLFW(S74LS374NAWrite) @@ -104,7 +115,7 @@ static DECLFW(S74LS374NAWrite) case 6:latch[1]=(latch[1]&1)|latch[3]|((V&3)<<1);break; case 7:latch[2]=V&1;break; } - S74LS374NSynco(); + S74LS374NASynco(); } } @@ -126,7 +137,6 @@ void S74LS374NA_Init(CartInfo *info) } static int type; -//static int PPUbus; static void S8259Synco(void) { int x; @@ -159,7 +169,10 @@ static void S8259Synco(void) } } } - MSync(latch[7]>>1); + if(!(latch[7]&1)) + S74LS374MSync(latch[7]>>1); + else + setmirror(MI_V); } static DECLFW(S8259Write) @@ -230,12 +243,6 @@ void S8259D_Init(CartInfo *info) // Kevin's Horton 137 mapper static void(*WSync)(void); -static void SA0161MSynco() -{ - setprg32(0x8000,(latch[0]>>3)&1); - setchr8(latch[0]&7); -} - static DECLFW(SAWrite) { if(A&0x100) @@ -245,7 +252,7 @@ static DECLFW(SAWrite) } } -static void SAReset(void) +static void SAPower(void) { latch[0]=0; WSync(); @@ -253,36 +260,35 @@ static void SAReset(void) SetWriteHandler(0x4100,0x5FFF,SAWrite); } -static void SA0161MRestore(int version) +static void SARestore(int version) { - SA0161MSynco(); + WSync(); } -void SA0161M_Init(CartInfo *info) +static DECLFW(SADWrite) { - WSync=SA0161MSynco; - GameStateRestore=SA0161MRestore; - info->Power=SAReset; - AddExState(&latch[0], 1, 0, "LATC"); + latch[0]=V; + WSync(); } -static void SA72007Synco() +static void SADPower(void) { - setprg32(0x8000,0); - setchr8(latch[0]>>7); + latch[0]=0; + WSync(); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,SADWrite); } -static void SA72007Restore(int version) +static void SA0161MSynco() { - SA72007Synco(); + setprg32(0x8000,(latch[0]>>3)&1); + setchr8(latch[0]&7); } -void SA72007_Init(CartInfo *info) +static void SA72007Synco() { - WSync=SA72007Synco; - GameStateRestore=SA72007Restore; - info->Power=SAReset; - AddExState(&latch[0], 1, 0, "LATC"); + setprg32(0x8000,0); + setchr8(latch[0]>>7); } static void SA72008Synco() @@ -291,57 +297,43 @@ static void SA72008Synco() setchr8(latch[0]&3); } -static void SA72008Restore(int version) -{ - SA72008Synco(); -} - -void SA72008_Init(CartInfo *info) +void SA0161M_Init(CartInfo *info) { - WSync=SA72008Synco; - GameStateRestore=SA72008Restore; - info->Power=SAReset; + WSync=SA0161MSynco; + GameStateRestore=SARestore; + info->Power=SAPower; AddExState(&latch[0], 1, 0, "LATC"); } -static DECLFW(SADWrite) -{ - latch[0]=V; - WSync(); -} - -static void SADReset(void) -{ - latch[0]=0; - WSync(); - SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0x8000,0xFFFF,SADWrite); -} - -static void SA0037Synco() +void SA72007_Init(CartInfo *info) { - setprg32(0x8000,(latch[0]>>3)&1); - setchr8(latch[0]&7); + WSync=SA72007Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); } -static void SA0037Restore(int version) +void SA72008_Init(CartInfo *info) { - SA0037Synco(); + WSync=SA72008Synco; + GameStateRestore=SARestore; + info->Power=SAPower; + AddExState(&latch[0], 1, 0, "LATC"); } void SA0036_Init(CartInfo *info) { WSync=SA72007Synco; - GameStateRestore=SA72007Restore; - info->Power=SADReset; + GameStateRestore=SARestore; + info->Power=SADPower; AddExState(&latch[0], 1, 0, "LATC"); } void SA0037_Init(CartInfo *info) { - WSync=SA0037Synco; - GameStateRestore=SA0037Restore; - info->Power=SADReset; + WSync=SA0161MSynco; + GameStateRestore=SARestore; + info->Power=SADPower; AddExState(&latch[0], 1, 0, "LATC"); } @@ -354,8 +346,10 @@ static void TCU01Synco() static DECLFW(TCWrite) { if((A&0x103)==0x102) + { latch[0]=V; - TCU01Synco(); + TCU01Synco(); + } } static void TCU01Reset(void) @@ -401,3 +395,4 @@ void TCA01_Init(CartInfo *info) { info->Power=TCA01Reset; } + diff --git a/boards/sheroes.c b/boards/sheroes.c new file mode 100644 index 0000000..d228a26 --- /dev/null +++ b/boards/sheroes.c @@ -0,0 +1,86 @@ +/* FCE Ultra - NES/Famicom Emulator + * + * Copyright notice for this file: + * Copyright (C) 2006 CaH4e3 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" +#include "mmc3.h" + +//static uint8 *CHRRAM; +static uint8 tekker; + +static void MSHCW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x40) + setchr8r(0x10,0); + else + { + if(A<0x800) + setchr1(A,V|((EXPREGS[0]&8)<<5)); + else if(A<0x1000) + setchr1(A,V|((EXPREGS[0]&4)<<6)); + else if(A<0x1800) + setchr1(A,V|((EXPREGS[0]&1)<<8)); + else + setchr1(A,V|((EXPREGS[0]&2)<<7)); + } +} + +static DECLFW(MSHWrite) +{ + EXPREGS[0]=V; + FixMMC3CHR(MMC3_cmd); +} + +static DECLFR(MSHRead) +{ + return(tekker); +} + +static void MSHReset(void) +{ + MMC3RegReset(); + tekker^=0xFF; +} + +static void MSHPower(void) +{ + tekker=0x00; + GenMMC3Power(); + SetWriteHandler(0x4100,0x4100,MSHWrite); + SetReadHandler(0x4100,0x4100,MSHRead); +} + +static void MSHClose(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM=NULL; +} + +void UNLSHeroes_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 512, 0, 0); + cwrap=MSHCW; + info->Power=MSHPower; + info->Reset=MSHReset; + info->Close=MSHClose; + CHRRAM = (uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(EXPREGS, 4, 0, "EXPR"); +} diff --git a/boards/sl1632.c b/boards/sl1632.c new file mode 100644 index 0000000..9e99722 --- /dev/null +++ b/boards/sl1632.c @@ -0,0 +1,159 @@ +/* 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 chrcmd[8], prg0, prg1, brk, mirr; +static uint8 reg[8], cmd; +static uint8 IRQCount,IRQLatch,IRQa; +static uint8 IRQReload; +static SFORMAT StateRegs[]= +{ + {reg, 8, "MMCREG"}, + {&cmd, 1, "MMCCMD"}, + {chrcmd, 8, "CHRCMD"}, + {&prg0, 1, "PRG0"}, + {&prg1, 1, "PRG1"}, + {&brk, 1, "BRK"}, + {&mirr, 1, "MIRR"}, + {&IRQReload, 1, "IRQR"}, + {&IRQCount, 1, "IRQC"}, + {&IRQLatch, 1, "IRQL"}, + {&IRQa, 1, "IRQA"}, + {0} +}; + +static void Sync(void) +{ +// if(brk&2) +// { +// setprg16(0x8000,~0); +// setprg16(0xC000,~0); +// } +// else + { + setprg8(0x8000,prg0); + setprg8(0xA000,prg1); + } + int i; + for(i=0; i<8; i++) + setchr1(i<<10,chrcmd[i]); + setmirror(mirr^1); +} + +static void Sync2(void) +{ + setprg8(0x8000,reg[6]&0x3F); + setprg8(0xA000,reg[7]&0x3F); + setchr2(0x0000,reg[0]>>1); + setchr2(0x8000,reg[1]>>1); + setchr1(0x1000,reg[2]); + setchr1(0x1400,reg[3]); + setchr1(0x1800,reg[4]); + setchr1(0x1C00,reg[5]); + setmirror(mirr^1); +} + +static DECLFW(UNLSL1632CMDWrite) +{ + FCEU_printf("bs %04x %02x\n",A,V); +// if((A&0xA131)==0xA131) brk=V; + if((A&0xA131)==0xA131) brk=V; + if(brk==2) + { + switch(A&0xE001) + { + case 0x8000: cmd=V&7; break; + case 0x8001: reg[cmd]=V; Sync(); break; + case 0xA000: mirr=V&1; break; + case 0xC000: IRQLatch=V; break; + case 0xC001: IRQReload=1; break; + case 0xE000: X6502_IRQEnd(FCEU_IQEXT); IRQa=0; break; + case 0xE001: IRQa=1; break; + } + Sync2(); + } + else + { + switch(A&0xF003) + { + case 0x8000: prg0=V; break; + case 0xA000: prg1=V; break; + case 0x9000: mirr=V&1; break; + case 0xB000: chrcmd[0]=(chrcmd[0]&0xF0)|(V&0x0F); break; + case 0xB001: chrcmd[0]=(chrcmd[0]&0x0F)|(V<<4); break; + case 0xB002: chrcmd[1]=(chrcmd[1]&0xF0)|(V&0x0F); break; + case 0xB003: chrcmd[1]=(chrcmd[1]&0x0F)|(V<<4); break; + case 0xC000: chrcmd[2]=(chrcmd[2]&0xF0)|(V&0x0F); break; + case 0xC001: chrcmd[2]=(chrcmd[2]&0x0F)|(V<<4); break; + case 0xC002: chrcmd[3]=(chrcmd[3]&0xF0)|(V&0x0F); break; + case 0xC003: chrcmd[3]=(chrcmd[3]&0x0F)|(V<<4); break; + case 0xD000: chrcmd[4]=(chrcmd[4]&0xF0)|(V&0x0F); break; + case 0xD001: chrcmd[4]=(chrcmd[4]&0x0F)|(V<<4); break; + case 0xD002: chrcmd[5]=(chrcmd[5]&0xF0)|(V&0x0F); break; + case 0xD003: chrcmd[5]=(chrcmd[5]&0x0F)|(V<<4); break; + case 0xE000: chrcmd[6]=(chrcmd[6]&0xF0)|(V&0x0F); break; + case 0xE001: chrcmd[6]=(chrcmd[6]&0x0F)|(V<<4); break; + case 0xE002: chrcmd[7]=(chrcmd[7]&0xF0)|(V&0x0F); break; + case 0xE003: chrcmd[7]=(chrcmd[7]&0x0F)|(V<<4); break; + } + Sync(); + } +} + +static void UNLSL1632IRQHook(void) +{ + int count = IRQCount; + if((scanline==128)&&IRQa)X6502_IRQBegin(FCEU_IQEXT); + if(!count || IRQReload) + { + IRQCount = IRQLatch; + IRQReload = 0; + } + else + IRQCount--; + if(!IRQCount) + { + if(IRQa) + { + X6502_IRQBegin(FCEU_IQEXT); + } + } +} + +static void StateRestore(int version) +{ + Sync(); +} + +static void UNLSL1632Power(void) +{ + setprg16(0xC000,~0); + SetReadHandler(0x8000,0xFFFF,CartBR); + SetWriteHandler(0x8000,0xFFFF,UNLSL1632CMDWrite); +} + +void UNLSL1632_Init(CartInfo *info) +{ + info->Power=UNLSL1632Power; + GameHBIRQHook2=UNLSL1632IRQHook; + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/sonic5.c b/boards/sonic5.c new file mode 100644 index 0000000..4a55d0d --- /dev/null +++ b/boards/sonic5.c @@ -0,0 +1,73 @@ +/* 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" +#include "mmc3.h" + +//static uint8 m_perm[8] = {0, 1, 0, 3, 0, 5, 6, 7}; + +static void UNLSonicPW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x80) + { + 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(UNLSonicWrite8000) +{ + if(V&0x80) + MMC3_CMDWrite(A,V); + else + MMC3_CMDWrite(A,m_perm[V&7]); +} +*/ + +static DECLFW(UNLSonicWriteLo) +{ + EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); +} + +static void UNLSonicPower(void) +{ + EXPREGS[0]=EXPREGS[1]=EXPREGS[2]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x5FFF,UNLSonicWriteLo); +// SetWriteHandler(0x8000,0x8000,UNLSonicWrite8000); +} + +void UNLSonic_Init(CartInfo *info) +{ + GenMMC3_Init(info, 256, 256, 0, 0); + pwrap=UNLSonicPW; + info->Power=UNLSonicPower; + AddExState(EXPREGS, 3, 0, "EXPR"); +} diff --git a/boards/subor.c b/boards/subor.c index 31e5b65..f96cc12 100644 --- a/boards/subor.c +++ b/boards/subor.c @@ -1,79 +1,79 @@ -#include "mapinc.h" - -static uint8 mode; -static uint8 DRegs[4]; - -static SFORMAT StateRegs[]= -{ - {DRegs, 4, "DREG"}, - {0} -}; - -static void Sync(void) -{ - int base, bank; - base = ((DRegs[0]^DRegs[1])&0x10)<<1; - bank = (DRegs[2]^DRegs[3])&0x1f; - - if(DRegs[1]&0x08) - { - bank &= 0xfe; - if(mode==0) - { - setprg16(0x8000,base+bank+1); - setprg16(0xC000,base+bank+0); - } - else - { - setprg16(0x8000,base+bank+0); - setprg16(0xC000,base+bank+1); - } - } - else - { - if(DRegs[1]&0x04) - { - setprg16(0x8000,0x1f); - setprg16(0xC000,base+bank); - } - else - { - setprg16(0x8000,base+bank); - if(mode==0) - setprg16(0xC000,0x20); - else - setprg16(0xC000,0x07); - } - } -} - -static DECLFW(Mapper167_write) -{ - DRegs[(A>>13)&0x03]=V; - Sync(); -} - -static void StateRestore(int version) -{ - Sync(); -} - -void Mapper166_init(void) -{ - mode=1; - DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; - Sync(); - SetWriteHandler(0x8000,0xFFFF,Mapper167_write); - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} - -void Mapper167_init(void) -{ - mode=0; - DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; - Sync(); - SetWriteHandler(0x8000,0xFFFF,Mapper167_write); - GameStateRestore=StateRestore; - AddExState(&StateRegs, ~0, 0, 0); -} +#include "mapinc.h" + +static uint8 mode; +static uint8 DRegs[4]; + +static SFORMAT StateRegs[]= +{ + {DRegs, 4, "DREG"}, + {0} +}; + +static void Sync(void) +{ + int base, bank; + base = ((DRegs[0]^DRegs[1])&0x10)<<1; + bank = (DRegs[2]^DRegs[3])&0x1f; + + if(DRegs[1]&0x08) + { + bank &= 0xfe; + if(mode==0) + { + setprg16(0x8000,base+bank+1); + setprg16(0xC000,base+bank+0); + } + else + { + setprg16(0x8000,base+bank+0); + setprg16(0xC000,base+bank+1); + } + } + else + { + if(DRegs[1]&0x04) + { + setprg16(0x8000,0x1f); + setprg16(0xC000,base+bank); + } + else + { + setprg16(0x8000,base+bank); + if(mode==0) + setprg16(0xC000,0x20); + else + setprg16(0xC000,0x07); + } + } +} + +static DECLFW(Mapper167_write) +{ + DRegs[(A>>13)&0x03]=V; + Sync(); +} + +static void StateRestore(int version) +{ + Sync(); +} + +void Mapper166_init(void) +{ + mode=1; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} + +void Mapper167_init(void) +{ + mode=0; + DRegs[0]=DRegs[1]=DRegs[2]=DRegs[3]=0; + Sync(); + SetWriteHandler(0x8000,0xFFFF,Mapper167_write); + GameStateRestore=StateRestore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/super24.c b/boards/super24.c index 4265b5c..205c8d2 100644 --- a/boards/super24.c +++ b/boards/super24.c @@ -1,141 +1,99 @@ -/* 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" -#include "mmc3.h" - -static uint8 *CHRRAM = NULL; -static uint8 resetmode; -static int masko8[8]={63,31,15,1,3,0,0,0}; - -static void Super24PW(uint32 A, uint8 V) -{ - uint32 NV=V&masko8[EXPREGS[0]&7]; - NV|=(EXPREGS[1]<<1); - setprg8r((NV>>6)&0xF,A,NV); -} - -static void Super24CW(uint32 A, uint8 V) -{ - if(EXPREGS[0]&0x20) - setchr1r(0x10,A,V); - else - { - uint32 NV=V|(EXPREGS[2]<<3); - setchr1r((NV>>9)&0xF,A,NV); - } -} - -static DECLFW(Super24Write) -{ - switch(A) - { - case 0x5FF0: EXPREGS[0]=V; - FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); - break; - case 0x5FF1: EXPREGS[1]=V; - FixMMC3PRG(MMC3_cmd); - break; - case 0x5FF2: EXPREGS[2]=V; - FixMMC3CHR(MMC3_cmd); - break; - } -} - -static DECLFW(Super24IRQ) -{ - switch(A&0xE001) - { - case 0xc000: IRQLatch=V; - if(resetmode==1) - IRQCount=IRQLatch; - break; - case 0xc001: resetmode=1; - IRQCount=IRQLatch; - break; - case 0xE000: IRQa=0; - X6502_IRQEnd(FCEU_IQEXT); - if(resetmode==1) - IRQCount=IRQLatch; - break; - case 0xE001: IRQa=1; - if(resetmode==1) - IRQCount=IRQLatch; - break; - } -} - -static void Super24HB(void) -{ - resetmode=0; - if(IRQCount!=0) - { - IRQCount--; - if(IRQCount==0) - { - if(IRQa) - { - resetmode=1; - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void Super24Power(void) -{ - EXPREGS[0]=0x24; - EXPREGS[1]=159; - EXPREGS[2]=0; - GenMMC3Power(); - SetWriteHandler(0x5000,0x7FFF,Super24Write); - SetWriteHandler(0xC000,0xFFFF,Super24IRQ); - SetReadHandler(0x8000,0xFFFF,CartBR); -} - -static void Super24Reset(void) -{ - EXPREGS[0]=0x24; - EXPREGS[1]=159; - EXPREGS[2]=0; - MMC3RegReset(); -} - -static void Super24Close(void) -{ - if(CHRRAM) - FCEU_gfree(CHRRAM); - CHRRAM = NULL; -} - -void Super24_Init(CartInfo *info) -{ - info->Power=Super24Power; - info->Reset=Super24Reset; - info->Close=Super24Close; - cwrap=Super24CW; - pwrap=Super24PW; - CHRRAM=(uint8*)FCEU_gmalloc(8192); - SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); - GameHBIRQHook=Super24HB; - AddExState(CHRRAM, 8192, 0, "CHRR"); - AddExState(EXPREGS, 3, 0, "BIG2"); -} +/* 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" +#include "mmc3.h" + +//static uint8 *CHRRAM = NULL; +static int masko8[8]={63,31,15,1,3,0,0,0}; + +static void Super24PW(uint32 A, uint8 V) +{ + uint32 NV=V&masko8[EXPREGS[0]&7]; + NV|=(EXPREGS[1]<<1); + setprg8r((NV>>6)&0xF,A,NV); +} + +static void Super24CW(uint32 A, uint8 V) +{ + if(EXPREGS[0]&0x20) + setchr1r(0x10,A,V); + else + { + uint32 NV=V|(EXPREGS[2]<<3); + setchr1r((NV>>9)&0xF,A,NV); + } +} + +static DECLFW(Super24Write) +{ + switch(A) + { + case 0x5FF0: EXPREGS[0]=V; + FixMMC3PRG(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); + break; + case 0x5FF1: EXPREGS[1]=V; + FixMMC3PRG(MMC3_cmd); + break; + case 0x5FF2: EXPREGS[2]=V; + FixMMC3CHR(MMC3_cmd); + break; + } +} + +static void Super24Power(void) +{ + EXPREGS[0]=0x24; + EXPREGS[1]=159; + EXPREGS[2]=0; + GenMMC3Power(); + SetWriteHandler(0x5000,0x7FFF,Super24Write); + SetReadHandler(0x8000,0xFFFF,CartBR); +} + +static void Super24Reset(void) +{ + EXPREGS[0]=0x24; + EXPREGS[1]=159; + EXPREGS[2]=0; + MMC3RegReset(); +} + +static void Super24Close(void) +{ + if(CHRRAM) + FCEU_gfree(CHRRAM); + CHRRAM = NULL; +} + +void Super24_Init(CartInfo *info) +{ + GenMMC3_Init(info, 128, 256, 0, 0); + info->Power=Super24Power; + info->Reset=Super24Reset; + info->Close=Super24Close; + cwrap=Super24CW; + pwrap=Super24PW; + CHRRAM=(uint8*)FCEU_gmalloc(8192); + SetupCartCHRMapping(0x10, CHRRAM, 8192, 1); + AddExState(CHRRAM, 8192, 0, "CHRR"); + AddExState(EXPREGS, 3, 0, "BIG2"); +} diff --git a/boards/supervision.c b/boards/supervision.c index 953c068..61a373d 100644 --- a/boards/supervision.c +++ b/boards/supervision.c @@ -24,30 +24,30 @@ static uint8 cmd0, cmd1; static void DoSuper(void) { - setprg8r((cmd0&0xC)>>2,0x6000,((cmd0&0x3)<<4)|0xF); - if(cmd0&0x10) - { - setprg16r((cmd0&0xC)>>2,0x8000,((cmd0&0x3)<<3)|(cmd1&7)); - setprg16r((cmd0&0xC)>>2,0xc000,((cmd0&0x3)<<3)|7); - } - else - setprg32r(4,0x8000,0); - setmirror(((cmd0&0x20)>>5)^1); + setprg8r((cmd0&0xC)>>2,0x6000,((cmd0&0x3)<<4)|0xF); + if(cmd0&0x10) + { + setprg16r((cmd0&0xC)>>2,0x8000,((cmd0&0x3)<<3)|(cmd1&7)); + setprg16r((cmd0&0xC)>>2,0xc000,((cmd0&0x3)<<3)|7); + } + else + setprg32r(4,0x8000,0); + setmirror(((cmd0&0x20)>>5)^1); } static DECLFW(SuperWrite) { - if(!(cmd0&0x10)) - { - cmd0=V; - DoSuper(); - } + if(!(cmd0&0x10)) + { + cmd0=V; + DoSuper(); + } } static DECLFW(SuperHi) { - cmd1=V; - DoSuper(); + cmd1=V; + DoSuper(); } static void SuperReset(void) @@ -62,7 +62,7 @@ static void SuperReset(void) static void SuperRestore(int version) { - DoSuper(); + DoSuper(); } void Supervision16_Init(CartInfo *info) diff --git a/boards/t-262.c b/boards/t-262.c new file mode 100644 index 0000000..fe9b446 --- /dev/null +++ b/boards/t-262.c @@ -0,0 +1,83 @@ +/* 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 uint16 addrreg; +static uint8 datareg; +static uint8 busy; +static SFORMAT StateRegs[]= +{ + {&addrreg, 2, "ADDRREG"}, + {&datareg, 1, "DATAREG"}, + {&busy, 1, "BUSY"}, + {0} +}; + +static void Sync(void) +{ + setprg16(0x8000,(datareg&7)|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); + setprg16(0xC000,7|((addrreg&0x60)>>2)|((addrreg&0x100)>>3)); + setmirror(((addrreg&2)>>1)^1); +} + +static DECLFW(BMCT262Write) +{ + if(busy||(A==0x8000)) + datareg=V; + else + { + addrreg=A; + busy=1; + } + Sync(); +} + +static void BMCT262Power(void) +{ + setchr8(0); + SetWriteHandler(0x8000,0xFFFF,BMCT262Write); + SetReadHandler(0x8000,0xFFFF,CartBR); + busy=0; + addrreg=0; + datareg=0; + Sync(); +} + +static void BMCT262Reset(void) +{ + busy=0; + addrreg=0; + datareg=0; + Sync(); +} + +static void BMCT262Restore(int version) +{ + Sync(); +} + +void BMCT262_Init(CartInfo *info) +{ + info->Power=BMCT262Power; + info->Reset=BMCT262Reset; + GameStateRestore=BMCT262Restore; + AddExState(&StateRegs, ~0, 0, 0); +} diff --git a/boards/tengen.c b/boards/tengen.c index 84f050a..a4f33f5 100644 --- a/boards/tengen.c +++ b/boards/tengen.c @@ -25,15 +25,15 @@ static uint8 DRegs[11]; static uint8 IRQCount,IRQa,IRQLatch; static SFORMAT Rambo_StateRegs[]={ - {&cmd, 1, "CMD"}, - {&mir, 1, "MIR"}, - {&rmode, 1, "RMOD"}, - {&IRQmode, 1, "IRQM"}, - {&IRQCount, 1, "IRQC"}, - {&IRQa, 1, "IRQA"}, - {&IRQLatch, 1, "IRQL"}, - {DRegs, 11, "DREG"}, - {0} + {&cmd, 1, "CMD"}, + {&mir, 1, "MIR"}, + {&rmode, 1, "RMOD"}, + {&IRQmode, 1, "IRQM"}, + {&IRQCount, 1, "IRQC"}, + {&IRQa, 1, "IRQA"}, + {&IRQLatch, 1, "IRQL"}, + {DRegs, 11, "DREG"}, + {0} }; static void FP_FASTAPASS(2) (*setchr1wrap)(unsigned int A, unsigned int V); @@ -41,67 +41,67 @@ static int nomirror; static void FP_FASTAPASS(1) RAMBO1_IRQHook(int a) { - static int smallcount; - if(!IRQmode) return; + static int smallcount; + if(!IRQmode) return; - smallcount+=a; - while(smallcount>=4) - { - smallcount-=4; - IRQCount--; - if(IRQCount==0xFF) + smallcount+=a; + while(smallcount>=4) + { + smallcount-=4; + IRQCount--; + if(IRQCount==0xFF) if(IRQa) X6502_IRQBegin(FCEU_IQEXT); - } + } } static void RAMBO1_hb(void) { - if(IRQmode) return; + if(IRQmode) return; if(scanline==240) return; /* hmm. Maybe that should be an mmc3-only call in fce.c. */ - rmode=0; - IRQCount--; - if(IRQCount==0xFF) - { - if(IRQa) - { - rmode = 1; - X6502_IRQBegin(FCEU_IQEXT); - } - } + rmode=0; + IRQCount--; + if(IRQCount==0xFF) + { + if(IRQa) + { + rmode = 1; + X6502_IRQBegin(FCEU_IQEXT); + } + } } static void Synco(void) { - int x; - - if(cmd&0x20) - { - setchr1wrap(0x0000,DRegs[0]); - setchr1wrap(0x0800,DRegs[1]); - setchr1wrap(0x0400,DRegs[8]); - setchr1wrap(0x0c00,DRegs[9]); - } - else - { - setchr1wrap(0x0000,(DRegs[0]&0xFE)); - setchr1wrap(0x0400,(DRegs[0]&0xFE)|1); - setchr1wrap(0x0800,(DRegs[1]&0xFE)); - setchr1wrap(0x0C00,(DRegs[1]&0xFE)|1); - } - - for(x=0;x<4;x++) - setchr1wrap(0x1000+x*0x400,DRegs[2+x]); - - setprg8(0x8000,DRegs[6]); - setprg8(0xA000,DRegs[7]); - - setprg8(0xC000,DRegs[10]); + int x; + + if(cmd&0x20) + { + setchr1wrap(0x0000,DRegs[0]); + setchr1wrap(0x0800,DRegs[1]); + setchr1wrap(0x0400,DRegs[8]); + setchr1wrap(0x0c00,DRegs[9]); + } + else + { + setchr1wrap(0x0000,(DRegs[0]&0xFE)); + setchr1wrap(0x0400,(DRegs[0]&0xFE)|1); + setchr1wrap(0x0800,(DRegs[1]&0xFE)); + setchr1wrap(0x0C00,(DRegs[1]&0xFE)|1); + } + + for(x=0;x<4;x++) + setchr1wrap(0x1000+x*0x400,DRegs[2+x]); + + setprg8(0x8000,DRegs[6]); + setprg8(0xA000,DRegs[7]); + + setprg8(0xC000,DRegs[10]); } static DECLFW(RAMBO1_write) { - switch(A&0xF001) + switch(A&0xF001) { case 0xa000: mir=V&1; if(!nomirror) @@ -110,19 +110,19 @@ static DECLFW(RAMBO1_write) case 0x8000: cmd = V; break; case 0x8001: if((cmd&0xF)<10) - DRegs[cmd&0xF]=V; - else if((cmd&0xF)==0xF) - DRegs[10]=V; - Synco(); - break; + DRegs[cmd&0xF]=V; + else if((cmd&0xF)==0xF) + DRegs[10]=V; + Synco(); + break; case 0xc000: IRQLatch=V; if(rmode==1) IRQCount=IRQLatch; break; case 0xc001: rmode=1; - IRQCount=IRQLatch; - IRQmode=V&1; - break; + IRQCount=IRQLatch; + IRQmode=V&1; + break; case 0xE000: IRQa=0; X6502_IRQEnd(FCEU_IQEXT); if(rmode==1) @@ -131,43 +131,43 @@ static DECLFW(RAMBO1_write) case 0xE001: IRQa=1; if(rmode==1) IRQCount=IRQLatch; - break; + break; } } static void RAMBO1_Restore(int version) { - Synco(); - if(!nomirror) - setmirror(mir^1); + Synco(); + if(!nomirror) + setmirror(mir^1); } static void RAMBO1_init(void) { - int x; - for(x=0;x<11;x++) - DRegs[x]=~0; + int x; + for(x=0;x<11;x++) + DRegs[x]=~0; cmd=mir=0; - if(!nomirror) - setmirror(1); - Synco(); - GameHBIRQHook=RAMBO1_hb; - MapIRQHook=RAMBO1_IRQHook; - GameStateRestore=RAMBO1_Restore; - SetWriteHandler(0x8000,0xffff,RAMBO1_write); - AddExState(Rambo_StateRegs, ~0, 0, 0); + if(!nomirror) + setmirror(1); + Synco(); + GameHBIRQHook=RAMBO1_hb; + MapIRQHook=RAMBO1_IRQHook; + GameStateRestore=RAMBO1_Restore; + SetWriteHandler(0x8000,0xffff,RAMBO1_write); + AddExState(Rambo_StateRegs, ~0, 0, 0); } static void FP_FASTAPASS(2) CHRWrap(unsigned int A, unsigned int V) { - setchr1(A,V); + setchr1(A,V); } void Mapper64_init(void) { - setchr1wrap=CHRWrap; - nomirror=0; - RAMBO1_init(); + setchr1wrap=CHRWrap; + nomirror=0; + RAMBO1_init(); } static int MirCache[8]; @@ -175,24 +175,24 @@ static unsigned int PPUCHRBus; static void FP_FASTAPASS(2) MirWrap(unsigned int A, unsigned int V) { - MirCache[A>>10]=(V>>7)&1; - if(PPUCHRBus==(A>>10)) - setmirror(MI_0+((V>>7)&1)); - setchr1(A,V); + MirCache[A>>10]=(V>>7)&1; + if(PPUCHRBus==(A>>10)) + setmirror(MI_0+((V>>7)&1)); + setchr1(A,V); } static void FP_FASTAPASS(1) MirrorFear(uint32 A) { - A&=0x1FFF; - A>>=10; - PPUCHRBus=A; - setmirror(MI_0+MirCache[A]); + A&=0x1FFF; + A>>=10; + PPUCHRBus=A; + setmirror(MI_0+MirCache[A]); } void Mapper158_init(void) { - setchr1wrap=MirWrap; - PPU_hook=MirrorFear; - nomirror=1; - RAMBO1_init(); + setchr1wrap=MirWrap; + PPU_hook=MirrorFear; + nomirror=1; + RAMBO1_init(); } diff --git a/drivers/gp2x/main.c b/drivers/gp2x/main.c index f700e4f..7f2d7af 100644 --- a/drivers/gp2x/main.c +++ b/drivers/gp2x/main.c @@ -400,7 +400,7 @@ int CLImain(int argc, char *argv[]) // TODO: handlers for other formats then iNES { int MapperNo; - iNES_HEADER *head = iNESGetHead(); + iNES_HEADER *head = iNESGetHead(); // TODO: ReMake MapperNo = (head->ROM_type>>4); MapperNo|=(head->ROM_type2&0xF0); FCEU_DispMessage("%s, Mapper: %d%s%s", PAL?"PAL":"NTSC", MapperNo, (head->ROM_type&2)?", BB":"", (head->ROM_type&4)?", T":""); diff --git a/ines-correct.h b/ines-correct.h index 666cf00..054b0ec 100644 --- a/ines-correct.h +++ b/ines-correct.h @@ -1,7 +1,7 @@ {0x9cbadc25,5,8}, /* JustBreed */ -{0x6e68e31a,16,8}, /* Dragon Ball 3*/ -{0x3f15d20d,153,8}, /* Famicom Jump 2 */ + {0x6e68e31a,16,8}, /* Dragon Ball 3*/ + {0x3f15d20d,153,8}, /* Famicom Jump 2 */ {0x983d8175,157,8}, /* Datach Battle Rush */ {0x894efdbc,157,8}, /* Datach Crayon Shin Chan */ {0x19e81461,157,8}, /* Datach DBZ */ @@ -13,14 +13,13 @@ {0xe62e3382,71,-1}, /* Mig-29 Soviet Fighter */ {0x21a653c7,4,-1}, /* Super Sky Kid */ -{0xdd4d9a62,209,-1}, /* Shin Samurai Spirits 2 */ + {0xdd4d9a62,209,-1}, /* Shin Samurai Spirits 2 */ {0x063b1151,209,-1}, /* Power Rangers 4 */ {0xdd8ced31,209,-1}, /* Power Rangers 3 */ -{0x60bfeb0c,90,-1}, /* MK 2*/ {0x0c47946d,210,-1}, /* Chibi Maruko Chan */ {0xbd523011,210,-1}, /* Dream Master */ -{0xc247cc80,210,-1}, /* Family Circuit '91 */ + {0xc247cc80,210,-1}, /* Family Circuit '91 */ {0x6ec51de5,210,-1}, /* Famista '92 */ {0xadffd64f,210,-1}, /* Famista '93 */ {0x429103c9,210,-1}, /* Famista '94 */ @@ -34,8 +33,8 @@ {0x276237b3,206,0}, /* Karnov */ {0x4e1c1e3c,206,0}, /* Karnov */ - /* Some entries to sort out the minor 33/48 mess. */ -{0xaebd6549,48,8}, /* Bakushou!! Jinsei Gekijou 3 */ + /* Some entries to sort out the minor 33/48 mess. */ + {0xaebd6549,48,8}, /* Bakushou!! Jinsei Gekijou 3 */ {0x6cdc0cd9,48,8}, /* Bubble Bobble 2 */ //{0x10e24006,48,8}, /* Flintstones 2 - bad dump? */ {0x40c0ad47,48,8}, /* Flintstones 2 */ @@ -53,14 +52,14 @@ {0xf518dd58,7,8}, /* Captain Skyhawk */ {0x7ccb12a3,43,-1}, /* SMB2j */ {0x6f12afc5,235,-1}, /* Golden Game 150-in-1 */ - {0xccc03440,156,-1}, + {0xccc03440,156,-1}, {0xc9ee15a7,3,-1}, /* 3 is probably best. 41 WILL NOT WORK. */ {0x3e1271d5,79,1}, /* Tiles of Fate */ {0x8eab381c,113,1}, /* Death Bots */ {0xd4a76b07,79,0}, /* F-15 City Wars*/ - {0xa4fbb438,79,0}, + {0xa4fbb438,79,0}, {0x1eb4a920,79,1}, /* Double Strike */ {0x345d3a1a,11,1}, /* Castle of Deceit */ @@ -68,7 +67,7 @@ {0x5caa3e61,144,1}, /* Death Race */ {0xd2699893,88,0}, /* Dragon Spirit */ -{0x2f27cdef,155,8}, /* Tatakae!! Rahmen Man */ + {0x2f27cdef,155,8}, /* Tatakae!! Rahmen Man */ {0xcfd4a281,155,8}, /* Money Game. Yay for money! */ {0xd1691028,154,8}, /* Devil Man */ @@ -80,7 +79,7 @@ {0xc2730c30,34,0}, /* Deadly Towers */ {0x932ff06e,34,1}, /* Classic Concentration */ {0x4c7c1af3,34,1}, /* Caesar's Palace */ - + {0x15141401,4,8}, /* Asmik Kun Land */ {0x59280bec,4,8}, /* Jackie Chan */ {0x4cccd878,4,8}, /* Cat Ninden Teyandee */ @@ -125,8 +124,8 @@ {0x291bcd7d,1,8}, /* Pachio Kun 2 */ {0xf74dfc91,1,-1}, /* Win, Lose, or Draw */ - {0x3f56a392,1,8}, /* Captain Ed (J) */ - {0x078ced30,1,8}, /* Choujin - Ultra Baseball */ + {0x3f56a392,1,8}, /* Captain Ed (J) */ + {0x078ced30,1,8}, /* Choujin - Ultra Baseball */ {0x391aa1b8,1,8}, /* Bloody Warriors (J) */ {0x61a852ea,1,8}, /* Battle Stadium - Senbatsu Pro Yakyuu */ {0xfe364be5,1,8}, /* Deep Dungeon 4 */ @@ -156,18 +155,18 @@ {0x5b837e8d,1,8}, /* Alien Syndrome */ {0x283ad224,32,8}, /* Ai Sensei no Oshiete */ {0x5555fca3,32,8}, /* "" "" */ - {0x243a8735,32,0x10|4}, /* Major League */ + {0x243a8735,32,0x10|4}, /* Major League */ -{0x6bc65d7e,66,1}, /* Youkai Club*/ -{0xc2df0a00,66,1}, /* Bio Senshi Dan(hacked) */ +{0x6bc65d7e,140,1}, /* Youkai Club*/ +{0xc2df0a00,140,1}, /* Bio Senshi Dan(hacked) */ {0xbde3ae9b,66,1}, /* Doraemon */ {0xd26efd78,66,1}, /* SMB Duck Hunt */ {0x811f06d9,66,1}, /* Dragon Power */ -{0x3293afea,66,1}, /* Mississippi Satsujin Jiken */ +{0x3293afea,140,1}, /* Mississippi Satsujin Jiken */ {0xe84274c5,66,1}, /* "" "" */ {0x9552e8df,66,1}, /* Dragon Ball */ - {0xba51ac6f,78,2}, + {0xba51ac6f,78,2}, {0x3d1c3137,78,8}, /* Uchuusen - Cosmo Carrier */ {0xbda8f8e4,152,8}, /* Gegege no Kitarou 2 */ @@ -183,12 +182,32 @@ {0xb9b4d9e0,118,-1}, /* NES Play Action Football */ {0x78b657ac,118,-1}, /* Armadillo */ {0x37b62d04,118,-1}, /* Ys 3 */ - {0x07d92c31,118,-1}, /* RPG Jinsei Game */ + {0x07d92c31,118,-1}, /* RPG Jinsei Game */ {0x2705eaeb,234,-1}, /* Maxi 15 */ {0x404b2e8b,4,2}, /* Rad Racer 2 */ - {0x2cc381f6,191,-1}, /* Sugoro Quest - Dice no Senshitachi (As).nes */ - {0x555a555e,191,-1}, {0xa912b064,51|0x800,8}, /* 11-in-1 Ball Games(has CHR ROM when it shouldn't) */ {0xc5e5c5b2,115,-1}, /* Bao Qing Tian (As).nes */ - {0,-1,-1} + {0xcfb224e6,-1,1}, /* Dragon Ninja (J) [p1][!].nes */ + {0xf46ef39a,37,-1}, /* Super Mario Bros. + Tetris + Nintendo World Cup (E) [!] */ + {0x0f05ff0a,181,-1}, /* Seicross (redump) */ + + {0x054bd3e9,74,-1}, /* Di 4 Ci - Ji Qi Ren Dai Zhan (As) */ + {0x496ac8f7,74,-1}, /* Ji Jia Zhan Shi (As) */ + {0xae854cef,74,-1}, /* Jia A Fung Yun (Chinese) */ + {0x2cc381f6,191,-1}, /* Sugoro Quest - Dice no Senshitachi (As) */ + {0x555a555e,191,-1}, + {0x98c1cd4b,192,-1},/* Ying Lie Qun Xia Zhuan (Chinese) */ + {0x442f1a29,192,-1},/* Young chivalry */ + {0xa925226c,194,-1},/* Dai-2-Ji - Super Robot Taisen (As) */ + {0xd5224fde,198,-1},/* [074]Crystalis (c) */ + {0x1bc0be6c,198,-1},/* Captain Tsubasa Vol 2 - Super Striker (C) */ + {0xdd431ba7,199,-1},/* Tenchi wo kurau 2 (c) */ + {0x28192599,199,-1}, + {0x700705f4,199,-1}, + {0x9a2cf02c,199,-1}, + {0xd8b401a7,199,-1}, + + {0x1f1326d4,218,-1}, + {0xa1dc16c0,116,-1}, + {0,-1,-1} diff --git a/ines.c b/ines.c index 71de2ba..6665a13 100644 --- a/ines.c +++ b/ines.c @@ -747,19 +747,20 @@ static void NONE_init(void) void (*MapInitTab[256])(void)= { + 0,0, //Mapper2_init,Mapper3_init, 0,0, -// Mapper2_init,Mapper3_init, 0,0, - 0,0, - Mapper6_init,Mapper7_init,Mapper8_init,Mapper9_init, - Mapper10_init,Mapper11_init, - 0, -// Mapper13_init, + Mapper6_init, + 0,//Mapper7_init, + Mapper8_init,Mapper9_init, + Mapper10_init, + 0, //Mapper11_init, + 0, //Mapper13_init, 0, 0, Mapper15_init,Mapper16_init,Mapper17_init,Mapper18_init, 0,0, - Mapper21_init,Mapper22_init,Mapper23_init,Mapper24_init, + Mapper21_init,Mapper22_init,Mapper23_init,Mapper24_init, Mapper25_init,Mapper26_init,Mapper27_init, 0,0,0,0, Mapper32_init,Mapper33_init,Mapper34_init, @@ -772,38 +773,52 @@ void (*MapInitTab[256])(void)= 0, Mapper50_init,Mapper51_init, 0,0,0,0,0, - Mapper57_init,Mapper58_init,Mapper59_init,Mapper60_init, + 0,// Mapper57_init, + 0,// Mapper58_init, + Mapper59_init,Mapper60_init, Mapper61_init,Mapper62_init, 0, - Mapper64_init,Mapper65_init,Mapper66_init,Mapper67_init, - Mapper68_init,Mapper69_init,Mapper70_init,Mapper71_init, + Mapper64_init,Mapper65_init, + 0,//Mapper66_init, + Mapper67_init, + Mapper68_init,Mapper69_init, + 0,//Mapper70_init, + Mapper71_init, Mapper72_init,Mapper73_init, 0, - Mapper75_init,Mapper76_init,Mapper77_init,Mapper78_init, + Mapper75_init,Mapper76_init,Mapper77_init, + 0, //Mapper78_init, Mapper79_init,Mapper80_init, 0, Mapper82_init,Mapper83_init, 0, - Mapper85_init,Mapper86_init,Mapper87_init,Mapper88_init, + Mapper85_init,Mapper86_init, + 0, //Mapper87_init, + 0, //Mapper88_init, Mapper89_init, 0, - Mapper91_init,Mapper92_init,Mapper93_init,Mapper94_init, + 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, - Mapper107_init, + 0, //Mapper107_init, 0,0,0,0, 0,Mapper113_init, 0,0,0, - Mapper117_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, - Mapper140_init, + 0, //Mapper140_init, 0,0,0, - Mapper144_init, + 0, //Mapper144_init, 0,0,0,0,0,0, - Mapper151_init,Mapper152_init,Mapper153_init,Mapper154_init, + Mapper151_init, + 0, //Mapper152_init, + Mapper153_init, + 0, //Mapper154_init, 0, Mapper156_init,Mapper157_init,Mapper158_init,0, 0,0,0,0,0,0, @@ -811,12 +826,12 @@ void (*MapInitTab[256])(void)= 0,0,0,0,0,0,0,0,0,0,0,0, Mapper180_init, 0,0,0, - Mapper184_init,Mapper185_init, + Mapper184_init, + 0, //Mapper185_init, 0,0,0, - Mapper189_init, - 0, -// Mapper191_init, + 0, //Mapper189_init, 0, + 0, //Mapper191_init, 0, Mapper193_init, 0,0,0,0,0,0, @@ -825,12 +840,14 @@ void (*MapInitTab[256])(void)= 0,0, Mapper207_init, 0,0,0, - Mapper211_init,Mapper212_init,Mapper213_init,Mapper214_init, + 0, //Mapper211_init, + Mapper212_init,Mapper213_init,Mapper214_init, 0,0,0,0,0,0,0,0,0,0, Mapper225_init,Mapper226_init,Mapper227_init,Mapper228_init, Mapper229_init,Mapper230_init,Mapper231_init,Mapper232_init, 0, - Mapper234_init,Mapper235_init, + Mapper234_init, + 0, //Mapper235_init, 0,0,0,0, Mapper240_init,Mapper241_init,Mapper242_init,0, Mapper244_init, @@ -840,6 +857,8 @@ void (*MapInitTab[256])(void)= Mapper255_init }; + + static DECLFW(BWRAM) { WRAM[A-0x6000]=V; @@ -958,68 +977,101 @@ typedef struct { } BMAPPING; static BMAPPING bmap[] = { + {0, NROM_Init}, {1, Mapper1_Init}, {2, UNROM_Init}, {3, CNROM_Init}, {4, Mapper4_Init}, {5, Mapper5_Init}, + {7, ANROM_Init}, + {11, Mapper11_Init}, {12, Mapper12_Init}, {13, CPROM_Init}, {19, Mapper19_Init}, + {37, Mapper37_Init}, {44, Mapper44_Init}, {45, Mapper45_Init}, {47, Mapper47_Init}, {49, Mapper49_Init}, {52, Mapper52_Init}, + {57, Mapper57_Init}, + {58, Mapper58_Init}, + {66, MHROM_Init}, + {70, Mapper70_Init}, {74, Mapper74_Init}, + {78, Mapper78_Init}, + {87, Mapper87_Init}, + {88, Mapper88_Init}, {90, Mapper90_Init}, + {93, SUNSOFT_UNROM_Init}, + {94, Mapper94_Init}, {95, Mapper95_Init}, {105, Mapper105_Init}, + {107, Mapper107_Init}, {112, Mapper112_Init}, {114, Mapper114_Init}, - {115, Mapper115_Init}, - {116, Mapper116_Init}, - {118, Mapper118_Init}, + {115, Mapper115_Init}, + {116, Mapper116_Init}, + {117, Mapper117_Init}, + {118, Mapper118_Init}, {119, Mapper119_Init}, {133, SA72008_Init}, {137, S8259D_Init}, {138, S8259B_Init}, {139, S8259C_Init}, + {140, Mapper140_Init}, {141, S8259A_Init}, {143, TCA01_Init}, + {144, Mapper144_Init}, {145, SA72007_Init}, {146, SA0161M_Init}, {147, TCU01_Init}, {148, SA0037_Init}, {149, SA0036_Init}, {150, S74LS374N_Init}, - {155, Mapper155_Init}, + {152, Mapper152_Init}, + {154, Mapper154_Init}, + {155, Mapper155_Init}, {160, Mapper90_Init}, {163, Mapper163_Init}, - {164, Mapper164_Init}, + {164, Mapper164_Init}, {165, Mapper165_Init}, + {181, Mapper181_Init}, {182, Mapper182_Init}, {183, Mapper183_Init}, + {185, Mapper185_Init}, {186, Mapper186_Init}, - {187, Mapper187_Init}, - {188, Mapper188_Init}, + {187, Mapper187_Init}, + {188, Mapper188_Init}, + {189, Mapper189_Init}, {191, Mapper191_Init}, + {192, Mapper192_Init}, + {194, Mapper194_Init}, + {198, Mapper198_Init}, + {199, Mapper199_Init}, {205, Mapper205_Init}, {206, DEIROM_Init}, - {208, Mapper208_Init}, + {208, Mapper208_Init}, {209, Mapper209_Init}, - {210, Mapper210_Init}, + {210, Mapper210_Init}, + {211, Mapper211_Init}, {215, Mapper215_Init}, {216, Mapper216_Init}, {217, Mapper217_Init}, + {218, UNLSonic_Init}, + {219, UNLSL1632_Init}, +// {220, Mapper220_Init}, + {222, Mapper222_Init}, + {235, Mapper235_Init}, {243, S74LS374NA_Init}, - {245, Mapper245_Init}, - {249, Mapper249_Init}, - {250, Mapper250_Init}, + {245, Mapper245_Init}, + {249, Mapper249_Init}, + {250, Mapper250_Init}, {254, Mapper254_Init}, { 0, 0} }; + static int NewiNES_Init(int num) { BMAPPING *tmp=bmap; diff --git a/ines.h b/ines.h index 5811d32..5a49aed 100644 --- a/ines.h +++ b/ines.h @@ -25,8 +25,6 @@ void iNESStateRestore(int version); extern uint32 iNESGameCRC32; -extern uint8 *VROM; - extern uint32 VROM_size; extern uint32 ROM_size; @@ -67,14 +65,14 @@ extern uint8 iNESIRQa; #else #endif - typedef struct { - char ID[4]; /*NES^Z*/ - uint8 ROM_size; - uint8 VROM_size; - uint8 ROM_type; - uint8 ROM_type2; - uint8 reserve[8]; - } iNES_HEADER; + typedef struct { + char ID[4]; /*NES^Z*/ + uint8 ROM_size; + uint8 VROM_size; + uint8 ROM_type; + uint8 ROM_type2; + uint8 reserve[8]; + } iNES_HEADER; void FASTAPASS(2) VRAM_BANK1(uint32 A, uint8 V); void FASTAPASS(2) VRAM_BANK4(uint32 A,uint32 V); @@ -99,18 +97,16 @@ void FASTAPASS(1) onemir(uint8 V); void FASTAPASS(1) MIRROR_SET2(uint8 V); void FASTAPASS(1) MIRROR_SET(uint8 V); -iNES_HEADER *iNESGetHead(void); - void Mapper0_init(void); void Mapper1_init(void); //void Mapper2_init(void); //void Mapper3_init(void); void Mapper6_init(void); -void Mapper7_init(void); +//void Mapper7_init(void); void Mapper8_init(void); void Mapper9_init(void); void Mapper10_init(void); -void Mapper11_init(void); +//void Mapper11_init(void); void Mapper12_init(void); //void Mapper13_init(void); void Mapper14_init(void); @@ -136,7 +132,7 @@ void Mapper33_init(void); void Mapper34_init(void); void Mapper35_init(void); void Mapper36_init(void); -void Mapper37_init(void); +//void Mapper37_init(void); void Mapper38_init(void); void Mapper39_init(void); void Mapper40_init(void); @@ -155,8 +151,6 @@ void Mapper53_init(void); void Mapper54_init(void); void Mapper55_init(void); void Mapper56_init(void); -void Mapper57_init(void); -void Mapper58_init(void); void Mapper59_init(void); void Mapper60_init(void); void Mapper61_init(void); @@ -164,11 +158,11 @@ void Mapper62_init(void); void Mapper63_init(void); void Mapper64_init(void); void Mapper65_init(void); -void Mapper66_init(void); +//void Mapper66_init(void); void Mapper67_init(void); void Mapper68_init(void); void Mapper69_init(void); -void Mapper70_init(void); +//void Mapper70_init(void); void Mapper71_init(void); void Mapper72_init(void); void Mapper73_init(void); @@ -176,7 +170,7 @@ void Mapper74_init(void); void Mapper75_init(void); void Mapper76_init(void); void Mapper77_init(void); -void Mapper78_init(void); +//void Mapper78_init(void); void Mapper79_init(void); void Mapper80_init(void); void Mapper81_init(void); @@ -185,34 +179,31 @@ void Mapper83_init(void); void Mapper84_init(void); void Mapper85_init(void); void Mapper86_init(void); -void Mapper87_init(void); +//void Mapper87_init(void); void Mapper88_init(void); void Mapper89_init(void); void Mapper91_init(void); void Mapper92_init(void); -void Mapper93_init(void); -void Mapper94_init(void); +//void Mapper93_init(void); +//void Mapper94_init(void); void Mapper96_init(void); void Mapper97_init(void); void Mapper98_init(void); void Mapper99_init(void); void Mapper100_init(void); void Mapper101_init(void); -void Mapper102_init(void); void Mapper103_init(void); void Mapper104_init(void); void Mapper106_init(void); -void Mapper107_init(void); +//void Mapper107_init(void); void Mapper108_init(void); void Mapper109_init(void); void Mapper110_init(void); void Mapper111_init(void); -//void Mapper112_init(void); void Mapper113_init(void); -//void Mapper114_init(void); void Mapper115_init(void); void Mapper116_init(void); -void Mapper117_init(void); +//void Mapper117_init(void); void Mapper120_init(void); void Mapper121_init(void); void Mapper122_init(void); @@ -229,20 +220,15 @@ void Mapper134_init(void); void Mapper135_init(void); void Mapper136_init(void); void Mapper137_init(void); -//void Mapper138_init(void); void Mapper139_init(void); -void Mapper140_init(void); +//void Mapper140_init(void); void Mapper141_init(void); void Mapper142_init(void); void Mapper143_init(void); -void Mapper144_init(void); -//void Mapper145_init(void); -//void Mapper146_init(void); -//void Mapper147_init(void); -//void Mapper149_init(void); +//void Mapper144_init(void); void Mapper150_init(void); void Mapper151_init(void); -void Mapper152_init(void); +//void Mapper152_init(void); void Mapper153_init(void); void Mapper154_init(void); void Mapper156_init(void); @@ -267,18 +253,17 @@ void Mapper177_init(void); void Mapper178_init(void); void Mapper179_init(void); void Mapper180_init(void); -void Mapper181_init(void); +//void Mapper181_init(void); void Mapper184_init(void); -void Mapper185_init(void); -void Mapper189_init(void); -//void Mapper191_init(void); -void Mapper192_init(void); +//void Mapper185_init(void); +//void Mapper189_init(void); +//void Mapper192_init(void); void Mapper193_init(void); -void Mapper194_init(void); +//void Mapper194_init(void); void Mapper195_init(void); void Mapper196_init(void); void Mapper197_init(void); -void Mapper198_init(void); +//void Mapper198_init(void); void Mapper199_init(void); void Mapper200_init(void); void Mapper201_init(void); @@ -286,15 +271,15 @@ void Mapper202_init(void); void Mapper203_init(void); void Mapper204_init(void); void Mapper207_init(void); -void Mapper211_init(void); +//void Mapper211_init(void); void Mapper212_init(void); void Mapper213_init(void); void Mapper214_init(void); -void Mapper218_init(void); +//void Mapper218_init(void); void Mapper219_init(void); -void Mapper220_init(void); +//void Mapper220_init(void); void Mapper221_init(void); -void Mapper222_init(void); +//void Mapper222_init(void); void Mapper223_init(void); void Mapper224_init(void); void Mapper225_init(void); @@ -307,7 +292,7 @@ void Mapper231_init(void); void Mapper232_init(void); void Mapper233_init(void); void Mapper234_init(void); -void Mapper235_init(void); +//void Mapper235_init(void); void Mapper236_init(void); void Mapper237_init(void); void Mapper238_init(void); @@ -335,41 +320,70 @@ void Mapper19_ESI(void); void Mapper1_Init(CartInfo *); void Mapper4_Init(CartInfo *); void Mapper5_Init(CartInfo *); +void Mapper11_Init(CartInfo *); void Mapper12_Init(CartInfo *); void Mapper19_Init(CartInfo *); +void Mapper37_Init(CartInfo *); void Mapper44_Init(CartInfo *); void Mapper45_Init(CartInfo *); void Mapper47_Init(CartInfo *); void Mapper49_Init(CartInfo *); void Mapper52_Init(CartInfo *); +void Mapper57_Init(CartInfo *); +void Mapper58_Init(CartInfo *); +void Mapper70_Init(CartInfo *); void Mapper74_Init(CartInfo *); +void Mapper78_Init(CartInfo *); +void Mapper87_Init(CartInfo *); +void Mapper88_Init(CartInfo *); void Mapper90_Init(CartInfo *); +void Mapper93_Init(CartInfo *); +void Mapper94_Init(CartInfo *); void Mapper95_Init(CartInfo *); void Mapper105_Init(CartInfo *); +void Mapper107_Init(CartInfo *); void Mapper112_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 Mapper125_Init(CartInfo *); +void Mapper140_Init(CartInfo *); +void Mapper144_Init(CartInfo *); +void Mapper152_Init(CartInfo *); +void Mapper154_Init(CartInfo *); void Mapper155_Init(CartInfo *); void Mapper163_Init(CartInfo *); void Mapper164_Init(CartInfo *); void Mapper165_Init(CartInfo *); +void Mapper181_Init(CartInfo *); void Mapper182_Init(CartInfo *); void Mapper183_Init(CartInfo *); +void Mapper185_Init(CartInfo *); void Mapper186_Init(CartInfo *); void Mapper187_Init(CartInfo *); void Mapper188_Init(CartInfo *); +void Mapper189_Init(CartInfo *); void Mapper191_Init(CartInfo *); +void Mapper192_Init(CartInfo *); +void Mapper194_Init(CartInfo *); +void Mapper198_Init(CartInfo *); +void Mapper199_Init(CartInfo *); void Mapper205_Init(CartInfo *); 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 Mapper235_Init(CartInfo *); +void Mapper236_Init(CartInfo *); +void Mapper237_Init(CartInfo *); void Mapper245_Init(CartInfo *); void Mapper249_Init(CartInfo *); void Mapper250_Init(CartInfo *); diff --git a/mappers/117.c b/mappers/117.c deleted file mode 100644 index f7302b4..0000000 --- a/mappers/117.c +++ /dev/null @@ -1,70 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - - - -DECLFW(Mapper117_write) -{ - //if(A>=0xc000) - //printf("$%04x:$%02x, %d,%d\n",A,V,scanline,timestamp); - switch(A) - { - case 0xc001:IRQLatch=V;break; - case 0xc003:IRQCount=IRQLatch;IRQa|=2;break; - case 0xe000:IRQa&=~1;IRQa|=V&1;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xc002:X6502_IRQEnd(FCEU_IQEXT);break; - case 0xa000:VROM_BANK1(0x0000,V);break; - case 0xa001:VROM_BANK1(0x0400,V);break; - case 0xa002:VROM_BANK1(0x0800,V);break; - case 0xa003:VROM_BANK1(0x0c00,V);break; - case 0xa004:VROM_BANK1(0x1000,V);break; - case 0xa005:VROM_BANK1(0x1400,V);break; - case 0xa006:VROM_BANK1(0x1800,V);break; - case 0xa007:VROM_BANK1(0x1c00,V);break; - case 0x8000:ROM_BANK8(0x8000,V);break; - case 0x8001:ROM_BANK8(0xa000,V);break; - case 0x8002:ROM_BANK8(0xc000,V);break; - case 0x8003:ROM_BANK8(0xe000,V);break; - } -} - -static void Mapper117_hb(void) -{ - //if(scanline==0x40) X6502_IRQBegin(FCEU_IQEXT); - //return; - if(IRQa==3 && IRQCount) - { - IRQCount--; - if(!IRQCount) - { - IRQa&=1; - X6502_IRQBegin(FCEU_IQEXT); - } - } -} - -void Mapper117_init(void) -{ - GameHBIRQHook=Mapper117_hb; - SetWriteHandler(0x8000,0xffff,Mapper117_write); -} - diff --git a/mappers/16.c b/mappers/16.c index fd922fb..2e8d013 100644 --- a/mappers/16.c +++ b/mappers/16.c @@ -56,11 +56,9 @@ static DECLFW(Mapper16_write) IRQa=V&1; IRQCount=IRQLatch; break; - case 0xB:IRQLatch&=0xFF00; - IRQLatch|=V; + case 0xB:IRQLatch&=0xFF00; IRQLatch|=V; break; - case 0xC:IRQLatch&=0xFF; - IRQLatch|=V<<8; + case 0xC:IRQLatch&=0xFF; IRQLatch|=V<<8; break; case 0xD: break;/* Serial EEPROM control port */ } diff --git a/mappers/187.c b/mappers/187.c deleted file mode 100644 index c9925df..0000000 --- a/mappers/187.c +++ /dev/null @@ -1,170 +0,0 @@ -/* FCE Ultra - NES/Famicom Emulator - * - * Copyright notice for this file: - * Copyright (C) 2003 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 LastWr; -static uint8 ExtMode; -static uint8 cmd; -static uint8 DRegs[8]; -static uint32 count=0; -static uint32 last=0; -static int safe=0; -static uint8 poofish; - -static void Sync(void) -{ - int x; - uint32 base=0; - - if(cmd&0x80) base=0x1000; - setchr2(0x0000^base,(0x100|DRegs[0])>>1); - setchr2(0x0800^base,(0x100|DRegs[1])>>1); - for(x=0;x<4;x++) - setchr1((0x1000^base)+x*0x400,DRegs[2+x]); - - if(ExtMode&0x80) - { - if(ExtMode&0x20) - setprg32(0x8000,(ExtMode&0x1F)>>1); - else - { - setprg16(0x8000,(ExtMode&0x1F)); - setprg16(0xc000,(ExtMode&0x1F)); - } - } - else - { - setprg8(0x8000,DRegs[6]); - setprg8(0xa000,DRegs[7]); - setprg8(0xc000,~1); - setprg8(0xe000,~0); - } -} - -static DECLFW(M187Write) -{ -// FCEU_printf("Write: %04x:%04x (%04x,%d)\n",A,V,X.PC,scanline); - LastWr=V; - if(A==0x5000) - ExtMode=V; - Sync(); -} - -static DECLFW(M187HWrite) -{ -// FCEU_printf("Write: %04x:%04x (%04x,%d)\n",A,V,X.PC,scanline); - //if(A==0x8003 && X.PC<0x800) FCEUI_DumpMem("dmp",0x0000,0xFFFF); - //printf("$%04x:$%02x, %04x\n",A,V,X.PC); - LastWr=V; - - if(A==0x8003) - { -// if(V==0x28 || V==0x2A) - poofish=V; - } - else if(A==0x8000) poofish=0; - - switch(A) - { - case 0xc000:IRQLatch=IRQCount=V;break; - case 0xc001:IRQCount=IRQLatch;last=count=0;break; - case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xe001:IRQa=1;break; - case 0xa000:MIRROR_SET(V&1);break; - - case 0x8000:cmd=V;safe=1;break; - case 0x8001: - if(safe) - { - //printf("Cmd: %d, %02x, %04x\n",cmd&0x7,V,X.PC); - DRegs[cmd&7]=V; - Sync(); - safe=0; - } - if(poofish==0x28) - setprg8(0xC000,0x17); - else if(poofish==0x2A) - setprg8(0xA000,0x0F); - break; - - } -} - -static DECLFR(ProtRead) -{ - switch(LastWr&0x3) - { - case 0x1: - case 0x0: return(0x83); - case 0x2: return(0x42); - } - return(0); -} - -DECLFW(Write_IRQFM); - -static void M187Power(void) -{ - Write_IRQFM(0x4017,0x40); - SetWriteHandler(0x5000,0x5fff,M187Write); - SetWriteHandler(0x8000,0xFFFF,M187HWrite); - SetReadHandler(0x5000,0x5FFF,ProtRead); - SetWriteHandler(0x6000,0x7FFF,M187Write); - SetReadHandler(0x8000,0xffff,CartBR); - Sync(); -} - -static void sl(void) -{ - if(IRQa) - { - if(IRQCount>=0) - { - IRQCount--; - if(IRQCount<0) - { - X6502_IRQBegin(FCEU_IQEXT); - } - } - } -} - -static void FP_FASTAPASS(1) foo(uint32 A) -{ - if((A&0x2000) && !(last&0x2000)) - { - count++; - if(count==42) - { - sl(); - count=0; - } - } - last=A; -} - -void Mapper187_Init(CartInfo *info) -{ - info->Power=M187Power; -// GameHBIRQHook=sl; - PPU_hook=foo; -} - diff --git a/mappers/189.c b/mappers/189.c deleted file mode 100644 index 68df5b5..0000000 --- a/mappers/189.c +++ /dev/null @@ -1,55 +0,0 @@ -/* Is this an MMC3 workalike piece of hardware, with the addition of - a register at $4120 or does it have only partial MMC3 functionality? - A good test would be to see if commands 6 and 7 can change PRG banks - and of course test the regs >=$c000, on the real cart. -*/ -#include "mapinc.h" - -#define cmd mapbyte1[0] -static DECLFW(Mapper189_write) -{ - //if(A>=0xc000) printf("$%04x:$%02x\n",A,V); - if((A&0xF100)==0x4100) ROM_BANK32(V>>4); - else if((A&0xF100)==0x6100) ROM_BANK32(V&3); - else switch(A&0xE001) - { - case 0xa000:MIRROR_SET(V&1);break; - case 0x8000:cmd=V;break; - case 0x8001:switch(cmd&7) - { - case 0:VROM_BANK2(0x0000,V>>1);break; - case 1:VROM_BANK2(0x0800,V>>1);break; - case 2:VROM_BANK1(0x1000,V);break; - case 3:VROM_BANK1(0x1400,V);break; - case 4:VROM_BANK1(0x1800,V);break; - case 5:VROM_BANK1(0x1C00,V);break; - } - case 0xc000:IRQLatch=V;break; - case 0xc001:IRQCount=IRQLatch;break; - case 0xe000:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xe001:IRQa=1;break; - break; - - } -} -void m189irq(void) -{ - if(IRQa) - { - if(IRQCount) - { - IRQCount--; - if(!IRQCount) X6502_IRQBegin(FCEU_IQEXT); - } - } - -} -void Mapper189_init(void) -{ - GameHBIRQHook=m189irq; - SetWriteHandler(0x4120,0xFFFF,Mapper189_write); - SetReadHandler(0x6000,0x7FFF,0); - ROM_BANK32(0); -} - - diff --git a/mappers/204.c b/mappers/204.c index 3d79918..edca423 100644 --- a/mappers/204.c +++ b/mappers/204.c @@ -1,38 +1,38 @@ -/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static DECLFW(Mapper204_write) -{ - int tmp2=A&0x6; - int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); - MIRROR_SET((A>>4)&1); - ROM_BANK16(0x8000,tmp1); - ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); - VROM_BANK8(tmp1); -} - -void Mapper204_init(void) -{ - ROM_BANK32(~0); - VROM_BANK8(~0); - SetWriteHandler(0x8000,0xFFFF,Mapper204_write); -} +/* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "mapinc.h" + +static DECLFW(Mapper204_write) +{ + int tmp2=A&0x6; + int tmp1=tmp2+((tmp2==0x6)?0:(A&1)); + MIRROR_SET((A>>4)&1); + ROM_BANK16(0x8000,tmp1); + ROM_BANK16(0xc000,tmp2+((tmp2==0x6)?1:(A&1))); + VROM_BANK8(tmp1); +} + +void Mapper204_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper204_write); +} diff --git a/mappers/211.c b/mappers/211.c deleted file mode 100644 index 5e6c5b2..0000000 --- a/mappers/211.c +++ /dev/null @@ -1,146 +0,0 @@ -#include "mapinc.h" - -static uint8 mul[2]; -static uint8 regie; -#define tkcom1 mapbyte1[1] -#define tkcom2 mapbyte1[2] -#define tkcom3 mapbyte1[3] - -#define prgb mapbyte2 -#define chr mapbyte3 - -static uint16 names[4]; -static uint8 tekker; - -static DECLFR(tekread) -{ -// FCEU_printf("READ READ READ: $%04x, $%04x, $%04x\n",A,X.PC,tekker); - switch(A) - { - case 0x5000:return(tekker); - case 0x5800:return(mul[0]*mul[1]); - case 0x5801:return((mul[0]*mul[1])>>8); - case 0x5803:return(regie); - default:break; - } - return(X.DB); -} - -static void mira(void) -{ - int x; - if(tkcom1&0x40) // Name tables are ROM-only - { - for(x=0;x<4;x++) - setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10), 0, x); - } - else // Name tables can be RAM or ROM. - { - for(x=0;x<4;x++) - { - if(((tkcom3&0x80)==(names[x]&0x80))) // RAM selected. - setntamem(NTARAM + ((names[x]&0x1)<<10),1,x); - else - setntamem(CHRptr[0]+(((names[x])&CHRmask1[0])<<10), 0, x); - } - } -} - -static void tekprom(void) -{ - switch(tkcom1&3) - { - case 1: // 16 KB - ROM_BANK16(0x8000,prgb[0]); - ROM_BANK16(0xC000,prgb[2]); - break; - - case 2: //2 = 8 KB ?? - ROM_BANK8(0x8000,prgb[0]); - ROM_BANK8(0xa000,prgb[1]); - ROM_BANK8(0xc000,prgb[2]); - ROM_BANK8(0xe000,~0); - break; - } -} - -static void tekvrom(void) -{ - int x; - switch(tkcom1&0x18) - { - case 0x00: // 8KB - setchr8(chr[0]); - break; - case 0x08: // 4KB - for(x=0;x<8;x+=4) - setchr4(x<<10,chr[x]); - break; - case 0x10: // 2KB - for(x=0;x<8;x+=2) - setchr2(x<<10,chr[x]); - break; - case 0x18: // 1KB - for(x=0;x<8;x++) - setchr1(x<<10,chr[x]); - break; - } -} - -static DECLFW(Mapper211_write) -{ - if(A==0x5800) mul[0]=V; - else if(A==0x5801) mul[1]=V; - else if(A==0x5803) regie=V; - - A&=0xF007; - if(A>=0x8000 && A<=0x8003) - { - prgb[A&3]=V; - tekprom(); - } - else if(A>=0x9000 && A<=0x9007) - { - chr[A&7]=V; - tekvrom(); - } - else if(A>=0xb000 && A<=0xb007) - { - names[A&3]=V&3; - mira(); - } - else switch(A) - { - case 0xc002:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0xc003: - case 0xc004:if(!IRQa) {IRQa=1;IRQCount=IRQLatch;} break; - case 0xc005:IRQCount=IRQLatch=V; - X6502_IRQEnd(FCEU_IQEXT);break; - case 0xd000: tkcom1=V; mira(); break; - case 0xd001: tkcom3=V; mira(); break; - } -} - -static void Mapper211_hb(void) -{ - if(IRQCount) IRQCount--; - if(!IRQCount) - { - if(IRQa) X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - } -} -static void togglie() -{ - tekker^=0xFF; -} - -void Mapper211_init(void) -{ - tekker=0xFF; - MapperReset=togglie; - SetWriteHandler(0x5000,0xffff,Mapper211_write); - SetReadHandler(0x5000,0x5fff,tekread); - GameHBIRQHook=Mapper211_hb; -} - diff --git a/mappers/212.c b/mappers/212.c index b069fc3..e5677b6 100644 --- a/mappers/212.c +++ b/mappers/212.c @@ -1,23 +1,23 @@ -#include "mapinc.h" - -static DECLFW(Mapper212_write) -{ - if((A&0x4000)==0x4000) - { - ROM_BANK32((A&6)>>1); - } - else - { - ROM_BANK16(0x8000,A&7); - ROM_BANK16(0xc000,A&7); - } - VROM_BANK8(A&7); - MIRROR_SET((A>>3)&1); -} - -void Mapper212_init(void) -{ - ROM_BANK32(~0); - VROM_BANK8(~0); - SetWriteHandler(0x8000,0xFFFF,Mapper212_write); -} +#include "mapinc.h" + +static DECLFW(Mapper212_write) +{ + if((A&0x4000)==0x4000) + { + ROM_BANK32((A&6)>>1); + } + else + { + ROM_BANK16(0x8000,A&7); + ROM_BANK16(0xc000,A&7); + } + VROM_BANK8(A&7); + MIRROR_SET((A>>3)&1); +} + +void Mapper212_init(void) +{ + ROM_BANK32(~0); + VROM_BANK8(~0); + SetWriteHandler(0x8000,0xFFFF,Mapper212_write); +} diff --git a/mappers/213.c b/mappers/213.c index e0b8d82..c537f6c 100644 --- a/mappers/213.c +++ b/mappers/213.c @@ -1,14 +1,14 @@ -#include "mapinc.h" - -static DECLFW(Mapper213_write) -{ - ROM_BANK32((A>>1)&3); - VROM_BANK8((A>>3)&7); -} - -void Mapper213_init(void) -{ - ROM_BANK32(0); - VROM_BANK8(0); - SetWriteHandler(0x8000,0xFFFF,Mapper213_write); -} +#include "mapinc.h" + +static DECLFW(Mapper213_write) +{ + ROM_BANK32((A>>1)&3); + VROM_BANK8((A>>3)&7); +} + +void Mapper213_init(void) +{ + ROM_BANK32(0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper213_write); +} diff --git a/mappers/214.c b/mappers/214.c index 03a73ce..deaf47d 100644 --- a/mappers/214.c +++ b/mappers/214.c @@ -1,17 +1,17 @@ -#include "mapinc.h" - -static DECLFW(Mapper214_write) -{ -// FCEU_printf("%02x:%02x\n",A,V); - ROM_BANK16(0x8000,(A>>2)&3); - ROM_BANK16(0xC000,(A>>2)&3); - VROM_BANK8(A&3); -} - -void Mapper214_init(void) -{ - ROM_BANK16(0x8000,0); - ROM_BANK16(0xC000,0); - VROM_BANK8(0); - SetWriteHandler(0x8000,0xFFFF,Mapper214_write); -} +#include "mapinc.h" + +static DECLFW(Mapper214_write) +{ +// FCEU_printf("%02x:%02x\n",A,V); + ROM_BANK16(0x8000,(A>>2)&3); + ROM_BANK16(0xC000,(A>>2)&3); + VROM_BANK8(A&3); +} + +void Mapper214_init(void) +{ + ROM_BANK16(0x8000,0); + ROM_BANK16(0xC000,0); + VROM_BANK8(0); + SetWriteHandler(0x8000,0xFFFF,Mapper214_write); +} diff --git a/mappers/255.c b/mappers/255.c index ede7af3..d65f18d 100644 --- a/mappers/255.c +++ b/mappers/255.c @@ -61,7 +61,7 @@ void Mapper255_init(void) mapbyte1[0]=mapbyte1[1]=0xF; ROM_BANK32(0); VROM_BANK8(0); - SetWriteHandler(0x5800,0x5FFF,Mapper255_wl); + SetWriteHandler(0x5800,0x5FF0,Mapper255_wl); SetWriteHandler(0x8000,0xffff,Mapper255_write); SetReadHandler(0x5800,0x5FFF,Mapper255_read); } diff --git a/mappers/27.c b/mappers/27.c index 9dbe5cf..4b5cd73 100644 --- a/mappers/27.c +++ b/mappers/27.c @@ -1,74 +1,74 @@ -#include "mapinc.h" - -static uint32 regchr[9]; - -static DECLFW(Mapper27_write) -{ - A&=0xF00F; - int regnum; - if((A>=0xB000) && (A<=0xE003)) { - regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); - if(A&1) - regchr[regnum]=(regchr[regnum]&0x0F)|(V<<4); - else - regchr[regnum]=(regchr[regnum]&0xFF0)|(V&0xF); - VROM_BANK1(regnum<<10,regchr[regnum]); - } - switch(A) - { - case 0x8000: if(regchr[8]&2) - ROM_BANK8(0xc000,V); - else - ROM_BANK8(0x8000,V); - break; - case 0xA000: ROM_BANK8(0xa000,V); break; - case 0x9000: - switch(V&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; - } - case 0x9002: regchr[8]=V; break; - case 0xF000: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0xF0)|(V&0x0F); - break; - case 0xF001: //X6502_IRQEnd(FCEU_IQEXT); - IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); - break; - case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); - X6502_IRQEnd(FCEU_IQEXT); - break; - case 0xF002: IRQa=V&3; - if(IRQa&0x02) IRQCount=IRQLatch; - X6502_IRQEnd(FCEU_IQEXT); - break; - } -// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline); -} - -static void Mapper27_hb(void) -{ -// FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch); - if(IRQa&0x2){ - if(IRQCount==0xFF){ - X6502_IRQBegin(FCEU_IQEXT); - IRQCount=IRQLatch+1; - } else { - IRQCount++; - } - } -} - -void Mapper27_init(void) -{ - int i; - for (i=0; i<9; i++) { - regchr[i]=0; - } - IRQa=0; - IRQCount=IRQLatch=0; - SetWriteHandler(0x8000,0xffff,Mapper27_write); - GameHBIRQHook=Mapper27_hb; -} - +#include "mapinc.h" + +static uint32 regchr[9]; + +static DECLFW(Mapper27_write) +{ + A&=0xF00F; + int regnum; + if((A>=0xB000) && (A<=0xE003)) { + regnum=((((A>>12)+1)&0x03)<<1)|((A&0x02)>>1); + if(A&1) + regchr[regnum]=(regchr[regnum]&0x0F)|(V<<4); + else + regchr[regnum]=(regchr[regnum]&0xFF0)|(V&0xF); + VROM_BANK1(regnum<<10,regchr[regnum]); + } + switch(A) + { + case 0x8000: if(regchr[8]&2) + ROM_BANK8(0xc000,V); + else + ROM_BANK8(0x8000,V); + break; + case 0xA000: ROM_BANK8(0xa000,V); break; + case 0x9000: + switch(V&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; + } + case 0x9002: regchr[8]=V; break; + case 0xF000: //X6502_IRQEnd(FCEU_IQEXT); + IRQLatch=(IRQLatch&0xF0)|(V&0x0F); + break; + case 0xF001: //X6502_IRQEnd(FCEU_IQEXT); + IRQLatch=(IRQLatch&0x0F)|((V&0xF)<<4); + break; + case 0xF003: IRQa=((IRQa&0x1)<<1)|(IRQa&0x1); + X6502_IRQEnd(FCEU_IQEXT); + break; + case 0xF002: IRQa=V&3; + if(IRQa&0x02) IRQCount=IRQLatch; + X6502_IRQEnd(FCEU_IQEXT); + break; + } +// if((A&0xF000)==0xF000) FCEU_printf("$%04x:$%02x, %d\n",A,V, scanline); +} + +static void Mapper27_hb(void) +{ +// FCEU_printf("%02x-%d,%d,%d\n",scanline,IRQa,IRQCount,IRQLatch); + if(IRQa&0x2){ + if(IRQCount==0xFF){ + X6502_IRQBegin(FCEU_IQEXT); + IRQCount=IRQLatch+1; + } else { + IRQCount++; + } + } +} + +void Mapper27_init(void) +{ + int i; + for (i=0; i<9; i++) { + regchr[i]=0; + } + IRQa=0; + IRQCount=IRQLatch=0; + SetWriteHandler(0x8000,0xffff,Mapper27_write); + GameHBIRQHook=Mapper27_hb; +} + diff --git a/mappers/6.c b/mappers/6.c index 45a8f0d..c6c5bf5 100644 --- a/mappers/6.c +++ b/mappers/6.c @@ -1,80 +1,80 @@ -/* 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 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 FP_FASTAPASS(1) FFEIRQHook(int a) -{ - if(IRQa) - { - IRQCount+=a; - if(IRQCount>=0x10000) - { - X6502_IRQBegin(FCEU_IQEXT); - IRQa=0; - IRQCount=0; - } - } -} - -DECLFW(Mapper6_write) -{ - if(A<0x8000) - { - switch(A){ - case 0x42FF:MIRROR_SET((V>>4)&1);break; - case 0x42FE:onemir((V>>3)&2); FFEmode=V&0x80;break; - case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; - case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; - case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break; - } - } else { - switch (FFEmode) - { - case 0x80: setchr8(V); break; - default: ROM_BANK16(0x8000,V>>2); - FVRAM_BANK8(0x0000,V&3); - } - } -} -void Mapper6_StateRestore(int version) -{ - int x; - for(x=0;x<8;x++) - if(PPUCHRRAM&(1<7) - VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400); - else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400); - } -} -void Mapper6_init(void) -{ -MapIRQHook=FFEIRQHook; -ROM_BANK16(0xc000,7); - -SetWriteHandler(0x4020,0x5fff,Mapper6_write); -SetWriteHandler(0x8000,0xffff,Mapper6_write); -MapStateRestore=Mapper6_StateRestore; -} +/* 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 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 FP_FASTAPASS(1) FFEIRQHook(int a) +{ + if(IRQa) + { + IRQCount+=a; + if(IRQCount>=0x10000) + { + X6502_IRQBegin(FCEU_IQEXT); + IRQa=0; + IRQCount=0; + } + } +} + +DECLFW(Mapper6_write) +{ + if(A<0x8000) + { + switch(A){ + case 0x42FF:MIRROR_SET((V>>4)&1);break; + case 0x42FE:onemir((V>>3)&2); FFEmode=V&0x80;break; + case 0x4501:IRQa=0;X6502_IRQEnd(FCEU_IQEXT);break; + case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; + case 0x4503:IRQCount&=0xFF;IRQCount|=V<<8;IRQa=1;break; + } + } else { + switch (FFEmode) + { + case 0x80: setchr8(V); break; + default: ROM_BANK16(0x8000,V>>2); + FVRAM_BANK8(0x0000,V&3); + } + } +} +void Mapper6_StateRestore(int version) +{ + int x; + for(x=0;x<8;x++) + if(PPUCHRRAM&(1<7) + VPage[x]=&MapperExRAM[(CHRBankList[x]&31)*0x400]-(x*0x400); + else VPage[x]=&CHRRAM[(CHRBankList[x]&7)*0x400]-(x*0x400); + } +} +void Mapper6_init(void) +{ +MapIRQHook=FFEIRQHook; +ROM_BANK16(0xc000,7); + +SetWriteHandler(0x4020,0x5fff,Mapper6_write); +SetWriteHandler(0x8000,0xffff,Mapper6_write); +MapStateRestore=Mapper6_StateRestore; +} diff --git a/mappers/62.c b/mappers/62.c index ed0f01d..4d03c88 100644 --- a/mappers/62.c +++ b/mappers/62.c @@ -23,7 +23,7 @@ static DECLFW(Mapper62_write) { VROM_BANK8(((A&0x1F)<<2)|(V&0x03)); - if((A&0x20)>>5) { + if(A&0x20) { ROM_BANK16(0x8000,(A&0x40)|((A>>8)&0x3F)); ROM_BANK16(0xc000,(A&0x40)|((A>>8)&0x3F)); } diff --git a/mappers/68.c b/mappers/68.c index 9c25f1b..69eaefc 100644 --- a/mappers/68.c +++ b/mappers/68.c @@ -39,6 +39,7 @@ static void Fixerit(void) DECLFW(Mapper68_write) { +// FCEU_printf("%04x,%04x\n",A,V); A&=0xF000; if(A>=0x8000 && A<=0xB000) diff --git a/mappers/83.c b/mappers/83.c index 3ab004f..9a3bcd7 100644 --- a/mappers/83.c +++ b/mappers/83.c @@ -58,9 +58,19 @@ static void m83prg(void) static void m83chr(void) { - int x; - for(x=0;x<8;x++) - VROM_BANK1(x*0x400,mapbyte2[x]|((mapbyte1[0]&0x30)<<4)); +// if(0) +// { +// 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) @@ -79,6 +89,7 @@ static DECLFW(Mapper83_write) } break; case 0x8100: + mapbyte3[0]=V&0x80; switch(V&0x3) { case 0x00:MIRROR_SET2(1);break; @@ -88,7 +99,7 @@ static DECLFW(Mapper83_write) } break; case 0x8200:IRQCount&=0xFF00;IRQCount|=V;X6502_IRQEnd(FCEU_IQEXT);break; - case 0x8201:IRQa=1;IRQCount&=0xFF;IRQCount|=V<<8;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; diff --git a/mappers/88.c b/mappers/88.c deleted file mode 100644 index 96ef0ed..0000000 --- a/mappers/88.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static int mn; -static DECLFW(Mapper88_write) -{ - //if(A>=0x8002 || A<0x8000) - //if(A==0xc000) - // printf("$%04x:$%02x\n",A,V); - switch(A&0x8001) //&0xc001) - { - case 0x8000:mapbyte1[0]=V; - if(mn) - onemir((V>>6)&1); - break; - case 0x8001: - switch(mapbyte1[0]&7) - { - case 0:VROM_BANK2(0,V>>1);break; - case 1:VROM_BANK2(0x800,V>>1);break; - case 2:VROM_BANK1(0x1000,V|0x40);break; - case 3:VROM_BANK1(0x1400,V|0x40);break; - case 4:VROM_BANK1(0x1800,V|0x40);break; - case 5:VROM_BANK1(0x1c00,V|0x40);break; - case 6:ROM_BANK8(0x8000,V);break; - case 7:ROM_BANK8(0xA000,V);break; - } - break; - - } -} - -void Mapper88_init(void) -{ - mn=0; - SetWriteHandler(0x8000,0xffff,Mapper88_write); -} - -void Mapper154_init(void) -{ - mn=1; - SetWriteHandler(0x8000,0xffff,Mapper88_write); -} diff --git a/mappers/95.c b/mappers/95.c deleted file mode 100644 index 11b6a8e..0000000 --- a/mappers/95.c +++ /dev/null @@ -1,136 +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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "mapinc.h" - -static uint8 lastA; -static uint8 DRegs[8]; -static uint8 cmd; -static uint8 MirCache[8]; - -static SFORMAT DB_StateRegs[]={ - {DRegs, 8, "DREG"}, - {&cmd, 1, "CMD"}, - {&lastA, 1, "LAST"}, - {0} -}; - -static void FP_FASTAPASS(1) dragonbust_ppu(uint32 A) -{ - static int last=-1; - static uint8 z; - - if(A>=0x2000) return; - - A>>=10; - - lastA=A; - - z=MirCache[A]; - if(z!=last) - { - onemir(z); - last=z; - } -} - -static void toot(void) -{ - int x; - - MirCache[0]=MirCache[1]=(DRegs[0]>>4)&1; - MirCache[2]=MirCache[3]=(DRegs[1]>>4)&1; - - for(x=0;x<4;x++) - MirCache[4+x]=(DRegs[2+x]>>5)&1; - onemir(MirCache[lastA]); -} - -static DECLFW(Mapper95_write) -{ - switch(A&0xF001) - { - - case 0x8000: - cmd = V; - break; - - case 0x8001: - switch(cmd&0x07) - { - case 0: DRegs[0]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0000,V&0x1F);break; - case 1: DRegs[1]=(V&0x3F)>>1;toot();V>>=1;setchr2(0x0800,V&0x1F);break; - case 2: DRegs[2]=V&0x3F;toot();setchr1(0x1000,V&0x1F); break; - case 3: DRegs[3]=V&0x3F;toot();setchr1(0x1400,V&0x1F); break; - case 4: DRegs[4]=V&0x3F;toot();setchr1(0x1800,V&0x1F); break; - case 5: DRegs[5]=V&0x3F;toot();setchr1(0x1C00,V&0x1F); break; - case 6: DRegs[6]=V&0x3F; - setprg8(0x8000,V); - break; - case 7: DRegs[7]=V&0x3F; - setprg8(0xA000,V); - break; - } - break; - } -} - -static void DBSync() -{ - int x; - - setchr2(0x0000,DRegs[0]); - setchr2(0x0800,DRegs[1]); - - for(x=0;x<4;x++) - setchr1(0x1000+x*0x400,DRegs[2+x]); - - setprg8(0x8000,DRegs[6]); - setprg8(0xa000,DRegs[7]); - toot(); -} - -static void DBPower(void) -{ - memset(DRegs,0x3F,8); - DRegs[0]=DRegs[1]=0x1F; - - DBSync(); - - setprg8(0xc000,0x3E); - setprg8(0xe000,0x3F); - - SetReadHandler(0x8000,0xffff,CartBR); - SetWriteHandler(0x8000,0xffff,Mapper95_write); -} - -static void StateRestore(int version) -{ - DBSync(); -} - -void Mapper95_Init(CartInfo *info) -{ - info->Power=DBPower; - AddExState(DB_StateRegs, ~0, 0, 0); - PPU_hook=dragonbust_ppu; - GameStateRestore=StateRestore; -} - diff --git a/mappers/Makefile b/mappers/Makefile index a29a0bf..4bee951 100644 --- a/mappers/Makefile +++ b/mappers/Makefile @@ -1,13 +1,83 @@ -MOBJS += mappers/6.o mappers/8.o mappers/15.o mappers/16.o mappers/17.o mappers/18.o mappers/21.o mappers/22.o -MOBJS += mappers/23.o mappers/24and26.o mappers/25.o mappers/27.o mappers/32.o mappers/33.o mappers/40.o -MOBJS += mappers/41.o mappers/42.o mappers/43.o mappers/46.o mappers/50.o mappers/51.o mappers/57.o mappers/58.o -MOBJS += mappers/59.o mappers/60.o mappers/61.o mappers/62.o mappers/65.o mappers/67.o mappers/68.o mappers/69.o -MOBJS += mappers/71.o mappers/72.o mappers/73.o mappers/75.o mappers/76.o mappers/77.o mappers/79.o mappers/80.o -MOBJS += mappers/82.o mappers/83.o mappers/85.o mappers/86.o mappers/88.o mappers/89.o mappers/91.o mappers/92.o -MOBJS += mappers/95.o mappers/97.o mappers/99.o mappers/113.o mappers/117.o mappers/151.o mappers/180.o mappers/183.o -MOBJS += mappers/184.o mappers/187.o mappers/189.o mappers/193.o mappers/200.o mappers/201.o mappers/202.o mappers/203.o -MOBJS += mappers/204.o mappers/208.o mappers/211.o mappers/212.o mappers/213.o mappers/214.o mappers/215.o -MOBJS += mappers/217.o mappers/225.o mappers/226.o mappers/227.o mappers/228.o mappers/229.o mappers/230.o mappers/231.o -MOBJS += mappers/232.o mappers/234.o mappers/235.o mappers/240.o mappers/241.o mappers/242.o mappers/244.o mappers/246.o -MOBJS += mappers/255.o mappers/emu2413.o mappers/mmc2and4.o mappers/simple.o +MM_C += mappers/113.c +MM_C += mappers/15.c +MM_C += mappers/151.c +MM_C += mappers/16.c +MM_C += mappers/17.c +MM_C += mappers/18.c +MM_C += mappers/180.c +MM_C += mappers/183.c +MM_C += mappers/184.c +MM_C += mappers/193.c +MM_C += mappers/200.c +MM_C += mappers/201.c +MM_C += mappers/202.c +MM_C += mappers/203.c +MM_C += mappers/204.c +MM_C += mappers/21.c +MM_C += mappers/212.c +MM_C += mappers/213.c +MM_C += mappers/214.c +MM_C += mappers/215.c +MM_C += mappers/217.c +MM_C += mappers/22.c +MM_C += mappers/225.c +MM_C += mappers/226.c +MM_C += mappers/227.c +MM_C += mappers/228.c +MM_C += mappers/229.c +MM_C += mappers/23.c +MM_C += mappers/230.c +MM_C += mappers/231.c +MM_C += mappers/232.c +MM_C += mappers/234.c +MM_C += mappers/240.c +MM_C += mappers/241.c +MM_C += mappers/242.c +MM_C += mappers/244.c +MM_C += mappers/246.c +MM_C += mappers/24and26.c +MM_C += mappers/25.c +MM_C += mappers/255.c +MM_C += mappers/27.c +MM_C += mappers/32.c +MM_C += mappers/33.c +MM_C += mappers/40.c +MM_C += mappers/41.c +MM_C += mappers/42.c +MM_C += mappers/43.c +MM_C += mappers/46.c +MM_C += mappers/50.c +MM_C += mappers/51.c +MM_C += mappers/59.c +MM_C += mappers/6.c +MM_C += mappers/60.c +MM_C += mappers/61.c +MM_C += mappers/62.c +MM_C += mappers/65.c +MM_C += mappers/67.c +MM_C += mappers/68.c +MM_C += mappers/69.c +MM_C += mappers/71.c +MM_C += mappers/72.c +MM_C += mappers/73.c +MM_C += mappers/75.c +MM_C += mappers/76.c +MM_C += mappers/77.c +MM_C += mappers/79.c +MM_C += mappers/8.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/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 + +MOBJS += $(patsubst %.c,%.o,$(MM_C)) diff --git a/mappers/mapinc.h b/mappers/mapinc.h index 9eec5c9..7e2f5e3 100644 --- a/mappers/mapinc.h +++ b/mappers/mapinc.h @@ -9,5 +9,4 @@ #include "../sound.h" #include "../state.h" #include "../svga.h" -#include "../dprintf.h" #include diff --git a/mappers/simple.c b/mappers/simple.c index b2c76d8..c393d09 100644 --- a/mappers/simple.c +++ b/mappers/simple.c @@ -23,91 +23,6 @@ static uint8 latche; -//static DECLFW(Mapper2_write) -//{ -// latche=V; -// ROM_BANK16(0x8000,V); -//} -// -//void Mapper2_init(void) -//{ -// SetWriteHandler(0x8000,0xFFFF,Mapper2_write); -// AddExState(&latche, 1, 0, "LATC"); -//} - -//static DECLFW(Mapper3_write) -//{ -// VROM_BANK8(V); -// latche=V; -//} - -//void Mapper3_init(void) -//{ -// SetWriteHandler(0x8000,0xFFFF,Mapper3_write); -// AddExState(&latche, 1, 0, "LATC"); -//} - -static DECLFW(Mapper7_write) -{ -// FCEU_printf("%04x,%04x\n",A,V); - ROM_BANK32(V&0xF); - onemir((V>>4)&1); - latche=V; -} - -void Mapper7_init(void) -{ - onemir(0); - ROM_BANK32(0); - SetWriteHandler(0x8000,0xFFFF,Mapper7_write); - AddExState(&latche, 1, 0, "LATC"); -} - -static DECLFW(Mapper11_write) -{ - ROM_BANK32(V&0xF); - VROM_BANK8(V>>4); - latche=V; -} - -void Mapper11_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x8000,0xFFFF,Mapper11_write); - AddExState(&latche, 1, 0, "LATC"); -} -void Mapper144_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x8001,0xFFFF,Mapper11_write); - AddExState(&latche, 1, 0, "LATC"); - -} -//static DECLFW(Mapper13_write) -//{ -// setchr4r(0x10,0x1000,V&3); -// setprg32(0x8000,(V>>4)&3); -// latche=V; -//} - -//static void Mapper13_StateRestore(int version) -//{ -// setchr4r(0x10,0x0000,0); -// setchr4r(0x10,0x1000,latche&3); -// setprg32(0x8000,(latche>>4)&3); -//} - -//void Mapper13_init(void) -//{ -// SetWriteHandler(0x8000,0xFFFF,Mapper13_write); -// GameStateRestore=Mapper13_StateRestore; -// AddExState(&latche, 1, 0, "LATC"); -// AddExState(MapperExRAM, 16384, 0, "CHRR"); -// SetupCartCHRMapping(0x10, MapperExRAM, 16384, 1); -// latche=0; -// Mapper13_StateRestore(FCEU_VERSION_NUMERIC); -//} - static DECLFW(Mapper34_write) { switch(A) @@ -126,101 +41,6 @@ void Mapper34_init(void) SetWriteHandler(0x7ffd,0xffff,Mapper34_write); } -DECLFW(Mapper66_write) -{ - VROM_BANK8(V&0xF); - ROM_BANK32((V>>4)); - latche=V; -} - -void Mapper66_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x6000,0xffff,Mapper66_write); - AddExState(&latche, 1, 0, "LATC"); -} - -DECLFW(Mapper152_write) -{ - ROM_BANK16(0x8000,(V>>4)&0x7); - VROM_BANK8(V&0xF); - onemir((V>>7)&1); /* Saint Seiya...hmm. */ - latche=V; -} - -void Mapper152_init(void) -{ - onemir(0); - SetWriteHandler(0x6000,0xffff,Mapper152_write); - AddExState(&latche, 1, 0, "LATC"); -} - -static DECLFW(Mapper70_write) -{ - ROM_BANK16(0x8000,V>>4); - VROM_BANK8(V&0xF); - latche=V; -} - -void Mapper70_init(void) -{ - SetWriteHandler(0x6000,0xffff,Mapper70_write); - AddExState(&latche, 1, 0, "LATC"); -} -/* Should be two separate emulation functions for this "mapper". Sigh. URGE TO KILL RISING. */ -static DECLFW(Mapper78_write) -{ - //printf("$%04x:$%02x\n",A,V&0x8); - ROM_BANK16(0x8000,V&0x7); - VROM_BANK8(V>>4); - onemir((V>>3)&1); - latche=V; -} - -void Mapper78_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper78_write); - AddExState(&latche, 1, 0, "LATC"); -} - -DECLFW(Mapper87_write) -{ - VROM_BANK8(V>>1); - latche=V; -} - -void Mapper87_init(void) -{ - SetWriteHandler(0x6000,0xffff,Mapper87_write); - AddExState(&latche, 1, 0, "LATC"); -} - -DECLFW(Mapper93_write) -{ - ROM_BANK16(0x8000,V>>4); - MIRROR_SET(V&1); - latche=V; -} - -void Mapper93_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper93_write); - AddExState(&latche, 1, 0, "LATC"); -} - - -DECLFW(Mapper94_write) -{ - ROM_BANK16(0x8000,V>>2); - latche=V; -} - -void Mapper94_init(void) -{ - SetWriteHandler(0x8000,0xffff,Mapper94_write); - AddExState(&latche, 1, 0, "LATC"); -} - /* 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. @@ -263,56 +83,6 @@ void Mapper96_init(void) GameStateRestore=M96Sync; } -static DECLFW(Mapper140_write) -{ - VROM_BANK8(V&0xF); - ROM_BANK32((V>>4)&0xF); -} - -void Mapper140_init(void) -{ - ROM_BANK32(0); - SetWriteHandler(0x6000,0x7FFF,Mapper140_write); -} - -static void M185Sync(int version) -{ -// on off -//1 0x0F, 0xF0 - Bird Week -//2 0x33, 0x00 - B-Wings -//3 0x11, 0x00 - Mighty Bomb Jack -//4 0x22, 0x20 - Sansuu 1 Nen, Sansuu 2 Nen -//5 0xFF, 0x00 - Sansuu 3 Nen -//6 0x21, 0x13 - Spy vs Spy - -// if((mapbyte1[0]&3)==1) // 6, 3 -// if(mapbyte1[0]&1) // 1, 2, 3, 5 -// if(mapbyte1[0]&2) // 1, 2, 4, 5, - if((mapbyte1[0]&2)||((mapbyte1[0]&3)==1)) // 1, 2, 3, 4, 5 - setchr8(0); - else - setchr8r(0x10,0); -} - -static DECLFW(Mapper185_write) -{ - mapbyte1[0]=V; - M185Sync(0); -} - -void Mapper185_init(void) -{ - int x; - for(x=0;x<8192;x++) - MapperExRAM[x]=0xff; - MapStateRestore=M185Sync; - mapbyte1[0]=0; - M185Sync(0); - SetupCartCHRMapping(0x10,MapperExRAM,8192,0); - SetWriteHandler(0x8000,0xFFFF,Mapper185_write); -} - - static DECLFW(M156Write) { if(A>=0xc000 && A<=0xC003) @@ -328,15 +98,3 @@ void Mapper156_init(void) onemir(0); SetWriteHandler(0xc000,0xc010,M156Write); } - -static DECLFW(m107w) -{ - ROM_BANK32((V>>1)&0x3); - VROM_BANK8(V&0x7); -} - -void Mapper107_init(void) -{ - SetWriteHandler(0x8000,0xffff,m107w); -} - diff --git a/sound.h b/sound.h index fcbcb25..b995633 100644 --- a/sound.h +++ b/sound.h @@ -84,3 +84,5 @@ void SetNESSoundMap(void); void FrameSoundUpdate(void); void FixOldSaveStateSFreq(void); +DECLFW(Write_IRQFM); + diff --git a/unif.c b/unif.c index e5bb8e1..dda5d7f 100644 --- a/unif.c +++ b/unif.c @@ -333,15 +333,14 @@ static BMAPPING bmap[] = { { "SA-0037", SA0037_Init,0}, { "SA-NROM", TCA01_Init,0}, - { "H2288", UNLH2288_Init,0}, - { "8237", UNL8237_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}, @@ -376,25 +375,42 @@ static BMAPPING bmap[] = { { "CPROM", CPROM_Init,BMCFLAG_16KCHRR}, { "CNROM", CNROM_Init,0}, - { "GNROM", GNROM_Init,0}, - { "NROM", NROM256_Init,0 }, - { "RROM", NROM128_Init,0 }, - { "RROM-128", NROM128_Init,0 }, - { "NROM-128", NROM128_Init,0 }, - { "NROM-256", NROM256_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}, + { "SUNSOFT_UNROM", SUNSOFT_UNROM_Init,0}, { "MARIO1-MALEE2", MALEE_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}, { "8157", UNL8157_Init,0}, + { "T-262", BMCT262_Init,0}, + { "FK23C", BMCFK23C_Init,0}, { "Supervision16in1", Supervision16_Init,0}, { "NovelDiamond9999999in1", Novel_Init,0}, { "Super24in1SC03", Super24_Init,0}, + { "42in1ResetSwitch", BMC42in1r_Init, 0}, + { "64in1NoRepeat", BMC64in1nr_Init, 0}, + { "13in1JY110", BMC13in1JY110_Init, 0}, + { "70in1", BMC70in1_Init, 0}, + { "70in1B", BMC70in1B_Init, 0}, + { "GK-192", Mapper58_Init, 0}, { "SuperHIK8in1", Mapper45_Init,0}, + { "DREAMTECH01", DreamTech01_Init,0}, { "KONAMI-QTAI", Mapper190_Init,0}, + + { "TEK90", Mapper90_Init,0}, + {0,0,0} }; diff --git a/unif.h b/unif.h index f423765..c8b0ef1 100644 --- a/unif.h +++ b/unif.h @@ -18,24 +18,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -void TCA01_Init(CartInfo *info); -void TCU01_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 SA0036_Init(CartInfo *info); -void SA0037_Init(CartInfo *info); - -void UNLH2288_Init(CartInfo *info); -void UNL8237_Init(CartInfo *info); -void UNL8157_Init(CartInfo *info); +void ANROM_Init(CartInfo *info); void HKROM_Init(CartInfo *info); @@ -56,14 +39,10 @@ void SNROM_Init(CartInfo *info); void SOROM_Init(CartInfo *info); void NROM_Init(CartInfo *info); -void NROM256_Init(CartInfo *info); -void NROM128_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 Supervision16_Init(CartInfo *info); -void Super24_Init(CartInfo *info); -void Novel_Init(CartInfo *info); void CNROM_Init(CartInfo *info); void CPROM_Init(CartInfo *info); void GNROM_Init(CartInfo *info); @@ -80,9 +59,44 @@ 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 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 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 BMC42in1r_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 DreamTech01_Init(CartInfo *info); void Mapper190_Init(CartInfo *info); void UNLCC21_Init(CartInfo *info); +void UNLSL1632_Init(CartInfo *info); +void UNLKOF97_Init(CartInfo *info); +void UNLSonic_Init(CartInfo *info); +void UNLSHeroes_Init(CartInfo *info); +void UNLH2288_Init(CartInfo *info); +void UNL8237_Init(CartInfo *info); +void UNL8157_Init(CartInfo *info); extern uint8 *UNIFchrrama; // Meh. So I can stop CHR RAM - // bank switcherooing with certain boards... + // bank switcherooing with certain boards... -- 2.39.2