Data and structures

Data declarations

CHARSET

CHARSET
CHARSET 'string',value
CHARSET start,value
CHARSET start,end,value
CHARSET 'string','string'
  • string+value, index each character of the string starting from value and incrementing at each character
  • start+value index each character from the ASCII code Start from value and increment at each character
  • start+end+value Same as above but from beginning to end only
  • string+string, to establish char to char conversion more easily (typical use in simple encryption)
  • No parameters, reset all ASCII codes to their initial value

UTF8REMAP 'character UTF8','8 bits code'

Some UTF8 characters, in particular accents, accented capitals and certain symbols, are not standard. It is possible to map them (CHARSET-style) by declaring them with this directive.

Please note that you must use the -fq command-line option for the preprocessor to authorize special characters.

utf8remap 'é',50
defb 'é' ; will output byte of value 50

DB, DEFB, DM, DEFM valeur1, valeur2, valeur3, …

This directive takes 1 or more parameters and generates a sequence of bytes representing the input parameters. The values can be literal, a formula, a character or even a string. DB, DM, DEFB, DEFM can be used. The following code will produce the string 'Roudoudou'

org #7500
label DEFB 'r'-'a'+'A','oudoud',#6F,hi(label)
DEFB 'roudoudou\xFF' ; add hex value #FF at the end of the string

STR string1, string2, …

This directive is similar to DEFB except that the last character produced undergoes an OR #80 (set to 1 of the most significant bit), mostly used to save 1 byte when declaring strings. The following two lines of code do exactly the same thing

str 'roudoudou'
defb 'roudoudo','u'|#80

DEFW valeur1,valeur2

Declaration of 16-bit values, it is no longer possible to use strings, but a single character between quotes is still possible!

DEFI valeur1,valeur2

Declaration of 32-bit values, it is no longer possible to use strings, but a single character between quotes is still possible!

DEFR valeur1,valeur2

Declaration of real values 40 bits of the locomotive Basic, it is no longer possible to use strings, but a single character between quotes is still possible!

DEFF valeur1,valeur2

Declaration of real values 40 bits Microsoft IEEE-754, it is no longer possible to use strings, but a single character between quotes is still possible!

Declarations and use of structures

STRUCT nom_du_prototype, nom_de_la_variable / ENDSTRUCT

When STRUCT is used with 1 parameter (name), the following labels will be used to declare the structure, in particular its indexes
When STRUCT is used with 2 parameters (type_name+struct_name), a structure is created of type_name and will be called structure_name

Although RASM allows you to put anything inside the declaration of a structure, the practical use is to declare labels and via the data definition instructions, a field size. It is not necessary to fill in a value in the DEF

struct st1
  ch1 defw
  ch2 defb
endstruct

struct metast1
  struct st1 pr1
  struct st1 pr2
endstruct

struct metast1 bigst ; instanciation de metast1 en bigst

ld hl,bigst.pr2.ch1 ; récupération de l'adresse absolue d'un membre de bigst
ld a,(hl)

ld a,(ix+metast1.pr2.ch1 ; utilisation de l'offset du champ via la définition de la structure (pas besoin d'instancier pour cet usage)

{SIZEOF} prefix

The prefix {sizeof} used with a structure or substructure name or in front of a structure field, allows to retrieve its size

ld a,{sizeof}metast1 ; LD A,6
ld a,{sizeof}metast1.pr2 ; LD A,3
ld a,{sizeof}metast1.pr2.ch1 ; LD A,2

tableau de STRUCT

It is possible to instantiate the same structure several times, as if it were an array of structures, in the following way

STRUCT mystruct my_instance,10

This is different from a DEFS 10*{sizeof}mystruct because the data is initialized with the default values if they were defined when the structure was declared, unlike a zero fill. Moreover it is possible to address each structure via an index by adding the index to the end of the instance name

ld hl,my_instances5 ; récupérer l'adresse de la cinquième structure

déclaration de STRUCT et initialisation

STRUCT mystruct
field1 defs 10
ENDSTRUCT

STRUCT mystruct my_instance,1,'roudoudou' ; declare 1 struct, set field to 'roudoudou', will be completed with zero (because declaration was not using any data)
Sauf mention contraire, le contenu de cette page est protégé par la licence Creative Commons Attribution-ShareAlike 3.0 License