added a way to extend command list without adding custom code to asm module
[bz80asm.git] / labman.zas
blob9a3d6f8f8cc67f5d9a3ed1bb9bd7ab020eceace0
1 ; label manager
3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
4 ;;
5 ;; create new label
6 ;; this is called from assembler to create a new label (or replace an existing one)
7 ;; the assembler doesn't try to check for duplicate labels
8 ;; IY points to the first char of label name
9 ;; after parsing, IY should point right after the parsed label
10 ;; it doesn't matter what this subroutine returns, it only
11 ;; has to parse and create a label
12 ;; all registers expect IY can be trashed
14 ;; IN:
15 ;;   IY: text input buffer
16 ;;   HL: label value
17 ;; OUT:
18 ;;   IY: text input buffer after the label
19 ;;   others (including alternate sets) are dead
21 DEFLABEL:
22   push  hl
23   ld    hl,msg_getvar
24   call  printstr
26   pop   hl
27   push  hl
28   ld    a,h
29   call  HEX
30   pop   hl
31   ld    a,l
32   call  HEX
33   ld    a,':'
34   call  EMIT
36   ld    a,(iy)
37   call  isAlpha
38   jp    c,error_identifier_expected
39   ld    b,0
40   push  iy
41 .idloop:
42   ld    a,(iy)
43   call  isIdChar
44   jr    c,.idend
45   inc   b
46   inc   iy
47   jr    .idloop
48 .idend:
49   ; print id
50   pop   iy
51 .iddumploop:
52   ld    a,(iy)
53   call  EMIT
54   inc   iy
55   djnz  .iddumploop
56   ld    a,'>'
57   call  EMIT
58   ld    a,13
59   call  EMIT
61   ret
63 msg_getvar: defx "NEWLABEL:<"