VM_GET_INT8
is a GBVM instruction used to retrieve a signed 8-bit integer value from a specific memory address within Work RAM (WRAM) and store it into a GBVM variable.
Purpose:
WRAM is the Game Boy’s primary read/write memory, used for storing dynamic game data. VM_GET_INT8
is essential for reading these 8-bit values (which can range from -128 to 127) from WRAM into a variable that your GBVM script can then use for logic, calculations, or display. This is particularly useful for smaller values like flags, counters, or small coordinates, saving memory compared to using 16-bit integers.
This instruction is crucial for:
Syntax:
VM_GET_INT8 IDXA, ADDR
IDXA
: The target variable (a GBVM variable) where the retrieved 8-bit signed integer will be stored.ADDR
: The address (label) in WRAM from which the 8-bit signed integer value will be read.Usage Example: Reading Player Direction
Imagine your game stores the player’s current facing direction (e.g., 0 for Up, 1 for Down, 2 for Left, 3 for Right) in an 8-bit WRAM location. You want to read this direction to update the player’s sprite animation or to determine interaction logic.
; In your GBVM script:
; Variable to store the retrieved player direction
VAR_PLAYER_DIRECTION:
.R_INT8 0 ; Initialize to 0 (e.g., Up)
; Assume WRAM_PLAYER_DIR is a label pointing to an 8-bit location in WRAM
; where the game engine or other scripts update the player's direction.
; Read the 8-bit signed integer from WRAM_PLAYER_DIR into VAR_PLAYER_DIRECTION
VM_GET_INT8 VAR_PLAYER_DIRECTION, WRAM_PLAYER_DIR
; Now VAR_PLAYER_DIRECTION holds the current player's direction.
; You can then use it for conditional logic:
VM_IF_CONST VAR_PLAYER_DIRECTION == 0 ; If player is facing Up
VM_ACTOR_SET_ANIM PLAYER_ACTOR, ANIM_PLAYER_WALK_UP
VM_ENDIF
; Example of how WRAM_PLAYER_DIR might be defined (conceptual, in WRAM section)
; SECTION "WRAM Data", WRAM
; WRAM_PLAYER_DIR:
; .BYTE 0 ; Reserve 1 byte for an 8-bit byte
In this example, VM_GET_INT8
fetches the current direction from WRAM_PLAYER_DIR
and places it into VAR_PLAYER_DIRECTION
, making it accessible for further GBVM operations like setting animations or conditional checks.
Analogy to other programming languages:
This is directly analogous to reading a single byte or a char
type variable from a specific memory address in C/C++:
int8_t currentDirection = *(int8_t*)WRAM_PLAYER_DIR_ADDRESS;
Or, more simply, accessing a global variable that is known to be an 8-bit integer:
int currentDirection = global_player_direction;
It’s about retrieving a numerical value of a specific, smaller size from a designated memory location.