From b86edcf92c1c6882f0bb9dd051eb6a1b0582de8b Mon Sep 17 00:00:00 2001 From: Lucas Shaw <49287729+shawlucas@users.noreply.github.com> Date: Wed, 17 Jun 2020 04:16:30 -0700 Subject: [PATCH] Matched some controller files (#178) * osPfsIsPlug.c and osContSetCh.c OK * update * __osPfsGetStatus.c OK * removed unused asm * Updated all libultra controller files to use new structs instead of the temporary structs. Added os_pfs.h * controller updates * fixed header guard * Made suggested changes --- asm/code_801014C0.s | 2 +- asm/code_80101910.s | 166 --------------- asm/code_80102420.s | 8 +- asm/code_80103010.s | 2 +- asm/code_80104810.s | 217 -------------------- asm/code_80104D00.s | 36 ---- asm/code_80104D60.s | 2 +- asm/code_80104F40.s | 2 +- asm/code_80105CF0.s | 10 +- data/code_80101910.bss.s | 13 -- data/code_80102420.data.s | 2 +- data/code_80105CF0.data.s | 2 +- include/PR/os_cont.h | 207 ------------------- include/PR/os_message.h | 8 - include/functions.h | 41 ++-- include/ultra64.h | 1 - include/ultra64/controller.h | 217 +++++++++++++------- include/ultra64/pfs.h | 70 +++++++ include/variables.h | 28 ++- include/z64.h | 26 +-- spec | 7 +- src/code/fault.c | 2 +- src/code/flg_set.c | 2 +- src/code/graph.c | 2 +- src/code/padmgr.c | 20 +- src/code/z_debug.c | 2 +- src/code/z_demo.c | 2 +- src/code/z_parameter.c | 2 +- src/code/z_sample.c | 2 +- src/libultra_code/__osPfsGetStatus.c | 77 +++++++ src/libultra_code/__osSiCreateAccessQueue.c | 16 +- src/libultra_code/code_801031F0.c | 8 +- src/libultra_code/osContInit.c | 104 +++++----- src/libultra_code/osContSetCh.c | 21 ++ src/libultra_code/osContStartReadData.c | 64 +++--- src/libultra_code/osMempakAddrCRC.c | 1 - src/libultra_code/osPfsIsPlug.c | 93 +++++++++ src/libultra_code/osReadMempak.c | 56 ++--- src/libultra_code/osRumblePak.c | 110 +++++----- 39 files changed, 650 insertions(+), 1001 deletions(-) delete mode 100644 asm/code_80101910.s delete mode 100644 asm/code_80104810.s delete mode 100644 asm/code_80104D00.s delete mode 100644 data/code_80101910.bss.s delete mode 100644 include/PR/os_cont.h create mode 100644 include/ultra64/pfs.h create mode 100644 src/libultra_code/__osPfsGetStatus.c create mode 100644 src/libultra_code/osContSetCh.c create mode 100644 src/libultra_code/osPfsIsPlug.c diff --git a/asm/code_801014C0.s b/asm/code_801014C0.s index 1fa71b9c94..f18fcb973b 100644 --- a/asm/code_801014C0.s +++ b/asm/code_801014C0.s @@ -317,7 +317,7 @@ glabel osPfsReadWriteFile .L801018E4: /* B78A84 801018E4 8E440004 */ lw $a0, 4($s2) .L801018E8: -/* B78A88 801018E8 0C040644 */ jal func_80101910 +/* B78A88 801018E8 0C040644 */ jal __osPfsGetStatus /* B78A8C 801018EC 8E450008 */ lw $a1, 8($s2) .L801018F0: /* B78A90 801018F0 8FBF002C */ lw $ra, 0x2c($sp) diff --git a/asm/code_80101910.s b/asm/code_80101910.s deleted file mode 100644 index fc5b9add08..0000000000 --- a/asm/code_80101910.s +++ /dev/null @@ -1,166 +0,0 @@ -.include "macro.inc" - -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 # allow use of 64-bit general purpose registers - -.section .text - -.balign 16 - -glabel func_80101910 -/* B78AB0 80101910 27BDFFD0 */ addiu $sp, $sp, -0x30 -/* B78AB4 80101914 AFA40030 */ sw $a0, 0x30($sp) -/* B78AB8 80101918 AFBF0014 */ sw $ra, 0x14($sp) -/* B78ABC 8010191C AFA50034 */ sw $a1, 0x34($sp) -/* B78AC0 80101920 240E00FA */ li $t6, 250 -/* B78AC4 80101924 3C018013 */ lui $at, %hi(D_80134CF4) # $at, 0x8013 -/* B78AC8 80101928 00A02025 */ move $a0, $a1 -/* B78ACC 8010192C A02E4CF4 */ sb $t6, %lo(D_80134CF4)($at) -/* B78AD0 80101930 0C040678 */ jal func_801019E0 -/* B78AD4 80101934 00002825 */ move $a1, $zero -/* B78AD8 80101938 3C058017 */ lui $a1, %hi(pifMempakBuf) # $a1, 0x8017 -/* B78ADC 8010193C 24A55960 */ addiu $a1, %lo(pifMempakBuf) # addiu $a1, $a1, 0x5960 -/* B78AE0 80101940 0C0404FC */ jal __osSiRawStartDma /*(s32 dir, void *addr)*/ -/* B78AE4 80101944 24040001 */ li $a0, 1 -/* B78AE8 80101948 8FA40030 */ lw $a0, 0x30($sp) -/* B78AEC 8010194C 27A50028 */ addiu $a1, $sp, 0x28 -/* B78AF0 80101950 0C000CA0 */ jal osRecvMesg -/* B78AF4 80101954 24060001 */ li $a2, 1 -/* B78AF8 80101958 3C058017 */ lui $a1, %hi(pifMempakBuf) # $a1, 0x8017 -/* B78AFC 8010195C 24A55960 */ addiu $a1, %lo(pifMempakBuf) # addiu $a1, $a1, 0x5960 -/* B78B00 80101960 0C0404FC */ jal __osSiRawStartDma /*(s32 dir, void *addr)*/ -/* B78B04 80101964 00002025 */ move $a0, $zero -/* B78B08 80101968 AFA2002C */ sw $v0, 0x2c($sp) -/* B78B0C 8010196C 8FA40030 */ lw $a0, 0x30($sp) -/* B78B10 80101970 27A50028 */ addiu $a1, $sp, 0x28 -/* B78B14 80101974 0C000CA0 */ jal osRecvMesg -/* B78B18 80101978 24060001 */ li $a2, 1 -/* B78B1C 8010197C 8FA40034 */ lw $a0, 0x34($sp) -/* B78B20 80101980 0C0406A9 */ jal func_80101AA4 -/* B78B24 80101984 27A50024 */ addiu $a1, $sp, 0x24 -/* B78B28 80101988 93A20026 */ lbu $v0, 0x26($sp) -/* B78B2C 8010198C 93B80027 */ lbu $t8, 0x27($sp) -/* B78B30 80101990 8FBF0014 */ lw $ra, 0x14($sp) -/* B78B34 80101994 30430001 */ andi $v1, $v0, 1 -/* B78B38 80101998 10600005 */ beqz $v1, .L801019B0 -/* B78B3C 8010199C 304F0002 */ andi $t7, $v0, 2 -/* B78B40 801019A0 11E00003 */ beqz $t7, .L801019B0 -/* B78B44 801019A4 00000000 */ nop -/* B78B48 801019A8 1000000B */ b .L801019D8 -/* B78B4C 801019AC 24020002 */ li $v0, 2 -.L801019B0: -/* B78B50 801019B0 17000003 */ bnez $t8, .L801019C0 -/* B78B54 801019B4 00000000 */ nop -/* B78B58 801019B8 14600003 */ bnez $v1, .L801019C8 -/* B78B5C 801019BC 30590004 */ andi $t9, $v0, 4 -.L801019C0: -/* B78B60 801019C0 10000005 */ b .L801019D8 -/* B78B64 801019C4 24020001 */ li $v0, 1 -.L801019C8: -/* B78B68 801019C8 13200003 */ beqz $t9, .L801019D8 -/* B78B6C 801019CC 8FA2002C */ lw $v0, 0x2c($sp) -/* B78B70 801019D0 10000001 */ b .L801019D8 -/* B78B74 801019D4 24020004 */ li $v0, 4 -.L801019D8: -/* B78B78 801019D8 03E00008 */ jr $ra -/* B78B7C 801019DC 27BD0030 */ addiu $sp, $sp, 0x30 - -glabel func_801019E0 -/* B78B80 801019E0 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B78B84 801019E4 3C068017 */ lui $a2, %hi(pifMempakBuf) -/* B78B88 801019E8 240700FE */ li $a3, 254 -/* B78B8C 801019EC 3C018017 */ lui $at, %hi(_osCont_lastPollType) # $at, 0x8017 -/* B78B90 801019F0 24C25960 */ addiu $v0, $a2, %lo(pifMempakBuf) -/* B78B94 801019F4 AFA5001C */ sw $a1, 0x1c($sp) -/* B78B98 801019F8 A0275810 */ sb $a3, %lo(_osCont_lastPollType)($at) -/* B78B9C 801019FC 240F0001 */ li $t7, 1 -/* B78BA0 80101A00 AC4F003C */ sw $t7, 0x3c($v0) -/* B78BA4 80101A04 24180001 */ li $t8, 1 -/* B78BA8 80101A08 24190003 */ li $t9, 3 -/* B78BAC 80101A0C 240800FF */ li $t0, 255 -/* B78BB0 80101A10 240900FF */ li $t1, 255 -/* B78BB4 80101A14 240A00FF */ li $t2, 255 -/* B78BB8 80101A18 A3B8000C */ sb $t8, 0xc($sp) -/* B78BBC 80101A1C A3B9000D */ sb $t9, 0xd($sp) -/* B78BC0 80101A20 A3A5000E */ sb $a1, 0xe($sp) -/* B78BC4 80101A24 A3A8000F */ sb $t0, 0xf($sp) -/* B78BC8 80101A28 A3A90010 */ sb $t1, 0x10($sp) -/* B78BCC 80101A2C A3AA0011 */ sb $t2, 0x11($sp) -/* B78BD0 80101A30 18800010 */ blez $a0, .L80101A74 -/* B78BD4 80101A34 00001825 */ move $v1, $zero -/* B78BD8 80101A38 30860003 */ andi $a2, $a0, 3 -/* B78BDC 80101A3C 10C00006 */ beqz $a2, .L80101A58 -/* B78BE0 80101A40 00C02825 */ move $a1, $a2 -.L80101A44: -/* B78BE4 80101A44 24630001 */ addiu $v1, $v1, 1 -/* B78BE8 80101A48 A0400000 */ sb $zero, ($v0) -/* B78BEC 80101A4C 14A3FFFD */ bne $a1, $v1, .L80101A44 -/* B78BF0 80101A50 24420001 */ addiu $v0, $v0, 1 -/* B78BF4 80101A54 10640007 */ beq $v1, $a0, .L80101A74 -.L80101A58: -/* B78BF8 80101A58 24630004 */ addiu $v1, $v1, 4 -/* B78BFC 80101A5C A0400001 */ sb $zero, 1($v0) -/* B78C00 80101A60 A0400002 */ sb $zero, 2($v0) -/* B78C04 80101A64 A0400003 */ sb $zero, 3($v0) -/* B78C08 80101A68 24420004 */ addiu $v0, $v0, 4 -/* B78C0C 80101A6C 1464FFFA */ bne $v1, $a0, .L80101A58 -/* B78C10 80101A70 A040FFFC */ sb $zero, -4($v0) -.L80101A74: -/* B78C14 80101A74 27AB000C */ addiu $t3, $sp, 0xc -/* B78C18 80101A78 8D610000 */ lw $at, ($t3) -/* B78C1C 80101A7C 24420006 */ addiu $v0, $v0, 6 -/* B78C20 80101A80 A841FFFA */ swl $at, -6($v0) -/* B78C24 80101A84 B841FFFD */ swr $at, -3($v0) -/* B78C28 80101A88 91610004 */ lbu $at, 4($t3) -/* B78C2C 80101A8C A041FFFE */ sb $at, -2($v0) -/* B78C30 80101A90 916D0005 */ lbu $t5, 5($t3) -/* B78C34 80101A94 A0470000 */ sb $a3, ($v0) -/* B78C38 80101A98 27BD0018 */ addiu $sp, $sp, 0x18 -/* B78C3C 80101A9C 03E00008 */ jr $ra -/* B78C40 80101AA0 A04DFFFF */ sb $t5, -1($v0) - -glabel func_80101AA4 -/* B78C44 80101AA4 3C028017 */ lui $v0, %hi(pifMempakBuf) # $v0, 0x8017 -/* B78C48 80101AA8 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B78C4C 80101AAC 24425960 */ addiu $v0, %lo(pifMempakBuf) # addiu $v0, $v0, 0x5960 -/* B78C50 80101AB0 1880000B */ blez $a0, .L80101AE0 -/* B78C54 80101AB4 00001825 */ move $v1, $zero -/* B78C58 80101AB8 30870003 */ andi $a3, $a0, 3 -/* B78C5C 80101ABC 10E00005 */ beqz $a3, .L80101AD4 -/* B78C60 80101AC0 00E03025 */ move $a2, $a3 -.L80101AC4: -/* B78C64 80101AC4 24630001 */ addiu $v1, $v1, 1 -/* B78C68 80101AC8 14C3FFFE */ bne $a2, $v1, .L80101AC4 -/* B78C6C 80101ACC 24420001 */ addiu $v0, $v0, 1 -/* B78C70 80101AD0 10640003 */ beq $v1, $a0, .L80101AE0 -.L80101AD4: -/* B78C74 80101AD4 24630004 */ addiu $v1, $v1, 4 -/* B78C78 80101AD8 1464FFFE */ bne $v1, $a0, .L80101AD4 -/* B78C7C 80101ADC 24420004 */ addiu $v0, $v0, 4 -.L80101AE0: -/* B78C80 80101AE0 88410000 */ lwl $at, ($v0) -/* B78C84 80101AE4 98410003 */ lwr $at, 3($v0) -/* B78C88 80101AE8 27AE000C */ addiu $t6, $sp, 0xc -/* B78C8C 80101AEC ADC10000 */ sw $at, ($t6) -/* B78C90 80101AF0 90410004 */ lbu $at, 4($v0) -/* B78C94 80101AF4 A1C10004 */ sb $at, 4($t6) -/* B78C98 80101AF8 90580005 */ lbu $t8, 5($v0) -/* B78C9C 80101AFC A1D80005 */ sb $t8, 5($t6) -/* B78CA0 80101B00 93B9000D */ lbu $t9, 0xd($sp) -/* B78CA4 80101B04 332800C0 */ andi $t0, $t9, 0xc0 -/* B78CA8 80101B08 00084903 */ sra $t1, $t0, 4 -/* B78CAC 80101B0C 312A00FF */ andi $t2, $t1, 0xff -/* B78CB0 80101B10 15400008 */ bnez $t2, .L80101B34 -/* B78CB4 80101B14 A0A90003 */ sb $t1, 3($a1) -/* B78CB8 80101B18 93AB0010 */ lbu $t3, 0x10($sp) -/* B78CBC 80101B1C 93AD000F */ lbu $t5, 0xf($sp) -/* B78CC0 80101B20 000B6200 */ sll $t4, $t3, 8 -/* B78CC4 80101B24 018D7825 */ or $t7, $t4, $t5 -/* B78CC8 80101B28 A4AF0000 */ sh $t7, ($a1) -/* B78CCC 80101B2C 93AE0011 */ lbu $t6, 0x11($sp) -/* B78CD0 80101B30 A0AE0002 */ sb $t6, 2($a1) -.L80101B34: -/* B78CD4 80101B34 03E00008 */ jr $ra -/* B78CD8 80101B38 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/code_80102420.s b/asm/code_80102420.s index dfbf3cb295..c209015f4c 100644 --- a/asm/code_80102420.s +++ b/asm/code_80102420.s @@ -650,8 +650,8 @@ glabel func_80102CC4 /* B79E8C 80102CEC AFA60060 */ sw $a2, 0x60($sp) /* B79E90 80102CF0 16800011 */ bnez $s4, .L80102D38 /* B79E94 80102CF4 AFA70064 */ sw $a3, 0x64($sp) -/* B79E98 80102CF8 3C0F8013 */ lui $t7, %hi(D_80134CF4) # $t7, 0x8013 -/* B79E9C 80102CFC 91EF4CF4 */ lbu $t7, %lo(D_80134CF4)($t7) +/* B79E98 80102CF8 3C0F8013 */ lui $t7, %hi(__osPfsInodeCacheBank) # $t7, 0x8013 +/* B79E9C 80102CFC 91EF4CF4 */ lbu $t7, %lo(__osPfsInodeCacheBank)($t7) /* B79EA0 80102D00 93B80067 */ lbu $t8, 0x67($sp) /* B79EA4 80102D04 3C198013 */ lui $t9, %hi(D_80134CF0) # $t9, 0x8013 /* B79EA8 80102D08 55F8000C */ bnel $t7, $t8, .L80102D3C @@ -813,13 +813,13 @@ glabel func_80102CC4 .L80102F48: /* B7A0E8 80102F48 93AB0067 */ lbu $t3, 0x67($sp) .L80102F4C: -/* B7A0EC 80102F4C 3C018013 */ lui $at, %hi(D_80134CF4) # $at, 0x8013 +/* B7A0EC 80102F4C 3C018013 */ lui $at, %hi(__osPfsInodeCacheBank) # $at, 0x8013 /* B7A0F0 80102F50 3C058017 */ lui $a1, %hi(D_80175860) # $a1, 0x8017 /* B7A0F4 80102F54 24A55860 */ addiu $a1, %lo(D_80175860) # addiu $a1, $a1, 0x5860 /* B7A0F8 80102F58 8FA4005C */ lw $a0, 0x5c($sp) /* B7A0FC 80102F5C 24060100 */ li $a2, 256 /* B7A100 80102F60 0C001BC4 */ jal bcopy -/* B7A104 80102F64 A02B4CF4 */ sb $t3, %lo(D_80134CF4)($at) +/* B7A104 80102F64 A02B4CF4 */ sb $t3, %lo(__osPfsInodeCacheBank)($at) /* B7A108 80102F68 8E4E0008 */ lw $t6, 8($s2) /* B7A10C 80102F6C 3C018013 */ lui $at, %hi(D_80134CF0) # $at, 0x8013 /* B7A110 80102F70 00001025 */ move $v0, $zero diff --git a/asm/code_80103010.s b/asm/code_80103010.s index 860751f7ce..665dbd35a9 100644 --- a/asm/code_80103010.s +++ b/asm/code_80103010.s @@ -61,7 +61,7 @@ glabel osPfsFindFile /* B7A264 801030C4 8FBF003C */ lw $ra, 0x3c($sp) /* B7A268 801030C8 8E440004 */ lw $a0, 4($s2) .L801030CC: -/* B7A26C 801030CC 0C040644 */ jal func_80101910 +/* B7A26C 801030CC 0C040644 */ jal __osPfsGetStatus /* B7A270 801030D0 8E450008 */ lw $a1, 8($s2) /* B7A274 801030D4 10400003 */ beqz $v0, .L801030E4 /* B7A278 801030D8 00403025 */ move $a2, $v0 diff --git a/asm/code_80104810.s b/asm/code_80104810.s deleted file mode 100644 index 2ae200f477..0000000000 --- a/asm/code_80104810.s +++ /dev/null @@ -1,217 +0,0 @@ -.include "macro.inc" - -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 # allow use of 64-bit general purpose registers - -.section .text - -.balign 16 - -glabel func_80104810 -/* B7B9B0 80104810 27BDFF90 */ addiu $sp, $sp, -0x70 -/* B7B9B4 80104814 AFBF003C */ sw $ra, 0x3c($sp) -/* B7B9B8 80104818 AFB5002C */ sw $s5, 0x2c($sp) -/* B7B9BC 8010481C AFB20020 */ sw $s2, 0x20($sp) -/* B7B9C0 80104820 AFB1001C */ sw $s1, 0x1c($sp) -/* B7B9C4 80104824 00809025 */ move $s2, $a0 -/* B7B9C8 80104828 AFBE0038 */ sw $fp, 0x38($sp) -/* B7B9CC 8010482C AFB70034 */ sw $s7, 0x34($sp) -/* B7B9D0 80104830 AFB60030 */ sw $s6, 0x30($sp) -/* B7B9D4 80104834 AFB40028 */ sw $s4, 0x28($sp) -/* B7B9D8 80104838 AFB30024 */ sw $s3, 0x24($sp) -/* B7B9DC 8010483C AFB00018 */ sw $s0, 0x18($sp) -/* B7B9E0 80104840 AFA50074 */ sw $a1, 0x74($sp) -/* B7B9E4 80104844 0000A825 */ move $s5, $zero -/* B7B9E8 80104848 0C0402E8 */ jal __osSiGetAccess -/* B7B9EC 8010484C 24110003 */ li $s1, 3 -/* B7B9F0 80104850 3C1E8017 */ lui $fp, %hi(_osCont_numControllers) # $fp, 0x8017 -/* B7B9F4 80104854 3C138017 */ lui $s3, %hi(pifMempakBuf) # $s3, 0x8017 -/* B7B9F8 80104858 26735960 */ addiu $s3, %lo(pifMempakBuf) # addiu $s3, $s3, 0x5960 -/* B7B9FC 8010485C 27DE5811 */ addiu $fp, %lo(_osCont_numControllers) # addiu $fp, $fp, 0x5811 -/* B7BA00 80104860 00008025 */ move $s0, $zero -/* B7BA04 80104864 27B70054 */ addiu $s7, $sp, 0x54 -/* B7BA08 80104868 27B60067 */ addiu $s6, $sp, 0x67 -/* B7BA0C 8010486C 27B40068 */ addiu $s4, $sp, 0x68 -.L80104870: -/* B7BA10 80104870 0C041267 */ jal func_8010499C -/* B7BA14 80104874 00002025 */ move $a0, $zero -/* B7BA18 80104878 24040001 */ li $a0, 1 -/* B7BA1C 8010487C 0C0404FC */ jal __osSiRawStartDma /*(s32 dir, void *addr)*/ -/* B7BA20 80104880 02602825 */ move $a1, $s3 -/* B7BA24 80104884 02402025 */ move $a0, $s2 -/* B7BA28 80104888 02802825 */ move $a1, $s4 -/* B7BA2C 8010488C 0C000CA0 */ jal osRecvMesg -/* B7BA30 80104890 24060001 */ li $a2, 1 -/* B7BA34 80104894 00002025 */ move $a0, $zero -/* B7BA38 80104898 0C0404FC */ jal __osSiRawStartDma /*(s32 dir, void *addr)*/ -/* B7BA3C 8010489C 02602825 */ move $a1, $s3 -/* B7BA40 801048A0 AFA2006C */ sw $v0, 0x6c($sp) -/* B7BA44 801048A4 02402025 */ move $a0, $s2 -/* B7BA48 801048A8 02802825 */ move $a1, $s4 -/* B7BA4C 801048AC 0C000CA0 */ jal osRecvMesg -/* B7BA50 801048B0 24060001 */ li $a2, 1 -/* B7BA54 801048B4 02C02025 */ move $a0, $s6 -/* B7BA58 801048B8 0C041294 */ jal func_80104A50 -/* B7BA5C 801048BC 02E02825 */ move $a1, $s7 -/* B7BA60 801048C0 93C30000 */ lbu $v1, ($fp) -/* B7BA64 801048C4 27A20054 */ addiu $v0, $sp, 0x54 -/* B7BA68 801048C8 5860000C */ blezl $v1, .L801048FC -/* B7BA6C 801048CC 02031026 */ xor $v0, $s0, $v1 -.L801048D0: -/* B7BA70 801048D0 904E0002 */ lbu $t6, 2($v0) -/* B7BA74 801048D4 31CF0004 */ andi $t7, $t6, 4 -/* B7BA78 801048D8 55E00004 */ bnezl $t7, .L801048EC -/* B7BA7C 801048DC 26100001 */ addiu $s0, $s0, 1 -/* B7BA80 801048E0 10000005 */ b .L801048F8 -/* B7BA84 801048E4 2631FFFF */ addiu $s1, $s1, -1 -/* B7BA88 801048E8 26100001 */ addiu $s0, $s0, 1 -.L801048EC: -/* B7BA8C 801048EC 0203082A */ slt $at, $s0, $v1 -/* B7BA90 801048F0 1420FFF7 */ bnez $at, .L801048D0 -/* B7BA94 801048F4 24420004 */ addiu $v0, $v0, 4 -.L801048F8: -/* B7BA98 801048F8 02031026 */ xor $v0, $s0, $v1 -.L801048FC: -/* B7BA9C 801048FC 14400002 */ bnez $v0, .L80104908 -/* B7BAA0 80104900 00008025 */ move $s0, $zero -/* B7BAA4 80104904 00008825 */ move $s1, $zero -.L80104908: -/* B7BAA8 80104908 1E20FFD9 */ bgtz $s1, .L80104870 -/* B7BAAC 8010490C 00000000 */ nop -/* B7BAB0 80104910 18600011 */ blez $v1, .L80104958 -/* B7BAB4 80104914 27A20054 */ addiu $v0, $sp, 0x54 -.L80104918: -/* B7BAB8 80104918 90580003 */ lbu $t8, 3($v0) -/* B7BABC 8010491C 5700000B */ bnezl $t8, .L8010494C -/* B7BAC0 80104920 26100001 */ addiu $s0, $s0, 1 -/* B7BAC4 80104924 90590002 */ lbu $t9, 2($v0) -/* B7BAC8 80104928 24090001 */ li $t1, 1 -/* B7BACC 8010492C 02095004 */ sllv $t2, $t1, $s0 -/* B7BAD0 80104930 33280001 */ andi $t0, $t9, 1 -/* B7BAD4 80104934 51000005 */ beql $t0, $zero, .L8010494C -/* B7BAD8 80104938 26100001 */ addiu $s0, $s0, 1 -/* B7BADC 8010493C 02AAA825 */ or $s5, $s5, $t2 -/* B7BAE0 80104940 32AB00FF */ andi $t3, $s5, 0xff -/* B7BAE4 80104944 0160A825 */ move $s5, $t3 -/* B7BAE8 80104948 26100001 */ addiu $s0, $s0, 1 -.L8010494C: -/* B7BAEC 8010494C 0203082A */ slt $at, $s0, $v1 -/* B7BAF0 80104950 1420FFF1 */ bnez $at, .L80104918 -/* B7BAF4 80104954 24420004 */ addiu $v0, $v0, 4 -.L80104958: -/* B7BAF8 80104958 0C0402F9 */ jal __osSiRelAccess -/* B7BAFC 8010495C 00000000 */ nop -/* B7BB00 80104960 8FAC0074 */ lw $t4, 0x74($sp) -/* B7BB04 80104964 A1950000 */ sb $s5, ($t4) -/* B7BB08 80104968 8FBF003C */ lw $ra, 0x3c($sp) -/* B7BB0C 8010496C 8FBE0038 */ lw $fp, 0x38($sp) -/* B7BB10 80104970 8FB70034 */ lw $s7, 0x34($sp) -/* B7BB14 80104974 8FB60030 */ lw $s6, 0x30($sp) -/* B7BB18 80104978 8FB5002C */ lw $s5, 0x2c($sp) -/* B7BB1C 8010497C 8FB40028 */ lw $s4, 0x28($sp) -/* B7BB20 80104980 8FB30024 */ lw $s3, 0x24($sp) -/* B7BB24 80104984 8FB20020 */ lw $s2, 0x20($sp) -/* B7BB28 80104988 8FB1001C */ lw $s1, 0x1c($sp) -/* B7BB2C 8010498C 8FB00018 */ lw $s0, 0x18($sp) -/* B7BB30 80104990 8FA2006C */ lw $v0, 0x6c($sp) -/* B7BB34 80104994 03E00008 */ jr $ra -/* B7BB38 80104998 27BD0070 */ addiu $sp, $sp, 0x70 - -glabel func_8010499C -/* B7BB3C 8010499C 27BDFFF0 */ addiu $sp, $sp, -0x10 -/* B7BB40 801049A0 3C058017 */ lui $a1, %hi(pifMempakBuf) -/* B7BB44 801049A4 3C018017 */ lui $at, %hi(_osCont_lastPollType) # $at, 0x8017 -/* B7BB48 801049A8 24A25960 */ addiu $v0, $a1, %lo(pifMempakBuf) -/* B7BB4C 801049AC AFA40010 */ sw $a0, 0x10($sp) -/* B7BB50 801049B0 A0245810 */ sb $a0, %lo(_osCont_lastPollType)($at) -/* B7BB54 801049B4 240F0001 */ li $t7, 1 -/* B7BB58 801049B8 AC4F003C */ sw $t7, 0x3c($v0) -/* B7BB5C 801049BC 3C068017 */ lui $a2, %hi(_osCont_numControllers) # $a2, 0x8017 -/* B7BB60 801049C0 24C65811 */ addiu $a2, %lo(_osCont_numControllers) # addiu $a2, $a2, 0x5811 -/* B7BB64 801049C4 90CD0000 */ lbu $t5, ($a2) -/* B7BB68 801049C8 241800FF */ li $t8, 255 -/* B7BB6C 801049CC 24190001 */ li $t9, 1 -/* B7BB70 801049D0 24080003 */ li $t0, 3 -/* B7BB74 801049D4 240900FF */ li $t1, 255 -/* B7BB78 801049D8 240A00FF */ li $t2, 255 -/* B7BB7C 801049DC 240B00FF */ li $t3, 255 -/* B7BB80 801049E0 240C00FF */ li $t4, 255 -/* B7BB84 801049E4 A3B80004 */ sb $t8, 4($sp) -/* B7BB88 801049E8 A3B90005 */ sb $t9, 5($sp) -/* B7BB8C 801049EC A3A80006 */ sb $t0, 6($sp) -/* B7BB90 801049F0 A3A40007 */ sb $a0, 7($sp) -/* B7BB94 801049F4 A3A90008 */ sb $t1, 8($sp) -/* B7BB98 801049F8 A3AA0009 */ sb $t2, 9($sp) -/* B7BB9C 801049FC A3AB000A */ sb $t3, 0xa($sp) -/* B7BBA0 80104A00 A3AC000B */ sb $t4, 0xb($sp) -/* B7BBA4 80104A04 19A0000E */ blez $t5, .L80104A40 -/* B7BBA8 80104A08 00001825 */ move $v1, $zero -/* B7BBAC 80104A0C 27A40004 */ addiu $a0, $sp, 4 -/* B7BBB0 80104A10 8C810000 */ lw $at, ($a0) -.L80104A14: -/* B7BBB4 80104A14 24630001 */ addiu $v1, $v1, 1 -/* B7BBB8 80104A18 24420008 */ addiu $v0, $v0, 8 -/* B7BBBC 80104A1C A841FFF8 */ swl $at, -8($v0) -/* B7BBC0 80104A20 B841FFFB */ swr $at, -5($v0) -/* B7BBC4 80104A24 8C8F0004 */ lw $t7, 4($a0) -/* B7BBC8 80104A28 A84FFFFC */ swl $t7, -4($v0) -/* B7BBCC 80104A2C B84FFFFF */ swr $t7, -1($v0) -/* B7BBD0 80104A30 90D80000 */ lbu $t8, ($a2) -/* B7BBD4 80104A34 0078082A */ slt $at, $v1, $t8 -/* B7BBD8 80104A38 5420FFF6 */ bnezl $at, .L80104A14 -/* B7BBDC 80104A3C 8C810000 */ lw $at, ($a0) -.L80104A40: -/* B7BBE0 80104A40 241900FE */ li $t9, 254 -/* B7BBE4 80104A44 A0590000 */ sb $t9, ($v0) -/* B7BBE8 80104A48 03E00008 */ jr $ra -/* B7BBEC 80104A4C 27BD0010 */ addiu $sp, $sp, 0x10 - -glabel func_80104A50 -/* B7BBF0 80104A50 3C078017 */ lui $a3, %hi(_osCont_numControllers) # $a3, 0x8017 -/* B7BBF4 80104A54 24E75811 */ addiu $a3, %lo(_osCont_numControllers) # addiu $a3, $a3, 0x5811 -/* B7BBF8 80104A58 90EE0000 */ lbu $t6, ($a3) -/* B7BBFC 80104A5C 3C038017 */ lui $v1, %hi(pifMempakBuf) # $v1, 0x8017 -/* B7BC00 80104A60 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B7BC04 80104A64 00001025 */ move $v0, $zero -/* B7BC08 80104A68 24635960 */ addiu $v1, %lo(pifMempakBuf) # addiu $v1, $v1, 0x5960 -/* B7BC0C 80104A6C 19C00020 */ blez $t6, .L80104AF0 -/* B7BC10 80104A70 00003025 */ move $a2, $zero -/* B7BC14 80104A74 27A8000C */ addiu $t0, $sp, 0xc -.L80104A78: -/* B7BC18 80104A78 88610000 */ lwl $at, ($v1) -/* B7BC1C 80104A7C 98610003 */ lwr $at, 3($v1) -/* B7BC20 80104A80 AD010000 */ sw $at, ($t0) -/* B7BC24 80104A84 88780004 */ lwl $t8, 4($v1) -/* B7BC28 80104A88 98780007 */ lwr $t8, 7($v1) -/* B7BC2C 80104A8C AD180004 */ sw $t8, 4($t0) -/* B7BC30 80104A90 93B9000E */ lbu $t9, 0xe($sp) -/* B7BC34 80104A94 332900C0 */ andi $t1, $t9, 0xc0 -/* B7BC38 80104A98 00095103 */ sra $t2, $t1, 4 -/* B7BC3C 80104A9C 314B00FF */ andi $t3, $t2, 0xff -/* B7BC40 80104AA0 1560000D */ bnez $t3, .L80104AD8 -/* B7BC44 80104AA4 A0AA0003 */ sb $t2, 3($a1) -/* B7BC48 80104AA8 93AC0011 */ lbu $t4, 0x11($sp) -/* B7BC4C 80104AAC 93AE0010 */ lbu $t6, 0x10($sp) -/* B7BC50 80104AB0 24190001 */ li $t9, 1 -/* B7BC54 80104AB4 000C6A00 */ sll $t5, $t4, 8 -/* B7BC58 80104AB8 01AE7825 */ or $t7, $t5, $t6 -/* B7BC5C 80104ABC A4AF0000 */ sh $t7, ($a1) -/* B7BC60 80104AC0 93B80012 */ lbu $t8, 0x12($sp) -/* B7BC64 80104AC4 00D94804 */ sllv $t1, $t9, $a2 -/* B7BC68 80104AC8 00491025 */ or $v0, $v0, $t1 -/* B7BC6C 80104ACC 304A00FF */ andi $t2, $v0, 0xff -/* B7BC70 80104AD0 01401025 */ move $v0, $t2 -/* B7BC74 80104AD4 A0B80002 */ sb $t8, 2($a1) -.L80104AD8: -/* B7BC78 80104AD8 90EB0000 */ lbu $t3, ($a3) -/* B7BC7C 80104ADC 24C60001 */ addiu $a2, $a2, 1 -/* B7BC80 80104AE0 24630008 */ addiu $v1, $v1, 8 -/* B7BC84 80104AE4 00CB082A */ slt $at, $a2, $t3 -/* B7BC88 80104AE8 1420FFE3 */ bnez $at, .L80104A78 -/* B7BC8C 80104AEC 24A50004 */ addiu $a1, $a1, 4 -.L80104AF0: -/* B7BC90 80104AF0 A0820000 */ sb $v0, ($a0) -/* B7BC94 80104AF4 03E00008 */ jr $ra -/* B7BC98 80104AF8 27BD0018 */ addiu $sp, $sp, 0x18 diff --git a/asm/code_80104D00.s b/asm/code_80104D00.s deleted file mode 100644 index 245cffb443..0000000000 --- a/asm/code_80104D00.s +++ /dev/null @@ -1,36 +0,0 @@ -.include "macro.inc" - -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 # allow use of 64-bit general purpose registers - -.section .text - -.balign 16 - -glabel func_80104D00 -/* B7BEA0 80104D00 27BDFFE8 */ addiu $sp, $sp, -0x18 -/* B7BEA4 80104D04 AFBF0014 */ sw $ra, 0x14($sp) -/* B7BEA8 80104D08 0C0402E8 */ jal __osSiGetAccess -/* B7BEAC 80104D0C AFA40018 */ sw $a0, 0x18($sp) -/* B7BEB0 80104D10 93A2001B */ lbu $v0, 0x1b($sp) -/* B7BEB4 80104D14 240E0004 */ li $t6, 4 -/* B7BEB8 80104D18 240F00FE */ li $t7, 254 -/* B7BEBC 80104D1C 28410005 */ slti $at, $v0, 5 -/* B7BEC0 80104D20 14200003 */ bnez $at, .L80104D30 -/* B7BEC4 80104D24 3C018017 */ lui $at, %hi(_osCont_numControllers) # $at, 0x8017 -/* B7BEC8 80104D28 10000003 */ b .L80104D38 -/* B7BECC 80104D2C A02E5811 */ sb $t6, %lo(_osCont_numControllers)($at) -.L80104D30: -/* B7BED0 80104D30 3C018017 */ lui $at, %hi(_osCont_numControllers) # $at, 0x8017 -/* B7BED4 80104D34 A0225811 */ sb $v0, %lo(_osCont_numControllers)($at) -.L80104D38: -/* B7BED8 80104D38 3C018017 */ lui $at, %hi(_osCont_lastPollType) # $at, 0x8017 -/* B7BEDC 80104D3C 0C0402F9 */ jal __osSiRelAccess -/* B7BEE0 80104D40 A02F5810 */ sb $t7, %lo(_osCont_lastPollType)($at) -/* B7BEE4 80104D44 8FBF0014 */ lw $ra, 0x14($sp) -/* B7BEE8 80104D48 27BD0018 */ addiu $sp, $sp, 0x18 -/* B7BEEC 80104D4C 00001025 */ move $v0, $zero -/* B7BEF0 80104D50 03E00008 */ jr $ra -/* B7BEF4 80104D54 00000000 */ nop diff --git a/asm/code_80104D60.s b/asm/code_80104D60.s index 1fb0ace469..cab7a9593a 100644 --- a/asm/code_80104D60.s +++ b/asm/code_80104D60.s @@ -132,7 +132,7 @@ glabel osPfsFileState /* B7C0A8 80104F08 0C001BC4 */ jal bcopy /* B7C0AC 80104F0C 24A5000A */ addiu $a1, $a1, 0xa /* B7C0B0 80104F10 8E640004 */ lw $a0, 4($s3) -/* B7C0B4 80104F14 0C040644 */ jal func_80101910 +/* B7C0B4 80104F14 0C040644 */ jal __osPfsGetStatus /* B7C0B8 80104F18 8E650008 */ lw $a1, 8($s3) .L80104F1C: /* B7C0BC 80104F1C 8FBF002C */ lw $ra, 0x2c($sp) diff --git a/asm/code_80104F40.s b/asm/code_80104F40.s index 3a2ebeb5c4..13dc7931f4 100644 --- a/asm/code_80104F40.s +++ b/asm/code_80104F40.s @@ -18,7 +18,7 @@ glabel osPfsInitPak /* B7C0F4 80104F54 0C0402E8 */ jal __osSiGetAccess /* B7C0F8 80104F58 AFA60078 */ sw $a2, 0x78($sp) /* B7C0FC 80104F5C 8FA40070 */ lw $a0, 0x70($sp) -/* B7C100 80104F60 0C040644 */ jal func_80101910 +/* B7C100 80104F60 0C040644 */ jal __osPfsGetStatus /* B7C104 80104F64 8FA50078 */ lw $a1, 0x78($sp) /* B7C108 80104F68 0C0402F9 */ jal __osSiRelAccess /* B7C10C 80104F6C AFA2006C */ sw $v0, 0x6c($sp) diff --git a/asm/code_80105CF0.s b/asm/code_80105CF0.s index 1d59931d6a..eb37294c9d 100644 --- a/asm/code_80105CF0.s +++ b/asm/code_80105CF0.s @@ -45,12 +45,12 @@ glabel func_80105CF0 /* B7CF08 80105D68 A7A60072 */ sh $a2, 0x72($sp) /* B7CF0C 80105D6C 0010C0C3 */ sra $t8, $s0, 3 /* B7CF10 80105D70 0010C940 */ sll $t9, $s0, 5 -/* B7CF14 80105D74 3C178013 */ lui $s7, %hi(D_80134D20) # $s7, 0x8013 -/* B7CF18 80105D78 3C168017 */ lui $s6, %hi(_osCont_lastPollType) # $s6, 0x8017 +/* B7CF14 80105D74 3C178013 */ lui $s7, %hi(__osPfsLastChannel) # $s7, 0x8013 +/* B7CF18 80105D78 3C168017 */ lui $s6, %hi(__osContLastPoll) # $s6, 0x8017 /* B7CF1C 80105D7C 3C138017 */ lui $s3, %hi(pifMempakBuf) # $s3, 0x8017 /* B7CF20 80105D80 26735960 */ addiu $s3, %lo(pifMempakBuf) # addiu $s3, $s3, 0x5960 -/* B7CF24 80105D84 26D65810 */ addiu $s6, %lo(_osCont_lastPollType) # addiu $s6, $s6, 0x5810 -/* B7CF28 80105D88 26F74D20 */ addiu $s7, %lo(D_80134D20) # addiu $s7, $s7, 0x4d20 +/* B7CF24 80105D84 26D65810 */ addiu $s6, %lo(__osContLastPoll) # addiu $s6, $s6, 0x5810 +/* B7CF28 80105D88 26F74D20 */ addiu $s7, %lo(__osPfsLastChannel) # addiu $s7, $s7, 0x4d20 /* B7CF2C 80105D8C AFB90040 */ sw $t9, 0x40($sp) /* B7CF30 80105D90 AFB80044 */ sw $t8, 0x44($sp) /* B7CF34 80105D94 241E0003 */ li $fp, 3 @@ -138,7 +138,7 @@ glabel func_80105CF0 /* B7D064 80105EC4 02A02025 */ move $a0, $s5 /* B7D068 80105EC8 51720009 */ beql $t3, $s2, .L80105EF0 /* B7D06C 80105ECC 24010004 */ li $at, 4 -/* B7D070 80105ED0 0C040644 */ jal func_80101910 +/* B7D070 80105ED0 0C040644 */ jal __osPfsGetStatus /* B7D074 80105ED4 02202825 */ move $a1, $s1 /* B7D078 80105ED8 14400009 */ bnez $v0, .L80105F00 /* B7D07C 80105EDC 00401825 */ move $v1, $v0 diff --git a/data/code_80101910.bss.s b/data/code_80101910.bss.s deleted file mode 100644 index 13828642c0..0000000000 --- a/data/code_80101910.bss.s +++ /dev/null @@ -1,13 +0,0 @@ -.include "macro.inc" - -# assembler directives -.set noat # allow manual use of $at -.set noreorder # don't insert nops after branches -.set gp=64 # allow use of 64-bit general purpose registers - -.section .bss - -.balign 16 - -glabel pifMempakBuf - .space 0x40 diff --git a/data/code_80102420.data.s b/data/code_80102420.data.s index 70477b5f13..f2856ad1d3 100644 --- a/data/code_80102420.data.s +++ b/data/code_80102420.data.s @@ -12,5 +12,5 @@ glabel D_80134CF0 .incbin "baserom.z64", 0xBABE90, 0x4 -glabel D_80134CF4 +glabel __osPfsInodeCacheBank .incbin "baserom.z64", 0xBABE94, 0xC diff --git a/data/code_80105CF0.data.s b/data/code_80105CF0.data.s index 9a09722391..f3749995cf 100644 --- a/data/code_80105CF0.data.s +++ b/data/code_80105CF0.data.s @@ -9,5 +9,5 @@ .balign 16 -glabel D_80134D20 +glabel __osPfsLastChannel .incbin "baserom.z64", 0xBABEC0, 0x10 diff --git a/include/PR/os_cont.h b/include/PR/os_cont.h deleted file mode 100644 index 2754f2504a..0000000000 --- a/include/PR/os_cont.h +++ /dev/null @@ -1,207 +0,0 @@ - -/*==================================================================== - * os_cont.h - * - * Copyright 1995, Silicon Graphics, Inc. - * All Rights Reserved. - * - * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, - * Inc.; the contents of this file may not be disclosed to third - * parties, copied or duplicated in any form, in whole or in part, - * without the prior written permission of Silicon Graphics, Inc. - * - * RESTRICTED RIGHTS LEGEND: - * Use, duplication or disclosure by the Government is subject to - * restrictions as set forth in subdivision (c)(1)(ii) of the Rights - * in Technical Data and Computer Software clause at DFARS - * 252.227-7013, and/or in similar or successor clauses in the FAR, - * DOD or NASA FAR Supplement. Unpublished - rights reserved under the - * Copyright Laws of the United States. - *====================================================================*/ - -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_cont.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:05 $ - *---------------------------------------------------------------------*/ - -#ifndef _OS_CONT_H_ -#define _OS_CONT_H_ - -#ifdef _LANGUAGE_C_PLUS_PLUS -extern "C" { -#endif - -#include -#include "os_message.h" - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Type definitions - * - */ - -/* - * Structure for controllers - */ - -typedef struct { - u16 type; /* Controller Type */ - u8 status; /* Controller status */ - u8 errno; -}OSContStatus; - -typedef struct { - u16 button; - s8 stick_x; /* -80 <= stick_x <= 80 */ - s8 stick_y; /* -80 <= stick_y <= 80 */ - u8 errno; -} OSContPad; - -typedef struct { - void *address; /* Ram pad Address: 11 bits */ - u8 databuffer[32]; /* address of the data buffer */ - u8 addressCrc; /* CRC code for address */ - u8 dataCrc; /* CRC code for data */ - u8 errno; -} OSContRamIo; - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -/************************************************************************** - * - * Global definitions - * - */ - -/* - * Controllers number - */ - -#ifndef _HW_VERSION_1 -#define MAXCONTROLLERS 4 -#else -#define MAXCONTROLLERS 6 -#endif - -/* controller errors */ -#define CONT_NO_RESPONSE_ERROR 0x8 -#define CONT_OVERRUN_ERROR 0x4 -#ifdef _HW_VERSION_1 -#define CONT_FRAME_ERROR 0x2 -#define CONT_COLLISION_ERROR 0x1 -#endif - -/* Controller type */ - -#define CONT_ABSOLUTE 0x0001 -#define CONT_RELATIVE 0x0002 -#define CONT_JOYPORT 0x0004 -#define CONT_EEPROM 0x8000 -#define CONT_EEP16K 0x4000 -#define CONT_TYPE_MASK 0x1f07 -#define CONT_TYPE_NORMAL 0x0005 -#define CONT_TYPE_MOUSE 0x0002 -#define CONT_TYPE_VOICE 0x0100 - -/* Controller status */ - -#define CONT_CARD_ON 0x01 -#define CONT_CARD_PULL 0x02 -#define CONT_ADDR_CRC_ER 0x04 -#define CONT_EEPROM_BUSY 0x80 - -/* Buttons */ - -#define CONT_A 0x8000 -#define CONT_B 0x4000 -#define CONT_G 0x2000 -#define CONT_START 0x1000 -#define CONT_UP 0x0800 -#define CONT_DOWN 0x0400 -#define CONT_LEFT 0x0200 -#define CONT_RIGHT 0x0100 -#define CONT_L 0x0020 -#define CONT_R 0x0010 -#define CONT_E 0x0008 -#define CONT_D 0x0004 -#define CONT_C 0x0002 -#define CONT_F 0x0001 - -/* Nintendo's official button names */ - -#define A_BUTTON CONT_A -#define B_BUTTON CONT_B -#define L_TRIG CONT_L -#define R_TRIG CONT_R -#define Z_TRIG CONT_G -#define START_BUTTON CONT_START -#define U_JPAD CONT_UP -#define L_JPAD CONT_LEFT -#define R_JPAD CONT_RIGHT -#define D_JPAD CONT_DOWN -#define U_CBUTTONS CONT_E -#define L_CBUTTONS CONT_C -#define R_CBUTTONS CONT_F -#define D_CBUTTONS CONT_D - -/* Controller error number */ - -#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ -#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ -#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ -#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ -#define CONT_ERR_NOT_READY 12 -#define CONT_ERR_VOICE_MEMORY 13 -#define CONT_ERR_VOICE_WORD 14 -#define CONT_ERR_VOICE_NO_RESPONSE 15 - - -#if defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) - -/************************************************************************** - * - * Macro definitions - * - */ - - -/************************************************************************** - * - * Extern variables - * - */ - - -/************************************************************************** - * - * Function prototypes - * - */ - -/* Controller interface */ - -extern s32 osContInit(OSMesgQueue *, u8 *, OSContStatus *); -extern s32 osContReset(OSMesgQueue *, OSContStatus *); -extern s32 osContStartQuery(OSMesgQueue *); -extern s32 osContStartReadData(OSMesgQueue *); -#ifndef _HW_VERSION_1 -extern s32 osContSetCh(u8); -#endif -extern void osContGetQuery(OSContStatus *); -extern void osContGetReadData(OSContPad *); - - -#endif /* defined(_LANGUAGE_C) || defined(_LANGUAGE_C_PLUS_PLUS) */ - -#ifdef _LANGUAGE_C_PLUS_PLUS -} -#endif - -#endif /* !_OS_CONT_H_ */ diff --git a/include/PR/os_message.h b/include/PR/os_message.h index 5bc565e360..cd3df6569f 100644 --- a/include/PR/os_message.h +++ b/include/PR/os_message.h @@ -19,14 +19,6 @@ * Copyright Laws of the United States. *====================================================================*/ -/*---------------------------------------------------------------------* - Copyright (C) 1998 Nintendo. (Originated by SGI) - - $RCSfile: os_message.h,v $ - $Revision: 1.1 $ - $Date: 1998/10/09 08:01:15 $ - *---------------------------------------------------------------------*/ - #ifndef _OS_MESSAGE_H_ #define _OS_MESSAGE_H_ diff --git a/include/functions.h b/include/functions.h index 27fed8b31c..c616b8143e 100644 --- a/include/functions.h +++ b/include/functions.h @@ -2409,28 +2409,28 @@ s16 sins(u16); // ? func_801004C0(?); // ? osSpTaskLoad(?); // ? osSpTaskStartGo(?); -// s32 osSetRumble(unk_controller_t *arg0, u32 vibrate); -// void osSetUpMempakWrite(s32 ctrlridx, pif_data_buffer_t* buf); -// s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, unk_controller_t *unk_controller, u32 ctrlridx); -// void __osSiCreateAccessQueue(); -// void __osSiGetAccess(); -// void __osSiRelAccess(); -// s32 osContInit(OSMesgQueue *mq, u8 *ctl_present_bitfield, OSContStatus *status); -// void __osContGetInitData(u8 *ctl_present_bitfield, OSContStatus *status); -// void __osPackRequestData(u8 command); -// s32 osContStartReadData(OSMesgQueue *mq); -// void osContGetReadData(OSContPad *pad); -// void __osPackReadData(); +s32 osSetRumble(OSPfs* pfs, u32 vibrate); +void osSetUpMempakWrite(s32 channel, OSPifRam* buf); +s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel); +void __osSiCreateAccessQueue(); +void __osSiGetAccess(); +void __osSiRelAccess(); +s32 osContInit(OSMesgQueue *mq, u8 *ctl_present_bitfield, OSContStatus *status); +void __osContGetInitData(u8 *ctl_present_bitfield, OSContStatus *status); +void __osPackRequestData(u8 poll); +s32 osContStartReadData(OSMesgQueue *mq); +void osContGetReadData(OSContPad* pad); +void __osPackReadData(); // ? guPerspectiveF(?); // ? guPerspective(?); // ? __osSpRawStartDma(?); -// s32 __osSiRawStartDma(s32 dir, void *addr); +s32 __osSiRawStartDma(s32 dir, void *addr); // ? osSpTaskYield(?); // ? func_801014C0(?); s32 osPfsReadWriteFile(OSPfs* pfs, s32 file_no, u8 flag, s32 offset, s32 nbytes, u8* data_buffer); -// ? func_80101910(?); -// ? func_801019E0(?); -// ? func_80101AA4(?); +s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel); +void __osPfsRequestOneChannel(s32 channel, u8 poll); +void __osPfsGetOneChannelData(s32 channel, OSContStatus* contData); // ? guMtxIdentF(?); void guLookAtF(MtxF* mf, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp); void guLookAt(Mtx*, f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp); @@ -2472,11 +2472,12 @@ void guOrtho(Mtx*, f32, f32, f32, f32, f32, f32, f32); f32 cosf(f32); s16 coss(u16); void osViSetEvent(OSMesgQueue* mq, OSMesg m, u32 retraceCount); -// ? func_8010499C(?); -// ? func_80104A50(?); +s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern); +void __osPfsRequestData(u8 poll); +void __osPfsGetInitData(u8 *pattern, OSContStatus* contData); void guS2DInitBg(uObjBg *bg); // ? func_80104C80(?); -void func_80104D00(u8 a0); +s32 osContSetCh(u8 ch); s32 osPfsFileState(OSPfs* pfs, s32 file_no, OSPfsState* state); s32 osPfsInitPak(OSMesgQueue* mq, OSPfs* pfs, s32 controller_no); // ? func_80105148(?); @@ -2486,7 +2487,7 @@ s32 osPfsInitPak(OSMesgQueue* mq, OSPfs* pfs, s32 controller_no); // ? osAiGetLength(?); void guTranslate(Mtx* m, f32 x, f32 y, f32 z); // ? func_80105CF0(?); -// s32 osReadMempak(OSMesgQueue* ctrlrqueue, u32 ctrlridx, s16 addr, PIF_mempak_data_t* data) +s32 osReadMempak(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data); u8 osMempakAddrCRC(u16 addr); u8 osMempakDataCRC(u8* data); u32 __osSpGetStatus(); diff --git a/include/ultra64.h b/include/ultra64.h index 5c2a3abff0..daf79835b5 100644 --- a/include/ultra64.h +++ b/include/ultra64.h @@ -13,7 +13,6 @@ #include #include #include -//#include #include #include #include diff --git a/include/ultra64/controller.h b/include/ultra64/controller.h index 462621fae4..019ccf89f9 100644 --- a/include/ultra64/controller.h +++ b/include/ultra64/controller.h @@ -2,10 +2,13 @@ #define _ULTRA64_CONTROLLER_H_ #include - -#include +#include #include +#define SIAccessQueueSize 2 +#define BLOCKSIZE 32 +#define MAXCONTROLLERS 4 + #define CONT_CMD_REQUEST_STATUS 0 #define CONT_CMD_READ_BUTTON 1 #define CONT_CMD_READ_MEMPACK 2 @@ -34,10 +37,84 @@ #define CONT_CMD_END 0xFE // Indicates end of a command #define CONT_CMD_EXE 1 // Set pif ram status byte to this to do a command +#define CONT_ERR_NO_CONTROLLER PFS_ERR_NOPACK /* 1 */ +#define CONT_ERR_CONTRFAIL CONT_OVERRUN_ERROR /* 4 */ +#define CONT_ERR_INVALID PFS_ERR_INVALID /* 5 */ +#define CONT_ERR_DEVICE PFS_ERR_DEVICE /* 11 */ +#define CONT_ERR_NOT_READY 12 +#define CONT_ERR_VOICE_MEMORY 13 +#define CONT_ERR_VOICE_WORD 14 +#define CONT_ERR_VOICE_NO_RESPONSE 15 + + #define DIR_STATUS_EMPTY 0 #define DIR_STATUS_UNKNOWN 1 #define DIR_STATUS_OCCUPIED 2 +#define PFS_FORCE 1 +#define PFS_DELETE 1 + +#define PFS_LABEL_AREA 7 + +#define PFS_ERR_NOPACK 1 + +/* controller errors */ +#define CONT_NO_RESPONSE_ERROR 0x8 +#define CONT_OVERRUN_ERROR 0x4 + +/* Controller type */ + +#define CONT_ABSOLUTE 0x0001 +#define CONT_RELATIVE 0x0002 +#define CONT_JOYPORT 0x0004 +#define CONT_EEPROM 0x8000 +#define CONT_EEP16K 0x4000 +#define CONT_TYPE_MASK 0x1F07 +#define CONT_TYPE_NORMAL 0x0005 +#define CONT_TYPE_MOUSE 0x0002 +#define CONT_TYPE_VOICE 0x0100 + +/* Controller status */ + +#define CONT_CARD_ON 0x01 +#define CONT_CARD_PULL 0x02 +#define CONT_ADDR_CRC_ER 0x04 +#define CONT_EEPROM_BUSY 0x80 + +/* Buttons */ + +#define CONT_A 0x8000 +#define CONT_B 0x4000 +#define CONT_G 0x2000 +#define CONT_START 0x1000 +#define CONT_UP 0x0800 +#define CONT_DOWN 0x0400 +#define CONT_LEFT 0x0200 +#define CONT_RIGHT 0x0100 +#define CONT_L 0x0020 +#define CONT_R 0x0010 +#define CONT_E 0x0008 +#define CONT_D 0x0004 +#define CONT_C 0x0002 +#define CONT_F 0x0001 + +/* Nintendo's official button names */ + +#define A_BUTTON CONT_A +#define B_BUTTON CONT_B +#define L_TRIG CONT_L +#define R_TRIG CONT_R +#define Z_TRIG CONT_G +#define START_BUTTON CONT_START +#define U_JPAD CONT_UP +#define L_JPAD CONT_LEFT +#define R_JPAD CONT_RIGHT +#define D_JPAD CONT_DOWN +#define U_CBUTTONS CONT_E +#define L_CBUTTONS CONT_C +#define R_CBUTTONS CONT_F +#define D_CBUTTONS CONT_D + typedef struct { /* 0x00 */ union{ @@ -65,88 +142,76 @@ typedef struct /* 0x03 */ s8 y; } PadInput; // size = 0x4 -typedef struct -{ - u8 slot_type; //0xFF for valid command, 0x00 for don't read this controller, 0xFE for end of commands - u8 bytes_send; //normally 1 (command) - u8 status_hi_bytes_rec_lo; //Status errors as defined in os_cont.h; bytes normally 4 - u8 command; //0: get status, 1: read buttons, 2: read mempak, 3: write mempak, 4: read eeprom, 5: write eeprom, FF: reset controller -} PIF_header_t; - -typedef struct -{ - PIF_header_t hdr; - union{ - PadInput input; - struct{ - u8 ctl_type_lo; - u8 ctl_type_hi; - u8 ctl_status; - u8 dummy; - }; - }; -} PIF_IO_slot_t; - -typedef union -{ - u8 bytes[0x27]; - struct{ - PIF_header_t hdr; - u8 data[0x23]; //Yes, really 0x23 bytes of data - }; -} PIF_mempak_wr_t; +typedef struct { + u32 ram[15]; /* RAM */ + u32 status; +} OSPifRam; typedef struct { - u8 data[0x20]; -} PIF_mempak_data_t; + u16 type; /* Controller Type */ + u8 status; /* Controller status */ + u8 errno; +} OSContStatus; -typedef union -{ - u8 bytes[0x40]; - struct{ - u32 words[0xF]; - u32 status_control; - }; - PIF_IO_slot_t slots[8]; -} pif_data_buffer_t; +typedef struct { + u16 button; + s8 stick_x; /* -80 <= stick_x <= 80 */ + s8 stick_y; /* -80 <= stick_y <= 80 */ + u8 errno; +} OSContPad; -typedef union { - struct { - /* 0x0000 */ u32 unk0; //0x8 is some flag that needs to be set - /* 0x0004 */ OSMesgQueue *ctrlrqueue; - /* 0x0008 */ u32 ctrlridx; //0 to 3 - }; - u8 bytes[0x68]; -} unk_controller_t; // size = 0x68 +typedef struct { + void *address; /* Ram pad Address: 11 bits */ + u8 databuffer[32]; /* address of the data buffer */ + u8 addressCrc; /* CRC code for address */ + u8 dataCrc; /* CRC code for data */ + u8 errno; +} OSContRamIo; -extern pif_data_buffer_t osPifBuffers[4]; +// Original name: __OSContRequesFormat +typedef struct { + u8 align; + u8 txsize; + u8 rxsize; + u8 poll; + u8 typeh; + u8 typel; + u8 status; + u8 align1; +} __OSContRequestHeader; -#define SIAccessQueueSize 2 -extern OSMesg osSiMesgBuff[SIAccessQueueSize]; -extern OSMesgQueue gOsSiMessageQueue; -extern u32 gOsSiAccessQueueCreated; // = 0 +// Original name: __OSContRequesHeaderFormatShort +typedef struct { + u8 txsize; + u8 rxsize; + u8 poll; + u8 typeh; + u8 typel; + u8 status; +} __OSContRequestHeaderAligned; -extern pif_data_buffer_t _osPifInternalBuff; -extern u8 _osCont_lastPollType; -extern u8 _osCont_numControllers; //always 4 -extern u32 gOsContInitialized; // = 0 -extern OSMesgQueue _osContMesgQueue; -extern OSMesg _osContMesgBuff[4]; +// Original Name: __OSContRamReadFormat +typedef struct { + u8 unk_00; + u8 txsize; + u8 rxsize; + u8 poll; + u8 hi; + u8 lo; + u8 data[BLOCKSIZE]; + u8 datacrc; +} __OSContRamHeader; -extern s32 osSetRumble(unk_controller_t *arg0, u32 vibrate); -extern void osSetUpMempakWrite(s32 ctrlridx, pif_data_buffer_t* buf); -extern s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, unk_controller_t *unk_controller, u32 ctrlridx); -extern void __osSiCreateAccessQueue(); -extern void __osSiGetAccess(); -extern void __osSiRelAccess(); -extern s32 osContInit(OSMesgQueue *mq, u8 *ctl_present_bitfield, OSContStatus *status); -extern void __osContGetInitData(u8 *ctl_present_bitfield, OSContStatus *status); -extern void __osPackRequestData(u8 command); +// Original name: __OSContReadFormat +typedef struct { + u8 align; + u8 txsize; + u8 rxsize; + u8 poll; + u16 button; + s8 joyX; + s8 joyY; +} __OSContReadHeader; -extern s32 osContStartReadData(OSMesgQueue *mq); -extern void osContGetReadData(OSContPad *pad); -extern void __osPackReadData(); - -extern s32 __osSiRawStartDma(s32 dir, void *addr); #endif //_ULTRA64_CONTROLLER_H_ diff --git a/include/ultra64/pfs.h b/include/ultra64/pfs.h new file mode 100644 index 0000000000..6d59a58c8f --- /dev/null +++ b/include/ultra64/pfs.h @@ -0,0 +1,70 @@ +#ifndef _ULTRA64_PFS_H_ +#define _ULTRA64_PFS_H_ + +#include + +typedef struct { + int status; + OSMesgQueue* queue; + int channel; + u8 id[32]; + u8 label[32]; + int version; + int dir_size; + int inode_table; /* block location */ + int minode_table; /* mirrioring inode_table */ + int dir_table; /* block location */ + int inode_start_page; /* page # */ + u8 banks; + u8 activebank; +} OSPfs; + +typedef struct { + u32 file_size; /* bytes */ + u32 game_code; + u16 company_code; + char ext_name[4]; + char game_name[16]; +} OSPfsState; + +/* File System size */ +#define OS_PFS_VERSION 0x0200 +#define OS_PFS_VERSION_HI (OS_PFS_VERSION >> 8) +#define OS_PFS_VERSION_LO (OS_PFS_VERSION & 255) + +#define PFS_FILE_NAME_LEN 16 +#define PFS_FILE_EXT_LEN 4 +#define BLOCKSIZE 32 +#define PFS_ONE_PAGE 8 +#define PFS_MAX_BANKS 62 + +/* File System flag */ + +#define PFS_READ 0 +#define PFS_WRITE 1 +#define PFS_CREATE 2 + +/* File System status */ +#define PFS_INITIALIZED 0x1 +#define PFS_CORRUPTED 0x2 +#define PFS_ID_BROKEN 0x4 +#define PFS_MOTOR_INITIALIZED 0x8 +#define PFS_GBPAK_INITIALIZED 0x10 + +/* File System error number */ + +#define PFS_ERR_NOPACK 1 /* no memory card is plugged or */ +#define PFS_ERR_NEW_PACK 2 /* ram pack has been changed to a different one */ +#define PFS_ERR_INCONSISTENT 3 /* need to run Pfschecker*/ +#define PFS_ERR_CONTRFAIL CONT_OVERRUN_ERROR +#define PFS_ERR_INVALID 5 /* invalid parameter or file not exist*/ +#define PFS_ERR_BAD_DATA 6 /* the data read from pack are bad*/ +#define PFS_DATA_FULL 7 /* no free pages on ram pack*/ +#define PFS_DIR_FULL 8 /* no free directories on ram pack*/ +#define PFS_ERR_EXIST 9 /* file exists*/ +#define PFS_ERR_ID_FATAL 10 /* dead ram pack */ +#define PFS_ERR_DEVICE 11 /* wrong device type*/ +#define PFS_ERR_NO_GBCART 12 /* no gb cartridge (64GB-PAK) */ +#define PFS_ERR_NEW_GBCART 13 /* gb cartridge may be changed */ + +#endif diff --git a/include/variables.h b/include/variables.h index bc165ff7be..e50f4a445b 100644 --- a/include/variables.h +++ b/include/variables.h @@ -820,11 +820,11 @@ extern s32 gOverlayLogSeverity; //extern ? D_80134484; extern s32 gSystemArenaLogSeverity; //extern ? D_801344C0; -//extern u32 gOsSiAccessQueueCreated = 0; -//extern u32 gOsContInitialized = 0; +extern u32 gOSSiAccessQueueCreated; // = 0; +extern u32 gOSContInitialized; // = 0 //extern ? D_80134CF0; -//extern ? D_80134CF4; -extern s32 D_80134D20; +extern u8 __osPfsInodeCacheBank; +extern s32 __osPfsLastChannel; //extern ? D_80135130; //extern ? D_80135158; //extern ? D_801351A8; @@ -3737,16 +3737,16 @@ extern u32 __osMalloc_FreeBlockTest_Enable; //extern ? D_801756A0; //extern ? D_801756A8; extern Arena gSystemArena; -//extern pif_data_buffer_t osPifBuffers[4]; -//extern OSMesg osSiMesgBuff[SIAccessQueueSize]; -//extern OSMesgQueue gOsSiMessageQueue; -//extern pif_data_buffer_t _osPifInternalBuff; -extern u8 _osCont_lastPollType; -//extern u8 _osCont_numControllers; -//extern OSMesgQueue _osContMesgQueue; -//extern OSMesg _osContMesgBuff[4]; +extern OSPifRam osPifBuffers[MAXCONTROLLERS]; +extern OSMesg osSiMesgBuff[SIAccessQueueSize]; +extern OSMesgQueue gOSSiMessageQueue; +extern OSPifRam __osPifInternalBuff; +extern u8 __osContLastPoll; +extern u8 __osMaxControllers; +extern OSMesgQueue __osContMesgQueue; +extern OSMesg __osContMesgBuff[4]; //extern ? D_80175860; -extern pif_data_buffer_t pifMempakBuf; +extern OSPifRam pifMempakBuf; //extern ? D_801759A0; //extern ? D_801759A4; //extern ? D_801759A8; @@ -3761,7 +3761,6 @@ extern pif_data_buffer_t pifMempakBuf; //extern ? D_801759BA; //extern ? D_801759BC; //extern ? D_801759BE; - extern u16 gZBuffer[SCREEN_WIDTH * SCREEN_HEIGHT]; // 0x25800 bytes extern u64 gGfxSPTaskOutputBuffer[0x3000]; // 0x18000 bytes extern u8 gGfxSPTaskYieldBuffer[OS_YIELD_DATA_SIZE]; // 0xC00 bytes @@ -3770,7 +3769,6 @@ extern GfxPool gGfxPools[2]; // 0x24820 bytes extern u8 gAudioHeap[0x38000]; // 0x38000 bytes extern u8 gSystemHeap[]; extern MapMarksData* gMapMarkDataTable[]; - //extern ? D_A4040004; //extern ? D_A4040008; //extern ? D_A404000C; diff --git a/include/z64.h b/include/z64.h index 0fe33433c9..aaaf5cd3f1 100644 --- a/include/z64.h +++ b/include/z64.h @@ -1558,7 +1558,7 @@ typedef struct { /* 0x02AE */ u8 pakType[4]; // 1 if rumble pack, 2 if mempak? /* 0x02B2 */ volatile u8 rumbleEnable[4]; /* 0x02B6 */ u8 rumbleCounter[4]; // not clear exact meaning - /* 0x02BC */ unk_controller_t unk_controller[4]; + /* 0x02BC */ OSPfs pfs[4]; /* 0x045C */ volatile u8 rumbleOffFrames; /* 0x045D */ volatile u8 rumbleOnFrames; /* 0x045E */ u8 preNMIShutdown; @@ -1946,30 +1946,6 @@ typedef struct { /* 0x0C */ F3dzexSetModeMacroValue values[4]; } F3dzexSetModeMacro; // size = 0x2C -typedef struct { - /* 0x00 */ s32 status; - /* 0x04 */ OSMesgQueue* queue; - /* 0x08 */ s32 channel; - /* 0x0C */ u8 id[32]; - /* 0x2C */ u8 label[32]; - /* 0x4C */ s32 version; - /* 0x50 */ s32 dir_size; - /* 0x54 */ s32 inode_table; - /* 0x58 */ s32 minode_table; - /* 0x5C */ s32 dir_table; - /* 0x60 */ s32 inode_start_page; - /* 0x64 */ u8 banks; - /* 0x65 */ u8 activebank; -} OSPfs; // size = 0x68 - -typedef struct { - /* 0x00 */ u32 file_size; - /* 0x04 */ u32 game_code; - /* 0x08 */ u16 company_code; - /* 0x0A */ char ext_name[4]; - /* 0x0E */ char game_name[16]; -} OSPfsState; // size = 0x20 - typedef struct { /* 0x00 */ u16* value; /* 0x04 */ const char* name; diff --git a/spec b/spec index e4d7f8ac03..0256452b1e 100644 --- a/spec +++ b/spec @@ -475,8 +475,7 @@ beginseg include "build/src/libultra_code/osSpTaskYield.o" include "build/asm/code_801014C0.o" include "build/data/code_801014C0.bss.o" - include "build/asm/code_80101910.o" - include "build/data/code_80101910.bss.o" + include "build/src/libultra_code/__osPfsGetStatus.o" include "build/asm/guMtxIdentF.o" include "build/src/libultra_code/guLookAt.o" include "build/asm/code_80101EB0.o" @@ -503,10 +502,10 @@ beginseg include "build/src/libultra_code/cosf.o" include "build/src/libultra_code/coss.o" include "build/src/libultra_code/osViSetEvent.o" - include "build/asm/code_80104810.o" + include "build/src/libultra_code/osPfsIsPlug.o" include "build/src/libultra_code/guS2DInitBg.o" include "build/asm/code_80104C80.o" - include "build/asm/code_80104D00.o" + include "build/src/libultra_code/osContSetCh.o" include "build/asm/code_80104D60.o" include "build/asm/code_80104F40.o" include "build/asm/code_80105250.o" diff --git a/src/code/fault.c b/src/code/fault.c index e5c6259658..e4e27fb170 100644 --- a/src/code/fault.c +++ b/src/code/fault.c @@ -1,8 +1,8 @@ #include +#include #include #include #include -#include // data const char* sExceptionNames[] = { diff --git a/src/code/flg_set.c b/src/code/flg_set.c index 941c6f8038..170d144558 100644 --- a/src/code/flg_set.c +++ b/src/code/flg_set.c @@ -1,5 +1,5 @@ #include -#include +#include void FlagSet_Update(GlobalContext* globalCtx) { static s32 entryIdx = 0; diff --git a/src/code/graph.c b/src/code/graph.c index 169134fb1c..06b257f787 100644 --- a/src/code/graph.c +++ b/src/code/graph.c @@ -1,7 +1,7 @@ #include #include +#include #include -#include #define GFXPOOL_HEAD_MAGIC 0x1234 #define GFXPOOL_TAIL_MAGIC 0x5678 diff --git a/src/code/padmgr.c b/src/code/padmgr.c index 132fde97d5..33da52e959 100644 --- a/src/code/padmgr.c +++ b/src/code/padmgr.c @@ -1,10 +1,8 @@ #include +#include #include #include -#include -#include - s32 D_8012D280 = 1; OSMesgQueue* PadMgr_LockSerialMesgQueue(PadMgr* padmgr) { @@ -78,7 +76,7 @@ void PadMgr_RumbleControl(PadMgr* padmgr) { osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック ぶるぶるぶるぶる"); osSyncPrintf(VT_RST); - if (osSetRumble(&padmgr->unk_controller[i], temp) != 0) { + if (osSetRumble(&padmgr->pfs[i], temp) != 0) { padmgr->pakType[i] = 0; osSyncPrintf(VT_FGCOL(YELLOW)); // "A communication error has occurred with the vibraton pack" @@ -100,7 +98,7 @@ void PadMgr_RumbleControl(PadMgr* padmgr) { osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); osSyncPrintf(VT_RST); - if (osSetRumble(&padmgr->unk_controller[i], 0) != 0) { + if (osSetRumble(&padmgr->pfs[i], 0) != 0) { padmgr->pakType[i] = 0; osSyncPrintf(VT_FGCOL(YELLOW)); // "A communication error has occurred with the vibration pack" @@ -139,12 +137,12 @@ void PadMgr_RumbleControl(PadMgr* padmgr) { i = frame % 4; if (padmgr->ctrlrIsConnected[i] && (padmgr->padStatus[i].status & 1) && (padmgr->pakType[i] != 1)) { - var4 = osProbeRumblePak(ctrlrQ, &padmgr->unk_controller[i], i); + var4 = osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i); if (var4 == 0) { padmgr->pakType[i] = 1; - osSetRumble(&padmgr->unk_controller[i], 1); - osSetRumble(&padmgr->unk_controller[i], 0); + osSetRumble(&padmgr->pfs[i], 1); + osSetRumble(&padmgr->pfs[i], 0); osSyncPrintf(VT_FGCOL(YELLOW)); // "Recognized vibration pack" osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パックを認識しました"); @@ -172,14 +170,14 @@ void PadMgr_RumbleStop(PadMgr* padmgr) { ctrlrQ = PadMgr_LockSerialMesgQueue(padmgr); for (i = 0; i < 4; i++) { - if (osProbeRumblePak(ctrlrQ, &padmgr->unk_controller[i], i) == 0) { + if (osProbeRumblePak(ctrlrQ, &padmgr->pfs[i], i) == 0) { if ((gFaultStruct.msgId == 0) && (padmgr->rumbleOnFrames != 0)) { osSyncPrintf(VT_FGCOL(YELLOW)); osSyncPrintf("padmgr: %dコン: %s\n", i + 1, "振動パック 停止"); // "Stop vibration pack" osSyncPrintf(VT_RST); } - osSetRumble(&padmgr->unk_controller[i], 0); + osSetRumble(&padmgr->pfs[i], 0); } } @@ -417,7 +415,7 @@ void PadMgr_Init(PadMgr* padmgr, OSMesgQueue* siIntMsgQ, IrqMgr* irqMgr, OSId id func_800FCD40(siIntMsgQ, &padmgr->validCtrlrsMask, padmgr); padmgr->ncontrollers = 4; - func_80104D00(padmgr->ncontrollers); + osContSetCh(padmgr->ncontrollers); osCreateThread(&padmgr->thread, id, PadMgr_ThreadEntry, padmgr, stack, priority); osStartThread(&padmgr->thread); diff --git a/src/code/z_debug.c b/src/code/z_debug.c index 287c83ea24..a595de5a68 100644 --- a/src/code/z_debug.c +++ b/src/code/z_debug.c @@ -1,6 +1,6 @@ #include +#include #include -#include typedef struct { u8 x; diff --git a/src/code/z_demo.c b/src/code/z_demo.c index a5f5867d1d..df0f8c227c 100644 --- a/src/code/z_demo.c +++ b/src/code/z_demo.c @@ -1,6 +1,6 @@ #include +#include #include -#include u16 D_8011E1C0 = 0; u16 D_8011E1C4 = 0; diff --git a/src/code/z_parameter.c b/src/code/z_parameter.c index c47971f4ee..4caee3394d 100644 --- a/src/code/z_parameter.c +++ b/src/code/z_parameter.c @@ -1,7 +1,7 @@ #include +#include #include #include -#include typedef struct { /* 0x00 */ u8 scene; diff --git a/src/code/z_sample.c b/src/code/z_sample.c index 3805e44144..a6bed1e3c4 100644 --- a/src/code/z_sample.c +++ b/src/code/z_sample.c @@ -1,6 +1,6 @@ #include +#include #include -#include void Sample_HandleStateChange(SampleContext* this) { if (CHECK_PAD(this->state.input[0].press, START_BUTTON)) { diff --git a/src/libultra_code/__osPfsGetStatus.c b/src/libultra_code/__osPfsGetStatus.c new file mode 100644 index 0000000000..a05f722b16 --- /dev/null +++ b/src/libultra_code/__osPfsGetStatus.c @@ -0,0 +1,77 @@ +#include +#include + +OSPifRam pifMempakBuf; + +s32 __osPfsGetStatus(OSMesgQueue* queue, s32 channel) { + s32 ret = 0; + OSMesg msg; + OSContStatus data; + + __osPfsInodeCacheBank = 250; + + __osPfsRequestOneChannel(channel, CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + osRecvMesg(queue, &msg, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &pifMempakBuf); + osRecvMesg(queue, &msg, OS_MESG_BLOCK); + + __osPfsGetOneChannelData(channel, &data); + if (((data.status & CONT_CARD_ON) != 0) && ((data.status & CONT_CARD_PULL) != 0)) { + return PFS_ERR_NEW_PACK; + } else if (data.errno || ((data.status & CONT_CARD_ON) == 0)) { + return PFS_ERR_NOPACK; + } else if ((data.status & CONT_ADDR_CRC_ER) != 0) { + return PFS_ERR_CONTRFAIL; + } + return ret; +} + +void __osPfsRequestOneChannel(s32 channel, u8 poll) { + u8* bufptr; + __OSContRequestHeaderAligned req; + s32 idx; + + __osContLastPoll = CONT_CMD_END; + + pifMempakBuf.status = CONT_CMD_READ_BUTTON; + + bufptr = &pifMempakBuf; + + req.txsize = 1; + req.rxsize = 3; + req.poll = poll; + req.typeh = 0xFF; + req.typel = 0xFF; + req.status = 0xFF; + + for (idx = 0; idx < channel; idx++) { + *bufptr++ = 0; + } + + *((__OSContRequestHeaderAligned*)bufptr) = req; + bufptr += sizeof(req); + *((u8*)bufptr) = CONT_CMD_END; +} + +void __osPfsGetOneChannelData(s32 channel, OSContStatus* contData) { + u8* bufptr; + __OSContRequestHeaderAligned req; + s32 idx; + + bufptr = &pifMempakBuf; + + for (idx = 0; idx < channel; idx++) { + bufptr++; + } + + req = *((__OSContRequestHeaderAligned*)bufptr); + contData->errno = (req.rxsize & 0xC0) >> 4; + if (contData->errno) { + return; + } + + contData->type = (req.typel << 8) | req.typeh; + contData->status = req.status; +} diff --git a/src/libultra_code/__osSiCreateAccessQueue.c b/src/libultra_code/__osSiCreateAccessQueue.c index b1ed321afc..5f886339d1 100644 --- a/src/libultra_code/__osSiCreateAccessQueue.c +++ b/src/libultra_code/__osSiCreateAccessQueue.c @@ -4,23 +4,23 @@ #include OSMesg osSiMesgBuff[SIAccessQueueSize]; -OSMesgQueue gOsSiMessageQueue; -u32 gOsSiAccessQueueCreated = 0; +OSMesgQueue gOSSiMessageQueue; +u32 gOSSiAccessQueueCreated = 0; void __osSiCreateAccessQueue() { - gOsSiAccessQueueCreated = 1; - osCreateMesgQueue(&gOsSiMessageQueue, &osSiMesgBuff[0], SIAccessQueueSize - 1); - osSendMesg(&gOsSiMessageQueue, NULL, OS_MESG_NOBLOCK); + gOSSiAccessQueueCreated = 1; + osCreateMesgQueue(&gOSSiMessageQueue, &osSiMesgBuff[0], SIAccessQueueSize - 1); + osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK); } void __osSiGetAccess() { OSMesg sp1c; - if (!gOsSiAccessQueueCreated) { + if (!gOSSiAccessQueueCreated) { __osSiCreateAccessQueue(); } - osRecvMesg(&gOsSiMessageQueue, &sp1c, OS_MESG_BLOCK); + osRecvMesg(&gOSSiMessageQueue, &sp1c, OS_MESG_BLOCK); } void __osSiRelAccess() { - osSendMesg(&gOsSiMessageQueue, NULL, OS_MESG_NOBLOCK); + osSendMesg(&gOSSiMessageQueue, NULL, OS_MESG_NOBLOCK); } diff --git a/src/libultra_code/code_801031F0.c b/src/libultra_code/code_801031F0.c index 3a5ba4f181..12bb4668f5 100644 --- a/src/libultra_code/code_801031F0.c +++ b/src/libultra_code/code_801031F0.c @@ -15,13 +15,13 @@ s32 osContStartQuery(OSMesgQueue* mq) { ret = 0; __osSiGetAccess(); - if (_osCont_lastPollType != CONT_CMD_REQUEST_STATUS) { + if (__osContLastPoll != CONT_CMD_REQUEST_STATUS) { __osPackRequestData(CONT_CMD_REQUEST_STATUS); - ret = __osSiRawStartDma(OS_WRITE, &_osPifInternalBuff); + ret = __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff); osRecvMesg(mq, NULL, OS_MESG_BLOCK); } - ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff); - _osCont_lastPollType = CONT_CMD_REQUEST_STATUS; + ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff); + __osContLastPoll = CONT_CMD_REQUEST_STATUS; __osSiRelAccess(); return ret; } diff --git a/src/libultra_code/osContInit.c b/src/libultra_code/osContInit.c index 33cc136b8f..8a0bd6b103 100644 --- a/src/libultra_code/osContInit.c +++ b/src/libultra_code/osContInit.c @@ -1,90 +1,90 @@ #include #include - #include -pif_data_buffer_t _osPifInternalBuff; -u8 _osCont_lastPollType; -u8 _osCont_numControllers; // always 4 +OSPifRam __osPifInternalBuff; +u8 __osContLastPoll; +u8 __osMaxControllers; // always 4 -// Not sure if the following is a struct together with the last two variables -u16 unk_80175812; -u32 unk_80175814; -u8 unk_80175818[0x20]; +OSTimer __osEepromTimer; +OSMesgQueue __osEepromTimerMsgQ; +OSMesg __osEepromTimerMsg; -u32 gOsContInitialized = 0; -OSMesgQueue _osContMesgQueue; -OSMesg _osContMesgBuff[4]; +u32 gOSContInitialized = 0; #define HALF_SECOND OS_USEC_TO_CYCLES(500000) -s32 osContInit(OSMesgQueue* mq, u8* ctl_present_bitfield, OSContStatus* status) { +s32 osContInit(OSMesgQueue* mq, u8* ctlBitfield, OSContStatus* status) { OSMesg mesg; s32 ret = 0; OSTime currentTime; OSTimer timer; OSMesgQueue timerqueue; - if (gOsContInitialized) { + if (gOSContInitialized) { return 0; } - gOsContInitialized = 1; + gOSContInitialized = 1; currentTime = osGetTime(); if (HALF_SECOND > currentTime) { osCreateMesgQueue(&timerqueue, &mesg, 1); osSetTimer(&timer, HALF_SECOND - currentTime, 0, &timerqueue, &mesg); osRecvMesg(&timerqueue, &mesg, OS_MESG_BLOCK); } - _osCont_numControllers = 4; - __osPackRequestData(0); - ret = __osSiRawStartDma(OS_WRITE, &_osPifInternalBuff); + __osMaxControllers = MAXCONTROLLERS; + __osPackRequestData(CONT_CMD_REQUEST_STATUS); + ret = __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff); osRecvMesg(mq, &mesg, OS_MESG_BLOCK); - ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff); + ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff); osRecvMesg(mq, &mesg, OS_MESG_BLOCK); - __osContGetInitData(ctl_present_bitfield, status); - _osCont_lastPollType = 0; + __osContGetInitData(ctlBitfield, status); + __osContLastPoll = CONT_CMD_REQUEST_STATUS; __osSiCreateAccessQueue(); - osCreateMesgQueue(&_osContMesgQueue, _osContMesgBuff, 1); + osCreateMesgQueue(&__osEepromTimerMsgQ, &__osEepromTimerMsg, 1); return ret; } -void __osContGetInitData(u8* ctl_present_bitfield, OSContStatus* status) { - PIF_IO_slot_t* slot_ptr; - PIF_IO_slot_t slot; +void __osContGetInitData(u8* ctlBitfield, OSContStatus* status) { + u8* bufptr; + __OSContRequestHeader req; s32 i; - u8 bitfield_temp; - bitfield_temp = 0; - slot_ptr = _osPifInternalBuff.slots; - for (i = 0; i < _osCont_numControllers; i++, slot_ptr++, status++) { - slot = *slot_ptr; - status->errno = (slot.hdr.status_hi_bytes_rec_lo & 0xc0) >> 4; - if (status->errno == 0) { - status->type = slot.ctl_type_hi << 8 | slot.ctl_type_lo; - status->status = slot.ctl_status; - bitfield_temp |= 1 << i; + u8 bitfieldTemp = 0; + bufptr = (u8*)(&__osPifInternalBuff); + for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), status++) { + req = *((__OSContRequestHeader*)bufptr); + status->errno = (req.rxsize & 0xC0) >> 4; + if (status->errno) { + continue; } + status->type = req.typel << 8 | req.typeh; + status->status = req.status; + bitfieldTemp |= 1 << i; } - *ctl_present_bitfield = bitfield_temp; + *ctlBitfield = bitfieldTemp; } -void __osPackRequestData(u8 command) { - PIF_IO_slot_t* slot_ptr; - PIF_IO_slot_t slot; +void __osPackRequestData(u8 poll) { + u8* bufptr; + __OSContRequestHeader req; s32 i; for (i = 0; i < 0xF; i++) { - _osPifInternalBuff.words[i] = 0; + __osPifInternalBuff.ram[i] = 0; } - _osPifInternalBuff.status_control = 1; - slot.hdr.slot_type = 0xFF; - slot.hdr.bytes_send = 1; - slot.hdr.status_hi_bytes_rec_lo = 3; - slot.hdr.command = command; - slot.ctl_type_lo = 0xFF; - slot.ctl_type_hi = 0xFF; - slot.ctl_status = 0xFF; - slot.dummy = 0xFF; - slot_ptr = _osPifInternalBuff.slots; - for (i = 0; i < _osCont_numControllers; i++) { - *slot_ptr++ = slot; + __osPifInternalBuff.status = 1; + + bufptr = &__osPifInternalBuff; + + req.align = 0xFF; + req.txsize = 1; + req.rxsize = 3; + req.poll = poll; + req.typeh = 0xFF; + req.typel = 0xFF; + req.status = 0xFF; + req.align1 = 0xFF; + + for (i = 0; i < __osMaxControllers; i++) { + *((__OSContRequestHeader*)bufptr) = req; + bufptr += sizeof(req); } - slot_ptr->hdr.slot_type = 254; + *((u8*)bufptr) = 254; } diff --git a/src/libultra_code/osContSetCh.c b/src/libultra_code/osContSetCh.c new file mode 100644 index 0000000000..cd5c09de96 --- /dev/null +++ b/src/libultra_code/osContSetCh.c @@ -0,0 +1,21 @@ +#include +#include + +/* + * s32 osContSetCh(u8 ch) + * This function specifies the number of devices for the functions to access when those functions access to multiple + * direct SI devices. + */ +s32 osContSetCh(u8 ch) { + __osSiGetAccess(); + + if (ch > MAXCONTROLLERS) { + __osMaxControllers = MAXCONTROLLERS; + } else { + __osMaxControllers = ch; + } + + __osContLastPoll = -2; + __osSiRelAccess(); + return 0; +} diff --git a/src/libultra_code/osContStartReadData.c b/src/libultra_code/osContStartReadData.c index 60e415028a..d45b07f6e8 100644 --- a/src/libultra_code/osContStartReadData.c +++ b/src/libultra_code/osContStartReadData.c @@ -1,56 +1,56 @@ #include #include - #include s32 osContStartReadData(OSMesgQueue* mq) { s32 ret; - __osSiGetAccess(); // __osSiGetAccess - if (_osCont_lastPollType != 1) { + __osSiGetAccess(); + if (__osContLastPoll != 1) { __osPackReadData(); - __osSiRawStartDma(OS_WRITE, &_osPifInternalBuff); + __osSiRawStartDma(OS_WRITE, &__osPifInternalBuff); osRecvMesg(mq, NULL, OS_MESG_BLOCK); } - ret = __osSiRawStartDma(OS_READ, &_osPifInternalBuff); - _osCont_lastPollType = 1; + ret = __osSiRawStartDma(OS_READ, &__osPifInternalBuff); + __osContLastPoll = CONT_CMD_READ_BUTTON; __osSiRelAccess(); return ret; } -void osContGetReadData(OSContPad* pad) { - PIF_IO_slot_t* slot_ptr; - PIF_IO_slot_t slot; +void osContGetReadData(OSContPad* contData) { + u8* bufptr; + __OSContReadHeader read; s32 i; - slot_ptr = _osPifInternalBuff.slots; - for (i = 0; i < _osCont_numControllers; i++, slot_ptr++, pad++) { - slot = *slot_ptr; - pad->errno = (slot.hdr.status_hi_bytes_rec_lo & 0xc0) >> 4; - if (pad->errno == 0) { - pad->button = slot.input.button; - pad->stick_x = slot.input.x; - pad->stick_y = slot.input.y; + bufptr = (u8*)(&__osPifInternalBuff); + for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(read), contData++) { + read = *((__OSContReadHeader*)bufptr); + contData->errno = (read.rxsize & 0xC0) >> 4; + if (contData->errno == 0) { + contData->button = read.button; + contData->stick_x = read.joyX; + contData->stick_y = read.joyY; } }; } void __osPackReadData() { - PIF_IO_slot_t* slot_ptr; - PIF_IO_slot_t slot; + u8* bufptr; + __OSContReadHeader read; s32 i; - slot_ptr = _osPifInternalBuff.slots; + bufptr = (u8*)(&__osPifInternalBuff); for (i = 0; i < 0xF; i++) { - _osPifInternalBuff.words[i] = 0; + __osPifInternalBuff.ram[i] = 0; } - _osPifInternalBuff.status_control = 1; - slot.hdr.slot_type = 0xFF; - slot.hdr.bytes_send = 1; - slot.hdr.status_hi_bytes_rec_lo = 4; - slot.hdr.command = 1; - slot.input.button = 0xFFFF; - slot.input.x = 0xFF; - slot.input.y = 0xFF; - for (i = 0; i < _osCont_numControllers; i++) { - *slot_ptr++ = slot; + __osPifInternalBuff.status = 1; + read.align = 0xFF; + read.txsize = 1; + read.rxsize = 4; + read.poll = CONT_CMD_READ_BUTTON; + read.button = 0xFFFF; + read.joyX = 0xFF; + read.joyY = 0xFF; + for (i = 0; i < __osMaxControllers; i++) { + *((__OSContReadHeader*)bufptr) = read; + bufptr += sizeof(read); } - slot_ptr->hdr.slot_type = 0xFE; + *((u8*)bufptr) = CONT_CMD_END; } diff --git a/src/libultra_code/osMempakAddrCRC.c b/src/libultra_code/osMempakAddrCRC.c index 4565ff4eed..cf4eb8c4d2 100644 --- a/src/libultra_code/osMempakAddrCRC.c +++ b/src/libultra_code/osMempakAddrCRC.c @@ -1,6 +1,5 @@ #include #include - #include // Valid addr up to 0x7FF diff --git a/src/libultra_code/osPfsIsPlug.c b/src/libultra_code/osPfsIsPlug.c new file mode 100644 index 0000000000..bb221a07e2 --- /dev/null +++ b/src/libultra_code/osPfsIsPlug.c @@ -0,0 +1,93 @@ +#include +#include + +s32 osPfsIsPlug(OSMesgQueue* mq, u8* pattern) { + s32 ret = 0; + OSMesg msg; + u8 bitpattern; + OSContStatus contData[MAXCONTROLLERS]; + s32 channel; + u8 bits = 0; + s32 crcErrorCount = 3; + + __osSiGetAccess(); + + do { + __osPfsRequestData(CONT_CMD_REQUEST_STATUS); + + ret = __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + ret = __osSiRawStartDma(OS_READ, &pifMempakBuf); + osRecvMesg(mq, &msg, OS_MESG_BLOCK); + + __osPfsGetInitData(&bitpattern, &contData[0]); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].status & CONT_ADDR_CRC_ER) == 0) { + crcErrorCount--; + break; + } + } + if (channel == __osMaxControllers) { + crcErrorCount = 0; + } + } while (crcErrorCount > 0); + + for (channel = 0; channel < __osMaxControllers; channel++) { + if ((contData[channel].errno == 0) && ((contData[channel].status & CONT_CARD_ON) != 0)) { + bits |= (1 << channel); + } + } + __osSiRelAccess(); + *pattern = bits; + return ret; +} + +void __osPfsRequestData(u8 poll) { + u8* bufPtr = &pifMempakBuf; + __OSContRequestHeader req; + s32 i; + + __osContLastPoll = poll; + + pifMempakBuf.status = 1; + + req.align = 0xFF; + req.txsize = 1; + req.rxsize = 3; + req.poll = poll; + req.typeh = 0xFF; + req.typel = 0xFF; + req.status = 0xFF; + req.align1 = 0xFF; + + for (i = 0; i < __osMaxControllers; i++) { + *((__OSContRequestHeader*)bufPtr) = req; + bufPtr += sizeof(req); + } + *((u8*)bufPtr) = CONT_CMD_END; +} + +void __osPfsGetInitData(u8* pattern, OSContStatus* contData) { + u8* bufptr; + __OSContRequestHeader req; + s32 i; + u8 bits = 0; + + bufptr = &pifMempakBuf; + + for (i = 0; i < __osMaxControllers; i++, bufptr += sizeof(req), contData++) { + req = *((__OSContRequestHeader*)bufptr); + contData->errno = ((req.rxsize & 0xC0) >> 4); + + if (contData->errno) { + continue; + } + + contData->type = ((req.typel << 8) | req.typeh); + contData->status = req.status; + bits |= (1 << i); + } + *pattern = bits; +} diff --git a/src/libultra_code/osReadMempak.c b/src/libultra_code/osReadMempak.c index 9b6955a7d8..6640db0b63 100644 --- a/src/libultra_code/osReadMempak.c +++ b/src/libultra_code/osReadMempak.c @@ -1,50 +1,52 @@ #include #include - #include -s32 osReadMempak(OSMesgQueue* ctrlrqueue, s32 ctrlridx, u16 addr, PIF_mempak_data_t* data) { +#define BLOCKSIZE 32 + +s32 osReadMempak(OSMesgQueue* ctrlrqueue, s32 channel, u16 addr, u8* data) { s32 ret; s32 i; u8* bufptr; - s32 read_try_count = 2; + s32 retryCount = 2; __osSiGetAccess(); do { - if ((_osCont_lastPollType != 2) || (ctrlridx != D_80134D20)) { - bufptr = &pifMempakBuf.bytes[0]; - _osCont_lastPollType = 2; - D_80134D20 = ctrlridx; + bufptr = &pifMempakBuf; + if ((__osContLastPoll != 2) || (__osPfsLastChannel != channel)) { + + __osContLastPoll = 2; + __osPfsLastChannel = channel; // clang-format off - for (i = 0; i < ctrlridx; i++) { *bufptr++ = 0; } + for (i = 0; i < channel; i++) { *bufptr++ = 0; } // clang-format on - pifMempakBuf.status_control = 1; - ((PIF_header_t*)bufptr)->slot_type = 0xff; - ((PIF_header_t*)bufptr)->bytes_send = 3; - ((PIF_header_t*)bufptr)->status_hi_bytes_rec_lo = 0x21; - ((PIF_header_t*)bufptr)->command = 2; // read mempak; send byte 0 + pifMempakBuf.status = 1; + ((__OSContRamHeader*)bufptr)->unk_00 = 0xFF; + ((__OSContRamHeader*)bufptr)->txsize = 3; + ((__OSContRamHeader*)bufptr)->rxsize = 0x21; + ((__OSContRamHeader*)bufptr)->poll = CONT_CMD_READ_MEMPACK; // read mempak; send byte 0 + ((__OSContRamHeader*)bufptr)->datacrc = 0xFF; // read mempak; send byte 0 // Received bytes are 6-26 inclusive - bufptr[0x26] = 0xff; // last byte of receive - bufptr[0x27] = 0xfe; // End of commands + bufptr[sizeof(__OSContRamHeader)] = CONT_CMD_END; // End of commands } else { - bufptr = &pifMempakBuf.bytes[ctrlridx]; + bufptr += channel; } - bufptr[4] = addr >> 3; // send byte 1 - bufptr[5] = (s8)(osMempakAddrCRC(addr) | (addr << 5)); // send byte 2 - __osSiRawStartDma(1, &pifMempakBuf); - osRecvMesg(ctrlrqueue, 0, 1); - __osSiRawStartDma(0, &pifMempakBuf); - osRecvMesg(ctrlrqueue, 0, 1); - ret = (((PIF_header_t*)bufptr)->status_hi_bytes_rec_lo & 0xc0) >> 4; + ((__OSContRamHeader*)bufptr)->hi = addr >> 3; // send byte 1 + ((__OSContRamHeader*)bufptr)->lo = (s8)(osMempakAddrCRC(addr) | (addr << 5)); // send byte 2 + __osSiRawStartDma(OS_WRITE, &pifMempakBuf); + osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); + __osSiRawStartDma(OS_READ, &pifMempakBuf); + osRecvMesg(ctrlrqueue, NULL, OS_MESG_BLOCK); + ret = (((__OSContRamHeader*)bufptr)->rxsize & 0xC0) >> 4; if (!ret) { - if (bufptr[0x26] != osMempakDataCRC(bufptr + 6)) { - ret = func_80101910(ctrlrqueue, ctrlridx); + if (((__OSContRamHeader*)bufptr)->datacrc != osMempakDataCRC(bufptr + 6)) { + ret = __osPfsGetStatus(ctrlrqueue, channel); if (ret) { break; } ret = 4; // Retry } else { - bcopy(bufptr + 6, data, 0x20); + bcopy(bufptr + 6, data, BLOCKSIZE); } } else { ret = 1; // Error @@ -52,7 +54,7 @@ s32 osReadMempak(OSMesgQueue* ctrlrqueue, s32 ctrlridx, u16 addr, PIF_mempak_dat if (ret != 4) { break; } - } while (0 <= read_try_count--); + } while (0 <= retryCount--); __osSiRelAccess(); return ret; } diff --git a/src/libultra_code/osRumblePak.c b/src/libultra_code/osRumblePak.c index d2b47f2c66..6be487e457 100644 --- a/src/libultra_code/osRumblePak.c +++ b/src/libultra_code/osRumblePak.c @@ -1,41 +1,43 @@ #include #include - #include -pif_data_buffer_t osPifBuffers[4]; +#define BANK_ADDR 0x400 +#define MOTOR_ID 0x80 + +OSPifRam osPifBuffers[MAXCONTROLLERS]; // func_800CF990 in 1.0 -s32 osSetRumble(unk_controller_t* arg0, u32 vibrate) { +s32 osSetRumble(OSPfs* pfs, u32 vibrate) { s32 i; s32 ret; u8* buf; - buf = (u8*)&osPifBuffers[arg0->ctrlridx]; - if (!(arg0->unk0 & 8)) { + buf = (u8*)&osPifBuffers[pfs->channel]; + if (!(pfs->status & 8)) { return 5; } __osSiGetAccess(); - osPifBuffers[arg0->ctrlridx].status_control = 1; - buf += arg0->ctrlridx; - for (i = 0; i < 0x20; i++) { - ((PIF_mempak_wr_t*)buf)->data[i + 2] = vibrate; + osPifBuffers[pfs->channel].status = 1; + buf += pfs->channel; + for (i = 0; i < BLOCKSIZE; i++) { + ((__OSContRamHeader*)buf)->data[i] = vibrate; } - _osCont_lastPollType = 0xfe; // last controller poll type? - __osSiRawStartDma(OS_WRITE, &osPifBuffers[arg0->ctrlridx]); - osRecvMesg(arg0->ctrlrqueue, NULL, OS_MESG_BLOCK); - __osSiRawStartDma(OS_READ, &osPifBuffers[arg0->ctrlridx]); - osRecvMesg(arg0->ctrlrqueue, NULL, OS_MESG_BLOCK); - ret = ((PIF_mempak_wr_t*)buf)->hdr.status_hi_bytes_rec_lo & 0xc0; + __osContLastPoll = CONT_CMD_END; + __osSiRawStartDma(OS_WRITE, &osPifBuffers[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + __osSiRawStartDma(OS_READ, &osPifBuffers[pfs->channel]); + osRecvMesg(pfs->queue, NULL, OS_MESG_BLOCK); + ret = ((__OSContRamHeader*)buf)->rxsize & 0xC0; if (!ret) { if (!vibrate) { - if (((PIF_mempak_wr_t*)buf)->data[0x22] != 0) { - ret = 4; + if (((__OSContRamHeader*)buf)->datacrc != 0) { + ret = PFS_ERR_CONTRFAIL; } } else { - if (((PIF_mempak_wr_t*)buf)->data[0x22] != 0xeb) { - ret = 4; + if (((__OSContRamHeader*)buf)->datacrc != 0xEB) { + ret = PFS_ERR_CONTRFAIL; } } } @@ -43,47 +45,43 @@ s32 osSetRumble(unk_controller_t* arg0, u32 vibrate) { return ret; } -void osSetUpMempakWrite(s32 ctrlridx, pif_data_buffer_t* buf) { - u8* buf_ptr = (u8*)buf; - PIF_mempak_wr_t mempakwr; +void osSetUpMempakWrite(s32 channel, OSPifRam* buf) { + u8* bufptr = (u8*)buf; + __OSContRamHeader mempakwr; s32 i; - mempakwr.hdr.slot_type = 0xFF; - mempakwr.hdr.bytes_send = 0x23; - mempakwr.hdr.status_hi_bytes_rec_lo = 1; - mempakwr.hdr.command = 3; // write mempak - mempakwr.data[0] = 0x600 >> 3; - mempakwr.data[1] = (u8)(osMempakAddrCRC(0x600) | (0x600 << 5)); - if (ctrlridx != 0) { - for (i = 0; i < ctrlridx; ++i) { - *buf_ptr++ = 0; + mempakwr.unk_00 = 0xFF; + mempakwr.txsize = 0x23; + mempakwr.rxsize = 1; + mempakwr.poll = 3; // write mempak + mempakwr.hi = 0x600 >> 3; + mempakwr.lo = (u8)(osMempakAddrCRC(0x600) | (0x600 << 5)); + if (channel != 0) { + for (i = 0; i < channel; ++i) { + *bufptr++ = 0; } } - *(PIF_mempak_wr_t*)buf_ptr = mempakwr; - buf_ptr += 0x27; - *buf_ptr = 0xFE; + *(__OSContRamHeader*)bufptr = mempakwr; + bufptr += sizeof(mempakwr); + *bufptr = 0xFE; } -typedef struct { - u8 unk[0x20]; -} unk_sp24_t; - -s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, unk_controller_t* unk_controller, u32 ctrlridx) { +s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, OSPfs* pfs, u32 channel) { s32 ret; - unk_sp24_t sp24; + u8 sp24[BLOCKSIZE]; - unk_controller->ctrlrqueue = ctrlrqueue; - unk_controller->ctrlridx = ctrlridx; - unk_controller->bytes[0x65] = 0xff; - unk_controller->unk0 = 0; + pfs->queue = ctrlrqueue; + pfs->channel = channel; + pfs->activebank = 0xFF; + pfs->status = 0; - ret = func_80104C80(unk_controller, 0xfe); + ret = func_80104C80(pfs, 0xFE); if (ret == 2) { - ret = func_80104C80(unk_controller, 0x80); + ret = func_80104C80(pfs, MOTOR_ID); } if (ret != 0) { return ret; } - ret = osReadMempak(ctrlrqueue, ctrlridx, 0x400, &sp24); + ret = osReadMempak(ctrlrqueue, channel, BANK_ADDR, sp24); ret = ret; if (ret == 2) { ret = 4; // "Controller pack communication error" @@ -91,29 +89,29 @@ s32 osProbeRumblePak(OSMesgQueue* ctrlrqueue, unk_controller_t* unk_controller, if (ret != 0) { return ret; } - if (sp24.unk[0x1F] == 0xfe) { - return 0xb; // possibly controller pack? (Some other valid return value other than rumble pak) + if (sp24[BLOCKSIZE - 1] == 0xFE) { + return 0xB; } - ret = func_80104C80(unk_controller, 0x80); + ret = func_80104C80(pfs, MOTOR_ID); if (ret == 2) { ret = 4; // "Controller pack communication error" } if (ret != 0) { return ret; } - ret = osReadMempak(ctrlrqueue, ctrlridx, 0x400, &sp24); + ret = osReadMempak(ctrlrqueue, channel, BANK_ADDR, sp24); if (ret == 2) { ret = 4; // "Controller pack communication error" } if (ret != 0) { return ret; } - if (sp24.unk[0x1F] != 0x80) { - return 0xb; // possibly controller pack? (Some other valid return value other than rumble pak) + if (sp24[BLOCKSIZE - 1] != MOTOR_ID) { + return 0xB; } - if ((unk_controller->unk0 & 8) == 0) { - osSetUpMempakWrite(ctrlridx, &osPifBuffers[ctrlridx]); + if ((pfs->status & PFS_MOTOR_INITIALIZED) == 0) { + osSetUpMempakWrite(channel, &osPifBuffers[channel]); } - unk_controller->unk0 = 8; + pfs->status = PFS_MOTOR_INITIALIZED; return 0; // "Recognized rumble pak" }