Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Mario face looks better
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Aug 11, 2023
1 parent 8c6801f commit c838c8e
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 36 deletions.
108 changes: 73 additions & 35 deletions n64/core/n64_rdp.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -342,27 +342,29 @@ namespace hydra::N64
// Loads a tile (part of the bigger texture set by SetTextureImage) into TMEM
LoadTileCommand command;
command.full = data[0];
TileDescriptor& tile = tiles_[command.Tile];

int sl = command.SL;
int tl = command.TL;
int sh = command.SH + 1;
int th = command.TH + 1;

sh *= sizeof(uint16_t);
sl *= sizeof(uint16_t);
for (int t = tl; t < th; t++)
{
for (int s = sl; s < sh; s++)
{
uint16_t src = *reinterpret_cast<uint16_t*>(
&rdram_ptr_[texture_dram_address_latch_ +
(t * texture_width_latch_ + s) * 2]);
uint16_t* dst = reinterpret_cast<uint16_t*>(
&tmem_[tile.tmem_address + (t - tl) * tile.line_width + (s - sl) * 2]);
*dst = src;
}
}
// TileDescriptor& tile = tiles_[command.Tile];

// int sl = command.SL;
// int tl = command.TL;
// int sh = command.SH + 1;
// int th = command.TH + 1;

// sh *= sizeof(uint16_t);
// sl *= sizeof(uint16_t);
// for (int t = tl; t < th; t++)
// {
// for (int s = sl; s < sh; s++)
// {
// uint16_t src = *reinterpret_cast<uint16_t*>(
// &rdram_ptr_[texture_dram_address_latch_ +
// (t * texture_width_latch_ + s) * 2]);
// uint16_t* dst = reinterpret_cast<uint16_t*>(
// &tmem_[tile.tmem_address + (t - tl) * tile.line_width + (s - sl) *
// 2]);
// *dst = src;
// }
// }
Logger::WarnOnce("LoadTile: {}", command.full);
break;
}
case RDPCommandType::LoadBlock:
Expand All @@ -377,21 +379,48 @@ namespace hydra::N64
int DxT = command.DxT;

bool odd = false;
// 16 bits
sh *= sizeof(uint16_t);
sl *= sizeof(uint16_t);
for (int i = sl; i < sh; i += 8)

switch (texture_format_latch_)
{
uint64_t src =
*reinterpret_cast<uint64_t*>(&rdram_ptr_[texture_dram_address_latch_ + i]);
if (odd)
case Format::RGBA:
{
src = (src >> 32) | (src << 32);
switch (texture_pixel_size_latch_)
{
case 16:
{
sh *= sizeof(uint16_t);
sl *= sizeof(uint16_t);
for (int i = sl; i < sh; i += 8)
{
uint64_t src = *reinterpret_cast<uint64_t*>(
&rdram_ptr_[texture_dram_address_latch_ + i]);
if (odd)
{
src = (src >> 32) | (src << 32);
}
uint64_t* dst =
reinterpret_cast<uint64_t*>(&tmem_[tile.tmem_address + i]);
*dst = hydra::bswap64(src);
tl += DxT;
odd = (tl >> 11) & 1;
}
break;
}
default:
{
Logger::WarnOnce("Using unknown RGBA size for LoadBlock: {}\n",
texture_pixel_size_latch_);
break;
}
}
break;
}
default:
{
Logger::WarnOnce("Using unknown format for LoadBlock: {}\n",
static_cast<int>(texture_format_latch_));
break;
}
uint64_t* dst = reinterpret_cast<uint64_t*>(&tmem_[tile.tmem_address + i]);
*dst = hydra::bswap64(src);
tl += DxT;
odd = (tl >> 11) & 1;
}
break;
}
Expand All @@ -410,15 +439,24 @@ namespace hydra::N64
tile.palette_index = command.Palette << 4;
break;
}
case RDPCommandType::SetTileSize:
{
SetTileSizeCommand command;
command.full = data[0];
TileDescriptor& tile = tiles_[command.Tile];
tile.s = command.SL << 3;
tile.t = command.TL << 3;
break;
}
case RDPCommandType::SetTextureImage:
{
// The gsDPSetTextureImage command sets a pointer to the location of the image.
SetTextureImageCommand command;
command.full = data[0];
texture_dram_address_latch_ = command.DRAMAddress;
texture_width_latch_ = command.width + 1;
texture_format_latch_ = command.format;
texture_pixel_size_latch_ = command.size;
texture_format_latch_ = static_cast<Format>(command.format);
texture_pixel_size_latch_ = (1 << command.size) * 4;
break;
}
case RDPCommandType::SetOtherModes:
Expand Down
3 changes: 2 additions & 1 deletion n64/core/n64_rdp.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ namespace hydra::N64
uint8_t size;
uint8_t palette_index;
uint16_t line_width;
uint16_t s, t;
};

class RDP final
Expand Down Expand Up @@ -181,7 +182,7 @@ namespace hydra::N64
uint32_t texture_dram_address_latch_;
uint32_t texture_width_latch_;
uint32_t texture_pixel_size_latch_;
uint32_t texture_format_latch_;
Format texture_format_latch_;

std::array<TileDescriptor, 8> tiles_;
std::array<uint8_t, 4096> tmem_;
Expand Down
21 changes: 21 additions & 0 deletions n64/core/n64_rdp_commands.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,27 @@ namespace hydra::N64
}
};

union SetTileSizeCommand
{
uint64_t full;

struct
{
uint64_t TH : 12;
uint64_t SH : 12;
uint64_t Tile : 3;
uint8_t : 5;
uint64_t TL : 12;
uint64_t SL : 12;
uint64_t : 8;
};

SetTileSizeCommand()
{
full = 0;
}
};

union LoadTileCommand
{
uint64_t full;
Expand Down

0 comments on commit c838c8e

Please sign in to comment.