summaryrefslogtreecommitdiff
path: root/mm/src/code/z_fbdemo_dlftbls.c
blob: 7819536b1672ca6780685ad51a6532f1ff56d880 (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
#include "z64transition.h"

#include "segment_symbols.h"
#include "z64lib.h"

// Profile and Linker symbol declarations (used in the table below)
#define DEFINE_TRANSITION(_enumValue, structName, _instanceName, name) \
    extern TransitionProfile structName##_Profile;                     \
    DECLARE_OVERLAY_SEGMENT(name)

#define DEFINE_TRANSITION_INTERNAL(_enumValue, structName, _instanceName) extern TransitionProfile structName##_Profile;

#include "tables/transition_table.h"

#undef DEFINE_TRANSITION
#undef DEFINE_TRANSITION_INTERNAL
// BENTODO
#define DEFINE_TRANSITION(_enumValue, structName, _instanceName, name) \
    {                                                                  \
        { 0, 0 },                                                      \
        SEGMENT_START(ovl_##name),                                     \
        SEGMENT_END(ovl_##name),                                       \
        SEGMENT_ROM_START(ovl_##name),                                 \
        SEGMENT_ROM_END(ovl_##name),                                   \
        &structName##_Profile,                                         \
        sizeof(structName),                                            \
    },

#define DEFINE_TRANSITION_INTERNAL(_enumValue, structName, _instanceName) \
    { { 0, 0 }, NULL, NULL, 0, 0, &structName##_Profile, sizeof(structName) },

TransitionOverlay gTransitionOverlayTable[] = {
#include "tables/transition_table.h"
};

#undef DEFINE_TRANSITION
#undef DEFINE_TRANSITION_INTERNAL

void Transition_Init(TransitionContext* transitionCtx) {
    TransitionOverlay* overlayEntry;
    ptrdiff_t relocOffset;
    TransitionProfile* profile[1];

    overlayEntry = &gTransitionOverlayTable[transitionCtx->fbdemoType];
    TransitionOverlay_Load(overlayEntry);

    relocOffset = (uintptr_t)Lib_PhysicalToVirtual(overlayEntry->loadInfo.addr) - (uintptr_t)overlayEntry->vramStart;
    profile[0] = NULL;
    profile[0] = (overlayEntry->profile != NULL) ? (TransitionProfile*)((uintptr_t)overlayEntry->profile + relocOffset)
                                                 : profile[0];

    transitionCtx->init = profile[0]->init;
    transitionCtx->destroy = profile[0]->destroy;
    transitionCtx->start = profile[0]->start;
    transitionCtx->isDone = profile[0]->isDone;
    transitionCtx->draw = profile[0]->draw;
    transitionCtx->update = profile[0]->update;
    transitionCtx->setType = profile[0]->setType;
    transitionCtx->setColor = profile[0]->setColor;
    transitionCtx->setEnvColor = profile[0]->setEnvColor;
}

void Transition_Destroy(TransitionContext* transitionCtx) {
    TransitionOverlay_Free(&gTransitionOverlayTable[transitionCtx->fbdemoType]);
}