summaryrefslogtreecommitdiff
path: root/src/code/z_actor_dlftbls.c
blob: 05a1da25dab1d00cdb1fbb68da663e9d0e80f6e2 (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
#include "z64actor_dlftbls.h"

#include "fault.h"

// Segment and Profile declarations (also used in the table below)
#define DEFINE_ACTOR(name, _enumValue, _allocType, _debugName) \
    extern struct ActorProfile name##_Profile;                 \
    DECLARE_OVERLAY_SEGMENT(name)
#define DEFINE_ACTOR_INTERNAL(name, _enumValue, _allocType, _debugName) extern struct ActorProfile name##_Profile;
#define DEFINE_ACTOR_UNSET(_enumValue)

#include "tables/actor_table.h"

#undef DEFINE_ACTOR
#undef DEFINE_ACTOR_INTERNAL
#undef DEFINE_ACTOR_UNSET

// Actor Overlay Table definition
#define DEFINE_ACTOR(name, _enumValue, allocType, _debugName) \
    {                                                         \
        ROM_FILE(ovl_##name),                                 \
        SEGMENT_START(ovl_##name),                            \
        SEGMENT_END(ovl_##name),                              \
        NULL,                                                 \
        &name##_Profile,                                      \
        NULL,                                                 \
        allocType,                                            \
        0,                                                    \
    },

#define DEFINE_ACTOR_INTERNAL(name, _enumValue, allocType, _debugName)         \
    {                                                                          \
        ROM_FILE_UNSET, NULL, NULL, NULL, &name##_Profile, NULL, allocType, 0, \
    },

#define DEFINE_ACTOR_UNSET(_enumValue) { 0 },

ActorOverlay gActorOverlayTable[] = {
#include "tables/actor_table.h"
};

#undef DEFINE_ACTOR
#undef DEFINE_ACTOR_INTERNAL
#undef DEFINE_ACTOR_UNSET

ActorId gMaxActorId = 0;

FaultClient sActorOverlayTableFaultClient;
FaultAddrConvClient sActorOverlayTableFaultAddrConvClient;

void ActorOverlayTable_FaultClient(void* arg0, void* arg1) {
    ActorOverlay* overlayEntry;
    u32 overlaySize;
    ActorId actorId;

    FaultDrawer_SetCharPad(-2, 0);

    FaultDrawer_Printf("actor_dlftbls %u\n", gMaxActorId);
    FaultDrawer_Printf("No. RamStart- RamEnd cn  Name\n");

    for (actorId = 0, overlayEntry = &gActorOverlayTable[0]; actorId < gMaxActorId; actorId++, overlayEntry++) {
        overlaySize = (uintptr_t)overlayEntry->vramEnd - (uintptr_t)overlayEntry->vramStart;
        if (overlayEntry->loadedRamAddr != NULL) {
            FaultDrawer_Printf("%3d %08x-%08x %3d %s\n", actorId, overlayEntry->loadedRamAddr,
                               (u32)overlayEntry->loadedRamAddr + overlaySize, overlayEntry->numLoaded, "");
        }
    }
}

uintptr_t ActorOverlayTable_FaultAddrConv(uintptr_t address, void* param) {
    uintptr_t addr = address;
    ActorOverlay* actorOvl = &gActorOverlayTable[0];
    uintptr_t ramConv;
    void* ramStart;
    size_t diff;
    ActorId actorId;

    for (actorId = 0; actorId < gMaxActorId; actorId++, actorOvl++) {
        diff = (uintptr_t)actorOvl->vramEnd - (uintptr_t)actorOvl->vramStart;
        ramStart = actorOvl->loadedRamAddr;
        ramConv = (uintptr_t)actorOvl->vramStart - (uintptr_t)ramStart;

        if (ramStart != NULL) {
            if ((addr >= (uintptr_t)ramStart) && (addr < (uintptr_t)ramStart + diff)) {
                return addr + ramConv;
            }
        }
    }

    return 0;
}

void ActorOverlayTable_Init(void) {
    gMaxActorId = ACTOR_ID_MAX;
    Fault_AddClient(&sActorOverlayTableFaultClient, ActorOverlayTable_FaultClient, NULL, NULL);
    Fault_AddAddrConvClient(&sActorOverlayTableFaultAddrConvClient, ActorOverlayTable_FaultAddrConv, NULL);
}

void ActorOverlayTable_Cleanup(void) {
    Fault_RemoveClient(&sActorOverlayTableFaultClient);
    Fault_RemoveAddrConvClient(&sActorOverlayTableFaultAddrConvClient);
    gMaxActorId = 0;
}