aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-09-26 16:49:56 +0800
committerGitHub <noreply@github.com>2022-09-26 16:49:56 +0800
commitc4a2533d21dfd05cde841ea48c67b05e0e6a853f (patch)
treec7ef61653b157b69fb0956709366996ddbc4ecfa /examples
parenta8b404b3400c3ebd8e0b923dcaefcc49ea563e36 (diff)
parent86f0064afb8200e60dd80827535cac30d0eab028 (diff)
downloadpsn00bsdk-c4a2533d21dfd05cde841ea48c67b05e0e6a853f.tar.gz
Merge pull request #55 from spicyjpeg/psxmdec
Full MDEC support, C library refactors, cleanups and bugfixes (v0.20)
Diffstat (limited to 'examples')
-rw-r--r--examples/README.md11
-rw-r--r--examples/cdrom/cdbrowse/CMakeLists.txt4
-rw-r--r--examples/cdrom/cdbrowse/ball16c.h16
-rw-r--r--examples/cdrom/cdbrowse/ball16c.timbin0 -> 192 bytes
-rw-r--r--examples/cdrom/cdbrowse/main.c11
-rw-r--r--examples/cdrom/cdxa/CMakeLists.txt4
-rw-r--r--examples/cdrom/cdxa/ball16c.h16
-rw-r--r--examples/cdrom/cdxa/ball16c.timbin0 -> 192 bytes
-rw-r--r--examples/cdrom/cdxa/main.c30
-rw-r--r--examples/demos/n00bdemo/disp.c2
-rw-r--r--examples/demos/n00bdemo/smd.s4
-rw-r--r--examples/demos/n00bdemo/smd_cel.s4
-rw-r--r--examples/demos/n00bdemo/smd_flat.s4
-rw-r--r--examples/graphics/balls/CMakeLists.txt4
-rw-r--r--examples/graphics/balls/ball16c.h16
-rw-r--r--examples/graphics/balls/main.c16
-rw-r--r--examples/graphics/gte/CMakeLists.txt4
-rw-r--r--examples/graphics/gte/main.c49
-rw-r--r--examples/graphics/gte/texture.timbin0 -> 16928 bytes
-rw-r--r--examples/io/system573/k573io.c7
-rw-r--r--examples/io/system573/k573io.h64
-rw-r--r--examples/io/system573/main.c2
-rw-r--r--examples/mdec/mdecimage/main.c2
-rw-r--r--examples/sound/spustream/CMakeLists.txt7
-rw-r--r--examples/sound/spustream/main.c74
-rw-r--r--examples/sound/spustream/stream.binbin0 -> 4685824 bytes
-rw-r--r--examples/sound/vagsample/main.c73
-rw-r--r--examples/system/childexec/CMakeLists.txt1
-rw-r--r--examples/system/childexec/ball16c.h16
-rw-r--r--examples/system/childexec/ball16c.timbin0 -> 192 bytes
-rw-r--r--examples/system/childexec/child/child.c10
-rw-r--r--examples/system/childexec/parent.c10
-rw-r--r--examples/system/console/CMakeLists.txt4
-rw-r--r--examples/system/console/ball16c.h16
-rw-r--r--examples/system/console/ball16c.timbin0 -> 192 bytes
-rw-r--r--examples/system/console/main.c16
-rw-r--r--examples/system/dynlink/CMakeLists.txt4
-rw-r--r--examples/system/dynlink/library/ball16c.h16
-rw-r--r--examples/system/dynlink/library/ball16c.timbin0 -> 192 bytes
-rw-r--r--examples/system/dynlink/library/balls.c5
-rw-r--r--examples/system/dynlink/main.c8
41 files changed, 229 insertions, 301 deletions
diff --git a/examples/README.md b/examples/README.md
index 4025a56..82d7698 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -25,7 +25,7 @@ Additional information may be found in the source code of each example.
| [`io/system573`](./io/system573) | Konami System 573 (PS1-based arcade board) example | CD | |
| [`lowlevel/cartrom`](./lowlevel/cartrom) | ROM firmware for cheat devices written using GNU GAS | ROM | 4 |
| [`mdec/mdecimage`](./mdec/mdecimage) | Displays a (raw) MDEC format image using libpsxpress | EXE | |
-| [`sound/spustream`](./sound/spustream) | Custom (non XA) CD-ROM audio streaming using the SPU | CD | 1 |
+| [`sound/spustream`](./sound/spustream) | Custom (non XA) CD-ROM audio streaming using the SPU | CD | |
| [`sound/vagsample`](./sound/vagsample) | Demonstrates playing VAG sound files using the SPU | EXE | |
| [`system/childexec`](./system/childexec) | Loading a child program and returning to parent | EXE | |
| [`system/console`](./system/console) | TTY based text console that interrupts gameplay | EXE | |
@@ -35,10 +35,9 @@ Additional information may be found in the source code of each example.
Notes:
-1. `cdrom/cdxa` and `sound/spustream` do not come with example audio files. In
- order to run these examples you'll have to provide your own files (and, in
- the case of `spustream`, convert them using the included Python script) and
- build the CD image manually.
+1. `cdrom/cdxa` does not come with an example XA audio file. In order to run
+ this example you'll have to provide your own file and build the CD image
+ manually.
2. `demos/n00bdemo` suffers from flickering on real hardware, especially when
masking/stencil buffering is used.
3. `io/pads` seems to work on real hardware, but fails to automatically enable
@@ -85,4 +84,4 @@ are for rebuilding the examples *after* the SDK has been installed.
CD images for each example.
-----------------------------------------
-_Last updated on 2022-02-06 by spicyjpeg_
+_Last updated on 2022-08-11 by spicyjpeg_
diff --git a/examples/cdrom/cdbrowse/CMakeLists.txt b/examples/cdrom/cdbrowse/CMakeLists.txt
index e36407d..c2e93fc 100644
--- a/examples/cdrom/cdbrowse/CMakeLists.txt
+++ b/examples/cdrom/cdbrowse/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
cdbrowse
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK CD file browser example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -15,6 +15,8 @@ file(GLOB _sources *.c)
psn00bsdk_add_executable(cdbrowse STATIC ${_sources})
psn00bsdk_add_cd_image(cdbrowse_iso cdbrowse iso.xml DEPENDS cdbrowse)
+psn00bsdk_target_incbin(cdbrowse PRIVATE ball16c ball16c.tim)
+
install(
FILES
${PROJECT_BINARY_DIR}/cdbrowse.bin
diff --git a/examples/cdrom/cdbrowse/ball16c.h b/examples/cdrom/cdbrowse/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/cdrom/cdbrowse/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/cdrom/cdbrowse/ball16c.tim b/examples/cdrom/cdbrowse/ball16c.tim
new file mode 100644
index 0000000..e2a5d17
--- /dev/null
+++ b/examples/cdrom/cdbrowse/ball16c.tim
Binary files differ
diff --git a/examples/cdrom/cdbrowse/main.c b/examples/cdrom/cdbrowse/main.c
index 9a1dbd0..f614f1d 100644
--- a/examples/cdrom/cdbrowse/main.c
+++ b/examples/cdrom/cdbrowse/main.c
@@ -54,7 +54,7 @@
* July 12, 2020: Updated CD-ROM directory query logic on disc change slightly.
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -67,9 +67,6 @@
#include <psxspu.h>
#include <psxcd.h>
-#include "ball16c.h"
-
-
#define MAX_BALLS 1536 /* Number of balls to display */
#define OT_LEN 8 /* Ordering table length */
@@ -87,7 +84,7 @@ DISPENV disp[2];
DRAWENV draw[2];
char pribuff[2][65536]; /* Primitive packet buffers */
-u_long ot[2][OT_LEN]; /* Ordering tables */
+uint32_t ot[2][OT_LEN]; /* Ordering tables */
char *nextpri; /* Pointer to next packet buffer offset */
int db = 0; /* Double buffer index */
@@ -102,6 +99,8 @@ typedef struct BALL_TYPE
BALL_TYPE balls[MAX_BALLS];
+/* Ball texture reference */
+extern const uint32_t ball16c[];
/* TIM image parameters for loading the ball texture and drawing sprites */
TIM_IMAGE tim;
@@ -192,7 +191,7 @@ void init()
/* Upload the ball texture */
- GetTimInfo((u_long*)ball16c, &tim); /* Get TIM parameters */
+ GetTimInfo(ball16c, &tim); /* Get TIM parameters */
LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */
if( tim.mode & 0x8 )
{
diff --git a/examples/cdrom/cdxa/CMakeLists.txt b/examples/cdrom/cdxa/CMakeLists.txt
index 7b90f59..70ef77c 100644
--- a/examples/cdrom/cdxa/CMakeLists.txt
+++ b/examples/cdrom/cdxa/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
cdxa
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK CD-XA playback example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -16,6 +16,8 @@ file(GLOB _sources *.c)
psn00bsdk_add_executable(cdxa STATIC ${_sources})
#psn00bsdk_add_cd_image(cdxa_iso cdxa iso.xml DEPENDS cdxa)
+psn00bsdk_target_incbin(cdxa PRIVATE ball16c ball16c.tim)
+
install(
FILES
#${PROJECT_BINARY_DIR}/cdxa.bin
diff --git a/examples/cdrom/cdxa/ball16c.h b/examples/cdrom/cdxa/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/cdrom/cdxa/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/cdrom/cdxa/ball16c.tim b/examples/cdrom/cdxa/ball16c.tim
new file mode 100644
index 0000000..e2a5d17
--- /dev/null
+++ b/examples/cdrom/cdxa/ball16c.tim
Binary files differ
diff --git a/examples/cdrom/cdxa/main.c b/examples/cdrom/cdxa/main.c
index 284b92f..4921658 100644
--- a/examples/cdrom/cdxa/main.c
+++ b/examples/cdrom/cdxa/main.c
@@ -116,7 +116,7 @@
*
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -129,14 +129,10 @@
#include <psxspu.h>
#include <psxcd.h>
-#include "ball16c.h"
-
-
#define MAX_BALLS 1536 /* Number of balls to display */
#define OT_LEN 8 /* Ordering table length */
-
/* Screen coordinates */
#define SCREEN_XRES 320
#define SCREEN_YRES 240
@@ -150,7 +146,7 @@ DISPENV disp[2];
DRAWENV draw[2];
char pribuff[2][65536]; /* Primitive packet buffers */
-u_long ot[2][OT_LEN]; /* Ordering tables */
+uint32_t ot[2][OT_LEN]; /* Ordering tables */
char *nextpri; /* Pointer to next packet buffer offset */
int db = 0; /* Double buffer index */
@@ -165,6 +161,8 @@ typedef struct BALL_TYPE
BALL_TYPE balls[MAX_BALLS];
+/* Ball texture reference */
+extern const uint32_t ball16c[];
/* TIM image parameters for loading the ball texture and drawing sprites */
TIM_IMAGE tim;
@@ -179,9 +177,9 @@ CdlLOC xa_loc; /* XA data start location
/* Sector header structure for video sector terminator */
typedef struct SECTOR_HEAD
{
- u_short id;
- u_short chan;
- u_char pad[28];
+ uint16_t id;
+ uint16_t chan;
+ uint8_t pad[28];
} SECTOR_HEAD;
@@ -199,7 +197,7 @@ void xa_callback(int intr, unsigned char *result)
if (intr == CdlDataReady)
{
/* Fetch data sector */
- CdGetSector((u_long*)&xa_sector_buff, 512);
+ CdGetSector(&xa_sector_buff, 512);
/* Quirk: This CdGetSector() implementation must fetch 2048 bytes */
/* or more otherwise the following sectors will be read in an */
@@ -224,7 +222,7 @@ void xa_callback(int intr, unsigned char *result)
num_loops++;
/* Retry playback by seeking to start of XA data and stream */
- CdControlF(CdlReadS, (u_char*)&xa_loc);
+ CdControlF(CdlReadS, &xa_loc);
/* Stop playback */
//CdControlF(CdlPause, 0);
@@ -276,7 +274,7 @@ void init()
/* Upload the ball texture */
- GetTimInfo((u_long*)ball16c, &tim); /* Get TIM parameters */
+ GetTimInfo(ball16c, &tim); /* Get TIM parameters */
LoadImage(tim.prect, tim.paddr); /* Upload texture to VRAM */
if( tim.mode & 0x8 )
{
@@ -355,7 +353,7 @@ int main(int argc, const char* argv[])
/* Set CD mode for XA streaming (2x speed, send XA to SPU, enable filter */
i = CdlModeSpeed|CdlModeRT|CdlModeSF;
- CdControl(CdlSetmode, (u_char*)&i, 0);
+ CdControl(CdlSetmode, &i, 0);
/* Set file 1 on filter for channels 0-7 */
filter.file = 1;
@@ -410,8 +408,8 @@ int main(int argc, const char* argv[])
if( !p_cross )
{
filter.chan = sel_channel;
- CdControl(CdlSetfilter, (u_char*)&filter, 0);
- CdControl(CdlReadS, (u_char*)&xa_loc, 0);
+ CdControl(CdlSetfilter, &filter, 0);
+ CdControl(CdlReadS, &xa_loc, 0);
xa_play_channel = sel_channel;
p_cross = 1;
}
@@ -441,7 +439,7 @@ int main(int argc, const char* argv[])
if( !p_right )
{
filter.chan = sel_channel;
- CdControl(CdlSetfilter, (u_char*)&filter, 0);
+ CdControl(CdlSetfilter, &filter, 0);
xa_play_channel = sel_channel;
p_right = 1;
}
diff --git a/examples/demos/n00bdemo/disp.c b/examples/demos/n00bdemo/disp.c
index c134163..d8d2bbf 100644
--- a/examples/demos/n00bdemo/disp.c
+++ b/examples/demos/n00bdemo/disp.c
@@ -19,7 +19,7 @@ MATRIX mtx;
void initDisplay() {
- ResetGraph( 3 );
+ ResetGraph( 0 );
if( GetVideoMode() == MODE_NTSC ) {
SetDefDispEnv( &disp, 0, 0, 640, 480 );
diff --git a/examples/demos/n00bdemo/smd.s b/examples/demos/n00bdemo/smd.s
index f9cf2fe..d25f760 100644
--- a/examples/demos/n00bdemo/smd.s
+++ b/examples/demos/n00bdemo/smd.s
@@ -1,7 +1,7 @@
.set noreorder
-.include "gtereg.h"
-.include "inline_s.h"
+.include "gtereg.inc"
+.include "inline_s.inc"
.include "smd_s.h"
diff --git a/examples/demos/n00bdemo/smd_cel.s b/examples/demos/n00bdemo/smd_cel.s
index ece0dd8..383f043 100644
--- a/examples/demos/n00bdemo/smd_cel.s
+++ b/examples/demos/n00bdemo/smd_cel.s
@@ -1,7 +1,7 @@
.set noreorder
-.include "gtereg.h"
-.include "inline_s.h"
+.include "gtereg.inc"
+.include "inline_s.inc"
.include "smd_s.h"
diff --git a/examples/demos/n00bdemo/smd_flat.s b/examples/demos/n00bdemo/smd_flat.s
index 0d48c63..4b47be4 100644
--- a/examples/demos/n00bdemo/smd_flat.s
+++ b/examples/demos/n00bdemo/smd_flat.s
@@ -1,7 +1,7 @@
.set noreorder
-.include "gtereg.h"
-.include "inline_s.h"
+.include "gtereg.inc"
+.include "inline_s.inc"
.include "smd_s.h"
diff --git a/examples/graphics/balls/CMakeLists.txt b/examples/graphics/balls/CMakeLists.txt
index f5297c3..deee473 100644
--- a/examples/graphics/balls/CMakeLists.txt
+++ b/examples/graphics/balls/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
balls
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK sprites example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -15,4 +15,6 @@ file(GLOB _sources *.c)
psn00bsdk_add_executable(balls STATIC ${_sources})
#psn00bsdk_add_cd_image(balls_iso balls iso.xml DEPENDS balls)
+psn00bsdk_target_incbin(balls PRIVATE ball16c ball16c.tim)
+
install(FILES ${PROJECT_BINARY_DIR}/balls.exe TYPE BIN)
diff --git a/examples/graphics/balls/ball16c.h b/examples/graphics/balls/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/graphics/balls/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/graphics/balls/main.c b/examples/graphics/balls/main.c
index e429a4b..5af0bfb 100644
--- a/examples/graphics/balls/main.c
+++ b/examples/graphics/balls/main.c
@@ -18,14 +18,12 @@
*
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <psxetc.h>
#include <psxgte.h>
#include <psxgpu.h>
-#include "ball16c.h"
-
#define MAX_BALLS 1024
@@ -42,10 +40,10 @@
DISPENV disp;
DRAWENV draw;
-char pribuff[2][65536]; /* Primitive packet buffers */
-u_long ot[2][OT_LEN]; /* Ordering tables */
-char *nextpri; /* Pointer to next packet buffer offset */
-int db = 0; /* Double buffer index */
+char pribuff[2][65536]; /* Primitive packet buffers */
+uint32_t ot[2][OT_LEN]; /* Ordering tables */
+char *nextpri; /* Pointer to next packet buffer offset */
+int db = 0; /* Double buffer index */
/* Ball struct and array */
@@ -57,6 +55,8 @@ typedef struct {
BALL_TYPE balls[MAX_BALLS];
+/* Ball texture reference */
+extern const uint32_t ball16c[];
/* TIM image parameters for loading the ball texture and drawing sprites */
TIM_IMAGE tim;
@@ -96,7 +96,7 @@ void init() {
/* Upload the ball texture */
printf("Upload texture... ");
- GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */
+ GetTimInfo( ball16c, &tim ); /* Get TIM parameters */
LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */
if( tim.mode & 0x8 ) {
diff --git a/examples/graphics/gte/CMakeLists.txt b/examples/graphics/gte/CMakeLists.txt
index f95c5ff..90d897b 100644
--- a/examples/graphics/gte/CMakeLists.txt
+++ b/examples/graphics/gte/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
gte
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK GTE 3D cube example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -15,4 +15,6 @@ file(GLOB _sources *.c)
psn00bsdk_add_executable(gte STATIC ${_sources})
#psn00bsdk_add_cd_image(gte_iso gte iso.xml DEPENDS gte)
+psn00bsdk_target_incbin(gte PRIVATE tim_texture texture.tim)
+
install(FILES ${PROJECT_BINARY_DIR}/gte.exe TYPE BIN)
diff --git a/examples/graphics/gte/main.c b/examples/graphics/gte/main.c
index a7ddb6b..6907c84 100644
--- a/examples/graphics/gte/main.c
+++ b/examples/graphics/gte/main.c
@@ -12,13 +12,15 @@
*
* Changelog:
*
- * May 10, 2021 - Variable types updated for psxgpu.h changes.
+ * Aug 10, 2022 - Added texture to cube faces.
+ *
+ * May 10, 2021 - Variable types updated for psxgpu.h changes.
*
* Jan 26, 2019 - Initial version.
*
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <psxgpu.h>
#include <psxgte.h>
@@ -39,10 +41,10 @@
/* Double buffer structure */
typedef struct {
- DISPENV disp; /* Display environment */
- DRAWENV draw; /* Drawing environment */
- u_long ot[OT_LEN]; /* Ordering table */
- char p[PACKET_LEN]; /* Packet buffer */
+ DISPENV disp; /* Display environment */
+ DRAWENV draw; /* Drawing environment */
+ uint32_t ot[OT_LEN]; /* Ordering table */
+ char p[PACKET_LEN]; /* Packet buffer */
} DB;
/* Double buffer variables */
@@ -98,9 +100,9 @@ INDEX cube_indices[] = {
/* source color when using gte_nccs(). 4096 is 1.0 in this matrix */
/* A column of zeroes disables the light source. */
MATRIX color_mtx = {
- ONE, 0, 0, /* Red */
- ONE, 0, 0, /* Green */
- ONE, 0, 0 /* Blue */
+ ONE / 2, 0, 0, /* Red */
+ ONE / 2, 0, 0, /* Green */
+ ONE / 2, 0, 0 /* Blue */
};
/* Light matrix */
@@ -114,6 +116,13 @@ MATRIX light_mtx = {
};
+/* Reference texture data */
+extern const uint32_t tim_texture[];
+
+/* TPage and CLUT values */
+uint16_t texture_tpage; /* For the scrolling blending pattern */
+uint16_t texture_clut;
+
/* Function declarations */
void init();
void display();
@@ -128,7 +137,7 @@ int main() {
VECTOR pos = { 0, 0, 400 }; /* Translation vector for TransMatrix */
MATRIX mtx,lmtx; /* Rotation matrices for geometry and lighting */
- POLY_F4 *pol4; /* Flat shaded quad primitive pointer */
+ POLY_FT4 *pol4; /* Flat shaded textured quad primitive pointer */
/* Init graphics and GTE */
@@ -159,7 +168,7 @@ int main() {
/* Draw the cube */
- pol4 = (POLY_F4*)db_nextpri;
+ pol4 = (POLY_FT4*)db_nextpri;
for( i=0; i<CUBE_FACES; i++ ) {
@@ -192,7 +201,7 @@ int main() {
continue;
/* Initialize a quad primitive */
- setPolyF4( pol4 );
+ setPolyFT4( pol4 );
/* Set the projected vertices to the primitive */
gte_stsxy0( &pol4->x0 );
@@ -218,6 +227,11 @@ int main() {
/* Store result to the primitive */
gte_strgb( &pol4->r0 );
+ /* Set face texture */
+ setUVWH( pol4, 0, 1, 128, 128 );
+ pol4->tpage = texture_tpage;
+ pol4->clut = texture_clut;
+
/* Sort primitive to the ordering table */
addPrim( db[db_active].ot+(p>>2), pol4 );
@@ -240,6 +254,7 @@ int main() {
}
void init() {
+ TIM_IMAGE tim;
/* Reset the GPU, also installs a VSync event handler */
ResetGraph( 0 );
@@ -287,7 +302,15 @@ void init() {
/* Set light ambient color and light color matrix */
gte_SetBackColor( 63, 63, 63 );
gte_SetColorMatrix( &color_mtx );
+
+ /* Load .TIM file */
+ GetTimInfo(tim_texture, &tim);
+ if( tim.mode & 0x8 )
+ LoadImage( tim.crect, tim.caddr ); /* Upload CLUT if present */
+ LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */
+ texture_tpage = getTPage(tim.mode, 1, tim.prect->x, tim.prect->y);
+ texture_clut = getClut(tim.crect->x, tim.crect->y);
}
void display() {
@@ -313,4 +336,4 @@ void display() {
/* Start drawing the OT of the last buffer */
DrawOTag( db[1-db_active].ot+(OT_LEN-1) );
-} \ No newline at end of file
+}
diff --git a/examples/graphics/gte/texture.tim b/examples/graphics/gte/texture.tim
new file mode 100644
index 0000000..54ce2f0
--- /dev/null
+++ b/examples/graphics/gte/texture.tim
Binary files differ
diff --git a/examples/io/system573/k573io.c b/examples/io/system573/k573io.c
index bc13852..53c109f 100644
--- a/examples/io/system573/k573io.c
+++ b/examples/io/system573/k573io.c
@@ -75,7 +75,7 @@ uint32_t K573_GetJAMMAInputs(void) {
inputs |= ((K573_IO_CHIP[IO_REG_IN1_HIGH] >> 8) & 0x1f) << 24;
inputs |= (K573_IO_CHIP[IO_REG_IN1_LOW] & 0x07) << 29;
- return inputs;
+ return ~inputs;
}
void K573_SetLights(uint32_t lights) {
@@ -120,5 +120,10 @@ void K573_Init(void) {
EXP1_ADDR = 0x1f000000;
EXP1_DELAY_SIZE = 0x24173f47; // 573 BIOS uses this value
+ // Bit 6 of this register controls the audio DAC and must be set, otherwise
+ // no sound will be output. Most of the other bits are data clocks/strobes
+ // and should be pulled high when not in use.
+ K573_IO_CHIP[IO_REG_OUT0] = 0x01e7;
+
K573_RESET_WATCHDOG();
}
diff --git a/examples/io/system573/k573io.h b/examples/io/system573/k573io.h
index 7095a7c..8655237 100644
--- a/examples/io/system573/k573io.h
+++ b/examples/io/system573/k573io.h
@@ -10,21 +10,22 @@
/* Register definitions */
-#define K573_BANK_SWITCH *((volatile uint16_t *) 0x1f500000)
-#define K573_IDE_RESET *((volatile uint16_t *) 0x1f560000)
-#define K573_WATCHDOG *((volatile uint16_t *) 0x1f5c0000)
-#define K573_EXT_OUT *((volatile uint16_t *) 0x1f600000)
-#define K573_JVS_INPUT *((volatile uint16_t *) 0x1f680000)
-#define K573_SECURITY_OUT *((volatile uint16_t *) 0x1f6a0000)
-
-#define K573_FLASH ((volatile uint16_t *) 0x1f000000)
-#define K573_IO_CHIP ((volatile uint16_t *) 0x1f400000)
-#define K573_IDE_CS0 ((volatile uint16_t *) 0x1f480000)
-#define K573_IDE_CS1 ((volatile uint16_t *) 0x1f4c0000)
-#define K573_RTC ((volatile uint16_t *) 0x1f620000)
-#define K573_IO_BOARD ((volatile uint16_t *) 0x1f640000)
+#define K573_BANK_SWITCH *((volatile uint16_t *) 0xbf500000)
+#define K573_IDE_RESET *((volatile uint16_t *) 0xbf560000)
+#define K573_WATCHDOG *((volatile uint16_t *) 0xbf5c0000)
+#define K573_EXT_OUT *((volatile uint16_t *) 0xbf600000)
+#define K573_JVS_INPUT *((volatile uint16_t *) 0xbf680000)
+#define K573_SECURITY_OUT *((volatile uint16_t *) 0xbf6a0000)
+
+#define K573_FLASH ((volatile uint16_t *) 0xbf000000)
+#define K573_IO_CHIP ((volatile uint16_t *) 0xbf400000)
+#define K573_IDE_CS0 ((volatile uint16_t *) 0xbf480000)
+#define K573_IDE_CS1 ((volatile uint16_t *) 0xbf4c0000)
+#define K573_RTC ((volatile uint16_t *) 0xbf620000)
+#define K573_IO_BOARD ((volatile uint16_t *) 0xbf640000)
typedef enum _K573_IOChipRegister {
+ IO_REG_OUT0 = 0x0,
IO_REG_IN0 = 0x0,
IO_REG_IN1_LOW = 0x2,
IO_REG_IN1_HIGH = 0x3,
@@ -34,26 +35,29 @@ typedef enum _K573_IOChipRegister {
} K573_IOChipRegister;
typedef enum _K573_IOBoardRegister {
- ANALOG_IO_REG_LIGHTS0 = 0x40,
- ANALOG_IO_REG_LIGHTS1 = 0x44,
- ANALOG_IO_REG_LIGHTS2 = 0x48,
- ANALOG_IO_REG_LIGHTS3 = 0x4c,
+ ANALOG_IO_REG_LIGHTS0 = 0x40,
+ ANALOG_IO_REG_LIGHTS1 = 0x44,
+ ANALOG_IO_REG_LIGHTS2 = 0x48,
+ ANALOG_IO_REG_LIGHTS3 = 0x4c,
// The digital I/O board has a lot more registers than these, but there
// seems to be no DIGITAL_IO_LIGHTS6 register. WTF
- DIGITAL_IO_REG_LIGHTS1 = 0x70,
- DIGITAL_IO_REG_LIGHTS0 = 0x71,
- DIGITAL_IO_REG_LIGHTS3 = 0x72,
- DIGITAL_IO_REG_LIGHTS7 = 0x73,
- DIGITAL_IO_REG_LIGHTS4 = 0x7d,
- DIGITAL_IO_REG_LIGHTS5 = 0x7e,
- DIGITAL_IO_REG_LIGHTS2 = 0x7f,
-
- FISHBAIT_IO_REG_UNKNOWN = 0x08,
- FISHBAIT_IO_REG_MOTOR = 0x40,
- FISHBAIT_IO_REG_BRAKE = 0x44,
- FISHBAIT_IO_REG_ENCODER = 0x4c,
- FISHBAIT_IO_REG_RESET_Y = 0x50
+ DIGITAL_IO_REG_LIGHTS1 = 0x70,
+ DIGITAL_IO_REG_LIGHTS0 = 0x71,
+ DIGITAL_IO_REG_LIGHTS3 = 0x72,
+ DIGITAL_IO_REG_LIGHTS7 = 0x73,
+ DIGITAL_IO_REG_DS2401 = 0x77,
+ DIGITAL_IO_REG_FPGA_STATUS = 0x7b,
+ DIGITAL_IO_REG_FPGA_UPLOAD = 0x7c,
+ DIGITAL_IO_REG_LIGHTS4 = 0x7d,
+ DIGITAL_IO_REG_LIGHTS5 = 0x7e,
+ DIGITAL_IO_REG_LIGHTS2 = 0x7f,
+
+ FISHBAIT_IO_REG_UNKNOWN = 0x08,
+ FISHBAIT_IO_REG_MOTOR = 0x40,
+ FISHBAIT_IO_REG_BRAKE = 0x44,
+ FISHBAIT_IO_REG_ENCODER = 0x4c,
+ FISHBAIT_IO_REG_RESET_Y = 0x50
} K573_IOBoardRegister;
// The 573's real-time clock chip is an M48T58, which behaves like a standard
diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c
index 64722d7..3404ee4 100644
--- a/examples/io/system573/main.c
+++ b/examples/io/system573/main.c
@@ -207,7 +207,7 @@ int main(int argc, const char* argv[]) {
// Change the currently active light if the test button on the 573's
// front panel is pressed. DDR non-light outputs are skipped.
- if ((last_inputs & JAMMA_TEST) && !(inputs & JAMMA_TEST)) {
+ if (!(last_inputs & JAMMA_TEST) && (inputs & JAMMA_TEST)) {
current_light++;
if (
(current_light == 4) || // DDR_LIGHT_P1_MUX_DATA
diff --git a/examples/mdec/mdecimage/main.c b/examples/mdec/mdecimage/main.c
index b59fdaf..1ad02d9 100644
--- a/examples/mdec/mdecimage/main.c
+++ b/examples/mdec/mdecimage/main.c
@@ -71,7 +71,7 @@ int main(int argc, const char* argv[]) {
DecDCTout(slice, BLOCK_SIZE * SCREEN_YRES / 2);
DecDCToutSync(0);
- LoadImage(&rect, (u_long *) slice);
+ LoadImage(&rect, slice);
DrawSync(0);
}
diff --git a/examples/sound/spustream/CMakeLists.txt b/examples/sound/spustream/CMakeLists.txt
index 9e84fa3..397796a 100644
--- a/examples/sound/spustream/CMakeLists.txt
+++ b/examples/sound/spustream/CMakeLists.txt
@@ -14,12 +14,11 @@ project(
# TODO: add rules to actually generate a valid STREAM.BIN file
file(GLOB _sources *.c)
psn00bsdk_add_executable(spustream STATIC ${_sources})
-#psn00bsdk_add_cd_image(spustream_iso spustream iso.xml DEPENDS spustream)
+psn00bsdk_add_cd_image(spustream_iso spustream iso.xml DEPENDS spustream)
install(
FILES
- #${PROJECT_BINARY_DIR}/spustream.bin
- #${PROJECT_BINARY_DIR}/spustream.cue
- ${PROJECT_BINARY_DIR}/spustream.exe
+ ${PROJECT_BINARY_DIR}/spustream.bin
+ ${PROJECT_BINARY_DIR}/spustream.cue
TYPE BIN
)
diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c
index 6b9db93..6179179 100644
--- a/examples/sound/spustream/main.c
+++ b/examples/sound/spustream/main.c
@@ -51,10 +51,9 @@
* +----------+----------+----------+----------+----------+----------+----
* \________________________Chunk________________________/
*
- * Such file isn't provided as PSn00bSDK doesn't yet have a tool for audio
- * transcoding. A Python script is included to generate STREAM.BIN from one or
- * more SPU ADPCM (.VAG) files, one for each channel (the .VAG format only
- * supports mono).
+ * A Python script is included to generate STREAM.BIN from one or more SPU
+ * ADPCM (.VAG) files, one for each channel (the .VAG format only supports
+ * mono).
*
* Of course SPU streaming isn't the only way to play music, as the CD drive
* can play CD-DA tracks and XA files natively with zero CPU overhead. However
@@ -101,7 +100,7 @@
// size can be increased to get more idle time between CD reads, however it is
// usually best to keep it to 1-2 seconds as SPU RAM is only 512 KB.
#define SAMPLE_RATE 0x1000 // 44100 Hz
-#define BUFFER_SIZE 26624 // (26624 / 16 * 28) / 44100 = 1.05 seconds
+#define BUFFER_SIZE 0x6800 // (0x6800 / 16 * 28) / 44100 = 1.05 seconds
#define NUM_CHANNELS 2
#define CHANNEL_MASK 0x03
@@ -123,8 +122,8 @@ typedef struct {
} DB;
typedef struct {
- DB db[2];
- uint32_t db_active;
+ DB db[2];
+ int db_active;
} CONTEXT;
void init_context(CONTEXT *ctx) {
@@ -170,23 +169,13 @@ void display(CONTEXT *ctx) {
/* Stream interrupt handlers */
-// This is a silent looping sample used to keep unused SPU channels busy,
-// preventing them from accidentally triggering the SPU RAM interrupt and
-// throwing off the timing (all channels are always reading sample data, even
-// when "stopped"). It is 64 bytes as that is the minimum size for SPU DMA
-// transfers, however only the first 16 bytes are kept. The rest is going to be
-// overwritten by chunks.
-// https://problemkaputt.de/psx-spx.htm#spuinterrupt
-const uint8_t SPU_DUMMY_BLOCK[] = {
- 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
-};
-
// The first 4 KB of SPU RAM are reserved for capture buffers, so we have to
-// place stream buffers after those. Sony's SPU library additionally places a
-// dummy sample at 0x1000; we are going to do the same with the block above.
+// place stream buffers after those. A dummy sample is additionally placed by
+// default by the SPU library at 0x1000; it is going to be used here to keep
+// unused SPU channels busy, preventing them from accidentally triggering the
+// SPU RAM interrupt and throwing off the timing (all channels are always
+// reading sample data, even when "stopped").
+// https://problemkaputt.de/psx-spx.htm#spuinterrupt
#define DUMMY_BLOCK_ADDR 0x1000
#define BUFFER_START_ADDR 0x1010
#define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS)
@@ -207,7 +196,7 @@ static volatile StreamContext str_ctx;
// read from the CD and uploaded to SPU RAM. Due to DMA limitations it can't be
// allocated on the stack (especially not in the interrupt callbacks' stack,
// whose size is very limited).
-static uint8_t sector_buffer[2048];
+static uint32_t sector_buffer[512];
void spu_irq_handler(void) {
// Acknowledge the interrupt to ensure it can be triggered again. The only
@@ -231,7 +220,7 @@ void spu_irq_handler(void) {
str_ctx.spu_addr = BUFFER_START_ADDR + CHUNK_SIZE * str_ctx.db_active;
SPU_IRQ_ADDR = SPU_RAM_ADDR(str_ctx.spu_addr);
- for (uint32_t i = 0; i < NUM_CHANNELS; i++)
+ for (int i = 0; i < NUM_CHANNELS; i++)
SPU_CH_LOOP_ADDR(i) = SPU_RAM_ADDR(str_ctx.spu_addr + BUFFER_SIZE * i);
// Start loading the next chunk. cd_event_handler() will be called
@@ -241,7 +230,7 @@ void spu_irq_handler(void) {
CdControlF(CdlReadN, &pos);
}
-void cd_event_handler(int32_t event, uint8_t *payload) {
+void cd_event_handler(int event, uint8_t *payload) {
// Ignore all events other than a sector being ready.
// TODO: read errors should be handled properly
if (event != CdlDataReady)
@@ -255,12 +244,12 @@ void cd_event_handler(int32_t event, uint8_t *payload) {
// other buffer, as we're overriding loop addresses) at the end.
// NOTE: this isn't actually necessary here as the stream converter script
// already sets these flags in the file.
- /*for (uint32_t i = 0; i < NUM_CHANNELS; i++) {
+ /*for (int i = 0; i < NUM_CHANNELS; i++) {
if (
str_ctx.spu_pos >= (BUFFER_SIZE * i - 2048) &&
str_ctx.spu_pos < (BUFFER_SIZE * i)
)
- sector[(BUFFER_SIZE * i - str_ctx.spu_pos) - 15] = 0x03;
+ sector_buffer[(BUFFER_SIZE * i - str_ctx.spu_pos) - 15] = 0x03;
}*/
// Copy the sector to SPU RAM, appending it to the buffer that is not
@@ -268,7 +257,7 @@ void cd_event_handler(int32_t event, uint8_t *payload) {
// just treat the chunk as a single blob of data and copy it as-is; we only
// have to trim the padding at the end (if any) to avoid overwriting other
// data in SPU RAM.
- uint32_t length = CHUNK_SIZE - str_ctx.spu_pos;
+ size_t length = CHUNK_SIZE - str_ctx.spu_pos;
if (length > 2048)
length = 2048;
@@ -278,7 +267,6 @@ void cd_event_handler(int32_t event, uint8_t *payload) {
// If the buffer has been filled completely, stop reading and re-enable the
// SPU IRQ.
- // TODO TODO: preload first sector
if (str_ctx.spu_pos >= CHUNK_SIZE) {
CdControlF(CdlPause, 0);
SPU_CTRL |= 0x0040;
@@ -287,17 +275,17 @@ void cd_event_handler(int32_t event, uint8_t *payload) {
/* Stream helpers */
-void init_spu_channels(void) {
- // Upload the dummy block to the SPU and play it on all channels, locking
- // them up and stopping them from messing with the SPU interrupt.
- // TODO: is this really necessary? (needs testing on real hardware)
- SpuSetTransferStartAddr(DUMMY_BLOCK_ADDR);
- SpuWrite(SPU_DUMMY_BLOCK, 64);
-
+// This isn't actually required for this example, however it is necessary if
+// you want to allocate the stream buffers into a region of SPU RAM that was
+// previously used (to make sure the IRQ isn't going to be triggered by any
+// inactive channels).
+void reset_spu_channels(void) {
SPU_KEY_OFF = 0x00ffffff;
- for (uint32_t i = 0; i < 24; i++)
+ for (int i = 0; i < 24; i++) {
SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR);
+ SPU_CH_FREQ(i) = 0x1000;
+ }
SPU_KEY_ON = 0x00ffffff;
}
@@ -324,16 +312,16 @@ void init_stream(CdlFILE *file) {
spu_irq_handler();
while (str_ctx.spu_pos < CHUNK_SIZE)
- __asm__("nop");
+ __asm__ volatile("");
}
void start_stream(void) {
SPU_KEY_OFF = CHANNEL_MASK;
- for (uint32_t i = 0; i < NUM_CHANNELS; i++) {
+ for (int i = 0; i < NUM_CHANNELS; i++) {
SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i);
SPU_CH_FREQ(i) = SAMPLE_RATE;
- SPU_CH_ADSR(i) = 0x1fee80ff; // or 0x9fc080ff, 0xdff18087
+ SPU_CH_ADSR(i) = 0x1fee80ff;
}
// Unmute the channels and route them for stereo output. You'll want to
@@ -361,7 +349,7 @@ int main(int argc, const char* argv[]) {
SHOW_STATUS("INITIALIZING\n");
SpuInit();
CdInit();
- init_spu_channels();
+ reset_spu_channels();
SHOW_STATUS("LOCATING STREAM FILE\n");
@@ -429,7 +417,7 @@ int main(int argc, const char* argv[]) {
// Only set the sample rate registers if necessary.
if (pad->btn != 0xffff) {
- for (uint32_t i = 0; i < NUM_CHANNELS; i++)
+ for (int i = 0; i < NUM_CHANNELS; i++)
SPU_CH_FREQ(i) = sample_rate;
}
diff --git a/examples/sound/spustream/stream.bin b/examples/sound/spustream/stream.bin
new file mode 100644
index 0000000..e53b726
--- /dev/null
+++ b/examples/sound/spustream/stream.bin
Binary files differ
diff --git a/examples/sound/vagsample/main.c b/examples/sound/vagsample/main.c
index 2b04c34..c79e68e 100644
--- a/examples/sound/vagsample/main.c
+++ b/examples/sound/vagsample/main.c
@@ -32,13 +32,14 @@
*/
#include <stdio.h>
-#include <sys/types.h>
+#include <stdint.h>
#include <psxetc.h>
#include <psxgte.h>
#include <psxgpu.h>
#include <psxpad.h>
#include <psxapi.h>
#include <psxspu.h>
+#include <hwregs_c.h>
extern const unsigned char proyt[];
extern const int proyt_size;
@@ -103,8 +104,8 @@ void init(void)
SpuSetTransferStartAddr(addr_temp);
// Upload first sound clip and wait for transfer to finish
- SpuWrite(((unsigned char*)proyt)+48, proyt_size-48);
- SpuWait();
+ SpuWrite((const uint32_t *) &proyt[48], proyt_size-48);
+ SpuIsTransferCompleted(SPU_TRANSFER_WAIT);
// Obtain the address of the sound and advance address for the next one
// Samples are addressed in 8-byte units, so it'll have to be divided by 8
@@ -115,8 +116,8 @@ void init(void)
// Upload second sound clip
SpuSetTransferStartAddr(addr_temp);
- SpuWrite(((unsigned char*)tdfx)+48, tdfx_size-48);
- SpuWait();
+ SpuWrite((const uint32_t *) &tdfx[48], tdfx_size-48);
+ SpuIsTransferCompleted(SPU_TRANSFER_WAIT);
// Obtain the address of the second sound clip
tdfx_addr = addr_temp/8;
@@ -127,7 +128,7 @@ void init(void)
// Begin pad polling
InitPAD( pad_buff[0], 34, pad_buff[1], 34 );
StartPAD();
-
+ ChangeClearPAD(0);
} /* init */
// Display function
@@ -158,27 +159,17 @@ int main(int argc, const char *argv[])
int counter,nextchan;
int cross_pressed;
int circle_pressed;
-
PADTYPE *pad;
- SpuVoiceRaw voice;
// Init stuff
init();
-
- // Set common values for the SpuVoiceRaw stuct
- // Technically one struct can be used to play all sounds as the
- // parameters are copied to the SPU registers
-
- voice.vol.left = 0x3FFE; // Left voice volume, 3FFEh = max
- voice.vol.right = 0x3FFE; // Right voice volume, 3FFEh = max
- voice.adsr_param = 0xdff18087; // ADSR parameters
-
+
// Main loop
counter = 0;
nextchan = 0;
cross_pressed = 0;
circle_pressed = 0;
-
+
while(1)
{
pad = (PADTYPE*)&pad_buff[0][0];
@@ -194,22 +185,24 @@ int main(int argc, const char *argv[])
if( !cross_pressed )
{
// Voice frequency
- // (400h = 11.25KHz, 1000h = 44.1KHz)
- voice.freq = 0x800;
+ // (800h = 22.05KHz)
+ SPU_CH_FREQ(nextchan) = 0x800;
// Voice start playback address
// (transfer address / 8)
- voice.addr = proyt_addr;
+ SPU_CH_ADDR(nextchan) = proyt_addr;
// Voice loop address
// (transfer address / 8)
- voice.loop_addr = proyt_addr;
-
+ SPU_CH_LOOP_ADDR(nextchan) = proyt_addr;
+ // Voice volume and envelope
+ SPU_CH_VOL_L(nextchan) = 0x3fff;
+ SPU_CH_VOL_R(nextchan) = 0x3fff;
+ SPU_CH_ADSR(nextchan) = 0x1fee80ff;
+
// Set voice to key-off to allow restart
- SpuSetKey(0, 1<<nextchan);
- // Set voice parameters
- SpuSetVoiceRaw(nextchan, &voice);
+ SPU_KEY_OFF = 1 << nextchan;
// Set voice to key-on
- SpuSetKey(1, 1<<nextchan);
-
+ SPU_KEY_ON = 1 << nextchan;
+
// Advance to next voice
nextchan++;
if( nextchan > 23 )
@@ -229,27 +222,29 @@ int main(int argc, const char *argv[])
if( !circle_pressed )
{
// Voice frequency
- // (400h = 11.25KHz, 1000h = 44.1KHz)
- voice.freq = 0x1000;
+ // (1000h = 44.1KHz)
+ SPU_CH_FREQ(nextchan) = 0x1000;
// Voice start playback address
// (transfer address / 8)
- voice.addr = tdfx_addr;
+ SPU_CH_ADDR(nextchan) = tdfx_addr;
// Voice loop address
// (transfer address / 8)
- voice.loop_addr = tdfx_addr;
-
+ SPU_CH_LOOP_ADDR(nextchan) = tdfx_addr;
+ // Voice volume and envelope
+ SPU_CH_VOL_L(nextchan) = 0x3fff;
+ SPU_CH_VOL_R(nextchan) = 0x3fff;
+ SPU_CH_ADSR(nextchan) = 0x1fee80ff;
+
// Set voice to key-off to allow restart
- SpuSetKey(0, 1<<nextchan);
- // Set voice parameters
- SpuSetVoiceRaw(nextchan, &voice);
+ SPU_KEY_OFF = 1 << nextchan;
// Set voice to key-on
- SpuSetKey(1, 1<<nextchan);
-
+ SPU_KEY_ON = 1 << nextchan;
+
// Advance to next voice
nextchan++;
if( nextchan > 23 )
nextchan = 0;
-
+
circle_pressed = 1;
}
}
diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt
index b781dea..7e91589 100644
--- a/examples/system/childexec/CMakeLists.txt
+++ b/examples/system/childexec/CMakeLists.txt
@@ -17,6 +17,7 @@ psn00bsdk_add_executable(parent STATIC ${_sources})
psn00bsdk_add_executable(child STATIC ${_child_sources})
#psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS parent)
+psn00bsdk_target_incbin(parent PRIVATE ball16c ball16c.tim)
psn00bsdk_target_incbin(
parent PRIVATE child_exe
${PROJECT_BINARY_DIR}/child.exe
diff --git a/examples/system/childexec/ball16c.h b/examples/system/childexec/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/system/childexec/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/system/childexec/ball16c.tim b/examples/system/childexec/ball16c.tim
new file mode 100644
index 0000000..e2a5d17
--- /dev/null
+++ b/examples/system/childexec/ball16c.tim
Binary files differ
diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c
index 2ddfa73..bd17440 100644
--- a/examples/system/childexec/child/child.c
+++ b/examples/system/childexec/child/child.c
@@ -1,4 +1,4 @@
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <psxapi.h>
#include <psxgpu.h>
@@ -21,10 +21,10 @@
/* Double buffer structure */
typedef struct {
- DISPENV disp; /* Display environment */
- DRAWENV draw; /* Drawing environment */
- u_long ot[OT_LEN]; /* Ordering table */
- char p[PACKET_LEN]; /* Packet buffer */
+ DISPENV disp; /* Display environment */
+ DRAWENV draw; /* Drawing environment */
+ uint32_t ot[OT_LEN]; /* Ordering table */
+ char p[PACKET_LEN]; /* Packet buffer */
} DB;
/* Double buffer variables */
diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c
index 58f03f7..3e7d218 100644
--- a/examples/system/childexec/parent.c
+++ b/examples/system/childexec/parent.c
@@ -20,7 +20,7 @@
*
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
@@ -29,8 +29,6 @@
#include <psxgte.h>
#include <psxgpu.h>
#include <psxpad.h>
-#include "ball16c.h"
-
#define MAX_BALLS 1024
@@ -48,7 +46,7 @@ DISPENV disp;
DRAWENV draw;
char pribuff[2][65536]; /* Primitive packet buffers */
-u_long ot[2][OT_LEN]; /* Ordering tables */
+uint32_t ot[2][OT_LEN]; /* Ordering tables */
char *nextpri; /* Pointer to next packet buffer offset */
int db = 0; /* Double buffer index */
@@ -62,6 +60,8 @@ typedef struct {
BALL_TYPE balls[MAX_BALLS];
+/* Ball texture reference */
+extern const uint32_t ball16c[];
/* TIM image parameters for loading the ball texture and drawing sprites */
TIM_IMAGE tim;
@@ -103,7 +103,7 @@ void init() {
/* Upload the ball texture */
printf("Upload texture... ");
- GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */
+ GetTimInfo( ball16c, &tim ); /* Get TIM parameters */
LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */
if( tim.mode & 0x8 ) {
diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt
index d58f212..eeb8e62 100644
--- a/examples/system/console/CMakeLists.txt
+++ b/examples/system/console/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
console
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK stdio console example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -15,4 +15,6 @@ file(GLOB _sources *.c)
psn00bsdk_add_executable(console STATIC ${_sources})
#psn00bsdk_add_cd_image(console_iso console iso.xml DEPENDS console)
+psn00bsdk_target_incbin(console PRIVATE ball16c ball16c.tim)
+
install(FILES ${PROJECT_BINARY_DIR}/console.exe TYPE BIN)
diff --git a/examples/system/console/ball16c.h b/examples/system/console/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/system/console/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/system/console/ball16c.tim b/examples/system/console/ball16c.tim
new file mode 100644
index 0000000..e2a5d17
--- /dev/null
+++ b/examples/system/console/ball16c.tim
Binary files differ
diff --git a/examples/system/console/main.c b/examples/system/console/main.c
index 92df0a8..b4f91b4 100644
--- a/examples/system/console/main.c
+++ b/examples/system/console/main.c
@@ -21,7 +21,7 @@
*
*/
-#include <sys/types.h>
+#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -32,8 +32,6 @@
#include <psxgte.h>
#include <psxgpu.h>
#include <psxsio.h>
-#include "ball16c.h"
-
#define MAX_BALLS 1024
@@ -50,10 +48,10 @@
DISPENV disp;
DRAWENV draw;
-char pribuff[2][65536]; /* Primitive packet buffers */
-u_long ot[2][OT_LEN]; /* Ordering tables */
-char *nextpri; /* Pointer to next packet buffer offset */
-int db = 0; /* Double buffer index */
+char pribuff[2][65536]; /* Primitive packet buffers */
+uint32_t ot[2][OT_LEN]; /* Ordering tables */
+char *nextpri; /* Pointer to next packet buffer offset */
+int db = 0; /* Double buffer index */
/* Ball struct and array */
@@ -65,6 +63,8 @@ typedef struct {
BALL_TYPE balls[MAX_BALLS];
+/* Ball texture reference */
+extern const uint32_t ball16c[];
/* TIM image parameters for loading the ball texture and drawing sprites */
TIM_IMAGE tim;
@@ -104,7 +104,7 @@ void init() {
/* Upload the ball texture */
printf("Upload texture... ");
- GetTimInfo( (u_long*)ball16c, &tim ); /* Get TIM parameters */
+ GetTimInfo( ball16c, &tim ); /* Get TIM parameters */
LoadImage( tim.prect, tim.paddr ); /* Upload texture to VRAM */
if( tim.mode & 0x8 ) {
diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt
index aae3bb3..f5f4ea8 100644
--- a/examples/system/dynlink/CMakeLists.txt
+++ b/examples/system/dynlink/CMakeLists.txt
@@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.20)
project(
dynlink
- LANGUAGES C
+ LANGUAGES C ASM
VERSION 1.0.0
DESCRIPTION "PSn00bSDK dynamic linker example"
HOMEPAGE_URL "http://lameguy64.net/?page=psn00bsdk"
@@ -20,6 +20,8 @@ psn00bsdk_add_cd_image(
DEPENDS dynlink_main dynlink_cube dynlink_balls
)
+psn00bsdk_target_incbin(dynlink_balls PRIVATE ball16c library/ball16c.tim)
+
install(
FILES
${PROJECT_BINARY_DIR}/dynlink.bin
diff --git a/examples/system/dynlink/library/ball16c.h b/examples/system/dynlink/library/ball16c.h
deleted file mode 100644
index c79f273..0000000
--- a/examples/system/dynlink/library/ball16c.h
+++ /dev/null
@@ -1,16 +0,0 @@
-unsigned int ball16c_size=192;
-unsigned char ball16c[] = {
-0x10,0x00,0x00,0x00,0x08,0x00,0x00,0x00,0x2c,0x00,0x00,0x00,0xc0,0x03,0x10,
-0x01,0x10,0x00,0x01,0x00,0x00,0x00,0x31,0xc6,0x73,0xce,0x94,0xd2,0x07,0x9d,
-0xd6,0xda,0x38,0xe3,0xef,0xbd,0x9b,0xef,0x8c,0xb1,0xc6,0x98,0xde,0xfb,0x4a,
-0xa9,0xa4,0x90,0xad,0xb5,0x00,0x00,0x8c,0x00,0x00,0x00,0xc0,0x03,0x00,0x01,
-0x04,0x00,0x10,0x00,0x00,0x00,0x10,0x22,0x12,0x02,0x00,0x00,0x00,0x10,0x32,
-0x33,0x23,0x11,0x04,0x00,0x00,0x23,0x55,0x66,0x35,0x72,0x47,0x00,0x20,0x52,
-0x86,0x68,0x36,0x12,0x97,0x0a,0x20,0x65,0xbb,0x8b,0x36,0x12,0x91,0x04,0x31,
-0x85,0xbb,0x68,0x35,0x12,0x97,0xdc,0x32,0x86,0x8b,0x56,0x35,0x73,0x97,0xa4,
-0x32,0x66,0x68,0x55,0x23,0x71,0x9e,0xac,0x32,0x65,0x56,0x33,0x13,0x71,0xce,
-0xa4,0x21,0x33,0x33,0x23,0x11,0xe7,0xc9,0xd4,0x12,0x22,0x22,0x13,0x71,0xe7,
-0xc9,0xda,0x10,0x17,0x11,0x77,0x77,0x9e,0x4c,0x0d,0x40,0x77,0x71,0xe7,0x9e,
-0xc9,0xd4,0x0d,0x00,0x94,0x99,0x99,0xcc,0x4c,0xda,0x00,0x00,0xa0,0xc4,0xc4,
-0x44,0xda,0x0d,0x00,0x00,0x00,0xd0,0xaa,0xda,0x0d,0x00,0x00
-};
diff --git a/examples/system/dynlink/library/ball16c.tim b/examples/system/dynlink/library/ball16c.tim
new file mode 100644
index 0000000..e2a5d17
--- /dev/null
+++ b/examples/system/dynlink/library/ball16c.tim
Binary files differ
diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c
index ef6993e..c537167 100644
--- a/examples/system/dynlink/library/balls.c
+++ b/examples/system/dynlink/library/balls.c
@@ -12,7 +12,8 @@
#include <inline_c.h>
#include "dll_common.h"
-#include "ball16c.h"
+
+extern const uint32_t ball16c[];
/* Balls data */
@@ -38,7 +39,7 @@ static BALL_TYPE balls[MAX_BALLS];
static TIM_IMAGE ball_tim;
void init(CONTEXT *ctx) {
- GetTimInfo((u_long *) ball16c, &ball_tim);
+ GetTimInfo(ball16c, &ball_tim);
LoadImage(ball_tim.prect, ball_tim.paddr);
if (ball_tim.mode & 8)
diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c
index 9b94b30..fff7aa5 100644
--- a/examples/system/dynlink/main.c
+++ b/examples/system/dynlink/main.c
@@ -108,13 +108,13 @@ void init_context(CONTEXT *ctx) {
// Set up the ordering tables and primitive buffers.
db = &(ctx->db[0]);
ctx->db_nextpri = db->p;
- ClearOTagR((u_long *) db->ot, OT_LEN);
+ ClearOTagR(db->ot, OT_LEN);
PutDrawEnv(&(db->draw));
//PutDispEnv(&(db->disp));
db = &(ctx->db[1]);
- ClearOTagR((u_long *) db->ot, OT_LEN);
+ ClearOTagR(db->ot, OT_LEN);
// Create a text stream at the top of the screen.
FntLoad(960, 0);
@@ -130,14 +130,14 @@ void display(CONTEXT *ctx) {
db = &(ctx->db[ctx->db_active]);
ctx->db_nextpri = db->p;
- ClearOTagR((u_long *) db->ot, OT_LEN);
+ ClearOTagR(db->ot, OT_LEN);
PutDrawEnv(&(db->draw));
PutDispEnv(&(db->disp));
SetDispMask(1);
db = &(ctx->db[!ctx->db_active]);
- DrawOTag((u_long *) &(db->ot[OT_LEN - 1]));
+ DrawOTag(&(db->ot[OT_LEN - 1]));
}
/* Symbol overriding example */