Add overlays
This commit is contained in:
parent
627db26cda
commit
ac41aa1db7
56
OVL/common.h
Normal file
56
OVL/common.h
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <libgte.h>
|
||||||
|
#include <libetc.h>
|
||||||
|
#include <libgpu.h>
|
||||||
|
#include <libapi.h>
|
||||||
|
#include <libcd.h>
|
||||||
|
#include <libds.h>
|
||||||
|
#include <libpress.h>
|
||||||
|
#include <malloc.h>
|
||||||
|
#include <kernel.h>
|
||||||
|
#include "../third_party/nugget/common/syscalls/syscalls.h"
|
||||||
|
#define printf ramsyscall_printf
|
||||||
|
|
||||||
|
#define setRGB(p, r0, g0, b0) \
|
||||||
|
(p)->r = r0, (p)->g = g0, (p)->b = b0
|
||||||
|
|
||||||
|
#define VMODE 0
|
||||||
|
#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 FONTX 960
|
||||||
|
#define FONTY 0
|
||||||
|
#define OTLEN 512 // 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 uint8_t useOT;
|
||||||
|
extern CVECTOR BGcolor;
|
||||||
|
extern int timeout;
|
||||||
|
|
||||||
|
enum OverlayNumber {
|
||||||
|
MOTHERSHIP = -1,
|
||||||
|
OVERLAY_HELLO = 0,
|
||||||
|
OVERLAY_TILE = 1,
|
||||||
|
OVERLAY_POLY = 2,
|
||||||
|
OVERLAY_SPRT = 3,
|
||||||
|
OVERLAY_CUBE = 4,
|
||||||
|
OVERLAY_LIGHT = 5,
|
||||||
|
OVERLAY_PAD = 6,
|
||||||
|
};
|
||||||
|
extern enum OverlayNumber next_overlay;
|
||||||
|
|
||||||
|
extern void init(void);
|
||||||
|
extern void display(void);
|
||||||
|
extern void clearVRAM(void);
|
||||||
|
extern void LoadTexture(u_long * tim, TIM_IMAGE * tparam);
|
8
OVL/hello_cubetex/Makefile
Normal file
8
OVL/hello_cubetex/Makefile
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
TARGET = hello_cubetex
|
||||||
|
|
||||||
|
SRCS = hello_cubetex.c \
|
||||||
|
TIM/cubetex.tim \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
BIN
OVL/hello_cubetex/TIM/cubetex.tim
Normal file
BIN
OVL/hello_cubetex/TIM/cubetex.tim
Normal file
Binary file not shown.
128
OVL/hello_cubetex/cubetex.c
Normal file
128
OVL/hello_cubetex/cubetex.c
Normal file
@ -0,0 +1,128 @@
|
|||||||
|
SVECTOR modelCubeTex_mesh[] = {
|
||||||
|
{32,32,-32.0},
|
||||||
|
{32,-32,-32},
|
||||||
|
{-32,-32,-32},
|
||||||
|
{-32,32,-32},
|
||||||
|
{32,32,32},
|
||||||
|
{32,-32,32},
|
||||||
|
{-32,-32,32},
|
||||||
|
{-32,32,32}
|
||||||
|
};
|
||||||
|
|
||||||
|
SVECTOR modelCubeTex_normal[] = {
|
||||||
|
0,-0,-1,0,
|
||||||
|
0,0,1,0,
|
||||||
|
1,0,-2,0,
|
||||||
|
-9,-1,-3,0,
|
||||||
|
-1,2,-1,0,
|
||||||
|
3,1,2,0,
|
||||||
|
0,0,-1,0,
|
||||||
|
0,-0,1,0,
|
||||||
|
1,-6,3,0,
|
||||||
|
-5,-1,9,0,
|
||||||
|
-1,2,-1,0,
|
||||||
|
2,1,2,0
|
||||||
|
};
|
||||||
|
|
||||||
|
SVECTOR modelCubeTex_uv[] = {
|
||||||
|
84,84, 0, 0,
|
||||||
|
125,42, 0, 0,
|
||||||
|
84,42, 0, 0,
|
||||||
|
125,84, 0, 0,
|
||||||
|
84,125, 0, 0,
|
||||||
|
125,125, 0, 0,
|
||||||
|
1,84, 0, 0,
|
||||||
|
42,125, 0, 0,
|
||||||
|
42,84, 0, 0,
|
||||||
|
42,125, 0, 0,
|
||||||
|
84,84, 0, 0,
|
||||||
|
42,84, 0, 0,
|
||||||
|
42,1, 0, 0,
|
||||||
|
1,42, 0, 0,
|
||||||
|
42,42, 0, 0,
|
||||||
|
42,84, 0, 0,
|
||||||
|
1,42, 0, 0,
|
||||||
|
1,84, 0, 0,
|
||||||
|
84,84, 0, 0,
|
||||||
|
125,84, 0, 0,
|
||||||
|
125,42, 0, 0,
|
||||||
|
125,84, 0, 0,
|
||||||
|
84,84, 0, 0,
|
||||||
|
84,125, 0, 0,
|
||||||
|
1,84, 0, 0,
|
||||||
|
1,125, 0, 0,
|
||||||
|
42,125, 0, 0,
|
||||||
|
42,125, 0, 0,
|
||||||
|
84,125, 0, 0,
|
||||||
|
84,84, 0, 0,
|
||||||
|
42,1, 0, 0,
|
||||||
|
1,1, 0, 0,
|
||||||
|
1,42, 0, 0,
|
||||||
|
42,84, 0, 0,
|
||||||
|
42,42, 0, 0,
|
||||||
|
1,42, 0, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
CVECTOR modelCubeTex_color[] = {
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,0,251, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,5,7, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
4,18,255, 0,
|
||||||
|
255,5,7, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
254,255,23, 0,
|
||||||
|
122,255,107, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
254,255,94, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
35,255,11, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,5,7, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,5,7, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,5,7, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
254,255,23, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
122,255,107, 0,
|
||||||
|
255,255,255, 0,
|
||||||
|
54,65,255, 0,
|
||||||
|
255,255,255, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
int modelCubeTex_index[] = {
|
||||||
|
0,2,3,
|
||||||
|
7,5,4,
|
||||||
|
4,1,0,
|
||||||
|
5,2,1,
|
||||||
|
2,7,3,
|
||||||
|
0,7,4,
|
||||||
|
0,1,2,
|
||||||
|
7,6,5,
|
||||||
|
4,5,1,
|
||||||
|
5,6,2,
|
||||||
|
2,6,7,
|
||||||
|
0,3,7
|
||||||
|
};
|
||||||
|
|
||||||
|
TMESH modelCubeTex = {
|
||||||
|
modelCubeTex_mesh,
|
||||||
|
modelCubeTex_normal,
|
||||||
|
modelCubeTex_uv,
|
||||||
|
modelCubeTex_color,
|
||||||
|
12
|
||||||
|
};
|
||||||
|
|
||||||
|
TIM_IMAGE tim_cube;
|
64
OVL/hello_cubetex/hello_cubetex.c
Normal file
64
OVL/hello_cubetex/hello_cubetex.c
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
DISPENV disp[2];
|
||||||
|
DRAWENV draw[2];
|
||||||
|
u_long ot[2][OTLEN];
|
||||||
|
char primbuff[2][32768];
|
||||||
|
char * nextpri = primbuff[0];
|
||||||
|
uint8_t db = 0;
|
||||||
|
CVECTOR BGcolor = { 0, 200, 255 };
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
PadInit(0);
|
||||||
|
ResetGraph(0);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
SetDispMask(1);
|
||||||
|
setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
draw[0].isbg = 1;
|
||||||
|
draw[1].isbg = 1;
|
||||||
|
PutDispEnv(&disp[db]);
|
||||||
|
PutDrawEnv(&draw[db]);
|
||||||
|
FntLoad(960, 0);
|
||||||
|
FntOpen(16, 16, 196, 64, 0, 256);
|
||||||
|
}
|
||||||
|
void display(void)
|
||||||
|
{
|
||||||
|
DrawSync(0);
|
||||||
|
VSync(-1);
|
||||||
|
PutDispEnv(&disp[db]);
|
||||||
|
PutDrawEnv(&draw[db]);
|
||||||
|
DrawOTag(&ot[db][OTLEN - 1]);
|
||||||
|
db = !db;
|
||||||
|
nextpri = primbuff[db];
|
||||||
|
}
|
||||||
|
void LoadTexture(u_long * tim, TIM_IMAGE * tparam)
|
||||||
|
{
|
||||||
|
OpenTIM(tim);
|
||||||
|
ReadTIM(tparam);
|
||||||
|
LoadImage(tparam->prect, tparam->paddr);
|
||||||
|
DrawSync(0);
|
||||||
|
if (tparam->mode & 0x8) {
|
||||||
|
LoadImage(tparam->crect, tparam->caddr);
|
||||||
|
DrawSync(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#include "hello_ovl_cubetex.c"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
ovl_main_cubetex();
|
||||||
|
}
|
145
OVL/hello_cubetex/hello_ovl_cubetex.c
Normal file
145
OVL/hello_cubetex/hello_ovl_cubetex.c
Normal file
@ -0,0 +1,145 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
#include "cubetex.c"
|
||||||
|
|
||||||
|
#ifdef STANDALONE
|
||||||
|
extern unsigned long _binary_TIM_cubetex_tim_start[];
|
||||||
|
#else
|
||||||
|
extern unsigned long _binary_OVL_hello_cubetex_TIM_cubetex_tim_start[];
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int ovl_main_cubetex()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
int PadStatus;
|
||||||
|
int TPressed=0;
|
||||||
|
int AutoRotate=1;
|
||||||
|
long t, p, OTz, Flag; // t == vertex count, p == depth cueing interpolation value, OTz == value to create Z-ordered OT, Flag == see LibOver47.pdf, p.143
|
||||||
|
POLY_GT3 *poly = {0}; // pointer to a POLY_G4
|
||||||
|
SVECTOR Rotate={ 256, 256, 0, 0 }; // Rotation coordinates
|
||||||
|
VECTOR Trans={ 0, 0, CENTERX, 0 }; // Translation coordinates
|
||||||
|
VECTOR Scale={ ONE, ONE, ONE, 0 }; // ONE == 4096
|
||||||
|
MATRIX Matrix={0}; // Matrix data for the GTE
|
||||||
|
DR_MODE * dr_mode; // Pointer to dr_mode prim
|
||||||
|
RECT tws = {0, 0, 32, 32}; // Texture window coordinates : x, y, w, h
|
||||||
|
init();
|
||||||
|
#ifdef STANDALONE
|
||||||
|
LoadTexture(_binary_TIM_cubetex_tim_start, &tim_cube);
|
||||||
|
#else
|
||||||
|
LoadTexture(_binary_OVL_hello_cubetex_TIM_cubetex_tim_start, &tim_cube);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int primSet = 0;
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
while (1) {
|
||||||
|
i++;
|
||||||
|
// Read pad status
|
||||||
|
PadStatus = PadRead(0);
|
||||||
|
if (AutoRotate == 0) {
|
||||||
|
if (PadStatus & PADL1) Trans.vz -= 4;
|
||||||
|
if (PadStatus & PADR1) Trans.vz += 4;
|
||||||
|
if (PadStatus & PADL2) Rotate.vz -= 8;
|
||||||
|
if (PadStatus & PADR2) Rotate.vz += 8;
|
||||||
|
if (PadStatus & PADLup) Rotate.vx -= 8;
|
||||||
|
if (PadStatus & PADLdown) Rotate.vx += 8;
|
||||||
|
if (PadStatus & PADLleft) Rotate.vy -= 8;
|
||||||
|
if (PadStatus & PADLright) Rotate.vy += 8;
|
||||||
|
if (PadStatus & PADRup) Trans.vy -= 2;
|
||||||
|
if (PadStatus & PADRdown) Trans.vy += 2;
|
||||||
|
if (PadStatus & PADRleft) Trans.vx -= 2;
|
||||||
|
if (PadStatus & PADRright) Trans.vx += 2;
|
||||||
|
if (PadStatus & PADselect) {
|
||||||
|
Rotate.vx = Rotate.vy = Rotate.vz = 0;
|
||||||
|
Scale.vx = Scale.vy = Scale.vz = ONE;
|
||||||
|
Trans.vx = Trans.vy = 0;
|
||||||
|
Trans.vz = CENTERX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (PadStatus & PADstart) {
|
||||||
|
if (TPressed == 0) {
|
||||||
|
AutoRotate = (AutoRotate + 1) & 1;
|
||||||
|
Rotate.vx = Rotate.vy = Rotate.vz = 0;
|
||||||
|
Scale.vx = Scale.vy = Scale.vz = ONE;
|
||||||
|
Trans.vx = Trans.vy = 0;
|
||||||
|
Trans.vz = CENTERX;
|
||||||
|
}
|
||||||
|
TPressed = 1;
|
||||||
|
} else {
|
||||||
|
TPressed = 0;
|
||||||
|
}
|
||||||
|
if (AutoRotate) {
|
||||||
|
Rotate.vy += 8; // Pan
|
||||||
|
Rotate.vx += 8; // Tilt
|
||||||
|
}
|
||||||
|
// Clear the current OT
|
||||||
|
ClearOTagR(ot[db], OTLEN);
|
||||||
|
// Convert and set the matrices
|
||||||
|
RotMatrix(&Rotate, &Matrix);
|
||||||
|
TransMatrix(&Matrix, &Trans);
|
||||||
|
ScaleMatrix(&Matrix, &Scale);
|
||||||
|
SetRotMatrix(&Matrix);
|
||||||
|
SetTransMatrix(&Matrix);
|
||||||
|
// Render the sample vector model
|
||||||
|
// modelCubeTex is a TMESH, len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
|
||||||
|
//~ if (primSet == 0){
|
||||||
|
for (int v = 0; v < (modelCubeTex.len*3); v += 3) {
|
||||||
|
poly = (POLY_GT3 *)nextpri;
|
||||||
|
// Initialize the primitive and set its color values
|
||||||
|
SetPolyGT3(poly);
|
||||||
|
((POLY_GT3 *)poly)->tpage = getTPage(tim_cube.mode&0x3, 0,
|
||||||
|
tim_cube.prect->x,
|
||||||
|
tim_cube.prect->y
|
||||||
|
);
|
||||||
|
setRGB0(poly, modelCubeTex.c[v].r , modelCubeTex.c[v].g , modelCubeTex.c[v].b);
|
||||||
|
setRGB1(poly, modelCubeTex.c[v+2].r, modelCubeTex.c[v+2].g, modelCubeTex.c[v+2].b);
|
||||||
|
setRGB2(poly, modelCubeTex.c[v+1].r, modelCubeTex.c[v+1].g, modelCubeTex.c[v+1].b);
|
||||||
|
setUV3(poly, modelCubeTex.u[v].vx, modelCubeTex.u[v].vy,
|
||||||
|
modelCubeTex.u[v+2].vx, modelCubeTex.u[v+2].vy,
|
||||||
|
modelCubeTex.u[v+1].vx, modelCubeTex.u[v+1].vy);
|
||||||
|
// Rotate, translate, and project the vectors and output the results into a primitive
|
||||||
|
OTz = RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v]] , (long*)&poly->x0, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v+2]], (long*)&poly->x1, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v+1]], (long*)&poly->x2, &p, &Flag);
|
||||||
|
// Sort the primitive into the OT
|
||||||
|
OTz /= 3;
|
||||||
|
if ((OTz > 0) && (OTz < OTLEN))
|
||||||
|
AddPrim(&ot[db][OTz-2], poly);
|
||||||
|
nextpri += sizeof(POLY_GT3);
|
||||||
|
}
|
||||||
|
//~ dr_mode = (DR_MODE *)nextpri;
|
||||||
|
//~ setDrawMode(dr_mode,1,0, getTPage(tim_cube.mode&0x3, 0,
|
||||||
|
//~ tim_cube.prect->x,
|
||||||
|
//~ tim_cube.prect->y), &tws); //set texture window
|
||||||
|
//~ AddPrim(&ot[db], dr_mode);
|
||||||
|
//~ nextpri += sizeof(DR_MODE);
|
||||||
|
//~ primSet = 1;
|
||||||
|
//~ } else {
|
||||||
|
//~ nextpri = primbuff[db];
|
||||||
|
//~ for (int v = 0; v < (modelCubeTex.len*3); v += 3) {
|
||||||
|
//~ // Rotate, translate, and project the vectors and output the results into a primitive
|
||||||
|
//~ OTz = RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v]] , (long*) &((POLY_GT3 * ) (&(primbuff[0][ sizeof(POLY_GT3) * (v/3) ]) ) )->x0, &p, &Flag);
|
||||||
|
//~ OTz += RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v+2]], (long*) &((POLY_GT3 * ) (&(primbuff[0][ sizeof(POLY_GT3) * (v/3) ]) ) )->x1, &p, &Flag);
|
||||||
|
//~ OTz += RotTransPers(&modelCubeTex_mesh[modelCubeTex_index[v+1]], (long*) &((POLY_GT3 * ) (&(primbuff[0][ sizeof(POLY_GT3) * (v/3) ]) ) )->x2, &p, &Flag);
|
||||||
|
//~ // Sort the primitive into the OT
|
||||||
|
//~ OTz /= 3;
|
||||||
|
//~ if ((OTz > 0) && (OTz < OTLEN))
|
||||||
|
//~ AddPrim(&ot[db][OTz-2], (POLY_GT3 * ) (&(primbuff[0][ sizeof(POLY_GT3) * (v/3) ])) );
|
||||||
|
//~ }
|
||||||
|
//~ }
|
||||||
|
FntPrint(0, "Hello textured cube! %d\n", i);
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
7
OVL/hello_light/Makefile
Normal file
7
OVL/hello_light/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
TARGET = hello_light
|
||||||
|
|
||||||
|
SRCS = hello_light.c \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
167
OVL/hello_light/cube.c
Normal file
167
OVL/hello_light/cube.c
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
SVECTOR modelCube_mesh[] = {
|
||||||
|
{ -128,128,128 },
|
||||||
|
{ 128,128,128 },
|
||||||
|
{ 128,128,-128 },
|
||||||
|
{ -128,128,-128 },
|
||||||
|
{ -128,-128,128 },
|
||||||
|
{ 128,-128,128 },
|
||||||
|
{ 128,-128,-128 },
|
||||||
|
{ -128,-128,-128 }
|
||||||
|
};
|
||||||
|
|
||||||
|
SVECTOR modelCube_normal[] = {
|
||||||
|
2365,-2365,-2365, 0,
|
||||||
|
-2365,-2365,-2365, 0,
|
||||||
|
-2365,-2365,2365, 0,
|
||||||
|
2365,-2365,2365, 0,
|
||||||
|
2365,2365,-2365, 0,
|
||||||
|
-2365,2365,-2365, 0,
|
||||||
|
-2365,2365,2365, 0,
|
||||||
|
2365,2365,2365, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
CVECTOR modelCube_color[] = {
|
||||||
|
255,237,0, 0,
|
||||||
|
255,235,0, 0,
|
||||||
|
255,236,0, 0,
|
||||||
|
255,2,0, 0,
|
||||||
|
254,3,0, 0,
|
||||||
|
255,8,0, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
5,16,250, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
4,251,25, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
255,237,0, 0,
|
||||||
|
255,237,0, 0,
|
||||||
|
255,235,0, 0,
|
||||||
|
255,2,0, 0,
|
||||||
|
255,6,2, 0,
|
||||||
|
254,3,0, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
232,21,232, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
5,16,250, 0,
|
||||||
|
2,13,253, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
4,251,25, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
int modelCube_index[] = {
|
||||||
|
0,2,3,
|
||||||
|
7,5,4,
|
||||||
|
4,1,0,
|
||||||
|
5,2,1,
|
||||||
|
2,7,3,
|
||||||
|
0,7,4,
|
||||||
|
0,1,2,
|
||||||
|
7,6,5,
|
||||||
|
4,5,1,
|
||||||
|
5,6,2,
|
||||||
|
2,6,7,
|
||||||
|
0,3,7
|
||||||
|
};
|
||||||
|
|
||||||
|
TMESH modelCube = {
|
||||||
|
modelCube_mesh,
|
||||||
|
modelCube_normal,
|
||||||
|
0,
|
||||||
|
modelCube_color,
|
||||||
|
12
|
||||||
|
};
|
||||||
|
|
||||||
|
SVECTOR modelCube1_mesh[] = {
|
||||||
|
{ -128,128,128 },
|
||||||
|
{ 128,128,128 },
|
||||||
|
{ 128,128,-128 },
|
||||||
|
{ -128,128,-128 },
|
||||||
|
{ -128,-128,128 },
|
||||||
|
{ 128,-128,128 },
|
||||||
|
{ 128,-128,-128 },
|
||||||
|
{ -128,-128,-128 }
|
||||||
|
};
|
||||||
|
|
||||||
|
SVECTOR modelCube1_normal[] = {
|
||||||
|
2365,-2365,-2365, 0,
|
||||||
|
-2365,-2365,-2365, 0,
|
||||||
|
-2365,-2365,2365, 0,
|
||||||
|
2365,-2365,2365, 0,
|
||||||
|
2365,2365,-2365, 0,
|
||||||
|
-2365,2365,-2365, 0,
|
||||||
|
-2365,2365,2365, 0,
|
||||||
|
2365,2365,2365, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
CVECTOR modelCube1_color[] = {
|
||||||
|
255,237,0, 0,
|
||||||
|
255,235,0, 0,
|
||||||
|
255,236,0, 0,
|
||||||
|
255,2,0, 0,
|
||||||
|
254,3,0, 0,
|
||||||
|
255,8,0, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
5,16,250, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
4,251,25, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
255,237,0, 0,
|
||||||
|
255,237,0, 0,
|
||||||
|
255,235,0, 0,
|
||||||
|
255,2,0, 0,
|
||||||
|
255,6,2, 0,
|
||||||
|
254,3,0, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
232,21,232, 0,
|
||||||
|
229,0,255, 0,
|
||||||
|
5,16,250, 0,
|
||||||
|
2,13,253, 0,
|
||||||
|
0,12,255, 0,
|
||||||
|
4,251,25, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,255,26, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0,
|
||||||
|
0,248,255, 0
|
||||||
|
};
|
||||||
|
|
||||||
|
int modelCube1_index[] = {
|
||||||
|
0,2,3,
|
||||||
|
7,5,4,
|
||||||
|
4,1,0,
|
||||||
|
5,2,1,
|
||||||
|
2,7,3,
|
||||||
|
0,7,4,
|
||||||
|
0,1,2,
|
||||||
|
7,6,5,
|
||||||
|
4,5,1,
|
||||||
|
5,6,2,
|
||||||
|
2,6,7,
|
||||||
|
0,3,7
|
||||||
|
};
|
||||||
|
|
||||||
|
TMESH modelCube1 = {
|
||||||
|
modelCube1_mesh,
|
||||||
|
modelCube1_normal,
|
||||||
|
0,
|
||||||
|
modelCube1_color,
|
||||||
|
12
|
||||||
|
};
|
57
OVL/hello_light/hello_light.c
Normal file
57
OVL/hello_light/hello_light.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
DISPENV disp[2];
|
||||||
|
DRAWENV draw[2];
|
||||||
|
u_long ot[2][OTLEN];
|
||||||
|
char primbuff[2][32768];
|
||||||
|
char * nextpri = primbuff[0];
|
||||||
|
uint8_t db = 0;
|
||||||
|
CVECTOR BGcolor = { 40, 120, 168 };
|
||||||
|
|
||||||
|
// Prototypes
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
// Reset the GPU before doing anything and the controller
|
||||||
|
PadInit(0);
|
||||||
|
ResetGraph(0);
|
||||||
|
// Initialize and setup the GTE
|
||||||
|
InitGeom();
|
||||||
|
SetGeomOffset(CENTERX, CENTERY); // x, y offset
|
||||||
|
SetGeomScreen(CENTERX); // Distance between eye and screen
|
||||||
|
// Set the display and draw environments
|
||||||
|
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);
|
||||||
|
setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
draw[0].isbg = 1;
|
||||||
|
draw[1].isbg = 1;
|
||||||
|
PutDispEnv(&disp[db]);
|
||||||
|
PutDrawEnv(&draw[db]);
|
||||||
|
// Init font system
|
||||||
|
FntLoad(960, 0);
|
||||||
|
FntOpen(16, 16, 196, 64, 0, 256);
|
||||||
|
}
|
||||||
|
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_light.c"
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
ovl_main_light();
|
||||||
|
}
|
201
OVL/hello_light/hello_ovl_light.c
Normal file
201
OVL/hello_light/hello_ovl_light.c
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
// Sample vector model
|
||||||
|
#include "cube.c"
|
||||||
|
|
||||||
|
long t, p, OTz, Flag;
|
||||||
|
// Lighting
|
||||||
|
CVECTOR BGc = {150, 50, 75, 0};
|
||||||
|
VECTOR BKc = {128, 128, 128, 0};
|
||||||
|
SVECTOR lgtang = {0, 0, 0};
|
||||||
|
MATRIX rotlgt, rotcube, light;
|
||||||
|
MATRIX lgtmat = {
|
||||||
|
// X Y Z
|
||||||
|
-ONE, -ONE, ONE, // Lightsource 1 : here, the light source is at the Bottom-Left of the screen, and points into the screen.
|
||||||
|
0, 0, 0, // Lightsource 2
|
||||||
|
0, 0, 0, // Lightsource 3
|
||||||
|
};
|
||||||
|
// Local Color Matrix
|
||||||
|
MATRIX cmat = {
|
||||||
|
// L1 L2 L3
|
||||||
|
4096, 0, 0, // R
|
||||||
|
4096, 0, 0, // G
|
||||||
|
4096, 0, 0 // B
|
||||||
|
};
|
||||||
|
|
||||||
|
static void setLightEnv()
|
||||||
|
{
|
||||||
|
// Set light env
|
||||||
|
// Set far color
|
||||||
|
SetFarColor( BGc.r, BGc.g, BGc.b );
|
||||||
|
// Set Ambient color
|
||||||
|
SetBackColor( BKc.vx, BKc.vy, BKc.vz );
|
||||||
|
// Set Color matrix
|
||||||
|
SetColorMatrix(&cmat);
|
||||||
|
// Set Fog settings
|
||||||
|
SetFogNearFar( 1200, 2200, SCREENXRES );
|
||||||
|
}
|
||||||
|
|
||||||
|
int ovl_main_light()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
int PadStatus;
|
||||||
|
int TPressed=0;
|
||||||
|
int AutoRotate=1;
|
||||||
|
// Rotating cube
|
||||||
|
POLY_G3 * poly;
|
||||||
|
SVECTOR Rotate={ ONE/6,ONE/6,ONE/6 }; // Rotation coordinates
|
||||||
|
VECTOR Trans={ -SCREENXRES/2, 0, CENTERX * 3, 0 }; // Translation coordinates
|
||||||
|
VECTOR Scale={ ONE/2, ONE/2, ONE/2, 0 }; // Scaling coordinates : ONE == 4096
|
||||||
|
MATRIX Matrix={0}; // Matrix data for the GTE
|
||||||
|
// Static cube
|
||||||
|
POLY_G3 * poly1; // pointer to a POLY_G4
|
||||||
|
SVECTOR Rotate1={ ONE/6, ONE/6, ONE/6, 0 }; // Rotation coordinates
|
||||||
|
VECTOR Trans1={ SCREENXRES/2, 0, CENTERX * 3, 0 }; // Translation coordinates
|
||||||
|
VECTOR Scale1={ ONE/2, ONE/2, ONE/2, 0 }; // Scaling coordinates : ONE == 4096
|
||||||
|
MATRIX Matrix1={0}; // Matrix data for the GTE
|
||||||
|
init();
|
||||||
|
setLightEnv();
|
||||||
|
// Main loop
|
||||||
|
while (1) {
|
||||||
|
i++;
|
||||||
|
// Read pad status
|
||||||
|
PadStatus = PadRead(0);
|
||||||
|
if (AutoRotate == 0) {
|
||||||
|
if (PadStatus & PADL1) Trans.vz -= 4;
|
||||||
|
if (PadStatus & PADR1) Trans.vz += 4;
|
||||||
|
if (PadStatus & PADL2) Rotate.vz -= 8;
|
||||||
|
if (PadStatus & PADR2) Rotate.vz += 8;
|
||||||
|
if (PadStatus & PADLup) Rotate.vx -= 8;
|
||||||
|
if (PadStatus & PADLdown) Rotate.vx += 8;
|
||||||
|
if (PadStatus & PADLleft) Rotate.vy -= 8;
|
||||||
|
if (PadStatus & PADLright) Rotate.vy += 8;
|
||||||
|
if (PadStatus & PADRup) Trans.vy -= 2;
|
||||||
|
if (PadStatus & PADRdown) Trans.vy += 2;
|
||||||
|
if (PadStatus & PADRleft) Trans.vx -= 2;
|
||||||
|
if (PadStatus & PADRright) Trans.vx += 2;
|
||||||
|
}
|
||||||
|
if (PadStatus & PADstart) {
|
||||||
|
if (TPressed == 0) {
|
||||||
|
AutoRotate = (AutoRotate + 1) & 1;
|
||||||
|
Rotate.vy = Rotate.vx = Rotate.vz = ONE/6;
|
||||||
|
Scale.vx = Scale.vy = Scale.vz = ONE/2;
|
||||||
|
Trans.vx = -SCREENXRES/2;
|
||||||
|
Trans.vy = 0;
|
||||||
|
Trans.vz = CENTERX * 3;
|
||||||
|
}
|
||||||
|
TPressed = 1;
|
||||||
|
} else {
|
||||||
|
TPressed = 0;
|
||||||
|
}
|
||||||
|
if (AutoRotate) {
|
||||||
|
Rotate.vy += 8; // Pan
|
||||||
|
Rotate.vx += 8; // Tilt
|
||||||
|
//~ Rotate.vz += 8; // Roll
|
||||||
|
}
|
||||||
|
// Clear the current OT
|
||||||
|
ClearOTagR(ot[db], OTLEN);
|
||||||
|
// Render the sample vector model
|
||||||
|
t=0;
|
||||||
|
// modelCube is a TMESH, len member == # vertices, but here it's # of triangle... So, for each tri * 3 vertices ...
|
||||||
|
for (int v = 0; v < (modelCube.len*3); v += 3) {
|
||||||
|
poly = (POLY_G3 *)nextpri;
|
||||||
|
// Initialize the primitive and set its color values
|
||||||
|
SetPolyG3(poly);
|
||||||
|
// Rotate, translate, and project the vectors and output the results into a primitive
|
||||||
|
// Could be replaced with one call with RotTransPers3()
|
||||||
|
OTz = RotTransPers(&modelCube_mesh[modelCube_index[t]] , (long*)&poly->x0, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCube_mesh[modelCube_index[t+2]], (long*)&poly->x1, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCube_mesh[modelCube_index[t+1]], (long*)&poly->x2, &p, &Flag);
|
||||||
|
// Find light color
|
||||||
|
// Work color vectors
|
||||||
|
CVECTOR outCol, outCol1, outCol2 = { 0,0,0,0 };
|
||||||
|
// Find local color from three normal vectors and perform depth cueing.
|
||||||
|
// Could be replaced with one call with NormalColorDpq3()
|
||||||
|
NormalColorDpq(&modelCube.n[ modelCube_index[t+0] ], &modelCube.c[v+0], p, &outCol);
|
||||||
|
NormalColorDpq(&modelCube.n[ modelCube_index[t+2] ], &modelCube.c[v+2], p, &outCol1);
|
||||||
|
NormalColorDpq(&modelCube.n[ modelCube_index[t+1] ], &modelCube.c[v+1], p, &outCol2);
|
||||||
|
// Set vertex colors
|
||||||
|
setRGB0(poly, outCol.r, outCol.g , outCol.b);
|
||||||
|
setRGB1(poly, outCol1.r, outCol1.g, outCol1.b);
|
||||||
|
setRGB2(poly, outCol2.r, outCol2.g, outCol2.b);
|
||||||
|
// Sort the primitive into the OT
|
||||||
|
OTz /= 3;
|
||||||
|
if ((OTz > 0) && (OTz < OTLEN))
|
||||||
|
AddPrim(&ot[db][OTz-2], poly);
|
||||||
|
nextpri += sizeof(POLY_G3);
|
||||||
|
t+=3;
|
||||||
|
}
|
||||||
|
// Find and apply light rotation matrix
|
||||||
|
// Find rotmat from light angles
|
||||||
|
RotMatrix_gte(&lgtang, &rotlgt);
|
||||||
|
// Find rotmat from cube angles
|
||||||
|
RotMatrix_gte(&Rotate, &rotcube);
|
||||||
|
// RotMatrix cube * RotMatrix light
|
||||||
|
MulMatrix0(&rotcube, &rotlgt, &rotlgt);
|
||||||
|
// Light Matrix * RotMatrix light
|
||||||
|
MulMatrix0(&lgtmat, &rotlgt, &light);
|
||||||
|
// Set new light matrix
|
||||||
|
SetLightMatrix(&light);
|
||||||
|
// Convert and set the matrices
|
||||||
|
// Find Rotation matrix from object's angles
|
||||||
|
RotMatrix(&Rotate, &Matrix);
|
||||||
|
// Find Scale matrix from object's angles
|
||||||
|
ScaleMatrix(&Matrix, &Scale);
|
||||||
|
// Find Translation matrix from object's angles
|
||||||
|
TransMatrix(&Matrix, &Trans);
|
||||||
|
// Set GTE's rotation matrix
|
||||||
|
SetRotMatrix(&Matrix);
|
||||||
|
// Set GTE's Translation matrix
|
||||||
|
SetTransMatrix(&Matrix);
|
||||||
|
// Draw static cube
|
||||||
|
t=0;
|
||||||
|
for (int v = 0; v < (modelCube1.len*3); v += 3) {
|
||||||
|
poly1 = (POLY_G3 *)nextpri;
|
||||||
|
SetPolyG3(poly1);
|
||||||
|
OTz = RotTransPers(&modelCube1_mesh[modelCube1_index[t]] , (long*)&poly1->x0, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCube1_mesh[modelCube1_index[t+2]], (long*)&poly1->x1, &p, &Flag);
|
||||||
|
OTz += RotTransPers(&modelCube1_mesh[modelCube1_index[t+1]], (long*)&poly1->x2, &p, &Flag);
|
||||||
|
CVECTOR outCol = { 0,0,0,0 };
|
||||||
|
CVECTOR outCol1 = { 0,0,0,0 };
|
||||||
|
CVECTOR outCol2 = { 0,0,0,0 };
|
||||||
|
NormalColorDpq(&modelCube1.n[ modelCube1_index[t+0] ], &modelCube1.c[v+0], p, &outCol);
|
||||||
|
NormalColorDpq(&modelCube1.n[ modelCube1_index[t+2] ], &modelCube1.c[v+2], p, &outCol1);
|
||||||
|
NormalColorDpq(&modelCube1.n[ modelCube1_index[t+1] ], &modelCube1.c[v+1], p, &outCol2);
|
||||||
|
setRGB0(poly1, outCol.r, outCol.g , outCol.b);
|
||||||
|
setRGB1(poly1, outCol1.r, outCol1.g, outCol1.b);
|
||||||
|
setRGB2(poly1, outCol2.r, outCol2.g, outCol2.b);
|
||||||
|
OTz /= 3;
|
||||||
|
if ((OTz > 0) && (OTz < OTLEN))
|
||||||
|
AddPrim(&ot[db][OTz-2], poly1);
|
||||||
|
nextpri += sizeof(POLY_G3);
|
||||||
|
t+=3;
|
||||||
|
}
|
||||||
|
// See l.216
|
||||||
|
RotMatrix_gte(&lgtang, &rotlgt);
|
||||||
|
RotMatrix_gte(&Rotate1, &rotcube);
|
||||||
|
MulMatrix0(&rotcube, &rotlgt, &rotlgt);
|
||||||
|
MulMatrix0(&lgtmat, &rotlgt, &light);
|
||||||
|
SetLightMatrix(&light);
|
||||||
|
// See l.227
|
||||||
|
RotMatrix(&Rotate1, &Matrix1);
|
||||||
|
ScaleMatrix(&Matrix1, &Scale1);
|
||||||
|
TransMatrix(&Matrix1, &Trans1);
|
||||||
|
SetRotMatrix(&Matrix1);
|
||||||
|
SetTransMatrix(&Matrix1);
|
||||||
|
FntPrint(0, "Hello lightsources !\n %d", i);
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
7
OVL/hello_ovl_world/Makefile
Normal file
7
OVL/hello_ovl_world/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
TARGET = hello_world
|
||||||
|
|
||||||
|
SRCS = hello_world.c \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
25
OVL/hello_ovl_world/hello_ovl_world.c
Normal file
25
OVL/hello_ovl_world/hello_ovl_world.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
int ovl_main_hello(void)
|
||||||
|
{
|
||||||
|
uint16_t i = 0;
|
||||||
|
init();
|
||||||
|
while(1)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
FntPrint(0, "Hello world ! %d\n", i);
|
||||||
|
#else
|
||||||
|
FntPrint(0, "Hello standalone ! %d\n", i);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
FntFlush(0);
|
||||||
|
display();
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
};
|
||||||
|
|
50
OVL/hello_ovl_world/hello_world.c
Normal file
50
OVL/hello_ovl_world/hello_world.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#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 };
|
||||||
|
|
||||||
|
void init(void)
|
||||||
|
{
|
||||||
|
ResetCallback();
|
||||||
|
ResetGraph(3);
|
||||||
|
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]);
|
||||||
|
db = !db;
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "hello_ovl_world.c"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
ovl_main_hello();
|
||||||
|
};
|
||||||
|
|
7
OVL/hello_pad/Makefile
Normal file
7
OVL/hello_pad/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
TARGET = hello_pad
|
||||||
|
|
||||||
|
SRCS = hello_pad.c \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
94
OVL/hello_pad/hello_ovl_pad.c
Normal file
94
OVL/hello_pad/hello_ovl_pad.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
int ovl_main_pad()
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
TILE * PADL; // Tile primitives
|
||||||
|
TILE * TRIGGERL;
|
||||||
|
TILE * PADR;
|
||||||
|
TILE * TRIGGERR;
|
||||||
|
TILE * START, * SELECT;
|
||||||
|
int pad = 0;
|
||||||
|
init();
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ClearOTagR(ot[db], OTLEN);
|
||||||
|
// D-cross
|
||||||
|
PADL = (TILE *)nextpri;
|
||||||
|
setTile(PADL);
|
||||||
|
setRGB0(PADL, 0, 0, 255);
|
||||||
|
setXY0(PADL, CENTERX - 80, CENTERY);
|
||||||
|
setWH(PADL, 24, 24);
|
||||||
|
addPrim(ot[db], PADL);
|
||||||
|
nextpri += sizeof(TILE);
|
||||||
|
// L1+L2
|
||||||
|
TRIGGERL = (TILE *)nextpri;
|
||||||
|
setTile(TRIGGERL);
|
||||||
|
setRGB0(TRIGGERL, 255, 0, 0);
|
||||||
|
setXY0(TRIGGERL, CENTERX - 80, CENTERY - 80);
|
||||||
|
setWH(TRIGGERL, 24, 24);
|
||||||
|
addPrim(ot[db], TRIGGERL);
|
||||||
|
nextpri += sizeof(TILE);
|
||||||
|
// /\, X, O, []
|
||||||
|
PADR = (TILE *)nextpri;
|
||||||
|
setTile(PADR);
|
||||||
|
setRGB0(PADR, 0, 255, 0);
|
||||||
|
setXY0(PADR, CENTERX + 50, CENTERY);
|
||||||
|
setWH(PADR, 24, 24);
|
||||||
|
addPrim(ot[db], PADR);
|
||||||
|
nextpri += sizeof(TILE);
|
||||||
|
// R1+R2
|
||||||
|
TRIGGERR = (TILE *)nextpri;
|
||||||
|
setTile(TRIGGERR);
|
||||||
|
setRGB0(TRIGGERR, 255, 0, 255);
|
||||||
|
setXY0(TRIGGERR, CENTERX + 50, CENTERY -80);
|
||||||
|
setWH(TRIGGERR, 24, 24);
|
||||||
|
addPrim(ot[db], TRIGGERR);
|
||||||
|
nextpri += sizeof(TILE);
|
||||||
|
// START + SELECT
|
||||||
|
START = (TILE *)nextpri;
|
||||||
|
setTile(START);
|
||||||
|
setRGB0(START, 240, 240, 240);
|
||||||
|
setXY0(START, CENTERX - 16, CENTERY - 36);
|
||||||
|
setWH(START, 24, 24);
|
||||||
|
addPrim(ot[db], START);
|
||||||
|
nextpri += sizeof(TILE);
|
||||||
|
// Pad stuff
|
||||||
|
pad = PadRead(0); // Read pads input. id is unused, always 0.
|
||||||
|
// PadRead() returns a 32 bit value, where input from pad 1 is stored in the low 2 bytes and input from pad 2 is stored in the high 2 bytes. (https://matiaslavik.wordpress.com/2015/02/13/diving-into-psx-development/)
|
||||||
|
// D-pad
|
||||||
|
if(pad & PADLup) {PADL->y0 = CENTERY - 16;} // 🡩 // To access pad 2, use ( pad >> 16 & PADLup)...
|
||||||
|
if(pad & PADLdown) {PADL->y0 = CENTERY + 16;} // 🡫
|
||||||
|
if(pad & PADLright){PADL->x0 = CENTERX - 64;} // 🡪
|
||||||
|
if(pad & PADLleft) {PADL->x0 = CENTERX - 96;} // 🡨
|
||||||
|
// Buttons
|
||||||
|
if(pad & PADRup) {PADR->y0 = CENTERY - 16;} // △
|
||||||
|
if(pad & PADRdown) {PADR->y0 = CENTERY + 16;} // ╳
|
||||||
|
if(pad & PADRright){PADR->x0 = CENTERX + 66;} // ⭘
|
||||||
|
if(pad & PADRleft) {PADR->x0 = CENTERX + 34;} // ⬜
|
||||||
|
// Shoulder buttons
|
||||||
|
if(pad & PADL1){TRIGGERL->y0 = CENTERY - 64;} // L1
|
||||||
|
if(pad & PADL2){TRIGGERL->y0 = CENTERY - 96;} // L2
|
||||||
|
if(pad & PADR1){TRIGGERR->y0 = CENTERY - 64;} // R1
|
||||||
|
if(pad & PADR2){TRIGGERR->y0 = CENTERY - 96;} // R2
|
||||||
|
// Start & Select
|
||||||
|
if(pad & PADstart){START->w = 32; START->h = 32;START->x0 -= 4;START->y0 -= 4;} // START
|
||||||
|
if(pad & PADselect){START->r0 = 0;} // SELECT
|
||||||
|
FntPrint(0, "Hello Pad! %d", i);
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
50
OVL/hello_pad/hello_pad.c
Normal file
50
OVL/hello_pad/hello_pad.c
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
DISPENV disp[2];
|
||||||
|
DRAWENV draw[2];
|
||||||
|
u_long ot[2][OTLEN];
|
||||||
|
char primbuff[2][32768];
|
||||||
|
char *nextpri = primbuff[0];
|
||||||
|
uint8_t db = 0;
|
||||||
|
CVECTOR BGcolor = { 140, 160, 40 };
|
||||||
|
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
setRGB0(&draw[0], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
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_pad.c"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
ovl_main_pad();
|
||||||
|
}
|
7
OVL/hello_poly/Makefile
Normal file
7
OVL/hello_poly/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
TARGET = hello_poly
|
||||||
|
|
||||||
|
SRCS = hello_poly.c \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
71
OVL/hello_poly/hello_ovl_poly.c
Normal file
71
OVL/hello_poly/hello_ovl_poly.c
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
int ovl_main_poly(void)
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
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
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
FntPrint(0, "Hello Poly ! %d", i);
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
57
OVL/hello_poly/hello_poly.c
Normal file
57
OVL/hello_poly/hello_poly.c
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#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, 127, 60 };
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
10
OVL/hello_sprt/Makefile
Normal file
10
OVL/hello_sprt/Makefile
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
TARGET = hello_sprt
|
||||||
|
|
||||||
|
SRCS = hello_sprt.c \
|
||||||
|
TIM/TIM16.tim \
|
||||||
|
TIM/TIM8.tim \
|
||||||
|
TIM/TIM4.tim \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
BIN
OVL/hello_sprt/TIM/TIM16.tim
Normal file
BIN
OVL/hello_sprt/TIM/TIM16.tim
Normal file
Binary file not shown.
BIN
OVL/hello_sprt/TIM/TIM4.tim
Normal file
BIN
OVL/hello_sprt/TIM/TIM4.tim
Normal file
Binary file not shown.
BIN
OVL/hello_sprt/TIM/TIM8.tim
Normal file
BIN
OVL/hello_sprt/TIM/TIM8.tim
Normal file
Binary file not shown.
112
OVL/hello_sprt/hello_ovl_sprt.c
Normal file
112
OVL/hello_sprt/hello_ovl_sprt.c
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
#define DBG_FNTX 36
|
||||||
|
#define DBG_FNTY 168
|
||||||
|
// Embedded TIMs
|
||||||
|
#ifdef STANDALONE
|
||||||
|
extern unsigned long _binary_TIM_TIM16_tim_start[];
|
||||||
|
extern unsigned long _binary_TIM_TIM8_tim_start[];
|
||||||
|
extern unsigned long _binary_TIM_TIM4_tim_start[];
|
||||||
|
#else
|
||||||
|
extern unsigned long _binary_OVL_hello_sprt_TIM_TIM16_tim_start[];
|
||||||
|
extern unsigned long _binary_OVL_hello_sprt_TIM_TIM8_tim_start[];
|
||||||
|
extern unsigned long _binary_OVL_hello_sprt_TIM_TIM4_tim_start[];
|
||||||
|
#endif
|
||||||
|
TIM_IMAGE TIM_16;
|
||||||
|
TIM_IMAGE TIM_8;
|
||||||
|
TIM_IMAGE TIM_4;
|
||||||
|
|
||||||
|
int ovl_main_sprt(void)
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
SPRT * sprt_16b; // Define 3 pointers to SPRT struct
|
||||||
|
SPRT * sprt_8b;
|
||||||
|
SPRT * sprt_4b;
|
||||||
|
DR_TPAGE * tpage_16b; // Define 3 pointers to DR_TPAGE struct. We need three because our images are on three
|
||||||
|
DR_TPAGE * tpage_8b; // different texture pages.
|
||||||
|
DR_TPAGE * tpage_4b;
|
||||||
|
init();
|
||||||
|
#ifdef STANDALONE
|
||||||
|
LoadTexture(_binary_TIM_TIM16_tim_start, &TIM_16); // Load everything to vram
|
||||||
|
LoadTexture(_binary_TIM_TIM8_tim_start, &TIM_8);
|
||||||
|
LoadTexture(_binary_TIM_TIM4_tim_start, &TIM_4);
|
||||||
|
#else
|
||||||
|
LoadTexture(_binary_OVL_hello_sprt_TIM_TIM16_tim_start, &TIM_16); // Load everything to vram
|
||||||
|
LoadTexture(_binary_OVL_hello_sprt_TIM_TIM8_tim_start, &TIM_8);
|
||||||
|
LoadTexture(_binary_OVL_hello_sprt_TIM_TIM4_tim_start, &TIM_4);
|
||||||
|
#endif
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
ClearOTagR(ot[db], OTLEN);
|
||||||
|
// Loading a 16 bit TIM
|
||||||
|
sprt_16b = (SPRT *)nextpri; // Cast whats at nexpri as a SPRT named sprt_16b
|
||||||
|
setSprt(sprt_16b); // Initialize the SPRT struct
|
||||||
|
setRGB0(sprt_16b, 128, 128, 128); // Set RGB color. 128,128,128 is neutral. You can color the image by adjusting these values
|
||||||
|
setXY0(sprt_16b, 28, MARGINY); // Set sprite position
|
||||||
|
setWH(sprt_16b, 64, 128 ); // Set sprite width and height
|
||||||
|
addPrim(ot[db][OTLEN-2], sprt_16b); // add the sprite primitive to the ordering table
|
||||||
|
nextpri += sizeof(SPRT); // increment nextpri so that it points just after sprt_16b in the primitive buffer
|
||||||
|
// Set Texture page for the 16bit tim : 768, 0 - No CLUT
|
||||||
|
// Note : You need to use setDrawTPage each time you want to use a texture that's on a different texture page
|
||||||
|
tpage_16b = (DR_TPAGE*)nextpri;
|
||||||
|
setDrawTPage(tpage_16b, 0, 1, // Set the Texture Page the texture we want resides on.
|
||||||
|
getTPage(TIM_16.mode&0x3, 0, // Here we are using bitmasking to deduce the picture mode : &0x3
|
||||||
|
TIM_16.prect->x, TIM_16.prect->y)); // In binary, 3 is 11, so we only keep the first two bits
|
||||||
|
// Values can be 00 (0), 01 (1), 10(2), respectively, 4bpp, 8bpp, 15bpp, 24bpp. See Fileformat47.pdf, p.180
|
||||||
|
// Similarly, we could use bitmasking to deduce if there is a CLUT by bitmasking the 4th bit : if(TIM_IMAGE.mode & 0x8) LoadImage... :
|
||||||
|
addPrim(ot[db][OTLEN-2], tpage_16b); // add the sprite primitive to the ordering table
|
||||||
|
nextpri += sizeof(DR_TPAGE); // Advance next primitive address
|
||||||
|
// Loading a 8 bit TIM
|
||||||
|
sprt_8b = (SPRT *)nextpri;
|
||||||
|
setSprt(sprt_8b);
|
||||||
|
setRGB0(sprt_8b, 128, 128, 128);
|
||||||
|
setXY0(sprt_8b, sprt_16b->x0 + sprt_16b->w + 32, MARGINY);
|
||||||
|
setWH(sprt_8b, 64, 128 );
|
||||||
|
setClut(sprt_8b, TIM_8.crect->x, TIM_8.crect->y); // Only difference here is we set the CLUT to the position of the VRAM we loaded the palette earlier (see LoadTexture())
|
||||||
|
addPrim(ot[db][OTLEN-2], sprt_8b);
|
||||||
|
nextpri += sizeof(SPRT);
|
||||||
|
// Set Texture page for the 8bit tim : 512, 256 - CLUT is at 0, 480
|
||||||
|
tpage_8b = (DR_TPAGE*)nextpri;
|
||||||
|
setDrawTPage(tpage_8b, 0, 1,
|
||||||
|
getTPage(TIM_8.mode&0x3, 0,
|
||||||
|
TIM_8.prect->x, TIM_8.prect->y));
|
||||||
|
addPrim(ot[db][OTLEN-2], tpage_8b);
|
||||||
|
nextpri += sizeof(DR_TPAGE);
|
||||||
|
// Loading a 4 bit TIM
|
||||||
|
sprt_4b = (SPRT *)nextpri;
|
||||||
|
setSprt(sprt_4b);
|
||||||
|
setRGB0(sprt_4b, 128, 128, 128);
|
||||||
|
setXY0(sprt_4b, sprt_8b->x0 + sprt_8b->w + 32, MARGINY);
|
||||||
|
setWH(sprt_4b, 64, 128 );
|
||||||
|
setClut(sprt_4b, TIM_4.crect->x, TIM_4.crect->y);
|
||||||
|
addPrim(ot[db][OTLEN-2], sprt_4b);
|
||||||
|
nextpri += sizeof(SPRT);
|
||||||
|
// Set Texture page for the 4bit tim : 512, 256 - CLUT is at 0, 480
|
||||||
|
tpage_4b = (DR_TPAGE*)nextpri;
|
||||||
|
setDrawTPage(tpage_4b, 0, 1,
|
||||||
|
getTPage(TIM_4.mode&0x3, 0,
|
||||||
|
TIM_4.prect->x, TIM_4.prect->y));
|
||||||
|
addPrim(ot[db][OTLEN-2], tpage_4b);
|
||||||
|
nextpri += sizeof(DR_TPAGE);
|
||||||
|
|
||||||
|
FntPrint(0, "16 Bit! ");
|
||||||
|
FntPrint(0, "8 Bit! ");
|
||||||
|
FntPrint(0, "4 Bit!\n\n");
|
||||||
|
FntPrint(0, "Check VRAM in emu to see the dif");
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
59
OVL/hello_sprt/hello_sprt.c
Normal file
59
OVL/hello_sprt/hello_sprt.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
DISPENV disp[2];
|
||||||
|
DRAWENV draw[2];
|
||||||
|
u_long ot[2][OTLEN];
|
||||||
|
char primbuff[2][32768];
|
||||||
|
char * nextpri = primbuff[0];
|
||||||
|
uint8_t db = 0;
|
||||||
|
CVECTOR BGcolor = { 255, 108, 0 };
|
||||||
|
|
||||||
|
void LoadTexture(u_long * tim, TIM_IMAGE * tparam){ // This part is from Lameguy64's tutorial series : lameguy64.net/svn/pstutorials/chapter1/3-textures.html login/pw: annoyingmous
|
||||||
|
OpenTIM(tim); // Open the tim binary data, feed it the address of the data in memory
|
||||||
|
ReadTIM(tparam); // This read the header of the TIM data and sets the corresponding members of the TIM_IMAGE structure
|
||||||
|
LoadImage(tparam->prect, tparam->paddr); // Transfer the data from memory to VRAM at position prect.x, prect.y
|
||||||
|
DrawSync(0); // Wait for the drawing to end
|
||||||
|
if (tparam->mode & 0x8){ // check 4th bit // If 4th bit == 1, TIM has a CLUT
|
||||||
|
LoadImage(tparam->crect, tparam->caddr); // Load it to VRAM at position crect.x, crect.y
|
||||||
|
DrawSync(0); // Wait for drawing to end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
setRGB0(&draw[1], BGcolor.r, BGcolor.g, BGcolor.b);
|
||||||
|
draw[0].isbg = 1;
|
||||||
|
draw[1].isbg = 1;
|
||||||
|
PutDispEnv(&disp[db]);
|
||||||
|
PutDrawEnv(&draw[db]);
|
||||||
|
FntLoad(960, 0);
|
||||||
|
FntOpen(36, 168, 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_sprt.c"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
ovl_main_sprt();
|
||||||
|
}
|
7
OVL/hello_tile/Makefile
Normal file
7
OVL/hello_tile/Makefile
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
TARGET = hello_tile
|
||||||
|
|
||||||
|
SRCS = hello_tile.c \
|
||||||
|
|
||||||
|
CPPFLAGS+=-DSTANDALONE
|
||||||
|
|
||||||
|
include ../../common.mk
|
70
OVL/hello_tile/hello_ovl_tile.c
Normal file
70
OVL/hello_tile/hello_ovl_tile.c
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#include "../common.h"
|
||||||
|
|
||||||
|
int ovl_main_tile(void)
|
||||||
|
{
|
||||||
|
#ifndef STANDALONE
|
||||||
|
useOT = 1;
|
||||||
|
#endif
|
||||||
|
uint16_t i = 0;
|
||||||
|
TILE * blue_tile;
|
||||||
|
TILE * pink_tile;
|
||||||
|
// This one is added at a different OT index
|
||||||
|
TILE * yellow_tile;
|
||||||
|
init();
|
||||||
|
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);
|
||||||
|
|
||||||
|
i++;
|
||||||
|
|
||||||
|
FntPrint(0, "Hello tile ! %d\n", i);
|
||||||
|
FntFlush(0);
|
||||||
|
#ifndef STANDALONE
|
||||||
|
if (i == timeout){
|
||||||
|
useOT = 0;
|
||||||
|
next_overlay = MOTHERSHIP;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
display();
|
||||||
|
|
||||||
|
}
|
||||||
|
return next_overlay;
|
||||||
|
}
|
52
OVL/hello_tile/hello_tile.c
Normal file
52
OVL/hello_tile/hello_tile.c
Normal file
@ -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();
|
||||||
|
};
|
BIN
STR/menu1.str
Normal file
BIN
STR/menu1.str
Normal file
Binary file not shown.
BIN
VAG/selectd.wav
BIN
VAG/selectd.wav
Binary file not shown.
BIN
VAG/switchs.wav
BIN
VAG/switchs.wav
Binary file not shown.
Loading…
Reference in New Issue
Block a user