Jpeg: Play it safe with load/unload handling.

This commit is contained in:
Unknown W. Brackets 2022-10-07 00:24:19 -07:00
parent 0931b343c2
commit 7f87cd077a
3 changed files with 28 additions and 3 deletions

View File

@ -442,6 +442,13 @@ static int sceJpegDecompressAllImage() {
return 0;
}
void JpegNotifyLoadStatus(int state) {
if (state == -1) {
// Reset our state on unload.
__JpegInit();
}
}
const HLEFunction sceJpeg[] =
{
{0X0425B986, &WrapI_V<sceJpegDecompressAllImage>, "sceJpegDecompressAllImage", 'i', "" },

View File

@ -19,6 +19,8 @@
class PointerWrap;
void JpegNotifyLoadStatus(int state);
void Register_sceJpeg();
void __JpegInit();
void __JpegDoState(PointerWrap &p);

View File

@ -34,6 +34,7 @@
#include "Core/Reporting.h"
#include "Core/System.h"
#include "Core/HLE/sceJpeg.h"
#include "Core/HLE/sceKernel.h"
#include "Core/HLE/sceKernelInterrupt.h"
#include "Core/HLE/sceKernelMemory.h"
@ -79,16 +80,21 @@ static const int mpegBaseModuleDeps[] = {0x0300, 0};
static const int mp4ModuleDeps[] = {0x0300, 0};
struct ModuleLoadInfo {
ModuleLoadInfo(int m, u32 s) : mod(m), size(s), dependencies(noDeps) {
ModuleLoadInfo(int m, u32 s, void(*n)(int) = nullptr) : mod(m), size(s), dependencies(noDeps), notify(n) {
}
ModuleLoadInfo(int m, u32 s, const int *d) : mod(m), size(s), dependencies(d) {
ModuleLoadInfo(int m, u32 s, const int *d, void(*n)(int) = nullptr) : mod(m), size(s), dependencies(d), notify(n) {
}
const int mod;
const u32 size;
const int *const dependencies;
void (*notify)(int state);
};
static void NotifyLoadStatusAvcodec(int state) {
JpegNotifyLoadStatus(state);
}
static const ModuleLoadInfo moduleLoadInfo[] = {
ModuleLoadInfo(0x0100, 0x00014000),
ModuleLoadInfo(0x0101, 0x00020000),
@ -104,7 +110,7 @@ static const ModuleLoadInfo moduleLoadInfo[] = {
ModuleLoadInfo(0x0202, 0x00000000),
ModuleLoadInfo(0x0203, 0x00000000),
ModuleLoadInfo(0x02ff, 0x00000000),
ModuleLoadInfo(0x0300, 0x00000000),
ModuleLoadInfo(0x0300, 0x00000000, &NotifyLoadStatusAvcodec),
ModuleLoadInfo(0x0301, 0x00000000),
ModuleLoadInfo(0x0302, 0x00008000, atrac3PlusModuleDeps),
ModuleLoadInfo(0x0303, 0x0000c000, mpegBaseModuleDeps),
@ -470,12 +476,16 @@ static u32 sceUtilityLoadAvModule(u32 module)
}
INFO_LOG(SCEUTILITY, "0=sceUtilityLoadAvModule(%i)", module);
if (module == 0)
JpegNotifyLoadStatus(1);
return hleDelayResult(0, "utility av module loaded", 25000);
}
static u32 sceUtilityUnloadAvModule(u32 module)
{
INFO_LOG(SCEUTILITY,"0=sceUtilityUnloadAvModule(%i)", module);
if (module == 0)
JpegNotifyLoadStatus(-1);
return hleDelayResult(0, "utility av module unloaded", 800);
}
@ -516,6 +526,9 @@ static u32 sceUtilityLoadModule(u32 module) {
currentlyLoadedModules[module] = 0;
}
if (info->notify)
info->notify(1);
// TODO: Each module has its own timing, technically, but this is a low-end.
if (module == 0x3FF)
return hleDelayResult(hleLogSuccessInfoI(SCEUTILITY, 0), "utility module loaded", 130);
@ -537,6 +550,9 @@ static u32 sceUtilityUnloadModule(u32 module) {
}
currentlyLoadedModules.erase(module);
if (info->notify)
info->notify(-1);
// TODO: Each module has its own timing, technically, but this is a low-end.
if (module == 0x3FF)
return hleDelayResult(hleLogSuccessInfoI(SCEUTILITY, 0), "utility module unloaded", 110);