Defined SM64 functions for CajeASM
Users browsing this thread: 1 Guest(s)

So if you have ever done your own custom ASM code, then you are very familiar with the JAL command that allows you to call functions. You would have to go searching for the specific address every time you forgot about it, unless you just write everything yourself.

As a small side project I'm creating a file that you can include into your ASM source code, so you only have to remember the names of each function. So instead of remembering that 0x802D66C0 is the function that prints text, you can just put down @PrintXY instead.

.include "SM64Functions.txt"
// Later in the code...
LUI A2, 0x802C
ORI A2, A2, 0xB23C // Pointer to ASCII string
ORI A0, R0, 0x0028 // X position
JAL @PrintXY
ORI A1, R0, 0x0050 // Y position

Inside the file itself includes documentation on every function along with the define; so if you don't know how many arguments a function needs, or what the function returns, then you can just look it up in the file.

Spoiler :
[Image: fYR5SN4.png]

I am hosting the file over on github, so you can add to the project if you want to. There is not a lot of functions at the moment, but I will continuously add more over time. There are hundreds of functions in SM64, so I want to only add the ones that ASM coders will find useful in multiple situations.

​Github page

This will be really useful
Gone for a while.

I added 2 more functions: @ConfigureTimer and @PlayTransition. In this post there are 2 example projects that show how to use both of these functions in-game.

The @ConfigureTimer function allows you to enable, disable, start, or stop the HUD timer.

[Image: qpEviG5.png]

Spoiler: Definition
/*
ConfigureTimer (0x802495E0 / 0x45E0)

Enables, disables, starts, or stops the HUD timer

Arguments:
A0 = option
- 0 = Shows timer and resets time value to zero
- 1 = Starts timer
- 2 = Stops timer
- 3 = Stops showing timer and resets time value to zero
Returns:
V0 = time value (value / 30 = time in seconds)
*/

[ConfigureTimer]​: 0x002495E0
Spoiler: TimerExample.asm
.include "SM64Functions.txt"

// Re-organize Mario's behavior
​.org 0x21CCC0 
​hex

00 00 00 00 
10 05 00 00 
11 01 01 00 
11 03 00 01 
23 00 00 00 00 25 00 A0 
08 00 00 00 
0C 00 00 00 80 29 CA 58 
0C 00 00 00 80 2C B2 64 
0C 00 00 00 80 7F 00 00 
09 00 00 00 
}


​// Overwriting part of the top levelscript.
​.org 0x108A18
​hex
{
11 08 00 00 80 2C B1 C0 
}


​// Function that will copy data from the ROM to the RAM
​.org 0x861C0
​ADDIU SP, SP, $FFE8
​SW RA, $0014 (SP)
​SW A0, $0010 (SP)
// lvl cmd 0x11 safeguard

​// Do not remove these following 4 instructions
​JAL @osViBlack
​MOV A0, R0
​LUI T0, 0x8039
​SW R0, 0xBE24(T0)
// Set level accumulator to 0

​LUI T0, 0x807F
​ORI A0, T0, 0x0000
​LUI T1, 0x03D0
​ORI A1, T1, 0x0000
​JAL @DmaCopy
​ORI A2, T1, 0x4000

​LW V0, $0010 (SP)
// lvl cmd 0x11 safeguard
​LW RA, $0014 (SP)
​JR RA
​ADDIU SP, SP, $0018 

/*
Custom loop function 0x807F0000

Use the D-Pad to configure the timer
D-pad Up = Enables Timer
D-pad Down = Disables Timer
D-pad Left = Starts Timer
D-pad Right = Stops Timer
*/

​.org 0x3D00000
​ADDIU SP, SP, $FFE8
​SW RA, $0014 (SP)

​LUI T0, 0x8034
​LH T0, 0xAFA0(T0)

​ANDI AT, T0, 0x0800
​BNEZ AT, 807F0000_ENABLETIMER
// Check D-Pad Up
​NOP
​ANDI AT, T0, 0x0400
​BNEZ AT, 807F0000_DISABLETIMER
// Check D-Pad Down
​NOP
​ANDI AT, T0, 0x0200
​BNEZ AT, 807F0000_STARTTIMER
// Check D-Pad Left
​NOP
​ANDI AT, T0, 0x0100
​BNEZ AT, 807F0000_STOPTIMER
// Check D-Pad Right
​NOP
​BEQZ R0, 807F0000_END
​NOP

807F0000_ENABLETIMER:
​JAL @ConfigureTimer
​ADDIU A0, R0, 0x00
​BEQZ R0, 807F0000_END
​NOP
807F0000_STARTTIMER:
​JAL @ConfigureTimer
​ADDIU A0, R0, 0x01
​BEQZ R0, 807F0000_END
​NOP
807F0000_STOPTIMER:
​JAL @ConfigureTimer
​ADDIU A0, R0, 0x02
​BEQZ R0, 807F0000_END
​NOP
807F0000_DISABLETIMER:
​JAL @ConfigureTimer
​ADDIU A0, R0, 0x03

807F0000_END:
​LW RA, $0014 (SP)
​JR RA
​ADDIU SP, SP, $0018 
The @PlayTransition function is used by the game's warp system to play a transition animation when mario goes to another level/area. The arguments of this function change which image is used and what RGB color to use for the background. Now this function has nothing to do with warps, but instead the transition animation that goes with warping. After the transition animation is completed, you will need to set the byte at 0x8033BAB3 to 0 to clear the screen.

[Image: 12f3we0.png]

Spoiler: Definition

/*
PlayTransition (0x8027B1A0 / 0x0361A0)

Plays a transition on the screen.

Arguments:
A0 = Image
- 0x01 = No image (fade to color)
- 0x09 = Star image
- 0x0B = Circle image
- 0x11 = Mario face image
- 0x13 = Bowser image
A1 = amount of time for transition to complete
A2 = red color amount (0x00 to 0xFF)
A3 = green color amount (0x00 to 0xFF)
SP + 0x10 = blue color amount (0x00 to 0xFF)

Note:
After the transition has been played, the screen will be filled up
with whatever color you chose. To fix this, detect if the byte at
0x8033BAB3 is equal to 1. If it is 1, then set that value to zero.
*/

[PlayTransition]​: 0x0027B1A0
Spoiler: TransitionExample.asm
.include "SM64Functions.txt"

// Re-organize Mario's behavior
​.org 0x21CCC0 
​hex

00 00 00 00 
10 05 00 00 
11 01 01 00 
11 03 00 01 
23 00 00 00 00 25 00 A0 
08 00 00 00 
0C 00 00 00 80 29 CA 58 
0C 00 00 00 80 2C B2 64 
0C 00 00 00 80 7F 00 00 
09 00 00 00 
}


​// Overwriting part of the top levelscript.
​.org 0x108A18
​hex
{
11 08 00 00 80 2C B1 C0 
}


​// Function that will copy data from the ROM to the RAM
​.org 0x861C0
​ADDIU SP, SP, $FFE8
​SW RA, $0014 (SP)
​SW A0, $0010 (SP)
// lvl cmd 0x11 safeguard

​// Do not remove these following 4 instructions
​JAL @osViBlack
​MOV A0, R0
​LUI T0, 0x8039
​SW R0, 0xBE24(T0)
// Set level accumulator to 0

​LUI T0, 0x807F
​ORI A0, T0, 0x0000
​LUI T1, 0x03D0
​ORI A1, T1, 0x0000
​JAL @DmaCopy
​ORI A2, T1, 0x4000

​LW V0, $0010 (SP)
// lvl cmd 0x11 safeguard
​LW RA, $0014 (SP)
​JR RA
​ADDIU SP, SP, $0018 

/*
Custom loop function 0x807F0000

Press L to play a mario-face transition with a purple background.
*/

​.org 0x3D00000
​ADDIU SP, SP, $FFE8
​SW RA, $0014 (SP)

​LUI AT, 0x8034
​LB AT, 0xBAB3(AT)
​BNEZ AT, 807F0000_PATH2
​NOP

807F0000_PATH1:
​LUI T0, 0x8034
​LH T0, 0xAFA0(T0)
​ANDI AT, T0, 0x20
​BEQZ AT, 807F0000_END
// Check for L-button input
​NOP

​ADDIU T9, R0, 0xFF
// Blue color amount
​SW T9, 0x10(SP)
​ADDIU A0, R0, 0x11
// Fade image type
/*
  0x01 = No image (fade to color)
  0x09 = Star image
  0x0B = Circle image
  0x11 = Mario face image
  0x13 = Bowser image
*/

​ADDIU A1, R0, 0x40
// Timer (How long the effect will last)
​ADDIU A2, R0, 0x7F
// Red color amount
​JAL @PlayTransition
​ADDIU A3, R0, 0x00
// Green color amount

807F0000_PATH2:
​LUI T1, 0x8034
​SB R0, 0xBAB3(T1)
// When the effect is done, clear the screen.

807F0000_END:
​LW RA, $0014 (SP)
​JR RA
​ADDIU SP, SP, $0018 
(This post was last modified: 23-04-2016, 09:38 PM by David.)

Defined SM64 functions for CajeASM
Users browsing this thread: 1 Guest(s)


  EN ・日本語