diff --git a/source/fceultra/boards/103.cpp b/source/fceultra/boards/103.cpp index 3db051d..4c83614 100644 --- a/source/fceultra/boards/103.cpp +++ b/source/fceultra/boards/103.cpp @@ -54,7 +54,17 @@ static void Sync(void) setprg2r(0x10,0xd000,7); setprg2(0xd800,(0xe<<2)+3); } - setmirror(reg1); + setmirror(reg1^1); +} + +static DECLFW(M103RamWrite0) +{ + WRAM[A&0x1FFF]=V; +} + +static DECLFW(M103RamWrite1) +{ + WRAM[0x2000+((A-0xB800)&0x1FFF)]=V; } static DECLFW(M103Write0) @@ -80,9 +90,9 @@ static void M103Power(void) reg0=reg1=0; reg2=0; Sync(); SetReadHandler(0x6000,0x7FFF,CartBR); - SetWriteHandler(0x6000,0x7FFF,CartBW); + SetWriteHandler(0x6000,0x7FFF,M103RamWrite0); SetReadHandler(0x8000,0xFFFF,CartBR); - SetWriteHandler(0xB800,0xD7FF,CartBW); + SetWriteHandler(0xB800,0xD7FF,M103RamWrite1); SetWriteHandler(0x8000,0x8FFF,M103Write0); SetWriteHandler(0xE000,0xEFFF,M103Write1); SetWriteHandler(0xF000,0xFFFF,M103Write2); diff --git a/source/fceultra/debug.h b/source/fceultra/debug.h index e948cc5..dc4b360 100644 --- a/source/fceultra/debug.h +++ b/source/fceultra/debug.h @@ -95,7 +95,7 @@ extern uint8 PPU[4],PALRAM[0x20],SPRAM[0x100],VRAMBuffer,PPUGenLatch,XOffset; extern uint32 RefreshAddr; extern int debug_loggingCD; -extern int numWPs; +extern int numWPs; ///encapsulates the operational state of the debugger core class DebuggerState { diff --git a/source/fceultra/fceu.cpp b/source/fceultra/fceu.cpp index 88285b4..af31675 100644 --- a/source/fceultra/fceu.cpp +++ b/source/fceultra/fceu.cpp @@ -50,6 +50,10 @@ #include "vsuni.h" #include "ines.h" +#ifdef WIN32 +#include "drivers/win/pref.h" +#endif + #include #include @@ -97,6 +101,18 @@ static void CloseGame(void) { if(GameInfo) { + +#ifdef WIN32 +// ################################## Start of SP CODE ########################### + extern char LoadedRomFName[2048]; + + if (storePreferences(LoadedRomFName)) + { + FCEUD_PrintError("Couldn't store debugging data"); + } +// ################################## End of SP CODE ########################### +#endif + if(FCEUnetplay) { FCEUD_NetworkClose(); @@ -443,6 +459,19 @@ endlseq: FCEU_fclose(fp); +#ifdef WIN32 +// ################################## Start of SP CODE ########################### + extern char LoadedRomFName[2048]; + extern int loadDebugDataFailed; + + if ((loadDebugDataFailed = loadPreferences(LoadedRomFName))) + { + FCEUD_PrintError("Couldn't load debugging data"); + } + +// ################################## End of SP CODE ########################### +#endif + FCEU_ResetVidSys(); if(GameInfo->type!=GIT_NSF) @@ -666,6 +695,7 @@ void FCEUI_CloseGame(void) { if(!FCEU_IsValidUI(FCEUI_CLOSEGAME)) return; + CloseGame(); } diff --git a/source/fceultra/ines.cpp b/source/fceultra/ines.cpp index 84d81c6..2375e8c 100644 --- a/source/fceultra/ines.cpp +++ b/source/fceultra/ines.cpp @@ -520,6 +520,17 @@ typedef struct { void (*init)(CartInfo *); } NewMI; +//this is for games that is not the a power of 2 +//mapper based for now... +//not really accurate but this works since games +//that are not in the power of 2 tends to come +//in obscure mappers themselves which supports such +//size +static int not_power2[] = +{ + 228 +}; + int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) { struct md5_context md5; @@ -534,6 +545,9 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) memset(&iNESCart,0,sizeof(iNESCart)); + MapperNo = (head.ROM_type>>4); + MapperNo|=(head.ROM_type2&0xF0); + Mirroring = (head.ROM_type&1); // int ROM_size=0; @@ -545,19 +559,29 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) //head.ROM_size++; } else - ROM_size=head.ROM_size; + ROM_size=uppow2(head.ROM_size); // ROM_size = head.ROM_size; VROM_size = head.VROM_size; + + int round = true; + for (int i = 0; i != sizeof(not_power2)/sizeof(not_power2[0]); ++i) + { + //for games not to the power of 2, so we just read enough + //prg rom from it, but we have to keep ROM_size to the power of 2 + //since PRGCartMapping wants ROM_size to be to the power of 2 + //so instead if not to power of 2, we just use head.ROM_size when + //we use FCEU_read + if (not_power2[i] == MapperNo) + { + round = false; + break; + } + } - ROM_size=uppow2(ROM_size); - - if(VROM_size) + if(VROM_size) VROM_size=uppow2(VROM_size); - MapperNo = (head.ROM_type>>4); - MapperNo|=(head.ROM_type2&0xF0); - Mirroring = (head.ROM_type&1); if(head.ROM_type&8) Mirroring=2; @@ -623,9 +647,9 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) ResetExState(0,0); SetupCartPRGMapping(0,ROM,ROM_size*0x4000,0); -// SetupCartPRGMapping(1,WRAM,8192,1); + // SetupCartPRGMapping(1,WRAM,8192,1); - FCEU_fread(ROM,0x4000,ROM_size,fp); + FCEU_fread(ROM,0x4000,(round) ? ROM_size : head.ROM_size,fp); if(VROM_size) FCEU_fread(VROM,0x2000,head.VROM_size,fp); @@ -646,7 +670,7 @@ int iNESLoad(const char *name, FCEUFILE *fp, int OverwriteVidMode) iNESCart.CRC32=iNESGameCRC32; FCEU_printf(" PRG ROM: %3d x 16KiB\n CHR ROM: %3d x 8KiB\n ROM CRC32: 0x%08lx\n", - ROM_size,head.VROM_size,iNESGameCRC32); + (round) ? ROM_size : head.ROM_size, head.VROM_size,iNESGameCRC32); { int x; @@ -1409,6 +1433,7 @@ static BMAPPING bmap[] = { {245, Mapper245_Init}, {249, Mapper249_Init}, {250, Mapper250_Init}, + {253, Mapper253_Init}, {254, Mapper254_Init}, { 0, 0} }; diff --git a/source/fceultra/ines.h b/source/fceultra/ines.h index 516428a..9020bb1 100644 --- a/source/fceultra/ines.h +++ b/source/fceultra/ines.h @@ -107,6 +107,7 @@ struct iNES_HEADER { } } }; +extern struct iNES_HEADER head; //for mappers usage void VRAM_BANK1(uint32 A, uint8 V); void VRAM_BANK4(uint32 A,uint32 V); @@ -341,7 +342,7 @@ void Mapper247_init(void); void Mapper249_init(void); void Mapper251_init(void); void Mapper252_init(void); -void Mapper253_init(void); +//void Mapper253_init(void); void Mapper255_init(void); void NSFVRC6_Init(void); @@ -452,6 +453,7 @@ void Mapper240_Init(CartInfo *); void Mapper245_Init(CartInfo *); void Mapper249_Init(CartInfo *); void Mapper250_Init(CartInfo *); +void Mapper253_Init(CartInfo *); void Mapper254_Init(CartInfo *); #endif diff --git a/source/fceultra/input.cpp b/source/fceultra/input.cpp index 3fed7b9..e2f81ff 100644 --- a/source/fceultra/input.cpp +++ b/source/fceultra/input.cpp @@ -192,16 +192,12 @@ static uint8 ReadGPVS(int w) static void UpdateGP(int w, void *data, int arg) { if(w==0) //adelikat, 3/14/09: Changing the joypads to inclusive OR the user's joypad + the Lua joypad, this way lua only takes over the buttons it explicity says to - { + { //FatRatKnight: Assume lua is always good. If it's doing nothing in particular using my logic, it'll pass-through the values anyway. #ifdef _S9XLUA_H - //joy[0]= FCEU_LuaUsingJoypad(0) ? FCEU_LuaReadJoypad(0) : *(uint32 *)joyports[0].ptr; - joy[0]= FCEU_LuaUsingJoypad(0) ? (FCEU_LuaReadJoypad(0) | (*(uint32 *)joyports[0].ptr)) : *(uint32 *)joyports[0].ptr; - if (FCEU_LuaReadJoypadFalse(0)) - joy[0] &= FCEU_LuaReadJoypadFalse(0); - //joy[2]= FCEU_LuaUsingJoypad(2) ? FCEU_LuaReadJoypad(2) : *(uint32 *)joyports[0].ptr >> 16; - joy[2]= FCEU_LuaUsingJoypad(2) ? (FCEU_LuaReadJoypad(2) | (*(uint32 *)joyports[0].ptr >> 16)) : *(uint32 *)joyports[0].ptr >> 16; - if (FCEU_LuaReadJoypadFalse(2)) - joy[2] &= FCEU_LuaReadJoypadFalse(2); + joy[0]= *(uint32 *)joyports[0].ptr; + joy[0]= FCEU_LuaReadJoypad(0,joy[0]); + joy[2]= *(uint32 *)joyports[0].ptr >> 16; + joy[2]= FCEU_LuaReadJoypad(2,joy[2]); #else // without this, there seems to be no input at all without Lua joy[0] = *(uint32 *)joyports[0].ptr;; joy[2] = *(uint32 *)joyports[0].ptr >> 16; @@ -210,14 +206,10 @@ static void UpdateGP(int w, void *data, int arg) else { #ifdef _S9XLUA_H - //joy[1]= FCEU_LuaUsingJoypad(1) ? FCEU_LuaReadJoypad(1) : *(uint32 *)joyports[1].ptr >> 8; - joy[1]= FCEU_LuaUsingJoypad(1) ? (FCEU_LuaReadJoypad(1) | (*(uint32 *)joyports[1].ptr >> 8)) : *(uint32 *)joyports[1].ptr >> 8; - if (FCEU_LuaReadJoypadFalse(1)) - joy[1] &= FCEU_LuaReadJoypadFalse(1); - //joy[3]= FCEU_LuaUsingJoypad(3) ? FCEU_LuaReadJoypad(3) : *(uint32 *)joyports[1].ptr >> 24; - joy[3]= FCEU_LuaUsingJoypad(3) ? (FCEU_LuaReadJoypad(3) | (*(uint32 *)joyports[1].ptr >> 24)) : *(uint32 *)joyports[1].ptr >> 24; - if (FCEU_LuaReadJoypadFalse(3)) - joy[3] &= FCEU_LuaReadJoypadFalse(3); + joy[1]= *(uint32 *)joyports[1].ptr >> 8; + joy[1]= FCEU_LuaReadJoypad(1,joy[1]); + joy[3]= *(uint32 *)joyports[1].ptr >> 24; + joy[3]= FCEU_LuaReadJoypad(3,joy[3]); #else // same goes for the other two pads joy[1] = *(uint32 *)joyports[1].ptr >> 8; joy[3] = *(uint32 *)joyports[1].ptr >> 24; diff --git a/source/fceultra/mappers/228.cpp b/source/fceultra/mappers/228.cpp index bfae3a6..e23bd44 100644 --- a/source/fceultra/mappers/228.cpp +++ b/source/fceultra/mappers/228.cpp @@ -20,34 +20,57 @@ #include "mapinc.h" +//16 bits of ram in total +//only use bottom 4 bits as ram though +static uint8 mapper228_ram[4]; + +static SFORMAT StateRegs[]= +{ + { mapper228_ram, 4, "MAPPER_RAM" }, + { 0 } +}; + +static DECLFR(Mapper228_read) +{ + return mapper228_ram[A & 3] & 0xF; +} + static DECLFW(Mapper228_write) { - uint32 page,pagel,pageh; + uint32 page, pagel, pageh; - MIRROR_SET((A>>13)&1); + //write to ram + if (A < 0x6000) + { + mapper228_ram[A & 3] = V; + return; + } + MIRROR_SET((A >> 13) & 1); + page = (A >> 7) & 0x3F; - page=(A>>7)&0x3F; - //printf("%04x\n",A); - if((page&0x30)==0x30) - page-=0x10; - - pagel=pageh=(page<<1) + (((A>>6)&1)&((A>>5)&1)); - pageh+=((A>>5)&1)^1; + if( (page & 0x30) == 0x30) + page -= 0x10; - ROM_BANK16(0x8000,pagel); - ROM_BANK16(0xC000,pageh); - VROM_BANK8( (V&0x3) | ((A&0xF)<<2) ); + 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) ); } static void A52Reset(void) { - Mapper228_write(0,0); + Mapper228_write(0x8000, 0); } void Mapper228_init(void) { - MapperReset=A52Reset; - A52Reset(); - SetWriteHandler(0x8000,0xffff,Mapper228_write); + MapperReset=A52Reset; + A52Reset(); + SetWriteHandler(0x8000, 0xFFFF, Mapper228_write); + SetWriteHandler(0x4020, 0x5FFF, Mapper228_write); + SetReadHandler (0x4020, 0x5FFF, Mapper228_read); + AddExState(StateRegs, ~0, 0, 0); } diff --git a/source/fceultra/mappers/253.cpp b/source/fceultra/mappers/253.cpp new file mode 100644 index 0000000..964730a --- /dev/null +++ b/source/fceultra/mappers/253.cpp @@ -0,0 +1,211 @@ +//Thanks to VirtualNES developer for reverse engineering this mapper +//first screen add 32 to chr +//second screen at 0x42000 +#include "mapinc.h" + +static uint8 reg[9], VRAM_switch; +static int32 irq_enable, irq_counter, irq_latch, irq_clock; + +static void Mapper253_IRQHook(int cycles) +{ + if( irq_enable & 0x02 ) + { + if( (irq_clock+=cycles) >= 0x72 ) + { + irq_clock -= 0x72; + if( irq_counter == 0xFF ) + { + irq_counter = irq_latch; + irq_enable = (irq_enable & 0x01) * 3; + X6502_IRQBegin(FCEU_IQEXT); + } else + { + irq_counter++; + } + } + } +} + +static void SetBank_PPUSUB(int bank, int page) +{ + if(page == 0x88) + { + VRAM_switch = 0; + return; + } + else if(page == 0xC8) + { + VRAM_switch = 1; + return; + } + if ((page == 4) || (page == 5)) + { + printf("Page in 4 5: %d\n", page); + if(VRAM_switch == 0) + setchr1( bank << 10, page ); //CHR-ROM + else + setchr1( bank << 10, page ); //CHR-RAM + } + else + { + printf("Page: %d\n", page); + setchr1(bank << 10, page); + } +} + +static DECLFW(Mapper253_Write) +{ + printf("Address: 0x%X V: 0x%X\n", A, V); + if (A == 0x8010) //8kb select at 0x8000 + { + setprg8(0x8000, V); + return; + } + + if (A == 0xA010) //8kb select at 0xA000 + { + setprg8(0xA000, V); + return; + } + + if (A == 0x9400) //Mirroring + { + V &= 0x03; + switch (V) + { + case 0: + setmirror(MI_V); + break; + case 1: + setmirror(MI_H); + break; + case 2: + setmirror(MI_0); + break; + case 3: + setmirror(MI_1); + break; + } + } + + switch (A & 0xF00C) + { + case 0xB000: + reg[0] = (reg[0] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 0, reg[0] ); + break; + case 0xB004: + reg[0] = (reg[0] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 0, reg[0] + ((V>>4)*0x100) ); + break; + case 0xB008: + reg[1] = (reg[1] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 1, reg[1] ); + break; + case 0xB00C: + reg[1] = (reg[1] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 1, reg[1] + ((V>>4)*0x100) ); + break; + case 0xC000: + reg[2] = (reg[2] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 2, reg[2] ); + break; + case 0xC004: + reg[2] = (reg[2] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 2, reg[2] + ((V>>4)*0x100) ); + break; + case 0xC008: + reg[3] = (reg[3] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 3, reg[3] ); + break; + case 0xC00C: + reg[3] = (reg[3] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 3, reg[3] + ((V>>4)*0x100) ); + break; + case 0xD000: + reg[4] = (reg[4] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 4, reg[4] ); + break; + case 0xD004: + reg[4] = (reg[4] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 4, reg[4] + ((V>>4)*0x100) ); + break; + case 0xD008: + reg[5] = (reg[5] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 5, reg[5] ); + break; + case 0xD00C: + reg[5] = (reg[5] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 5, reg[5] + ((V>>4)*0x100) ); + break; + case 0xE000: + reg[6] = (reg[6] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 6, reg[6] ); + break; + case 0xE004: + reg[6] = (reg[6] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 6, reg[6] + ((V>>4)*0x100) ); + break; + case 0xE008: + reg[7] = (reg[7] & 0xF0) | (V & 0x0F); + SetBank_PPUSUB( 7, reg[7] ); + break; + case 0xE00C: + reg[7] = (reg[7] & 0x0F) | ((V & 0x0F) << 4); + SetBank_PPUSUB( 7, reg[7] + ((V>>4)*0x100) ); + break; + case 0xF000: + irq_latch = (irq_latch & 0xF0) | (V & 0x0F); + break; + case 0xF004: + irq_latch = (irq_latch & 0x0F) | ((V & 0x0F) << 4); + break; + case 0xF008: + irq_enable = V & 0x03; + if (irq_enable & 0x02) + { + irq_counter = irq_latch; + irq_clock = 0; + } + X6502_IRQEnd(FCEU_IQEXT); + break; + default: + break; + //printf("Not handled 0x%X 0x%X", A, V); + } +} + +static void Mapper253_Power(void) +{ + int i; + for (i = 0; i != 8; ++i) + reg[i] = i; + + reg[8] = 0; + irq_enable = 0; + irq_counter = 0; + irq_latch = 0; + irq_clock = 0; + VRAM_switch = 0; + + setprg16(0x8000, 0); //first bank + setprg16(0xC000, head.ROM_size - 1); //last bank + setchr8(0); + + SetWriteHandler(0x8000, 0xFFFF, Mapper253_Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + +static void Mapper253_Close(void) +{ +} + +void Mapper253_Init(CartInfo *info) +{ + info->Power = Mapper253_Power; + MapIRQHook = Mapper253_IRQHook; + info->Close = Mapper253_Close; + SetWriteHandler(0x8000, 0xFFFF, Mapper253_Write); + SetReadHandler(0x8000, 0xFFFF, CartBR); +} + diff --git a/source/fceultra/sound.cpp b/source/fceultra/sound.cpp index 1da02c9..24541c8 100644 --- a/source/fceultra/sound.cpp +++ b/source/fceultra/sound.cpp @@ -31,6 +31,7 @@ #include "filter.h" #include "state.h" #include "wave.h" +#include "debug.h" static uint32 wlookup1[32]; static uint32 wlookup2[203]; @@ -159,6 +160,12 @@ static uint32 ChannelBC[5]; //savestate sync hack stuff int movieSyncHackOn=0,resetDMCacc=0,movieConvertOffset1,movieConvertOffset2; +#ifdef WIN32 +extern volatile int datacount, undefinedcount; +extern int debug_loggingCD; +extern unsigned char *cdloggerdata; +#endif + static void LoadDMCPeriod(uint8 V) { if(PAL) @@ -171,6 +178,31 @@ static void PrepDPCM() { DMCAddress=0x4000+(DMCAddressLatch<<6); DMCSize=(DMCSizeLatch<<4)+1; + + #ifdef WIN32 + if(debug_loggingCD)LogDPCM(0x8000+DMCAddress, DMCSize); + #endif + +} + +void LogDPCM(int romaddress, int dpcmsize){ + int i = GetPRGAddress(romaddress); + + if(i == -1)return; + + for (int dpcmstart = i; dpcmstart < (i + dpcmsize); dpcmstart++) { + if(!(cdloggerdata[dpcmstart] & 0x40)) { + cdloggerdata[dpcmstart] |= 0x40; + + if(!(cdloggerdata[dpcmstart] & 2)){ + datacount++; + cdloggerdata[dpcmstart] |= 2; + if(!(cdloggerdata[dpcmstart] & 1))undefinedcount--; + } + } + } + + return; } /* Instantaneous? Maybe the new freq value is being calculated all of the time... */ diff --git a/source/fceultra/sound.h b/source/fceultra/sound.h index 6a98297..c409a0e 100644 --- a/source/fceultra/sound.h +++ b/source/fceultra/sound.h @@ -51,6 +51,12 @@ extern int32 WaveFinal[2048+512]; extern int32 WaveHi[]; extern uint32 soundtsinc; +#ifdef WIN32 +extern volatile int datacount, undefinedcount; +extern int debug_loggingCD; +extern unsigned char *cdloggerdata; +#endif + extern uint32 soundtsoffs; #define SOUNDTS (timestamp + soundtsoffs) @@ -65,4 +71,6 @@ void FCEUSND_LoadState(int version); void FCEU_SoundCPUHook(int); void Write_IRQFM (uint32 A, uint8 V); //mbg merge 7/17/06 brought over from latest mmbuild +void LogDPCM(int romaddress, int dpcmsize); + #endif