Skip to content

MSC Tutorial Part 6

jam1garner edited this page Sep 19, 2017 · 2 revisions

syscalls

In MSC we can do a lot, but some things we need native code (what the game is compiled to) to do some of the heavy lifting for us. While as of writing this not all syscalls have been figured out we can still learn a lot about them just from looking at how they work. For this example we will use the random syscall.

pushInt. 0
pushInt. 9
sys. 2, 9
pushInt. "Random number: %i"
printf 2

This will print a random number from 0 to 9, including both 0 and 9. This is useful for things such as peach's turnips, villager's turnips, and much more. The syntax for the sys command is sys [argCount], [syscall number]. The random syscall is 9 and we pass in a range start and range end.

Shared variable access

ACMD and MSC share a set of variables they can both access through a variable id. This id will be a number such as 0x1E00000A or 0x20000078. Using syscall 0x16 we can access or modify these variables. The syntax for it is:

pushInt. [operationNum]
pushInt. (optional, depends on operation) [value]
pushInt. [variable id]
sys [args], 0x16

Table of some simple known operations

Number Operation Requires option value
0x6 Get value X
0x7 Set value

So if we want to set a variable we do something like:

pushInt. 7
pushInt. 5000
pushInt. 0x2000000
sys 0x3, 0x16

Which sets 0x2000000 to 5000. We can also get a variable like this:

pushInt. 6
pushInt. 0x2000000
sys. 0x2, 0x16

Remember, the . on sys is important because we want it to return something to the stack.

NOTES ABOUT PYMSC EMU: these are the only two syscalls supported in emulation as of writing this. Variable access is a bit gimped however as the only values accessed are ones written by the user, rather than having some exist without MSC writing to them.

Things to Try:

  • Get a random number between 1 and 100, print it and say if it is greater or lower than 50
  • Set variable 0x30000000 to a random number then print out variable 0x30000000's contents
  • Get 2 random numbers, store them in localVar0 and localVar1 and print [localVar0] % [localVar1] = [localVar0 modulous localVar1] (fill in things in square brackets with the values they represent)
Clone this wiki locally