Add dependency to perl-modules
[rrq/maintain_lilo.git] / src / menu.S
1 #if 0
2 ; menu.S  is
3 Copyright 2000-2004 John Coffman.
4 All rights reserved.
5
6 Licensed under the terms contained in the file 'COPYING' in the 
7 source directory.
8
9 #endif
10 #define PAGE0
11 ;
12 ; mn_init:
13 ;       enter with nothing
14 ;
15 ;       return with:
16 ;               AH = #columns
17 ;               AL = video mode
18 ;               BH = active page
19 ;               CH = rows-1
20 ;               CL = cols-1
21 ;
22 ;       side effects:
23 ;               If video mode 7 (MDA) is detected, the default attributes
24 ;               are modified to those suitable for monochrome
25 ;
26 mn_init:
27         mov     ah,#0x0f
28         int     0x10            ; AH=cols, AL=mode, BH=page
29         mov     ch,#0x18
30         cmp     al,#7
31         je      mn_imono        ; MDA does not use 40:84
32         push    ds
33         push    #0x40
34         pop     ds
35         mov     ch,[0x84]       ; get rows-1
36         pop     ds
37 mn_imono:
38         mov     cl,ah
39         dec     cl              ; CL=cols-1
40 #ifndef PAGE0
41         mov     [mn_page],bh    ; save page
42 #endif
43         mov     [mn_max_row_col],cx     ; save max screen coord.
44         cmp     al,#7           ; test for monochrome
45         jne     mn_init9
46         push    dword [mn_at_mono]      ; move 4 bytes
47         pop     dword [mn_attrib]
48 mn_init9:
49         ret
50
51 ; mn_getcursor:
52 ;       exit with:
53 ;               DX = current cursor position
54 ;
55 mn_getcursor:
56         push    ax
57         push    bx
58         push    cx
59         mov     ah,#3
60 #ifndef PAGE0
61         mov     bh,[mn_page]
62 #else
63         xor     bh,bh
64 #endif
65         int     0x10
66         pop     cx
67         pop     bx
68         pop     ax
69         ret
70
71 ; mn_setcursor:
72 ;
73 ;       enter with:
74 ;               DX = row/col for cursor
75 ;
76 mn_setcursor:
77         push    ax
78         push    bx
79         mov     ah,#2
80 #ifndef PAGE0
81         mov     bh,[mn_page]
82 #else
83         xor     bh,bh
84 #endif
85         int     0x10
86         pop     bx
87         pop     ax
88         ret
89
90 ; mn_cursoroff:
91 ;
92 mn_cursoroff:
93         push    dx
94         mov     dx,[mn_max_row_col]
95         inc     dh
96         xor     dl,dl
97         call    mn_setcursor
98         pop     dx
99         ret
100
101 ; mn_rdcha:  read character and attribute
102 ;       enter with:
103 ;               DX = row/col
104 ;
105 ;       exit with:
106 ;               AH = attribute
107 ;               AL = character
108 ;
109 mn_rdcha:
110         push    bx
111         mov     ah,#2           ;set cursor position
112 #ifndef PAGE0
113         mov     bh,[mn_page]
114 #else
115         xor     bh,bh
116 #endif
117         int     0x10
118         mov     ah,#8           ; read char and attr
119         int     0x10
120         pop     bx
121         ret
122
123 ; mn_wrcha:  write character and attribute
124 ;       enter with:
125 ;               AH = attribute
126 ;               AL = character
127 ;               DX = row/col
128 ;       
129 mn_wrcha:
130         push    cx
131         push    bx
132         push    ax
133         mov     ah,#2
134 #ifndef PAGE0
135         mov     bh,[mn_page]
136 #else
137         xor     bh,bh
138 #endif
139         int     0x10    ; set cursor position
140         pop     ax
141         push    ax
142         mov     bl,ah
143         mov     cx,#1
144         mov     ah,#9
145         int     0x10
146         pop     ax
147         pop     bx
148         pop     cx
149         ret
150
151 ; mn_wrstra:  write string with attribute
152 ;       enter with:
153 ;               AL = attribute
154 ;               DS:BX points at string
155 ;               DX = row/col of start
156 ;
157 mn_wrstra:
158         push    ax
159         push    bx
160         push    dx
161         mov     ah,al
162 mn_wrs1:
163         mov     al,(bx)
164         inc     bx
165         or      al,al
166         jz      mn_wrs9
167         call    mn_wrcha
168         inc     dl
169         jmp     mn_wrs1
170 mn_wrs9:
171         pop     dx
172         pop     bx
173         pop     ax
174         ret
175         
176 ; mn_drawbox:
177 ;       enter with:
178 ;               AL =    0 no border
179 ;                       1 single border
180 ;                       2 double border
181 ;                       3 single top/bot, double sides
182 ;                       4 double top/bot, single sides
183 ;          (if hi-bit of AL is set, expand box by 1 in horizontal)
184 ;               BH = attribute for area
185 ;               CX = row/col of upper left
186 ;               DX = delta row/delta col
187 ;
188 mn_drawbox:
189         push    dx
190         push    cx
191         push    ax
192         or      al,al
193         jns     mn_dr01
194         dec     cl
195         inc     dl
196         inc     dl
197 mn_dr01:
198         mov     ax,#0x0600
199         add     dx,cx
200         int     0x10
201         pop     ax
202         pop     cx
203         pop     dx
204         test    al,#0x7F
205         jz      mn_dr9
206
207         push    ax
208         push    si
209         and     ax,#0x7F
210         mov     si,ax
211         shl     si,#3
212         lea     si,[mn_box-8](si)
213
214         mov     ah,[mn_at_border]
215         xchg    dx,cx
216
217         push    cx
218
219         lodsb
220 mn_dr1: call    mn_wrcha
221         inc     dl
222         dec     cl
223         mov     al,(si)
224         jnz     mn_dr1
225
226         inc     si
227         lodsb
228 mn_dr2: call    mn_wrcha
229         inc     dh
230         dec     ch
231         mov     al,(si)
232         jnz     mn_dr2
233
234         pop     cx
235         push    cx
236         inc     si
237         lodsb
238 mn_dr3: call    mn_wrcha
239         dec     dl
240         dec     cl
241         mov     al,(si)
242         jnz     mn_dr3
243
244         inc     si
245         lodsb
246 mn_dr4: call    mn_wrcha
247         dec     dh
248         dec     ch
249         mov     al,(si)
250         jnz     mn_dr4
251
252         pop     cx
253         xchg    cx,dx
254         
255         pop     si
256         pop     ax
257
258 mn_dr9: ret
259
260 ; mn_vline:  vertical line
261 ;
262 ;       enter with:
263 ;               AL = 1 (single line), 2 (double line)
264 ;               CX = row/col to start
265 ;               DH = delta Y
266 ;
267 mn_vline:
268         pusha
269         cbw
270         mov     si,ax
271         mov     bl,[mn_ver-1](si)
272         shl     si,#3
273         lea     si,[mn_vint-8](si)
274         mov     di,#0x100
275         xchg    cx,dx
276         mov     cl,ch
277         jmp     mn_line00       ; join common code
278
279
280
281 ; mn_hline:  horizontal line
282 ;
283 ;       enter with:
284 ;               AL = 1 (single line), 2 (double line)
285 ;               CX = row/col to start
286 ;               DL = delta X
287 ;
288 mn_hline:
289         pusha
290         cbw
291         mov     si,ax
292         mov     bl,[mn_hor-1](si)       ; BL is char to write
293         shl     si,#3
294         lea     si,[mn_hint-8](si)      ; SI is intersect table
295         mov     di,#1
296         xchg    cx,dx
297 ; do the beginning of the line
298 mn_line00:
299         call    mn_rdcha
300         mov     ah,bl           ; AH is char to write
301         cmp     al,(si)         ; know intersect?
302         jne     mn_line01
303         mov     ah,[1](si)
304 mn_line01:
305         cmp     al,[4](si)
306         jne     mn_line02
307         mov     ah,[5](si)
308 mn_line02:
309         mov     al,ah
310         mov     ah,[mn_at_border]
311         call    mn_wrcha
312         add     dx,di
313         dec     cl
314         jz      mn_line20
315
316 mn_line10:              ;do the central part of the line
317         call    mn_rdcha
318         mov     ah,bl
319         cmp     al,(si)
320         jne     mn_line11
321         mov     ah,[2](si)
322 mn_line11:
323         cmp     al,[4](si)
324         jne     mn_line12
325         mov     ah,[6](si)
326 mn_line12:
327         mov     al,ah
328         mov     ah,[mn_at_border]
329         call    mn_wrcha
330         add     dx,di
331         dec     cl
332         jnz     mn_line10
333
334 mn_line20:              ;do the end of the line
335         call    mn_rdcha
336         mov     ah,bl
337         cmp     al,(si)
338         jne     mn_line21
339         mov     ah,[3](si)
340 mn_line21:
341         cmp     al,[4](si)
342         jne     mn_line22
343         mov     ah,[7](si)
344 mn_line22:
345         mov     al,ah
346         mov     ah,[mn_at_border]
347         call    mn_wrcha
348
349         popa
350         ret
351
352 mn_box: db      SE,EW,SW,NS,NW,EW,NE,NS
353         db      SSEE,EEWW,SSWW,NNSS,NNWW,EEWW,NNEE,NNSS
354         db      SSE,EW,SSW,NNSS,NNW,EW,NNE,NNSS
355         db      SEE,EEWW,SWW,NS,NWW,EEWW,NEE,NS
356
357 mn_hor: db      EW,EEWW
358 mn_hint:  db    NS,NSE,NSEW,NSW
359         db      NNSS,NNSSE,NNSSEW,NNSSW
360         db      NS,NSEE,NSEEWW,NSWW
361         db      NNSS,NNSSEE,NNSSEEWW,NNSSWW
362
363 mn_ver: db      NS,NNSS
364 mn_vint:  db    EW,SEW,NSEW,NEW
365         db      EEWW,SEEWW,NSEEWW,NEEWW
366         db      EW,SSEW,NNSSEW,NNEW
367         db      EEWW,SSEEWW,NNSSEEWW,NNEEWW
368
369 mn_attrib:
370 mn_at_text:     db      0x47
371 mn_at_hilite:   db      0x71
372 mn_at_border:   db      0x47
373 mn_at_title:    db      0x4E
374
375 mn_at_mono:     db      0x07,0x70,0x07,0x0F
376 #ifndef PAGE0
377 mn_page:        db      0
378 #endif
379 mn_max_row_col: dw      0
380
381 ; end of menu.S
382