1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-07-04 06:54:33 +00:00

Decompile sleep.c and printutils.c

- Decompile sleep.c (OK)
- Decompile printutils.c (OK)
- Fix 1 non-matching in z_room.c
- Get rid of some magic numbers
This commit is contained in:
Random 2020-04-08 18:36:15 +02:00
parent 0a25ab74c4
commit d0cf6e153b
20 changed files with 94 additions and 308 deletions

View file

@ -711,7 +711,7 @@ void __osDisplayArena(Arena* arena) {
iter->size);
if (!iter->isFree) {
osSyncPrintf(" [%016llu:%2d:%s:%d]", (iter->time * 64ll) / 3ull, iter->threadId,
osSyncPrintf(" [%016llu:%2d:%s:%d]", OS_CYCLES_TO_NSEC(iter->time), iter->threadId,
iter->filename ? iter->filename : "**NULL**", iter->line);
}

View file

@ -9,7 +9,7 @@ u32 D_8012DBC0 = false;
void func_800D31A0() {
osSyncPrintf(VT_FGCOL(RED) "\n**** Freeze!! ****\n" VT_RST);
while (true) {
func_800FF4AC(1000); // msleep
Sleep_Msec(1000);
}
}

View file

@ -2,6 +2,7 @@
#include <global.h>
#include <alloca.h>
#include <vt.h>
#include <PR/os_cont.h>
// data
const char* sExceptionNames[] = {
@ -42,7 +43,7 @@ FaultThreadStruct gFaultStruct;
void Fault_SleepImpl(u32 duration) {
u64 value = (duration * OS_CPU_COUNTER) / 1000ull;
func_800FF3A0(value);
Sleep_Cycles(value);
}
void Fault_ClientProcessThread(FaultClientContext* ctx) {
@ -582,7 +583,7 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) {
count--;
Fault_Sleep(0x10);
Fault_UpdatePadImpl();
if (!~(curInput->padPressed | ~0x20)) {
if (!~(curInput->padPressed | ~L_TRIG)) {
sFaultStructPtr->faultActive = false;
}
}
@ -592,40 +593,40 @@ void Fault_DrawMemDump(u32 pc, u32 sp, u32 unk0, u32 unk1) {
Fault_UpdatePadImpl();
} while (curInput->padPressed == 0);
if (!~(curInput->padPressed | ~0x1000)) {
if (!~(curInput->padPressed | ~START_BUTTON)) {
return;
}
if (!~(curInput->raw.pad | ~0x8000)) {
if (!~(curInput->raw.pad | ~A_BUTTON)) {
return;
}
off = 0x10;
if (!~(curInput->raw.pad | ~0x2000)) {
if (!~(curInput->raw.pad | ~Z_TRIG)) {
off = 0x100;
}
if (!~(curInput->raw.pad | ~0x4000)) {
if (!~(curInput->raw.pad | ~B_BUTTON)) {
off <<= 8;
}
if (!~(curInput->raw.pad | ~0x800)) {
if (!~(curInput->raw.pad | ~U_JPAD)) {
addr -= off;
}
if (!~(curInput->raw.pad | ~0x400)) {
if (!~(curInput->raw.pad | ~D_JPAD)) {
addr += off;
}
if (!~(curInput->raw.pad | ~0x8)) {
if (!~(curInput->raw.pad | ~U_CBUTTONS)) {
addr = pc;
}
if (!~(curInput->raw.pad | ~0x4)) {
if (!~(curInput->raw.pad | ~D_CBUTTONS)) {
addr = sp;
}
if (!~(curInput->raw.pad | ~0x2)) {
if (!~(curInput->raw.pad | ~L_CBUTTONS)) {
addr = unk0;
}
if (!~(curInput->raw.pad | ~0x1)) {
if (!~(curInput->raw.pad | ~R_CBUTTONS)) {
addr = unk1;
}
if (!~(curInput->raw.pad | ~0x20)) {
if (!~(curInput->raw.pad | ~L_TRIG)) {
break;
}
}

View file

@ -388,7 +388,7 @@ Gfx* GfxPrint_Close(GfxPrint* this) {
}
void GfxPrint_VPrintf(GfxPrint* this, const char* fmt, va_list args) {
func_800FF340(&this->callback, fmt, args);
PrintUtils_VPrintf(&this->callback, fmt, args);
}
void GfxPrint_Printf(GfxPrint* this, const char* fmt, ...) {

View file

@ -233,7 +233,7 @@ void PadMgr_Run(PadMgr* padmgr) {
while (bVar2 == 0) {
if ((D_8012D280 > 2) && (padmgr->queue3.validCount == 0)) {
// EUC-JP: コントローラスレッドイベント待ち | Waiting for controller thread event
osSyncPrintf("コントローラスレッドイベント待ち %lld\n", (osGetTime() * 64) / 3000);
osSyncPrintf("コントローラスレッドイベント待ち %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
}
osRecvMesg(&padmgr->queue3, &mesg, OS_MESG_BLOCK);
@ -242,13 +242,13 @@ void PadMgr_Run(PadMgr* padmgr) {
switch (*mesg) {
case OS_SC_RETRACE_MSG:
if (D_8012D280 > 2) {
osSyncPrintf("padmgr_HandleRetraceMsg START %lld\n", (osGetTime() * 64) / 3000);
osSyncPrintf("padmgr_HandleRetraceMsg START %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
}
func_800C7C14(padmgr);
if (D_8012D280 > 2) {
osSyncPrintf("padmgr_HandleRetraceMsg END %lld\n", (osGetTime() * 64) / 3000);
osSyncPrintf("padmgr_HandleRetraceMsg END %lld\n", OS_CYCLES_TO_USEC(osGetTime()));
}
break;

14
src/code/printutils.c Normal file
View file

@ -0,0 +1,14 @@
#include <global.h>
void PrintUtils_VPrintf(char** arg0, const char* fmt, va_list args)
{
_Printf(*arg0, arg0, fmt, args);
}
void PrintUtils_Printf(void* arg0, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
PrintUtils_VPrintf(arg0, fmt, args);
}

View file

@ -35,7 +35,7 @@ void func_800C8910(SchedContext* sc) {
osSpTaskYield();
if (D_8012D290 != 0) {
osSyncPrintf("%08d:osSpTaskYield\n", (u32)((osGetTime() * 64) / 3000));
osSyncPrintf("%08d:osSpTaskYield\n", (u32)(OS_CYCLES_TO_USEC(osGetTime())));
}
}
}

33
src/code/sleep.c Normal file
View file

@ -0,0 +1,33 @@
#include <global.h>
void Sleep_Cycles(OSTime cycles)
{
OSMesgQueue mq;
OSMesg msg;
OSTimer timer;
osCreateMesgQueue(&mq, &msg, OS_MESG_BLOCK);
osSetTimer(&timer, cycles, 0, &mq, NULL);
osRecvMesg(&mq, NULL, OS_MESG_BLOCK);
}
void Sleep_Nsec(u32 nsec)
{
Sleep_Cycles(OS_NSEC_TO_CYCLES(nsec));
}
void Sleep_Usec(u32 usec)
{
Sleep_Cycles(OS_USEC_TO_CYCLES(usec));
}
// originally "msleep"
void Sleep_Msec(u32 ms)
{
Sleep_Cycles((ms * OS_CPU_COUNTER) / 1000ull);
}
void Sleep_Sec(u32 sec)
{
Sleep_Cycles((sec * OS_CPU_COUNTER));
}

View file

@ -114,7 +114,7 @@ void func_8006390C(Input* input) {
s32 i;
regGroup = (gGameInfo->regGroup * REG_PAGES + gGameInfo->regPage) * REG_PER_PAGE - REG_PER_PAGE;
dpad = input->raw.pad & 0xF00;
dpad = input->raw.pad & (U_JPAD | L_JPAD | R_JPAD | D_JPAD);
if (!~(input->raw.pad | ~L_TRIG) || !~(input->raw.pad | ~R_TRIG) || !~(input->raw.pad | ~START_BUTTON)) {
input_combo = inputCombos;
for (i = 0; i < REG_GROUPS; i++) {

View file

@ -444,15 +444,15 @@ void Cutscene_Command_Terminator(GlobalContext* globalCtx, CutsceneContext* csCt
if ((gSaveContext.game_mode != 0) && (gSaveContext.game_mode != 3) && (globalCtx->sceneNum != SCENE_SPOT00) &&
(csCtx->frames > 20) &&
(!~(globalCtx->state.input[0].padPressed | 0xFFFF7FFF) || !~(globalCtx->state.input[0].padPressed | -0x4001) ||
!~(globalCtx->state.input[0].padPressed | -0x1001)) &&
(!~(globalCtx->state.input[0].padPressed | ~A_BUTTON) || !~(globalCtx->state.input[0].padPressed | ~B_BUTTON) ||
!~(globalCtx->state.input[0].padPressed | ~START_BUTTON)) &&
(gSaveContext.file_num != 0xFEDC) && (globalCtx->sceneLoadFlag == 0)) {
Audio_PlaySoundGeneral(NA_SE_SY_PIECE_OF_HEART, &D_801333D4, 4, &D_801333E0, &D_801333E0, &D_801333E8);
temp = 1;
}
if ((csCtx->frames == cmd->startFrame) || (temp != 0) ||
((csCtx->frames > 20) && (!~(globalCtx->state.input[0].padPressed | -0x1001)) &&
((csCtx->frames > 20) && (!~(globalCtx->state.input[0].padPressed | ~START_BUTTON)) &&
(gSaveContext.file_num != 0xFEDC))) {
csCtx->state = CS_STATE_UNSKIPPABLE_EXEC;
func_800F68BC(0);
@ -1524,7 +1524,7 @@ void Cutscene_ProcessCommands(GlobalContext* globalCtx, CutsceneContext* csCtx,
return;
}
if (!~(globalCtx->state.input[0].padPressed | -0x101)) {
if (!~(globalCtx->state.input[0].padPressed | ~R_JPAD)) {
csCtx->state = CS_STATE_UNSKIPPABLE_INIT;
return;
}

View file

@ -1,6 +1,7 @@
#include <ultra64.h>
#include <global.h>
#include <vt.h>
#include <PR/os_cont.h>
typedef struct {
/* 0x00 */ u8 scene;
@ -3981,13 +3982,13 @@ void Interface_Update(GlobalContext* globalCtx) {
u16 action;
Input* input = &globalCtx->state.input[2];
if (!~(input->padPressed | -0x201)) {
if (!~(input->padPressed | ~L_JPAD)) {
gSaveContext.language = 0;
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
} else if (!~(input->padPressed | -0x801)) {
} else if (!~(input->padPressed | ~U_JPAD)) {
gSaveContext.language = 1;
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
} else if (!~(input->padPressed | -0x101)) {
} else if (!~(input->padPressed | ~R_JPAD)) {
gSaveContext.language = 2;
osSyncPrintf("J_N=%x J_N=%x\n", gSaveContext.language, &gSaveContext.language);
}

View file

@ -230,11 +230,7 @@ void func_80095D04(GlobalContext* globalCtx, Room* room, u32 flags) {
#define JPEG_MARKER 0xFFD8FFE0
#ifdef NON_MATCHING
// long multiplication by 64 doesn't quite match
s32 func_80096238(void* data) {
OSTime timeBefore;
OSTime timeAfter;
OSTime time;
if (*(u32*)data == JPEG_MARKER) {
@ -245,13 +241,12 @@ s32 func_80096238(void* data) {
// Translates to: "WORK BUFFER ADDRESS (Z BUFFER) %08x"
osSyncPrintf("ワークバッファアドレス(Zバッファ)%08x\n", gZBuffer);
timeBefore = osGetTime();
time = osGetTime();
if (!func_8006E418(data, gZBuffer, gGfxSPTaskOutputBuffer, sizeof(gGfxSPTaskOutputBuffer))) {
timeAfter = osGetTime();
time = ((timeAfter - timeBefore) * 64) / 3000;
time = osGetTime() - time;
// Translates to: "SUCCESS... I THINK. time = %6.3f ms"
osSyncPrintf("成功…だと思う。 time = %6.3f ms \n", (f64)(time / 1000.0f));
osSyncPrintf("成功…だと思う。 time = %6.3f ms \n", (f64)(OS_CYCLES_TO_USEC(time) / 1000.0f));
// Translates to: "WRITING BACK TO ORIGINAL ADDRESS FROM WORK BUFFER."
osSyncPrintf("ワークバッファから元のアドレスに書き戻します。\n");
// Translates to: "IF THE ORIGINAL BUFFER SIZE ISN'T AT LEAST 150KB, IT WILL BE OUT OF CONTROL."
@ -266,9 +261,6 @@ s32 func_80096238(void* data) {
return 0;
}
#else
#pragma GLOBAL_ASM("asm/non_matchings/code/z_room/func_80096238.s")
#endif
#ifdef NON_MATCHING
// pointer arithmetic doesn't quite match