110 lines
3.0 KiB
C
110 lines
3.0 KiB
C
/* V2MemTest - A CLI Tool to test & fix Voodoo² TMU System
|
|
* Copyright (C) 2026 ChaCha
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#include "cvg.h"
|
|
#include "glide.h"
|
|
#include "sst1init.h"
|
|
|
|
#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
|
|
{
|
|
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));
|
|
}
|
|
|
|
void
|
|
drawSquare( const SstRegs * const sst,
|
|
const int16_t x,
|
|
const int16_t y,
|
|
const int16_t tSize)
|
|
{
|
|
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);
|
|
|
|
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);
|
|
}
|