Add DolphinCPalette, logic matched, unfortunately has instruction swaps around TLUT ops

Former-commit-id: 9684ace9af
This commit is contained in:
Phillip Stephens 2022-12-02 22:01:02 -08:00
parent 16987ab59b
commit 696d65dd24
11 changed files with 101 additions and 17 deletions

View File

@ -40,7 +40,8 @@
"oscontext.h": "c",
"oscache.h": "c",
"stdlib.h": "c",
"musyx_priv.h": "c"
"musyx_priv.h": "c",
"gxenum.h": "c"
},
"files.autoSave": "onFocusChange",
"files.insertFinalNewline": true,

View File

@ -167,8 +167,8 @@ lbl_8036CBF8:
/* 8036CC14 00369B74 38 21 00 20 */ addi r1, r1, 0x20
/* 8036CC18 00369B78 4E 80 00 20 */ blr
.global sub_8036cc1c
sub_8036cc1c:
.global sub_8036cc1c__19CFrameDelayedKillerFbPv
sub_8036cc1c__19CFrameDelayedKillerFbPv:
/* 8036CC1C 00369B7C 94 21 FF E0 */ stwu r1, -0x20(r1)
/* 8036CC20 00369B80 7C 08 02 A6 */ mflr r0
/* 8036CC24 00369B84 2C 03 00 01 */ cmpwi r3, 1

View File

@ -902,7 +902,7 @@ __dt__6CModelFv:
/* 80355C98 00352BF8 38 00 00 00 */ li r0, 0
/* 80355C9C 00352BFC 38 60 00 01 */ li r3, 1
/* 80355CA0 00352C00 90 1E 00 00 */ stw r0, 0(r30)
/* 80355CA4 00352C04 48 01 6F 79 */ bl sub_8036cc1c
/* 80355CA4 00352C04 48 01 6F 79 */ bl sub_8036cc1c__19CFrameDelayedKillerFbPv
/* 80355CA8 00352C08 48 00 00 24 */ b lbl_80355CCC
lbl_80355CAC:
/* 80355CAC 00352C0C 38 03 FF FF */ addi r0, r3, -1
@ -912,7 +912,7 @@ lbl_80355CAC:
/* 80355CBC 00352C1C 38 00 00 00 */ li r0, 0
/* 80355CC0 00352C20 38 60 00 00 */ li r3, 0
/* 80355CC4 00352C24 90 1E 00 00 */ stw r0, 0(r30)
/* 80355CC8 00352C28 48 01 6F 55 */ bl sub_8036cc1c
/* 80355CC8 00352C28 48 01 6F 55 */ bl sub_8036cc1c__19CFrameDelayedKillerFbPv
lbl_80355CCC:
/* 80355CCC 00352C2C 34 1E 00 28 */ addic. r0, r30, 0x28
/* 80355CD0 00352C30 41 82 00 0C */ beq lbl_80355CDC
@ -1523,4 +1523,3 @@ lbl_803D8308:
# ROM: 0x3D5308
.asciz "??(??)"
.balign 4

View File

@ -3,8 +3,8 @@
.section .sbss, "wa"
.balign 8
.global lbl_805A9428
lbl_805A9428:
.global sCurrentFrameCount__16CGraphicsPalette
sCurrentFrameCount__16CGraphicsPalette:
.skip 0x8
.section .text, "ax"
@ -48,7 +48,7 @@ Load__16CGraphicsPaletteCFv:
/* 8030DED8 0030AE38 7C 7F 1B 78 */ mr r31, r3
/* 8030DEDC 0030AE3C 38 7F 00 10 */ addi r3, r31, 0x10
/* 8030DEE0 0030AE40 48 06 C6 51 */ bl GXLoadTlut
/* 8030DEE4 0030AE44 80 0D A8 68 */ lwz r0, lbl_805A9428@sda21(r13)
/* 8030DEE4 0030AE44 80 0D A8 68 */ lwz r0, sCurrentFrameCount__16CGraphicsPalette@sda21(r13)
/* 8030DEE8 0030AE48 90 1F 00 04 */ stw r0, 4(r31)
/* 8030DEEC 0030AE4C 80 01 00 14 */ lwz r0, 0x14(r1)
/* 8030DEF0 0030AE50 83 E1 00 0C */ lwz r31, 0xc(r1)
@ -67,7 +67,7 @@ __dt__16CGraphicsPaletteFv:
/* 8030DF18 0030AE78 7C 7E 1B 79 */ or. r30, r3, r3
/* 8030DF1C 0030AE7C 41 82 00 50 */ beq lbl_8030DF6C
/* 8030DF20 0030AE80 80 7E 00 04 */ lwz r3, 4(r30)
/* 8030DF24 0030AE84 80 0D A8 68 */ lwz r0, lbl_805A9428@sda21(r13)
/* 8030DF24 0030AE84 80 0D A8 68 */ lwz r0, sCurrentFrameCount__16CGraphicsPalette@sda21(r13)
/* 8030DF28 0030AE88 7C 03 00 50 */ subf r0, r3, r0
/* 8030DF2C 0030AE8C 28 00 00 02 */ cmplwi r0, 2
/* 8030DF30 0030AE90 40 80 00 1C */ bge lbl_8030DF4C
@ -76,7 +76,7 @@ __dt__16CGraphicsPaletteFv:
/* 8030DF3C 0030AE9C 7C 00 00 34 */ cntlzw r0, r0
/* 8030DF40 0030AEA0 90 7E 00 0C */ stw r3, 0xc(r30)
/* 8030DF44 0030AEA4 54 03 D9 7E */ srwi r3, r0, 5
/* 8030DF48 0030AEA8 48 05 EC D5 */ bl sub_8036cc1c
/* 8030DF48 0030AEA8 48 05 EC D5 */ bl sub_8036cc1c__19CFrameDelayedKillerFbPv
lbl_8030DF4C:
/* 8030DF4C 0030AEAC 34 1E 00 0C */ addic. r0, r30, 0xc
/* 8030DF50 0030AEB0 41 82 00 0C */ beq lbl_8030DF5C

View File

@ -66,7 +66,7 @@ sub_8030e10c__8CTextureFv:
/* 8030E128 0030B088 48 04 A2 AD */ bl sub_803583d4
/* 8030E12C 0030B08C 7C 64 1B 78 */ mr r4, r3
/* 8030E130 0030B090 38 60 00 01 */ li r3, 1
/* 8030E134 0030B094 48 05 EA E9 */ bl sub_8036cc1c
/* 8030E134 0030B094 48 05 EA E9 */ bl sub_8036cc1c__19CFrameDelayedKillerFbPv
lbl_8030E138:
/* 8030E138 0030B098 80 01 00 14 */ lwz r0, 0x14(r1)
/* 8030E13C 0030B09C 7C 08 03 A6 */ mtlr r0

View File

@ -1007,7 +1007,7 @@ __dt__8CMapAreaFv:
/* 80080EB0 0007DE10 90 8D A2 F0 */ stw r4, lbl_805A8EB0@sda21(r13)
/* 80080EB4 0007DE14 80 9E 00 44 */ lwz r4, 0x44(r30)
/* 80080EB8 0007DE18 90 1E 00 44 */ stw r0, 0x44(r30)
/* 80080EBC 0007DE1C 48 2E BD 61 */ bl sub_8036cc1c
/* 80080EBC 0007DE1C 48 2E BD 61 */ bl sub_8036cc1c__19CFrameDelayedKillerFbPv
/* 80080EC0 0007DE20 34 1E 00 44 */ addic. r0, r30, 0x44
/* 80080EC4 0007DE24 41 82 00 0C */ beq lbl_80080ED0
/* 80080EC8 0007DE28 80 7E 00 44 */ lwz r3, 0x44(r30)
@ -1146,4 +1146,3 @@ lbl_803CD66C:
.asciz "??(??)"
.balign 4
.4byte 0

View File

@ -8991,7 +8991,7 @@ FrameBegin__13CStateManagerFUi:
/* 8004B574 000484D4 80 03 08 D4 */ lwz r0, 0x8d4(r3)
/* 8004B578 000484D8 90 0D A8 70 */ stw r0, lbl_805A9430@sda21(r13)
/* 8004B57C 000484DC 80 03 08 D4 */ lwz r0, 0x8d4(r3)
/* 8004B580 000484E0 90 0D A8 68 */ stw r0, lbl_805A9428@sda21(r13)
/* 8004B580 000484E0 90 0D A8 68 */ stw r0, sCurrentFrameCount__16CGraphicsPalette@sda21(r13)
/* 8004B584 000484E4 4B FF FF D5 */ bl SwapOutTexturesToARAM__13CStateManagerFiUi
/* 8004B588 000484E8 80 01 00 14 */ lwz r0, 0x14(r1)
/* 8004B58C 000484EC 7C 08 03 A6 */ mtlr r0

View File

@ -558,8 +558,8 @@ LIBS = [
"Kyoto/Graphics/CCubeModel",
["Kyoto/Graphics/CGX", True],
["Kyoto/Graphics/CTevCombiners", True],
"Kyoto/Graphics/DolphinCGraphics",
"Kyoto/Graphics/DolphinCPalette",
["Kyoto/Graphics/DolphinCGraphics", False],
["Kyoto/Graphics/DolphinCPalette", False],
"Kyoto/Graphics/DolphinCTexture",
["Kyoto/Math/CloseEnough", True],
"Kyoto/Math/CMatrix3f",

View File

@ -9,6 +9,7 @@ public:
static void ShutDown();
static void sub_8036cb90();
static void sub_8036cc1c(bool unk1, void* unk2);
};
#endif // _CFRAMEDELAYEDKILLER

View File

@ -0,0 +1,39 @@
#ifndef _CGRAPHICSPALETTE
#define _CGRAPHICSPALETTE
#include "types.h"
#include "dolphin/gx.h"
#include <rstl/single_ptr.hpp>
enum EPaletteFormat {
kPF_IA8 = GX_TL_IA8,
kPF_RGB565 = GX_TL_RGB565,
kPF_RGB5A3 = GX_TL_RGB5A3,
};
class CInputStream;
class CGraphicsPalette {
public:
CGraphicsPalette(EPaletteFormat format, int numEntries);
CGraphicsPalette(CInputStream& in);
~CGraphicsPalette();
ushort* GetPaletteData() { return xc_entries.get(); }
const ushort* GetPaletteData() const { return xc_entries.get(); }
void Load() const;
void UnLock();
private:
static uint sCurrentFrameCount;
EPaletteFormat x0_fmt;
mutable uint x4_frameLoaded;
uint x8_entryCount;
rstl::single_ptr<ushort> xc_entries;
GXTlutObj x10_tlutObj;
bool x1c_locked;
};
#endif // _CGRAPHICSPALETTE

View File

@ -0,0 +1,45 @@
#include "Kyoto/Graphics/CGraphicsPalette.hpp"
#include "Kyoto/Alloc/CMemorySys.hpp"
#include "Kyoto/CFrameDelayedKiller.hpp"
#include "Kyoto/Streams/CInputStream.hpp"
#include "dolphin/os/OSCache.h"
uint CGraphicsPalette::sCurrentFrameCount = 0;
CGraphicsPalette::CGraphicsPalette(EPaletteFormat format, int numEntries)
: x0_fmt(format)
, x8_entryCount(numEntries)
, xc_entries((ushort*)CMemory::Alloc(numEntries * sizeof(ushort), IAllocator::kHI_RoundUpLen))
, x1c_locked(false) {
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), (GXTlutFmt)(x0_fmt), x8_entryCount);
}
CGraphicsPalette::CGraphicsPalette(CInputStream& in)
: x0_fmt(EPaletteFormat(in.ReadLong()))
, x8_entryCount(in.Get< short >() * in.Get< short >())
, xc_entries((ushort*)CMemory::Alloc(x8_entryCount * sizeof(ushort), IAllocator::kHI_RoundUpLen))
, x1c_locked(false) {
in.Get(reinterpret_cast< uchar* >(xc_entries.get()), x8_entryCount * sizeof(ushort));
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), static_cast< GXTlutFmt >(x0_fmt), x8_entryCount);
DCFlushRange(xc_entries.get(), x8_entryCount * sizeof(ushort));
}
CGraphicsPalette::~CGraphicsPalette() {
uint frameDiff = sCurrentFrameCount - x4_frameLoaded;
if (frameDiff < 2) {
CFrameDelayedKiller::sub_8036cc1c(frameDiff == 0, xc_entries.release());
}
}
void CGraphicsPalette::Load() const {
GXLoadTlut(&x10_tlutObj, GX_TLUT0);
x4_frameLoaded = sCurrentFrameCount;
}
void CGraphicsPalette::UnLock() {
DCStoreRange(xc_entries.get(), x8_entryCount * sizeof(ushort));
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), static_cast< GXTlutFmt >(x0_fmt), x8_entryCount);
DCFlushRange(xc_entries.get(), x8_entryCount * sizeof(ushort));
x1c_locked = false;
}