Added macros header

Additionally, updated code to use PHYSICAL_TO_VIRTUAL and ALIGN16 macros.
Additionally, retyped gRspSegmentPhysAddrs back to u32 as in OOT. These get the straight return value of PHYSICAL_TO_VIRTUAL, so they are u32.
This commit is contained in:
Kenix3 2020-06-04 23:07:09 -04:00
parent 664182c289
commit 5c97d35841
8 changed files with 31 additions and 27 deletions

View File

@ -4,5 +4,6 @@
#include "structs.h" #include "structs.h"
#include "functions.h" #include "functions.h"
#include "variables.h" #include "variables.h"
#include "macros.h"
#endif #endif

13
include/macros.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef _MACROS_H_
#define _MACROS_H_
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
#define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0]))
#define PHYSICAL_TO_VIRTUAL(addr) ((u32)(addr) + 0x80000000)
#define PHYSICAL_TO_VIRTUAL2(addr) ((u32)(addr) - 0x80000000)
#define SEGMENTED_TO_VIRTUAL(addr) (void*)(PHYSICAL_TO_VIRTUAL(gRspSegmentPhysAddrs[SEGMENT_NUMBER(addr)]) + SEGMENT_OFFSET(addr))
#define ALIGN16(val) (((val) + 0xF) & ~0xF)
#endif

View File

@ -1468,7 +1468,7 @@ typedef struct {
/* 0x009 */ u8 spawnedObjectCount; /* 0x009 */ u8 spawnedObjectCount;
/* 0x00A */ u8 mainKeepIndex; /* 0x00A */ u8 mainKeepIndex;
/* 0x00B */ u8 keepObjectId; /* 0x00B */ u8 keepObjectId;
/* 0x00C */ SceneObject objects[35]; /* 0x00C */ SceneObject objects[35]; // TODO: OBJECT_EXCHANGE_BANK_MAX array size
} SceneContext; // size = 0x958 } SceneContext; // size = 0x958
typedef struct { typedef struct {

View File

@ -4109,7 +4109,7 @@ extern UNK_TYPE1 D_801F80F8; // D_801F80F8
extern u64 lastRenderFrameTimestamp; // D_801F8150 extern u64 lastRenderFrameTimestamp; // D_801F8150
extern OSMesgQueue siEventCallbackQueue; // D_801F8160 extern OSMesgQueue siEventCallbackQueue; // D_801F8160
extern OSMesg siEventCallbackBuffer[1]; // D_801F8178 extern OSMesg siEventCallbackBuffer[1]; // D_801F8178
extern void* gRspSegmentPhysAddrs[16]; // D_801F8180 extern u32 gRspSegmentPhysAddrs[16]; // D_801F8180
extern SchedThreadStruct schedContext; // D_801F81C0 extern SchedThreadStruct schedContext; // D_801F81C0
extern OSMesgQueueListNode mainIrqmgrCallbackNode; // D_801F84F8 extern OSMesgQueueListNode mainIrqmgrCallbackNode; // D_801F84F8
extern OSMesgQueue mainIrqmgrCallbackQueue; // D_801F8500 extern OSMesgQueue mainIrqmgrCallbackQueue; // D_801F8500

View File

@ -215,9 +215,8 @@ void Actor_SetScale(Actor* actor, f32 scale) {
} }
void Actor_SetObjectSegment(GlobalContext* ctxt, Actor* actor) { void Actor_SetObjectSegment(GlobalContext* ctxt, Actor* actor) {
// TODO: PHYSICAL_TO_VIRTUAL macro
// TODO: Segment number enum // TODO: Segment number enum
gRspSegmentPhysAddrs[6] = (void*)((u32)ctxt->sceneContext.objects[actor->objBankIndex].vramAddr + 0x80000000); gRspSegmentPhysAddrs[6] = PHYSICAL_TO_VIRTUAL(ctxt->sceneContext.objects[actor->objBankIndex].vramAddr);
} }
#ifdef NON_MATCHING #ifdef NON_MATCHING

View File

@ -607,9 +607,8 @@ f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) {
void Lib_Nop801004FC(void) {} void Lib_Nop801004FC(void) {}
void* Lib_PtrSegToVirt(void* ptr) { void* Lib_PtrSegToVirt(void* ptr) {
// TODO: PHYSICAL_TO_VIRTUAL macro
// UB to cast the pointer to u32 // UB to cast the pointer to u32
return (void*)(((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000); return (void*)PHYSICAL_TO_VIRTUAL((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF));
} }
void* Lib_PtrSegToVirtNull(void* ptr) { void* Lib_PtrSegToVirtNull(void* ptr) {
@ -618,17 +617,15 @@ void* Lib_PtrSegToVirtNull(void* ptr) {
return ptr; return ptr;
} }
// TODO: PHYSICAL_TO_VIRTUAL macro
// UB to cast the pointer to u32 // UB to cast the pointer to u32
return (void*)(((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF)) + 0x80000000); return (void*)PHYSICAL_TO_VIRTUAL((u32)gRspSegmentPhysAddrs[((u32)ptr << 4) >> 28] + ((u32)ptr & 0xFFFFFF));
} }
void* Lib_PtrSegToK0(void* ptr) { void* Lib_PtrSegToK0(void* ptr) {
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} else { } else {
// TODO: PHYSICAL_TO_VIRTUAL macro return (void*)PHYSICAL_TO_VIRTUAL(ptr);
return (void*)((u32)ptr + 0x80000000);
} }
} }
@ -636,7 +633,6 @@ void* Lib_PtrSegToK0Null(void* ptr) {
if (ptr == NULL) { if (ptr == NULL) {
return NULL; return NULL;
} else { } else {
// TODO: PHYSICAL_TO_VIRTUAL macro return (void*)PHYSICAL_TO_VIRTUAL(ptr);
return (void*)((u32)ptr + 0x80000000);
} }
} }

View File

@ -109,9 +109,8 @@ s32 Room_HandleLoadCallbacks(GlobalContext* ctxt, RoomContext* roomCtxt) {
{ {
roomCtxt->unk31 = 0; roomCtxt->unk31 = 0;
roomCtxt->currRoom.segment = roomCtxt->activeRoomVram; roomCtxt->currRoom.segment = roomCtxt->activeRoomVram;
// TODO: PHYSICAL_TO_VIRTUAL macro
// TODO: Segment number enum // TODO: Segment number enum
gRspSegmentPhysAddrs[3] = (void*)((u32)roomCtxt->activeRoomVram + 0x80000000); gRspSegmentPhysAddrs[3] = PHYSICAL_TO_VIRTUAL(roomCtxt->activeRoomVram);
Scene_ProcessHeader(ctxt, (SceneCmd*)roomCtxt->currRoom.segment); Scene_ProcessHeader(ctxt, (SceneCmd*)roomCtxt->currRoom.segment);
func_80123140(ctxt, (ActorPlayer*)ctxt->actorCtx.actorList[2].first); func_80123140(ctxt, (ActorPlayer*)ctxt->actorCtx.actorList[2].first);
@ -135,9 +134,8 @@ s32 Room_HandleLoadCallbacks(GlobalContext* ctxt, RoomContext* roomCtxt) {
void Room_Draw(GlobalContext* ctxt, Room* room, u32 flags) { void Room_Draw(GlobalContext* ctxt, Room* room, u32 flags) {
if (room->segment != NULL) { if (room->segment != NULL) {
// TODO: PHYSICAL_TO_VIRTUAL macro
// TODO: Segment number enum // TODO: Segment number enum
gRspSegmentPhysAddrs[3] = (void*)((u32)room->segment + 0x80000000); gRspSegmentPhysAddrs[3] = PHYSICAL_TO_VIRTUAL(room->segment);
roomDrawFuncs[room->mesh->type0.type](ctxt, room, flags); roomDrawFuncs[room->mesh->type0.type](ctxt, room, flags);
} }
return; return;

View File

@ -5,10 +5,9 @@
TODO: TODO:
There are a few issues left with this file, but many rely on larger structural project changes. There are a few issues left with this file, but many rely on larger structural project changes.
I am avoiding these in the mean time in order to not break the Ghidra project structures. I am avoiding these in the mean time in order to not break the Ghidra project structures.
We need a header file for just z_scene. Including relevant structs, Scene, and Object enums. We need a header file for just z_scene. Including relevant structs, scene, and object enums.
Needs definition for OBJECT_EXCHANGE_BANK_MAX
The .data, .bss, and .rodata sections are not migrated to this file yet. The .data, .bss, and .rodata sections are not migrated to this file yet.
Additionally we need a macro header file for ALIGN16, PHYSICAL_TO_VIRTUAL, OBJECT_EXCHANGE_BANK_MAX and other global macros.
*/ */
s32 Scene_LoadObject(SceneContext* sceneCtxt, s16 id) { s32 Scene_LoadObject(SceneContext* sceneCtxt, s16 id) {
@ -26,8 +25,8 @@ s32 Scene_LoadObject(SceneContext* sceneCtxt, s16 id) {
// TODO: This 0x22 is OBJECT_EXCHANGE_BANK_MAX - 1 in OOT // TODO: This 0x22 is OBJECT_EXCHANGE_BANK_MAX - 1 in OOT
if (sceneCtxt->objectCount < 0x22) { if (sceneCtxt->objectCount < 0x22) {
sceneCtxt->objects[sceneCtxt->objectCount + 1].vramAddr = sceneCtxt->objects[sceneCtxt->objectCount + 1].vramAddr =
// TODO: ALIGN16 macro here // UB to cast pointer to u32
(void*)((((u32)sceneCtxt->objects[sceneCtxt->objectCount].vramAddr + size) + 0xF) & ~0xF); (void*)ALIGN16((u32)sceneCtxt->objects[sceneCtxt->objectCount].vramAddr + size);
} }
sceneCtxt->objectCount++; sceneCtxt->objectCount++;
@ -66,9 +65,8 @@ void Scene_Init(GlobalContext* ctxt, SceneContext* sceneCtxt) {
sceneCtxt->objectVramEnd = (void*)((u32)sceneCtxt->objectVramStart + spaceSize); sceneCtxt->objectVramEnd = (void*)((u32)sceneCtxt->objectVramStart + spaceSize);
// TODO: Second argument here is an object enum // TODO: Second argument here is an object enum
sceneCtxt->mainKeepIndex = Scene_LoadObject(sceneCtxt, 1); sceneCtxt->mainKeepIndex = Scene_LoadObject(sceneCtxt, 1);
// TODO: PHYSICAL_TO_VIRTUAL macro
// TODO: Segment number enum // TODO: Segment number enum
gRspSegmentPhysAddrs[4] = (void*)((u32)sceneCtxt->objects[sceneCtxt->mainKeepIndex].vramAddr + 0x80000000); gRspSegmentPhysAddrs[4] = PHYSICAL_TO_VIRTUAL(sceneCtxt->objects[sceneCtxt->mainKeepIndex].vramAddr);
} }
void Scene_ReloadUnloadedObjects(SceneContext* sceneCtxt) { void Scene_ReloadUnloadedObjects(SceneContext* sceneCtxt) {
@ -148,7 +146,7 @@ void* func_8012F73C(SceneContext* sceneCtxt, s32 iParm2, s16 id) {
// TODO: UB to cast void to u32 // TODO: UB to cast void to u32
addr = ((u32)sceneCtxt->objects[iParm2].vramAddr) + vromSize; addr = ((u32)sceneCtxt->objects[iParm2].vramAddr) + vromSize;
// TODO: This is ALIGN16 macro from OOT. Seems to be aligning an address to DMA // TODO: This is ALIGN16 macro from OOT. Seems to be aligning an address to DMA
addr = (addr + 0xF) & ~0xF; addr = ALIGN16(addr);
// UB to cast u32 to pointer // UB to cast u32 to pointer
return (void*)addr; return (void*)addr;
} }
@ -236,10 +234,9 @@ void Scene_HeaderCommand07(GlobalContext* ctxt, SceneCmd* entry) {
if (entry->specialFiles.keepObjectId != 0) { if (entry->specialFiles.keepObjectId != 0) {
ctxt->sceneContext.keepObjectId = Scene_LoadObject(&ctxt->sceneContext, ctxt->sceneContext.keepObjectId = Scene_LoadObject(&ctxt->sceneContext,
entry->specialFiles.keepObjectId); entry->specialFiles.keepObjectId);
// TODO: PHYSICAL_TO_VIRTUAL macro
// TODO: Segment number enum // TODO: Segment number enum
gRspSegmentPhysAddrs[5] = (void*)((u32)(ctxt->sceneContext.objects[ctxt->sceneContext.keepObjectId].vramAddr) gRspSegmentPhysAddrs[5] =
+ 0x80000000); PHYSICAL_TO_VIRTUAL(ctxt->sceneContext.objects[ctxt->sceneContext.keepObjectId].vramAddr);
} }
if (entry->specialFiles.cUpElfMsgNum != 0) { if (entry->specialFiles.cUpElfMsgNum != 0) {