GBL Programming

Keywords

The following list shows the reserved words in GBL. These reserved words may not be used as constants or variables or any other identifier names.

else

return

for

if

while

def

asm

get

set

setOAM

screenOff

screenOn

clearOAM

loadScreenshot

loadTiles

loadBlackAndWhiteTiles

loadMap

loadMapDisplay

gamepadButtons

gamepadDirections

copy

fill

rand

halt

Variables

Variable

The following example shows to declare a variable

scrollX = 0;

Array

The following example shows to declare an array. Array size must be between 0 and 255.

data[20];
data[0] = 0;
data[1] = 0;

Constants & Literals

Integer Literals

An integer literal can be a decimal, binary, or hexadecimal constant. A prefix specifies the base or radix: $ for hexadecimal, % for binary, and nothing for decimal.

Let’s define value 42 in the 3 forms :

a = 42;
b = $2A;
c = %00101010;

Defining Constants

In GBL constants can be defined like this

define GAMEPAD_START = $08;
define GAMEPAD_DOWN = $08;
define GAMEPAD_UP = $04;
define GAMEPAD_LEFT = $02;
define GAMEPAD_RIGHT = $01;
define GAMEPAD_A = $01;
define GAMEPAD_B = $02;

Operators

Relational Operators

The following table shows all the relational operators supported by GBL

Operator Description

==

Returns true if the values of two operands are equal.

!=

Returns true if the values of two operands are not equal.

>

Returns true if the value of left operand is greater than the value of right operand.

<

Returns true if the value of left operand is less than the value of right operand.

>=

Returns true if the value of left operand is greater than or equal to the value of right operand.

Returns true if the value of left operand is less than or equal to the value of right operand.

Logical Operators

Following table shows all the logical operators supported by GBL

Operator Description Example

&&

Logical AND operator. If both the operands are non-zero, then the condition becomes true.

(A && B) is false.

Logical OR Operator. If any of the two operands is non-zero, then the condition becomes true.

(A

Assignment Operators

The following table lists the assignment operators supported by GBL

Operator Description Example

=

Simple assignment operator.

C = A

+=

Add AND assignment operator.

C += A is equivalent to C = C + A.

-=

Subtract AND assignment operator.

C -= A is equivalent to C = C - A.

Decision Making

If Else statements

The syntax of an if…​else statement in GBL programming language is

if(expression) {
   /* statement(s) */
} else if(boolean_expression) {
   /* statement(s) */
} else {
   /* statement(s) */
}

GBL does not support switch

Ternary operator

The syntax of ternary operator in GBL programming language is

scrollx = scrollx > 42 ? 0 : scrollx;

Loops

While loop

The syntax of a while loop in GBL programming language is

while(condition) {
   statement;
}

For loop

The syntax of a for each loop in GBL programming language is

for ( val in Number ) {
   statement(s);
}

The syntax of a for loop in GBL programming language is

for ( init; condition; increment ) {
   statement(s);
}

Function

Function Declaration

This example is the source code for a function called max(). This function takes two parameters num1 and num2 and returns the maximum value between the two.

/* function returning the max between two numbers */
max(num1, num2) {

   /* local variable declaration */
   result = 0;

   if (num1 > num2)
      result = num1;
   else
      result = num2;

   return result;
}

Calling a Function

To call a function, you simply need to pass the required parameters along with the function name.

/* max value between 42 and 1989 */
maxValue = max(42,1989);