aboutsummaryrefslogtreecommitdiff
path: root/examples/system
diff options
context:
space:
mode:
authorJohn "Lameguy" Wilbert Villamor <lameguy64@gmail.com>2022-10-19 17:57:06 +0800
committerGitHub <noreply@github.com>2022-10-19 17:57:06 +0800
commite08a3d9366f8ca14a76b3dd569dac1fb9f569748 (patch)
tree33654513b0b184c27f8035dbc405640fcbeb44ab /examples/system
parentc4a2533d21dfd05cde841ea48c67b05e0e6a853f (diff)
parent9b2ffc6078a850b7d354855cca7622090b41f30c (diff)
downloadpsn00bsdk-e08a3d9366f8ca14a76b3dd569dac1fb9f569748.tar.gz
Merge pull request #59 from spicyjpeg/psxmdec
IRQ handler fix, .STR playback example, multiple library builds (v0.21)
Diffstat (limited to 'examples/system')
-rw-r--r--examples/system/childexec/CMakeLists.txt20
-rw-r--r--examples/system/childexec/child/child.c8
-rw-r--r--examples/system/childexec/parent.c27
-rw-r--r--examples/system/console/CMakeLists.txt4
-rw-r--r--examples/system/dynlink/CMakeLists.txt4
-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
-rw-r--r--examples/system/timer/CMakeLists.txt4
-rw-r--r--examples/system/tty/CMakeLists.txt4
11 files changed, 66 insertions, 74 deletions
diff --git a/examples/system/childexec/CMakeLists.txt b/examples/system/childexec/CMakeLists.txt
index 7e91589..e542d2a 100644
--- a/examples/system/childexec/CMakeLists.txt
+++ b/examples/system/childexec/CMakeLists.txt
@@ -1,7 +1,7 @@
# PSn00bSDK example CMake script
# (C) 2021 spicyjpeg - MPL licensed
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.21)
project(
childexec
@@ -13,14 +13,14 @@ project(
file(GLOB _sources *.c)
file(GLOB _child_sources child/*.c)
-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_add_executable(childexec GPREL ${_sources})
+psn00bsdk_add_executable(childexec_child GPREL ${_child_sources})
+#psn00bsdk_add_cd_image(childexec_iso childexec iso.xml DEPENDS childexec)
-psn00bsdk_target_incbin(parent PRIVATE ball16c ball16c.tim)
+psn00bsdk_target_incbin(childexec PRIVATE ball16c ball16c.tim)
psn00bsdk_target_incbin(
- parent PRIVATE child_exe
- ${PROJECT_BINARY_DIR}/child.exe
+ childexec PRIVATE child_exe
+ ${PROJECT_BINARY_DIR}/childexec_child.exe
)
# Relocate the child executable to a non-default address to prevent it from
@@ -28,9 +28,9 @@ psn00bsdk_target_incbin(
# NOTE: child executables are not position-independent and can't be relocated
# at runtime. If you need your code to be relocatable (e.g. to load it into a
# dynamically-allocated buffer), consider using a DLL instead.
-target_link_options(child PRIVATE -Ttext=0x80030000)
+target_link_options(childexec_child PRIVATE -Ttext=0x80030000)
# Make sure the child executable is built before the parent.
-add_dependencies(parent child)
+add_dependencies(childexec childexec_child)
-install(FILES ${PROJECT_BINARY_DIR}/parent.exe TYPE BIN)
+install(FILES ${PROJECT_BINARY_DIR}/childexec.exe TYPE BIN)
diff --git a/examples/system/childexec/child/child.c b/examples/system/childexec/child/child.c
index bd17440..dcfbfaf 100644
--- a/examples/system/childexec/child/child.c
+++ b/examples/system/childexec/child/child.c
@@ -98,8 +98,8 @@ MATRIX light_mtx = {
char pad_buff[2][34];
/* Function declarations */
-void init();
-void display();
+void init(void);
+void display(void);
/* Main function */
@@ -245,7 +245,7 @@ int main(int argc, const char *argv[]) {
}
-void init() {
+void init(void) {
/* Reset the GPU, also installs a VSync event handler */
ResetGraph( 0 );
@@ -300,7 +300,7 @@ void init() {
}
-void display() {
+void display(void) {
/* Wait for GPU to finish drawing and vertical retrace */
DrawSync( 0 );
diff --git a/examples/system/childexec/parent.c b/examples/system/childexec/parent.c
index 3e7d218..83d964c 100644
--- a/examples/system/childexec/parent.c
+++ b/examples/system/childexec/parent.c
@@ -67,12 +67,12 @@ extern const uint32_t ball16c[];
TIM_IMAGE tim;
-void run_child();
+void run_child(void);
char pad_buff[2][34];
-void init() {
+void init(void) {
int i;
@@ -270,10 +270,7 @@ typedef struct {
// Child program address
extern char child_exe[];
-// Manually defined as its not defined in psxapi by default
-void SetDefaultExitFromException();
-
-void run_child() {
+void run_child(void) {
// Arguments for the child program
char *args[] =
@@ -289,29 +286,23 @@ void run_child() {
// Copy child executable to its intended adddress
memcpy((void*)exe->param.t_addr, child_exe+2048, exe->param.t_size);
- // Enter critical section to prepare for program execution
- EnterCriticalSection();
+ // Prepare for program execution and disable interrupts
+ //EnterCriticalSection();
+ StopCallback();
// Stop pads, enable auto acknowledge
StopPAD();
ChangeClearPAD(1);
ChangeClearRCnt(3, 1);
-
- // Set default exception handler just in case
- //SetDefaultExitFromException();
-
- // Last three function calls could be relegated to
- // a StopCallback() function in the future.
-
+
// Execute child
printf("Child exec!\n");
Exec(&exe->param, 3, args);
// Restore interrupts for this PS-EXE
- EnterCriticalSection();
RestartCallback();
- ExitCriticalSection();
-
+ //ExitCriticalSection();
+
// Re-init and re-enable pads
InitPAD(pad_buff[0], 34, pad_buff[1], 34);
StartPAD();
diff --git a/examples/system/console/CMakeLists.txt b/examples/system/console/CMakeLists.txt
index eeb8e62..c6fa573 100644
--- a/examples/system/console/CMakeLists.txt
+++ b/examples/system/console/CMakeLists.txt
@@ -1,7 +1,7 @@
# PSn00bSDK example CMake script
# (C) 2021 spicyjpeg - MPL licensed
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.21)
project(
console
@@ -12,7 +12,7 @@ project(
)
file(GLOB _sources *.c)
-psn00bsdk_add_executable(console STATIC ${_sources})
+psn00bsdk_add_executable(console GPREL ${_sources})
#psn00bsdk_add_cd_image(console_iso console iso.xml DEPENDS console)
psn00bsdk_target_incbin(console PRIVATE ball16c ball16c.tim)
diff --git a/examples/system/dynlink/CMakeLists.txt b/examples/system/dynlink/CMakeLists.txt
index f5f4ea8..e750fd1 100644
--- a/examples/system/dynlink/CMakeLists.txt
+++ b/examples/system/dynlink/CMakeLists.txt
@@ -1,7 +1,7 @@
# PSn00bSDK example CMake script
# (C) 2021 spicyjpeg - MPL licensed
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.21)
project(
dynlink
@@ -12,7 +12,7 @@ project(
)
file(GLOB _sources *.c)
-psn00bsdk_add_executable(dynlink_main DYNAMIC ${_sources})
+psn00bsdk_add_executable(dynlink_main NOGPREL ${_sources})
psn00bsdk_add_library (dynlink_cube SHARED library/cube.c)
psn00bsdk_add_library (dynlink_balls SHARED library/balls.c)
psn00bsdk_add_cd_image(
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 */
diff --git a/examples/system/timer/CMakeLists.txt b/examples/system/timer/CMakeLists.txt
index 328e07e..30efbf3 100644
--- a/examples/system/timer/CMakeLists.txt
+++ b/examples/system/timer/CMakeLists.txt
@@ -1,7 +1,7 @@
# PSn00bSDK example CMake script
# (C) 2021 spicyjpeg - MPL licensed
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.21)
project(
timer
@@ -12,7 +12,7 @@ project(
)
file(GLOB _sources *.c)
-psn00bsdk_add_executable(timer STATIC ${_sources})
+psn00bsdk_add_executable(timer GPREL ${_sources})
#psn00bsdk_add_cd_image(timer_iso timer iso.xml DEPENDS timer)
install(FILES ${PROJECT_BINARY_DIR}/timer.exe TYPE BIN)
diff --git a/examples/system/tty/CMakeLists.txt b/examples/system/tty/CMakeLists.txt
index 0664502..75ce689 100644
--- a/examples/system/tty/CMakeLists.txt
+++ b/examples/system/tty/CMakeLists.txt
@@ -1,7 +1,7 @@
# PSn00bSDK example CMake script
# (C) 2021 spicyjpeg - MPL licensed
-cmake_minimum_required(VERSION 3.20)
+cmake_minimum_required(VERSION 3.21)
project(
tty
@@ -12,7 +12,7 @@ project(
)
file(GLOB _sources *.c)
-psn00bsdk_add_executable(tty STATIC ${_sources})
+psn00bsdk_add_executable(tty GPREL ${_sources})
#psn00bsdk_add_cd_image(tty_iso tty iso.xml DEPENDS tty)
install(FILES ${PROJECT_BINARY_DIR}/tty.exe TYPE BIN)