mirror of
https://github.com/JaCzekanski/Avocado.git
synced 2024-06-02 19:27:41 -04:00
system: single file .psf loader
This commit is contained in:
parent
c63bd427d3
commit
7ac2600855
7563
externals/miniz/miniz.c
vendored
Normal file
7563
externals/miniz/miniz.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
1328
externals/miniz/miniz.h
vendored
Normal file
1328
externals/miniz/miniz.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
26
premake5.lua
26
premake5.lua
|
@ -134,6 +134,18 @@ project "glad"
|
|||
"externals/glad/src/*.c",
|
||||
}
|
||||
|
||||
project "miniz"
|
||||
uuid "4D28CBE8-3092-4400-B67B-FD51FCAFBD34"
|
||||
kind "StaticLib"
|
||||
language "c"
|
||||
location "build/libs/miniz"
|
||||
includedirs {
|
||||
"externals/miniz"
|
||||
}
|
||||
files {
|
||||
"externals/miniz/*.c",
|
||||
}
|
||||
|
||||
project "imgui"
|
||||
uuid "a8f18b69-f15a-4804-80f7-e8f80ab91369"
|
||||
kind "StaticLib"
|
||||
|
@ -152,10 +164,15 @@ project "common"
|
|||
kind "StaticLib"
|
||||
location "build/libs/common"
|
||||
|
||||
dependson {
|
||||
"miniz"
|
||||
}
|
||||
|
||||
includedirs {
|
||||
"src",
|
||||
"externals/glm",
|
||||
"externals/json/include"
|
||||
"externals/json/include",
|
||||
"externals/miniz"
|
||||
}
|
||||
|
||||
files {
|
||||
|
@ -169,6 +186,10 @@ project "common"
|
|||
"src/platform/**.*"
|
||||
}
|
||||
|
||||
links {
|
||||
"miniz"
|
||||
}
|
||||
|
||||
filter "system:windows"
|
||||
defines "WIN32"
|
||||
|
||||
|
@ -196,7 +217,8 @@ project "avocado"
|
|||
}
|
||||
|
||||
links {
|
||||
"common"
|
||||
"common",
|
||||
"miniz"
|
||||
}
|
||||
|
||||
filter "system:windows"
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include "utils/cue/cueParser.h"
|
||||
#include "utils/file.h"
|
||||
#include "utils/string.h"
|
||||
#include "utils/psf.h"
|
||||
#include "version.h"
|
||||
#include "sound/sound.h"
|
||||
#include "bios/exe_bootstrap.h"
|
||||
|
@ -164,6 +165,11 @@ void loadFile(std::unique_ptr<System>& sys, std::string path) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (ext == "psf" || ext == "minipsf" || ext=="psflib") {
|
||||
loadPsf(sys.get(), path);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ext == "exe" || ext == "psexe") {
|
||||
loadExe(path);
|
||||
return;
|
||||
|
|
|
@ -362,11 +362,13 @@ void System::softReset() {
|
|||
state = State::run;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool System::loadExeFile(const std::vector<uint8_t>& _exe) {
|
||||
PsxExe exe;
|
||||
if (_exe.empty()) return false;
|
||||
assert(_exe.size() >= 0x800);
|
||||
|
||||
PsxExe exe;
|
||||
memcpy(&exe, _exe.data(), sizeof(exe));
|
||||
|
||||
if (exe.t_size > _exe.size() - 0x800) {
|
||||
|
|
|
@ -135,4 +135,4 @@ struct System {
|
|||
|
||||
std::vector<IO_LOG_ENTRY> ioLogList;
|
||||
#endif
|
||||
};
|
||||
};
|
||||
|
|
71
src/utils/psf.cpp
Normal file
71
src/utils/psf.cpp
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "psf.h"
|
||||
#include "miniz.h"
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
uint32_t read_u32(const std::vector<uint8_t>& vec, size_t offset) {
|
||||
if (offset+4 > vec.size()) return 0;
|
||||
|
||||
uint32_t ret = 0;
|
||||
ret |= vec[offset];
|
||||
ret |= vec[offset+1] << 8;
|
||||
ret |= vec[offset+2] << 16;
|
||||
ret |= vec[offset+3] << 24;
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool loadPsf(System* sys, const std::string& path) {
|
||||
std::string ext = getExtension(path);
|
||||
transform(ext.begin(), ext.end(), ext.begin(), tolower);
|
||||
|
||||
if (ext != "psf" && ext != "minipsf" && ext != "psflib") {
|
||||
printf("[PSF] .psf and .minipsf extensions are supported.\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto file = getFileContents(path);
|
||||
if (file.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file.size() < 16 || memcmp("PSF\x01", file.data(), 4) != 0) {
|
||||
printf("[PSF] Invalid header\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
auto reservedArea = read_u32(file, 4);
|
||||
auto compressedSize = read_u32(file, 8);
|
||||
|
||||
std::vector<uint8_t> exe;
|
||||
size_t exeSize = 2*1024*1024;
|
||||
exe.resize(exeSize);
|
||||
|
||||
mz_uncompress(exe.data(), &exeSize, file.data()+16, compressedSize);
|
||||
|
||||
exe.resize(exeSize);
|
||||
|
||||
auto tagOffset = 16 + compressedSize;
|
||||
if (file.size() < tagOffset + 5 || memcmp("[TAG]", file.data() + tagOffset, 5) != 0) {
|
||||
return true;
|
||||
} else {
|
||||
std::string tags;
|
||||
tags.assign(file.begin() + tagOffset + 5, file.end());
|
||||
|
||||
std::stringstream stream;
|
||||
stream.str(tags);
|
||||
|
||||
std::string line;
|
||||
while (std::getline(stream, line)) {
|
||||
if (line.rfind("_lib", 0) == 0) {
|
||||
// Load libs
|
||||
}
|
||||
|
||||
printf("[PSF]%s\n", line.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
putFileContents("dump.exe" ,exe);
|
||||
sys->loadExeFile(exe);
|
||||
|
||||
return true;
|
||||
}
|
4
src/utils/psf.h
Normal file
4
src/utils/psf.h
Normal file
|
@ -0,0 +1,4 @@
|
|||
#pragma once
|
||||
#include "system.h"
|
||||
|
||||
bool loadPsf(System* sys, const std::string& file);
|
Loading…
Reference in a new issue