.include "macros.inc"
.section .text, "ax"
.global GXSetMisc
GXSetMisc:
cmpwi r3, 1
beq lbl_800A81B0
bltlr
cmpwi r3, 3
bgelr
b lbl_800A81F8
lbl_800A81B0:
lwz r3, gx@sda21(r13)
li r0, 1
sth r4, 4(r3)
lwz r4, gx@sda21(r13)
lhz r3, 4(r4)
cntlzw r3, r3
rlwinm r3, r3, 0x1b, 0x10, 0x1f
sth r3, 0(r4)
lwz r3, gx@sda21(r13)
sth r0, 2(r3)
lwz r3, gx@sda21(r13)
lhz r0, 4(r3)
cmplwi r0, 0
beqlr
lwz r0, 0x4f4(r3)
ori r0, r0, 8
stw r0, 0x4f4(r3)
blr
lbl_800A81F8:
neg r4, r4
lwz r3, gx@sda21(r13)
addic r0, r4, -1
subfe r0, r0, r4
stb r0, 0x4f1(r3)
blr
.global GXFlush
GXFlush:
mflr r0
stw r0, 4(r1)
stwu r1, -8(r1)
lwz r3, gx@sda21(r13)
lwz r0, 0x4f4(r3)
cmplwi r0, 0
beq lbl_800A8230
bl __GXSetDirtyState
lbl_800A8230:
li r0, 0
lis r3, 0xCC008000@ha
stw r0, 0xCC008000@l(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
stw r0, -0x8000(r3)
bl PPCSync
lwz r0, 0xc(r1)
addi r1, r1, 8
mtlr r0
blr
.global GXSetDrawSync
GXSetDrawSync:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
mr r30, r3
bl OSDisableInterrupts
li r6, 0x61
lwz r4, gx@sda21(r13)
lis r5, 0xCC008000@ha
clrlwi r0, r30, 0x10
stb r6, 0xCC008000@l(r5)
oris r0, r0, 0x4800
stw r0, -0x8000(r5)
rlwinm r0, r0, 0, 0, 0xf
rlwimi r0, r30, 0, 0x10, 0x1f
clrlwi r0, r0, 8
stb r6, -0x8000(r5)
oris r0, r0, 0x4700
stw r0, -0x8000(r5)
mr r30, r3
lwz r0, 0x4f4(r4)
cmplwi r0, 0
beq lbl_800A82D0
bl __GXSetDirtyState
lbl_800A82D0:
li r31, 0
lis r3, 0xCC008000@ha
stw r31, 0xCC008000@l(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
bl PPCSync
mr r3, r30
bl OSRestoreInterrupts
lwz r3, gx@sda21(r13)
sth r31, 2(r3)
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXSetDrawDone
GXSetDrawDone:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
bl OSDisableInterrupts
li r0, 0x61
lwz r4, gx@sda21(r13)
lis r6, 0xCC008000@ha
lis r5, 0x45000002@ha
stb r0, 0xCC008000@l(r6)
addi r0, r5, 0x45000002@l
stw r0, -0x8000(r6)
mr r30, r3
lwz r0, 0x4f4(r4)
cmplwi r0, 0
beq lbl_800A836C
bl __GXSetDirtyState
lbl_800A836C:
li r31, 0
lis r3, 0xCC008000@ha
stw r31, 0xCC008000@l(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
stw r31, -0x8000(r3)
bl PPCSync
stb r31, DrawDone@sda21(r13)
mr r3, r30
bl OSRestoreInterrupts
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXWaitDrawDone
GXWaitDrawDone:
mflr r0
stw r0, 4(r1)
stwu r1, -0x10(r1)
stw r31, 0xc(r1)
bl OSDisableInterrupts
mr r31, r3
b lbl_800A83E0
lbl_800A83D8:
addi r3, r13, FinishQueue@sda21
bl OSSleepThread
lbl_800A83E0:
lbz r0, DrawDone@sda21(r13)
cmplwi r0, 0
beq lbl_800A83D8
mr r3, r31
bl OSRestoreInterrupts
lwz r0, 0x14(r1)
lwz r31, 0xc(r1)
addi r1, r1, 0x10
mtlr r0
blr
.global GXDrawDone
GXDrawDone:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
bl OSDisableInterrupts
li r0, 0x61
lis r5, 0xCC008000@ha
lis r4, 0x45000002@ha
stb r0, 0xCC008000@l(r5)
addi r0, r4, 0x45000002@l
stw r0, -0x8000(r5)
mr r31, r3
bl GXFlush
li r0, 0
stb r0, DrawDone@sda21(r13)
mr r3, r31
bl OSRestoreInterrupts
bl OSDisableInterrupts
mr r31, r3
b lbl_800A8460
lbl_800A8458:
addi r3, r13, FinishQueue@sda21
bl OSSleepThread
lbl_800A8460:
lbz r0, DrawDone@sda21(r13)
cmplwi r0, 0
beq lbl_800A8458
mr r3, r31
bl OSRestoreInterrupts
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXPixModeSync
GXPixModeSync:
li r0, 0x61
lwz r4, gx@sda21(r13)
lis r5, 0xCC008000@ha
stb r0, 0xCC008000@l(r5)
li r0, 0
lwz r3, 0x1dc(r4)
stw r3, -0x8000(r5)
sth r0, 2(r4)
blr
.global GXPokeAlphaMode
GXPokeAlphaMode:
lwz r5, __peReg@sda21(r13)
clrlwi r0, r4, 0x18
rlwimi r0, r3, 8, 0, 0x17
sth r0, 6(r5)
blr
.global GXPokeAlphaRead
GXPokeAlphaRead:
rlwinm r0, r3, 0, 0x1e, 0x1c
lwz r3, __peReg@sda21(r13)
ori r0, r0, 4
sth r0, 8(r3)
blr
.global GXPokeAlphaUpdate
GXPokeAlphaUpdate:
lwz r4, __peReg@sda21(r13)
rlwinm r0, r3, 4, 0x14, 0x1b
lhzu r3, 2(r4)
rlwinm r3, r3, 0, 0x1c, 0x1a
or r0, r3, r0
sth r0, 0(r4)
blr
.global GXPokeBlendMode
GXPokeBlendMode:
lwz r7, __peReg@sda21(r13)
cmpwi r3, 1
li r9, 1
addi r10, r7, 2
lhz r7, 2(r7)
beq lbl_800A8514
cmpwi r3, 3
beq lbl_800A8514
li r9, 0
lbl_800A8514:
rlwinm r8, r7, 0, 0, 0x1e
subfic r0, r3, 3
cntlzw r7, r0
subfic r0, r3, 2
or r8, r8, r9
cntlzw r0, r0
rlwinm r8, r8, 0, 0x15, 0x13
rlwinm r3, r7, 6, 0, 0x14
or r3, r8, r3
rlwinm r3, r3, 0, 0x1f, 0x1d
rlwinm r0, r0, 0x1c, 4, 0x1e
or r0, r3, r0
rlwinm r3, r0, 0, 0x14, 0xf
slwi r0, r6, 0xc
or r0, r3, r0
rlwinm r3, r0, 0, 0x18, 0x14
slwi r0, r4, 8
or r0, r3, r0
rlwinm r3, r0, 0, 0x1b, 0x17
slwi r0, r5, 5
or r0, r3, r0
clrlwi r0, r0, 8
oris r0, r0, 0x4100
sth r0, 0(r10)
blr
.global GXPokeColorUpdate
GXPokeColorUpdate:
lwz r4, __peReg@sda21(r13)
rlwinm r0, r3, 3, 0x15, 0x1c
lhzu r3, 2(r4)
rlwinm r3, r3, 0, 0x1d, 0x1b
or r0, r3, r0
sth r0, 0(r4)
blr
.global GXPokeDstAlpha
GXPokeDstAlpha:
lwz r5, __peReg@sda21(r13)
rlwinm r0, r3, 8, 0x10, 0x17
rlwimi r0, r4, 0, 0x18, 0x1f
sth r0, 4(r5)
blr
.global GXPokeDither
GXPokeDither:
lwz r4, __peReg@sda21(r13)
rlwinm r0, r3, 2, 0x16, 0x1d
lhzu r3, 2(r4)
rlwinm r3, r3, 0, 0x1e, 0x1c
or r0, r3, r0
sth r0, 0(r4)
blr
.global GXPokeZMode
GXPokeZMode:
clrlwi r0, r3, 0x18
lwz r3, __peReg@sda21(r13)
rlwinm r6, r0, 0, 0x1f, 0x1b
slwi r0, r4, 1
or r0, r6, r0
rlwinm r4, r0, 0, 0x1c, 0x1a
rlwinm r0, r5, 4, 0x14, 0x1b
or r0, r4, r0
sth r0, 0(r3)
blr
.global GXPeekARGB
GXPeekARGB:
rlwinm r0, r3, 2, 0xe, 0x1d
oris r0, r0, 0xc800
rlwinm r3, r0, 0, 0x14, 9
rlwinm r0, r4, 0xc, 4, 0x13
or r0, r3, r0
rlwinm r3, r0, 0, 0xa, 7
lwz r0, 0(r3)
stw r0, 0(r5)
blr
.global GXPeekZ
GXPeekZ:
rlwinm r0, r3, 2, 0xe, 0x1d
oris r0, r0, 0xc800
rlwinm r3, r0, 0, 0x14, 9
rlwinm r0, r4, 0xc, 4, 0x13
or r0, r3, r0
rlwinm r0, r0, 0, 0xa, 7
oris r3, r0, 0x40
lwz r0, 0(r3)
stw r0, 0(r5)
blr
.global GXSetDrawSyncCallback
GXSetDrawSyncCallback:
mflr r0
stw r0, 4(r1)
stwu r1, -0x18(r1)
stw r31, 0x14(r1)
stw r30, 0x10(r1)
mr r30, r3
lwz r31, TokenCB@sda21(r13)
bl OSDisableInterrupts
stw r30, TokenCB@sda21(r13)
bl OSRestoreInterrupts
mr r3, r31
lwz r0, 0x1c(r1)
lwz r31, 0x14(r1)
lwz r30, 0x10(r1)
addi r1, r1, 0x18
mtlr r0
blr
.global GXTokenInterruptHandler
GXTokenInterruptHandler:
mflr r0
stw r0, 4(r1)
stwu r1, -0x2e0(r1)
stw r31, 0x2dc(r1)
stw r30, 0x2d8(r1)
mr r30, r4
lwz r0, TokenCB@sda21(r13)
lwz r3, __peReg@sda21(r13)
cmplwi r0, 0
lhz r31, 0xe(r3)
beq lbl_800A86D8
addi r3, r1, 0x10
bl OSClearContext
addi r3, r1, 0x10
bl OSSetCurrentContext
lwz r12, TokenCB@sda21(r13)
addi r3, r31, 0
mtlr r12
blrl
addi r3, r1, 0x10
bl OSClearContext
mr r3, r30
bl OSSetCurrentContext
lbl_800A86D8:
lwz r3, __peReg@sda21(r13)
lhzu r0, 0xa(r3)
rlwinm r0, r0, 0, 0x1e, 0x1c
ori r0, r0, 4
sth r0, 0(r3)
lwz r0, 0x2e4(r1)
lwz r31, 0x2dc(r1)
lwz r30, 0x2d8(r1)
addi r1, r1, 0x2e0
mtlr r0
blr
.global GXFinishInterruptHandler
GXFinishInterruptHandler:
mflr r0
li r3, 1
stw r0, 4(r1)
stwu r1, -0x2e0(r1)
stw r31, 0x2dc(r1)
addi r31, r4, 0
lwz r5, __peReg@sda21(r13)
lhz r0, 0xa(r5)
rlwinm r0, r0, 0, 0x1d, 0x1b
ori r0, r0, 8
sth r0, 0xa(r5)
lwz r0, DrawDoneCB@sda21(r13)
stb r3, DrawDone@sda21(r13)
cmplwi r0, 0
beq lbl_800A876C
addi r3, r1, 0x10
bl OSClearContext
addi r3, r1, 0x10
bl OSSetCurrentContext
lwz r12, DrawDoneCB@sda21(r13)
mtlr r12
blrl
addi r3, r1, 0x10
bl OSClearContext
mr r3, r31
bl OSSetCurrentContext
lbl_800A876C:
addi r3, r13, FinishQueue@sda21
bl OSWakeupThread
lwz r0, 0x2e4(r1)
lwz r31, 0x2dc(r1)
addi r1, r1, 0x2e0
mtlr r0
blr
.global __GXPEInit
__GXPEInit:
mflr r0
lis r3, GXTokenInterruptHandler@ha
stw r0, 4(r1)
addi r4, r3, GXTokenInterruptHandler@l
li r3, 0x12
stwu r1, -8(r1)
bl __OSSetInterruptHandler
lis r3, GXFinishInterruptHandler@ha
addi r4, r3, GXFinishInterruptHandler@l
li r3, 0x13
bl __OSSetInterruptHandler
addi r3, r13, FinishQueue@sda21
bl OSInitThreadQueue
li r3, 0x2000
bl __OSUnmaskInterrupts
li r3, 0x1000
bl __OSUnmaskInterrupts
lwz r3, __peReg@sda21(r13)
lhzu r0, 0xa(r3)
rlwinm r0, r0, 0, 0x1e, 0x1c
ori r0, r0, 4
rlwinm r0, r0, 0, 0x1d, 0x1b
ori r0, r0, 8
rlwinm r0, r0, 0, 0, 0x1e
ori r0, r0, 1
rlwinm r0, r0, 0, 0x1f, 0x1d
ori r0, r0, 2
sth r0, 0(r3)
lwz r0, 0xc(r1)
addi r1, r1, 8
mtlr r0
blr
.section .sbss, "wa"
TokenCB:
.skip 0x4
DrawDoneCB:
.skip 0x4
DrawDone:
.skip 0x4
FinishQueue:
.skip 0xC