X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=boards%2Fmmc5.c;h=daf973fafe3d9c4081afd55e382780c0d197f7db;hb=43725da7349c85fa13e828fdbf20cc7ac8d298d6;hp=d14ca0ebaaf8161871a7a2ed7d6bcfd440adda7c;hpb=d97315ac0bca825d2d50a44453bc5652946e2c67;p=fceu.git diff --git a/boards/mmc5.c b/boards/mmc5.c index d14ca0e..daf973f 100644 --- a/boards/mmc5.c +++ b/boards/mmc5.c @@ -26,15 +26,15 @@ static void (*sfun)(int P); static void (*psfun)(void); void MMC5RunSound(int Count); -//void MMC5RunSoundHQ(void); +void MMC5RunSoundHQ(void); static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) { - if(CHRptr[0]) - { - V&=CHRmask1[0]; - MMC5SPRVPage[(A)>>10]=&CHRptr[0][(V)<<10]-(A); - } + 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);}} @@ -76,183 +76,184 @@ static void MMC5CHRA(void); static void MMC5CHRB(void); typedef struct __cartdata { - uint32 crc32; - uint8 size; + uint32 crc32; + uint8 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]= +cartdata MMC5CartList[]= { - {0x9c18762b,2}, /* L'Empereur */ - {0x26533405,2}, - {0x6396b988,2}, + {0x9c18762b,2}, /* L'Empereur */ + {0x26533405,2}, + {0x6396b988,2}, - {0xaca15643,2}, /* Uncharted Waters */ - {0xfe3488d1,2}, /* Dai Koukai Jidai */ + {0xaca15643,2}, /* Uncharted Waters */ + {0xfe3488d1,2}, /* Dai Koukai Jidai */ - {0x15fe6d0f,2}, /* BKAC */ - {0x39f2ce4b,2}, /* Suikoden */ + {0x15fe6d0f,2}, /* BKAC */ + {0x39f2ce4b,2}, /* Suikoden */ - {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ - {0xeee9a682,2}, + {0x8ce478db,2}, /* Nobunaga's Ambition 2 */ + {0xeee9a682,2}, + {0xf9b4240f,2}, - {0x1ced086f,2}, /* Ishin no Arashi */ + {0x1ced086f,2}, /* Ishin no Arashi */ - {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ + {0xf540677b,4}, /* Nobunaga...Bushou Fuuun Roku */ - {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ + {0x6f4e4312,4}, /* Aoki Ookami..Genchou */ - {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ - {0x184c2124,4}, /* Sangokushi 2 */ + {0xf011e490,4}, /* Romance of the 3 Kingdoms 2 */ + {0x184c2124,4}, /* Sangokushi 2 */ + {0xee8e6553,4}, }; - +#define MMC5_NOCARTS (sizeof(MMC5CartList)/sizeof(MMC5CartList[0])) int DetectMMC5WRAMSize(uint32 crc32) { - int x; - for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); - return(MMC5CartList[x].size*8); - } - return(8); + int x; + for(x=0;x8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); + return(MMC5CartList[x].size*8); + } + return(8); } static void BuildWRAMSizeTable(void) { - int x; - for(x=0;x<8;x++) - { - switch(MMC5WRAMsize) + int x; + for(x=0;x<8;x++) { + switch(MMC5WRAMsize) + { case 0: MMC5WRAMIndex[x]=255; break; case 1: MMC5WRAMIndex[x]=(x>3)?255:0; break; case 2: MMC5WRAMIndex[x]=(x&4)>>2; break; case 4: MMC5WRAMIndex[x]=(x>3)?255:(x&3); break; + } } - } } static void MMC5CHRA(void) { - int x; - switch(mmc5vsize&3) - { + int x; + switch(mmc5vsize&3) + { case 0: setchr8(CHRBanksA[7]); - MMC5SPRVROM_BANK8(CHRBanksA[7]); - break; + MMC5SPRVROM_BANK8(CHRBanksA[7]); + break; case 1: setchr4(0x0000,CHRBanksA[3]); - setchr4(0x1000,CHRBanksA[7]); - MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); - MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); - break; + setchr4(0x1000,CHRBanksA[7]); + MMC5SPRVROM_BANK4(0x0000,CHRBanksA[3]); + MMC5SPRVROM_BANK4(0x1000,CHRBanksA[7]); + break; case 2: setchr2(0x0000,CHRBanksA[1]); - setchr2(0x0800,CHRBanksA[3]); - setchr2(0x1000,CHRBanksA[5]); - setchr2(0x1800,CHRBanksA[7]); - MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); - MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); - MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); - MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); - break; + setchr2(0x0800,CHRBanksA[3]); + setchr2(0x1000,CHRBanksA[5]); + setchr2(0x1800,CHRBanksA[7]); + MMC5SPRVROM_BANK2(0x0000,CHRBanksA[1]); + MMC5SPRVROM_BANK2(0x0800,CHRBanksA[3]); + MMC5SPRVROM_BANK2(0x1000,CHRBanksA[5]); + MMC5SPRVROM_BANK2(0x1800,CHRBanksA[7]); + break; case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksA[x]); - MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); - } - break; - } + { + setchr1(x<<10,CHRBanksA[x]); + MMC5SPRVROM_BANK1(x<<10,CHRBanksA[x]); + } + break; + } } static void MMC5CHRB(void) { - int x; - switch(mmc5vsize&3) - { + int x; + switch(mmc5vsize&3) + { case 0: setchr8(CHRBanksB[3]); - MMC5BGVROM_BANK8(CHRBanksB[3]); - break; + MMC5BGVROM_BANK8(CHRBanksB[3]); + break; case 1: setchr4(0x0000,CHRBanksB[3]); - setchr4(0x1000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); - MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); - break; + setchr4(0x1000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x0000,CHRBanksB[3]); + MMC5BGVROM_BANK4(0x1000,CHRBanksB[3]); + break; case 2: setchr2(0x0000,CHRBanksB[1]); - setchr2(0x0800,CHRBanksB[3]); - setchr2(0x1000,CHRBanksB[1]); - setchr2(0x1800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); - MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); - MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); - break; + setchr2(0x0800,CHRBanksB[3]); + setchr2(0x1000,CHRBanksB[1]); + setchr2(0x1800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x0000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x0800,CHRBanksB[3]); + MMC5BGVROM_BANK2(0x1000,CHRBanksB[1]); + MMC5BGVROM_BANK2(0x1800,CHRBanksB[3]); + break; case 3: for(x=0;x<8;x++) - { - setchr1(x<<10,CHRBanksB[x&3]); - MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); - } - break; - } + { + setchr1(x<<10,CHRBanksB[x&3]); + MMC5BGVROM_BANK1(x<<10,CHRBanksB[x&3]); + } + break; + } } static void FASTAPASS(2) MMC5WRAM(uint32 A, uint32 V) { - //printf("%02x\n",V); - V=MMC5WRAMIndex[V&7]; - if(V!=255) - { + //printf("%02x\n",V); + V=MMC5WRAMIndex[V&7]; + if(V!=255) + { setprg8r(0x10,A,V); MMC5MemIn[(A-0x6000)>>13]=1; - } - else + } + else MMC5MemIn[(A-0x6000)>>13]=0; } static void MMC5PRG(void) { - int x; - switch(mmc5psize&3) + int x; + switch(mmc5psize&3) { case 0: MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]= - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); - for(x=0;x<4;x++) - MMC5MemIn[1+x]=1; - break; + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg32(0x8000,((PRGBanks[1]&0x7F)>>2)); + for(x=0;x<4;x++) + MMC5MemIn[1+x]=1; + break; case 1: if(PRGBanks[1]&0x80) - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]>>1)); - MMC5MemIn[1]=MMC5MemIn[2]=1; - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - MMC5MemIn[3]=MMC5MemIn[4]=1; - MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; - setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); - break; + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]>>1)); + MMC5MemIn[1]=MMC5MemIn[2]=1; + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + MMC5MemIn[3]=MMC5MemIn[4]=1; + MMC5ROMWrProtect[2]=MMC5ROMWrProtect[3]=1; + setprg16(0xC000,(PRGBanks[3]&0x7F)>>1); + break; case 2: if(PRGBanks[1]&0x80) - { - MMC5MemIn[1]=MMC5MemIn[2]=1; - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; - setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); - } - else - { - MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; - MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); - MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); - } - if(PRGBanks[2]&0x80) + { + MMC5MemIn[1]=MMC5MemIn[2]=1; + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=1; + setprg16(0x8000,(PRGBanks[1]&0x7F)>>1); + } + else + { + MMC5ROMWrProtect[0]=MMC5ROMWrProtect[1]=0; + MMC5WRAM(0x8000,PRGBanks[1]&7&0xFE); + MMC5WRAM(0xA000,(PRGBanks[1]&7&0xFE)+1); + } + if(PRGBanks[2]&0x80) { MMC5ROMWrProtect[2]=1; MMC5MemIn[3]=1; @@ -268,49 +269,49 @@ static void MMC5PRG(void) setprg8(0xE000,PRGBanks[3]&0x7F); break; case 3: for(x=0;x<3;x++) - if(PRGBanks[x]&0x80) - { - MMC5ROMWrProtect[x]=1; - setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); - MMC5MemIn[1+x]=1; - } - else - { - MMC5ROMWrProtect[x]=0; - MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); - } - MMC5MemIn[4]=1; - MMC5ROMWrProtect[3]=1; - setprg8(0xE000,PRGBanks[3]&0x7F); - break; + if(PRGBanks[x]&0x80) + { + MMC5ROMWrProtect[x]=1; + setprg8(0x8000+(x<<13),PRGBanks[x]&0x7F); + MMC5MemIn[1+x]=1; + } + else + { + MMC5ROMWrProtect[x]=0; + MMC5WRAM(0x8000+(x<<13),PRGBanks[x]&7); + } + MMC5MemIn[4]=1; + MMC5ROMWrProtect[3]=1; + setprg8(0xE000,PRGBanks[3]&0x7F); + break; } } static DECLFW(Mapper5_write) { if(A>=0x5120&&A<=0x5127) - { - ABMode = 0; - CHRBanksA[A&7]=V; - MMC5CHRA(); - } - else switch(A) - { + { + ABMode = 0; + CHRBanksA[A&7]=V; + MMC5CHRA(); + } + else switch(A) + { case 0x5105: { - int x; - for(x=0;x<4;x++) - { - switch((V>>(x<<1))&3) - { - case 0:PPUNTARAM|=1<>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>3)&0x1F;break; case 0x5202: MMC5HackSPPage=V&0x3F;break; @@ -363,15 +364,15 @@ static DECLFW(Mapper5_write) static DECLFR(MMC5_ReadROMRAM) { - if(MMC5MemIn[(A-0x6000)>>13]) - return Page[A>>11][A]; - else - return X.DB; + if(MMC5MemIn[(A-0x6000)>>13]) + return Page[A>>11][A]; + else + return X.DB; } static DECLFW(MMC5_WriteROMRAM) { - if(A>=0x8000) + if(A>=0x8000) if(MMC5ROMWrProtect[(A-0x8000)>>13]) return; if(MMC5MemIn[(A-0x6000)>>13]) if(((WRAMMaskEnable[0]&3)|((WRAMMaskEnable[1]&3)<<2)) == 6) Page[A>>11][A]=V; @@ -379,8 +380,8 @@ static DECLFW(MMC5_WriteROMRAM) static DECLFW(MMC5_ExRAMWr) { - if(MMC5HackCHRMode!=3) - ExRAM[A&0x3ff]=V; + if(MMC5HackCHRMode!=3) + ExRAM[A&0x3ff]=V; } static DECLFR(MMC5_ExRAMRd) @@ -394,59 +395,61 @@ static DECLFR(MMC5_ExRAMRd) static DECLFR(MMC5_read) { - switch(A) - { + switch(A) + { case 0x5204: X6502_IRQEnd(FCEU_IQEXT); - { - uint8 x; - x=MMC5IRQR; - if(!fceuindbg) - MMC5IRQR&=0x40; - return x; - } + { + uint8 x; + x=MMC5IRQR; + #ifdef FCEUDEF_DEBUGGER + if(!fceuindbg) + #endif + MMC5IRQR&=0x40; + return x; + } case 0x5205: return (mul[0]*mul[1]); case 0x5206: return ((mul[0]*mul[1])>>8); - } - return(X.DB); + } + return(X.DB); } void MMC5Synco(void) { - int x; + int x; - MMC5PRG(); - for(x=0;x<4;x++) - { - switch((NTAMirroring>>(x<<1))&3) - { - case 0:PPUNTARAM|=1<>(x<<1))&3) + { + case 0:PPUNTARAM|=1<>4]+=MMC5Sound.raw<<1; + Wave[V>>4]+=MMC5Sound.raw<<1; } -#if 0 static void Do5PCMHQ() { - int32 V; - if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) + int32 V; + if(!(MMC5Sound.rawcontrol&0x40) && MMC5Sound.raw) for(V=MMC5Sound.BC[2];V>2); - MMC5Sound.env[A>>2]=V; - break; - case 0x2: + switch(A) + { + case 0x10:if(psfun) psfun();MMC5Sound.rawcontrol=V;break; + case 0x11:if(psfun) psfun();MMC5Sound.raw=V;break; + + case 0x0: + case 0x4://printf("%04x:$%02x\n",A,V&0x30); + if(sfun) sfun(A>>2); + MMC5Sound.env[A>>2]=V; + break; + case 0x2: case 0x6: if(sfun) sfun(A>>2); - MMC5Sound.wl[A>>2]&=~0x00FF; - MMC5Sound.wl[A>>2]|=V&0xFF; - break; - case 0x3: - case 0x7://printf("%04x:$%02x\n",A,V>>3); + MMC5Sound.wl[A>>2]&=~0x00FF; + MMC5Sound.wl[A>>2]|=V&0xFF; + break; + case 0x3: + case 0x7://printf("%04x:$%02x\n",A,V>>3); MMC5Sound.wl[A>>2]&=~0x0700; MMC5Sound.wl[A>>2]|=(V&0x07)<<8; MMC5Sound.running|=1<<(A>>2); @@ -599,7 +601,6 @@ static void Do5SQ(int P) } } -#if 0 static void Do5SQHQ(int P) { static int tal[4]={1,2,4,6}; @@ -646,7 +647,6 @@ void MMC5HiSync(int32 ts) int x; for(x=0;x<3;x++) MMC5Sound.BC[x]=ts; } -#endif void MMC5RunSound(int Count) { @@ -663,14 +663,12 @@ void Mapper5_ESI(void) GameExpSound.RChange=Mapper5_ESI; if(FSettings.SndRate) { -#if 0 if(FSettings.soundq>=1) { sfun=Do5SQHQ; psfun=Do5PCMHQ; } else -#endif { sfun=Do5SQ; psfun=Do5PCM; @@ -683,7 +681,7 @@ void Mapper5_ESI(void) } memset(MMC5Sound.BC,0,sizeof(MMC5Sound.BC)); memset(MMC5Sound.vcount,0,sizeof(MMC5Sound.vcount)); - GameExpSound.HiSync=0;//MMC5HiSync; + GameExpSound.HiSync=MMC5HiSync; } void NSFMMC5_Init(void)