aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorspicyjpeg <thatspicyjpeg@gmail.com>2022-10-15 10:02:35 +0200
committerspicyjpeg <thatspicyjpeg@gmail.com>2022-10-15 10:02:35 +0200
commit6eabb5aa549254c2272cedee26d4245f31f2dc7a (patch)
tree1962581a2ea36f421718aad7bf90b1a37cc4c530 /examples
parentb458ea70700739bf8a64217af369c7ace08fc954 (diff)
downloadpsn00bsdk-6eabb5aa549254c2272cedee26d4245f31f2dc7a.tar.gz
Update sound/spustream, clean up other examples
Diffstat (limited to 'examples')
-rw-r--r--examples/cdrom/cdbrowse/iso.xml1
-rw-r--r--examples/cdrom/cdxa/iso.xml1
-rw-r--r--examples/graphics/tilesasm/iso.xml34
-rw-r--r--examples/graphics/tilesasm/system.cnf4
-rw-r--r--examples/io/pads/main.c22
-rw-r--r--examples/io/system573/iso.xml2
-rw-r--r--examples/io/system573/main.c22
-rw-r--r--examples/sound/spustream/iso.xml1
-rw-r--r--examples/sound/spustream/main.c91
-rw-r--r--examples/system/dynlink/library/balls.c27
-rw-r--r--examples/system/dynlink/library/cube.c14
-rw-r--r--examples/system/dynlink/library/dll_common.h11
-rw-r--r--examples/system/dynlink/main.c17
13 files changed, 113 insertions, 134 deletions
diff --git a/examples/cdrom/cdbrowse/iso.xml b/examples/cdrom/cdbrowse/iso.xml
index 5ffca18..771b0e9 100644
--- a/examples/cdrom/cdbrowse/iso.xml
+++ b/examples/cdrom/cdbrowse/iso.xml
@@ -17,7 +17,6 @@
<directory_tree>
<file name="SYSTEM.CNF" type="data" source="${PROJECT_SOURCE_DIR}/system.cnf" />
<file name="CDBROWSE.EXE" type="data" source="cdbrowse.exe" />
- <file name="CDBROWSE.MAP" type="data" source="cdbrowse.map" />
<dir name="DIRA">
<dir name="DIRAA">
diff --git a/examples/cdrom/cdxa/iso.xml b/examples/cdrom/cdxa/iso.xml
index b98a16f..6715f94 100644
--- a/examples/cdrom/cdxa/iso.xml
+++ b/examples/cdrom/cdxa/iso.xml
@@ -17,7 +17,6 @@
<directory_tree>
<file name="SYSTEM.CNF" type="data" source="${PROJECT_SOURCE_DIR}/system.cnf" />
<file name="CDXA.EXE" type="data" source="cdxa.exe" />
- <file name="CDXA.MAP" type="data" source="cdxa.map" />
<!-- CD-XA file, you'll have to provide your own to make this example work -->
<file name="XASAMPLE.XA" type="mixed" source="${PROJECT_SOURCE_DIR}/xasample.xa"/>
diff --git a/examples/graphics/tilesasm/iso.xml b/examples/graphics/tilesasm/iso.xml
deleted file mode 100644
index 477c636..0000000
--- a/examples/graphics/tilesasm/iso.xml
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- This file is processed by CMake and used by mkpsxiso to build the CD image.
-
- NOTE: all paths are relative to the build directory; if you want to include
- a file from the source tree, you'll have to prepend its path with
- ${PROJECT_SOURCE_DIR}.
--->
-<iso_project
- image_name="${CD_IMAGE_NAME}.bin"
- cue_sheet="${CD_IMAGE_NAME}.cue"
->
- <track type="data">
- <identifiers
- system ="PLAYSTATION"
- volume ="PSN00BSDK_TEMPLATE"
- volume_set ="PSN00BSDK_TEMPLATE"
- publisher ="MEIDOTEK"
- data_preparer ="PSN00BSDK ${PSN00BSDK_VERSION}"
- application ="PLAYSTATION"
- copyright ="README.TXT;1"
- />
-
- <directory_tree>
- <file name="SYSTEM.CNF" type="data" source="${PROJECT_SOURCE_DIR}/system.cnf" />
- <file name="TEMPLATE.EXE" type="data" source="template.exe" />
- <file name="TEMPLATE.MAP" type="data" source="template.map" />
-
- <dummy sectors="1024"/>
- </directory_tree>
- </track>
-
- <!--<track type="audio" source="track2.wav" />-->
-</iso_project>
diff --git a/examples/graphics/tilesasm/system.cnf b/examples/graphics/tilesasm/system.cnf
deleted file mode 100644
index e221726..0000000
--- a/examples/graphics/tilesasm/system.cnf
+++ /dev/null
@@ -1,4 +0,0 @@
-BOOT=cdrom:\template.exe;1
-TCB=4
-EVENT=10
-STACK=801FFFF0
diff --git a/examples/io/pads/main.c b/examples/io/pads/main.c
index 17bf331..29bb527 100644
--- a/examples/io/pads/main.c
+++ b/examples/io/pads/main.c
@@ -62,17 +62,17 @@ static const char *const PAD_TYPEIDS[] = {
#define BGCOLOR_B 0
typedef struct {
- DISPENV disp;
- DRAWENV draw;
-} DB;
+ DISPENV disp;
+ DRAWENV draw;
+} Framebuffer;
typedef struct {
- DB db[2];
- uint32_t db_active;
-} CONTEXT;
+ Framebuffer db[2];
+ int db_active;
+} RenderContext;
-void init_context(CONTEXT *ctx) {
- DB *db;
+void init_context(RenderContext *ctx) {
+ Framebuffer *db;
ResetGraph(0);
ctx->db_active = 0;
@@ -99,8 +99,8 @@ void init_context(CONTEXT *ctx) {
FntOpen(8, 16, 304, 208, 2, 512);
}
-void display(CONTEXT *ctx) {
- DB *db;
+void display(RenderContext *ctx) {
+ Framebuffer *db;
DrawSync(0);
VSync(0);
@@ -227,7 +227,7 @@ void poll_cb(uint32_t port, const volatile uint8_t *buff, size_t rx_len) {
/* Main */
-static CONTEXT ctx;
+static RenderContext ctx;
int main(int argc, const char* argv[]) {
init_context(&ctx);
diff --git a/examples/io/system573/iso.xml b/examples/io/system573/iso.xml
index 0bb84d5..2226089 100644
--- a/examples/io/system573/iso.xml
+++ b/examples/io/system573/iso.xml
@@ -30,8 +30,6 @@
-->
<!--<file name="SYSTEM.CNF" type="data" source="${PROJECT_SOURCE_DIR}/system.cnf" />-->
<file name="PSX.EXE" type="data" source="system573.exe" />
- <file name="PSX.MAP" type="data" source="system573.map" />
-
<file name="QSY.DXD" type="data" source="system573.exe" />
<file name="SSW.BXF" type="data" source="system573.exe" />
<file name="TSV.AXG" type="data" source="system573.exe" />
diff --git a/examples/io/system573/main.c b/examples/io/system573/main.c
index 3404ee4..39ddb64 100644
--- a/examples/io/system573/main.c
+++ b/examples/io/system573/main.c
@@ -83,17 +83,17 @@ const char *const IO_BOARD_TYPES[] = {
#define BGCOLOR_B 0
typedef struct {
- DISPENV disp;
- DRAWENV draw;
-} DB;
+ DISPENV disp;
+ DRAWENV draw;
+} Framebuffer;
typedef struct {
- DB db[2];
- uint32_t db_active;
-} CONTEXT;
+ Framebuffer db[2];
+ int db_active;
+} RenderContext;
-void init_context(CONTEXT *ctx) {
- DB *db;
+void init_context(RenderContext *ctx) {
+ Framebuffer *db;
ResetGraph(0);
ctx->db_active = 0;
@@ -120,8 +120,8 @@ void init_context(CONTEXT *ctx) {
FntOpen(8, 16, 304, 208, 2, 512);
}
-void display(CONTEXT *ctx) {
- DB *db;
+void display(RenderContext *ctx) {
+ Framebuffer *db;
DrawSync(0);
VSync(0);
@@ -135,7 +135,7 @@ void display(CONTEXT *ctx) {
/* Main */
-static CONTEXT ctx;
+static RenderContext ctx;
#define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); }
#define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); }
diff --git a/examples/sound/spustream/iso.xml b/examples/sound/spustream/iso.xml
index 3807046..050d673 100644
--- a/examples/sound/spustream/iso.xml
+++ b/examples/sound/spustream/iso.xml
@@ -17,7 +17,6 @@
<directory_tree>
<file name="SYSTEM.CNF" type="data" source="${PROJECT_SOURCE_DIR}/system.cnf" />
<file name="SPUSTRM.EXE" type="data" source="spustream.exe" />
- <file name="SPUSTRM.MAP" type="data" source="spustream.map" />
<file name="STREAM.BIN" type="data" source="${PROJECT_SOURCE_DIR}/stream.bin" />
diff --git a/examples/sound/spustream/main.c b/examples/sound/spustream/main.c
index 6179179..acd4f60 100644
--- a/examples/sound/spustream/main.c
+++ b/examples/sound/spustream/main.c
@@ -117,17 +117,17 @@
#define BGCOLOR_B 0
typedef struct {
- DISPENV disp;
- DRAWENV draw;
-} DB;
+ DISPENV disp;
+ DRAWENV draw;
+} Framebuffer;
typedef struct {
- DB db[2];
- int db_active;
-} CONTEXT;
+ Framebuffer db[2];
+ int db_active;
+} RenderContext;
-void init_context(CONTEXT *ctx) {
- DB *db;
+void init_context(RenderContext *ctx) {
+ Framebuffer *db;
ResetGraph(0);
ctx->db_active = 0;
@@ -154,8 +154,8 @@ void init_context(CONTEXT *ctx) {
FntOpen(8, 16, 304, 208, 2, 512);
}
-void display(CONTEXT *ctx) {
- DB *db;
+void display(RenderContext *ctx) {
+ Framebuffer *db;
DrawSync(0);
VSync(0);
@@ -181,13 +181,9 @@ void display(CONTEXT *ctx) {
#define CHUNK_SIZE (BUFFER_SIZE * NUM_CHANNELS)
typedef struct {
- uint32_t lba;
- uint32_t length;
- uint32_t pos;
-
- uint32_t spu_addr;
- uint32_t spu_pos;
- uint32_t db_active;
+ int lba, length, pos;
+ int spu_addr, spu_pos;
+ int db_active;
} StreamContext;
static volatile StreamContext str_ctx;
@@ -316,10 +312,10 @@ void init_stream(CdlFILE *file) {
}
void start_stream(void) {
- SPU_KEY_OFF = CHANNEL_MASK;
+ uint32_t addr = BUFFER_START_ADDR + CHUNK_SIZE * str_ctx.db_active;
for (int i = 0; i < NUM_CHANNELS; i++) {
- SPU_CH_ADDR(i) = SPU_RAM_ADDR(BUFFER_START_ADDR + BUFFER_SIZE * i);
+ SPU_CH_ADDR(i) = SPU_RAM_ADDR(addr + BUFFER_SIZE * i);
SPU_CH_FREQ(i) = SAMPLE_RATE;
SPU_CH_ADSR(i) = 0x1fee80ff;
}
@@ -332,13 +328,25 @@ void start_stream(void) {
SPU_CH_VOL_L(1) = 0x0000;
SPU_CH_VOL_R(1) = 0x3fff;
- SPU_KEY_ON = CHANNEL_MASK;
spu_irq_handler();
+ SPU_KEY_ON = CHANNEL_MASK;
+}
+
+// This is basically a variant of reset_spu_channels() that only resets the
+// channels used to play the stream, to (again) prevent them from triggering
+// the SPU IRQ while the stream is paused.
+void stop_stream(void) {
+ SPU_KEY_OFF = CHANNEL_MASK;
+
+ for (int i = 0; i < NUM_CHANNELS; i++)
+ SPU_CH_ADDR(i) = SPU_RAM_ADDR(DUMMY_BLOCK_ADDR);
+
+ SPU_KEY_ON = CHANNEL_MASK;
}
/* Main */
-static CONTEXT ctx;
+static RenderContext ctx;
#define SHOW_STATUS(...) { FntPrint(-1, __VA_ARGS__); FntFlush(-1); display(&ctx); }
#define SHOW_ERROR(...) { SHOW_STATUS(__VA_ARGS__); while (1) __asm__("nop"); }
@@ -351,7 +359,13 @@ int main(int argc, const char* argv[]) {
CdInit();
reset_spu_channels();
- SHOW_STATUS("LOCATING STREAM FILE\n");
+ // Set up controller polling.
+ uint8_t pad_buff[2][34];
+ InitPAD(pad_buff[0], 34, pad_buff[1], 34);
+ StartPAD();
+ ChangeClearPAD(0);
+
+ SHOW_STATUS("OPENING STREAM FILE\n");
CdlFILE file;
if (!CdSearchFile(&file, "\\STREAM.BIN"))
@@ -361,28 +375,27 @@ int main(int argc, const char* argv[]) {
init_stream(&file);
start_stream();
- // Set up controller polling.
- uint8_t pad_buff[2][34];
- InitPAD(pad_buff[0], 34, pad_buff[1], 34);
- StartPAD();
- ChangeClearPAD(0);
+ int paused = 0;
uint16_t sample_rate = SAMPLE_RATE;
uint16_t last_buttons = 0xffff;
while (1) {
- FntPrint(-1, "PLAYING SPU STREAM\n");
+ FntPrint(-1, "PLAYING SPU STREAM\n\n");
+
+ FntPrint(-1, "BUFFER: %d\nSTATUS: ", str_ctx.db_active);
if (str_ctx.spu_pos >= CHUNK_SIZE)
- FntPrint(-1, "STATUS: IDLE\n\n");
- else if (!str_ctx.spu_pos)
- FntPrint(-1, "STATUS: SEEKING\n\n");
+ FntPrint(-1, "IDLE\n\n");
+ else if (str_ctx.spu_pos)
+ FntPrint(-1, "BUFFERING\n\n");
else
- FntPrint(-1, "STATUS: BUFFERING\n\n");
+ FntPrint(-1, "SEEKING\n\n");
- FntPrint(-1, "POSITION=%5d/%5d\n", str_ctx.pos, str_ctx.length);
- FntPrint(-1, "BUFFERED=%5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE);
- FntPrint(-1, "SMP RATE=%5d HZ\n\n", (sample_rate * 44100) >> 12);
+ FntPrint(-1, "POSITION: %5d/%5d\n", str_ctx.pos, str_ctx.length);
+ FntPrint(-1, "BUFFERED: %5d/%5d\n", str_ctx.spu_pos, CHUNK_SIZE);
+ FntPrint(-1, "SMP RATE: %5d HZ\n\n", (sample_rate * 44100) >> 12);
+ FntPrint(-1, "[START] %s\n", paused ? "RESUME" : "PAUSE");
FntPrint(-1, "[LEFT/RIGHT] SEEK\n");
FntPrint(-1, "[O] RESET POSITION\n");
FntPrint(-1, "[UP/DOWN] CHANGE SAMPLE RATE\n");
@@ -399,6 +412,14 @@ int main(int argc, const char* argv[]) {
if ((pad->type != 4) && (pad->type != 5) && (pad->type != 7))
continue;
+ if ((last_buttons & PAD_START) && !(pad->btn & PAD_START)) {
+ paused ^= 1;
+ if (paused)
+ stop_stream();
+ else
+ start_stream();
+ }
+
// Seeking by an arbitrary number of sectors isn't a problem as
// spu_irq_handler() always realigns the counter.
if (!(pad->btn & PAD_LEFT))
diff --git a/examples/system/dynlink/library/balls.c b/examples/system/dynlink/library/balls.c
index c537167..457ec4e 100644
--- a/examples/system/dynlink/library/balls.c
+++ b/examples/system/dynlink/library/balls.c
@@ -21,7 +21,7 @@ typedef struct {
int16_t x, y;
int16_t xdir, ydir;
uint8_t r, g, b, p;
-} BALL_TYPE;
+} Ball;
#define MAX_BALLS 512
@@ -35,12 +35,13 @@ typedef struct {
// initialize variables or hardware.
static uint32_t frame = 0;
-static BALL_TYPE balls[MAX_BALLS];
+static Ball balls[MAX_BALLS];
static TIM_IMAGE ball_tim;
-void init(CONTEXT *ctx) {
- GetTimInfo(ball16c, &ball_tim);
+void init(RenderContext *ctx) {
+ Framebuffer *db = &(ctx->db[ctx->db_active]);
+ GetTimInfo(ball16c, &ball_tim);
LoadImage(ball_tim.prect, ball_tim.paddr);
if (ball_tim.mode & 8)
LoadImage(ball_tim.crect, ball_tim.caddr);
@@ -48,10 +49,10 @@ void init(CONTEXT *ctx) {
// Initialize the balls by giving them a random initial position, velocity
// and color.
for (uint32_t i = 0; i < MAX_BALLS; i++) {
- BALL_TYPE *b = &(balls[i]);
+ Ball *b = &(balls[i]);
- b->x = rand() % (ctx->xres - 16);
- b->y = rand() % (ctx->yres - 16);
+ b->x = rand() % (db->draw.clip.w - 16);
+ b->y = rand() % (db->draw.clip.h - 16);
b->xdir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1);
b->ydir = ((rand() & 1) ? 1 : -1) * ((rand() % 3) + 1);
b->r = rand() & 0xff;
@@ -60,12 +61,12 @@ void init(CONTEXT *ctx) {
}
}
-void render(CONTEXT *ctx, uint16_t buttons) {
- DB *db = &(ctx->db[ctx->db_active]);
- SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri;
+void render(RenderContext *ctx, uint16_t buttons) {
+ Framebuffer *db = &(ctx->db[ctx->db_active]);
+ SPRT_16 *sprt = (SPRT_16 *) ctx->db_nextpri;
for (uint32_t i = 0; i < MAX_BALLS; i++) {
- BALL_TYPE *b = &(balls[i]);
+ Ball *b = &(balls[i]);
setSprt16(sprt);
@@ -85,12 +86,12 @@ void render(CONTEXT *ctx, uint16_t buttons) {
if (
(b->x < 0) ||
- ((b->x + 16) > ctx->xres)
+ ((b->x + 16) > db->draw.clip.w)
)
b->xdir *= -1;
if (
(b->y < 0) ||
- ((b->y + 16) > ctx->yres)
+ ((b->y + 16) > db->draw.clip.h)
)
b->ydir *= -1;
}
diff --git a/examples/system/dynlink/library/cube.c b/examples/system/dynlink/library/cube.c
index 84fe552..22a805f 100644
--- a/examples/system/dynlink/library/cube.c
+++ b/examples/system/dynlink/library/cube.c
@@ -81,16 +81,18 @@ static SVECTOR rot = { 0 };
static VECTOR pos = { 0, 0, 400 };
static MATRIX mtx, lmtx;
-void init(CONTEXT *ctx) {
+void init(RenderContext *ctx) {
+ Framebuffer *db = &(ctx->db[ctx->db_active]);
+
InitGeom();
- gte_SetGeomOffset(ctx->xres / 2, ctx->yres / 2);
- gte_SetGeomScreen(ctx->xres / 2);
+ gte_SetGeomOffset(db->draw.clip.w / 2, db->draw.clip.h / 2);
+ gte_SetGeomScreen(db->draw.clip.w / 2);
gte_SetBackColor(63, 63, 63);
gte_SetColorMatrix(&color_mtx);
}
-void render(CONTEXT *ctx, uint16_t buttons) {
+void render(RenderContext *ctx, uint16_t buttons) {
RotMatrix(&rot, &mtx);
TransMatrix(&mtx, &pos);
MulMatrix0(&light_mtx, &mtx, &lmtx);
@@ -104,8 +106,8 @@ void render(CONTEXT *ctx, uint16_t buttons) {
rot.vx += step;
rot.vz += step;
- DB *db = &(ctx->db[ctx->db_active]);
- POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri;
+ Framebuffer *db = &(ctx->db[ctx->db_active]);
+ POLY_F4 *pol4 = (POLY_F4 *) ctx->db_nextpri;
for (uint32_t i = 0; i < CUBE_FACES; i++) {
int32_t p;
diff --git a/examples/system/dynlink/library/dll_common.h b/examples/system/dynlink/library/dll_common.h
index 315a993..6606bda 100644
--- a/examples/system/dynlink/library/dll_common.h
+++ b/examples/system/dynlink/library/dll_common.h
@@ -19,13 +19,12 @@ typedef struct {
DRAWENV draw;
uint32_t ot[OT_LEN];
uint8_t p[PACKET_LEN];
-} DB;
+} Framebuffer;
typedef struct {
- uint16_t xres, yres;
- DB db[2];
- uint32_t db_active;
- uint8_t *db_nextpri;
-} CONTEXT;
+ Framebuffer db[2];
+ int db_active;
+ uint8_t *db_nextpri;
+} RenderContext;
#endif
diff --git a/examples/system/dynlink/main.c b/examples/system/dynlink/main.c
index fff7aa5..fcce5b1 100644
--- a/examples/system/dynlink/main.c
+++ b/examples/system/dynlink/main.c
@@ -83,12 +83,10 @@ static const char *const DLL_FILENAMES[] = {
#define BGCOLOR_G 24
#define BGCOLOR_B 0
-void init_context(CONTEXT *ctx) {
- DB *db;
+void init_context(RenderContext *ctx) {
+ Framebuffer *db;
ResetGraph(0);
- ctx->xres = SCREEN_XRES;
- ctx->yres = SCREEN_YRES;
ctx->db_active = 0;
db = &(ctx->db[0]);
@@ -121,8 +119,8 @@ void init_context(CONTEXT *ctx) {
FntOpen(4, 12, 312, 32, 2, 256);
}
-void display(CONTEXT *ctx) {
- DB *db;
+void display(RenderContext *ctx) {
+ Framebuffer *db;
DrawSync(0);
VSync(0);
@@ -185,13 +183,14 @@ void *custom_resolver(DLL *dll, const char *name) {
// and the pointers returned by DL_GetDLLSymbol() should be saved and reused as
// much as possible.
typedef struct {
- void (*init)(CONTEXT *);
- void (*render)(CONTEXT *, uint16_t buttons);
+ void (*init)(RenderContext *);
+ void (*render)(RenderContext *, uint16_t buttons);
} DLL_API;
static DLL *dll = 0;
static DLL_API dll_api;
-static CONTEXT ctx;
+
+static RenderContext ctx;
/* Main */