Wrap a few semaphore sceKernel* funcs.

This commit is contained in:
Unknown W. Brackets 2012-11-11 17:57:35 -08:00
parent 3acca0f941
commit 8e2fff97bf
4 changed files with 38 additions and 44 deletions

View File

@ -90,6 +90,11 @@ template<int func(int, int, int)> void WrapI_III() {
RETURN(retval);
}
template<int func(int, int, u32)> void WrapI_IIU() {
int retval = func(PARAM(0), PARAM(1), PARAM(2));
RETURN(retval);
}
template<void func(int, u32)> void WrapV_IU() {
func(PARAM(0), PARAM(1));
}

View File

@ -333,11 +333,11 @@ const HLEFunction ThreadManForUser[] =
{0x8FFDF9A2,sceKernelCancelSema, "sceKernelCancelSema"},
{0xD6DA4BA1,sceKernelCreateSema, "sceKernelCreateSema"},
{0x28b6489c,sceKernelDeleteSema, "sceKernelDeleteSema"},
{0x58b1f937,sceKernelPollSema, "sceKernelPollSema"},
{0xBC6FEBC5,sceKernelReferSemaStatus,"sceKernelReferSemaStatus"},
{0x3F53E640,sceKernelSignalSema, "sceKernelSignalSema"},
{0x4E3A1105,sceKernelWaitSema, "sceKernelWaitSema"},
{0x6d212bac,sceKernelWaitSemaCB, "sceKernelWaitSemaCB"},
{0x58b1f937,&WrapI_II<sceKernelPollSema>, "sceKernelPollSema"},
{0xBC6FEBC5,&WrapI_IU<sceKernelReferSemaStatus>, "sceKernelReferSemaStatus"},
{0x3F53E640,&WrapI_II<sceKernelSignalSema>, "sceKernelSignalSema"},
{0x4E3A1105,&WrapI_IIU<sceKernelWaitSema>, "sceKernelWaitSema"},
{0x6d212bac,&WrapI_IIU<sceKernelWaitSemaCB>, "sceKernelWaitSemaCB"},
{0x60107536,0,"sceKernelDeleteLwMutex"},
{0x19CFF145,0,"sceKernelCreateLwMutex"},

View File

@ -93,31 +93,28 @@ void sceKernelDeleteSema()
RETURN(kernelObjects.Destroy<Semaphore>(id));
}
void sceKernelReferSemaStatus()
int sceKernelReferSemaStatus(SceUID id, u32 infoPtr)
{
SceUID id = PARAM(0);
u32 error;
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
if (s)
{
DEBUG_LOG(HLE,"sceKernelReferSemaStatus(%i, %08x)", id, PARAM(1));
NativeSemaphore *outptr = (NativeSemaphore*)Memory::GetPointer(PARAM(1));
DEBUG_LOG(HLE,"sceKernelReferSemaStatus(%i, %08x)", id, infoPtr);
NativeSemaphore *outptr = (NativeSemaphore*)Memory::GetPointer(infoPtr);
memcpy((char*)outptr, (char*)&s->ns, s->ns.size);
RETURN(0);
return 0;
}
else
{
ERROR_LOG(HLE,"Error %08x", error);
RETURN(error);
return error;
}
}
//int sceKernelSignalSema(SceUID semaid, int signal);
void sceKernelSignalSema()
int sceKernelSignalSema(SceUID id, int signal)
{
//TODO: check that this thing really works :)
SceUID id = PARAM(0);
u32 signal = PARAM(1);
u32 error;
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
if (s)
@ -154,22 +151,18 @@ retry:
// I don't think we should reschedule here
//if (wokeThreads)
// __KernelReSchedule("semaphore signalled");
return 0;
}
else
{
ERROR_LOG(HLE, "sceKernelSignalSema : Trying to signal invalid semaphore %i", id);
RETURN(error);
return error;
}
}
//int sceKernelWaitSema(SceUID semaid, int signal, SceUInt *timeout);
void sceKernelWaitSema()
int sceKernelWaitSema(SceUID id, int wantedCount, u32 timeoutPtr)
{
SceUID id = PARAM(0);
int wantedCount = PARAM(1);
u32 timeoutPtr = PARAM(2);
u32 error;
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
if (s)
@ -178,29 +171,27 @@ void sceKernelWaitSema()
if (s->ns.currentCount >= wantedCount) //TODO fix
{
s->ns.currentCount -= wantedCount;
RETURN(0);
return 0;
}
else
{
s->waitingThreads.push_back(__KernelGetCurThread());
__KernelWaitCurThread(WAITTYPE_SEMA, id, wantedCount, 0, false);
return;
return 0;
}
}
else
{
ERROR_LOG(HLE, "sceKernelWaitSema : Trying to wait for invalid semaphore %i", id);
RETURN(error);
return error;
}
}
//int sceKernelWaitSemaCB(SceUID semaid, int signal, SceUInt *timeout);
void sceKernelWaitSemaCB()
int sceKernelWaitSemaCB(SceUID id, int wantedCount, u32 timeoutPtr)
{
SceUID id = PARAM(0);
int wantedCount = PARAM(1);
int timeout = PARAM(2);
DEBUG_LOG(HLE,"sceKernelWaitSemaCB(%i, %i, %i)", id, wantedCount, timeout);
DEBUG_LOG(HLE,"sceKernelWaitSemaCB(%i, %i, %i)", id, wantedCount, timeoutPtr);
u32 error;
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
if (s)
@ -214,26 +205,24 @@ void sceKernelWaitSemaCB()
else
{
s->waitingThreads.push_back(__KernelGetCurThread());
// TODO: timeoutPtr?
__KernelWaitCurThread(WAITTYPE_SEMA, id, wantedCount, 0, true);
__KernelCheckCallbacks();
return;
return 0;
}
DEBUG_LOG(HLE,"After: CurrentCount: %i, Signal: %i", s->ns.currentCount, wantedCount);
RETURN(0);
return 0;
}
else
{
ERROR_LOG(HLE,"sceKernelWaitSemaCB - Bad semaphore");
RETURN(error);
return error;
}
}
// Should be same as WaitSema but without the wait, instead returning SCE_KERNEL_ERROR_SEMA_ZERO
void sceKernelPollSema()
int sceKernelPollSema(SceUID id, int wantedCount)
{
SceUID id = PARAM(0);
int wantedCount = PARAM(1);
u32 error;
Semaphore *s = kernelObjects.Get<Semaphore>(id, error);
if (s)
@ -242,17 +231,17 @@ void sceKernelPollSema()
if (s->ns.currentCount >= wantedCount) //TODO fix
{
s->ns.currentCount -= wantedCount;
RETURN(0);
return 0;
}
else
{
RETURN(SCE_KERNEL_ERROR_SEMA_ZERO);
return SCE_KERNEL_ERROR_SEMA_ZERO;
}
}
else
{
ERROR_LOG(HLE, "sceKernelPollSema : Trying to poll invalid semaphore %i", id);
RETURN(error);
return error;
}
}

View File

@ -20,8 +20,8 @@
void sceKernelCancelSema();
void sceKernelCreateSema();
void sceKernelDeleteSema();
void sceKernelPollSema();
void sceKernelReferSemaStatus();
void sceKernelSignalSema();
void sceKernelWaitSema();
void sceKernelWaitSemaCB();
int sceKernelPollSema(SceUID id, int wantedCount);
int sceKernelReferSemaStatus(SceUID id, u32 infoPtr);
int sceKernelSignalSema(SceUID id, int signal);
int sceKernelWaitSema(SceUID semaid, int signal, u32 timeoutPtr);
int sceKernelWaitSemaCB(SceUID semaid, int signal, u32 timeoutPtr);