integration on real hardware

This commit is contained in:
2026-03-09 01:10:56 +01:00
parent c54b332e8d
commit cde38d3f75
14 changed files with 1771 additions and 1109 deletions

137
Draw.c
View File

@@ -21,89 +21,72 @@
#include "Draw.h"
#define XY_ONE (1 << SST_XY_FRACBITS)
#define ST_ONE (1 << SST_ST_FRACBITS)
#define W_ONE (1 << SST_W_FRACBITS)
typedef struct _def_sPoint
static inline uint32_t f32u(const float f)
{
int16_t x;
int16_t y;
}def_sPoint;
typedef struct _def_sTriangle
{
def_sPoint vA;
def_sPoint vB;
def_sPoint vC;
int32_t s;
int32_t t;
int32_t w;
int32_t dsdx;
int32_t dtdx;
int32_t dwdx;
int32_t dsdy;
int32_t dtdy;
int32_t dwdy;
}def_sTriangle;
static inline uint32_t v2_triangle_cmd_from_abc(const def_sPoint A,
const def_sPoint B,
const def_sPoint C)
{
const int32_t abx = (int32_t)B.x - (int32_t)A.x;
const int32_t aby = (int32_t)B.y - (int32_t)A.y;
const int32_t acx = (int32_t)C.x - (int32_t)A.x;
const int32_t acy = (int32_t)C.y - (int32_t)A.y;
const int64_t s = (int64_t )abx * (int64_t )acy - (int64_t )aby * (int64_t )acx;
return (s < 0) ? 0x80000000u : 0u;
}
static void inline drawTriangle(const SstRegs * const sst, const def_sTriangle * const sTri)
{
ISET(sst->vA.x, sTri->vA.x*XY_ONE); ISET(sst->vA.y, sTri->vA.y*XY_ONE);
ISET(sst->vB.x, sTri->vB.x*XY_ONE); ISET(sst->vB.y, sTri->vB.y*XY_ONE);
ISET(sst->vC.x, sTri->vC.x*XY_ONE); ISET(sst->vC.y, sTri->vC.y*XY_ONE);
ISET(sst->s, sTri->s*ST_ONE);
ISET(sst->t, sTri->t*ST_ONE);
ISET(sst->w, sTri->w*W_ONE);
ISET(sst->dsdx, sTri->dsdx*ST_ONE);
ISET(sst->dtdx, sTri->dtdx*ST_ONE);
ISET(sst->dwdx, sTri->dwdx*W_ONE);
ISET(sst->dsdy, sTri->dsdy*ST_ONE);
ISET(sst->dtdy, sTri->dtdy*ST_ONE);
ISET(sst->dwdy, sTri->dwdy*W_ONE);
ISET(sst->triangleCMD,v2_triangle_cmd_from_abc(sTri->vA, sTri->vB, sTri->vC));
const union { float f; uint32_t u;} v = {.f = f};
return v.u;
}
void
drawSquare( const SstRegs * const sst,
drawRect( const SstRegs * const sst,
const int16_t x,
const int16_t y,
const int16_t tSize)
const int16_t tSizeX,
const int16_t tSizeY)
{
const def_sTriangle tri1 = {
.vA = {.x= (x+0), .y = (y+0)},
.vB = {.x= (x+tSize), .y = (y+0)},
.vC = {.x= (x+0), .y = (y+tSize)},
.s = 0,
.t = 0,
.w = 1,
.dsdx = 1, .dtdx = 0,
.dwdx = 0,
.dsdy = 0, .dtdy = 1,
.dwdy = 0};
drawTriangle(sst, &tri1);
ISET(sst->sARGB,0xFFFFFFFF);
ISET(sst->sOowfbi,f32u(1.0f));
ISET(sst->sVx, f32u((float)x));
ISET(sst->sVy, f32u((float)y));
ISET(sst->sSow0,f32u(0.0f));
ISET(sst->sTow0,f32u(0.0f));
/* 0b10 0000 (Update only S0/T0), doc page 76 */
ISET(sst->sSetupMode, 0x0020);
ISET(sst->sBeginTriCMD, 1);
const def_sTriangle tri2 = {
.vA = {.x= (x+0), .y = (y+tSize)},
.vB = {.x= (x+tSize), .y = (y+0)},
.vC = {.x= (x+tSize), .y = (y+tSize)},
.s = 0,
.t = tSize,
.w = 1,
.dsdx = 1, .dtdx = 0,
.dwdx = 0,
.dsdy = 0, .dtdy = 1,
.dwdy = 0 };
drawTriangle(sst, &tri2);
ISET(sst->sVx, f32u((float)(x+tSizeX)));
ISET(sst->sVy, f32u((float)y));
ISET(sst->sSow0,f32u((float)tSizeX));
ISET(sst->sTow0,f32u(0.0f));
ISET(sst->sDrawTriCMD, 1);
ISET(sst->sVx, f32u((float)x));
ISET(sst->sVy, f32u((float)y+tSizeY));
ISET(sst->sSow0,f32u(0.0f));
ISET(sst->sTow0,f32u((float)tSizeY));
ISET(sst->sDrawTriCMD, 1);
ISET(sst->sVx, f32u((float)x+tSizeX));
ISET(sst->sVy, f32u((float)y+tSizeY));
ISET(sst->sSow0,f32u((float)tSizeX));
ISET(sst->sTow0,f32u((float)tSizeY));
ISET(sst->sDrawTriCMD, 1);
ISET(sst->nopCMD, 0x1);
}
void
clearScreen( const SstRegs * const sst,
const uint32_t u32Color,
const int16_t u16SizeX,
const int16_t u16SizeY)
{
ISET(sst->clipLeftRight, u16SizeX);
ISET(sst->clipBottomTop, u16SizeY);
ISET(sst->zaColor, u32Color);
//ISET(sst->zaColor, 0x0000);
const uint32_t fbz_saved = IGET(sst->fbzMode);
ISET(sst->c1,u32Color);
ISET(sst->c0,0x0);
ISET(sst->zaColor,0x0);
ISET(sst->fbzMode, SST_RGBWRMASK | SST_ZAWRMASK);
ISET(sst->fastfillCMD, 0);
ISET(sst->nopCMD, 0x1);
ISET(sst->fbzMode, fbz_saved);
}