diff options
| author | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-10-15 10:02:35 +0200 |
|---|---|---|
| committer | spicyjpeg <thatspicyjpeg@gmail.com> | 2022-10-15 10:02:35 +0200 |
| commit | 6eabb5aa549254c2272cedee26d4245f31f2dc7a (patch) | |
| tree | 1962581a2ea36f421718aad7bf90b1a37cc4c530 /examples/system | |
| parent | b458ea70700739bf8a64217af369c7ace08fc954 (diff) | |
| download | psn00bsdk-6eabb5aa549254c2272cedee26d4245f31f2dc7a.tar.gz | |
Update sound/spustream, clean up other examples
Diffstat (limited to 'examples/system')
| -rw-r--r-- | examples/system/dynlink/library/balls.c | 27 | ||||
| -rw-r--r-- | examples/system/dynlink/library/cube.c | 14 | ||||
| -rw-r--r-- | examples/system/dynlink/library/dll_common.h | 11 | ||||
| -rw-r--r-- | examples/system/dynlink/main.c | 17 |
4 files changed, 35 insertions, 34 deletions
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 */ |
