From 9f4891f95070c66ea9f1aba99d72724d4ab24e5a Mon Sep 17 00:00:00 2001 From: "John Wilbert M. Villamor" Date: Sat, 19 Sep 2020 20:43:05 +0800 Subject: Revised makefiles, added strtok(), command line arguments, SetHeapSize(), moved ISR and callback system to psxetc, moved debug font to psxgpu, fixed CD-ROM library crashing on PSIO, fixed interrupt callback setup to fix crashing on ResetGraph() --- examples/beginner/hello/makefile | 4 +-- examples/cdrom/cdbrowse/main.c | 44 ++++++++++++++---------- examples/cdrom/cdbrowse/makefile | 4 +-- examples/cdrom/cdxa/main.c | 7 ++-- examples/cdrom/cdxa/makefile | 4 +-- examples/demos/n00bdemo/makefile | 4 +-- examples/examples-setup.mk | 63 +++++++++++++++++++++++++++++++++++ examples/graphics/balls/makefile | 4 +-- examples/graphics/billboard/makefile | 4 +-- examples/graphics/fpscam/makefile | 4 +-- examples/graphics/gte/makefile | 4 +-- examples/graphics/render2tex/makefile | 4 +-- examples/graphics/rgb24/makefile | 4 +-- examples/sdk-common.mk | 34 ------------------- examples/system/childexec/child.c | 8 ++++- examples/system/childexec/makefile | 8 ++--- examples/system/childexec/parent.c | 28 ++++++++++++---- examples/system/console/main.c | 2 +- examples/system/console/makefile | 4 +-- examples/system/timer/makefile | 4 +-- examples/system/tty/makefile | 4 +-- 21 files changed, 151 insertions(+), 95 deletions(-) create mode 100644 examples/examples-setup.mk delete mode 100644 examples/sdk-common.mk (limited to 'examples') diff --git a/examples/beginner/hello/makefile b/examples/beginner/hello/makefile index 1893a48..27ca670 100644 --- a/examples/beginner/hello/makefile +++ b/examples/beginner/hello/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk # Project target name TARGET = hello.elf @@ -19,7 +19,7 @@ INCLUDE += LIBDIRS += # Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc # C compiler flags CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections diff --git a/examples/cdrom/cdbrowse/main.c b/examples/cdrom/cdbrowse/main.c index 65475ad..772ddc1 100644 --- a/examples/cdrom/cdbrowse/main.c +++ b/examples/cdrom/cdbrowse/main.c @@ -39,7 +39,7 @@ * * Up/Down - Move selection cursor. * Cross - Enter directory. - * Circle - Go back to root directory. + * Circle - Go back to parent directory. * * * Example by Lameguy64 @@ -48,6 +48,8 @@ * Changelog: * * February 25, 2020: Initial version. + * + * July 12, 2020: Updated CD-ROM directory query logic on disc change slightly. */ #include @@ -70,7 +72,6 @@ #define OT_LEN 8 /* Ordering table length */ - /* Screen coordinates */ #define SCREEN_XRES 320 #define SCREEN_YRES 240 @@ -146,6 +147,9 @@ void init() { int i; + /* Uncomment to send tty messages to SIO */ + //AddSIO( 115200 ); + /* Reset GPU (also installs event handler for VSync) */ printf("Init GPU... "); ResetGraph( 0 ); @@ -158,7 +162,7 @@ void init() /* Initialize SPU and CD-ROM */ printf("Initializing CD-ROM... "); - SpuInit(); + //SpuInit(); CdInit(); printf("Done.\n"); @@ -218,10 +222,14 @@ void init() /* Initialize pad */ + EnterCriticalSection(); + InitPAD(padbuff[0], 34, padbuff[1], 34); StartPAD(); ChangeClearPAD(0); + ExitCriticalSection(); + } @@ -258,6 +266,10 @@ int main(int argc, const char* argv[]) disc_present = false; update_listing = true; + printf( "Calling CdStatus()...\n" ); + CdStatus(); + printf( "Call done.\n" ); + while(1) { /* Set flag if disc has been removed */ @@ -383,23 +395,19 @@ int main(int argc, const char* argv[]) /* Updates directory listing */ if( update_listing ) { - if ( (CdStatus()&0x12) == 0x2 ) + /* Reset path and update label if new disc inserted */ + if( !disc_present ) { - - /* Reset path and update label if new disc inserted */ - if( !disc_present ) - { - strcpy( path, "\\" ); - CdGetVolumeLabel(disc_label); - disc_present = true; - } - - /* Query directory */ - files_found = query_dir( path, files, 40 ); - sel_channel = 0; - list_scroll = 0; - + strcpy( path, "\\" ); + CdGetVolumeLabel(disc_label); + disc_present = true; } + + /* Query directory */ + files_found = query_dir( path, files, 40 ); + sel_channel = 0; + list_scroll = 0; + update_listing = false; } diff --git a/examples/cdrom/cdbrowse/makefile b/examples/cdrom/cdbrowse/makefile index f5ee962..adbc9cb 100644 --- a/examples/cdrom/cdbrowse/makefile +++ b/examples/cdrom/cdbrowse/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = cdbrowse.elf @@ -10,7 +10,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) PREFIX = mipsel-unknown-elf- -LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc +LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) \ diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c index 55cb508..0112437 100644 --- a/examples/cdrom/cdxa/main.c +++ b/examples/cdrom/cdxa/main.c @@ -235,14 +235,13 @@ void init() { int i; + /* Uncomment to direct tty messages to serial */ + //AddSIO(115200); + /* Reset GPU (also installs event handler for VSync) */ printf("Init GPU... "); ResetGraph( 0 ); printf("Done.\n"); - - - /* Uncomment to direct tty messages to serial */ - AddSIO(115200); /* Initialize SPU and CD-ROM */ diff --git a/examples/cdrom/cdxa/makefile b/examples/cdrom/cdxa/makefile index 8858979..3e46301 100644 --- a/examples/cdrom/cdxa/makefile +++ b/examples/cdrom/cdxa/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = cdxa.elf @@ -10,7 +10,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) PREFIX = mipsel-unknown-elf- -LIBS = -lpsxcd -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxapi -lc +LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) \ diff --git a/examples/demos/n00bdemo/makefile b/examples/demos/n00bdemo/makefile index 63dc345..f90fb11 100644 --- a/examples/demos/n00bdemo/makefile +++ b/examples/demos/n00bdemo/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = demo.elf @@ -9,7 +9,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) INCLUDE += -I../../../libpsn00b/lzp -LIBS = -llzp -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -llzp -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/examples-setup.mk b/examples/examples-setup.mk new file mode 100644 index 0000000..a5cfc20 --- /dev/null +++ b/examples/examples-setup.mk @@ -0,0 +1,63 @@ +# PSn00bSDK examples setup file +# Part of the PSn00bSDK Project +# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# +# This is only for the PSn00bSDK example programs, not recommended +# for use with user projects + +PREFIX = mipsel-unknown-elf- + +ifndef GCC_VERSION + +GCC_VERSION = 7.4.0 + +endif # GCC_VERSION + +# PSn00bSDK library/include path setup +ifndef PSN00BSDK_LIBS + +# Default assumes libpsn00b is just in the parent dir of the examples dir + +LIBDIRS = -L../../../libpsn00b +INCLUDE = -I../../../libpsn00b/include + +else + +LIBDIRS = -L$(PSN00BSDK_LIBS) +INCLUDE = -I$(PSN00BSDK_LIBS)/include + +endif # PSN00BSDK_LIBS + +# PSn00bSDK toolchain path setup +ifndef GCC_BASE + +ifndef PSN00BSDK_TC + +# Default assumes GCC toolchain is in root of C drive or /usr/local + +ifeq "$(OS)" "Windows_NT" + +GCC_BASE = /c/mipsel-unknown-elf +GCC_BIN = + +else + +GCC_BASE = /usr/local/mipsel-unknown-elf +GCC_BIN = + +endif + +else + +GCC_BASE = $(PSN00BSDK_TC) +GCC_BIN = $(PSN00BSDK_TC)/bin/ + +endif # PSN00BSDK_TC + +endif # GCC_BASE + +CC = $(GCC_BIN)$(PREFIX)gcc +CXX = $(GCC_BIN)$(PREFIX)g++ +AS = $(GCC_BIN)$(PREFIX)as +AR = $(GCC_BIN)$(PREFIX)ar +RANLIB = $(GCC_BIN)$(PREFIX)ranlib \ No newline at end of file diff --git a/examples/graphics/balls/makefile b/examples/graphics/balls/makefile index 50ed0f1..c5ae67b 100644 --- a/examples/graphics/balls/makefile +++ b/examples/graphics/balls/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk # Project target name TARGET = balls.elf @@ -19,7 +19,7 @@ INCLUDE += LIBDIRS += # Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc # C compiler flags CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections diff --git a/examples/graphics/billboard/makefile b/examples/graphics/billboard/makefile index d6add7a..6537d49 100644 --- a/examples/graphics/billboard/makefile +++ b/examples/graphics/billboard/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = billboard.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/graphics/fpscam/makefile b/examples/graphics/fpscam/makefile index 339bb91..fe62ea8 100644 --- a/examples/graphics/fpscam/makefile +++ b/examples/graphics/fpscam/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = fpscam.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/graphics/gte/makefile b/examples/graphics/gte/makefile index 8b3f81f..2cd5ed5 100644 --- a/examples/graphics/gte/makefile +++ b/examples/graphics/gte/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = gte.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/graphics/render2tex/makefile b/examples/graphics/render2tex/makefile index aaa3b1d..a6c2e91 100644 --- a/examples/graphics/render2tex/makefile +++ b/examples/graphics/render2tex/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = render2tex.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lc -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lgcc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/graphics/rgb24/makefile b/examples/graphics/rgb24/makefile index 61ef24f..ca99600 100644 --- a/examples/graphics/rgb24/makefile +++ b/examples/graphics/rgb24/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = rgb24.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lpsxgpu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/sdk-common.mk b/examples/sdk-common.mk deleted file mode 100644 index 0503b57..0000000 --- a/examples/sdk-common.mk +++ /dev/null @@ -1,34 +0,0 @@ -# Adjustable common makefile values for PSn00bSDK example programs. -# You may need to modify these values to match with your toolchain setup. - -# Toolchain prefix -PREFIX = mipsel-unknown-elf- - -# Include directories -INCLUDE = -I../../../libpsn00b/include - -# Library directories, last entry must point toolchain libraries -LIBDIRS = -L../../../libpsn00b - -ifndef GCC_VERSION - -GCC_VERSION = 7.4.0 - -endif - -ifndef GCC_BASE - -ifeq "$(OS)" "Windows_NT" # For Windows - -GCC_BASE = /c/mipsel-unknown-elf - -else # For Linux/BSDs - -GCC_BASE = /usr/local/mipsel-unknown-elf - -endif - -endif - -LIBDIRS += -L$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION) -INCLUDE += -I$(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION)/include diff --git a/examples/system/childexec/child.c b/examples/system/childexec/child.c index fb38b63..2ed656b 100644 --- a/examples/system/childexec/child.c +++ b/examples/system/childexec/child.c @@ -102,7 +102,7 @@ void display(); /* Main function */ -int main() { +int main(int argc, const char *argv[]) { int i,p,xy_temp; @@ -113,6 +113,12 @@ int main() { POLY_F4 *pol4; /* Flat shaded quad primitive pointer */ + printf( "Arguments passed: %d\n", argc ); + for( i=0; iparam, 0, 0); + Exec(&exe->param, 3, args); - // Reset previous handler + // Restore interrupts for this PS-EXE EnterCriticalSection(); RestartCallback(); ExitCriticalSection(); @@ -300,6 +313,7 @@ void run_child() { ChangeClearPAD(0); // Set this program's display mode + SetDispMask(0); PutDispEnv(&disp); } diff --git a/examples/system/console/main.c b/examples/system/console/main.c index 988b428..405f0d6 100644 --- a/examples/system/console/main.c +++ b/examples/system/console/main.c @@ -172,7 +172,7 @@ int main(int argc, const char* argv[]) { /* Uncomment this line if you don't have tty interfaces * provided by n00brom or similar development environments with tty */ - AddSIO(115200); + //AddSIO(115200); /* Main loop */ diff --git a/examples/system/console/makefile b/examples/system/console/makefile index 0c27b55..d7e9374 100644 --- a/examples/system/console/makefile +++ b/examples/system/console/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk # Project target name TARGET = console.elf @@ -19,7 +19,7 @@ INCLUDE += LIBDIRS += # Libraries to link -LIBS = -lpsxsio -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxsio -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc # C compiler flags CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections diff --git a/examples/system/timer/makefile b/examples/system/timer/makefile index c35c445..3fe1562 100644 --- a/examples/system/timer/makefile +++ b/examples/system/timer/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk TARGET = timer.elf @@ -11,7 +11,7 @@ OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o) INCLUDE += LIBDIRS += -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile index a3884ad..d0a8caa 100644 --- a/examples/system/tty/makefile +++ b/examples/system/tty/makefile @@ -1,4 +1,4 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk # Project target name TARGET = tty.elf @@ -19,7 +19,7 @@ INCLUDE += LIBDIRS += # Libraries to link -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lpsxapi -lc +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc # C compiler flags CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections -- cgit v1.2.3