FantASM

FantASM - A Z80 assembler

View on GitHub

FantASM

FantASM is a two pass non optimising assembler for the Z80 processor.

It supports all undocumented op-codes and the extended instruction set of the ZX Next and additional pseudo opcodes used by the CSpect emulator to control debugging.

Usage

fantasm <source> <output> [options]

Commandline options

  -h,--help             Show this help message and exit
  -N,--z80n             Enable Z80n (ZX Next) cpu extensions
  -c,--cspect           Enable cspect "exit" and "break" instructions
  -n,--nologo           Do no display the program name and version
  -v,--verbose          Enable verbose output
  -V,--version          Displays the version and exits
  -I,--include file     Add a directory to search for include files
  -i,--case-insensitive Enable case insensitive labels
  -D,--define constant  Define 1 more constants
  -e,--export-labels file
                        Export labels to a file
  -O,--origin address   Address to start assembling code
  -M,--max-code-size size
                        Limit the size of assembled code

Labels & Constants

Labels must start with a letter and may contain letters, numbers or underscores and optionally end with a semi colon. Local labels start with a period (.) and are only valid until the next none local label is defined.

Constants must start with a letter and may contain letters, numbers or underscores, but not semi-colons. Constants are defined using the following syntax:

<name> = <expression> (the = may be substituted with ‘equ’)

<expression> may only reference other constants or labels that have previously defined.

Non-Decimal Number Formats

Hexadecimal numbers may be in any of the following formats

Binary numbers may be in any of the following formats

Directives

Directives are not case sensitive, so any variation of ORG, org, Org etc. are completely valid.

ORG expr

Tells the assembler at which address to start assembling code.

!opt / #pragma

Controls different assembly options.

!message "string"

Displays a message on the console during assembly

DB,BYTE nn[,..]

outputs one or more bytes (8 bit values)

DW,WORD nnnn[,..]

outputs one or more words (16 bit values)

DS nn,size

creates a block of size and fills with the byte nn

DH,HEX "0-F.."

Outputs a sequence of 8 bit values by converting each 2 characters at a time, so “12FF” would be output as 0x12,0xFF

include "filename" I Includes another source file to be assembled.

binary,incbin "filename"

Includes a binary file.

IF / ELSE / ENDIF

Conditinally control assembly.


Returns the size of a struct or included binary file.
In order to support ```SIZEOF```, your ```INCBIN``` must be preceded by a label.

```GLOBAL label```

Marks a label as global. This determines whether a label will be included when using the -e,--export-labels switches

```STRUCT name```

Example
STRUCT rect
    left.w      // 2 bytes
    top.w
    width.w
    height.w
    flags.b    ; Single byte
END

ld  hl,(window.left)
ld  de,window.top

window: rect 0,0,0,0


```ENUM <name>,[<value>,<increment>]```

Example
ENUM name 0,1
    first
    second
    ...
    another = 20
    last       
END ```

Expressions

Macros

Macros may have 0 or more parameters, and may only declare local labels (labels that start with a .)

Simple Macro Example

``` org 0x8000

MACRO   border colour
    out (0xfe),colour
ENDM

start border 0 ret ```

History

1.1.10

1.1.8

1.1.7

1.1.6

1.1.5

1.1.4

1.1.3

1.1.2

1.1.1

1.1.0

1.0.0-rc2

1.0.0-rc1

0.9.1

0.9.0

0.8.0

0.7.7

0.7.6

0.7.5

0.7.4

0.7.3

0.7.2

0.7.1