diff --git a/Makefile b/Makefile index e3418e1..ff08b7f 100644 --- a/Makefile +++ b/Makefile @@ -1,55 +1,69 @@ -hello_world: - $(MAKE) -C hello_world hello_2pads: $(MAKE) -C hello_2pads -hello_cube: - $(MAKE) -C hello_cube -hello_cubetex: - $(MAKE) -C hello_cubetex -hello_cubetex_stp: - $(MAKE) -C hello_cubetex_stp -hello_poly_fun: - $(MAKE) -C hello_poly_fun -hello_gte_opti: - $(MAKE) -C hello_gte_opti -hello_light: - $(MAKE) -C hello_light -hello_multi_vag: - $(MAKE) -C hello_multi_vag -hello_pad: - $(MAKE) -C hello_pad -hello_poly: - $(MAKE) -C hello_poly -hello_poly_stp: - $(MAKE) -C hello_poly_stp -hello_poly_ft: - $(MAKE) -C hello_poly_ft -hello_poly_gt: - $(MAKE) -C hello_poly_gt -hello_poly_gt_tw: - $(MAKE) -C hello_poly_gt_tw -hello_poly_inline: - $(MAKE) -C hello_poly_inline -hello_sio: - $(MAKE) -C hello_sio -hello_sprt: - $(MAKE) -C hello_sprt -hello_tile: - $(MAKE) -C hello_tile -hello_vag: - $(MAKE) -C hello_vag -hello_cd: - $(MAKE) -C hello_cd all -hello_cdda: - $(MAKE) -C hello_cdda all -hello_xa: - $(MAKE) -C hello_xa all hello_bs: - $(MAKE) -C hello_bs all + $(MAKE) -C hello_bs +hello_cd: + $(MAKE) -C hello_cd +hello_cdda: + $(MAKE) -C hello_cdda +hello_cd_exec: + $(MAKE) -C hello_cd_exec +hello_cube: + $(MAKE) -C hello_cube +hello_cubetex: + $(MAKE) -C hello_cubetex +hello_cubetex_stp: + $(MAKE) -C hello_cubetex_stp +hello_font: + $(MAKE) -C hello_font +hello_fx: + $(MAKE) -C hello_fx +hello_gte_opti: + $(MAKE) -C hello_gte_opti +hello_light: + $(MAKE) -C hello_light +hello_mod: + $(MAKE) -C hello_mod +hello_multi_vag: + $(MAKE) -C hello_multi_vag +hello_multi_xa: + $(MAKE) -C hello_multi_xa +hello_ovl_exec: + $(MAKE) -C hello_ovl_exec +hello_pad: + $(MAKE) -C hello_pad +hello_poly: + $(MAKE) -C hello_poly +hello_poly_ft: + $(MAKE) -C hello_poly_ft +hello_poly_fun: + $(MAKE) -C hello_poly_fun +hello_poly_gt: + $(MAKE) -C hello_poly_gt +hello_poly_gt_tw: + $(MAKE) -C hello_poly_gt_tw +hello_poly_inline: + $(MAKE) -C hello_poly_inline +hello_poly_stp: + $(MAKE) -C hello_poly_stp +hello_sio: + $(MAKE) -C hello_sio +hello_sprt: + $(MAKE) -C hello_sprt hello_str: - $(MAKE) -C hello_str all + $(MAKE) -C hello_str hello_strplay: - $(MAKE) -C hello_strplay all + $(MAKE) -C hello_strplay +hello_tile: + $(MAKE) -C hello_tile +hello_vag: + $(MAKE) -C hello_vag +hello_world: + $(MAKE) -C hello_world +hello_xa: + $(MAKE) -C hello_xa +hello_xa_streaming: + $(MAKE) -C hello_xa_streaming clean: $(MAKE) -C hello_2pads clean @@ -108,9 +122,5 @@ all: $(MAKE) -C hello_strplay all # declare phony rules -.PHONY: hello_2pads hello_cube hello_cubetex hello_poly_fun hello_gte_opti \ - hello_light hello_multi_vag hello_pad hello_poly hello_poly_ft hello_poly_gt \ - hello_poly_gt_tw hello_poly_inline hello_sio hello_sprt hello_tile \ - hello_vag hello_world hello_cdda hello_cd hello_xa hello_bs hello_str hello_strplay \ - hello_poly_stp hello_cubetex_stp \ +.PHONY: hello_2pads hello_bs hello_cd hello_cdda hello_cd_exec hello_cube hello_cubetex hello_cubetex_stp hello_font hello_fx hello_gte_opti hello_light hello_mod hello_multi_vag hello_multi_xa hello_ovl_exec hello_pad hello_poly hello_poly_ft hello_poly_fun hello_poly_gt hello_poly_gt_tw hello_poly_inline hello_poly_stp hello_sio hello_sprt hello_str hello_strplay hello_tile hello_vag hello_world hello_xa hello_xa_streaming \ clean all diff --git a/hello_ovl_exec/Makefile b/hello_ovl_exec/Makefile new file mode 100644 index 0000000..cc145b1 --- /dev/null +++ b/hello_ovl_exec/Makefile @@ -0,0 +1,27 @@ +.PHONY: all cleansub +all: + $(MAKE) -C hello_poly clean all + $(MAKE) -C hello_ovl_world clean all + $(MAKE) -C hello_tile clean all + mkpsxiso -y ./isoconfig.xml +cleansub: + $(MAKE) -C hello_poly clean + $(MAKE) -C hello_tile clean + $(MAKE) -C hello_ovl_world clean + $(MAKE) clean + rm -f hello_ovl_exec.cue hello_ovl_exec.bin + rm -f *.mcd *.frag *.lua *.vert + rm -f */*.mcd */*.frag */*.lua */*.vert */*.elf +#~ rm -f */*.mcd */*.frag */*.lua */*.vert */*.elf */*.map */*.ps-exe */*.o */*.dep + +TARGET = hello_ovl_exec + +OVERLAYSCRIPT ?= overlay.ld +OVERLAYSECTION ?= .ovly0 .ovly1 .ovly2 + +SRCS = hello_ovl_exec.c \ +hello_ovl_world/hello_ovl_world.c \ +hello_tile/hello_ovl_tile.c \ +hello_poly/hello_ovl_poly.c \ + +include ../common.mk diff --git a/hello_ovl_exec/README.md b/hello_ovl_exec/README.md new file mode 100644 index 0000000..bbcec45 --- /dev/null +++ b/hello_ovl_exec/README.md @@ -0,0 +1,35 @@ +## Creating the disk image + +After compiling, you need to generate a disk image with [mkpsxiso](https://github.com/Lameguy64/mkpsxiso): + +```bash +mkpsxiso -y isoconfig.xml +``` + +## Using ffmpeg to generate a CDDA compliant Wav file + +Needed Specification : `RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, stereo 44100 Hz` + +### Conversion + +```bash +ffmpeg -i input.mp3 -acodec pcm_s16le -ac 2 -ar 44100 output.wav +``` + +### Merging two mono audio channels into one stereo channel + +```bash +ffmpeg -i herb.wav.new -filter_complex "[0:a][0:a]amerge=inputs=2[a]" -map "[a]" herbi.wav +``` + +## Music credits + +Track 1 : +Beach Party by Kevin MacLeod +Link: https://incompetech.filmmusic.io/song/3429-beach-party +License: https://filmmusic.io/standard-license + +Track 2: +Funk Game Loop by Kevin MacLeod +Link: https://incompetech.filmmusic.io/song/3787-funk-game-loop +License: https://filmmusic.io/standard-license diff --git a/hello_ovl_exec/common.h b/hello_ovl_exec/common.h new file mode 100644 index 0000000..6719432 --- /dev/null +++ b/hello_ovl_exec/common.h @@ -0,0 +1,44 @@ +#pragma once +#include +#include +#include +#include +#include +#include +#include +#include +#include +// CD library +#include + +#define setRGB(p, r0, g0, b0) \ + (p)->r = r0, (p)->g = g0, (p)->b = b0 + +#define VMODE 0 +//~ #define VMODE 0 // Video Mode : 0 : NTSC, 1: PAL +#define SCREENXRES 320 // Screen width +#define SCREENYRES (240 + (VMODE << 4)) // Screen height : If VMODE is 0 = 240, if VMODE is 1 = 256 +#define CENTERX SCREENXRES/2 // Center of screen on x +#define CENTERY SCREENYRES/2 // Center of screen on y +#define MARGINX 0 // margins for text display +#define MARGINY 32 +#define FONTSIZE 18 * 7 // Text Field Height +#define OTLEN 8 // Ordering Table Length + +extern DRAWENV draw[2]; +extern char primbuff[2][32768]; +extern char *nextpri; +extern u_long ot[2][OTLEN]; +extern uint8_t db; +extern CVECTOR BGcolor; + +enum OverlayNumber { + MOTHERSHIP = -1, + OVERLAY_HELLO = 0, + OVERLAY_TILE = 1, + OVERLAY_POLY = 2, + }; +extern enum OverlayNumber next_overlay; + +extern void init(void); +extern void display(void); diff --git a/hello_ovl_exec/hello_ovl_exec.c b/hello_ovl_exec/hello_ovl_exec.c new file mode 100644 index 0000000..6bde547 --- /dev/null +++ b/hello_ovl_exec/hello_ovl_exec.c @@ -0,0 +1,137 @@ +// Load overlay files from CD and execute them +// Schnappy 10-2021 +// With the help of Nicolas Noble and impiaa +// https://discord.com/channels/642647820683444236/663664210525290507/894624082367229952 +#include "common.h" + +DISPENV disp[2]; // Double buffered DISPENV and DRAWENV +DRAWENV draw[2]; +char primbuff[2][32768]; // double primitive buffer of length 32768 * 8 = 262.144 bits / 32,768 Kbytes +u_long ot[2][OTLEN]; +char *nextpri = primbuff[0]; +uint8_t db = 0; +CVECTOR BGcolor = { 0, 150, 255 }; + +extern u_long load_all_overlays_here; + +typedef struct Overlay { + char filename[0x7c]; + int (*main)(); + char commandline[0x180]; +} Overlay; + +int ovl_main_hello(); +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 }, +}; + +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 ); + +void (*dispp) (void); +int CDreadOK = 0; + +void init(void) +{ + ResetCallback(); + ResetGraph(0); // Initialize drawing engine with a complete reset (0) + // Initialize and setup the GTE + InitGeom(); + SetGeomOffset(CENTERX,CENTERY); + SetGeomScreen(CENTERX); + SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES); // Set display area for both &disp[0] and &disp[1] + SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); // &disp[0] is on top of &disp[1] + SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); // Set draw for both &draw[0] and &draw[1] + SetDefDrawEnv(&draw[1], 0, 0 , SCREENXRES, SCREENYRES); // &draw[0] is below &draw[1] + // Set video mode + if (VMODE){ SetVideoMode(MODE_PAL);} + SetDispMask(1); // Display on screen + setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b); // set color for first draw area + setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b); // set color for second draw area + draw[0].isbg = 1; // set mask for draw areas. 1 means repainting the area with the RGB color each frame + draw[1].isbg = 1; + PutDispEnv(&disp[db]); // set the disp and draw environnments + PutDrawEnv(&draw[db]); + 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 +} + +void display(void) +{ + DrawSync(0); // Wait for all drawing to terminate + 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]); + db = !db; // flip db value (0 or 1) + nextpri = primbuff[db]; +} + +int loadOverlayAndStart(Overlay * overlay) +{ + int CDreadResult = 0; + int next_ovl = -1; + // Load overlay file + CDreadResult = CdReadFile(overlay->filename, &load_all_overlays_here, 0); + CdReadSync(0, 0); + printf( "CD read: %d", CDreadResult); + // If file loaded sucessfully + if (CDreadResult) + { + //~ StopCallback(); + ResetGraph(3); + // Execute + next_ovl = overlay->main(); + EmptyOTag(&ot[db], &primbuff[db], nextpri); + setRGB(&BGcolor, 0, 150, 255); + init(); + } + return next_ovl; +} + +void EmptyOTag(u_long ot[2][OTLEN], char primbuff[2][32768], char * nextpri ) +{ + for (uint16_t p; p < OTLEN; p++) + { + ot[0][p] = 0; + ot[1][p] = 0; + } + nextpri = primbuff[!db]; +} + +int main(void) +{ + int t = 0; + // init() display + init(); + // Init CD system + CdInit(); + + prev_overlay = next_overlay; + while(1){ + if (t == 100){ + next_overlay = OVERLAY_HELLO; + } + if (next_overlay != -1 && next_overlay != prev_overlay){ + prev_overlay = next_overlay; + next_overlay = loadOverlayAndStart(&g_chainload[next_overlay]); + t = 0; + } + t++; + FntPrint("Mothership: %d\nOvl: %d %d", t, prev_overlay, next_overlay); + FntFlush(-1); + display(); + } + // + return 0; +} diff --git a/hello_ovl_exec/hello_ovl_world/Makefile b/hello_ovl_exec/hello_ovl_world/Makefile new file mode 100644 index 0000000..603a0a5 --- /dev/null +++ b/hello_ovl_exec/hello_ovl_world/Makefile @@ -0,0 +1,7 @@ +TARGET = hello_world + +SRCS = hello_world.c \ + +CPPFLAGS+=-DSTANDALONE + +include ../../common.mk diff --git a/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c b/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c new file mode 100644 index 0000000..4270a54 --- /dev/null +++ b/hello_ovl_exec/hello_ovl_world/hello_ovl_world.c @@ -0,0 +1,25 @@ +#include "../common.h" + +int ovl_main_hello(void) +{ + setRGB(&BGcolor, 0, 255, 100); + init(); + int i = 0; + while(1) + { + i++; + #ifndef STANDALONE + if (i==100){ + next_overlay = OVERLAY_TILE; + break; + } + FntPrint("Hello world ! %d\n", i); + #else + FntPrint("Hello standalone ! %d\n", i); + #endif + FntFlush(-1); + display(); + } + return next_overlay; +}; + diff --git a/hello_ovl_exec/hello_ovl_world/hello_world.c b/hello_ovl_exec/hello_ovl_world/hello_world.c new file mode 100644 index 0000000..43cb957 --- /dev/null +++ b/hello_ovl_exec/hello_ovl_world/hello_world.c @@ -0,0 +1,52 @@ +#include "../common.h" + +DISPENV disp[2]; // Double buffered DISPENV and DRAWENV +DRAWENV draw[2]; +u_long ot[2][OTLEN]; // double ordering table of length 8 * 32 = 256 bits / 32 bytes +char primbuff[2][32768];// double primitive buffer of length 32768 * 8 = 262.144 bits / 32,768 Kbytes +char *nextpri = primbuff[0]; // pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0] +uint8_t db = 0; // index of which buffer is used, values 0, 1 +CVECTOR BGcolor = { 0, 255, 100 }; +//~ int next_overlay; + +void init(void) +{ + ResetGraph(0); + SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES); + SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[1], 0, 0, SCREENXRES, SCREENYRES); + if (VMODE) + { + SetVideoMode(MODE_PAL); + disp[0].screen.y += 8; + disp[1].screen.y += 8; + } + SetDispMask(1); // Display on screen + setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b); // set color for first draw area + setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b); // set color for second draw area + draw[0].isbg = 1; + draw[1].isbg = 1; + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + FntLoad(960, 0); + FntOpen(MARGINX, SCREENYRES - MARGINY - FONTSIZE, SCREENXRES - MARGINX * 2, FONTSIZE, 0, 280 ); +} +void display(void) +{ + DrawSync(0); + VSync(0); + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + DrawOTag(&ot[db][OTLEN - 1]); + db = !db; + nextpri = primbuff[db]; +} + +#include "hello_ovl_world.c" + +int main(void) +{ + ovl_main_hello(); +}; + diff --git a/hello_ovl_exec/hello_poly/Makefile b/hello_ovl_exec/hello_poly/Makefile new file mode 100644 index 0000000..4a9cd63 --- /dev/null +++ b/hello_ovl_exec/hello_poly/Makefile @@ -0,0 +1,7 @@ +TARGET = hello_poly + +SRCS = hello_poly.c \ + +CPPFLAGS+=-DSTANDALONE + +include ../../common.mk diff --git a/hello_ovl_exec/hello_poly/hello_ovl_poly.c b/hello_ovl_exec/hello_poly/hello_ovl_poly.c new file mode 100644 index 0000000..17b3660 --- /dev/null +++ b/hello_ovl_exec/hello_poly/hello_ovl_poly.c @@ -0,0 +1,72 @@ +#include "../common.h" + +int ovl_main_poly(void) +{ + setRGB(&BGcolor, 250, 0, 250); + init(); + uint16_t timer = 0; + uint16_t timeout = 100; + MATRIX IDMATRIX = {0}; + POLY_F4 *poly = {0}; + SVECTOR RotVector = {0, 0, 0}; + VECTOR MovVector = {0, 0, CENTERX, 0}; + SVECTOR VertPos[4] = { + {-32, -32, 1 }, + {-32, 32, 1 }, + { 32, -32, 1 }, + { 32, 32, 1 } + }; + MATRIX PolyMatrix = IDMATRIX; + + long polydepth; + long polyflag; + long OTz; + + init(); + + while (1) + { + + ClearOTagR(ot[db], OTLEN); + + poly = (POLY_F4 *)nextpri; // Set poly to point to the address of the next primitiv in the buffer + + // Set transform matrices for this polygon + + RotMatrix(&RotVector, &PolyMatrix); // Apply rotation matrix + TransMatrix(&PolyMatrix, &MovVector); + SetRotMatrix(&PolyMatrix); // Set default rotation matrix + SetTransMatrix(&PolyMatrix); // Set default transformation matrix + setPolyF4(poly); // Initialize poly as a POLY_F4 + setRGB0(poly, 255, 255, 0); // Set poly color + + // RotTransPers + OTz = RotTransPers4( + &VertPos[0], &VertPos[1], &VertPos[2], &VertPos[3], + (long*)&poly->x0, (long*)&poly->x1, (long*)&poly->x2, (long*)&poly->x3, + &polydepth, + &polyflag + ); // Perform coordinate and perspective transformation for 4 vertices + + RotVector.vy += 4; + RotVector.vz += 4; // Apply rotation on Z-axis. On PSX, the Z-axis is pointing away from the screen. + + //~ addPrim(ot[db], poly); // add poly to the Ordering table + addPrim(ot[db][OTLEN-1], poly); // add poly to the Ordering table + + nextpri += sizeof(POLY_F4); // increment nextpri address with size of a POLY_F4 struct + + timer++; + + FntPrint("Hello Poly ! %d", timer); + #ifndef STANDALONE + if (timer == timeout){ + next_overlay = MOTHERSHIP; + break; + } + #endif + FntFlush(-1); + display(); + } + return next_overlay; +}; diff --git a/hello_ovl_exec/hello_poly/hello_poly.c b/hello_ovl_exec/hello_poly/hello_poly.c new file mode 100644 index 0000000..e098a92 --- /dev/null +++ b/hello_ovl_exec/hello_poly/hello_poly.c @@ -0,0 +1,58 @@ +#include "../common.h" + +DISPENV disp[2]; // Double buffered DISPENV and DRAWENV +DRAWENV draw[2]; +u_long ot[2][OTLEN]; // double ordering table of length 8 * 32 = 256 bits / 32 bytes +char primbuff[2][32768]; // double primitive buffer of length 32768 * 8 = 262.144 bits / 32,768 Kbytes +char *nextpri = primbuff[0]; // pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0] +uint8_t db = 0; // index of which buffer is used, values 0, 1 +CVECTOR BGcolor = { 50, 255, 150 }; + +void init(void) +{ + ResetCallback(); + ResetGraph(3); + // Initialize and setup the GTE + InitGeom(); + SetGeomOffset(CENTERX,CENTERY); + SetGeomScreen(CENTERX); + SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES); + SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[1], 0, 0, SCREENXRES, SCREENYRES); + if (VMODE) + { + SetVideoMode(MODE_PAL); + disp[0].screen.y += 8; + disp[1].screen.y += 8; + } + setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b); // set color for first draw area + setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b); // set color for second draw area + SetDispMask(1); + draw[0].isbg = 1; + draw[1].isbg = 1; + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + + FntLoad(960, 0); + FntOpen(MARGINX, SCREENYRES - MARGINY - FONTSIZE, SCREENXRES - MARGINX * 2, FONTSIZE, 0, 280 ); + +} + +void display(void) +{ + DrawSync(0); + VSync(0); + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + DrawOTag(&ot[db][OTLEN - 1]); + db = !db; + nextpri = primbuff[db]; +} + +#include "hello_ovl_poly.c" + +int main(void) +{ + ovl_main_poly(); +} diff --git a/hello_ovl_exec/hello_poly/hello_poly.ld b/hello_ovl_exec/hello_poly/hello_poly.ld new file mode 100644 index 0000000..837a4e7 --- /dev/null +++ b/hello_ovl_exec/hello_poly/hello_poly.ld @@ -0,0 +1,3 @@ +TLOAD_ADDR = 0x8001E8480; +__heap_base = 0x8001E8480; + diff --git a/hello_ovl_exec/hello_tile/Makefile b/hello_ovl_exec/hello_tile/Makefile new file mode 100644 index 0000000..db14b06 --- /dev/null +++ b/hello_ovl_exec/hello_tile/Makefile @@ -0,0 +1,7 @@ +TARGET = hello_tile + +SRCS = hello_tile.c \ + +CPPFLAGS+=-DSTANDALONE + +include ../../common.mk diff --git a/hello_ovl_exec/hello_tile/hello_ovl_tile.c b/hello_ovl_exec/hello_tile/hello_ovl_tile.c new file mode 100644 index 0000000..1596bbf --- /dev/null +++ b/hello_ovl_exec/hello_tile/hello_ovl_tile.c @@ -0,0 +1,69 @@ +#include "../common.h" + +int ovl_main_tile(void) +{ + setRGB(&BGcolor, 150, 0, 50); + init(); + uint16_t timer = 0; + uint16_t timeout = 100; + TILE * blue_tile; + TILE * pink_tile; + // This one is added at a different OT index + TILE * yellow_tile; + while(1) + { + // Initialize the reversed ordering table. This means the elements at index OTLEN - 1 is drawn first. + ClearOTagR(ot[db], OTLEN); + + // yellow_tile + + yellow_tile = (TILE * ) nextpri; // yellow_tile is a pointer to primbuf content at adress nextpri, that's cast (type converted) to a TILE struc. + + setTile(yellow_tile); // initialize the TILE structure ( fill the length and tag(?) value ) + setXY0(yellow_tile, CENTERX - 32 , CENTERY - 48); // Set X,Y + setWH(yellow_tile, 128, 40); // Set Width, Height + setRGB0(yellow_tile, 255, 255, 0); // Set color + addPrim(ot[db][OTLEN - 1], yellow_tile); // Add primitive to ordering table + + nextpri += sizeof(TILE); + + // blue_tile + + blue_tile = (TILE * ) nextpri; // blue_tile is a pointer to primbuf content at adress nextpri, that's cast (type converted) to a blue_tile struc. + + setTile(blue_tile); // initialize the blue_tile structure ( fill the length and tag(?) value ) + setXY0(blue_tile, CENTERX - 16, CENTERY - 32); // Set X,Y + setWH(blue_tile, 32, 64); // Set Width, Height + setRGB0(blue_tile, 60, 180, 255); // Set color + addPrim(ot[db][OTLEN - 2], blue_tile); // Add primitive to ordering table + + nextpri += sizeof(TILE); // Increment the adress nextpri points to by the size of TILE struct + + // pink_tile + + pink_tile = (TILE * ) nextpri; // pink_tile is a pointer to primbuf content at adress nextpri, that's cast (type converted) to a TILE struc. + + setTile(pink_tile); // initialize the TILE structure ( fill the length and tag(?) value ) + setXY0(pink_tile, CENTERX, CENTERY - 64); // Set X,Y + setWH(pink_tile, 64, 64); // Set Width, Height + setRGB0(pink_tile, 255, 32, 255); // Set color + addPrim(ot[db][OTLEN - 2], pink_tile); // Add primitive to ordering table + + nextpri += sizeof(TILE); + + timer ++; + + FntPrint("Hello tile ! %d\n", timer); + #ifndef STANDALONE + if (timer == timeout){ + next_overlay = OVERLAY_POLY; + // Empty ordering table + //~ EmptyOTag(&ot[db], &primbuff[db], nextpri); + break; + } + #endif + FntFlush(-1); + display(); + } + return next_overlay; +}; diff --git a/hello_ovl_exec/hello_tile/hello_tile.c b/hello_ovl_exec/hello_tile/hello_tile.c new file mode 100644 index 0000000..6a6b350 --- /dev/null +++ b/hello_ovl_exec/hello_tile/hello_tile.c @@ -0,0 +1,52 @@ +#include "../common.h" + +DISPENV disp[2]; // Double buffered DISPENV and DRAWENV +DRAWENV draw[2]; +u_long ot[2][OTLEN]; // double ordering table of length 8 * 32 = 256 bits / 32 bytes +char primbuff[2][32768]; // double primitive buffer of length 32768 * 8 = 262.144 bits / 32,768 Kbytes +char *nextpri = primbuff[0]; // pointer to the next primitive in primbuff. Initially, points to the first bit of primbuff[0] +uint8_t db = 0; // index of which buffer is used, values 0, 1 +CVECTOR BGcolor = { 50, 255, 150 }; + +void init(void) +{ + ResetGraph(0); + SetDefDispEnv(&disp[0], 0, 0, SCREENXRES, SCREENYRES); + SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); + SetDefDrawEnv(&draw[1], 0, 0, SCREENXRES, SCREENYRES); + if (VMODE) + { + SetVideoMode(MODE_PAL); + disp[0].screen.y += 8; + disp[1].screen.y += 8; + } + SetDispMask(1); // Display on screen + setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b); // set color for first draw area + setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b); // set color for second draw area + draw[0].isbg = 1; + draw[1].isbg = 1; + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + FntLoad(960, 0); + FntOpen(MARGINX, SCREENYRES - MARGINY - FONTSIZE, SCREENXRES - MARGINX * 2, FONTSIZE, 0, 280 ); +} +void display(void) +{ + DrawSync(0); + VSync(0); + PutDispEnv(&disp[db]); + PutDrawEnv(&draw[db]); + // We're using a reverse OT, so we want to display the last item first. See PsyQ's LibRef47.pdf, p.277 + DrawOTag(&ot[db][OTLEN - 1]); + // Comment above line, and uncomment the following line to use a regular oredered OT. Comment l.71 and Uncomment l.73 accordingly + db = !db; + nextpri = primbuff[db]; +} + +#include "hello_ovl_tile.c" + +int main(void) +{ + ovl_main_tile(); +}; diff --git a/hello_ovl_exec/isoconfig.xml b/hello_ovl_exec/isoconfig.xml new file mode 100644 index 0000000..87728b5 --- /dev/null +++ b/hello_ovl_exec/isoconfig.xml @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/hello_ovl_exec/overlay.ld b/hello_ovl_exec/overlay.ld new file mode 100644 index 0000000..80f5795 --- /dev/null +++ b/hello_ovl_exec/overlay.ld @@ -0,0 +1,60 @@ +__heap_base = MAX(__ovly0_end, __ovly2_end); + +SECTIONS { + OVERLAY __bss_end : NOCROSSREFS SUBALIGN(4) + { + .ovlyload + { + load_all_overlays_here = .; + } + .ovly0 + { + KEEP(hello_poly/*.o(.text)) + __ovly0_ctor = .; + KEEP(hello_poly/*.o(.text.startup._GLOBAL__*)) + KEEP(hello_poly/*.o(.text.*)) + KEEP(hello_poly/*.o(.rodata*)) + KEEP(hello_poly/*.o(.sdata*)) + KEEP(hello_poly/*.o(.data*)) + KEEP(hello_poly/*.o(.sbss*)) + KEEP(hello_poly/*.o(.bss*)) + KEEP(hello_poly/*.o(.ctors)) + + . = ALIGN(4); + __ovly0_end = .; + } + + .ovly1 + { + KEEP(hello_tile/*.o(.text)) + __ovly1_ctor = .; + KEEP(hello_tile/*.o(.text.startup._GLOBAL__*)) + KEEP(hello_tile/*.o(.text.*)) + KEEP(hello_tile/*.o(.rodata*)) + KEEP(hello_tile/*.o(.sdata*)) + KEEP(hello_tile/*.o(.data*)) + KEEP(hello_tile/*.o(.sbss*)) + KEEP(hello_tile/*.o(.bss*)) + KEEP(hello_tile/*.o(.ctors)) + + . = ALIGN(4); + __ovly1_end = .; + } + .ovly2 + { + KEEP(hello_ovl_world/*.o(.text)) + __ovly2_ctor = .; + KEEP(hello_ovl_world/*.o(.text.startup._GLOBAL__*)) + KEEP(hello_ovl_world/*.o(.text.*)) + KEEP(hello_ovl_world/*.o(.rodata*)) + KEEP(hello_ovl_world/*.o(.sdata*)) + KEEP(hello_ovl_world/*.o(.data*)) + KEEP(hello_ovl_world/*.o(.sbss*)) + KEEP(hello_ovl_world/*.o(.bss*)) + KEEP(hello_ovl_world/*.o(.ctors)) + + . = ALIGN(4); + __ovly2_end = .; + } + } +} diff --git a/hello_ovl_exec/system.cnf b/hello_ovl_exec/system.cnf new file mode 100644 index 0000000..ae2db18 --- /dev/null +++ b/hello_ovl_exec/system.cnf @@ -0,0 +1,4 @@ +BOOT=cdrom:\SCES_313.37;1 +TCB=4 +EVENT=10 +STACK=801FFFF0