1
0
mirror of https://github.com/blawar/GLideN64.git synced 2024-06-22 20:39:35 +00:00

expand tmem

This commit is contained in:
Blake Warner 2022-03-29 17:42:02 -04:00
parent 0b4909721c
commit 746be9cfa1
5 changed files with 57 additions and 54 deletions

View File

@ -5,7 +5,7 @@ u8* HEADER;
u8 *DMEM;
u8 *IMEM;
#endif
u64 TMEM[512];
u64 TMEM[TMEM_SIZE];
#ifndef NATIVE
u8 *RDRAM;
#endif

View File

@ -3,13 +3,9 @@
#include "Types.h"
/*
#ifdef NATIVE
#define RDRAM_PTR(a) ((u8*)a)
#else
#define RDRAM_PTR(a) RDRAM[a]
#endif
*/
#define TMEM_SIZE (1024 * 1024 * 4)
#define LOAD_BLOCK32_MAX (0x0400 * 16)
#define LOAD_BLOCK32_MASK ((0x0400 * 16) - 1)
#define MI_INTR_DP 0x20 // Bit 5: DP intr
@ -59,7 +55,7 @@ extern u8 *DMEM;
extern u8 *IMEM;
extern u8 *RDRAM;
#endif
extern u64 TMEM[512];
extern u64 TMEM[TMEM_SIZE];
extern word RDRAMSize;
extern bool ConfigOpen;

View File

@ -131,13 +131,18 @@ void RDP_SetTile( const Gwords words )
_SHIFTR( words.w1, 0, 4 ) ); // shifts
}
#define LRS_UPPER_VALUE (_SHIFTR(words.w1, 27, 5) << 12)
#define TILE_VALUE _SHIFTR(words.w1, 24, 3)
#define LRS_VALUE _SHIFTR(words.w1, 12, 12)
#define LRT_VALUE _SHIFTR(words.w1, 0, 12)
void RDP_LoadTile( const Gwords words )
{
gDPLoadTile( _SHIFTR( words.w1, 24, 3 ), // tile
gDPLoadTile( TILE_VALUE, // tile
_SHIFTR( words.w0, 12, 12 ), // uls
_SHIFTR( words.w0, 0, 12 ), // ult
_SHIFTR( words.w1, 12, 12 ), // lrs
_SHIFTR( words.w1, 0, 12 ) ); // lrt
LRS_VALUE | LRS_UPPER_VALUE, // lrs
LRT_VALUE ); // lrt
}
static u32 lbw0, lbw1;
@ -145,11 +150,11 @@ void RDP_LoadBlock( const Gwords words )
{
lbw0 = words.w0;
lbw1 = words.w1;
gDPLoadBlock( _SHIFTR( words.w1, 24, 3 ), // tile
gDPLoadBlock( TILE_VALUE, // tile
_SHIFTR( words.w0, 12, 12 ), // uls
_SHIFTR( words.w0, 0, 12 ), // ult
_SHIFTR( words.w1, 12, 12 ), // lrs
_SHIFTR( words.w1, 0, 12 ) ); // dxt
LRS_VALUE | LRS_UPPER_VALUE, // lrs
LRT_VALUE ); // dxt
}
void RDP_RepeatLastLoadBlock()
@ -159,20 +164,20 @@ void RDP_RepeatLastLoadBlock()
void RDP_SetTileSize( const Gwords words )
{
gDPSetTileSize( _SHIFTR( words.w1, 24, 3 ), // tile
gDPSetTileSize( TILE_VALUE, // tile
_SHIFTR( words.w0, 12, 12 ), // uls
_SHIFTR( words.w0, 0, 12 ), // ult
_SHIFTR( words.w1, 12, 12 ), // lrs
_SHIFTR( words.w1, 0, 12 ) ); // lrt
LRS_VALUE | LRS_UPPER_VALUE, // lrs
LRT_VALUE ); // lrt
}
void RDP_LoadTLUT( const Gwords words )
{
gDPLoadTLUT( _SHIFTR( words.w1, 24, 3 ), // tile
gDPLoadTLUT( TILE_VALUE, // tile
_SHIFTR( words.w0, 12, 12 ), // uls
_SHIFTR( words.w0, 0, 12 ), // ult
_SHIFTR( words.w1, 12, 12 ), // lrs
_SHIFTR( words.w1, 0, 12 ) ); // lrt
LRS_VALUE | LRS_UPPER_VALUE, // lrs
LRT_VALUE ); // lrt
}
void RDP_SetOtherMode( const Gwords words )

View File

@ -251,7 +251,7 @@ u32 GetIA88_RGBA4444(u16 offset, u16 x, u16 i, u8 palette)
inline u32 Get32BitColor(u16 offset, u16 x, u16 i)
{
u32* tmem32 = reinterpret_cast<u32*>(TMEM);
return tmem32[((offset << 1) + (x ^ i)) & 0x3FF];
return tmem32[((offset << 1) + (x ^ i)) & LOAD_BLOCK32_MASK];
}
u32 GetRGBA8888_RGBA8888(u16 offset, u16 x, u16 i, u8 palette)
@ -865,8 +865,8 @@ void _calcTileSizes(u32 _t, TileSizes & _sizes, gDPTile * _pLoadTile)
pTile->masks = pTile->originalMaskS;
pTile->maskt = pTile->originalMaskT;
u32 tileWidth = ((pTile->lrs - pTile->uls) & 0x03FF) + 1;
u32 tileHeight = ((pTile->lrt - pTile->ult) & 0x03FF) + 1;
u32 tileWidth = ((pTile->lrs - pTile->uls) & LOAD_BLOCK32_MASK) + 1;
u32 tileHeight = ((pTile->lrt - pTile->ult) & LOAD_BLOCK32_MASK) + 1;
const u32 tMemMask = gDP.otherMode.textureLUT == G_TT_NONE ? 0x1FF : 0xFF;
gDPLoadTileInfo &info = gDP.loadInfo[pTile->tmem & tMemMask];
@ -1332,13 +1332,13 @@ void TextureCache::_getTextureDestData(CachedTexture& tmptex,
for (x = 0; x < tmptex.width; ++x) {
tx = min(x, clampSClamp) & maskSMask;
u32 taddr = ((tline + tx) ^ xorval) & 0x3ff;
u32 taddr = ((tline + tx) ^ xorval) & LOAD_BLOCK32_MASK;
#ifdef NATIVE
gr = tmem16[taddr];
ab = tmem16[taddr | 0x400];
ab = tmem16[taddr | LOAD_BLOCK32_MAX];
#else
gr = swapword(tmem16[taddr]);
ab = swapword(tmem16[taddr | 0x400]);
ab = swapword(tmem16[taddr | LOAD_BLOCK32_MAX]);
#endif
pDest[j++] = (ab << 16) | gr;
}

View File

@ -352,7 +352,7 @@ void gDPSetTileSize( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt )
{
gDP.tiles[tile].uls = _SHIFTR( uls, 2, 10 );
gDP.tiles[tile].ult = _SHIFTR( ult, 2, 10 );
gDP.tiles[tile].lrs = _SHIFTR( lrs, 2, 10 );
gDP.tiles[tile].lrs = _SHIFTR( lrs, 2, 15 );
gDP.tiles[tile].lrt = _SHIFTR( lrt, 2, 10 );
gDP.tiles[tile].fuls = _FIXED2FLOAT( uls, 2 );
@ -478,13 +478,13 @@ void gDPLoadTile32b(u32 uls, u32 ult, u32 lrs, u32 lrt)
xorval = (j & 1) ? 3 : 1;
for (u32 i = 0; i < width; ++i) {
c = src[addr + s + i];
ptr = ((tline + i) ^ xorval) & 0x3ff;
ptr = ((tline + i) ^ xorval) & LOAD_BLOCK32_MASK;
#ifdef NATIVE
tmem16[ptr | 0x400] = c >> 16;
tmem16[ptr | LOAD_BLOCK32_MAX] = c >> 16;
tmem16[ptr] = c & 0xffff;
#else
tmem16[ptr] = c >> 16;
tmem16[ptr | 0x400] = c & 0xffff;
tmem16[ptr | LOAD_BLOCK32_MAX] = c & 0xffff;
#endif
}
}
@ -501,8 +501,8 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt)
if (gDP.loadTile->lrs < gDP.loadTile->uls || gDP.loadTile->lrt < gDP.loadTile->ult)
return;
const u32 width = (gDP.loadTile->lrs - gDP.loadTile->uls + 1) & 0x03FF;
const u32 height = (gDP.loadTile->lrt - gDP.loadTile->ult + 1) & 0x03FF;
const u32 width = (gDP.loadTile->lrs - gDP.loadTile->uls + 1) & LOAD_BLOCK32_MASK;
const u32 height = (gDP.loadTile->lrt - gDP.loadTile->ult + 1) & LOAD_BLOCK32_MASK;
const u32 bpl = gDP.loadTile->line << 3;
u32 alignedWidth = width;
@ -572,9 +572,9 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt)
if (address + bpl > RDRAMSize)
UnswapCopyWrap(RDRAM, address, reinterpret_cast<u8*>(TMEM), tmemAddr << 3, 0xFFF, RDRAMSize - address);
else
UnswapCopyWrap(RDRAM, address, reinterpret_cast<u8*>(TMEM), tmemAddr << 3, 0xFFF, bpr);
UnswapCopyWrap(RDRAM, address, reinterpret_cast<u8*>(TMEM), tmemAddr << 3, (0x1000 * 8 - 1), bpr);
if (y & 1)
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, 0x3FF, qwpr);
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, LOAD_BLOCK32_MASK, qwpr);
address += gDP.textureImage.bpl;
if (address >= RDRAMSize)
@ -602,8 +602,10 @@ void gDPLoadBlock32(u32 uls,u32 lrs, u32 dxt)
u32 width = (lrs - uls + 1) << 2;
if (width == 4) // lr_s == 0, 1x1 texture
width = 1;
else if (width & 7)
width = (width & (~7U)) + 8;
else if(width & 7)
{
//width = (width & (~7U)) + 8;
}
if (dxt != 0) {
u32 j = 0;
@ -617,36 +619,36 @@ void gDPLoadBlock32(u32 uls,u32 lrs, u32 dxt)
t = ((j >> 11) & 1) ? 3 : 1;
if (t != oldt)
i += line;
ptr = ((tb + i) ^ t) & 0x3ff;
ptr = ((tb + i) ^ t) & LOAD_BLOCK32_MASK;
c = src[addr + i];
#ifdef NATIVE
tmem16[ptr | 0x400] = c >> 16;
tmem16[ptr | LOAD_BLOCK32_MAX] = c >> 16;
tmem16[ptr] = c & 0xffff;
ptr = ((tb + i + 1) ^ t) & 0x3ff;
ptr = ((tb + i + 1) ^ t) & LOAD_BLOCK32_MASK;
c = src[addr + i + 1];
tmem16[ptr | 0x400] = c >> 16;
tmem16[ptr | LOAD_BLOCK32_MAX] = c >> 16;
tmem16[ptr] = c & 0xffff;
#else
tmem16[ptr] = c >> 16;
tmem16[ptr | 0x400] = c & 0xffff;
ptr = ((tb + i + 1) ^ t) & 0x3ff;
tmem16[ptr | LOAD_BLOCK32_MAX] = c & 0xffff;
ptr = ((tb + i + 1) ^ t) & LOAD_BLOCK32_MASK;
c = src[addr + i + 1];
tmem16[ptr] = c >> 16;
tmem16[ptr | 0x400] = c & 0xffff;
tmem16[ptr | LOAD_BLOCK32_MAX] = c & 0xffff;
#endif
j += dxt;
}
} else {
u32 c, ptr;
for (u32 i = 0; i < width; i++) {
ptr = ((tb + i) ^ 1) & 0x3ff;
ptr = ((tb + i) ^ 1) & LOAD_BLOCK32_MASK;
c = src[addr + i];
#ifdef NATIVE
tmem16[ptr | 0x400] = c >> 16;
tmem16[ptr | LOAD_BLOCK32_MAX] = c >> 16;
tmem16[ptr] = c & 0xffff;
#else
tmem16[ptr] = c >> 16;
tmem16[ptr | 0x400] = c & 0xffff;
tmem16[ptr | LOAD_BLOCK32_MAX] = c & 0xffff;
#endif
}
}
@ -681,10 +683,10 @@ void gDPLoadBlock(u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt)
info.size = static_cast<u8>(gDP.textureImage.size);
info.loadType = LOADTYPE_BLOCK;
const u32 width = (lrs - uls + 1) & 0x0FFF;
const u32 width = (lrs - uls + 1);// & (0x1000 - 1);
u32 bytes = width << gDP.loadTile->size >> 1;
if ((bytes & 7) != 0)
bytes = (bytes & (~7U)) + 8;
//if ((bytes & 7) != 0)
// bytes = (bytes & (~7U)) + 8;
info.bytes = bytes;
word address = gDP.textureImage.address + ult * gDP.textureImage.bpl + (uls << gDP.textureImage.size >> 1);
@ -740,12 +742,12 @@ void gDPLoadBlock(u32 tile, u32 uls, u32 ult, u32 lrs, u32 dxt)
goto end_dxt_test;
dxtCounter += dxt;
} while ((dxtCounter & 0x800) != 0);
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, 0x3FF, line);
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, LOAD_BLOCK32_MASK, line);
tmemAddr += line;
line = 0;
}
end_dxt_test:
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, 0x3FF, line);
DWordInterleaveWrap(reinterpret_cast<u32*>(TMEM), tmemAddr << 1, LOAD_BLOCK32_MASK, line);
}
}
@ -769,10 +771,10 @@ void gDPLoadTLUT( u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt )
while (i < count) {
for (u16 j = 0; (j < 16) && (i < count); ++j, ++i) {
#ifdef NATIVE
//dest[(destIdx | 0x0400) & 0x07FF] = *reinterpret_cast<u16*>(RDRAM + (address ^ 2));
//dest[(destIdx | LOAD_BLOCK32_MAX) & 0x07FF] = *reinterpret_cast<u16*>(RDRAM + (address ^ 2));
dest[(destIdx) & 0x07FF] = *reinterpret_cast<u16*>(RDRAM + (address));
#else
dest[(destIdx | 0x0400) & 0x07FF] = swapword(*reinterpret_cast<u16*>(RDRAM + (address ^ 2)));
dest[(destIdx | LOAD_BLOCK32_MAX) & 0x07FF] = swapword(*reinterpret_cast<u16*>(RDRAM + (address ^ 2)));
#endif
address += 2;
destIdx += 4;