- implemented mc write status command;
- add feature custom initial value mc data on reset; (fix bug #1325 Daigassou! Band Brothers DX - JP)
This commit is contained in:
mtabachenko 2013-11-07 02:27:20 +00:00
parent cb5e9df984
commit 4d79e39f36
4 changed files with 37 additions and 28 deletions

View File

@ -2435,8 +2435,7 @@ u32 DmaController::read32()
static INLINE void write_auxspicnt(const int PROCNUM, const int size, const int adr, const int val) static INLINE void write_auxspicnt(const int PROCNUM, const int size, const int adr, const int val)
{ {
//u16 oldCnt = MMU.AUX_SPI_CNT; u16 oldCnt = MMU.AUX_SPI_CNT;
bool csOld = (MMU.AUX_SPI_CNT & (1 << 6))?true:false;
switch(size) switch(size)
{ {
@ -2448,9 +2447,11 @@ static INLINE void write_auxspicnt(const int PROCNUM, const int size, const int
break; break;
} }
bool csOld = (oldCnt & (1 << 6))?true:false;
bool cs = (MMU.AUX_SPI_CNT & (1 << 6))?true:false; bool cs = (MMU.AUX_SPI_CNT & (1 << 6))?true:false;
bool spi = (MMU.AUX_SPI_CNT & (1 << 13))?true:false;
if (!cs && csOld) if ((!cs && csOld) || (spi && (oldCnt == 0) && !cs))
{ {
//printf("MMU%c: CS changed from HIGH to LOW *****\n", PROCNUM?'7':'9'); //printf("MMU%c: CS changed from HIGH to LOW *****\n", PROCNUM?'7':'9');
slot1_device->auxspi_reset(PROCNUM); slot1_device->auxspi_reset(PROCNUM);

View File

@ -111,9 +111,6 @@ static u8 ExpMemory_read08(u32 procnum, u32 adr)
{ {
EXPINFO("ExpMemory: read 08 at 0x%08X\n", adr); EXPINFO("ExpMemory: read 08 at 0x%08X\n", adr);
if (adr == 0x08240000)
return (ext_ram_lock?0:1);
if(adr>=0x080000B0 && adr<0x080000C0) if(adr>=0x080000B0 && adr<0x080000C0)
return T1ReadByte(header_0x00B0,adr-0x080000B0); return T1ReadByte(header_0x00B0,adr-0x080000B0);
@ -128,9 +125,6 @@ static u8 ExpMemory_read08(u32 procnum, u32 adr)
} }
static u16 ExpMemory_read16(u32 procnum, u32 adr) static u16 ExpMemory_read16(u32 procnum, u32 adr)
{ {
if (adr == 0x08240000)
return (ext_ram_lock?0:1);
if(adr>=0x080000B0 && adr<0x080000C0) if(adr>=0x080000B0 && adr<0x080000C0)
return T1ReadWord(header_0x00B0,adr-0x080000B0); return T1ReadWord(header_0x00B0,adr-0x080000B0);
@ -149,9 +143,6 @@ static u16 ExpMemory_read16(u32 procnum, u32 adr)
} }
static u32 ExpMemory_read32(u32 procnum, u32 adr) static u32 ExpMemory_read32(u32 procnum, u32 adr)
{ {
if (adr == 0x08240000)
return (ext_ram_lock?0:1);
if(adr>=0x080000B0 && adr<0x080000C0) if(adr>=0x080000B0 && adr<0x080000C0)
return T1ReadLong(header_0x00B0,adr-0x080000B0); return T1ReadLong(header_0x00B0,adr-0x080000B0);

View File

@ -63,7 +63,7 @@
//the game reads its initial sound volumes from uninitialized data, and if it is 0, the game will be silent //the game reads its initial sound volumes from uninitialized data, and if it is 0, the game will be silent
//if it is 0xFF then the game starts with its sound and music at max, as presumably it is supposed to. //if it is 0xFF then the game starts with its sound and music at max, as presumably it is supposed to.
//so in r3303 I finally changed it (no$ appears definitely to initialize to 0xFF) //so in r3303 I finally changed it (no$ appears definitely to initialize to 0xFF)
static const u8 kUninitializedSaveDataValue = 0xFF; static u8 kUninitializedSaveDataValue = 0xFF;
static const char* kDesmumeSaveCookie = "|-DESMUME SAVE-|"; static const char* kDesmumeSaveCookie = "|-DESMUME SAVE-|";
@ -116,7 +116,7 @@ void backup_setManualBackupType(int type)
bool BackupDevice::save_state(EMUFILE* os) bool BackupDevice::save_state(EMUFILE* os)
{ {
u32 version = 3; u32 version = 4;
//v0 //v0
write32le(version,os); write32le(version,os);
write32le(write_enable,os); write32le(write_enable,os);
@ -133,6 +133,8 @@ bool BackupDevice::save_state(EMUFILE* os)
write8le(motionFlag,os); write8le(motionFlag,os);
//v3 //v3
writebool(reset_command_state,os); writebool(reset_command_state,os);
//v4
write8le(write_protect,os);
return true; return true;
} }
@ -166,6 +168,11 @@ bool BackupDevice::load_state(EMUFILE* is)
readbool(&reset_command_state,is); readbool(&reset_command_state,is);
} }
if(version>=4)
{
read8le(&write_protect,is);
}
return true; return true;
} }
@ -189,6 +196,7 @@ void BackupDevice::movie_mode()
void BackupDevice::reset_hardware() void BackupDevice::reset_hardware()
{ {
write_enable = FALSE; write_enable = FALSE;
write_protect = 0;
com = 0; com = 0;
addr = addr_counter = 0; addr = addr_counter = 0;
motionInitState = MOTION_INIT_STATE_IDLE; motionInitState = MOTION_INIT_STATE_IDLE;
@ -197,6 +205,10 @@ void BackupDevice::reset_hardware()
reset_command_state = false; reset_command_state = false;
flushPending = false; flushPending = false;
lazyFlushPending = false; lazyFlushPending = false;
kUninitializedSaveDataValue = 0xFF;
if(!memcmp(gameInfo.header.gameCode,"AXBJ", 4)) kUninitializedSaveDataValue = 0x00; // Daigassou! Band Brothers DX (JP)
} }
void BackupDevice::reset() void BackupDevice::reset()
@ -302,7 +314,7 @@ void BackupDevice::checkReset()
//for a performance hack, save files are only flushed after each reset command //for a performance hack, save files are only flushed after each reset command
//(hopefully, after each page) //(hopefully, after each page)
if(flushPending) if(flushPending && (com == BM_CMD_WRITELOW || com == BM_CMD_WRITEHIGH))
{ {
flush(); flush();
flushPending = false; flushPending = false;
@ -337,8 +349,13 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
switch (com) switch (com)
{ {
case BM_CMD_READLOW: case BM_CMD_WRITESTATUS:
//printf("MC%c: write status %02X\n", PROCNUM?'7':'9', val);
write_protect = (val & 0xFC);
break;
case BM_CMD_WRITELOW: case BM_CMD_WRITELOW:
case BM_CMD_READLOW:
//handle data or address //handle data or address
if(state == DETECTING) if(state == DETECTING)
{ {
@ -391,7 +408,7 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
case BM_CMD_READSTATUS: case BM_CMD_READSTATUS:
//handle request to read status //handle request to read status
//LOG("Backup Memory Read Status: %02X\n", write_enable << 1); //LOG("Backup Memory Read Status: %02X\n", write_enable << 1);
val = (write_enable << 1) | (3<<2); val = (write_enable << 1) | write_protect;
break; break;
case BM_CMD_IRDA: case BM_CMD_IRDA:
@ -402,16 +419,20 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
default: default:
if (com != 0) if (com != 0)
{ {
//printf("MC%c: Unhandled Backup Memory command %02X, value %02X (PC:%08X)\n", PROCNUM?'7':'9', com, val, PROCNUM?NDS_ARM7.instruct_adr:NDS_ARM9.instruct_adr); printf("MC%c: Unhandled Backup Memory command %02X, value %02X (PC:%08X)\n", PROCNUM?'7':'9', com, val, PROCNUM?NDS_ARM7.instruct_adr:NDS_ARM9.instruct_adr);
break; break;
} }
com = val; com = val;
val = 0xFF;
//there is no current command. receive one //there is no current command. receive one
switch (com) switch (com)
{ {
case BM_CMD_NOP: break; case BM_CMD_NOP: break;
case BM_CMD_WRITESTATUS: break;
#ifdef _ENABLE_MOTION #ifdef _ENABLE_MOTION
case 0xFE: case 0xFE:
if(motionInitState == MOTION_INIT_STATE_IDLE) { motionInitState = MOTION_INIT_STATE_FE; return 0; } if(motionInitState == MOTION_INIT_STATE_IDLE) { motionInitState = MOTION_INIT_STATE_FE; return 0; }
@ -449,6 +470,7 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
break; break;
case BM_CMD_WRITEDISABLE: case BM_CMD_WRITEDISABLE:
//printf("MC%c: write disable\n", PROCNUM?'7':'9');
#ifdef _ENABLE_MOTION #ifdef _ENABLE_MOTION
switch (motionInitState) switch (motionInitState)
{ {
@ -457,18 +479,13 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
} }
#endif #endif
write_enable = FALSE; write_enable = FALSE;
com = 0;
break; break;
case BM_CMD_READSTATUS: case BM_CMD_READSTATUS: break;
//val = (write_enable << 1) | (3<<2);
val = 0xFF;
break;
case BM_CMD_WRITEENABLE: case BM_CMD_WRITEENABLE:
//printf("MC%c: write enable\n", PROCNUM?'7':'9'); //printf("MC%c: write enable\n", PROCNUM?'7':'9');
write_enable = TRUE; write_enable = TRUE;
com = 0;
break; break;
case BM_CMD_WRITELOW: case BM_CMD_WRITELOW:
@ -476,14 +493,13 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
//printf("XLO: %08X\n",addr); //printf("XLO: %08X\n",addr);
addr_counter = 0; addr_counter = 0;
addr = 0; addr = 0;
val = 0xFF;
break; break;
case BM_CMD_WRITEHIGH: case BM_CMD_WRITEHIGH:
case BM_CMD_READHIGH: case BM_CMD_READHIGH:
//printf("XHI: %08X\n",addr); //printf("XHI: %08X\n",addr);
if(val == BM_CMD_WRITEHIGH) com = BM_CMD_WRITELOW; if(com == BM_CMD_WRITEHIGH) com = BM_CMD_WRITELOW;
if(val == BM_CMD_READHIGH) com = BM_CMD_READLOW; if(com == BM_CMD_READHIGH) com = BM_CMD_READLOW;
addr_counter = 0; addr_counter = 0;
addr = 0; addr = 0;
if(addr_size==1) if(addr_size==1)
@ -497,7 +513,7 @@ u8 BackupDevice::data_command(u8 val, u8 PROCNUM)
break; break;
default: default:
printf("MC%c: Unhandled Backup Memory command: %02X FROM %08X\n", PROCNUM?'7':'9', val, PROCNUM?NDS_ARM7.instruct_adr:NDS_ARM9.instruct_adr); printf("MC%c: Unhandled Backup Memory command: %02X FROM %08X\n", PROCNUM?'7':'9', com, PROCNUM?NDS_ARM7.instruct_adr:NDS_ARM9.instruct_adr);
break; break;
} //switch(val) } //switch(val)
break; break;

View File

@ -126,6 +126,7 @@ private:
std::string filename; std::string filename;
bool write_enable; //is write enabled? bool write_enable; //is write enabled?
u8 write_protect;
bool reset_command_state; bool reset_command_state;
u32 com; //persistent command actually handled u32 com; //persistent command actually handled
u32 addr_size, addr_counter; u32 addr_size, addr_counter;