X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=boards%2Fmmc1.c;h=df7ddf8be86b56a98f7431e575c79a3ff5450742;hb=refs%2Fheads%2Fmaster;hp=0eefc5943165a9f401c96dcc9df8beb7f7d708c3;hpb=d97315ac0bca825d2d50a44453bc5652946e2c67;p=fceu.git diff --git a/boards/mmc1.c b/boards/mmc1.c index 0eefc59..df7ddf8 100644 --- a/boards/mmc1.c +++ b/boards/mmc1.c @@ -24,8 +24,8 @@ static void GenMMC1Power(void); static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery); -static uint8 DRegs[4]; -static uint8 Buffer,BufferShift; +static uint8 BufferShift,DRegs[4]; +static uint8 Buffer; static int mmc1opts; @@ -34,7 +34,7 @@ static void (*MMC1PRGHook16)(uint32 A, uint8 V); static uint8 *WRAM=NULL; static uint8 *CHRRAM=NULL; -static int is155; +static int is155, is171; static DECLFW(MBWRAM) { @@ -58,6 +58,7 @@ static void MMC1CHR(void) else setprg8r(0x10,0x6000,(DRegs[1]>>3)&1); } + if(MMC1CHRHook4) { if(DRegs[0]&0x10) @@ -86,7 +87,6 @@ static void MMC1CHR(void) static void MMC1PRG(void) { uint8 offs=DRegs[1]&0x10; - if(MMC1PRGHook16) { switch(DRegs[0]&0xC) @@ -104,49 +104,54 @@ static void MMC1PRG(void) break; } } - else switch(DRegs[0]&0xC) + else { - case 0xC: setprg16(0x8000,(DRegs[3]+offs)); - setprg16(0xC000,0xF+offs); - break; - case 0x8: setprg16(0xC000,(DRegs[3]+offs)); - setprg16(0x8000,offs); - break; - case 0x0: - case 0x4: - setprg16(0x8000,((DRegs[3]&~1)+offs)); - setprg16(0xc000,((DRegs[3]&~1)+offs+1)); - break; + switch(DRegs[0]&0xC) + { + case 0xC: setprg16(0x8000,(DRegs[3]+offs)); + setprg16(0xC000,0xF+offs); + break; + case 0x8: setprg16(0xC000,(DRegs[3]+offs)); + setprg16(0x8000,offs); + break; + case 0x0: + case 0x4: + setprg16(0x8000,((DRegs[3]&~1)+offs)); + setprg16(0xc000,((DRegs[3]&~1)+offs+1)); + break; + } } } static void MMC1MIRROR(void) { - switch(DRegs[0]&3) - { - case 2: setmirror(MI_V); break; - case 3: setmirror(MI_H); break; - case 0: setmirror(MI_0); break; - case 1: setmirror(MI_1); break; - } + if(!is171) + switch(DRegs[0]&3) + { + case 2: setmirror(MI_V); break; + case 3: setmirror(MI_H); break; + case 0: setmirror(MI_0); break; + case 1: setmirror(MI_1); break; + } } - 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); +// FCEU_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; - + deal with 2 writes in a row from a single RMW instruction. + */ + if((timestampbase+timestamp)<(lreset+2)) + return; +// FCEU_printf("Write %04x:%02x\n",A,V); if(V&0x80) { DRegs[0]|=0xC; @@ -155,9 +160,12 @@ static DECLFW(MMC1_write) lreset=timestampbase+timestamp; return; } + Buffer|=(V&1)<<(BufferShift++); + if(BufferShift==5) { +// FCEU_printf("REG[%d]=%02x\n",n,Buffer); DRegs[n] = Buffer; BufferShift = Buffer = 0; switch(n) @@ -175,16 +183,18 @@ static void MMC1_Restore(int version) MMC1MIRROR(); MMC1CHR(); MMC1PRG(); - //lreset=0; /* timestamp(base) is not stored in save states. */ // it is now! + lreset=0; /* timestamp(base) is not stored in save states. */ } static void MMC1CMReset(void) { int i; + for(i=0;i<4;i++) DRegs[i]=0; Buffer = BufferShift = 0; DRegs[0]=0x1F; + DRegs[1]=0; DRegs[2]=0; // Should this be something other than 0? DRegs[3]=0; @@ -203,6 +213,8 @@ static int DetectMMC1WRAMSize(uint32 crc32) case 0x4642dda6: /* Nobunaga's Ambition */ case 0x29449ba9: /* "" "" (J) */ case 0x2b11e0b0: /* "" "" (J) */ + case 0xb8747abf: /* Best Play Pro Yakyuu Special (J) */ + case 0xc9556b36: /* Final Fantasy I & II (J) [!] */ FCEU_printf(" >8KB external WRAM present. Use UNIF if you hack the ROM image.\n"); return(16); break; @@ -214,7 +226,7 @@ static uint32 NWCIRQCount; static uint8 NWCRec; #define NWCDIP 0xE -static void FP_FASTAPASS(1) NWCIRQHook(int a) +static void NWCIRQHook(int a) { if(!(NWCRec&0x10)) { @@ -234,6 +246,7 @@ static void NWCCHRHook(uint32 A, uint8 V) NWCIRQCount=0; X6502_IRQEnd(FCEU_IQEXT); } + NWCRec=V; if(V&0x08) MMC1PRG(); @@ -333,8 +346,6 @@ static void GenMMC1Init(CartInfo *info, int prg, int chr, int wram, int battery) info->Power=GenMMC1Power; GameStateRestore=MMC1_Restore; AddExState(&lreset, 8, 1, "LRST"); - AddExState(&Buffer, 1, 1, "BFFR"); - AddExState(&BufferShift, 1, 1, "BFRS"); } void Mapper1_Init(CartInfo *info) @@ -350,6 +361,14 @@ void Mapper155_Init(CartInfo *info) is155=1; } +/* Same as mapper 1, with different (or without) mirroring control. */ +/* Kaiser KS7058 board, KS203 custom chip */ +void Mapper171_Init(CartInfo *info) +{ + GenMMC1Init(info,32,32,0,0); + is171=1; +} + void SAROM_Init(CartInfo *info) { GenMMC1Init(info, 128, 64, 8, info->battery);