From c0bf6f9f02a2b6afb961a7e9195e2168d7e9cecf Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 22 Apr 2007 21:12:48 +0000 Subject: [PATCH] mapper fixes for ncpu, debug is broken atm git-svn-id: file:///home/notaz/opt/svn/fceu@107 be3aeb3a-fb24-0410-a615-afba39da0efa --- boards/h2288.c | 8 ++++-- boards/novel.c | 3 +- boards/sachen.c | 14 ++++++++-- boards/simple.c | 4 ++- boards/super24.c | 5 +++- boards/supervision.c | 5 ++-- drivers/gp2x/asmutils.s | 57 +++++++++++++++++++++++++++++++++++++ fce.c | 13 ++------- input.c | 11 ++++++++ mappers/105.c | 7 +++-- mappers/112.c | 1 + mappers/113.c | 6 ++-- mappers/117.c | 12 +++++--- mappers/15.c | 4 +++ mappers/151.c | 9 ++++-- mappers/16.c | 8 ++++-- mappers/17.c | 12 +++++--- mappers/18.c | 1 + mappers/180.c | 3 +- mappers/182.c | 6 ++-- mappers/189.c | 8 ++++-- mappers/19.c | 9 ++++-- mappers/21.c | 7 ++++- mappers/22.c | 6 ++-- mappers/225.c | 1 + mappers/226.c | 1 + mappers/227.c | 1 + mappers/228.c | 3 +- mappers/229.c | 1 + mappers/23.c | 11 ++++++-- mappers/232.c | 1 + mappers/234.c | 3 +- mappers/240.c | 1 + mappers/242.c | 3 +- mappers/245.c | 1 + mappers/246.c | 12 +++++--- mappers/248.c | 1 + mappers/24and26.c | 22 ++++++++------- mappers/25.c | 5 ++++ mappers/32.c | 3 ++ mappers/33.c | 8 ++++-- mappers/40.c | 5 ++-- mappers/41.c | 1 + mappers/42.c | 3 +- mappers/43.c | 1 + mappers/46.c | 2 ++ mappers/51.c | 3 +- mappers/6.c | 1 + mappers/64.c | 3 +- mappers/65.c | 9 ++++-- mappers/67.c | 3 +- mappers/68.c | 3 +- mappers/69.c | 22 +++++++++------ mappers/71.c | 3 +- mappers/72.c | 3 ++ mappers/73.c | 3 +- mappers/75.c | 9 ++++-- mappers/76.c | 2 ++ mappers/77.c | 4 ++- mappers/79.c | 1 + mappers/8.c | 1 + mappers/80.c | 9 ++++-- mappers/82.c | 9 ++++-- mappers/83.c | 3 +- mappers/85.c | 9 ++++-- mappers/86.c | 1 + mappers/88.c | 6 ++-- mappers/89.c | 1 + mappers/90.c | 3 +- mappers/92.c | 4 +-- mappers/95.c | 2 ++ mappers/97.c | 1 + mappers/mmc2and4.c | 4 ++- mappers/simple.c | 24 ++++++++++++++-- mbshare/mmc1.c | 14 ++++++---- mbshare/mmc3.c | 20 ++++++++----- mbshare/mmc5.c | 23 +++++++++------ ncpu.S | 37 +++++++++++++++++++----- ncpu_debug.c | 62 ++++++++++++++++++++++++++++++++++------- nsf.c | 16 ++++++----- ops.h | 20 ++++++------- out_gp2x/readme.txt | 6 ++++ state.h | 2 ++ x6502.c | 38 +++++++++++++++++++++---- x6502.h | 6 +++- 85 files changed, 520 insertions(+), 179 deletions(-) diff --git a/boards/h2288.c b/boards/h2288.c index c8ad1e0..9b9dcbc 100644 --- a/boards/h2288.c +++ b/boards/h2288.c @@ -64,11 +64,13 @@ static DECLFW(H2288Write) { case 0xa000:setmirror((V&1)^1);break; case 0x8000:// DumpMem("out",0x0000,0xFFFF); - cmd=V;DoPRG();DoCHR();break; + cmd=V;DoPRG();DoCHR(); + X6502_Rebase();break; case 0x8001:regs[cmd&7]=V; - if((cmd&7)==4 || (cmd&7)==5) + if((cmd&7)==4 || (cmd&7)==5) { DoPRG(); - else + X6502_Rebase(); + } else DoCHR(); break; } diff --git a/boards/novel.c b/boards/novel.c index 7d620db..fe3a37c 100644 --- a/boards/novel.c +++ b/boards/novel.c @@ -24,6 +24,7 @@ static void DoNovel(void) { setprg32(0x8000,GameMemBlock[0]&3); setchr8(GameMemBlock[0]&7); + X6502_Rebase(); } static DECLFW(NovelWrite) @@ -35,7 +36,7 @@ static DECLFW(NovelWrite) static void NovelReset(void) { SetWriteHandler(0x8000,0xFFFF,NovelWrite); - SetReadHandler(0x8000,0xFFFF,CartBR); + SetReadHandler(0x8000,0xFFFF,CartBR); setprg32(0x8000,0); setchr8(0); } diff --git a/boards/sachen.c b/boards/sachen.c index d4d20c2..a26dd07 100644 --- a/boards/sachen.c +++ b/boards/sachen.c @@ -27,6 +27,7 @@ static uint8 latch[8]; static void S74LS374NSynco(void) { setprg32(0x8000,latch[0]); + X6502_Rebase(); setchr8(latch[1]); setmirror(latch[2]&1); // setchr8(6); @@ -38,7 +39,7 @@ static DECLFW(S74LS374NWrite) A&=0x4101; if(A==0x4100) cmd=V&7; - else + else { switch(cmd) { @@ -80,6 +81,7 @@ static void S8259Synco(void) int x; setprg32(0x8000,latch[5]&7); + X6502_Rebase(); if(!UNIFchrrama) // No CHR RAM? Then BS'ing is ok. { @@ -107,7 +109,7 @@ static DECLFW(S8259Write) { A&=0x4101; if(A==0x4100) cmd=V; - else + else { latch[cmd&7]=V; S8259Synco(); @@ -160,7 +162,8 @@ static void(*WSync)(void); static void SA0161MSynco() { - setprg32(0x8000,(latch[0]>>3)&1); + setprg32(0x8000,(latch[0]>>3)&1); + X6502_Rebase(); setchr8(latch[0]&7); } @@ -192,6 +195,7 @@ void SA0161M_Init(void) static void SA72007Synco() { setprg32(0x8000,0); + X6502_Rebase(); setchr8(latch[0]>>7); } @@ -206,6 +210,7 @@ void SA72007_Init(void) static void SA72008Synco() { setprg32(0x8000,(latch[0]>>2)&1); + X6502_Rebase(); setchr8(latch[0]&3); } @@ -234,12 +239,14 @@ static void SADReset(void) static void SA0036Synco() { setprg32(0x8000,0); + X6502_Rebase(); setchr8(latch[0]>>7); } static void SA0037Synco() { setprg32(0x8000,(latch[0]>>3)&1); + X6502_Rebase(); setchr8(latch[0]&7); } @@ -262,6 +269,7 @@ void SA0037_Init(void) static void TCU01Synco() { setprg32(0x8000,(latch[0]>>2)&1); + X6502_Rebase(); setchr8((latch[0]>>3)&0xF); } diff --git a/boards/simple.c b/boards/simple.c index ca4d1db..5629a5f 100644 --- a/boards/simple.c +++ b/boards/simple.c @@ -105,6 +105,7 @@ static DECLFW(MHROMWrite) setprg32(0x8000,V>>4); setchr8(V); latche=V; + X6502_Rebase(); } static void MHROMReset(void) @@ -123,7 +124,7 @@ static void MHROMRestore(int version) } void MHROM_Init(void) -{ +{ BoardPower=MHROMReset; AddExState(&latche, 1, 0,"LATC"); PRGmask32[0]&=1; @@ -140,6 +141,7 @@ static DECLFW(UNROMWrite) { setprg16(0x8000,V); latche=V; + X6502_Rebase(); } static void UNROMReset(void) diff --git a/boards/super24.c b/boards/super24.c index 64af337..7cf0646 100644 --- a/boards/super24.c +++ b/boards/super24.c @@ -56,7 +56,7 @@ static void swsetchr2(uint32 A, uint32 V) else { //V&=masko1[sizer&7]>>1; - V|=bigbank2*4; + V|=bigbank2*4; setchr2r((V/256)&15,A,V); } } @@ -117,6 +117,7 @@ static INLINE void FixMMC3PRG(int V) swsetprg8(0x8000,DRegBuf[6]); swsetprg8(0xC000,~1); } + X6502_Rebase(); } static INLINE void FixMMC3CHR(int V) @@ -157,8 +158,10 @@ static DECLFW(Super24hiwrite) case 5: swsetchr1(cbase^0x1C00,V); break; case 6: if (MMC3_cmd&0x40) swsetprg8(0xC000,V); else swsetprg8(0x8000,V); + X6502_Rebase(); break; case 7: swsetprg8(0xA000,V); + X6502_Rebase(); break; } } diff --git a/boards/supervision.c b/boards/supervision.c index fc22599..cb2890f 100644 --- a/boards/supervision.c +++ b/boards/supervision.c @@ -34,6 +34,7 @@ static void DoSuper(void) setprg32r(4,0x8000,0); setmirror(((GameMemBlock[0]&0x20)>>5)^1); + X6502_Rebase(); } static DECLFW(SuperWrite) @@ -47,7 +48,7 @@ static DECLFW(SuperWrite) static DECLFW(SuperHi) { - GameMemBlock[1]=V; + GameMemBlock[1]=V; DoSuper(); } @@ -55,7 +56,7 @@ static void SuperReset(void) { SetWriteHandler(0x6000,0x7FFF,SuperWrite); SetWriteHandler(0x8000,0xFFFF,SuperHi); - SetReadHandler(0x6000,0xFFFF,CartBR); + SetReadHandler(0x6000,0xFFFF,CartBR); GameMemBlock[0]=GameMemBlock[1]=0; setprg32r(4,0x8000,0); setvram8(CHRRAM); diff --git a/drivers/gp2x/asmutils.s b/drivers/gp2x/asmutils.s index c87a3ab..917bb08 100644 --- a/drivers/gp2x/asmutils.s +++ b/drivers/gp2x/asmutils.s @@ -7,3 +7,60 @@ flushcache: swi #0x9f0002 mov pc, lr + +/* buggy and slow, probably because function call overhead +@ renderer helper, based on bitbank's method +.global draw8pix @ uint8 *P, uint8 *C, uint8 *PALRAM @ dest, src, pal + +draw8pix: + stmfd sp!, {r4,r5} + + ldrb r3, [r1] @ get bit 0 pixels + mov r12,#1 + orr r12,r12,r12,lsl #8 + orr r12,r12,r12,lsl #16 + ldrb r1, [r1, #8] @ get bit 1 pixels + orr r3, r3, r3, lsl #9 @ shift them over 1 byte + 1 bit + orr r3, r3, r3, lsl #18 @ now 4 pixels take up 4 bytes + and r4, r12,r3, lsr #7 @ mask off the upper nibble pixels we want + and r5, r12,r3, lsr #3 @ mask off the lower nibble pixels we want + ldr r2, [r2] + + orr r1, r1, r1, lsl #9 @ process the bit 1 pixels + orr r1, r1, r1, lsl #18 + and r3, r12,r1, lsr #7 @ mask off the upper nibble pixels we want + and r1, r12,r1, lsr #3 @ mask off the lower nibble + orr r4, r4, r3, lsl #1 + orr r5, r5, r1, lsl #5 + + @ can this be avoided? + mov r4, r4, lsl #3 @ *8 + mov r3, r2, ror r4 + strb r3, [r0], #1 + mov r4, r4, lsr #8 + mov r3, r2, ror r4 + strb r3, [r0], #1 + mov r4, r4, lsr #8 + mov r3, r2, ror r4 + strb r3, [r0], #1 + mov r4, r4, lsr #8 + mov r3, r2, ror r4 + strb r3, [r0], #1 + + mov r5, r5, lsl #3 @ *8 + mov r3, r2, ror r5 + strb r3, [r0], #1 + mov r5, r5, lsr #8 + mov r3, r2, ror r5 + strb r3, [r0], #1 + mov r5, r5, lsr #8 + mov r3, r2, ror r5 + strb r3, [r0], #1 + mov r5, r5, lsr #8 + mov r3, r2, ror r5 + strb r3, [r0], #1 + + ldmfd sp!, {r4,r5} + bx lr +*/ + diff --git a/fce.c b/fce.c index bec2511..1d5b493 100644 --- a/fce.c +++ b/fce.c @@ -142,7 +142,7 @@ void asmcpu_unpack(void) nes_registers[2] = X.Y; pc_base = 0; nes_registers[3] = X.PC; - X6502_rebase_a(); + X6502_Rebase_a(); nes_registers[4] = X.S << 24; nes_registers[4]|= X.IRQlow << 8; nes_registers[7] = (uint32)X.count; @@ -323,7 +323,7 @@ static DECLFR(A2002) vtoggle=0; PPU_status&=0x7F; #ifdef DEBUG_ASM_6502 - cpu_lastval=ret|(PPUGenLatch&0x1F); +// cpu_lastval=ret|(PPUGenLatch&0x1F); #endif return ret|(PPUGenLatch&0x1F); } @@ -356,7 +356,7 @@ static DECLFR(A2007) else RefreshAddr++; if(PPU_hook) PPU_hook(RefreshAddr&0x3fff); #ifdef DEBUG_ASM_6502 - cpu_lastval=ret; +// cpu_lastval=ret; #endif return ret; } @@ -483,16 +483,9 @@ static DECLFW(B4014) { uint32 t=V<<8; int x; -#ifdef DEBUG_ASM_6502 - if (cpu_repeat) { X6502_AddCycles_a(512); return; } - for(x=0;x<256;x++) - B2004(0x2004,X.DB=ARead[t+x](t+x)); - X6502_AddCycles_c(512); -#else for(x=0;x<256;x++) B2004(0x2004,X.DB=ARead[t+x](t+x)); X6502_AddCycles(512); -#endif } void BGRender(uint8 *target) diff --git a/input.c b/input.c index 40c0ff8..dc48c71 100644 --- a/input.c +++ b/input.c @@ -30,6 +30,11 @@ #include "input.h" #include "movie.h" +#ifdef DEBUG_ASM_6502 +extern int cpu_repeat; +extern int cpu_lastval; +#endif + extern INPUTC *FCEU_InitZapper(int w); extern INPUTC *FCEU_InitPowerpad(int w); extern INPUTC *FCEU_InitArkanoid(int w); @@ -97,6 +102,9 @@ static DECLFR(JPRead) { uint8 ret=0; +#ifdef DEBUG_ASM_6502 + if (cpu_repeat) return cpu_lastval; +#endif if(JPorts[A&1]->Read) ret|=JPorts[A&1]->Read(A&1); @@ -105,6 +113,9 @@ static DECLFR(JPRead) ret=FCExp->Read(A&1,ret); ret|=X.DB&0xC0; +#ifdef DEBUG_ASM_6502 +// cpu_lastval=ret; +#endif return(ret); } diff --git a/mappers/105.c b/mappers/105.c index 977e9f2..07f4ceb 100644 --- a/mappers/105.c +++ b/mappers/105.c @@ -45,9 +45,9 @@ static void FP_FASTAPASS(1) NWCIRQHook(int a) static void MMC1PRG(void) { if(MMC1_reg[1]&8) - { + { switch(MMC1_reg[0]&0xC) - { + { case 0xC: ROM_BANK16(0x8000,8+(MMC1_reg[3]&7)); ROM_BANK16(0xC000,15); break; @@ -65,6 +65,7 @@ static void MMC1PRG(void) { ROM_BANK32((MMC1_reg[1]>>1)&3); } + X6502_Rebase(); } DECLFW(Mapper105_write) @@ -86,7 +87,7 @@ DECLFW(Mapper105_write) //MMC1_reg[n]&=~((1)<<(MMC1_sft)); MMC1_buf|=(V&1)<<(MMC1_sft++); - if (MMC1_sft==5) + if (MMC1_sft==5) { if(n==3) V&=0xF; else V&=0x1F; diff --git a/mappers/112.c b/mappers/112.c index bfa4595..273d550 100644 --- a/mappers/112.c +++ b/mappers/112.c @@ -41,6 +41,7 @@ switch(A) case 6:VROM_BANK1(0x1800,V);break; case 7:VROM_BANK1(0x1c00,V);break; } + X6502_Rebase(); break; } } diff --git a/mappers/113.c b/mappers/113.c index 66548b5..4662ed5 100644 --- a/mappers/113.c +++ b/mappers/113.c @@ -22,20 +22,22 @@ /* I'm getting the feeling this is another "jam two different bank switching hardwares into one mapper". -*/ +*/ /* HES 4-in-1 */ DECLFW(Mapper113_write) { ROM_BANK32((V>>3)&7); VROM_BANK8(V&7); + X6502_Rebase(); } - + /* Deathbots */ DECLFW(Mapper113_writeh) { ROM_BANK32(V&0xF); + X6502_Rebase(); } diff --git a/mappers/117.c b/mappers/117.c index aa0ea5f..6f1051c 100644 --- a/mappers/117.c +++ b/mappers/117.c @@ -36,10 +36,14 @@ DECLFW(Mapper117_write) case 0xa005:VROM_BANK1(0x1400,V);break; case 0xa006:VROM_BANK1(0x1800,V);break; case 0xa007:VROM_BANK1(0x1c00,V);break; - case 0x8000:ROM_BANK8(0x8000,V);break; - case 0x8001:ROM_BANK8(0xa000,V);break; - case 0x8002:ROM_BANK8(0xc000,V);break; - case 0x8003:ROM_BANK8(0xe000,V);break; + case 0x8000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0x8001:ROM_BANK8(0xa000,V); + X6502_Rebase();break; + case 0x8002:ROM_BANK8(0xc000,V); + X6502_Rebase();break; + case 0x8003:ROM_BANK8(0xe000,V); + X6502_Rebase();break; } } diff --git a/mappers/15.c b/mappers/15.c index 05146af..e3ad005 100644 --- a/mappers/15.c +++ b/mappers/15.c @@ -42,11 +42,13 @@ switch(A) ROM_BANK16(0xC000,V+1); } MIRROR_SET((V>>6)&1); + X6502_Rebase(); break; case 0x8001: MIRROR_SET(0); ROM_BANK16(0x8000,V); ROM_BANK16(0xc000,~0); + X6502_Rebase(); break; case 0x8002: if(V&0x80) @@ -63,6 +65,7 @@ switch(A) ROM_BANK8(0xC000,(V<<1)); ROM_BANK8(0xE000,(V<<1)); } + X6502_Rebase(); break; case 0x8003: MIRROR_SET((V>>6)&1); @@ -75,6 +78,7 @@ switch(A) { ROM_BANK16(0xC000,V); } + X6502_Rebase(); break; } } diff --git a/mappers/151.c b/mappers/151.c index cc59c6c..e7c123e 100644 --- a/mappers/151.c +++ b/mappers/151.c @@ -26,9 +26,12 @@ DECLFW(Mapper151_write) { switch(A&0xF000) { - case 0x8000:ROM_BANK8(0x8000,V);break; - case 0xA000:ROM_BANK8(0xA000,V);break; - case 0xC000:ROM_BANK8(0xC000,V);break; + case 0x8000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0xA000:ROM_BANK8(0xA000,V); + X6502_Rebase();break; + case 0xC000:ROM_BANK8(0xC000,V); + X6502_Rebase();break; case 0xe000:VROM_BANK4(0x0000,V);break; case 0xf000:VROM_BANK4(0x1000,V);break; } diff --git a/mappers/16.c b/mappers/16.c index 3742c34..58dd0b1 100644 --- a/mappers/16.c +++ b/mappers/16.c @@ -43,7 +43,10 @@ static DECLFW(Mapper16_write) if(A<=0x7) VROM_BANK1(A<<10,V); else if(A==0x8) + { ROM_BANK16(0x8000,V); + X6502_Rebase(); + } else switch(A) { case 0x9: switch(V&3) { case 0x00:MIRROR_SET2(1);break; @@ -78,17 +81,18 @@ static void PRGO(void) uint32 base=(mapbyte1[0]&1)<<4; ROM_BANK16(0x8000,(mapbyte2[0]&0xF)|base); ROM_BANK16(0xC000,base|0xF); + X6502_Rebase(); } static DECLFW(Mapper153_write) { A&=0xF; - if(A<=0x7) + if(A<=0x7) { mapbyte1[A&7]=V; PRGO(); } - else if(A==0x8) + else if(A==0x8) { mapbyte2[0]=V; PRGO(); diff --git a/mappers/17.c b/mappers/17.c index 66b85d4..1e76421 100644 --- a/mappers/17.c +++ b/mappers/17.c @@ -52,10 +52,14 @@ DECLFW(Mapper17_write) case 0x4501:IRQa=V&1;break; case 0x4502:IRQCount&=0xFF00;IRQCount|=V;break; case 0x4503:IRQCount&=0x00FF;IRQCount|=V<<8;IRQa=1;break; - case 0x4504: ROM_BANK8(0x8000,V);break; - case 0x4505: ROM_BANK8(0xA000,V);break; - case 0x4506: ROM_BANK8(0xC000,V);break; - case 0x4507: ROM_BANK8(0xE000,V);break; + case 0x4504: ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0x4505: ROM_BANK8(0xA000,V); + X6502_Rebase();break; + case 0x4506: ROM_BANK8(0xC000,V); + X6502_Rebase();break; + case 0x4507: ROM_BANK8(0xE000,V); + X6502_Rebase();break; case 0x4510: VROM_BANK1(0x0000,V);break; case 0x4511: VROM_BANK1(0x0400,V);break; case 0x4512: VROM_BANK1(0x0800,V);break; diff --git a/mappers/18.c b/mappers/18.c index f77e831..13b3ab9 100644 --- a/mappers/18.c +++ b/mappers/18.c @@ -47,6 +47,7 @@ DECLFW(Mapper18_write) K4buf2[x]&=(0xF0)>>((A&1)<<2); K4buf2[x]|=(V&0xF)<<((A&1)<<2); ROM_BANK8(0x8000+(x<<13),K4buf2[x]); + X6502_Rebase(); } else if(A>=0xa000 && A<=0xd003) { diff --git a/mappers/180.c b/mappers/180.c index bd877c8..45342dc 100644 --- a/mappers/180.c +++ b/mappers/180.c @@ -4,7 +4,8 @@ DECLFW(Mapper180_write) { -ROM_BANK16(0xC000,V); + ROM_BANK16(0xC000,V); + X6502_Rebase(); } void Mapper180_init(void) diff --git a/mappers/182.c b/mappers/182.c index 5fe0750..a7f65e5 100644 --- a/mappers/182.c +++ b/mappers/182.c @@ -14,8 +14,10 @@ DECLFW(Mapper182_write) case 1:VROM_BANK1(0x1400,V);break; case 2:VROM_BANK2(0x0800,V>>1);break; case 3:VROM_BANK1(0x1c00,V);break; - case 4:ROM_BANK8(0x8000,V);break; - case 5:ROM_BANK8(0xA000,V);break; + case 4:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 5:ROM_BANK8(0xA000,V); + X6502_Rebase();break; case 6:VROM_BANK1(0x1000,V);break; case 7:VROM_BANK1(0x1800,V);break; } diff --git a/mappers/189.c b/mappers/189.c index 7d8bcff..bdcf4b7 100644 --- a/mappers/189.c +++ b/mappers/189.c @@ -8,11 +8,15 @@ #define cmd mapbyte1[0] static DECLFW(Mapper189_write) { - if(A==0x4120) ROM_BANK32(V>>4); + if(A==0x4120) + { + ROM_BANK32(V>>4); + X6502_Rebase(); + } else switch(A&0xE001) { case 0xa000:MIRROR_SET(V&1);break; - case 0x8000:cmd=V;break; + case 0x8000:cmd=V;break; case 0x8001:switch(cmd&7) { case 0:VROM_BANK2(0x0000,V>>1);break; diff --git a/mappers/19.c b/mappers/19.c index 53de232..d928b4e 100644 --- a/mappers/19.c +++ b/mappers/19.c @@ -67,7 +67,7 @@ static void FASTAPASS(2) DoNTARAMROM(int w, uint8 V) // setntamem(NTARAM+((V&1)<<10), 1, w); if((V>=0xE0)) // || ((gorko>>(6+(w>>1)))&1) ) setntamem(NTARAM+((V&1)<<10), 1, w); - else + else { V&=CHRmask1[0]; setntamem(VROM+(V<<10), 0, w); @@ -134,13 +134,16 @@ static DECLFW(Mapper19_write) case 0xE000:gorko=V&0xC0; //FixNTAR(); ROM_BANK8(0x8000,V); + X6502_Rebase(); break; case 0xE800:gorfus=V&0xC0; FixCRR(); ROM_BANK8(0xA000,V); + X6502_Rebase(); break; case 0xF000: ROM_BANK8(0xC000,V); + X6502_Rebase(); break; } } @@ -152,7 +155,7 @@ static void NamcoSoundHack(void) { int32 z,a; - z=((timestamp<<16)/soundtsinc)>>4; + z=((timestamp<<16)/soundtsinc)>>4; a=z-dwave; if(a) DoNamcoSound(&Wave[dwave], a); @@ -208,7 +211,7 @@ static void DoNamcoSound(uint32 *Wave, int Count) duff>>=4; duff&=0xF; duff2=(duff*envelope)>>14; - + lengo=((8-((MapperExRAM[0x44+(P<<3)]>>2)&7)))<<2; for(V=0;V>5)&0xF); if((A&0xF000)==0xA000) + { ROM_BANK8(0xA000,V); + X6502_Rebase(); + } else if((A&0xF000)==0x8000) { if(K4sel&2) ROM_BANK8(0xC000,V); else ROM_BANK8(0x8000,V); + X6502_Rebase(); } else if(A>=0xb000 && A<=0xefff) { @@ -49,7 +53,7 @@ DECLFW(Mapper21_write) K4buf[x]|=(V&0xF)<<((A&2)<<1); VROM_BANK1(x<<10,K4buf[x]); } - + } else switch(A&0xF006) { @@ -70,6 +74,7 @@ DECLFW(Mapper21_write) swa=PRGBankList[0]; ROM_BANK8(0x8000,PRGBankList[2]); ROM_BANK8(0xc000,swa); + X6502_Rebase(); } K4sel=V; break; diff --git a/mappers/22.c b/mappers/22.c index 44ebe25..a40e05f 100644 --- a/mappers/22.c +++ b/mappers/22.c @@ -30,8 +30,10 @@ DECLFW(Mapper22_write) { switch(A&0xF000) { - case 0x8000:ROM_BANK8(0x8000,V);break; - case 0xa000:ROM_BANK8(0xA000,V);break; + case 0x8000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0xa000:ROM_BANK8(0xA000,V); + X6502_Rebase();break; case 0x9000:switch(V&3) { case 0x00:MIRROR_SET2(1);break; diff --git a/mappers/225.c b/mappers/225.c index 6edb486..23992fc 100644 --- a/mappers/225.c +++ b/mappers/225.c @@ -76,6 +76,7 @@ DECLFW(Mapper225_write) { ROM_BANK32(((((A>>7)&0x1F)+(banks<<5)))); } + X6502_Rebase(); } void Mapper225_init(void) diff --git a/mappers/226.c b/mappers/226.c index 41fd9a4..45dc067 100644 --- a/mappers/226.c +++ b/mappers/226.c @@ -31,6 +31,7 @@ static void DoPRG(void) } else ROM_BANK32(b); + X6502_Rebase(); } static DECLFW(Mapper226_write) diff --git a/mappers/227.c b/mappers/227.c index a006ce3..2754369 100644 --- a/mappers/227.c +++ b/mappers/227.c @@ -51,6 +51,7 @@ static void DoSync(uint32 A) else ROM_BANK16(0xC000,(p<<1)&(~7)); } + X6502_Rebase(); } static DECLFW(Mapper227_write) diff --git a/mappers/228.c b/mappers/228.c index 741bab0..e38063d 100644 --- a/mappers/228.c +++ b/mappers/228.c @@ -29,13 +29,14 @@ static DECLFW(Mapper228_write) page=(A>>7)&0x3F; if((page&0x30)==0x30) page-=0x10; - + pagel=pageh=(page<<1) + (((A>>6)&1)&((A>>5)&1)); pageh+=((A>>5)&1)^1; ROM_BANK16(0x8000,pagel); ROM_BANK16(0xC000,pageh); VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); + X6502_Rebase(); } static void A52Reset(void) diff --git a/mappers/229.c b/mappers/229.c index 8ffe911..46c898b 100644 --- a/mappers/229.c +++ b/mappers/229.c @@ -37,6 +37,7 @@ else ROM_BANK16(0xC000,A&0x1f); } VROM_BANK8(A); + X6502_Rebase(); } } diff --git a/mappers/23.c b/mappers/23.c index 12f30d8..db96e8e 100644 --- a/mappers/23.c +++ b/mappers/23.c @@ -32,9 +32,13 @@ DECLFW(Mapper23_write) ROM_BANK8(0xC000,V); else ROM_BANK8(0x8000,V); - } - else if((A&0xF000)==0xA000) + X6502_Rebase(); + } + else if((A&0xF000)==0xA000) + { ROM_BANK8(0xA000,V); + X6502_Rebase(); + } else { A|=((A>>2)&0x3)|((A>>4)&0x3)|((A>>6)&0x3); @@ -47,7 +51,7 @@ DECLFW(Mapper23_write) K4buf[x]|=(V&0xF)<<((A&1)<<2); VROM_BANK1(x<<10,K4buf[x]); } - else + else switch(A) { case 0xf000:X6502_IRQEnd(FCEU_IQEXT);IRQLatch&=0xF0;IRQLatch|=V&0xF;break; @@ -63,6 +67,7 @@ DECLFW(Mapper23_write) swa=PRGBankList[0]; ROM_BANK8(0x8000,PRGBankList[2]); ROM_BANK8(0xc000,swa); + X6502_Rebase(); } K4sel=V; break; diff --git a/mappers/232.c b/mappers/232.c index 9d71b24..5084ba4 100644 --- a/mappers/232.c +++ b/mappers/232.c @@ -24,6 +24,7 @@ static void DoIt(void) { ROM_BANK16(0x8000,(mapbyte1[1]&3) | ((mapbyte1[0]&0x18)>>1)); ROM_BANK16(0xc000,3|(((mapbyte1[0])&0x18)>>1)); + X6502_Rebase(); } DECLFW(Mapper232_write) diff --git a/mappers/234.c b/mappers/234.c index 4a8ac45..4a2b9ee 100644 --- a/mappers/234.c +++ b/mappers/234.c @@ -35,6 +35,7 @@ static void DoBS(void) ROM_BANK32(r1&0xF); VROM_BANK8( ((r1&0xF)<<2) | ((r2>>4)&3) ); } + X6502_Rebase(); } static void R1Set(uint8 V) @@ -100,7 +101,7 @@ void Mapper234_init(void) SetWriteHandler(0x6000,0x7FFF,0); M15Reset(); - + GameStateRestore=M15Restore; MapperReset=M15Reset; } diff --git a/mappers/240.c b/mappers/240.c index 4c1fd27..0869349 100644 --- a/mappers/240.c +++ b/mappers/240.c @@ -28,6 +28,7 @@ DECLFW(Mapper240_write) { ROM_BANK32(V>>4); VROM_BANK8(V&0xF); + X6502_Rebase(); } } diff --git a/mappers/242.c b/mappers/242.c index 93f654c..3b4dced 100644 --- a/mappers/242.c +++ b/mappers/242.c @@ -24,11 +24,12 @@ DECLFW(Mapper242_write) { ROM_BANK32((A>>3)&0xF); + X6502_Rebase(); switch(V&3) { case 0:MIRROR_SET(0);break; case 1:MIRROR_SET(1);break; - case 2:onemir(0);break; + case 2:onemir(0);break; case 3:onemir(1);break; } } diff --git a/mappers/245.c b/mappers/245.c index 2a25182..ae20c18 100644 --- a/mappers/245.c +++ b/mappers/245.c @@ -26,6 +26,7 @@ static void Synco(void) ROM_BANK8(0xA000,mapbyte2[1]); ROM_BANK8(0xc000,0x3e); ROM_BANK8(0xe000,0x3f); + X6502_Rebase(); } static DECLFW(Mapper245_write) { diff --git a/mappers/246.c b/mappers/246.c index 42613fc..d36b277 100644 --- a/mappers/246.c +++ b/mappers/246.c @@ -25,10 +25,14 @@ DECLFW(Mapper246_write) { switch(A&0xF007) { - case 0x6000:ROM_BANK8(0x8000,V);break; - case 0x6001:ROM_BANK8(0xA000,V);break; - case 0x6002:ROM_BANK8(0xC000,V);break; - case 0x6003:ROM_BANK8(0xE000,V);break; + case 0x6000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0x6001:ROM_BANK8(0xA000,V); + X6502_Rebase();break; + case 0x6002:ROM_BANK8(0xC000,V); + X6502_Rebase();break; + case 0x6003:ROM_BANK8(0xE000,V); + X6502_Rebase();break; case 0x6004:VROM_BANK2(0x0000,V);break; case 0x6005:VROM_BANK2(0x0800,V);break; case 0x6006:VROM_BANK2(0x1000,V);break; diff --git a/mappers/248.c b/mappers/248.c index af40264..e2dff8c 100644 --- a/mappers/248.c +++ b/mappers/248.c @@ -35,6 +35,7 @@ static void PRGSynco(void) ROM_BANK8(0x8000,prgl[0]&0x1F); ROM_BANK8(0xa000,prgl[1]&0x1F); } + X6502_Rebase(); } static DECLFW(Mapper248_writelow) diff --git a/mappers/24and26.c b/mappers/24and26.c index 575e5e6..1981d12 100644 --- a/mappers/24and26.c +++ b/mappers/24and26.c @@ -95,7 +95,8 @@ DECLFW(Mapper24_write) switch(A&0xF003) { - case 0x8000:ROM_BANK16(0x8000,V);break; + case 0x8000:ROM_BANK16(0x8000,V); + X6502_Rebase();break; case 0xB003: switch(V&0xF) { @@ -105,7 +106,8 @@ DECLFW(Mapper24_write) case 0xC:onemir(1);break; } break; - case 0xC000:ROM_BANK8(0xC000,V);break; + case 0xC000:ROM_BANK8(0xC000,V); + X6502_Rebase();break; case 0xD000:VROM_BANK1(0x0000,V);break; case 0xD001:VROM_BANK1(0x0400,V);break; case 0xD002:VROM_BANK1(0x0800,V);break; @@ -135,7 +137,7 @@ static void DoSQV1(void) int V; int32 start,end; - start=CVBC[0]; + start=CVBC[0]; end=(timestamp<<16)/soundtsinc; if(end<=start) return; CVBC[0]=end; @@ -150,7 +152,7 @@ static void DoSQV1(void) } else { - unsigned long dcycs; + unsigned long dcycs; freq=(((VPSG[0x2]|((VPSG[0x3]&15)<<8))+1)); inc=(long double)((unsigned long)((FSettings.SndRate OVERSAMPLE)<<12))/((long double)PSG_base/freq); switch(VPSG[0]&0x70) @@ -183,7 +185,7 @@ static void DoSQV2(void) int32 start,end; start=CVBC[1]; - end=(timestamp<<16)/soundtsinc; + end=(timestamp<<16)/soundtsinc; if(end<=start) return; CVBC[1]=end; @@ -229,7 +231,7 @@ static void DoSawV(void) int32 start,end; start=CVBC[2]; - end=(timestamp<<16)/soundtsinc; + end=(timestamp<<16)/soundtsinc; if(end<=start) return; CVBC[2]=end; @@ -260,7 +262,7 @@ static void DoSawV(void) b3=0; phaseacc=0; } - if(saw1phaseacc<=0) + if(saw1phaseacc<=0) goto rea; duff=(((phaseacc>>3)&0x1f)<<4); } @@ -292,9 +294,9 @@ void VRC6SoundC(void) { for(x=000;x<0x1000;x+=4) { - SetWriteHandler(0x9000+x,0x9002+x,0); - SetWriteHandler(0xa000+x,0xa002+x,0); - SetWriteHandler(0xb000+x,0xb002+x,0); + SetWriteHandler(0x9000+x,0x9002+x,0); + SetWriteHandler(0xa000+x,0xa002+x,0); + SetWriteHandler(0xb000+x,0xb002+x,0); } } } diff --git a/mappers/25.c b/mappers/25.c index db5ba33..0735b9b 100644 --- a/mappers/25.c +++ b/mappers/25.c @@ -29,7 +29,10 @@ DECLFW(Mapper25_write) A=(A&0xF003)|((A&0xC)>>2); if((A&0xF000)==0xA000) + { ROM_BANK8(0xA000,V); + X6502_Rebase(); + } else if(A>=0xB000 && A<=0xEFFF) { int x=(A&1)|((A-0xB000)>>11); @@ -44,6 +47,7 @@ DECLFW(Mapper25_write) ROM_BANK8(0xC000,V); else ROM_BANK8(0x8000,V); + X6502_Rebase(); } else switch(A) { @@ -61,6 +65,7 @@ DECLFW(Mapper25_write) swa=PRGBankList[0]; ROM_BANK8(0x8000,PRGBankList[2]); ROM_BANK8(0xc000,swa); + X6502_Rebase(); } K4sel=V; break; diff --git a/mappers/32.c b/mappers/32.c index da856b9..fd455d2 100644 --- a/mappers/32.c +++ b/mappers/32.c @@ -31,14 +31,17 @@ static DECLFW(Mapper32_write) mapbyte1[1]=V; if(IREMCon) {ROM_BANK8(0xc000,V);ROM_BANK8(0x8000,~1);} else {ROM_BANK8(0x8000,V);ROM_BANK8(0xc000,~1);} + X6502_Rebase(); break; case 0x9:MIRROR_SET2(V&1); IREMCon=(V>>1)&1; if(IREMCon) {ROM_BANK8(0xc000,mapbyte1[1]);ROM_BANK8(0x8000,~1);} else {ROM_BANK8(0x8000,mapbyte1[1]); ROM_BANK8(0xc000,~1);} MIRROR_SET(V&1); + X6502_Rebase(); break; case 0xa:ROM_BANK8(0xA000,V); + X6502_Rebase(); break; } diff --git a/mappers/33.c b/mappers/33.c index baa2bf9..a675ec0 100644 --- a/mappers/33.c +++ b/mappers/33.c @@ -30,9 +30,11 @@ static DECLFW(Mapper33_write) else switch(A){ case 0x8000:if(!mapbyte1[0]) MIRROR_SET((V>>6)&1); - ROM_BANK8(0x8000,V); + ROM_BANK8(0x8000,V); + X6502_Rebase(); break; - case 0x8001:ROM_BANK8(0xA000,V); break; + case 0x8001:ROM_BANK8(0xA000,V); + X6502_Rebase();break; case 0x8002:VROM_BANK2(0x0000,V);break; case 0x8003:VROM_BANK2(0x0800,V);break; case 0xc000:IRQLatch=V;break; @@ -48,7 +50,7 @@ static void heho(void) if(IRQa) { IRQCount++; - if(IRQCount==0x100) + if(IRQCount==0x100) { TriggerIRQ(); IRQa=0; diff --git a/mappers/40.c b/mappers/40.c index 30f9459..d608de2 100644 --- a/mappers/40.c +++ b/mappers/40.c @@ -27,7 +27,8 @@ static DECLFW(Mapper40_write) { case 0x8000:IRQa=0;IRQCount=0;break; case 0xa000:IRQa=1;break; - case 0xe000:ROM_BANK8(0xc000,V&7);break; + case 0xe000:ROM_BANK8(0xc000,V&7); + X6502_Rebase();break; } } @@ -35,7 +36,7 @@ static void FP_FASTAPASS(1) Mapper40IRQ(int a) { if(IRQa) { - if(IRQCount<4096) + if(IRQCount<4096) IRQCount+=a; else { diff --git a/mappers/41.c b/mappers/41.c index 1139db9..ce63408 100644 --- a/mappers/41.c +++ b/mappers/41.c @@ -29,6 +29,7 @@ DECLFW(Mapper41_write) if(A<0x8000) { ROM_BANK32(A&7); + X6502_Rebase(); MIRROR_SET((A>>5)&1); calreg=A; calchr&=0x3; diff --git a/mappers/42.c b/mappers/42.c index 2700227..6bab879 100644 --- a/mappers/42.c +++ b/mappers/42.c @@ -25,7 +25,8 @@ static DECLFW(Mapper42_write) { switch(A&0xe003) { - case 0xe000:mapbyte1[0]=V;ROM_BANK8(0x6000,V&0xF);break; + case 0xe000:mapbyte1[0]=V;ROM_BANK8(0x6000,V&0xF); + X6502_Rebase();break; case 0xe001:MIRROR_SET((V>>3)&1);break; case 0xe002:IRQa=V&2;if(!IRQa) IRQCount=0;break; } diff --git a/mappers/43.c b/mappers/43.c index 2e5f427..0ca0cee 100644 --- a/mappers/43.c +++ b/mappers/43.c @@ -54,6 +54,7 @@ DECLFW(Mapper43_write) } else ROM_BANK32(m); + X6502_Rebase(); } void Mapper43_init(void) diff --git a/mappers/46.c b/mappers/46.c index 4157f2b..ab8133e 100644 --- a/mappers/46.c +++ b/mappers/46.c @@ -30,6 +30,7 @@ DECLFW(Mapper46_writel) A64reg=V; ROM_BANK32((A64wr&1)+((A64reg&0xF)<<1)); VROM_BANK8(((A64wr>>4)&7)+((A64reg&0xF0)>>1)); + X6502_Rebase(); } DECLFW(Mapper46_write) @@ -37,6 +38,7 @@ DECLFW(Mapper46_write) A64wr=V; ROM_BANK32((V&1)+((A64reg&0xF)<<1)); VROM_BANK8(((V>>4)&7)+((A64reg&0xF0)>>1)); + X6502_Rebase(); } void Mapper46_init(void) diff --git a/mappers/51.c b/mappers/51.c index c6a33f3..90986ea 100644 --- a/mappers/51.c +++ b/mappers/51.c @@ -26,7 +26,7 @@ static uint32 Get8K(uint32 A) { uint32 bank; - + bank=(page<<2)|((A>>13)&1); if(A&0x4000 && !(mode&1)) bank|=0xC; @@ -45,6 +45,7 @@ static void Synco(void) MIRROR_SET2(0); for(x=0x6000;x<0x10000;x+=8192) ROM_BANK8(x,Get8K(x)); + X6502_Rebase(); } static DECLFW(Write) diff --git a/mappers/6.c b/mappers/6.c index 015aa9c..29caa6a 100644 --- a/mappers/6.c +++ b/mappers/6.c @@ -51,6 +51,7 @@ DECLFW(Mapper6_write) } else { ROM_BANK16(0x8000,V>>2); FVRAM_BANK8(0x0000,V&3); + X6502_Rebase(); } } void Mapper6_StateRestore(int version) diff --git a/mappers/64.c b/mappers/64.c index 96dbac2..68c7696 100644 --- a/mappers/64.c +++ b/mappers/64.c @@ -68,6 +68,7 @@ static void Synco(void) setprg8(0xA000,regsl[7]); setprg8(0xC000,regsh[7]); + X6502_Rebase(); } @@ -105,7 +106,7 @@ static DECLFW(RAMBO1_write) if(rmode==1) {IRQCount=IRQLatch;} break; - } + } } static void RAMBO1_Restore(int version) diff --git a/mappers/65.c b/mappers/65.c index b4051e8..51983ef 100644 --- a/mappers/65.c +++ b/mappers/65.c @@ -39,7 +39,8 @@ DECLFW(Mapper65_write) { switch(A) { -case 0x8000:ROM_BANK8(0x8000,V);break; +case 0x8000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; case 0x9000:MIRROR_SET2((V>>6)&1);break; case 0x9003:IRQa=V&0x80;break; case 0x9004:IRQCount=IRQLatch;break; @@ -56,8 +57,10 @@ case 0xB004:VROM_BANK1(0x1000,V);break; case 0xB005:VROM_BANK1(0x1400,V);break; case 0xB006:VROM_BANK1(0x1800,V);break; case 0xB007:VROM_BANK1(0x1C00,V);break; -case 0xa000:ROM_BANK8(0xA000,V);break; -case 0xC000:ROM_BANK8(0xC000,V);break; +case 0xa000:ROM_BANK8(0xA000,V); + X6502_Rebase();break; +case 0xC000:ROM_BANK8(0xC000,V); + X6502_Rebase();break; } } diff --git a/mappers/67.c b/mappers/67.c index 96c695b..f5bbb2b 100644 --- a/mappers/67.c +++ b/mappers/67.c @@ -48,7 +48,8 @@ DECLFW(Mapper67_write) case 3:onemir(1);break; } break; - case 0xf800:ROM_BANK16(0x8000,V);break; + case 0xf800:ROM_BANK16(0x8000,V); + X6502_Rebase();break; } } static void FP_FASTAPASS(1) SunIRQHook(int a) diff --git a/mappers/68.c b/mappers/68.c index 98cb0d8..f1e5f68 100644 --- a/mappers/68.c +++ b/mappers/68.c @@ -74,7 +74,8 @@ DECLFW(Mapper68_write) PPUNTARAM=0; } break; - case 0xf000: ROM_BANK16(0x8000,V);break; + case 0xf000: ROM_BANK16(0x8000,V); + X6502_Rebase();break; } } diff --git a/mappers/69.c b/mappers/69.c index ec6336f..66e702f 100644 --- a/mappers/69.c +++ b/mappers/69.c @@ -39,7 +39,7 @@ DECLFW(SUN5BWRAM) DECLFR(SUN5AWRAM) { if((sungah&0xC0)==0x40) - return X.DB; + return X.DB; return CartBR(A); } @@ -67,7 +67,7 @@ DECLFW(Mapper69_SWH) DoAYSQ(1); DoAYSQ(2);break; } - MapperExRAM[sunindex]=V; + MapperExRAM[sunindex]=V; } DECLFW(Mapper69_write) @@ -91,10 +91,14 @@ DECLFW(Mapper69_write) } else setprg8(0x6000,V); + X6502_Rebase(); break; - case 9:ROM_BANK8(0x8000,V);break; - case 0xa:ROM_BANK8(0xa000,V);break; - case 0xb:ROM_BANK8(0xc000,V);break; + case 9:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0xa:ROM_BANK8(0xa000,V); + X6502_Rebase();break; + case 0xb:ROM_BANK8(0xc000,V); + X6502_Rebase();break; case 0xc: switch(V&3) { @@ -121,7 +125,7 @@ static void DoAYSQ(int x) unsigned char amp; int32 start,end; - start=CAYBC[x]; + start=CAYBC[x]; end=(timestamp<<16)/soundtsinc; if(end<=start) return; CAYBC[x]=end; @@ -153,7 +157,7 @@ static void DoAYNoise(void) unsigned char amp; int32 start,end; - start=CAYBC[3]; + start=CAYBC[3]; end=(timestamp<<16)/soundtsinc; if(end<=start) return; CAYBC[3]=end; @@ -239,13 +243,13 @@ static void M69SC(void) { if(FSettings.SndRate) Mapper69_ESI(); - else + else SetWriteHandler(0xc000,0xffff,(writefunc)0); } void Mapper69_ESI(void) { - GameExpSound.RChange=M69SC; + GameExpSound.RChange=M69SC; if(FSettings.SndRate) { SetWriteHandler(0xc000,0xdfff,Mapper69_SWL); diff --git a/mappers/71.c b/mappers/71.c index 7643978..4c34706 100644 --- a/mappers/71.c +++ b/mappers/71.c @@ -29,7 +29,8 @@ switch(A&0xF000) case 0xF000: case 0xE000: case 0xD000: - case 0xC000:ROM_BANK16(0x8000,V);break; + case 0xC000:ROM_BANK16(0x8000,V); + X6502_Rebase();break; case 0x9000:onemir((V>>3)&2);break; } } diff --git a/mappers/72.c b/mappers/72.c index dcc5828..c0a2c63 100644 --- a/mappers/72.c +++ b/mappers/72.c @@ -25,7 +25,10 @@ DECLFW(Mapper72_write) { mapbyte1[0]=V; if(V&0x80) + { ROM_BANK16(0x8000,V&0xF); + X6502_Rebase(); + } if(V&0x40) VROM_BANK8(V&0xF); } diff --git a/mappers/73.c b/mappers/73.c index ca230f8..0911fd8 100644 --- a/mappers/73.c +++ b/mappers/73.c @@ -31,7 +31,8 @@ switch(A&0xF000) case 0xa000:IRQCount&=0xF0FF;IRQCount|=(V&0xF)<<8;break; case 0xb000:IRQCount&=0x0FFF;IRQCount|=(V&0xF)<<12;break; case 0xc000:IRQa=V&2;break; - case 0xf000:ROM_BANK16(0x8000,V);break; + case 0xf000:ROM_BANK16(0x8000,V); + X6502_Rebase();break; } } diff --git a/mappers/75.c b/mappers/75.c index 0bd2711..cf0c6ee 100644 --- a/mappers/75.c +++ b/mappers/75.c @@ -28,13 +28,16 @@ DECLFW(Mapper75_write) { switch(A&0xF000) { - case 0x8000:ROM_BANK8(0x8000,V);break; + case 0x8000:ROM_BANK8(0x8000,V); + X6502_Rebase();break; case 0x9000: VROM_BANK4(0x0000,map75ar[0]|((V&2)<<3)); VROM_BANK4(0x1000,map75ar[1]|((V&4)<<2)); map75sel=V;MIRROR_SET(V&1);break; - case 0xa000:ROM_BANK8(0xa000,V);break; - case 0xc000:ROM_BANK8(0xc000,V);break; + case 0xa000:ROM_BANK8(0xa000,V); + X6502_Rebase();break; + case 0xc000:ROM_BANK8(0xc000,V); + X6502_Rebase();break; case 0xe000:V&=0xF;map75ar[0]=V;V|=(map75sel&2)<<3;VROM_BANK4(0x0000,V);break; case 0xf000:V&=0xF;map75ar[1]=V;V|=(map75sel&4)<<2;VROM_BANK4(0x1000,V);break; } diff --git a/mappers/76.c b/mappers/76.c index d901bb7..40aa821 100644 --- a/mappers/76.c +++ b/mappers/76.c @@ -37,8 +37,10 @@ DECLFW(Mapper76_write) case 6: if (MMC3_cmd&0x40) ROM_BANK8(0xC000,V); else ROM_BANK8(0x8000,V); + X6502_Rebase(); break; case 7: ROM_BANK8(0xA000,V); + X6502_Rebase(); break; } break; diff --git a/mappers/77.c b/mappers/77.c index e9d0015..e3c0e52 100644 --- a/mappers/77.c +++ b/mappers/77.c @@ -27,16 +27,18 @@ static DECLFW(Mapper77_write) mapbyte1[0]=V; ROM_BANK32(V&0x7); VROM_BANK2(0x0000, (V&0xf0)>>4); + X6502_Rebase(); } static void Mapper77_StateRestore(int version) { int x; - + if(version>=72) { ROM_BANK32(mapbyte1[0]&0x7); VROM_BANK2(0x0000, (mapbyte1[0]&0xf0)>>4); + X6502_Rebase(); } for(x=2;x<8;x++) VRAM_BANK1(x*0x400,x); diff --git a/mappers/79.c b/mappers/79.c index 5e79efe..1e9d219 100644 --- a/mappers/79.c +++ b/mappers/79.c @@ -27,6 +27,7 @@ DECLFW(Mapper79_write) if(A<0x8000 && ((A^0x4100)==0)) { ROM_BANK32((V>>3)&1); + X6502_Rebase(); } VROM_BANK8(V); } diff --git a/mappers/8.c b/mappers/8.c index 1a68bf8..46a7d00 100644 --- a/mappers/8.c +++ b/mappers/8.c @@ -28,6 +28,7 @@ DECLFW(Mapper8_write) { ROM_BANK16(0x8000,V>>3); VROM_BANK8(V&7); + X6502_Rebase(); } void Mapper8_init(void) diff --git a/mappers/80.c b/mappers/80.c index c824a12..b867398 100644 --- a/mappers/80.c +++ b/mappers/80.c @@ -34,11 +34,14 @@ switch(A) case 0x7ef4: VROM_BANK1(0x1800,V);break; case 0x7ef5: VROM_BANK1(0x1c00,V);break; case 0x7efa: - case 0x7efb: ROM_BANK8(0x8000,V);break; + case 0x7efb: ROM_BANK8(0x8000,V); + X6502_Rebase();break; case 0x7efd: - case 0x7efc: ROM_BANK8(0xA000,V);break; + case 0x7efc: ROM_BANK8(0xA000,V); + X6502_Rebase();break; case 0x7efe: - case 0x7eff: ROM_BANK8(0xC000,V);break; + case 0x7eff: ROM_BANK8(0xC000,V); + X6502_Rebase();break; } } diff --git a/mappers/82.c b/mappers/82.c index b6a1cb2..a4f643e 100644 --- a/mappers/82.c +++ b/mappers/82.c @@ -46,9 +46,12 @@ static DECLFW(Mapper82_write) MIRROR_SET2(V&1); DoCHR(); break; - case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V);break; - case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V);break; - case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V);break; + case 0x7efa:V>>=2;mapbyte2[0]=V;ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 0x7efb:V>>=2;mapbyte2[1]=V;ROM_BANK8(0xa000,V); + X6502_Rebase();break; + case 0x7efc:V>>=2;mapbyte2[2]=V;ROM_BANK8(0xc000,V); + X6502_Rebase();break; } } diff --git a/mappers/83.c b/mappers/83.c index 6bcca19..5cc7d03 100644 --- a/mappers/83.c +++ b/mappers/83.c @@ -48,6 +48,7 @@ static void m83prg(void) { ROM_BANK16(0x8000,mapbyte1[0]&0x3F); ROM_BANK16(0xC000,(mapbyte1[0]&0x30)|0xF); + X6502_Rebase(); } static void m83chr(void) @@ -96,7 +97,7 @@ static DECLFW(Mapper83_write) case 0x8317:mapbyte2[7]=V;m83chr();break; } // printf("$%04x:$%02x, $%04x\n",A,V,X.PC.W); - + } void Mapper83_init(void) diff --git a/mappers/85.c b/mappers/85.c index 0d45898..c93788b 100644 --- a/mappers/85.c +++ b/mappers/85.c @@ -59,9 +59,12 @@ DECLFW(Mapper85_write) } else switch(A&0xF010) { - case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V);break; - case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V);break; - case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V);break; + case 0x8000:mapbyte2[0]=V;setprg8(0x8000,V); + X6502_Rebase();break; + case 0x8010:mapbyte2[1]=V;setprg8(0xa000,V); + X6502_Rebase();break; + case 0x9000:mapbyte2[2]=V;setprg8(0xc000,V); + X6502_Rebase();break; case 0x9010:indox=V;break; case 0xe000:mapbyte2[3]=V;DaMirror(V);break; case 0xE010:IRQLatch=V; diff --git a/mappers/86.c b/mappers/86.c index 5bcefcd..60777b8 100644 --- a/mappers/86.c +++ b/mappers/86.c @@ -24,6 +24,7 @@ DECLFW(Mapper86_write) { VROM_BANK8((V&3)|((V>>4)&4)); ROM_BANK32((V>>4)&3); + X6502_Rebase(); } void Mapper86_init(void) diff --git a/mappers/88.c b/mappers/88.c index d6a7f86..84c9ded 100644 --- a/mappers/88.c +++ b/mappers/88.c @@ -41,8 +41,10 @@ static DECLFW(Mapper88_write) case 3:VROM_BANK1(0x1400,V|0x40);break; case 4:VROM_BANK1(0x1800,V|0x40);break; case 5:VROM_BANK1(0x1c00,V|0x40);break; - case 6:ROM_BANK8(0x8000,V);break; - case 7:ROM_BANK8(0xA000,V);break; + case 6:ROM_BANK8(0x8000,V); + X6502_Rebase();break; + case 7:ROM_BANK8(0xA000,V); + X6502_Rebase();break; } break; diff --git a/mappers/89.c b/mappers/89.c index 696e698..cdc028a 100644 --- a/mappers/89.c +++ b/mappers/89.c @@ -25,6 +25,7 @@ DECLFW(Mapper89_write) VROM_BANK8((V&7)|((V>>4)&8)); ROM_BANK16(0x8000,(V>>4)&7); onemir((V>>3)&1); + X6502_Rebase(); } void Mapper89_init(void) diff --git a/mappers/90.c b/mappers/90.c index 97405dc..35ceb0d 100644 --- a/mappers/90.c +++ b/mappers/90.c @@ -52,6 +52,7 @@ static void tekprom(void) ROM_BANK8(0xe000,prgb[3]); break; } + X6502_Rebase(); } static void tekvrom(void) @@ -132,7 +133,7 @@ static void Mapper90_hb(void) { if(IRQa) { - if(IRQCount) + if(IRQCount) { IRQCount--; if(!IRQCount) diff --git a/mappers/92.c b/mappers/92.c index 1494e7f..4b8ce71 100644 --- a/mappers/92.c +++ b/mappers/92.c @@ -29,12 +29,12 @@ static DECLFW(Mapper92_write) if(A>=0x9000) { - if(reg==0xD) ROM_BANK16(0xc000,bank); + if(reg==0xD) { ROM_BANK16(0xc000,bank); X6502_Rebase(); } else if(reg==0xE) VROM_BANK8(bank); } else { - if(reg==0xB) ROM_BANK16(0xc000,bank); + if(reg==0xB) { ROM_BANK16(0xc000,bank); X6502_Rebase(); } else if(reg==0x7) VROM_BANK8(bank); } } diff --git a/mappers/95.c b/mappers/95.c index 2d6792b..4b208be 100644 --- a/mappers/95.c +++ b/mappers/95.c @@ -59,9 +59,11 @@ DECLFW(Mapper95_write) case 5: dbarray[7]=(V&0x20)>>4;onemir((V&0x20)>>4);VROM_BANK1(0x1C00,V); break; case 6: ROM_BANK8(0x8000,V); + X6502_Rebase(); break; case 7: ROM_BANK8(0xA000,V); + X6502_Rebase(); break; } break; diff --git a/mappers/97.c b/mappers/97.c index f019fdc..e02b12d 100644 --- a/mappers/97.c +++ b/mappers/97.c @@ -25,6 +25,7 @@ DECLFW(Mapper97_write) { ROM_BANK16(0xC000,V&15); +X6502_Rebase(); switch(V>>6) { case 0:break; diff --git a/mappers/mmc2and4.c b/mappers/mmc2and4.c index 1688d57..1b23e49 100644 --- a/mappers/mmc2and4.c +++ b/mappers/mmc2and4.c @@ -31,7 +31,7 @@ static void FP_FASTAPASS(1) latchcheck(uint32 VAddr) h=VAddr>>8; - if(h>=0x20 || ((h&0xF)!=0xF)) + if(h>=0x20 || ((h&0xF)!=0xF)) return; l=VAddr&0xF0; @@ -67,11 +67,13 @@ static void FP_FASTAPASS(1) latchcheck(uint32 VAddr) DECLFW(Mapper9_write) // $Axxx { ROM_BANK8(0x8000,V); + X6502_Rebase(); } DECLFW(Mapper10_write) { ROM_BANK16(0x8000,V); + X6502_Rebase(); } DECLFW(Mapper9and10_write) diff --git a/mappers/simple.c b/mappers/simple.c index 9318933..de6c42f 100644 --- a/mappers/simple.c +++ b/mappers/simple.c @@ -27,6 +27,7 @@ static DECLFW(Mapper2_write) { latche=V; ROM_BANK16(0x8000,V); + X6502_Rebase(); } void Mapper2_init(void) @@ -52,6 +53,7 @@ DECLFW(Mapper7_write) ROM_BANK32(V&0xF); onemir((V>>4)&1); latche=V; + X6502_Rebase(); } void Mapper7_init(void) @@ -67,6 +69,7 @@ DECLFW(Mapper11_write) ROM_BANK32(V); VROM_BANK8(V>>4); latche=V; + X6502_Rebase(); } void Mapper11_init(void) @@ -81,6 +84,7 @@ static DECLFW(Mapper13_write) setchr4r(0x10,0x1000,V&3); setprg32(0x8000,(V>>4)&3); latche=V; + X6502_Rebase(); } static void Mapper13_StateRestore(int version) @@ -88,6 +92,7 @@ static void Mapper13_StateRestore(int version) setchr4r(0x10,0x0000,0); setchr4r(0x10,0x1000,latche&3); setprg32(0x8000,(latche>>4)&3); + X6502_Rebase(); } void Mapper13_init(void) @@ -106,12 +111,16 @@ DECLFW(Mapper34_write) { switch(A) { - case 0x7FFD:ROM_BANK32(V);break; + case 0x7FFD:ROM_BANK32(V); + X6502_Rebase();break; case 0x7FFE:VROM_BANK4(0x0000,V);break; case 0x7fff:VROM_BANK4(0x1000,V);break; } -if(A>=0x8000) - ROM_BANK32(V); + if(A>=0x8000) + { + ROM_BANK32(V); + X6502_Rebase(); + } } void Mapper34_init(void) @@ -124,6 +133,7 @@ DECLFW(Mapper66_write) VROM_BANK8(V&0xF); ROM_BANK32((V>>4)); latche=V; + X6502_Rebase(); } void Mapper66_init(void) @@ -139,6 +149,7 @@ DECLFW(Mapper152_write) VROM_BANK8(V&0xF); onemir((V>>7)&1); /* Saint Seiya...hmm. */ latche=V; + X6502_Rebase(); } void Mapper152_init(void) @@ -153,6 +164,7 @@ static DECLFW(Mapper70_write) ROM_BANK16(0x8000,V>>4); VROM_BANK8(V&0xF); latche=V; + X6502_Rebase(); } void Mapper70_init(void) @@ -168,6 +180,7 @@ static DECLFW(Mapper78_write) VROM_BANK8(V>>4); onemir((V>>3)&1); latche=V; + X6502_Rebase(); } void Mapper78_init(void) @@ -193,6 +206,7 @@ DECLFW(Mapper93_write) ROM_BANK16(0x8000,V>>4); MIRROR_SET(V&1); latche=V; + X6502_Rebase(); } void Mapper93_init(void) @@ -206,6 +220,7 @@ DECLFW(Mapper94_write) { ROM_BANK16(0x8000,V>>2); latche=V; + X6502_Rebase(); } void Mapper94_init(void) @@ -226,6 +241,7 @@ static DECLFW(Mapper96_write) setprg32(0x8000,V&3); setchr4r(0x10,0x0000,(latche&4)|M96LA); setchr4r(0x10,0x1000,(latche&4)|3); + X6502_Rebase(); } static void FP_FASTAPASS(1) M96Hook(uint32 A) @@ -241,6 +257,7 @@ static void M96Sync() setprg32(0x8000,latche&3); setchr4r(0x10,0x0000,(latche&4)|M96LA); setchr4r(0x10,0x1000,(latche&4)|3); + X6502_Rebase(); } void Mapper96_init(void) @@ -259,6 +276,7 @@ static DECLFW(Mapper140_write) { VROM_BANK8(V&0xF); ROM_BANK32((V>>4)&0xF); + X6502_Rebase(); } void Mapper140_init(void) diff --git a/mbshare/mmc1.c b/mbshare/mmc1.c index 8b238d7..8386ee3 100644 --- a/mbshare/mmc1.c +++ b/mbshare/mmc1.c @@ -38,7 +38,7 @@ static DECLFW(MBWRAM) static DECLFR(MAWRAM) { - if(MMC1_reg[3]&0x10) + if(MMC1_reg[3]&0x10) return X.DB; // WRAM is disabled return(Page[A>>11][A]); } @@ -51,6 +51,7 @@ static void MMC1CHR(void) setprg8r(0x10,0x6000,(MMC1_reg[1]>>4)&1); else setprg8r(0x10,0x6000,(MMC1_reg[1]>>3)&1); + X6502_Rebase(); } if(MMC1_reg[0]&0x10) @@ -81,6 +82,7 @@ static void MMC1PRG(void) setprg16(0xc000,((MMC1_reg[3]&~1)+offs+1)); break; } + X6502_Rebase(); } static void MMC1MIRROR(void) { @@ -189,7 +191,7 @@ void Mapper1_init(void) { lreset=0; mmc1opts=0; - MMC1CMReset(); + MMC1CMReset(); SetWriteHandler(0x8000,0xFFFF,MMC1_write); MapStateRestore=MMC1_Restore; AddExState(&lreset, 8, 1, "LRST"); @@ -245,8 +247,8 @@ static void GenMMC1Init(int prg, int chr, int wram, int battery) CHRmask4[0]&=(chr>>12)-1; CHRmask8[0]&=(chr>>13)-1; - if(wram) - { + if(wram) + { mmc1opts|=1; if(wram>8) mmc1opts|=4; SetupCartPRGMapping(0x10,WRAM,wram*1024,1); @@ -279,7 +281,7 @@ static void GenMMC1Init(int prg, int chr, int wram, int battery) //static void GenMMC1Init(int prg, int chr, int wram, int battery) void SAROM_Init(void) { - GenMMC1Init(128, 64, 8, 1); + GenMMC1Init(128, 64, 8, 1); } void SBROM_Init(void) @@ -287,7 +289,7 @@ void SBROM_Init(void) GenMMC1Init(128, 64, 0, 0); } -void SCROM_Init(void) +void SCROM_Init(void) { GenMMC1Init(128, 128, 0, 0); } diff --git a/mbshare/mmc3.c b/mbshare/mmc3.c index e1e55c8..872e376 100644 --- a/mbshare/mmc3.c +++ b/mbshare/mmc3.c @@ -65,7 +65,7 @@ static DECLFW(MMC3_IRQWrite) resetmode=1; break; case 0xE001:IRQa=1; - if(latched) + if(latched) IRQCount=IRQLatch; break; } @@ -85,6 +85,7 @@ static INLINE void FixMMC3PRG(int V) } pwrap(0xA000,DRegBuf[7]); pwrap(0xE000,~0); + X6502_Rebase(); } static INLINE void FixMMC3CHR(int V) @@ -148,8 +149,10 @@ static DECLFW(Mapper4_write) 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; } } @@ -213,8 +216,8 @@ static void GENNOMWRAP(uint8 V) A000B=V; } -static void genmmc3ii(void (*PW)(uint32 A, uint8 V), - void (*CW)(uint32 A, uint8 V), +static void genmmc3ii(void (*PW)(uint32 A, uint8 V), + void (*CW)(uint32 A, uint8 V), void (*MW)(uint8 V)) { pwrap=GENPWRAP; @@ -262,7 +265,7 @@ static DECLFW(M47Write) { PIRREGS[0]=V&1; FixMMC3PRG(MMC3_cmd); - FixMMC3CHR(MMC3_cmd); + FixMMC3CHR(MMC3_cmd); } void Mapper47_init(void) @@ -324,7 +327,7 @@ static void M52CW(uint32 A, uint8 V) static DECLFW(Mapper52_write) { - if(PIRREGS[1]) + if(PIRREGS[1]) { (WRAM-0x6000)[A]=V; return; @@ -338,7 +341,7 @@ static DECLFW(Mapper52_write) static void M52Reset(void) { PIRREGS[0]=PIRREGS[1]=0; - MMC3RegReset(); + MMC3RegReset(); } void Mapper52_init(void) @@ -397,7 +400,10 @@ static void M49PW(uint32 A, uint8 V) setprg8(A,V); } else + { setprg32(0x8000,(PIRREGS[0]>>4)&3); + X6502_Rebase(); + } } static void M49CW(uint32 A, uint8 V) @@ -459,7 +465,7 @@ static void FP_FASTAPASS(1) TKSPPU(uint32 A) //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); + // setmirror(MI_1); //printf("$%04x\n",A); A>>=10; diff --git a/mbshare/mmc5.c b/mbshare/mmc5.c index bb3e8f1..00cdae7 100644 --- a/mbshare/mmc5.c +++ b/mbshare/mmc5.c @@ -25,7 +25,7 @@ void MMC5Sound(int Count); void Do5SQ(int P); -static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) +static INLINE void MMC5SPRVROM_BANK1(uint32 A,uint32 V) { if(CHRptr[0]) { @@ -46,7 +46,7 @@ static INLINE void MMC5SPRVROM_BANK8(uint32 V) {if(CHRptr[0]){V&=CHRmask8[0];MMC 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]; +uint8 MMC5fill[0x400] __attribute__ ((aligned (4))); #define MMC5IRQR mapbyte3[4] #define MMC5LineCounter mapbyte3[5] @@ -216,6 +216,7 @@ static void MMC5PRG(void) 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; @@ -302,8 +303,10 @@ static DECLFW(Mapper5_write) mapbyte4[3]=V; break; - case 0x5113:mapbyte4[6]=V;MMC5WRAM(0x6000,V&7);break; - case 0x5100:mapbyte1[0]=V;MMC5PRG();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();} @@ -315,7 +318,8 @@ static DECLFW(Mapper5_write) case 0x5115: case 0x5116: case 0x5117: - mapbyte1[A&7]=V;MMC5PRG();break; + mapbyte1[A&7]=V;MMC5PRG(); + X6502_Rebase();break; case 0x5120: case 0x5121: @@ -455,6 +459,7 @@ void MMC5Synco(void) } X6502_IRQEnd(FCEU_IQEXT); MMC5HackCHRMode=mapbyte4[2]&3; + X6502_Rebase(); } void MMC5_hbo(void) @@ -485,7 +490,7 @@ void MMC5_hb(void) if(MMC5LineCounter<240) { MMC5LineCounter++; - if(MMC5LineCounter==IRQCount) + if(MMC5LineCounter==IRQCount) { MMC5IRQR|=0x80; if(IRQa&0x80) @@ -523,7 +528,7 @@ static void Do5PCM(void) end=(timestamp<<16)/soundtsinc; if(end<=start) return; C5BC[2]=end; - + if(!(MMC5PSG[0x10]&0x40) && MMC5PSG[0x11]) for(V=start;V>4]+=MMC5PSG[0x11]<<2; @@ -623,7 +628,7 @@ static void MMC5SoundC(void) if(FSettings.SndRate) Mapper5_ESI(); else - SetWriteHandler(0x5000,0x5015,0); + SetWriteHandler(0x5000,0x5015,0); } void Mapper5_ESI(void) @@ -706,7 +711,7 @@ static void GenMMC5_Init(int wsize, int battery) AddExState(&MMC5HackSPScroll, 1, 0, "SPLS"); AddExState(&MMC5HackSPPage, 1, 0, "SPLP"); - MMC5WRAMsize=wsize/8; + MMC5WRAMsize=wsize/8; BuildWRAMSizeTable(); GameStateRestore=Mapper5_StateRestore; BoardPower=GenMMC5Reset; diff --git a/ncpu.S b/ncpu.S index 2a7fafe..410baa8 100644 --- a/ncpu.S +++ b/ncpu.S @@ -16,7 +16,7 @@ #define OTOFFS_NES_REGS (nes_registers - cpu_exec_table) #define OTOFFS_PC_BASE (pc_base - cpu_exec_table) #define OTOFFS_IRQ_HOOK (MapIRQHook - cpu_exec_table) -#define OTOFFS_X (X - cpu_exec_table) +#define OTOFFS_X (X_ - cpu_exec_table) @ fceu #define FCEU_IQNMI 0x08 @@ -30,6 +30,10 @@ SECTION_TEXT ALIGN +bbbb: +.ascii "rebase: %04x" +.byte 0x0a,0 +.align 4 @@@ @@ -38,6 +42,12 @@ @@@ .macro REBASE_PC @ FIXME: do something with mem not in Page[]. +@ stmfd sp!, {r0-r3,r12,lr} +@ mov r1, r0 +@ ldr r0, =bbbb +@ bl printf +@ ldmfd sp!, {r0-r3,r12,lr} + cmp r0, #0x2000 ldrge r1, =Page movge r2, r0, lsr #11 @@ -2822,10 +2832,20 @@ read_save_ram: mov REG_PC, lr @ r7 mov REG_P_REST, r3 @ r8 +#ifndef DEBUG_ASM_6502 ldr r2, =ARead bic r0, REG_ADDR, #0x00ff0000 mov lr, pc ldr pc, [r2, r0, lsl #2] +#else + ldr r1, =cpu_lastval + ldr r0, [r1] + tst r0, #0x20000 + orreq r0, r0, #0x20000 + streq r0, [r1] + movne r0, r0, lsr #8 + and r0, r0, #0xff +#endif ldr REG_OP_TABLE, =cpu_exec_table @ got trashed because was in r12 mov lr, REG_PC @@ -2841,6 +2861,7 @@ write_ppu_reg: write_high_reg: write_save_ram: write_rom_byte: +#ifndef DEBUG_ASM_6502 @ must preserve r3 for the callers too str REG_PC, [REG_OP_TABLE, #(OTOFFS_NES_REGS + 0x0c)] @ might get rebased str REG_P_REST, [REG_OP_TABLE, #(OTOFFS_NES_REGS + 0x10)] @ might set irq @@ -2860,6 +2881,7 @@ write_rom_byte: ldr REG_PC, [REG_OP_TABLE, #(OTOFFS_NES_REGS + 0x0c)] @ might get rebased ldr REG_P_REST, [REG_OP_TABLE, #(OTOFFS_NES_REGS + 0x10)] @ might set irq ldr REG_CYCLE, [REG_OP_TABLE, #(OTOFFS_NES_REGS + 0x1c)] @ might get used +#endif bx lr @@ -2958,9 +2980,7 @@ cpu_exec_table: @@@ nes_registers: .fill 0x40, 1, 0 -#ifndef DEBUG_ASM_6502 RAM: -#endif nes_internal_ram: .fill 0x100, 1, 0 nes_stack: @@ -2968,13 +2988,14 @@ nes_stack: @ TODO: write code which keeps it up-to-date pc_base: .long 0 -#ifndef DEBUG_ASM_6502 MapIRQHook: .long 0 timestamp: .long 0 -X: .fill 0x20, 1, 0 +#ifndef DEBUG_ASM_6502 +X: #endif +X_: .fill 0x20, 1, 0 .pool @@ -3090,6 +3111,8 @@ op9E: @ SHX $nnnn, Y .globl RAM .globl timestamp .globl MapIRQHook @ (int a) +#else + .globl nes_internal_ram #endif .globl X6502_Reset_a @ (void); .globl X6502_Power_a @ (void); @@ -3100,7 +3123,7 @@ op9E: @ SHX $nnnn, Y .globl X6502_AddCycles_a @ (int x); .globl X6502_IRQBegin_a @ (int w); .globl X6502_IRQEnd_a @ (int w); - .globl X6502_rebase_a @ (void); + .globl X6502_Rebase_a @ (void); SECTION_TEXT ALIGN @@ -3166,7 +3189,7 @@ X6502_AddCycles_a: @ rebase PC when not executing or in memhandlers -X6502_rebase_a: +X6502_Rebase_a: stmfd sp!,{REG_PC,REG_OP_TABLE} ldr REG_OP_TABLE, =cpu_exec_table ldr r0, [REG_OP_TABLE, #(OTOFFS_NES_REGS+0x0c)] @ PC diff --git a/ncpu_debug.c b/ncpu_debug.c index ebb32fa..7da9b73 100644 --- a/ncpu_debug.c +++ b/ncpu_debug.c @@ -8,15 +8,19 @@ // asm core state extern uint32 nes_registers[0x10]; extern uint32 pc_base; -uint32 PC_prev = 0, g_cnt = 0; +extern uint8 nes_internal_ram[0x800]; +uint32 PC_prev = 0xcccccc, OP_prev = 0xcccccc; +int32 g_cnt = 0; int cpu_repeat; int cpu_lastval; +static int pending_add_cycles = 0, pending_rebase = 0; static void leave(void) { printf("\nA: %02x, X: %02x, Y: %02x, S: %02x\n", X.A, X.X, X.Y, X.S); - printf("PC = %04lx, OP=%02X\n", PC_prev, (PC_prev < 0x2000) ? RAM[PC_prev&0x7ff] : ARead[PC_prev](PC_prev)); + printf("PC = %04lx, OP=%02lX\n", PC_prev, OP_prev); + printf("cpu_lastval = %02x\n", cpu_lastval); exit(1); } @@ -74,6 +78,24 @@ static void compare_state(void) if (fail) leave(); } +#if 1 +static void compare_ram(void) +{ + int i, fail = 0; + for (i = 0; i < 0x800/4; i++) + { + if (((int *)nes_internal_ram)[i] != ((int32 *)RAM)[i]) { + int u; + fail = 1; + for (u = i*4; u < i*4+4; u++) + if (nes_internal_ram[u] != RAM[u]) + printf("RAM[%03x]: %02x vs %02x\n", u, nes_internal_ram[u], RAM[u]); + } + } + + if (fail) leave(); +} +#endif void TriggerIRQ_d(void) { @@ -97,18 +119,21 @@ void TriggerNMINSF_d(void) void X6502_Run_d(int32 c) { - int32 cycles = c << 4; /* *16 */ \ - if (PAL) cycles -= c; /* *15 */ \ + int32 cycles = c << 4; /* *16 */ + if (PAL) cycles -= c; /* *15 */ //printf("-- %06i: run(%i)\n", (int)g_cnt, (int)c); - g_cnt += c; + g_cnt += cycles; - while (cycles > 0) + if (c > 200) + compare_ram(); + + while (g_cnt > 0) { - PC_prev = X.PC; nes_registers[7]=1; X.count=1; + cpu_lastval = 0; cpu_repeat = 0; X6502_Run_c(); @@ -116,7 +141,17 @@ void X6502_Run_d(int32 c) X6502_Run_a(); compare_state(); - cycles -= 1 - X.count; + g_cnt -= 1 - X.count; + if (pending_add_cycles) { + //X6502_AddCycles_c(pending_add_cycles); + //X6502_AddCycles_a(pending_add_cycles); + g_cnt -= pending_add_cycles*48; + pending_add_cycles = 0; + } + if (pending_rebase) { + X6502_Rebase_a(); + pending_rebase = 0; + } } //printf("-- run_end\n"); @@ -134,6 +169,7 @@ void X6502_Reset_d(void) void X6502_Power_d(void) { printf("-- power\n"); + if (nes_internal_ram == RAM) printf("nes_internal_ram == RAM!!\n"); X6502_Power_c(); X6502_Power_a(); @@ -144,8 +180,9 @@ void X6502_AddCycles_d(int x) { printf("-- AddCycles(%i|%i)\n", x, x*48); - printf("can't use this in debug\n"); - exit(1); + pending_add_cycles = x; // *48; +// printf("can't use this in debug\n"); +// exit(1); //X6502_AddCycles_c(x); //X6502_AddCycles_a(x); //compare_state(); @@ -168,4 +205,9 @@ void X6502_IRQEnd_d(int w) } +void X6502_Rebase_d(void) +{ + pending_rebase = 1; +} + diff --git a/nsf.c b/nsf.c index 2d287d2..2db647c 100644 --- a/nsf.c +++ b/nsf.c @@ -123,7 +123,7 @@ static INLINE void BANKSET(uint32 A, uint32 bank) bank&=NSFMaxBank; if(NSFHeader.SoundChip&4) memcpy(FDSMEM+(A-0x6000),NSFDATA+(bank<<12),4096); - else + else setprg4(A,bank); } @@ -157,7 +157,7 @@ int NSFLoad(int fp) FCEU_fseek(fp,0x80,SEEK_SET); memset(NSFDATA,0x00,NSFMaxBank*4096); FCEU_fread(NSFDATA+(LoadAddr&0xfff),1,NSFSize,fp); - + NSFMaxBank--; BSon=0; @@ -189,7 +189,7 @@ int NSFLoad(int fp) for(x=0;x<32;x++) { double ta,no; - + ta=sin(fruit)*7; ta+=modf(ta,&no); sinetable[x]=ta; @@ -282,7 +282,7 @@ void NSF_init(void) SetReadHandler(0x4020,0x5fff,NSF_read); - if(NSFHeader.SoundChip&1) { + if(NSFHeader.SoundChip&1) { VRC6_ESI(0); } else if (NSFHeader.SoundChip&2) { VRC7_ESI(); @@ -305,7 +305,7 @@ DECLFW(NSF_write) switch(A) { case 0x5FF2:if((X.PC&0xF000)==0x3000) DoUpdateStuff=V;break; - + case 0x5FF6: case 0x5FF7:if(!(NSFHeader.SoundChip&4)) return; case 0x5FF8: @@ -318,6 +318,7 @@ switch(A) case 0x5FFF:if(!BSon) return; A&=0xF; BANKSET((A*4096),V); + X6502_Rebase(); break; } } @@ -343,12 +344,13 @@ DECLFR(NSF_read) BWrite[0x4011](0x4011,0x40); BWrite[0x4015](0x4015,0xF); BWrite[0x4017](0x4017,0x40); - if(NSFHeader.SoundChip&4) + if(NSFHeader.SoundChip&4) BWrite[0x4089](0x4089,0x80); if(BSon) { for(x=0;x<8;x++) BANKSET(0x8000+x*4096,NSFHeader.BankSwitch[x]); + X6502_Rebase(); } return (CurrentSong-1); } @@ -397,7 +399,7 @@ void DrawNSF(uint8 *XBuf) } void NSFControl(int z) -{ +{ if(z==1) { if(CurrentSong>1))&0x40;arrtmp=_A>>7;_A>>=1;_A|=(_P&C_FLAG)<<7;_P&=~C_FLAG;_P|=arrtmp;X_ZN(_A)); } /* ASR */ @@ -341,7 +341,7 @@ case 0x4B: LD_IM(AND;LSRA); /* ATX(OAL) Is this(OR with $EE) correct? */ case 0xAB: LD_IM(_A|=0xEE;AND;_X=_A); -/* AXS */ +/* AXS */ case 0xCB: LD_IM(AXS); /* DCP */ @@ -468,11 +468,11 @@ case 0x9B: _S=_A&_X;ST_ABY(_S& (((A-_Y)>>8)+1) ); /* TOP */ case 0x0C: LD_AB(;); -case 0x1C: -case 0x3C: -case 0x5C: -case 0x7C: -case 0xDC: +case 0x1C: +case 0x3C: +case 0x5C: +case 0x7C: +case 0xDC: case 0xFC: LD_ABX(;); /* XAA - BIG QUESTION MARK HERE */ diff --git a/out_gp2x/readme.txt b/out_gp2x/readme.txt index 6218b92..235eaec 100644 --- a/out_gp2x/readme.txt +++ b/out_gp2x/readme.txt @@ -81,6 +81,12 @@ Current Features -------------------------------------------------------------------- +ver 0.4 (by notaz) + + - Compatibility fixes for the asm core. + - Fixed an anligment problem in MMC5 mapper. + + ver 0.3 (by notaz) - Major improvement: added ARM asm CPU core from LJGP32, diff --git a/state.h b/state.h index 75b2623..71163f7 100644 --- a/state.h +++ b/state.h @@ -18,6 +18,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + void SaveState(void); void LoadState(void); int FCEUSS_LoadFP(FILE *st, int make_backup); diff --git a/x6502.c b/x6502.c index cb0d761..81eb56e 100644 --- a/x6502.c +++ b/x6502.c @@ -26,6 +26,11 @@ #include "sound.h" #include "cart.h" +#ifdef DEBUG_ASM_6502 +extern uint32 PC_prev, OP_prev; +extern int cpu_lastval; +#endif + X6502 X; uint32 timestamp; void FP_FASTAPASS(1) (*MapIRQHook)(int a); @@ -59,7 +64,16 @@ static INLINE uint8 RdMem(unsigned int A) return (_DB=RAM[A&0x7FF]); } #endif - return((_DB=ARead[A](A))); + _DB=ARead[A](A); +#ifdef DEBUG_ASM_6502 + // TODO: read counter, not 0x10000.. + if (cpu_lastval) + cpu_lastval|=_DB<<8; + else + cpu_lastval=_DB|0x10000; + printf("read [%04x] %02x, cpu_lastval=%02x\n", A, _DB, cpu_lastval); +#endif + return _DB; } static INLINE void WrMem(unsigned int A, uint8 V) @@ -130,7 +144,7 @@ static uint8 ZNTable[256] = { //#define X_ZN(zort) _P&=~(Z_FLAG|N_FLAG);_P|=ZNTable[zort] //#define X_ZNT(zort) _P|=ZNTable[zort] #define X_ZN(zort) _P&=~(Z_FLAG|N_FLAG);if(!zort) _P|=Z_FLAG;else _P|=zort&N_FLAG -#define X_ZNT(zort) if(!zort) _P|=Z_FLAG;else _P|=zort&N_FLAG +#define X_ZNT(zort) if(!zort) _P|=Z_FLAG;else _P|=(zort&N_FLAG) /* Care must be taken if you want to turn this into a macro. Use { and }. */ #define JR(); \ @@ -402,9 +416,14 @@ static void TriggerNMIReal(void) ADDCYC(7); PUSH(_PC>>8); PUSH(_PC); - PUSH((_P&~B_FLAG)|(U_FLAG)); + _P&=~B_FLAG; + PUSH(_P|U_FLAG); _PC=RdMem(0xFFFA); _PC|=RdMem(0xFFFB)<<8; +#ifdef DEBUG_ASM_6502 + PC_prev = _PC; + OP_prev = 0x100; +#endif } } @@ -415,10 +434,15 @@ void TriggerIRQReal(void) ADDCYC(7); PUSH(_PC>>8); PUSH(_PC); - PUSH((_P&~B_FLAG)|(U_FLAG)); + _P&=~B_FLAG; + PUSH(_P|U_FLAG); _P|=I_FLAG; _PC=RdMem(0xFFFE); _PC|=RdMem(0xFFFF)<<8; +#ifdef DEBUG_ASM_6502 + PC_prev = _PC; + OP_prev = 0x101; +#endif } } @@ -440,7 +464,6 @@ void X6502_Power_c(void) //int asdc = 0; - void X6502_Run_c(void/*int32 cycles*/) { /* @@ -502,6 +525,11 @@ void X6502_Run_c(void/*int32 cycles*/) } } +#ifdef DEBUG_ASM_6502 + PC_prev = _PC; + OP_prev = b1; + cpu_lastval = 0; +#endif //printf("$%04x:$%02x\n",_PC,b1); //_PC++; //printf("$%02x\n",b1); diff --git a/x6502.h b/x6502.h index 9411108..1b63a2f 100644 --- a/x6502.h +++ b/x6502.h @@ -63,6 +63,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_AddCycles X6502_AddCycles_d #define X6502_IRQBegin X6502_IRQBegin_d #define X6502_IRQEnd X6502_IRQEnd_d +#define X6502_Rebase X6502_Rebase_d #define X6502_C #define X6502_A #define X6502_D @@ -76,6 +77,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_AddCycles X6502_AddCycles_a #define X6502_IRQBegin X6502_IRQBegin_a #define X6502_IRQEnd X6502_IRQEnd_a +#define X6502_Rebase X6502_Rebase_a #define X6502_A #define X6502_Run(c) \ @@ -100,6 +102,7 @@ extern void FP_FASTAPASS(1) (*MapIRQHook)(int a); #define X6502_AddCycles X6502_AddCycles_c #define X6502_IRQBegin X6502_IRQBegin_c #define X6502_IRQEnd X6502_IRQEnd_c +#define X6502_Rebase(...) #define X6502_C #define X6502_Run(c) \ @@ -138,7 +141,7 @@ void X6502_Power_a(void); void X6502_AddCycles_a(int x); void X6502_IRQBegin_a(int w); void X6502_IRQEnd_a(int w); -void X6502_rebase_a(void); +void X6502_Rebase_a(void); #endif // debug @@ -152,5 +155,6 @@ void X6502_Power_d(void); void X6502_AddCycles_d(int x); void X6502_IRQBegin_d(int w); void X6502_IRQEnd_d(int w); +void X6502_Rebase_d(void); #endif -- 2.39.5