diff options
| author | John "Lameguy" Wilbert Villamor <lameguy64@gmail.com> | 2021-10-15 09:22:45 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-10-15 09:22:45 +0800 |
| commit | dd0f088aaa4c6bf013643be2d1d8621dbffdb000 (patch) | |
| tree | d848d6ce007d8bb9357c8b99d6a0a39ec41d244e /examples/demos | |
| parent | 9e08d1047fa8deeb3ccb3ce9bb11d69e25a52d56 (diff) | |
| parent | eb719a424e6a16fb64209139a32c9f8a7235a929 (diff) | |
| download | psn00bsdk-dd0f088aaa4c6bf013643be2d1d8621dbffdb000.tar.gz | |
Merge pull request #38 from spicyjpeg/cmake
Full CMake support (in place of makefiles)
Diffstat (limited to 'examples/demos')
| -rw-r--r-- | examples/demos/n00bdemo/CMakeLists.txt | 50 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/data.h | 4 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/data.s.template (renamed from examples/demos/n00bdemo/data.s) | 8 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/data.xml | 49 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/data.xml.template | 49 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/logo.c | 2 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/main.c | 10 | ||||
| -rw-r--r-- | examples/demos/n00bdemo/makefile | 65 |
8 files changed, 113 insertions, 124 deletions
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.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 b/examples/demos/n00bdemo/data.s.template index f3b2a83..9fbef2e 100644 --- a/examples/demos/n00bdemo/data.s +++ b/examples/demos/n00bdemo/data.s.template @@ -1,9 +1,9 @@ .section .data -.global lz_resources -.type lz_resources, @object -lz_resources: - .incbin "build/data.lzp" +.global _lz_resources +.type _lz_resources, @object +_lz_resources: + .incbin "${PROJECT_BINARY_DIR}/data.lzp" #.global smd_mtekdisk #.type smd_mtekdisk, @object 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 @@ -<lzp_project> - - <create packname="build/textures.qlp" format="qlp"> - - <file alias="petscum">data/petscum16c.tim</file> - <file alias="bungirl">data/bungirl.tim</file> - - <!-- These are for the timerift background --> - <file alias="clocktex">data/clktower.tim</file> - <file alias="riftbldg1">data/riftbld1.tim</file> - <file alias="riftbldg2">data/riftbld2.tim</file> - <file alias="hatkid">data/hatkid.tim</file> - - <file alias="celmap">data/celmapi.tim</file> - - <file alias="lamelotl">data/lamelotl16c.tim</file> - <file alias="n00blogo">data/n00blogo-pixel.tim</file> - <file alias="font">data/font.tim</file> - - </create> - - <create packname="build/data.lzp" format="lzp"> - - <!-- intro assets --> - <file alias="mtekdisk">data/mtekdisk.smd</file> - <file alias="mtektext">data/mtektext.smd</file> - <file alias="starsprite">data/star.smd</file> - <file alias="psn00blogo">data/psn00blogo.smd</file> - <file alias="n00blogo">data/logo.smd</file> - - <!-- lighting demo assets --> - <file alias="lightworld">data/petscum.smd</file> - <file alias="lightbulb">data/bulb.smd</file> - - <!-- Hi-res bungirl demo assets --> - <file alias="bungirl">data/bungirl.smd</file> - - <file alias="starmask">data/star_mask.smd</file> - <file alias="timerift">data/timerift.smd</file> - <file alias="rbowshade">data/rbowshade.smd</file> - - <file alias="hatkid">data/hatkid.smd</file> - - <!-- Global textures --> - <file alias="textures">build/textures.qlp</file> - - </create> - -</lzp_project>
\ 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 @@ +<lzp_project> + + <create packname="textures.qlp" format="qlp"> + + <file alias="petscum">${DATA_DIR}/petscum16c.tim</file> + <file alias="bungirl">${DATA_DIR}/bungirl.tim</file> + + <!-- These are for the timerift background --> + <file alias="clocktex">${DATA_DIR}/clktower.tim</file> + <file alias="riftbldg1">${DATA_DIR}/riftbld1.tim</file> + <file alias="riftbldg2">${DATA_DIR}/riftbld2.tim</file> + <file alias="hatkid">${DATA_DIR}/hatkid.tim</file> + + <file alias="celmap">${DATA_DIR}/celmapi.tim</file> + + <file alias="lamelotl">${DATA_DIR}/lamelotl16c.tim</file> + <file alias="n00blogo">${DATA_DIR}/n00blogo-pixel.tim</file> + <file alias="font">${DATA_DIR}/font.tim</file> + + </create> + + <create packname="data.lzp" format="lzp"> + + <!-- intro assets --> + <file alias="mtekdisk">${DATA_DIR}/mtekdisk.smd</file> + <file alias="mtektext">${DATA_DIR}/mtektext.smd</file> + <file alias="starsprite">${DATA_DIR}/star.smd</file> + <file alias="psn00blogo">${DATA_DIR}/psn00blogo.smd</file> + <file alias="n00blogo">${DATA_DIR}/logo.smd</file> + + <!-- lighting demo assets --> + <file alias="lightworld">${DATA_DIR}/petscum.smd</file> + <file alias="lightbulb">${DATA_DIR}/bulb.smd</file> + + <!-- Hi-res bungirl demo assets --> + <file alias="bungirl">${DATA_DIR}/bungirl.smd</file> + + <file alias="starmask">${DATA_DIR}/star_mask.smd</file> + <file alias="timerift">${DATA_DIR}/timerift.smd</file> + <file alias="rbowshade">${DATA_DIR}/rbowshade.smd</file> + + <file alias="hatkid">${DATA_DIR}/hatkid.smd</file> + + <!-- Global textures --> + <file alias="textures">textures.qlp</file> + + </create> + +</lzp_project>
\ 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 <inline_c.h> #include "malloc.h" #include "smd.h" -#include "lzp.h" +#include <lzp/lzp.h> #include "disp.h" #include "data.h" diff --git a/examples/demos/n00bdemo/main.c b/examples/demos/n00bdemo/main.c index 623d8cc..ba21d88 100644 --- a/examples/demos/n00bdemo/main.c +++ b/examples/demos/n00bdemo/main.c @@ -29,8 +29,8 @@ #include <psxspu.h> #include <inline_c.h> #include <string.h> -#include <lzp.h> -#include <lzqlp.h> +#include <lzp/lzp.h> +#include <lzp/lzqlp.h> #include "malloc.h" #include "smd.h" @@ -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/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 |
