summaryrefslogtreecommitdiff
path: root/src/box_party_pokemon_dropdown.c
blob: a74f1611cc3d7ccb2fb0c746fe092c5bc956ba89 (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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "global.h"
#include "bg.h"
#include "box_party_pokemon_dropdown.h"
#include "malloc.h"

struct UnkStruct_203ABE4_Sub
{
    s16 destX;
    s16 destY;
    u16 width;
    u16 height;
    s16 destX2;
    s16 destY2;
};

struct UnkStruct_203ABE4
{
    struct UnkStruct_203ABE4_Sub map1Rect;
    struct UnkStruct_203ABE4_Sub map2Rect;
    const void * src1;
    const void * src2;
    u16 src1Height;
    u16 src1Width;
    u16 src2Height;
    u16 unk_26;
    u16 unk_28;
    u8 mapSize;
    u8 bgId;
    bool8 bgUpdateScheduled;
};

static EWRAM_DATA struct UnkStruct_203ABE4 * sBoxPartyPokemonDropdownPtr = NULL;
static EWRAM_DATA u16 sBoxPartyPokemonDropdownCount = 0;

static void PushMap1(u8 a0);
static void PushMap2(u8 a0);

static const struct {
    u16 height;
    u16 width;
} sBGdims[2][4] = {
    {
        {0x0100, 0x0100},
        {0x0200, 0x0100},
        {0x0100, 0x0200},
        {0x0200, 0x0200}
    }, {
        {0x0080, 0x0080},
        {0x0100, 0x0100},
        {0x0200, 0x0200},
        {0x0400, 0x0400}
    }
};

void sub_80F7AD8(u8 num)
{
    u16 i;
    sBoxPartyPokemonDropdownPtr = Alloc(num * sizeof(struct UnkStruct_203ABE4));
    sBoxPartyPokemonDropdownCount = sBoxPartyPokemonDropdownPtr == NULL ? 0 : num;
    for (i = 0; i < sBoxPartyPokemonDropdownCount; i++)
    {
        sBoxPartyPokemonDropdownPtr[i].src1 = NULL;
        sBoxPartyPokemonDropdownPtr[i].bgUpdateScheduled = FALSE;
    }
}

void sub_80F7B2C(void)
{
    Free(sBoxPartyPokemonDropdownPtr);
}

void sub_80F7B40(void)
{
    int i;

    for (i = 0; i < sBoxPartyPokemonDropdownCount; i++)
    {
        if (sBoxPartyPokemonDropdownPtr[i].bgUpdateScheduled == TRUE)
            sub_80F7E54(i);
    }
}

void sub_80F7B80(u8 a0, u8 a1, const void * a2, u16 a3, u16 a4)
{
    u16 screenSize;
    u16 bgType;

    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        sBoxPartyPokemonDropdownPtr[a0].src1 = NULL;
        sBoxPartyPokemonDropdownPtr[a0].src2 = a2;
        sBoxPartyPokemonDropdownPtr[a0].bgId = a1;
        sBoxPartyPokemonDropdownPtr[a0].src2Height = a3;
        sBoxPartyPokemonDropdownPtr[a0].unk_26 = a4;
        screenSize = GetBgAttribute(a1, BG_ATTR_SCREENSIZE);
        bgType = GetBgAttribute(a1, BG_ATTR_BGTYPE);
        sBoxPartyPokemonDropdownPtr[a0].src1Height = sBGdims[bgType][screenSize].height;
        sBoxPartyPokemonDropdownPtr[a0].src1Width = sBGdims[bgType][screenSize].width;
        if (bgType != 0)
            sBoxPartyPokemonDropdownPtr[a0].mapSize = 1;
        else
            sBoxPartyPokemonDropdownPtr[a0].mapSize = 2;
        sBoxPartyPokemonDropdownPtr[a0].unk_28 = a3 * sBoxPartyPokemonDropdownPtr[a0].mapSize;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.width = a3;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.height = a4;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX = 0;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY = 0;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 = 0;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 = 0;
        sBoxPartyPokemonDropdownPtr[a0].map1Rect = sBoxPartyPokemonDropdownPtr[a0].map2Rect;
        sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
    }
}

void sub_80F7C7C(u8 a0, const void * a1)
{
    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        sBoxPartyPokemonDropdownPtr[a0].src1 = a1;
        sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
    }
}

void sub_80F7CAC(u8 a0, u16 a1, u16 a2)
{
    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 = a1;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 = a2;
        sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
    }
}

void sub_80F7CE8(u8 a0, u16 a1, u16 a2, u16 a3, u16 a4)
{
    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX = a1;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY = a2;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.width = a3;
        sBoxPartyPokemonDropdownPtr[a0].map2Rect.height = a4;
        sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
    }
}

void sub_80F7D30(u8 a0, u8 a1, s8 a2)
{
    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        switch (a1)
        {
        case 0:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 += a2;
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.width -= a2;
            break;
        case 1:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX += a2;
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.width += a2;
            break;
        case 2:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 += a2;
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.height -= a2;
            break;
        case 3:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY -= a2;
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.height += a2;
            break;
        case 4:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2 += a2;
            break;
        case 5:
            sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 += a2;
            break;
        }
        sBoxPartyPokemonDropdownPtr[a0].bgUpdateScheduled = TRUE;
    }
}

void sub_80F7E54(u8 a0)
{
    if (a0 < sBoxPartyPokemonDropdownCount)
    {
        if (sBoxPartyPokemonDropdownPtr[a0].src1 != NULL)
            PushMap1(a0);
        PushMap2(a0);
        sBoxPartyPokemonDropdownPtr[a0].map1Rect = sBoxPartyPokemonDropdownPtr[a0].map2Rect;
    }
}

static void PushMap1(u8 a0)
{
    int i;
    int r9 = sBoxPartyPokemonDropdownPtr[a0].mapSize * sBoxPartyPokemonDropdownPtr[a0].src1Height;
    const void * addr = sBoxPartyPokemonDropdownPtr[a0].src1 + r9 * sBoxPartyPokemonDropdownPtr[a0].map1Rect.destY2 + sBoxPartyPokemonDropdownPtr[a0].map1Rect.destX2 * sBoxPartyPokemonDropdownPtr[a0].mapSize;
    for (i = 0; i < sBoxPartyPokemonDropdownPtr[a0].map1Rect.height; i++)
    {
        CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[a0].bgId, addr, sBoxPartyPokemonDropdownPtr[a0].map1Rect.destX2, sBoxPartyPokemonDropdownPtr[a0].map1Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[a0].map1Rect.width, 1);
        addr += r9;
    }
}

static void PushMap2(u8 a0)
{
    int i;
    int r9 = sBoxPartyPokemonDropdownPtr[a0].mapSize * sBoxPartyPokemonDropdownPtr[a0].src2Height;
    const void * addr = sBoxPartyPokemonDropdownPtr[a0].src2 + r9 * sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY + sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX * sBoxPartyPokemonDropdownPtr[a0].mapSize;
    for (i = 0; i < sBoxPartyPokemonDropdownPtr[a0].map2Rect.height; i++)
    {
        CopyToBgTilemapBufferRect(sBoxPartyPokemonDropdownPtr[a0].bgId, addr, sBoxPartyPokemonDropdownPtr[a0].map2Rect.destX2, sBoxPartyPokemonDropdownPtr[a0].map2Rect.destY2 + i, sBoxPartyPokemonDropdownPtr[a0].map2Rect.width, 1);
        addr += r9;
    }
}