From 9b87a2a6df4a7d1aa4b83561941d0427762cd45c Mon Sep 17 00:00:00 2001 From: Kovensky Date: Mon, 26 Nov 2012 19:03:44 -0300 Subject: [PATCH 1/8] Add vim modeline to CMakeLists.txt --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1b69828f02..fe1df2a46f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,3 +1,4 @@ +# vim:noexpandtab: cmake_minimum_required(VERSION 2.8.8) project(PPSSPP) From 3b6d413dc114a727826fc07be7ef6c03a2288d76 Mon Sep 17 00:00:00 2001 From: Kovensky Date: Mon, 26 Nov 2012 19:04:30 -0300 Subject: [PATCH 2/8] Only disable the Headless target on mobile platforms As in actual phone OSes, not ARM or APPLE. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fe1df2a46f..e2c65f50cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ else() # Assume x86 set(X86 ON) endif() -if(ARM OR APPLE) +if(ANDROID OR BLACKBERRY OR IOS) set(HEADLESS OFF) elseif(NOT DEFINED HEADLESS) set(HEADLESS ON) From faab4af701b3657eb93d908c6724ae00973e8a00 Mon Sep 17 00:00:00 2001 From: Kovensky Date: Mon, 26 Nov 2012 19:06:18 -0300 Subject: [PATCH 3/8] Support building PPSSPPHeadless on APPLE --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e2c65f50cf..d694d2146e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -70,6 +70,9 @@ else() endif() include(FindSDL) include(FindThreads) +if(APPLE) + find_library(COCOA_LIBRARY Cocoa) +endif() # Needed for Globals.h include_directories("${CMAKE_SOURCE_DIR}") @@ -816,7 +819,8 @@ endif() if(HEADLESS) add_executable(PPSSPPHeadless headless/Headless.cpp) - target_link_libraries(PPSSPPHeadless ${CoreLibName} ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(PPSSPPHeadless ${CoreLibName} + ${COCOA_LIBRARY} ${CMAKE_THREAD_LIBS_INIT}) setup_target_project(PPSSPPHeadless headless) endif() @@ -849,7 +853,6 @@ if(SDL_FOUND) set(SDL_Main ${SDL_Main} SDL/SDLMain.h SDL/SDLMain.mm) - find_library(COCOA_LIBRARY Cocoa) set(LinkCommon ${LinkCommon} ${COCOA_LIBRARY}) endif() From c124c079dcdb056f88840b3d3cda9b66d0dc468a Mon Sep 17 00:00:00 2001 From: Kevin Armstrong Date: Mon, 26 Nov 2012 23:37:21 +0000 Subject: [PATCH 4/8] more sceRTC functions. Ones marked as hack either fail the tests or are a bit wrong --- Core/HLE/sceRtc.cpp | 174 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 149 insertions(+), 25 deletions(-) diff --git a/Core/HLE/sceRtc.cpp b/Core/HLE/sceRtc.cpp index 6e43f7bb7c..ed497e8633 100644 --- a/Core/HLE/sceRtc.cpp +++ b/Core/HLE/sceRtc.cpp @@ -154,13 +154,13 @@ void __RtcTicksToPspTime(ScePspDateTime &t, u64 ticks) t.microsecond = ticks % 1000000; } -u64 JumpYMD(u64 Y, u64 M, u64 D) { - return 367*Y - 7*(Y+(M+9)/12)/4 + 275*M/9 + D; +u64 JumpYMD(u64 year, u64 month, u64 day) { + return 367*year - 7*(year+(month+9)/12)/4 + 275*month/9 + day; } -u64 JumpSeconds(u64 Y, u64 M, u64 D, u64 H, u64 m, u64 S) { +u64 JumpSeconds(u64 year, u64 month, u64 day, u64 hour, u64 minute, u64 second) { static const u64 secs_per_day = 24 * 60 * 60; - return JumpYMD(Y, M, D) * secs_per_day + H * 3600 + m * 60 + S; + return JumpYMD(year, month, day) * secs_per_day + hour * 3600 + minute * 60 + second; } u64 __RtcPspTimeToTicks(ScePspDateTime &t) @@ -332,52 +332,160 @@ u32 sceRtcGetDaysInMonth(u32 year, u32 month) return numberOfDays; } -// these need tests and code writing: u32 sceRtcIsLeapYear(u32 year) { - ERROR_LOG(HLE, "UNIMPL sceRtcIsLeapYear(%d)", year); - return 0; + ERROR_LOG(HLE, "sceRtcIsLeapYear(%d)", year); + return (year % 4 == 0) && !(year % 100 == 0)|| (year % 400 == 0); } int sceRtcConvertLocalTimeToUTC(u32 tickLocalPtr,u32 tickUTCPtr) { - ERROR_LOG(HLE, "UNIMPL sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr); + DEBUG_LOG(HLE, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr); + if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr)) + { + u64 srcTick = Memory::Read_U64(tickLocalPtr); + // TODO:convert UTC as ticks to localtime as ticks.. fake it by preteding timezone is UTC for now + Memory::Write_U64(srcTick, tickUTCPtr); + } + else + { + return 1; + } return 0; } int sceRtcConvertUtcToLocalTime(u32 tickUTCPtr,u32 tickLocalPtr) { - ERROR_LOG(HLE, "UNIMPL sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr); + ERROR_LOG(HLE, "sceRtcConvertLocalTimeToUTC(%d, %d)", tickLocalPtr, tickUTCPtr); + if (Memory::IsValidAddress(tickLocalPtr) && Memory::IsValidAddress(tickUTCPtr)) + { + u64 srcTick = Memory::Read_U64(tickUTCPtr); + // TODO:convert localtime as ticks to UTC as ticks.. fake it by preteding timezone is UTC for now + Memory::Write_U64(srcTick, tickLocalPtr); + } + else + { + return 1; + } return 0; } int sceRtcCheckValid(u32 datePtr) { - ERROR_LOG(HLE, "UNIMPL sceRtcCheckValid(%d)", datePtr); - return 0; + DEBUG_LOG(HLE, "sceRtcCheckValid(%d)", datePtr); + int ret = 0; + + if (Memory::IsValidAddress(datePtr)) + { + ScePspDateTime pt; + Memory::ReadStruct(datePtr, &pt); + if (pt.year >= 0) // is there a maximum? + { + ret = PSP_TIME_INVALID_YEAR; + } + else if (pt.month < 1 || pt.month > 12) + { + ret = PSP_TIME_INVALID_MONTH; + } + else if (pt.day < 1 || pt.day > 31) + { + ret = PSP_TIME_INVALID_DAY; + } + else if (pt.day < 0 || pt.day > 31) // TODO: Needs to check actual days in month, including leaps + { + ret = PSP_TIME_INVALID_DAY; + } + else if (pt.hour < 0 || pt.hour > 23) + { + ret = PSP_TIME_INVALID_HOUR; + } + else if (pt.minute < 0 || pt.minute > 59) + { + ret = PSP_TIME_INVALID_MINUTES; + } + else if (pt.second < 0 || pt.second > 59) + { + ret = PSP_TIME_INVALID_SECONDS; + } + else if (pt.microsecond < 0 || pt.microsecond >= 1000000) + { + ret = PSP_TIME_INVALID_MICROSECONDS; + } + } + else + { + ret=-1; + } + return ret; } int sceRtcSetTime_t(u32 datePtr, u64 time) { - ERROR_LOG(HLE, "UNIMPL sceRtcSetTime_t(%d,%d)", datePtr, time); + ERROR_LOG(HLE, "HACK sceRtcSetTime_t(%d,%d)", datePtr, time); + if (Memory::IsValidAddress(datePtr)) + { + ScePspDateTime pt; + + __RtcTicksToPspTime(pt, time); + Memory::WriteStruct(datePtr, &pt); + } + else + { + return 1; + } return 0; } -int sceRtcGetTime_t(u32 datePtr, u64 time) +int sceRtcGetTime_t(u32 datePtr, u32 timePtr) { - ERROR_LOG(HLE, "UNIMPL sceRtcGetTime_t(%d,%d)", datePtr, time); + ERROR_LOG(HLE, "HACK sceRtcGetTime_t(%d,%d)", datePtr, time); + if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(timePtr)) + { + ScePspDateTime pt; + Memory::ReadStruct(datePtr, &pt); + u64 result = __RtcPspTimeToTicks(pt); + Memory::Write_U64(result, timePtr); + } + else + { + return 1; + } return 0; } + int sceRtcSetDosTime(u32 datePtr, u32 dosTime) { - ERROR_LOG(HLE, "UNIMPL sceRtcSetDosTime(%d,%d)", datePtr, dosTime); + ERROR_LOG(HLE, "HACK sceRtcSetDosTime(%d,%d)", datePtr, dosTime); + if (Memory::IsValidAddress(datePtr)) + { + ScePspDateTime pt; + + __RtcTicksToPspTime(pt, dosTime); + Memory::WriteStruct(datePtr, &pt); + } + else + { + return 1; + } return 0; } int sceRtcGetDosTime(u32 datePtr, u32 dosTime) { - ERROR_LOG(HLE, "UNIMPL sceRtcGetDosTime(%d,%d)", datePtr, dosTime); + ERROR_LOG(HLE, "HACK sceRtcGetDosTime(%d,%d)", datePtr, dosTime); + if (Memory::IsValidAddress(datePtr)&&Memory::IsValidAddress(dosTime)) + { + ScePspDateTime pt; + Memory::ReadStruct(datePtr, &pt); + u64 result = __RtcPspTimeToTicks(pt); + Memory::Write_U64(result, dosTime); + } + else + { + return 1; + } return 0; + } int sceRtcSetWin32FileTime(u32 datePtr, u32 win32TimePtr) @@ -394,7 +502,22 @@ int sceRtcGetWin32FileTime(u32 datePtr, u32 win32TimePtr) int sceRtcCompareTick(u32 tick1Ptr, u32 tick2Ptr) { - ERROR_LOG(HLE, "UNIMPL sceRtcCompareTick(%d,%d)", tick1Ptr, tick2Ptr); + ERROR_LOG(HLE, "HACK sceRtcCompareTick(%d,%d)", tick1Ptr, tick2Ptr); + if (Memory::IsValidAddress(tick1Ptr)&&Memory::IsValidAddress(tick1Ptr)) + { + u64 tick1 = Memory::Read_U64(tick1Ptr); + u64 tick2 = Memory::Read_U64(tick2Ptr); + + if (tick1 > tick2) + { + return 1; + } + + if (tick1 < tick2) + { + return -1; + } + } return 0; } @@ -408,7 +531,7 @@ int sceRtcTickAddTicks(u32 destTickPtr, u32 srcTickPtr, u64 numTicks) Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "sceRtcTickAddTicks(%d,%d,%d)", destTickPtr, srcTickPtr, numTicks); + DEBUG_LOG(HLE, "sceRtcTickAddTicks(%d,%d,%d)", destTickPtr, srcTickPtr, numTicks); return 0; } @@ -448,7 +571,7 @@ int sceRtcTickAddMinutes(u32 destTickPtr, u32 srcTickPtr, u64 numMins) srcTick += numMins*60000000UL; Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "UNIMPL sceRtcTickAddMinutes(%d,%d,%d)", destTickPtr, srcTickPtr, numMins); + ERROR_LOG(HLE, "HACK sceRtcTickAddMinutes(%d,%d,%d)", destTickPtr, srcTickPtr, numMins); return 0; } @@ -461,7 +584,7 @@ int sceRtcTickAddHours(u32 destTickPtr, u32 srcTickPtr, int numHours) srcTick += numHours*3600000000UL; Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "UNIMPL sceRtcTickAddMinutes(%d,%d,%d)", destTickPtr, srcTickPtr, numHours); + ERROR_LOG(HLE, "HACK sceRtcTickAddMinutes(%d,%d,%d)", destTickPtr, srcTickPtr, numHours); return 0; } @@ -474,7 +597,7 @@ int sceRtcTickAddDays(u32 destTickPtr, u32 srcTickPtr, int numDays) srcTick += numDays*86400000000UL; Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "UNIMPL sceRtcTickAddDays(%d,%d,%d)", destTickPtr, srcTickPtr, numDays); + ERROR_LOG(HLE, "HACK sceRtcTickAddDays(%d,%d,%d)", destTickPtr, srcTickPtr, numDays); return 0; } @@ -487,7 +610,7 @@ int sceRtcTickAddWeeks(u32 destTickPtr, u32 srcTickPtr, int numWeeks) srcTick += numWeeks*604800000000UL; Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "UNIMPL sceRtcTickAddWeeks(%d,%d,%d)", destTickPtr, srcTickPtr, numWeeks); + ERROR_LOG(HLE, "HACK sceRtcTickAddWeeks(%d,%d,%d)", destTickPtr, srcTickPtr, numWeeks); return 0; } @@ -510,10 +633,11 @@ int sceRtcTickAddMonths(u32 destTickPtr, u32 srcTickPtr, int numMonths) Memory::Write_U64(srcTick, destTickPtr); } - ERROR_LOG(HLE, "UNIMPL sceRtcTickAddMonths(%d,%d,%d)", destTickPtr, srcTickPtr, numMonths); + ERROR_LOG(HLE, "HACK sceRtcTickAddMonths(%d,%d,%d)", destTickPtr, srcTickPtr, numMonths); return 0; } +//TODO: off by 6 days every 2000 years. int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears) { if (Memory::IsValidAddress(destTickPtr) && Memory::IsValidAddress(srcTickPtr)) @@ -546,7 +670,7 @@ int sceRtcTickAddYears(u32 destTickPtr, u32 srcTickPtr, int numYears) Memory::Write_U64(srcTick, destTickPtr); } - DEBUG_LOG(HLE, "sceRtcTickAddYears(%d,%d,%d)", destTickPtr, srcTickPtr, numYears); + DEBUG_LOG(HLE, "HACK sceRtcTickAddYears(%d,%d,%d)", destTickPtr, srcTickPtr, numYears); return 0; } @@ -571,7 +695,7 @@ const HLEFunction sceRtc[] = {0x57726bc1, WrapU_UUU, "sceRtcGetDayOfWeek"}, {0x4B1B5E82, WrapI_U, "sceRtcCheckValid"}, {0x3a807cc8, WrapI_UU64, "sceRtcSetTime_t"}, - {0x27c4594c, WrapI_UU64, "sceRtcGetTime_t"}, + {0x27c4594c, WrapI_UU, "sceRtcGetTime_t"}, {0xF006F264, WrapI_UU, "sceRtcSetDosTime"}, {0x36075567, WrapI_UU, "sceRtcGetDosTime"}, {0x7ACE4C04, WrapI_UU, "sceRtcSetWin32FileTime"}, From 6db4ea2ad1ad20d80e57055d492e042aa8b04977 Mon Sep 17 00:00:00 2001 From: Ced2911 Date: Tue, 27 Nov 2012 10:18:36 +0100 Subject: [PATCH 5/8] less Memory::GetPointer --- Core/HLE/sceAtrac.cpp | 21 +++++++------------- Core/HLE/sceCtrl.cpp | 2 +- Core/HLE/sceDmac.cpp | 2 +- Core/HLE/sceIo.cpp | 35 +++++++++++++++++---------------- Core/HLE/sceKernelInterrupt.cpp | 2 +- Core/HLE/sceKernelMbx.cpp | 6 +++--- Core/HLE/sceKernelMemory.cpp | 18 +++++++---------- Core/HLE/sceKernelSemaphore.cpp | 3 +-- Core/HLE/sceKernelThread.cpp | 5 ++--- Core/HLE/sceSas.cpp | 2 +- Core/HLE/sceUtility.cpp | 20 ++++++++++--------- 11 files changed, 53 insertions(+), 63 deletions(-) diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index a13bfc15ad..3bf7b1e950 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -104,8 +104,7 @@ void sceAtracGetMaxSample() void sceAtracGetNextDecodePosition() { ERROR_LOG(HLE, "UNIMPL sceAtracGetNextDecodePosition(%i, %08x)", PARAM(0), PARAM(1)); - u32 *outPos = (u32*)Memory::GetPointer(PARAM(1)); - *outPos = 1; + Memory::Write_U32(1, PARAM(1)); // outpos RETURN(0); } @@ -121,30 +120,24 @@ void sceAtracGetNextSample() void sceAtracGetRemainFrame() { ERROR_LOG(HLE, "sceAtracGetRemainFrame(%i, %08x)",PARAM(0),PARAM(1)); - u32 *outPos = (u32*)Memory::GetPointer(PARAM(1)); - *outPos = 12; + Memory::Write_U32(12, PARAM(1)); // outpos RETURN(0); } void sceAtracGetSecondBufferInfo() { ERROR_LOG(HLE, "sceAtracGetSecondBufferInfo(%i, %08x, %08x)",PARAM(0),PARAM(1),PARAM(2)); - u32 *outPos = (u32*)Memory::GetPointer(PARAM(1)); - u32 *outBytes = (u32*)Memory::GetPointer(PARAM(2)); - *outPos = 0; - *outBytes = 0x10000; + Memory::Write_U32(0, PARAM(1)); // outpos + Memory::Write_U32(0x10000, PARAM(2)); // outBytes RETURN(0); } void sceAtracGetSoundSample() { ERROR_LOG(HLE, "UNIMPL sceAtracGetSoundSample(%i, %08x, %08x, %08x)",PARAM(0),PARAM(1),PARAM(2),PARAM(3)); - u32 *outEndSample = (u32*)Memory::GetPointer(PARAM(1)); - u32 *outLoopStartSample = (u32*)Memory::GetPointer(PARAM(2)); - u32 *outLoopEndSample = (u32*)Memory::GetPointer(PARAM(2)); - *outEndSample = 0x10000; - *outLoopStartSample = -1; - *outLoopEndSample = -1; + Memory::Write_U32(0x10000, PARAM(1)); // outEndSample + Memory::Write_U32(-1, PARAM(2)); // outLoopStartSample + Memory::Write_U32(-1, PARAM(3)); // outLoopEndSample RETURN(0); } diff --git a/Core/HLE/sceCtrl.cpp b/Core/HLE/sceCtrl.cpp index 02511f7ad6..0e255bfdd7 100644 --- a/Core/HLE/sceCtrl.cpp +++ b/Core/HLE/sceCtrl.cpp @@ -157,7 +157,7 @@ u32 sceCtrlReadBufferPositive(u32 ctrlDataPtr, u32 nBufs) //if (ctrlInited) //{ SampleControls(); - memcpy(Memory::GetPointer(ctrlDataPtr), &ctrl, sizeof(_ctrl_data)); + Memory::WriteStruct(ctrlDataPtr, &ctrl); //} return 1; } diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index 921f62468e..7390351af1 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -22,7 +22,7 @@ u32 sceDmacMemcpy(u32 dst, u32 src, u32 size) { DEBUG_LOG(HLE, "sceDmacMemcpy(dest=%08x, src=%08x, size=%i)", dst, src, size); // TODO: check the addresses. - memcpy(Memory::GetPointer(dst), Memory::GetPointer(src), size); + Memory::Memcpy(dst, Memory::GetPointer(src), size); return 0; } diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index c8b0347f1f..771b2af590 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -250,9 +250,11 @@ void sceIoGetstat() const char *filename = Memory::GetCharPointer(PARAM(0)); u32 addr = PARAM(1); - SceIoStat *stat = (SceIoStat*)Memory::GetPointer(addr); + SceIoStat stat; PSPFileInfo info = pspFileSystem.GetFileInfo(filename); - __IoGetStat(stat, info); + __IoGetStat(&stat, info); + Memory::WriteStruct(addr, &stat); + DEBUG_LOG(HLE,"sceIoGetstat(%s, %08x) : sector = %08x",filename,addr,info.startSector); RETURN(0); @@ -793,9 +795,8 @@ void sceIoGetAsyncStat() FileNode *f = kernelObjects.Get(id, error); if (f) { - u64 *resPtr = (u64*)Memory::GetPointer(PARAM(2)); - *resPtr = f->asyncResult; - DEBUG_LOG(HLE,"%i = sceIoGetAsyncStat(%i, %i, %08x) (HACK)", (u32)*resPtr, id, PARAM(1), PARAM(2)); + Memory::Write_U64(f->asyncResult, PARAM(2)); + DEBUG_LOG(HLE,"%i = sceIoGetAsyncStat(%i, %i, %08x) (HACK)", (u32)f->asyncResult, id, PARAM(1), PARAM(2)); RETURN(0); //completed } else @@ -813,14 +814,14 @@ void sceIoWaitAsync() FileNode *f = kernelObjects.Get(id, error); if (f) { - u64 *resPtr = (u64*)Memory::GetPointer(PARAM(1)); - *resPtr = f->asyncResult; + u64 res = f->asyncResult; if (defAction) { - *resPtr = defAction(id, defParam); + res = defAction(id, defParam); defAction = 0; } - DEBUG_LOG(HLE,"%i = sceIoWaitAsync(%i, %08x) (HACK)", (u32)*resPtr, id, PARAM(1)); + Memory::Write_U64(res, PARAM(1)); + DEBUG_LOG(HLE,"%i = sceIoWaitAsync(%i, %08x) (HACK)", (u32)res, id, PARAM(1)); RETURN(0); //completed } else @@ -839,14 +840,14 @@ void sceIoWaitAsyncCB() FileNode *f = kernelObjects.Get(id, error); if (f) { - u64 *resPtr = (u64*)Memory::GetPointer(PARAM(1)); - *resPtr = f->asyncResult; + u64 res = f->asyncResult; if (defAction) { - *resPtr = defAction(id, defParam); + res = defAction(id, defParam); defAction = 0; } - DEBUG_LOG(HLE,"%i = sceIoWaitAsyncCB(%i, %08x) (HACK)", (u32)*resPtr, id, PARAM(1)); + Memory::Write_U64(res, PARAM(1)); + DEBUG_LOG(HLE,"%i = sceIoWaitAsyncCB(%i, %08x) (HACK)", (u32)res, id, PARAM(1)); RETURN(0); //completed } else @@ -862,14 +863,14 @@ void sceIoPollAsync() FileNode *f = kernelObjects.Get(id, error); if (f) { - u64 *resPtr = (u64*)Memory::GetPointer(PARAM(1)); - *resPtr = f->asyncResult; + u64 res = f->asyncResult; if (defAction) { - *resPtr = defAction(id, defParam); + res = defAction(id, defParam); defAction = 0; } - DEBUG_LOG(HLE,"%i = sceIoPollAsync(%i, %08x) (HACK)", (u32)*resPtr, id, PARAM(1)); + Memory::Write_U64(res, PARAM(1)); + DEBUG_LOG(HLE,"%i = sceIoPollAsync(%i, %08x) (HACK)", (u32)res, id, PARAM(1)); RETURN(0); //completed } else diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 260d1606e2..e23207bff2 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -426,7 +426,7 @@ u32 sceKernelMemcpy(u32 dst, u32 src, u32 size) DEBUG_LOG(HLE, "sceKernelMemcpy(dest=%08x, src=%08x, size=%i)", dst, src, size); if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(src+size)) // a bit of bound checking. Wrong?? { - memcpy(Memory::GetPointer(dst), Memory::GetPointer(src), size); + Memory::Memcpy(dst, Memory::GetPointer(src), size); } return 0; } diff --git a/Core/HLE/sceKernelMbx.cpp b/Core/HLE/sceKernelMbx.cpp index beb29cad3c..a6e45b63bf 100644 --- a/Core/HLE/sceKernelMbx.cpp +++ b/Core/HLE/sceKernelMbx.cpp @@ -246,7 +246,6 @@ int sceKernelCancelReceiveMbx(SceUID id, u32 numWaitingThreadsAddr) { u32 error; Mbx *m = kernelObjects.Get(id, error); - int *numWaitingThreads = (int*)Memory::GetPointer(numWaitingThreadsAddr); if (!m) { @@ -262,8 +261,9 @@ int sceKernelCancelReceiveMbx(SceUID id, u32 numWaitingThreadsAddr) __KernelResumeThreadFromWait(m->waitingThreads[i].first); } m->waitingThreads.clear(); - if (numWaitingThreads) - *numWaitingThreads = count; + + if (numWaitingThreadsAddr) + Memory::Write_U32(count, numWaitingThreadsAddr); return 0; } diff --git a/Core/HLE/sceKernelMemory.cpp b/Core/HLE/sceKernelMemory.cpp index 1493ad565a..452196087b 100644 --- a/Core/HLE/sceKernelMemory.cpp +++ b/Core/HLE/sceKernelMemory.cpp @@ -515,13 +515,12 @@ void sceKernelAllocateVpl() if (vpl) { u32 size = PARAM(1); - u32 *blockPtrPtr = (u32 *)Memory::GetPointer(PARAM(2)); - int timeOut = PARAM(2); + int timeOut = PARAM(3); DEBUG_LOG(HLE,"sceKernelAllocateVpl(vpl=%i, size=%i, ptrout= %08x , timeout=%i)", id, size, PARAM(2), timeOut); u32 addr = vpl->alloc.Alloc(size); if (addr != (u32)-1) { - *blockPtrPtr = addr; + Memory::Write_U32(addr, PARAM(2)); RETURN(0); } else @@ -545,13 +544,12 @@ void sceKernelAllocateVplCB() if (vpl) { u32 size = PARAM(1); - u32 *blockPtrPtr = (u32 *)Memory::GetPointer(PARAM(2)); - int timeOut = PARAM(2); + int timeOut = PARAM(3); DEBUG_LOG(HLE,"sceKernelAllocateVplCB(vpl=%i, size=%i, ptrout= %08x , timeout=%i)", id, size, PARAM(2), timeOut); u32 addr = vpl->alloc.Alloc(size); if (addr != (u32)-1) { - *blockPtrPtr = addr; + Memory::Write_U32(addr, PARAM(2)); RETURN(0); } else @@ -576,13 +574,12 @@ void sceKernelTryAllocateVpl() if (vpl) { u32 size = PARAM(1); - u32 *blockPtrPtr = (u32 *)Memory::GetPointer(PARAM(2)); - int timeOut = PARAM(2); + int timeOut = PARAM(3); DEBUG_LOG(HLE,"sceKernelAllocateVplCB(vpl=%i, size=%i, ptrout= %08x , timeout=%i)", id, size, PARAM(2), timeOut); u32 addr = vpl->alloc.Alloc(size); if (addr != (u32)-1) { - *blockPtrPtr = addr; + Memory::Write_U32(addr, PARAM(2)); RETURN(0); } else @@ -634,9 +631,8 @@ void sceKernelReferVplStatus() if (v) { DEBUG_LOG(HLE,"sceKernelReferVplStatus(%i, %08x)", id, PARAM(1)); - SceKernelVplInfo *info = (SceKernelVplInfo*)Memory::GetPointer(PARAM(1)); v->nv.freeSize = v->alloc.GetTotalFreeBytes(); - *info = v->nv; + Memory::WriteStruct(PARAM(1), &v->nv); } else { diff --git a/Core/HLE/sceKernelSemaphore.cpp b/Core/HLE/sceKernelSemaphore.cpp index 1b3a228947..2cb1a8b9c1 100644 --- a/Core/HLE/sceKernelSemaphore.cpp +++ b/Core/HLE/sceKernelSemaphore.cpp @@ -117,8 +117,7 @@ void sceKernelCancelSema(SceUID id, int newCount, u32 numWaitThreadsPtr) if (numWaitThreadsPtr) { - u32* numWaitThreads = (u32*)Memory::GetPointer(numWaitThreadsPtr); - *numWaitThreads = s->ns.numWaitThreads; + Memory::Write_U32(s->ns.numWaitThreads, numWaitThreadsPtr); } if (newCount < 0) diff --git a/Core/HLE/sceKernelThread.cpp b/Core/HLE/sceKernelThread.cpp index ea5fdf0671..c6bee53c8f 100644 --- a/Core/HLE/sceKernelThread.cpp +++ b/Core/HLE/sceKernelThread.cpp @@ -452,13 +452,12 @@ void sceKernelReferThreadStatus() if (t) { DEBUG_LOG(HLE,"sceKernelReferThreadStatus(%i, %08x)", threadID, PARAM(1)); - void *outptr = (void*)Memory::GetPointer(PARAM(1)); - u32 wantedSize = *(u32 *)outptr; + u32 wantedSize = Memory::Read_U32(PARAM(1)); u32 sz = sizeof(NativeThread); if (wantedSize) { t->nt.nativeSize = sz = std::min(sz, wantedSize); } - memcpy(outptr, &(t->nt), sz); + Memory::Memcpy(PARAM(1), &(t->nt), sz); RETURN(0); } else diff --git a/Core/HLE/sceSas.cpp b/Core/HLE/sceSas.cpp index d5bd7d2342..7f47ef87bf 100644 --- a/Core/HLE/sceSas.cpp +++ b/Core/HLE/sceSas.cpp @@ -211,7 +211,7 @@ void _sceSasCore() { u32 outAddr = PARAM(1); DEBUG_LOG(HLE,"0=sceSasCore(, %08x) (grain: %i samples)", outAddr, sas.grainSize); - memset(Memory::GetPointer(outAddr), 0, sas.grainSize * 2 * 2); + Memory::Memset(outAddr, 0, sas.grainSize * 2 * 2); sas.mix(outAddr); RETURN(0); } diff --git a/Core/HLE/sceUtility.cpp b/Core/HLE/sceUtility.cpp index e69a3734a8..63644b783a 100644 --- a/Core/HLE/sceUtility.cpp +++ b/Core/HLE/sceUtility.cpp @@ -559,36 +559,38 @@ u32 sceUtilityGetSystemParamString(u32 id, u32 destaddr, u32 unknownparam) u32 sceUtilityGetSystemParamInt(u32 id, u32 destaddr) { DEBUG_LOG(HLE,"sceUtilityGetSystemParamInt(%i, %08x)", id,destaddr); - u32 *outPtr = (u32*)Memory::GetPointer(destaddr); + u32 param = 0; switch (id) { case PSP_SYSTEMPARAM_ID_INT_ADHOC_CHANNEL: - *outPtr = PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC; + param = PSP_SYSTEMPARAM_ADHOC_CHANNEL_AUTOMATIC; break; case PSP_SYSTEMPARAM_ID_INT_WLAN_POWERSAVE: - *outPtr = PSP_SYSTEMPARAM_WLAN_POWERSAVE_OFF; + param = PSP_SYSTEMPARAM_WLAN_POWERSAVE_OFF; break; case PSP_SYSTEMPARAM_ID_INT_DATE_FORMAT: - *outPtr = PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY; + param = PSP_SYSTEMPARAM_DATE_FORMAT_DDMMYYYY; break; case PSP_SYSTEMPARAM_ID_INT_TIME_FORMAT: - *outPtr = PSP_SYSTEMPARAM_TIME_FORMAT_24HR; + param = PSP_SYSTEMPARAM_TIME_FORMAT_24HR; break; case PSP_SYSTEMPARAM_ID_INT_TIMEZONE: - *outPtr = 60; + param = 60; break; case PSP_SYSTEMPARAM_ID_INT_DAYLIGHTSAVINGS: - *outPtr = PSP_SYSTEMPARAM_TIME_FORMAT_24HR; + param = PSP_SYSTEMPARAM_TIME_FORMAT_24HR; break; case PSP_SYSTEMPARAM_ID_INT_LANGUAGE: - *outPtr = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH; + param = PSP_SYSTEMPARAM_LANGUAGE_ENGLISH; break; case PSP_SYSTEMPARAM_ID_INT_UNKNOWN: - *outPtr = 1; + param = 1; break; default: return PSP_SYSTEMPARAM_RETVAL_FAIL; } + Memory::Write_U32(param, destaddr); + return 0; } From f6fd7e13d126fd7d1a721ce5a69c3c80b759ebd1 Mon Sep 17 00:00:00 2001 From: Ced2911 Date: Tue, 27 Nov 2012 12:18:58 +0100 Subject: [PATCH 6/8] sceAudio wrap --- Core/HLE/sceAudio.cpp | 50 ++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/Core/HLE/sceAudio.cpp b/Core/HLE/sceAudio.cpp index 7a44243f59..35fadde9ec 100644 --- a/Core/HLE/sceAudio.cpp +++ b/Core/HLE/sceAudio.cpp @@ -212,7 +212,7 @@ u32 sceAudioChReserve(u32 channel, u32 sampleCount, u32 format) //.Allocate soun { WARN_LOG(HLE, "WARNING: Reserving already reserved channel. Error?"); } - DEBUG_LOG(HLE, "%i = sceAudioChReserve(%i, %i, %i)", channel, PARAM(0), sampleCount, format); + DEBUG_LOG(HLE, "%i = sceAudioChReserve(%i, %i, %i)", channel, sampleCount, format); chans[channel].sampleCount = sampleCount; chans[channel].reserved = true; @@ -300,46 +300,42 @@ u32 sceAudioChangeChannelVolume(u32 chan, u32 lvolume, u32 rvolume) } } -void sceAudioInit() +u32 sceAudioInit() { - DEBUG_LOG(HLE,"sceAudioInit()"); + DEBUG_LOG(HLE,"sceAudioInit()"); // Don't need to do anything - RETURN(0); + return 0; } -void sceAudioEnd() +u32 sceAudioEnd() { DEBUG_LOG(HLE,"sceAudioEnd()"); // Don't need to do anything - RETURN(0); + return 0; } -void sceAudioOutput2Reserve() +u32 sceAudioOutput2Reserve(u32 sampleCount) { - int sampleCount = PARAM(0); - ERROR_LOG(HLE,"sceAudioOutput2Reserve(%i)", sampleCount); + ERROR_LOG(HLE,"sceAudioOutput2Reserve(%i)", sampleCount); chans[0].sampleCount = sampleCount; chans[0].reserved = true; - RETURN(0); + return 0; } -void sceAudioOutput2OutputBlocking() +u32 sceAudioOutput2OutputBlocking(u32 vol, u32 dataPtr) { - int vol = PARAM(0); - u32 dataPtr = PARAM(1); - - WARN_LOG(HLE,"FAKE sceAudioOutput2OutputBlocking(%i, %08x)", vol, dataPtr); + WARN_LOG(HLE,"FAKE sceAudioOutput2OutputBlocking(%i, %08x)", vol, dataPtr); chans[0].leftVolume = vol; chans[0].rightVolume = vol; chans[0].sampleAddress = dataPtr; - RETURN(0); - u32 retval = __AudioEnqueue(chans[0], 0, true); + return 0; + u32 retval = __AudioEnqueue(chans[0], 0, true); if (retval < 0) - RETURN(retval); + return retval; } u32 sceAudioOutput2ChangeLength(u32 sampleCount) { - WARN_LOG(HLE,"sceAudioOutput2ChangeLength(%i)", sampleCount); + WARN_LOG(HLE,"sceAudioOutput2ChangeLength(%i)", sampleCount); chans[0].sampleCount = sampleCount; return 0; } @@ -350,11 +346,11 @@ u32 sceAudioOutput2GetRestSample() return chans[0].sampleQueue.size() * 2; } -void sceAudioOutput2Release() +u32 sceAudioOutput2Release() { - WARN_LOG(HLE,"sceAudioOutput2Release()"); + WARN_LOG(HLE,"sceAudioOutput2Release()"); chans[0].reserved = false; - RETURN(0); + return 0; } u32 sceAudioSetFrequency(u32 freq) { @@ -372,14 +368,14 @@ const HLEFunction sceAudio[] = { // Newer simplified single channel audio output. Presumably for games that use Atrac3 // directly from Sas instead of playing it on a separate audio channel. - {0x01562ba3, sceAudioOutput2Reserve, "sceAudioOutput2Reserve"}, - {0x2d53f36e, sceAudioOutput2OutputBlocking, "sceAudioOutput2OutputBlocking"}, + {0x01562ba3, WrapU_U, "sceAudioOutput2Reserve"}, + {0x2d53f36e, WrapU_UU, "sceAudioOutput2OutputBlocking"}, {0x63f2889c, WrapU_U, "sceAudioOutput2ChangeLength"}, {0x647cef33, WrapU_V, "sceAudioOutput2GetRestSample"}, - {0x43196845, sceAudioOutput2Release, "sceAudioOutput2Release"}, + {0x43196845, WrapU_V, "sceAudioOutput2Release"}, - {0x80F1F7E0, sceAudioInit, "sceAudioInit"}, - {0x210567F7, sceAudioEnd, "sceAudioEnd"}, + {0x80F1F7E0, WrapU_V, "sceAudioInit"}, + {0x210567F7, WrapU_V, "sceAudioEnd"}, {0xA2BEAA6C, WrapU_U, "sceAudioSetFrequency"}, {0x927AC32B, 0, "sceAudioSetVolumeOffset"}, From 8bf93cfb5449cc5d9799b241050d9f95949743f1 Mon Sep 17 00:00:00 2001 From: Ced2911 Date: Tue, 27 Nov 2012 13:05:51 +0100 Subject: [PATCH 7/8] sceAtrac wrap --- Core/HLE/FunctionWrappers.h | 10 ++++ Core/HLE/sceAtrac.cpp | 93 ++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Core/HLE/FunctionWrappers.h b/Core/HLE/FunctionWrappers.h index 442247a7b9..4e6c5c1f04 100644 --- a/Core/HLE/FunctionWrappers.h +++ b/Core/HLE/FunctionWrappers.h @@ -256,3 +256,13 @@ template void WrapU_UUUUUU() { u32 retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4), PARAM(5)); RETURN(retval); } + +template void WrapI_IUUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)); + RETURN(retval); +} + +template void WrapI_IUU() { + int retval = func(PARAM(0), PARAM(1), PARAM(2)); + RETURN(retval); +} \ No newline at end of file diff --git a/Core/HLE/sceAtrac.cpp b/Core/HLE/sceAtrac.cpp index 3bf7b1e950..3243892c4b 100644 --- a/Core/HLE/sceAtrac.cpp +++ b/Core/HLE/sceAtrac.cpp @@ -28,19 +28,14 @@ #define ATRAC_ERROR_API_FAIL 0x80630002 #define ATRAC_ERROR_ALL_DATA_DECODED 0x80630024 -void sceAtracAddStreamData() +int sceAtracAddStreamData(int atracID, u32 bytesToAdd) { - ERROR_LOG(HLE, "UNIMPL sceAtracAddStreamData(%i, %i)", PARAM(0), PARAM(1)); - RETURN(0); + ERROR_LOG(HLE, "UNIMPL sceAtracAddStreamData(%i, %i)", atracID, bytesToAdd); + return 0; } -void sceAtracDecodeData() +int sceAtracDecodeData(int atracID, u32 outAddr, u32 numSamplesAddr, u32 finishFlagAddr, u32 remainAddr) { - u32 atracID = PARAM(0); - u32 outAddr = PARAM(1); - u32 numSamplesAddr = PARAM(2); - u32 finishFlagAddr = PARAM(3); - u32 remainAddr = PARAM(4); ERROR_LOG(HLE, "FAKE sceAtracDecodeData(%i, %08x, %08x, %08x, %08x)", atracID, outAddr, numSamplesAddr, finishFlagAddr, remainAddr); Memory::Write_U16(0, outAddr); // Write a single 16-bit stereo @@ -50,7 +45,7 @@ void sceAtracDecodeData() Memory::Write_U32(1, finishFlagAddr); // Lie that decoding is finished Memory::Write_U32(0, remainAddr); // Lie that decoding is finished - RETURN(0); + return 0; } void sceAtracEndEntry() @@ -71,10 +66,10 @@ void sceAtracGetBufferInfoForReseting() RETURN(0); } -void sceAtracGetBitrate() +int sceAtracGetBitrate(int atracID, u32 outBitrateAddr) { ERROR_LOG(HLE, "UNIMPL sceAtracGetBitrate"); - RETURN(0); + return 0; } void sceAtracGetChannel() @@ -101,57 +96,51 @@ void sceAtracGetMaxSample() RETURN(0); } -void sceAtracGetNextDecodePosition() +int sceAtracGetNextDecodePosition(int atracID, u32 outposAddr) { - ERROR_LOG(HLE, "UNIMPL sceAtracGetNextDecodePosition(%i, %08x)", PARAM(0), PARAM(1)); - Memory::Write_U32(1, PARAM(1)); // outpos - RETURN(0); + ERROR_LOG(HLE, "UNIMPL sceAtracGetNextDecodePosition(%i, %08x)", atracID, outposAddr); + Memory::Write_U32(1, outposAddr); // outpos + return 0; } -void sceAtracGetNextSample() +int sceAtracGetNextSample(int atracID, u32 outNAddr) { - u32 atracID = PARAM(0); - u32 outN = PARAM(1); - ERROR_LOG(HLE, "FAKE sceAtracGetNextSample(%i, %08x)", atracID, outN); - Memory::Write_U32(0, outN); - RETURN(0); + ERROR_LOG(HLE, "FAKE sceAtracGetNextSample(%i, %08x)", atracID, outNAddr); + Memory::Write_U32(0, outNAddr); + return 0; } -void sceAtracGetRemainFrame() +int sceAtracGetRemainFrame(int atracID, u32 outposAddr) { - ERROR_LOG(HLE, "sceAtracGetRemainFrame(%i, %08x)",PARAM(0),PARAM(1)); - Memory::Write_U32(12, PARAM(1)); // outpos - RETURN(0); + ERROR_LOG(HLE, "sceAtracGetRemainFrame(%i, %08x)", atracID, outposAddr); + Memory::Write_U32(12, outposAddr); // outpos + return 0; } -void sceAtracGetSecondBufferInfo() +int sceAtracGetSecondBufferInfo(int atracID, u32 outposAddr, u32 outBytesAddr) { - ERROR_LOG(HLE, "sceAtracGetSecondBufferInfo(%i, %08x, %08x)",PARAM(0),PARAM(1),PARAM(2)); - Memory::Write_U32(0, PARAM(1)); // outpos - Memory::Write_U32(0x10000, PARAM(2)); // outBytes - RETURN(0); + ERROR_LOG(HLE, "sceAtracGetSecondBufferInfo(%i, %08x, %08x)", atracID, outposAddr, outBytesAddr); + Memory::Write_U32(0, outposAddr); // outpos + Memory::Write_U32(0x10000, outBytesAddr); // outBytes + return 0; } -void sceAtracGetSoundSample() +int sceAtracGetSoundSample(int atracID, u32 outEndSampleAddr, u32 outLoopStartSampleAddr, u32 outLoopEndSampleAddr) { - ERROR_LOG(HLE, "UNIMPL sceAtracGetSoundSample(%i, %08x, %08x, %08x)",PARAM(0),PARAM(1),PARAM(2),PARAM(3)); - Memory::Write_U32(0x10000, PARAM(1)); // outEndSample - Memory::Write_U32(-1, PARAM(2)); // outLoopStartSample - Memory::Write_U32(-1, PARAM(3)); // outLoopEndSample - RETURN(0); + ERROR_LOG(HLE, "UNIMPL sceAtracGetSoundSample(%i, %08x, %08x, %08x)", atracID, outEndSampleAddr, outLoopStartSampleAddr, outLoopEndSampleAddr); + Memory::Write_U32(0x10000, outEndSampleAddr); // outEndSample + Memory::Write_U32(-1, outLoopStartSampleAddr); // outLoopStartSample + Memory::Write_U32(-1, outLoopEndSampleAddr); // outLoopEndSample + return 0; } -void sceAtracGetStreamDataInfo() +int sceAtracGetStreamDataInfo(int atracID, u32 writePointerAddr, u32 availableBytesAddr, u32 readOffsetAddr) { - u32 atracID = PARAM(0); - u32 writePointerAddr = PARAM(1); - u32 availableBytesAddr = PARAM(2); - u32 readOffsetAddr = PARAM(3); ERROR_LOG(HLE, "FAKE sceAtracGetStreamDataInfo(%i, %08x, %08x, %08x)", atracID, writePointerAddr, availableBytesAddr, readOffsetAddr); Memory::Write_U32(0, readOffsetAddr); Memory::Write_U32(0, availableBytesAddr); Memory::Write_U32(0, writePointerAddr); - RETURN(0); + return 0; } void sceAtracReleaseAtracID() @@ -211,22 +200,22 @@ void sceAtracSetLoopNum() const HLEFunction sceAtrac3plus[] = { - {0x7db31251,sceAtracAddStreamData,"sceAtracAddStreamData"}, - {0x6a8c3cd5,sceAtracDecodeData,"sceAtracDecodeData"}, + {0x7db31251,WrapI_IU,"sceAtracAddStreamData"}, + {0x6a8c3cd5,WrapI_IUUUU,"sceAtracDecodeData"}, {0xd5c28cc0,sceAtracEndEntry,"sceAtracEndEntry"}, {0x780f88d1,sceAtracGetAtracID,"sceAtracGetAtracID"}, {0xca3ca3d2,sceAtracGetBufferInfoForReseting,"sceAtracGetBufferInfoForReseting"}, - {0xa554a158,sceAtracGetBitrate,"sceAtracGetBitrate"}, + {0xa554a158,WrapI_IU,"sceAtracGetBitrate"}, {0x31668baa,sceAtracGetChannel,"sceAtracGetChannel"}, {0xfaa4f89b,sceAtracGetLoopStatus,"sceAtracGetLoopStatus"}, {0xe88f759b,sceAtracGetInternalErrorInfo,"sceAtracGetInternalErrorInfo"}, {0xd6a5f2f7,sceAtracGetMaxSample,"sceAtracGetMaxSample"}, - {0xe23e3a35,sceAtracGetNextDecodePosition,"sceAtracGetNextDecodePosition"}, - {0x36faabfb,sceAtracGetNextSample,"sceAtracGetNextSample"}, - {0x9ae849a7,sceAtracGetRemainFrame,"sceAtracGetRemainFrame"}, - {0x83e85ea0,sceAtracGetSecondBufferInfo,"sceAtracGetSecondBufferInfo"}, - {0xa2bba8be,sceAtracGetSoundSample,"sceAtracGetSoundSample"}, - {0x5d268707,sceAtracGetStreamDataInfo,"sceAtracGetStreamDataInfo"}, + {0xe23e3a35,WrapI_IU,"sceAtracGetNextDecodePosition"}, + {0x36faabfb,WrapI_IU,"sceAtracGetNextSample"}, + {0x9ae849a7,WrapI_IU,"sceAtracGetRemainFrame"}, + {0x83e85ea0,WrapI_IUU,"sceAtracGetSecondBufferInfo"}, + {0xa2bba8be,WrapI_IUUU,"sceAtracGetSoundSample"}, + {0x5d268707,WrapI_IUUU,"sceAtracGetStreamDataInfo"}, {0x61eb33f5,sceAtracReleaseAtracID,"sceAtracReleaseAtracID"}, {0x644e5607,sceAtracResetPlayPosition,"sceAtracResetPlayPosition"}, {0x3f6e26b5,sceAtracSetHalfwayBuffer,"sceAtracSetHalfwayBuffer"}, From 6192bdf6df97c6e6ac444870cd58a82fcdf7b398 Mon Sep 17 00:00:00 2001 From: Sacha Date: Wed, 28 Nov 2012 04:57:30 +1000 Subject: [PATCH 8/8] sceIoRename function --- Core/FileSystems/DirectoryFileSystem.cpp | 40 +++++++++++++++++------- Core/FileSystems/DirectoryFileSystem.h | 5 +-- Core/FileSystems/FileSystem.h | 2 ++ Core/FileSystems/ISOFileSystem.h | 1 + Core/FileSystems/MetaFileSystem.cpp | 15 +++++++++ Core/FileSystems/MetaFileSystem.h | 1 + Core/HLE/sceIo.cpp | 7 +++-- 7 files changed, 56 insertions(+), 15 deletions(-) diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index d1a4e02091..f1fb84ac7d 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -35,17 +35,16 @@ std::string DirectoryFileSystem::GetLocalPath(std::string localpath) if (localpath.empty()) return basePath; - if (localpath[0] == '/') - localpath.erase(0,1); + if (localpath[0] == '/') + localpath.erase(0,1); //Convert slashes #ifdef _WIN32 for (size_t i = 0; i < localpath.size(); i++) { if (localpath[i] == '/') localpath[i] = '\\'; - } + } #endif - return basePath + localpath; } @@ -56,8 +55,8 @@ bool DirectoryFileSystem::MkDir(const std::string &dirname) #ifdef _WIN32 return CreateDirectory(fullName.c_str(), NULL) == TRUE; #else - mkdir(fullName.c_str(), 0777); - return true; + mkdir(fullName.c_str(), 0777); + return true; #endif } @@ -67,7 +66,26 @@ bool DirectoryFileSystem::RmDir(const std::string &dirname) #ifdef _WIN32 return RemoveDirectory(fullName.c_str()) == TRUE; #else - return 0 == rmdir(fullName.c_str()); + return 0 == rmdir(fullName.c_str()); +#endif +} + +bool DirectoryFileSystem::RenameFile(const std::string &from, const std::string &to) +{ + std::string fullFrom = GetLocalPath(from); + std::string fullTo = to; + // TO filename may not include path. Intention is that it uses FROM's path + if (to.find("/") != std::string::npos) { + int offset = from.find_last_of("/"); + if (offset >= 0) { + fullTo = from.substr(0, offset + 1) + to; + } + } + fullTo = GetLocalPath(fullTo); +#ifdef _WIN32 + return MoveFile(fullFrom.c_str(), fullTo.c_str()) == TRUE; +#else + return 0 == rename(fullFrom.c_str(), fullTo.c_str()); #endif } @@ -77,7 +95,7 @@ bool DirectoryFileSystem::DeleteFile(const std::string &filename) #ifdef _WIN32 return DeleteFile(fullName.c_str()) == TRUE; #else - return 0 == unlink(fullName.c_str()); + return 0 == unlink(fullName.c_str()); #endif } @@ -243,7 +261,7 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) x.name = filename; - std::string fullName = GetLocalPath(filename); + std::string fullName = GetLocalPath(filename); if (!File::Exists(fullName)) { return x; } @@ -257,8 +275,8 @@ PSPFileInfo DirectoryFileSystem::GetFileInfo(std::string filename) x.size = data.nFileSizeLow | ((u64)data.nFileSizeHigh<<32); #else - x.size = File::GetSize(fullName); - //TODO + x.size = File::GetSize(fullName); + //TODO #endif return x; diff --git a/Core/FileSystems/DirectoryFileSystem.h b/Core/FileSystems/DirectoryFileSystem.h index e0598cbde7..df81ccab34 100644 --- a/Core/FileSystems/DirectoryFileSystem.h +++ b/Core/FileSystems/DirectoryFileSystem.h @@ -36,7 +36,7 @@ class DirectoryFileSystem : public IFileSystem #ifdef _WIN32 HANDLE hFile; #else - FILE *hFile; + FILE *hFile; #endif }; @@ -61,6 +61,7 @@ public: bool OwnsHandle(u32 handle); bool MkDir(const std::string &dirname); bool RmDir(const std::string &dirname); + bool RenameFile(const std::string &from, const std::string &to); bool DeleteFile(const std::string &filename); }; - \ No newline at end of file + diff --git a/Core/FileSystems/FileSystem.h b/Core/FileSystems/FileSystem.h index 8024461d1c..069296d7de 100644 --- a/Core/FileSystems/FileSystem.h +++ b/Core/FileSystems/FileSystem.h @@ -83,6 +83,7 @@ public: virtual bool OwnsHandle(u32 handle) = 0; virtual bool MkDir(const std::string &dirname) = 0; virtual bool RmDir(const std::string &dirname) = 0; + virtual bool RenameFile(const std::string &from, const std::string &to) = 0; virtual bool DeleteFile(const std::string &filename) = 0; }; @@ -100,6 +101,7 @@ public: bool OwnsHandle(u32 handle) {return false;} virtual bool MkDir(const std::string &dirname) {return false;} virtual bool RmDir(const std::string &dirname) {return false;} + virtual bool RenameFile(const std::string &from, const std::string &to) {return false;} virtual bool DeleteFile(const std::string &filename) {return false;} }; diff --git a/Core/FileSystems/ISOFileSystem.h b/Core/FileSystems/ISOFileSystem.h index 530e152145..61f30016f1 100644 --- a/Core/FileSystems/ISOFileSystem.h +++ b/Core/FileSystems/ISOFileSystem.h @@ -82,5 +82,6 @@ public: virtual bool MkDir(const std::string &dirname) {return false;} virtual bool RmDir(const std::string &dirname) {return false;} + virtual bool RenameFile(const std::string &from, const std::string &to) {return false;} virtual bool DeleteFile(const std::string &filename) {return false;} }; diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index 7ca1a9a619..55895968fc 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -177,6 +177,21 @@ bool MetaFileSystem::RmDir(const std::string &dirname) } } +bool MetaFileSystem::RenameFile(const std::string &from, const std::string &to) +{ + std::string of; + std::string rf; + IFileSystem *system; + if (MapFilePath(from, of, &system) && MapFilePath(to, rf, &system)) + { + return system->RenameFile(of, rf); + } + else + { + return false; + } +} + bool MetaFileSystem::DeleteFile(const std::string &filename) { std::string of; diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index 35ed0e55b5..dee552e098 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -56,6 +56,7 @@ public: virtual bool MkDir(const std::string &dirname); virtual bool RmDir(const std::string &dirname); + virtual bool RenameFile(const std::string &from, const std::string &to); virtual bool DeleteFile(const std::string &filename); // TODO: void IoCtl(...) diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 771b2af590..6b5501cfe2 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -700,8 +700,11 @@ void sceIoRename() //(const char *oldname, const char *newname); { const char *from = Memory::GetCharPointer(PARAM(0)); const char *to = Memory::GetCharPointer(PARAM(1)); - ERROR_LOG(HLE,"UNIMPL sceIoRename(%s, %s)", from, to); - RETURN(0); + if (pspFileSystem.RenameFile(from, to)) + RETURN(0); + else + RETURN(-1); + DEBUG_LOG(HLE,"sceIoRename(%s, %s)", from, to); } void sceIoChdir()