static void ndspFinalize(bool suspend) { LightLock_Lock(&ndspMutex); u16 val = suspend ? 3 : 1; DSP_WriteProcessPipe(2, &val, 4); for (;;) { bool ready; DSP_RecvDataIsReady(0, &ready); if (ready) { DSP_RecvData(0, &val); if (val == 1) break; } } if (suspend) memcpy(dspVar5Backup, ndspVars[5][0], sizeof(dspVar5Backup)); DSP_RegisterInterruptEvents(0, 2, 2); svcCloseHandle(irqEvent); svcCloseHandle(dspSem); DSP_UnloadComponent(); bComponentLoaded = false; bDspReady = false; LightLock_Unlock(&ndspMutex); }
void ndspAuxSetVolume(int id, float volume) { LightLock_Lock(&ndspMaster.lock); ndspMaster.aux[id].volume = volume; ndspMaster.flags |= MFLAG_AUX_VOLUME(id); LightLock_Unlock(&ndspMaster.lock); }
void ndspSetMasterVol(float volume) { LightLock_Lock(&ndspMaster.lock); ndspMaster.masterVol = volume; ndspMaster.flags |= MFLAG_MASTERVOL; LightLock_Unlock(&ndspMaster.lock); }
void ndspSetOutputCount(int count) { LightLock_Lock(&ndspMaster.lock); ndspMaster.outputCount = count; ndspMaster.flags |= MFLAG_OUTPUTCOUNT; LightLock_Unlock(&ndspMaster.lock); }
void ndspSetClippingMode(ndspClippingMode mode) { LightLock_Lock(&ndspMaster.lock); ndspMaster.clippingMode = mode; ndspMaster.flags |= MFLAG_CLIPPINGMODE; LightLock_Unlock(&ndspMaster.lock); }
void ndspSurroundSetPos(ndspSpeakerPos pos) { LightLock_Lock(&ndspMaster.lock); ndspMaster.surround.pos = pos; ndspMaster.flags |= MFLAG_SURR_POS; LightLock_Unlock(&ndspMaster.lock); }
void ndspSurroundSetDepth(u16 depth) { LightLock_Lock(&ndspMaster.lock); ndspMaster.surround.depth = depth; ndspMaster.flags |= MFLAG_SURR_DEPTH; LightLock_Unlock(&ndspMaster.lock); }
void ndspAuxSetEnable(int id, bool enable) { LightLock_Lock(&ndspMaster.lock); ndspMaster.aux[id].enable = enable ? 1 : 0; ndspMaster.flags |= MFLAG_AUX_ENABLE(id); LightLock_Unlock(&ndspMaster.lock); }
void ndspSurroundSetRearRatio(u16 ratio) { LightLock_Lock(&ndspMaster.lock); ndspMaster.surround.rearRatio = ratio; ndspMaster.flags |= MFLAG_SURR_RRATIO; LightLock_Unlock(&ndspMaster.lock); }
void ndspAuxSetFrontBypass(int id, bool bypass) { LightLock_Lock(&ndspMaster.lock); ndspMaster.aux[id].frontBypass = bypass ? 1 : 0; ndspMaster.flags |= MFLAG_AUX_BYPASS(id); LightLock_Unlock(&ndspMaster.lock); }
void ndspSetOutputMode(ndspOutputMode mode) { LightLock_Lock(&ndspMaster.lock); ndspMaster.outputMode = mode; ndspMaster.flags |= MFLAG_OUTPUTMODE; LightLock_Unlock(&ndspMaster.lock); }
static inline void ndspWaitForIrq(void) { LightLock_Lock(&ndspMutex); svcWaitSynchronization(irqEvent, U64_MAX); svcClearEvent(irqEvent); LightLock_Unlock(&ndspMutex); }
u32 aptGetStatusPower(void) { u32 ret; LightLock_Lock(&aptStatusMutex); ret = aptStatusPower; LightLock_Unlock(&aptStatusMutex); return ret; }
APT_AppStatus aptGetStatus(void) { APT_AppStatus ret; LightLock_Lock(&aptStatusMutex); ret = aptStatus; LightLock_Unlock(&aptStatusMutex); return ret; }
void LightEvent_Clear(LightEvent* event) { if (event->state == 1) { LightLock_Lock(&event->lock); LightEvent_SetState(event, -2); LightLock_Unlock(&event->lock); } else if (event->state == 0) LightEvent_SetState(event, -1); }
void RecursiveLock_Lock(RecursiveLock* lock) { u32 tag = (u32)getThreadLocalStorage(); if (lock->thread_tag != tag) { LightLock_Lock(&lock->lock); lock->thread_tag = tag; } lock->counter ++; }
static inline void debug(const char *format, ...) { #ifdef DEBUG LightLock_Lock(&debug_lock); consoleSelect(&bottomScreen); va_list ap; va_start(ap, format); vfprintf(stderr, format, ap); va_end(ap); LightLock_Unlock(&debug_lock); #endif }
void LightEvent_Signal(LightEvent* event) { if (event->state == -1) { LightEvent_SetState(event, 0); svcArbitrateAddress(arbiter, (u32)event, ARBITRATION_SIGNAL, 1, 0); } else if (event->state == -2) { LightLock_Lock(&event->lock); LightEvent_SetState(event, 1); svcArbitrateAddress(arbiter, (u32)event, ARBITRATION_SIGNAL, -1, 0); LightLock_Unlock(&event->lock); } }
static inline void print(const char *format, ...) { #ifdef DEBUG LightLock_Lock(&debug_lock); #endif consoleSelect(&topScreen); va_list ap; va_start(ap, format); vprintf(format, ap); va_end(ap); #ifdef DEBUG LightLock_Unlock(&debug_lock); #endif }
void aptSetStatus(APT_AppStatus status) { LightLock_Lock(&aptStatusMutex); aptStatus = status; //if(prevstatus != APP_NOTINITIALIZED) //{ if(status == APP_RUNNING) __ctru_speedup_config(); if(status == APP_RUNNING || status == APP_EXITING || status == APP_APPLETSTARTED || status == APP_APPLETCLOSED) svcSignalEvent(aptStatusEvent); //} LightLock_Unlock(&aptStatusMutex); }
void aptSetStatusPower(u32 status) { LightLock_Lock(&aptStatusMutex); aptStatusPower = status; LightLock_Unlock(&aptStatusMutex); }
void aptOpenSession(void) { LightLock_Lock(&aptStatusMutex); __apt_initservicehandle(); }
static void ndspUpdateMaster(void) { DspMasterStatus* m = ndspiGetMasterStatus(); LightLock_Lock(&ndspMaster.lock); u32 flags = m->flags, mflags = ndspMaster.flags; int i; m->headsetConnected = *(vu8*)0x1FF810C0; flags |= 0x10000000; if (mflags & MFLAG_MASTERVOL) { m->masterVol = ndspMaster.masterVol; flags |= 0x00010000; } if (mflags & MFLAG_OUTPUTMODE) { m->outputMode = ndspMaster.outputMode; flags |= 0x04000000; } if (mflags & MFLAG_CLIPPINGMODE) { m->clippingMode = ndspMaster.clippingMode; flags |= 0x08000000; } if (mflags & MFLAG_OUTPUTCOUNT) { m->outBufCount = ndspMaster.outputCount; flags |= 0x00008000; } if (mflags & MFLAG_SYNCMODE) { m->syncMode = ndspMaster.syncMode; m->unknown |= 0x10000; //? } if (mflags & MFLAG_SURR_DEPTH) { m->surroundDepth = ndspMaster.surround.depth; flags |= 0x20000000; } if (mflags & MFLAG_SURR_POS) { m->surroundSpeakerPos = ndspMaster.surround.pos; flags |= 0x40000000; } if (mflags & MFLAG_SURR_RRATIO) { m->rearRatio = ndspMaster.surround.rearRatio; flags |= 0x80000000; } for (i = 0; i < 2; i ++) { if (mflags & MFLAG_AUX_ENABLE(i)) { m->auxBusEnable[i] = ndspMaster.aux[i].enable; flags |= 0x00000100 << i; } if (mflags & MFLAG_AUX_BYPASS(i)) { m->auxFrontBypass[i] = ndspMaster.aux[i].frontBypass; flags |= 0x00000040 << i; } if (mflags & MFLAG_AUX_VOLUME(i)) { m->auxReturnVol[i] = ndspMaster.aux[i].volume; flags |= 0x01000000 << i; } } m->flags = flags; ndspMaster.flags = 0; LightLock_Unlock(&ndspMaster.lock); }