mirror of
https://github.com/libretro/ppsspp.git
synced 2025-03-04 14:37:17 +00:00
Reference fontlibs indirectly for savestates.
Well, not pretty, but much easier to savestate.
This commit is contained in:
parent
165cfe53a3
commit
affcdfabd5
@ -3,6 +3,9 @@
|
|||||||
#include "base/timeutil.h"
|
#include "base/timeutil.h"
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <vector>
|
||||||
|
#include <map>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include "HLE.h"
|
#include "HLE.h"
|
||||||
#include "../MIPS/MIPS.h"
|
#include "../MIPS/MIPS.h"
|
||||||
@ -185,43 +188,49 @@ static std::vector<Font *> internalFonts;
|
|||||||
// However, these we must save - but we could take a shortcut
|
// However, these we must save - but we could take a shortcut
|
||||||
// for LoadedFonts that point to internal fonts.
|
// for LoadedFonts that point to internal fonts.
|
||||||
static std::map<u32, LoadedFont *> fontMap;
|
static std::map<u32, LoadedFont *> fontMap;
|
||||||
static std::map<u32, FontLib *> fontLibMap;
|
static std::map<u32, u32> fontLibMap;
|
||||||
|
// We keep this list to avoid ptr references, even before alloc is called.
|
||||||
|
static std::vector<FontLib *> fontLibList;
|
||||||
|
|
||||||
class PostAllocCallback : public Action {
|
class PostAllocCallback : public Action {
|
||||||
public:
|
public:
|
||||||
PostAllocCallback() {}
|
PostAllocCallback() {}
|
||||||
static Action *Create() { return new PostAllocCallback(); }
|
static Action *Create() { return new PostAllocCallback(); }
|
||||||
void DoState(PointerWrap &p) { /*TODO*/ p.DoMarker("PostAllocCallback"); }
|
void DoState(PointerWrap &p) { p.Do(fontLibID_); p.DoMarker("PostAllocCallback"); }
|
||||||
void run(MipsCall &call);
|
void run(MipsCall &call);
|
||||||
void SetFontLib(FontLib *fontLib) { fontLib_ = fontLib; }
|
void SetFontLib(u32 fontLibID) { fontLibID_ = fontLibID; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FontLib *fontLib_;
|
u32 fontLibID_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PostOpenCallback : public Action {
|
class PostOpenCallback : public Action {
|
||||||
public:
|
public:
|
||||||
PostOpenCallback() {}
|
PostOpenCallback() {}
|
||||||
static Action *Create() { return new PostOpenCallback(); }
|
static Action *Create() { return new PostOpenCallback(); }
|
||||||
void DoState(PointerWrap &p) { /*TODO*/ p.DoMarker("PostOpenCallback"); }
|
void DoState(PointerWrap &p) { p.Do(fontLibID_); p.DoMarker("PostOpenCallback"); }
|
||||||
void run(MipsCall &call);
|
void run(MipsCall &call);
|
||||||
void SetFontLib(FontLib *fontLib) { fontLib_ = fontLib; }
|
void SetFontLib(u32 fontLibID) { fontLibID_ = fontLibID; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FontLib *fontLib_;
|
u32 fontLibID_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// A "fontLib" is a container of loaded fonts.
|
// A "fontLib" is a container of loaded fonts.
|
||||||
// One can open either "internal" fonts or custom fonts into a fontlib.
|
// One can open either "internal" fonts or custom fonts into a fontlib.
|
||||||
class FontLib {
|
class FontLib {
|
||||||
public:
|
public:
|
||||||
|
FontLib() {
|
||||||
|
// For save states only.
|
||||||
|
}
|
||||||
|
|
||||||
FontLib(u32 paramPtr) : fontHRes_(128.0f), fontVRes_(128.0f) {
|
FontLib(u32 paramPtr) : fontHRes_(128.0f), fontVRes_(128.0f) {
|
||||||
Memory::ReadStruct(paramPtr, ¶ms_);
|
Memory::ReadStruct(paramPtr, ¶ms_);
|
||||||
fakeAlloc_ = 0x13370;
|
fakeAlloc_ = 0x13370;
|
||||||
// We use the same strange scheme that JPCSP uses.
|
// We use the same strange scheme that JPCSP uses.
|
||||||
u32 allocSize = 4 + 4 * params_.numFonts;
|
u32 allocSize = 4 + 4 * params_.numFonts;
|
||||||
PostAllocCallback *action = (PostAllocCallback*) __KernelCreateAction(actionPostAllocCallback);
|
PostAllocCallback *action = (PostAllocCallback*) __KernelCreateAction(actionPostAllocCallback);
|
||||||
action->SetFontLib(this);
|
action->SetFontLib(GetListID());
|
||||||
|
|
||||||
if (false) {
|
if (false) {
|
||||||
// This fails in dissidia. The function at 088ff320 (params_.allocFuncAddr) calls some malloc function, the second one returns 0 which causes
|
// This fails in dissidia. The function at 088ff320 (params_.allocFuncAddr) calls some malloc function, the second one returns 0 which causes
|
||||||
@ -231,11 +240,15 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
AllocDone(fakeAlloc_);
|
AllocDone(fakeAlloc_);
|
||||||
fakeAlloc_ += allocSize;
|
fakeAlloc_ += allocSize;
|
||||||
fontLibMap[handle()] = this;
|
fontLibMap[handle()] = GetListID();
|
||||||
INFO_LOG(HLE, "Leaving PostAllocCallback::run");
|
INFO_LOG(HLE, "Leaving PostAllocCallback::run");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 GetListID() {
|
||||||
|
return (u32)(std::find(fontLibList.begin(), fontLibList.end(), this) - fontLibList.begin());
|
||||||
|
}
|
||||||
|
|
||||||
void Close() {
|
void Close() {
|
||||||
__KernelDirectMipsCall(params_.closeFuncAddr, 0, 0, 0, false);
|
__KernelDirectMipsCall(params_.closeFuncAddr, 0, 0, 0, false);
|
||||||
}
|
}
|
||||||
@ -312,12 +325,15 @@ public:
|
|||||||
|
|
||||||
void DoState(PointerWrap &p) {
|
void DoState(PointerWrap &p) {
|
||||||
p.Do(fonts_);
|
p.Do(fonts_);
|
||||||
|
p.Do(isfontopen_);
|
||||||
p.Do(params_);
|
p.Do(params_);
|
||||||
p.Do(fontHRes_);
|
p.Do(fontHRes_);
|
||||||
p.Do(fontVRes_);
|
p.Do(fontVRes_);
|
||||||
p.Do(fileFontHandle_);
|
p.Do(fileFontHandle_);
|
||||||
p.Do(handle_);
|
p.Do(handle_);
|
||||||
p.Do(altCharCode_);
|
p.Do(altCharCode_);
|
||||||
|
p.Do(fakeAlloc_);
|
||||||
|
p.DoMarker("FontLib");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetFileFontHandle(u32 handle) {
|
void SetFileFontHandle(u32 handle) {
|
||||||
@ -345,19 +361,21 @@ private:
|
|||||||
void PostAllocCallback::run(MipsCall &call) {
|
void PostAllocCallback::run(MipsCall &call) {
|
||||||
INFO_LOG(HLE, "Entering PostAllocCallback::run");
|
INFO_LOG(HLE, "Entering PostAllocCallback::run");
|
||||||
u32 v0 = currentMIPS->r[0];
|
u32 v0 = currentMIPS->r[0];
|
||||||
fontLib_->AllocDone(call.savedV0);
|
FontLib *fontLib = fontLibList[fontLibID_];
|
||||||
fontLibMap[fontLib_->handle()] = fontLib_;
|
fontLib->AllocDone(call.savedV0);
|
||||||
call.setReturnValue(fontLib_->handle());
|
fontLibMap[fontLib->handle()] = fontLibID_;
|
||||||
|
call.setReturnValue(fontLib->handle());
|
||||||
INFO_LOG(HLE, "Leaving PostAllocCallback::run");
|
INFO_LOG(HLE, "Leaving PostAllocCallback::run");
|
||||||
}
|
}
|
||||||
|
|
||||||
void PostOpenCallback::run(MipsCall &call) {
|
void PostOpenCallback::run(MipsCall &call) {
|
||||||
fontLib_->SetFileFontHandle(call.savedV0);
|
FontLib *fontLib = fontLibList[fontLibID_];
|
||||||
|
fontLib->SetFileFontHandle(call.savedV0);
|
||||||
}
|
}
|
||||||
|
|
||||||
FontLib *GetFontLib(u32 handle) {
|
FontLib *GetFontLib(u32 handle) {
|
||||||
if (fontLibMap.find(handle) != fontLibMap.end()) {
|
if (fontLibMap.find(handle) != fontLibMap.end()) {
|
||||||
return fontLibMap[handle];
|
return fontLibList[fontLibMap[handle]];
|
||||||
} else {
|
} else {
|
||||||
ERROR_LOG(HLE, "No fontlib with handle %08x", handle);
|
ERROR_LOG(HLE, "No fontlib with handle %08x", handle);
|
||||||
return 0;
|
return 0;
|
||||||
@ -463,9 +481,10 @@ void __FontShutdown() {
|
|||||||
fontLib->CloseFont(iter->second);
|
fontLib->CloseFont(iter->second);
|
||||||
}
|
}
|
||||||
fontMap.clear();
|
fontMap.clear();
|
||||||
for (auto iter = fontLibMap.begin(); iter != fontLibMap.end(); iter++) {
|
for (auto iter = fontLibList.begin(); iter != fontLibList.end(); iter++) {
|
||||||
delete iter->second;
|
delete *iter;
|
||||||
}
|
}
|
||||||
|
fontLibList.clear();
|
||||||
fontLibMap.clear();
|
fontLibMap.clear();
|
||||||
for (auto iter = internalFonts.begin(); iter != internalFonts.end(); ++iter) {
|
for (auto iter = internalFonts.begin(); iter != internalFonts.end(); ++iter) {
|
||||||
delete *iter;
|
delete *iter;
|
||||||
@ -474,7 +493,9 @@ void __FontShutdown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void __FontDoState(PointerWrap &p) {
|
void __FontDoState(PointerWrap &p) {
|
||||||
// TODO: Needs much work.
|
p.Do(fontLibList);
|
||||||
|
p.Do(fontLibMap);
|
||||||
|
// TODO: p.Do(fontMap);
|
||||||
|
|
||||||
p.Do(actionPostAllocCallback);
|
p.Do(actionPostAllocCallback);
|
||||||
__KernelRestoreActionType(actionPostAllocCallback, PostAllocCallback::Create);
|
__KernelRestoreActionType(actionPostAllocCallback, PostAllocCallback::Create);
|
||||||
@ -490,6 +511,7 @@ u32 sceFontNewLib(u32 paramPtr, u32 errorCodePtr) {
|
|||||||
Memory::Write_U32(0, errorCodePtr);
|
Memory::Write_U32(0, errorCodePtr);
|
||||||
|
|
||||||
FontLib *newLib = new FontLib(paramPtr);
|
FontLib *newLib = new FontLib(paramPtr);
|
||||||
|
fontLibList.push_back(newLib);
|
||||||
// The game should never see this value, the return value is replaced
|
// The game should never see this value, the return value is replaced
|
||||||
// by the action. Except if we disable the alloc, in this case we return
|
// by the action. Except if we disable the alloc, in this case we return
|
||||||
// the handle correctly here.
|
// the handle correctly here.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user