Skip to content

Commit

Permalink
Debugger: SNES - Fixed palette display for mode 0 layers in tilemap v…
Browse files Browse the repository at this point in the history
…iewer
  • Loading branch information
SourMesen committed Apr 27, 2024
1 parent 8cbaf3a commit d9f1d48
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions Core/Debugger/PpuTools.h
Expand Up @@ -151,6 +151,7 @@ struct DebugTilemapTileInfo

int32_t PaletteIndex = -1;
int32_t PaletteAddress = -1;
int32_t BasePaletteIndex = -1;

int32_t AttributeAddress = -1;
int16_t AttributeData = -1;
Expand Down
3 changes: 2 additions & 1 deletion Core/GBA/Debugger/GbaPpuTools.cpp
Expand Up @@ -354,7 +354,7 @@ DebugTilemapTileInfo GbaPpuTools::GetTilemapTileInfo(uint32_t x, uint32_t y, uin
result.TileAddress = tileStart;
result.PixelData = pixelData;
result.PaletteIndex = paletteIndex;
result.PaletteAddress = paletteIndex << 4;
result.PaletteAddress = paletteIndex << 5;
result.HorizontalMirroring = hMirror;
result.VerticalMirroring = vMirror;
return result;
Expand Down Expand Up @@ -460,6 +460,7 @@ void GbaPpuTools::GetSpriteInfo(DebugSpriteInfo& sprite, uint32_t* spritePreview
sprite.TileIndex = oam[addr + 4] | ((oam[addr + 5] & 0x03) << 8);
sprite.Priority = (DebugSpritePriority)((oam[addr + 5] >> 2) & 0x03);
sprite.Palette = bpp8Mode ? 0 : (oam[addr + 5] >> 4) & 0x0F;
sprite.PaletteAddress = bpp8Mode ? -1 : (sprite.Palette << 5);

static constexpr uint8_t sprSize[4][4][2] = {
{ { 8, 8 }, { 16, 8 }, { 8, 16 }, { 8, 8 } },
Expand Down
12 changes: 6 additions & 6 deletions Core/SNES/Debugger/SnesPpuTools.cpp
Expand Up @@ -464,11 +464,6 @@ DebugTilemapTileInfo SnesPpuTools::GetTilemapTileInfo(uint32_t x, uint32_t y, ui
return result;
}

uint16_t basePaletteOffset = 0;
if(state.BgMode == 0) {
basePaletteOffset = options.Layer * 32;
}

uint32_t row;
uint32_t column;

Expand Down Expand Up @@ -499,13 +494,18 @@ DebugTilemapTileInfo SnesPpuTools::GetTilemapTileInfo(uint32_t x, uint32_t y, ui
result.HorizontalMirroring = (NullableBoolean)((vram[addr + 1] & 0x40) != 0);
result.HighPriority = (NullableBoolean)((vram[addr + 1] & 0x20) != 0);
result.PaletteIndex = bpp == 8 ? 0 : (vram[addr + 1] >> 2) & 0x07;
if(state.BgMode == 0) {
result.BasePaletteIndex = result.PaletteIndex;
result.PaletteIndex += options.Layer * 8;
}
result.PaletteAddress = result.PaletteIndex * (1 << bpp);

result.TileIndex = ((vram[addr + 1] & 0x03) << 8) | vram[addr];
result.TileMapAddress = addr;

uint16_t tileStart = (layer.ChrAddress << 1) + result.TileIndex * 8 * bpp;
result.TileAddress = tileStart;

result.PaletteAddress = basePaletteOffset + (result.PaletteIndex * (1 << bpp));
}

result.Row = row;
Expand Down
6 changes: 5 additions & 1 deletion UI/Debugger/ViewModels/TilemapViewerViewModel.cs
Expand Up @@ -606,7 +606,11 @@ private void UpdateTilemapInfo()
}
}
if(tileInfo.PaletteIndex >= 0) {
entries.AddEntry("Palette index", tileInfo.PaletteIndex.ToString());
if(tileInfo.BasePaletteIndex >= 0) {
entries.AddEntry("Palette index", $"{tileInfo.BasePaletteIndex} ({tileInfo.PaletteIndex})");
} else {
entries.AddEntry("Palette index", tileInfo.PaletteIndex.ToString());
}
}
if(tileInfo.PaletteAddress >= 0) {
entries.AddEntry("Palette address", "$" + tileInfo.PaletteAddress.ToString("X2"));
Expand Down
1 change: 1 addition & 0 deletions UI/Interop/DebugApi.cs
Expand Up @@ -1097,6 +1097,7 @@ public struct DebugTilemapTileInfo

public Int32 PaletteIndex;
public Int32 PaletteAddress;
public Int32 BasePaletteIndex;

public Int32 AttributeAddress;
public Int16 AttributeData;
Expand Down

0 comments on commit d9f1d48

Please sign in to comment.