Skip to main content

Call a subroutine

SCRIPT_CALL · opcode 0xef · 3 bytes

Script virtual machine · Opcode list · Control flow

Runs the script code at another position of the level's script buffer, then comes back when that code executes Return from a call.

Encoding​

Offsets count from the opcode byte. Words are little-endian.

OffsetTypeFieldMeaning
0u8opcode0xef
1u16letargetOffset from the start of the runtime script buffer.

Example (constructed, not from a level): ef 02 00 calls the code at buffer offset 2.

Behavior​

The return stack holds up to ten positions.1

if return_depth < 10:
return_stack[return_depth] = position after the operand
return_depth = return_depth + 1
continue at script_buffer + target
else:
continue after the operand # the call is silently skipped

target uses the same base as Jump: the start of the buffer, not the instruction.

Edge cases and unknowns​

  • A full stack makes the call a no-op rather than an error.
  • target is not checked: it is added to the buffer's offset in 16 bits, so a target of 7,508 or more runs the bytes of the areas that follow the script buffer, and a sum beyond 65,535 wraps to the start of the buffer's memory segment.

Sources​

Footnotes​

  1. Handler for 0xef, with the return stack, its depth and the script buffer pointer. Comparative source: oeob_callSubroutine in REF-SCUMM-003. ↩