2019-05-20 02:57:59 +10:00
|
|
|
; zasm
|
|
|
|
;
|
|
|
|
; Reads input from specified blkdev ID, assemble the binary in two passes and
|
|
|
|
; spit the result in another specified blkdev ID.
|
|
|
|
;
|
|
|
|
; We don't buffer the whole source in memory, so we need our input blkdev to
|
|
|
|
; support Seek so we can read the file a second time. So, for input, we need
|
|
|
|
; GetC and Seek.
|
|
|
|
;
|
|
|
|
; For output, we only need PutC. Output doesn't start until the second pass.
|
|
|
|
;
|
|
|
|
; The goal of the second pass is to assign values to all symbols so that we
|
|
|
|
; can have forward references (instructions referencing a label that happens
|
|
|
|
; later).
|
|
|
|
;
|
|
|
|
; Labels and constants are both treated the same way, that is, they can be
|
|
|
|
; forward-referenced in instructions. ".equ" directives, however, are evaluated
|
|
|
|
; during the first pass so forward references are not allowed.
|
|
|
|
;
|
|
|
|
; *** Requirements ***
|
|
|
|
; strncmp
|
|
|
|
; addDE
|
|
|
|
; addHL
|
|
|
|
; upcase
|
|
|
|
; unsetZ
|
|
|
|
; intoDE
|
|
|
|
; intoHL
|
|
|
|
; writeHLinDE
|
|
|
|
; findchar
|
|
|
|
; parseHex
|
|
|
|
; parseHexPair
|
|
|
|
; blkSel
|
2019-06-05 10:45:01 +10:00
|
|
|
; blkSet
|
2019-05-20 02:57:59 +10:00
|
|
|
; fsFindFN
|
|
|
|
; fsOpen
|
|
|
|
; fsGetC
|
2019-06-01 01:12:29 +10:00
|
|
|
; cpHLDE
|
2019-06-03 04:05:20 +10:00
|
|
|
; parseArgs
|
2019-06-05 01:53:02 +10:00
|
|
|
; _blkGetC
|
|
|
|
; _blkPutC
|
|
|
|
; _blkSeek
|
|
|
|
; _blkTell
|
2019-06-20 01:42:39 +10:00
|
|
|
; printstr
|
2019-05-20 02:57:59 +10:00
|
|
|
; FS_HANDLE_SIZE
|
2019-06-05 01:53:02 +10:00
|
|
|
; BLOCKDEV_SIZE
|
2019-05-20 02:57:59 +10:00
|
|
|
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "user.h"
|
2019-07-24 06:50:19 +10:00
|
|
|
|
|
|
|
; *** Overridable consts ***
|
2019-10-07 06:42:09 +11:00
|
|
|
; NOTE: These limits below are designed to be *just* enough for zasm to assemble
|
|
|
|
; itself. Considering that this app is Collapse OS' biggest app, it's safe to
|
|
|
|
; assume that it will be enough for many many use cases. If you need to compile
|
|
|
|
; apps with lots of big symbols, you'll need to adjust these.
|
|
|
|
; With these default settings, zasm runs with less than 0x1800 bytes of RAM!
|
|
|
|
|
2019-07-24 06:50:19 +10:00
|
|
|
; Maximum number of symbols we can have in the global and consts registry
|
|
|
|
.equ ZASM_REG_MAXCNT 0xff
|
|
|
|
|
|
|
|
; Maximum number of symbols we can have in the local registry
|
2019-10-07 06:42:09 +11:00
|
|
|
.equ ZASM_LREG_MAXCNT 0x20
|
2019-07-24 06:50:19 +10:00
|
|
|
|
|
|
|
; Size of the symbol name buffer size. This is a pool. There is no maximum name
|
|
|
|
; length for a single symbol, just a maximum size for the whole pool.
|
|
|
|
; Global labels and consts have the same buf size
|
2019-10-07 06:42:09 +11:00
|
|
|
.equ ZASM_REG_BUFSZ 0x700
|
2019-07-24 06:50:19 +10:00
|
|
|
|
|
|
|
; Size of the names buffer for the local context registry
|
2019-10-07 06:42:09 +11:00
|
|
|
.equ ZASM_LREG_BUFSZ 0x100
|
2019-07-24 06:50:19 +10:00
|
|
|
|
|
|
|
; ******
|
|
|
|
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "err.h"
|
2019-05-20 02:57:59 +10:00
|
|
|
.org USER_CODE
|
|
|
|
|
|
|
|
jp zasmMain
|
|
|
|
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/const.asm"
|
|
|
|
.inc "lib/util.asm"
|
|
|
|
.inc "zasm/util.asm"
|
2019-05-20 02:57:59 +10:00
|
|
|
.equ IO_RAMSTART USER_RAMSTART
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/io.asm"
|
2019-05-20 02:57:59 +10:00
|
|
|
.equ TOK_RAMSTART IO_RAMEND
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/tok.asm"
|
|
|
|
.inc "lib/parse.asm"
|
2019-07-26 04:02:04 +10:00
|
|
|
.equ INS_RAMSTART TOK_RAMEND
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/instr.asm"
|
2019-07-26 04:02:04 +10:00
|
|
|
.equ DIREC_RAMSTART INS_RAMEND
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/directive.asm"
|
|
|
|
.inc "zasm/parse.asm"
|
|
|
|
.inc "zasm/expr.asm"
|
2019-05-20 02:57:59 +10:00
|
|
|
.equ SYM_RAMSTART DIREC_RAMEND
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/symbol.asm"
|
2019-05-20 02:57:59 +10:00
|
|
|
.equ ZASM_RAMSTART SYM_RAMEND
|
2019-10-07 05:32:23 +11:00
|
|
|
.inc "zasm/main.asm"
|