Collection of PsyQ basic examples NOT using libgs
Go to file
2021-07-06 15:51:26 +02:00
TIM add 3d gouraud textured cube example 2021-01-05 12:31:12 +01:00
VAG correct VAG Readme links 2020-12-22 12:39:47 +01:00
CPUMAC.H Add GTE optimization example : macro file 2021-07-06 13:20:45 +02:00
cube.blend add 3d gouraud cube example 2021-01-05 12:18:27 +01:00
cube.c Add light source example 2021-06-26 19:21:40 +02:00
cube.gif Beautify readme 2021-05-04 16:52:17 +02:00
cubetex.blend add 3d gouraud textured cube example 2021-01-05 12:31:12 +01:00
cubetex.c add cubetex 2021-01-05 12:32:38 +01:00
fun_with_poly.c gte init corrections 2020-12-28 12:05:26 +01:00
hello_2pads.c corrected R1 and R2 inverted 2021-04-18 19:08:55 +02:00
hello_cube.c Add light source example 2021-06-26 19:21:40 +02:00
hello_cubetex.c Correct vertex order 2021-06-26 12:08:27 +02:00
hello_gt.jpg add pic 2020-12-27 19:34:03 +01:00
hello_gte_opti.c Fix bug : ALWAYS init your vetors to 0! 2021-07-06 15:51:26 +02:00
hello_light.c Update header infos 2021-06-26 19:24:40 +02:00
hello_multivag.c add VAG examples 2020-12-22 12:26:30 +01:00
hello_pad.c add 2nd controller instructions 2020-12-26 16:55:39 +01:00
hello_poly_ft.c Add light source example 2021-06-26 19:21:40 +02:00
hello_poly_gt_tw.c add ref to possible tw values l.172 2021-04-18 18:51:47 +02:00
hello_poly_gt.c nextpri inc error 2020-12-29 12:05:19 +01:00
hello_poly_inline.c Add GTE inline polygon example 2021-07-05 12:45:22 +02:00
hello_poly.c Add light source example 2021-06-26 19:21:40 +02:00
hello_sio.c Add Serial example 2021-05-04 16:39:59 +02:00
hello_sprt.c typo in comment 2021-04-18 18:53:15 +02:00
hello_tile.c Clarify OT order vs drawing order 2021-06-26 11:51:19 +02:00
hello_vag.c add VAG examples 2020-12-22 12:26:30 +01:00
hello_world.c add world, poly, vag 2020-12-22 11:52:22 +01:00
LICENSE Initial commit 2020-12-21 17:26:40 +01:00
Makefile Add GTE optimization example 2021-07-06 13:17:31 +02:00
README.md Remove toxic word from readme 2021-06-07 10:35:31 +02:00

Nolibgs Hello Worlds !

3D power ! 3D power ! 3D power !

So you want to begin developping on the original PSX but don't know where to start ?

This repo is destined to host a bunch of simple examples, each describing how to do one thing.

The code here will be using PsyQ, the "Official" Sony SDK, but we will not be using libGS, the Extended Graphics Library for the graphic stuff...

Instead we'll try to devise methods to reproduce libgs functions. This will not necessarly be more efficient, but we'll learn a lot more stuff !

Setting up the SDK : Modern GCC + PsyQ a.k.a Nugget+PsyQ

For this we'll rely heavily on grumpy-coder's work with pcsx-redux and various tools, which will provide us with:

  • A way to compile the code with a modern version of GCC
  • An emulator with a lot of debugging features

Let's do it !

MacOS

  • On MacOs, a brew installation script can be found here.

Windows 10

GNU/Linux

  1. Install the needed software packages ( aka dependencies in Linux world ) :
  • To be able to build PsyQ code, you only need the MIPS toolchain :
sudo apt-get install gcc-mipsel-linux-gnu g++-mipsel-linux-gnu binutils-mipsel-linux-gnu
  • If you want to compile pcsx-redux, you need a few more packages :
sudo apt-get install -y git make pkg-config clang g++ libfreetype6-dev libavcodec-dev libavformat-dev libavutil-dev libglfw3-dev libsdl2-dev libswresample-dev libuv1-dev zlib1g-dev

See here if you're using an Arch derivative.

  1. Clone the pcsx-redux repo :
git clone https://github.com/grumpycoders/pcsx-redux.git --recursive
  1. Enter pcsx-redux folder:
cd pcsx-redux
  1. Compile pcsx-redux :
make

If you encounter an error due to an old version of GCC (< 10) like something about -fcoroutines, then you can use clang ( min version 9) to compile pcsx-redux :


CC=clang CXX=clang++ LD=clang++ make
  1. Get the converted PsyQ 4.7 libs :
wget http://psx.arthus.net/sdk/Psy-Q/psyq-4.7-converted-full.7z
  1. Extract this archive to [...]pcsx-redux/src/mips/psyq/, adapting the path ( the part after -o) in the command below to the folder you cloned pcsx-redux in :
7z x -o./src/mips/psyq/ psyq-4.7-converted-full.7z

Your pcsx-redux/src/mips/psyq/ directory should now contain an include and a lib folder with a bunch of files in each of them :

$tree ~/pcsx-redux/src/mips/psyq/
.
├── include
│   ├── abs.h
│   ├── ...
│   ├── strings.h
│   └── sys
│       ├── errno.h
│       ├── ...
│       └── types.h
├── lib
│   ├── libapi.a
│   ├── ...
│   └── libtap.a
└── tree

3 directories, 82 files
  1. That's it ! After that you can check everything's working by trying to compile some example code :
cd src/mips/psyq/cube
make 

You should know have a 'cube.ps-exe' file in the folder. This is a PSX executable you can load with most emulators.

Embedding binary data in a ps-exe

So, if you don't know it yet, the fun in PSX development is to be able to upload your exes on real hardware with a USB/Serial cable. This means that the data you'll use in your program ( graphics, sounds, etc.) will have to be embedded in your exe in a binary form, as you won't be able to stream them from the serial port.

Well technically you could load them in memory before uploading your exe or stream them from a cd, but let's keep things simple for now.

With our setup, this is quite easy !

  1. In pcsx-redux/src/mips/common.mk , add the lines :
# convert TIM file to bin
%.o: %.tim
  $(PREFIX)-objcopy -I binary --set-section-alignment .data=4 --rename-section .data=.rodata,alloc,load,readonly,data,contents -O elf32-tradlittlemips -B mips $< $@

# convert VAG files to bin
%.o: %.vag
  $(PREFIX)-objcopy -I binary --set-section-alignment .data=4 --rename-section .data=.rodata,alloc,load,readonly,data,contents -O elf32-tradlittlemips -B mips $< $@

If you pay attention, you can see that's the same command, but for different file types. TIM files are bitmap images and VAG is the sound format used in this example. Each time you'll want to add a file type, duplicate and change %.vag to %.filetype

Then, in your project folder, copy the makefile from the cube example :

mkdir new_project && cd new_project
cp ../cube/Makefile ../

All you have to do now is add the files you wish to embed to the SRCS variable, without forgetting the \ :

SRCS = main.c \
../common/crt0/crt0.s \
file_to_embed.ext \
  1. So this part takes care of converting our data to binary. Now to access them from your program, use this in your sources :
extern ulong _binary_filename_extension_start[]; 
extern ulong _binary_filename_extension_end[];
extern ulong _binary_bowsht_tim_length[];

The filename variable must begin with _binary_ followed by the full path of your file, with . and / replaced by _ (underscore), and end with _start[]; or _end[]; or _length[]; source

_start and _end are pointers, while _length is a constant.

That's it! When you'll type make next time, it should convert your files to .o, then include them in your ps-exe.

Compiling the examples in this repo

All you have to do is uncomment the corresponding rules in Makefile then compile with make.

Links and Doc

Credits, thanks, hugs

Everything here was learnt from some more talented persons, mainly but not excluding others that hang around on the psxdev discord Nicolas Noble, Lameguy64, NDR008, Jaby smoll seamonstah, danhans42, rama, sickle, paul, squaresoft74, and lot mores !