TRSE Syntax

Program structure

Programs must start with the “program” keyword. Variable declarations must happen before procedure declarations. Main block starts with a “begin” and “end.

Program MyProgram;
var
    a,b,c : byte = 0;
 
Procedure Myprocedure(mp_i:byte);
var
  somProcedureVariable : byte;
begin
  // Do someting
end;
 
// This is the main block.
begin
   // Call user-defined procedures etc
   MyProcedure(2);
end.

Types

TRSE supports several data types:

  • byte : values 0-255. Supported on all systems.
  • integer: values 0-65535. Supported on all systems, still dodgy on the Z80
  • pointer : Points to an address in memory. Uses zero pages on the 6502, “long” on the m68k and is simply an integer on the (GB)Z80
  • string : An array of characters
  • incbin : include a binary file
  • incsid : include SID music file (C64 only)
  • incnsf : include NSF music file (NES only)

The motorola 68000 as some additional types:

  • long : 32 bit numbers
  • pointer of byte/integer/long : pointer to byte/integer/long array (motorola 68000 only)

Type modifiers

On some systems, it is necessary to attribute a specific type in order to tell TRSE where the block should be placed. This is mostly relevant for the Amiga and the Gameboy. Examples:
Program MyProgram;
var
   myArray: array[$100] of byte chipmem; // Places data in chipmem (AMIGA only)
   sprite_data : array[4*3] of byte sprram; // Puts data in sprite    (GAMEBOY only)

Arrays

Arrays of bytes and integers are defined as such:

// Preprocessor constants are basically string-replace operation performed before compile
@define somePreprocessorConstant 25
 
var
   // Real constant
   const someConstant : byte = 25;
   myArray1 : array[128] of integeger; // 128*2 bytes of zeros are declared
   myArray2 : array[4*someConstant] of byte = (0,5,$90, someConstant*2);
   myArray3 : array[] of integer = ($1000, $2000, $3000, someConstant*$100); // unspecified array count
   myArray4 : array[255-55] of byte = (1,2,3); // only 3 values defined, rest will be padded with zeros.

Arrays are accessed as such:

myArray[i]:=someValue*5;

there are no out-of bonds testing in TRSE.

Conditional statements

if

An if-else block in TRSE is defined as such:

if (a=1) then DoSomething();
if (a<>3) then  // not equals
begin
   DoSomethingElse();
   IgnoreMe(4);
end;
if (a*2=b*3) then=return() else somethingelse();

Note that an there should be no semicolon “;” before an “else”.
A final note: The “empty” conditional

if (a) then DoSomething() else DoSomethingElse();

is the same as typing “if (a=true)”

while

While conditionals works similar to if statements:

while (a>0) then do 
begin
  PrintSomething(a);
  dec(a);
end;

Multiple conditionals:

Multiple conditionals needs to be nested in a hierarchy as such:
if (a>0 and (c<10 or d<>5)) then ... 
if (j<>k*2 or (c<10 or (b=c and d=e))) then ...

Cases

Cases tests a single variable for multiple values as such:

 case i of:
   0: DoSomething();
   1: begin 
        HelloThere();
        b:=b+5;
      end;
   2+i : ThisIsWeird();
  else 
     begin
       PerformElseBlock();
     end;

The else block is optional.

Procedures

Procedures are defined as such:

Procedure NoParameters();
begin
   // .. code here
end;
 
// Procedure with single parameter and variable block
procedure DoSomething(a,b:byte; zp: pointer);
var
  localVar : byte;
 
begin
   zp:=zp+a;
   localVar := a+b; 
   // ...
end;

You can return a value from a procedure by using ‘ReturnValue(myValue)’.

Functions

Functions are procedures that can return values. TRSE currently only supports ‘byte’ and ‘integer’ as return values.

function Calc( p : byte ) : byte;
begin
   // return some random calculation
   Calc := p*p + 2; 
end;
begin
   // Call function
   i:=Calc( j+2 );
   // ...
end;

For loops

For 6502 systems, due to the nature of pointers and arrays, only bytes are allowed as counter variables.

for i:=0 to 10 do 
begin
   doSomething(i);
end;
 
for j:=a to b step 2 do  // increases j with 2 for each step
  someArray[j]:=a+b*j;

Preprocessors

TRSE has a lot of preprocessor directives defined. These can be used to give messages to the compiler before the actual parsing of the program is executed.

Constants

Constants are preprocessors that will be string replaced before compilation occurs.

@define myConstant 4
@define myText "WHOO PARTY"
 
...
a:=@myConstant * 5; // same as 4*5

Preprocessor ifdef / if / else / endif

You can define preprocessor constants and use them in preprocessor expressions as such:
@define L 1
@define N 10
 
 
@ifdef L // If @L is defined...
	@if N = 10    // if @N holds the value of 10
		screen_bg_col:=1; 
	@else
		screen_bg_col:=2;
	@endif
@else // if L is not defined
	screen_bg_col:=4;
@endif

Records

A record is similar to a “typedef” in C, and lets the programmer bundle a set of variables together to a primitive object. TRSE allows for creation of these objects in arrays.
program SomeRecords;
var
	monster_type = record
		x,y : byte; // Current position of monster 
		color : byte; // Current colour of monster
                health : byte;
	end;
 
        player : monster_type; // Declare "player" as a single monster type
        const noMonsters: byte = 10;
        // Declare an array of monsters_type
        monsters : array[noMonsters] of monster_type;