Ovl example now works on real hw

This commit is contained in:
ABelliqueux 2021-11-11 16:32:31 +01:00
parent 3ddba887eb
commit 62dc760f33
6 changed files with 79 additions and 35 deletions

View File

@ -6,10 +6,12 @@
#include <libetc.h> #include <libetc.h>
#include <libgpu.h> #include <libgpu.h>
#include <libapi.h> #include <libapi.h>
#include <libcd.h>
#include <malloc.h> #include <malloc.h>
#include <kernel.h> #include <kernel.h>
// CD library
#include <libcd.h> #include "../thirdparty/nugget/common/syscalls/syscalls.h"
#define printf ramsyscall_printf
#define setRGB(p, r0, g0, b0) \ #define setRGB(p, r0, g0, b0) \
(p)->r = r0, (p)->g = g0, (p)->b = b0 (p)->r = r0, (p)->g = g0, (p)->b = b0
@ -30,6 +32,7 @@ extern char primbuff[2][32768];
extern char *nextpri; extern char *nextpri;
extern u_long ot[2][OTLEN]; extern u_long ot[2][OTLEN];
extern uint8_t db; extern uint8_t db;
extern uint8_t useOT;
extern CVECTOR BGcolor; extern CVECTOR BGcolor;
enum OverlayNumber { enum OverlayNumber {

View File

@ -10,7 +10,7 @@ char primbuff[2][32768]; // double primitive buffer of length 32768 * 8 =
u_long ot[2][OTLEN]; u_long ot[2][OTLEN];
char *nextpri = primbuff[0]; char *nextpri = primbuff[0];
uint8_t db = 0; uint8_t db = 0;
CVECTOR BGcolor = { 0, 150, 255 }; CVECTOR BGcolor, MScolor = { 224, 108, 76 };
extern u_long load_all_overlays_here; extern u_long load_all_overlays_here;
@ -18,6 +18,7 @@ typedef struct Overlay {
char filename[0x7c]; char filename[0x7c];
int (*main)(); int (*main)();
char commandline[0x180]; char commandline[0x180];
CVECTOR BGcolor;
} Overlay; } Overlay;
int ovl_main_hello(); int ovl_main_hello();
@ -25,20 +26,24 @@ int ovl_main_tile();
int ovl_main_poly(); int ovl_main_poly();
Overlay g_chainload[] = { Overlay g_chainload[] = {
{"\\HELLO.OVL;1", ovl_main_hello, ""}, {"\\HELLO.OVL;1", ovl_main_hello, "", { 225, 220, 40 }},
{"\\TILE.OVL;1", ovl_main_tile, ""}, {"\\TILE.OVL;1", ovl_main_tile, "", { 150, 30 , 40 }},
{"\\POLY.OVL;1", ovl_main_poly, ""}, {"\\POLY.OVL;1", ovl_main_poly, "", { 60 , 127, 0 }},
//~ { "\\POLY.OVL;1" , 0 },
}; };
enum OverlayNumber next_overlay = MOTHERSHIP; enum OverlayNumber next_overlay = MOTHERSHIP;
enum OverlayNumber prev_overlay = MOTHERSHIP; enum OverlayNumber prev_overlay = MOTHERSHIP;
int main(void); int main(void);
int loadOverlayAndStart(Overlay *); int loadOverlayAndStart(Overlay * overlay);
void EmptyOTag(u_long ot[2][OTLEN], char primbuff[2][32768], char * nextpri ); 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); void (*dispp) (void);
uint8_t useOT = 0;
int CDreadOK = 0; int CDreadOK = 0;
void init(void) void init(void)
@ -72,11 +77,39 @@ void display(void)
VSync(0); // Wait for the next vertical blank VSync(0); // Wait for the next vertical blank
PutDispEnv(&disp[db]); // set alternate disp and draw environnments PutDispEnv(&disp[db]); // set alternate disp and draw environnments
PutDrawEnv(&draw[db]); PutDrawEnv(&draw[db]);
DrawOTag(&ot[db][OTLEN - 1]); if (useOT)
{
DrawOTag(&ot[db][OTLEN - 1]);
}
db = !db; // flip db value (0 or 1) db = !db; // flip db value (0 or 1)
nextpri = primbuff[db]; 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 loadOverlayAndStart(Overlay * overlay)
{ {
int CDreadResult = 0; int CDreadResult = 0;
@ -88,35 +121,41 @@ int loadOverlayAndStart(Overlay * overlay)
// If file loaded sucessfully // If file loaded sucessfully
if (CDreadResult) if (CDreadResult)
{ {
//~ StopCallback(); // Pre OVL
ResetGraph(3); preInitOvl(overlay);
// Execute // Exec OVL
next_ovl = overlay->main(); next_ovl = overlay->main();
EmptyOTag(&ot[db], &primbuff[db], nextpri); // Post OVL
setRGB(&BGcolor, 0, 150, 255); postInitOvl(overlay);
init();
} }
return next_ovl; return next_ovl;
} }
void EmptyPrimBuf(char primbuff[2][32768], char ** nextpri)
void EmptyOTag(u_long ot[2][OTLEN], 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++) for (uint16_t p; p < OTLEN; p++)
{ {
ot[0][p] = 0; ot[0][p] = 0;
ot[1][p] = 0; ot[1][p] = 0;
} }
nextpri = primbuff[!db];
} }
int main(void) int main(void)
{ {
int t = 0; int t = 0;
setRGB(&BGcolor, MScolor.r, MScolor.g, MScolor.b);
// init() display // init() display
init(); init();
// Init CD system // Init CD system
CdInit(); CdInit();
prev_overlay = next_overlay; prev_overlay = next_overlay;
while(1){ while(1){
if (t == 100){ if (t == 100){

View File

@ -2,7 +2,6 @@
int ovl_main_hello(void) int ovl_main_hello(void)
{ {
setRGB(&BGcolor, 0, 255, 100);
init(); init();
int i = 0; int i = 0;
while(1) while(1)

View File

@ -1,8 +1,11 @@
#include "../common.h" #include "../common.h"
int ovl_main_poly(void) int ovl_main_poly(void)
{ {
setRGB(&BGcolor, 250, 0, 250); #ifndef STANDALONE
useOT = 1;
#endif
init(); init();
uint16_t timer = 0; uint16_t timer = 0;
uint16_t timeout = 100; uint16_t timeout = 100;
@ -59,14 +62,16 @@ int ovl_main_poly(void)
timer++; timer++;
FntPrint("Hello Poly ! %d", timer); FntPrint("Hello Poly ! %d", timer);
FntFlush(-1);
#ifndef STANDALONE #ifndef STANDALONE
if (timer == timeout){ if (timer == timeout){
useOT = 0;
next_overlay = MOTHERSHIP; next_overlay = MOTHERSHIP;
break; break;
} }
#endif #endif
FntFlush(-1);
display(); display();
} }
return next_overlay; return next_overlay;
}; };

View File

@ -1,3 +0,0 @@
TLOAD_ADDR = 0x8001E8480;
__heap_base = 0x8001E8480;

View File

@ -2,14 +2,16 @@
int ovl_main_tile(void) int ovl_main_tile(void)
{ {
setRGB(&BGcolor, 150, 0, 50); #ifndef STANDALONE
init(); useOT = 1;
#endif
uint16_t timer = 0; uint16_t timer = 0;
uint16_t timeout = 100; uint16_t timeout = 100;
TILE * blue_tile; TILE * blue_tile = 0;
TILE * pink_tile; TILE * pink_tile = 0;
// This one is added at a different OT index // This one is added at a different OT index
TILE * yellow_tile; TILE * yellow_tile = 0;
init();
while(1) while(1)
{ {
// Initialize the reversed ordering table. This means the elements at index OTLEN - 1 is drawn first. // 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 ++; timer ++;
FntPrint("Hello tile ! %d\n", timer); FntPrint("Hello tile ! %d\n", timer);
FntFlush(-1);
#ifndef STANDALONE #ifndef STANDALONE
if (timer == timeout){ if (timer == timeout){
useOT = 0;
next_overlay = OVERLAY_POLY; next_overlay = OVERLAY_POLY;
// Empty ordering table
//~ EmptyOTag(&ot[db], &primbuff[db], nextpri);
break; break;
} }
#endif #endif
FntFlush(-1);
display(); display();
} }
return next_overlay; return next_overlay;