B(0x02) init timer

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
r4 = timer
r5 = reload value
r6 = flags (in logic order:)
     0x10 - (if off) set mode to 48. else set mode to 49
     0x01 - (if off) mode OR 0x100
     0x1000 - (if on) mode OR 0x10
000015f8: 3084ffff andi r4,r4,0xffff
000015fc: 28810003 slti r1,r4,0x0003
00001600: 30a5ffff andi r5,r5,0xffff
00001604: 14200003 bne r1,r0,0x00001614        # branch if legal timer
00001608: 00c03821 addu r7,r6,r0
0000160c: 03e00008 jr r31                      # if VBLANK, RETURN 0
00001610: 00001021 addu r2,r0,r0

if not VBLANK

00001614: 3c0e0000 lui r14,0x0000
00001618: 8dce6d44 lw r14,0x6d44(r14)          #1f801100 hardware timer 0
0000161c: 00047900 sll r15,r4,0x04             #timer * 0x10
00001620: 3c01f200 lui r1,0xf200
00001624: 00811026 xor r2,r4,r1                
00001628: 01cf1821 addu r3,r14,r15             #timer hardware field
0000162c: a4600004 sh r0,0x0004(r3)            #timer mode = 0x0000
00001630: 2c420001 sltiu r2,r2,0x0001
00001634: a4650008 sh r5,0x0008(r3)            #timer field 0x8 = reload
00001638: 14400004 bne r2,r0,0x0000164c        #branch always
0000163c: 24060048 addiu r6,r0,0x0048          #if bit4 = 1, mode= 0x48
00001640: 34580001 ori r24,r2,0x0001           # UNREACHABLE
00001644: 1300000b beq r24,r0,0x00001674       # UNREACHABLE
00001648: 34490002 ori r9,r2,0x0002            # UNREACHABLE
0000164c: 30f90010 andi r25,r7,0x0010          # UNREACHABLE
00001650: 13200003 beq r25,r0,0x00001660       #branch if bit4 = 0
00001654: 30e80001 andi r8,r7,0x0001
00001658: 24060049 addiu r6,r0,0x0049          #if bit4 = 0, mode=0x49
0000165c: 30e80001 andi r8,r7,0x0001
00001660: 1500000b bne r8,r0,0x00001690        #branch if bit0 = 0
00001664: 30eb1000 andi r11,r7,0x1000
00001668: 10000008 beq r0,r0,0x0000168c
0000166c: 34c60100 ori r6,r6,0x0100            #if bit0 = 0, mode OR 0x0100
00001670: 34490002 ori r9,r2,0x0002            # UNREACHABLE
00001674: 11200006 beq r9,r0,0x00001690        # UNREACHABLE
00001678: 30eb1000 andi r11,r7,0x1000          # UNREACHABLE
0000167c: 30ea0001 andi r10,r7,0x0001          # UNREACHABLE
00001680: 15400003 bne r10,r0,0x00001690       # UNREACHABLE
00001684: 30eb1000 andi r11,r7,0x1000          # UNREACHABLE
00001688: 24060248 addiu r6,r0,0x0248          # UNREACHABLE
0000168c: 30eb1000 andi r11,r7,0x1000
00001690: 11600002 beq r11,r0,0x0000169c       #branch if bit12 = 0
00001694: 00000000 nop
00001698: 34c60010 ori r6,r6,0x0010            #if bit12 = 1, mode OR 0x10
0000169c: a4660004 sh r6,0x0004(r3)            #store timer mode
000016a0: 24020001 addiu r2,r0,0x0001          #RETURN 1
000016a4: 03e00008 jr r31
000016a8: 00000000 nop