try to handle slot1 motion pack commands without confusing it with save memory access.

This commit is contained in:
zeromus 2010-06-20 09:42:16 +00:00
parent 1ef7d2101c
commit 9804f0119a
2 changed files with 86 additions and 6 deletions

View File

@ -271,7 +271,8 @@ u8 fw_transfer(memory_chip_t *mc, u8 data)
bool BackupDevice::save_state(EMUFILE* os) bool BackupDevice::save_state(EMUFILE* os)
{ {
u32 version = 1; u32 version = 2;
//v0
write32le(version,os); write32le(version,os);
write32le(write_enable,os); write32le(write_enable,os);
write32le(com,os); write32le(com,os);
@ -280,7 +281,11 @@ bool BackupDevice::save_state(EMUFILE* os)
write32le((u32)state,os); write32le((u32)state,os);
writebuffer(data,os); writebuffer(data,os);
writebuffer(data_autodetect,os); writebuffer(data_autodetect,os);
//v1
write32le(addr,os); write32le(addr,os);
//v2
write8le(motionInitState,os);
write8le(motionFlag,os);
return true; return true;
} }
@ -288,7 +293,8 @@ bool BackupDevice::load_state(EMUFILE* is)
{ {
u32 version; u32 version;
if(read32le(&version,is)!=1) return false; if(read32le(&version,is)!=1) return false;
if(version==0 || version==1) { if(version>=0)
{
readbool(&write_enable,is); readbool(&write_enable,is);
read32le(&com,is); read32le(&com,is);
read32le(&addr_size,is); read32le(&addr_size,is);
@ -298,9 +304,15 @@ bool BackupDevice::load_state(EMUFILE* is)
state = (STATE)temp; state = (STATE)temp;
readbuffer(data,is); readbuffer(data,is);
readbuffer(data_autodetect,is); readbuffer(data_autodetect,is);
if(version==1)
read32le(&addr,is);
} }
if(version>=1)
read32le(&addr,is);
if(version>=2)
{
read8le(&motionInitState,is);
read8le(&motionFlag,is);
}
return true; return true;
} }
@ -336,7 +348,8 @@ void BackupDevice::reset()
data.resize(0); data.resize(0);
write_enable = FALSE; write_enable = FALSE;
data_autodetect.resize(0); data_autodetect.resize(0);
motionInitState = MOTION_INIT_STATE_IDLE;
motionFlag = MOTION_FLAG_NONE;
state = DETECTING; state = DETECTING;
addr_size = 0; addr_size = 0;
loadfile(); loadfile();
@ -361,6 +374,7 @@ void BackupDevice::close_rom()
void BackupDevice::reset_command() void BackupDevice::reset_command()
{ {
//printf("MC RESET\n");
//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)
@ -424,6 +438,23 @@ void BackupDevice::reset_command()
} }
u8 BackupDevice::data_command(u8 val, int cpu) u8 BackupDevice::data_command(u8 val, int cpu)
{ {
//printf("MC CMD: %02X\n",val);
//motion: some guessing here... hope it doesn't break anything
if(com == BM_CMD_READLOW && motionInitState == MOTION_INIT_STATE_RECEIVED_4_B && val == 0)
{
motionInitState = MOTION_INIT_STATE_IDLE;
motionFlag |= MOTION_FLAG_ENABLED;
//return 0x04; //return 0x04 to enable motion!!!!!
return 0; //but we return 0 to disable it! since we don't emulate it anyway
}
//if the game firmly believes we have motion support, then ignore all motion commands, since theyre not emulated.
if(motionFlag & MOTION_FLAG_SENSORMODE)
{
return 0;
}
if(com == BM_CMD_READLOW || com == BM_CMD_WRITELOW) if(com == BM_CMD_READLOW || com == BM_CMD_WRITELOW)
{ {
//handle data or address //handle data or address
@ -492,12 +523,45 @@ u8 BackupDevice::data_command(u8 val, int cpu)
{ {
case 0: break; //?? case 0: break; //??
case 0xFE:
if(motionInitState == MOTION_INIT_STATE_IDLE) { motionInitState = MOTION_INIT_STATE_FE; return 0; }
break;
case 0xFD:
if(motionInitState == MOTION_INIT_STATE_FE) { motionInitState = MOTION_INIT_STATE_FD; return 0; }
break;
case 0xFB:
if(motionInitState == MOTION_INIT_STATE_FD) { motionInitState = MOTION_INIT_STATE_FB; return 0; }
break;
case 0xF8:
//enable sensor mode
if(motionInitState == MOTION_INIT_STATE_FD)
{
motionInitState = MOTION_INIT_STATE_IDLE;
motionFlag |= MOTION_FLAG_SENSORMODE;
return 0;
}
break;
case 0xF9:
//disable sensor mode
if(motionInitState == MOTION_INIT_STATE_FD)
{
motionInitState = MOTION_INIT_STATE_IDLE;
motionFlag &= ~MOTION_FLAG_SENSORMODE;
return 0;
}
break;
case 8: case 8:
printf("COMMAND%c: Unverified Backup Memory command: %02X FROM %08X\n",(cpu==ARMCPU_ARM9)?'9':'7',val, (cpu==ARMCPU_ARM9)?NDS_ARM9.instruct_adr:NDS_ARM7.instruct_adr); printf("COMMAND%c: Unverified Backup Memory command: %02X FROM %08X\n",(cpu==ARMCPU_ARM9)?'9':'7',val, (cpu==ARMCPU_ARM9)?NDS_ARM9.instruct_adr:NDS_ARM7.instruct_adr);
val = 0xAA; val = 0xAA;
break; break;
case BM_CMD_WRITEDISABLE: case BM_CMD_WRITEDISABLE:
switch(motionInitState)
{
case MOTION_INIT_STATE_IDLE: motionInitState = MOTION_INIT_STATE_RECEIVED_4; break;
case MOTION_INIT_STATE_RECEIVED_4: motionInitState = MOTION_INIT_STATE_RECEIVED_4_B; break;
}
write_enable = FALSE; write_enable = FALSE;
break; break;
@ -538,7 +602,10 @@ u8 BackupDevice::data_command(u8 val, int cpu)
default: default:
printf("COMMAND%c: Unhandled Backup Memory command: %02X FROM %08X\n",(cpu==ARMCPU_ARM9)?'9':'7',val, (cpu==ARMCPU_ARM9)?NDS_ARM9.instruct_adr:NDS_ARM7.instruct_adr); printf("COMMAND%c: Unhandled Backup Memory command: %02X FROM %08X\n",(cpu==ARMCPU_ARM9)?'9':'7',val, (cpu==ARMCPU_ARM9)?NDS_ARM9.instruct_adr:NDS_ARM7.instruct_adr);
break; break;
} } //switch(val)
//motion control state machine broke, return to ground
motionInitState = MOTION_INIT_STATE_IDLE;
} }
return val; return val;
} }

View File

@ -134,6 +134,19 @@ private:
DETECTING = 0, RUNNING = 1 DETECTING = 0, RUNNING = 1
} state; } state;
enum MOTION_INIT_STATE
{
MOTION_INIT_STATE_IDLE, MOTION_INIT_STATE_RECEIVED_4, MOTION_INIT_STATE_RECEIVED_4_B,
MOTION_INIT_STATE_FE, MOTION_INIT_STATE_FD, MOTION_INIT_STATE_FB
};
enum MOTION_FLAG
{
MOTION_FLAG_NONE=0,
MOTION_FLAG_ENABLED=1,
MOTION_FLAG_SENSORMODE=2
};
u8 motionInitState, motionFlag;
void loadfile(); void loadfile();
bool _loadfile(const char *fname); bool _loadfile(const char *fname);
void ensure(u32 addr); void ensure(u32 addr);