From 62dc760f339f2c9b0fd89fa085744b3564e18080 Mon Sep 17 00:00:00 2001 From: ABelliqueux Date: Thu, 11 Nov 2021 16:32:31 +0100 Subject: [PATCH] Ovl example now works on real hw --- hello_ovl_exec/common.h | 7 +- hello_ovl_exec/hello_ovl_exec.c | 77 ++++++++++++++----- .../hello_ovl_world/hello_ovl_world.c | 1 - hello_ovl_exec/hello_poly/hello_ovl_poly.c | 9 ++- hello_ovl_exec/hello_poly/hello_poly.ld | 3 - hello_ovl_exec/hello_tile/hello_ovl_tile.c | 17 ++-- 6 files changed, 79 insertions(+), 35 deletions(-) delete mode 100644 hello_ovl_exec/hello_poly/hello_poly.ld diff --git a/hello_ovl_exec/common.h b/hello_ovl_exec/common.h index 6719432..b594adb 100644 --- a/hello_ovl_exec/common.h +++ b/hello_ovl_exec/common.h @@ -6,10 +6,12 @@ #include #include #include +#include #include #include -// CD library -#include + +#include "../thirdparty/nugget/common/syscalls/syscalls.h" +#define printf ramsyscall_printf #define setRGB(p, r0, g0, b0) \ (p)->r = r0, (p)->g = g0, (p)->b = b0 @@ -30,6 +32,7 @@ extern char primbuff[2][32768]; extern char *nextpri; extern u_long ot[2][OTLEN]; extern uint8_t db; +extern uint8_t useOT; extern CVECTOR BGcolor; enum OverlayNumber { diff --git a/hello_ovl_exec/hello_ovl_exec.c b/hello_ovl_exec/hello_ovl_exec.c index 6bde547..febc30f 100644 --- a/hello_ovl_exec/hello_ovl_exec.c +++ b/hello_ovl_exec/hello_ovl_exec.c @@ -10,7 +10,7 @@ char primbuff[2][32768]; // double primitive buffer of length 32768 * 8 = u_long ot[2][OTLEN]; char *nextpri = primbuff[0]; uint8_t db = 0; -CVECTOR BGcolor = { 0, 150, 255 }; +CVECTOR BGcolor, MScolor = { 224, 108, 76 }; extern u_long load_all_overlays_here; @@ -18,6 +18,7 @@ typedef struct Overlay { char filename[0x7c]; int (*main)(); char commandline[0x180]; + CVECTOR BGcolor; } Overlay; int ovl_main_hello(); @@ -25,20 +26,24 @@ int ovl_main_tile(); int ovl_main_poly(); Overlay g_chainload[] = { - {"\\HELLO.OVL;1", ovl_main_hello, ""}, - {"\\TILE.OVL;1", ovl_main_tile, ""}, - {"\\POLY.OVL;1", ovl_main_poly, ""}, - //~ { "\\POLY.OVL;1" , 0 }, + {"\\HELLO.OVL;1", ovl_main_hello, "", { 225, 220, 40 }}, + {"\\TILE.OVL;1", ovl_main_tile, "", { 150, 30 , 40 }}, + {"\\POLY.OVL;1", ovl_main_poly, "", { 60 , 127, 0 }}, }; enum OverlayNumber next_overlay = MOTHERSHIP; enum OverlayNumber prev_overlay = MOTHERSHIP; int main(void); -int loadOverlayAndStart(Overlay *); -void EmptyOTag(u_long ot[2][OTLEN], char primbuff[2][32768], char * nextpri ); +int loadOverlayAndStart(Overlay * overlay); +void EmptyOTag(u_long ot[2][OTLEN]); +void EmptyPrimBuf(char primbuff[2][32768], char ** nextpri); +void preInitOvl(Overlay * overlay); +void postInitOvl(Overlay * overlay); +void clearVRAM(void); void (*dispp) (void); +uint8_t useOT = 0; int CDreadOK = 0; void init(void) @@ -72,11 +77,39 @@ void display(void) VSync(0); // Wait for the next vertical blank PutDispEnv(&disp[db]); // set alternate disp and draw environnments PutDrawEnv(&draw[db]); - DrawOTag(&ot[db][OTLEN - 1]); + if (useOT) + { + DrawOTag(&ot[db][OTLEN - 1]); + } db = !db; // flip db value (0 or 1) nextpri = primbuff[db]; } - +void clearVRAM(void) +{ + RECT vram = {0,0,1024,512}; + ClearImage(&vram,0,0,0); +} +void preInitOvl(Overlay * overlay) +{ + //~ clearVRAM(); + ResetCallback(); + ResetGraph(3); + EmptyPrimBuf(primbuff, &nextpri); + EmptyOTag(&ot[db]); + setRGB(&BGcolor, overlay->BGcolor.r, overlay->BGcolor.g, overlay->BGcolor.b ); +} +void postInitOvl(Overlay * overlay) +{ + //~ clearVRAM(); + //~ ResetGraph(3); + EmptyPrimBuf(primbuff, &nextpri); + EmptyOTag(&ot[db]); + setRGB(&BGcolor, MScolor.r, MScolor.g, MScolor.b); + setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b); // set color for first draw area + setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b); + FntLoad(960, 0); // Load font to vram at 960,0(+128) + FntOpen(MARGINX, SCREENYRES - MARGINY - FONTSIZE, SCREENXRES - MARGINX * 2, FONTSIZE, 0, 280 ); // FntOpen(x, y, width, height, black_bg, max. nbr. chars +} int loadOverlayAndStart(Overlay * overlay) { int CDreadResult = 0; @@ -88,35 +121,41 @@ int loadOverlayAndStart(Overlay * overlay) // If file loaded sucessfully if (CDreadResult) { - //~ StopCallback(); - ResetGraph(3); - // Execute + // Pre OVL + preInitOvl(overlay); + // Exec OVL next_ovl = overlay->main(); - EmptyOTag(&ot[db], &primbuff[db], nextpri); - setRGB(&BGcolor, 0, 150, 255); - init(); + // Post OVL + postInitOvl(overlay); } return next_ovl; } - -void EmptyOTag(u_long ot[2][OTLEN], char primbuff[2][32768], char * nextpri ) +void EmptyPrimBuf(char primbuff[2][32768], char ** nextpri) +{ + for(uint16_t p; p < 32768; p++) + { + primbuff[0][p] = 0; + primbuff[1][p] = 0; + } + *nextpri = primbuff[0]; +} +void EmptyOTag(u_long ot[2][OTLEN]) { for (uint16_t p; p < OTLEN; p++) { ot[0][p] = 0; ot[1][p] = 0; } - nextpri = primbuff[!db]; } int main(void) { int t = 0; + setRGB(&BGcolor, MScolor.r, MScolor.g, MScolor.b); // init() display init(); // Init CD system CdInit(); - prev_overlay = next_overlay; while(1){ if (t == 100){ diff --git a/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c b/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c index 4270a54..c3cee18 100644 --- a/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c +++ b/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c @@ -2,7 +2,6 @@ int ovl_main_hello(void) { - setRGB(&BGcolor, 0, 255, 100); init(); int i = 0; while(1) diff --git a/hello_ovl_exec/hello_poly/hello_ovl_poly.c b/hello_ovl_exec/hello_poly/hello_ovl_poly.c index 17b3660..086f888 100644 --- a/hello_ovl_exec/hello_poly/hello_ovl_poly.c +++ b/hello_ovl_exec/hello_poly/hello_ovl_poly.c @@ -1,8 +1,11 @@ #include "../common.h" + int ovl_main_poly(void) { - setRGB(&BGcolor, 250, 0, 250); + #ifndef STANDALONE + useOT = 1; + #endif init(); uint16_t timer = 0; uint16_t timeout = 100; @@ -59,14 +62,16 @@ int ovl_main_poly(void) timer++; FntPrint("Hello Poly ! %d", timer); + FntFlush(-1); #ifndef STANDALONE if (timer == timeout){ + useOT = 0; next_overlay = MOTHERSHIP; break; } #endif - FntFlush(-1); display(); + } return next_overlay; }; diff --git a/hello_ovl_exec/hello_poly/hello_poly.ld b/hello_ovl_exec/hello_poly/hello_poly.ld deleted file mode 100644 index 837a4e7..0000000 --- a/hello_ovl_exec/hello_poly/hello_poly.ld +++ /dev/null @@ -1,3 +0,0 @@ -TLOAD_ADDR = 0x8001E8480; -__heap_base = 0x8001E8480; - diff --git a/hello_ovl_exec/hello_tile/hello_ovl_tile.c b/hello_ovl_exec/hello_tile/hello_ovl_tile.c index 1596bbf..3409ebb 100644 --- a/hello_ovl_exec/hello_tile/hello_ovl_tile.c +++ b/hello_ovl_exec/hello_tile/hello_ovl_tile.c @@ -2,14 +2,16 @@ int ovl_main_tile(void) { - setRGB(&BGcolor, 150, 0, 50); - init(); + #ifndef STANDALONE + useOT = 1; + #endif uint16_t timer = 0; uint16_t timeout = 100; - TILE * blue_tile; - TILE * pink_tile; + TILE * blue_tile = 0; + TILE * pink_tile = 0; // This one is added at a different OT index - TILE * yellow_tile; + TILE * yellow_tile = 0; + init(); while(1) { // Initialize the reversed ordering table. This means the elements at index OTLEN - 1 is drawn first. @@ -54,15 +56,14 @@ int ovl_main_tile(void) timer ++; FntPrint("Hello tile ! %d\n", timer); + FntFlush(-1); #ifndef STANDALONE if (timer == timeout){ + useOT = 0; next_overlay = OVERLAY_POLY; - // Empty ordering table - //~ EmptyOTag(&ot[db], &primbuff[db], nextpri); break; } #endif - FntFlush(-1); display(); } return next_overlay;