From d0cf6e153b4f47f04f73656a1534314208b2f596 Mon Sep 17 00:00:00 2001 From: Random <28494085+Random06457@users.noreply.github.com> Date: Wed, 8 Apr 2020 18:36:15 +0200 Subject: [PATCH] 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 --- asm/{code_800FF340.s => code_800FF540.s} | 142 ------------------ .../code/z_fbdemo/func_800B1DBC.s | 2 +- asm/non_matchings/code/z_room/func_80096238.s | 120 --------------- .../actors/ovl_kaleido_scope/func_8081F2FC.s | 2 +- include/functions.h | 9 +- spec | 4 +- src/code/__osMalloc.c | 2 +- src/code/code_800D31A0.c | 2 +- src/code/fault.c | 27 ++-- src/code/gfxprint.c | 2 +- src/code/padmgr.c | 6 +- src/code/printutils.c | 14 ++ src/code/sched.c | 2 +- src/code/sleep.c | 33 ++++ src/code/z_debug.c | 2 +- src/code/z_demo.c | 8 +- src/code/z_parameter.c | 7 +- src/code/z_room.c | 14 +- src/libultra_boot_O1/initialize.c | 2 +- .../actors/ovl_En_Wallmas/z_en_wallmas.c | 2 +- 20 files changed, 94 insertions(+), 308 deletions(-) rename asm/{code_800FF340.s => code_800FF540.s} (72%) delete mode 100644 asm/non_matchings/code/z_room/func_80096238.s create mode 100644 src/code/printutils.c create mode 100644 src/code/sleep.c diff --git a/asm/code_800FF340.s b/asm/code_800FF540.s similarity index 72% rename from asm/code_800FF340.s rename to asm/code_800FF540.s index dab139f9d5..665d133360 100644 --- a/asm/code_800FF340.s +++ b/asm/code_800FF540.s @@ -9,148 +9,6 @@ .align 4 -glabel func_800FF340 -/* B764E0 800FF340 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B764E4 800FF344 AFA5001C */ sw $a1, 0x1c($sp) -/* B764E8 800FF348 00802825 */ move $a1, $a0 -/* B764EC 800FF34C AFBF0014 */ sw $ra, 0x14($sp) -/* B764F0 800FF350 AFA40018 */ sw $a0, 0x18($sp) -/* B764F4 800FF354 00C03825 */ move $a3, $a2 -/* B764F8 800FF358 8FA6001C */ lw $a2, 0x1c($sp) -/* B764FC 800FF35C 0C0014B8 */ jal _Printf -/* B76500 800FF360 8C840000 */ lw $a0, ($a0) -/* B76504 800FF364 8FBF0014 */ lw $ra, 0x14($sp) -/* B76508 800FF368 27BD0018 */ addiu $sp, $sp, 0x18 -/* B7650C 800FF36C 03E00008 */ jr $ra -/* B76510 800FF370 00000000 */ nop - -glabel func_800FF374 -/* B76514 800FF374 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* B76518 800FF378 AFBF0014 */ sw $ra, 0x14($sp) -/* B7651C 800FF37C AFA60028 */ sw $a2, 0x28($sp) -/* B76520 800FF380 AFA50024 */ sw $a1, 0x24($sp) -/* B76524 800FF384 AFA7002C */ sw $a3, 0x2c($sp) -/* B76528 800FF388 0C03FCD0 */ jal func_800FF340 -/* B7652C 800FF38C 27A60028 */ addiu $a2, $sp, 0x28 -/* B76530 800FF390 8FBF0014 */ lw $ra, 0x14($sp) -/* B76534 800FF394 27BD0020 */ addiu $sp, $sp, 0x20 -/* B76538 800FF398 03E00008 */ jr $ra -/* B7653C 800FF39C 00000000 */ nop - -glabel func_800FF3A0 -/* B76540 800FF3A0 27BDFF98 */ addiu $sp, $sp, -0x68 -/* B76544 800FF3A4 AFBF0024 */ sw $ra, 0x24($sp) -/* B76548 800FF3A8 AFA40068 */ sw $a0, 0x68($sp) -/* B7654C 800FF3AC AFA5006C */ sw $a1, 0x6c($sp) -/* B76550 800FF3B0 27A5004C */ addiu $a1, $sp, 0x4c -/* B76554 800FF3B4 27A40050 */ addiu $a0, $sp, 0x50 -/* B76558 800FF3B8 0C001874 */ jal osCreateMesgQueue -/* B7655C 800FF3BC 24060001 */ li $a2, 1 -/* B76560 800FF3C0 240E0000 */ li $t6, 0 -/* B76564 800FF3C4 240F0000 */ li $t7, 0 -/* B76568 800FF3C8 27B80050 */ addiu $t8, $sp, 0x50 -/* B7656C 800FF3CC AFB80018 */ sw $t8, 0x18($sp) -/* B76570 800FF3D0 AFAF0014 */ sw $t7, 0x14($sp) -/* B76574 800FF3D4 AFAE0010 */ sw $t6, 0x10($sp) -/* B76578 800FF3D8 27A40028 */ addiu $a0, $sp, 0x28 -/* B7657C 800FF3DC 8FA60068 */ lw $a2, 0x68($sp) -/* B76580 800FF3E0 8FA7006C */ lw $a3, 0x6c($sp) -/* B76584 800FF3E4 0C0418B8 */ jal osSetTimer -/* B76588 800FF3E8 AFA0001C */ sw $zero, 0x1c($sp) -/* B7658C 800FF3EC 27A40050 */ addiu $a0, $sp, 0x50 -/* B76590 800FF3F0 00002825 */ move $a1, $zero -/* B76594 800FF3F4 0C000CA0 */ jal osRecvMesg -/* B76598 800FF3F8 24060001 */ li $a2, 1 -/* B7659C 800FF3FC 8FBF0024 */ lw $ra, 0x24($sp) -/* B765A0 800FF400 27BD0068 */ addiu $sp, $sp, 0x68 -/* B765A4 800FF404 03E00008 */ jr $ra -/* B765A8 800FF408 00000000 */ nop - -glabel func_800FF40C -/* B765AC 800FF40C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B765B0 800FF410 AFBF0014 */ sw $ra, 0x14($sp) -/* B765B4 800FF414 AFA40018 */ sw $a0, 0x18($sp) -/* B765B8 800FF418 00802825 */ move $a1, $a0 -/* B765BC 800FF41C 24040000 */ li $a0, 0 -/* B765C0 800FF420 24060000 */ li $a2, 0 -/* B765C4 800FF424 0C000E1E */ jal __ll_mul -/* B765C8 800FF428 24070003 */ li $a3, 3 -/* B765CC 800FF42C 00402025 */ move $a0, $v0 -/* B765D0 800FF430 00602825 */ move $a1, $v1 -/* B765D4 800FF434 24060000 */ li $a2, 0 -/* B765D8 800FF438 0C000DDE */ jal __ull_div -/* B765DC 800FF43C 24070040 */ li $a3, 64 -/* B765E0 800FF440 00402025 */ move $a0, $v0 -/* B765E4 800FF444 0C03FCE8 */ jal func_800FF3A0 -/* B765E8 800FF448 00602825 */ move $a1, $v1 -/* B765EC 800FF44C 8FBF0014 */ lw $ra, 0x14($sp) -/* B765F0 800FF450 27BD0018 */ addiu $sp, $sp, 0x18 -/* B765F4 800FF454 03E00008 */ jr $ra -/* B765F8 800FF458 00000000 */ nop - -glabel func_800FF45C -/* B765FC 800FF45C 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B76600 800FF460 AFBF0014 */ sw $ra, 0x14($sp) -/* B76604 800FF464 AFA40018 */ sw $a0, 0x18($sp) -/* B76608 800FF468 00802825 */ move $a1, $a0 -/* B7660C 800FF46C 24040000 */ li $a0, 0 -/* B76610 800FF470 24060000 */ li $a2, 0 -/* B76614 800FF474 0C000E1E */ jal __ll_mul -/* B76618 800FF478 24070BB8 */ li $a3, 3000 -/* B7661C 800FF47C 00402025 */ move $a0, $v0 -/* B76620 800FF480 00602825 */ move $a1, $v1 -/* B76624 800FF484 24060000 */ li $a2, 0 -/* B76628 800FF488 0C000DDE */ jal __ull_div -/* B7662C 800FF48C 24070040 */ li $a3, 64 -/* B76630 800FF490 00402025 */ move $a0, $v0 -/* B76634 800FF494 0C03FCE8 */ jal func_800FF3A0 -/* B76638 800FF498 00602825 */ move $a1, $v1 -/* B7663C 800FF49C 8FBF0014 */ lw $ra, 0x14($sp) -/* B76640 800FF4A0 27BD0018 */ addiu $sp, $sp, 0x18 -/* B76644 800FF4A4 03E00008 */ jr $ra -/* B76648 800FF4A8 00000000 */ nop - -glabel func_800FF4AC -/* B7664C 800FF4AC 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B76650 800FF4B0 AFBF0014 */ sw $ra, 0x14($sp) -/* B76654 800FF4B4 AFA40018 */ sw $a0, 0x18($sp) -/* B76658 800FF4B8 00802825 */ move $a1, $a0 -/* B7665C 800FF4BC 3C0702CB */ lui $a3, (0x02CB4178 >> 16) # lui $a3, 0x2cb -/* B76660 800FF4C0 34E74178 */ ori $a3, (0x02CB4178 & 0xFFFF) # ori $a3, $a3, 0x4178 -/* B76664 800FF4C4 24040000 */ li $a0, 0 -/* B76668 800FF4C8 0C000E1E */ jal __ll_mul -/* B7666C 800FF4CC 24060000 */ li $a2, 0 -/* B76670 800FF4D0 00402025 */ move $a0, $v0 -/* B76674 800FF4D4 00602825 */ move $a1, $v1 -/* B76678 800FF4D8 24060000 */ li $a2, 0 -/* B7667C 800FF4DC 0C000DDE */ jal __ull_div -/* B76680 800FF4E0 240703E8 */ li $a3, 1000 -/* B76684 800FF4E4 00402025 */ move $a0, $v0 -/* B76688 800FF4E8 0C03FCE8 */ jal func_800FF3A0 -/* B7668C 800FF4EC 00602825 */ move $a1, $v1 -/* B76690 800FF4F0 8FBF0014 */ lw $ra, 0x14($sp) -/* B76694 800FF4F4 27BD0018 */ addiu $sp, $sp, 0x18 -/* B76698 800FF4F8 03E00008 */ jr $ra -/* B7669C 800FF4FC 00000000 */ nop - -glabel func_800FF500 -/* B766A0 800FF500 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B766A4 800FF504 AFBF0014 */ sw $ra, 0x14($sp) -/* B766A8 800FF508 AFA40018 */ sw $a0, 0x18($sp) -/* B766AC 800FF50C 00802825 */ move $a1, $a0 -/* B766B0 800FF510 3C0702CB */ lui $a3, (0x02CB4178 >> 16) # lui $a3, 0x2cb -/* B766B4 800FF514 34E74178 */ ori $a3, (0x02CB4178 & 0xFFFF) # ori $a3, $a3, 0x4178 -/* B766B8 800FF518 24040000 */ li $a0, 0 -/* B766BC 800FF51C 0C000E1E */ jal __ll_mul -/* B766C0 800FF520 24060000 */ li $a2, 0 -/* B766C4 800FF524 00402025 */ move $a0, $v0 -/* B766C8 800FF528 0C03FCE8 */ jal func_800FF3A0 -/* B766CC 800FF52C 00602825 */ move $a1, $v1 -/* B766D0 800FF530 8FBF0014 */ lw $ra, 0x14($sp) -/* B766D4 800FF534 27BD0018 */ addiu $sp, $sp, 0x18 -/* B766D8 800FF538 03E00008 */ jr $ra -/* B766DC 800FF53C 00000000 */ nop - glabel func_800FF540 /* B766E0 800FF540 30C300FF */ andi $v1, $a2, 0xff /* B766E4 800FF544 00A03825 */ move $a3, $a1 diff --git a/asm/non_matchings/code/z_fbdemo/func_800B1DBC.s b/asm/non_matchings/code/z_fbdemo/func_800B1DBC.s index e971fd3916..1918456d44 100644 --- a/asm/non_matchings/code/z_fbdemo/func_800B1DBC.s +++ b/asm/non_matchings/code/z_fbdemo/func_800B1DBC.s @@ -36,7 +36,7 @@ glabel func_800B1DBC /* B28F7C 800B1DDC 3C048014 */ lui $a0, %hi(D_80142F58) # $a0, 0x8014 /* B28F80 800B1DE0 0C00084C */ jal osSyncPrintf /* B28F84 800B1DE4 24842F58 */ addiu $a0, %lo(D_80142F58) # addiu $a0, $a0, 0x2f58 -/* B28F88 800B1DE8 0C03FD2B */ jal func_800FF4AC +/* B28F88 800B1DE8 0C03FD2B */ jal Sleep_Msec /* B28F8C 800B1DEC 24040064 */ li $a0, 100 /* B28F90 800B1DF0 8E04000C */ lw $a0, 0xc($s0) /* B28F94 800B1DF4 3C058014 */ lui $a1, %hi(D_80142F68) # $a1, 0x8014 diff --git a/asm/non_matchings/code/z_room/func_80096238.s b/asm/non_matchings/code/z_room/func_80096238.s deleted file mode 100644 index fac5877a24..0000000000 --- a/asm/non_matchings/code/z_room/func_80096238.s +++ /dev/null @@ -1,120 +0,0 @@ -.rdata -glabel D_8013EF8C - .asciz "JPEGデータを展開します\n" - .balign 4 - -glabel D_8013EFA4 - .asciz "JPEGデータアドレス %08x\n" - .balign 4 - -glabel D_8013EFC0 - .asciz "ワークバッファアドレス(Zバッファ)%08x\n" - .balign 4 - -glabel D_8013EFEC - .asciz "成功…だと思う。 time = %6.3f ms \n" - .balign 4 - -glabel D_8013F010 - .asciz "ワークバッファから元のアドレスに書き戻します。\n" - .balign 4 - -glabel D_8013F040 - .asciz "元のバッファのサイズが150キロバイト無いと暴走するでしょう。\n" - .balign 4 - -glabel D_8013F080 - .asciz "失敗!なんで〜\n" - .balign 4 - -.text -glabel func_80096238 -/* B0D3D8 80096238 27BDFFE0 */ addiu $sp, $sp, -0x20 -/* B0D3DC 8009623C AFBF0014 */ sw $ra, 0x14($sp) -/* B0D3E0 80096240 AFA40020 */ sw $a0, 0x20($sp) -/* B0D3E4 80096244 8C8F0000 */ lw $t7, ($a0) -/* B0D3E8 80096248 3C01FFD8 */ lui $at, (0xFFD8FFE0 >> 16) # lui $at, 0xffd8 -/* B0D3EC 8009624C 3421FFE0 */ ori $at, (0xFFD8FFE0 & 0xFFFF) # ori $at, $at, 0xffe0 -/* B0D3F0 80096250 15E10049 */ bne $t7, $at, .L80096378 -/* B0D3F4 80096254 3C048014 */ lui $a0, %hi(D_8013EF8C) # $a0, 0x8014 -/* B0D3F8 80096258 0C00084C */ jal osSyncPrintf -/* B0D3FC 8009625C 2484EF8C */ addiu $a0, %lo(D_8013EF8C) # addiu $a0, $a0, -0x1074 -/* B0D400 80096260 3C048014 */ lui $a0, %hi(D_8013EFA4) # $a0, 0x8014 -/* B0D404 80096264 2484EFA4 */ addiu $a0, %lo(D_8013EFA4) # addiu $a0, $a0, -0x105c -/* B0D408 80096268 0C00084C */ jal osSyncPrintf -/* B0D40C 8009626C 8FA50020 */ lw $a1, 0x20($sp) -/* B0D410 80096270 3C048014 */ lui $a0, %hi(D_8013EFC0) # $a0, 0x8014 -/* B0D414 80096274 3C058017 */ lui $a1, %hi(D_801759C0) # $a1, 0x8017 -/* B0D418 80096278 24A559C0 */ addiu $a1, %lo(D_801759C0) # addiu $a1, $a1, 0x59c0 -/* B0D41C 8009627C 0C00084C */ jal osSyncPrintf -/* B0D420 80096280 2484EFC0 */ addiu $a0, %lo(D_8013EFC0) # addiu $a0, $a0, -0x1040 -/* B0D424 80096284 0C001A78 */ jal osGetTime -/* B0D428 80096288 00000000 */ nop -/* B0D42C 8009628C 3C058017 */ lui $a1, %hi(D_801759C0) # $a1, 0x8017 -/* B0D430 80096290 3C06801A */ lui $a2, %hi(gGfxSPTaskOutputBuffer) # $a2, 0x801a -/* B0D434 80096294 3C070001 */ lui $a3, (0x00018000 >> 16) # lui $a3, 1 -/* B0D438 80096298 AFA20018 */ sw $v0, 0x18($sp) -/* B0D43C 8009629C AFA3001C */ sw $v1, 0x1c($sp) -/* B0D440 800962A0 34E78000 */ ori $a3, (0x00018000 & 0xFFFF) # ori $a3, $a3, 0x8000 -/* B0D444 800962A4 24C6B1C0 */ addiu $a2, %lo(gGfxSPTaskOutputBuffer) # addiu $a2, $a2, -0x4e40 -/* B0D448 800962A8 24A559C0 */ addiu $a1, %lo(D_801759C0) # addiu $a1, $a1, 0x59c0 -/* B0D44C 800962AC 0C01B906 */ jal func_8006E418 -/* B0D450 800962B0 8FA40020 */ lw $a0, 0x20($sp) -/* B0D454 800962B4 1440002E */ bnez $v0, .L80096370 -/* B0D458 800962B8 3C048014 */ lui $a0, %hi(D_8013F080) -/* B0D45C 800962BC 0C001A78 */ jal osGetTime -/* B0D460 800962C0 00000000 */ nop -/* B0D464 800962C4 8FB80018 */ lw $t8, 0x18($sp) -/* B0D468 800962C8 8FB9001C */ lw $t9, 0x1c($sp) -/* B0D46C 800962CC 24060000 */ li $a2, 0 -/* B0D470 800962D0 00584023 */ subu $t0, $v0, $t8 -/* B0D474 800962D4 0079082B */ sltu $at, $v1, $t9 -/* B0D478 800962D8 01012023 */ subu $a0, $t0, $at -/* B0D47C 800962DC 00792823 */ subu $a1, $v1, $t9 -/* B0D480 800962E0 AFA5001C */ sw $a1, 0x1c($sp) -/* B0D484 800962E4 AFA40018 */ sw $a0, 0x18($sp) -/* B0D488 800962E8 0C000E1E */ jal __ll_mul -/* B0D48C 800962EC 24070040 */ li $a3, 64 -/* B0D490 800962F0 00402025 */ move $a0, $v0 -/* B0D494 800962F4 00602825 */ move $a1, $v1 -/* B0D498 800962F8 24060000 */ li $a2, 0 -/* B0D49C 800962FC 0C000DDE */ jal __ull_div -/* B0D4A0 80096300 24070BB8 */ li $a3, 3000 -/* B0D4A4 80096304 00402025 */ move $a0, $v0 -/* B0D4A8 80096308 0C0419CA */ jal __ull_to_f -/* B0D4AC 8009630C 00602825 */ move $a1, $v1 -/* B0D4B0 80096310 3C01447A */ li $at, 0x447A0000 # 0.000000 -/* B0D4B4 80096314 44812000 */ mtc1 $at, $f4 -/* B0D4B8 80096318 3C048014 */ lui $a0, %hi(D_8013EFEC) # $a0, 0x8014 -/* B0D4BC 8009631C 2484EFEC */ addiu $a0, %lo(D_8013EFEC) # addiu $a0, $a0, -0x1014 -/* B0D4C0 80096320 46040183 */ div.s $f6, $f0, $f4 -/* B0D4C4 80096324 46003221 */ cvt.d.s $f8, $f6 -/* B0D4C8 80096328 44074000 */ mfc1 $a3, $f8 -/* B0D4CC 8009632C 44064800 */ mfc1 $a2, $f9 -/* B0D4D0 80096330 0C00084C */ jal osSyncPrintf -/* B0D4D4 80096334 00000000 */ nop -/* B0D4D8 80096338 3C048014 */ lui $a0, %hi(D_8013F010) # $a0, 0x8014 -/* B0D4DC 8009633C 0C00084C */ jal osSyncPrintf -/* B0D4E0 80096340 2484F010 */ addiu $a0, %lo(D_8013F010) # addiu $a0, $a0, -0xff0 -/* B0D4E4 80096344 3C048014 */ lui $a0, %hi(D_8013F040) # $a0, 0x8014 -/* B0D4E8 80096348 0C00084C */ jal osSyncPrintf -/* B0D4EC 8009634C 2484F040 */ addiu $a0, %lo(D_8013F040) # addiu $a0, $a0, -0xfc0 -/* B0D4F0 80096350 3C048017 */ lui $a0, %hi(D_801759C0) # $a0, 0x8017 -/* B0D4F4 80096354 3C060002 */ lui $a2, (0x00025800 >> 16) # lui $a2, 2 -/* B0D4F8 80096358 34C65800 */ ori $a2, (0x00025800 & 0xFFFF) # ori $a2, $a2, 0x5800 -/* B0D4FC 8009635C 248459C0 */ addiu $a0, %lo(D_801759C0) # addiu $a0, $a0, 0x59c0 -/* B0D500 80096360 0C001BC4 */ jal bcopy -/* B0D504 80096364 8FA50020 */ lw $a1, 0x20($sp) -/* B0D508 80096368 10000004 */ b .L8009637C -/* B0D50C 8009636C 8FBF0014 */ lw $ra, 0x14($sp) -.L80096370: -/* B0D510 80096370 0C00084C */ jal osSyncPrintf -/* B0D514 80096374 2484F080 */ addiu $a0, %lo(D_8013F080) -.L80096378: -/* B0D518 80096378 8FBF0014 */ lw $ra, 0x14($sp) -.L8009637C: -/* B0D51C 8009637C 27BD0020 */ addiu $sp, $sp, 0x20 -/* B0D520 80096380 00001025 */ move $v0, $zero -/* B0D524 80096384 03E00008 */ jr $ra -/* B0D528 80096388 00000000 */ nop - diff --git a/asm/non_matchings/overlays/actors/ovl_kaleido_scope/func_8081F2FC.s b/asm/non_matchings/overlays/actors/ovl_kaleido_scope/func_8081F2FC.s index b119fffc7f..425fa9499f 100644 --- a/asm/non_matchings/overlays/actors/ovl_kaleido_scope/func_8081F2FC.s +++ b/asm/non_matchings/overlays/actors/ovl_kaleido_scope/func_8081F2FC.s @@ -1,7 +1,7 @@ glabel func_8081F2FC /* 0BADC 8081F2FC 27BDFFE8 */ addiu $sp, $sp, 0xFFE8 ## $sp = FFFFFFE8 /* 0BAE0 8081F300 AFBF0014 */ sw $ra, 0x0014($sp) -/* 0BAE4 8081F304 0C03FD2B */ jal func_800FF4AC +/* 0BAE4 8081F304 0C03FD2B */ jal Sleep_Msec /* 0BAE8 8081F308 24040032 */ addiu $a0, $zero, 0x0032 ## $a0 = 00000032 /* 0BAEC 8081F30C 3C048083 */ lui $a0, %hi(D_808321B0) ## $a0 = 80830000 /* 0BAF0 8081F310 0C030DDC */ jal func_800C3770 diff --git a/include/functions.h b/include/functions.h index 9dcdad1af9..5cc3b46f5c 100644 --- a/include/functions.h +++ b/include/functions.h @@ -2309,8 +2309,13 @@ void __osDisplayArena(Arena* arena); void ArenaImpl_FaultClient(Arena* arena); u32 __osCheckArena(Arena* arena); u8 func_800FF334(Arena* arena); -// ? func_800FF3A0(?); -// ? func_800FF4AC(?); +void PrintUtils_VPrintf(char** arg0, const char* fmt, va_list args); +void PrintUtils_Printf(void* arg0, const char* fmt, ...); +void Sleep_Cycles(OSTime cycles); +void Sleep_Nsec(u32 nsec); +void Sleep_Usec(u32 usec); +void Sleep_Msec(u32 ms); +void Sleep_Sec(u32 sec); // ? func_800FF540(?); // ? func_800FF5A8(?); // ? func_800FF62C(?); diff --git a/spec b/spec index b2114edd79..6d022e7a1d 100644 --- a/spec +++ b/spec @@ -502,7 +502,9 @@ beginseg include "build/data/code_800FD970.data.o" include "build/data/code_800FD970.bss.o" include "build/src/code/__osMalloc.o" - include "build/asm/code_800FF340.o" + include "build/src/code/printutils.o" + include "build/src/code/sleep.o" + include "build/asm/code_800FF540.o" include "build/asm/code_800FFA50.o" include "build/data/code_800FFA50.bss.o" include "build/asm/code_80100040.o" diff --git a/src/code/__osMalloc.c b/src/code/__osMalloc.c index d5501c663d..6b4d84eafe 100644 --- a/src/code/__osMalloc.c +++ b/src/code/__osMalloc.c @@ -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); } diff --git a/src/code/code_800D31A0.c b/src/code/code_800D31A0.c index 3f73824402..54201e35fc 100644 --- a/src/code/code_800D31A0.c +++ b/src/code/code_800D31A0.c @@ -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); } } diff --git a/src/code/fault.c b/src/code/fault.c index 05bee87d51..92f2526479 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -2,6 +2,7 @@ #include #include #include +#include // 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; } } diff --git a/src/code/gfxprint.c b/src/code/gfxprint.c index 7d17af7900..0555e1cec0 100644 --- a/src/code/gfxprint.c +++ b/src/code/gfxprint.c @@ -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, ...) { diff --git a/src/code/padmgr.c b/src/code/padmgr.c index dc3e9c472a..ac345c86b6 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -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; diff --git a/src/code/printutils.c b/src/code/printutils.c new file mode 100644 index 0000000000..e1e70f076f --- /dev/null +++ b/src/code/printutils.c @@ -0,0 +1,14 @@ +#include + +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); +} diff --git a/src/code/sched.c b/src/code/sched.c index af971ff2e2..b7306425d4 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -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()))); } } } diff --git a/src/code/sleep.c b/src/code/sleep.c new file mode 100644 index 0000000000..f83ccc0703 --- /dev/null +++ b/src/code/sleep.c @@ -0,0 +1,33 @@ +#include + +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)); +} diff --git a/src/code/z_debug.c b/src/code/z_debug.c index adda7974bd..cb21e0125a 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -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++) { diff --git a/src/code/z_demo.c b/src/code/z_demo.c index 5735a56890..f43eb59f07 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -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; } diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index d94f95a3a8..19e5915aa7 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1,6 +1,7 @@ #include #include #include +#include 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); } diff --git a/src/code/z_room.c b/src/code/z_room.c index 690ce974c4..dd181d6067 100644 --- a/src/code/z_room.c +++ b/src/code/z_room.c @@ -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 diff --git a/src/libultra_boot_O1/initialize.c b/src/libultra_boot_O1/initialize.c index 903a9212aa..3683ad3b8c 100644 --- a/src/libultra_boot_O1/initialize.c +++ b/src/libultra_boot_O1/initialize.c @@ -8,7 +8,7 @@ typedef struct { u32 ins_0C; // nop } struct_exceptionPreamble; -u64 osClockRate = 62500000; +u64 osClockRate = OS_CLOCK_RATE; u32 osViClock = VI_NTSC_CLOCK; u32 __osShutdown = 0; u32 __OSGlobalIntMask = 0x003FFF01; diff --git a/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c b/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c index b17544c460..27a77c388a 100644 --- a/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c +++ b/src/overlays/actors/ovl_En_Wallmas/z_en_wallmas.c @@ -9,7 +9,7 @@ #define ROOM 0x00 #define FLAGS 0x00000015 -#define TIMER_SCALE 0.0062500000931322574615478515625f +#define TIMER_SCALE ((f32)OS_CLOCK_RATE/10000000000) #define DEGREE_60_RAD 1.0471975803375244140625f #define DEGREE_15_RAD 0.261799395084381103515625f