summaryrefslogtreecommitdiff
path: root/arm9/lib/src/GX_load3d.c
blob: 5aa15581661b6acfb66323eeac30fd9c893b1ce6 (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include "global.h"
#include "main.h"
#include "GX.h"

extern u32 GXi_DmaId;

extern u32 sTex;
extern u32 sTexLCDCBlk1;
extern u32 sTexLCDCBlk2;
extern u32 sSzTexBlk1;

static const struct _TexStartAddrTable
{
    u16     blk1;                      // 12 bit shift
    u16     blk2;                      // 12 bit shift
    u16     szBlk1;                    // 12 bit shift
};
extern struct _TexStartAddrTable sTexStartAddrTable[16];


extern u32 sTexPltt;
extern u32 sTexPlttLCDCBlk;
extern u16 sTexPlttStartAddrTable[8];

extern s32 sClrImg;
extern u32 sClrImgLCDCBlk;

ARM_FUNC void GX_BeginLoadTex(){
    u32 temp = GX_ResetBankForTex();
    sTex = temp;
    sTexLCDCBlk1 = sTexStartAddrTable[temp].blk1 << 0xC;
    sTexLCDCBlk2 = sTexStartAddrTable[temp].blk2 << 0xC;
    sSzTexBlk1 = sTexStartAddrTable[temp].szBlk1 << 0xC;
}

ARM_FUNC void GX_LoadTex(void *src, u32 offset, u32 size){
    void *temp;
    if (!sTexLCDCBlk2)
    {
        temp = (void *)(sTexLCDCBlk1 + offset);
    }
    else
    {
        if ((offset + size) < sSzTexBlk1)
        {
            temp = (void *)(sTexLCDCBlk1 + offset);
        }
        else if (offset >= sSzTexBlk1)
        {
            temp = (void *)(sTexLCDCBlk2 + offset - sSzTexBlk1);
        }
        else
        {
            void *temp2 = (void *)sTexLCDCBlk2;
            u32 temp1 = sSzTexBlk1 - offset;
            temp = (void *)(sTexLCDCBlk1 + offset);
            GXi_DmaCopy32(GXi_DmaId, src, temp, temp1);
            GXi_DmaCopy32Async(GXi_DmaId, (void *)((u8 *)src + temp1), temp2, (size - temp1), NULL, NULL);
            return;
        }
    }
    GXi_DmaCopy32Async(GXi_DmaId, src, temp, size, NULL, NULL);
}

ARM_FUNC void GX_EndLoadTex(){
    GXi_WaitDma(GXi_DmaId);
    GX_SetBankForTex(sTex);
    sSzTexBlk1 = 0x0;
    sTexLCDCBlk2 = 0x0;
    sTexLCDCBlk1 = 0x0;
    sTex = 0x0;
}

ARM_FUNC void GX_BeginLoadTexPltt(){
    s32 temp = GX_ResetBankForTexPltt();
    sTexPltt = temp;
    sTexPlttLCDCBlk = sTexPlttStartAddrTable[temp >> 4] << 0xC;
}

ARM_FUNC void GX_LoadTexPltt(void *src, u32 offset, u32 size){
    GXi_DmaCopy32Async(GXi_DmaId, src, (void *)(sTexPlttLCDCBlk + offset), size, NULL, NULL);
}

ARM_FUNC void GX_EndLoadTexPltt(){
    GXi_WaitDma(GXi_DmaId);
    GX_SetBankForTexPltt(sTexPltt);
    sTexPltt = 0x0;
    sTexPlttLCDCBlk = 0x0;
}

ARM_FUNC void GX_BeginLoadClearImage(){
    s32 temp = GX_ResetBankForClearImage();
    sClrImg = temp;
    switch (temp)
    {
    case 2:
    case 3:
        sClrImgLCDCBlk = 0x6800000;
        return;
    case 8:
    case 12:
        sClrImgLCDCBlk = 0x6840000;
        return;
    case 1:
        sClrImgLCDCBlk = 0x67E0000;
        return;
    case 4:
        sClrImgLCDCBlk = 0x6820000;
    }
}

ARM_FUNC void GX_LoadClearImageColor(void *src, u32 size){
    GXi_DmaCopy32Async(GXi_DmaId, src, (void *)(sClrImgLCDCBlk), size, NULL, NULL);
}

ARM_FUNC void GX_LoadClearImageDepth(void *src, u32 size){
    GXi_DmaCopy32Async(GXi_DmaId, src, (void *)(sClrImgLCDCBlk + 0x20000), size, NULL, NULL);
}

ARM_FUNC void GX_EndLoadClearImage(){
    GXi_WaitDma(GXi_DmaId);
    GX_SetBankForClearImage(sClrImg);
    sClrImg = 0x0;
    sClrImgLCDCBlk = 0x0;
}