summaryrefslogtreecommitdiff
path: root/libs/revolution/src/tpl/TPL.c
blob: 466f390f8364e23832ce9d4260a246619b11b839 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <revolution/tpl.h>
#include <revolution/os.h>

void TPLBind(TPLPalettePtr ptr) {
    u16 i;

    if (ptr->versionNumber != 2142000) {
        OSPanic(__FILE__, 0x19, "invalid version number for texture palette");
    }

    ptr->descriptorArray = (TPLDescriptorPtr)(((u32)(ptr->descriptorArray)) + ((u32)ptr));

    for (i = 0; i < ptr->numDescriptors; i++) {
        if (ptr->descriptorArray[i].textureHeader) {
            ptr->descriptorArray[i].textureHeader = (TPLHeaderPtr)(((u32)(ptr->descriptorArray[i].textureHeader)) + ((u32)ptr));

            if (!ptr->descriptorArray[i].textureHeader->unpacked) {
                ptr->descriptorArray[i].textureHeader->data = (char*)((u32)(ptr->descriptorArray[i].textureHeader->data) + (u32)ptr);
                ptr->descriptorArray[i].textureHeader->unpacked = 1;
            }
        }

        if (ptr->descriptorArray[i].CLUTHeader) {
            ptr->descriptorArray[i].CLUTHeader = (TPLClutHeaderPtr)((u32)(ptr->descriptorArray[i].CLUTHeader) + (u32)ptr);

            if (!ptr->descriptorArray[i].CLUTHeader->unpacked) {
                ptr->descriptorArray[i].CLUTHeader->data = (char*)((u32)(ptr->descriptorArray[i].CLUTHeader->data) + (u32)ptr);
                ptr->descriptorArray[i].CLUTHeader->unpacked = 1;
            }
        }
    }
}

TPLDescriptorPtr TPLGet(TPLPalettePtr ptr, u32 id) {
    id %= ptr->numDescriptors;
    return &ptr->descriptorArray[id];
}