CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/Core/HLE/sceDeflt.cpp
Views: 1401
// Copyright (c) 2012- PPSSPP Project.12// This program is free software: you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation, version 2.0 or later versions.56// This program is distributed in the hope that it will be useful,7// but WITHOUT ANY WARRANTY; without even the implied warranty of8// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9// GNU General Public License 2.0 for more details.1011// A copy of the GPL 2.0 should have been included with the program.12// If not, see http://www.gnu.org/licenses/1314// Official git repository and contact information can be found at15// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.1617#include "zlib.h"1819#include "Common/CommonTypes.h"20#include "Core/Debugger/MemBlockInfo.h"21#include "Core/HLE/HLE.h"22#include "Core/HLE/FunctionWrappers.h"23#include "Core/HLE/sceDeflt.h"24#include "Core/MemMap.h"2526// All the decompress functions are identical with only differing window bits.27static int CommonDecompress(int windowBits, u32 OutBuffer, int OutBufferLength, u32 InBuffer, u32 Crc32Addr) {28if (!Memory::IsValidAddress(OutBuffer) || !Memory::IsValidAddress(InBuffer)) {29return hleLogError(Log::HLE, 0, "bad address");30}3132auto crc32Addr = PSPPointer<u32_le>::Create(Crc32Addr);33if (Crc32Addr && !crc32Addr.IsValid()) {34return hleLogError(Log::HLE, 0, "bad crc32 address");35}3637z_stream stream{};38u8 *outBufferPtr = Memory::GetPointerWrite(OutBuffer);39stream.next_in = (Bytef*)Memory::GetPointer(InBuffer);40// We don't know the available length, just let it use as much as it wants.41stream.avail_in = (uInt)Memory::ValidSize(InBuffer, Memory::g_MemorySize);42stream.next_out = outBufferPtr;43stream.avail_out = (uInt)OutBufferLength;4445int err = inflateInit2(&stream, windowBits);46if (err != Z_OK) {47return hleLogError(Log::HLE, 0, "inflateInit2 failed %08x", err);48}49err = inflate(&stream, Z_FINISH);50inflateEnd(&stream);5152if (err != Z_STREAM_END) {53return hleLogError(Log::HLE, 0, "inflate failed %08x", err);54}55if (crc32Addr.IsValid()) {56uLong crc = crc32(0L, Z_NULL, 0);57*crc32Addr = crc32(crc, outBufferPtr, stream.total_out);58}5960if (MemBlockInfoDetailed(stream.total_in, stream.total_out)) {61char tagData[128];62size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "sceDeflt/", InBuffer, stream.total_in);63NotifyMemInfo(MemBlockFlags::READ, InBuffer, stream.total_in, tagData, tagSize);64NotifyMemInfo(MemBlockFlags::WRITE, OutBuffer, stream.total_out, tagData, tagSize);65}6667return hleLogSuccessI(Log::HLE, stream.total_out);68}6970static int sceDeflateDecompress(u32 OutBuffer, int OutBufferLength, u32 InBuffer, u32 Crc32Addr) {71return CommonDecompress(-MAX_WBITS, OutBuffer, OutBufferLength, InBuffer, Crc32Addr);72}7374static int sceGzipDecompress(u32 OutBuffer, int OutBufferLength, u32 InBuffer, u32 Crc32Addr) {75return CommonDecompress(16 + MAX_WBITS, OutBuffer, OutBufferLength, InBuffer, Crc32Addr);76}7778static int sceZlibDecompress(u32 OutBuffer, int OutBufferLength, u32 InBuffer, u32 Crc32Addr) {79return CommonDecompress(MAX_WBITS, OutBuffer, OutBufferLength, InBuffer, Crc32Addr);80}8182const HLEFunction sceDeflt[] = {83{0X0BA3B9CC, nullptr, "sceGzipGetCompressedData", '?', "" },84{0X106A3552, nullptr, "sceGzipGetName", '?', "" },85{0X1B5B82BC, nullptr, "sceGzipIsValid", '?', "" },86{0X2EE39A64, nullptr, "sceZlibAdler32", '?', "" },87{0X44054E03, &WrapI_UIUU<sceDeflateDecompress>, "sceDeflateDecompress", 'i', "xixp"},88{0X6A548477, nullptr, "sceZlibGetCompressedData", '?', "" },89{0X6DBCF897, &WrapI_UIUU<sceGzipDecompress>, "sceGzipDecompress", 'i', "xixp"},90{0X8AA82C92, nullptr, "sceGzipGetInfo", '?', "" },91{0XA9E4FB28, &WrapI_UIUU<sceZlibDecompress>, "sceZlibDecompress", 'i', "xixp"},92{0XAFE01FD3, nullptr, "sceZlibGetInfo", '?', "" },93{0XB767F9A0, nullptr, "sceGzipGetComment", '?', "" },94{0XE46EB986, nullptr, "sceZlibIsValid", '?', "" },95};9697void Register_sceDeflt() {98RegisterModule("sceDeflt", ARRAY_SIZE(sceDeflt), sceDeflt);99}100101102