sm64

A Super Mario 64 decompilation
Log | Files | Refs | README | LICENSE

geo_commands.h (11952B)


      1 #ifndef GEO_COMMANDS_H
      2 #define GEO_COMMANDS_H
      3 
      4 #include "command_macros_base.h"
      5 
      6 #include "game/shadow.h"
      7 #include "game/object_helpers.h"
      8 #include "game/behavior_actions.h"
      9 #include "game/segment2.h"
     10 #include "game/mario_misc.h"
     11 #include "game/mario_actions_cutscene.h"
     12 
     13 // sky background params
     14 #define BACKGROUND_OCEAN_SKY        0
     15 #define BACKGROUND_FLAMING_SKY      1
     16 #define BACKGROUND_UNDERWATER_CITY  2
     17 #define BACKGROUND_BELOW_CLOUDS     3
     18 #define BACKGROUND_SNOW_MOUNTAINS   4
     19 #define BACKGROUND_DESERT           5
     20 #define BACKGROUND_HAUNTED          6
     21 #define BACKGROUND_GREEN_SKY        7
     22 #define BACKGROUND_ABOVE_CLOUDS     8
     23 #define BACKGROUND_PURPLE_SKY       9
     24 
     25 // geo layout macros
     26 
     27 /**
     28  * 0x00: Branch and store return address
     29  *   0x04: scriptTarget, segment address of geo layout
     30  */
     31 #define GEO_BRANCH_AND_LINK(scriptTarget) \
     32     CMD_BBH(0x00, 0x00, 0x0000), \
     33     CMD_PTR(scriptTarget)
     34 
     35 /**
     36  * 0x01: Terminate geo layout
     37  *   0x01-0x03: unused
     38  */
     39 #define GEO_END() \
     40     CMD_BBH(0x01, 0x00, 0x0000)
     41 
     42 /**
     43  * 0x02: Branch
     44  *   0x01: if 1, store next geo layout address on stack
     45  *   0x02-0x03: unused
     46  *   0x04: scriptTarget, segment address of geo layout
     47  */
     48 #define GEO_BRANCH(type, scriptTarget) \
     49     CMD_BBH(0x02, type, 0x0000), \
     50     CMD_PTR(scriptTarget)
     51 
     52 /**
     53  * 0x03: Return from branch
     54  *   0x01-0x03: unused
     55  */
     56 #define GEO_RETURN() \
     57     CMD_BBH(0x03, 0x00, 0x0000)
     58 
     59 /**
     60  * 0x04: Open node
     61  *   0x01-0x03: unused
     62  */
     63 #define GEO_OPEN_NODE() \
     64     CMD_BBH(0x04, 0x00, 0x0000)
     65 
     66 /**
     67  * 0x05: Close node
     68  *   0x01-0x03: unused
     69  */
     70 #define GEO_CLOSE_NODE() \
     71     CMD_BBH(0x05, 0x00, 0x0000)
     72 
     73 /**
     74  * 0x06: Register the current node at the given index in the gGeoViews array
     75  *   0x01: unused
     76  *   0x02: s16 index
     77  */
     78 #define GEO_ASSIGN_AS_VIEW(index) \
     79     CMD_BBH(0x06, 0x00, index)
     80 
     81 /**
     82  * 0x07: Update current scene graph node flags
     83  *   0x01: u8 operation (0 = reset, 1 = set, 2 = clear)
     84  *   0x02: s16 bits
     85  */
     86 #define GEO_UPDATE_NODE_FLAGS(operation, flagBits) \
     87     CMD_BBH(0x07, operation, flagBits)
     88 
     89 /**
     90  * 0x08: Create screen area scene graph node
     91  *   0x01: unused
     92  *   0x02: s16 num entries (+2) to allocate
     93  *   0x04: s16 x
     94  *   0x06: s16 y
     95  *   0x08: s16 width
     96  *   0x0A: s16 height
     97  */
     98 #define GEO_NODE_SCREEN_AREA(numEntries, x, y, width, height) \
     99     CMD_BBH(0x08, 0x00, numEntries), \
    100     CMD_HH(x, y), \
    101     CMD_HH(width, height)
    102 
    103 /**
    104  * 0x09: Create orthographic projection scene graph node
    105  *   0x02: s16 scale as percentage
    106  */
    107 #define GEO_NODE_ORTHO(scale) \
    108     CMD_BBH(0x09, 0x00, scale)
    109 
    110 /**
    111  * 0x0A: Create camera frustum scene graph node
    112  *   0x01: u8  if nonzero, enable function field
    113  *   0x02: s16 field of view
    114  *   0x04: s16 near
    115  *   0x06: s16 far
    116  *   0x08: [GraphNodeFunc function]
    117 */
    118 #define GEO_CAMERA_FRUSTUM(fov, near, far) \
    119     CMD_BBH(0x0A, 0x00, fov), \
    120     CMD_HH(near, far)
    121 #define GEO_CAMERA_FRUSTUM_WITH_FUNC(fov, near, far, func) \
    122     CMD_BBH(0x0A, 0x01, fov), \
    123     CMD_HH(near, far), \
    124     CMD_PTR(func)
    125 
    126 /**
    127  * 0x0B: Create a root scene graph node
    128  *   0x01-0x03: unused
    129  */
    130 #define GEO_NODE_START() \
    131     CMD_BBH(0x0B, 0x00, 0x0000)
    132 
    133 /**
    134  * 0x0C: Create zbuffer-toggling scene graph node
    135  *   0x01: u8 enableZBuffer (1 = on, 0 = off)
    136  *   0x02-0x03: unused
    137  */
    138 #define GEO_ZBUFFER(enable) \
    139     CMD_BBH(0x0C, enable, 0x0000)
    140 
    141 /**
    142  * 0x0D: Create render range scene graph node
    143  *   0x01-0x03: unused
    144  *   0x04: s16 minDistance
    145  *   0x06: s16 maxDistance
    146  */
    147 #define GEO_RENDER_RANGE(minDistance, maxDistance) \
    148     CMD_BBH(0x0D, 0x00, 0x0000), \
    149     CMD_HH(minDistance, maxDistance)
    150 
    151 /**
    152  * 0x0E: Create switch-case scene graph node
    153  *   0x01: unused
    154  *   0x02: s16 numCases
    155  *   0x04: GraphNodeFunc caseSelectorFunc
    156  */
    157 #define GEO_SWITCH_CASE(count, function) \
    158     CMD_BBH(0x0E, 0x00, count), \
    159     CMD_PTR(function)
    160 
    161 /**
    162  * 0x0F: Create a camera scene graph node.
    163  *   0x01: unused
    164  *   0x02: s16 camera type
    165  *   0x04: s16 posX
    166  *   0x06: s16 posY
    167  *   0x08: s16 posZ
    168  *   0x0A: s16 focusX
    169  *   0x0C: s16 focusY
    170  *   0x0E: s16 focusZ
    171  *   0x10: GraphNodeFunc function
    172  */
    173 #define GEO_CAMERA(type, x1, y1, z1, x2, y2, z2, function) \
    174     CMD_BBH(0x0F, 0x00, type), \
    175     CMD_HHHHHH(x1, y1, z1, x2, y2, z2), \
    176     CMD_PTR(function)
    177 
    178 /**
    179  * 0x10: Create translation & rotation scene graph node with optional display list
    180  * Four different versions of 0x10
    181  *   cmd+0x01: u8 params
    182  *     0b1000_0000: if set, enable displayList field and drawingLayer
    183  *     0b0111_0000: fieldLayout (determines how rest of data is formatted
    184  *     0b0000_1111: drawingLayer
    185  *
    186  *   fieldLayout = 0: Translate & Rotate
    187  *     0x04: s16 xTranslation
    188  *     0x06: s16 yTranslation
    189  *     0x08: s16 zTranslation
    190  *     0x0A: s16 xRotation
    191  *     0x0C: s16 yRotation
    192  *     0x0E: s16 zRotation
    193  *     0x10: [u32 displayList: if MSbit of params set, display list segmented address]
    194  */
    195 #define GEO_TRANSLATE_ROTATE(layer, tx, ty, tz, rx, ry, rz) \
    196     CMD_BBH(0x10, (0x00 | layer), 0x0000), \
    197     CMD_HHHHHH(tx, ty, tz, rx, ry, rz)
    198 #define GEO_TRANSLATE_ROTATE_WITH_DL(layer, tx, ty, tz, rx, ry, rz, displayList) \
    199     CMD_BBH(0x10, (0x00 | layer | 0x80), 0x0000), \
    200     CMD_HHHHHH(tx, ty, tz, rx, ry, rz), \
    201     CMD_PTR(displayList)
    202 
    203 /**
    204  *   fieldLayout = 1: Translate
    205  *     0x02: s16 xTranslation
    206  *     0x04: s16 yTranslation
    207  *     0x06: s16 zTranslation
    208  *     0x08: [u32 displayList: if MSbit of params set, display list segmented address]
    209  */
    210 #define GEO_TRANSLATE(layer, tx, ty, tz) \
    211     CMD_BBH(0x10, (0x10 | layer), tx), \
    212     CMD_HH(ty, tz)
    213 #define GEO_TRANSLATE_WITH_DL(layer, tx, ty, tz, displayList) \
    214     CMD_BBH(0x10, (0x10 | layer | 0x80), tx), \
    215     CMD_HH(ty, tz), \
    216     CMD_PTR(displayList)
    217 
    218 /**
    219  *   fieldLayout = 2: Rotate
    220  *     0x02: s16 xRotation
    221  *     0x04: s16 yRotation
    222  *     0x06: s16 zRotation
    223  *     0x08: [u32 displayList: if MSbit of params set, display list segmented address]
    224  */
    225 #define GEO_ROTATE(layer, rx, ry, rz) \
    226     CMD_BBH(0x10, (0x20 | layer), rx), \
    227     CMD_HH(ry, rz)
    228 #define GEO_ROTATE_WITH_DL(layer, rx, ry, rz, displayList) \
    229     CMD_BBH(0x10, (0x20 | layer | 0x80), rx), \
    230     CMD_HH(ry, rz), \
    231     CMD_PTR(displayList)
    232 
    233 /**
    234  *   fieldLayout = 3: Rotate Y
    235  *     0x02: s16 yRotation
    236  *     0x04: [u32 displayList: if MSbit of params set, display list segmented address]
    237  */
    238 #define GEO_ROTATE_Y(layer, ry) \
    239     CMD_BBH(0x10, (0x30 | layer), ry)
    240 #define GEO_ROTATE_Y_WITH_DL(layer, ry, displayList) \
    241     CMD_BBH(0x10, (0x30 | layer | 0x80), ry), \
    242     CMD_PTR(displayList)
    243 
    244 /**
    245  * 0x11: Create translation scene graph node with optional display list
    246  *   0x01: u8 params
    247  *     0b1000_0000: if set, enable displayList field and drawingLayer
    248  *     0b0000_1111: drawingLayer
    249  *   0x02: s16 translationX
    250  *   0x04: s16 translationY
    251  *   0x06: s16 translationZ
    252  *   0x08: [u32 displayList: if MSbit of params set, display list segmented address]
    253  */
    254 #define GEO_TRANSLATE_NODE(layer, ux, uy, uz) \
    255     CMD_BBH(0x11, layer, ux), \
    256     CMD_HH(uy, uz)
    257 #define GEO_TRANSLATE_NODE_WITH_DL(layer, ux, uy, uz, displayList) \
    258     CMD_BBH(0x11, (layer | 0x80), ux), \
    259     CMD_HH(uy, uz), \
    260     CMD_PTR(displayList)
    261 
    262 /**
    263  * 0x12: Create rotation scene graph node with optional display list
    264  *   0x01: u8 params
    265  *      0b1000_0000: if set, enable displayList field and drawingLayer
    266  *      0b0000_1111: drawingLayer
    267  *   0x02: s16 rotationX
    268  *   0x04: s16 rotationY
    269  *   0x06: s16 rotationZ
    270  *   0x08: [u32 displayList: if MSbit of params set, display list segmented address]
    271  */
    272 #define GEO_ROTATION_NODE(layer, ux, uy, uz) \
    273     CMD_BBH(0x12, layer, ux), \
    274     CMD_HH(uy, uz)
    275 #define GEO_ROTATION_NODE_WITH_DL(layer, ux, uy, uz, displayList) \
    276     CMD_BBH(0x12, (layer | 0x80), ux), \
    277     CMD_HH(uy, uz), \
    278     CMD_PTR(displayList)
    279 
    280 /**
    281  * 0x13: Create a scene graph node that is rotated by the object's animation.
    282  *   0x01: u8 drawingLayer
    283  *   0x02: s16 xTranslation
    284  *   0x04: s16 yTranslation
    285  *   0x06: s16 zTranslation
    286  *   0x08: u32 displayList: dislay list segmented address
    287  */
    288 #define GEO_ANIMATED_PART(layer, x, y, z, displayList) \
    289     CMD_BBH(0x13, layer, x), \
    290     CMD_HH(y, z), \
    291     CMD_PTR(displayList)
    292 
    293 /**
    294  * 0x14: Create billboarding node with optional display list
    295  *   0x01: u8 params
    296  *      0b1000_0000: if set, enable displayList field and drawingLayer
    297  *      0b0000_1111: drawingLayer
    298  *   0x02: s16 xTranslation
    299  *   0x04: s16 yTranslation
    300  *   0x06: s16 zTranslation
    301  *   0x08: [u32 displayList: if MSbit of params is set, display list segmented address]
    302  */
    303 #define GEO_BILLBOARD_WITH_PARAMS(layer, tx, ty, tz) \
    304     CMD_BBH(0x14, layer, tx), \
    305     CMD_HH(ty, tz)
    306 #define GEO_BILLBOARD_WITH_PARAMS_AND_DL(layer, tx, ty, tz, displayList) \
    307     CMD_BBH(0x14, (layer | 0x80), tx), \
    308     CMD_HH(ty, tz), \
    309     CMD_PTR(displayList)
    310 #define GEO_BILLBOARD() \
    311      GEO_BILLBOARD_WITH_PARAMS(0, 0, 0, 0)
    312 
    313 /**
    314  * 0x15: Create plain display list scene graph node
    315  *   0x01: u8 drawingLayer
    316  *   0x02-0x03: unused
    317  *   0x04: u32 displayList: display list segmented address
    318  */
    319 #define GEO_DISPLAY_LIST(layer, displayList) \
    320     CMD_BBH(0x15, layer, 0x0000), \
    321     CMD_PTR(displayList)
    322 
    323 /**
    324  * 0x16: Create shadow scene graph node
    325  *   0x01: unused
    326  *   0x02: s16 shadowType (cast to u8)
    327  *   0x04: s16 shadowSolidity (cast to u8)
    328  *   0x06: s16 shadowScale
    329  */
    330 #define GEO_SHADOW(type, solidity, scale) \
    331     CMD_BBH(0x16, 0x00, type), \
    332     CMD_HH(solidity, scale)
    333 
    334 /**
    335  * 0x17: Create render object scene graph node
    336  *   0x01-0x03: unused
    337  */
    338 #define GEO_RENDER_OBJ() \
    339     CMD_BBH(0x17, 0x00, 0x0000)
    340 
    341 /**
    342  * 0x18: Create dynamically generated displaylist scene graph node
    343  *   0x01: unused
    344  *   0x02: s16 parameter
    345  *   0x04: GraphNodeFunc function
    346  */
    347 #define GEO_ASM(param, function) \
    348     CMD_BBH(0x18, 0x00, param), \
    349     CMD_PTR(function)
    350 
    351 /**
    352  * 0x19: Create background scene graph node
    353  *   0x02: s16 background: background ID, or RGBA5551 color if backgroundFunc is null
    354  *   0x04: GraphNodeFunc backgroundFunc
    355  */
    356 #define GEO_BACKGROUND(background, function) \
    357     CMD_BBH(0x19, 0x00, background), \
    358     CMD_PTR(function)
    359 #define GEO_BACKGROUND_COLOR(background) \
    360      GEO_BACKGROUND(background, NULL)
    361 
    362 /**
    363  * 0x1A: No operation
    364  */
    365 #define GEO_NOP_1A() \
    366     CMD_BBH(0x1A, 0x00, 0x0000), \
    367     CMD_HH(0x0000, 0x0000)
    368 
    369 /**
    370  * 0x1B: Copy the shared children from an object parent node from a specific view
    371  * to a newly created object parent.
    372  *   0x02: s16 index of array
    373  */
    374 #define GEO_COPY_VIEW(index) \
    375     CMD_BBH(0x1B, 0x00, index)
    376 
    377 /**
    378  * 0x1C: Create a held object scene graph node
    379  *  cmd+0x01: u8 unused
    380  *  cmd+0x02: s16 offsetX
    381  *  cmd+0x04: s16 offsetY
    382  *  cmd+0x06: s16 offsetZ
    383  *  cmd+0x08: GraphNodeFunc nodeFunc
    384  */
    385 #define GEO_HELD_OBJECT(param, ux, uy, uz, nodeFunc) \
    386     CMD_BBH(0x1C, param, ux), \
    387     CMD_HH(uy, uz), \
    388     CMD_PTR(nodeFunc)
    389 
    390 /**
    391  * 0x1D: Create scale scene graph node with optional display list
    392  *   0x01: u8 params
    393  *     0b1000_0000: if set, enable displayList field and drawingLayer
    394  *     0b0000_1111: drawingLayer
    395  *   0x02-0x03: unused
    396  *   0x04: u32 scale (0x10000 = 1.0)
    397  *   0x08: [u32 displayList: if MSbit of params is set, display list segment address]
    398  */
    399 #define GEO_SCALE(layer, scale) \
    400     CMD_BBH(0x1D, layer, 0x0000), \
    401     CMD_W(scale)
    402 #define GEO_SCALE_WITH_DL(layer, scale, displayList) \
    403     CMD_BBH(0x1D, (layer | 0x80), 0x0000), \
    404     CMD_W(scale), \
    405     CMD_PTR(displayList)
    406 
    407 /**
    408  * 0x1E: No operation
    409  */
    410 #define GEO_NOP_1E() \
    411     CMD_BBH(0x1E, 0x00, 0x0000), \
    412     CMD_HH(0x0000, 0x0000)
    413 
    414 /**
    415  * 0x1F: No operation
    416  */
    417 #define GEO_NOP_1F() \
    418     CMD_BBH(0x1F, 0x00, 0x0000), \
    419     CMD_HH(0x0000, 0x0000), \
    420     CMD_HH(0x0000, 0x0000), \
    421     CMD_HH(0x0000, 0x0000)
    422 
    423 /**
    424  * 0x20: Create a scene graph node that specifies for an object the radius that
    425  * is used for frustum culling.
    426  *   0x01: unused
    427  *   0x02: s16 cullingRadius
    428  */
    429 #define GEO_CULLING_RADIUS(cullingRadius) \
    430     CMD_BBH(0x20, 0x00, cullingRadius)
    431 
    432 #endif // GEO_COMMANDS_H