-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathtermdef.mac
315 lines (259 loc) · 5.99 KB
/
termdef.mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
;**********************************************************************;
; ;
; This file is part of TED, a clone of the screen-oriented text ;
; editor that was once available for the RT-11 OS. ;
; Copyright (C) 2011-2020, Hector Peraza. ;
; ;
; This program is free software; you can redistribute it and/or ;
; modify it under the terms of the GNU General Public License as ;
; published by the Free Software Foundation; either version 2 of ;
; the License, or (at your option) any later version. ;
; ;
; This program is distributed in the hope that it will be useful, ;
; but WITHOUT ANY WARRANTY; without even the implied warranty of ;
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;
; GNU General Public License for more details. ;
; ;
; You should have received a copy of the GNU General Public License ;
; along with this program; if not, write to the Free Software ;
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;
; ;
;**********************************************************************;
.Z80
title TED - Text Editor
subttl Terminal I/O routines
include TED.INC
VT100 equ TRUE
;=======================================================================
; T E R M I N A L C O N T R O L M O D U L E
; (Link as first module)
public HOME,CLS,CLREOS,CLREOL,CSRUP,CSRDN,CSRLFT
public CSRRGT,PUTCUR,FWDIDX,REVIDX,INSLIN,DELLIN
public HASSRG,SCRLRG,TRMNAM
extrn PUTC
;--------------------------------------------------------------
cseg
; Display patch area
org 10h-3
if VT100
vtname: db 'VT100',0,0,0,0,0,0,0,0,0
vtsize: db 80,24 ; width, height
vclscr: db 6,ESC,'[H',ESC,'[J',0
vcleos: db 3,ESC,'[J',0,0,0,0
vcleol: db 3,ESC,'[K',0,0,0,0
vcurup: db 3,ESC,'[A',0,0,0,0
vcurdn: db 3,ESC,'[B',0,0,0,0
vcurrgt:db 3,ESC,'[C',0,0,0,0
vcurlft:db 3,ESC,'[D',0,0,0,0
vhome: db 3,ESC,'[H',0,0,0,0
vcurprf:db 2,ESC,'[',0,0,0,0,0
vcursep:db 1,';',0,0,0,0,0,0
vcurpst:db 1,'H',0,0,0,0,0,0
vcurbcd:db TRUE
vcuryof:db 1
vcurxof:db 1
vxfirst:db FALSE
vfwdidx:db 2,ESC,'D',0,0,0,0,0
vrevidx:db 2,ESC,'M',0,0,0,0,0
vinsln: db 0,0,0,0,0,0,0,0 ; VT220/240 only?
vdelln: db 0,0,0,0,0,0,0,0
vscrlrg:db 1,'r',0,0,0,0,0,0
else
vtname: db 'VT52',0,0,0,0,0,0,0,0,0,0
vtsize: db 80,24 ; width, height
vclscr: db 4,ESC,'H',ESC,'J',0,0,0
vcleos: db 2,ESC,'J',0,0,0,0,0
vcleol: db 2,ESC,'K',0,0,0,0,0
vcurup: db 2,ESC,'A',0,0,0,0,0
vcurdn: db 2,ESC,'B',0,0,0,0,0
vcurrgt:db 2,ESC,'C',0,0,0,0,0
vcurlft:db 2,ESC,'D',0,0,0,0,0
vhome: db 2,ESC,'H',0,0,0,0,0
vcurprf:db 2,ESC,'Y',0,0,0,0,0
vcursep:db 0,0,0,0,0,0,0,0
vcurpst:db 0,0,0,0,0,0,0,0
vcurbcd:db FALSE
vcuryof:db 32
vcurxof:db 32
vxfirst:db FALSE
vfwdidx:db 1,LF,0,0,0,0,0,0
vrevidx:db 2,ESC,'I',0,0,0,0,0
vinsln: db 0,0,0,0,0,0,0,0
vdelln: db 0,0,0,0,0,0,0,0
vscrlrg:db 0,0,0,0,0,0,0,0
endif
org 0B0h-3
;--------------------------------------------------------------
TRMNAM: ld hl,vtname
ret
CLS: push hl
ld hl,vclscr
jp pseq
CLREOS: push hl
ld hl,vcleos
jp pseq
CLREOL: push hl
ld hl,vcleol
jp pseq
HOME: push hl
ld hl,vhome
ld a,(hl)
or a
jp nz,pseq
ld hl,0
call PUTCUR
pop hl
ret
; H = x coord, L = y coord
PUTCUR: push hl
push de
push bc
if TRUE
ex de,hl
ld hl,(vcuryof) ; H = vcurxof, L = vcuryof
add hl,de ; should not generate any CY from L to H
ex de,hl
else
ld a,(vcurxof) ; this is the same as above, but takes
add a,h ; more bytes
ld d,a
ld a,(vcuryof)
add a,l
ld e,a
endif
ld a,(vxfirst)
or a
jr z,noswap
ld a,e
ld e,d
ld d,a
noswap: ld hl,vcurprf ; prefix
call putseq
ld c,e ; y coord
call pcurnum
ld hl,vcursep ; separator
call putseq
ld c,d ; x coord
call pcurnum
ld hl,vcurpst ; postfix
call putseq
pop bc
pop de
pop hl
ret
; H = bottom line, L = top line
SCRLRG: ld a,(vscrlrg)
or a
ret z
push hl
push de
push bc
if FALSE
ex de,hl
ld hl,(vcuryof) ; H = vcurxof, L = vcuryof
add hl,de ; should not generate any CY from L to H
ex de,hl
else
ld a,(vcurxof) ; this prevents carry from L to H
add a,h ; in case HL = -1 (reset region)
ld d,a
ld a,(vcuryof)
add a,l
ld e,a
endif
ld a,(vxfirst)
or a
jr z,noswp
ld a,e
ld e,d
ld d,a
noswp: ld hl,vcurprf ; prefix
call putseq
ld c,e ; y coord
call pcurnum
ld hl,vcursep ; separator
call putseq
ld c,d ; x coord
call pcurnum
ld hl,vscrlrg ; postfix
call putseq
pop bc
pop de
pop hl
ret
HASSRG: ld a,(vscrlrg)
or a ; return NZ if terminal supports scroll region
ret
pcurnum:ld a,(vcurbcd)
or a
ld a,c
jp z,PUTC
; fall thru
; Display A as decimal number (up to 3 digits, no leading zeros)
adec: push de
push bc
ld d,0
ld b,100
call ad1
ld b,10
call ad1
add a,'0'
call PUTC
pop bc
pop de
ret
ad1: ld c,'0'-1
ad2: inc c
sub b
jr nc,ad2
add a,b
push af
ld a,c
cp '0'
jr nz,ad4
inc d
dec d
jr z,ad5
ad4: call PUTC
ld d,1
ad5: pop af
ret
CSRUP: push hl
ld hl,vcurup
jr pseq
CSRDN: push hl
ld hl,vcurdn
jr pseq
CSRLFT: push hl
ld hl,vcurlft
jr pseq
CSRRGT: push hl
ld hl,vcurrgt
jr pseq
FWDIDX: push hl
ld hl,vfwdidx
jr pseq
REVIDX: push hl
ld hl,vrevidx
jr pseq
INSLIN: push hl
ld hl,vinsln
jr putseq
DELLIN: push hl
ld hl,vdelln
pseq: call putseq
pop hl
ret
putseq: ld a,(hl)
or a
ret z
push bc
ld b,a
inc hl
pseq1: ld a,(hl)
call PUTC
inc hl
djnz pseq1
pop bc
ret
end