SM64 Exposed ASM Functions

By James S.

For the N64 version of SM64. Any value starting with 0x is a hex value.

Functions are simply a number of instructions that perform certain tasks ranging from very simple to complex, such as to copy values or to spawn an object. Some functions require information to do their job, known as input parameters; for example, the spawn function needs to know, amongst other input values, the behaviour and GFX ID of the object to be spawned. These values can be passed using registers, by placing data on the stack, or the function can use global variables, or combinations of the three.

At assembler level, the functions appear as either JAL (Jump And Link) or, JR (Jump Register) where the address of the function is placed in a register before using the JR instruction. JAL is limited to using a fixed address for the location of the function whereas JR can use any value that's in a register and is commonly used to jump to a function whose address comes from a look-up table.

Note: I will update the information on this page as I find and test more functions.

As well as helping you to understand how the game works, you can use these functions yourself in your own programs. Some of my more advanced codes are actually short programs which make use of these functions.

The names of the functions were decided by me since there's no way of knowing what they were originally called when looking at the game software at assembler level. I will update this page as often as I can.

For each function the PAL (UK) address is listed first, followed by the NTSC (USA) address and then the name I have given the function with any input parameters and return value (if any) shown also.

0x8037C470 set_xyz_obj_size(float f12)

Takes single param in f12 which is the size to use for the object's width (offset 0x2C), height (offset 0x30) and depth (offset 0x34). Affects the object that is currently being updated.

0x8037C458 set_xyz_obj_size2(int *A0, int A1)

Uses the size value in A1 (which is converted to a float) and stores it at offset A0+0x2C (width), A0+0x30 (height) and A0+0x34 (depth). Since A0 could point to anywhere in memory it doesn't have to be used with objects and the input could be used for anything.

0x8036FF2C 0x80378840 store_32-bit_triplet_series(int *A0, int A1, int A2, int A3)

Takes 32-bit values in registers A1, A2 and A3 and stores them as floats at the address pointed to by A0, A0+4 and A0+8. One use of this function is to set Mario's size in his object structure.

0x8036FF00 copy_float_triplet(int *A0, int *A1)

Copies the floating-point values stored at addresses pointed to by A1, A1+4 and A1+8 and stores them at addresses pointed to by A0, A0+4 and A0+8. One use of this function is to copy Mario's position (X,Y,Z) variables stored outside of the Mario object to the position variables in the Mario object.

A0=destination addresss.

A1=source address.

0x8037DB24 V0=test_obj_collision(int *A0, int *A1)

Test for collision between two objects. Input params:

A0=pointer to an object structure.

A1=pointer to another object structure.

Returns:

V0=0 if collision between the two objects; 1 if no collision.***Check***

0x8037C80C v0=find_obj_with_behaviour(int A0)

Find an object that has a certain behaviour.

A0=segment/offset behaviour value.

Returns:

V0=address of object with specified behaviour (or zero if no object found with required behaviour?)

0x8037FA08 go_to_function_by_action(int A0)

Executes a function based on the value of the current object's action variable (offset 0x14C) as an index value into a list of pointers to functions. Example use is the Thwomp behaviour to execute the correct function depending on its current action.

A0=address of the first pointer to function which will be executed if the object's action variable is zero. If the object's action variable is 1 the address of the function that will be executed will be (A0+4) and so on.

0x8037BF88 0x8029EDCC *V0=spawn_object(int *A0,int A1,int A2)

Spawns an object. Input params:

A0=pointer to object for positioning spawned object (i.e. the object whose behaviour is responsible for spawning the object, but could be another object).

A1=graphic ID of object to be spawned (not needed for some behaviours in which the graphic ID should be zero).

A2=segment/offset pointer to start of behaviour script for object to be spawned (determines behaviour to use for spawned object).

Returns:

V0=pointer to spawned object.

0x8037C0D0 0x8029EF64 *v0=spawn_object2(int A0,int A1,int A2,int A3,int *T0,int T1,int T2)

Spawns an object a set distance from the parent object. Input params:

A0=Extra value to be passed to the behaviour for spawning the object (e.g., type of Koopa, etc).

A1=X distance from parent object.

A2=Y distance from parent object.

A3=Z distance from parent object.

T0 (T2 NTSC) =Pointer to parent object.***Check***

T1 (T3 NTSC) =Graphic ID for spawning object.***Check***

T2 (T4 NTSC) =Segment/offset behaviour value for spawning object.***Check***

Returns:

V0=pointer to spawned object.

0x802AC420 print_scrn(int A0, int A1, int *A2, int A3)

Displays colourful text and integer value on screen (e.g. of use is for debug).

A0=Screen X position (high values are towards right of the screen).

A1=Screen Y position (low values are towards bottom of the screen).

A2=Pointer to C style zero terminated string (uses ASCII).

A3=Integer value to display with string.

0x802AC708 0x802D66C0 print_scrn2(int A0, int A1, int *A2)

Displays colourful text on screen (e.g. of use is for level select).

A0=Screen X position (high values are towards right of the screen).

A1=Screen Y position (low values are towards bottom of the screen).

A2=Pointer to zero terminated string (uses ASCII).

0x802AE828 print_scrn3(int A0, int *A1, int A2) ***NOT TESTED***

Displays colourful text on screen (e.g. of use is at file select screen).

A0=Screen X position (high values are towards right of the screen).

A1=Pointer to text string (does not use ASCII but Nintendo's own format instead).

A2=?

0x802ADC18 print_scrn4(int A1, int A2, int *A3) ***NOT TESTED***

Displays colourful text on screen (e.g. of use is at file select screen).

A1=?

A2=?

A3=Pointer to text string (does not use ASCII but Nintendo's own format instead).

0x80380884 0x802A50FC shake_screen(int A0)

Shakes the screen such as when a Thwomp hits the ground.

A0=type of screen shake (0=none or stop screen shake 1=shake screen 2=shake screen even more).

0x802BA1A4 0x802E6AF8 explode_object()

Makes an object explode and spawns a Bob-omb with no yellow coin(?), like a Bob-omb. Where does the yellow coin come from? The function looks up the current object that is being updated so the object that explodes will be the one whose behaviour called this function.

0x802A3890 0x802CA190 play_sound(int A0)

Plays the sound determined by the value loaded into register A0, for example, 0x60086001 is the Bob-omb lit fuse sound (although only the upper half, i.e. 0x6008, changes what sound is played). It seems that every sound is always available including what Peach says in the ending cut-scene. The function looks up what the current object is perhaps as to play the sound from the object's position. Calls function play_sound2 so it's a wrapper function.

0x802E9C34 0x8031EB00 play_sound2(int A0,int* A1) NOT TESTED

Plays a sound. Example of use is for playing the pause sound effect.

A0=Sound value

A1=Pointer to sound related variables?

0x802B6AFC 0x802E2414 Create preset objects (those which use behaviour and GFX ID values from look-up table)?

0x802692F0 V0=segOffConvAddr(int A0)

Converts a segment/offset value to actual address (including 0x80 at start of address value).

A0=segment/offset value (32-bit)

V0=address (32-bit) calculated from segment/offset value

0x803721C0 initObj0_10(int *A0)

Initializes variables at offset 0x00 to 0x10 of an object structure.

A0=pointer to start of the object structure to initialize.

0x8024A740 Change Mario's pose?

A0,A2,A3=?

A1=pose/action type

0x8037CFEC conv_GFX_ID_Store(int A0)

Converts a graphic ID value to the actual address of the graphics to use for an object and stores the graphics pointer at offset 0x14 in the object that is currently being updated.

A0=graphic ID

0x8024F2E0 display_credits()

Displays credis text used in the ending?

Input params=(not added yet)

0x8026B140 0x8027A7D0 set_screen_attributes(int A0, int *A1, int A2, int A3)

Changes the screen size (so that it becomes a window), position, colour of unused area of screen, and possibly other attributes. The function must be called constantly to have an affect on the screen. An example of when this function is used is during the end credits to change the size of the screen.

A0=? Used by NTSC version but not in PAL version. Unknown use.

A1=Pointer to screen values such as size and position?

A2=Red colour of unused area of screen.

A3=Green colour of unused area of screen.

The blue colour amount for the unused area of screen should be stored at SP+0x13 as a byte before calling the function (the game uses black and stores zero as a word at SP+0x10 but it has the same effect).

0x802AEC64 0x802D8D08 display_message_box(int A0)

Displays text in black in a white box which can be scrolled through using the A and B buttons. Used by signposts and other objects. Also, sounds and music changes are played with the message.

A0=message number

0x8029D7C0 0x802C17BC spawn_item(int *A0,int A1)

Spawns a preset item, used by item boxes.

A0=pointer to list of item related values (behaviour, GFX ID, etc) used by the item boxes.

A1=item number.

0x8037D060 0x802A0568 remove_object(int *A0)

Disables an object by writing zero (16-bit) at offset 0x74 of the object structure pointed to by A0.

0x8037AF88 remove_object(int *A0)

Same as 0x8037D060: Disables an object by writing zero (16-bit) at offset 0x74 of the object structure pointed to by A0.

0x8037C628 hide_object()

Hides the object currently being updated so it is invisible. It does this by ORing 0x0010 with the value at offset 0x0002 in the object.

0x8037197C face_other_object(float F12, float F14) ? Other params?

Make an object face another object? Used by most baddies so that they home in on Mario. Also used by Mario behaviour to face Mario in direction of the analgue stick.

***Is current object affected?***

F12=Z distance between the two objects.

F14=X distance between the two objects.

Returns?

0x8037EC98 rotate_object() ?

Rotates object on all 3 axis depending on values in the object structure? Affects object currently being updated. Used by the clock hands inside the castle.

0x8037DBC0 V0=check_object_behaviour(int A0)

Checks if the object currently being updated has a certain behaviour.

A0=behaviour segment/offset value

Returns:

V0=0 Object currently being updated does not have the specified behaviour.

V0=1 Object currently being updated does have the specified behaviour.

All content of this and related pages is copyright (c) James S. 2007-2009