From fa854001782dbf87877e2058987d6698f7b9072d Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 20 Jul 2013 21:50:35 -0700 Subject: [PATCH] Make sceCccDecode*() work. --- Core/HLE/sceCcc.cpp | 66 ++++++++++++++++++++++++++++++++++++--------- native | 2 +- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/Core/HLE/sceCcc.cpp b/Core/HLE/sceCcc.cpp index 50ad24a056..08524d0855 100644 --- a/Core/HLE/sceCcc.cpp +++ b/Core/HLE/sceCcc.cpp @@ -16,10 +16,15 @@ // https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/. #include "util/text/utf8.h" +#include "util/text/utf16.h" +#include "util/text/shiftjis.h" #include "Core/HLE/HLE.h" #include "Core/Reporting.h" +typedef PSPPointer PSPCharPointer; +typedef PSPPointer PSPWCharPointer; + static u16 errorUTF8; static u16 errorUTF16; static u16 errorSJIS; @@ -124,31 +129,66 @@ int sceCccEncodeSJIS(u32 dstAddr, u32 ucs) int sceCccDecodeUTF8(u32 dstAddrAddr) { - DEBUG_LOG(HLE, "sceCccDecodeUTF8(%08x)", dstAddrAddr); - PSPPointer dst; - dst = dstAddrAddr; + PSPPointer dstp; + dstp = dstAddrAddr; - int result = 0; - if (dst.IsValid()) - { - int size = 0; - result = u8_nextchar(**dst, &size); - *dst += size; + if (!dstp.IsValid() || !dstp->IsValid()) { + ERROR_LOG(HLE, "sceCccDecodeUTF8(%08x): invalid pointer", dstAddrAddr); + // Should crash? + return 0; } + DEBUG_LOG(HLE, "sceCccDecodeUTF8(%08x)", dstAddrAddr); + UTF8 utf(*dstp); + int result = utf.next(); + *dstp += utf.byteIndex(); + + if (result == UTF8::INVALID) + return errorUTF8; return result; } int sceCccDecodeUTF16(u32 dstAddrAddr) { - ERROR_LOG_REPORT(HLE, "UNIMPL sceCccDecodeUTF16(%08x)", dstAddrAddr); - return 0; + PSPPointer dstp; + dstp = dstAddrAddr; + + if (!dstp.IsValid() || !dstp->IsValid()) { + ERROR_LOG(HLE, "sceCccDecodeUTF16(%08x): invalid pointer", dstAddrAddr); + // Should crash? + return 0; + } + + DEBUG_LOG(HLE, "sceCccDecodeUTF16(%08x)", dstAddrAddr); + // TODO: Does it do any detection of BOM? + UTF16LE utf(*dstp); + int result = utf.next(); + *dstp += utf.byteIndex(); + + if (result == UTF16LE::INVALID) + return errorUTF16; + return result; } int sceCccDecodeSJIS(u32 dstAddrAddr) { - ERROR_LOG_REPORT(HLE, "UNIMPL sceCccDecodeSJIS(%08x)", dstAddrAddr); - return 0; + PSPPointer dstp; + dstp = dstAddrAddr; + + if (!dstp.IsValid() || !dstp->IsValid()) { + ERROR_LOG(HLE, "sceCccDecodeSJIS(%08x): invalid pointer", dstAddrAddr); + // Should crash? + return 0; + } + + DEBUG_LOG(HLE, "sceCccDecodeSJIS(%08x)", dstAddrAddr); + ShiftJIS sjis(*dstp); + int result = sjis.next(); + *dstp += sjis.byteIndex(); + + if (result == ShiftJIS::INVALID) + return errorSJIS; + return result; } u32 sceCccSetErrorCharUTF8(u32 c) diff --git a/native b/native index d70ac3bba5..f3da7ce00a 160000 --- a/native +++ b/native @@ -1 +1 @@ -Subproject commit d70ac3bba52fcfceaae40922e1f8af2b034a768d +Subproject commit f3da7ce00a7e5153c959ceb5c421a038b02b1474