From 880c9deb620ac14e5dcb1af9a4cf8aca9e367ab4 Mon Sep 17 00:00:00 2001 From: CaH4e3 Date: Wed, 12 Dec 2012 20:28:34 +0000 Subject: [PATCH] removed old ines code, more formatting --- src/cart.cpp | 693 +++++++++++++++++++-------------------------- src/cart.h | 52 ++-- src/fceu.cpp | 780 ++++++++++++++++++++++----------------------------- src/ines.cpp | 526 ++-------------------------------- src/ines.h | 290 +------------------ 5 files changed, 673 insertions(+), 1668 deletions(-) diff --git a/src/cart.cpp b/src/cart.cpp index 8464be61..64061136 100644 --- a/src/cart.cpp +++ b/src/cart.cpp @@ -1,22 +1,22 @@ /* FCE Ultra - NES/Famicom Emulator -* -* Copyright notice for this file: -* Copyright (C) 2002 Xodnizel -* -* This program is free software; you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation; either version 2 of the License, or -* (at your option) any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -*/ + * + * Copyright notice for this file: + * Copyright (C) 2002 Xodnizel + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ /// \file /// \brief This file contains all code for coordinating the mapping in of the address space external to the NES. @@ -37,8 +37,8 @@ #include "utils/memory.h" -uint8 *Page[32],*VPage[8]; -uint8 **VPageR=VPage; +uint8 *Page[32], *VPage[8]; +uint8 **VPageR = VPage; uint8 *VPageG[8]; uint8 *MMC5SPRVPage[8]; uint8 *MMC5BGVPage[8]; @@ -66,7 +66,7 @@ uint32 CHRmask2[32]; uint32 CHRmask4[32]; uint32 CHRmask8[32]; -int geniestage=0; +int geniestage = 0; int modcon; @@ -75,614 +75,487 @@ uint8 geniech[3]; uint32 genieaddr[3]; -static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram) -{ - uint32 AB=A>>11; +static INLINE void setpageptr(int s, uint32 A, uint8 *p, int ram) { + uint32 AB = A >> 11; int x; - if(p) - for(x=(s>>1)-1;x>=0;x--) - { - PRGIsRAM[AB+x]=ram; - Page[AB+x]=p-A; + if (p) + for (x = (s >> 1) - 1; x >= 0; x--) { + PRGIsRAM[AB + x] = ram; + Page[AB + x] = p - A; } else - for(x=(s>>1)-1;x>=0;x--) - { - PRGIsRAM[AB+x]=0; - Page[AB+x]=0; + for (x = (s >> 1) - 1; x >= 0; x--) { + PRGIsRAM[AB + x] = 0; + Page[AB + x] = 0; } } static uint8 nothing[8192]; -void ResetCartMapping(void) -{ +void ResetCartMapping(void) { int x; PPU_ResetHooks(); - for(x=0;x<32;x++) - { - Page[x]=nothing-x*2048; - PRGptr[x]=CHRptr[x]=0; - PRGsize[x]=CHRsize[x]=0; + for (x = 0; x < 32; x++) { + Page[x] = nothing - x * 2048; + PRGptr[x] = CHRptr[x] = 0; + PRGsize[x] = CHRsize[x] = 0; } - for(x=0;x<8;x++) - { - MMC5SPRVPage[x]=MMC5BGVPage[x]=VPageR[x]=nothing-0x400*x; + for (x = 0; x < 8; x++) { + MMC5SPRVPage[x] = MMC5BGVPage[x] = VPageR[x] = nothing - 0x400 * x; } - } -void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram) -{ - PRGptr[chip]=p; - PRGsize[chip]=size; +void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram) { + PRGptr[chip] = p; + PRGsize[chip] = size; - PRGmask2[chip]=(size>>11)-1; - PRGmask4[chip]=(size>>12)-1; - PRGmask8[chip]=(size>>13)-1; - PRGmask16[chip]=(size>>14)-1; - PRGmask32[chip]=(size>>15)-1; + PRGmask2[chip] = (size >> 11) - 1; + PRGmask4[chip] = (size >> 12) - 1; + PRGmask8[chip] = (size >> 13) - 1; + PRGmask16[chip] = (size >> 14) - 1; + PRGmask32[chip] = (size >> 15) - 1; - PRGram[chip]=ram?1:0; + PRGram[chip] = ram ? 1 : 0; } -void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram) -{ - CHRptr[chip]=p; - CHRsize[chip]=size; +void SetupCartCHRMapping(int chip, uint8 *p, uint32 size, int ram) { + CHRptr[chip] = p; + CHRsize[chip] = size; - CHRmask1[chip]=(size>>10)-1; - CHRmask2[chip]=(size>>11)-1; - CHRmask4[chip]=(size>>12)-1; - CHRmask8[chip]=(size>>13)-1; + CHRmask1[chip] = (size >> 10) - 1; + CHRmask2[chip] = (size >> 11) - 1; + CHRmask4[chip] = (size >> 12) - 1; + CHRmask8[chip] = (size >> 13) - 1; - CHRram[chip]=ram; + CHRram[chip] = ram; } -DECLFR(CartBR) -{ - return Page[A>>11][A]; +DECLFR(CartBR) { + return Page[A >> 11][A]; } -DECLFW(CartBW) -{ +DECLFW(CartBW) { //printf("Ok: %04x:%02x, %d\n",A,V,PRGIsRAM[A>>11]); - if(PRGIsRAM[A>>11] && Page[A>>11]) - Page[A>>11][A]=V; + if (PRGIsRAM[A >> 11] && Page[A >> 11]) + Page[A >> 11][A] = V; } -DECLFR(CartBROB) -{ - if(!Page[A>>11]) return(X.DB); - return Page[A>>11][A]; -} - -void setprg2r(int r, unsigned int A, unsigned int V) -{ - V&=PRGmask2[r]; - setpageptr(2,A,PRGptr[r]?(&PRGptr[r][V<<11]):0,PRGram[r]); -} - -void setprg2(uint32 A, uint32 V) -{ - setprg2r(0,A,V); -} - -void setprg4r(int r, unsigned int A, unsigned int V) -{ - V&=PRGmask4[r]; - setpageptr(4,A,PRGptr[r]?(&PRGptr[r][V<<12]):0,PRGram[r]); -} - -void setprg4(uint32 A, uint32 V) -{ - setprg4r(0,A,V); -} - -void setprg8r(int r, unsigned int A, unsigned int V) -{ - if(PRGsize[r]>=8192) - { - V&=PRGmask8[r]; - setpageptr(8,A,PRGptr[r]?(&PRGptr[r][V<<13]):0,PRGram[r]); - } +DECLFR(CartBROB) { + if (!Page[A >> 11]) + return(X.DB); else - { - uint32 VA=V<<2; + return Page[A >> 11][A]; +} + +void setprg2r(int r, uint32 A, uint32 V) { + V &= PRGmask2[r]; + setpageptr(2, A, PRGptr[r] ? (&PRGptr[r][V << 11]) : 0, PRGram[r]); +} + +void setprg2(uint32 A, uint32 V) { + setprg2r(0, A, V); +} + +void setprg4r(int r, uint32 A, uint32 V) { + V &= PRGmask4[r]; + setpageptr(4, A, PRGptr[r] ? (&PRGptr[r][V << 12]) : 0, PRGram[r]); +} + +void setprg4(uint32 A, uint32 V) { + setprg4r(0, A, V); +} + +void setprg8r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 8192) { + V &= PRGmask8[r]; + setpageptr(8, A, PRGptr[r] ? (&PRGptr[r][V << 13]) : 0, PRGram[r]); + } else { + uint32 VA = V << 2; int x; - for(x=0;x<4;x++) - setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + for (x = 0; x < 4; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); } } -void setprg8(uint32 A, uint32 V) -{ - setprg8r(0,A,V); +void setprg8(uint32 A, uint32 V) { + setprg8r(0, A, V); } -void setprg16r(int r, unsigned int A, unsigned int V) -{ - if(PRGsize[r]>=16384) - { - V&=PRGmask16[r]; - setpageptr(16,A,PRGptr[r]?(&PRGptr[r][V<<14]):0,PRGram[r]); - } - else - { - uint32 VA=V<<3; +void setprg16r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 16384) { + V &= PRGmask16[r]; + setpageptr(16, A, PRGptr[r] ? (&PRGptr[r][V << 14]) : 0, PRGram[r]); + } else { + uint32 VA = V << 3; int x; - for(x=0;x<8;x++) - setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + for (x = 0; x < 8; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); } } -void setprg16(uint32 A, uint32 V) -{ - setprg16r(0,A,V); +void setprg16(uint32 A, uint32 V) { + setprg16r(0, A, V); } -void setprg32r(int r,unsigned int A, unsigned int V) -{ - if(PRGsize[r]>=32768) - { - V&=PRGmask32[r]; - setpageptr(32,A,PRGptr[r]?(&PRGptr[r][V<<15]):0,PRGram[r]); - } - else - { - uint32 VA=V<<4; +void setprg32r(int r, uint32 A, uint32 V) { + if (PRGsize[r] >= 32768) { + V &= PRGmask32[r]; + setpageptr(32, A, PRGptr[r] ? (&PRGptr[r][V << 15]) : 0, PRGram[r]); + } else { + uint32 VA = V << 4; int x; - for(x=0;x<16;x++) - setpageptr(2,A+(x<<11),PRGptr[r]?(&PRGptr[r][((VA+x)&PRGmask2[r])<<11]):0,PRGram[r]); + for (x = 0; x < 16; x++) + setpageptr(2, A + (x << 11), PRGptr[r] ? (&PRGptr[r][((VA + x) & PRGmask2[r]) << 11]) : 0, PRGram[r]); } } -void setprg32(uint32 A, uint32 V) -{ - setprg32r(0,A,V); +void setprg32(uint32 A, uint32 V) { + setprg32r(0, A, V); } -void setchr1r(int r, unsigned int A, unsigned int V) -{ - if(!CHRptr[r]) return; +void setchr1r(int r, uint32 A, uint32 V) { + if (!CHRptr[r]) return; FCEUPPU_LineUpdate(); - V&=CHRmask1[r]; - if(CHRram[r]) - PPUCHRRAM|=(1<<(A>>10)); + V &= CHRmask1[r]; + if (CHRram[r]) + PPUCHRRAM |= (1 << (A >> 10)); else - PPUCHRRAM&=~(1<<(A>>10)); - VPageR[(A)>>10]=&CHRptr[r][(V)<<10]-(A); + PPUCHRRAM &= ~(1 << (A >> 10)); + VPageR[(A) >> 10] = &CHRptr[r][(V) << 10] - (A); } -void setchr2r(int r, unsigned int A, unsigned int V) -{ - if(!CHRptr[r]) return; +void setchr2r(int r, uint32 A, uint32 V) { + if (!CHRptr[r]) return; FCEUPPU_LineUpdate(); - V&=CHRmask2[r]; - VPageR[(A)>>10]=VPageR[((A)>>10)+1]=&CHRptr[r][(V)<<11]-(A); - if(CHRram[r]) - PPUCHRRAM|=(3<<(A>>10)); + V &= CHRmask2[r]; + VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] = &CHRptr[r][(V) << 11] - (A); + if (CHRram[r]) + PPUCHRRAM |= (3 << (A >> 10)); else - PPUCHRRAM&=~(3<<(A>>10)); + PPUCHRRAM &= ~(3 << (A >> 10)); } -void setchr4r(int r, unsigned int A, unsigned int V) -{ - if(!CHRptr[r]) return; +void setchr4r(int r, unsigned int A, unsigned int V) { + if (!CHRptr[r]) return; FCEUPPU_LineUpdate(); - V&=CHRmask4[r]; - VPageR[(A)>>10]=VPageR[((A)>>10)+1]= - VPageR[((A)>>10)+2]=VPageR[((A)>>10)+3]=&CHRptr[r][(V)<<12]-(A); - if(CHRram[r]) - PPUCHRRAM|=(15<<(A>>10)); + V &= CHRmask4[r]; + VPageR[(A) >> 10] = VPageR[((A) >> 10) + 1] = + VPageR[((A) >> 10) + 2] = VPageR[((A) >> 10) + 3] = &CHRptr[r][(V) << 12] - (A); + if (CHRram[r]) + PPUCHRRAM |= (15 << (A >> 10)); else - PPUCHRRAM&=~(15<<(A>>10)); + PPUCHRRAM &= ~(15 << (A >> 10)); } -void setchr8r(int r, unsigned int V) -{ +void setchr8r(int r, uint32 V) { int x; - if(!CHRptr[r]) return; + if (!CHRptr[r]) return; FCEUPPU_LineUpdate(); - V&=CHRmask8[r]; - for(x=7;x>=0;x--) - VPageR[x]=&CHRptr[r][V<<13]; - if(CHRram[r]) - PPUCHRRAM|=(255); + V &= CHRmask8[r]; + for (x = 7; x >= 0; x--) + VPageR[x] = &CHRptr[r][V << 13]; + if (CHRram[r]) + PPUCHRRAM |= (255); else - PPUCHRRAM=0; + PPUCHRRAM = 0; } -void setchr1(unsigned int A, unsigned int V) -{ - setchr1r(0,A,V); +void setchr1(uint32 A, uint32 V) { + setchr1r(0, A, V); } -void setchr2(unsigned int A, unsigned int V) -{ - setchr2r(0,A,V); +void setchr2(uint32 A, uint32 V) { + setchr2r(0, A, V); } -void setchr4(unsigned int A, unsigned int V) -{ - setchr4r(0,A,V); +void setchr4(uint32 A, uint32 V) { + setchr4r(0, A, V); } -void setchr8(unsigned int V) -{ - setchr8r(0,V); -} - -void setvram8(uint8 *p) -{ - int x; - for(x=7;x>=0;x--) - VPageR[x]=p; - PPUCHRRAM|=255; -} - -void setvram4(uint32 A, uint8 *p) -{ - int x; - for(x=3;x>=0;x--) - VPageR[(A>>10)+x]=p-A; - PPUCHRRAM|=(15<<(A>>10)); -} - -void setvramb1(uint8 *p, uint32 A, uint32 b) -{ - FCEUPPU_LineUpdate(); - VPageR[A>>10]=p-A+(b<<10); - PPUCHRRAM|=(1<<(A>>10)); -} - -void setvramb2(uint8 *p, uint32 A, uint32 b) -{ - FCEUPPU_LineUpdate(); - VPageR[(A>>10)]=VPageR[(A>>10)+1]=p-A+(b<<11); - PPUCHRRAM|=(3<<(A>>10)); -} - -void setvramb4(uint8 *p, uint32 A, uint32 b) -{ - int x; - - FCEUPPU_LineUpdate(); - for(x=3;x>=0;x--) - VPageR[(A>>10)+x]=p-A+(b<<12); - PPUCHRRAM|=(15<<(A>>10)); -} - -void setvramb8(uint8 *p, uint32 b) -{ - int x; - - FCEUPPU_LineUpdate(); - for(x=7;x>=0;x--) - VPageR[x]=p+(b<<13); - PPUCHRRAM|=255; +void setchr8(uint32 V) { + setchr8r(0, V); } /* This function can be called without calling SetupCartMirroring(). */ -void setntamem(uint8 *p, int ram, uint32 b) -{ +void setntamem(uint8 *p, int ram, uint32 b) { FCEUPPU_LineUpdate(); - vnapage[b]=p; - PPUNTARAM&=~(1<>2]=V;break; + case 0x8004: genieval[((A - 4) & 0xF) >> 2] = V; break; case 0x800b: case 0x8007: - case 0x8003:geniech[((A-3)&0xF)>>2]=V;break; + case 0x8003: geniech[((A - 3) & 0xF) >> 2] = V; break; case 0x800a: case 0x8006: - case 0x8002:genieaddr[((A-2)&0xF)>>2]&=0xFF00;genieaddr[((A-2)&0xF)>>2]|=V;break; + case 0x8002: genieaddr[((A - 2) & 0xF) >> 2] &= 0xFF00; genieaddr[((A - 2) & 0xF) >> 2] |= V; break; case 0x8009: case 0x8005: - case 0x8001:genieaddr[((A-1)&0xF)>>2]&=0xFF;genieaddr[((A-1)&0xF)>>2]|=(V|0x80)<<8;break; + case 0x8001: genieaddr[((A - 1) & 0xF) >> 2] &= 0xFF; genieaddr[((A - 1) & 0xF) >> 2] |= (V | 0x80) << 8; break; - case 0x8000:if(!V) - FixGenieMap(); - else - { - modcon=V^0xFF; - if(V==0x71) - modcon=0; - } - break; + case 0x8000: + if (!V) + FixGenieMap(); + else { + modcon = V ^ 0xFF; + if (V == 0x71) + modcon = 0; + } + break; } } static readfunc GenieBackup[3]; -static DECLFR(GenieFix1) -{ - uint8 r=GenieBackup[0](A); +static DECLFR(GenieFix1) { + uint8 r = GenieBackup[0](A); - if((modcon>>1)&1) // No check + if ((modcon >> 1) & 1) // No check return genieval[0]; - else if(r==geniech[0]) + else if (r == geniech[0]) return genieval[0]; return r; } -static DECLFR(GenieFix2) -{ - uint8 r=GenieBackup[1](A); +static DECLFR(GenieFix2) { + uint8 r = GenieBackup[1](A); - if((modcon>>2)&1) // No check + if ((modcon >> 2) & 1) // No check return genieval[1]; - else if(r==geniech[1]) + else if (r == geniech[1]) return genieval[1]; return r; } -static DECLFR(GenieFix3) -{ - uint8 r=GenieBackup[2](A); +static DECLFR(GenieFix3) { + uint8 r = GenieBackup[2](A); - if((modcon>>3)&1) // No check + if ((modcon >> 3) & 1) // No check return genieval[2]; - else if(r==geniech[2]) + else if (r == geniech[2]) return genieval[2]; return r; } -void FixGenieMap(void) -{ +void FixGenieMap(void) { int x; - geniestage=2; + geniestage = 2; - for(x=0;x<8;x++) - VPage[x]=VPageG[x]; + for (x = 0; x < 8; x++) + VPage[x] = VPageG[x]; - VPageR=VPage; + VPageR = VPage; FlushGenieRW(); //printf("Rightyo\n"); - for(x=0;x<3;x++) - if((modcon>>(4+x))&1) - { - readfunc tmp[3]={GenieFix1,GenieFix2,GenieFix3}; - GenieBackup[x]=GetReadHandler(genieaddr[x]); - SetReadHandler(genieaddr[x],genieaddr[x],tmp[x]); + for (x = 0; x < 3; x++) + if ((modcon >> (4 + x)) & 1) { + readfunc tmp[3] = { GenieFix1, GenieFix2, GenieFix3 }; + GenieBackup[x] = GetReadHandler(genieaddr[x]); + SetReadHandler(genieaddr[x], genieaddr[x], tmp[x]); } } -void GeniePower(void) -{ +void FCEU_GeniePower(void) { uint32 x; - if(!geniestage) + if (!geniestage) return; - geniestage=1; - for(x=0;x<3;x++) - { - genieval[x]=0xFF; - geniech[x]=0xFF; - genieaddr[x]=0xFFFF; + geniestage = 1; + for (x = 0; x < 3; x++) { + genieval[x] = 0xFF; + geniech[x] = 0xFF; + genieaddr[x] = 0xFFFF; } - modcon=0; + modcon = 0; - SetWriteHandler(0x8000,0xFFFF,GenieWrite); - SetReadHandler(0x8000,0xFFFF,GenieRead); + SetWriteHandler(0x8000, 0xFFFF, GenieWrite); + SetReadHandler(0x8000, 0xFFFF, GenieRead); - for(x=0;x<8;x++) - VPage[x]=GENIEROM+4096-0x400*x; + for (x = 0; x < 8; x++) + VPage[x] = GENIEROM + 4096 - 0x400 * x; - if(AllocGenieRW()) - VPageR=VPageG; + if (AllocGenieRW()) + VPageR = VPageG; else - geniestage=2; + geniestage = 2; } -void FCEU_SaveGameSave(CartInfo *LocalHWInfo) -{ - if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) - { +void FCEU_SaveGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { FILE *sp; - std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); - if((sp=FCEUD_UTF8fopen(soot,"wb"))==NULL) - { - FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n",soot.c_str()); - } - else - { - for(int x=0;x<4;x++) - if(LocalHWInfo->SaveGame[x]) - { - fwrite(LocalHWInfo->SaveGame[x],1, - LocalHWInfo->SaveGameLen[x],sp); + std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); + if ((sp = FCEUD_UTF8fopen(soot, "wb")) == NULL) { + FCEU_PrintError("WRAM file \"%s\" cannot be written to.\n", soot.c_str()); + } else { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) { + fwrite(LocalHWInfo->SaveGame[x], 1, + LocalHWInfo->SaveGameLen[x], sp); } } } } // hack, movie.cpp has to communicate with this function somehow -int disableBatteryLoading=0; +int disableBatteryLoading = 0; -void FCEU_LoadGameSave(CartInfo *LocalHWInfo) -{ - if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) - { +void FCEU_LoadGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0] && !disableBatteryLoading) { FILE *sp; - std::string soot = FCEU_MakeFName(FCEUMKF_SAV,0,"sav"); - sp=FCEUD_UTF8fopen(soot,"rb"); - if(sp!=NULL) - { - for(int x=0;x<4;x++) - if(LocalHWInfo->SaveGame[x]) - fread(LocalHWInfo->SaveGame[x],1,LocalHWInfo->SaveGameLen[x],sp); + std::string soot = FCEU_MakeFName(FCEUMKF_SAV, 0, "sav"); + sp = FCEUD_UTF8fopen(soot, "rb"); + if (sp != NULL) { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) + fread(LocalHWInfo->SaveGame[x], 1, LocalHWInfo->SaveGameLen[x], sp); } } } //clears all save memory. call this if you want to pretend the saveram has been reset (it doesnt touch what is on disk though) -void FCEU_ClearGameSave(CartInfo *LocalHWInfo) -{ - if(LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) - { - for(int x=0;x<4;x++) - if(LocalHWInfo->SaveGame[x]) - memset(LocalHWInfo->SaveGame[x],0,LocalHWInfo->SaveGameLen[x]); +void FCEU_ClearGameSave(CartInfo *LocalHWInfo) { + if (LocalHWInfo->battery && LocalHWInfo->SaveGame[0]) { + for (int x = 0; x < 4; x++) + if (LocalHWInfo->SaveGame[x]) + memset(LocalHWInfo->SaveGame[x], 0, LocalHWInfo->SaveGameLen[x]); } } diff --git a/src/cart.h b/src/cart.h index 524715da..92d53659 100644 --- a/src/cart.h +++ b/src/cart.h @@ -1,31 +1,29 @@ typedef struct { - /* Set by mapper/board code: */ - void (*Power)(void); - void (*Reset)(void); - void (*Close)(void); - uint8 *SaveGame[4]; /* Pointers to memory to save/load. */ - uint32 SaveGameLen[4]; /* How much memory to save/load. */ + // Set by mapper/board code: + void (*Power)(void); + void (*Reset)(void); + void (*Close)(void); + uint8 *SaveGame[4]; // Pointers to memory to save/load. + uint32 SaveGameLen[4]; // How much memory to save/load. - /* Set by iNES/UNIF loading code. */ - int mirror; /* As set in the header or chunk. - iNES/UNIF specific. Intended - to help support games like "Karnov" - that are not really MMC3 but are - set to mapper 4. - */ - int battery; /* Presence of an actual battery. */ - uint8 MD5[16]; - uint32 CRC32; /* Should be set by the iNES/UNIF loading - code, used by mapper/board code, maybe - other code in the future. - */ + // Set by iNES/UNIF loading code. + int mirror; // As set in the header or chunk. + // iNES/UNIF specific. Intended + // to help support games like "Karnov" + // that are not really MMC3 but are + // set to mapper 4. + int battery; // Presence of an actual battery. + uint8 MD5[16]; + uint32 CRC32; // Should be set by the iNES/UNIF loading + // code, used by mapper/board code, maybe + // other code in the future. } CartInfo; void FCEU_SaveGameSave(CartInfo *LocalHWInfo); void FCEU_LoadGameSave(CartInfo *LocalHWInfo); void FCEU_ClearGameSave(CartInfo *LocalHWInfo); -extern uint8 *Page[32],*VPage[8],*MMC5SPRVPage[8],*MMC5BGVPage[8]; +extern uint8 *Page[32], *VPage[8], *MMC5SPRVPage[8], *MMC5BGVPage[8]; void ResetCartMapping(void); void SetupCartPRGMapping(int chip, uint8 *p, uint32 size, int ram); @@ -75,14 +73,6 @@ void setchr2(unsigned int A, unsigned int V); void setchr4(unsigned int A, unsigned int V); void setchr8(unsigned int V); -void setvram4(uint32 A, uint8 *p); -void setvram8(uint8 *p); - -void setvramb1(uint8 *p, uint32 A, uint32 b); -void setvramb2(uint8 *p, uint32 A, uint32 b); -void setvramb4(uint8 *p, uint32 A, uint32 b); -void setvramb8(uint8 *p, uint32 b); - void setmirror(int t); void setmirrorw(int a, int b, int c, int d); void setntamem(uint8 *p, int ram, uint32 b); @@ -94,8 +84,8 @@ void setntamem(uint8 *p, int ram, uint32 b); extern int geniestage; -void GeniePower(void); +void FCEU_GeniePower(void); -void OpenGenie(void); -void CloseGenie(void); +void FCEU_OpenGenie(void); +void FCEU_CloseGenie(void); void FCEU_KillGenie(void); diff --git a/src/fceu.cpp b/src/fceu.cpp index bfe1af64..5064c909 100644 --- a/src/fceu.cpp +++ b/src/fceu.cpp @@ -84,52 +84,42 @@ using namespace std; int AFon = 1, AFoff = 1, AutoFireOffset = 0; //For keeping track of autofire settings bool justLagged = false; bool frameAdvanceLagSkip = false; //If this is true, frame advance will skip over lag frame (i.e. it will emulate 2 frames instead of 1) -bool AutoSS = false; //Flagged true when the first auto-savestate is made while a game is loaded, flagged false on game close +bool AutoSS = false; //Flagged true when the first auto-savestate is made while a game is loaded, flagged false on game close bool movieSubtitles = true; //Toggle for displaying movie subtitles bool DebuggerWasUpdated = false; //To prevent the debugger from updating things without being updated. FCEUGI::FCEUGI() -: filename(0) -, archiveFilename(0) -{ + : filename(0) + , archiveFilename(0) { //printf("%08x",opsize); // WTF?! } -FCEUGI::~FCEUGI() -{ - if(filename) delete filename; - if(archiveFilename) delete archiveFilename; +FCEUGI::~FCEUGI() { + if (filename) delete filename; + if (archiveFilename) delete archiveFilename; } -bool CheckFileExists(const char* filename) -{ +bool CheckFileExists(const char* filename) { //This function simply checks to see if the given filename exists if (!filename) return false; fstream test; - test.open(filename,fstream::in); + test.open(filename, fstream::in); - if (test.fail()) - { + if (test.fail()) { test.close(); return false; - } - else - { + } else { test.close(); return true; } } -void FCEU_TogglePPU(void) -{ +void FCEU_TogglePPU(void) { newppu ^= 1; - if (newppu) - { + if (newppu) { FCEU_DispMessage("New PPU loaded", 0); FCEUI_printf("New PPU loaded"); - } - else - { + } else { FCEU_DispMessage("Old PPU loaded", 0); FCEUI_printf("Old PPU loaded"); } @@ -138,49 +128,42 @@ void FCEU_TogglePPU(void) #endif } -static void FCEU_CloseGame(void) -{ - if(GameInfo) - { - +static void FCEU_CloseGame(void) { + if (GameInfo) { #ifdef WIN32 //SP CODE - extern char LoadedRomFName[2048]; + extern char LoadedRomFName[2048]; - if (storePreferences(LoadedRomFName)) - { - FCEUD_PrintError("Couldn't store debugging data"); - } + if (storePreferences(LoadedRomFName)) { + FCEUD_PrintError("Couldn't store debugging data"); + } #endif - if(FCEUnetplay) - { + if (FCEUnetplay) { FCEUD_NetworkClose(); } - if(GameInfo->name) - { + if (GameInfo->name) { free(GameInfo->name); - GameInfo->name=0; + GameInfo->name = 0; } - if(GameInfo->type!=GIT_NSF) - { - FCEU_FlushGameCheats(0,0); + if (GameInfo->type != GIT_NSF) { + FCEU_FlushGameCheats(0, 0); } GameInterface(GI_CLOSE); FCEUI_StopMovie(); - ResetExState(0,0); + ResetExState(0, 0); //clear screen when game is closed extern uint8 *XBuf; - if(XBuf) - memset(XBuf,0,256*256); + if (XBuf) + memset(XBuf, 0, 256 * 256); - CloseGenie(); + FCEU_CloseGenie(); delete GameInfo; GameInfo = NULL; @@ -211,13 +194,13 @@ readfunc ARead[0x10000]; writefunc BWrite[0x10000]; static readfunc *AReadG; static writefunc *BWriteG; -static int RWWrap=0; +static int RWWrap = 0; //mbg merge 7/18/06 docs //bit0 indicates whether emulation is paused //bit1 indicates whether emulation is in frame step mode -int EmulationPaused=0; -bool frameAdvanceRequested=false; +int EmulationPaused = 0; +bool frameAdvanceRequested = false; int frameAdvanceDelay; //indicates that the emulation core just frame advanced (consumed the frame advance state and paused) @@ -232,100 +215,88 @@ int AutosaveFrequency = 256; // Number of frames between autosaves int EnableAutosave = 0; ///a wrapper for unzip.c -extern "C" FILE *FCEUI_UTF8fopen_C(const char *n, const char *m) { return ::FCEUD_UTF8fopen(n,m); } - -static DECLFW(BNull) -{ - +extern "C" FILE *FCEUI_UTF8fopen_C(const char *n, const char *m) { + return ::FCEUD_UTF8fopen(n, m); } -static DECLFR(ANull) -{ +static DECLFW(BNull) { +} + +static DECLFR(ANull) { return(X.DB); } -int AllocGenieRW(void) -{ - if(!(AReadG=(readfunc *)FCEU_malloc(0x8000*sizeof(readfunc)))) +int AllocGenieRW(void) { + if (!(AReadG = (readfunc*)FCEU_malloc(0x8000 * sizeof(readfunc)))) return 0; - if(!(BWriteG=(writefunc *)FCEU_malloc(0x8000*sizeof(writefunc)))) + if (!(BWriteG = (writefunc*)FCEU_malloc(0x8000 * sizeof(writefunc)))) return 0; - RWWrap=1; + RWWrap = 1; return 1; } -void FlushGenieRW(void) -{ +void FlushGenieRW(void) { int32 x; - if(RWWrap) - { - for(x=0;x<0x8000;x++) - { - ARead[x+0x8000]=AReadG[x]; - BWrite[x+0x8000]=BWriteG[x]; + if (RWWrap) { + for (x = 0; x < 0x8000; x++) { + ARead[x + 0x8000] = AReadG[x]; + BWrite[x + 0x8000] = BWriteG[x]; } free(AReadG); free(BWriteG); - AReadG=0; - BWriteG=0; - RWWrap=0; + AReadG = 0; + BWriteG = 0; + RWWrap = 0; } } -readfunc GetReadHandler(int32 a) -{ - if(a>=0x8000 && RWWrap) - return AReadG[a-0x8000]; +readfunc GetReadHandler(int32 a) { + if (a >= 0x8000 && RWWrap) + return AReadG[a - 0x8000]; else return ARead[a]; } -void SetReadHandler(int32 start, int32 end, readfunc func) -{ +void SetReadHandler(int32 start, int32 end, readfunc func) { int32 x; - if(!func) - func=ANull; + if (!func) + func = ANull; - if(RWWrap) - for(x=end;x>=start;x--) - { - if(x>=0x8000) - AReadG[x-0x8000]=func; + if (RWWrap) + for (x = end; x >= start; x--) { + if (x >= 0x8000) + AReadG[x - 0x8000] = func; else - ARead[x]=func; + ARead[x] = func; } else - - for(x=end;x>=start;x--) - ARead[x]=func; + for (x = end; x >= start; x--) + ARead[x] = func; } -writefunc GetWriteHandler(int32 a) -{ - if(RWWrap && a>=0x8000) - return BWriteG[a-0x8000]; +writefunc GetWriteHandler(int32 a) { + if (RWWrap && a >= 0x8000) + return BWriteG[a - 0x8000]; else return BWrite[a]; } -void SetWriteHandler(int32 start, int32 end, writefunc func) -{ +void SetWriteHandler(int32 start, int32 end, writefunc func) { int32 x; - if(!func) - func=BNull; + if (!func) + func = BNull; - if(RWWrap) - for(x=end;x>=start;x--) - { - if(x>=0x8000) - BWriteG[x-0x8000]=func; + if (RWWrap) + for (x = end; x >= start; x--) { + if (x >= 0x8000) + BWriteG[x - 0x8000] = func; else - BWrite[x]=func; + BWrite[x] = func; } else - for(x=end;x>=start;x--) - BWrite[x]=func; + for (x = end; x >= start; x--) + BWrite[x] = func; } uint8 *GameMemBlock; @@ -334,64 +305,57 @@ uint8 *RAM; //--------- //windows might need to allocate these differently, so we have some special code -static void AllocBuffers() -{ +static void AllocBuffers() { GameMemBlock = (uint8*)FCEU_gmalloc(GAME_MEM_BLOCK_SIZE); RAM = (uint8*)FCEU_gmalloc(0x800); } -static void FreeBuffers() -{ +static void FreeBuffers() { FCEU_free(GameMemBlock); FCEU_free(RAM); } //------ -uint8 PAL=0; +uint8 PAL = 0; -static DECLFW(BRAML) -{ - RAM[A]=V; +static DECLFW(BRAML) { + RAM[A] = V; #ifdef _S9XLUA_H CallRegisteredLuaMemHook(A, 1, V, LUAMEMHOOK_WRITE); #endif } -static DECLFW(BRAMH) -{ - RAM[A&0x7FF]=V; +static DECLFW(BRAMH) { + RAM[A & 0x7FF] = V; #ifdef _S9XLUA_H - CallRegisteredLuaMemHook(A&0x7FF, 1, V, LUAMEMHOOK_WRITE); + CallRegisteredLuaMemHook(A & 0x7FF, 1, V, LUAMEMHOOK_WRITE); #endif } -static DECLFR(ARAML) -{ +static DECLFR(ARAML) { return RAM[A]; } -static DECLFR(ARAMH) -{ - return RAM[A&0x7FF]; +static DECLFR(ARAMH) { + return RAM[A & 0x7FF]; } -void ResetGameLoaded(void) -{ - if(GameInfo) FCEU_CloseGame(); +void ResetGameLoaded(void) { + if (GameInfo) FCEU_CloseGame(); EmulationPaused = 0; //mbg 5/8/08 - loading games while paused was bad news. maybe this fixes it - GameStateRestore=0; - PPU_hook=0; - GameHBIRQHook=0; + GameStateRestore = 0; + PPU_hook = 0; + GameHBIRQHook = 0; FFCEUX_PPURead = 0; FFCEUX_PPUWrite = 0; - if(GameExpSound.Kill) + if (GameExpSound.Kill) GameExpSound.Kill(); - memset(&GameExpSound,0,sizeof(GameExpSound)); - MapIRQHook=0; - MMC5Hack=0; - PAL&=1; - pale=0; + memset(&GameExpSound, 0, sizeof(GameExpSound)); + MapIRQHook = 0; + MMC5Hack = 0; + PAL &= 1; + pale = 0; } int UNIFLoad(const char *name, FCEUFILE *fp); @@ -402,8 +366,7 @@ int NSFLoad(const char *name, FCEUFILE *fp); //char lastLoadedGameName [2048] = {0,}; // hack for movie WRAM clearing on record from poweron //name should be UTF-8, hopefully, or else there may be trouble -FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) -{ +FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) { //mbg merge 7/17/07 - why is this here //#ifdef WIN32 // StopSound(); @@ -413,13 +376,13 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) //attempt to open the files FCEUFILE *fp; - FCEU_printf("Loading %s...\n\n",name); + FCEU_printf("Loading %s...\n\n", name); - const char* romextensions[] = {"nes","fds",0}; - fp=FCEU_fopen(name,0,"rb",0,-1,romextensions); + const char* romextensions[] = { "nes", "fds", 0 }; + fp = FCEU_fopen(name, 0, "rb", 0, -1, romextensions); - if(!fp) { - FCEU_PrintError("Error opening \"%s\"!",name); + if (!fp) { + FCEU_PrintError("Error opening \"%s\"!", name); return 0; } @@ -434,8 +397,8 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) MasterRomInfoParams = TMasterRomInfoParams(); if (!AutosaveStatus) - AutosaveStatus = (int*)FCEU_dmalloc(sizeof(int)*AutosaveQty); - for (AutosaveIndex=0; AutosaveIndexfilename = strdup(fp->filename.c_str()); - if(fp->archiveFilename != "") GameInfo->archiveFilename = strdup(fp->archiveFilename.c_str()); + if (fp->archiveFilename != "") GameInfo->archiveFilename = strdup(fp->archiveFilename.c_str()); GameInfo->archiveCount = fp->archiveCount; GameInfo->soundchan = 0; GameInfo->soundrate = 0; - GameInfo->name=0; - GameInfo->type=GIT_CART; - GameInfo->vidsys=GIV_USER; - GameInfo->input[0]=GameInfo->input[1]=SI_UNSET; - GameInfo->inputfc=SIFC_UNSET; - GameInfo->cspecial=SIS_NONE; + GameInfo->name = 0; + GameInfo->type = GIT_CART; + GameInfo->vidsys = GIV_USER; + GameInfo->input[0] = GameInfo->input[1] = SI_UNSET; + GameInfo->inputfc = SIFC_UNSET; + GameInfo->cspecial = SIS_NONE; //try to load each different format - bool FCEUXLoad(const char *name, FCEUFILE *fp); + bool FCEUXLoad(const char *name, FCEUFILE * fp); /*if(FCEUXLoad(name,fp)) - goto endlseq;*/ - if(iNESLoad(name,fp,OverwriteVidMode)) + goto endlseq;*/ + if (iNESLoad(name, fp, OverwriteVidMode)) goto endlseq; - if(NSFLoad(name,fp)) + if (NSFLoad(name, fp)) goto endlseq; - if(UNIFLoad(name,fp)) + if (UNIFLoad(name, fp)) goto endlseq; - if(FDSLoad(name,fp)) + if (FDSLoad(name, fp)) goto endlseq; FCEU_PrintError("An error occurred while loading the file."); @@ -476,35 +439,35 @@ FCEUGI *FCEUI_LoadGameVirtual(const char *name, int OverwriteVidMode) return 0; -endlseq: + endlseq: FCEU_fclose(fp); #ifdef WIN32 // ################################## Start of SP CODE ########################### - extern char LoadedRomFName[2048]; - extern int loadDebugDataFailed; + extern char LoadedRomFName[2048]; + extern int loadDebugDataFailed; - if ((loadDebugDataFailed = loadPreferences(LoadedRomFName))) - FCEU_printf("Couldn't load debugging data.\n"); + if ((loadDebugDataFailed = loadPreferences(LoadedRomFName))) + FCEU_printf("Couldn't load debugging data.\n"); // ################################## End of SP CODE ########################### #endif FCEU_ResetVidSys(); - if(GameInfo->type!=GIT_NSF) - if(FSettings.GameGenie) - OpenGenie(); + if (GameInfo->type != GIT_NSF) + if (FSettings.GameGenie) + FCEU_OpenGenie(); PowerNES(); - if(GameInfo->type!=GIT_NSF) + if (GameInfo->type != GIT_NSF) FCEU_LoadGamePalette(); FCEU_ResetPalette(); - FCEU_ResetMessages(); // Save state, status messages, etc. + FCEU_ResetMessages(); // Save state, status messages, etc. - if(GameInfo->type!=GIT_NSF) + if (GameInfo->type != GIT_NSF) FCEU_LoadGameCheats(0); #if defined (WIN32) || defined (WIN64) @@ -516,19 +479,16 @@ endlseq: return GameInfo; } -FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode) -{ - return FCEUI_LoadGameVirtual(name,OverwriteVidMode); +FCEUGI *FCEUI_LoadGame(const char *name, int OverwriteVidMode) { + return FCEUI_LoadGameVirtual(name, OverwriteVidMode); } //Return: Flag that indicates whether the function was succesful or not. -bool FCEUI_Initialize() -{ +bool FCEUI_Initialize() { srand(time(0)); - if(!FCEU_InitVirtualVideo()) - { + if (!FCEU_InitVirtualVideo()) { return false; } @@ -537,19 +497,19 @@ bool FCEUI_Initialize() // Initialize some parts of the settings structure //mbg 5/7/08 - I changed the ntsc settings to match pal. //this is more for precision emulation, instead of entertainment, which is what fceux is all about nowadays - memset(&FSettings,0,sizeof(FSettings)); + memset(&FSettings, 0, sizeof(FSettings)); //FSettings.UsrFirstSLine[0]=8; - FSettings.UsrFirstSLine[0]=0; - FSettings.UsrFirstSLine[1]=0; + FSettings.UsrFirstSLine[0] = 0; + FSettings.UsrFirstSLine[1] = 0; //FSettings.UsrLastSLine[0]=231; - FSettings.UsrLastSLine[0]=239; - FSettings.UsrLastSLine[1]=239; - FSettings.SoundVolume=150; //0-150 scale - FSettings.TriangleVolume=256; //0-256 scale (256 is max volume) - FSettings.Square1Volume=256; //0-256 scale (256 is max volume) - FSettings.Square2Volume=256; //0-256 scale (256 is max volume) - FSettings.NoiseVolume=256; //0-256 scale (256 is max volume) - FSettings.PCMVolume=256; //0-256 scale (256 is max volume) + FSettings.UsrLastSLine[0] = 239; + FSettings.UsrLastSLine[1] = 239; + FSettings.SoundVolume = 150; //0-150 scale + FSettings.TriangleVolume = 256; //0-256 scale (256 is max volume) + FSettings.Square1Volume = 256; //0-256 scale (256 is max volume) + FSettings.Square2Volume = 256; //0-256 scale (256 is max volume) + FSettings.NoiseVolume = 256; //0-256 scale (256 is max volume) + FSettings.PCMVolume = 256; //0-256 scale (256 is max volume) FCEUPPU_Init(); @@ -558,8 +518,7 @@ bool FCEUI_Initialize() return true; } -void FCEUI_Kill(void) -{ +void FCEUI_Kill(void) { #ifdef _S9XLUA_H FCEU_LuaStop(); #endif @@ -569,55 +528,42 @@ void FCEUI_Kill(void) } int rapidAlternator = 0; -int AutoFirePattern[8] = {1,0,0,0,0,0,0,0}; +int AutoFirePattern[8] = { 1, 0, 0, 0, 0, 0, 0, 0 }; int AutoFirePatternLength = 2; -void SetAutoFirePattern(int onframes, int offframes) -{ +void SetAutoFirePattern(int onframes, int offframes) { int i; - for(i = 0; i < onframes && i < 8; i++) - { + for (i = 0; i < onframes && i < 8; i++) { AutoFirePattern[i] = 1; } - for(;i < 8; i++) - { + for (; i < 8; i++) { AutoFirePattern[i] = 0; } - if(onframes + offframes < 2) - { + if (onframes + offframes < 2) { AutoFirePatternLength = 2; - } - else if(onframes + offframes > 8) - { + } else if (onframes + offframes > 8) { AutoFirePatternLength = 8; - } - else - { + } else { AutoFirePatternLength = onframes + offframes; } AFon = onframes; AFoff = offframes; } -void SetAutoFireOffset(int offset) -{ - if(offset < 0 || offset > 8) return; +void SetAutoFireOffset(int offset) { + if (offset < 0 || offset > 8) return; AutoFireOffset = offset; } -void AutoFire(void) -{ +void AutoFire(void) { static int counter = 0; if (justLagged == false) - counter = (counter + 1) % (8*7*5*3); + counter = (counter + 1) % (8 * 7 * 5 * 3); //If recording a movie, use the frame # for the autofire so the offset //doesn't get screwed up when loading. - if(FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY)) - { - rapidAlternator= AutoFirePattern[(AutoFireOffset + FCEUMOV_GetFrame())%AutoFirePatternLength]; //adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire? - } - else - { - rapidAlternator= AutoFirePattern[(AutoFireOffset + counter)%AutoFirePatternLength]; + if (FCEUMOV_Mode(MOVIEMODE_RECORD | MOVIEMODE_PLAY)) { + rapidAlternator = AutoFirePattern[(AutoFireOffset + FCEUMOV_GetFrame()) % AutoFirePatternLength]; //adelikat: TODO: Think through this, MOVIEMODE_FINISHED should not use movie data for auto-fire? + } else { + rapidAlternator = AutoFirePattern[(AutoFireOffset + counter) % AutoFirePatternLength]; } } @@ -626,30 +572,27 @@ void UpdateAutosave(void); ///Emulates a single frame. ///Skip may be passed in, if FRAMESKIP is #defined, to cause this to emulate more than one frame -void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int skip) -{ +void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int skip) { //skip initiates frame skip if 1, or frame skip and sound skip if 2 - int r,ssize; + int r, ssize; JustFrameAdvanced = false; - if (frameAdvanceRequested) - { - if (frameAdvanceDelay==0 || frameAdvanceDelay>=10) + if (frameAdvanceRequested) { + if (frameAdvanceDelay == 0 || frameAdvanceDelay >= 10) EmulationPaused = 3; - if (frameAdvanceDelay==0 || frameAdvanceDelay < 10) + if (frameAdvanceDelay == 0 || frameAdvanceDelay < 10) frameAdvanceDelay++; } - if(EmulationPaused&2) + if (EmulationPaused & 2) EmulationPaused &= ~1; // clear paused flag temporarily (frame advance) - else if((EmulationPaused&1)) - { - memcpy(XBuf, XBackBuf, 256*256); + else if ((EmulationPaused & 1)) { + memcpy(XBuf, XBackBuf, 256 * 256); FCEU_PutImage(); - *pXBuf=XBuf; - *SoundBuf=WaveFinal; - *SoundBufSize=0; + *pXBuf = XBuf; + *SoundBuf = WaveFinal; + *SoundBufSize = 0; return; } @@ -668,10 +611,10 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski CallRegisteredLuaFunctions(LUACALL_BEFOREEMULATION); #endif - if(geniestage!=1) FCEU_ApplyPeriodicCheats(); + if (geniestage != 1) FCEU_ApplyPeriodicCheats(); r = FCEUPPU_Loop(skip); - if (skip != 2) ssize=FlushEmulateSound(); //If skip = 2 we are skipping sound processing + if (skip != 2) ssize = FlushEmulateSound(); //If skip = 2 we are skipping sound processing #ifdef _S9XLUA_H CallRegisteredLuaFunctions(LUACALL_AFTEREMULATION); @@ -692,53 +635,44 @@ void FCEUI_Emulate(uint8 **pXBuf, int32 **SoundBuf, int32 *SoundBufSize, int ski timestampbase += timestamp; timestamp = 0; - *pXBuf=skip?0:XBuf; - if (skip == 2) //If skip = 2, then bypass sound - { - *SoundBuf=0; - *SoundBufSize=0; - } - else - { - *SoundBuf=WaveFinal; - *SoundBufSize=ssize; + *pXBuf = skip ? 0 : XBuf; + if (skip == 2) { //If skip = 2, then bypass sound + *SoundBuf = 0; + *SoundBufSize = 0; + } else { + *SoundBuf = WaveFinal; + *SoundBufSize = ssize; } - if (EmulationPaused&2 && ( !frameAdvanceLagSkip || !lagFlag) ) - //Lots of conditions here. EmulationPaused&2 must be true. In addition frameAdvanceLagSkip or lagFlag must be false - { - EmulationPaused = 1; // restore paused flag + if (EmulationPaused & 2 && (!frameAdvanceLagSkip || !lagFlag)) { + //Lots of conditions here. EmulationPaused&2 must be true. In addition frameAdvanceLagSkip or lagFlag must be false + EmulationPaused = 1; // restore paused flag JustFrameAdvanced = true; #ifdef WIN32 - if(soundoptions&SO_MUTEFA) //mute the frame advance if the user requested it - *SoundBufSize=0; //keep sound muted + if (soundoptions & SO_MUTEFA) //mute the frame advance if the user requested it + *SoundBufSize = 0; //keep sound muted #endif - } - if (lagFlag) - { + if (lagFlag) { lagCounter++; justLagged = true; - } - else justLagged = false; + } else justLagged = false; if (movieSubtitles) ProcessSubtitles(); } -void FCEUI_CloseGame(void) -{ - if(!FCEU_IsValidUI(FCEUI_CLOSEGAME)) +void FCEUI_CloseGame(void) { + if (!FCEU_IsValidUI(FCEUI_CLOSEGAME)) return; FCEU_CloseGame(); } -void ResetNES(void) -{ +void ResetNES(void) { FCEUMOV_AddCommand(FCEUNPCMD_RESET); - if(!GameInfo) return; + if (!GameInfo) return; GameInterface(GI_RESETM2); FCEUSND_Reset(); FCEUPPU_Reset(); @@ -746,16 +680,14 @@ void ResetNES(void) // clear back baffer extern uint8 *XBackBuf; - memset(XBackBuf,0,256*256); + memset(XBackBuf, 0, 256 * 256); FCEU_DispMessage("Reset", 0); } -void FCEU_MemoryRand(uint8 *ptr, uint32 size) -{ - int x=0; - while(size) - { +void FCEU_MemoryRand(uint8 *ptr, uint32 size) { + int x = 0; + while (size) { *ptr = (x & 4) ? 0xFF : 0x00; // Huang Di DEBUG MODE enabled by default // Cybernoid NO MUSIC by default // *ptr = (x & 4) ? 0x7F : 0x00; // Huang Di DEBUG MODE enabled by default @@ -770,26 +702,17 @@ void FCEU_MemoryRand(uint8 *ptr, uint32 size) } } -void hand(X6502 *X, int type, unsigned int A) -{ - +void hand(X6502 *X, int type, uint32 A) { } -//int suppressAddPowerCommand=0; // hack... yeah, I know... -void PowerNES(void) -{ - //void MapperInit(); - //MapperInit(); - - //if(!suppressAddPowerCommand) - FCEUMOV_AddCommand(FCEUNPCMD_POWER); - - if(!GameInfo) return; +void PowerNES(void) { + FCEUMOV_AddCommand(FCEUNPCMD_POWER); + if (!GameInfo) return; FCEU_CheatResetRAM(); - FCEU_CheatAddRAM(2,0,RAM); + FCEU_CheatAddRAM(2, 0, RAM); - GeniePower(); + FCEU_GeniePower(); //dont do this, it breaks some games: Cybernoid; Minna no Taabou no Nakayoshi Daisakusen; and maybe mechanized attack //memset(RAM,0xFF,0x800); @@ -798,16 +721,16 @@ void PowerNES(void) //this should work better, based on observational evidence. fixes all of the above: //for(int i=0;i<0x800;i++) if(i&1) RAM[i] = 0xAA; else RAM[i] = 0x55; //but we're leaving this for now until we collect some more data - FCEU_MemoryRand(RAM,0x800); + FCEU_MemoryRand(RAM, 0x800); - SetReadHandler(0x0000,0xFFFF,ANull); - SetWriteHandler(0x0000,0xFFFF,BNull); + SetReadHandler(0x0000, 0xFFFF, ANull); + SetWriteHandler(0x0000, 0xFFFF, BNull); - SetReadHandler(0,0x7FF,ARAML); - SetWriteHandler(0,0x7FF,BRAML); + SetReadHandler(0, 0x7FF, ARAML); + SetWriteHandler(0, 0x7FF, BRAML); - SetReadHandler(0x800,0x1FFF,ARAMH); // Part of a little - SetWriteHandler(0x800,0x1FFF,BRAMH); //hack for a small speed boost. + SetReadHandler(0x800, 0x1FFF, ARAMH); // Part of a little + SetWriteHandler(0x800, 0x1FFF, BRAMH); //hack for a small speed boost. InitializeInput(); FCEUSND_Power(); @@ -815,12 +738,12 @@ void PowerNES(void) //Have the external game hardware "powered" after the internal NES stuff. Needed for the NSF code and VS System code. GameInterface(GI_POWER); - if(GameInfo->type==GIT_VSUNI) + if (GameInfo->type == GIT_VSUNI) FCEU_VSUniPower(); //if we are in a movie, then reset the saveram extern int disableBatteryLoading; - if(disableBatteryLoading) + if (disableBatteryLoading) GameInterface(GI_RESETSAVE); timestampbase = 0; @@ -832,7 +755,7 @@ void PowerNES(void) LagCounterReset(); // clear back baffer extern uint8 *XBackBuf; - memset(XBackBuf,0,256*256); + memset(XBackBuf, 0, 256 * 256); #ifdef WIN32 Update_RAM_Search(); // Update_RAM_Watch() is also called. @@ -841,92 +764,80 @@ void PowerNES(void) FCEU_DispMessage("Power on", 0); } -void FCEU_ResetVidSys(void) -{ +void FCEU_ResetVidSys(void) { int w; - if(GameInfo->vidsys==GIV_NTSC) - w=0; - else if(GameInfo->vidsys==GIV_PAL) - w=1; + if (GameInfo->vidsys == GIV_NTSC) + w = 0; + else if (GameInfo->vidsys == GIV_PAL) + w = 1; else - w=FSettings.PAL; + w = FSettings.PAL; - PAL=w?1:0; + PAL = w ? 1 : 0; FCEUPPU_SetVideoSystem(w); SetSoundVariables(); } FCEUS FSettings; -void FCEU_printf(char *format, ...) -{ +void FCEU_printf(char *format, ...) { char temp[2048]; va_list ap; - va_start(ap,format); - vsnprintf(temp,sizeof(temp),format,ap); + va_start(ap, format); + vsnprintf(temp, sizeof(temp), format, ap); FCEUD_Message(temp); va_end(ap); } -void FCEU_PrintError(char *format, ...) -{ +void FCEU_PrintError(char *format, ...) { char temp[2048]; va_list ap; - va_start(ap,format); - vsnprintf(temp,sizeof(temp),format,ap); + va_start(ap, format); + vsnprintf(temp, sizeof(temp), format, ap); FCEUD_PrintError(temp); va_end(ap); } -void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) -{ - FSettings.UsrFirstSLine[0]=ntscf; - FSettings.UsrLastSLine[0]=ntscl; - FSettings.UsrFirstSLine[1]=palf; - FSettings.UsrLastSLine[1]=pall; - if(PAL) - { - FSettings.FirstSLine=FSettings.UsrFirstSLine[1]; - FSettings.LastSLine=FSettings.UsrLastSLine[1]; +void FCEUI_SetRenderedLines(int ntscf, int ntscl, int palf, int pall) { + FSettings.UsrFirstSLine[0] = ntscf; + FSettings.UsrLastSLine[0] = ntscl; + FSettings.UsrFirstSLine[1] = palf; + FSettings.UsrLastSLine[1] = pall; + if (PAL) { + FSettings.FirstSLine = FSettings.UsrFirstSLine[1]; + FSettings.LastSLine = FSettings.UsrLastSLine[1]; + } else { + FSettings.FirstSLine = FSettings.UsrFirstSLine[0]; + FSettings.LastSLine = FSettings.UsrLastSLine[0]; } - else - { - FSettings.FirstSLine=FSettings.UsrFirstSLine[0]; - FSettings.LastSLine=FSettings.UsrLastSLine[0]; - } - } -void FCEUI_SetVidSystem(int a) -{ - FSettings.PAL=a?1:0; - if(GameInfo) - { +void FCEUI_SetVidSystem(int a) { + FSettings.PAL = a ? 1 : 0; + if (GameInfo) { FCEU_ResetVidSys(); FCEU_ResetPalette(); FCEUD_VideoChanged(); } } -int FCEUI_GetCurrentVidSystem(int *slstart, int *slend) -{ - if(slstart) - *slstart=FSettings.FirstSLine; - if(slend) - *slend=FSettings.LastSLine; +int FCEUI_GetCurrentVidSystem(int *slstart, int *slend) { + if (slstart) + *slstart = FSettings.FirstSLine; + if (slend) + *slend = FSettings.LastSLine; return(PAL); } //Enable or disable Game Genie option. -void FCEUI_SetGameGenie(bool a) -{ +void FCEUI_SetGameGenie(bool a) { FSettings.GameGenie = a; } @@ -936,89 +847,76 @@ void FCEUI_SetGameGenie(bool a) // FSettings.SnapName = a; //} -int32 FCEUI_GetDesiredFPS(void) -{ - if(PAL) - return(838977920); // ~50.007 +int32 FCEUI_GetDesiredFPS(void) { + if (PAL) + return(838977920); // ~50.007 else - return(1008307711); // ~60.1 + return(1008307711); // ~60.1 } -int FCEUI_EmulationPaused(void) -{ - return (EmulationPaused&1); +int FCEUI_EmulationPaused(void) { + return(EmulationPaused & 1); } -int FCEUI_EmulationFrameStepped() -{ - return (EmulationPaused&2); +int FCEUI_EmulationFrameStepped() { + return(EmulationPaused & 2); } -void FCEUI_ClearEmulationFrameStepped() -{ - EmulationPaused &=~2; +void FCEUI_ClearEmulationFrameStepped() { + EmulationPaused &= ~2; } //mbg merge 7/18/06 added //ideally maybe we shouldnt be using this, but i need it for quick merging -void FCEUI_SetEmulationPaused(int val) -{ +void FCEUI_SetEmulationPaused(int val) { EmulationPaused = val; } -void FCEUI_ToggleEmulationPause(void) -{ - EmulationPaused = (EmulationPaused&1)^1; +void FCEUI_ToggleEmulationPause(void) { + EmulationPaused = (EmulationPaused & 1) ^ 1; DebuggerWasUpdated = false; } -void FCEUI_FrameAdvanceEnd(void) -{ +void FCEUI_FrameAdvanceEnd(void) { frameAdvanceRequested = false; } -void FCEUI_FrameAdvance(void) -{ +void FCEUI_FrameAdvance(void) { frameAdvanceRequested = true; frameAdvanceDelay = 0; } static int AutosaveCounter = 0; -void UpdateAutosave(void) -{ - if(!EnableAutosave || turbo) +void UpdateAutosave(void) { + if (!EnableAutosave || turbo) return; char * f; - if(++AutosaveCounter >= AutosaveFrequency) - { + if (++AutosaveCounter >= AutosaveFrequency) { AutosaveCounter = 0; AutosaveIndex = (AutosaveIndex + 1) % AutosaveQty; - f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE,AutosaveIndex,0).c_str()); + f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str()); FCEUSS_Save(f); - AutoSS = true; //Flag that an auto-savestate was made + AutoSS = true; //Flag that an auto-savestate was made free(f); AutosaveStatus[AutosaveIndex] = 1; } } -void FCEUI_Autosave(void) -{ - if(!EnableAutosave || !AutoSS) +void FCEUI_Autosave(void) { + if (!EnableAutosave || !AutoSS) return; - if(AutosaveStatus[AutosaveIndex] == 1) - { + if (AutosaveStatus[AutosaveIndex] == 1) { char * f; - f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE,AutosaveIndex,0).c_str()); + f = strdup(FCEU_MakeFName(FCEUMKF_AUTOSTATE, AutosaveIndex, 0).c_str()); FCEUSS_Load(f); free(f); //Set pointer to previous available slot - if(AutosaveStatus[(AutosaveIndex + AutosaveQty-1)%AutosaveQty] == 1) - { - AutosaveIndex = (AutosaveIndex + AutosaveQty-1)%AutosaveQty; + if (AutosaveStatus[(AutosaveIndex + AutosaveQty - 1) % AutosaveQty] == 1) { + AutosaveIndex = (AutosaveIndex + AutosaveQty - 1) % AutosaveQty; } //Reset time to next Auto-save @@ -1026,22 +924,18 @@ void FCEUI_Autosave(void) } } -int FCEU_TextScanlineOffset(int y) -{ - return FSettings.FirstSLine*256; +int FCEU_TextScanlineOffset(int y) { + return FSettings.FirstSLine * 256; } -int FCEU_TextScanlineOffsetFromBottom(int y) -{ - return (FSettings.LastSLine-y)*256; +int FCEU_TextScanlineOffsetFromBottom(int y) { + return (FSettings.LastSLine - y) * 256; } -bool FCEU_IsValidUI(EFCEUI ui) -{ - switch(ui) - { +bool FCEU_IsValidUI(EFCEUI ui) { + switch (ui) { case FCEUI_OPENGAME: case FCEUI_CLOSEGAME: - if(FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false; + if (FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false; break; case FCEUI_RECORDMOVIE: case FCEUI_PLAYMOVIE: @@ -1052,35 +946,34 @@ bool FCEU_IsValidUI(EFCEUI ui) case FCEUI_NEXTSAVESTATE: case FCEUI_PREVIOUSSAVESTATE: case FCEUI_VIEWSLOTS: - if(!GameInfo) return false; - if(FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false; + if (!GameInfo) return false; + if (FCEUMOV_Mode(MOVIEMODE_TASEDITOR)) return false; break; case FCEUI_STOPMOVIE: - return (FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD|MOVIEMODE_FINISHED)); + return(FCEUMOV_Mode(MOVIEMODE_PLAY | MOVIEMODE_RECORD | MOVIEMODE_FINISHED)); case FCEUI_PLAYFROMBEGINNING: - return (FCEUMOV_Mode(MOVIEMODE_PLAY|MOVIEMODE_RECORD|MOVIEMODE_TASEDITOR|MOVIEMODE_FINISHED)); + return(FCEUMOV_Mode(MOVIEMODE_PLAY | MOVIEMODE_RECORD | MOVIEMODE_TASEDITOR | MOVIEMODE_FINISHED)); case FCEUI_STOPAVI: return FCEUI_AviIsRecording(); case FCEUI_TASEDITOR: - if(!GameInfo) return false; + if (!GameInfo) return false; break; case FCEUI_RESET: case FCEUI_POWER: case FCEUI_EJECT_DISK: case FCEUI_SWITCH_DISK: - if(!GameInfo) return false; - if(FCEUMOV_Mode(MOVIEMODE_RECORD)) return true; + if (!GameInfo) return false; + if (FCEUMOV_Mode(MOVIEMODE_RECORD)) return true; #ifdef WIN32 - if(FCEUMOV_Mode(MOVIEMODE_TASEDITOR) && TaseditorIsRecording()) return true; + if (FCEUMOV_Mode(MOVIEMODE_TASEDITOR) && TaseditorIsRecording()) return true; #endif - if(!FCEUMOV_Mode(MOVIEMODE_INACTIVE)) return false; + if (!FCEUMOV_Mode(MOVIEMODE_INACTIVE)) return false; break; - } return true; } @@ -1090,26 +983,26 @@ bool FCEU_IsValidUI(EFCEUI ui) class FCEUXCart { public: - int mirroring; - int chrPages, prgPages; - uint32 chrSize, prgSize; - char* CHR, *PRG; +int mirroring; +int chrPages, prgPages; +uint32 chrSize, prgSize; +char* CHR, *PRG; - FCEUXCart() - : CHR(0) - , PRG(0) - {} +FCEUXCart() + : CHR(0) + , PRG(0) { +} - ~FCEUXCart() { - if(CHR) delete[] CHR; - if(PRG) delete[] PRG; - } +~FCEUXCart() { + if (CHR) delete[] CHR; + if (PRG) delete[] PRG; +} - virtual void Power() { - } +virtual void Power() { +} protected: - //void SetReadHandler(int32 start, int32 end, readfunc func) { +//void SetReadHandler(int32 start, int32 end, readfunc func) { }; FCEUXCart* cart = 0; @@ -1127,77 +1020,76 @@ FCEUXCart* cart = 0; class NROM : FCEUXCart { public: - virtual void Power() { - SetReadHandler(0x8000,0xFFFF,CartBR); - setprg16(0x8000,0); - setprg16(0xC000,~0); - setchr8(0); +virtual void Power() { + SetReadHandler(0x8000, 0xFFFF, CartBR); + setprg16(0x8000, 0); + setprg16(0xC000, ~0); + setchr8(0); - vnapage[0] = NTARAM; - vnapage[2] = NTARAM; - vnapage[1] = NTARAM+0x400; - vnapage[3] = NTARAM+0x400; - PPUNTARAM=0xF; - } + vnapage[0] = NTARAM; + vnapage[2] = NTARAM; + vnapage[1] = NTARAM + 0x400; + vnapage[3] = NTARAM + 0x400; + PPUNTARAM = 0xF; +} }; void FCEUXGameInterface(GI command) { - switch(command) { - case GI_POWER: - cart->Power(); + switch (command) { + case GI_POWER: + cart->Power(); } } -bool FCEUXLoad(const char *name, FCEUFILE *fp) -{ +bool FCEUXLoad(const char *name, FCEUFILE *fp) { //read ines header iNES_HEADER head; - if(FCEU_fread(&head,1,16,fp)!=16) + if (FCEU_fread(&head, 1, 16, fp) != 16) return false; //validate header - if(memcmp(&head,"NES\x1a",4)) + if (memcmp(&head, "NES\x1a", 4)) return 0; - int mapper = (head.ROM_type>>4); - mapper |= (head.ROM_type2&0xF0); + int mapper = (head.ROM_type >> 4); + mapper |= (head.ROM_type2 & 0xF0); //choose what kind of cart to use. cart = (FCEUXCart*)new NROM(); //fceu ines loading code uses 256 here when the romsize is 0. cart->prgPages = head.ROM_size; - if(cart->prgPages == 0) { + if (cart->prgPages == 0) { printf("FCEUX: received zero prgpages\n"); cart->prgPages = 256; } cart->chrPages = head.VROM_size; - cart->mirroring = (head.ROM_type&1); - if(head.ROM_type&8) cart->mirroring=2; + cart->mirroring = (head.ROM_type & 1); + if (head.ROM_type & 8) cart->mirroring = 2; //skip trainer - bool hasTrainer = (head.ROM_type&4)!=0; - if(hasTrainer) { - FCEU_fseek(fp,512,SEEK_CUR); + bool hasTrainer = (head.ROM_type & 4) != 0; + if (hasTrainer) { + FCEU_fseek(fp, 512, SEEK_CUR); } //load data - cart->prgSize = cart->prgPages*16*1024; - cart->chrSize = cart->chrPages*8*1024; + cart->prgSize = cart->prgPages * 16 * 1024; + cart->chrSize = cart->chrPages * 8 * 1024; cart->PRG = new char[cart->prgSize]; cart->CHR = new char[cart->chrSize]; - FCEU_fread(cart->PRG,1,cart->prgSize,fp); - FCEU_fread(cart->CHR,1,cart->chrSize,fp); + FCEU_fread(cart->PRG, 1, cart->prgSize, fp); + FCEU_fread(cart->CHR, 1, cart->chrSize, fp); //setup the emulator - GameInterface=FCEUXGameInterface; + GameInterface = FCEUXGameInterface; ResetCartMapping(); - SetupCartPRGMapping(0,(uint8*)cart->PRG,cart->prgSize,0); - SetupCartCHRMapping(0,(uint8*)cart->CHR,cart->chrSize,0); + SetupCartPRGMapping(0, (uint8*)cart->PRG, cart->prgSize, 0); + SetupCartCHRMapping(0, (uint8*)cart->CHR, cart->chrSize, 0); return true; } @@ -1205,8 +1097,8 @@ bool FCEUXLoad(const char *name, FCEUFILE *fp) uint8 FCEU_ReadRomByte(uint32 i) { extern iNES_HEADER head; - if(i < 16) return *((unsigned char *)&head+i); - if(i < 16+PRGsize[0])return PRGptr[0][i-16]; - if(i < 16+PRGsize[0]+CHRsize[0])return CHRptr[0][i-16-PRGsize[0]]; + if (i < 16) return *((unsigned char*)&head + i); + if (i < 16 + PRGsize[0]) return PRGptr[0][i - 16]; + if (i < 16 + PRGsize[0] + CHRsize[0]) return CHRptr[0][i - 16 - PRGsize[0]]; return 0; } diff --git a/src/ines.cpp b/src/ines.cpp index eb7d1b42..59d0d5b1 100644 --- a/src/ines.cpp +++ b/src/ines.cpp @@ -51,31 +51,18 @@ uint8 *ROM = NULL; uint8 *VROM = NULL; iNES_HEADER head; - - static CartInfo iNESCart; -uint8 iNESMirroring = 0; -uint16 iNESCHRBankList[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -int32 iNESIRQLatch = 0, iNESIRQCount = 0; -uint8 iNESIRQa = 0; - +uint8 Mirroring = 0; uint32 ROM_size = 0; uint32 VROM_size = 0; char LoadedRomFName[2048]; //mbg merge 7/17/06 added static int CHRRAMSize = -1; -static void iNESPower(void); -static int NewiNES_Init(int num); - -void (*MapperReset)(void); +static int iNES_Init(int num); static int MapperNo = 0; -/* MapperReset() is called when the NES is reset(with the reset button). - Mapperxxx_init is called when the NES has been powered on. -*/ - static DECLFR(TrainerRead) { return(trainerpoo[A & 0x1FF]); } @@ -106,8 +93,6 @@ void iNESGI(GI h) { //bbit edited: removed static keyword break; case GI_RESETM2: - if (MapperReset) - MapperReset(); if (iNESCart.Reset) iNESCart.Reset(); break; @@ -117,16 +102,19 @@ void iNESGI(GI h) { //bbit edited: removed static keyword case GI_CLOSE: { FCEU_SaveGameSave(&iNESCart); - - if (iNESCart.Close) iNESCart.Close(); + if (iNESCart.Close) + iNESCart.Close(); if (ROM) { - free(ROM); ROM = NULL; + free(ROM); + ROM = NULL; } if (VROM) { - free(VROM); VROM = NULL; + free(VROM); + VROM = NULL; } if (trainerpoo) { - FCEU_gfree(trainerpoo); trainerpoo = 0; + FCEU_gfree(trainerpoo); + trainerpoo = NULL; } } break; @@ -249,10 +237,7 @@ static struct BADINF BadROMImages[] = }; void CheckBad(uint64 md5partial) { - int x; - - x = 0; - //printf("0x%llx\n",md5partial); + int32 x = 0; while (BadROMImages[x].name) { if (BadROMImages[x].md5partial == md5partial) { FCEU_PrintError("The copy game you have loaded, \"%s\", is bad, and will not work properly in FCEUX.", BadROMImages[x].name); @@ -270,18 +255,6 @@ struct CHINF { const char* params; }; -void MapperInit() { - if (NewiNES_Init(MapperNo)) { - } else { - iNESCart.Power = iNESPower; - SetupCartPRGMapping(1, WRAM, 8192, 1); - if (head.ROM_type & 2) { - iNESCart.SaveGame[0] = WRAM; - iNESCart.SaveGameLen[0] = 8192; - } - } -} - static const TMasterRomInfo sMasterRomInfo[] = { { 0x62b51b108a01d2beLL, "bonus=0" }, //4-in-1 (FK23C8021)[p1][!].nes { 0x8bb48490d8d22711LL, "bonus=0" }, //4-in-1 (FK23C8033)[p1][!].nes @@ -345,14 +318,11 @@ static void CheckHInfo(void) { { #include "ines-correct.h" }; - int tofix = 0; - int x; + int32 tofix = 0, x; uint64 partialmd5 = 0; - for (x = 0; x < 8; x++) { + for (x = 0; x < 8; x++) partialmd5 |= (uint64)iNESCart.MD5[15 - x] << (x * 8); - //printf("%16llx\n",partialmd5); - } CheckBad(partialmd5); MasterRomInfo = NULL; @@ -373,7 +343,6 @@ static void CheckHInfo(void) { } x = 0; - do { if (moo[x].crc32 == iNESGameCRC32) { if (moo[x].mapper >= 0) { @@ -451,7 +420,7 @@ static void CheckHInfo(void) { } typedef struct { - int mapper; + int32 mapper; void (*init)(CartInfo *); } NewMI; @@ -466,8 +435,8 @@ static int not_power2[] = 228 }; typedef struct { - char* name; - int number; + char *name; + int32 number; void (*init)(CartInfo *); } BMAPPINGLocal; @@ -865,9 +834,10 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { iNESCart.battery = (head.ROM_type & 2) ? 1 : 0; iNESCart.mirror = Mirroring; + if (!iNES_Init(MapperNo)) + FCEU_PrintError("iNES mapper #%d is not supported at all.", MapperNo); GameInfo->mappernum = MapperNo; - MapperInit(); FCEU_LoadGameSave(&iNESCart); strcpy(LoadedRomFName, name); //bbit edited: line added @@ -966,461 +936,7 @@ char *iNesShortFName() { return ret + 1; } -void VRAM_BANK1(uint32 A, uint8 V) { - V &= 7; - PPUCHRRAM |= (1 << (A >> 10)); - CHRBankList[(A) >> 10] = V; - VPage[(A) >> 10] = &CHRRAM[V << 10] - (A); -} - -void VRAM_BANK4(uint32 A, uint32 V) { - V &= 1; - PPUCHRRAM |= (0xF << (A >> 10)); - CHRBankList[(A) >> 10] = (V << 2); - CHRBankList[((A) >> 10) + 1] = (V << 2) + 1; - CHRBankList[((A) >> 10) + 2] = (V << 2) + 2; - CHRBankList[((A) >> 10) + 3] = (V << 2) + 3; - VPage[(A) >> 10] = &CHRRAM[V << 10] - (A); -} -void VROM_BANK1(uint32 A, uint32 V) { - setchr1(A, V); - CHRBankList[(A) >> 10] = V; -} - -void VROM_BANK2(uint32 A, uint32 V) { - setchr2(A, V); - CHRBankList[(A) >> 10] = (V << 1); - CHRBankList[((A) >> 10) + 1] = (V << 1) + 1; -} - -void VROM_BANK4(uint32 A, uint32 V) { - setchr4(A, V); - CHRBankList[(A) >> 10] = (V << 2); - CHRBankList[((A) >> 10) + 1] = (V << 2) + 1; - CHRBankList[((A) >> 10) + 2] = (V << 2) + 2; - CHRBankList[((A) >> 10) + 3] = (V << 2) + 3; -} - -void VROM_BANK8(uint32 V) { - setchr8(V); - 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; -} - -void ROM_BANK8(uint32 A, uint32 V) { - setprg8(A, V); - if (A >= 0x8000) - PRGBankList[((A - 0x8000) >> 13)] = V; -} - -void ROM_BANK16(uint32 A, uint32 V) { - setprg16(A, V); - if (A >= 0x8000) { - PRGBankList[((A - 0x8000) >> 13)] = V << 1; - PRGBankList[((A - 0x8000) >> 13) + 1] = (V << 1) + 1; - } -} - -void ROM_BANK32(uint32 V) { - setprg32(0x8000, V); - PRGBankList[0] = V << 2; - PRGBankList[1] = (V << 2) + 1; - PRGBankList[2] = (V << 2) + 2; - PRGBankList[3] = (V << 2) + 3; -} - -void onemir(uint8 V) { - if (Mirroring == 2) return; - if (V > 1) - V = 1; - Mirroring = 0x10 | V; - setmirror(MI_0 + V); -} - -void MIRROR_SET2(uint8 V) { - if (Mirroring == 2) return; - Mirroring = V; - setmirror(V); -} - -void MIRROR_SET(uint8 V) { - if (Mirroring == 2) return; - V ^= 1; - Mirroring = V; - setmirror(V); -} - -static void NONE_init(void) { - ROM_BANK16(0x8000, 0); - ROM_BANK16(0xC000, ~0); - - if (VROM_size) - VROM_BANK8(0); - else - setvram8(CHRRAM); -} - -void(*MapInitTab[256]) (void) = -{ - 0, - 0, - 0, //Mapper2_init, - 0, //Mapper3_init, - 0, - 0, - 0, //Mapper6_init, - 0, //Mapper7_init, - 0, //Mapper8_init, - 0, //Mapper9_init, - 0, //Mapper10_init, - 0, //Mapper11_init, - 0, - 0, //Mapper13_init, - 0, - 0, //Mapper15_init, - 0, //Mapper16_init, - 0, //Mapper17_init, - 0, //Mapper18_init, - 0, - 0, - 0, //Mapper21_init, - 0, //Mapper22_init, - 0, //Mapper23_init, - 0, //Mapper24_init, - 0, //Mapper25_init, - 0, //Mapper26_init, - 0, //Mapper27_init, - 0, - 0, - 0, - 0, - 0, //Mapper32_init, - 0, //Mapper33_init, - 0, //Mapper34_init, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper40_init, - 0, //Mapper41_init, - 0, //Mapper42_init, - 0, //Mapper43_init, - 0, - 0, - 0, //Mapper46_init, - 0, - 0, //Mapper48_init, - 0, - 0, //Mapper50_init, - 0, //Mapper51_init, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper57_init, - 0, //Mapper58_init, - 0, //Mapper59_init, - 0, //Mapper60_init, - 0, //Mapper61_init, - 0, //Mapper62_init, - 0, - 0, //Mapper64_init, - 0, //Mapper65_init, - 0, //Mapper66_init, - 0, //Mapper67_init, - 0, //Mapper68_init, - 0, //Mapper69_init, - 0, //Mapper70_init, - 0, //Mapper71_init, - 0, //Mapper72_init, - 0, //Mapper73_init, - 0, - 0, //Mapper75_init, - 0, //Mapper76_init, - 0, //Mapper77_init, - 0, //Mapper78_init, - 0, //Mapper79_init, - 0, //Mapper80_init, - 0, - 0, //Mapper82_init, - 0, //Mapper83_init, - 0, - 0, //Mapper85_init, - 0, //Mapper86_init, - 0, //Mapper87_init, - 0, //Mapper88_init, - 0, //Mapper89_init, - 0, - 0, //Mapper91_init, - 0, //Mapper92_init, - 0, //Mapper93_init, - 0, //Mapper94_init, - 0, - 0, //Mapper96_init, - 0, //Mapper97_init, - 0, - 0, //Mapper99_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper107_init, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper113_init, - 0, - 0, - 0, //Mapper116_init, - 0, //Mapper117_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper140_init, - 0, - 0, - 0, - 0, //Mapper144_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper151_init, - 0, //Mapper152_init, - 0, //Mapper153_init, - 0, //Mapper154_init, - 0, - 0, //Mapper156_init, - 0, //Mapper157_init, - 0, //Mapper158_init, removed - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper166_init, - 0, //Mapper167_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper180_init, - 0, - 0, - 0, - 0, //Mapper184_init, - 0, //Mapper185_init, - 0, - 0, - 0, - 0, //Mapper189_init, - 0, - 0, //Mapper191_init, - 0, - 0, //Mapper193_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper200_init, - 0, //Mapper201_init, - 0, //Mapper202_init, - 0, //Mapper203_init, - 0, //Mapper204_init, - 0, - 0, - 0, //Mapper207_init, - 0, - 0, - 0, - 0, //Mapper211_init, - 0, //Mapper212_init, - 0, //Mapper213_init, - 0, //Mapper214_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper225_init, - 0, //Mapper226_init, - 0, //Mapper227_init, - 0, //Mapper228_init, - 0, //Mapper229_init, - 0, //Mapper230_init, - 0, //Mapper231_init, - 0, //Mapper232_init, - 0, - 0, //Mapper234_init, - 0, //Mapper235_init, - 0, - 0, - 0, - 0, - 0, //Mapper240_init, - 0, //Mapper241_init, - 0, //Mapper242_init, - 0, - 0, //Mapper244_init, - 0, - 0, //Mapper246_init, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, //Mapper255_init -}; - -static DECLFW(BWRAM) { - WRAM[A - 0x6000] = V; -} - -static DECLFR(AWRAM) { - return WRAM[A - 0x6000]; -} - - -void (*MapStateRestore)(int version); -void iNESStateRestore(int version) { - int x; - - if (!MapperNo) return; - - for (x = 0; x < 4; x++) - setprg8(0x8000 + x * 8192, PRGBankList[x]); - - if (VROM_size) - for (x = 0; x < 8; x++) - setchr1(0x400 * x, CHRBankList[x]); - - if (0) switch (Mirroring) { - case 0: setmirror(MI_H); break; - case 1: setmirror(MI_V); break; - case 0x12: - case 0x10: setmirror(MI_0); break; - case 0x13: - case 0x11: setmirror(MI_1); break; - } - if (MapStateRestore) MapStateRestore(version); -} - -static void iNESPower(void) { - int x; - int type = MapperNo; - - SetReadHandler(0x8000, 0xFFFF, CartBR); - GameStateRestore = iNESStateRestore; - MapperReset = 0; - MapStateRestore = 0; - - setprg8r(1, 0x6000, 0); - - SetReadHandler(0x6000, 0x7FFF, AWRAM); - SetWriteHandler(0x6000, 0x7FFF, BWRAM); - FCEU_CheatAddRAM(8, 0x6000, WRAM); - - /* This statement represents atrocious code. I need to rewrite - all of the iNES mapper code... */ - IRQCount = IRQLatch = IRQa = 0; - if (head.ROM_type & 2) - memset(GameMemBlock + 8192, 0, GAME_MEM_BLOCK_SIZE - 8192); - else - memset(GameMemBlock, 0, GAME_MEM_BLOCK_SIZE); - - NONE_init(); - ResetExState(0, 0); - - if (GameInfo->type == GIT_VSUNI) - AddExState(FCEUVSUNI_STATEINFO, ~0, 0, 0); - - AddExState(WRAM, 8192, 0, "WRAM"); - if (type == 85) - AddExState(MapperExRAM, 32768, 0, "MEXR"); - if ((!VROM_size || type == 6 || type == 19) && (type != 13)) - AddExState(CHRRAM, 8192 * 4, 0, "CHRR"); - if (head.ROM_type & 8) - AddExState(ExtraNTARAM, 2048, 0, "EXNR"); - - /* Exclude some mappers whose emulation code handle save state stuff - themselves. */ - if (type && type != 13) { - AddExState(mapbyte1, 32, 0, "MPBY"); - AddExState(&Mirroring, 1, 0, "MIRR"); - AddExState(&IRQCount, 4, 1, "IRQC"); - AddExState(&IRQLatch, 4, 1, "IQL1"); - AddExState(&IRQa, 1, 0, "IRQA"); - AddExState(PRGBankList, 4, 0, "PBL"); - for (x = 0; x < 8; x++) { - char tak[8]; - sprintf(tak, "CBL%d", x); - AddExState(&CHRBankList[x], 2, 1, tak); - } - } - - if (MapInitTab[type]) - MapInitTab[type](); - else - if (type) { - FCEU_PrintError("iNES mapper #%d is not supported at all.", type); - } -} - -static int NewiNES_Init(int num) { +static int iNES_Init(int num) { BMAPPINGLocal *tmp = bmap; CHRRAMSize = -1; @@ -1430,9 +946,9 @@ static int NewiNES_Init(int num) { while (tmp->init) { if (num == tmp->number) { - UNIFchrrama = 0; // need here for compatibility with UNIF mapper code + UNIFchrrama = 0; // need here for compatibility with UNIF mapper code if (!VROM_size) { - switch (num) { // FIXME, mapper or game data base with the board parameters and ROM/RAM sizes + switch (num) { // FIXME, mapper or game data base with the board parameters and ROM/RAM sizes case 13: CHRRAMSize = 16 * 1024; break; case 6: case 96: CHRRAMSize = 32 * 1024; break; diff --git a/src/ines.h b/src/ines.h index 9d5a9428..aa7f41f7 100644 --- a/src/ines.h +++ b/src/ines.h @@ -26,46 +26,17 @@ #include #ifdef INESPRIV -void iNESStateRestore(int version); -extern uint32 iNESGameCRC32; - -extern uint32 VROM_size; -extern uint32 ROM_size; - -extern void (*MapStateRestore)(int version); -extern void (*MapClose)(void); -extern void (*MapperReset)(void); - /* This order is necessary */ -#define WRAM (GameMemBlock) -#define sizeofWRAM 8192 +#define WRAM (GameMemBlock) +#define sizeofWRAM 8192 -#define MapperExRAM (GameMemBlock+sizeofWRAM) -#define sizeofMapperExRAM 32768 /* for the MMC5 code to work properly. It might be fixed later... */ +#define CHRRAM (GameMemBlock + sizeofWRAM) +#define sizeofCHRRAM 8192 -#define CHRRAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM) -#define sizeofCHRRAM 8192 +#define ExtraNTARAM (GameMemBlock + sizeofWRAM + sizeofCHRRAM) +#define sizeofExtraNTARAM 2048 -#define ExtraNTARAM (GameMemBlock+sizeofWRAM+sizeofMapperExRAM+sizeofCHRRAM) -#define sizeofExtraNTARAM 2048 - -#define PRGBankList (ExtraNTARAM+sizeofExtraNTARAM) - -#define mapbyte1 (PRGBankList+4) -#define mapbyte2 (mapbyte1+8) -#define mapbyte3 (mapbyte2+8) -#define mapbyte4 (mapbyte3+8) -extern uint16 iNESCHRBankList[8]; -extern int32 iNESIRQLatch,iNESIRQCount; -extern uint8 iNESMirroring; -extern uint8 iNESIRQa; - -#define IRQa iNESIRQa -#define Mirroring iNESMirroring -#define IRQCount iNESIRQCount -#define IRQLatch iNESIRQLatch -#define CHRBankList iNESCHRBankList #else #endif @@ -94,12 +65,12 @@ extern TMasterRomInfoParams MasterRomInfoParams; //mbg merge 7/19/06 changed to c++ decl format struct iNES_HEADER { - char ID[4]; /*NES^Z*/ - uint8 ROM_size; - uint8 VROM_size; - uint8 ROM_type; - uint8 ROM_type2; - uint8 reserve[8]; + char ID[4]; /*NES^Z*/ + uint8 ROM_size; + uint8 VROM_size; + uint8 ROM_type; + uint8 ROM_type2; + uint8 reserve[8]; void cleanup() { @@ -124,248 +95,11 @@ struct iNES_HEADER { }; extern struct iNES_HEADER head; //for mappers usage -void VRAM_BANK1(uint32 A, uint8 V); -void VRAM_BANK4(uint32 A,uint32 V); - -void VROM_BANK1(uint32 A,uint32 V); -void VROM_BANK2(uint32 A,uint32 V); -void VROM_BANK4(uint32 A, uint32 V); -void VROM_BANK8(uint32 V); -void ROM_BANK8(uint32 A, uint32 V); -void ROM_BANK16(uint32 A, uint32 V); -void ROM_BANK32(uint32 V); - -extern uint8 vmask; -extern uint32 vmask1; -extern uint32 vmask2; -extern uint32 vmask4; -extern uint32 pmask8; -extern uint8 pmask16; -extern uint8 pmask32; - -void onemir(uint8 V); -void MIRROR_SET2(uint8 V); -void MIRROR_SET(uint8 V); - -//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 Mapper8_init(void); -//void Mapper9_init(void); -//void Mapper10_init(void); -//void Mapper11_init(void); -void Mapper12_init(void); -//void Mapper13_init(void); -void Mapper14_init(void); -//void Mapper15_init(void); -//void Mapper16_init(void); -//void Mapper17_init(void); -//void Mapper18_init(void); -void Mapper19_init(void); -void Mapper20_init(void); -//void Mapper21_init(void); -//void Mapper22_init(void); -//void Mapper23_init(void); -//void Mapper24_init(void); -//void Mapper25_init(void); -//void Mapper26_init(void); -//void Mapper27_init(void); -void Mapper28_init(void); -void Mapper29_init(void); -void Mapper30_init(void); -void Mapper31_init(void); -//void Mapper32_init(void); -//void Mapper33_init(void); -//void Mapper34_init(void); -void Mapper35_init(void); -void Mapper36_init(void); -//void Mapper37_init(void); -//void Mapper38_init(void); -//void Mapper39_init(void); -//void Mapper40_init(void); -//void Mapper41_init(void); -//void Mapper42_init(void); -//void Mapper43_init(void); -void Mapper44_init(void); -void Mapper45_init(void); -//void Mapper46_init(void); -void Mapper47_init(void); -//void Mapper48_init(void); -void Mapper49_init(void); -//void Mapper50_init(void); -//void Mapper51_init(void); -void Mapper53_init(void); -void Mapper54_init(void); -void Mapper55_init(void); -void Mapper56_init(void); -//void Mapper59_init(void); -void Mapper60_init(void); -//void Mapper61_init(void); -//void Mapper62_init(void); -void Mapper63_init(void); -//void Mapper64_init(void); -//void Mapper65_init(void); -//void Mapper66_init(void); -//void Mapper67_init(void); -//void Mapper68_init(void); -//void Mapper69_init(void); -//void Mapper70_init(void); -//void Mapper71_init(void); -//void Mapper72_init(void); -//void Mapper73_init(void); -//void Mapper74_init(void); -//void Mapper75_init(void); -//void Mapper76_init(void); -//void Mapper77_init(void); -//void Mapper78_init(void); -//void Mapper79_init(void); -//void Mapper80_init(void); -void Mapper81_init(void); -//void Mapper82_init(void); -void Mapper83_init(void); -void Mapper84_init(void); -//void Mapper85_init(void); -//void Mapper86_init(void); -//void Mapper87_init(void); -void Mapper88_init(void); -//void Mapper89_init(void); -//void Mapper91_init(void); -//void Mapper92_init(void); -//void 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 Mapper103_init(void); -void Mapper104_init(void); -//void Mapper106_init(void); -//void Mapper107_init(void); -//void Mapper108_init(void); -void Mapper109_init(void); -void Mapper110_init(void); -//void Mapper111_init(void); -//void Mapper113_init(void); -void Mapper115_init(void); -//void Mapper116_init(void); -//void Mapper117_init(void); -//void Mapper120_init(void); -//void Mapper121_init(void); -void Mapper122_init(void); -void Mapper123_init(void); -void Mapper124_init(void); -void Mapper126_init(void); -void Mapper127_init(void); -void Mapper128_init(void); -void Mapper129_init(void); -void Mapper130_init(void); -void Mapper131_init(void); -void Mapper132_init(void); -//void Mapper134_init(void); -void Mapper135_init(void); -void Mapper136_init(void); -void Mapper137_init(void); -void Mapper139_init(void); -//void Mapper140_init(void); -void Mapper141_init(void); -//void Mapper142_init(void); -void Mapper143_init(void); -//void Mapper144_init(void); -void Mapper150_init(void); -//void Mapper151_init(void); -//void Mapper152_init(void); -//void Mapper153_init(void); -void Mapper154_init(void); -//void Mapper156_init(void); -//void Mapper157_init(void); -//void Mapper158_init(void); -//void Mapper159_init(void); -void Mapper160_init(void); -void Mapper161_init(void); -void Mapper162_init(void); -//void Mapper166_init(void); -//void Mapper167_init(void); -void Mapper168_init(void); -//void Mapper169_init(void); -void Mapper170_init(void); -//void Mapper171_init(void); -//void Mapper172_init(void); -//void Mapper173_init(void); -void Mapper174_init(void); -void Mapper175_init(void); -void Mapper176_init(void); -//void Mapper177_init(void); -//void Mapper178_init(void); -//void Mapper179_init(void); -void Mapper180_init(void); -//void Mapper181_init(void); -//void Mapper184_init(void); -//void Mapper185_init(void); -//void Mapper189_init(void); -//void Mapper192_init(void); -//void Mapper193_init(void); -//void Mapper194_init(void); -//void Mapper195_init(void); -//void Mapper196_init(void); -//void Mapper197_init(void); -//void Mapper198_init(void); -void Mapper199_init(void); -//void Mapper200_init(void); -//void Mapper201_init(void); -//void Mapper202_init(void); -//void Mapper203_init(void); -//void Mapper204_init(void); -//void Mapper207_init(void); -//void Mapper211_init(void); -//void Mapper212_init(void); -//void Mapper213_init(void); -//void Mapper214_init(void); -//void Mapper218_init(void); -void Mapper219_init(void); -//void Mapper220_init(void); -//void Mapper221_init(void); -//void Mapper222_init(void); -void Mapper223_init(void); -void Mapper224_init(void); -//void Mapper225_init(void); -//void Mapper226_init(void); -//void Mapper227_init(void); -//void Mapper228_init(void); -//void Mapper229_init(void); -//void Mapper230_init(void); -//void Mapper231_init(void); -//void Mapper232_init(void); -//void Mapper233_init(void); -//void Mapper234_init(void); -//void Mapper235_init(void); -void Mapper236_init(void); -void Mapper237_init(void); -void Mapper238_init(void); -void Mapper239_init(void); -void Mapper240_init(void); -//void Mapper241_init(void); -//void Mapper242_init(void); -//void Mapper244_init(void); -void Mapper245_init(void); -//void Mapper246_init(void); -void Mapper247_init(void); -void Mapper249_init(void); -void Mapper251_init(void); -//void Mapper252_init(void); -//void Mapper253_init(void); -//void Mapper255_init(void); - void NSFVRC6_Init(void); void NSFMMC5_Init(void); void NSFAY_Init(void); void NSFN106_Init(void); void NSFVRC7_Init(void); -void Mapper19_ESI(void); void Mapper1_Init(CartInfo *); void Mapper4_Init(CartInfo *);