Advertisement
Zoinkity

MK64 Geometry Microcode

Aug 28th, 2015
507
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.52 KB | None | 0 0
  1. xx: move lights at offset x
  2.     BC000002 80000040
  3.     03860010 09000008
  4.     03880010 09000000
  5. 00
  6. 01
  7. 02
  8. 03
  9. 04
  10. 05
  11. 06
  12. 07
  13. 08
  14. 09
  15. 0A
  16. 0B
  17. 0C
  18. 0D
  19. 0E
  20. 0F
  21. 10
  22. 11
  23. 12
  24. 13
  25. 14
  26.  
  27. 15: setcombine
  28.     FC121824 FF33FFFF
  29.  
  30. 16: setcombine
  31.     FC127E24 FFFFF3F9
  32.  
  33. 17: setcombine
  34.     FCFFFFFF FFFE793C
  35.  
  36. 18: setothermode_low
  37.     B900031D 00552078
  38.  
  39. 19: setothermode_low
  40.     B900031D 00553078
  41.  
  42. xx.ss.tt:   tilesync, settile, settilesize
  43.     E8000000 00000000
  44.     F5100000 00000000
  45.     F2000000 00000000
  46. 1A.ss.tt    c16 32x32 image
  47. 1B.ss.tt    c16 32x64 image
  48. 1C.ss.tt    c16 64x32 image
  49. 1D.ss.tt    ia16 32x32 image
  50. 1E.ss.tt    ia16 32x64 image
  51. 1F.ss.tt    ia16 64x32 image
  52. 2C.ss.tt    c16 32x32 image to tmem 0x100 (256 color palette)
  53.     2000    clamp s
  54.     1000    mirror s
  55.     0F00    mask s
  56.     0020    clamp t
  57.     0010    mirror t
  58.     000F    mask t
  59.  
  60. xx.ii.tt:   settextureimage, loadsync, settile, tilesync, loadblock
  61.     FD100000 05000000
  62.     E8000000 00000000
  63.     F5100000 00000000
  64.     E6000000 00000000
  65.     F3000000 00000000
  66. 20.ii.tt    c16 32x32 image
  67. 21.ii.tt    c16 32x64 image
  68. 22.ii.tt    c16 64x32 image
  69. 23.ii.tt    ia16 32x32 image
  70. 24.ii.tt    ia16 32x64 image
  71. 25.ii.tt    ia16 64x32 image
  72.     FF00    image index; multiply by 0x800 for actual
  73.     00F0    tile#
  74.     000F    tmem offset for settile
  75.  
  76. 26: texture: on, s = -1, t = -1
  77.     BB000001 FFFFFFFF
  78.  
  79. 27: texture: off, s = 1, t = 1
  80.     BB000000 00010001
  81.  
  82. 28.xxxx.ss.nn:  loadvertices
  83.     04000000 04000000
  84.     FFFF0000    vertex offset, little-endian; multiply by 0x10 for actual
  85.     00003F00    byte size of data loaded
  86.     0000003F    offset in vertex bank to start at
  87.  
  88. 29.xxxx:    tri; reversed if 800DC604 nonzero
  89.     BF000000 00000000
  90.     1F00    vtx1
  91.     E003    vtx2
  92.     007C    vtx3
  93.  
  94. 2A: endDL
  95.     B8000000 00000000
  96.  
  97. 2B.xxxx:    DLbranch within generated file
  98.     06000000 07000000
  99.     FFFF    DW offset to display list target, little-endian; << 3 for actual
  100.  
  101. 2D: cullDL
  102.     BE000000 00000140
  103.  
  104. 2E: setcombine
  105.     FC127E24 FFFFF3F9
  106.  
  107. 2F: setothermode_low
  108.     B900031D 005049D8
  109.  
  110. 30.xxxxxx:  quad; reversed if 800DC604 nonzero
  111.     B5000000 00000000
  112.     1F0000  vtx1
  113.     E00300  vtx2
  114.     007C00  vtx3
  115.     00800F  vtx4
  116.  
  117. 31: NOP
  118.  
  119. 32: NOP
  120.  
  121. cmd.xxxx:   loadvertices
  122.     04000000 04000000
  123. 33.xxxx 1 vertex
  124. 34.xxxx 2 vertices
  125. 34.xxxx 3 vertices
  126. 35.xxxx 4 vertices
  127. 36.xxxx 5 vertices
  128. 37.xxxx 6 vertices
  129. 38.xxxx 7 vertices
  130. 39.xxxx 8 vertices
  131. 3A.xxxx 9 vertices
  132. 3B.xxxx 10 vertices
  133. 3C.xxxx 11 vertices
  134. 3D.xxxx 12 vertices
  135. 3E.xxxx 13 vertices
  136. 3F.xxxx 14 vertices
  137. 40.xxxx 15 vertices
  138. 41.xxxx 16 vertices
  139. 42.xxxx 17 vertices
  140. 43.xxxx 18 vertices
  141. 44.xxxx 19 vertices
  142. 45.xxxx 20 vertices
  143. 46.xxxx 21 vertices
  144. 47.xxxx 22 vertices
  145. 48.xxxx 23 vertices
  146. 49.xxxx 24 vertices
  147. 4A.xxxx 25 vertices
  148. 4B.xxxx 26 vertices
  149. 4C.xxxx 27 vertices
  150. 4D.xxxx 28 vertices
  151. 4E.xxxx 29 vertices
  152. 4F.xxxx 30 vertices
  153. 50.xxxx 31 vertices
  154. 51.xxxx 32 vertices
  155. 52.xxxx 33 vertices
  156.     FFFF    vertex offset, little-endian; multiply by 0x10 for actual
  157.  
  158. 53: setcombine
  159.     FCFFFFFF FFFCF279
  160.  
  161. 54: setothermode_low
  162.     B900031D 00442D58
  163.  
  164. 55: setothermode_low
  165.     B900031D 00404DD8
  166.  
  167. 56: setgeometrymode: cull back
  168.     B7000000 00002000
  169.  
  170. 57: cleargeometrymode: cull back
  171.     B6000000 00002000
  172.  
  173. 58.xxxx.yyyy:   tri2; reversed if 800DC604 nonzero
  174.     B1000000 00000000
  175.     1F000000    tri1, vtx1
  176.     E0030000    tri1, vtx2
  177.     007C0000    tri1, vtx3
  178.     00001F00    tri2, vtx1
  179.     0000E003    tri2, vtx2
  180.     0000007C    tri2, vtx3
  181.  
  182. FF: end command list
  183.  
  184. +_+
  185.  
  186. def geo2dl(data, flip=False):
  187.     from array import array
  188.     out = array("L")
  189.     sizes = {0:(0,32,32,0),
  190.              1:(0,32,64,0),
  191.              2:(0,64,32,0),
  192.              3:(3,32,32,0),
  193.              4:(3,32,64,0),
  194.              5:(3,64,32,0),
  195.              0x12:(0,32,32,0x100)}
  196.  
  197.     geo = iter(data)
  198.     c = next(geo)
  199.     while c != 0xFF:
  200.         if c in range(0, 0x15):
  201.             c *= 0x18
  202.             out.append(0xBC000002)
  203.             out.append(0x80000040)
  204.             out.append(0x03860010)
  205.             out.append(0x09000008 | c)
  206.             out.append(0x03880010)
  207.             out.append(0x09000000 | c)
  208.         elif c == 0x15:
  209.             out.append(0xFC121824)
  210.             out.append(0xFF33FFFF)
  211.         elif c == 0x16:
  212.             out.append(0xFC127E24)
  213.             out.append(0xFFFFF3F9)
  214.         elif c == 0x17:
  215.             out.append(0xFCFFFFFF)
  216.             out.append(0xFFFE793C)
  217.         elif c == 0x18:
  218.             out.append(0xB900031D)
  219.             out.append(0x00552078)
  220.         elif c == 0x19:
  221.             out.append(0xB900031D)
  222.             out.append(0x00553078)
  223.         elif c in range(0x1A, 0x20) or c == 0x2C:
  224.             e = sizes.get(c-0x1A)
  225.             s_mask = next(geo)
  226.             s_flags = s_mask >> 4
  227.             s_mask &= 0xF
  228.             t_mask = next(geo)
  229.             t_flags = t_mask >> 4
  230.             t_mask &= 0xF
  231.             line = (e[2] << 1) + 7
  232.             line >>= 3
  233.             w = e[1] - 1
  234.             h = e[2] - 1
  235.             out.append(0xE8000000)
  236.             out.append(0)
  237.             out.append(0xF5100000 | (e[0] << 0x15) | (line << 9) | e[3])
  238.             out.append((t_mask << 0x12) | (t_flags << 0xE) | (s_mask << 8) | (s_flags << 4))
  239.             out.append(0xF2000000)
  240.             out.append((h << 0xE) | (w << 2))
  241.         elif c in range(0x20, 0x26):
  242.             e = sizes.get(c-0x20)
  243.             index = next(geo)
  244.             index |= next(geo) << 8
  245.             index <<= 11
  246.             tile = next(geo)
  247.             tmem = tile & 0xF
  248.             tile >>= 4
  249.             tile <<= 0x18
  250.             lrs = min((e[1] * e[2]) - 1, 0x7FF)
  251.             lrt = max((e[2] << 1) >> 3, 1)
  252.             lrt = (0x7FF + lrt) // max(lrt, 1)
  253.             out.append(0xFD100000 | (e[0] << 0x15))
  254.             out.append(0x05000000 | index)
  255.             out.append(0xE8000000)
  256.             out.append(0)
  257.             out.append(0xF5100000 | (e[0] << 0x15) | tmem)
  258.             out.append(tile)
  259.             out.append(0xE6000000)
  260.             out.append(0)
  261.             out.append(0xF3000000)
  262.             out.append(tile | (lrs << 12) | lrt)
  263.         elif c == 0x26:
  264.             out.append(0xBB000001)
  265.             out.append(0xFFFFFFFF)
  266.         elif c == 0x27:
  267.             out.append(0xBB000000)
  268.             out.append(0x00010001)
  269.         elif c == 0x28:
  270.             offset = next(geo)
  271.             offset |= next(geo) << 8
  272.             s = next(geo) & 0x3F
  273.             n = next(geo) & 0x3F
  274.             s = (s << 10) + (s << 4) - 1
  275.             out.append(0x04000000 | (n << 17) | s)
  276.             out.append(0x04000000 | (offset << 4))
  277.         elif c == 0x29:
  278.             x = next(geo)
  279.             x |= next(geo) << 8
  280.             y = x & 0x1F
  281.             x >>= 5
  282.             v2 = x & 0x1F
  283.             x >>= 5
  284.             z = x & 0x1F
  285.             if flip:
  286.                 v1, v3 = y, z
  287.             else:
  288.                 v3, v1 = y, z
  289.             out.append(0xBF000000)
  290.             out.append((v3 << 17) | (v2 << 9) | (v1 << 1))
  291.         elif c == 0x2A:
  292.             out.append(0xB8000000)
  293.             out.append(0)
  294.         elif c == 0x2B:
  295.             offset = next(geo)
  296.             offset |= next(geo) << 8
  297.             out.append(0x06000000)
  298.             out.append(0x07000000 | (offset << 3))
  299.         elif c == 0x2D:
  300.             out.append(0xBE000000)
  301.             out.append(0x00000140)
  302.         elif c == 0x2E:
  303.             out.append(0xFC127E24)
  304.             out.append(0xFFFFF3F9)
  305.         elif c == 0x2F:
  306.             out.append(0xB900031D)
  307.             out.append(0x005049D8)
  308.         elif c == 0x30:
  309.             x = next(geo)
  310.             x |= next(geo) << 8
  311.             x |= next(geo) << 16
  312.             v1 = x & 0x1F
  313.             x >>= 5
  314.             v2 = x & 0x1F
  315.             x >>= 5
  316.             v3 = x & 0x1F
  317.             x >>= 5
  318.             v4 = x & 0x1F
  319.             if flip:
  320.                 ul, ur, ll, lr = v1, v4, v3, v2
  321.             else:
  322.                 ul, ur, ll, lr = v4, v1, v2, v3
  323.             out.append(0xB5000000)
  324.             out.append((ul << 25) | (ur << 17) | (ll << 9) | (lr << 1))
  325.         elif c == 0x31:
  326.             pass
  327.         elif c == 0x32:
  328.             pass
  329.         elif c in range(0x33, 0x53):
  330.             offset = next(geo)
  331.             offset |= next(geo) << 8
  332.             s = c - 0x32
  333.             s = (s << 10) + (s << 4) - 1
  334.             out.append(0x04000000 | s)
  335.             out.append(0x04000000 | (offset << 4))
  336.         elif c == 0x53:
  337.             out.append(0xFCFFFFFF)
  338.             out.append(0xFFFCF279)
  339.         elif c == 0x54:
  340.             out.append(0xB900031D)
  341.             out.append(0x00442D58)
  342.         elif c == 0x55:
  343.             out.append(0xB900031D)
  344.             out.append(0x00404DD8)
  345.         elif c == 0x56:
  346.             out.append(0xB7000000)
  347.             out.append(0x00002000)
  348.         elif c == 0x57:
  349.             out.append(0xB6000000)
  350.             out.append(0x00002000)
  351.         elif c == 0x58:
  352.             x = next(geo)
  353.             x |= next(geo) << 8
  354.             v1 = x & 0x1F
  355.             x >>= 5
  356.             v2 = x & 0x1F
  357.             x >>= 5
  358.             v3 = x & 0x1F
  359.             if flip:
  360.                 t11, t12, t13 = v1, v2, v3
  361.             else:
  362.                 t11, t12, t13 = v3, v2, v1
  363.             x = next(geo)
  364.             x |= next(geo) << 8
  365.             v1 = x & 0x1F
  366.             x >>= 5
  367.             v2 = x & 0x1F
  368.             x >>= 5
  369.             v3 = x & 0x1F
  370.             if flip:
  371.                 t21, t22, t23 = v1, v2, v3
  372.             else:
  373.                 t21, t22, t23 = v3, v2, v1
  374.             out.append(0xB1000000 | (t13 << 17) | (t12 << 9) | (t11 << 1))
  375.             out.append((t23 << 17) | (t22 << 9) | (t21 << 1))
  376.         else:
  377.             raise ValueError("0x{:02X} is not a valid command.")
  378.         c = next(geo)
  379.     out.byteswap()
  380.     return out.tobytes()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement