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