Menu

Data Segment

 
      The data segment is located at very first portion of virtual address space in a GPC bytecode. It contains static values that are initialized by the programmer. The size of this segment is determined by the values placed inside of the data statement. The values of the data segment are read-only, it can't be altered at run-time. The main purpose of the data segment is store static information, which can be accessed by the script through an indexer.
 
      A data segment must be defined in the very beginning of a GPC script, using syntax such as the following:
 
// Defines can be declared before data segment.
define SOME_VAL = 40;
 
// The data segment defines a sequence of values expressed in bytes.
data(5, 10, 255, 0, 8, SOME_VAL, 147, 216, 186, 99);
 
      The values inside of the data segment must be expressed in bytes (8 bits unsigned integer).
 
  Related GPC Functions:
 
      The functions below provides a interface to access values stored in the data segment. Each element of data segment is accessed by an index. In GPC, indexing starts from 0.
 
dchar      Returns a char (8 bits signed integer) from data segment
dbyte      Returns a byte (8 bits unsigned integer) from data segment
dword      Returns a word (16 bits signed integer) from data segment
 

  1. dchar

      Returns a char (8 bits signed integer) from the data segment.
 
  Prototype:
 
int dchar ( <index> )
 
  Parameters:
 
<index> : index of an element in the data segment
 
  Return:
 
The char value of the element in the position specified by <index>
 
  Example:
 
data(255, 1);
 
int val;
 
main {
    val = dchar(0); // val = -1;
    val = dchar(1); // val = 1;
}
 

  2. dbyte

      Returns a byte (8 bits unsigned integer) from the data segment.
 
  Prototype:
 
int dbyte ( <index> )
 
  Parameters:
 
<index> : index of an element in the data segment
 
  Return:
 
The byte value of the element in the position specified by <index>
 
  Example:
 
data(255, 1);
 
int val;
 
main {
    val = dbyte(0); // val = 255;
    val = dbyte(1); // val = 1;
}
 

  3. dword

      Returns a word (16 bits signed integer) from the data segment.
 
  Prototype:
 
int dword ( <index> )
 
  Parameters:
 
<index> : index of an element in the data segment
 
  Return:
 
The word value of the element in the position specified by <index>
 
  Example:
 
data(255, 1);
 
int val;
 
main {
    val = dword(0); // val = 511;
}