Command 0x04: Call subroutine

Plays the sequence at the specified address repeatedly, the specified number of times.

Syntax

0x04, byte count, ushort address

Parameters

ParameterTypeContents
countbytePlay count (0 means 256 times)
addressushortAPU RAM address of the subroutine

Remarks

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 by command 0x05.
Each time command 0x05 is executed, the remaining count decreases by 1, and execution returns to the start of the subroutine until it reaches 0. When it reaches 0, playback continues right after this command.

The call stack has 8 levels per channel. Subroutines can call further subroutines.

This command takes no time to process, and the following event is read within the same tick.

Note

  • There is no check of the call stack depth. Calling beyond 8 levels corrupts the call stack of the neighboring channel.
  • If 0 is specified as the play count, it becomes 255 at the end of the first pass, so it is played 256 times in total.

See also

Structure of sequence data
Command 0x05
Command 0x21