diff options
| author | Kenix3 <kenixwhisperwind@gmail.com> | 2020-06-04 23:07:09 -0400 |
|---|---|---|
| committer | Kenix3 <kenixwhisperwind@gmail.com> | 2020-06-04 23:07:09 -0400 |
| commit | 5c97d35841f99bbb23dffa797475f16ec1e3403b (patch) | |
| tree | 3807897f537f4a6ca0a2317332a401d0f35df249 /src | |
| parent | 664182c2899ba341be31f4cd7364a74867ee422c (diff) | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/code/z_actor.c | 3 | ||||
| -rw-r--r-- | src/code/z_lib.c | 12 | ||||
| -rw-r--r-- | src/code/z_room.c | 6 | ||||
| -rw-r--r-- | src/code/z_scene.c | 19 |
4 files changed, 15 insertions, 25 deletions
diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 2a7abb458..c792a6b1e 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -215,9 +215,8 @@ void Actor_SetScale(Actor* actor, f32 scale) { } void Actor_SetObjectSegment(GlobalContext* ctxt, Actor* actor) { - // TODO: PHYSICAL_TO_VIRTUAL macro // 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 diff --git a/src/code/z_lib.c b/src/code/z_lib.c index f4209e98b..101af60d9 100644 --- a/src/code/z_lib.c +++ b/src/code/z_lib.c @@ -607,9 +607,8 @@ f32 Lib_PushAwayVec3f(Vec3f* start, Vec3f* pusher, f32 distanceToApproach) { void Lib_Nop801004FC(void) {} void* Lib_PtrSegToVirt(void* ptr) { - // TODO: PHYSICAL_TO_VIRTUAL macro // 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) { @@ -618,17 +617,15 @@ void* Lib_PtrSegToVirtNull(void* ptr) { return ptr; } - // TODO: PHYSICAL_TO_VIRTUAL macro // 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) { if (ptr == NULL) { return NULL; } else { - // TODO: PHYSICAL_TO_VIRTUAL macro - return (void*)((u32)ptr + 0x80000000); + return (void*)PHYSICAL_TO_VIRTUAL(ptr); } } @@ -636,7 +633,6 @@ void* Lib_PtrSegToK0Null(void* ptr) { if (ptr == NULL) { return NULL; } else { - // TODO: PHYSICAL_TO_VIRTUAL macro - return (void*)((u32)ptr + 0x80000000); + return (void*)PHYSICAL_TO_VIRTUAL(ptr); } }
\ No newline at end of file diff --git a/src/code/z_room.c b/src/code/z_room.c index 5e8e6d42e..390783018 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -109,9 +109,8 @@ s32 Room_HandleLoadCallbacks(GlobalContext* ctxt, RoomContext* roomCtxt) { { roomCtxt->unk31 = 0; roomCtxt->currRoom.segment = roomCtxt->activeRoomVram; - // TODO: PHYSICAL_TO_VIRTUAL macro // 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); 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) { if (room->segment != NULL) { - // TODO: PHYSICAL_TO_VIRTUAL macro // 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); } return; diff --git a/src/code/z_scene.c b/src/code/z_scene.c index 79422d7ae..9d0f89fd1 100644 --- a/src/code/z_scene.c +++ b/src/code/z_scene.c @@ -5,10 +5,9 @@ TODO: 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. -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. - -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) { @@ -26,8 +25,8 @@ s32 Scene_LoadObject(SceneContext* sceneCtxt, s16 id) { // TODO: This 0x22 is OBJECT_EXCHANGE_BANK_MAX - 1 in OOT if (sceneCtxt->objectCount < 0x22) { sceneCtxt->objects[sceneCtxt->objectCount + 1].vramAddr = - // TODO: ALIGN16 macro here - (void*)((((u32)sceneCtxt->objects[sceneCtxt->objectCount].vramAddr + size) + 0xF) & ~0xF); + // UB to cast pointer to u32 + (void*)ALIGN16((u32)sceneCtxt->objects[sceneCtxt->objectCount].vramAddr + size); } sceneCtxt->objectCount++; @@ -66,9 +65,8 @@ void Scene_Init(GlobalContext* ctxt, SceneContext* sceneCtxt) { sceneCtxt->objectVramEnd = (void*)((u32)sceneCtxt->objectVramStart + spaceSize); // TODO: Second argument here is an object enum sceneCtxt->mainKeepIndex = Scene_LoadObject(sceneCtxt, 1); - // TODO: PHYSICAL_TO_VIRTUAL macro // 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) { @@ -148,7 +146,7 @@ void* func_8012F73C(SceneContext* sceneCtxt, s32 iParm2, s16 id) { // TODO: UB to cast void to u32 addr = ((u32)sceneCtxt->objects[iParm2].vramAddr) + vromSize; // 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 return (void*)addr; } @@ -236,10 +234,9 @@ void Scene_HeaderCommand07(GlobalContext* ctxt, SceneCmd* entry) { if (entry->specialFiles.keepObjectId != 0) { ctxt->sceneContext.keepObjectId = Scene_LoadObject(&ctxt->sceneContext, entry->specialFiles.keepObjectId); - // TODO: PHYSICAL_TO_VIRTUAL macro // TODO: Segment number enum - gRspSegmentPhysAddrs[5] = (void*)((u32)(ctxt->sceneContext.objects[ctxt->sceneContext.keepObjectId].vramAddr) - + 0x80000000); + gRspSegmentPhysAddrs[5] = + PHYSICAL_TO_VIRTUAL(ctxt->sceneContext.objects[ctxt->sceneContext.keepObjectId].vramAddr); } if (entry->specialFiles.cUpElfMsgNum != 0) { |
