From 89751f29467b359339a8c8b57c218cc3328bae43 Mon Sep 17 00:00:00 2001 From: spicyjpeg <88942473+spicyjpeg@users.noreply.github.com> Date: Tue, 17 Aug 2021 11:36:56 +0000 Subject: Rewritten all Makefiles, set up proper GCC options, added iso.xml to template --- examples/system/childexec/child.c | 326 -------------------------------- examples/system/childexec/child/child.c | 326 ++++++++++++++++++++++++++++++++ examples/system/childexec/child_exe.s | 2 +- examples/system/childexec/makefile | 105 +++++++--- 4 files changed, 408 insertions(+), 351 deletions(-) delete mode 100644 examples/system/childexec/child.c create mode 100644 examples/system/childexec/child/child.c (limited to 'examples/system/childexec') diff --git a/examples/system/childexec/child.c b/examples/system/childexec/child.c deleted file mode 100644 index 2ddfa73..0000000 --- a/examples/system/childexec/child.c +++ /dev/null @@ -1,326 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -/* OT and Packet Buffer sizes */ -#define OT_LEN 256 -#define PACKET_LEN 1024 - -/* Screen resolution */ -#define SCREEN_XRES 320 -#define SCREEN_YRES 240 - -/* Screen center position */ -#define CENTERX SCREEN_XRES>>1 -#define CENTERY SCREEN_YRES>>1 - - -/* Double buffer structure */ -typedef struct { - DISPENV disp; /* Display environment */ - DRAWENV draw; /* Drawing environment */ - u_long ot[OT_LEN]; /* Ordering table */ - char p[PACKET_LEN]; /* Packet buffer */ -} DB; - -/* Double buffer variables */ -DB db[2]; -int db_active = 0; -char *db_nextpri; - - -/* For easier handling of vertex indices */ -typedef struct { - short v0,v1,v2,v3; -} INDEX; - -/* Cube vertices */ -SVECTOR cube_verts[] = { - { -100, -100, -100, 0 }, - { 100, -100, -100, 0 }, - { -100, 100, -100, 0 }, - { 100, 100, -100, 0 }, - { 100, -100, 100, 0 }, - { -100, -100, 100, 0 }, - { 100, 100, 100, 0 }, - { -100, 100, 100, 0 } -}; - -/* Cube face normals */ -SVECTOR cube_norms[] = { - { 0, 0, -ONE, 0 }, - { 0, 0, ONE, 0 }, - { 0, -ONE, 0, 0 }, - { 0, ONE, 0, 0 }, - { -ONE, 0, 0, 0 }, - { ONE, 0, 0, 0 } -}; - -/* Cube vertex indices */ -INDEX cube_indices[] = { - { 0, 1, 2, 3 }, - { 4, 5, 6, 7 }, - { 5, 4, 0, 1 }, - { 6, 7, 3, 2 }, - { 0, 2, 5, 7 }, - { 3, 1, 6, 4 } -}; - -/* Number of faces of cube */ -#define CUBE_FACES 6 - - -/* Light color matrix */ -/* Each column represents the color matrix of each light source and is */ -/* used as material color when using gte_ncs() or multiplied by a */ -/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ -/* A column of zeroes disables the light source. */ -MATRIX color_mtx = { - ONE, 0, 0, /* Red */ - ONE, 0, 0, /* Green */ - ONE, 0, 0 /* Blue */ -}; - -/* Light matrix */ -/* Each row represents a vector direction of each light source. */ -/* An entire row of zeroes disables the light source. */ -MATRIX light_mtx = { - /* X, Y, Z */ - -2048 , -2048 , -2048, - 0 , 0 , 0, - 0 , 0 , 0 -}; - -char pad_buff[2][34]; - -/* Function declarations */ -void init(); -void display(); - - -/* Main function */ -int main(int argc, const char *argv[]) { - - int i,p,xy_temp; - - SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ - VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ - MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ - - POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ - - - printf( "Arguments passed: %d\n", argc ); - for( i=0; istat == 0 ) { - - // For digital pad, dual-analog and dual-shock - if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { - - if( !(pad->btn&PAD_SELECT) ) { - break; - } - - } - - } - - /* Set rotation and translation to the matrix */ - RotMatrix( &rot, &mtx ); - TransMatrix( &mtx, &pos ); - - /* Multiply light matrix by rotation matrix so light source */ - /* won't appear relative to the model's rotation */ - MulMatrix0( &light_mtx, &mtx, &lmtx ); - - /* Set rotation and translation matrix */ - gte_SetRotMatrix( &mtx ); - gte_SetTransMatrix( &mtx ); - - /* Set light matrix */ - gte_SetLightMatrix( &lmtx ); - - /* Make the cube SPEEN */ - rot.vx += 16; - rot.vz += 16; - - - /* Draw the cube */ - pol4 = (POLY_F4*)db_nextpri; - - for( i=0; i>2) > OT_LEN ) - continue; - - /* Initialize a quad primitive */ - setPolyF4( pol4 ); - - /* Set the projected vertices to the primitive */ - gte_stsxy0( &pol4->x0 ); - gte_stsxy1( &pol4->x1 ); - gte_stsxy2( &pol4->x2 ); - - /* Compute the last vertex and set the result */ - gte_ldv0( &cube_verts[cube_indices[i].v3] ); - gte_rtps(); - gte_stsxy( &pol4->x3 ); - - /* Load primitive color even though gte_ncs() doesn't use it. */ - /* This is so the GTE will output a color result with the */ - /* correct primitive code. */ - gte_ldrgb( &pol4->r0 ); - - /* Load the face normal */ - gte_ldv0( &cube_norms[i] ); - - /* Normal Color Single */ - gte_ncs(); - - /* Store result to the primitive */ - gte_strgb( &pol4->r0 ); - - /* Sort primitive to the ordering table */ - addPrim( db[db_active].ot+(p>>2), pol4 ); - - /* Advance to make another primitive */ - pol4++; - - } - - /* Update nextpri variable */ - /* (IMPORTANT if you plan to sort more primitives after this) */ - db_nextpri = (char*)pol4; - - /* Swap buffers and draw the primitives */ - display(); - - } - - StopPAD(); - - return 0; - -} - -void init() { - - /* Reset the GPU, also installs a VSync event handler */ - ResetGraph( 0 ); - - /* Set display and draw environment areas */ - /* (display and draw areas must be separate, otherwise hello flicker) */ - SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - - /* Enable draw area clear and dither processing */ - setRGB0( &db[0].draw, 63, 0, 127 ); - db[0].draw.isbg = 1; - db[0].draw.dtd = 1; - - - /* Define the second set of display/draw environments */ - SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); - SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); - - setRGB0( &db[1].draw, 63, 0, 127 ); - db[1].draw.isbg = 1; - db[1].draw.dtd = 1; - - - /* Apply the drawing environment of the first double buffer */ - PutDrawEnv( &db[0].draw ); - - - /* Clear both ordering tables to make sure they are clean at the start */ - ClearOTagR( db[0].ot, OT_LEN ); - ClearOTagR( db[1].ot, OT_LEN ); - - /* Set primitive pointer address */ - db_nextpri = db[0].p; - - /* Initialize the GTE */ - InitGeom(); - - /* Set GTE offset (recommended method of centering) */ - gte_SetGeomOffset( CENTERX, CENTERY ); - - /* Set screen depth (basically FOV control, W/2 works best) */ - gte_SetGeomScreen( CENTERX ); - - /* Set light ambient color and light color matrix */ - gte_SetBackColor( 63, 63, 63 ); - gte_SetColorMatrix( &color_mtx ); - - InitPAD(pad_buff[0], 34, pad_buff[1], 34); - StartPAD(); - ChangeClearPAD(0); - -} - -void display() { - - /* Wait for GPU to finish drawing and vertical retrace */ - DrawSync( 0 ); - VSync( 0 ); - - /* Swap buffers */ - db_active ^= 1; - db_nextpri = db[db_active].p; - - /* Clear the OT of the next frame */ - ClearOTagR( db[db_active].ot, OT_LEN ); - - /* Apply display/drawing environments */ - PutDrawEnv( &db[db_active].draw ); - PutDispEnv( &db[db_active].disp ); - - /* Enable display */ - SetDispMask( 1 ); - - /* Start drawing the OT of the last buffer */ - DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); - -} \ No newline at end of file diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c new file mode 100644 index 0000000..2ddfa73 --- /dev/null +++ b/examples/system/childexec/child/child.c @@ -0,0 +1,326 @@ +#include +#include +#include +#include +#include +#include +#include + +/* OT and Packet Buffer sizes */ +#define OT_LEN 256 +#define PACKET_LEN 1024 + +/* Screen resolution */ +#define SCREEN_XRES 320 +#define SCREEN_YRES 240 + +/* Screen center position */ +#define CENTERX SCREEN_XRES>>1 +#define CENTERY SCREEN_YRES>>1 + + +/* Double buffer structure */ +typedef struct { + DISPENV disp; /* Display environment */ + DRAWENV draw; /* Drawing environment */ + u_long ot[OT_LEN]; /* Ordering table */ + char p[PACKET_LEN]; /* Packet buffer */ +} DB; + +/* Double buffer variables */ +DB db[2]; +int db_active = 0; +char *db_nextpri; + + +/* For easier handling of vertex indices */ +typedef struct { + short v0,v1,v2,v3; +} INDEX; + +/* Cube vertices */ +SVECTOR cube_verts[] = { + { -100, -100, -100, 0 }, + { 100, -100, -100, 0 }, + { -100, 100, -100, 0 }, + { 100, 100, -100, 0 }, + { 100, -100, 100, 0 }, + { -100, -100, 100, 0 }, + { 100, 100, 100, 0 }, + { -100, 100, 100, 0 } +}; + +/* Cube face normals */ +SVECTOR cube_norms[] = { + { 0, 0, -ONE, 0 }, + { 0, 0, ONE, 0 }, + { 0, -ONE, 0, 0 }, + { 0, ONE, 0, 0 }, + { -ONE, 0, 0, 0 }, + { ONE, 0, 0, 0 } +}; + +/* Cube vertex indices */ +INDEX cube_indices[] = { + { 0, 1, 2, 3 }, + { 4, 5, 6, 7 }, + { 5, 4, 0, 1 }, + { 6, 7, 3, 2 }, + { 0, 2, 5, 7 }, + { 3, 1, 6, 4 } +}; + +/* Number of faces of cube */ +#define CUBE_FACES 6 + + +/* Light color matrix */ +/* Each column represents the color matrix of each light source and is */ +/* used as material color when using gte_ncs() or multiplied by a */ +/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */ +/* A column of zeroes disables the light source. */ +MATRIX color_mtx = { + ONE, 0, 0, /* Red */ + ONE, 0, 0, /* Green */ + ONE, 0, 0 /* Blue */ +}; + +/* Light matrix */ +/* Each row represents a vector direction of each light source. */ +/* An entire row of zeroes disables the light source. */ +MATRIX light_mtx = { + /* X, Y, Z */ + -2048 , -2048 , -2048, + 0 , 0 , 0, + 0 , 0 , 0 +}; + +char pad_buff[2][34]; + +/* Function declarations */ +void init(); +void display(); + + +/* Main function */ +int main(int argc, const char *argv[]) { + + int i,p,xy_temp; + + SVECTOR rot = { 0 }; /* Rotation vector for Rotmatrix */ + VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */ + MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */ + + POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + + + printf( "Arguments passed: %d\n", argc ); + for( i=0; istat == 0 ) { + + // For digital pad, dual-analog and dual-shock + if( ( pad->type == 0x4 ) || ( pad->type == 0x5 ) || ( pad->type == 0x7 ) ) { + + if( !(pad->btn&PAD_SELECT) ) { + break; + } + + } + + } + + /* Set rotation and translation to the matrix */ + RotMatrix( &rot, &mtx ); + TransMatrix( &mtx, &pos ); + + /* Multiply light matrix by rotation matrix so light source */ + /* won't appear relative to the model's rotation */ + MulMatrix0( &light_mtx, &mtx, &lmtx ); + + /* Set rotation and translation matrix */ + gte_SetRotMatrix( &mtx ); + gte_SetTransMatrix( &mtx ); + + /* Set light matrix */ + gte_SetLightMatrix( &lmtx ); + + /* Make the cube SPEEN */ + rot.vx += 16; + rot.vz += 16; + + + /* Draw the cube */ + pol4 = (POLY_F4*)db_nextpri; + + for( i=0; i>2) > OT_LEN ) + continue; + + /* Initialize a quad primitive */ + setPolyF4( pol4 ); + + /* Set the projected vertices to the primitive */ + gte_stsxy0( &pol4->x0 ); + gte_stsxy1( &pol4->x1 ); + gte_stsxy2( &pol4->x2 ); + + /* Compute the last vertex and set the result */ + gte_ldv0( &cube_verts[cube_indices[i].v3] ); + gte_rtps(); + gte_stsxy( &pol4->x3 ); + + /* Load primitive color even though gte_ncs() doesn't use it. */ + /* This is so the GTE will output a color result with the */ + /* correct primitive code. */ + gte_ldrgb( &pol4->r0 ); + + /* Load the face normal */ + gte_ldv0( &cube_norms[i] ); + + /* Normal Color Single */ + gte_ncs(); + + /* Store result to the primitive */ + gte_strgb( &pol4->r0 ); + + /* Sort primitive to the ordering table */ + addPrim( db[db_active].ot+(p>>2), pol4 ); + + /* Advance to make another primitive */ + pol4++; + + } + + /* Update nextpri variable */ + /* (IMPORTANT if you plan to sort more primitives after this) */ + db_nextpri = (char*)pol4; + + /* Swap buffers and draw the primitives */ + display(); + + } + + StopPAD(); + + return 0; + +} + +void init() { + + /* Reset the GPU, also installs a VSync event handler */ + ResetGraph( 0 ); + + /* Set display and draw environment areas */ + /* (display and draw areas must be separate, otherwise hello flicker) */ + SetDefDispEnv( &db[0].disp, 0, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[0].draw, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + + /* Enable draw area clear and dither processing */ + setRGB0( &db[0].draw, 63, 0, 127 ); + db[0].draw.isbg = 1; + db[0].draw.dtd = 1; + + + /* Define the second set of display/draw environments */ + SetDefDispEnv( &db[1].disp, SCREEN_XRES, 0, SCREEN_XRES, SCREEN_YRES ); + SetDefDrawEnv( &db[1].draw, 0, 0, SCREEN_XRES, SCREEN_YRES ); + + setRGB0( &db[1].draw, 63, 0, 127 ); + db[1].draw.isbg = 1; + db[1].draw.dtd = 1; + + + /* Apply the drawing environment of the first double buffer */ + PutDrawEnv( &db[0].draw ); + + + /* Clear both ordering tables to make sure they are clean at the start */ + ClearOTagR( db[0].ot, OT_LEN ); + ClearOTagR( db[1].ot, OT_LEN ); + + /* Set primitive pointer address */ + db_nextpri = db[0].p; + + /* Initialize the GTE */ + InitGeom(); + + /* Set GTE offset (recommended method of centering) */ + gte_SetGeomOffset( CENTERX, CENTERY ); + + /* Set screen depth (basically FOV control, W/2 works best) */ + gte_SetGeomScreen( CENTERX ); + + /* Set light ambient color and light color matrix */ + gte_SetBackColor( 63, 63, 63 ); + gte_SetColorMatrix( &color_mtx ); + + InitPAD(pad_buff[0], 34, pad_buff[1], 34); + StartPAD(); + ChangeClearPAD(0); + +} + +void display() { + + /* Wait for GPU to finish drawing and vertical retrace */ + DrawSync( 0 ); + VSync( 0 ); + + /* Swap buffers */ + db_active ^= 1; + db_nextpri = db[db_active].p; + + /* Clear the OT of the next frame */ + ClearOTagR( db[db_active].ot, OT_LEN ); + + /* Apply display/drawing environments */ + PutDrawEnv( &db[db_active].draw ); + PutDispEnv( &db[db_active].disp ); + + /* Enable display */ + SetDispMask( 1 ); + + /* Start drawing the OT of the last buffer */ + DrawOTag( db[1-db_active].ot+(OT_LEN-1) ); + +} \ No newline at end of file diff --git a/examples/system/childexec/child_exe.s b/examples/system/childexec/child_exe.s index 842ac88..66bd0e2 100644 --- a/examples/system/childexec/child_exe.s +++ b/examples/system/childexec/child_exe.s @@ -3,4 +3,4 @@ .global child_exe # Insert spoopypasta .type child_exe, @object child_exe: - .incbin "child.exe" \ No newline at end of file + .incbin "build/child/child.exe" \ No newline at end of file diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile index 30229ae..e801739 100644 --- a/examples/system/childexec/makefile +++ b/examples/system/childexec/makefile @@ -1,36 +1,93 @@ -include ../../examples-setup.mk +# PSn00bSDK makefile template +# Part of the PSn00bSDK Project +# 2019 - 2021 Lameguy64 / Meido-Tek Productions -INCLUDE += -LIBDIRS += +## Settings -LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc +PSN00BSDK_LIBS ?= ../../../libpsn00b -CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -CPPFLAGS = $(CFLAGS) -fno-exceptions -AFLAGS = -g -msoft-float -LDFLAGS = -g -gc-sections \ - -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x +# 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 -LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000 -LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000 +# Project target name +#TARGET = childexec -all: child parent +## Files -child: build/child.o - $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf - elf2x -q child.elf +# 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 $@ -parent: build/parent.o build/child_exe.o - $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf - elf2x -q parent.elf - build/%.o: %.c @mkdir -p $(dir $@) - $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ - + $(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) $(INCLUDE) -c $< -o $@ - + $(CC) $(AFLAGS_EXE) $(INCLUDE) -c $< -o $@ + clean: - rm -rf build parent.elf parent.exe child.elf child.exe + rm -rf build -- cgit v1.2.3