.include "macros.inc"
.section .text, "ax"
.global TRKSetBufferUsed
TRKSetBufferUsed:
stw r4, 4(r3)
blr
.global TRKInitializeMessageBuffers
TRKInitializeMessageBuffers:
mflr r0
lis r3, gTRKMsgBufs@ha
stw r0, 4(r1)
addi r0, r3, gTRKMsgBufs@l
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
stw r30, 8(r1)
li r30, 0
mulli r4, r30, 0x890
add r31, r0, r4
lbl_800880B0:
mr r3, r31
bl TRKInitializeMutex
mr r3, r31
bl TRKAcquireMutex
addi r3, r31, 0
li r4, 0
bl TRKSetBufferUsed
mr r3, r31
bl TRKReleaseMutex
addi r30, r30, 1
addi r31, r31, 0x890
cmpwi r30, 3
blt lbl_800880B0
lwz r31, 0xc(r1)
li r3, 0
lwz r30, 8(r1)
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.global TRKGetFreeBuffer
TRKGetFreeBuffer:
mflr r0
stw r0, 4(r1)
li r0, 0
stwu r1, -0x20(r1)
stmw r27, 0xc(r1)
addi r28, r4, 0
addi r27, r3, 0
li r31, 0x300
li r30, 0
stw r0, 0(r4)
b lbl_8008817C
lbl_8008812C:
mr r3, r30
bl TRKGetBuffer
mr r29, r3
bl TRKAcquireMutex
lwz r0, 4(r29)
cmpwi r0, 0
bne lbl_80088170
addi r3, r29, 0
li r4, 1
bl TRKResetBuffer
addi r3, r29, 0
li r4, 1
bl TRKSetBufferUsed
stw r29, 0(r28)
li r31, 0
stw r30, 0(r27)
li r30, 3
lbl_80088170:
mr r3, r29
bl TRKReleaseMutex
addi r30, r30, 1
lbl_8008817C:
cmpwi r30, 3
blt lbl_8008812C
mr r3, r31
lmw r27, 0xc(r1)
addi r1, r1, 0x20
lwz r0, 4(r1)
mtlr r0
blr
.global TRKGetBuffer
TRKGetBuffer:
cmpwi r3, 0
li r0, 0
blt lbl_800881C0
cmpwi r3, 3
bge lbl_800881C0
mulli r4, r3, 0x890
lis r3, gTRKMsgBufs@ha
addi r0, r3, gTRKMsgBufs@l
add r0, r0, r4
lbl_800881C0:
mr r3, r0
blr
.global TRKReleaseBuffer
TRKReleaseBuffer:
mflr r0
cmpwi r3, -1
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
beq lbl_8008821C
cmpwi r3, 0
blt lbl_8008821C
cmpwi r3, 3
bge lbl_8008821C
mulli r4, r3, 0x890
lis r3, gTRKMsgBufs@ha
addi r0, r3, gTRKMsgBufs@l
add r31, r0, r4
addi r3, r31, 0
bl TRKAcquireMutex
addi r3, r31, 0
li r4, 0
bl TRKSetBufferUsed
mr r3, r31
bl TRKReleaseMutex
lbl_8008821C:
lwz r31, 0xc(r1)
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.global TRKResetBuffer
TRKResetBuffer:
mflr r0
li r5, 0
stw r0, 4(r1)
clrlwi. r0, r4, 0x18
stwu r1, -8(r1)
stw r5, 8(r3)
stw r5, 0xc(r3)
bne lbl_80088260
addi r3, r3, 0x10
li r4, 0
li r5, 0x880
bl TRK_memset
lbl_80088260:
addi r1, r1, 8
lwz r0, 4(r1)
mtlr r0
blr
.global TRKSetBufferPosition
TRKSetBufferPosition:
cmplwi r4, 0x880
li r5, 0
ble lbl_80088284
li r5, 0x301
b lbl_80088298
lbl_80088284:
stw r4, 0xc(r3)
lwz r0, 8(r3)
cmplw r4, r0
ble lbl_80088298
stw r4, 8(r3)
lbl_80088298:
mr r3, r5
blr
.global TRKAppendBuffer
TRKAppendBuffer:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
li r31, 0
stw r30, 0x10(r1)
or. r30, r5, r5
stw r29, 0xc(r1)
addi r29, r3, 0
bne lbl_800882D0
li r3, 0
b lbl_80088328
lbl_800882D0:
lwz r3, 0xc(r29)
subfic r0, r3, 0x880
cmplw r0, r30
bge lbl_800882E8
li r31, 0x301
mr r30, r0
lbl_800882E8:
cmplwi r30, 1
bne lbl_80088300
lbz r0, 0(r4)
add r3, r29, r3
stb r0, 0x10(r3)
b lbl_80088310
lbl_80088300:
addi r3, r3, 0x10
addi r5, r30, 0
add r3, r29, r3
bl TRK_memcpy
lbl_80088310:
lwz r0, 0xc(r29)
addi r3, r31, 0
add r0, r0, r30
stw r0, 0xc(r29)
lwz r0, 0xc(r29)
stw r0, 8(r29)
lbl_80088328:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer
TRKReadBuffer:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
li r31, 0
stw r30, 0x10(r1)
or. r30, r5, r5
stw r29, 0xc(r1)
addi r29, r3, 0
addi r3, r4, 0
bne lbl_80088378
li r3, 0
b lbl_800883B4
lbl_80088378:
lwz r4, 0xc(r29)
lwz r0, 8(r29)
subf r0, r4, r0
cmplw r30, r0
ble lbl_80088394
li r31, 0x302
mr r30, r0
lbl_80088394:
addi r4, r4, 0x10
addi r5, r30, 0
add r4, r29, r4
bl TRK_memcpy
lwz r0, 0xc(r29)
addi r3, r31, 0
add r0, r0, r30
stw r0, 0xc(r29)
lbl_800883B4:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKAppendBuffer1_ui16
TRKAppendBuffer1_ui16:
mflr r0
lis r5, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x10(r1)
sth r4, 8(r1)
lwz r0, gTRKBigEndian@l(r5)
cmpwi r0, 0
beq lbl_800883F8
addi r4, r1, 8
b lbl_8008840C
lbl_800883F8:
lbz r0, 9(r1)
addi r4, r1, 0xc
stb r0, 0xc(r1)
lbz r0, 8(r1)
stb r0, 0xd(r1)
lbl_8008840C:
li r5, 2
bl TRKAppendBuffer
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.global TRKAppendBuffer1_ui32
TRKAppendBuffer1_ui32:
mflr r0
lis r5, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r4, 8(r1)
lwz r0, gTRKBigEndian@l(r5)
cmpwi r0, 0
beq lbl_8008844C
addi r4, r1, 8
b lbl_80088470
lbl_8008844C:
lbz r0, 0xb(r1)
addi r4, r1, 0xc
stb r0, 0xc(r1)
lbz r0, 0xa(r1)
stb r0, 0xd(r1)
lbz r0, 9(r1)
stb r0, 0xe(r1)
lbz r0, 8(r1)
stb r0, 0xf(r1)
lbl_80088470:
li r5, 4
bl TRKAppendBuffer
addi r1, r1, 0x10
lwz r0, 4(r1)
mtlr r0
blr
.global TRKAppendBuffer1_ui64
TRKAppendBuffer1_ui64:
mflr r0
lis r4, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r5, 8(r1)
stw r6, 0xc(r1)
lwz r0, gTRKBigEndian@l(r4)
cmpwi r0, 0
beq lbl_800884B4
addi r4, r1, 8
b lbl_800884F8
lbl_800884B4:
lbz r0, 0xf(r1)
addi r4, r1, 0x10
stb r0, 0x10(r1)
lbz r0, 0xe(r1)
stb r0, 0x11(r1)
lbz r0, 0xd(r1)
stb r0, 0x12(r1)
lbz r0, 0xc(r1)
stb r0, 0x13(r1)
lbz r0, 0xb(r1)
stb r0, 0x14(r1)
lbz r0, 0xa(r1)
stb r0, 0x15(r1)
lbz r0, 9(r1)
stb r0, 0x16(r1)
lbz r0, 8(r1)
stb r0, 0x17(r1)
lbl_800884F8:
li r5, 8
bl TRKAppendBuffer
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKAppendBuffer_ui8
TRKAppendBuffer_ui8:
li r9, 0
li r0, 0
b lbl_80088560
lbl_8008851C:
lwz r7, 0xc(r3)
lbz r8, 0(r4)
cmplwi r7, 0x880
blt lbl_80088534
li r7, 0x301
b lbl_80088554
lbl_80088534:
addi r6, r7, 1
addi r0, r7, 0x10
stw r6, 0xc(r3)
li r7, 0
stbx r8, r3, r0
lwz r6, 8(r3)
addi r0, r6, 1
stw r0, 8(r3)
lbl_80088554:
addi r0, r7, 0
addi r9, r9, 1
addi r4, r4, 1
lbl_80088560:
cmpwi r0, 0
bne lbl_80088570
cmpw r9, r5
blt lbl_8008851C
lbl_80088570:
mr r3, r0
blr
.global TRKAppendBuffer_ui32
TRKAppendBuffer_ui32:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
li r30, 0
slwi r0, r30, 2
stw r29, 0xc(r1)
add r31, r4, r0
addi r29, r5, 0
stw r28, 8(r1)
addi r28, r3, 0
li r3, 0
b lbl_800885C4
lbl_800885B0:
mr r3, r28
lwz r4, 0(r31)
bl TRKAppendBuffer1_ui32
addi r30, r30, 1
addi r31, r31, 4
lbl_800885C4:
cmpwi r3, 0
bne lbl_800885D4
cmpw r30, r29
blt lbl_800885B0
lbl_800885D4:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
lwz r28, 8(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer1_ui8
TRKReadBuffer1_ui8:
mflr r0
li r5, 1
stw r0, 4(r1)
stwu r1, -8(r1)
bl TRKReadBuffer
addi r1, r1, 8
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer1_ui16
TRKReadBuffer1_ui16:
mflr r0
lis r5, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
addi r30, r4, 0
lwz r0, gTRKBigEndian@l(r5)
cmpwi r0, 0
beq lbl_80088648
mr r31, r30
b lbl_8008864C
lbl_80088648:
addi r31, r1, 8
lbl_8008864C:
addi r4, r31, 0
li r5, 2
bl TRKReadBuffer
lis r4, gTRKBigEndian@ha
lwz r0, gTRKBigEndian@l(r4)
cmpwi r0, 0
bne lbl_80088680
cmpwi r3, 0
bne lbl_80088680
lbz r0, 1(r31)
stb r0, 0(r30)
lbz r0, 0(r31)
stb r0, 1(r30)
lbl_80088680:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer1_ui32
TRKReadBuffer1_ui32:
mflr r0
lis r5, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
addi r30, r4, 0
lwz r0, gTRKBigEndian@l(r5)
cmpwi r0, 0
beq lbl_800886C8
mr r31, r30
b lbl_800886CC
lbl_800886C8:
addi r31, r1, 8
lbl_800886CC:
addi r4, r31, 0
li r5, 4
bl TRKReadBuffer
lis r4, gTRKBigEndian@ha
lwz r0, gTRKBigEndian@l(r4)
cmpwi r0, 0
bne lbl_80088710
cmpwi r3, 0
bne lbl_80088710
lbz r0, 3(r31)
stb r0, 0(r30)
lbz r0, 2(r31)
stb r0, 1(r30)
lbz r0, 1(r31)
stb r0, 2(r30)
lbz r0, 0(r31)
stb r0, 3(r30)
lbl_80088710:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer1_ui64
TRKReadBuffer1_ui64:
mflr r0
lis r5, gTRKBigEndian@ha
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
addi r30, r4, 0
lwz r0, gTRKBigEndian@l(r5)
cmpwi r0, 0
beq lbl_80088758
mr r31, r30
b lbl_8008875C
lbl_80088758:
addi r31, r1, 8
lbl_8008875C:
addi r4, r31, 0
li r5, 8
bl TRKReadBuffer
lis r4, gTRKBigEndian@ha
lwz r0, gTRKBigEndian@l(r4)
cmpwi r0, 0
bne lbl_800887C0
cmpwi r3, 0
bne lbl_800887C0
lbz r0, 7(r31)
stb r0, 0(r30)
lbz r0, 6(r31)
stb r0, 1(r30)
lbz r0, 5(r31)
stb r0, 2(r30)
lbz r0, 4(r31)
stb r0, 3(r30)
lbz r0, 3(r31)
stb r0, 4(r30)
lbz r0, 2(r31)
stb r0, 5(r30)
lbz r0, 1(r31)
stb r0, 6(r30)
lbz r0, 0(r31)
stb r0, 7(r30)
lbl_800887C0:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer_ui8
TRKReadBuffer_ui8:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
li r31, 0
stw r30, 0x10(r1)
addi r30, r5, 0
stw r29, 0xc(r1)
addi r29, r4, 0
stw r28, 8(r1)
addi r28, r3, 0
li r3, 0
b lbl_8008881C
lbl_8008880C:
addi r3, r28, 0
add r4, r29, r31
bl TRKReadBuffer1_ui8
addi r31, r31, 1
lbl_8008881C:
cmpwi r3, 0
bne lbl_8008882C
cmpw r31, r30
blt lbl_8008880C
lbl_8008882C:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
lwz r28, 8(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.global TRKReadBuffer_ui32
TRKReadBuffer_ui32:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
li r30, 0
slwi r0, r30, 2
stw r29, 0xc(r1)
add r31, r4, r0
addi r29, r5, 0
stw r28, 8(r1)
addi r28, r3, 0
li r3, 0
b lbl_80088898
lbl_80088884:
addi r3, r28, 0
addi r4, r31, 0
bl TRKReadBuffer1_ui32
addi r30, r30, 1
addi r31, r31, 4
lbl_80088898:
cmpwi r3, 0
bne lbl_800888A8
cmpw r30, r29
blt lbl_80088884
lbl_800888A8:
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
lwz r29, 0xc(r1)
lwz r28, 8(r1)
addi r1, r1, 0x18
lwz r0, 4(r1)
mtlr r0
blr
.section .bss, "wa"
.global gTRKMsgBufs
gTRKMsgBufs:
.skip 0x19B0