From 7cf54f48113b77a4d7b21d5858ec98862195b2a6 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Sun, 12 Sep 2021 19:39:12 +0200 Subject: Migrated examples to CMake --- examples/CMakeLists.txt | 25 +++++++ examples/beginner/cppdemo/CMakeLists.txt | 22 ++++++ examples/beginner/cppdemo/makefile | 65 ----------------- examples/beginner/hello/CMakeLists.txt | 22 ++++++ examples/beginner/hello/makefile | 65 ----------------- examples/cdrom/cdbrowse/CMakeLists.txt | 27 +++++++ examples/cdrom/cdbrowse/iso.xml | 12 ++-- examples/cdrom/cdbrowse/makefile | 65 ----------------- examples/cdrom/cdxa/CMakeLists.txt | 29 ++++++++ examples/cdrom/cdxa/iso.xml | 14 ++-- examples/cdrom/cdxa/makefile | 65 ----------------- examples/demos/n00bdemo/CMakeLists.txt | 50 +++++++++++++ examples/demos/n00bdemo/data.s | 31 -------- examples/demos/n00bdemo/data.s.template | 31 ++++++++ examples/demos/n00bdemo/data.xml | 49 ------------- examples/demos/n00bdemo/data.xml.template | 49 +++++++++++++ examples/demos/n00bdemo/logo.c | 2 +- examples/demos/n00bdemo/main.c | 4 +- examples/demos/n00bdemo/makefile | 65 ----------------- examples/graphics/balls/CMakeLists.txt | 22 ++++++ examples/graphics/balls/makefile | 65 ----------------- examples/graphics/billboard/CMakeLists.txt | 28 ++++++++ examples/graphics/billboard/makefile | 65 ----------------- examples/graphics/billboard/tim.s | 7 -- examples/graphics/billboard/tim.s.template | 6 ++ examples/graphics/fpscam/CMakeLists.txt | 22 ++++++ examples/graphics/fpscam/makefile | 65 ----------------- examples/graphics/gte/CMakeLists.txt | 22 ++++++ examples/graphics/gte/makefile | 65 ----------------- examples/graphics/hdtv/CMakeLists.txt | 22 ++++++ examples/graphics/hdtv/makefile | 65 ----------------- examples/graphics/render2tex/CMakeLists.txt | 28 ++++++++ examples/graphics/render2tex/makefile | 65 ----------------- examples/graphics/render2tex/texture.s | 9 --- examples/graphics/render2tex/texture.s.template | 8 +++ examples/graphics/rgb24/CMakeLists.txt | 28 ++++++++ examples/graphics/rgb24/makefile | 65 ----------------- examples/graphics/rgb24/tim.s | 7 -- examples/graphics/rgb24/tim.s.template | 6 ++ examples/makefile | 34 --------- examples/system/childexec/CMakeLists.txt | 34 +++++++++ examples/system/childexec/child_exe.s | 6 -- examples/system/childexec/child_exe.s.template | 6 ++ examples/system/childexec/makefile | 93 ------------------------ examples/system/console/CMakeLists.txt | 22 ++++++ examples/system/console/makefile | 65 ----------------- examples/system/dynlink/CMakeLists.txt | 32 +++++++++ examples/system/dynlink/iso.xml | 16 ++--- examples/system/dynlink/makefile | 95 ------------------------- examples/system/timer/CMakeLists.txt | 22 ++++++ examples/system/timer/makefile | 65 ----------------- examples/system/tty/CMakeLists.txt | 22 ++++++ examples/system/tty/makefile | 65 ----------------- 53 files changed, 609 insertions(+), 1330 deletions(-) create mode 100644 examples/CMakeLists.txt create mode 100644 examples/beginner/cppdemo/CMakeLists.txt delete mode 100644 examples/beginner/cppdemo/makefile create mode 100644 examples/beginner/hello/CMakeLists.txt delete mode 100644 examples/beginner/hello/makefile create mode 100644 examples/cdrom/cdbrowse/CMakeLists.txt delete mode 100644 examples/cdrom/cdbrowse/makefile create mode 100644 examples/cdrom/cdxa/CMakeLists.txt delete mode 100644 examples/cdrom/cdxa/makefile create mode 100644 examples/demos/n00bdemo/CMakeLists.txt delete mode 100644 examples/demos/n00bdemo/data.s create mode 100644 examples/demos/n00bdemo/data.s.template delete mode 100644 examples/demos/n00bdemo/data.xml create mode 100644 examples/demos/n00bdemo/data.xml.template delete mode 100644 examples/demos/n00bdemo/makefile create mode 100644 examples/graphics/balls/CMakeLists.txt delete mode 100644 examples/graphics/balls/makefile create mode 100644 examples/graphics/billboard/CMakeLists.txt delete mode 100644 examples/graphics/billboard/makefile delete mode 100644 examples/graphics/billboard/tim.s create mode 100644 examples/graphics/billboard/tim.s.template create mode 100644 examples/graphics/fpscam/CMakeLists.txt delete mode 100644 examples/graphics/fpscam/makefile create mode 100644 examples/graphics/gte/CMakeLists.txt delete mode 100644 examples/graphics/gte/makefile create mode 100644 examples/graphics/hdtv/CMakeLists.txt delete mode 100644 examples/graphics/hdtv/makefile create mode 100644 examples/graphics/render2tex/CMakeLists.txt delete mode 100644 examples/graphics/render2tex/makefile delete mode 100644 examples/graphics/render2tex/texture.s create mode 100644 examples/graphics/render2tex/texture.s.template create mode 100644 examples/graphics/rgb24/CMakeLists.txt delete mode 100644 examples/graphics/rgb24/makefile delete mode 100644 examples/graphics/rgb24/tim.s create mode 100644 examples/graphics/rgb24/tim.s.template delete mode 100644 examples/makefile create mode 100644 examples/system/childexec/CMakeLists.txt delete mode 100644 examples/system/childexec/child_exe.s create mode 100644 examples/system/childexec/child_exe.s.template delete mode 100644 examples/system/childexec/makefile create mode 100644 examples/system/console/CMakeLists.txt delete mode 100644 examples/system/console/makefile create mode 100644 examples/system/dynlink/CMakeLists.txt delete mode 100644 examples/system/dynlink/makefile create mode 100644 examples/system/timer/CMakeLists.txt delete mode 100644 examples/system/timer/makefile create mode 100644 examples/system/tty/CMakeLists.txt delete mode 100644 examples/system/tty/makefile (limited to 'examples') diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..7cd7e98 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,25 @@ +# PSn00bSDK examples build script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +project( + PSn00bSDK-examples + LANGUAGES NONE + DESCRIPTION "PSn00bSDK examples" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file( + GLOB_RECURSE _examples + ${PROJECT_SOURCE_DIR}/CMakeLists.txt +) + +foreach(_script IN LISTS _examples) + cmake_path(GET _script PARENT_PATH _dir) + if(_dir STREQUAL PROJECT_SOURCE_DIR) + continue() + endif() + + add_subdirectory(${_dir}) +endforeach() diff --git a/examples/beginner/cppdemo/CMakeLists.txt b/examples/beginner/cppdemo/CMakeLists.txt new file mode 100644 index 0000000..83f0f0a --- /dev/null +++ b/examples/beginner/cppdemo/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + cppdemo + LANGUAGES CXX + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK basic C++ example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.cpp) +psn00bsdk_add_executable(cppdemo STATIC ${_sources}) +#psn00bsdk_add_cd_image(cppdemo_iso cppdemo iso.xml DEPENDS cppdemo) + +install(FILES ${PROJECT_BINARY_DIR}/cppdemo.exe DESTINATION .) diff --git a/examples/beginner/cppdemo/makefile b/examples/beginner/cppdemo/makefile deleted file mode 100644 index 630a280..0000000 --- a/examples/beginner/cppdemo/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = cppdemo - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/beginner/hello/CMakeLists.txt b/examples/beginner/hello/CMakeLists.txt new file mode 100644 index 0000000..40e30b0 --- /dev/null +++ b/examples/beginner/hello/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + hello + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK hello world example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(hello STATIC ${_sources}) +#psn00bsdk_add_cd_image(hello_iso hello iso.xml DEPENDS hello) + +install(FILES ${PROJECT_BINARY_DIR}/hello.exe DESTINATION .) diff --git a/examples/beginner/hello/makefile b/examples/beginner/hello/makefile deleted file mode 100644 index e4bed20..0000000 --- a/examples/beginner/hello/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = hello - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt new file mode 100644 index 0000000..6eb4cbb --- /dev/null +++ b/examples/cdrom/cdbrowse/CMakeLists.txt @@ -0,0 +1,27 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + cdbrowse + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK CD file browser example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(cdbrowse STATIC ${_sources}) +psn00bsdk_add_cd_image(cdbrowse_iso cdbrowse iso.xml DEPENDS cdbrowse) + +install( + FILES + ${PROJECT_BINARY_DIR}/cdbrowse.bin + ${PROJECT_BINARY_DIR}/cdbrowse.cue + DESTINATION . +) diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml index 5d8963d..5ffca18 100644 --- a/examples/cdrom/cdbrowse/iso.xml +++ b/examples/cdrom/cdbrowse/iso.xml @@ -1,7 +1,7 @@ - - - + + + diff --git a/examples/cdrom/cdbrowse/makefile b/examples/cdrom/cdbrowse/makefile deleted file mode 100644 index 954408b..0000000 --- a/examples/cdrom/cdbrowse/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = cdbrowse - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -#all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt new file mode 100644 index 0000000..b0c8d90 --- /dev/null +++ b/examples/cdrom/cdxa/CMakeLists.txt @@ -0,0 +1,29 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + cdxa + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK CD-XA playback example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +# TODO: add rules to actually generate a valid .XA file +file(GLOB _sources *.c) +psn00bsdk_add_executable(cdxa STATIC ${_sources}) +#psn00bsdk_add_cd_image(cdxa_iso cdxa iso.xml DEPENDS cdxa) + +install( + FILES + #${PROJECT_BINARY_DIR}/cdxa.bin + #${PROJECT_BINARY_DIR}/cdxa.cue + ${PROJECT_BINARY_DIR}/cdxa.exe + DESTINATION . +) diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml index 9a6a206..b98a16f 100644 --- a/examples/cdrom/cdxa/iso.xml +++ b/examples/cdrom/cdxa/iso.xml @@ -1,7 +1,7 @@ - - - + + + - + diff --git a/examples/cdrom/cdxa/makefile b/examples/cdrom/cdxa/makefile deleted file mode 100644 index b1627f7..0000000 --- a/examples/cdrom/cdxa/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = cdxa - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/demos/n00bdemo/CMakeLists.txt b/examples/demos/n00bdemo/CMakeLists.txt new file mode 100644 index 0000000..0b51beb --- /dev/null +++ b/examples/demos/n00bdemo/CMakeLists.txt @@ -0,0 +1,50 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + n00bdemo + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "n00bdemo (PSn00bSDK demo)" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +set(DATA_DIR ${PROJECT_SOURCE_DIR}/data) + +configure_file(data.s.template data.s) +configure_file(data.xml.template data.xml) + +# Add a build step to pack assets into a single .LZP file. This archive is then +# embedded into the binary through data.s, which is in turn generated from +# data.s.template. Note that, since we specify dependencies, CMake can detect +# when source assets are edited and rebuild the archive automatically. +file(GLOB _assets ${DATA_DIR}/*.tim ${DATA_DIR}/*.smd) +add_custom_command( + COMMAND ${LZPACK} -y data.xml + OUTPUT data.lzp + BYPRODUCTS textures.qlp + DEPENDS ${_assets} + COMMENT "Building LZP archive" +) + +file(GLOB _sources *.s *.c) +psn00bsdk_add_executable( + n00bdemo STATIC + ${_sources} + ${PROJECT_BINARY_DIR}/data.s +) +target_include_directories(n00bdemo PRIVATE ${PROJECT_SOURCE_DIR}) +#psn00bsdk_add_cd_image(n00bdemo_iso n00bdemo iso.xml DEPENDS n00bdemo) + +# Ensure data.lzp is built before the executable. Due to CMake's limitations we +# actually have to wrap it in a dummy target. +add_custom_target(n00bdemo_data DEPENDS data.lzp) +add_dependencies(n00bdemo n00bdemo_data) + +install(FILES ${PROJECT_BINARY_DIR}/n00bdemo.exe DESTINATION .) diff --git a/examples/demos/n00bdemo/data.s b/examples/demos/n00bdemo/data.s deleted file mode 100644 index f3b2a83..0000000 --- a/examples/demos/n00bdemo/data.s +++ /dev/null @@ -1,31 +0,0 @@ -.section .data - -.global lz_resources -.type lz_resources, @object -lz_resources: - .incbin "build/data.lzp" - -#.global smd_mtekdisk -#.type smd_mtekdisk, @object -#smd_mtekdisk: -# .incbin "data/mtekdisk.smd" - -#.global smd_mtektext -#.type smd_mtektext, @object -#smd_mtektext: -# .incbin "data/mtektext.smd" - -#.global smd_star -#.type smd_star, @object -#smd_star: -# .incbin "data/star.smd" - -#.global smd_psn00b -#.type smd_psn00b, @object -#smd_psn00b: -# .incbin "data/psn00blogo.smd" - -#.global smd_scarletlogo -#.type smd_scarletlogo, @object -#smd_scarletlogo: -# .incbin "data/scarletlogo.smd" \ No newline at end of file diff --git a/examples/demos/n00bdemo/data.s.template b/examples/demos/n00bdemo/data.s.template new file mode 100644 index 0000000..a7237cd --- /dev/null +++ b/examples/demos/n00bdemo/data.s.template @@ -0,0 +1,31 @@ +.section .data + +.global lz_resources +.type lz_resources, @object +lz_resources: + .incbin "${PROJECT_BINARY_DIR}/data.lzp" + +#.global smd_mtekdisk +#.type smd_mtekdisk, @object +#smd_mtekdisk: +# .incbin "data/mtekdisk.smd" + +#.global smd_mtektext +#.type smd_mtektext, @object +#smd_mtektext: +# .incbin "data/mtektext.smd" + +#.global smd_star +#.type smd_star, @object +#smd_star: +# .incbin "data/star.smd" + +#.global smd_psn00b +#.type smd_psn00b, @object +#smd_psn00b: +# .incbin "data/psn00blogo.smd" + +#.global smd_scarletlogo +#.type smd_scarletlogo, @object +#smd_scarletlogo: +# .incbin "data/scarletlogo.smd" \ No newline at end of file diff --git a/examples/demos/n00bdemo/data.xml b/examples/demos/n00bdemo/data.xml deleted file mode 100644 index 6761f16..0000000 --- a/examples/demos/n00bdemo/data.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - data/petscum16c.tim - data/bungirl.tim - - - data/clktower.tim - data/riftbld1.tim - data/riftbld2.tim - data/hatkid.tim - - data/celmapi.tim - - data/lamelotl16c.tim - data/n00blogo-pixel.tim - data/font.tim - - - - - - - data/mtekdisk.smd - data/mtektext.smd - data/star.smd - data/psn00blogo.smd - data/logo.smd - - - data/petscum.smd - data/bulb.smd - - - data/bungirl.smd - - data/star_mask.smd - data/timerift.smd - data/rbowshade.smd - - data/hatkid.smd - - - build/textures.qlp - - - - \ No newline at end of file diff --git a/examples/demos/n00bdemo/data.xml.template b/examples/demos/n00bdemo/data.xml.template new file mode 100644 index 0000000..057d6a6 --- /dev/null +++ b/examples/demos/n00bdemo/data.xml.template @@ -0,0 +1,49 @@ + + + + + ${DATA_DIR}/petscum16c.tim + ${DATA_DIR}/bungirl.tim + + + ${DATA_DIR}/clktower.tim + ${DATA_DIR}/riftbld1.tim + ${DATA_DIR}/riftbld2.tim + ${DATA_DIR}/hatkid.tim + + ${DATA_DIR}/celmapi.tim + + ${DATA_DIR}/lamelotl16c.tim + ${DATA_DIR}/n00blogo-pixel.tim + ${DATA_DIR}/font.tim + + + + + + + ${DATA_DIR}/mtekdisk.smd + ${DATA_DIR}/mtektext.smd + ${DATA_DIR}/star.smd + ${DATA_DIR}/psn00blogo.smd + ${DATA_DIR}/logo.smd + + + ${DATA_DIR}/petscum.smd + ${DATA_DIR}/bulb.smd + + + ${DATA_DIR}/bungirl.smd + + ${DATA_DIR}/star_mask.smd + ${DATA_DIR}/timerift.smd + ${DATA_DIR}/rbowshade.smd + + ${DATA_DIR}/hatkid.smd + + + textures.qlp + + + + \ No newline at end of file diff --git a/examples/demos/n00bdemo/logo.c b/examples/demos/n00bdemo/logo.c index 2cebf6b..d10b5b4 100644 --- a/examples/demos/n00bdemo/logo.c +++ b/examples/demos/n00bdemo/logo.c @@ -7,7 +7,7 @@ #include #include "malloc.h" #include "smd.h" -#include "lzp.h" +#include #include "disp.h" #include "data.h" diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index 623d8cc..fcd38b8 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include "malloc.h" #include "smd.h" diff --git a/examples/demos/n00bdemo/makefile b/examples/demos/n00bdemo/makefile deleted file mode 100644 index 9206e09..0000000 --- a/examples/demos/n00bdemo/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = demo - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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 += -llzp - -## Build rules - -#all: iso -all: build/$(TARGET) - -iso: build/$(TARGET) - $(MKPSXISO) -y -q iso.xml - -resources: - $(LZPACK) data.xml - touch data.s - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s resources - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt new file mode 100644 index 0000000..b063425 --- /dev/null +++ b/examples/graphics/balls/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + balls + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK sprites example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(balls STATIC ${_sources}) +#psn00bsdk_add_cd_image(balls_iso balls iso.xml DEPENDS balls) + +install(FILES ${PROJECT_BINARY_DIR}/balls.exe DESTINATION .) diff --git a/examples/graphics/balls/makefile b/examples/graphics/balls/makefile deleted file mode 100644 index 44d3d71..0000000 --- a/examples/graphics/balls/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = balls - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/billboard/CMakeLists.txt b/examples/graphics/billboard/CMakeLists.txt new file mode 100644 index 0000000..bf73297 --- /dev/null +++ b/examples/graphics/billboard/CMakeLists.txt @@ -0,0 +1,28 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + billboard + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK billboard sprite example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +configure_file(tim.s.template tim.s) + +file(GLOB _sources *.c) +psn00bsdk_add_executable( + billboard STATIC + ${_sources} + ${PROJECT_BINARY_DIR}/tim.s +) +#psn00bsdk_add_cd_image(billboard_iso billboard iso.xml DEPENDS billboard) + +install(FILES ${PROJECT_BINARY_DIR}/billboard.exe DESTINATION .) diff --git a/examples/graphics/billboard/makefile b/examples/graphics/billboard/makefile deleted file mode 100644 index 462e73c..0000000 --- a/examples/graphics/billboard/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = billboard - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/billboard/tim.s b/examples/graphics/billboard/tim.s deleted file mode 100644 index 1fa8d69..0000000 --- a/examples/graphics/billboard/tim.s +++ /dev/null @@ -1,7 +0,0 @@ -.section .data - -.global tim_image -.type tim_image, @object -tim_image: - .incbin "texture64.tim" - \ No newline at end of file diff --git a/examples/graphics/billboard/tim.s.template b/examples/graphics/billboard/tim.s.template new file mode 100644 index 0000000..fbe7522 --- /dev/null +++ b/examples/graphics/billboard/tim.s.template @@ -0,0 +1,6 @@ +.section .data + +.global tim_image +.type tim_image, @object +tim_image: + .incbin "${PROJECT_SOURCE_DIR}/texture64.tim" diff --git a/examples/graphics/fpscam/CMakeLists.txt b/examples/graphics/fpscam/CMakeLists.txt new file mode 100644 index 0000000..8fa66f2 --- /dev/null +++ b/examples/graphics/fpscam/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + hello + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK 3D camera controls example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(fpscam STATIC ${_sources}) +#psn00bsdk_add_cd_image(fpscam_iso fpscam iso.xml DEPENDS fpscam) + +install(FILES ${PROJECT_BINARY_DIR}/fpscam.exe DESTINATION .) diff --git a/examples/graphics/fpscam/makefile b/examples/graphics/fpscam/makefile deleted file mode 100644 index 2ddb7fd..0000000 --- a/examples/graphics/fpscam/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = fpscam - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt new file mode 100644 index 0000000..3cdf2ff --- /dev/null +++ b/examples/graphics/gte/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + hello + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK GTE 3D cube example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(gte STATIC ${_sources}) +#psn00bsdk_add_cd_image(gte_iso gte iso.xml DEPENDS gte) + +install(FILES ${PROJECT_BINARY_DIR}/gte.exe DESTINATION .) diff --git a/examples/graphics/gte/makefile b/examples/graphics/gte/makefile deleted file mode 100644 index f44e72b..0000000 --- a/examples/graphics/gte/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = gte - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/hdtv/CMakeLists.txt b/examples/graphics/hdtv/CMakeLists.txt new file mode 100644 index 0000000..98a0b3f --- /dev/null +++ b/examples/graphics/hdtv/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + hdtv + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK HDTV widescreen example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(hdtv STATIC ${_sources}) +#psn00bsdk_add_cd_image(hdtv_iso hdtv iso.xml DEPENDS hdtv) + +install(FILES ${PROJECT_BINARY_DIR}/hdtv.exe DESTINATION .) diff --git a/examples/graphics/hdtv/makefile b/examples/graphics/hdtv/makefile deleted file mode 100644 index 6659c98..0000000 --- a/examples/graphics/hdtv/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = hdtv - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/render2tex/CMakeLists.txt b/examples/graphics/render2tex/CMakeLists.txt new file mode 100644 index 0000000..42a063b --- /dev/null +++ b/examples/graphics/render2tex/CMakeLists.txt @@ -0,0 +1,28 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + render2tex + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK render-to-texture example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +configure_file(texture.s.template texture.s) + +file(GLOB _sources *.c) +psn00bsdk_add_executable( + render2tex STATIC + ${_sources} + ${PROJECT_BINARY_DIR}/texture.s +) +#psn00bsdk_add_cd_image(render2tex_iso render2tex iso.xml DEPENDS render2tex) + +install(FILES ${PROJECT_BINARY_DIR}/render2tex.exe DESTINATION .) diff --git a/examples/graphics/render2tex/makefile b/examples/graphics/render2tex/makefile deleted file mode 100644 index bb0ef3c..0000000 --- a/examples/graphics/render2tex/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = render2tex - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/render2tex/texture.s b/examples/graphics/render2tex/texture.s deleted file mode 100644 index e786dce..0000000 --- a/examples/graphics/render2tex/texture.s +++ /dev/null @@ -1,9 +0,0 @@ -# Assembler file for including the texture file in a more elegant manner - -.section .data - -.global tim_blendpattern -.type tim_blendpattern, @object -tim_blendpattern: - .incbin "blendpattern-16c.tim" - \ No newline at end of file diff --git a/examples/graphics/render2tex/texture.s.template b/examples/graphics/render2tex/texture.s.template new file mode 100644 index 0000000..8b09ad8 --- /dev/null +++ b/examples/graphics/render2tex/texture.s.template @@ -0,0 +1,8 @@ +# Assembler file for including the texture file in a more elegant manner + +.section .data + +.global tim_blendpattern +.type tim_blendpattern, @object +tim_blendpattern: + .incbin "${PROJECT_SOURCE_DIR}/blendpattern-16c.tim" diff --git a/examples/graphics/rgb24/CMakeLists.txt b/examples/graphics/rgb24/CMakeLists.txt new file mode 100644 index 0000000..c66ae69 --- /dev/null +++ b/examples/graphics/rgb24/CMakeLists.txt @@ -0,0 +1,28 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + rgb24 + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK 24-bit RGB display example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +configure_file(tim.s.template tim.s) + +file(GLOB _sources *.c) +psn00bsdk_add_executable( + rgb24 STATIC + ${_sources} + ${PROJECT_BINARY_DIR}/tim.s +) +#psn00bsdk_add_cd_image(rgb24_iso rgb24 iso.xml DEPENDS rgb24) + +install(FILES ${PROJECT_BINARY_DIR}/rgb24.exe DESTINATION .) diff --git a/examples/graphics/rgb24/makefile b/examples/graphics/rgb24/makefile deleted file mode 100644 index 9fa35ec..0000000 --- a/examples/graphics/rgb24/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = rgb24 - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/graphics/rgb24/tim.s b/examples/graphics/rgb24/tim.s deleted file mode 100644 index a4432d9..0000000 --- a/examples/graphics/rgb24/tim.s +++ /dev/null @@ -1,7 +0,0 @@ -.section .data - -.global tim_image -.type tim_image, @object -tim_image: - .incbin "bunpattern.tim" - \ No newline at end of file diff --git a/examples/graphics/rgb24/tim.s.template b/examples/graphics/rgb24/tim.s.template new file mode 100644 index 0000000..9fb1fb6 --- /dev/null +++ b/examples/graphics/rgb24/tim.s.template @@ -0,0 +1,6 @@ +.section .data + +.global tim_image +.type tim_image, @object +tim_image: + .incbin "${PROJECT_SOURCE_DIR}/bunpattern.tim" diff --git a/examples/makefile b/examples/makefile deleted file mode 100644 index bdc62ce..0000000 --- a/examples/makefile +++ /dev/null @@ -1,34 +0,0 @@ -# Run using make (Linux) or gmake (BSD) -# Part of the PSn00bSDK Project -# 2019-2020 Lameguy64 / Meido-Tek Productions - -TOPTARGETS = all clean - -# Beginner examples -DIRS = beginner/hello beginner/cppdemo - -# Graphics examples -DIRS += graphics/balls graphics/billboard graphics/fpscam \ - graphics/gte graphics/hdtv graphics/render2tex \ - graphics/rgb24 - -# System related examples -DIRS += system/childexec system/console system/dynlink \ - system/timer system/tty - -# Low-level examples -DIRS += - -# CD-ROM examples -DIRS += cdrom/cdbrowse cdrom/cdxa - -# Demos -DIRS += demos/n00bdemo - -$(TOPTARGETS): $(DIRS) -$(DIRS): - @$(MAKE) -C $@ $(MAKECMDGOALS) - -clean: $(DIRS) - -.PHONY: $(TOPTARGETS) $(DIRS) diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt new file mode 100644 index 0000000..8092bec --- /dev/null +++ b/examples/system/childexec/CMakeLists.txt @@ -0,0 +1,34 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + childexec + LANGUAGES C ASM + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK child process example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +configure_file(child_exe.s.template child_exe.s) + +file(GLOB _sources *.c) +file(GLOB _child_sources child/*.c) +psn00bsdk_add_executable( + parent STATIC + ${_sources} + ${PROJECT_BINARY_DIR}/child_exe.s +) +psn00bsdk_add_executable(child STATIC ${_child_sources}) +#psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent) + +# Make sure the child executable is built before the parent (so it can be +# embedded via child_exe.s). +add_dependencies(parent child) + +install(FILES ${PROJECT_BINARY_DIR}/parent.exe DESTINATION .) diff --git a/examples/system/childexec/child_exe.s b/examples/system/childexec/child_exe.s deleted file mode 100644 index 66bd0e2..0000000 --- a/examples/system/childexec/child_exe.s +++ /dev/null @@ -1,6 +0,0 @@ -.section .data - -.global child_exe # Insert spoopypasta -.type child_exe, @object -child_exe: - .incbin "build/child/child.exe" \ No newline at end of file diff --git a/examples/system/childexec/child_exe.s.template b/examples/system/childexec/child_exe.s.template new file mode 100644 index 0000000..f76bb3d --- /dev/null +++ b/examples/system/childexec/child_exe.s.template @@ -0,0 +1,6 @@ +.section .data + +.global child_exe # Insert spoopypasta +.type child_exe, @object +child_exe: + .incbin "${PROJECT_BINARY_DIR}/child.exe" diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile deleted file mode 100644 index e801739..0000000 --- a/examples/system/childexec/makefile +++ /dev/null @@ -1,93 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -#TARGET = childexec - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES_PARENT = $(notdir $(wildcard *.c)) -CPPFILES_PARENT = $(notdir $(wildcard *.cpp)) -AFILES_PARENT = $(notdir $(wildcard *.s)) - -CFILES_CHILD = $(notdir $(wildcard child/*.c)) -CPPFILES_CHILD = $(notdir $(wildcard child/*.cpp)) -AFILES_CHILD = $(notdir $(wildcard child/*.s)) - -# Create names for object files -OFILES_PARENT = $(addprefix build/,$(CFILES_PARENT:.c=.o)) \ - $(addprefix build/,$(CPPFILES_PARENT:.cpp=.o)) \ - $(addprefix build/,$(AFILES_PARENT:.s=.o)) -OFILES_CHILD = $(addprefix build/child/,$(CFILES_CHILD:.c=.o)) \ - $(addprefix build/child/,$(CPPFILES_CHILD:.cpp=.o)) \ - $(addprefix build/child/,$(AFILES_CHILD:.s=.o)) - -# Project specific includes and libraries -# (use -I for include dirs, -L for library dirs, -l for static libraries) -INCLUDE += -LIBDIRS += -LIBS += - -# Relocate the child executable to 0x30000 -LDFLAGS_CHILD = -Ttext=0x80030000 - -## Build rules - -#all: iso -all: build/child/child build/parent - -iso: build/child/child build/parent resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/child/child: $(OFILES_CHILD) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LDFLAGS_CHILD) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/parent: $(OFILES_PARENT) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/child/%.o: child/%.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/child/%.o: child/%.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/child/%.o: child/%.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt new file mode 100644 index 0000000..acae08f --- /dev/null +++ b/examples/system/console/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + console + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK stdio console example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(console STATIC ${_sources}) +#psn00bsdk_add_cd_image(console_iso console iso.xml DEPENDS console) + +install(FILES ${PROJECT_BINARY_DIR}/console.exe DESTINATION .) diff --git a/examples/system/console/makefile b/examples/system/console/makefile deleted file mode 100644 index addf02a..0000000 --- a/examples/system/console/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = console - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt new file mode 100644 index 0000000..3af5d4b --- /dev/null +++ b/examples/system/dynlink/CMakeLists.txt @@ -0,0 +1,32 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + dynlink + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK dynamic linker example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(dynlink_main DYNAMIC ${_sources}) +psn00bsdk_add_library (dynlink_cube SHARED library/cube.c) +psn00bsdk_add_library (dynlink_balls SHARED library/balls.c) +psn00bsdk_add_cd_image( + dynlink_iso dynlink iso.xml + DEPENDS dynlink_main dynlink_cube dynlink_balls +) + +install( + FILES + ${PROJECT_BINARY_DIR}/dynlink.bin + ${PROJECT_BINARY_DIR}/dynlink.cue + DESTINATION . +) diff --git a/examples/system/dynlink/iso.xml b/examples/system/dynlink/iso.xml index 76cc8fc..8f40510 100644 --- a/examples/system/dynlink/iso.xml +++ b/examples/system/dynlink/iso.xml @@ -1,7 +1,7 @@ - - - + + + - - + + diff --git a/examples/system/dynlink/makefile b/examples/system/dynlink/makefile deleted file mode 100644 index b3fb298..0000000 --- a/examples/system/dynlink/makefile +++ /dev/null @@ -1,95 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -#TARGET = dynlink - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES_MAIN = $(notdir $(wildcard *.c)) -CPPFILES_MAIN = $(notdir $(wildcard *.cpp)) -AFILES_MAIN = $(notdir $(wildcard *.s)) - -CFILES_DLL = $(notdir $(wildcard library/*.c)) -CPPFILES_DLL = $(notdir $(wildcard library/*.cpp)) -AFILES_DLL = $(notdir $(wildcard library/*.s)) - -# Create names for object files -OFILES_MAIN = $(addprefix build/,$(CFILES_MAIN:.c=.o)) \ - $(addprefix build/,$(CPPFILES_MAIN:.cpp=.o)) \ - $(addprefix build/,$(AFILES_MAIN:.s=.o)) -OFILES_CUBE = build/library/cube.o -OFILES_BALLS = build/library/balls.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: iso -#all: build/library/cube build/library/balls build/main - -iso: build/library/cube build/library/balls build/main resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/library/cube: $(OFILES_CUBE) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_DLL) $^ -o $@ - #$(NM) -f posix -l -n $@ >$@.map - $(OBJCOPY) -O binary $@ $@.dll - -build/library/balls: $(OFILES_BALLS) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_DLL) $^ -o $@ - #$(NM) -f posix -l -n $@ >$@.map - $(OBJCOPY) -O binary $@ $@.dll - -build/main: $(OFILES_MAIN) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXEDYN) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/library/%.o: library/%.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_DLL) $(INCLUDE) -c $< -o $@ - -build/library/%.o: library/%.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_DLL) $(INCLUDE) -c $< -o $@ - -build/library/%.o: library/%.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_DLL) $(INCLUDE) -c $< -o $@ - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXEDYN) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXEDYN) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXEDYN) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/system/timer/CMakeLists.txt b/examples/system/timer/CMakeLists.txt new file mode 100644 index 0000000..189bf87 --- /dev/null +++ b/examples/system/timer/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + timer + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK hardware timer example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(timer STATIC ${_sources}) +#psn00bsdk_add_cd_image(timer_iso timer iso.xml DEPENDS timer) + +install(FILES ${PROJECT_BINARY_DIR}/timer.exe DESTINATION .) diff --git a/examples/system/timer/makefile b/examples/system/timer/makefile deleted file mode 100644 index c418af4..0000000 --- a/examples/system/timer/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = timer - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build diff --git a/examples/system/tty/CMakeLists.txt b/examples/system/tty/CMakeLists.txt new file mode 100644 index 0000000..024ccd4 --- /dev/null +++ b/examples/system/tty/CMakeLists.txt @@ -0,0 +1,22 @@ +# PSn00bSDK example CMake script +# (C) 2021 spicyjpeg - MPL licensed + +cmake_minimum_required(VERSION 3.21) + +if(NOT DEFINED CMAKE_TOOLCHAIN_FILE AND DEFINED ENV{PSN00BSDK_LIBS}) + set(CMAKE_TOOLCHAIN_FILE $ENV{PSN00BSDK_LIBS}/cmake/sdk.cmake) +endif() + +project( + tty + LANGUAGES C + VERSION 1.0.0 + DESCRIPTION "PSn00bSDK stdio terminal example" + HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk" +) + +file(GLOB _sources *.c) +psn00bsdk_add_executable(tty STATIC ${_sources}) +#psn00bsdk_add_cd_image(tty_iso tty iso.xml DEPENDS tty) + +install(FILES ${PROJECT_BINARY_DIR}/tty.exe DESTINATION .) diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile deleted file mode 100644 index 381aa41..0000000 --- a/examples/system/tty/makefile +++ /dev/null @@ -1,65 +0,0 @@ -# PSn00bSDK makefile template -# Part of the PSn00bSDK Project -# 2019 - 2021 Lameguy64 / Meido-Tek Productions - -## Settings - -PSN00BSDK_LIBS ?= ../../../libpsn00b - -# Edit this to point to psn00bsdk-setup.mk, or copy that over to your project's -# root folder (it only depends on environment variables). -include ../../../psn00bsdk-setup.mk - -# Project target name -TARGET = tty - -## Files - -# Searches for C, C++ and S (assembler) files in local directory -CFILES = $(notdir $(wildcard *.c)) -CPPFILES= $(notdir $(wildcard *.cpp)) -AFILES = $(notdir $(wildcard *.s)) - -# Create names for object files -OFILES = $(addprefix build/,$(CFILES:.c=.o)) \ - $(addprefix build/,$(CPPFILES:.cpp=.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: iso -all: build/$(TARGET) - -iso: build/$(TARGET) resources - $(MKPSXISO) -y -q iso.xml - -resources: - # Add commands to build/convert your assets here - #$(LZPACK) data.xml - -build/$(TARGET): $(OFILES) - @mkdir -p $(dir $@) - $(LD) $(LDFLAGS_EXE) $(LIBDIRS) $^ $(LIBS) -o $@ - $(NM) -f posix -l -n $@ >$@.map - $(ELF2X) -q $@ $@.exe - -build/%.o: %.c - @mkdir -p $(dir $@) - $(CC) $(CFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.cpp - @mkdir -p $(dir $@) - $(CXX) $(CPPFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -build/%.o: %.s - @mkdir -p $(dir $@) - $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ - -clean: - rm -rf build -- cgit v1.2.3 From 0e3278a087daa25cba541d7c1dae19dfd4e2d422 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 27 Sep 2021 20:11:10 +0200 Subject: Misc MSVC/CMake fixes, also fixed childexec example --- CMakeLists.txt | 5 ++-- INSTALL.md | 42 +++++++++++++++++++------------- doc/dev notes.txt | 9 +++++++ examples/system/childexec/CMakeLists.txt | 7 ++++++ libpsn00b/cmake/sdk.cmake | 41 +++++++++++++++++++------------ libpsn00b/lzp/compress.c | 10 ++++---- libpsn00b/lzp/crc.c | 8 +++--- libpsn00b/lzp/lzp.c | 32 ++++++++++++------------ libpsn00b/lzp/lzp.h | 18 +++++++------- libpsn00b/lzp/lzqlp.h | 23 ++++++++++------- libpsn00b/lzp/qlp.c | 24 +++++++++--------- tools/lzpack/filelist.h | 7 +++++- tools/lzpack/main.cpp | 30 ++++++++++++----------- tools/smxlink/main.cpp | 4 +++ tools/smxlink/timreader.cpp | 4 +++ tools/util/elf2cpe.c | 4 +++ tools/util/elf2x.c | 9 ++++++- 17 files changed, 172 insertions(+), 105 deletions(-) (limited to 'examples') diff --git a/CMakeLists.txt b/CMakeLists.txt index 71f9acf..fa04b71 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,9 @@ if(NOT SKIP_DOWNLOAD) ExternalProject_Add( tinyxml2 GIT_REPOSITORY "https://github.com/leethomason/tinyxml2" - CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/install_temp + CMAKE_CACHE_ARGS + -DCMAKE_INSTALL_PREFIX:PATH=${PROJECT_BINARY_DIR}/install_temp + -DCMAKE_MSVC_RUNTIME_LIBRARY:STRING=MultiThreaded$<$:Debug> INSTALL_DIR install_temp ) ExternalProject_Add( @@ -154,7 +156,6 @@ set(CPACK_RESOURCE_FILE_README ${PROJECT_SOURCE_DIR}/README.md) set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/LICENSE.md) set(CPACK_PRE_BUILD_SCRIPTS ${PROJECT_SOURCE_DIR}/cpack/fakeroot_fix.cmake) - set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.28), cmake (>= 3.21), gcc-mipsel-unknown-elf") set(CPACK_DEBIAN_PACKAGE_SUGGESTS "git") set(CPACK_DEBIAN_PACKAGE_SECTION devel) diff --git a/INSTALL.md b/INSTALL.md index 974ee0a..6547c2b 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -11,22 +11,29 @@ tested but should work. install the `build-essential` package provided by most Linux distros. 2. Install Git and CMake. Note that some Linux distros ship relatively old - versions of CMake, so make sure you have at least CMake 3.21. You may also - want to grab [Ninja](https://ninja-build.org) (it is a single executable, you - have to copy it to any directory listed in the `PATH` environment variable) - as a faster alternative to `make`. + versions of CMake, so make sure you have at least CMake 3.21. You will also + need [Ninja](https://ninja-build.org) (it is a single executable, you have to + copy it to any directory listed in the `PATH` environment variable) on + Windows as there is no preinstalled build system; on Linux you can use `make` + instead, but Ninja is still recommended. 3. Build and install a GCC toolchain for `mipsel-unknown-elf`. As GCC is notoriously hard to compile under Windows, you may download a precompiled - version from [Lameguy64's website](http://lameguy64.net?page=psn00bsdk) - and extract it to the root of your C drive instead. See - [toolchain.txt](toolchain.txt) for details on compiling GCC. - -4. Set the `PSN00BSDK_TC` environment variable to point to the location you - installed or extracted the toolchain to. The default is - `C:\Program Files\PSn00bSDK\mips-unknown-elf` on Windows or - `/usr/local/mips-unknown-elf` on Linux; installing to a different path is - not recommended. + version from [Lameguy64's website](http://lameguy64.net?page=psn00bsdk) and + and extract it into Program Files instead. See [toolchain.txt](toolchain.txt) + for details on compiling GCC. + +4. If you chose a non-standard install location for the toolchain, set the + `PSN00BSDK_TC` environment variable to point to the toolchain's root + directory. This step is unnecessary if you installed/extracted the toolchain + into any of these directories: + + - `C:\Program Files\mipsel-unknown-elf` + - `C:\Program Files (x86)\mipsel-unknown-elf` + - `C:\mipsel-unknown-elf` + - `/usr/local/mipsel-unknown-elf` + - `/usr/mipsel-unknown-elf` + - `/opt/mipsel-unknown-elf` 5. Clone/download the PSn00bSDK repo and run the following commands: @@ -55,9 +62,10 @@ with debugging capabilities such as [no$psx](https://problemkaputt.de/psx.htm) ## Building installer packages -CPack can be used to build NSIS-based installers on Windows or DEB/RPM packages -on Linux, plus zipped packages on all platforms. Note that currently none of the -built packages include the GCC toolchain, thus their usefulness is limited. +CPack can be used to build NSIS-based installers, DEB/RPM packages and zipped +releases. Note that currently none of the built packages include the toolchain, +thus their usefulness is limited. Distributing prebuilt releases is discouraged +anyway since PSn00bSDK is still far from being feature-complete. 1. Follow steps 1-4 above to set up the toolchain, then install NSIS on Windows or `dpkg` and `rpm` on Linux. @@ -97,4 +105,4 @@ The toolchain script defines a few CMake macros to create PS1 executables, DLLs and CD images. See the [reference](doc/cmake_reference.md) for details. ----------------------------------------- -_Last updated on 2021-09-12 by spicyjpeg_ +_Last updated on 2021-09-26 by spicyjpeg_ diff --git a/doc/dev notes.txt b/doc/dev notes.txt index 151a441..8fd8d7f 100644 --- a/doc/dev notes.txt +++ b/doc/dev notes.txt @@ -102,6 +102,15 @@ project() command. The poorly documented solution to this is to move such commands to a separate file and set CMAKE_PROJECT_INCLUDE to point to it, so project() will execute it immediately after initialization. +* After executing the toolchain file, CMake generates and attempts to build +several dummy projects to test the compiler. Each of these projects re-includes +the toolchain script (which is why you'll see commands executed multiple times) +and uses the same variable values as the main project, however CMake will *NOT* +pass custom variables through by default. If your toolchain script has options +that can be set via custom variables (like PSN00BSDK_TC and PSN00BSDK_PREFIX in +PSn00bSDK), you'll have to set CMAKE_TRY_COMPILE_PLATFORM_VARIABLES to a list +of variable names to be exported to generated dummy projects. + * There is no way to use multiple toolchains (PS1 + host) in a single project, even if you use add_subdirectory() to execute multiple project files (which, confusingly, adds their targets to the parent project rather than treating them diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt index 8092bec..c9983c4 100644 --- a/examples/system/childexec/CMakeLists.txt +++ b/examples/system/childexec/CMakeLists.txt @@ -27,6 +27,13 @@ psn00bsdk_add_executable( psn00bsdk_add_executable(child STATIC ${_child_sources}) #psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent) +# Relocate the child executable to a non-default address to prevent it from +# overlapping with the main one at 0x80010000. +# NOTE: child executables are not position-independent and can't be relocated +# at runtime. If you need your code to be relocatable (e.g. to load it into a +# dynamically-allocated buffer), consider using a DLL instead. +target_link_options(child PRIVATE -Ttext=0x80030000) + # Make sure the child executable is built before the parent (so it can be # embedded via child_exe.s). add_dependencies(parent child) diff --git a/libpsn00b/cmake/sdk.cmake b/libpsn00b/cmake/sdk.cmake index 82e921c..4c2f330 100644 --- a/libpsn00b/cmake/sdk.cmake +++ b/libpsn00b/cmake/sdk.cmake @@ -22,23 +22,29 @@ 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. This dodges -# missing C++ standard library errors. -set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY) +# 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. PSN00BSDK_TC can be left unset if the toolchain can be -# found in the PATH environment variable. +# 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 @@ -57,18 +63,23 @@ 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_EXECUTABLE_SUFFIX}) -set(CMAKE_C_COMPILER ${_prefix}-gcc${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_CXX_COMPILER ${_prefix}-g++${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_AR ${_prefix}-ar${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_LINKER ${_prefix}-ld${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_RANLIB ${_prefix}-ranlib${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_OBJCOPY ${_prefix}-objcopy${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_SIZE ${_prefix}-size${CMAKE_EXECUTABLE_SUFFIX}) -set(CMAKE_STRIP ${_prefix}-strip${CMAKE_EXECUTABLE_SUFFIX}) -set(TOOLCHAIN_NM ${_prefix}-nm${CMAKE_EXECUTABLE_SUFFIX}) +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 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..7cc7bf3 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> 8) ^ crcTable[tmp&0xff]; @@ -70,10 +70,10 @@ 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 char* byteBuff = (const unsigned char*)buff; unsigned int byte; unsigned int crcTable[256]; 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 +#ifdef _WIN32 +#include +#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/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/tools/lzpack/filelist.h b/tools/lzpack/filelist.h index 5351335..f6ad478 100644 --- a/tools/lzpack/filelist.h +++ b/tools/lzpack/filelist.h @@ -4,9 +4,14 @@ #include #include #include -#include #include +#ifdef WIN32 +#include +#else +#include +#endif + #ifndef MAX_PATH #define MAX_PATH PATH_MAX #endif diff --git a/tools/lzpack/main.cpp b/tools/lzpack/main.cpp index e57117e..f684d18 100644 --- a/tools/lzpack/main.cpp +++ b/tools/lzpack/main.cpp @@ -151,11 +151,10 @@ int main(int argc, const char* argv[]) { int CreateLZPfile(const char* packFile, FileListClass* fileList) { FILE* packp; - LZP_FILE entry[fileList->EntryCount()]; + LZP_FILE* entry=new LZP_FILE[fileList->EntryCount()]; int overallSize=0; int overallPackedSize=0; - packp = fopen(packFile, "wb"); fseek(packp, sizeof(LZP_HEAD)+(sizeof(LZP_FILE)*fileList->EntryCount()), SEEK_SET); @@ -179,6 +178,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); + delete entry; return(0); @@ -199,13 +199,13 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { int fileSize = ftell(fp); fseek(fp, 0, SEEK_SET); - void* fileBuff = malloc(fileSize); + char* fileBuff = new char[fileSize]; fread(fileBuff, fileSize, 1, fp); fclose(fp); - void* compBuff = malloc(fileSize+16384); + char* compBuff = new char[fileSize+16384]; int compSize = lzCompress(compBuff, fileBuff, fileSize, 2); @@ -216,8 +216,8 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(compBuff, compSize, 1, packp); - free(compBuff); - free(fileBuff); + delete compBuff; + delete fileBuff; printf("Ok. (%.02f%%)\n", 100.f*((float)compSize/fileSize)); @@ -238,7 +238,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(entry, sizeof(LZP_FILE), fileList->EntryCount(), packp); fclose(packp); - + delete entry; printf("Packed %d file(s) totaling %d bytes (%.02f%% compression ratio).\n", fileList->EntryCount(), @@ -255,7 +255,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { FILE* packp; QLP_HEAD head; - QLP_FILE fileEntry[fileList->EntryCount()]; + QLP_FILE* fileEntry=new QLP_FILE[fileList->EntryCount()]; strncpy(head.id, "QLP", 3); head.numFiles = fileList->EntryCount(); @@ -285,6 +285,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); + delete fileEntry; return(0); @@ -315,7 +316,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { FILE* fp = fopen(fileList->Entry(i)->fileName, "rb"); int bytesCopied = 0; - void* copyBuff = malloc(BUFF_SIZE); + char* copyBuff = new char[BUFF_SIZE]; while(!feof(fp)) { @@ -327,7 +328,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { } - free(copyBuff); + delete copyBuff; fclose(fp); fileEntry[i].fileSize = bytesCopied; @@ -344,6 +345,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { fwrite(fileEntry, sizeof(QLP_FILE), head.numFiles, packp); fclose(packp); + delete fileEntry; return(true); @@ -402,7 +404,7 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { } FILE* fp = fopen(fileList->Entry(i)->fileName, "rb"); - void* buff = malloc(BUFF_SIZE); + char* buff = new char[BUFF_SIZE]; int bytesTotal = 0; @@ -415,18 +417,18 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { } fclose(fp); - free(buff); + delete buff; toc.file[i].size = bytesTotal; if ((2048*((ftell(packp)+2047)/2048)) != ftell(packp)) { int pad = (2048*(((ftell(packp)%2048)+2047)/2048))-(ftell(packp)%2048); - char padding[pad]; + char* padding = new char[pad]; memset(padding, 0x00, pad); fwrite(padding, pad, 1, packp); - + delete padding; } printf("Done.\n"); diff --git a/tools/smxlink/main.cpp b/tools/smxlink/main.cpp index 8072274..d58f36a 100644 --- a/tools/smxlink/main.cpp +++ b/tools/smxlink/main.cpp @@ -15,6 +15,10 @@ //#include #include "timreader.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define VERSION "0.25b" namespace param diff --git a/tools/smxlink/timreader.cpp b/tools/smxlink/timreader.cpp index a8fba94..5116f52 100644 --- a/tools/smxlink/timreader.cpp +++ b/tools/smxlink/timreader.cpp @@ -2,6 +2,10 @@ #include #include "timreader.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + int GetTimCoords(const char* fileName, TIM_COORDS *coords) { FILE* fp = fopen(fileName, "rb"); diff --git a/tools/util/elf2cpe.c b/tools/util/elf2cpe.c index 4379f4a..46b0a37 100644 --- a/tools/util/elf2cpe.c +++ b/tools/util/elf2cpe.c @@ -3,6 +3,10 @@ #include #include "elf.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define MAX_prg_entry_count 128 #ifndef false diff --git a/tools/util/elf2x.c b/tools/util/elf2x.c index 26ec9a3..9a7c126 100644 --- a/tools/util/elf2x.c +++ b/tools/util/elf2x.c @@ -6,6 +6,10 @@ #include #include "elf.h" +#ifdef WIN32 +#define strcasecmp _stricmp +#endif + #define MAX_prg_entry_count 128 #define true (1) #define false (0) @@ -233,9 +237,12 @@ int main(int argc, char** argv) { exe.params.t_size = exe_tsize; exe.params.pc0 = head.prg_entry_addr; + // Some later PAL BIOS versions seem to actually verify the license string + // in the executable (despite what the nocash docs claim) and display the + // dreaded "insert PlayStation CD-ROM" screen if it's not valid. strncpy( exe.header, "PS-X EXE", 8 ); strcpy( exe.license, - "Not Licensed or Endorsed by Sony Computer Entertainment Inc." ); + "Sony Computer Entertainment Inc. for Europe area" ); strcpy( exe.pad2, "Built using GCC and PSn00bSDK libraries" ); -- cgit v1.2.3 From 49ea4e7561980d79ec3bed869982852b45b597e8 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Mon, 27 Sep 2021 22:27:17 +0200 Subject: Updated changelog and files missing from last commit --- changelog.txt | 16 ++++++++++++++++ doc/cmake_reference.md | 6 +++++- examples/demos/n00bdemo/data.h | 4 +++- examples/demos/n00bdemo/data.s.template | 6 +++--- examples/demos/n00bdemo/main.c | 6 ++++-- libpsn00b/cmake/internal_setup.cmake | 3 +++ libpsn00b/include/lzp/lzp.h | 18 +++++++++--------- libpsn00b/include/lzp/lzqlp.h | 23 ++++++++++++++--------- libpsn00b/lzp/bit.c | 2 +- libpsn00b/lzp/bit.h | 2 +- libpsn00b/lzp/crc.c | 6 +++--- tools/lzpack/main.cpp | 18 +++++++++--------- 12 files changed, 71 insertions(+), 39 deletions(-) (limited to 'examples') diff --git a/changelog.txt b/changelog.txt index 03d2d10..046f4fe 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,22 @@ PSn00bSDK changelog Items that are lower in the log are more recently implemented. +09-27-2021 by spicyjpeg: + +* liblzp, tools: Fixed tools not building on MSVC and cleaned up LZP API + declarations (replaced meaningless void* pointers with proper types). + +* libpsn00b: Added missing PSN00BSDK_VERSION CMake variable. + +* examples: Fixed childexec (parent.exe) example crashing due to the child + executable not being relocated in the new build script. Patched n00bdemo to + suppress liblzp pointer type warnings. + +* Fixed another MSVC linker error when building tinyxml2 automatically, as well + as various toolchain/compiler test errors sometimes thrown by CMake. Updated + INSTALL.md with more details. + + 09-13-2021 by spicyjpeg: * Migrated libpsn00b, tools, examples and template to CMake, added a top-level diff --git a/doc/cmake_reference.md b/doc/cmake_reference.md index 8810ad4..3b586ab 100644 --- a/doc/cmake_reference.md +++ b/doc/cmake_reference.md @@ -182,6 +182,10 @@ the build script. ## Read-only variables +- `PSN00BSDK_VERSION` + + The SDK's version number (`major.minor.patch`). + - `PSN00BSDK_TOOLS`, `PSN00BSDK_INCLUDE`, `PSN00BSDK_LDSCRIPTS` Lists of paths used internally. Should not be set, manipulated or overridden @@ -200,4 +204,4 @@ the build script. LZP archives as part of the build pipeline. ----------------------------------------- -_Last updated on 2021-09-12 by spicyjpeg_ +_Last updated on 2021-09-27 by spicyjpeg_ diff --git a/examples/demos/n00bdemo/data.h b/examples/demos/n00bdemo/data.h index 3be0e3d..9e64ea1 100644 --- a/examples/demos/n00bdemo/data.h +++ b/examples/demos/n00bdemo/data.h @@ -1,7 +1,9 @@ #ifndef _DATA_H #define _DATA_H -extern unsigned char lz_resources[]; +extern unsigned char _lz_resources[]; + +#define lz_resources ((const LZP_HEAD*) _lz_resources) /*extern unsigned char smd_mtekdisk[]; extern unsigned char smd_mtektext[]; diff --git a/examples/demos/n00bdemo/data.s.template b/examples/demos/n00bdemo/data.s.template index a7237cd..9fbef2e 100644 --- a/examples/demos/n00bdemo/data.s.template +++ b/examples/demos/n00bdemo/data.s.template @@ -1,8 +1,8 @@ .section .data -.global lz_resources -.type lz_resources, @object -lz_resources: +.global _lz_resources +.type _lz_resources, @object +_lz_resources: .incbin "${PROJECT_BINARY_DIR}/data.lzp" #.global smd_mtekdisk diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index fcd38b8..ba21d88 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -85,11 +85,12 @@ void loadTextures() { Unpack textures from an embedded LZP archive and upload them to VRAM. */ int i; - int *tex_buff,*ttim,j; + int *ttim,j; + QLP_HEAD *tex_buff; TIM_IMAGE tim; i = lzpSearchFile( "textures", lz_resources ); - tex_buff = (int*)malloc( lzpFileSize( lz_resources, i ) ); + tex_buff = (QLP_HEAD*)malloc( lzpFileSize( lz_resources, i ) ); lzpUnpackFile( tex_buff, lz_resources, i ); @@ -148,6 +149,7 @@ void loadTextures() { font_tpage = getTPage( 0, 1, tim.prect->x, tim.prect->y )|0x200; font_clut = getClut( tim.crect->x, tim.crect->y ); + free( tex_buff ); } void unpackModels() { diff --git a/libpsn00b/cmake/internal_setup.cmake b/libpsn00b/cmake/internal_setup.cmake index e9423a4..e3d4be7 100644 --- a/libpsn00b/cmake/internal_setup.cmake +++ b/libpsn00b/cmake/internal_setup.cmake @@ -7,6 +7,9 @@ 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") diff --git a/libpsn00b/include/lzp/lzp.h b/libpsn00b/include/lzp/lzp.h index ffd7933..cfeeb72 100644 --- a/libpsn00b/include/lzp/lzp.h +++ b/libpsn00b/include/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/include/lzp/lzqlp.h b/libpsn00b/include/lzp/lzqlp.h index fae6438..5b70b40 100644 --- a/libpsn00b/include/lzp/lzqlp.h +++ b/libpsn00b/include/lzp/lzqlp.h @@ -1,6 +1,11 @@ #ifndef _QLP_H #define _QLP_H +#include +#ifdef _WIN32 +#include +#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/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/crc.c b/libpsn00b/lzp/crc.c index 7cc7bf3..3c1ae57 100644 --- a/libpsn00b/lzp/crc.c +++ b/libpsn00b/lzp/crc.c @@ -73,9 +73,9 @@ unsigned short lzCRC16(const void* buff, int bytes, unsigned short crc) { unsigned int lzCRC32(const void* buff, int bytes, unsigned int crc) { int i; - unsigned char* byteBuff = (const 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/tools/lzpack/main.cpp b/tools/lzpack/main.cpp index f684d18..506b76c 100644 --- a/tools/lzpack/main.cpp +++ b/tools/lzpack/main.cpp @@ -178,7 +178,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); - delete entry; + delete[] entry; return(0); @@ -216,8 +216,8 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(compBuff, compSize, 1, packp); - delete compBuff; - delete fileBuff; + delete[] compBuff; + delete[] fileBuff; printf("Ok. (%.02f%%)\n", 100.f*((float)compSize/fileSize)); @@ -238,7 +238,7 @@ int CreateLZPfile(const char* packFile, FileListClass* fileList) { fwrite(entry, sizeof(LZP_FILE), fileList->EntryCount(), packp); fclose(packp); - delete entry; + delete[] entry; printf("Packed %d file(s) totaling %d bytes (%.02f%% compression ratio).\n", fileList->EntryCount(), @@ -285,7 +285,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { printf("ERROR: Entry '%s' has more than 15 characters.\n", name); fclose(packp); unlink(packFile); - delete fileEntry; + delete[] fileEntry; return(0); @@ -328,7 +328,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { } - delete copyBuff; + delete[] copyBuff; fclose(fp); fileEntry[i].fileSize = bytesCopied; @@ -345,7 +345,7 @@ int CreateQLPfile(const char* packFile, FileListClass* fileList) { fwrite(fileEntry, sizeof(QLP_FILE), head.numFiles, packp); fclose(packp); - delete fileEntry; + delete[] fileEntry; return(true); @@ -417,7 +417,7 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { } fclose(fp); - delete buff; + delete[] buff; toc.file[i].size = bytesTotal; @@ -428,7 +428,7 @@ int CreatePCKfile(const char* packFile, FileListClass* fileList) { memset(padding, 0x00, pad); fwrite(padding, pad, 1, packp); - delete padding; + delete[] padding; } printf("Done.\n"); -- cgit v1.2.3