GBVM Operations
Core
VM_STOP
VM_STOP
Stops execution of context.
VM_PUSH_CONST
VM_PUSH_CONST VAL
Pushes immediate value to the top of the VM stack.
- VAL: Immediate value to be pushed.
VM_POP
VM_POP N
Removes the top values from the VM stack.
- N: Number of values to be removed from the stack.
VM_CALL
VM_CALL ADDR
Calls script by near address.
- ADDR: Address of the script subroutine.
VM_RET
VM_RET
Returns from the near call.
VM_RET_N
VM_RET_N N
Returns from the near call and clears N arguments on stack.
- N: Number of arguments to be removed from the stack.
VM_GET_FAR
VM_GET_FAR IDX, SIZE, BANK, ADDR
Gets byte or word by the far pointer into variable.
- IDX: Target variable.
- SIZE: Size of the object to be acquired:
.GET_BYTE
- Get 8-bit value.
.GET_WORD
- Get 16-bit value. - BANK: Bank number of the object
- ADDR: Address of the object
VM_LOOP
VM_LOOP IDX, LABEL, N
Loops while variable is not zero, by the near address.
- IDX: Loop counter variable.
- LABEL: Jump label for the next iteration.
- N: Amount of values to be removed from stack on exit.
.CASE
.CASE VAL, LABEL
VM_SWITCH
VM_SWITCH IDX, SIZE, N
Compares variable with a set of values, and if equal, jumps to the specified label.
Values for testing may be defined with the .CASE macro, where VAL parameter is a value for testing and LABEL is a jump label.
- IDX: Variable for compare.
- SIZE: Amount of entries for test.
- N: Amount of values to be cleaned from stack on exit.
VM_JUMP
VM_JUMP LABEL
Jumps to near address.
- ARG0: Jump label.
VM_CALL_FAR
VM_CALL_FAR BANK, ADDR
Calls far routine (inter-bank call).
- BANK: Bank number of the routine.
- ADDR: Address of the routine.
VM_RET_FAR
VM_RET_FAR
Returns from the far call.
VM_RET_FAR_N
VM_RET_FAR_N N
Returns from the far call and removes N arguments from stack.
- N: Number of arguments to be removed from stack.
VM_INVOKE
VM_INVOKE BANK, ADDR, N, PARAMS
Invokes C function until it returns true.
- BANK: Bank number of the function.
- ADDR: Address of the function, currently 2 functions are implemented:
_wait_frames
- Wait for N vblank intervals.
_camera_shake
- Shake camera N times. - N: Number of arguments to be removed from stack on return.
- PARAMS: Points the first parameter to be passed into the C function.
VM_BEGINTHREAD
VM_BEGINTHREAD BANK, THREADPROC, HTHREAD, NARGS
Spawns a thread in a separate context.
- BANK: Bank number of a thread function.
- THREADPROC: Address of a thread function.
- HTHREAD: Variable that receives the thread handle.
- NARGS: Amount of values from the stack to be copied into the stack of the new context.
VM_IF
VM_IF CONDITION, IDXA, IDXB, LABEL, N
Compares two variables using for condition.
- CONDITION: Condition for test:
.EQ
- Variables are equal.
.LT
- A is lower than B.
.LTE
- A is lower or equal than B.
.GT
- A is greater than B.
.GTE
- A is greater or equal than B.
.NE
- A is not equal to B. - IDXA: A variable.
- IDXB: B variable.
- LABEL: Jump label when result is TRUE.
- N: Number of values to be removed from stack after evaluating the condition.
VM_PUSH_VALUE_IND
VM_PUSH_VALUE_IND IDX
Pushes a value on VM stack or a global indirectly from an index in the variable.
- IDX: Variable that contains the index of the variable to be pushed on stack.
VM_PUSH_VALUE
VM_PUSH_VALUE IDX
Pushes a value of the variable onto stack.
- IDX: Variable to be pushed.
VM_RESERVE
VM_RESERVE N
Reserves or disposes amount of values on stack.
- N: Positive value - amount of variables to be reserved on stack, negative value - amount of variables to be popped from stack.
VM_SET
VM_SET IDXA, IDXB
Assigns variable B to variable A.
- IDXA: Variable A.
- IDXB: Variable B.
VM_SET_CONST
VM_SET_CONST IDX, VAL
Assigns immediate value to the variable.
- IDX: Target variable.
- VAL: Source immediate value.
VM_RPN
VM_RPN
Reverse Polish Notation (RPN) calculator, returns result(s) on the VM stack.
.R_INT8
.R_INT8 ARG0
.R_INT16
.R_INT16 ARG0
.R_REF
.R_REF ARG0
.R_REF_IND
.R_REF_IND ARG0
.R_REF_SET
.R_REF_SET ARG0
.R_REF_SET_IND
.R_REF_SET_IND ARG0
.R_REF_MEM
.R_REF_MEM TYP, ADDR
.R_REF_MEM_SET
.R_REF_MEM_SET TYP, ADDR
.R_OPERATOR
.R_OPERATOR ARG0
.R_STOP
.R_STOP
VM_JOIN
VM_JOIN IDX
Joins a thread.
- IDX: Thread handle for joining.
VM_TERMINATE
VM_TERMINATE IDX
Kills a thread.
- IDX: Thread handle for killing.
VM_IDLE
VM_IDLE
Signals thread runner that context is in a waitable state.
VM_GET_TLOCAL
VM_GET_TLOCAL IDXA, IDXB
Gets thread local variable.
- IDXA: Target variable.
- IDXB: Thread local variable index.
VM_IF_CONST
VM_IF_CONST CONDITION, IDXA, B, LABEL, N
Compares a variable to an immediate value.
- CONDITION: Condition for test:
.EQ
- Variables are equal.
.LT
- A is lower than B.
.LTE
- A is lower or equal than B.
.GT
- A is greater than B.
.GTE
- A is greater or equal than B.
.NE
- A is not equal to B. - IDXA: A variable.
- B: Immediate value to be compared with.
- LABEL: Jump label when result is TRUE.
- N: Number of values to be removed from stack after evaluating the condition.
VM_GET_UINT8
VM_GET_UINT8 IDXA, ADDR
Gets unsigned int8 from WRAM.
- IDXA: Target variable.
- ADDR: Address of the unsigned 8-bit value in WRAM.
VM_GET_INT8
VM_GET_INT8 IDXA, ADDR
Gets signed int8 from WRAM.
- IDXA: Target variable.
- ADDR: Address of the signed 8-bit value in WRAM.
VM_GET_INT16
VM_GET_INT16 IDXA, ADDR
Gets signed int16 from WRAM.
- IDXA: Target variable.
- ADDR: Address of the signed 16-bit value in WRAM.
VM_SET_UINT8
VM_SET_UINT8 ADDR, IDXA
Sets unsigned int8 in WRAM from variable.
- ADDR: Address of the unsigned 8-bit value in WRAM.
- IDXA: Source variable.
VM_SET_INT8
VM_SET_INT8 ADDR, IDXA
Sets signed int8 in WRAM from variable.
- ADDR: Address of the signed 8-bit value in WRAM.
- IDXA: Source variable.
VM_SET_INT16
VM_SET_INT16 ADDR, IDXA
Sets signed int16 in WRAM from variable.
- ADDR: Address of the signed 16-bit value in WRAM.
- IDXA: Source variable.
VM_SET_CONST_INT8
VM_SET_CONST_INT8 ADDR, VAL
Sets signed int8 in WRAM to the immediate value.
- ADDR: Address of the signed 8-bit value in WRAM.
- VAL: Immediate value.
VM_SET_CONST_UINT8
VM_SET_CONST_UINT8 ADDR, VAL
Sets unsigned int8 in WRAM to the immediate value.
- ADDR: Address of the unsigned 8-bit value in WRAM.
- VAL: Immediate value.
VM_SET_CONST_INT16
VM_SET_CONST_INT16 ADDR, VAL
Sets signed int16 in WRAM to the immediate value.
- ADDR: Address of the signed 16-bit value in WRAM.
- VAL: Immediate value.
VM_INIT_RNG
VM_INIT_RNG IDX
Initializes RNG seed with the value from the variable.
- IDX: Seed value.
VM_RANDOMIZE
VM_RANDOMIZE
Initializes RNG seed.
VM_RAND
VM_RAND IDX, MIN, LIMIT
Returns random value between MIN and MIN + LIMIT.
- IDX: Target variable.
- MIN: Minimal random value.
- LIMIT: Range of the random values.
VM_LOCK
VM_LOCK
Disables switching of VM threads.
VM_UNLOCK
VM_UNLOCK
Enables switching of VM threads.
VM_RAISE
VM_RAISE CODE, SIZE
Raises an exception.
- CODE: Exception code:
EXCEPTION_RESET
- Resets the device.
EXCEPTION_CHANGE_SCENE
- Changes to a new scene.
EXCEPTION_SAVE
- Saves the state of the game.
EXCEPTION_LOAD
- Loads the saved state of the game. - SIZE: Length of the parameters to be passed into the exception handler.
VM_SET_INDIRECT
VM_SET_INDIRECT IDXA, IDXB
Assigns variable that is addressed indirectly to the other variable.
- IDXA: Variable that contains the index of the target variable.
- IDXB: Source variable that contains the value to be assigned.
VM_GET_INDIRECT
VM_GET_INDIRECT IDXA, IDXB
Assigns a variable to the value of variable that is addressed indirectly.
- IDXA: Target variable.
- IDXB: Variable that contains the index of the source variable.
VM_TEST_TERMINATE
VM_TEST_TERMINATE FLAGS
Terminates unit-testing immediately.
- FLAGS: Terminate flags:
.TEST_WAIT_VBL
- Wait for VBlank before terminating.
VM_POLL_LOADED
VM_POLL_LOADED IDX
Checks that VM state was restored and resets the restore flag.
- IDX: Target result variable.
VM_PUSH_REFERENCE
VM_PUSH_REFERENCE IDX
Translates IDX into absolute index and pushes result to VM stack.
- IDX: Index of the variable.
VM_CALL_NATIVE
VM_CALL_NATIVE BANK, PTR
Calls native code by the far pointer.
- BANK: Bank number of the native routine.
- PTR: Address of the native routine.
VM_MEMSET
VM_MEMSET DEST, VALUE, COUNT
Clears VM memory.
- DEST: First variable to be cleared.
- VALUE: Variable containing the value to be filled with.
- COUNT: Number of variables to be filled.
VM_MEMCPY
VM_MEMCPY DEST, SOUR, COUNT
Copies VM memory.
- DEST: First destination variable.
- SOUR: First source variable.
- COUNT: Number of variables to be copied.
Actor
VM_ACTOR_MOVE_TO
VM_ACTOR_MOVE_TO IDX
Moves actor to a new position.
- IDX: points to the beginning of the pseudo-structure that contains these members:
ID
- Actor number.
X
- New X-coordinate of the actor.
Y
- New Y-coordinate of the actor.
ATTR
- Bit flags:
.ACTOR_ATTR_H_FIRST
- Move horizontal first.
.ACTOR_ATTR_CHECK_COLL
- Respect collisions.
.ACTOR_ATTR_DIAGONAL
- Allow diagonal movement
VM_ACTOR_MOVE_CANCEL
VM_ACTOR_MOVE_CANCEL ACTOR
Cancels movement of actor.
- ACTOR: Variable that contains the actor number.
VM_ACTOR_ACTIVATE
VM_ACTOR_ACTIVATE ACTOR
Activates actor.
- ACTOR: Variable that contains the actor number.
VM_ACTOR_SET_DIR
VM_ACTOR_SET_DIR ACTOR, DIR
Sets direction of actor.
- ACTOR: Variable that contains the actor number.
- DIR: One of these directions:
.DIR_DOWN
- Actor faces down.
.DIR_RIGHT
- Actor faces right.
.DIR_UP
- Actor faces up.
.DIR_LEFT
- Actor faces left.
VM_ACTOR_DEACTIVATE
VM_ACTOR_DEACTIVATE ACTOR
Deactivates actor.
- ACTOR: Variable that contains the actor number.
VM_ACTOR_SET_ANIM
VM_ACTOR_SET_ANIM ACTOR, ANIM
Sets actor animation.
- ACTOR: Variable that contains the actor number.
- ANIM: Animation number.
VM_ACTOR_SET_POS
VM_ACTOR_SET_POS IDX
Sets actor position.
- IDX: points to the beginning of the pseudo-structure that contains these members:
ID
- Actor number.
X
- New X-coordinate of the actor.
Y
- New Y-coordinate of the actor.
VM_ACTOR_EMOTE
VM_ACTOR_EMOTE ACTOR, AVATAR_BANK, AVATAR
Sets actor emotion.
- ACTOR: Variable that contains the actor number.
- AVATAR_BANK: Bank of the avatar image.
- AVATAR: Address of the avatar image.
VM_ACTOR_SET_BOUNDS
VM_ACTOR_SET_BOUNDS ACTOR, LEFT, RIGHT, TOP, BOTTOM
Sets actor bounding box.
- ACTOR: Variable that contains the actor number.
- LEFT: Left boundary of the bounding box.
- RIGHT: Right boundary of the bounding box.
- TOP: Top boundary of the bounding box.
- BOTTOM: Bottom boundary of the bounding box.
VM_ACTOR_SET_SPRITESHEET
VM_ACTOR_SET_SPRITESHEET ACTOR, SHEET_BANK, SHEET
Sets actor spritesheet.
- ACTOR: Variable that contains the actor number.
- SHEET_BANK: Bank of the sprite sheet.
- SHEET: Address of the sprite sheet.
VM_ACTOR_SET_SPRITESHEET_BY_REF
VM_ACTOR_SET_SPRITESHEET_BY_REF ACTOR, FAR_PTR
Sets actor spritesheet using far pointer in variables.
- ACTOR: Variable that contains the actor number
- FAR_PTR: points to the pseudo-struct that contains the address of the sprite sheet:
BANK
- Bank of the sprite sheet
DATA
- Address of the sprite sheet
VM_ACTOR_REPLACE_TILE
VM_ACTOR_REPLACE_TILE ACTOR, TARGET_TILE, TILEDATA_BANK, TILEDATA, START, LEN
Replaces tile in the actor spritesheet.
- ACTOR: Variable that contains the actor number.
- TARGET_TILE: Tile number for replacement.
- TILEDATA_BANK: Bank of the tile data.
- TILEDATA: Address of the tile data.
- START: Start tile in the tile data array.
- LEN: Amount of tiles to be replaced.
VM_ACTOR_GET_POS
VM_ACTOR_GET_POS IDX
Gets actor position.
- IDX: points to the beginning of the pseudo-structure that contains these members:
ID
- Actor number.
X
- X-coordinate of the actor.
Y
- Y-coordinate of the actor.
VM_ACTOR_GET_DIR
VM_ACTOR_GET_DIR IDX, DEST
Gets actor direction.
- IDX: Variable that contains the actor number.
- DEST: Target variable that receive the actor direction.
VM_ACTOR_GET_ANGLE
VM_ACTOR_GET_ANGLE IDX, DEST
Gets actor angle.
- IDX: Variable that contains the actor number.
- DEST: Target variable to receive the actor angle.
VM_ACTOR_SET_ANIM_TICK
VM_ACTOR_SET_ANIM_TICK ACTOR, TICK
Sets actor animation tick.
- ACTOR: Variable that contains the actor number.
- TICK: Animation tick.
VM_ACTOR_SET_MOVE_SPEED
VM_ACTOR_SET_MOVE_SPEED ACTOR, SPEED
Sets actor move speed.
- ACTOR: Variable that contains the actor number.
- SPEED: Actor move speed.
VM_ACTOR_SET_FLAGS
VM_ACTOR_SET_FLAGS ACTOR, FLAGS, MASK
Sets actor flags.
- ACTOR: Variable that contains the actor number.
- FLAGS: Bit values to be set or cleared:
.ACTOR_FLAG_PINNED
- Pin/unpin the actor.
.ACTOR_FLAG_HIDDEN
- Hide/show actor.
.ACTOR_FLAG_ANIM_NOLOOP
- Disable animation loop.
.ACTOR_FLAG_COLLISION
- Disable/enable collision.
.ACTOR_FLAG_PERSISTENT
- Set persistent actor flag. - MASK: Bit mask of values to be set or cleared.
VM_ACTOR_SET_HIDDEN
VM_ACTOR_SET_HIDDEN ACTOR, HIDDEN
Hides or shows actor.
- ACTOR: Variable that contains the actor number.
- HIDDEN:
.ACTOR_VISIBLE
shows actor,.ACTOR_HIDDEN
hides actor.
VM_ACTOR_SET_COLL_ENABLED
VM_ACTOR_SET_COLL_ENABLED ACTOR, ENABLED
Enables or disables actor collisions.
- ACTOR: Variable that contains the actor number.
- ENABLED:
.ACTOR_COLLISION_DISABLED
disables actor collision,.ACTOR_COLLISION_ENABLED
enables actor collision.
VM_ACTOR_BEGIN_UPDATE
VM_ACTOR_BEGIN_UPDATE ACTOR
Begins actor update script.
- ACTOR: Variable that contains the actor number.
VM_ACTOR_TERMINATE_UPDATE
VM_ACTOR_TERMINATE_UPDATE ACTOR
Terminates actor update script.
- ACTOR: Variable that contains the actor number.
VM_ACTOR_SET_ANIM_FRAME
VM_ACTOR_SET_ANIM_FRAME ACTOR
Sets actor animation frame.
- ACTOR: Pseudo-struct that contains these members:
ID
- Actor number.
FRAME
- Animation frame.
VM_ACTOR_GET_ANIM_FRAME
VM_ACTOR_GET_ANIM_FRAME ACTOR
Gets actor animation frame.
- ACTOR: Pseudo-struct that contains these members:
ID
- Actor number.
FRAME
- Animation frame.
VM_ACTOR_SET_ANIM_SET
VM_ACTOR_SET_ANIM_SET ACTOR, OFFSET
Sets actor animation set.
- ACTOR: Variable that contains the actor number.
- OFFSET: Animation set number.
Camera
VM_CAMERA_MOVE_TO
VM_CAMERA_MOVE_TO IDX, SPEED, AFTER_LOCK
Moves the camera to a new position.
- IDX: Start of the pseudo-structure which contains the new camera position:
X
- X-coordinate of the camera position.
Y
- Y-coordinate of the camera position. - SPEED: Speed of the camera movement.
- AFTER_LOCK: Lock status of the camera after the movement:
.CAMERA_LOCK
- Lock camera by X and Y.
.CAMERA_LOCK_X
- Lock camera by X.
.CAMERA_LOCK_Y
- Lock camera by Y.
.CAMERA_UNLOCK
- Unlock camera.
VM_CAMERA_SET_POS
VM_CAMERA_SET_POS IDX
Sets the camera position.
- IDX: Start of the pseudo-structure which contains the new camera position:
X
- X-coordinate of the camera position.
Y
- Y-coordinate of the camera position.
Color
.DMG_PAL
.DMG_PAL COL1, COL2, COL3, COL4
.CGB_PAL
.CGB_PAL R1,G1,B1 R2,G2,B2 R3,G3,B3 R4,G4,B4
VM_LOAD_PALETTE
VM_LOAD_PALETTE MASK, OPTIONS
Game Boy
VM_LOAD_TILESET
VM_LOAD_TILESET IDX, BANK, BKG
Loads a new tileset into the background VRAM tiles starting at a given tile id (IDX
).
VM_SET_SPRITE_VISIBLE
VM_SET_SPRITE_VISIBLE MODE
Sets visibility of sprite layer. Has priority over VM_ACTOR_SET_HIDDEN.
- MODE: Mode:
.SPRITES_SHOW
- Show sprite layer.
.SPRITES_HIDE
- Hide sprite layer.
VM_SHOW_SPRITES
VM_SHOW_SPRITES
Macro for SET_SPRITES_VISIBLE .SPRITES_SHOW.
VM_HIDE_SPRITES
VM_HIDE_SPRITES
Macro for SET_SPRITES_VISIBLE .SPRITES_HIDE.
VM_INPUT_WAIT
VM_INPUT_WAIT MASK
Waits to receive an input.
- MASK: Input mask.
VM_INPUT_ATTACH
VM_INPUT_ATTACH MASK, SLOT
Attaches a script to an input.
- MASK: Input mask.
- SLOT: Slot containing script to attach.
VM_INPUT_GET
VM_INPUT_GET IDX, JOYID
Gets input from joypad. Up to 4 joypads are supported when using SGB.
- IDX: Target variable that receives result.
- JOYID: Joypad to get input from:
.JOY0
- Joypad 0.
.JOY1
- Joypad 1.
.JOY2
- Joypad 2.
.JOY3
- Joypad 3.
VM_CONTEXT_PREPARE
VM_CONTEXT_PREPARE SLOT, BANK, ADDR
Assigns a script to a slot for VM_INPUT_ATTACH.
- SLOT: Slot to assign to.
- BANK: Bank number of the script.
- ADDR: Address of the script.