Set Tile Background Color

From Final Fantasy Hacktics Wiki
Jump to navigation Jump to search
#   ROUTINE: SET TILE BACKGROUND COLOR? (0x12cf44)
#       Parameters:
#           r4 = ?
#           r5 = ?
#           r6 = ?

0012cf44: 27bdffc0 addiu r29,r29,-0x0040             
0012cf48: afb0003c sw r16,0x003c(r29)
0012cf4c: afb10038 sw r17,0x0038(r29)
0012cf50: afb20034 sw r18,0x0034(r29)
0012cf54: afb30030 sw r19,0x0030(r29)
0012cf58: 3c088013 lui r8,0x8013
0012cf5c: 2508d878 addiu r8,r8,-0x2788                  #   0x8012d878
0012cf60: 8d090000 lw r9,0x0000(r8)                     #   *0x8012d878
0012cf64: 20d3ffff addi r19,r6,-0x0001                  #   [Parameter 3] - 1
0012cf68: 32730e00 andi r19,r19,0x0e00                  #   ([Parameter 3] - 1) & 0xe00
0012cf6c: 00139a42 srl r19,r19,0x09                     #   (([Parameter 3] - 1) & 0xe00) >> 9
0012cf70: 20d00200 addi r16,r6,0x0200                   #   [Parameter 3] + 0x200 (512)
0012cf74: 321003ff andi r16,r16,0x03ff                  #   ([Parameter 3] + 0x200) & 0x3ff
0012cf78: 30c60c00 andi r6,r6,0x0c00                    #   [Parameter 3] & 0xc00
0012cf7c: 00063282 srl r6,r6,0x0a                       #   r6 = ([Parameter 3] & 0xc00) >> 10
0012cf80: 12000002 beq r16,r0,0x0012cf8c                #   if (r6 != 0) {
0012cf84: 00000000 nop
0012cf88: 34060004 ori r6,r0,0x0004                     #       r6 = 4
                                                        #   }
0012cf8c: 21290001 addi r9,r9,0x0001                    #   *0x8012d878 + 1   
0012cf90: ad090000 sw r9,0x0000(r8)                     #   *0x8012d878 = *0x8012d878 + 1
0012cf94: 3c128010 lui r18,0x8010
0012cf98: 8e52bdfc lw r18,-0x4204(r18)                  #   r18 = *0x800fbdfc
0012cf9c: 3c118010 lui r17,0x8010
0012cfa0: 8e31a6bc lw r17,-0x5944(r17)                  #   *0x800fa6bc
0012cfa4: 3c0e800f lui r14,0x800f
0012cfa8: 8dce5b88 lw r14,0x5b88(r14)                   #   *0x800f5b88
0012cfac: 20a5ffcc addi r5,r5,-0x0034                   #   pointer = pointer - 0x34 (52) 
0012cfb0: 2252ffe0 addi r18,r18,-0x0020                 #   r18 = r18 - 0x20 (32) 

0012cfb4: 21ceffff addi r14,r14,-0x0001                 #   *0x800f5b88 - 1
0012cfb8: 05c10008 bgez r14,0x0012cfdc                  #   if ((*0x800f5b88 - 1) < 0) {
0012cfbc: 00000000 nop
0012cfc0: 8fb30030 lw r19,0x0030(r29)
0012cfc4: 8fb20034 lw r18,0x0034(r29)
0012cfc8: 8fb10038 lw r17,0x0038(r29)
0012cfcc: 8fb0003c lw r16,0x003c(r29)
0012cfd0: 27bd0040 addiu r29,r29,0x0040
0012cfd4: 03e00008 jr r31                               #       return;
0012cfd8: 00000000 nop
                                                        #   }
0012cfdc: ca200000 lwc2 gtedr00_vxy0,0x0000(r17)        #   Load r17 pointer data into GTE
0012cfe0: ca210004 lwc2 gtedr01_vz0,0x0004(r17)
0012cfe4: 22310008 addi r17,r17,0x0008                  #   r17 = r17 + 8
0012cfe8: 20a50034 addi r5,r5,0x0034                    #   pointer = pointer + offset (0x34 = 52)?
0012cfec: 4a480012 mvmva                                #   matrix x vector + other vector
0012cff0: 86270006 lh r7,0x0006(r17)                    #   *(r17 + 6)
0012cff4: 22520020 addi r18,r18,0x0020                  #   r18 = r18 + offset (0x20 = 32)
0012cff8: 4808c800 mfc2 r8,gtedr25_mac1                 #   Get results of operation from GTE
0012cffc: 4809d000 mfc2 r9,gtedr26_mac2
0012d000: 4819d800 mfc2 r25,gtedr27_mac3
0012d004: ca200000 lwc2 gtedr00_vxy0,0x0000(r17)        #   Load r17 pointer data into GTE
0012d008: ca210004 lwc2 gtedr01_vz0,0x0004(r17)
0012d00c: 22310008 addi r17,r17,0x0008                  #   r17 = r17 + 8
0012d010: 0009c400 sll r24,r9,0x10                      #   (GTE $26) << 16
0012d014: 4a480012 mvmva                                #   matrix x vector + other vector
0012d018: a4a80008 sh r8,0x0008(r5)                     #   *(pointer + 8) = (GTE $25)
0012d01c: a4a9000a sh r9,0x000a(r5)                     #   *(pointer + 10) = (GTE $26)
0012d020: 0118c025 or r24,r8,r24                        #   (GTE $25) | ((GTE $26) << 16)
0012d024: 48986000 mtc2 r24,gtedr12_sxy0                #   Load data into GTE
0012d028: 48998000 mtc2 r25,gtedr16_sz0
0012d02c: 480ac800 mfc2 r10,gtedr25_mac1
0012d030: 480bd000 mfc2 r11,gtedr26_mac2
0012d034: 4819d800 mfc2 r25,gtedr27_mac3
0012d038: ca200000 lwc2 gtedr00_vxy0,0x0000(r17)
0012d03c: ca210004 lwc2 gtedr01_vz0,0x0004(r17)
0012d040: 22310008 addi r17,r17,0x0008
0012d044: 000bc400 sll r24,r11,0x10
0012d048: 4a480012 mvmva                                #   matrix x vecotr + other vector
0012d04c: a4aa0014 sh r10,0x0014(r5)
0012d050: a4ab0016 sh r11,0x0016(r5)
0012d054: 0158c025 or r24,r10,r24
0012d058: 48986800 mtc2 r24,gtedr13_sxy1
0012d05c: 48998800 mtc2 r25,gtedr17_sz1
0012d060: 480cc800 mfc2 r12,gtedr25_mac1
0012d064: 480dd000 mfc2 r13,gtedr26_mac2
0012d068: 4819d800 mfc2 r25,gtedr27_mac3
0012d06c: ca200000 lwc2 gtedr00_vxy0,0x0000(r17)
0012d070: ca210004 lwc2 gtedr01_vz0,0x0004(r17)
0012d074: 000dc400 sll r24,r13,0x10
0012d078: 22310008 addi r17,r17,0x0008
0012d07c: 4a480012 mvmva                                #   
0012d080: a4ac0020 sh r12,0x0020(r5)
0012d084: a4ad0022 sh r13,0x0022(r5)
0012d088: 0198c025 or r24,r12,r24
0012d08c: 48987000 mtc2 r24,gtedr14_sxy2
0012d090: 48999000 mtc2 r25,gtedr18_sz2
0012d094: 4802c800 mfc2 r2,gtedr25_mac1
0012d098: 4803d000 mfc2 r3,gtedr26_mac2
0012d09c: 4819d800 mfc2 r25,gtedr27_mac3
0012d0a0: 000dc400 sll r24,r13,0x10
0012d0a4: 0198c025 or r24,r12,r24
0012d0a8: a4a2002c sh r2,0x002c(r5)
0012d0ac: a4a3002e sh r3,0x002e(r5)
0012d0b0: 48987000 mtc2 r24,gtedr14_sxy2
0012d0b4: 48999800 mtc2 r25,gtedr19_sz3
0012d0b8: 30ef3ffc andi r15,r7,0x3ffc
0012d0bc: 026fc006 srlv r24,r15,r19
0012d0c0: 33180004 andi r24,r24,0x0004
0012d0c4: 1700ffbb bne r24,r0,0x0012cfb4
0012d0c8: 00cf7806 srlv r15,r15,r6
0012d0cc: 31ef0400 andi r15,r15,0x0400
0012d0d0: 15e0ffb8 bne r15,r0,0x0012cfb4
0012d0d4: 00000000 nop
0012d0d8: 00000000 nop
0012d0dc: 4b400006 nclip                             #   normal clipping?
0012d0e0: 05010009 bgez r8,0x0012d108
0012d0e4: 00000000 nop
0012d0e8: 05410007 bgez r10,0x0012d108
0012d0ec: 00000000 nop
0012d0f0: 05810005 bgez r12,0x0012d108
0012d0f4: 00000000 nop
0012d0f8: 04410003 bgez r2,0x0012d108
0012d0fc: 00000000 nop
0012d100: 0804b3ed j 0x0012cfb4
0012d104: 00000000 nop
0012d108: 05210009 bgez r9,0x0012d130
0012d10c: 00000000 nop
0012d110: 05610007 bgez r11,0x0012d130
0012d114: 00000000 nop
0012d118: 05a10005 bgez r13,0x0012d130
0012d11c: 00000000 nop
0012d120: 04610003 bgez r3,0x0012d130
0012d124: 00000000 nop
0012d128: 0804b3ed j 0x0012cfb4
0012d12c: 00000000 nop
0012d130: 2108fd80 addi r8,r8,-0x0280
0012d134: 05000009 bltz r8,0x0012d15c
0012d138: 214afd80 addi r10,r10,-0x0280
0012d13c: 05400007 bltz r10,0x0012d15c
0012d140: 218cfd80 addi r12,r12,-0x0280
0012d144: 05800005 bltz r12,0x0012d15c
0012d148: 2042fd80 addi r2,r2,-0x0280
0012d14c: 04400003 bltz r2,0x0012d15c
0012d150: 00000000 nop
0012d154: 0804b3ed j 0x0012cfb4
0012d158: 00000000 nop
0012d15c: 4818c000 mfc2 r24,gtedr24_mac0
0012d160: 2129fe20 addi r9,r9,-0x01e0
0012d164: 0700ff93 bltz r24,0x0012cfb4
0012d168: 216bfe20 addi r11,r11,-0x01e0
0012d16c: 05200009 bltz r9,0x0012d194
0012d170: 21adfe20 addi r13,r13,-0x01e0
0012d174: 05600007 bltz r11,0x0012d194
0012d178: 2063fe20 addi r3,r3,-0x01e0
0012d17c: 05a00005 bltz r13,0x0012d194
0012d180: 00000000 nop
0012d184: 04600003 bltz r3,0x0012d194
0012d188: 00000000 nop
0012d18c: 0804b3ed j 0x0012cfb4
0012d190: 00000000 nop
0012d194: 00000000 nop
0012d198: 00000000 nop
0012d19c: 4b68002e avsz4                                #   take average of 4 vectors
0012d1a0: 48193800 mfc2 r25,gtedr07_otz
0012d1a4: 00000000 nop
0012d1a8: 0720ff82 bltz r25,0x0012cfb4
0012d1ac: 00000000 nop
0012d1b0: 0320c021 addu r24,r25,r0
0012d1b4: 2339fe80 addi r25,r25,-0x0180
0012d1b8: 0721ff7e bgez r25,0x0012cfb4
0012d1bc: 00000000 nop
0012d1c0: 00e07821 addu r15,r7,r0
0012d1c4: 31e30001 andi r3,r15,0x0001
0012d1c8: 10600009 beq r3,r0,0x0012d1f0
0012d1cc: 00000000 nop
0012d1d0: ca410004 lwc2 gtedr01_vz0,0x0004(r18)         #   normal colour vector for 1st corner
0012d1d4: ca400000 lwc2 gtedr00_vxy0,0x0000(r18)        #   
0012d1d8: ca420008 lwc2 gtedr02_vxy1,0x0008(r18)        #   2nd corner
0012d1dc: ca43000c lwc2 gtedr03_vz1,0x000c(r18)         #   
0012d1e0: ca440010 lwc2 gtedr04_vxy2,0x0010(r18)        #   3rd corner
0012d1e4: ca450014 lwc2 gtedr05_vz2,0x0014(r18)         #   
0012d1e8: ca410004 lwc2 gtedr01_vz0,0x0004(r18)         #   start load again into gte? as strange as it looks I think this is paced to finish loading after nct starts executing; for ncs below.
0012d1ec: ca400000 lwc2 gtedr00_vxy0,0x0000(r18)        #   
0012d1f0: 0018c080 sll r24,r24,0x02
0012d1f4: 00804021 addu r8,r4,r0
0012d1f8: 4ad80420 nct                                  #   GTE operation: Calculate normal color (nct)
0012d1fc: 00982020 add r4,r4,r24
0012d200: 0804b484 j 0x0012d210                         #   Marvelous.
0012d204: 00000000 nop
0012d208: 0804b484 j 0x0012d210                         #   Marvelous!
0012d20c: 00000000 nop
0012d210: 3c1800ff lui r24,0x00ff
0012d214: 3718ffff ori r24,r24,0xffff                   #   0x00ffffff
0012d218: 3c19ff00 lui r25,0xff00                       #   0xff000000
0012d21c: 8ca30000 lw r3,0x0000(r5)
0012d220: 8c820000 lw r2,0x0000(r4)
0012d224: 00791824 and r3,r3,r25
0012d228: 00581024 and r2,r2,r24
0012d22c: 00621825 or r3,r3,r2
0012d230: aca30000 sw r3,0x0000(r5)
0012d234: 8c820000 lw r2,0x0000(r4)
0012d238: 00b84824 and r9,r5,r24
0012d23c: 00591024 and r2,r2,r25
0012d240: 00491025 or r2,r2,r9
0012d244: ac820000 sw r2,0x0000(r4)
0012d248: 01002021 addu r4,r8,r0
0012d24c: 31e30001 andi r3,r15,0x0001
0012d250: 10600016 beq r3,r0,0x0012d2ac
0012d254: 00000000 nop
0012d258: 4808a000 mfc2 r8,gtedr20_rgb0                 #   Load r/g/b/? values (Location #1) (Format: 0x??BBGGRR)
0012d25c: 4809a800 mfc2 r9,gtedr21_rgb1                 #   Load r/g/b/? values (Location #2) (Format: 0x??BBGGRR)
0012d260: 480ab000 mfc2 r10,gtedr22_rgb2                #   Load r/g/b/? values (Location #3) (Format: 0x??BBGGRR)
0012d264: ca400018 lwc2 gtedr00_vxy0,0x0018(r18)
0012d268: ca41001c lwc2 gtedr01_vz0,0x001c(r18)
0012d26c: a4a80004 sh r8,0x0004(r5)                     #   Store red and green values (polygt4 rgb0)
0012d270: a4a90010 sh r9,0x0010(r5)                     #   Store red and green values (rgb1)
0012d274: 4ac8041e ncs                                  #   GTE operation:  Calculate normal color (ncs)
0012d278: a4aa001c sh r10,0x001c(r5)                    #   Store red and green values (rgb2)
0012d27c: 00084402 srl r8,r8,0x10
0012d280: 00094c02 srl r9,r9,0x10
0012d284: 000a5402 srl r10,r10,0x10
0012d288: a0a80006 sb r8,0x0006(r5)                     #   Store blue value (rgb0)
0012d28c: a0a90012 sb r9,0x0012(r5)                     #   Store blue value (rgb1)
0012d290: 4808b000 mfc2 r8,gtedr22_rgb2
0012d294: a0aa001e sb r10,0x001e(r5)                    #   Store blue value (rgb2)
0012d298: a4a80028 sh r8,0x0028(r5)                     #   Store red and green values (rgb3)
0012d29c: 00084402 srl r8,r8,0x10
0012d2a0: a0a8002a sb r8,0x002a(r5)                     #   Store blue value (rgb3)
0012d2a4: 0804b4ab j 0x0012d2ac                         #   Tremendous, tremendous.
0012d2a8: 00000000 nop
0012d2ac: 0804b3ed j 0x0012cfb4                         #   Jump back into position that decrements variable and might return (0x12cfb4), otherwise re-iterates.
0012d2b0: 00000000 nop