Macros, structs & enums

FantASM offers structured-programming constructs on top of plain assembly.

Macros

MACRO <name> [<params>] defines a reusable block of code, ended by END or ENDM. Parameters are referenced by name in the body:

MACRO setborder colour
    ld a, colour
    out ($fe), a
ENDM

    setborder 2        ; expands inline with colour = 2

Structs

STRUCT <name> defines a memory layout. Members are declared as <name> [DB|DW|BYTE|WORD], and the block ends with ENDS or END:

STRUCT Sprite
    x   DB
    y   DB
    tile DW
ENDS

Instantiate a struct by writing <label> <struct_name> <initializers> (comma-separated):

player  Sprite 128, 96, tile_hero

Use SIZEOF(Sprite) to get the size of the structure.

Enums

ENUM <name> [<start>] [, <step>] defines a set of named constants. Members are <name> [= <value>], and the block ends with ENDE or END. The resulting constants are named <enum_name>.<member>:

ENUM State 0
    idle           ; State.idle  = 0
    walking        ; State.walking = 1
    jumping        ; State.jumping = 2
    dead = 10      ; State.dead   = 10
ENDE

    ld a, State.walking