cleanup
authornotaz <notasas@gmail.com>
Mon, 30 Apr 2007 14:47:40 +0000 (14:47 +0000)
committernotaz <notasas@gmail.com>
Mon, 30 Apr 2007 14:47:40 +0000 (14:47 +0000)
git-svn-id: file:///home/notaz/opt/svn/fceu@118 be3aeb3a-fb24-0410-a615-afba39da0efa

Makefile.base
mbshare/Makefile [deleted file]
mbshare/mapinc.h [deleted file]
mbshare/mmc1.c [deleted file]
mbshare/mmc3.c [deleted file]
mbshare/mmc5.c [deleted file]

index af0e348..be38984 100644 (file)
@@ -5,7 +5,6 @@ OBJECTS = fce.o video.o general.o endian.o svga.o sound.o nsf.o fds.o netplay.o
 fceu:          fceu2
 include        mappers/Makefile
 include boards/Makefile
-#include mbshare/Makefile
 include input/Makefile
 
 fceu2:         ${OBJECTS} ${MOBJS} ${MUOBJS} ${MUSOBJS} ${INPOBJS} ${OBJDRIVER}
diff --git a/mbshare/Makefile b/mbshare/Makefile
deleted file mode 100644 (file)
index 3508da1..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-MUSOBJS   =       mbshare/mmc5.o mbshare/mmc3.o mbshare/mmc1.o
-
-mbshare/mmc1.o:                mbshare/mmc1.c
-mbshare/mmc3.o:         mbshare/mmc3.c
-mbshare/mmc5.o:         mbshare/mmc5.c
diff --git a/mbshare/mapinc.h b/mbshare/mapinc.h
deleted file mode 100644 (file)
index 9702ec2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#include        "../types.h"
-#include        "../x6502.h"
-#include        "../fce.h"
-#define INESPRIV
-#include        "../ines.h"
-#include        "../version.h"
-#include        "../memory.h"
-#include       "../sound.h"
-#include       "../svga.h"
-#include       "../state.h"
-#define UNIFPRIV
-#include       "../unif.h"
-#include       "../cart.h"
-#include       "../cheat.h"
diff --git a/mbshare/mmc1.c b/mbshare/mmc1.c
deleted file mode 100644 (file)
index 8386ee3..0000000
+++ /dev/null
@@ -1,355 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
- *
- * 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"
-
-#define MMC1_reg mapbyte1
-#define MMC1_buf mapbyte2[0]
-#define MMC1_sft mapbyte3[0]
-
-static int mmc1opts;
-
-
-uint8 MMC1WRAMsize;    /* For use in iNES.c */
-
-static DECLFW(MBWRAM)
-{
- if(!(MMC1_reg[3]&0x10))
-  Page[A>>11][A]=V;     // WRAM is enabled.
-}
-
-static DECLFR(MAWRAM)
-{
- if(MMC1_reg[3]&0x10)
-  return X.DB;          // WRAM is disabled
- return(Page[A>>11][A]);
-}
-
-static void MMC1CHR(void)
-{
-    if(mmc1opts&4)
-    {
-     if(MMC1_reg[0]&0x10)
-      setprg8r(0x10,0x6000,(MMC1_reg[1]>>4)&1);
-     else
-      setprg8r(0x10,0x6000,(MMC1_reg[1]>>3)&1);
-     X6502_Rebase();
-    }
-
-    if(MMC1_reg[0]&0x10)
-    {
-     setchr4(0x0000,MMC1_reg[1]);
-     setchr4(0x1000,MMC1_reg[2]);
-    }
-    else
-     setchr8(MMC1_reg[1]>>1);
-}
-
-static void MMC1PRG(void)
-{
-        uint8 offs;
-
-        offs=MMC1_reg[1]&0x10;
-        switch(MMC1_reg[0]&0xC)
-        {
-          case 0xC: setprg16(0x8000,(MMC1_reg[3]+offs));
-                    setprg16(0xC000,0xF+offs);
-                    break;
-          case 0x8: setprg16(0xC000,(MMC1_reg[3]+offs));
-                    setprg16(0x8000,offs);
-                    break;
-          case 0x0:
-          case 0x4:
-                    setprg16(0x8000,((MMC1_reg[3]&~1)+offs));
-                    setprg16(0xc000,((MMC1_reg[3]&~1)+offs+1));
-                    break;
-        }
-        X6502_Rebase();
-}
-static void MMC1MIRROR(void)
-{
-                switch(MMC1_reg[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)
-        {
-        MMC1_reg[0]|=0xC;
-         MMC1_sft=MMC1_buf=0;
-        MMC1PRG();
-        lreset=timestampbase+timestamp;
-         return;
-        }
-
-        MMC1_buf|=(V&1)<<(MMC1_sft++);
-
-  if (MMC1_sft==5) {
-        MMC1_reg[n]=MMC1_buf;
-        MMC1_sft = MMC1_buf=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();
-}
-
-static void MMC1CMReset(void)
-{
-        int i;
-
-        for(i=0;i<4;i++)
-         MMC1_reg[i]=0;
-        MMC1_sft = MMC1_buf =0;
-        MMC1_reg[0]=0x1F;
-
-        MMC1_reg[1]=0;
-        MMC1_reg[2]=0;                  // Should this be something other than 0?
-        MMC1_reg[3]=0;
-
-        MMC1MIRROR();
-        MMC1CHR();
-        MMC1PRG();
-}
-
-void DetectMMC1WRAMSize(void)
-{
-        switch(iNESGameCRC32)
-        {
-         default:MMC1WRAMsize=1;break;
-        case 0xc6182024:       /* Romance of the 3 Kingdoms */
-         case 0x2225c20f:       /* Genghis Khan */
-         case 0x4642dda6:       /* Nobunaga's Ambition */
-        case 0x29449ba9:       /* ""   "" (J) */
-        case 0x2b11e0b0:       /* ""   "" (J) */
-                MMC1WRAMsize=2;
-                break;
-        }
-}
-
-void Mapper1_init(void)
-{
-       lreset=0;
-       mmc1opts=0;
-        MMC1CMReset();
-       SetWriteHandler(0x8000,0xFFFF,MMC1_write);
-       MapStateRestore=MMC1_Restore;
-       AddExState(&lreset, 8, 1, "LRST");
-
-       if(!VROM_size)
-        SetupCartCHRMapping(0, CHRRAM, 8192, 1);
-
-       if(MMC1WRAMsize==2)
-        mmc1opts|=4;
-
-       SetupCartPRGMapping(0x10,WRAM,MMC1WRAMsize*8192,1);
-       SetReadHandler(0x6000,0x7FFF,MAWRAM);
-       SetWriteHandler(0x6000,0x7FFF,MBWRAM);
-       setprg8r(0x10,0x6000,0);
-}
-
-static void GenMMC1Close(void)
-{
- UNIFOpenWRAM(UOW_WR,0,0);
- UNIFWriteWRAM(WRAM+((mmc1opts&4)?8192:0),8192);
- UNIFCloseWRAM();
-}
-
-
-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 GenMMC1Init(int prg, int chr, int wram, int battery)
-{
- mmc1opts=0;
- PRGmask16[0]&=(prg>>14)-1;
- CHRmask4[0]&=(chr>>12)-1;
- CHRmask8[0]&=(chr>>13)-1;
-
- if(wram)
- {
-  mmc1opts|=1;
-  if(wram>8) mmc1opts|=4;
-  SetupCartPRGMapping(0x10,WRAM,wram*1024,1);
-  AddExState(WRAM, wram*1024, 0, "WRAM");
- }
-
- if(battery && UNIFbattery)
- {
-  mmc1opts|=2;
-  BoardClose=GenMMC1Close;
-
-  UNIFOpenWRAM(UOW_RD,0,0);
-  UNIFReadWRAM(WRAM+((mmc1opts&4)?8192:0),8192);
-  UNIFCloseWRAM();
- }
-
- if(!chr)
- {
-  CHRmask4[0]=1;
-  SetupCartCHRMapping(0, CHRRAM, 8192, 1);
-  AddExState(CHRRAM, 8192, 0, "CHRR");
- }
- AddExState(mapbyte1, 32, 0, "MPBY");
- BoardPower=GenMMC1Power;
-
- GameStateRestore=MMC1_Restore;
- AddExState(&lreset, 8, 1, "LRST");
-}
-
-//static void GenMMC1Init(int prg, int chr, int wram, int battery)
-void SAROM_Init(void)
-{
- GenMMC1Init(128, 64, 8, 1);
-}
-
-void SBROM_Init(void)
-{
- GenMMC1Init(128, 64, 0, 0);
-}
-
-void SCROM_Init(void)
-{
- GenMMC1Init(128, 128, 0, 0);
-}
-
-void SEROM_Init(void)
-{
- GenMMC1Init(32, 64, 0, 0);
-}
-
-void SGROM_Init(void)
-{
- GenMMC1Init(256, 0, 0, 0);
-}
-
-void SKROM_Init(void)
-{
- GenMMC1Init(256, 64, 8, 1);
-}
-
-void SLROM_Init(void)
-{
- GenMMC1Init(256, 128, 0, 0);
-}
-
-void SL1ROM_Init(void)
-{
- GenMMC1Init(128, 128, 0, 0);
-}
-
-/* Begin unknown - may be wrong - perhaps they use different MMC1s from the
-   similarly functioning boards?
-*/
-
-void SL2ROM_Init(void)
-{
- GenMMC1Init(256, 256, 0, 0);
-}
-
-void SFROM_Init(void)
-{
- GenMMC1Init(256, 256, 0, 0);
-}
-
-void SHROM_Init(void)
-{
- GenMMC1Init(256, 256, 0, 0);
-}
-
-/* End unknown  */
-/*              */
-/*              */
-
-void SNROM_Init(void)
-{
- GenMMC1Init(256, 0, 8, 1);
-}
-
-void SOROM_Init(void)
-{
- GenMMC1Init(256, 0, 16, 1);
-}
-
-
diff --git a/mbshare/mmc3.c b/mbshare/mmc3.c
deleted file mode 100644 (file)
index 872e376..0000000
+++ /dev/null
@@ -1,655 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 1998 BERO
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/*  Code for emulating iNES mappers 4, 118,119 */
-
-#include "mapinc.h"
-
-#define resetmode mapbyte1[0]
-#define MMC3_cmd mapbyte1[1]
-#define A000B mapbyte1[2]
-#define A001B mapbyte1[3]
-#define DRegBuf mapbyte4
-
-#define PPUCHRBus mapbyte2[0]
-#define TKSMIR mapbyte3
-#define PIRREGS        mapbyte2
-
-static void (*pwrap)(uint32 A, uint8 V);
-static void (*cwrap)(uint32 A, uint8 V);
-static void (*mwrap)(uint8 V);
-
-static int mmc3opts=0;
-
-static INLINE void FixMMC3PRG(int V);
-static INLINE void FixMMC3CHR(int V);
-
-static int latched;
-
-static DECLFW(MMC3_IRQWrite)
-{
-       //printf("$%04x:$%02x, %d\n",A,V,scanline);
-        switch(A&0xE001)
-        {
-         case 0xc000:IRQLatch=V;
-                    latched=1;
-                    if(resetmode)
-                    {
-                     IRQCount=V;
-                     latched=0;
-                     //resetmode=0;
-                    }
-                     break;
-         case 0xc001:IRQCount=IRQLatch;
-                     break;
-         case 0xE000:IRQa=0;
-                    X6502_IRQEnd(FCEU_IQEXT);
-                    resetmode=1;
-                     break;
-         case 0xE001:IRQa=1;
-                    if(latched)
-                     IRQCount=IRQLatch;
-                     break;
-        }
-}
-
-static INLINE void FixMMC3PRG(int V)
-{
-          if(V&0x40)
-          {
-           pwrap(0xC000,DRegBuf[6]);
-           pwrap(0x8000,~1);
-          }
-          else
-          {
-           pwrap(0x8000,DRegBuf[6]);
-           pwrap(0xC000,~1);
-          }
-         pwrap(0xA000,DRegBuf[7]);
-         pwrap(0xE000,~0);
-          X6502_Rebase();
-}
-
-static INLINE void FixMMC3CHR(int V)
-{
-           int cbase=(V&0x80)<<5;
-           cwrap((cbase^0x000),DRegBuf[0]&(~1));
-           cwrap((cbase^0x400),DRegBuf[0]|1);
-           cwrap((cbase^0x800),DRegBuf[1]&(~1));
-           cwrap((cbase^0xC00),DRegBuf[1]|1);
-
-           cwrap(cbase^0x1000,DRegBuf[2]);
-           cwrap(cbase^0x1400,DRegBuf[3]);
-           cwrap(cbase^0x1800,DRegBuf[4]);
-           cwrap(cbase^0x1c00,DRegBuf[5]);
-}
-
-static void MMC3RegReset(void)
-{
- IRQCount=IRQLatch=IRQa=MMC3_cmd=0;
-
- DRegBuf[0]=0;
- DRegBuf[1]=2;
- DRegBuf[2]=4;
- DRegBuf[3]=5;
- DRegBuf[4]=6;
- DRegBuf[5]=7;
- DRegBuf[6]=0;
- DRegBuf[7]=1;
-
- FixMMC3PRG(0);
- FixMMC3CHR(0);
-}
-
-static DECLFW(Mapper4_write)
-{
-        switch(A&0xE001)
-       {
-         case 0x8000:
-          if((V&0x40) != (MMC3_cmd&0x40))
-          FixMMC3PRG(V);
-          if((V&0x80) != (MMC3_cmd&0x80))
-           FixMMC3CHR(V);
-          MMC3_cmd = V;
-          break;
-
-        case 0x8001:
-                {
-                 int cbase=(MMC3_cmd&0x80)<<5;
-                 DRegBuf[MMC3_cmd&0x7]=V;
-                 switch(MMC3_cmd&0x07)
-                 {
-                  case 0: cwrap((cbase^0x000),V&(~1));
-                         cwrap((cbase^0x400),V|1);
-                         break;
-                  case 1: cwrap((cbase^0x800),V&(~1));
-                         cwrap((cbase^0xC00),V|1);
-                         break;
-                  case 2: cwrap(cbase^0x1000,V); break;
-                  case 3: cwrap(cbase^0x1400,V); break;
-                  case 4: cwrap(cbase^0x1800,V); break;
-                  case 5: cwrap(cbase^0x1C00,V); break;
-                  case 6: if (MMC3_cmd&0x40) pwrap(0xC000,V);
-                          else pwrap(0x8000,V);
-                          X6502_Rebase();
-                          break;
-                  case 7: pwrap(0xA000,V);
-                          X6502_Rebase();
-                          break;
-                 }
-                }
-                break;
-
-        case 0xA000:
-               if(mwrap) mwrap(V&1);
-                break;
-       case 0xA001:
-               A001B=V;
-               break;
- }
-}
-
-static void MMC3_hb(void)
-{
-      resetmode=0;
-      if(IRQCount>=0)
-      {
-        IRQCount--;
-        if(IRQCount<0)
-        {
-        //printf("IRQ: %d\n",scanline);
-         if(IRQa)
-         X6502_IRQBegin(FCEU_IQEXT);
-        }
-      }
-}
-static int isines;
-
-static void genmmc3restore(int version)
-{
- if(version>=56)
- {
-  mwrap(A000B&1);
-  FixMMC3PRG(MMC3_cmd);
-  FixMMC3CHR(MMC3_cmd);
- }
- else if(isines)
-  iNESStateRestore(version);
-}
-
-static void GENCWRAP(uint32 A, uint8 V)
-{
- setchr1(A,V);
-}
-
-static void GENPWRAP(uint32 A, uint8 V)
-{
- setprg8(A,V&0x3F);
-}
-
-static void GENMWRAP(uint8 V)
-{
- A000B=V;
- setmirror(V^1);
-}
-
-static void GENNOMWRAP(uint8 V)
-{
- A000B=V;
-}
-
-static void genmmc3ii(void (*PW)(uint32 A, uint8 V),
-                     void (*CW)(uint32 A, uint8 V),
-                     void (*MW)(uint8 V))
-{
- pwrap=GENPWRAP;
- cwrap=GENCWRAP;
- mwrap=GENMWRAP;
- if(PW) pwrap=PW;
- if(CW) cwrap=CW;
- if(MW) mwrap=MW;
- A000B=(Mirroring&1)^1; // For hard-wired mirroring on some MMC3 games.
-                        // iNES format needs to die or be extended...
- mmc3opts=0;
- SetWriteHandler(0x8000,0xBFFF,Mapper4_write);
- SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
-
- GameHBIRQHook=MMC3_hb;
- GameStateRestore=genmmc3restore;
- if(!VROM_size)
-  SetupCartCHRMapping(0, CHRRAM, 8192, 1);
- isines=1;
- MMC3RegReset();
- MapperReset=MMC3RegReset;
-}
-
-void Mapper4_init(void)
-{
- genmmc3ii(0,0,0);
-}
-
-static void M47PW(uint32 A, uint8 V)
-{
- V&=0xF;
- V|=PIRREGS[0]<<4;
- setprg8(A,V);
-}
-
-static void M47CW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- NV&=0x7F;
- NV|=PIRREGS[0]<<7;
- setchr1(A,NV);
-}
-
-static DECLFW(M47Write)
-{
- PIRREGS[0]=V&1;
- FixMMC3PRG(MMC3_cmd);
- FixMMC3CHR(MMC3_cmd);
-}
-
-void Mapper47_init(void)
-{
- genmmc3ii(M47PW,M47CW,0);
- SetWriteHandler(0x6000,0x7FFF,M47Write);
- SetReadHandler(0x6000,0x7FFF,0);
-}
-
-static void M44PW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- if(PIRREGS[0]>=6) NV&=0x1F;
- else NV&=0x0F;
- NV|=PIRREGS[0]<<4;
- setprg8(A,NV);
-}
-static void M44CW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- if(PIRREGS[0]<6) NV&=0x7F;
- NV|=PIRREGS[0]<<7;
- setchr1(A,NV);
-}
-
-static DECLFW(Mapper44_write)
-{
- if(A&1)
- {
-  PIRREGS[0]=V&7;
-  FixMMC3PRG(MMC3_cmd);
-  FixMMC3CHR(MMC3_cmd);
- }
- else
-  Mapper4_write(A,V);
-}
-
-void Mapper44_init(void)
-{
- genmmc3ii(M44PW,M44CW,0);
- SetWriteHandler(0xA000,0xBFFF,Mapper44_write);
-}
-
-static void M52PW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- NV&=0x1F^((PIRREGS[0]&8)<<1);
- NV|=((PIRREGS[0]&6)|((PIRREGS[0]>>3)&PIRREGS[0]&1))<<4;
- setprg8(A,NV);
-}
-
-static void M52CW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- NV&=0xFF^((PIRREGS[0]&0x40)<<1);
- NV|=(((PIRREGS[0]>>3)&4)|((PIRREGS[0]>>1)&2)|((PIRREGS[0]>>6)&(PIRREGS[0]>>4)&1))<<7;
- setchr1(A,NV);
-}
-
-static DECLFW(Mapper52_write)
-{
- if(PIRREGS[1])
- {
-  (WRAM-0x6000)[A]=V;
-  return;
- }
- PIRREGS[1]=1;
- PIRREGS[0]=V;
- FixMMC3PRG(MMC3_cmd);
- FixMMC3CHR(MMC3_cmd);
-}
-
-static void M52Reset(void)
-{
- PIRREGS[0]=PIRREGS[1]=0;
- MMC3RegReset();
-}
-
-void Mapper52_init(void)
-{
- genmmc3ii(M52PW,M52CW,0);
- SetWriteHandler(0x6000,0x7FFF,Mapper52_write);
- MapperReset=M52Reset;
-}
-
-static void M45CW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- if(PIRREGS[2]&8)
-  NV&=(1<<( (PIRREGS[2]&7)+1 ))-1;
- else
-  NV&=0;
- NV|=PIRREGS[0]|((PIRREGS[2]&0x10)<<4);
- setchr1(A,NV);
-}
-
-static void M45PW(uint32 A, uint8 V)
-{
- V&=(PIRREGS[3]&0x3F)^0x3F;
- V|=PIRREGS[1];
- setprg8(A,V);
-}
-
-static DECLFW(Mapper45_write)
-{
- if(PIRREGS[3]&0x40) return;
- PIRREGS[PIRREGS[4]]=V;
- PIRREGS[4]=(PIRREGS[4]+1)&3;
- FixMMC3PRG(MMC3_cmd);
- FixMMC3CHR(MMC3_cmd);
-}
-
-static void M45Reset(void)
-{
- FCEU_dwmemset(PIRREGS,0,5);
- MMC3RegReset();
-}
-
-void Mapper45_init(void)
-{
- genmmc3ii(M45PW,M45CW,0);
- SetWriteHandler(0x6000,0x7FFF,Mapper45_write);
- SetReadHandler(0x6000,0x7FFF,0);
- MapperReset=M45Reset;
-}
-static void M49PW(uint32 A, uint8 V)
-{
- if(PIRREGS[0]&1)
- {
-  V&=0xF;
-  V|=(PIRREGS[0]&0xC0)>>2;
-  setprg8(A,V);
- }
- else
- {
-  setprg32(0x8000,(PIRREGS[0]>>4)&3);
-  X6502_Rebase();
- }
-}
-
-static void M49CW(uint32 A, uint8 V)
-{
- uint32 NV=V;
- NV&=0x7F;
- NV|=(PIRREGS[0]&0xC0)<<1;
- setchr1(A,NV);
-}
-
-static DECLFW(M49Write)
-{
- //printf("$%04x:$%02x\n",A,V);
- if(A001B&0x80)
- {
-  PIRREGS[0]=V;
-  FixMMC3PRG(MMC3_cmd);
-  FixMMC3CHR(MMC3_cmd);
- }
-}
-
-static void M49Reset(void)
-{
- PIRREGS[0]=0;
- MMC3RegReset();
-}
-
-void Mapper49_init(void)
-{
- genmmc3ii(M49PW,M49CW,0);
- SetWriteHandler(0x6000,0x7FFF,M49Write);
- SetReadHandler(0x6000,0x7FFF,0);
- MapperReset=M49Reset;
-}
-
-static DECLFW(Mapper250_write)
-{
-       Mapper4_write((A&0xE000)|((A&0x400)>>10),A&0xFF);
-}
-
-static DECLFW(M250_IRQWrite)
-{
-       MMC3_IRQWrite((A&0xE000)|((A&0x400)>>10),A&0xFF);
-}
-
-void Mapper250_init(void)
-{
- genmmc3ii(0,0,0);
- SetWriteHandler(0x8000,0xBFFF,Mapper250_write);
- SetWriteHandler(0xC000,0xFFFF,M250_IRQWrite);
-}
-
-static void FP_FASTAPASS(1) TKSPPU(uint32 A)
-{
- //static uint8 z;
- //if(A>=0x2000 || type<0) return;
- //if(type<0) return;
- A&=0x1FFF;
- //if(scanline>=140 && scanline<=200) {setmirror(MI_1);return;}
- //if(scanline>=140 && scanline<=200)
- // if(scanline>=190 && scanline<=200) {setmirror(MI_1);return;}
- // setmirror(MI_1);
- //printf("$%04x\n",A);
-
- A>>=10;
- PPUCHRBus=A;
- setmirror(MI_0+TKSMIR[A]);
-}
-
-static void TKSWRAP(uint32 A, uint8 V)
-{
- TKSMIR[A>>10]=V>>7;
- setchr1(A,V&0x7F);
- if(PPUCHRBus==(A>>10))
-  setmirror(MI_0+(V>>7));
-}
-
-void Mapper118_init(void)
-{
-  genmmc3ii(0,TKSWRAP,GENNOMWRAP);
-  PPU_hook=TKSPPU;
-}
-
-static void TQWRAP(uint32 A, uint8 V)
-{
- setchr1r((V&0x40)>>2,A,V&0x3F);
-}
-
-void Mapper119_init(void)
-{
-  genmmc3ii(0,TQWRAP,0);
-  SetupCartCHRMapping(0x10, CHRRAM, 8192, 1);
-}
-
-static int wrams;
-
-static void GenMMC3Close(void)
-{
- UNIFOpenWRAM(UOW_WR,0,1);
- UNIFWriteWRAM(WRAM,wrams);
- UNIFCloseWRAM();
-}
-
-static DECLFW(MBWRAM)
-{
-  (WRAM-0x6000)[A]=V;
-}
-
-static DECLFR(MAWRAM)
-{
- return((WRAM-0x6000)[A]);
-}
-
-static DECLFW(MBWRAMMMC6)
-{
- WRAM[A&0x3ff]=V;
-}
-
-static DECLFR(MAWRAMMMC6)
-{
- return(WRAM[A&0x3ff]);
-}
-
-static void GenMMC3Power(void)
-{
- SetWriteHandler(0x8000,0xBFFF,Mapper4_write);
- SetReadHandler(0x8000,0xFFFF,CartBR);
- SetWriteHandler(0xC000,0xFFFF,MMC3_IRQWrite);
-
- if(mmc3opts&1)
- {
-  if(wrams==1024)
-  {
-   FCEU_CheatAddRAM(1,0x7000,WRAM);
-   SetReadHandler(0x7000,0x7FFF,MAWRAMMMC6);
-   SetWriteHandler(0x7000,0x7FFF,MBWRAMMMC6);
-  }
-  else
-  {
-   FCEU_CheatAddRAM(wrams/1024,0x6000,WRAM);
-   SetReadHandler(0x6000,0x6000+wrams-1,MAWRAM);
-   SetWriteHandler(0x6000,0x6000+wrams-1,MBWRAM);
-  }
-  if(!(mmc3opts&2))
-   FCEU_dwmemset(WRAM,0,wrams);
- }
- MMC3RegReset();
-}
-
-void GenMMC3_Init(int prg, int chr, int wram, int battery)
-{
- pwrap=GENPWRAP;
- cwrap=GENCWRAP;
- mwrap=GENMWRAP;
-
- wrams=wram*1024;
-
- PRGmask8[0]&=(prg>>13)-1;
- CHRmask1[0]&=(chr>>10)-1;
- CHRmask2[0]&=(chr>>11)-1;
-
- if(wram)
- {
-  mmc3opts|=1;
-  AddExState(WRAM, wram*1024, 0, "WRAM");
- }
-
- if(battery)
- {
-  mmc3opts|=2;
-  BoardClose=GenMMC3Close;
-
-  UNIFOpenWRAM(UOW_RD,0,1);
-  UNIFReadWRAM(WRAM,wram*1024);
-  UNIFCloseWRAM();
- }
-
- if(!chr)
- {
-  CHRmask1[0]=7;
-  CHRmask2[0]=3;
-  SetupCartCHRMapping(0, CHRRAM, 8192, 1);
-  AddExState(CHRRAM, 8192, 0, "CHRR");
- }
- AddExState(mapbyte1, 32, 0, "MPBY");
- AddExState(&IRQa, 1, 0, "IRQA");
- AddExState(&IRQCount, 4, 1, "IRQC");
- AddExState(&IRQLatch, 4, 1, "IQL1");
-
- BoardPower=GenMMC3Power;
- BoardReset=MMC3RegReset;
-
- GameHBIRQHook=MMC3_hb;
- GameStateRestore=genmmc3restore;
- isines=0;
-}
-
-// void GenMMC3_Init(int prg, int chr, int wram, int battery)
-
-void TFROM_Init(void)
-{
- GenMMC3_Init(512, 64, 0, 0);
-}
-
-void TGROM_Init(void)
-{
- GenMMC3_Init(512, 0, 0, 0);
-}
-
-void TKROM_Init(void)
-{
- GenMMC3_Init(512, 256, 8, 1);
-}
-
-void TLROM_Init(void)
-{
- GenMMC3_Init(512, 256, 0, 0);
-}
-
-void TSROM_Init(void)
-{
- GenMMC3_Init(512, 256, 8, 0);
-}
-
-void TLSROM_Init(void)
-{
- GenMMC3_Init(512, 256, 8, 0);
- cwrap=TKSWRAP;
- mwrap=GENNOMWRAP;
-}
-
-void TKSROM_Init(void)
-{
- GenMMC3_Init(512, 256, 8, 1);
- cwrap=TKSWRAP;
- mwrap=GENNOMWRAP;
-}
-
-void TQROM_Init(void)
-{
- GenMMC3_Init(512, 64, 0, 0);
- cwrap=TQWRAP;
-}
-
-/* MMC6 board */
-void HKROM_Init(void)
-{
- GenMMC3_Init(512, 512, 1, 1);
-}
diff --git a/mbshare/mmc5.c b/mbshare/mmc5.c
deleted file mode 100644 (file)
index 219ae77..0000000
+++ /dev/null
@@ -1,763 +0,0 @@
-/* FCE Ultra - NES/Famicom Emulator
- *
- * Copyright notice for this file:
- *  Copyright (C) 2002 Ben Parnell
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-/* None of this code should use any of the iNES bank switching wrappers. */
-
-#include "mapinc.h"
-
-void MMC5Sound(int Count);
-void Do5SQ(int P);
-
-static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V)
-{
- if(CHRptr[0])
- {
-  V&=CHRmask1[0];
-  MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);
- }
-}
-
-static INLINE void MMC5BGVROM_BANK1(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask1[0];MMC5BGVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A);}}
-
-static INLINE void MMC5SPRVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}}
-static INLINE void MMC5BGVROM_BANK2(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask2[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=&CHRptr[0][(V)<<11]-(A);}}
-
-static INLINE void MMC5SPRVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5SPRVPage[(A)>>10]=MMC5SPRVPage[((A)>>10)+1]= MMC5SPRVPage[((A)>>10)+2]=MMC5SPRVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}}
-static INLINE void MMC5BGVROM_BANK4(uint32 A,uint32 V) {if(CHRptr[0]){V&=CHRmask4[0];MMC5BGVPage[(A)>>10]=MMC5BGVPage[((A)>>10)+1]=MMC5BGVPage[((A)>>10)+2]=MMC5BGVPage[((A)>>10)+3]=&CHRptr[0][(V)<<12]-(A);}}
-
-static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5SPRVPage[0]=MMC5SPRVPage[1]=MMC5SPRVPage[2]=MMC5SPRVPage[3]=MMC5SPRVPage[4]=MMC5SPRVPage[5]=MMC5SPRVPage[6]=MMC5SPRVPage[7]=&CHRptr[0][(V)<<13];}}
-static INLINE void MMC5BGVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC5BGVPage[0]=MMC5BGVPage[1]=MMC5BGVPage[2]=MMC5BGVPage[3]=MMC5BGVPage[4]=MMC5BGVPage[5]=MMC5BGVPage[6]=MMC5BGVPage[7]=&CHRptr[0][(V)<<13];}}
-
-static int32 inc;
-uint8 MMC5fill[0x400] __attribute__ ((aligned (4)));
-
-#define MMC5IRQR        mapbyte3[4]
-#define MMC5LineCounter mapbyte3[5]
-#define mmc5psize mapbyte1[0]
-#define mmc5vsize mapbyte1[1]
-
-uint8 MMC5WRAMsize;
-uint8 MMC5WRAMIndex[8];
-
-uint8 MMC5ROMWrProtect[4];
-uint8 MMC5MemIn[5];
-
-static void MMC5CHRA(void);
-static void MMC5CHRB(void);
-
-typedef struct __cartdata {
-        unsigned long crc32;
-        unsigned char size;
-} cartdata;
-
-
-// ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB
-// EWROM seems to have 32KB of WRAM
-
-#define MMC5_NOCARTS 14
-cartdata MMC5CartList[MMC5_NOCARTS]=
-{
- {0x9c18762b,2},         /* L'Empereur */
- {0x26533405,2},
- {0x6396b988,2},
-
- {0xaca15643,2},        /* Uncharted Waters */
- {0xfe3488d1,2},        /* Dai Koukai Jidai */
-
- {0x15fe6d0f,2},        /* BKAC             */
- {0x39f2ce4b,2},        /* Suikoden              */
-
- {0x8ce478db,2},        /* Nobunaga's Ambition 2 */
- {0xeee9a682,2},
-
- {0x1ced086f,2},       /* Ishin no Arashi */
-
- {0xf540677b,4},        /* Nobunaga...Bushou Fuuun Roku */
-
- {0x6f4e4312,4},        /* Aoki Ookami..Genchou */
-
- {0xf011e490,4},        /* Romance of the 3 Kingdoms 2 */
- {0x184c2124,4},        /* Sangokushi 2 */
-};
-
-
-// Called by iNESLoad()
-void DetectMMC5WRAMSize(void)
-{
- int x;
-
- MMC5WRAMsize=1;
-
- for(x=0;x<MMC5_NOCARTS;x++)
-  if(iNESGameCRC32==MMC5CartList[x].crc32)
-   {
-   MMC5WRAMsize=MMC5CartList[x].size;
-   break;
-   }
-}
-
-static void BuildWRAMSizeTable(void)
-{
- int x;
-
- for(x=0;x<8;x++)
- {
-  switch(MMC5WRAMsize)
-  {
-    default:
-    case 1:MMC5WRAMIndex[x]=(x>3)?255:0;break;
-    case 2:MMC5WRAMIndex[x]=(x&4)>>2;break;
-    case 4:MMC5WRAMIndex[x]=(x>3)?255:(x&3);break;
-  }
- }
-}
-
-static void MMC5CHRA(void)
-{
-       int x;
-       switch(mapbyte1[1]&3)
-       {
-        case 0:MMC5SPRVROM_BANK8(mapbyte2[7]);
-               setchr8(mapbyte2[7]);
-               break;
-        case 1:MMC5SPRVROM_BANK4(0x0000,mapbyte2[3]);
-               MMC5SPRVROM_BANK4(0x1000,mapbyte2[7]);
-               setchr4(0x0000,mapbyte2[3]);
-               setchr4(0x1000,mapbyte2[7]);
-               break;
-        case 2:MMC5SPRVROM_BANK2(0x0000,mapbyte2[1]);
-               MMC5SPRVROM_BANK2(0x0800,mapbyte2[3]);
-               MMC5SPRVROM_BANK2(0x1000,mapbyte2[5]);
-               MMC5SPRVROM_BANK2(0x1800,mapbyte2[7]);
-               setchr2(0x0000,mapbyte2[1]);
-               setchr2(0x0800,mapbyte2[3]);
-               setchr2(0x1000,mapbyte2[5]);
-               setchr2(0x1800,mapbyte2[7]);
-               break;
-        case 3:
-               for(x=0;x<8;x++)
-               {
-                setchr1(x<<10,mapbyte2[x]);
-                MMC5SPRVROM_BANK1(x<<10,mapbyte2[x]);
-               }
-               break;
- }
-}
-
-static void MMC5CHRB(void)
-{
-int x;
-switch(mapbyte1[1]&3)
- {
- case 0:MMC5BGVROM_BANK8(mapbyte3[3]);
-        setchr8(mapbyte3[3]);
-        break;
- case 1:
-        MMC5BGVROM_BANK4(0x0000,mapbyte3[3]);
-        MMC5BGVROM_BANK4(0x1000,mapbyte3[3]);
-        setchr4(0x0000,mapbyte3[3]);
-        setchr4(0x1000,mapbyte3[3]);
-        break;
- case 2:MMC5BGVROM_BANK2(0x0000,mapbyte3[1]);
-        MMC5BGVROM_BANK2(0x0800,mapbyte3[3]);
-        MMC5BGVROM_BANK2(0x1000,mapbyte3[1]);
-        MMC5BGVROM_BANK2(0x1800,mapbyte3[3]);
-        setchr2(0x0000,mapbyte3[1]);
-        setchr2(0x0800,mapbyte3[3]);
-        setchr2(0x1000,mapbyte3[1]);
-        setchr2(0x1800,mapbyte3[3]);
-        break;
- case 3:
-        for(x=0;x<8;x++)
-       {
-        setchr1(x<<10,mapbyte3[x&3]);
-         MMC5BGVROM_BANK1(x<<10,mapbyte3[x&3]);
-       }
-        break;
- }
-}
-
-static void FASTAPASS(2) MMC5WRAM(uint32 A, uint32 V)
-{
-   V=MMC5WRAMIndex[V&7];
-   if(V!=255)
-   {
-    setprg8r(0x10,A,V);
-    MMC5MemIn[(A-0x6000)>>13]=1;
-   }
-   else
-    MMC5MemIn[(A-0x6000)>>13]=0;
-}
-
-static void MMC5PRG(void)
-{
- int x;
-
- switch(mapbyte1[0]&3)
-  {
-  case 0:
-           MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=
-           MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1;
-           setprg32(0x8000,((mapbyte1[5]&0x7F)>>2));
-           X6502_Rebase();
-          for(x=0;x<4;x++)
-           MMC5MemIn[1+x]=1;
-           break;
-  case 1:
-         if(mapbyte1[5]&0x80)
-          {
-           MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1;
-           setprg16(0x8000,(mapbyte1[5]>>1));
-          MMC5MemIn[1]=MMC5MemIn[2]=1;
-          }
-         else
-          {
-           MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0;
-           MMC5WRAM(0x8000,mapbyte1[5]&7&0xFE);
-           MMC5WRAM(0xA000,(mapbyte1[5]&7&0xFE)+1);
-          }
-         MMC5MemIn[3]=MMC5MemIn[4]=1;
-          MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1;
-          setprg16(0xC000,(mapbyte1[7]&0x7F)>>1);
-         break;
-  case 2:
-         if(mapbyte1[5]&0x80)
-          {
-          MMC5MemIn[1]=MMC5MemIn[2]=1;
-           MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1;
-           setprg16(0x8000,(mapbyte1[5]&0x7F)>>1);
-          }
-         else
-          {
-           MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0;
-           MMC5WRAM(0x8000,mapbyte1[5]&7&0xFE);
-           MMC5WRAM(0xA000,(mapbyte1[5]&7&0xFE)+1);
-          }
-         if(mapbyte1[6]&0x80)
-          {MMC5ROMWrProtect[2]=1;MMC5MemIn[3]=1;setprg8(0xC000,mapbyte1[6]&0x7F);}
-         else
-          {MMC5ROMWrProtect[2]=0;MMC5WRAM(0xC000,mapbyte1[6]&7);}
-        MMC5MemIn[4]=1;
-         MMC5ROMWrProtect[3]=1;
-         setprg8(0xE000,mapbyte1[7]&0x7F);
-         break;
-  case 3:
-        for(x=0;x<3;x++)
-         if(mapbyte1[4+x]&0x80)
-         {
-          MMC5ROMWrProtect[0]=1;
-          setprg8(0x8000+(x<<13),mapbyte1[4+x]&0x7F);
-          MMC5MemIn[1+x]=1;
-         }
-         else
-         {
-          MMC5ROMWrProtect[0]=0;
-          MMC5WRAM(0x8000+(x<<13),mapbyte1[4+x]&7);
-         }
-        MMC5MemIn[4]=1;
-         MMC5ROMWrProtect[3]=1;
-         setprg8(0xE000,mapbyte1[7]&0x7F);
-         break;
-  }
-}
-
-#define mul1 mapbyte3[6]
-#define mul2 mapbyte3[7]
-
-static DECLFW(Mapper5_write)
-{
- switch(A)
-  {
-   default:break;
-   case 0x5105:
-                {
-                int x;
-                for(x=0;x<4;x++)
-                {
-                 switch((V>>(x<<1))&3)
-                 {
-                  case 0:PPUNTARAM|=1<<x;vnapage[x]=NTARAM;break;
-                  case 1:PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;
-                  case 2:PPUNTARAM|=1<<x;vnapage[x]=MapperExRAM+0x6000;break;
-                  case 3:PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;
-                 }
-                }
-               }
-               mapbyte4[3]=V;
-               break;
-
-   case 0x5113:mapbyte4[6]=V;MMC5WRAM(0x6000,V&7);
-               X6502_Rebase();break;
-   case 0x5100:mapbyte1[0]=V;MMC5PRG();
-               X6502_Rebase();break;
-   case 0x5101:mapbyte1[1]=V;
-               if(!mapbyte4[7])
-                {MMC5CHRB();MMC5CHRA();}
-               else
-                {MMC5CHRA();MMC5CHRB();}
-               break;
-
-   case 0x5114:
-   case 0x5115:
-   case 0x5116:
-   case 0x5117:
-               mapbyte1[A&7]=V;MMC5PRG();
-               X6502_Rebase();break;
-
-   case 0x5120:
-   case 0x5121:
-   case 0x5122:
-   case 0x5123:
-   case 0x5124:
-   case 0x5125:
-   case 0x5126:
-   case 0x5127:mapbyte4[7]=0;
-               mapbyte2[A&7]=V;MMC5CHRA();break;
-   case 0x5128:
-   case 0x5129:
-   case 0x512a:
-   case 0x512b:mapbyte4[7]=1;
-               mapbyte3[A&3]=V;MMC5CHRB();break;
-   case 0x5102:mapbyte4[0]=V;break;
-   case 0x5103:mapbyte4[1]=V;break;
-   case 0x5104:mapbyte4[2]=V;MMC5HackCHRMode=V&3;break;
-   case 0x5106:if(V!=mapbyte4[4])
-               {
-               uint32 t;
-               t=V|(V<<8)|(V<<16)|(V<<24);
-                FCEU_dwmemset(MMC5fill,t,0x3c0);
-               }
-               mapbyte4[4]=V;
-               break;
-   case 0x5107:if(V!=mapbyte4[5])
-               {
-                unsigned char moop;
-                uint32 t;
-                moop=V|(V<<2)|(V<<4)|(V<<6);
-               t=moop|(moop<<8)|(moop<<16)|(moop<<24);
-                FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);
-               }
-               mapbyte4[5]=V;
-               break;
-   case 0x5200:MMC5HackSPMode=V;break;
-   case 0x5201:MMC5HackSPScroll=(V>>3)&0x1F;break;
-   case 0x5202:MMC5HackSPPage=V&0x3F;break;
-   case 0x5203:X6502_IRQEnd(FCEU_IQEXT);IRQCount=V;break;
-   case 0x5204:X6502_IRQEnd(FCEU_IQEXT);IRQa=V&0x80;break;
-   case 0x5205:mul1=V;break;
-   case 0x5206:mul2=V;break;
-  }
-}
-
-DECLFR(MMC5_ReadROMRAM)
-{
-       if(MMC5MemIn[(A-0x6000)>>13])
-         return Page[A>>11][A];
-       else
-        return X.DB;
-}
-
-DECLFW(MMC5_WriteROMRAM)
-{
-       if(A>=0x8000)
-        if(MMC5ROMWrProtect[(A-0x8000)>>13])
-         return;
-       if(MMC5MemIn[(A-0x6000)>>13])
-        if(((mapbyte4[0]&3)|((mapbyte4[1]&3)<<2)) == 6)
-         Page[A>>11][A]=V;
-}
-
-static DECLFW(MMC5_ExRAMWr)
-{
- if(MMC5HackCHRMode!=3)
-  (MapperExRAM+0x6000)[A&0x3ff]=V;
-}
-
-static DECLFR(MMC5_ExRAMRd)
-{
- /* Not sure if this is correct, so I'll comment it out for now. */
- //if(MMC5HackCHRMode>=2)
-  return (MapperExRAM+0x6000)[A&0x3ff];
- //else
- // return(X.DB);
-}
-
-static DECLFR(MMC5_read)
-{
- switch(A)
- {
-  //default:printf("$%04x\n",A);break;
-  case 0x5204:X6502_IRQEnd(FCEU_IQEXT);
-              {
-               uint8 x;
-               x=MMC5IRQR;
-               MMC5IRQR&=0x40;
-               return x;
-             }
-  case 0x5205:return (mul1*mul2);
-  case 0x5206:return ((mul1*mul2)>>8);
- }
- return(X.DB);
-}
-
-uint8 dorko[0x400];
-
-void MMC5Synco(void)
-{
- int x;
-
- MMC5PRG();
- for(x=0;x<4;x++)
- {
-  switch((mapbyte4[3]>>(x<<1))&3)
-   {
-    case 0:PPUNTARAM|=1<<x;vnapage[x]=NTARAM;break;
-    case 1:PPUNTARAM|=1<<x;vnapage[x]=NTARAM+0x400;break;
-    case 2:PPUNTARAM|=1<<x;vnapage[x]=MapperExRAM+0x6000;break;
-    case 3:PPUNTARAM&=~(1<<x);vnapage[x]=MMC5fill;break;
-   }
- }
- MMC5WRAM(0x6000,mapbyte4[6]&7);
- if(!mapbyte4[7])
- {
-  MMC5CHRB();
-  MMC5CHRA();
- }
- else
- {
-   MMC5CHRA();
-   MMC5CHRB();
- }
-  {
-    uint32 t;
-    t=mapbyte4[4]|(mapbyte4[4]<<8)|(mapbyte4[4]<<16)|(mapbyte4[4]<<24);
-    FCEU_dwmemset(MMC5fill,t,0x3c0);
-  }
-  {
-   unsigned char moop;
-   uint32 t;
-   moop=mapbyte4[5]|(mapbyte4[5]<<2)|(mapbyte4[5]<<4)|(mapbyte4[5]<<6);
-   t=moop|(moop<<8)|(moop<<16)|(moop<<24);
-   FCEU_dwmemset(MMC5fill+0x3c0,t,0x40);
-  }
-  X6502_IRQEnd(FCEU_IQEXT);
-  MMC5HackCHRMode=mapbyte4[2]&3;
-  X6502_Rebase();
-}
-
-void MMC5_hbo(void)
-{
-  if(scanline==0)
-   MMC5LineCounter=0;
-
-  if(MMC5LineCounter<245)
-  {
-   MMC5LineCounter++;
-   if(MMC5LineCounter==IRQCount) MMC5IRQR|=0x80;
-   if((MMC5LineCounter==IRQCount && IRQa&0x80))
-    X6502_IRQBegin(FCEU_IQEXT);
-  }
-  if(MMC5LineCounter>=239)
-    MMC5IRQR|=0x40;
-}
-
-void MMC5_hb(void)
-{
-  if(scanline==240)
-  {
-   MMC5LineCounter=0;
-   MMC5IRQR=0x40;
-   return;
-  }
-
-  if(MMC5LineCounter<240)
-  {
-   MMC5LineCounter++;
-   if(MMC5LineCounter==IRQCount)
-   {
-    MMC5IRQR|=0x80;
-    if(IRQa&0x80)
-     X6502_IRQBegin(FCEU_IQEXT);
-   }
-  }
-//  printf("%d:%d\n",MMC5LineCounter,scanline);
- if(MMC5LineCounter==240)
-   MMC5IRQR=0;
-}
-
-void Mapper5_StateRestore(int version)
-{
- if(version<=70)
- {
-  uint8 tmp[8192];
-
-  FCEU_memmove(tmp,MapperExRAM,8192);
-  FCEU_memmove(MapperExRAM,MapperExRAM+8192,16384+8192);
-  FCEU_memmove(MapperExRAM+16384+8192,tmp,8192);
- }
- MMC5Synco();
-}
-
-#define MMC5PSG         (MapperExRAM+0x640B+8)
-
-static int C5BC[3]={0,0,0};
-
-static void Do5PCM(void)
-{
-   int32 V;
-   int32 start,end;
-
-   start=C5BC[2];
-   end=(SOUNDTS<<16)/soundtsinc;
-   if(end<=start) return;
-   C5BC[2]=end;
-
-   if(!(MMC5PSG[0x10]&0x40) && MMC5PSG[0x11])
-    for(V=start;V<end;V++)
-     Wave[V>>4]+=MMC5PSG[0x11]<<2;
-}
-
-DECLFW(Mapper5_SW)
-{
- GameExpSound.Fill=MMC5Sound;
- A&=0x1F;
-
- switch(A)
- {
-  case 0x10:
-  case 0x11:Do5PCM();break;
-
-  case 0x0:Do5SQ(0);break;
-  case 0x2:Do5SQ(0);break;
-  case 0x3:Do5SQ(0);break;
-  case 0x4:Do5SQ(1);break;
-  case 0x6:Do5SQ(1);break;
-  case 0x7:Do5SQ(1);break;
-  case 0x15:
-         {
-          int t=V^MMC5PSG[0x15];
-           if(t&1)
-            Do5SQ(0);
-           if(t&2)
-            Do5SQ(1);
-         }
-          break;
- }
- MMC5PSG[A]=V;
-}
-
-static int32 vcount[2];
-void Do5SQ(int P)
-{
-    int32 start,end;
-    int V;
-    int32 freq;
-
-    start=C5BC[P];
-    end=(SOUNDTS<<16)/soundtsinc;
-    if(end<=start) return;
-    C5BC[P]=end;
-
-
-
-    if(MMC5PSG[0x15]&(P+1))
-    {
-     unsigned long dcycs;
-     unsigned char amplitude;
-     long vcoo;
-
-     freq=(((MMC5PSG[(P<<2)+0x2]|((MMC5PSG[(P<<2)+0x3]&7)<<8))));
-
-     if(freq<8) goto mmc5enda;
-     freq+=1;
-     inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/((long double)PSG_base/freq);
-
-     switch(MMC5PSG[P<<2]&0xC0)
-     {
-     default:
-     case 0x00:dcycs=inc>>3;break;
-     case 0x40:dcycs=inc>>2;break;
-     case 0x80:dcycs=inc>>1;break;
-     case 0xC0:dcycs=(inc+inc+inc)>>2;break;
-     }
-
-      amplitude=(MMC5PSG[P<<2]&15)<<4;
-
-      vcoo=vcount[P];
-             for(V=start;V<end;V++)
-              {
-               if(vcoo<dcycs)
-                Wave[V>>4]+=amplitude;
-               vcoo+=0x1000;
-               if(vcoo>=inc) vcoo-=inc;
-               }
-      vcount[P]=vcoo;
-    }
-  mmc5enda:; // semi-colon must be here for MSVC
-}
-
-void MMC5Sound(int Count)
-{
-  int x;
-  Do5SQ(0);
-  Do5SQ(1);
-  Do5PCM();
-  for(x=0;x<3;x++)
-   C5BC[x]=Count;
-}
-
-static void MMC5SoundC(void)
-{
- if(FSettings.SndRate)
-  Mapper5_ESI();
- else
-  SetWriteHandler(0x5000,0x5015,0);
-}
-
-void Mapper5_ESI(void)
-{
- GameExpSound.RChange=MMC5SoundC;
-
- if(FSettings.SndRate)
- {
-  SetWriteHandler(0x5000,0x5015,Mapper5_SW);
-  SetWriteHandler(0x5205,0x5206,Mapper5_write);
-  SetReadHandler(0x5205,0x5206,MMC5_read);
- }
- if(FCEUGameInfo.type==GIT_NSF)
- {
-  SetWriteHandler(0x5c00,0x5fef,MMC5_ExRAMWr);
-  SetReadHandler(0x5c00,0x5fef,MMC5_ExRAMRd);
-  MMC5HackCHRMode=2;
- }
- else
-  GameHBIRQHook=MMC5_hb;
-}
-
-static void GenMMC5Reset(void)
-{
- mapbyte1[4]=mapbyte1[5]=mapbyte1[6]=mapbyte1[7]=~0;
- mapbyte1[0]=mapbyte1[1]=3;
- mapbyte4[2]=0;
-
- mapbyte4[3]=mapbyte4[4]=mapbyte4[5]=0xFF;
-
- MMC5Synco();
-
- SetWriteHandler(0x4020,0x5bff,Mapper5_write);
- SetReadHandler(0x4020,0x5bff,MMC5_read);
-
- SetWriteHandler(0x5c00,0x5fff,MMC5_ExRAMWr);
- SetReadHandler(0x5c00,0x5fff,MMC5_ExRAMRd);
-
- SetWriteHandler(0x6000,0xFFFF,MMC5_WriteROMRAM);
- SetReadHandler(0x6000,0xFFFF,MMC5_ReadROMRAM);
-
- Mapper5_ESI();
-
- GameHBIRQHook=MMC5_hb;
- FCEU_CheatAddRAM(8,0x6000,WRAM);
- FCEU_CheatAddRAM(1,0x5c00,MapperExRAM+0x6000);
-}
-
-void Mapper5_init(void)
-{
- AddExState(&MMC5HackSPMode, 1, 0, "SPLM");
- AddExState(&MMC5HackSPScroll, 1, 0, "SPLS");
- AddExState(&MMC5HackSPPage, 1, 0, "SPLP");
- SetupCartPRGMapping(0x10,WRAM,32768,1);
- GenMMC5Reset();
- BuildWRAMSizeTable();
- GameStateRestore=Mapper5_StateRestore;
-}
-
-static int m5boo;
-static void GenMMC5_Close(void)
-{
- UNIFOpenWRAM(UOW_WR,0,1);
- if(m5boo<=16)
-  UNIFWriteWRAM(WRAM,8192);
- else
-  UNIFWriteWRAM(WRAM,32768);
- UNIFCloseWRAM();
-}
-
-static void GenMMC5_Init(int wsize, int battery)
-{
- SetupCartPRGMapping(0x10,WRAM,32768,1);
- AddExState(WRAM, 8192, 0, "WRAM");
- AddExState(MapperExRAM, 32768, 0, "MEXR");
- AddExState(&IRQCount, 4, 1, "IRQC");
- AddExState(&IRQa, 1, 0, "IRQA");
- AddExState(mapbyte1, 32, 0, "MPBY");
- AddExState(&MMC5HackSPMode, 1, 0, "SPLM");
- AddExState(&MMC5HackSPScroll, 1, 0, "SPLS");
- AddExState(&MMC5HackSPPage, 1, 0, "SPLP");
-
- MMC5WRAMsize=wsize/8;
- BuildWRAMSizeTable();
- GameStateRestore=Mapper5_StateRestore;
- BoardPower=GenMMC5Reset;
-
- if(battery)
- {
-  UNIFOpenWRAM(UOW_RD,0,1);
-  if(wsize<=16)
-   UNIFReadWRAM(WRAM,8192);
-  else
-   UNIFReadWRAM(WRAM,32768);
-  UNIFCloseWRAM();
-  BoardClose=GenMMC5_Close;
-  m5boo=wsize;
- }
-
- MMC5HackVROMMask=CHRmask4[0];
- MMC5HackExNTARAMPtr=MapperExRAM+0x6000;
- MMC5Hack=1;
- MMC5HackVROMPTR=CHRptr[0];
- MMC5HackCHRMode=0;
- MMC5HackSPMode=MMC5HackSPScroll=MMC5HackSPPage=0;
-
-}
-
-// ETROM seems to have 16KB of WRAM, ELROM seems to have 8KB
-// EWROM seems to have 32KB of WRAM
-
-// ETROM and EWROM are battery-backed, ELROM isn't.
-
-void ETROM_Init(void)
-{
- GenMMC5_Init(16,1);
-}
-
-void ELROM_Init(void)
-{
- GenMMC5_Init(8,0);
-}
-
-void EWROM_Init(void)
-{
- GenMMC5_Init(32,1);
-}
-
-void EKROM_Init(void)
-{
- GenMMC5_Init(8,1);
-}