summaryrefslogtreecommitdiff
path: root/src/manager/manager9.c
blob: 1baa8d98eea2d230b12de93d89e5713d85cc1e1d (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
#include "global.h"
#include "manager.h"
#include "room.h"
#include "screen.h"
#include "functions.h"

typedef struct {
    Manager manager;
    u8 unk_00[0x1C];
    u32 unk_3c;
} Manager9;

void sub_08058204(Manager9*);
void sub_08058210(Manager9*);
u32 sub_08058244(int);
void sub_080582A0(u32, u32*, u16*);
void sub_080582F8(u8*, u8*);

extern u32 gUnk_02006F00[];

const u16 gUnk_081081EC[] = { 0x30, 0x30, 0x30, 0x38 };

void sub_080581D8(Manager9* this) {
    sub_08058210(this);
    if (!this->manager.action) {
        this->manager.action = 1;
        gScreen.bg.bg1Updated = 0;
        sub_08052D74(this, sub_08058204, NULL);
    }
}

void sub_08058204(Manager9* this) {
    sub_08058324(this->manager.unk_0a);
}

void sub_08058210(Manager9* this) {
    u32 tmp = sub_08058244(this->manager.unk_0a);
    if (this->unk_3c == tmp)
        return;
    this->unk_3c = tmp;
    sub_080582A0(tmp, gUnk_02006F00, gBG3Buffer);
    gScreen.bg.bg1Updated = 1;
}

u32 sub_08058244(int i) {
    u32 tmp;
    s32 tmp2;
    u32 tmp3;
    s32 tmp4;
    tmp = ((gRoomControls.roomScrollY - gRoomControls.roomOriginY) * 0x20) / (gRoomControls.height - 0xa0);
    gScreen.bg.bg1yOffset = gRoomControls.roomOriginY + tmp;
    tmp = (((gRoomControls.roomScrollX - gRoomControls.roomOriginX) * gUnk_081081EC[i]) / (gRoomControls.width - 0xf0));
    gScreen.bg.bg1xOffset = tmp & 0xf;
    return tmp;
}

void sub_080582A0(u32 unk, u32* unk2, u16* unk3) {
    int i = 0x20;
    unk2 += unk >> 4;
    for (; i != 0; i--) {
        DmaSet(3, unk2, unk3, 0x80000020);
        unk2 += 0x40;
        unk3 += 0x20;
    }
}

extern u8 gMapDataTopSpecial[];

void sub_080582D0() {
    u8* tmp = gMapDataTopSpecial;
    u8* tmp2 = tmp + 0x4000;
    sub_080582F8(tmp, tmp2);
    tmp += 0x800;
    tmp2 += 0x40;
    sub_080582F8(tmp, tmp2);
}

void sub_080582F8(u8* unk, u8* unk2) {
    u32 i;
    for (i = 0; i < 0x20; i++, unk += 0x40, unk2 += 0x100) {
        DmaSet(3, unk, unk2, 0x80000020);
    }
}

extern u32 gUnk_0200B650;

void sub_08058324(u32 unk) {
    gUnk_0200B650 = 0;
    LoadPaletteGroup(unk + 0x86);
    LoadGfxGroup(unk + 0x36);
    sub_080582D0();
    sub_080582A0(sub_08058244(unk), gUnk_02006F00, gBG3Buffer);
    gScreen.bg.bg1Control = 0x1D47;
    gScreen.bg.bg1Tilemap = gBG3Buffer;
    gScreen.bg.bg1Updated = 1;
    gScreen.lcd.displayControl |= 0x200;
}