Call Inner Subroutine (WORLD.BIN)
Jump to navigation
Jump to search
# ROUTINE: CALL INNER SUBROUTINE (ON MAIN THREAD) (WORLD.BIN) # This routine acts as a wrapper for a call to another routine, and forces the routine to run on the main thread (thread 0). # This routine is the WORLD.BIN analog of Call Inner Subroutine in BATTLE.BIN. # # Parameters: # Parameters for inner subroutine: r4 - r7 with additional parameters on the stack, as usual # *0x801cd78c = [Address of subroutine to call] # # Returns: # r2 = [Result of inner subroutine] 80100384: 3c018010 lui r1,0x8010 80100388: 00200821 addu r1,r1,r0 8010038c: ac3f042c sw r31,0x042c(r1) # Save return address to 0x8010042c 80100390: 3c01801d lui r1,0x801d 80100394: 00200821 addu r1,r1,r0 80100398: 8c28d170 lw r8,-0x2e90(r1) # threadID (*0x801cd170) 8010039c: 00000000 nop 801003a0: 11000015 beq r8,r0,0x801003f8 # if (threadID != 0) 801003a4: 00000000 nop # { 801003a8: 3c018015 lui r1,0x8015 801003ac: 00200821 addu r1,r1,r0 801003b0: 8c28327c lw r8,0x327c(r1) # threads[0] (*0x8015327c) 801003b4: 00000000 nop 801003b8: 8d08003c lw r8,0x003c(r8) # threads[0].StackPointer 801003bc: 00000000 nop 801003c0: 2108fff0 addi r8,r8,-0x0010 # Save stack pointer 801003c4: ad1d0004 sw r29,0x0004(r8) 801003c8: ad1f0008 sw r31,0x0008(r8) 801003cc: 0100e821 addu r29,r8,r0 # $sp = threads[0].StackPointer 801003d0: 3c01801d lui r1,0x801d 801003d4: 00200821 addu r1,r1,r0 801003d8: 8c28d78c lw r8,-0x2874(r1) # *0x801cd78c 801003dc: 00000000 nop 801003e0: 0100f809 jalr r8,r31 # Call subroutine at *0x801cd78c 801003e4: 00000000 nop 801003e8: 8fbf0008 lw r31,0x0008(r29) 801003ec: 8fbd0004 lw r29,0x0004(r29) # Load stack pointer back 801003f0: 03e00008 jr r31 801003f4: 00000000 nop # } else { 801003f8: 3c01801d lui r1,0x801d 801003fc: 00200821 addu r1,r1,r0 80100400: 8c28d78c lw r8,-0x2874(r1) # *0x801cd78c 80100404: 00000000 nop 80100408: 0100f809 jalr r8,r31 # Call subroutine at *0x801cd78c 8010040c: 00000000 nop 80100410: 3c018010 lui r1,0x8010 80100414: 00200821 addu r1,r1,r0 80100418: 8c3f042c lw r31,0x042c(r1) # Load return address from 0x8010042c 8010041c: 00000000 nop 80100420: 03e00008 jr r31 80100424: 00000000 nop # }