Command 0x04: Call subroutine
Plays the sequence at the specified address repeatedly, the specified number of times.
Syntax
0x04, byte count, ushort address
Parameters
| Parameter | Type | Description |
|---|---|---|
| count | byte | Play count (0 means 256 times) |
| address | ushort | APU RAM address of the subroutine |
Description
Pushes the current read position (the address of this command itself) and the play count onto the call stack, and moves to address. The end of the subroutine is marked with command 0x05.
Each time command 0x05 is executed, the remaining count is decremented by 1, and playback returns to the start of the subroutine until it reaches 0. When it reaches 0, playback continues from immediately after this command.
Each channel’s call stack has 8 levels. A subroutine can call further subroutines.
This command takes no time to process; the following event is read within the same tick.
Note
- There is no check of the call stack depth. Calling more than 8 levels deep corrupts the neighboring channel’s call stack.
- If the play count is 0, it becomes 255 at the end of the first pass, so it plays 256 times in total.