/* 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 . */ #include "cvg.h" #include "glide.h" #include "sst1init.h" #include "Draw.h" static inline uint32_t f32u(const float f) { const union { float f; uint32_t u;} v = {.f = f}; return v.u; } void drawRect( const SstRegs * const sstregs, const unsigned char ucNumTMU, const int16_t x, const int16_t y, const int16_t tSizeX, const int16_t tSizeY) { ISET(sstregs->sSetupMode, 0x0020); ISET(SST_TREX(sstregs,ucNumTMU)->sARGB,0xFFFFFFFF); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sOowfbi,f32u(1.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0,f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0,f32u(0.0f)); /* 0b10 0000 (Update only S0/T0), doc page 76 */ ISET(sstregs->sBeginTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)(x+tSizeX))); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0,f32u((float)tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0,f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y+tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0,f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0,f32u((float)tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x+tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y+tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0,f32u((float)tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0,f32u((float)tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(sstregs->nopCMD, 0x1); } void drawRect2( const SstRegs * const sstregs, const unsigned char ucNumTMU, const int16_t x, const int16_t y, const int16_t tSizeX, const int16_t tSizeY) { ISET(sstregs->sSetupMode, 0x0020); //ISET(SST_TREX(sstregs,ucNumTMU)->sARGB,0xFF55AA55); ISET(SST_TREX(sstregs,ucNumTMU)->sOowfbi, f32u(1.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u(0.0f)); /* 0b10 0000 (Update only S0/T0), doc page 76 */ ISET(sstregs->sBeginTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)(x+tSizeX))); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u((float)tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y+tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u((float)tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x+tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y+tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u((float)tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u((float)tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(sstregs->nopCMD, 0x1); } void clearScreen( const SstRegs * const sstregs, const uint32_t u32Color, const int16_t u16SizeX, const int16_t u16SizeY) { ISET(sstregs->clipLeftRight, u16SizeX); ISET(sstregs->clipBottomTop, u16SizeY); ISET(sstregs->zaColor, u32Color); //ISET(sstregs->zaColor, 0x0000); const uint32_t fbz_saved = IGET(sstregs->fbzMode); ISET(sstregs->c1,u32Color); ISET(sstregs->c0,0x0); ISET(sstregs->zaColor,0x0F); ISET(sstregs->fbzMode, SST_RGBWRMASK | SST_ZAWRMASK); ISET(sstregs->fastfillCMD, 0); ISET(sstregs->nopCMD, 0x1); ISET(sstregs->fbzMode, fbz_saved); } #define XY_ONE (1<vA.x,x*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->vA.y,y*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->vB.x,(x+2)*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->vB.y,y*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->vC.x,x*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->vC.y,(y+1)*XY_ONE); ISET(SST_TREX(sstregs,ucNumTMU)->triangleCMD,0); } void drawTriangle( const SstRegs * const sstregs, const unsigned char ucNumTMU, const int16_t x, const int16_t y, const int16_t tSizeX, const int16_t tSizeY) { ISET(sstregs->sSetupMode, 0x0020); //ISET(SST_TREX(sstregs,ucNumTMU)->sARGB,0xFF55AA55); ISET(SST_TREX(sstregs,ucNumTMU)->sOowfbi, f32u(1.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u(0.0f)); /* 0b10 0000 (Update only S0/T0), doc page 76 */ ISET(sstregs->sBeginTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)(x+tSizeX))); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u((float)tSizeX)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(SST_TREX(sstregs,ucNumTMU)->sVx, f32u((float)x)); ISET(SST_TREX(sstregs,ucNumTMU)->sVy, f32u((float)y+tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sSow0, f32u(0.0f)); ISET(SST_TREX(sstregs,ucNumTMU)->sTow0, f32u((float)tSizeY)); ISET(SST_TREX(sstregs,ucNumTMU)->sDrawTriCMD, 1); ISET(sstregs->nopCMD, 0x1); }