diff options
| author | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-09-19 20:43:05 +0800 |
|---|---|---|
| committer | John Wilbert M. Villamor <lameguy64@gmail.com> | 2020-09-19 20:43:05 +0800 |
| commit | 9f4891f95070c66ea9f1aba99d72724d4ab24e5a (patch) | |
| tree | 723e3ef2118a3d1a9e6dafa811ed1b8b1bc9196e | |
| parent | 6762c39551ded059450d17d8bb0cb80642c8aaab (diff) | |
| download | psn00bsdk-9f4891f95070c66ea9f1aba99d72724d4ab24e5a.tar.gz | |
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()
65 files changed, 1368 insertions, 680 deletions
@@ -28,7 +28,7 @@ performance reasons. ## Notable features -As of LibPSn00b run-time library v0.15b +As of September 19, 2020 * Extensive GPU support with polygon primitives, high-speed DMA VRAM transfers and DMA ordering table processing. All video modes for both NTSC @@ -48,7 +48,7 @@ As of LibPSn00b run-time library v0.15b programs. * Complete Serial I/O support with SIOCONS driver for tty console access - through serial interface. + through serial interface. Handshake and flow control also supported. * BIOS controller functions for polling controller input work as intended thanks to proper interrupt handling. No crude manual polling of controllers @@ -57,8 +57,8 @@ As of LibPSn00b run-time library v0.15b * Full CD-ROM support with data reading, CD audio and XA audio playback. Features built-in ISO9660 file system parser for locating files and supports directories containing more than 30 files (classic ISO9660 only, - no Rock Ridge or Joliet extensions support). Data streaming should also be - possible. + no Rock Ridge or Joliet extensions support). Also supports multi-session + discs. * Uses Sony SDK library syntax for familiarity to experienced programmers and to make porting existing homebrew projects to PSn00bSDK easier. @@ -86,6 +86,21 @@ under Windows than on Linux and BSDs. ## Building the SDK +You may set one of the following variables either with set/export or on the +make command line to specify various parameters in building PSn00bSDK and +projects made with it. + +* ``GCC_VERSION`` specifies the GCC version number. This is only really + required for building the libc library. If not defined, the default value + of `7.4.0` is used. +* ``PSN00BSDK_TC`` specifies the base directory of the GCC toolchain to + build PSn00bSDK with, otherwise the makefile assumes you have the + toolchain binaries in one of your PATH directories. +* ``PSN00BSDK_LIBS`` specifies the target directory you wish to install + the compiled libpsn00b libraries to. If not specified, compiled + libraries are consolidated to the libpsn00b directory. + + ### Windows: 1. Download the following: * MSys2 (32-bit or 64-bit version whichever you prefer) @@ -127,20 +142,20 @@ programs with PSn00bSDK within the Command Prompt. ### Linux and Unix-likes: 1. Install gcc, make, texinfo, git and development packages of mpfr, mpc, - gmp, isl and tinyxml2 libraries. + gmp, isl and tinyxml2 libraries for your distro. 2. Build and install the GNU GCC toolchain targeting mipsel-unknown-elf - (see toolchain.txt for details). Update your PATH environment variable to - include the bin directory of the toolchain and make sure they can be - accessed from any directory. + (see toolchain.txt for details). Export a variable named `PSN00BSDK_TC` + containing a path to the installed toolchain's base directory. Also + export a `GCC_VERSION` variable if you're using a version of GCC other + than 7.4.0. 3. Clone from PSn00bSDK source with `git clone https://github.com/lameguy64/psn00bsdk` 4. Enter tools directory and run `make`, then `make install` to consolidate the tools to a bin directory. Add this directory to your PATH variable and - make sure `elf2x` is accessible from any directory. -5. Enter the libpsn00b directory and run `make`. You may need to edit the - `common.mk` file to correspond with the GCC version you're using. + make sure `elf2x` and `lzpack` (required for n00bDEMO) is accessible from + any directory. +5. Enter the libpsn00b directory and run `make`. 6. Compile the example programs to test if the SDK is set up correctly. - Update directory paths in `sdk-common.mk` when necessary. ## Examples @@ -177,6 +192,10 @@ If modifications to the SDK were made as part of the development of such projects that enhance its functionality, such changes must be contributed back in return. +Homebrew made with PSn00bSDK may not be released under 'annoyingmous'. Although +there's nothing that would enforce it, this term may as well be ignored despite +it annoying this SDK's author. + ## Credits @@ -184,7 +203,7 @@ Main developer: * Lameguy64 Honorable mentions: -* ijacquez (for the helpful suggestions on getting C++ working) +* ijacquez (for the helpful suggestions for getting C++ working) Helpful contributors can be found in the changelog. diff --git a/changelog.txt b/changelog.txt index 23d662d..3076656 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,71 @@ PSn00bSDK changelog Items that are lower in the log are more recently implemented. +09-19-2020 by Lameguy64: + +* libpsn00b: Revised makefiles for building the libraries and examples in a + way to make building with different toolchain versions easier with the + PSN00BSDK_TC environment variable. Library installation and linking is + also made easier with the PSN00BSDK_LIBS environment variable. See readme + in the libpsn00b directory for details. + +* examples: Fixed libgcc not found error when compiling some of the examples. + +* libc: Added strtok(). + +* libc: Added support for command line arguments. Pass arguments via + SYSTEM.CNF BOOT= string or a string array with Exec(). Arguments can + be read via argc/argv[] in main() or __argc/__argv anywhere else. + +* libc: Added SetHeapSize(). + +* psxgpu: Moved ISR and callback subsystem to psxetc. You'll have to link + psxetc after psxgpu and psxapi after psxetc in your library string. + +* psxetc: Moved debug font functions (FntInit(), FntOpen(), etc) to psxgpu. + +* psxetc: Fixed stack management in RestartCallback(). + +* examples: Added argument passing in childexec example. + +* psxcd: Fixed crashing on PSIO and possibly some emulators by implementing + a response buffer read limiter. + +* psxgpu: Interrupts are now disabled before setting up ISR and callbacks + in ResetGraph(), as LoadExec() still has interrupts enabled when jumping + to the loaded PS-EXE's entrypoint. Fixes programs made with PSn00bSDK + crashing at ResetGraph() on PSIO when loading from the Menu System and + possibly some emulators. + + +07-25-2020 by Lameguy64: + +* psxgte: Added ScaleMatrixL(). + +* doc: Corrected documentation for CdReadSync() function. + +* psxcd: Added new define: CdlIsoLidOpen. + +* psxcd: Updated media change detection logic, media change is checked + by lid open status bit in all CD-ROM file functions. CdControl() calls will + also trigger the media change status on lid open. + +* psxcd: Fixed bug in CdGetVolumeLabel() where it constantly reparses the file + system regardless of media change status. + +* examples: Updated cdrom/cdbrowse example slightly. + +* psxcd: Added CdLoadSession(). + +* psxcd: Fixed bug where CdReadDir() locks up in an infinite loop when it + encounters a NULL directory record, and the parser has not yet exceeded the + length of the directory record. + +* doc: Replaced library version numbers with SVN revision numbers in the + introduced fields. + +* doc: Started work on CD-ROM library overview. + 04-24-2020 by Lameguy64: 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 <stdio.h> @@ -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; i<argc; i++ ) + { + printf( "%s\n", argv[i] ); + } + /* Init graphics and GTE */ init(); diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile index 79a27b6..4475832 100644 --- a/examples/system/childexec/makefile +++ b/examples/system/childexec/makefile @@ -1,9 +1,9 @@ -include ../../sdk-common.mk +include ../../examples-setup.mk INCLUDE += LIBDIRS += -LIBS = -lpsxetc -lpsxgpu -lpsxgte -lpsxspu -lc -lpsxapi +LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections CPPFLAGS = $(CFLAGS) -fno-exceptions @@ -20,11 +20,11 @@ all: child parent child: build/child.o $(LD) $(LDFLAGS_C) $(LIBDIRS) build/child.o $(LIBS) -o child.elf - elf2x child.elf + elf2x -q child.elf parent: build/parent.o build/child_exe.o $(LD) $(LDFLAGS_P) $(LIBDIRS) build/parent.o build/child_exe.o $(LIBS) -o parent.elf - elf2x parent.elf + elf2x -q parent.elf build/%.o: %.c @mkdir -p $(dir $@) diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c index 7f577e4..ed5710a 100644 --- a/examples/system/childexec/parent.c +++ b/examples/system/childexec/parent.c @@ -2,9 +2,14 @@ * LibPSn00b Example Programs * * Child Program Execution Example - * 2019 Meido-Tek Productions / PSn00bSDK Project + * 2020 Meido-Tek Productions / PSn00bSDK Project * - * This is a modification of the balls example, modified to execute + * This example demonstrates how to execute a child PS-EXE from a parent + * PS-EXE using the Exec() function, and transferring execution back from + * the child PS-EXE to the parent PS-EXE. Passing arguments to the child + * PS-EXE is also demonstrated here. + * + * This is actually a modification of the balls example, modified to execute * a child program for this example. * * Example by Lameguy64 @@ -88,9 +93,6 @@ void init() { PutDispEnv( &disp ); PutDrawEnv( &draw ); - /* Enable video output */ - SetDispMask( 1 ); - printf("Done.\n"); @@ -232,6 +234,9 @@ int main(int argc, const char* argv[]) { DrawSync( 0 ); VSync( 0 ); + /* Enable video output */ + SetDispMask( 1 ); + /* Since draw.isbg is non-zero this clears the screen */ PutDrawEnv( &draw ); @@ -265,6 +270,14 @@ void SetDefaultExitFromException(); void run_child() { + // Arguments for the child program + char *args[] = + { + "SAMPLE=0", + "SESSION=1", + "ARGH!" + }; + // So child header is readable EXE_HEAD *exe = (EXE_HEAD*)child_exe; @@ -287,9 +300,9 @@ void run_child() { // Execute child printf("Child exec!\n"); - Exec(&exe->param, 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 diff --git a/libpsn00b/common.mk b/libpsn00b/common.mk deleted file mode 100644 index d15d4a5..0000000 --- a/libpsn00b/common.mk +++ /dev/null @@ -1,35 +0,0 @@ -# Adjustable common makefile values for PSn00bSDK example programs. -# You may need to modify these values to match with your toolchain setup. - -# GCC version -ifndef GCC_VERSION - -GCC_VERSION = 7.4.0 - -endif - -# GCC base paths -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 - - -# Toolchain prefix -PREFIX = mipsel-unknown-elf- - -# Include directories -INCLUDE = -I../include - -# Finish paths -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/libpsn00b/include/hwregs_a.h b/libpsn00b/include/hwregs_a.h index 9d4313b..d9f46ba 100644 --- a/libpsn00b/include/hwregs_a.h +++ b/libpsn00b/include/hwregs_a.h @@ -21,6 +21,7 @@ .set CD_REG2, 0x1802 .set CD_REG3, 0x1803 +.set SBUS_5, 0x1018 .set COM_DELAY, 0x1020 # SPU (must be used with 16-bit load/store instructions) diff --git a/libpsn00b/include/malloc.h b/libpsn00b/include/malloc.h index e6cd126..d94823f 100644 --- a/libpsn00b/include/malloc.h +++ b/libpsn00b/include/malloc.h @@ -7,6 +7,7 @@ extern "C" { unsigned int *GetBSSend(); void InitHeap(unsigned int *addr, int size); +int SetHeapSize(int size); void *malloc(int size); void free(void *ptr); diff --git a/libpsn00b/include/psxapi.h b/libpsn00b/include/psxapi.h index 0953dc3..c366702 100644 --- a/libpsn00b/include/psxapi.h +++ b/libpsn00b/include/psxapi.h @@ -179,7 +179,7 @@ void ChangeClearPAD(int mode); void ChangeClearRCnt(int t, int m); // Executable functions -int Exec(struct EXEC *exec, int argc, char *argv); +int Exec(struct EXEC *exec, int argc, char **argv); void _boot(void); diff --git a/libpsn00b/include/psxcd.h b/libpsn00b/include/psxcd.h index 072a219..6616b53 100644 --- a/libpsn00b/include/psxcd.h +++ b/libpsn00b/include/psxcd.h @@ -72,6 +72,7 @@ #define CdlIsoSeekError 0x01 #define CdlIsoReadError 0x02 #define CdlIsoInvalidFs 0x03 +#define CdlIsoLidOpen 0x04 #define btoi(b) ((b)/16*10+(b)%16) /* Convert BCD value to integer */ #define itob(i) ((i)/10*16+(i)%10) /* Convert integer to BCD value */ @@ -161,6 +162,8 @@ int CdGetVolumeLabel(char* label); long* CdAutoPauseCallback(void(*func)()); int CdIsoError(); +int CdLoadSession(int session); + #ifdef __cplusplus } #endif diff --git a/libpsn00b/include/psxetc.h b/libpsn00b/include/psxetc.h index d0c8bc1..a55e593 100644 --- a/libpsn00b/include/psxetc.h +++ b/libpsn00b/include/psxetc.h @@ -5,11 +5,11 @@ extern "C" { #endif -void FntLoad(int x, int y); -char *FntSort(unsigned int *ot, char *pri, int x, int y, const char *text); -int FntOpen(int x, int y, int w, int h, int isbg, int n); -int FntPrint(int id, const char *fmt, ...); -char *FntFlush(int id); +// Interrupt callback functions +void *DMACallback(int dma, void (*func)(void)); +void *InterruptCallback(int irq, void (*func)(void)); +void *GetInterruptCallback(int irq); // Original +void RestartCallback(); #ifdef __cplusplus } diff --git a/libpsn00b/include/psxgpu.h b/libpsn00b/include/psxgpu.h index 01b3280..bcd1835 100644 --- a/libpsn00b/include/psxgpu.h +++ b/libpsn00b/include/psxgpu.h @@ -560,12 +560,6 @@ void WaitGPUdma(void); void *VSyncCallback(void (*func)(void)); void *DrawSyncCallback(void (*func)(void)); -// Interrupt callback functions -void *DMACallback(int dma, void (*func)(void)); -void *InterruptCallback(int irq, void (*func)(void)); -void *GetInterruptCallback(int irq); // Original -void RestartCallback(); - void LoadImage(RECT *rect, unsigned int *data); void StoreImage(RECT *rect, unsigned int *data); @@ -582,6 +576,14 @@ int GetTimInfo(unsigned int *tim, TIM_IMAGE *timimg); DISPENV *SetDefDispEnv(DISPENV *disp, int x, int y, int w, int h); DRAWENV *SetDefDrawEnv(DRAWENV *draw, int x, int y, int w, int h); +// Debug font functions + +void FntLoad(int x, int y); +char *FntSort(unsigned int *ot, char *pri, int x, int y, const char *text); +int FntOpen(int x, int y, int w, int h, int isbg, int n); +int FntPrint(int id, const char *fmt, ...); +char *FntFlush(int id); + #ifdef __cplusplus } #endif diff --git a/libpsn00b/include/psxgte.h b/libpsn00b/include/psxgte.h index 98d9fa4..da9aff6 100644 --- a/libpsn00b/include/psxgte.h +++ b/libpsn00b/include/psxgte.h @@ -58,6 +58,7 @@ MATRIX *HiRotMatrix(VECTOR *r, MATRIX *m); MATRIX *TransMatrix(MATRIX *m, VECTOR *r); MATRIX *ScaleMatrix(MATRIX *m, VECTOR *s); +MATRIX *ScaleMatrixL(MATRIX *m, VECTOR *s); MATRIX *MulMatrix(MATRIX *m0, MATRIX *m1); MATRIX *MulMatrix0(MATRIX *m0, MATRIX *m1, MATRIX *m2); diff --git a/libpsn00b/include/stdlib.h b/libpsn00b/include/stdlib.h index 845cbea..474eba6 100644 --- a/libpsn00b/include/stdlib.h +++ b/libpsn00b/include/stdlib.h @@ -45,6 +45,9 @@ void *realloc(void *buf , int n); extern "C" { #endif +extern int __argc; +extern char __argv[]; + int rand(); void srand(unsigned long seed); diff --git a/libpsn00b/libc/makefile b/libpsn00b/libc/makefile index c925b53..f639823 100644 --- a/libpsn00b/libc/makefile +++ b/libpsn00b/libc/makefile @@ -1,24 +1,29 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libc.a +TARGET = libc.a -CFILES = $(notdir $(wildcard ./*.c)) -CXXFILES = $(notdir $(wildcard ./*.cxx)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CXXFILES:.cxx=.o) $(AFILES:.s=.o)) +INCLUDE = -I../include -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,-strip-local-absolute +CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -Wa,-strip-local-absolute -CC = $(PREFIX)gcc -CXX = $(PREFIX)g++ -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFILES = $(notdir $(wildcard ./*.c)) +CXXFILES = $(notdir $(wildcard ./*.cxx)) +AFILES = $(notdir $(wildcard ./*.s)) + +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CXXFILES:.cxx=.o) \ + $(AFILES:.s=.o)) + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -39,5 +44,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/libc/malloc.s b/libpsn00b/libc/malloc.s index fdb196d..90f9bd4 100644 --- a/libpsn00b/libc/malloc.s +++ b/libpsn00b/libc/malloc.s @@ -38,6 +38,17 @@ InitHeap: jr $ra sw $0 , ND_SIZE($a0) + +# Changes the heap size without clearing or relocating the heap +# a0 - Size of memory heap in bytes +.global SetHeapSize +.type SetHeapSize, @function +SetHeapSize: + la $v1, _malloc_size + lw $v0, 0($v1) + jr $ra + sw $a1, 0($v1) + # Allocates a block of memory in the heap # a0 - Size of memory block to allocate. diff --git a/libpsn00b/libc/start.c b/libpsn00b/libc/start.c index c234e03..354ebb9 100644 --- a/libpsn00b/libc/start.c +++ b/libpsn00b/libc/start.c @@ -1,4 +1,5 @@ #include <stdio.h> +#include <string.h> #include <malloc.h> #define load_gp() __asm__ volatile ( \ @@ -9,6 +10,11 @@ extern int main(int argc, const char* argv[]); void _mem_init(void); +int __argc; +const char **__argv; + +static const char *_arg_ptrs_int[8]; +static char _arg_buff[132]; static void _call_global_ctors(void) { @@ -36,8 +42,50 @@ static void _call_global_dtors(void) } } -void _start(void) { +void _parse_args( int argc, const char *args[] ) +{ + int i; + char *c,*s; + + memset( _arg_buff, 0, 132 ); + + if( !args ) + { + // Use arguments from kernel if args is NULL + strncpy( _arg_buff, (char*)0x180, 128 ); + + // Clean-up args froom stray line-ends + while( ( c = strrchr( _arg_buff, '\r' ) ) || + ( c = strrchr( _arg_buff, '\n' ) ) ) + *c = 0; + } + else + { + __argc = argc; + __argv = args; + return; + } + + __argc = 0; + for( i=0; i<8; i++ ) + _arg_ptrs_int[i] = 0; + s = _arg_buff; + while( c = strtok( s, " " ) ) + { + _arg_ptrs_int[__argc] = c; + __argc++; + s = NULL; + if( __argc >= 8 ) + break; + } + + __argv = _arg_ptrs_int; + +} /* parse_args */ + +void _start( int argc, const char *args[] ) +{ // Load GP address load_gp(); @@ -48,10 +96,15 @@ void _start(void) { // stupid gp relative addressing _mem_init(); + // process command line arguments + _parse_args( argc, args ); + _call_global_ctors(); - main(0, NULL); + *((int*)0x8000DFFC) = main( __argc, __argv ); _call_global_dtors(); -}
\ No newline at end of file + // Set return value to kernel return value area + +} /* _start */
\ No newline at end of file diff --git a/libpsn00b/libc/string.c b/libpsn00b/libc/string.c index 0b7307d..e11ed67 100644 --- a/libpsn00b/libc/string.c +++ b/libpsn00b/libc/string.c @@ -302,6 +302,48 @@ double strtod(const char *nptr, char **endptr) return (i + d)*s; } +/* implementation by Lameguy64, behaves like OpenWatcom's strtok() */ +/* BIOS strtok seemed either bugged, or designed for wide chars */ + +static char *_strtok_curpos; +static char *_strtok_endpos; + +char *strtok( char *s1, char *s2 ) +{ + char *c,*t; + + if( s1 ) + { + _strtok_curpos = s1; + _strtok_endpos = s1+strlen( s1 ); + } + else + { + if( _strtok_curpos >= _strtok_endpos ) + return( NULL ); + } + + if( !*_strtok_curpos ) + return( NULL ); + + if( c = strstr( _strtok_curpos, s2 ) ) + { + *c = 0; + t = _strtok_curpos; + _strtok_curpos = c+1; + return( t ); + } + else + { + t = _strtok_curpos; + _strtok_curpos += strlen( t ); + return( t ); + } + + return( NULL ); + +} /* strtok */ + long double strtold(const char *nptr, char **endptr) { return (long double)strtod(nptr, endptr); @@ -310,4 +352,4 @@ long double strtold(const char *nptr, char **endptr) float strtof(const char *nptr, char **endptr) { return (float)strtod(nptr, endptr); -} +}
\ No newline at end of file diff --git a/libpsn00b/lzp/makefile b/libpsn00b/lzp/makefile index aa495b5..ce830c2 100644 --- a/libpsn00b/lzp/makefile +++ b/libpsn00b/lzp/makefile @@ -1,15 +1,24 @@ -include ../common.mk +# Run using make (Linux) or gmake (BSD) +# Part of the PSn00bSDK Project +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -TARGET = ../liblzp.a +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -OFILES = $(addprefix build/,$(CFILES:.c=.o)) +TARGET = liblzp.a -CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections -ffunction-sections -Wa,--strip-local-absolute +INCLUDE = -I../include -CC = $(PREFIX)gcc -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFILES = $(notdir $(wildcard ./*.c)) +OFILES = $(addprefix build/,$(CFILES:.c=.o)) + +CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -21,5 +30,11 @@ build/%.o: %.c @mkdir -p build $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(OFILES) $(TARGET) diff --git a/libpsn00b/makefile b/libpsn00b/makefile index b3f6896..c2cf62f 100644 --- a/libpsn00b/makefile +++ b/libpsn00b/makefile @@ -1,16 +1,23 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions TOPTARGETS = all clean -LIBDIRS = libc lzp psxgpu psxgte psxapi psxetc psxspu psxsio psxcd +LIBS = libc psxgpu psxapi psxgte psxcd psxetc psxsio psxspu lzp +$(TOPTARGETS): $(LIBS) -$(TOPTARGETS): $(LIBDIRS) -$(LIBDIRS): - @$(MAKE) -C $@ $(MAKECMDGOALS) +install: $(LIBS) +ifdef PSN00BSDK_LIBS +ifneq ($(CURDIR),$(PSN00BSDK_LIBS)) # needs a better method + cp -R include $(PSN00BSDK_LIBS)/include +endif +endif -clean: $(LIBDIRS) +clean: $(LIBS) -.PHONY: $(TOPTARGETS) $(LIBDIRS) +$(LIBS): + @$(MAKE) -C $@ $(MAKECMDGOALS) + +.PHONY: $(TOPTARGETS) $(LIBS) diff --git a/libpsn00b/psxapi/makefile b/libpsn00b/psxapi/makefile index 819dc0a..356c162 100644 --- a/libpsn00b/psxapi/makefile +++ b/libpsn00b/psxapi/makefile @@ -1,22 +1,25 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxapi.a +TARGET = libpsxapi.a -SOURCES = stdio fs sys +INCLUDE = -I../include -AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s)) -OFILES = $(addprefix build/,$(AFILES:.s=.o)) +SOURCES = stdio fs sys -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +AFILES = $(foreach dir,$(SOURCES),$(wildcard $(dir)/*.s)) +OFILES = $(addprefix build/,$(AFILES:.s=.o)) -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +AFLAGS = -g -msoft-float -Wa,--strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -28,5 +31,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxcd/_cd_control.s b/libpsn00b/psxcd/_cd_control.s index 7f69266..c4153ff 100644 --- a/libpsn00b/psxcd/_cd_control.s +++ b/libpsn00b/psxcd/_cd_control.s @@ -15,6 +15,24 @@ _cd_control: # a1 - pointer to parameters # a2 - length of parameters + addiu $sp, -16 + sw $ra, 0($sp) + sw $a0, 4($sp) + sw $a1, 8($sp) + sw $a2, 12($sp) + +# move $a3, $a2 # Debug +# move $a2, $a1 +# move $a1, $a0 +# la $a0, _cd_control_msg +# jal printf +# addiu $sp, -16 +# addiu $sp, 16 + + lw $a0, 4($sp) + lw $a1, 8($sp) + lw $a2, 12($sp) + li $v0, 1 # Set acknowledge wait flag la $v1, _cd_ack_wait sb $v0, 0($v1) @@ -80,6 +98,15 @@ _cd_control: li $v0, 0x40 sb $v0, CD_REG3($v1) +#.Lflush_response: # Flush response FIFO +# lbu $v0, CD_REG1($v1) +# nop +# lbu $v0, CD_REG0($v1) +# nop +# andi $v0, 0x20 +# beqz $v0, .Lflush_response +# nop + .Lcmd_wait: # Wait for CD to become ready for commands lbu $v0, CD_REG0($v1) nop @@ -104,6 +131,14 @@ _cd_control: sb $0 , CD_REG0($v1) # Feed command value sb $a0, CD_REG1($v1) + lw $ra, 0($sp) + addiu $sp, 16 jr $ra nop + + +#.section .data + +#_cd_control_msg: +# .asciiz "CdControl(%d, %x, %d)\n"
\ No newline at end of file diff --git a/libpsn00b/psxcd/cdgetsector.s b/libpsn00b/psxcd/cdgetsector.s index 70039bf..9af3543 100644 --- a/libpsn00b/psxcd/cdgetsector.s +++ b/libpsn00b/psxcd/cdgetsector.s @@ -10,12 +10,12 @@ CdGetSector: lui $a2, IOBASE -.Lwait_fifo: - lbu $v0, CD_REG0($a2) - nop - andi $v0, 0x40 - beqz $v0, .Lwait_fifo - nop +#.Lwait_fifo: # Probably redundant as the BIOS CD-ROM +# lbu $v0, CD_REG0($a2) # routines do not not wait for this +# nop +# andi $v0, 0x40 +# beqz $v0, .Lwait_fifo +# nop lui $v0, 0x1 srl $a1, 2 @@ -27,11 +27,13 @@ CdGetSector: sw $v0, D3_CHCR($a2) nop nop -.Ldma_wait: + +.Ldma_wait: # Ensure DMA transfer has completed lw $v0, D3_CHCR($a2) nop srl $v0, 24 andi $v0, 0x1 + bnez $v0, .Ldma_wait nop diff --git a/libpsn00b/psxcd/isofs.c b/libpsn00b/psxcd/isofs.c index 149f746..11dba6c 100644 --- a/libpsn00b/psxcd/isofs.c +++ b/libpsn00b/psxcd/isofs.c @@ -4,152 +4,11 @@ #include <psxgpu.h> #include <psxsio.h> #include "psxcd.h" +#include "isofs.h" // Uncommend to enable debug output //#define DEBUG -#pragma pack(push, 1) - -/// Structure of a double-endian unsigned short word -typedef struct ISO_USHORT_PAIR -{ - unsigned short lsb; /// LSB format 16-bit word - unsigned short msb; /// MSB format 16-bit word -} ISO_USHORT_PAIR; - -/// Structure of a double-endian unsigned int word -typedef struct ISO_UINT_PAIR -{ - unsigned int lsb; /// LSB format 32-bit word - unsigned int msb; /// MSB format 32-bit word -} ISO_UINT_PAIR; - -/// ISO descriptor header structure -typedef struct ISO_DESCRIPTOR_HEADER -{ - unsigned char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator) - char id[5]; /// Volume descriptor ID (always CD001) - unsigned short version; /// Volume descriptor version (always 0x01) -} ISO_DESCRIPTOR_HEADER; - -/// Structure of a date stamp for ISO_DIR_ENTRY structure -typedef struct ISO_DATESTAMP -{ - unsigned char year; /// number of years since 1900 - unsigned char month; /// month, where 1=January, 2=February, etc. - unsigned char day; /// day of month, in the range from 1 to 31 - unsigned char hour; /// hour, in the range from 0 to 23 - unsigned char minute; /// minute, in the range from 0 to 59 - unsigned char second; /// Second, in the range from 0 to 59 - unsigned char GMToffs; /// Greenwich Mean Time offset -} ISO_DATESTAMP; - -/// Structure of an ISO path table entry (specifically for the cd::IsoReader class) -typedef struct ISO_PATHTABLE_ENTRY -{ - unsigned char nameLength; /// Name length (or 1 for the root directory) - unsigned char extLength; /// Number of sectors in extended attribute record - unsigned int dirOffs; /// Number of the first sector in the directory, as a double word - unsigned short dirLevel; /// Index of the directory record's parent directory - /// If nameLength is odd numbered, a padding byte will be present after the identifier text. -} ISO_PATHTABLE_ENTRY; - -typedef struct ISO_DIR_ENTRY -{ - unsigned char entryLength; // Directory entry length (variable, use for parsing through entries) - unsigned char extLength; // Extended entry data length (always 0) - ISO_UINT_PAIR entryOffs; // Points to the LBA of the file/directory entry - ISO_UINT_PAIR entrySize; // Size of the file/directory entry - ISO_DATESTAMP entryDate; // Date & time stamp of entry - unsigned char flags; // File flags (0x02 for directories, 0x00 for files) - unsigned char fileUnitSize; // Unit size (usually 0 even with Form 2 files such as STR/XA) - unsigned char interleaveGapSize; // Interleave gap size (usually 0 even with Form 2 files such as STR/XA) - ISO_USHORT_PAIR volSeqNum; // Volume sequence number (always 1) - unsigned char identifierLen; // Identifier (file/directory name) length in bytes -} ISO_DIR_ENTRY; - -typedef struct ISO_ROOTDIR_HEADER -{ - unsigned char entryLength; // Always 34 bytes - unsigned char extLength; // Always 0 - ISO_UINT_PAIR entryOffs; // Should point to LBA 22 - ISO_UINT_PAIR entrySize; // Size of entry extent - ISO_DATESTAMP entryDate; // Record date and time - unsigned char flags; // File flags - unsigned char fileUnitSize; - unsigned char interleaveGapSize; - ISO_USHORT_PAIR volSeqNum; - unsigned char identifierLen; // 0x01 - unsigned char identifier; // 0x00 -} ISO_ROOTDIR_HEADER; - -// ISO descriptor structure -typedef struct ISO_DESCRIPTOR -{ - - // ISO descriptor header - ISO_DESCRIPTOR_HEADER header; - // System ID (always PLAYSTATION) - char systemID[32]; - // Volume ID (or label, can be blank or anything) - char volumeID[32]; - // Unused null bytes - unsigned char pad2[8]; - // Size of volume in sector units - ISO_UINT_PAIR volumeSize; - // Unused null bytes - unsigned char pad3[32]; - // Number of discs in this volume set (always 1 for single volume) - ISO_USHORT_PAIR volumeSetSize; - // Number of this disc in volume set (always 1 for single volume) - ISO_USHORT_PAIR volumeSeqNumber; - // Size of sector in bytes (always 2048 bytes) - ISO_USHORT_PAIR sectorSize; - // Path table size in bytes (applies to all the path tables) - ISO_UINT_PAIR pathTableSize; - // LBA to Type-L path table - unsigned int pathTable1Offs; - // LBA to optional Type-L path table (usually a copy of the primary path table) - unsigned int pathTable2Offs; - // LBA to Type-L path table but with MSB format values - unsigned int pathTable1MSBoffs; - // LBA to optional Type-L path table but with MSB format values (usually a copy of the main path table) - unsigned int pathTable2MSBoffs; - // Directory entry for the root directory (similar to a directory entry) - ISO_ROOTDIR_HEADER rootDirRecord; - // Volume set identifier (can be blank or anything) - char volumeSetIdentifier[128]; - // Publisher identifier (can be blank or anything) - char publisherIdentifier[128]; - // Data preparer identifier (can be blank or anything) - char dataPreparerIdentifier[128]; - // Application identifier (always PLAYSTATION) - char applicationIdentifier[128]; - // Copyright file in the file system identifier (can be blank or anything) - char copyrightFileIdentifier[37]; - // Abstract file in the file system identifier (can be blank or anything) - char abstractFileIdentifier[37]; - // Bibliographical file identifier in the file system (can be blank or anything) - char bibliographicFilelIdentifier[37]; - // Volume create date (in text format YYYYMMDDHHMMSSMMGG) - char volumeCreateDate[17]; - // Volume modify date (in text format YYYYMMDDHHMMSSMMGG) - char volumeModifyDate[17]; - // Volume expiry date (in text format YYYYMMDDHHMMSSMMGG) - char volumeExpiryDate[17]; - // Volume effective date (in text format YYYYMMDDHHMMSSMMGG) - char volumeEffeciveDate[17]; - // File structure version (always 1) - unsigned char fileStructVersion; - // Padding - unsigned char dummy0; - // Application specific data (says CD-XA001 at [141], the rest are null bytes) - unsigned char appData[512]; - // Padding - unsigned char pad4[653]; - -} ISO_DESCRIPTOR; - typedef struct _CdlDIR_INT { u_int _pos; @@ -157,10 +16,7 @@ typedef struct _CdlDIR_INT u_char* _dir; } CdlDIR_INT; -// Leave non-aligned structure packing -#pragma pack(pop) - -extern char _cd_media_changed; +extern int _cd_media_changed; static int _cd_iso_last_dir_lba; @@ -176,7 +32,37 @@ static int _CdReadIsoDescriptor(int session_offs) CdlLOC loc; ISO_DESCRIPTOR *descriptor; - // Seek to volume descriptor location + // Check if the lid had been opened + if( !_cd_media_changed ) + { + CdControl(CdlNop, 0, 0); + if( (CdStatus()&0x10) ) + { + // Check if lid is still open + CdControl(CdlNop, 0, 0); + if( (CdStatus()&0x10) ) + { +#ifdef DEBUG + printf("psxcd: Lid is still open.\n"); +#endif + _cd_iso_error = CdlIsoLidOpen; + return -1; + } + // Reparse the file system + _cd_media_changed = 1; + } + } + + if( !_cd_media_changed ) + { + return 0; + } + +#ifdef DEBUG + printf("psxcd: Parsing ISO file system.\n"); +#endif + + // Seek to volume descriptor CdIntToPos(16+session_offs, &loc); if( !CdControl(CdlSetloc, (u_char*)&loc, 0) ) { @@ -186,9 +72,17 @@ static int _CdReadIsoDescriptor(int session_offs) _cd_iso_error = CdlIsoSeekError; return -1; } + +#ifdef DEBUG + printf("psxcd: Set seek target.\n"); +#endif +#ifdef DEBUG + printf("psxcd: Read sectors.\n"); +#endif // Read volume descriptor CdRead(1, (u_int*)_cd_iso_descriptor_buff, CdlModeSpeed); + if( CdReadSync(0, 0) ) { #ifdef DEBUG @@ -198,13 +92,16 @@ static int _CdReadIsoDescriptor(int session_offs) return -1; } +#ifdef DEBUG + printf("psxcd: Read complete.\n"); +#endif // Verify if volume descriptor is present descriptor = (ISO_DESCRIPTOR*)_cd_iso_descriptor_buff; if( strncmp("CD001", descriptor->header.id, 5) ) { #ifdef DEBUG - printf("psxcd: Disc does not have a ISO9660 file system.\n"); + printf("psxcd: Disc does not contain a ISO9660 file system.\n"); #endif _cd_iso_error = CdlIsoInvalidFs; return -1; @@ -240,8 +137,10 @@ static int _CdReadIsoDescriptor(int session_offs) return -1; } - _cd_iso_last_dir_lba = 0; - _cd_iso_error = CdlIsoOkay; + _cd_iso_last_dir_lba = 0; + _cd_iso_error = CdlIsoOkay; + + _cd_media_changed = 0; return 0; } @@ -572,21 +471,21 @@ CdlFILE *CdSearchFile(CdlFILE *fp, const char *filename) ISO_DIR_ENTRY dir_entry; // Read ISO descriptor if changed flag is set - if( _cd_media_changed ) - { + //if( _cd_media_changed ) + //{ // Read ISO descriptor and path table - if( _CdReadIsoDescriptor(0) ) - { + if( _CdReadIsoDescriptor(0) ) + { #ifdef DEBUG - printf("psxcd: Could not read ISO file system.\n"); + printf("psxcd: Could not read ISO file system.\n"); #endif - return NULL; - } + return NULL; + } #ifdef DEBUG - printf("psxcd: ISO file system cache updated.\n"); + // printf("psxcd: ISO file system cache updated.\n"); #endif - _cd_media_changed = 0; - } + // _cd_media_changed = 0; + //} // Get number of directories in path table num_dirs = get_pathtable_entry(0, NULL, NULL); @@ -692,21 +591,21 @@ CdlDIR *CdOpenDir(const char* path) ISO_PATHTABLE_ENTRY tbl_entry; // Read ISO descriptor if changed flag is set - if( _cd_media_changed ) +// if( _cd_media_changed ) +// { + // Read ISO descriptor and path table + if( _CdReadIsoDescriptor( 0 ) ) { - // Read ISO descriptor and path table - if( _CdReadIsoDescriptor( 0 ) ) - { #ifdef DEBUG - printf( "psxcd: Could not read ISO file system.\n" ); + printf( "psxcd: Could not read ISO file system.\n" ); #endif - return NULL; - } + return NULL; + } #ifdef DEBUG - printf( "psxcd: ISO file system cache updated.\n" ); +// printf( "psxcd: ISO file system cache updated.\n" ); #endif - _cd_media_changed = 0; - } +// _cd_media_changed = 0; +// } num_dirs = get_pathtable_entry( 0, NULL, NULL ); @@ -775,10 +674,17 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file) CdlDIR_INT* d_dir; ISO_DIR_ENTRY* dir_entry; + // Locks up in an infinite loop if directory record size is 6144 bytes + d_dir = (CdlDIR_INT*)dir; if( d_dir->_pos >= _cd_iso_directory_len ) return 0; + + // Some generated file systems have a premature NULL entry, consider this + // the end of the directory record + if( d_dir->_dir[d_dir->_pos] == 0 ) + return 0; dir_entry = (ISO_DIR_ENTRY*)(d_dir->_dir+d_dir->_pos); @@ -800,9 +706,17 @@ int CdReadDir(CdlDIR *dir, CdlFILE* file) CdIntToPos( dir_entry->entryOffs.lsb, &file->pos ); file->size = dir_entry->entrySize.lsb; + +#ifdef DEBUG + printf("dir_entry->entryLength = %d, ", dir_entry->entryLength); +#endif d_dir->_pos += dir_entry->entryLength; +#ifdef DEBUG + printf("d_dir->_pos = %d\n", d_dir->_pos); +#endif + // Check if padding is reached (end of record sector) if( d_dir->_dir[d_dir->_pos] == 0 ) { @@ -849,4 +763,148 @@ int CdGetVolumeLabel(char* label) label[i] = 0x00; return 0; -}
\ No newline at end of file +} + + +// Session load routine + +void _cd_control(unsigned char com, unsigned char *param, int plen); + +static volatile unsigned int _ready_oldcb; + +static volatile int _ses_scanfound; +static volatile int _ses_scancount; +static volatile int _ses_scancomplete; +//static volatile char _ses_scan_resultbuff[8]; +static volatile char *_ses_scanbuff; + +static void _scan_callback(int status, unsigned char *result) +{ + if( status == CdlDataReady ) + { + CdGetSector((void*)_ses_scanbuff, 2048); + + if( _ses_scanbuff[0] == 0x1 ) + { + if( strncmp((const char*)_ses_scanbuff+1, "CD001", 5) == 0 ) + { + _cd_control(CdlPause, 0, 0); + _ses_scancomplete = 1; + _ses_scanfound = 1; + return; + } + } + _ses_scancount++; + if( _ses_scancount >= 512 ) + { + _cd_control(CdlPause, 0, 0); + _ses_scancomplete = 1; + return; + } + } + + if( status == CdlDiskError ) + { + _cd_control(CdlPause, 0, 0); + _ses_scancomplete = 1; + } +} + +int CdLoadSession(int session) +{ + CdlLOC *loc; + unsigned int ready_oldcb; + char scanbuff[2048]; + char resultbuff[16]; + int i; + + // Seek to specified session +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Seeking to session %d...\n", session); +#endif + CdControl(CdlSetsession, (unsigned char*)&session, + (unsigned char*)&resultbuff); + + if( CdSync(0, 0) == CdlDiskError ) + { +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Session seek failed, " + "session does not exist.\n"); + printf("psxcd: CdLoadSession(): Restarting CD-ROM...\n"); +#endif + + // Restart CD-ROM on session seek failure + CdControl(CdlNop, 0, 0); + CdControl(CdlInit, 0, 0); + CdSync(0, 0); + + return -1; + } + + // Set search routine callback + ready_oldcb = CdReadyCallback(_scan_callback); + + _ses_scanfound = 0; + _ses_scancount = 0; + _ses_scancomplete = 0; + _ses_scanbuff = scanbuff; + + // Begin scan for an ISO volume descriptor +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Scanning for ISO9660 volume descriptor.\n"); +#endif + i = CdlModeSpeed; + CdControl(CdlSetmode, (unsigned char*)&i, 0); + CdControl(CdlReadN, 0, (unsigned char*)resultbuff); + + // Wait until scan complete + while(!_ses_scancomplete); + + CdReadyCallback((void*)_ready_oldcb); + + if( !_ses_scanfound ) + { +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Did not find volume descriptor.\n"); +#endif + _cd_iso_error = CdlIsoInvalidFs; + CdReadyCallback((CdlCB)ready_oldcb); + return -1; + } + + // Restore old callback if any + CdReadyCallback((CdlCB)ready_oldcb); + + // Wait until CD-ROM has completely stopped reading, to get a consistent + // fix of the CD-ROM pickup's current location + do + { + VSync(2); + CdControl(CdlNop, 0, 0); + } while(CdStatus()&0xE0); + + // Get location of volume descriptor + CdControl(CdlGetlocL, 0, (unsigned char*)resultbuff); + CdSync(0, 0); + + loc = (CdlLOC*)resultbuff; + +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Session found in %02d:%02d:%02d (LBA=%d)\n", + btoi(loc->minute), btoi(loc->second), btoi(loc->sector), CdPosToInt(loc)); +#endif + + i = CdPosToInt(loc)-17; +#ifdef DEBUG + printf("psxcd: CdLoadSession(): Session starting at LBA=%d\n", i); +#endif + + _cd_media_changed = 1; + + if( _CdReadIsoDescriptor(i) ) + { + return -1; + } + + return 0; +} diff --git a/libpsn00b/psxcd/isofs.h b/libpsn00b/psxcd/isofs.h new file mode 100644 index 0000000..5c5bf36 --- /dev/null +++ b/libpsn00b/psxcd/isofs.h @@ -0,0 +1,149 @@ +#ifndef _ISOFS_H +#define _ISOFS_H + +#pragma pack(push, 1) + +/// Structure of a double-endian unsigned short word +typedef struct ISO_USHORT_PAIR +{ + unsigned short lsb; /// LSB format 16-bit word + unsigned short msb; /// MSB format 16-bit word +} ISO_USHORT_PAIR; + +/// Structure of a double-endian unsigned int word +typedef struct ISO_UINT_PAIR +{ + unsigned int lsb; /// LSB format 32-bit word + unsigned int msb; /// MSB format 32-bit word +} ISO_UINT_PAIR; + +/// ISO descriptor header structure +typedef struct ISO_DESCRIPTOR_HEADER +{ + unsigned char type; /// Volume descriptor type (1 is descriptor, 255 is descriptor terminator) + char id[5]; /// Volume descriptor ID (always CD001) + unsigned short version; /// Volume descriptor version (always 0x01) +} ISO_DESCRIPTOR_HEADER; + +/// Structure of a date stamp for ISO_DIR_ENTRY structure +typedef struct ISO_DATESTAMP +{ + unsigned char year; /// number of years since 1900 + unsigned char month; /// month, where 1=January, 2=February, etc. + unsigned char day; /// day of month, in the range from 1 to 31 + unsigned char hour; /// hour, in the range from 0 to 23 + unsigned char minute; /// minute, in the range from 0 to 59 + unsigned char second; /// Second, in the range from 0 to 59 + unsigned char GMToffs; /// Greenwich Mean Time offset +} ISO_DATESTAMP; + +/// Structure of an ISO path table entry (specifically for the cd::IsoReader class) +typedef struct ISO_PATHTABLE_ENTRY +{ + unsigned char nameLength; /// Name length (or 1 for the root directory) + unsigned char extLength; /// Number of sectors in extended attribute record + unsigned int dirOffs; /// Number of the first sector in the directory, as a double word + unsigned short dirLevel; /// Index of the directory record's parent directory + /// If nameLength is odd numbered, a padding byte will be present after the identifier text. +} ISO_PATHTABLE_ENTRY; + +typedef struct ISO_DIR_ENTRY +{ + unsigned char entryLength; // Directory entry length (variable, use for parsing through entries) + unsigned char extLength; // Extended entry data length (always 0) + ISO_UINT_PAIR entryOffs; // Points to the LBA of the file/directory entry + ISO_UINT_PAIR entrySize; // Size of the file/directory entry + ISO_DATESTAMP entryDate; // Date & time stamp of entry + unsigned char flags; // File flags (0x02 for directories, 0x00 for files) + unsigned char fileUnitSize; // Unit size (usually 0 even with Form 2 files such as STR/XA) + unsigned char interleaveGapSize; // Interleave gap size (usually 0 even with Form 2 files such as STR/XA) + ISO_USHORT_PAIR volSeqNum; // Volume sequence number (always 1) + unsigned char identifierLen; // Identifier (file/directory name) length in bytes +} ISO_DIR_ENTRY; + +typedef struct ISO_ROOTDIR_HEADER +{ + unsigned char entryLength; // Always 34 bytes + unsigned char extLength; // Always 0 + ISO_UINT_PAIR entryOffs; // Should point to LBA 22 + ISO_UINT_PAIR entrySize; // Size of entry extent + ISO_DATESTAMP entryDate; // Record date and time + unsigned char flags; // File flags + unsigned char fileUnitSize; + unsigned char interleaveGapSize; + ISO_USHORT_PAIR volSeqNum; + unsigned char identifierLen; // 0x01 + unsigned char identifier; // 0x00 +} ISO_ROOTDIR_HEADER; + +// ISO descriptor structure +typedef struct ISO_DESCRIPTOR +{ + + // ISO descriptor header + ISO_DESCRIPTOR_HEADER header; + // System ID (always PLAYSTATION) + char systemID[32]; + // Volume ID (or label, can be blank or anything) + char volumeID[32]; + // Unused null bytes + unsigned char pad2[8]; + // Size of volume in sector units + ISO_UINT_PAIR volumeSize; + // Unused null bytes + unsigned char pad3[32]; + // Number of discs in this volume set (always 1 for single volume) + ISO_USHORT_PAIR volumeSetSize; + // Number of this disc in volume set (always 1 for single volume) + ISO_USHORT_PAIR volumeSeqNumber; + // Size of sector in bytes (always 2048 bytes) + ISO_USHORT_PAIR sectorSize; + // Path table size in bytes (applies to all the path tables) + ISO_UINT_PAIR pathTableSize; + // LBA to Type-L path table + unsigned int pathTable1Offs; + // LBA to optional Type-L path table (usually a copy of the primary path table) + unsigned int pathTable2Offs; + // LBA to Type-L path table but with MSB format values + unsigned int pathTable1MSBoffs; + // LBA to optional Type-L path table but with MSB format values (usually a copy of the main path table) + unsigned int pathTable2MSBoffs; + // Directory entry for the root directory (similar to a directory entry) + ISO_ROOTDIR_HEADER rootDirRecord; + // Volume set identifier (can be blank or anything) + char volumeSetIdentifier[128]; + // Publisher identifier (can be blank or anything) + char publisherIdentifier[128]; + // Data preparer identifier (can be blank or anything) + char dataPreparerIdentifier[128]; + // Application identifier (always PLAYSTATION) + char applicationIdentifier[128]; + // Copyright file in the file system identifier (can be blank or anything) + char copyrightFileIdentifier[37]; + // Abstract file in the file system identifier (can be blank or anything) + char abstractFileIdentifier[37]; + // Bibliographical file identifier in the file system (can be blank or anything) + char bibliographicFilelIdentifier[37]; + // Volume create date (in text format YYYYMMDDHHMMSSMMGG) + char volumeCreateDate[17]; + // Volume modify date (in text format YYYYMMDDHHMMSSMMGG) + char volumeModifyDate[17]; + // Volume expiry date (in text format YYYYMMDDHHMMSSMMGG) + char volumeExpiryDate[17]; + // Volume effective date (in text format YYYYMMDDHHMMSSMMGG) + char volumeEffeciveDate[17]; + // File structure version (always 1) + unsigned char fileStructVersion; + // Padding + unsigned char dummy0; + // Application specific data (says CD-XA001 at [141], the rest are null bytes) + unsigned char appData[512]; + // Padding + unsigned char pad4[653]; + +} ISO_DESCRIPTOR; + +// Leave non-aligned structure packing +#pragma pack(pop) + +#endif /* _ISOFS_H */
\ No newline at end of file diff --git a/libpsn00b/psxcd/makefile b/libpsn00b/psxcd/makefile index 87466b3..1886ace 100644 --- a/libpsn00b/psxcd/makefile +++ b/libpsn00b/psxcd/makefile @@ -1,24 +1,26 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxcd.a +TARGET = libpsxcd.a -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +INCLUDE = -I../include -INCLUDE = -I../include +CFILES = $(notdir $(wildcard ./*.c)) +AFILES = $(notdir $(wildcard ./*.s)) +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) -CFLAGS = -g -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +CFLAGS = -g -msoft-float -fno-builtin -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -Wa,--strip-local-absolute -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -34,5 +36,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxcd/psxcd.c b/libpsn00b/psxcd/psxcd.c index 76b6c08..76a8eba 100644 --- a/libpsn00b/psxcd/psxcd.c +++ b/libpsn00b/psxcd/psxcd.c @@ -17,7 +17,7 @@ volatile CdlLOC _cd_last_setloc; volatile unsigned int *_cd_last_read_addr; volatile int _cd_last_sector_count; -extern volatile char _cd_media_changed; +int _cd_media_changed; void _cd_init(void); void _cd_control(unsigned char com, unsigned char *param, int plen); @@ -62,6 +62,12 @@ int CdControl(unsigned char com, unsigned char *param, unsigned char *result) CdControlF(com, param); _cd_wait_ack(); + // Set media changed flag if lid had been opened + if( (CdStatus()&0x10) ) + { + _cd_media_changed = 1; + } + return 1; } diff --git a/libpsn00b/psxcd/psxcd_asm.s b/libpsn00b/psxcd/psxcd_asm.s index 0bfe5ca..1dbf542 100644 --- a/libpsn00b/psxcd/psxcd_asm.s +++ b/libpsn00b/psxcd/psxcd_asm.s @@ -15,6 +15,12 @@ _cd_init: nop lui $a3, IOBASE # Acknowledge all CD IRQs + + li $v0, 0x20943 # Set CD-ROM Delay/Size and common delay + sw $v0, SBUS_5($a3) + li $v0, 0x1325 + sw $v0, COM_DELAY($a3) + li $v0, 1 sb $v0, CD_REG0($a3) li $v0, 0x1f @@ -24,9 +30,6 @@ _cd_init: sb $0 , CD_REG0($a3) sb $0 , CD_REG3($a3) - li $v0, 0x1325 - sw $v0, COM_DELAY($a3) - la $a1, _cd_handler jal InterruptCallback li $a0, 2 @@ -76,29 +79,6 @@ _cd_init: jal ExitCriticalSection nop - #li $a0, 0x01 # GetStat - #jal _cd_control - #move $a2, $0 - #jal _cd_wait - #nop - - #li $a0, 0x0a # Init - #jal _cd_control - #move $a2, $0 - #jal _cd_wait - #nop - - #li $a0, 0x0c # Demute - #jal _cd_control - #move $a2, $0 - #jal _cd_wait - #nop - - #la $a0, _cd_init_msg - #jal printf - #addiu $sp, -16 - #addiu $sp, 16 - lw $ra, 0($sp) addiu $sp, 4 jr $ra @@ -153,7 +133,7 @@ _cd_handler: addiu $sp, -4 sw $ra, 0($sp) - lui $a3, IOBASE # Print out IRQ number + lui $a3, IOBASE # Get IRQ number li $v0, 1 sb $v0, CD_REG0($a3) @@ -167,6 +147,11 @@ _cd_handler: bne $v0, 0x1, .Lno_data nop + sb $0 , CD_REG0($a3) + lbu $v1, CD_REG0($a3) + sb $0 , CD_REG3($a3) + lbu $v1, CD_REG3($a3) + sb $0 , CD_REG0($a3) # Load data FIFO on INT1 li $v1, 0x80 sb $v1, CD_REG3($a3) @@ -189,6 +174,9 @@ _cd_handler: li $v1, 3 sw $v1, 0($0) + la $v1, _cd_last_int + lbu $v0, 0($v1) + beq $v0, 0x1, .Lirq_1 # Data ready nop beq $v0, 0x2, .Lirq_2 # Command finish @@ -371,17 +359,6 @@ _cd_fetch_result: .Lwrite_status: - andi $v1, $v0, 0x10 - - beqz $v1, .Lno_disc_change - nop - - la $v1, _cd_media_changed - addiu $a1, $0 , 1 - sw $a1, 0($v1) - -.Lno_disc_change: - sb $v0, 0($a0) .Lskip_status: @@ -394,23 +371,32 @@ _cd_fetch_result: sb $v0, 0($a0) addiu $a0, 1 + move $a1, $0 .Lread_futher_result: lbu $v0, CD_REG0($a3) nop andi $v0, 0x20 beqz $v0, .Lno_result + addu $a1, 1 + bge $a1, 7, .Lno_result # timeout (locks up here on PSIO) nop - lbu $v0, CD_REG1($a3) lbu $v1, CD_REG0($a3) sb $v0, 0($a0) - andi $v1, 0x20 + + andi $v1, 0x20 # when performing a CD-ROM read bnez $v1, .Lread_futher_result addiu $a0, 1 .Lno_result: +# lbu $v0, CD_REG0($a3) # Flush response FIFO +# nop +# andi $v0, 0x20 +# bnez $v0, .Lno_result +# lbu $v0, CD_REG1($a3) + jr $ra nop @@ -509,11 +495,7 @@ CdSyncCallback: .type psxcd_credits, @object psxgpu_credits: .ascii "psxcd library programs by Lameguy64\n" - .asciiz "2019 PSn00bSDK Project / Meido-Tek Productions\n" - -_cd_init_msg: -.asciiz "psxcd: Init OK\n" -.align 4 + .asciiz "2020 PSn00bSDK Project / Meido-Tek Productions\n" .comm _cd_last_cmd, 1, 1 .comm _cd_last_mode, 1, 1 @@ -523,9 +505,7 @@ _cd_init_msg: .comm _cd_status, 1, 1 .comm _cd_last_int, 1, 1 -.comm _cd_media_changed, 1, 1 - # Callback hooks .comm _cd_callback_int1_data, 4, 4 # Data IRQ callback -.comm _cd_callback_int4, 4, 4 # Autopause callback +.comm _cd_callback_int4, 4, 4 # Autopause callback .comm _cd_sync_cb, 4, 4 diff --git a/libpsn00b/psxcd/readme.txt b/libpsn00b/psxcd/readme.txt index a85fab5..64643ed 100644 --- a/libpsn00b/psxcd/readme.txt +++ b/libpsn00b/psxcd/readme.txt @@ -1,5 +1,5 @@ PSX CD-ROM library, part of PSn00bSDK -2019 Lameguy64 / Meido-Tek Productions +2020 Lameguy64 / Meido-Tek Productions Licensed under Mozilla Public License @@ -42,7 +42,4 @@ Todo list: * Data streaming functions (prefixed with St*) not yet implemented. Would require devising a PSn00bSDK equivalent of the STR file - format. - - * Original functions for querying directory contents in the file - system not yet implemented.
\ No newline at end of file + format.
\ No newline at end of file diff --git a/libpsn00b/psxgpu/dmacallback.s b/libpsn00b/psxetc/dmacallback.s index b2f86cf..b2f86cf 100644 --- a/libpsn00b/psxgpu/dmacallback.s +++ b/libpsn00b/psxetc/dmacallback.s diff --git a/libpsn00b/psxgpu/getinterruptcallback.s b/libpsn00b/psxetc/getinterruptcallback.s index 510447f..510447f 100644 --- a/libpsn00b/psxgpu/getinterruptcallback.s +++ b/libpsn00b/psxetc/getinterruptcallback.s diff --git a/libpsn00b/psxgpu/interruptcallback.s b/libpsn00b/psxetc/interruptcallback.s index 8e912d8..8e912d8 100644 --- a/libpsn00b/psxgpu/interruptcallback.s +++ b/libpsn00b/psxetc/interruptcallback.s diff --git a/libpsn00b/psxetc/isr.s b/libpsn00b/psxetc/isr.s new file mode 100644 index 0000000..00428a4 --- /dev/null +++ b/libpsn00b/psxetc/isr.s @@ -0,0 +1,107 @@ +.set noreorder + +.include "hwregs_a.h" + +.set ISR_STACK_SIZE, 4096 + + +.section .text + +# Global ISR handler of PSn00bSDK + +.set at + +.type _global_isr, @function +_global_isr: + +.Lisr_loop: + + #la $gp, _gp # Keep restoring GP since it gets + # changed elsewhere sometimes + + lui $a0, IOBASE # Get IRQ status + lw $v0, IMASK($a0) + nop + + srl $v0, $s1 # Check IRQ mask bit if set + andi $v0, 0x1 + + beqz $v0, .Lno_irq # Don't execute callback if IRQ not enabled + nop + + lw $v0, ISTAT($a0) + nop + srl $v0, $s1 # Check IRQ status bit if set + andi $v0, 0x1 + beqz $v0, .Lno_irq # Don't execute callback if no IRQ + nop + + lw $v1, 0($s0) # Load IRQ callback function + nop + + lw $v0, ISTAT($a0) # Acknowledge the IRQ (by writing a 0 bit) + li $a1, 1 + sll $a1, $s1 + addiu $a2, $0 , -1 + xor $a1, $a2 + sw $a1, ISTAT($a0) + + beqz $v1, .Lno_irq # Don't execute if callback is not set + nop + + jalr $v1 # Call interrupt handler + nop + +.Lno_irq: + + addiu $s0, 4 + + blt $s1, 11, .Lisr_loop + addiu $s1, 1 + + j ReturnFromException + nop + + +.section .data + +# Global ISR callback table + +.global _irq_func_table +.type _irq_func_table, @object +_irq_func_table: + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + .word 0 + +# Global ISR hook structure +.global _custom_exit +.type _custom_exit, @object +_custom_exit: + .word _global_isr # pc + .word _isr_stack+ISR_STACK_SIZE # sp + .word 0 # fp + .word _irq_func_table # s0 + .word 0 # s1 + .word 0 # s2 + .word 0 # s3 + .word 0 # s4 + .word 0 # s5 + .word 0 # s6 + .word 0 # s7 + .word _gp # gp + +# Global ISR stack +# .fill 1024 +#_custom_exit_stack: +# .fill 4 +.comm _isr_stack, ISR_STACK_SIZE+4 diff --git a/libpsn00b/psxetc/makefile b/libpsn00b/psxetc/makefile index 399fb91..3f938a6 100644 --- a/libpsn00b/psxetc/makefile +++ b/libpsn00b/psxetc/makefile @@ -1,22 +1,26 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxetc.a +TARGET = libpsxetc.a CFILES = $(notdir $(wildcard ./*.c)) AFILES = $(notdir $(wildcard ./*.s)) OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) -CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections -ffunction-sections -Wa,--strip-local-absolute +CFLAGS = -g -O2 -msoft-float -fno-builtin -nostdlib -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute AFLAGS = -g -msoft-float -strip-local-absolute -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +INCLUDE = -I../include + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -32,5 +36,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxgpu/restartcallback.s b/libpsn00b/psxetc/restartcallback.s index ffdeecd..151d78e 100644 --- a/libpsn00b/psxgpu/restartcallback.s +++ b/libpsn00b/psxetc/restartcallback.s @@ -13,21 +13,25 @@ RestartCallback: la $a0, _custom_exit jal SetCustomExitFromException - addiu $sp, -12 + addiu $sp, -4 + addiu $sp, 4 - jal ChangeClearPAD move $a0, $0 + jal ChangeClearPAD + addiu $sp, -4 + addiu $sp, 4 li $a0, 3 - jal ChangeClearRCnt move $a1, $0 - + jal ChangeClearRCnt + addiu $sp, -8 + addiu $sp, 8 la $a0, _irq_func_table move $a1, $0 move $v0, $0 -.Lcheck_cbs: +.Lcheck_cbs: # Set up the interrupt masks lw $v1, 0($a0) nop beqz $v1, .Lno_cb @@ -43,8 +47,8 @@ RestartCallback: sw $0 , ISTAT($a0) sw $v0, IMASK($a0) - addiu $sp, 12 lw $ra, 0($sp) - nop + addiu $sp, 4 jr $ra - nop
\ No newline at end of file + nop +
\ No newline at end of file diff --git a/libpsn00b/psxetc/dbugfont.c b/libpsn00b/psxgpu/dbugfont.c index ff21d84..ff21d84 100644 --- a/libpsn00b/psxetc/dbugfont.c +++ b/libpsn00b/psxgpu/dbugfont.c diff --git a/libpsn00b/psxetc/dbugfont.tim b/libpsn00b/psxgpu/dbugfont.tim Binary files differindex 4e6cce2..4e6cce2 100644 --- a/libpsn00b/psxetc/dbugfont.tim +++ b/libpsn00b/psxgpu/dbugfont.tim diff --git a/libpsn00b/psxetc/fntsort.c b/libpsn00b/psxgpu/fntsort.c index 3890ebb..3890ebb 100644 --- a/libpsn00b/psxetc/fntsort.c +++ b/libpsn00b/psxgpu/fntsort.c diff --git a/libpsn00b/psxetc/font.c b/libpsn00b/psxgpu/font.c index cd4acab..cd4acab 100644 --- a/libpsn00b/psxetc/font.c +++ b/libpsn00b/psxgpu/font.c diff --git a/libpsn00b/psxgpu/makefile b/libpsn00b/psxgpu/makefile index 980e311..2e984d0 100644 --- a/libpsn00b/psxgpu/makefile +++ b/libpsn00b/psxgpu/makefile @@ -1,22 +1,26 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxgpu.a +TARGET = libpsxgpu.a -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +INCLUDE = -I../include -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +CFILES = $(notdir $(wildcard ./*.c)) +AFILES = $(notdir $(wildcard ./*.s)) +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -Wa,--strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -32,5 +36,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxgpu/resetgraph.s b/libpsn00b/psxgpu/resetgraph.s index b956873..f469fbe 100644 --- a/libpsn00b/psxgpu/resetgraph.s +++ b/libpsn00b/psxgpu/resetgraph.s @@ -4,7 +4,7 @@ .section .text -.set ISR_STACK_SIZE, 2048 +.set ISR_STACK_SIZE, 4096 .global ResetGraph # Resets the GPU and installs a .type ResetGraph, @function # VSync event handler @@ -13,11 +13,30 @@ ResetGraph: sw $ra, 0($sp) # you call BIOS functions from asm) sw $a0, 4($sp) + la $a0, resetgraph_msg + move $a1, $0 + move $a2, $0 + la $a1, _irq_func_table + la $a2, _custom_exit + jal printf + addiu $sp, -16 + addiu $sp, 16 + + la $a0, sr_msg + mfc0 $a1, $12 + jal printf + addiu $sp, -16 + addiu $sp, 16 + la $v0, _hooks_installed # Skip installing hooks if this function lbu $v0, 0($v0) # has already been called before once nop bnez $v0, .Lskip_hook_init nop + + jal EnterCriticalSection # Disable interrupts as LoadExec() keeps + nop # interrupts enabled when transferring + # execution to the loaded program lui $a3, 0x1f80 # Base address for I/O @@ -38,31 +57,19 @@ ResetGraph: la $a1, _vsync_irq_callback # Install VSync interrupt callback jal InterruptCallback li $a0, 0 - - la $a0, _custom_exit # Set custom exit handler - jal SetCustomExitFromException - addiu $sp, -4 - addiu $sp, 4 - - move $a0, $0 - jal ChangeClearPAD # Disable VSync IRQ auto ack - addiu $sp, -4 - addiu $sp, 4 - li $a0, 3 - move $a1, $0 - jal ChangeClearRCnt # Remove RCnt timer IRQ auto ack - addiu $sp, -8 - addiu $sp, 8 + jal RestartCallback + nop + la $a0, cbhooks_msg + jal printf + addiu $sp, -16 + addiu $sp, 16 + jal _96_remove # Remove CD handling left by the BIOS nop - la $a0, resetgraph_msg - move $a1, $0 - move $a2, $0 - la $a1, _irq_func_table - la $a2, _custom_exit + la $a0, abouttoen_msg jal printf addiu $sp, -16 addiu $sp, 16 @@ -70,6 +77,11 @@ ResetGraph: jal ExitCriticalSection # Re-enable interrupts nop + la $a0, enableint_msg + jal printf + addiu $sp, -16 + addiu $sp, 16 + .Lskip_hook_init: lui $a3, 0x1f80 @@ -301,62 +313,6 @@ _vsync_irq_callback: nop -# Global ISR handler of PSn00bSDK - -.set at - -.type _global_isr, @function -_global_isr: - -.Lisr_loop: - - #la $gp, _gp # Keep restoring GP since it gets - # changed elsewhere sometimes - - lui $a0, IOBASE # Get IRQ status - lw $v0, IMASK($a0) - nop - - srl $v0, $s1 # Check IRQ mask bit if set - andi $v0, 0x1 - - beqz $v0, .Lno_irq # Don't execute callback if IRQ not enabled - nop - - lw $v0, ISTAT($a0) - nop - srl $v0, $s1 # Check IRQ status bit if set - andi $v0, 0x1 - beqz $v0, .Lno_irq # Don't execute callback if no IRQ - nop - - lw $v1, 0($s0) # Load IRQ callback function - nop - - lw $v0, ISTAT($a0) # Acknowledge the IRQ (by writing a 0 bit) - li $a1, 1 - sll $a1, $s1 - addiu $a2, $0 , -1 - xor $a1, $a2 - sw $a1, ISTAT($a0) - - beqz $v1, .Lno_irq # Don't execute if callback is not set - nop - - jalr $v1 # Call interrupt handler - nop - -.Lno_irq: - - addiu $s0, 4 - - blt $s1, 11, .Lisr_loop - addiu $s1, 1 - - j ReturnFromException - nop - - .section .data # VSync root counter @@ -374,59 +330,34 @@ _vsync_lasthblank: .comm _gpu_current_field, 4, 4 .comm _hooks_installed, 4, 4 - -# Global ISR callback table - -.global _irq_func_table -.type _irq_func_table, @object -_irq_func_table: - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - .word 0 - -# Global ISR hook structure -.global _custom_exit -.type _custom_exit, @object -_custom_exit: - .word _global_isr # pc - .word _custom_exit_stack+ISR_STACK_SIZE # sp - .word 0 # fp - .word _irq_func_table # s0 - .word 0 # s1 - .word 0 # s2 - .word 0 # s3 - .word 0 # s4 - .word 0 # s5 - .word 0 # s6 - .word 0 # s7 - .word _gp # gp - -# Global ISR stack -# .fill 1024 -#_custom_exit_stack: -# .fill 4 -.comm _custom_exit_stack, ISR_STACK_SIZE+4 .type vsynctimeout_msg, @object vsynctimeout_msg: .asciiz "VSync: timeout\n" - + .type resetgraph_msg, @object resetgraph_msg: .asciiz "ResetGraph:itb=%08x,ehk=%08x\n" +.type enableint_msg, @object +enableint_msg: + .asciiz "ResetGraph:Interrupts enabled!\n" + +.type cbhooks_msg, @object +cbhooks_msg: + .asciiz "ResetGraph:Interrupt hooks enabled.\n" + +.type abouttoen_msg, @object +abouttoen_msg: + .asciiz "ResetGraph:About to init interrupts.\n" + +.type sr_msg, @object +sr_msg: + .asciiz "ResetGraph:SR=%x\n" + .global psxgpu_credits .type psxgpu_credits, @object psxgpu_credits: .ascii "psxgpu programs by Lameguy64\n" - .asciiz "2019 PSn00bSDK Project / Meido-Tek Productions\n" + .asciiz "2020 PSn00bSDK Project / Meido-Tek Productions\n"
\ No newline at end of file diff --git a/libpsn00b/psxgte/makefile b/libpsn00b/psxgte/makefile index 270f719..dde722a 100644 --- a/libpsn00b/psxgte/makefile +++ b/libpsn00b/psxgte/makefile @@ -1,22 +1,26 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxgte.a +TARGET = libpsxgte.a -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +INCLUDE = -I../include -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -strip-local-absolute +CFILES = $(notdir $(wildcard ./*.c)) +AFILES = $(notdir $(wildcard ./*.s)) +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -32,5 +36,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxsio/makefile b/libpsn00b/psxsio/makefile index 67ea93b..135a8a1 100644 --- a/libpsn00b/psxsio/makefile +++ b/libpsn00b/psxsio/makefile @@ -1,22 +1,26 @@ # Run using make (Linux) or gmake (BSD) # Part of the PSn00bSDK Project -# 2019 Lameguy64 / Meido-Tek Productions +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -include ../common.mk +include ../../psn00bsdk-setup.mk -TARGET = ../libpsxsio.a +TARGET = libpsxsio.a -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +INCLUDE = -I../include -CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -Wa,--strip-local-absolute +CFILES = $(notdir $(wildcard ./*.c)) +AFILES = $(notdir $(wildcard ./*.s)) +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFLAGS = -g -O2 -msoft-float -fno-builtin -fdata-sections \ + -ffunction-sections -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -Wa,--strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -32,5 +36,11 @@ build/%.o: %.s @mkdir -p $(dir $@) $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@ +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) + clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/psxsio/siocons.c b/libpsn00b/psxsio/siocons.c index 703504f..db35eda 100644 --- a/libpsn00b/psxsio/siocons.c +++ b/libpsn00b/psxsio/siocons.c @@ -2,7 +2,7 @@ #include <string.h> #include <ioctl.h> #include <psxapi.h> -#include <psxgpu.h> +#include <psxetc.h> #include <psxsio.h> #define SIO_BUFF_LEN 32 diff --git a/libpsn00b/psxspu/makefile b/libpsn00b/psxspu/makefile index c492ffe..25ec051 100644 --- a/libpsn00b/psxspu/makefile +++ b/libpsn00b/psxspu/makefile @@ -1,18 +1,26 @@ -include ../common.mk +# Run using make (Linux) or gmake (BSD) +# Part of the PSn00bSDK Project +# 2019 - 2020 Lameguy64 / Meido-Tek Productions -TARGET = ../libpsxspu.a +include ../../psn00bsdk-setup.mk -CFILES = $(notdir $(wildcard ./*.c)) -AFILES = $(notdir $(wildcard ./*.s)) -OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) +TARGET = libpsxspu.a -CFLAGS = -g -O2 -msoft-float -fdata-sections -ffunction-sections -Wa,--strip-local-absolute -AFLAGS = -g -msoft-float -strip-local-absolute +INCLUDE = -I../include -CC = $(PREFIX)gcc -AS = $(PREFIX)as -AR = $(PREFIX)ar -RANLIB = $(PREFIX)ranlib +CFILES = $(notdir $(wildcard ./*.c)) +AFILES = $(notdir $(wildcard ./*.s)) +OFILES = $(addprefix build/,$(CFILES:.c=.o) $(AFILES:.s=.o)) + +CFLAGS = -g -O2 -msoft-float -fdata-sections -ffunction-sections \ + -Wa,--strip-local-absolute +AFLAGS = -g -msoft-float -strip-local-absolute + +ifndef PSN00BSDK_LIBS + +PSN00BSDK_LIBS = .. + +endif all: $(TARGET) @@ -27,6 +35,12 @@ build/%.o: %.c build/%.o: %.s @mkdir -p $(dir $@) $(AS) $(AFLAGS) $(INCLUDE) $< -o $@ + +install: +ifneq ($(PSN00BSDK_LIBS), "..") + @mkdir -p $(PSN00BSDK_LIBS) +endif + cp $(TARGET) $(PSN00BSDK_LIBS)/$(TARGET) clean: rm -Rf build $(TARGET) diff --git a/libpsn00b/readme.txt b/libpsn00b/readme.txt index b1b37ec..940746c 100644 --- a/libpsn00b/readme.txt +++ b/libpsn00b/readme.txt @@ -1,70 +1,98 @@ LibPSn00b, PSn00bSDK software libraries -2019 Lameguy64 / Meido-Tek Productions +2019 - 2020 Lameguy64 / Meido-Tek Productions Licensed under Mozilla Public License -LibPSn00b is a collection of libraries which make up the core backbone of -PSn00bSDK as it provides an essential software framework for developing -homebrew software for the PSX platform. Great majority of the libraries -are been written from scratch written in a mix of C and hand optimized -assembly language for best performance. - -These libraries can only be compiled with a build of GCC that supports mipsel -as one of the supported targets, naturally as these libraries are intended -for the PSX hardware which uses a MIPS R3000 CPU supported by mipsel. -Compiler version shouldn't matter much and should build fine in 9.1.0, -though 7.4.0 is the most recommended version to use as it is the version -currently used for the majority of the development and testing of LibPSn00b. +LibPSn00b is a collection of libraries that make up the core backbone of +PSn00bSDK, as it provides a higher level software interface for developing +software for the PS1 platform. The majority of the libraries are been written +from scratch in a mix of C and hand optimized assembly language for optimal +software performance. +These libraries can only be compiled using a build of GCC that targets +mipsel-unknown-elf. Compiler version shouldn't matter much and it should work +fine with GCC 9.1.0, though 7.4.0 is the recommended version as that is what +LibPSn00b is most tested most on. + Brief summary of libraries: - libc - Standard C library. Contains only a small subset of the full - standard C library such as string and memory manipulation - functions. Should include libgcc for special compiler specific - dependencies and prevents libc related linker hell. + libc - Standard C library. Covers only a small subset of the full + standard C library such as basic string and memory manipulation + functions. Should include libgcc to avoid libc/libgcc linker + hell (endless cross referencing). - psxgpu - GPU library for video and graphics control. Also includes - interrupt handling for various library subsystems. + psxgpu - GPU library for video, graphics control, and interrupt service + subsystem that other libraries that uses interrupts depend on. - psxgte - GTE library for GTE accelerated vector transformations necessary - for high performance 3D graphics. + psxgte - GTE library for hardware accelerated vector transformations + that are integral for high performance 3D graphics on the PS1 + (it is a Geometry Transformation Engine, NOT Transfer Engine). - psxapi - Provides access to various BIOS functions in the PSX BIOS. + psxapi - Provides function calls for using functions provided by the PS1 + BIOS. psxetc - Provides some miscellaneous features such as debug font. - psxspu - SPU library. Basic capabilities such as hardware init, - sample upload using DMA and playing samples are supported. - Lacks support for reverb and various sequenced music related - features. + psxspu - SPU library (work in progress). Currently supports hardware + init, sample data upload via DMA and playing sound samples. + Lacks support for reverb and a sequenced music subsystem. - psxcd - CD-ROM support library. Provides greater CD-ROM functionality - than what the BIOS subsystem can provide. + psxcd - CD-ROM library for loading files, parsing directories + (PSn00bSDK addition), CD Audio/XA playback with provisions for + data streaming. Also supports multi-session discs (must be + selected manually). Each library has its own readme file that contains a todo list, credits - and some additional details of the library. Changelog of all libraries are - compiled in the changelog.txt file. + and some additional details of the library. Changes of all the libraries + must be covered in the changelog.txt file. Compiling: - Compiling the LibPSn00b libraries requires GCC and binutils targeting - mipsel-unknown-elf built with libgcc. The path to those binaries must be - specified in your PATH environment variable and the binaries must be - prefixed by the target architecture (ie. mipsel-unknown-elf-gcc). - - Simply run the Makefile in this directory with make (or gmake if you're - working in a BSD environment). The Makefile should parse though each - library directory and run the makefile in it. + To compile the LibPSn00b libraries, you will first need a working GCC + toolchain which you can either build yourself as described in the + toolchain.txt file (preferred on Linux/BSDs) or download a precompiled + toolchain from the PSn00bSDK page of Lameguy64's website: + http://lameguy64.net/?page=psn00bsdk + + Once the toolchain is set up, you may want to set the following + environment variables if they're required for your particular setup: + + * PSN00BSDK_TC specifies the base directory of the GCC toolchain to + compile the libraries with. If GCC_BASE is defined in the environment it + will use the path of that variable instead. If neither variable is + defined the makefiles will assume the toolchain binaries are accessible + from your PATH variable and the GCC toolchain directory is at + C:\mipsel-unknown-elf in Windows or /usr/local/mipsel-unknown-elf + in Linux/BSD. + + * GCC_VERSION specifies the version of the toolchain. If not specified + the makefiles will default to 7.4.0. This is only used for building the + libc library which needs to inherit the libgcc library from the + toolchain directories to avoid the aforementioned linker hell, and the + path to that library file includes a directory named after the version + number. + + * PSN00BSDK_LIBS specifies the absolute directory path you wish the + compiled libraries will be copied to. If not defined the compiled + libraries will simply be copied to the parent directory of the libraries + (libpsn00b). + + Once the environment variables are set, building the libraries should just + be a matter of simply running 'make all install' within the LibPSn00b + directory and it should run through all the libraries. You may specify a + -j parameter to run the jobs in parallel on a mult-processor/core/thread + system. Documentation: - Documentation of all the libraries are found in libn00bref.odf and it - features the same formatting as the official library documents. It is - recommended to export it as a PDF document for easier viewing. + LibPSn00b documentation is all covered in the LibPSn00b Reference.odf + document complete with the same document formatting as found in official + library documents. It may be wise to export the document as a PDF + document for easier viewing. Contributing: @@ -84,28 +112,30 @@ Contributing: * Don't forget to put your name in the readme file of the library you've made a contribution on and details of what you've changed in the - changelog.txt file. Annoyingmous is not tolerated in this project. + changelog.txt file. Updates by 'annoyingmous' are not tolerated in this + project. * New functions that are not originally in the official SDK must be marked as original code in both the library headers and the libn00bref document to help differentiate from original functions and new additions. -LibPSn00b to-do list: +LibPSn00b Library to-do list: Because the PSn00bSDK project still a work in progress, a number of - essential libraries are considered but not yet developed. The following - lists a number of essential libraries not yet developed. + libraries have been considered but not yet developed. The following + lists a number of libraries that are not yet in development. psxpad - Pad/tap/gun library for better controller support. May support PS2 controllers natively. Should provide functions for directly controlling the controller/memory card interfaces to cater to - development of custom peripherals. + the development of custom peripherals. - psxmcrd - Better and faster memory card library that works alongside the - psxpad library. + psxmcrd - Better and faster memory card library with provisions for + low-level card access. The psxpad library would provide + communication routines for the card library. - psxpress - MDEC and data decompression library. May use DEFLATE for - compressing MDEC data instead of Huffman as used in the - official libraries, which may yield better compression and - higher quality FMVs.
\ No newline at end of file + psxpress - MDEC and data decompression library. May use DEFLATE or LZ77 + for compressing MDEC data instead of Huffman as used in the + official libraries. It may yield better compression which may + potentially result in higher quality FMVs.
\ No newline at end of file diff --git a/psn00bsdk-setup.mk b/psn00bsdk-setup.mk new file mode 100644 index 0000000..4bd24be --- /dev/null +++ b/psn00bsdk-setup.mk @@ -0,0 +1,63 @@ +# PSn00bSDK project setup file +# Part of the PSn00bSDK Project +# 2019 - 2020 Lameguy64 / Meido-Tek Productions +# +# This file may be copied for use with your projects, see the template +# directory for a makefile template + +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 PSn00bSDK is in the same parent dir as this project + +LIBDIRS = -L../psn00bsdk/libpsn00b +INCLUDE = -I../psn00bsdk/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 |
