aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wilbert M. Villamor <lameguy64@gmail.com>2021-02-18 13:31:17 +0800
committerJohn Wilbert M. Villamor <lameguy64@gmail.com>2021-02-18 13:31:17 +0800
commit63419d9cc07c56234d0f61a80f32105b192aec8e (patch)
tree827cf4d134cf3b4618d0167cc912f3efd47c3aac
parent1625072293c40ba3cb819f8f48aeb4b64e93b133 (diff)
downloadpsn00bsdk-63419d9cc07c56234d0f61a80f32105b192aec8e.tar.gz
Lots of makefile corrections, improved build and toolchain instructions, added elf2cpe converter, fixed typo in plasma_tbl.h of n00bdemo example
-rw-r--r--README.md104
-rw-r--r--changelog.txt23
-rw-r--r--examples/beginner/cppdemo/makefile2
-rw-r--r--examples/beginner/hello/makefile2
-rw-r--r--examples/cdrom/cdbrowse/makefile4
-rw-r--r--examples/cdrom/cdxa/makefile4
-rw-r--r--examples/demos/n00bdemo/makefile2
-rw-r--r--examples/demos/n00bdemo/plasma_tbl.h2
-rw-r--r--examples/examples-setup.mk14
-rw-r--r--examples/graphics/balls/makefile2
-rw-r--r--examples/graphics/billboard/makefile3
-rw-r--r--examples/graphics/fpscam/makefile3
-rw-r--r--examples/graphics/gte/makefile3
-rw-r--r--examples/graphics/hdtv/makefile3
-rw-r--r--examples/graphics/render2tex/makefile3
-rw-r--r--examples/graphics/rgb24/makefile3
-rw-r--r--examples/lowlevel/cartrom/rom.s3
-rw-r--r--examples/makefile10
-rw-r--r--examples/system/childexec/makefile3
-rw-r--r--examples/system/console/makefile2
-rw-r--r--examples/system/timer/makefile3
-rw-r--r--examples/system/tty/makefile2
-rw-r--r--libpsn00b/libc/makefile2
-rw-r--r--template/main.c118
-rw-r--r--template/makefile54
-rw-r--r--template/psn00bsdk-setup.mk (renamed from psn00bsdk-setup.mk)18
-rw-r--r--toolchain.txt51
-rw-r--r--tools/util/elf.h45
-rw-r--r--tools/util/elf2cpe.c251
-rw-r--r--tools/util/elf2x.c45
-rw-r--r--tools/util/makefile1
31 files changed, 640 insertions, 145 deletions
diff --git a/README.md b/README.md
index 5610a26..af9fc75 100644
--- a/README.md
+++ b/README.md
@@ -39,35 +39,37 @@ As of January 5, 2021
ROM checks used.
* Extensive GTE support with rotate, translate, perspective correction and
- lighting fully supported via C and assembly GTE macros, with high speed
- matrix and vector functions. All calculations performed in fixed point
- integer math.
+ lighting fully supported via C and assembly GTE macros paired with high
+ speed matrix and vector functions. All calculations performed in fixed
+ point integer math, not a single float defined.
* Flexible interrupt service routine with easy to use callback mechanism for
simplified handling and hooking of hardware and DMA interrupts, no crude
event handler hooks or kernel hacks providing great compatibility with
- HLE BIOS implementations. Should work without issue in loader/menu type
- programs.
+ HLE BIOS implementations. Should work without issue for loader/menu type
+ programs as well.
* Complete Serial I/O support with SIOCONS driver for tty stdin/stdout
- console access. Hardware handshake for flow control also supported.
+ console access. Hardware flow control also supported.
* BIOS controller functions for polling controller input work as intended
thanks to proper handling of hardware interrupts. No crude manual polling
of controllers in a main loop. BIOS memory card functions may also work,
but not yet tested extensively.
-* Full CD-ROM support with data read, CD audio and XA audio playback support.
- 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). Also supports reading new disc
- sessions in a multi-session disc.
+* Full CD-ROM support via libpsxcd with data read, CD audio and XA audio
+ playback support. Features built-in ISO9660 file system parser for locating
+ and querying files and directories. Supports directories containing more
+ than 30 files (classic ISO9660 only, no Rock Ridge or Joliet extensions)
+ and also supports reading new sessions on a multi-session disc.
* Uses Sony SDK library syntax for familiarity to experienced programmers
and to make porting existing homebrew projects to PSn00bSDK easier.
* Works on real hardware and most popular emulators.
+* Fully expandable and customizable to your heart's content.
+
## Obtaining PSn00bSDK
@@ -90,48 +92,56 @@ make command line, to specify various parameters in building PSn00bSDK and
projects made with it as you see fit.
* ``GCC_VERSION`` specifies the GCC version number. This is only required for
- building the libc library. If not defined, the default value of `7.4.0` is
+ 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 path to
- the toolchain binaries in one of your PATH directories.
+ the toolchain binaries in one of your PATH directories. Alternatively,
+ ``GCC_BASE`` can be specified in place of ``PSN00BSDK_TC``. If not
+ specified psn00bsdk-setup.mk assumes the toolchain is at
+ C:\mipsel-unknown-elf in Win32 or /usr/local/mipsel-unknown-elf in Linux.
* ``PSN00BSDK_LIBS`` specifies the target directory you wish to install
the compiled libpsn00b libraries to. If not defined, compiled
- libraries are consolidated to the libpsn00b directory.
+ libraries are consolidated to the libpsn00b directory and
+ psn00bsdk-setup.mk assumes the SDK libraries are at ../psn00bsdk/libpsn00b.
### Windows:
1. Download the following:
* MSys2 (32-bit or 64-bit version whichever you prefer)
* GCC 7.4.0 for mipsel-unknown-elf (download from Lameguy64's website at
- http://lameguy64.net?page=psn00bsdk )
+ http://lameguy64.net?page=psn00bsdk if you rather not build it yourself)
2. Install MSys2, update packages (with pacman -Syu) then install the
following packages:
* git
* make
* mingw-w64-i686-gcc (32-bit) or mingw-w64-x86_64-gcc (64-bit)
- You will need to close and reopen MSys2 for the PATH environment to
- update for MinGW.
+ You may need to close and reopen MSys2 for the PATH environment in the
+ shell to update for MinGW.
* mingw-w64-i686-tinyxml2 (32-bit) or mingw-w64-x86_64-tinyxml2 (64-bit)
+ Used by lzpack and smxlink.
3. Extract GCC 7.4.0 for mipsel-unknown-elf to the root of your C drive.
4. Edit `mipsel-unknown-elf/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x`
- and update the .text definitions as explained in toolchain.txt.
+ and append definitions to the .text definition as explained in
+ toolchain.txt.
5. Add `export PATH=$PATH:/c/mipsel-unknown-elf/bin` to your `.bash_profile`
- file in MSys2. Test if mipsel-unknown-elf-gcc can be called from any
- directory in the terminal.
+ file in MSys2. Test if `mipsel-unknown-elf-gcc` can be called from any
+ directory in the terminal after reloading the MSys2 shell for the change
+ to take effect.
6. Clone from PSn00bSDK source with
`git clone https://github.com/lameguy64/psn00bsdk`
- Clone it in the root of your C drive or in any location you choose.
-7. Enter tools directory in PSn00bSDK and run `make` to build all tools.
- Then, run `make install` to consolidate all tools to a single bin
+ Clone it in the root of your C drive or in any location you prefer.
+7. Enter the tools directory in PSn00bSDK and run `make` to build all tools,
+ then run `make install` to consolidate all tools to a single bin
directory. Add this directory to your PATH variable by adding
- `export=$PATH:<path to SDK>/tools/bin` in your .bash_profile file. You'll
- need to reload the MSys2 shell after making the changes.
+ `export=$PATH:<path to SDK>/tools/bin` in your .bash_profile. Reload
+ the MSys2 shell for the changes to take effect, then enter `elf2x` if
+ the tools can be executed from any directory.
8. Enter libpsn00b directory and run `make` to build all libpsn00b libraries,
- then `make install` to consolidate the libraries to the parent directory
- or the directory specified by ``PSN00BSDK_LIBS``.
-6. Compile the example programs to test if the SDK is set up correctly.
- Update directory paths in `sdk-common.mk` when necessary.
+ then `make install` to consolidate the libraries to either the parent
+ directory or the directory specified by ``PSN00BSDK_LIBS``.
+6. Compile the example programs by running `make` from the examples
+ directory to test the SDK.
If you prefer to do things in the Command Prompt, you can add the paths
c:\msys64\usr\bin, c:\msys64\mingw64\bin (mingw32 for 32-bit),
@@ -146,19 +156,20 @@ programs with PSn00bSDK within the Command Prompt.
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). 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.
+ containing a path to the installed toolchain's base directory if
+ you've installed the toolchain in a location other than /usr/local.
+ 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` and `lzpack` (required for n00bDEMO) is accessible from
- any directory.
-5. Enter the libpsn00b directory and run `make`. Then, run `make install` to
- consolidate the libraries to the libpsn00b parent directory or the
+ the tools to the bin directory. Add this directory to your PATH variable
+ and make sure `elf2x` and other tools are accessible from any directory.
+5. Enter the libpsn00b directory and run `make`. Then, run `make install`
+ to consolidate the libraries to the libpsn00b parent directory, or the
directory specified by ``PSN00BSDK_LIBS``.
-6. Compile example programs to test if the SDK is set up correctly.
+6. Compile the example programs by running `make` from the examples
+ directory to test the SDK.
## Examples
@@ -167,15 +178,24 @@ There are a few examples and complete source code of n00bdemo included in
the examples directory. More example programs may be added in the future
and contributed example programs are welcome.
+There's also Lameguy's PlayStation Programming Tutorial Series at
+http://lameguy64.net/tutorials/pstutorials/ for learning how to program
+for the PlayStation. The tutorials should still apply to PSn00bSDK.
+
## To-do List
* psxspu: Plenty of work to be done. Hardware timer driven sound/music
system may need to be implemented (an equivalent to the Ss* series of
- functions in libspu basically).
+ functions in libspu basically). Need to figure out the correct frequency
+ table for playing sounds in musical note notation.
+* psxcd: Implement a command queue mechanism for the CD-ROM?
+
* Support for MDEC.
+* Pad and memory card libraries that don't use the BIOS routines.
+
## Usage terms
@@ -200,10 +220,12 @@ Main developer:
* Lameguy64
Honorable mentions:
-* ijacquez (for the helpful suggestions for getting C++ working)
+* ijacquez - helpful suggestions for getting C++ working.
+* NicolasNoble - his OpenBIOS project gave insight to how the BIOS works
+ internally.
Helpful contributors can be found in the changelog.
References used:
* nocash's PlayStation specs document (http://problemkaputt.de/psx-spx.htm)
-* Tails92's PSXSDK project.
+* Tails92's PSXSDK project (during PSn00bSDK's infancy).
diff --git a/changelog.txt b/changelog.txt
index 0e7b514..b7cac11 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -2,6 +2,29 @@ PSn00bSDK changelog
Items that are lower in the log are more recently implemented.
+02-17-2021 by Lameguy64:
+
+* Improved build instructions in readme file and fixed some typos.
+
+* Improved toolchain.txt instructions.
+
+* tools: Added experimental elf2cpe converter for executing PSn00bSDK
+ programs in official development units. No debug symbols however.
+
+* Fixed prefixes to allow SDK libraries and examples to be built
+ with mipsel-none-elf.
+
+* examples: Fixed typo in plasma_tbl.h causing multiple definitions when
+ compiling with newer versions of GCC in n00bdemo.
+
+* examples: cartrom example now marked as obsoleted, but still kept for
+ reference purposes.
+
+* Includes alextrevisan's GTE macros in inline_c.h.
+
+* Added makefile template.
+
+
01-05-2021 by Lameguy64:
* psxgpu: Added struct names to many primitives.
diff --git a/examples/beginner/cppdemo/makefile b/examples/beginner/cppdemo/makefile
index 6a29033..3e122ab 100644
--- a/examples/beginner/cppdemo/makefile
+++ b/examples/beginner/cppdemo/makefile
@@ -32,7 +32,7 @@ AFLAGS = -g -msoft-float
# Linker flags
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/beginner/hello/makefile b/examples/beginner/hello/makefile
index f80d2aa..3fce1ae 100644
--- a/examples/beginner/hello/makefile
+++ b/examples/beginner/hello/makefile
@@ -32,7 +32,7 @@ AFLAGS = -g -msoft-float
# Linker flags
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/cdrom/cdbrowse/makefile b/examples/cdrom/cdbrowse/makefile
index 61e54ab..ee925d2 100644
--- a/examples/cdrom/cdbrowse/makefile
+++ b/examples/cdrom/cdbrowse/makefile
@@ -8,8 +8,6 @@ AFILES = $(notdir $(wildcard *.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o))
-PREFIX = mipsel-unknown-elf-
-
LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
@@ -22,7 +20,7 @@ CPPFLAGS = $(CFLAGS) \
AFLAGS = -g -msoft-float
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/cdrom/cdxa/makefile b/examples/cdrom/cdxa/makefile
index 8d6d215..b95efa7 100644
--- a/examples/cdrom/cdxa/makefile
+++ b/examples/cdrom/cdxa/makefile
@@ -8,8 +8,6 @@ AFILES = $(notdir $(wildcard *.s))
OFILES = $(addprefix build/,$(CFILES:.c=.o) $(CPPFILES:.cpp=.o) $(AFILES:.s=.o))
-PREFIX = mipsel-unknown-elf-
-
LIBS = -lpsxcd -lpsxgpu -lpsxgte -lpsxspu -lpsxsio -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
@@ -22,7 +20,7 @@ CPPFLAGS = $(CFLAGS) \
AFLAGS = -g -msoft-float
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/demos/n00bdemo/makefile b/examples/demos/n00bdemo/makefile
index 27d0f1e..7e3bd8e 100644
--- a/examples/demos/n00bdemo/makefile
+++ b/examples/demos/n00bdemo/makefile
@@ -14,7 +14,7 @@ LIBS = -llzp -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: resources $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/demos/n00bdemo/plasma_tbl.h b/examples/demos/n00bdemo/plasma_tbl.h
index dd322e6..9f54f98 100644
--- a/examples/demos/n00bdemo/plasma_tbl.h
+++ b/examples/demos/n00bdemo/plasma_tbl.h
@@ -1,7 +1,7 @@
#ifndef _PLASMA_TBL_H
#define _PLASMA_TBL_H
-unsigned int plasma_colors[256];
+extern unsigned int plasma_colors[];
extern short plasma_sin1[];
extern short plasma_sin2[];
extern short plasma_sin3[];
diff --git a/examples/examples-setup.mk b/examples/examples-setup.mk
index 0692d89..1fadd84 100644
--- a/examples/examples-setup.mk
+++ b/examples/examples-setup.mk
@@ -5,7 +5,7 @@
# This is only for the PSn00bSDK example programs, not recommended
# for use with user projects
-PREFIX = mipsel-unknown-elf-
+PREFIX = mipsel-unknown-elf
ifndef GCC_VERSION
@@ -56,9 +56,9 @@ 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
-LD = $(GCC_BIN)$(PREFIX)ld
-RANLIB = $(GCC_BIN)$(PREFIX)ranlib \ No newline at end of file
+CC = $(GCC_BIN)$(PREFIX)-gcc
+CXX = $(GCC_BIN)$(PREFIX)-g++
+AS = $(GCC_BIN)$(PREFIX)-as
+AR = $(GCC_BIN)$(PREFIX)-ar
+LD = $(GCC_BIN)$(PREFIX)-ld
+RANLIB = $(GCC_BIN)$(PREFIX)-ranlib \ No newline at end of file
diff --git a/examples/graphics/balls/makefile b/examples/graphics/balls/makefile
index f697fab..70f41bf 100644
--- a/examples/graphics/balls/makefile
+++ b/examples/graphics/balls/makefile
@@ -32,7 +32,7 @@ AFLAGS = -g -msoft-float
# Linker flags
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/billboard/makefile b/examples/graphics/billboard/makefile
index 5131d88..4f0fcf4 100644
--- a/examples/graphics/billboard/makefile
+++ b/examples/graphics/billboard/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/fpscam/makefile b/examples/graphics/fpscam/makefile
index dd2b13e..dac1d43 100644
--- a/examples/graphics/fpscam/makefile
+++ b/examples/graphics/fpscam/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/gte/makefile b/examples/graphics/gte/makefile
index bfcaff1..43b7c5b 100644
--- a/examples/graphics/gte/makefile
+++ b/examples/graphics/gte/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/hdtv/makefile b/examples/graphics/hdtv/makefile
index d9321bf..2c7cb71 100644
--- a/examples/graphics/hdtv/makefile
+++ b/examples/graphics/hdtv/makefile
@@ -17,7 +17,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/render2tex/makefile b/examples/graphics/render2tex/makefile
index c69d37f..52d650b 100644
--- a/examples/graphics/render2tex/makefile
+++ b/examples/graphics/render2tex/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/graphics/rgb24/makefile b/examples/graphics/rgb24/makefile
index 5c08f87..3ec9cfe 100644
--- a/examples/graphics/rgb24/makefile
+++ b/examples/graphics/rgb24/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/lowlevel/cartrom/rom.s b/examples/lowlevel/cartrom/rom.s
index 14c1167..587ba6f 100644
--- a/examples/lowlevel/cartrom/rom.s
+++ b/examples/lowlevel/cartrom/rom.s
@@ -3,6 +3,9 @@
#
# TurboBoot Example by Lameguy64
#
+# Note: This example is being obsoleted as GAS is not ideal for making
+# ROM firmwares. Use ARMIPS instead, but it cannot build this example
+# as it is not GAS syntax compatible.
# Uncomment either PAR or XPLORER depending on the cartridge
diff --git a/examples/makefile b/examples/makefile
index 84ca0a4..e02f7ba 100644
--- a/examples/makefile
+++ b/examples/makefile
@@ -8,14 +8,16 @@ TOPTARGETS = all clean
DIRS = beginner/hello beginner/cppdemo
# Graphics examples
-DIRS += graphics/balls graphics/billboard graphics/fpscam graphics/gte \
- graphics/hdtv graphics/render2tex graphics/rgb24
+DIRS += graphics/balls graphics/billboard graphics/fpscam \
+ graphics/gte graphics/hdtv graphics/render2tex \
+ graphics/rgb24
# System related examples
-DIRS += system/childexec system/console system/timer system/tty
+DIRS += system/childexec system/console system/timer \
+ system/tty
# Low-level examples
-DIRS += lowlevel/cartrom
+DIRS +=
# CD-ROM examples
DIRS += cdrom/cdbrowse cdrom/cdxa
diff --git a/examples/system/childexec/makefile b/examples/system/childexec/makefile
index b1952fc..30229ae 100644
--- a/examples/system/childexec/makefile
+++ b/examples/system/childexec/makefile
@@ -8,7 +8,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
LDFLAGS_P = $(LDFLAGS) -Ttext=0x80010000
LDFLAGS_C = $(LDFLAGS) -Ttext=0x80030000
diff --git a/examples/system/console/makefile b/examples/system/console/makefile
index 4e0456e..1ee638f 100644
--- a/examples/system/console/makefile
+++ b/examples/system/console/makefile
@@ -32,7 +32,7 @@ AFLAGS = -g -msoft-float
# Linker flags
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/system/timer/makefile b/examples/system/timer/makefile
index 4b4c1a6..a8defe7 100644
--- a/examples/system/timer/makefile
+++ b/examples/system/timer/makefile
@@ -16,7 +16,8 @@ LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS) -fno-exceptions
AFLAGS = -g -msoft-float
-LDFLAGS = -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/examples/system/tty/makefile b/examples/system/tty/makefile
index 5514916..43893d5 100644
--- a/examples/system/tty/makefile
+++ b/examples/system/tty/makefile
@@ -32,7 +32,7 @@ AFLAGS = -g -msoft-float
# Linker flags
LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
- -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
all: $(OFILES)
$(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
diff --git a/libpsn00b/libc/makefile b/libpsn00b/libc/makefile
index f639823..adfd92b 100644
--- a/libpsn00b/libc/makefile
+++ b/libpsn00b/libc/makefile
@@ -28,7 +28,7 @@ endif
all: $(TARGET)
$(TARGET): $(OFILES)
- cp $(GCC_BASE)/lib/gcc/mipsel-unknown-elf/$(GCC_VERSION)/libgcc.a ./$(TARGET)
+ cp $(GCC_BASE)/lib/gcc/$(PREFIX)/$(GCC_VERSION)/libgcc.a ./$(TARGET)
$(AR) r $(TARGET) $(OFILES)
$(RANLIB) $(TARGET)
diff --git a/template/main.c b/template/main.c
new file mode 100644
index 0000000..1f02f0b
--- /dev/null
+++ b/template/main.c
@@ -0,0 +1,118 @@
+/*
+ * LibPSn00b Example Programs
+ *
+ * Hello World Example
+ * 2019-2020 Meido-Tek Productions / PSn00bSDK Project
+ *
+ * The obligatory hello world example normally included in nearly every
+ * SDK package. This example should also get you started in how to manage
+ * the display using psxgpu.
+ *
+ * Example by Lameguy64
+ *
+ *
+ * Changelog:
+ *
+ * January 1, 2020 - Initial version
+ */
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <psxetc.h>
+#include <psxgte.h>
+#include <psxgpu.h>
+
+
+// Define display/draw environments for double buffering
+DISPENV disp[2];
+DRAWENV draw[2];
+int db;
+
+
+// Init function
+void init(void)
+{
+ // This not only resets the GPU but it also installs the library's
+ // ISR subsystem to the kernel
+ ResetGraph(0);
+
+ // Define display environments, first on top and second on bottom
+ SetDefDispEnv(&disp[0], 0, 0, 320, 240);
+ SetDefDispEnv(&disp[1], 0, 240, 320, 240);
+
+ // Define drawing environments, first on bottom and second on top
+ SetDefDrawEnv(&draw[0], 0, 240, 320, 240);
+ SetDefDrawEnv(&draw[1], 0, 0, 320, 240);
+
+ // Set and enable clear color
+ setRGB0(&draw[0], 0, 96, 0);
+ setRGB0(&draw[1], 0, 96, 0);
+ draw[0].isbg = 1;
+ draw[1].isbg = 1;
+
+ // Clear double buffer counter
+ db = 0;
+
+ // Apply the GPU environments
+ PutDispEnv(&disp[db]);
+ PutDrawEnv(&draw[db]);
+
+ // Load test font
+ FntLoad(960, 0);
+
+ // Open up a test font text stream of 100 characters
+ FntOpen(0, 8, 320, 224, 0, 100);
+}
+
+// Display function
+void display(void)
+{
+ // Flip buffer index
+ db = !db;
+
+ // Wait for all drawing to complete
+ DrawSync(0);
+
+ // Wait for vertical sync to cap the logic to 60fps (or 50 in PAL mode)
+ // and prevent screen tearing
+ VSync(0);
+
+ // Switch pages
+ PutDispEnv(&disp[db]);
+ PutDrawEnv(&draw[db]);
+
+ // Enable display output, ResetGraph() disables it by default
+ SetDispMask(1);
+
+}
+
+// Main function, program entrypoint
+int main(int argc, const char *argv[])
+{
+ int counter;
+
+ // Init stuff
+ init();
+
+ // Main loop
+ counter = 0;
+ while(1)
+ {
+
+ // Print the obligatory hello world and counter to show that the
+ // program isn't locking up to the last created text stream
+ FntPrint(-1, "HELLO WORLD\n");
+ FntPrint(-1, "COUNTER=%d\n", counter);
+
+ // Draw the last created text stream
+ FntFlush(-1);
+
+ // Update display
+ display();
+
+ // Increment the counter
+ counter++;
+ }
+
+ return 0;
+}
diff --git a/template/makefile b/template/makefile
new file mode 100644
index 0000000..42ff370
--- /dev/null
+++ b/template/makefile
@@ -0,0 +1,54 @@
+include psn00bsdk-setup.mk
+
+# Project target name
+TARGET = template.elf
+
+# Searches for C, C++ and S (assembler) files in local directory
+CFILES = $(notdir $(wildcard *.c))
+CPPFILES = $(notdir $(wildcard *.cpp))
+AFILES = $(notdir $(wildcard *.s))
+
+# Create names for object files
+OFILES = $(addprefix build/,$(CFILES:.c=.o)) \
+ $(addprefix build/,$(CPPFILES:.cpp=.o)) \
+ $(addprefix build/,$(AFILES:.s=.o))
+
+# Project specific include and library directories
+# (use -I for include dirs, -L for library dirs)
+INCLUDE +=
+LIBDIRS +=
+
+# Libraries to link
+LIBS = -lpsxgpu -lpsxgte -lpsxspu -lpsxetc -lpsxapi -lc
+
+# C compiler flags
+CFLAGS = -g -O2 -fno-builtin -fdata-sections -ffunction-sections
+
+# C++ compiler flags
+CPPFLAGS = $(CFLAGS) -fno-exceptions
+
+# Assembler flags
+AFLAGS = -g
+
+# Linker flags (-Ttext specifies the program text address)
+LDFLAGS = -g -Ttext=0x80010000 -gc-sections \
+ -T $(GCC_BASE)/$(PREFIX)/lib/ldscripts/elf32elmip.x
+
+all: $(OFILES)
+ $(LD) $(LDFLAGS) $(LIBDIRS) $(OFILES) $(LIBS) -o $(TARGET)
+ elf2x -q $(TARGET)
+
+build/%.o: %.c
+ @mkdir -p $(dir $@)
+ $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
+
+build/%.o: %.cpp
+ @mkdir -p $(dir $@)
+ $(CXX) $(AFLAGS) $(INCLUDE) -c $< -o $@
+
+build/%.o: %.s
+ @mkdir -p $(dir $@)
+ $(CC) $(AFLAGS) $(INCLUDE) -c $< -o $@
+
+clean:
+ rm -rf build $(TARGET) $(TARGET:.elf=.exe)
diff --git a/psn00bsdk-setup.mk b/template/psn00bsdk-setup.mk
index acf79e3..6ba23ae 100644
--- a/psn00bsdk-setup.mk
+++ b/template/psn00bsdk-setup.mk
@@ -5,7 +5,11 @@
# This file may be copied for use with your projects, see the template
# directory for a makefile template
-PREFIX = mipsel-unknown-elf-
+ifndef PREFIX
+
+PREFIX = mipsel-unknown-elf
+
+endif # PREFIX
ifndef GCC_VERSION
@@ -56,9 +60,9 @@ 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
-LD = $(GCC_BIN)$(PREFIX)ld
-RANLIB = $(GCC_BIN)$(PREFIX)ranlib \ No newline at end of file
+CC = $(GCC_BIN)$(PREFIX)-gcc
+CXX = $(GCC_BIN)$(PREFIX)-g++
+AS = $(GCC_BIN)$(PREFIX)-as
+AR = $(GCC_BIN)$(PREFIX)-ar
+LD = $(GCC_BIN)$(PREFIX)-ld
+RANLIB = $(GCC_BIN)$(PREFIX)-ranlib \ No newline at end of file
diff --git a/toolchain.txt b/toolchain.txt
index 9496f50..439f486 100644
--- a/toolchain.txt
+++ b/toolchain.txt
@@ -31,14 +31,14 @@ Make sure the following packages are installed prior to building:
Building binutils:
Binutils must be built first as GCC depends on binutils built for the same
-target architecture. In this case, to compile GCC targetting mipsel-unknown-elf,
-there must be a build of binutils targetting mipsel-unknown-elf as well.
+target architecture. In this case, building binutils and GCC to target
+mipsel-unknown-elf.
* Download binutils source files at ftp://ftp.gnu.org. Choose a version you
- wish to use with PSn00bSDK.
+ wish to use with PSn00bSDK. The reference version that PSn00bSDK is tested
+ with most is 2.31.
-* Extract the contents of the archive, preferably in a directory named gcc
- for example.
+* Extract the contents of the archive, preferably in a directory named gcc.
* Create a directory named binutils-build inside the gcc directory. Do not
create it inside the binutils directory with the source files.
@@ -59,17 +59,19 @@ root privileges to install).
system has available to speed up compiling).
* Run `make install-strip` to install binutils to the path specified by the
- --prefix argument (requires root privileges if you install to /usr/local).
+ --prefix argument (root privileges are required if the prefix points to
+ /usr/local).
Building gcc:
-With binutils built it should be possible to build the GCC compilers. Since
+With binutils built it should be possible to build the GCC toolchain. Since
GCC is considerably larger than binutils, compile time is going to be much
-longer so it's going to take a longer while to finish building.
+longer so it's going to take a longer while to build this.
-* Download gcc source files at ftp://ftp.gnu.org and choose a version you
- wish to use with PSn00bSDK.
+* Download gcc source files at ftp://ftp.gnu.org and choose the version you
+ wish to use with PSn00bSDK. The reference version that PSn00bSDK is tested
+ with most is 7.4.0.
* Extract it to the same gcc directory you extracted binutils in.
@@ -85,18 +87,19 @@ longer so it's going to take a longer while to finish building.
Replace <version> with the version of gcc you downloaded. The prefix path
must match to what you've specified for binutils earlier, if you've decided
-on a different path to install the toolchain to.
+to use a different prefix path for binutils.
-When building under Windows you must additionally specify --disable-libgcc, so
-libgcc won't be built as it requires symlinks not supported by the host system.
+When building under Windows you must additionally specify --disable-libgcc,
+as libgcc cannot be built under Windows as it needs symlinks which are not
+supported by the operating system.
-* Run make in the same manner as you built binutils to build gcc.
+* Run make in the same manner you built binutils with.
* Run `make install-strip` to install gcc to the path specified by --prefix
- (may require root privileges if you set the prefix to /usr/local).
+ (root privileges are required if the prefix points to /usr/local).
* Add a path to the bin directory of the toolchain into your PATH environment
- variable by adding the following line in your .bashrc file:
+ variable by adding the following line in your .bashrc or .bash_profile file:
export PATH=$PATH:/usr/local/mipsel-unknown-elf/bin
@@ -109,13 +112,13 @@ Updating the ldscript:
The following changes are required in order for basic C++ functionality to work
in PSn00bSDK. The changes define the constructor and deconstructor sections
which are required for the relevant support functions in PSn00bSDK's libc
-library to be linked properly.
+library to be linked properly for C++.
* Go to mipsel-unknown-elf/lib/ldscripts in the toolchain directory.
* Open elf32elmip.x in any text editor.
-* Locate the .text definition (with the {} brackets) and place the following
+* Locate the .text definition (with the {} brackets) and add the following
inside the bracket block:
__CTOR_LIST__ = .;
@@ -138,13 +141,14 @@ __DTOR_END__ = .;
* Save script changes.
-Since there's no known way (at least to me, Lameguy64) to configure GCC to use
-one of the scripts in ldscripts directory as a default, you must specify
-the modified script during the linking stage of your projects with the -T
+Since there's no known way (at least to me -Lameguy64) to configure GCC such
+that it uses the modified ldscript as the default, you must specify the
+modified script during the linking stage of your projects with the -T
argument, when invoking mipsel-unknown-elf-ld.
Alternatively, you can make a copy of the ldscript file and modify it within
-your project directory. This is especially useful when code overlaying is used.
+your project directory. This is especially useful if your project uses code
+overlays.
Note regarding C++ support:
@@ -156,3 +160,6 @@ the program. The required dependencies are supplied by libc of libpsn00b.
Standard C++ libraries are not implemented and likely never going to be
implemented due to bloat concerns that it may introduce. Besides, the official
SDK lacks full C++ support as well.
+
+If you're trying to compile with C++ code and you get a linker error about
+undefined vtables, try specifying --fno-rtti to the g++ command line. \ No newline at end of file
diff --git a/tools/util/elf.h b/tools/util/elf.h
new file mode 100644
index 0000000..9cb5cb3
--- /dev/null
+++ b/tools/util/elf.h
@@ -0,0 +1,45 @@
+#ifndef _ELF_H
+#define _ELF_H
+
+#pragma pack(push, 1)
+
+typedef struct {
+
+ unsigned int magic; // 0-3
+ unsigned char word_size; // 4
+ unsigned char endianness; // 5
+ unsigned char elf_version; // 6
+ unsigned char os_abi; // 7
+ unsigned int unused[2]; // 8-15
+
+ unsigned short type; // 16-17
+ unsigned short instr_set; // 18-19
+ unsigned int elf_version2; // 20-23
+
+ unsigned int prg_entry_addr; // 24-27
+ unsigned int prg_head_pos; // 28-31
+ unsigned int sec_head_pos; // 32-35
+ unsigned int flags; // 36-39
+ unsigned short head_size; // 40-41
+ unsigned short prg_entry_size; // 42-23
+ unsigned short prg_entry_count; // 44-45
+ unsigned short sec_entry_size; // 46-47
+ unsigned short sec_entry_count; // 48-49
+ unsigned short sec_names_index; // 50-51
+
+} ELF_HEADER;
+
+typedef struct {
+ unsigned int seg_type;
+ unsigned int p_offset;
+ unsigned int p_vaddr;
+ unsigned int undefined;
+ unsigned int p_filesz;
+ unsigned int p_memsz;
+ unsigned int flags;
+ unsigned int alignment;
+} PRG_HEADER;
+
+#pragma pack(pop)
+
+#endif /* _ELF_H */ \ No newline at end of file
diff --git a/tools/util/elf2cpe.c b/tools/util/elf2cpe.c
new file mode 100644
index 0000000..4379f4a
--- /dev/null
+++ b/tools/util/elf2cpe.c
@@ -0,0 +1,251 @@
+#include <stdio.h>
+#include <string.h>
+#include <malloc.h>
+#include "elf.h"
+
+#define MAX_prg_entry_count 128
+
+#ifndef false
+#define false 0
+#endif
+
+#ifndef true
+#define true 1
+#endif
+
+char *in_file = NULL;
+char *out_file = NULL;
+
+int quiet;
+
+int copydata( FILE *in, FILE *out, int len )
+{
+ char buff[8192];
+ int i,readlen;
+
+ while( len > 0 )
+ {
+ readlen = len;
+ if( readlen > 8192 )
+ {
+ readlen = 8192;
+ }
+
+ i = fread( buff, 1, readlen, in );
+ fwrite( buff, 1, i, out );
+
+ if( i < readlen )
+ {
+ break;
+ }
+ len -= readlen;
+ }
+
+ return( 0 );
+
+} /* copydata */
+
+int convertELF( void )
+{
+ ELF_HEADER head;
+ PRG_HEADER prg_heads[MAX_prg_entry_count];
+
+ int i;
+ char *output_name;
+
+ FILE *in_fp;
+ FILE *out_fp;
+
+ /* Generate output filename if no output is specified */
+ if( out_file )
+ {
+ output_name = out_file;
+ }
+ else
+ {
+ char *ptr;
+
+ output_name = strdup( in_file );
+
+ ptr = &output_name[strlen(output_name)];
+ while (ptr != output_name)
+ {
+ if (*ptr == '.')
+ break;
+ else
+ ptr--;
+ }
+
+ if( ptr != output_name )
+ {
+ strcpy( ptr, ".cpe" );
+ }
+ else
+ {
+ strcat( ptr, ".cpe" );
+ }
+ }
+
+ if( !out_file )
+ {
+ free( output_name );
+ }
+
+ if( !( in_fp = fopen( in_file, "rb" ) ) )
+ {
+ printf( "Cannot open input file.\n" );
+ return( -1 );
+ }
+
+ /* read ELF header */
+ fread( &head, 1, sizeof(head), in_fp );
+
+ /* test header to make sure it is valid */
+ if( head.magic != 0x464c457f )
+ {
+ printf( "File is not an ELF file.\n" );
+ fclose( in_fp );
+ return( -1 );
+ }
+
+ if( head.type != 2 )
+ {
+ printf( "Only executable ELF files are supported.\n" );
+ fclose( in_fp );
+ return( -1 );
+ }
+
+ if( head.instr_set != 8 )
+ {
+ printf( "ELF file is not a MIPS binary.\n" );
+ fclose( in_fp );
+ return( -1 );
+ }
+
+ if( head.word_size != 1 )
+ {
+ printf( "Only 32-bit ELF files are supported.\n" );
+ fclose( in_fp );
+ return( -1 );
+ }
+
+ if( head.endianness != 1 )
+ {
+ printf( "Only little endian ELF files are supported.\n" );
+ fclose( in_fp );
+ return( -1 );
+ }
+
+ /* read program headers */
+ fseek( in_fp, head.prg_head_pos, SEEK_SET );
+ fread( prg_heads, sizeof( PRG_HEADER ), head.prg_entry_count, in_fp );
+
+ if( !quiet )
+ {
+ printf( "pc:%08x\n", head.prg_entry_addr );
+ }
+
+ /* create the CPE file */
+ printf( "%s\n", output_name );
+ if( !( out_fp = fopen( output_name, "wb" ) ) )
+ {
+ printf( "Cannot create output file.\n" );
+ return( -1 );
+ }
+
+ /* create file header */
+ fputs( "CPE", out_fp );
+ fputc( 0x01, out_fp );
+
+ /* select unit 0 */
+ fputc( 0x08, out_fp ); /* chunk ID */
+ fputc( 0x00, out_fp ); /* unit number */
+
+ /* set entrypoint */
+ fputc( 0x03, out_fp ); /* chunk ID */
+ fputc( 0x90, out_fp ); /* entry point type */
+ fputc( 0x00, out_fp );
+ fwrite( &head.prg_entry_addr, 1, 4, out_fp );
+
+ /* copy the program chunks */
+ for( i=0; i<head.prg_entry_count; i++ )
+ {
+ if( prg_heads[i].flags == 4 )
+ {
+ continue;
+ }
+
+ /* seek to location of program chunk */
+ fseek( in_fp, prg_heads[i].p_offset, SEEK_SET );
+
+ /* create load chunk */
+ fputc( 0x01, out_fp ); /* chunk ID */
+ fwrite( &prg_heads[i].p_vaddr, 1, 4, out_fp ); /* load address */
+ fwrite( &prg_heads[i].p_filesz, 1, 4, out_fp ); /* load length */
+
+ /* copy the chunk data */
+ copydata( in_fp, out_fp, prg_heads[i].p_filesz );
+ }
+
+ /* end of file chunk */
+ fputc( 0x00, out_fp );
+
+ /* close files */
+ fclose( in_fp );
+ fclose( out_fp );
+
+ return( 0 );
+
+} /* convertELF */
+
+int main( int argc, char *argv[] )
+{
+ int i;
+
+ quiet = false;
+
+ /* parse program arguments */
+ for( i=1; i<argc; i++ )
+ {
+ if( strcasecmp( "-q", argv[i] ) == 0 )
+ {
+ quiet = true;
+ }
+ else
+ {
+ if( in_file == NULL )
+ {
+ in_file = argv[i];
+ }
+ else if( out_file == NULL )
+ {
+ out_file = argv[i];
+ }
+ }
+ }
+
+ /* print banner if not in quiet mode */
+ if( !quiet )
+ {
+ printf( "PSn00bSDK elf2cpe - Experimental ELF to CPE executable "
+ "converter\n" );
+ printf( "2021 Meido-Tek Productions\n\n" );
+ }
+
+ /* print usage parameters if no arguments specified */
+ if( argc == 1 )
+ {
+ printf( "Usage:\n" );
+ printf( " elf2cpe [-q] <elf_file> [cpe_file]\n" );
+ return( 0 );
+ }
+
+ if( !in_file )
+ {
+ printf( "No input file specified.\n" );
+ return( 0 );
+ }
+
+ return( convertELF() );
+
+} /* main */ \ No newline at end of file
diff --git a/tools/util/elf2x.c b/tools/util/elf2x.c
index 612ca41..26ec9a3 100644
--- a/tools/util/elf2x.c
+++ b/tools/util/elf2x.c
@@ -4,52 +4,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "elf.h"
#define MAX_prg_entry_count 128
#define true (1)
#define false (0)
-#pragma pack(push, 1)
-
-typedef struct {
-
- unsigned int magic; // 0-3
- unsigned char word_size; // 4
- unsigned char endianness; // 5
- unsigned char elf_version; // 6
- unsigned char os_abi; // 7
- unsigned int unused[2]; // 8-15
-
- unsigned short type; // 16-17
- unsigned short instr_set; // 18-19
- unsigned int elf_version2; // 20-23
-
- unsigned int prg_entry_addr; // 24-27
- unsigned int prg_head_pos; // 28-31
- unsigned int sec_head_pos; // 32-35
- unsigned int flags; // 36-39
- unsigned short head_size; // 40-41
- unsigned short prg_entry_size; // 42-23
- unsigned short prg_entry_count; // 44-45
- unsigned short sec_entry_size; // 46-47
- unsigned short sec_entry_count; // 48-49
- unsigned short sec_names_index; // 50-51
-
-} ELF_HEADER;
-
-typedef struct {
- unsigned int seg_type;
- unsigned int p_offset;
- unsigned int p_vaddr;
- unsigned int undefined;
- unsigned int p_filesz;
- unsigned int p_memsz;
- unsigned int flags;
- unsigned int alignment;
-} PRG_HEADER;
-
-#pragma pack(pop)
-
typedef struct {
unsigned int pc0;
unsigned int gp0;
@@ -112,7 +72,7 @@ int main(int argc, char** argv) {
if( !quiet ) {
printf( "PSn00bSDK elf2x - ELF to PS-EXE Converter\n" );
- printf( "2018-2019 Meido-Tek Productions\n\n" );
+ printf( "2018-2021 Meido-Tek Productions\n\n" );
}
if( argc == 1 ) {
@@ -140,6 +100,7 @@ int main(int argc, char** argv) {
// Check header
if( head.magic != 0x464c457f ) {
printf( "File is not an ELF file.\n" );
+ fclose( fp );
return EXIT_FAILURE;
}
diff --git a/tools/util/makefile b/tools/util/makefile
index c49a581..fe7aed5 100644
--- a/tools/util/makefile
+++ b/tools/util/makefile
@@ -10,6 +10,7 @@ endif
all:
$(CC) $(CFLAGS) elf2x.c -o elf2x$(EXE_SUFFIX)
+ $(CC) $(CFLAGS) elf2cpe.c -o elf2cpe$(EXE_SUFFIX)
install:
mkdir -p ../bin