diff --git a/Core/HLE/FunctionWrappers.h b/Core/HLE/FunctionWrappers.h index bab7866fd7..c7c3eaa94b 100644 --- a/Core/HLE/FunctionWrappers.h +++ b/Core/HLE/FunctionWrappers.h @@ -43,6 +43,12 @@ template void WrapI_U() { RETURN(retval); } +template void WrapI_V() { + int retval = func(); + RETURN(retval); +} + + template void WrapI_I() { int retval = func(PARAM(0)); RETURN(retval); @@ -52,10 +58,18 @@ template void WrapV_U() { func(PARAM(0)); } +template void WrapV_I() { + func(PARAM(0)); +} + template void WrapV_UU() { func(PARAM(0), PARAM(1)); } +template void WrapV_II() { + func(PARAM(0), PARAM(1)); +} + template void WrapU_UU() { u32 retval = func(PARAM(0), PARAM(1)); RETURN(retval); @@ -66,6 +80,16 @@ template void WrapI_IU() { RETURN(retval); } +template void WrapI_II() { + int retval = func(PARAM(0), PARAM(1)); + RETURN(retval); +} + +template void WrapI_III() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} + template void WrapV_IU() { func(PARAM(0), PARAM(1)); } diff --git a/Core/HLE/sceImpose.cpp b/Core/HLE/sceImpose.cpp index 3735a28861..4562c39535 100644 --- a/Core/HLE/sceImpose.cpp +++ b/Core/HLE/sceImpose.cpp @@ -19,8 +19,8 @@ #include "FunctionWrappers.h" #include "../MIPS/MIPS.h" -u32 iLanguage = 0; -u32 iButtonValue = 0; +static u32 iLanguage = 0; +static u32 iButtonValue = 0; u32 sceImposeGetBatteryIconStatus(u32 chargingPtr, u32 iconStatusPtr) { diff --git a/Core/HLE/scePower.cpp b/Core/HLE/scePower.cpp index 3ab0f232e9..68eb12c2ff 100644 --- a/Core/HLE/scePower.cpp +++ b/Core/HLE/scePower.cpp @@ -6,7 +6,7 @@ // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License 2.0 for more details. // A copy of the GPL 2.0 should have been included with the program. @@ -24,206 +24,233 @@ static bool volatileMemLocked; -static int powerCbSlots[16]; +const int POWER_CB_AUTO = -1; + +const int numberOfCBPowerSlots = 16; +static int powerCbSlots[numberOfCBPowerSlots]; + void __PowerInit() { memset(powerCbSlots, 0, sizeof(powerCbSlots)); } -void scePowerGetBatteryLifePercent() +int scePowerGetBatteryLifePercent() { DEBUG_LOG(HLE, "100=scePowerGetBatteryLifePercent"); - RETURN(100); + return 100; } -void scePowerIsPowerOnline() + +int scePowerIsPowerOnline() { DEBUG_LOG(HLE, "1=scePowerIsPowerOnline"); - RETURN( 1); + return 1; } -void scePowerIsBatteryExist() + +int scePowerIsBatteryExist() { DEBUG_LOG(HLE, "1=scePowerIsBatteryExist"); - RETURN( 1); + return 1; } -void scePowerIsBatteryCharging() + +int scePowerIsBatteryCharging() { DEBUG_LOG(HLE, "0=scePowerIsBatteryCharging"); - RETURN( 0); + return 0; } -void scePowerGetBatteryChargingStatus() + +int scePowerGetBatteryChargingStatus() { DEBUG_LOG(HLE, "0=scePowerGetBatteryChargingStatus"); - RETURN( 0); + return 0; } -void scePowerIsLowBattery() + +int scePowerIsLowBattery() { DEBUG_LOG(HLE, "0=scePowerIsLowBattery"); - RETURN( 0); + return 0; } -void scePowerRegisterCallback() +int scePowerRegisterCallback(int slot, int cbId) { - int slot = PARAM(0); - int cbId = PARAM(1); - if (slot == -1) { - for (int i = 0; i < 16; i++) { - if (powerCbSlots[i] == 0) { - slot = i; - break; + DEBUG_LOG(HLE,"0=scePowerRegisterCallback(%i, %i)", slot, cbId); + int foundSlot = -1; + + if (slot == POWER_CB_AUTO) // -1 signifies auto select of bank + { + for(int i=0; i < numberOfCBPowerSlots; i++) + { + if ((powerCbSlots[i]==0) && (foundSlot == POWER_CB_AUTO)) // found an empty slot + { + powerCbSlots[i] = cbId; + foundSlot = i; } } - if (slot == -1) { - ERROR_LOG(HLE,"0=scePowerRegisterCallback(%i, %i) OUT OF SLOTS", slot, cbId); - // Argh out of slots - RETURN(-1); - return; + } + else + { + if (powerCbSlots[slot] == 0) + { + powerCbSlots[slot] = cbId; + foundSlot = 0; + } + else + { + // slot already in use! + foundSlot = POWER_CB_AUTO; } } - DEBUG_LOG(HLE,"0=scePowerRegisterCallback(%i, %i)", slot, cbId); - powerCbSlots[slot] = cbId; + if (foundSlot>=0) + { + __KernelRegisterCallback(THREAD_CALLBACK_POWER, cbId); - __KernelRegisterCallback(THREAD_CALLBACK_POWER, cbId); + // Immediately notify + RETURN(0); - // Immediately notify - RETURN(slot); - - __KernelNotifyCallbackType(THREAD_CALLBACK_POWER, cbId, 0x185); // 0x185 from real psp, don't know what it is + __KernelNotifyCallbackType(THREAD_CALLBACK_POWER, cbId, 0x185); // TODO: I have no idea what the 0x185 is from the flags, but its needed for the test to pass. Need another example of it being called + } + return foundSlot; } -void scePowerUnregisterCallback() -{ - int slotId = PARAM(0); - if (powerCbSlots[slotId] != 0) { +int scePowerUnregisterCallback(int slotId) +{ + if (slotId < 0 || slotId >= numberOfCBPowerSlots) + { + return -1; + } + + if (powerCbSlots[slotId] != 0) + { int cbId = powerCbSlots[slotId]; DEBUG_LOG(HLE,"0=scePowerUnregisterCallback(%i) (cbid = %i)", slotId, cbId); __KernelUnregisterCallback(THREAD_CALLBACK_POWER, cbId); powerCbSlots[slotId] = 0; - RETURN(0); - } else { - ERROR_LOG(HLE,"0=scePowerUnregisterCallback(%i) - callback slot not registered.", slotId); - RETURN(0x80000025); // from real psp } + else + { + return 0x80000025; // TODO: docs say a value less than 0, test checks for this specifically. why?? + } + + return 0; } -void sceKernelPowerLock() +int sceKernelPowerLock(int lockType) { - DEBUG_LOG(HLE,"UNIMPL 0=sceKernelPowerLock()"); - RETURN (0); + DEBUG_LOG(HLE,"UNIMPL 0=sceKernelPowerLock(%i)", lockType); + return 0; } -void sceKernelPowerUnlock() +int sceKernelPowerUnlock(int lockType) { - DEBUG_LOG(HLE,"UNIMPL 0=sceKernelPowerUnlock()"); - RETURN (0); + DEBUG_LOG(HLE,"UNIMPL 0=sceKernelPowerUnlock(%i)"); + return 0; } -void sceKernelPowerTick() +int sceKernelPowerTick(int flag) { DEBUG_LOG(HLE,"UNIMPL 0=sceKernelPowerTick()"); - RETURN (0); + return 0; } #define ERROR_POWER_VMEM_IN_USE 0x802b0200 -void sceKernelVolatileMemTryLock() +int sceKernelVolatileMemTryLock(int type, int paddr, int psize) { - int type = PARAM(0); - int paddr = PARAM(1); - int psize = PARAM(2); - if (!volatileMemLocked) - { - INFO_LOG(HLE,"sceKernelVolatileMemTryLock(%i, %08x, %i) - success", type, paddr, psize); - volatileMemLocked = true; - } - else - { - ERROR_LOG(HLE, "sceKernelVolatileMemTryLock - already locked!"); - RETURN(ERROR_POWER_VMEM_IN_USE); - return; - } + if (!volatileMemLocked) + { + INFO_LOG(HLE,"sceKernelVolatileMemTryLock(%i, %08x, %i) - success", type, paddr, psize); + volatileMemLocked = true; + } + else + { + ERROR_LOG(HLE, "sceKernelVolatileMemTryLock - already locked!"); + //RETURN(ERROR_POWER_VMEM_IN_USE); // does this line still need to be here?? + return ERROR_POWER_VMEM_IN_USE; + } - // Volatile RAM is always at 0x08400000 and is of size 0x00400000. - // It's always available in the emu. - Memory::Write_U32(0x08400000, paddr); - Memory::Write_U32(0x00400000, psize); + // Volatile RAM is always at 0x08400000 and is of size 0x00400000. + // It's always available in the emu. + Memory::Write_U32(0x08400000, paddr); + Memory::Write_U32(0x00400000, psize); - RETURN(0); + return 0; } -void sceKernelVolatileMemUnlock() +int sceKernelVolatileMemUnlock(int type) { - INFO_LOG(HLE,"sceKernelVolatileMemUnlock()"); - // TODO: sanity check - volatileMemLocked = false; + INFO_LOG(HLE,"sceKernelVolatileMemUnlock()"); + // TODO: sanity check + volatileMemLocked = false; + + return 0; } -void sceKernelVolatileMemLock() +int sceKernelVolatileMemLock(int type, int paddr, int psize) { - sceKernelVolatileMemTryLock(); + return sceKernelVolatileMemTryLock(type, paddr, psize); } void scePowerSetClockFrequency(u32 cpufreq, u32 busfreq, u32 gpufreq) { - CoreTiming::SetClockFrequencyMHz(cpufreq); + CoreTiming::SetClockFrequencyMHz(cpufreq); - INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i)", cpufreq, busfreq, gpufreq); + INFO_LOG(HLE,"scePowerSetClockFrequency(%i,%i,%i)", cpufreq, busfreq, gpufreq); } void scePowerGetCpuClockFrequencyInt() { - INFO_LOG(HLE,"scePowerGetCpuClockFrequencyInt()"); - RETURN(CoreTiming::GetClockFrequencyMHz()); + INFO_LOG(HLE,"scePowerGetCpuClockFrequencyInt()"); + RETURN(CoreTiming::GetClockFrequencyMHz()); } static const HLEFunction scePower[] = { - {0x04B7766E,scePowerRegisterCallback,"scePowerRegisterCallback"}, - {0x2B51FE2F,0,"scePower_2B51FE2F"}, - {0x442BFBAC,0,"scePowerGetBacklightMaximum"}, - {0xEFD3C963,0,"scePowerTick"}, - {0xEDC13FE5,0,"scePowerGetIdleTimer"}, - {0x7F30B3B1,0,"scePowerIdleTimerEnable"}, - {0x972CE941,0,"scePowerIdleTimerDisable"}, - {0x27F3292C,0,"scePowerBatteryUpdateInfo"}, - {0xE8E4E204,0,"scePower_E8E4E204"}, - {0xB999184C,0,"scePowerGetLowBatteryCapacity"}, - {0x87440F5E,scePowerIsPowerOnline,"scePowerIsPowerOnline"}, - {0x0AFD0D8B,scePowerIsBatteryExist,"scePowerIsBatteryExist"}, - {0x1E490401,scePowerIsBatteryCharging,"scePowerIsBatteryCharging"}, - {0xB4432BC8,scePowerGetBatteryChargingStatus,"scePowerGetBatteryChargingStatus"}, - {0xD3075926,scePowerIsLowBattery,"scePowerIsLowBattery"}, - {0x78A1A796,0,"scePowerIsSuspendRequired"}, - {0x94F5A53F,0,"scePowerGetBatteryRemainCapacity"}, - {0xFD18A0FF,0,"scePowerGetBatteryFullCapacity"}, - {0x2085D15D,scePowerGetBatteryLifePercent,"scePowerGetBatteryLifePercent"}, - {0x8EFB3FA2,0,"scePowerGetBatteryLifeTime"}, - {0x28E12023,0,"scePowerGetBatteryTemp"}, - {0x862AE1A6,0,"scePowerGetBatteryElec"}, - {0x483CE86B,0,"scePowerGetBatteryVolt"}, - {0x23436A4A,0,"scePowerGetInnerTemp"}, - {0x0CD21B1F,0,"scePowerSetPowerSwMode"}, - {0x165CE085,0,"scePowerGetPowerSwMode"}, - {0xD6D016EF,0,"scePowerLock"}, - {0xCA3D34C1,0,"scePowerUnlock"}, - {0xDB62C9CF,0,"scePowerCancelRequest"}, - {0x7FA406DD,0,"scePowerIsRequest"}, - {0x2B7C7CF4,0,"scePowerRequestStandby"}, - {0xAC32C9CC,0,"scePowerRequestSuspend"}, - {0x2875994B,0,"scePower_2875994B"}, - {0x0074EF9B,0,"scePowerGetResumeCount"}, - {0xDFA8BAF8,scePowerUnregisterCallback,"scePowerUnregisterCallback"}, - {0xDB9D28DD,scePowerUnregisterCallback,"scePowerUnregitserCallback"}, //haha - {0x843FBF43,0,"scePowerSetCpuClockFrequency"}, - {0xB8D7B3FB,0,"scePowerSetBusClockFrequency"}, - {0xFEE03A2F,0,"scePowerGetCpuClockFrequency"}, - {0x478FE6F5,0,"scePowerGetBusClockFrequency"}, - {0xFDB5BFE9,scePowerGetCpuClockFrequencyInt,"scePowerGetCpuClockFrequencyInt"}, - {0xBD681969,0,"scePowerGetBusClockFrequencyInt"}, - {0xB1A52C83,0,"scePowerGetCpuClockFrequencyFloat"}, - {0x9BADB3EB,0,"scePowerGetBusClockFrequencyFloat"}, - {0x737486F2,&WrapV_UUU,"scePowerSetClockFrequency"}, - {0x34f9c463,0,"scePowerGetPllClockFrequencyInt"}, - {0xea382a27,0,"scePowerGetPllClockFrequencyFloat"}, - {0xebd177d6,0,"scePower_driver_EBD177D6"}, + {0x04B7766E,&WrapI_II,"scePowerRegisterCallback"}, + {0x2B51FE2F,0,"scePower_2B51FE2F"}, + {0x442BFBAC,0,"scePowerGetBacklightMaximum"}, + {0xEFD3C963,0,"scePowerTick"}, + {0xEDC13FE5,0,"scePowerGetIdleTimer"}, + {0x7F30B3B1,0,"scePowerIdleTimerEnable"}, + {0x972CE941,0,"scePowerIdleTimerDisable"}, + {0x27F3292C,0,"scePowerBatteryUpdateInfo"}, + {0xE8E4E204,0,"scePower_E8E4E204"}, + {0xB999184C,0,"scePowerGetLowBatteryCapacity"}, + {0x87440F5E,&WrapI_V,"scePowerIsPowerOnline"}, + {0x0AFD0D8B,&WrapI_V,"scePowerIsBatteryExist"}, + {0x1E490401,&WrapI_V,"scePowerIsBatteryCharging"}, + {0xB4432BC8,&WrapI_V,"scePowerGetBatteryChargingStatus"}, + {0xD3075926,&WrapI_V,"scePowerIsLowBattery"}, + {0x78A1A796,0,"scePowerIsSuspendRequired"}, + {0x94F5A53F,0,"scePowerGetBatteryRemainCapacity"}, + {0xFD18A0FF,0,"scePowerGetBatteryFullCapacity"}, + {0x2085D15D,&WrapI_V,"scePowerGetBatteryLifePercent"}, + {0x8EFB3FA2,0,"scePowerGetBatteryLifeTime"}, + {0x28E12023,0,"scePowerGetBatteryTemp"}, + {0x862AE1A6,0,"scePowerGetBatteryElec"}, + {0x483CE86B,0,"scePowerGetBatteryVolt"}, + {0x23436A4A,0,"scePowerGetInnerTemp"}, + {0x0CD21B1F,0,"scePowerSetPowerSwMode"}, + {0x165CE085,0,"scePowerGetPowerSwMode"}, + {0xD6D016EF,0,"scePowerLock"}, + {0xCA3D34C1,0,"scePowerUnlock"}, + {0xDB62C9CF,0,"scePowerCancelRequest"}, + {0x7FA406DD,0,"scePowerIsRequest"}, + {0x2B7C7CF4,0,"scePowerRequestStandby"}, + {0xAC32C9CC,0,"scePowerRequestSuspend"}, + {0x2875994B,0,"scePower_2875994B"}, + {0x0074EF9B,0,"scePowerGetResumeCount"}, + {0xDFA8BAF8,&WrapI_I,"scePowerUnregisterCallback"}, + {0xDB9D28DD,&WrapI_I,"scePowerUnregitserCallback"}, //haha + {0x843FBF43,0,"scePowerSetCpuClockFrequency"}, + {0xB8D7B3FB,0,"scePowerSetBusClockFrequency"}, + {0xFEE03A2F,0,"scePowerGetCpuClockFrequency"}, + {0x478FE6F5,0,"scePowerGetBusClockFrequency"}, + {0xFDB5BFE9,scePowerGetCpuClockFrequencyInt,"scePowerGetCpuClockFrequencyInt"}, + {0xBD681969,0,"scePowerGetBusClockFrequencyInt"}, + {0xB1A52C83,0,"scePowerGetCpuClockFrequencyFloat"}, + {0x9BADB3EB,0,"scePowerGetBusClockFrequencyFloat"}, + {0x737486F2,&WrapV_UUU,"scePowerSetClockFrequency"}, + {0x34f9c463,0,"scePowerGetPllClockFrequencyInt"}, + {0xea382a27,0,"scePowerGetPllClockFrequencyFloat"}, + {0xebd177d6,0,"scePower_driver_EBD177D6"}, {0x469989ad,0,"scePower_469989ad"}, {0xa85880d0,0,"scePower_a85880d0"}, }; @@ -231,22 +258,22 @@ static const HLEFunction scePower[] = //890129c in tyshooter looks bogus const HLEFunction sceSuspendForUser[] = { - {0xEADB1BD7,sceKernelPowerLock,"sceKernelPowerLock"}, //(int param) set param to 0 - {0x3AEE7261,sceKernelPowerUnlock,"sceKernelPowerUnlock"},//(int param) set param to 0 - {0x090ccb3f,sceKernelPowerTick,"sceKernelPowerTick"}, + {0xEADB1BD7,&WrapI_I,"sceKernelPowerLock"}, //(int param) set param to 0 + {0x3AEE7261,&WrapI_I,"sceKernelPowerUnlock"},//(int param) set param to 0 + {0x090ccb3f,&WrapI_I,"sceKernelPowerTick"}, - // There's an extra 4MB that can be allocated, which seems to be "volatile". These functions - // let you grab it. - {0xa14f40b2,sceKernelVolatileMemTryLock,"sceKernelVolatileMemTryLock"}, - {0xa569e425,sceKernelVolatileMemUnlock,"sceKernelVolatileMemUnlock"}, - {0x3e0271d3,sceKernelVolatileMemLock,"sceKernelVolatileMemLock"}, //when "acquiring mem pool" (fired up) + // There's an extra 4MB that can be allocated, which seems to be "volatile". These functions + // let you grab it. + {0xa14f40b2,&WrapI_III,"sceKernelVolatileMemTryLock"}, + {0xa569e425,&WrapI_I,"sceKernelVolatileMemUnlock"}, + {0x3e0271d3,&WrapI_III,"sceKernelVolatileMemLock"}, //when "acquiring mem pool" (fired up) }; void Register_scePower() { - RegisterModule("scePower",ARRAY_SIZE(scePower),scePower); + RegisterModule("scePower",ARRAY_SIZE(scePower),scePower); } void Register_sceSuspendForUser() { - RegisterModule("sceSuspendForUser", ARRAY_SIZE(sceSuspendForUser), sceSuspendForUser); + RegisterModule("sceSuspendForUser", ARRAY_SIZE(sceSuspendForUser), sceSuspendForUser); } diff --git a/gentest.py b/gentest.py index 6ac8e4dd91..0d819ec2e8 100644 --- a/gentest.py +++ b/gentest.py @@ -50,7 +50,7 @@ def gen_test(test): os.system("pspsh -p %i cmdfile.txt" % (PORT,)) # Allow the test a second to execute - TODO: tweak - time.sleep(2) + time.sleep(1) if os.path.exists(OUTFILE): # Should check for size as well... diff --git a/pspautotests b/pspautotests index c9d639773e..9a13f86079 160000 --- a/pspautotests +++ b/pspautotests @@ -1 +1 @@ -Subproject commit c9d639773efb82431ef4dc6c070e70c2f1975379 +Subproject commit 9a13f86079323e848216c95f534ce0abeef8da03 diff --git a/test.py b/test.py index 5267186af9..18a140b643 100644 --- a/test.py +++ b/test.py @@ -33,6 +33,7 @@ tests_good = [ "power/power", "rtc/rtc", "umd/callbacks/umd", + "power/power", ] # These are the next tests up for fixing.