some cleanups
[bz80asm.git] / output.zas
blob0c2aed26730429aeb92970c29b866a4df8e40a56
1 WIDTH: defb  30  ;PRINT WIDTH
4 emitInit:
5   ld    a,2
6   call  #1601 ; open main screen channel
7   ld    (emitSavedIY),iy
8   ret
11 emitSavedIY: defw 0
13 ; A: code
14 ; should preserve registers (except A and F)
15 OSWRCH:
16   push  iy
17   ld    iy,(emitSavedIY)
18   ei
19   rst   #10
20   di
21   ld    (emitSavedIY),iy
22   pop   iy
23   ret
25 ;OUT - SEND CHARACTER OR KEYWORD
26 ;   Inputs: A = character (>=10, <128)
27 ;           A = Token (<10, >=128)
28 ;  Destroys: A,F
30 EMIT:
31   cp    10
32   ret   z
33   push  af
34   call  OSWRCH
35   pop   af
36   cp    13
37   ld    a,0
38   jr    z,.cr
39   ld    a,(COUNT)
40   inc   a
41 .cr:
42   ld    (COUNT),a
43   ret
45 CRLF:
46   ld    a,13
47   call  EMIT
48   ret
51 ; A: position to move to
52 ; if current output is further than that, go to the new line
53 ; should preserve registers (except A and F)
54 TABIT:
55   ld      hl,COUNT
56   cp      (hl)
57   ret     z
58   push    af
59   call    c,CRLF
60   pop     af
61   sub     (hl)
62 FILL:
63   or      a
64   ret     z
65   push    bc
66   ld      b,a
67 FILL1:
68   ld      a,' '
69   call    EMIT
70   djnz    FILL1
71   pop     bc
72   xor     a
73   ret
76 printstr:
77   dec   hl
78 .loop:
79   inc   hl
80   ld    a,(hl)
81   and   #7f
82   call  EMIT
83   bit   7,(hl)
84   jr    z,.loop
85   ret
87 printstrnl:
88   call  printstr
89   ld    a,31
90   jp    EMIT
93 errmsg_identifier_expected:
94   defx  "integer expected"
95 errmsg_integer_expected:
96   defx  "integer expected"
97 errmsg_out_of_range:
98   defx  "out of range"
99 errmsg_string_expected:
100   defx  "string expected"
101 errmsg_syntax:
102   defx  "syntax error"
104 error_identifier_expected:
105   ld    hl,errmsg_identifier_expected
106   jp    error_common
107 error_integer_expected:
108   ld    hl,errmsg_integer_expected
109   jp    error_common
110 error_out_of_range:
111   ld    hl,errmsg_out_of_range
112   jp    error_common
113 error_string_expected:
114   ld    hl,errmsg_string_expected
115   jp    error_common
116 eror_syntax:
117   ld    hl,errmsg_syntax
118   jp    error_common
120 error_common:
121   call  printstrnl
123   ld    a,2
124   out   (#fe),a
125   jr    $