Two-pass table-driven assembler in the monitor: assembles BASIC-saved source files from the file system, or one line at a time with A addr. Labels, EQU/ORG/DB/DW/DS/END, expressions. Table generated from the disassembler (tools/gen-asmtab.py); round-trip and sdasz80 tests, plus a Z-80 build run in z80emu. Monitor RAM grows to 6000-7FFF for the symbol table. Works around an SDCC 4.5 inline strcpy bug with s_copy(). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
116 lines
2.8 KiB
ArmAsm
116 lines
2.8 KiB
ArmAsm
;; Monitor start-up. The monitor's bank holds ROM at 0000-5FFF and RAM at
|
|
;; 6000-7FFF. It is entered through the trampoline at 0066h (shared with
|
|
;; BASIC) with the program's AF and PC pushed on the program's stack.
|
|
.module crt0
|
|
.globl _mon_main
|
|
.globl l__INITIALIZER, s__INITIALIZER, s__INITIALIZED
|
|
.globl l__DATA, s__DATA
|
|
.globl _u
|
|
|
|
;; saved registers, at a fixed place gsinit never clears (see struct regs)
|
|
_u = 0x7F00
|
|
U_SP = 0x7F00
|
|
U_BC = 0x7F02
|
|
U_DE = 0x7F04
|
|
U_HL = 0x7F06
|
|
U_IX = 0x7F08
|
|
U_IY = 0x7F0A
|
|
U_AF2 = 0x7F0C
|
|
U_BC2 = 0x7F0E
|
|
U_DE2 = 0x7F10
|
|
U_HL2 = 0x7F12
|
|
U_I = 0x7F14
|
|
U_R = 0x7F15
|
|
U_EXIT = 0x7F16
|
|
INITED = 0x7FFE
|
|
|
|
.area _HEADER (ABS)
|
|
.org 0x0000
|
|
halt ; the bank is never in at reset
|
|
.include "../basic/tramp.s"
|
|
|
|
.org 0x0100
|
|
entry: ld (U_SP), sp
|
|
ld sp, #0x7F00
|
|
ld (U_BC), bc
|
|
ld (U_DE), de
|
|
ld (U_HL), hl
|
|
ld (U_IX), ix
|
|
ld (U_IY), iy
|
|
ex af, af'
|
|
push af
|
|
pop hl
|
|
ld (U_AF2), hl
|
|
ex af, af'
|
|
exx
|
|
ld (U_BC2), bc
|
|
ld (U_DE2), de
|
|
ld (U_HL2), hl
|
|
exx
|
|
ld a, i
|
|
ld (U_I), a
|
|
ld a, r
|
|
ld (U_R), a
|
|
ld a, (INITED) ; C data is set up once, then kept
|
|
cp #0xA5
|
|
jr z, 1$
|
|
call gsinit
|
|
ld a, #0xA5
|
|
ld (INITED), a
|
|
1$: call _mon_main
|
|
ld a, (U_I)
|
|
ld i, a
|
|
ld hl, (U_AF2)
|
|
push hl
|
|
pop af
|
|
ex af, af'
|
|
exx
|
|
ld bc, (U_BC2)
|
|
ld de, (U_DE2)
|
|
ld hl, (U_HL2)
|
|
exx
|
|
ld bc, (U_BC)
|
|
ld de, (U_DE)
|
|
ld hl, (U_HL)
|
|
ld ix, (U_IX)
|
|
ld iy, (U_IY)
|
|
ld sp, (U_SP)
|
|
ld a, (U_EXIT)
|
|
jp 0x0070
|
|
|
|
.area _HOME
|
|
.area _CODE
|
|
.area _INITIALIZER
|
|
.area _GSINIT
|
|
.area _GSFINAL
|
|
.area _DATA
|
|
.area _INITIALIZED
|
|
.area _BSEG
|
|
.area _BSS
|
|
.area _HEAP
|
|
|
|
.area _GSINIT
|
|
gsinit:
|
|
ld bc, #l__DATA ; clear uninitialised data
|
|
ld a, b
|
|
or a, c
|
|
jr z, 1$
|
|
ld hl, #s__DATA
|
|
ld (hl), #0
|
|
dec bc
|
|
ld a, b
|
|
or a, c
|
|
jr z, 1$
|
|
ld de, #s__DATA + 1
|
|
ldir
|
|
1$: ld bc, #l__INITIALIZER ; copy initialised data
|
|
ld a, b
|
|
or a, c
|
|
jr z, 2$
|
|
ld de, #s__INITIALIZED
|
|
ld hl, #s__INITIALIZER
|
|
ldir
|
|
2$:
|
|
.area _GSFINAL
|
|
ret
|