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
Call 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 clear N arguments on stack
- N: number of arguments to be removed from the stack
VM_GET_FAR
VM_GET_FAR IDX, SIZE, BANK, ADDR
Get byte or word by the far pointer into variable
- IDX: Target variable
- SIZE: Size of the ojject 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 jump 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 de 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
Call far routine (inter-bank call)
- BANK: Bank number of the routine
- ADDR: Address of the routine
VM_RET_FAR
VM_RET_FAR
Return from the far call
VM_RET_FAR_N
VM_RET_FAR_N N
Return from the far call and remove 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 if the result is true
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_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 if the result is true
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, V
Sets signed int8 in WRAM to the immediate value
- ADDR: Address of the signed 8-bit value in WRAM
- V: Immediate value
VM_SET_CONST_UINT8
VM_SET_CONST_UINT8 ADDR, V
Sets unsigned int8 in WRAM to the immediate value
- ADDR: Address of the unsigned 8-bit value in WRAM
- V: Immediate value
VM_SET_CONST_INT16
VM_SET_CONST_INT16 ADDR, V
Sets signed int16 in WRAM to the immediate value
- ADDR: Address of the signed 16-bit value in WRAM
- V: 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
Disable switching of VM threads
VM_UNLOCK
VM_UNLOCK
Enable 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 reset 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
Clear 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
copy 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
Move actor to the 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
Cancel movement of actor
- ACTOR: Variable that contains the actor number
VM_ACTOR_ACTIVATE
VM_ACTOR_ACTIVATE ACTOR
Activate the actor
- ACTOR: Variable that contains the actor number
VM_ACTOR_SET_DIR
VM_ACTOR_SET_DIR ACTOR, DIR
Set direction of the 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
Deactivate the actor
- ACTOR: Variable that contains the actor number
VM_ACTOR_SET_ANIM
VM_ACTOR_SET_ANIM ACTOR, ANIM
Set actor animation
- ACTOR: Variable that contains the actor number
- ANIM: Animation number
VM_ACTOR_SET_POS
VM_ACTOR_SET_POS IDX
Set new 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
Set 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
Set 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
Set 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
Set actor spritesheet using far the 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
Replace 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 for replacing
VM_ACTOR_GET_POS
VM_ACTOR_GET_POS IDX
Get 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
Get direction of the actor
- 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
Get actor angle
- IDX: Variable that contains the actor number
- DEST: Target variable that receive the actor angle
VM_ACTOR_SET_ANIM_TICK
VM_ACTOR_SET_ANIM_TICK ACTOR, TICK
Set 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
Set 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
Set 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
Hide/show actor
- ACTOR: Variable that contains the actor number
- HIDDEN:
.ACTOR_VISIBLE
shows actor,.ACTOR_HIDDEN
hides the actor
VM_ACTOR_SET_COLL_ENABLED
VM_ACTOR_SET_COLL_ENABLED ACTOR, ENABLED
Enable/disable actor collisions
- ACTOR: Variable that contains the actor number
- ENABLED:
.ACTOR_COLLISION_DISABLED
disables actor collision,.ACTOR_COLLISION_ENABLED
enables actor collision
VM_ACTOR_TERMINATE_UPDATE
VM_ACTOR_TERMINATE_UPDATE ACTOR
Terminates the actor update script
- ACTOR: Variable that contains the actor number
VM_ACTOR_SET_ANIM_FRAME
VM_ACTOR_SET_ANIM_FRAME ACTOR
Set animation frame for the actor
- ACTOR: pseudo-struct that contains these members:
ID
- Actor number
FRAME
- Animation frame
VM_ACTOR_GET_ANIM_FRAME
VM_ACTOR_GET_ANIM_FRAME ACTOR
Get animation frame of the actor
- 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
Set animation frame for the actor
- 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 the 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