Added support for Sleep mode (experimental), so for most games, when you close the lid, the game won't continue running. Also improved a bit the close lid func (no need to pause the SPU).

Also added basic support for the SPI power management device.
This commit is contained in:
luigi__ 2009-02-09 17:18:58 +00:00
parent eedd91854f
commit 2a47d2bcf6
4 changed files with 81 additions and 17 deletions

View File

@ -505,6 +505,14 @@ void MMU_clearMem()
for (int t = 0; t < 32; t++)
MMU.VRAM_MAP[i][t] = 7;
}
MMU.powerMan_CntReg = 0x00;
MMU.powerMan_CntRegWritten = FALSE;
MMU.powerMan_Reg[0] = 0x0B;
MMU.powerMan_Reg[1] = 0x00;
MMU.powerMan_Reg[2] = 0x01;
MMU.powerMan_Reg[3] = 0x00;
rtcInit();
partie = 1;
memset(VRAM_blockEnabled, 0, sizeof(VRAM_blockEnabled));
@ -3155,6 +3163,15 @@ static void FASTCALL _MMU_ARM7_write08(u32 adr, u8 val)
return;
}
if(adr == 0x04000301)
{
switch(val)
{
case 0xC0: NDS_Sleep(); break;
default: break;
}
}
#ifdef EXPERIMENTAL_WIFI
if ((adr & 0xFF800000) == 0x04800000)
{
@ -3279,6 +3296,26 @@ static void FASTCALL _MMU_ARM7_write16(u32 adr, u16 val)
switch((spicnt >> 8) & 0x3)
{
case 0 :
{
if(!MMU.powerMan_CntRegWritten)
{
MMU.powerMan_CntReg = (val & 0xFF);
MMU.powerMan_CntRegWritten = TRUE;
}
else
{
if(MMU.powerMan_CntReg & 0x80)
{
val = MMU.powerMan_Reg[MMU.powerMan_CntReg & 0x3];
}
else
{
MMU.powerMan_Reg[MMU.powerMan_CntReg & 0x3] = val;
}
MMU.powerMan_CntRegWritten = FALSE;
}
}
break;
case 1 : /* firmware memory device */

View File

@ -102,6 +102,10 @@ struct MMU_struct {
u32 sqrtResult;
u32 sqrtCnt;
s32 sqrtCycles;
u8 powerMan_CntReg;
BOOL powerMan_CntRegWritten;
u8 powerMan_Reg[4];
memory_chip_t fw;
memory_chip_t bupmem;

View File

@ -175,6 +175,8 @@ int NDS_Init( void) {
nds.VCount = 0;
nds.lignerendu = FALSE;
nds.sleeping = FALSE;
if (Screen_Init(GFXCORE_DUMMY) != 0)
return -1;
@ -336,11 +338,11 @@ static u32 ones32(u32 x)
return(x & 0x0000003f);
}
#endif
static void NDS_SetROMSerial()
{
NDS_header * header;
static void NDS_SetROMSerial()
{
NDS_header * header;
header = NDS_getROMHeader();
if (
// ??? in all Homebrews game title have is 2E0000EA
@ -354,7 +356,7 @@ static void NDS_SetROMSerial()
((header->gameCode[0] == 0x23) &&
(header->gameCode[1] == 0x23) &&
(header->gameCode[2] == 0x23) &&
(header->gameCode[3] == 0x23)
(header->gameCode[3] == 0x23)
) ||
(header->gameCode[0] == 0x00)
)
@ -371,11 +373,11 @@ static void NDS_SetROMSerial()
memcpy(ROMserial, header->gameTile, strlen(header->gameTile) < 12 ? strlen(header->gameTile) : 12);
memcpy(ROMserial+12+1, header->gameCode, 4);
memcpy(ROMserial+12+1+4, &header->makerCode, 2);
memset(ROMserial+19, '\0', 1);
memset(ROMserial+19, '\0', 1);
}
delete header;
delete header;
INFO("\nROM serial: %s\n\n", ROMserial);
}
}
#ifdef EXPERIMENTAL_GBASLOT
int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize)
@ -504,8 +506,8 @@ int NDS_LoadROM( const char *filename, int bmtype, u32 bmsize,
strcat(buf, ".dct"); // DeSmuME cheat :)
cheatsInit(buf);
NDS_SetROMSerial();
NDS_SetROMSerial();
return ret;
}
@ -1014,6 +1016,8 @@ int NDS_LoadFirmware(const char *filename)
return i;
}
void NDS_Sleep() { nds.sleeping = TRUE; }
bool skipThisFrame = false;
void NDS_SkipFrame(bool skip) { skipThisFrame = skip; }
@ -1057,6 +1061,9 @@ u32 NDS_exec(s32 nb)
#endif
for (i = 0; i < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); i++)
{
if(nds.sleeping) {
break;
} else
if(NDS_ARM9.waitIRQ) {
nds.ARM9Cycle += CYCLES_TO_WAIT_FOR_IRQ;
nds.idleCycles += CYCLES_TO_WAIT_FOR_IRQ;
@ -1094,6 +1101,9 @@ u32 NDS_exec(s32 nb)
#endif
for (i = 0; i < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); i++)
{
if(nds.sleeping) {
break;
} else
if(NDS_ARM7.waitIRQ)
{
nds.ARM7Cycle += CYCLES_TO_WAIT_FOR_IRQ;
@ -1108,6 +1118,9 @@ u32 NDS_exec(s32 nb)
}
}
if(!nds.sleeping)
{
nds.cycles = std::min(nds.ARM9Cycle,nds.ARM7Cycle);
//debug();
@ -1767,9 +1780,15 @@ u32 NDS_exec(s32 nb)
}
}
} // if(!nds.sleeping)
else
{
if((MMU.reg_IE[1] & MMU.reg_IF[1]) & (1<<22))
{
nds.sleeping = FALSE;
}
break;
}
}
return nds.cycles;
@ -1837,12 +1856,12 @@ void NDS_setPad(bool R,bool L,bool D,bool U,bool T,bool S,bool B,bool A,bool Y,b
LidClosed = (!LidClosed) & 0x01;
if (!LidClosed)
{
SPU_Pause(FALSE);
// SPU_Pause(FALSE);
NDS_makeARM7Int(22);
}
else
SPU_Pause(TRUE);
//else
//SPU_Pause(TRUE);
countLid = 30;
}

View File

@ -124,6 +124,8 @@ typedef struct
BOOL isTouch;
u16 pad;
BOOL sleeping;
//this is not essential NDS runtime state.
//it was perhaps a mistake to put it here.
//it is far less important than the above.
@ -213,6 +215,8 @@ int NDS_WriteBMP(const char *filename);
int NDS_LoadFirmware(const char *filename);
int NDS_CreateDummyFirmware( struct NDS_fw_config_data *user_settings);
void NDS_Sleep();
void NDS_SkipFrame(bool skip);
template<bool FORCE>