summaryrefslogtreecommitdiff
path: root/src/code/z_sample.c
blob: fa995e06ea66bf0b4da7be382acfb79474ee7fbd (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
#include <ultra64.h>
#include <global.h>
#include <PR/os_cont.h>

void Sample_Calc(SampleContext* this) {
    if (!~(this->state.input[0].padPressed | ~START_BUTTON)) {
        SET_NEXT_GAMESTATE(&this->state, func_800BCA64, GlobalContext);
        this->state.running = false;
    }
}

// very close from matching, the only difference is the place of "mtx" in the stack
#ifdef NON_MATCHING
void Sample_Draw(SampleContext* this) {
    u32 pad;
    GraphicsContext* gfxCtx = this->state.gfxCtx;
    View* view = &this->view;
    Gfx* dispRefs[4];
    Mtx* mtx;

    Graph_OpenDisps(dispRefs, gfxCtx, "../z_sample.c", 62);

    gSPSegment(gfxCtx->polyOpa.p++, 0x00, NULL);
    gSPSegment(gfxCtx->polyOpa.p++, 0x01, this->staticSegment);

    func_80095248(gfxCtx, 0, 0, 0);

    view->unk_120 = 7;
    func_800AAA50(view, 15);

    mtx = Graph_Alloc(gfxCtx, sizeof(Mtx));
    func_80103D58(mtx, SREG(37), SREG(38), SREG(39), 1.0f, SREG(40), SREG(41), SREG(42));
    gSPMatrix(gfxCtx->polyOpa.p++, mtx, G_MTX_LOAD);

    gfxCtx->polyOpa.p = Gfx_SetFog2(gfxCtx->polyOpa.p, 0xFF, 0xFF, 0xFF, 0, 0, 0);
    func_80093D18(gfxCtx);

    gDPSetCycleType(gfxCtx->polyOpa.p++, G_CYC_1CYCLE);
    gDPSetRenderMode(gfxCtx->polyOpa.p++, G_RM_AA_ZB_OPA_SURF, G_RM_AA_ZB_OPA_SURF2);
    gDPSetCombineLERP(gfxCtx->polyOpa.p++, 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE, 0, 0, 0, PRIMITIVE, 0, 0, 0,
                      PRIMITIVE);
    gDPSetPrimColor(gfxCtx->polyOpa.p++, 0, 0, 0xFF, 0xFF, 0x00, 0x00);

    Graph_CloseDisps(dispRefs, gfxCtx, "../z_sample.c", 111);
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_sample/Sample_Draw.s")
#endif

void Sample_Update(SampleContext* this) {
    Sample_Draw(this);
    Sample_Calc(this);
}

void Sample_Destroy(SampleContext* this) {
}

void Sample_SetupView(SampleContext* this) {
    View* view;
    GraphicsContext* gfxCtx;
    u32 v0[4];
    Vec3f v1;
    Vec3f v2;
    Vec3f v3;

    view = &this->view;
    gfxCtx = this->state.gfxCtx;
    func_800AA278(view, gfxCtx);

    // clang-format off
    v0[1] = SCREEN_HEIGHT; v0[3] = SCREEN_WIDTH; 
    v0[0] = 0; v0[2] = 0;
    // clang-format on

    func_800AA4FC(view, &v0);
    func_800AA460(view, 60, 10, 12800);

    v1.x = 0;
    v1.y = 0;
    v2.x = 0;
    v2.y = 0;
    v2.z = 0;
    v3.x = 0;
    v3.z = 0;
    v1.z = 3000;
    v3.y = 1;

    func_800AA358(view, &v1, &v2, &v3);
}

void Sample_LoadTitleStatic(SampleContext* this) {
    u32 size = _title_staticSegmentRomEnd - _title_staticSegmentRomStart;

    this->staticSegment = Game_Alloc(&this->state, size, "../z_sample.c", 163);
    DmaMgr_SendRequest1(this->staticSegment, _title_staticSegmentRomStart, size, "../z_sample.c", 164);
}

void Sample_Init(SampleContext* this) {
    this->state.main = Sample_Update;
    this->state.destroy = Sample_Destroy;
    R_UPDATE_RATE = 1;
    Sample_SetupView(this);
    Sample_LoadTitleStatic(this);
    SREG(37) = 0;
    SREG(38) = 0;
    SREG(39) = 0;
    SREG(40) = 0;
    SREG(41) = 0;
    SREG(42) = 0;
}