diff --git a/src/NDS.cpp b/src/NDS.cpp index c750bc6e..98c29248 100644 --- a/src/NDS.cpp +++ b/src/NDS.cpp @@ -764,6 +764,7 @@ u32 RunFrame() FrameSysClockCycles = 0; if (!Running) return 263; // dorp + if (CPUStop & 0x40000000) return 263; GPU::StartFrame(); @@ -852,6 +853,14 @@ u32 RunFrame() SysClockCycles += ndscyclestorun; LastSysClockCycles += ndscyclestorun; FrameSysClockCycles += ndscyclestorun; + + if (CPUStop & 0x40000000) + { + // checkme: when is sleep mode effective? + //CancelEvent(Event_LCD); + //GPU::TotalScanlines = 263; + break; + } } #ifdef DEBUG_CHECK_DESYNC @@ -953,6 +962,20 @@ void SetKeyMask(u32 mask) KeyInput |= key_lo | (key_hi << 16); } +void SetLidClosed(bool closed) +{ + if (closed) + { + KeyInput |= (1<<23); + } + else + { + KeyInput &= ~(1<<23); + SetIRQ(1, IRQ_LidOpen); + CPUStop &= ~0x40000000; + } +} + void MicInputFrame(s16* data, int samples) { return SPI_TSC::MicInputFrame(data, samples); @@ -1111,6 +1134,14 @@ void GXFIFOUnstall() CPUStop &= ~0x80000000; } +void EnterSleepMode() +{ + if (CPUStop & 0x40000000) return; + + CPUStop |= 0x40000000; + ARM7->Halt(2); +} + u32 GetPC(u32 cpu) { return cpu ? ARM7->R[15] : ARM9->R[15]; @@ -3224,7 +3255,10 @@ void ARM7IOWrite8(u32 addr, u8 val) return; case 0x04000301: - if (val == 0x80) ARM7->Halt(1); + val & 0xC0; + if (val == 0x40) printf("!! GBA MODE NOT SUPPORTED\n"); + else if (val == 0x80) ARM7->Halt(1); + else if (val == 0xC0) EnterSleepMode(); return; } diff --git a/src/NDS.h b/src/NDS.h index 2ffb35f6..bfb390f0 100644 --- a/src/NDS.h +++ b/src/NDS.h @@ -152,6 +152,8 @@ void ReleaseScreen(); void SetKeyMask(u32 mask); +void SetLidClosed(bool closed); + void MicInputFrame(s16* data, int samples); void ScheduleEvent(u32 id, bool periodic, s32 delay, void (*func)(u32), u32 param); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 3b484be4..e3d981e9 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -108,6 +108,7 @@ uiDrawMatrix BottomScreenTrans; bool Touching = false; u32 KeyInputMask; +bool LidCommand, LidStatus; SDL_Joystick* Joystick; const u32 kMicBufferSize = 2048; // must be power of two @@ -290,6 +291,8 @@ int EmuThreadFunc(void* burp) ScreenDrawInited = false; Touching = false; KeyInputMask = 0xFFF; + LidCommand = false; + LidStatus = false; u32 nframes = 0; u32 starttick = SDL_GetTicks(); @@ -347,6 +350,12 @@ int EmuThreadFunc(void* burp) } NDS::SetKeyMask(keymask & joymask); + if (LidCommand) + { + NDS::SetLidClosed(LidStatus); + LidCommand = false; + } + // microphone input if ((MicBufferReadPos + 735) > kMicBufferSize) { @@ -620,6 +629,12 @@ int OnAreaKeyEvent(uiAreaHandler* handler, uiArea* area, uiAreaKeyEvent* evt) if (evt->Scancode == Config::KeyMapping[i]) KeyInputMask &= ~(1<Scancode == 0x44) // F10, test + { + LidStatus = !LidStatus; + LidCommand = true; + } + if (evt->Scancode == 0x57) // F11 NDS::debug(0); }