aboutsummaryrefslogtreecommitdiff
path: root/libpsn00b
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2021-10-15 09:22:45 +0800
committerGitHub <noreply@github.com>2021-10-15 09:22:45 +0800
commitdd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch)
treed848d6ce007d8bb9357c8b99d6a0a39ec41d244e /libpsn00b
parent9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff)
parenteb719a424e6a16fb64209139a32c9f8a7235a929 (diff)
downloadpsn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'libpsn00b')
-rw-r--r--libpsn00b/CMakeLists.txt69
-rw-r--r--libpsn00b/cmake/internal_setup.cmake161
-rw-r--r--libpsn00b/cmake/sdk.cmake89
-rw-r--r--libpsn00b/cmake/virtual_targets.cmake109
-rw-r--r--libpsn00b/include/dlfcn.h2
-rw-r--r--libpsn00b/include/lzp/lzp.h223
-rw-r--r--libpsn00b/include/lzp/lzqlp.h31
-rw-r--r--libpsn00b/libc/makefile61
-rw-r--r--libpsn00b/lzp/bit.c2
-rw-r--r--libpsn00b/lzp/bit.h2
-rw-r--r--libpsn00b/lzp/compress.c10
-rw-r--r--libpsn00b/lzp/crc.c12
-rw-r--r--libpsn00b/lzp/lzp.c32
-rw-r--r--libpsn00b/lzp/lzp.h18
-rw-r--r--libpsn00b/lzp/lzqlp.h23
-rw-r--r--libpsn00b/lzp/makefile59
-rw-r--r--libpsn00b/lzp/qlp.c24
-rw-r--r--libpsn00b/makefile23
-rw-r--r--libpsn00b/psxapi/makefile61
-rw-r--r--libpsn00b/psxcd/makefile59
-rw-r--r--libpsn00b/psxetc/dl.c2
-rw-r--r--libpsn00b/psxetc/makefile59
-rw-r--r--libpsn00b/psxgpu/makefile59
-rw-r--r--libpsn00b/psxgte/makefile59
-rw-r--r--libpsn00b/psxsio/makefile59
-rw-r--r--libpsn00b/psxspu/makefile59
-rw-r--r--libpsn00b/readme.txt2
27 files changed, 749 insertions, 620 deletions
diff --git a/libpsn00b/CMakeLists.txt b/libpsn00b/CMakeLists.txt
new file mode 100644
index 0000000..52914d3
--- /dev/null
+++ b/libpsn00b/CMakeLists.txt
@@ -0,0 +1,69 @@
+# libpsn00b build script
+# (C) 2021 spicyjpeg - MPL licensed
+
+cmake_minimum_required(VERSION 3.21)
+
+# ${PROJECT_SOURCE_DIR} is not available until project() is called.
+set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/cmake/sdk.cmake)
+
+project(
+ libpsn00b
+ LANGUAGES C CXX ASM
+ DESCRIPTION "PSn00bSDK libraries"
+ HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
+)
+
+if(NOT DEFINED PSN00BSDK_LIBGCC)
+ message(FATAL_ERROR "Failed to obtain information about the GCC toolchain. Check your toolchain settings.")
+elseif(PSN00BSDK_LIBGCC STREQUAL "PSN00BSDK_LIBGCC-NOTFOUND")
+ message(FATAL_ERROR "Failed to find libgcc in the GCC toolchain's files. Check your toolchain settings, or set the path to libgcc using -DPSN00BSDK_LIBGCC.")
+endif()
+
+## Libraries
+
+foreach(_library IN LISTS PSN00BSDK_LIBRARIES)
+ # libc needs special handling due to the different directory name.
+ if(${_library} STREQUAL "c")
+ set(_path ${PROJECT_SOURCE_DIR}/libc)
+ else()
+ set(_path ${PROJECT_SOURCE_DIR}/${_library})
+ endif()
+
+ file(
+ GLOB_RECURSE _sources
+ ${_path}/*.s
+ ${_path}/*.c
+ ${_path}/*.cpp
+ ${_path}/*.cxx
+ )
+
+ psn00bsdk_add_library(${_library} STATIC ${_sources})
+endforeach()
+
+# Extract libgcc's contents and merge them into libc after building.
+add_custom_command(
+ TARGET c POST_BUILD
+ COMMAND ${CMAKE_AR} x ${PSN00BSDK_LIBGCC}
+ COMMAND ${CMAKE_AR} rsuU $<TARGET_FILE:c> *.o
+ COMMENT "Merging libgcc contents into SDK libc"
+)
+
+## Installation
+
+install(
+ TARGETS ${PSN00BSDK_LIBRARIES} ${PSN00BSDK_VIRTUAL_TARGETS}
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
+ EXPORT libpsn00b
+)
+install(
+ DIRECTORY cmake include ldscripts
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b
+)
+
+# Generate an import script, which will be used by the setup script to find the
+# libraries.
+install(
+ EXPORT libpsn00b
+ DESTINATION ${CMAKE_INSTALL_LIBDIR}/libpsn00b/cmake
+ #EXPORT_LINK_INTERFACE_LIBRARIES
+)
diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake
new file mode 100644
index 0000000..e3d4be7
--- /dev/null
+++ b/libpsn00b/cmake/internal_setup.cmake
@@ -0,0 +1,161 @@
+# PSn00bSDK internal setup script for CMake
+# (C) 2021 spicyjpeg - MPL licensed
+
+# This script is included automatically when using the toolchain file and
+# defines helper functions.
+
+cmake_minimum_required(VERSION 3.21)
+include(GNUInstallDirs)
+
+# IMPORTANT TODO: set a version number
+set(PSN00BSDK_VERSION 0.1.0)
+
+## Settings (can be overridden by projects)
+
+set(PSN00BSDK_EXECUTABLE_SUFFIX ".exe")
+set(PSN00BSDK_SHARED_LIBRARY_SUFFIX ".dll")
+set(PSN00BSDK_SYMBOL_MAP_SUFFIX ".map")
+
+## SDK libraries
+
+# DON'T CHANGE THE ORDER or you'll break the libraries' internal dependencies.
+set(PSN00BSDK_LIBRARIES psxgpu psxgte psxspu psxcd psxsio psxetc psxapi lzp c)
+
+include(${CMAKE_CURRENT_LIST_DIR}/libpsn00b.cmake OPTIONAL)
+if(NOT TARGET psn00bsdk_common)
+ include(${CMAKE_CURRENT_LIST_DIR}/virtual_targets.cmake)
+endif()
+
+# Use the toolchain path to find libgcc (used to build libpsn00b). Of course
+# different installers, packages and distros have different opinions when it
+# comes to deciding where to install toolchains, so we have to bruteforce
+# multiple combinations of paths.
+if(CMAKE_C_COMPILER_VERSION)
+ string(REGEX MATCH "^([0-9]+)\." _dummy ${CMAKE_C_COMPILER_VERSION})
+
+ find_library(
+ PSN00BSDK_LIBGCC gcc
+ HINTS
+ ${PSN00BSDK_TC}/lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
+ ${PSN00BSDK_TC}/lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
+ ${PSN00BSDK_TC}/lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
+ ${PSN00BSDK_TC}/lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
+ ${PSN00BSDK_TC}/../lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
+ ${PSN00BSDK_TC}/../lib/gcc-cross/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
+ ${PSN00BSDK_TC}/../lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_C_COMPILER_VERSION}
+ ${PSN00BSDK_TC}/../lib/gcc/${PSN00BSDK_TARGET}/${CMAKE_MATCH_1}
+ NO_DEFAULT_PATH
+ DOC "Path to libgcc (bundled with the GCC toolchain)"
+ )
+endif()
+
+## Tools
+
+set(
+ PSN00BSDK_TOOLS
+ ${CMAKE_CURRENT_LIST_DIR}/../../../${CMAKE_INSTALL_BINDIR}
+ ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}
+)
+
+find_program(ELF2X elf2x HINTS ${PSN00BSDK_TOOLS})
+find_program(ELF2CPE elf2cpe HINTS ${PSN00BSDK_TOOLS})
+find_program(SMXLINK elf2x HINTS ${PSN00BSDK_TOOLS})
+find_program(LZPACK lzpack HINTS ${PSN00BSDK_TOOLS})
+find_program(MKPSXISO mkpsxiso HINTS ${PSN00BSDK_TOOLS})
+
+## Helper functions for executables
+
+set(PSN00BSDK_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/../include)
+set(PSN00BSDK_LDSCRIPTS ${CMAKE_CURRENT_LIST_DIR}/../ldscripts)
+
+# psn00bsdk_add_executable(
+# <target name> <STATIC|DYNAMIC>
+# [EXCLUDE_FROM_ALL]
+# <sources> ...
+# )
+function(psn00bsdk_add_executable name type)
+ string(TOLOWER ${type} _type)
+ if(NOT ${_type} MATCHES "^(static|dynamic)$")
+ message(FATAL_ERROR "Invalid executable type: ${type} (must be STATIC or DYNAMIC)")
+ endif()
+
+ add_executable (${name} ${ARGN})
+ target_link_libraries(${name} psn00bsdk_${_type}_exe)
+ set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".elf")
+ target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/exe.ld)
+
+ target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE})
+
+ # Add post-build steps to generate the .exe and symbol map once the
+ # executable is built. CMake 3.21 added support for target-dependent
+ # generator expressions (catchy name lol) in add_custom_command(), so I'm
+ # making heavy use of those here.
+ add_custom_command(
+ TARGET ${name} POST_BUILD
+ COMMAND ${ELF2X} -q ${name}.elf ${name}${PSN00BSDK_EXECUTABLE_SUFFIX}
+ COMMAND ${TOOLCHAIN_NM} -f posix -l -n ${name}.elf $<ANGLE-R>${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX}
+ BYPRODUCTS ${name}${PSN00BSDK_EXECUTABLE_SUFFIX} ${name}${PSN00BSDK_SYMBOL_MAP_SUFFIX}
+ )
+endfunction()
+
+# psn00bsdk_add_library(
+# <target name> <STATIC|SHARED|MODULE>
+# [EXCLUDE_FROM_ALL]
+# <sources> ...
+# )
+# Note that SHARED and MODULE have the same meaning (both will create a DLL).
+# SDK libraries are NOT statically linked in by default; if you need to link
+# something, use target_link_libraries() manually.
+function(psn00bsdk_add_library name type)
+ string(TOUPPER ${type} _type_upper)
+ string(TOLOWER ${type} _type)
+ if(NOT ${_type} MATCHES "^(static|object|shared|module)$")
+ message(FATAL_ERROR "Invalid library type: ${type} (must be STATIC, OBJECT, SHARED or MODULE)")
+ endif()
+
+ add_library (${name} ${_type_upper} ${ARGN})
+ target_link_libraries(${name} psn00bsdk_${_type}_lib)
+
+ target_include_directories(${name} PRIVATE ${PSN00BSDK_INCLUDE})
+
+ if(${_type} MATCHES "^(shared|module)$")
+ set_target_properties(${name} PROPERTIES PREFIX "" SUFFIX ".so")
+ target_link_options (${name} PRIVATE -T${PSN00BSDK_LDSCRIPTS}/dll.ld)
+
+ # Add a post-build step to dump the DLL's raw contents into a new file
+ # separate from the built ELF.
+ add_custom_command(
+ TARGET ${name} POST_BUILD
+ COMMAND ${CMAKE_OBJCOPY} -O binary ${name}.so ${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX}
+ BYPRODUCTS ${name}${PSN00BSDK_SHARED_LIBRARY_SUFFIX}
+ )
+ else()
+ set_target_properties(${name} PROPERTIES PREFIX "lib" SUFFIX ".a")
+
+ # Remove virtual target dependencies to make sure linking against the
+ # library does not also propagate static library flags.
+ set_target_properties(${name} PROPERTIES INTERFACE_LINK_LIBRARIES "")
+ endif()
+endfunction()
+
+# psn00bsdk_add_cd_image(
+# <target name>
+# <image file name>
+# <mkpsxiso config template>
+# [DEPENDS <dependencies> ...]
+# [additional options passed to add_custom_target()]
+# )
+function(psn00bsdk_add_cd_image name image_name config_file)
+ set(CD_IMAGE_NAME ${image_name})
+ configure_file(${config_file} _gen_${config_file})
+
+ add_custom_target(
+ ${name} ALL
+ COMMAND ${MKPSXISO} -y -q _gen_${config_file}
+ BYPRODUCTS ${image_name}.bin ${image_name}.cue
+ COMMENT "Building CD image ${image_name}"
+ ${ARGN}
+ )
+endfunction()
+
+## Helper functions for assets (TODO)
diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake
new file mode 100644
index 0000000..4c2f330
--- /dev/null
+++ b/libpsn00b/cmake/sdk.cmake
@@ -0,0 +1,89 @@
+# PSn00bSDK toolchain setup file for CMake
+# (C) 2021 spicyjpeg - MPL licensed
+
+cmake_minimum_required(VERSION 3.21)
+
+set(
+ PSN00BSDK_TC $ENV{PSN00BSDK_TC}
+ CACHE PATH "Path to the GCC toolchain's installation directory"
+)
+set(
+ PSN00BSDK_TARGET mipsel-unknown-elf
+ CACHE STRING "GCC toolchain target triplet"
+)
+
+## CMake configuration
+
+set(CMAKE_SYSTEM_NAME PlayStation)
+set(CMAKE_SYSTEM_PROCESSOR mipsel)
+
+set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
+set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
+set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
+#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
+
+# Tell CMake not to run the linker when compiling test programs, and to pass
+# toolchain settings to the generated test projects. This dodges missing C++
+# standard library errors.
+set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
+set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES PSN00BSDK_TC PSN00BSDK_TARGET)
+
+## Toolchain path setup
+
+# Attempt to find GCC using a list of common installation locations.
+# PSN00BSDK_TC can be left unset if the toolchain can be found in any of these
+# or in the PATH environment variable.
+find_program(
+ _gcc ${PSN00BSDK_TARGET}-gcc
+ HINTS
+ ${PSN00BSDK_TC}/bin
+ ${PSN00BSDK_TC}/../bin
+ # Same as ${CMAKE_INSTALL_PREFIX}/${PSN00BSDK_TARGET}/bin
+ ${CMAKE_CURRENT_LIST_DIR}/../../../${PSN00BSDK_TARGET}/bin
+ PATHS
+ "C:/Program Files/${PSN00BSDK_TARGET}/bin"
+ "C:/Program Files (x86)/${PSN00BSDK_TARGET}/bin"
+ "C:/${PSN00BSDK_TARGET}/bin"
+ /opt/${PSN00BSDK_TARGET}/bin
+ /usr/local/${PSN00BSDK_TARGET}/bin
+ /usr/${PSN00BSDK_TARGET}/bin
+ NO_CACHE REQUIRED
+)
+cmake_path(GET _gcc PARENT_PATH _bin)
+cmake_path(GET _bin PARENT_PATH _toolchain)
+
+# Overwrite the empty cache entry, so it won't have to be found again.
+if(NOT IS_DIRECTORY PSN00BSDK_TC)
+ set(
+ PSN00BSDK_TC ${_toolchain}
+ CACHE PATH "Path to the GCC toolchain's installation directory"
+ FORCE
+ )
+endif()
+
+## Toolchain executables
+
+# ${CMAKE_EXECUTABLE_SUFFIX} seems not to work in toolchain scripts, so we
+# can't rely on it to determine the host OS extension for executables. The best
+# workaround I found is to extract the extension from the path returned by
+# find_program() using a regex.
+set(_prefix ${_bin}/${PSN00BSDK_TARGET})
+string(REGEX MATCH ".+-gcc(.*)$" _dummy ${_gcc})
+
+set(CMAKE_ASM_COMPILER ${_prefix}-gcc${CMAKE_MATCH_1})
+set(CMAKE_C_COMPILER ${_prefix}-gcc${CMAKE_MATCH_1})
+set(CMAKE_CXX_COMPILER ${_prefix}-g++${CMAKE_MATCH_1})
+set(CMAKE_AR ${_prefix}-ar${CMAKE_MATCH_1})
+set(CMAKE_LINKER ${_prefix}-ld${CMAKE_MATCH_1})
+set(CMAKE_RANLIB ${_prefix}-ranlib${CMAKE_MATCH_1})
+set(CMAKE_OBJCOPY ${_prefix}-objcopy${CMAKE_MATCH_1})
+set(CMAKE_SIZE ${_prefix}-size${CMAKE_MATCH_1})
+set(CMAKE_STRIP ${_prefix}-strip${CMAKE_MATCH_1})
+set(TOOLCHAIN_NM ${_prefix}-nm${CMAKE_MATCH_1})
+
+## SDK setup
+
+# We can't set up the SDK here as the find_*() functions may fail if they are
+# called before project(). We can however set a script to be executed right
+# after project() is invoked.
+set(CMAKE_PROJECT_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/internal_setup.cmake)
diff --git a/libpsn00b/cmake/virtual_targets.cmake b/libpsn00b/cmake/virtual_targets.cmake
new file mode 100644
index 0000000..df1df79
--- /dev/null
+++ b/libpsn00b/cmake/virtual_targets.cmake
@@ -0,0 +1,109 @@
+# libpsn00b interface targets
+# (C) 2021 spicyjpeg - MPL licensed
+
+# This script creates several "virtual" targets (psn00bsdk_*) that set include
+# directories and compiler flags when a target is linked against them. These
+# all end up in the autogenerated libpsn00b setup script after installation,
+# so this file is only included when building libpsn00b.
+
+# The following targets are currently defined:
+# - psn00bsdk_common
+# - psn00bsdk_object_lib (same as psn00bsdk_common)
+# - psn00bsdk_static_exe
+# - psn00bsdk_dynamic_exe
+# - psn00bsdk_static_lib
+# - psn00bsdk_shared_lib
+# - psn00bsdk_module_lib (same as psn00bsdk_shared_lib)
+
+include(GNUInstallDirs)
+
+set(PSN00BSDK_VIRTUAL_TARGETS "")
+
+macro(_add_interface_target name)
+ add_library(${name} INTERFACE)
+ list(APPEND PSN00BSDK_VIRTUAL_TARGETS ${name})
+
+ target_compile_options(
+ ${name} INTERFACE
+ ${_aflags}
+ $<$<COMPILE_LANGUAGE:C,CXX>:${_cflags}>
+ $<$<COMPILE_LANGUAGE:CXX>:${_cxxflags}>
+ )
+ target_link_options (${name} INTERFACE ${_ldflags})
+ target_link_libraries(${name} INTERFACE ${ARGN})
+endmacro()
+
+macro(_add_alias_target name)
+ #add_library(${name} ALIAS ${ARGN})
+ add_library(${name} INTERFACE)
+ list(APPEND PSN00BSDK_VIRTUAL_TARGETS ${name})
+
+ target_link_libraries(${name} INTERFACE ${ARGN})
+endmacro()
+
+# Options common to all target types:
+# - Define PLAYSTATION=1 and set include directories
+# - Optimize for MIPS R3000
+# - Inject zero checks into division operations (will throw breaks)
+# - All standard libraries (including libgcc) disabled
+# - Put all symbols into separate sections when building
+# - C++ features that require runtime support disabled
+# - Unused section stripping enabled
+set(_aflags -msoft-float -march=r3000 -mtune=r3000 -mabi=32)
+set(_cflags -mdivide-breaks -O2 -ffreestanding -fno-builtin -nostdlib -fdata-sections -ffunction-sections -fsigned-char -fno-strict-overflow -fdiagnostics-color=always)
+set(_cxxflags -fno-exceptions -fno-rtti -fno-unwind-tables -fno-threadsafe-statics -fno-use-cxa-atexit)
+set(_ldflags -nostdlib -Wl,-gc-sections)
+
+_add_interface_target(psn00bsdk_common)
+_add_alias_target (psn00bsdk_object_lib psn00bsdk_common)
+
+target_compile_definitions(
+ psn00bsdk_common INTERFACE
+ PLAYSTATION=1
+ $<$<CONFIG:DEBUG>:DEBUG=1>
+)
+
+# Options for executables without support for dynamic linking:
+# - Position-independent code disabled
+# - GP-relative addressing enabled only for local symbols
+# - ABI-compatible calls disabled (incompatible with GP-relative addr)
+set(_aflags -G8)
+set(_cflags -mno-abicalls -mgpopt -mno-extern-sdata)
+set(_cxxflags)
+set(_ldflags -G8 -static)
+
+_add_interface_target(psn00bsdk_static_exe psn00bsdk_common ${PSN00BSDK_LIBRARIES})
+
+# Options for executables with support for dynamic linking:
+# - Position-independent code disabled
+# - GP-relative addressing disabled
+# - ABI-compatible calls disabled (must be performed manually)
+set(_aflags -G0)
+set(_cflags -mno-abicalls -mno-gpopt)
+set(_cxxflags)
+set(_ldflags -G0 -static)
+
+_add_interface_target(psn00bsdk_dynamic_exe psn00bsdk_common ${PSN00BSDK_LIBRARIES})
+
+# Options for static libraries:
+# - GP-relative addressing disabled
+# - ABI-compatible calls disabled
+# - Local stripping enabled
+set(_aflags -G0 -Wa,--strip-local-absolute)
+set(_cflags -mno-abicalls -mno-gpopt)
+set(_cxxflags)
+set(_ldflags)
+
+_add_interface_target(psn00bsdk_static_lib psn00bsdk_common)
+
+# Options for dynamically-loaded libraries:
+# - Position-independent code enabled
+# - GP-relative addressing disabled (incompatible with ABI calls)
+# - ABI-compatible calls enabled
+set(_aflags -G0)
+set(_cflags -mabicalls -mshared -mno-gpopt -fPIC)
+set(_cxxflags)
+set(_ldflags -G0 -shared)
+
+_add_interface_target(psn00bsdk_shared_lib psn00bsdk_common)
+_add_alias_target (psn00bsdk_module_lib psn00bsdk_shared_lib)
diff --git a/libpsn00b/include/dlfcn.h b/libpsn00b/include/dlfcn.h
index 5fdd343..0c51821 100644
--- a/libpsn00b/include/dlfcn.h
+++ b/libpsn00b/include/dlfcn.h
@@ -119,7 +119,7 @@ void DL_SetResolveCallback(void *(*callback)(DLL *, const char *));
*
* The third argument specifies when symbols in the DLL should be resolved.
* Setting it to RTLD_LAZY defers resolution of undefined functions to when
- * they are first called, while RTLD_DEFAULT forces all symbols to be resolved
+ * they are first called, while RTLD_NOW forces all symbols to be resolved
* immediately. If a custom resolver has been set via DL_SetResolveCallback(),
* it will be called for each symbol to resolve.
*
diff --git a/libpsn00b/include/lzp/lzp.h b/libpsn00b/include/lzp/lzp.h
new file mode 100644
index 0000000..cfeeb72
--- /dev/null
+++ b/libpsn00b/include/lzp/lzp.h
@@ -0,0 +1,223 @@
+/*! \file lzp.h
+ * \brief Main library header
+ */
+
+/*! \mainpage
+ * \version 0.20b
+ * \author John Wilbert 'Lameguy64' Villamor
+ *
+ * \section creditsSection Credits
+ * - LZ77 data compression/decompression routines based from Ilya Muravyov's
+ * crush.cpp released under public domain. Refined and ported to C by Lameguy64.
+ * - CRC calculation routines based from Lammert Bies' lib_crc routines.
+ *
+ */
+
+#ifndef _LZPACK_H
+#define _LZPACK_H
+
+#include <sys/types.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+/*! \addtogroup crcBaseRemainders CRC Base Remainder Values
+ * @{
+ */
+//! Initial remainder value for lzCRC16()
+#define LZP_CRC16_REMAINDER 0x0000
+//! Initial remainder value for lzCRC32()
+#define LZP_CRC32_REMAINDER 0xFFFFFFFF
+/*! @} */
+
+
+/*! \addtogroup compLevels Compression Levels
+ * \brief Compression levels for the lzCompress() function.
+ * @{
+ */
+//! Minimal (but fast) compression
+#define LZP_COMPRESS_FAST 0
+//! Normal compression level
+#define LZP_COMPRESS_NORMAL 1
+//! Maximum compression level
+#define LZP_COMPRESS_MAX 2
+/*! @} */
+
+
+/*! \addtogroup libraryErrorCodes Library Error Codes
+ * @{
+ */
+//! No error
+#define LZP_ERR_NONE 0
+//! Decompression error
+#define LZP_ERR_DECOMPRESS -1
+//! Not a valid LZP/QLP/PCK archive
+#define LZP_ERR_INVALID_PACK -2
+//! File not found
+#define LZP_ERR_NOTFOUND -3
+//! CRC check mismatch (data corruption)
+#define LZP_ERR_CRC_MISMATCH -4
+/*! @} */
+
+
+//! Header structure of an LZP format archive file
+typedef struct {
+
+ //! File ID (must always be 'LZP')
+ char id[3];
+ //! File count
+ u_char numFiles;
+
+} LZP_HEAD;
+
+//! File entry structure for an LZP format archive file
+typedef struct {
+
+ //! File name
+ char fileName[16];
+ //! CRC32 checksum of file
+ u_int crc;
+ //! Original size of file in bytes
+ u_int fileSize;
+ //! Compressed size of file
+ u_int packedSize;
+ //! File data offset
+ u_int offset;
+
+} LZP_FILE;
+
+
+// Function prototypes
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/*! \addtogroup compressFuncs Data Compression and Decompression Functions
+ * \brief Functions to compress and decompress data.
+ * @{
+ */
+
+/*! Compress a block of data.
+ *
+ * \details This function compresses a specified block of data in LZ77 encoding.
+ * Depending on the size of the input data and speed of the computer, compression
+ * may take a while to complete.
+ *
+ * \param[out] *outBuff Pointer to buffer to store compressed data.
+ * \param[in] *inBuff Pointer to data to compress.
+ * \param[in] inSize Size of data to compress in bytes.
+ * \param[in] level Compression level (see \ref compLevels).
+ *
+ * \returns The size of the compressed data in bytes.
+ */
+int lzCompress(void* outBuff, const void* inBuff, int inSize, int level);
+
+/*! Decompress a compressed block of data.
+ *
+ * \details Decompressed a compressed block of data produced by lzCompress(). It cannot
+ * return the decompressed size of the data ahead of time so you must preserve the decompressed
+ * size of the data yourself.
+ *
+ * \note The decompression algorithm used in this function is completely independent
+ * of the compression settings set by lzSetHashSizes() before compressing the data with
+ * lzCompress().
+ *
+ * \param[out] *outBuff Pointer to buffer to store decompressed data.
+ * \param[in] *inBuff Pointer to compressed data to decompress.
+ * \param[in] inSize Compressed data size in bytes.
+ *
+ * \returns Size of decompressed data in bytes or LZP_ERR_DECOMPRESS if a
+ * decompression error occurred.
+ */
+int lzDecompress(void* outBuff, const void* inBuff, int inSize);
+
+int lzDecompressLen(void* outBuff, int outSize, const void* inBuff, int inSize);
+
+/*! Sets the sizes of hash tables for data compression.
+ *
+ * \param[in] window Sliding window size.
+ * \param[in] hash1 Hash table 1 size.
+ * \param[in] hash2 Hash table 2 size.
+ */
+void lzSetHashSizes(int window, int hash1, int hash2);
+
+/*! Reset the sizes of hash tables to their defaults.
+ */
+void lzResetHashSizes();
+
+/*! @} */
+
+
+/*! \addtogroup crcFuncs CRC Hashing Functions
+ * \brief Functions to calculate CRC hashes of data.
+ * @{
+ */
+
+/*! Calculates a CRC16 hash of the specified buffer.
+ *
+ * \param[in] *buff Pointer to buffer to calculate a hash of.
+ * \param[in] bytes Size of buffer in bytes.
+ * \param[in] crc CRC remainder (use LZP_CRC16_REMAINDER).
+ *
+ * \returns CRC16 hash of specified buffer.
+ */
+unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc);
+
+/*! Calculates a CRC32 hash of the specified buffer.
+ *
+ * \param[in] *buff Pointer to buffer to calculate a hash of.
+ * \param[in] bytes Size of buffer in bytes.
+ * \param[in] crc CRC remainder (use LZP_CRC16_REMAINDER).
+ *
+ * \returns CRC32 hash of specified buffer.
+ */
+unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc);
+
+/*! @} */
+
+
+/*! \addtogroup lzpFunctions LZP Archive Handling Routines
+ * \brief Functions to index and unpack files from LZP archives.
+ * @{
+ */
+
+/*! Searches for a file by name in an LZP archive and returns a file entry number.
+ *
+ * \param[in] *fileName String of file to search (must be less than 13 characters).
+ * \param[in] *lzpack Pointer to LZP archive file.
+ *
+ * \returns File index of found file or one of \ref libraryErrorCodes if an error occurred.
+ */
+int lzpSearchFile(const char* fileName, const LZP_HEAD* lzpack);
+
+int lzpFileSize(const LZP_HEAD* lzpack, int fileNum);
+
+/*! Get a pointer to a file entry inside of an LZP archive.
+ *
+ * \param[in] *lzpack Pointer to LZP archive file.
+ * \param[in] fileNum File number to get an entry of (you may use lzpSearchFile()).
+ *
+ * \returns A pointer to an LZP_FILE struct or NULL if an error occurred.
+ */
+const LZP_FILE* lzpFileEntry(const LZP_HEAD* lzpack, int fileNum);
+
+/*! Unpacks a file from an LZP archive to the specified memory buffer.
+ *
+ * \param[in] *buff Pointer to buffer to store unpacked file.
+ * \param[in] *lzpack Pointer to LZP archive file.
+ * \param[in] fileNum File entry number of file to extract (you may use lzpSearchFile()).
+ *
+ * \returns Size of decompressed file in bytes or one of \ref libraryErrorCodes if an error occurred.
+ */
+int lzpUnpackFile(void* buff, const LZP_HEAD* lzpack, int fileNum);
+
+/*! @} */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // _LZPACK_H
diff --git a/libpsn00b/include/lzp/lzqlp.h b/libpsn00b/include/lzp/lzqlp.h
new file mode 100644
index 0000000..5b70b40
--- /dev/null
+++ b/libpsn00b/include/lzp/lzqlp.h
@@ -0,0 +1,31 @@
+#ifndef _QLP_H
+#define _QLP_H
+
+#include <sys/types.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
+#define PACK_ERR_NONE 0
+#define PACK_ERR_INVALID -1
+#define PACK_ERR_NOTFOUND -2
+#define PACK_ERR_INCOMPLETE -3
+#define PACK_ERR_READ_FAULT -4
+
+typedef struct {
+ char id[3];
+ u_char numfiles;
+} QLP_HEAD;
+
+typedef struct {
+ char name[16];
+ u_int size;
+ u_int offs;
+} QLP_FILE;
+
+int qlpFileCount(const QLP_HEAD* qlpfile);
+const QLP_FILE* qlpFileEntry(int index, const QLP_HEAD* qlpfile);
+const void* qlpFileAddr(int index, const QLP_HEAD* qlpfile);
+int qlpFindFile(char* fileName, const QLP_HEAD* qlpfile);
+
+#endif // _QLP_H \ No newline at end of file
diff --git a/libpsn00b/libc/makefile b/libpsn00b/libc/makefile
deleted file mode 100644
index bb3a687..0000000
--- a/libpsn00b/libc/makefile
+++ /dev/null
@@ -1,61 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libc.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- # "Import" libgcc's contents
- cp $(GCC_BASE)/lib/gcc/$(PREFIX)/$(GCC_VERSION)/libgcc.a ./$@
- $(AR) rs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/lzp/bit.c b/libpsn00b/lzp/bit.c
index aefa45d..9678357 100644
--- a/libpsn00b/lzp/bit.c
+++ b/libpsn00b/lzp/bit.c
@@ -3,7 +3,7 @@
// Bit I/O
//
-unsigned char* inPtr = 0;
+const unsigned char* inPtr = 0;
int inBytes = 0;
unsigned char* outPtr = 0;
int outBytes = 0;
diff --git a/libpsn00b/lzp/bit.h b/libpsn00b/lzp/bit.h
index ff71025..321160a 100644
--- a/libpsn00b/lzp/bit.h
+++ b/libpsn00b/lzp/bit.h
@@ -1,7 +1,7 @@
#ifndef _LZP_BIT_H
#define _LZP_BIT_H
-extern unsigned char* inPtr;
+extern const unsigned char* inPtr;
extern int inBytes;
extern unsigned char* outPtr;
extern int outBytes;
diff --git a/libpsn00b/lzp/compress.c b/libpsn00b/lzp/compress.c
index 5f2b78c..5969dd6 100644
--- a/libpsn00b/lzp/compress.c
+++ b/libpsn00b/lzp/compress.c
@@ -107,7 +107,7 @@ int get_penalty(int a, int b) {
}
-int lzCompress(void* outBuff, void* inBuff, int inSize, int level) {
+int lzCompress(void* outBuff, const void* inBuff, int inSize, int level) {
#if LZP_USE_MALLOC == FALSE
int head[HASH1_SIZE+HASH2_SIZE];
@@ -347,7 +347,7 @@ void lzResetHashSizes() {
#endif // LZP_NO_COMPRESS
-int lzDecompress(void* outBuff, void* inBuff, int inSize) {
+int lzDecompress(void* outBuff, const void* inBuff, int inSize) {
int p=0;
int len;
@@ -355,7 +355,7 @@ int lzDecompress(void* outBuff, void* inBuff, int inSize) {
int s;
int windowSize;
- inPtr = (unsigned char*)inBuff;
+ inPtr = (const unsigned char*)inBuff;
outPtr = (unsigned char*)outBuff;
inBytes = 0;
outBytes = 0;
@@ -408,7 +408,7 @@ int lzDecompress(void* outBuff, void* inBuff, int inSize) {
}
-int lzDecompressLen(void* outBuff, int outSize, void* inBuff, int inSize) {
+int lzDecompressLen(void* outBuff, int outSize, const void* inBuff, int inSize) {
int p=0;
int len;
@@ -416,7 +416,7 @@ int lzDecompressLen(void* outBuff, int outSize, void* inBuff, int inSize) {
int s;
int windowSize;
- inPtr = (unsigned char*)inBuff;
+ inPtr = (const unsigned char*)inBuff;
outPtr = (unsigned char*)outBuff;
inBytes = 0;
outBytes = 0;
diff --git a/libpsn00b/lzp/crc.c b/libpsn00b/lzp/crc.c
index c5ab702..3c1ae57 100644
--- a/libpsn00b/lzp/crc.c
+++ b/libpsn00b/lzp/crc.c
@@ -49,7 +49,7 @@ void initTable32(unsigned int* table) {
}
-unsigned short lzCRC16(void* buff, int bytes, unsigned short crc) {
+unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc) {
int i;
unsigned short tmp, short_c;
@@ -59,7 +59,7 @@ unsigned short lzCRC16(void* buff, int bytes, unsigned short crc) {
for(i=0; i<bytes; i++) {
- short_c = 0x00ff & (unsigned short)((unsigned char*)buff)[i];
+ short_c = 0x00ff & (unsigned short)((const unsigned char*)buff)[i];
tmp = crc ^ short_c;
crc = (crc >> 8) ^ crcTable[tmp&0xff];
@@ -70,12 +70,12 @@ unsigned short lzCRC16(void* buff, int bytes, unsigned short crc) {
}
-unsigned int lzCRC32(void* buff, int bytes, unsigned int crc) {
+unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc) {
int i;
- unsigned char* byteBuff = (unsigned char*)buff;
- unsigned int byte;
- unsigned int crcTable[256];
+ const unsigned char* byteBuff = (const unsigned char*)buff;
+ unsigned int byte;
+ unsigned int crcTable[256];
initTable32(crcTable);
diff --git a/libpsn00b/lzp/lzp.c b/libpsn00b/lzp/lzp.c
index 1f4fea4..9f2da48 100644
--- a/libpsn00b/lzp/lzp.c
+++ b/libpsn00b/lzp/lzp.c
@@ -17,7 +17,7 @@ static char* lcase(char* text) {
}
-int lzpSearchFile(const char* fileName, void* lzpack) {
+int lzpSearchFile(const char* fileName, const LZP_HEAD* lzpack) {
int i;
char searchName[16];
@@ -27,8 +27,8 @@ int lzpSearchFile(const char* fileName, void* lzpack) {
strcpy(searchName, fileName);
lcase(searchName);
- fileEntry = (LZP_FILE*)(lzpack+4);
- for(i=0; i<((LZP_HEAD*)lzpack)->numFiles; i++) {
+ fileEntry = (LZP_FILE*)(((const char*)lzpack)+sizeof(LZP_HEAD));
+ for(i=0; i<(lzpack->numFiles); i++) {
strcpy(compareName, fileEntry[i].fileName);
lcase(compareName);
@@ -42,44 +42,44 @@ int lzpSearchFile(const char* fileName, void* lzpack) {
}
-LZP_FILE* lzpFileEntry(void* lzpack, int fileNum) {
+const LZP_FILE* lzpFileEntry(const LZP_HEAD* lzpack, int fileNum) {
- if (strncmp("LZP", ((LZP_HEAD*)lzpack)->id, 3) != 0)
+ if (strncmp("LZP", lzpack->id, 3) != 0)
return(NULL);
- if ((fileNum < 0) || (fileNum > (((LZP_HEAD*)lzpack)->numFiles-1)))
+ if ((fileNum < 0) || (fileNum > (lzpack->numFiles-1)))
return(NULL);
- return(&((LZP_FILE*)(lzpack+4))[fileNum]);
+ return &((LZP_FILE*)(((const char*)lzpack)+sizeof(LZP_HEAD)))[fileNum];
}
-int lzpFileSize(void* lzpack, int fileNum) {
+int lzpFileSize(const LZP_HEAD* lzpack, int fileNum) {
- if (strncmp("LZP", ((LZP_HEAD*)lzpack)->id, 3) != 0)
+ if (strncmp("LZP", lzpack->id, 3) != 0)
return 0;
- if ((fileNum < 0) || (fileNum > (((LZP_HEAD*)lzpack)->numFiles-1)))
+ if ((fileNum < 0) || (fileNum > (lzpack->numFiles-1)))
return 0;
- return ((LZP_FILE*)(lzpack+4))[fileNum].fileSize;
+ return ((LZP_FILE*)(((const char*)lzpack)+sizeof(LZP_HEAD)))[fileNum].fileSize;
}
-int lzpUnpackFile(void* buff, void* lzpack, int fileNum) {
+int lzpUnpackFile(void* buff, const LZP_HEAD* lzpack, int fileNum) {
- LZP_FILE* fileEntry = &((LZP_FILE*)(lzpack+4))[fileNum];
+ LZP_FILE* fileEntry = &((LZP_FILE*)(((const char*)lzpack)+sizeof(LZP_HEAD)))[fileNum];
int unpackedSize;
// Check ID header
- if (strncmp("LZP", ((LZP_HEAD*)lzpack)->id, 3) != 0)
+ if (strncmp("LZP", lzpack->id, 3) != 0)
return(LZP_ERR_INVALID_PACK);
// Do a CRC16 check of the compressed data's integrity
- if (lzCRC32(lzpack+fileEntry->offset, fileEntry->packedSize, LZP_CRC32_REMAINDER) != fileEntry->crc)
+ if (lzCRC32(((const char*)lzpack)+fileEntry->offset, fileEntry->packedSize, LZP_CRC32_REMAINDER) != fileEntry->crc)
return(LZP_ERR_CRC_MISMATCH);
// Decompress data to the specified address
- unpackedSize = lzDecompress(buff, lzpack+fileEntry->offset, fileEntry->packedSize);
+ unpackedSize = lzDecompress(buff, ((const char*)lzpack)+fileEntry->offset, fileEntry->packedSize);
if (unpackedSize < 0)
return(unpackedSize);
diff --git a/libpsn00b/lzp/lzp.h b/libpsn00b/lzp/lzp.h
index ffd7933..cfeeb72 100644
--- a/libpsn00b/lzp/lzp.h
+++ b/libpsn00b/lzp/lzp.h
@@ -111,7 +111,7 @@ extern "C" {
*
* \returns The size of the compressed data in bytes.
*/
-int lzCompress(void* outBuff, void* inBuff, int inSize, int level);
+int lzCompress(void* outBuff, const void* inBuff, int inSize, int level);
/*! Decompress a compressed block of data.
*
@@ -130,9 +130,9 @@ int lzCompress(void* outBuff, void* inBuff, int inSize, int level);
* \returns Size of decompressed data in bytes or LZP_ERR_DECOMPRESS if a
* decompression error occurred.
*/
-int lzDecompress(void* outBuff, void* inBuff, int inSize);
+int lzDecompress(void* outBuff, const void* inBuff, int inSize);
-int lzDecompressLen(void* outBuff, int outSize, void* inBuff, int inSize);
+int lzDecompressLen(void* outBuff, int outSize, const void* inBuff, int inSize);
/*! Sets the sizes of hash tables for data compression.
*
@@ -162,7 +162,7 @@ void lzResetHashSizes();
*
* \returns CRC16 hash of specified buffer.
*/
-unsigned short lzCRC16(void* buff, int bytes, unsigned short crc);
+unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc);
/*! Calculates a CRC32 hash of the specified buffer.
*
@@ -172,7 +172,7 @@ unsigned short lzCRC16(void* buff, int bytes, unsigned short crc);
*
* \returns CRC32 hash of specified buffer.
*/
-unsigned int lzCRC32(void* buff, int bytes, unsigned int crc);
+unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc);
/*! @} */
@@ -189,9 +189,9 @@ unsigned int lzCRC32(void* buff, int bytes, unsigned int crc);
*
* \returns File index of found file or one of \ref libraryErrorCodes if an error occurred.
*/
-int lzpSearchFile(const char* fileName, void* lzpack);
+int lzpSearchFile(const char* fileName, const LZP_HEAD* lzpack);
-int lzpFileSize(void* lzpack, int fileNum);
+int lzpFileSize(const LZP_HEAD* lzpack, int fileNum);
/*! Get a pointer to a file entry inside of an LZP archive.
*
@@ -200,7 +200,7 @@ int lzpFileSize(void* lzpack, int fileNum);
*
* \returns A pointer to an LZP_FILE struct or NULL if an error occurred.
*/
-LZP_FILE* lzpFileEntry(void* lzpack, int fileNum);
+const LZP_FILE* lzpFileEntry(const LZP_HEAD* lzpack, int fileNum);
/*! Unpacks a file from an LZP archive to the specified memory buffer.
*
@@ -210,7 +210,7 @@ LZP_FILE* lzpFileEntry(void* lzpack, int fileNum);
*
* \returns Size of decompressed file in bytes or one of \ref libraryErrorCodes if an error occurred.
*/
-int lzpUnpackFile(void* buff, void* lzpack, int fileNum);
+int lzpUnpackFile(void* buff, const LZP_HEAD* lzpack, int fileNum);
/*! @} */
diff --git a/libpsn00b/lzp/lzqlp.h b/libpsn00b/lzp/lzqlp.h
index fae6438..5b70b40 100644
--- a/libpsn00b/lzp/lzqlp.h
+++ b/libpsn00b/lzp/lzqlp.h
@@ -1,6 +1,11 @@
#ifndef _QLP_H
#define _QLP_H
+#include <sys/types.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
#define PACK_ERR_NONE 0
#define PACK_ERR_INVALID -1
#define PACK_ERR_NOTFOUND -2
@@ -8,19 +13,19 @@
#define PACK_ERR_READ_FAULT -4
typedef struct {
- char id[3];
- unsigned char numfiles;
+ char id[3];
+ u_char numfiles;
} QLP_HEAD;
typedef struct {
- char name[16];
- unsigned int size;
- unsigned int offs;
+ char name[16];
+ u_int size;
+ u_int offs;
} QLP_FILE;
-int qlpFileCount(void* qlpfile);
-QLP_FILE* qlpFileEntry(int index, void* qlpfile);
-void* qlpFileAddr(int index, void* qlpfile);
-int qlpFindFile(char* fileName, void* qlpfile);
+int qlpFileCount(const QLP_HEAD* qlpfile);
+const QLP_FILE* qlpFileEntry(int index, const QLP_HEAD* qlpfile);
+const void* qlpFileAddr(int index, const QLP_HEAD* qlpfile);
+int qlpFindFile(char* fileName, const QLP_HEAD* qlpfile);
#endif // _QLP_H \ No newline at end of file
diff --git a/libpsn00b/lzp/makefile b/libpsn00b/lzp/makefile
deleted file mode 100644
index 02654ed..0000000
--- a/libpsn00b/lzp/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = liblzp.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/lzp/qlp.c b/libpsn00b/lzp/qlp.c
index 3be8356..e54f99f 100644
--- a/libpsn00b/lzp/qlp.c
+++ b/libpsn00b/lzp/qlp.c
@@ -14,34 +14,34 @@ static char* lcase(char* str) {
}
-int qlpFileCount(void* qlpfile) {
+int qlpFileCount(const QLP_HEAD* qlpfile) {
- if (strncmp(((QLP_HEAD*)qlpfile)->id, "QLP", 3) != 0)
+ if (strncmp(qlpfile->id, "QLP", 3) != 0)
return(PACK_ERR_INVALID);
- return(((QLP_HEAD*)qlpfile)->numfiles);
+ return(qlpfile->numfiles);
}
-QLP_FILE* qlpFileEntry(int index, void* qlpfile) {
+const QLP_FILE* qlpFileEntry(int index, const QLP_HEAD* qlpfile) {
- if (strncmp(((QLP_HEAD*)qlpfile)->id, "QLP", 3) != 0)
+ if (strncmp(qlpfile->id, "QLP", 3) != 0)
return(NULL);
- if (index > ((QLP_HEAD*)qlpfile)->numfiles)
+ if (index > qlpfile->numfiles)
return(NULL);
- return(&((QLP_FILE*)(qlpfile+4))[index]);
+ return(&((QLP_FILE*)(((const char*)qlpfile)+sizeof(QLP_HEAD)))[index]);
}
-void* qlpFileAddr(int index, void* qlpfile) {
+const void* qlpFileAddr(int index, const QLP_HEAD* qlpfile) {
- return( qlpfile+((QLP_FILE*)(qlpfile+4))[index].offs );
+ return( ((const char*)qlpfile)+((QLP_FILE*)(((const char*)qlpfile)+sizeof(QLP_HEAD)))[index].offs );
}
-int qlpFindFile(char* fileName, void* qlpfile) {
+int qlpFindFile(char* fileName, const QLP_HEAD* qlpfile) {
int i;
char nameBuff[2][16];
@@ -49,9 +49,9 @@ int qlpFindFile(char* fileName, void* qlpfile) {
strcpy(nameBuff[0], fileName);
lcase(nameBuff[0]);
- for(i=0; i<((QLP_HEAD*)qlpfile)->numfiles; i++) {
+ for(i=0; i<(qlpfile->numfiles); i++) {
- strcpy(nameBuff[1], ((QLP_FILE*)(qlpfile+4))[i].name);
+ strcpy(nameBuff[1], ((QLP_FILE*)(((const char*)qlpfile)+sizeof(QLP_HEAD)))[i].name);
lcase(nameBuff[1]);
if (strcmp(nameBuff[0], nameBuff[1]) == 0)
diff --git a/libpsn00b/makefile b/libpsn00b/makefile
deleted file mode 100644
index c2cf62f..0000000
--- a/libpsn00b/makefile
+++ /dev/null
@@ -1,23 +0,0 @@
-# Run using make (Linux) or gmake (BSD)
-# Part of the PSn00bSDK Project
-# 2019 - 2020 Lameguy64 / Meido-Tek Productions
-
-TOPTARGETS = all clean
-
-LIBS = libc psxgpu psxapi psxgte psxcd psxetc psxsio psxspu lzp
-
-$(TOPTARGETS): $(LIBS)
-
-install: $(LIBS)
-ifdef PSN00BSDK_LIBS
-ifneq ($(CURDIR),$(PSN00BSDK_LIBS)) # needs a better method
- cp -R include $(PSN00BSDK_LIBS)/include
-endif
-endif
-
-clean: $(LIBS)
-
-$(LIBS):
- @$(MAKE) -C $@ $(MAKECMDGOALS)
-
-.PHONY: $(TOPTARGETS) $(LIBS)
diff --git a/libpsn00b/psxapi/makefile b/libpsn00b/psxapi/makefile
deleted file mode 100644
index f300e5f..0000000
--- a/libpsn00b/psxapi/makefile
+++ /dev/null
@@ -1,61 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxapi.a
-
-## Files
-
-SOURCES = stdio fs sys
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.c))
-CXXFILES= $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.cxx))
-AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxcd/makefile b/libpsn00b/psxcd/makefile
deleted file mode 100644
index ee9b958..0000000
--- a/libpsn00b/psxcd/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxcd.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c
index 1485183..e405efc 100644
--- a/libpsn00b/psxetc/dl.c
+++ b/libpsn00b/psxetc/dl.c
@@ -35,7 +35,7 @@
/* Compile options */
// Uncomment before building to enable debug logging (via printf()).
-#define DEBUG
+//#define DEBUG
// Comment before building to disable functions that rely on BIOS file APIs,
// i.e. DL_LoadSymbolMap() and dlopen().
diff --git a/libpsn00b/psxetc/makefile b/libpsn00b/psxetc/makefile
deleted file mode 100644
index 84bb64b..0000000
--- a/libpsn00b/psxetc/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxetc.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxgpu/makefile b/libpsn00b/psxgpu/makefile
deleted file mode 100644
index adcb7fa..0000000
--- a/libpsn00b/psxgpu/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxgpu.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxgte/makefile b/libpsn00b/psxgte/makefile
deleted file mode 100644
index e60ff1e..0000000
--- a/libpsn00b/psxgte/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxgte.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxsio/makefile b/libpsn00b/psxsio/makefile
deleted file mode 100644
index c9dcade..0000000
--- a/libpsn00b/psxsio/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxsio.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/psxspu/makefile b/libpsn00b/psxspu/makefile
deleted file mode 100644
index 5710f39..0000000
--- a/libpsn00b/psxspu/makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# PSn00bSDK library makefile
-# Part of the PSn00bSDK Project
-# 2019 - 2021 Lameguy64 / Meido-Tek Productions
-
-## Settings
-
-PSN00BSDK_LIBS ?= ..
-
-include ../../psn00bsdk-setup.mk
-
-# Project target name
-TARGET = libpsxspu.a
-
-## Files
-
-# Searches for C, C++ and S (assembler) files in local directory
-CFILES = $(notdir $(wildcard *.c))
-CXXFILES= $(notdir $(wildcard *.cxx))
-AFILES = $(notdir $(wildcard *.s))
-
-# Create names for object files
-OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
- $(addprefix build/,$(CXXFILES:.cxx=.o)) \
- $(addprefix build/,$(AFILES:.s=.o))
-
-# Project specific includes and libraries
-# (use -I for include dirs, -L for library dirs, -l for static libraries)
-INCLUDE +=
-LIBDIRS +=
-LIBS +=
-
-## Build rules
-
-all: build/$(TARGET)
-
-build/$(TARGET): $(OFILES)
- @mkdir -p $(dir $@)
- $(AR) crs $@ $(OFILES)
-
-build/%.o: %.c
- @mkdir -p $(dir $@)
- $(CC) $(CFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.cxx
- @mkdir -p $(dir $@)
- $(CXX) $(CPPFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-build/%.o: %.s
- @mkdir -p $(dir $@)
- $(CC) $(AFLAGS_LIB) $(INCLUDE) -c $< -o $@
-
-install:
-ifneq ($(PSN00BSDK_LIBS), "..")
- @mkdir -p $(PSN00BSDK_LIBS)
-endif
- cp build/$(TARGET) $(PSN00BSDK_LIBS)/$(TARGET)
-
-clean:
- rm -rf build
diff --git a/libpsn00b/readme.txt b/libpsn00b/readme.txt
index 940746c..9f6ebc6 100644
--- a/libpsn00b/readme.txt
+++ b/libpsn00b/readme.txt
@@ -49,7 +49,7 @@ Brief summary of libraries:
must be covered in the changelog.txt file.
-Compiling:
+Compiling (OUTDATED):
To compile the LibPSn00b libraries, you will first need a working GCC
toolchain which you can either build yourself as described in the