Files
V2TMUMemTester/Test_Common.c

85 lines
2.4 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/>.
*/
#define _BSD_SOURCE 1
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "cvg.h"
#include <glide.h>
#include "sst1init.h"
#include "fxpci.h"
#include "Draw.h"
#include "Test_Common.h"
#define _DEF_PREHEAT_TIME_S 5
#define _DEF_PREHEAT_NB_PIXEL_ROW 256
#define _DEF_PREHEAT_NB_PIXEL_COL 256
void
HeatMemAndTMU( sst1DeviceInfoStruct * const devInfo,
FxU32 * const sst,
SstRegs * const sstregs,
const char ucNumTMU,
const FxU32 mem)
{
/* set downstream TMUs to passthrough */
for (int i=0; i<ucNumTMU; i++)
ISET(SST_TREX(sstregs,i)->textureMode, SST_TC_PASS | SST_TCA_PASS);
/* Setting texture base address window
*/
ISET(SST_TREX(sstregs,ucNumTMU)->texBaseAddr, (mem>>3));
/* Setting texture base address (to access it from CPU).
* We wont draw anything bigger than the texture so we can just use LOD0
* regardless of the actual size of the texture. And here its the maximum
* size (=LOD0) anyway.
*/
volatile FxU32 *texRowAddr
= (ucNumTMU<<(21-2))
+ (((FxU32)0)<<(17-2)) /*LOD0*/
+ (FxU32 *)SST_TEX_ADDRESS(sst);
for(unsigned short iter_row = 0; iter_row < _DEF_PREHEAT_NB_PIXEL_ROW; iter_row++)
{
for(unsigned short iter_col = 0; iter_col < _DEF_PREHEAT_NB_PIXEL_COL; iter_col+=2)
{
ISET(texRowAddr[iter_col/2], 0x55AA);
}
/* move to next line */
texRowAddr += (1<<(9-2));
}
clock_t begin = clock();
do
{
if(((sst1InitReturnStatus(sst) & SST_FIFOLEVEL)) >= 0x20)
{
/* draw a 256x256 square */
drawSquare(sstregs, ucNumTMU, 0, 0, 256);
}
}
while(((double)(clock() - begin)/CLOCKS_PER_SEC) < _DEF_PREHEAT_TIME_S );
sst1InitIdle(sst);
}