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 (%include e-macros)
33
34 (declare (special X Y screenheight screenlinelen ospeed given-tty-type))
35 (declare (special idel-lines-availablep idel-chars-availablep tty-type))
36 (declare (special DCTL-prologue-availablep DCTL-epilogue-availablep))
37 (declare (special region-scroll-availablep scroll-region-top scroll-region-bottom DCTL-insert-mode-on))
38 (declare (special DCTL-oflow-enabled))
39 (declare (array* (notype (screen ?))))
40 (declare (*expr DCTL-standard-set-modes Rprinc Rtyo))
41
42 (declare (defpl1 vt1xx_ctl_util_$re_enable_oflow ""))
43
44
45
46 (defun vt132p-escape macro (form)
47 (list 'Rprinc
48 (apply 'catenate
49 (cons (ItoC 33)
50 (cons "[" (cdr form))))))
51
52
53 (defun DCTL-outdec (n)
54 ((lambda (have-output)
55 (do digi '(1000. 100. 10. 1) (cdr digi) (null digi)
56 ((lambda (rem)
57 (cond ((or have-output (> rem 0) (= (car digi) 1))
58 (Rtyo (+ 60 rem))
59 (setq have-output t)))
60 (setq n (\ n (car digi))))
61 (// n (car digi)))))
62 nil))
63
64
65
66 (defun DCTL-pad (n)
67 (and (= ospeed 960.)
68 (DCTL-real-pad n)))
69
70
71
72 (defun DCTL-real-pad (n)
73 (or DCTL-oflow-enabled
74 (do-times (// (* n ospeed) 960.)
75 (Rtyo 0))))
76
77
78
79 (defun DCTL-init ()
80 (setq DCTL-prologue-availablep t DCTL-epilogue-availablep t)
81 (setq idel-lines-availablep t idel-chars-availablep t)
82 (setq region-scroll-availablep t)
83 (setq screenheight 24.)
84 (setq screenlinelen
85 (or (cdr (assq given-tty-type
86 '((vt132p . 131.) (vt132p_oflow . 131.)
87 (vt132p_80c . 79.) (vt132p_80c_oflow . 79.))))
88 131.))
89 (setq DCTL-oflow-enabled (memq given-tty-type '(vt132p_oflow vt132p_80c_oflow)))
90 (setq tty-type 'vt132p)
91 (DCTL-prologue)
92 (DCTL-home-cursor)
93 (DCTL-clear-rest-of-screen))
94
95
96 (defun DCTL-prologue ()
97 (Rtyo 33) (Rprinc "<") (DCTL-pad 20.)
98 (vt132p-escape "?4l")
99 (vt132p-escape "?6l")
100 (vt132p-escape "r")
101 (vt132p-escape "4h") (vt132p-escape "0q")
102 (vt132p-escape "20l")
103 (cond ((= screenlinelen 131.)
104 (vt132p-escape "?3h") (DCTL-pad 122.))
105 (t (vt132p-escape "?3l") (DCTL-pad 122.)))
106 (setq scroll-region-top 0 scroll-region-bottom (1- screenheight))
107 (setq DCTL-insert-mode-on nil)
108 (and DCTL-oflow-enabled (vt1xx_ctl_util_$re_enable_oflow)))
109
110
111
112 (defun DCTL-epilogue ()
113 (vt132p-escape "r")
114 (vt132p-escape "4h") (vt132p-escape "0q")
115 (setq DCTL-insert-mode-on nil))
116
117
118
119
120
121
122
123
124 (defun DCTL-position-cursor (x y)
125 (let ((deltax (- x X))
126 (deltay (- y Y)))
127 (cond ((= deltay 0)
128 (cond ((= deltax 0) nil)
129 ((> deltax 0)
130 (vt132p-escape)
131 (if (not (= deltax 1)) (DCTL-outdec deltax))
132 (Rprinc "C"))
133 (t (cond ((= x 0) (Rtyo 15))
134 ((< (- deltax) 4)
135 (do-times (- deltax) (Rtyo 10)))
136 (t (vt132p-escape)
137 (DCTL-outdec (- deltax))
138 (Rprinc "D"))))))
139 ((= deltax 0)
140
141 (cond ((or (and (> y scroll-region-bottom)
142 (not (> Y scroll-region-bottom)))
143 (and (< y scroll-region-top)
144 (not (< Y scroll-region-top))))
145 (vt132p-absolute-position x y))
146 ((> deltay 0)
147 (cond ((< deltay 4)
148 (do-times deltay (Rtyo 12)))
149 (t (vt132p-escape)
150 (DCTL-outdec deltay)
151 (Rprinc "B"))))
152 (t (cond ((= deltay -1)
153 (Rtyo 33) (Rprinc "M"))
154 (t (vt132p-escape)
155 (DCTL-outdec (- deltay))
156 (Rprinc "A"))))))
157 (t (vt132p-absolute-position x y)))
158 (setq X x Y y)))
159
160
161
162 (defun vt132p-absolute-position (x y)
163 (vt132p-escape)
164 (if (not (= y 0))
165 (DCTL-outdec (1+ y)))
166 (if (not (= x 0))
167 (Rprinc ";")
168 (DCTL-outdec (1+ x)))
169 (Rprinc "H"))
170
171
172
173 (defun DCTL-display-char-string (string)
174 ((lambda (strx)
175 (cond ((= strx 0))
176 (t (cond (DCTL-insert-mode-on
177 (setq DCTL-insert-mode-on nil)
178 (vt132p-escape "4h") (vt132p-escape "0q")))
179 (Rprinc string)
180 (setq X (+ X strx)))))
181 (stringlength string)))
182
183
184
185 (defun DCTL-home-cursor ()
186 (setq X 0 Y 0)
187 (vt132p-escape H))
188
189
190 (defun DCTL-clear-rest-of-screen ()
191 (vt132p-escape J) (DCTL-pad 45.))
192
193
194
195 (defun DCTL-kill-line ()
196 (vt132p-escape K) (DCTL-pad 2))
197
198
199
200
201 (defun DCTL-define-scroll-region (top bottom)
202 (cond ((and (= top scroll-region-top) (= bottom scroll-region-bottom)))
203 (t (setq scroll-region-top top scroll-region-bottom bottom)
204 (Rtyo 33) (Rprinc "7")
205 (Rtyo 33) (Rprinc "[")
206 (cond ((not (= top 0))
207 (DCTL-outdec (1+ top))))
208 (cond ((not (= bottom (1- screenheight)))
209 (Rprinc ";")
210 (DCTL-outdec (1+ bottom))))
211 (Rprinc "r")
212 (Rtyo 33) (Rprinc "8"))))
213
214
215
216 (defun DCTL-insert-lines (n)
217 (DCTL-scroll-down-region n (1- screenheight)))
218
219
220
221 (defun DCTL-delete-lines (n)
222 (DCTL-scroll-up-region n (1- screenheight)))
223
224
225
226 (defun DCTL-scroll-up-region (nlines bottom)
227 (DCTL-define-scroll-region Y bottom)
228 (let ((oldy Y))
229 (Rtyo 33) (Rprinc "7")
230 (DCTL-position-cursor 0 bottom)
231 (do-times nlines
232 (Rtyo 12) (DCTL-pad 30.))
233 (Rtyo 33) (Rprinc "8")
234 (setq Y oldy)))
235
236
237 (defun DCTL-scroll-down-region (nlines bottom)
238 (DCTL-define-scroll-region Y bottom)
239 (do-times nlines
240 (Rtyo 33) (Rprinc 'M) (DCTL-pad 30.)))
241
242
243
244 (defun DCTL-insert-char-string (string)
245 (cond (DCTL-insert-mode-on)
246 (t
247 (setq DCTL-insert-mode-on t)
248 (vt132p-escape "4l") (vt132p-escape "3q")))
249 (cond ((or (> X 2) (= screenlinelen 79.))
250 (Rprinc string))
251 (t
252 ((lambda (X extra)
253 (Rprinc string) (Rprinc extra)
254 (setq X (+ X (stringlength string) (stringlength extra)))
255 (DCTL-position-cursor (- X (stringlength extra)) Y))
256 X
257 (substr (cadr (screen Y)) (1+ X) (- 3 X)))))
258 (setq X (+ X (stringlength string))))
259
260
261
262 (defun DCTL-delete-chars (n)
263 (vt132p-escape)
264 (and (> n 1) (DCTL-outdec n))
265 (Rprinc "P"))
266
267
268
269 (putprop 'DCTL-standard-set-modes (get 'e_pl1_$set_emacs_tty_modes 'subr) 'subr)
270
271 (defun e_pl1_$set_emacs_tty_modes ()
272 (DCTL-standard-set-modes)
273 (and DCTL-oflow-enabled (vt1xx_ctl_util_$re_enable_oflow)))
274
275 (setq DCTL-oflow-enabled nil)
276
277
278
279 (cond ((status feature Emacs)
280 (load (list (car (namelist (truename infile))) "vt1xx_keys_"))))