# INJECTION POINT
# 0x802F3B04
_lr_backup:
subi sp, sp, 20
stw r3, 8(sp)
mflr r3
stw r3, 12(sp)
lwz r3, 8(sp)
_start:
b _main
nop
_backup:
subi sp, sp, 48
stw r0, 32(sp)
stw r1, 36(sp)
stw r2, 40(sp)
stw r3, 4(sp)
stw r4, 8(sp)
stw r5, 12(sp)
stw r6, 16(sp)
stw r7, 20(sp)
stw r8, 24(sp)
mfctr r3
stw r3, 28(sp)
lwz r3, 4(sp)
blr
nop
_restore:
lwz r3, 28(sp)
mtctr r3
lwz r0, 32(sp)
lwz r1, 36(sp)
lwz r2, 40(sp)
lwz r3, 4(sp)
lwz r4, 8(sp)
lwz r5, 12(sp)
lwz r6, 16(sp)
lwz r7, 20(sp)
lwz r8, 24(sp)
addi sp, sp, 48
blr
nop
_main:
bl _backup
nop
# Padding in the stack because I
# recall something about the edges
# of the stack not being safe when
# functions are called... so I'm
# just being safe!
# If the global frame timer is zero,
# then we will check the controllers
# to see if any of them have d-pad
# left pressed. If so, we'll
# activate CPU swap mode.
# We'll also init the activation timer
# in this startup code.
# GLOBAL FRAME TIMER -> 0x80479D60
# SECONDS LEFT IN GAME -> 0x8046B6C8
# CONTROLLER BLOCKS -> 0x804C1FAF
# RNG SEED -> 0x804D5F90
# --- free space in RAM (debug menu related)
# ACTIVATION TIMER -> 0x803FA4DC
# ENABLED FLAG -> 0x803FA4E0
# SFX PLAY PENDING -> 0x803FA4E4
# ::FUNCTIONS
# PLAY MENU BACK -> 0x8017435C
# PLAY MENU FORW -> 0x80174338
# IF (GFT == 0)
_if_gft_zero:
lis r3, 0x8047
ori r3, r3, 0x9D60
lwz r3, 0(r3)
cmplwi r3, 0
bne _end_if_gft_zero
nop
# if zero...
# set enabled flag to zero
lis r3, 0x803F
ori r3, r3, 0xA4E0
li r4, 0
stw r4, 0(r3)
# set sfx play pending to 0
lis r3, 0x803F
ori r3, r3, 0xA4E4
li r4, 0
stw r4, 0(r3)
# set activation timer to
# the current timer - 5
lis r3, 0x803F
ori r3, r3, 0xA4DC
lis r4, 0x8046
ori r4, r4, 0xB6C8
lwz r4, 0(r4)
subi r4, r4, 5
stw r4, 0(r3)
# now check all controllers
# for d-pad left ...
lis r3, 0x804C
ori r3, r3, 0x1FAF
li r4, 0
_controller_loop:
lbz r5, 0(r3)
addi r3, r3, 0x44
andi. r5, r5, 0x01
cmplwi r5, 0
beq _end_enabling
nop
lis r6, 0x803F
ori r6, r6, 0xA4E0
li r7, 1
stw r7, 0(r6)
_end_enabling:
addi r4, r4, 1
cmplwi r4, 4
blt _controller_loop
nop
_end_if_gft_zero:
# END IF (GFT == 0)
# IF NOT ENABLED, RETURN NORMAL MS VALUE
_if_not_enabled:
lis r3, 0x803F
ori r3, r3, 0xA4E0
lwz r3, 0(r3)
cmplwi r3, 0
bne _end_if_not_enabled
nop
# put the initial value of
# r5 into r24
b _default_ms_value
nop
_end_if_not_enabled:
# END IF NOT ENABLED
# IF ACTIVATION TIME == CURRENT TIME
_if_activation:
# Activation Timer
lis r3, 0x803F
ori r3, r3, 0xA4DC
lwz r5, 0(r3)
# Current time in seconds
lis r4, 0x8046
ori r4, r4, 0xB6C8
lwz r4, 0(r4)
cmplw r4, r5
bne _end_if_activation
nop
# RNG
lis r5, 0x804D
ori r5, r5, 0x5F90
lwz r5, 0(r5)
# modulus rng w/ 7
li r6, 7
divwu r7, r5, r6
mullw r7, r7, r6
subf r7, r7, r5
# current time - 10 - 12 - rng%7
subi r4, r4, 22
subf r4, r7, r4
stw r4, 0(r3)
# Play menu forward SFX
bl _backup
nop
lis r3, 0x8017
ori r3, r3, 0x4338
nop
mtctr r3
bctrl
nop
bl _restore
nop
# and set menu backwards SFX to pending!
lis r3, 0x803F
ori r3, r3, 0xA4E4
li r4, 1
stw r4, 0(r3)
_end_if_activation:
# END IF ACTIVATION TIME == CURRENT TIME
# STATIC BLOCKS : 0x80453080
# SEPERATION : 0xE90
# CPU|HMN TYPE OFFSET : 0x08
# PLAYER POINTERS : 0xB0
# --> CPU LEVEL : 0x1AFB
# LOOP THROUGH PLAYER BLOCKS
_player_block:
li r3, 0
lis r4, 0x8045
ori r4, r4, 0x3080
# begin loop...
_player_takeover_loop:
lwz r5, 0xB0(r4)
cmplwi r5, 0
beq _player_takeover_increment
nop
# IF ACTIVATION TIME + 10 >= CURRENT TIME
lis r6, 0x803F
ori r6, r6, 0xA4DC
lwz r6, 0(r6)
addi r6, r6, 10
lis r7, 0x8046
ori r7, r7, 0xB6C8
lwz r7, 0(r7)
cmplw r6, r7
blt _activation_else
nop
# CPU MODE
li r6, 9
stb r6, 0x1AFB(r5)
li r6, 1
stw r6, 0x08(r4)
# if an sfx play is pending, play it!
lis r6, 0x803F
ori r6, r6, 0xA4E4
lwz r7, 0(r6)
cmplwi r7, 1
bne _dont_play_sfx
nop
bl _backup
nop
lis r7, 0x8017
ori r7, r7, 0x435c
mtctr r7
bctrl
nop
bl _restore
nop
li r7, 0
stw r7, 0(r6)
_dont_play_sfx:
b _player_takeover_increment
nop
# ELSE (aka ACTIVATION TIME + 10 < CURRENT TIME)
_activation_else:
li r6, 0
stw r6, 0x08(r4)
# END IF ACTIVATION TIME + 10 >= CURRENT TIME
_player_takeover_increment:
addi r3, r3, 1
addi r4, r4, 0xE90
cmplwi r3, 4
ble _player_takeover_loop
nop
_end_player_block:
# END LOOPS THROUGH PLAYER BLOCKS
# CURRENT TIME / ACTIVATION TIME DIFFERENCE
# activation time
lis r3, 0x803F
ori r3, r3, 0xA4DC
lwz r3, 0(r3)
# current time
lis r4, 0x8046
ori r4, r4, 0xB6C8
lwz r4, 0(r4)
# r3 = current time - activation time
subf r3, r3, r4
cmpwi r3, 0
ble _default_ms_value
nop
cmpwi r3, 10
bgt _default_ms_value
nop
addi r24, r3, 0
b _end
nop
# SET MS TO DEFAULT VALUE
_default_ms_value:
lwz r24, 12(sp)
# Restore Registers...
_end:
bl _restore
nop
_lr_restore:
stw r3, 8(sp)
lwz r3, 12(sp)
mtlr r3
lwz r3, 8(sp)
addi sp, sp, 20
_exit: