Imported Upstream version 24.0
[rrq/maintain_lilo.git] / src / bitmap.S
1 ; bitmap.S
2 ;
3 ;  Copyright 2001-2005 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 ncol KEYTABLE+256+mt_ncol
12
13
14 ; menu_setup:
15 ;   main setup menu for LILO boot selection process
16 ;
17 ;   replaces code to load & display the message in second.S
18 ;
19 ;   exit with DS=ES=CS
20 ;
21 menu_setup:
22         pusha
23
24 ;;      BEG_FS
25 ;;      SEG_FS                  ! message disabled ?
26         cmp     word ptr par2_msg_len+SSDIFF,#0         ;MSG_OFF+SSDIFF,#0
27 ;;      END_FS
28         je      ms_do_find      ! yes -> skip this
29
30
31 ;BEG_FS
32 ;SEG_FS         ! load the message file
33         mov     cx,mt_msg+KEYTABLE+256                  ;MSG_OFF+SSDIFF+2
34 ;SEG_FS
35         mov     dx,mt_msg+2+KEYTABLE+256
36 ;SEG_FS
37         mov     al,mt_msg+4+KEYTABLE+256
38 ;END_FS
39         mov     bx,#MAP
40         call    sread
41         call    loadfile
42
43         push    #SYSSEG
44         pop     es
45         xor     bx,bx
46         push    es              ; save for later
47         push    bx
48
49         call    _display4       ; ES:BX points to the Message or BITMAP
50
51         pop     bx
52
53 ;;      BEG_FS
54 ;;      SEG_FS
55         xchg    bx,par2_msg_len+SSDIFF          ;MSG_OFF+SSDIFF
56 ;;      END_FS
57
58         cmp     ax,#1
59         jb      good_bitmap             ; AX==0, bitmap was displayed
60
61         pop     ds      
62         ja      ms_do_find              ; AX==2, 3, or 4; "BM" sig found, but
63                                         ; wrong bitmap or no VGA adapter
64                                         ; or no VESA support (4)
65
66         ; AX==1, no "BM" signature, assume "message"
67
68         mov     byte ptr (bx),#0
69         call    crlf
70         xor     bx,bx           ! display the message
71         call    say
72         jmp     ms_do_find
73 ;--------------------------------------------
74
75 good_bitmap:
76         pop     es
77         inc     word [suppress]
78         mov     word [abs_cx],#0x101    ; mark screen in use    
79
80
81 ms_do_find:
82         push    cs
83         pop     ds              ; make sure DS is good
84         xor     si,si           ; number of names
85         xor     di,di           ; max. name length
86         mov     cx,#IMAGES      ; get max number to search
87         mov     bx,#DESCR0      ; get address to start at
88 findl1: call    strlen          ; get length in ax
89         or      ax,ax
90         jz      findl3
91 #ifdef LCF_VIRTUAL
92         test    word ptr (bx+id_flags),#FLAG_VMDEFAULT
93         jz      findl1c
94         call    vmtest
95         jnc     findl1c
96         mov     [vimage],si
97 findl1c:
98 #endif
99 #ifdef LCF_NOKEYBOARD
100         test    word ptr (bx+id_flags),#FLAG_NOKBDEFAULT
101         jz      findl1d
102         call    kbtest
103         jc      findl1d
104         mov     [vimage],si
105 findl1d:
106 #endif
107         cmp     ax,di
108         jb      findl2
109         xchg    ax,di
110 findl2: add     bx,#id_size
111         inc     si
112         loop    findl1
113
114 findl3: mov     [nimage],si
115         mov     [limage],di
116 ;;;
117         mov     ax,si                   ; number of images
118         mov     bx,[ncol]               ; 
119         add     ax,bx
120         dec     ax
121         div     bl
122 ;MINROW = 4
123         cmp     al,[KEYTABLE+256+mt_mincol]
124         ja      row1
125         mov     al,[KEYTABLE+256+mt_mincol]
126 row1:
127         mov     bx,[KEYTABLE+256+mt_maxcol]     ;
128         cmp     al,bl
129         jbe     row2
130         xchg    ax,bx
131 row2:
132         mov     [nrow],al
133 ;;;
134         xor     ax,ax                   ;display the list of names
135         mov     cx,si
136 findl4: call    lowlite
137         inc     ax
138         loop    findl4
139         mov     ax,[dimage]             ; bug fix
140 #if defined(LCF_VIRTUAL) || defined(LCF_NOKEYBOARD)
141         test    byte ptr [cmdline],#0xFF
142         jnz     vdone3
143         mov     ax,[vimage]
144 vdone3:
145 #endif
146         call    hilite
147
148         push    cs
149         pop     es                      ; make sure ES is good on exit
150
151         popa
152         ret
153 ; end of menu_setup subroutine
154 #if DEBUG_NEW
155 no_bmp: .ascii  " = AL; NOT a bitmap file\n"
156         .byte   0
157 #endif
158
159
160 #if 0
161 ; find_image
162 ;       if there is something on the command line
163 ;       return the image number it selects
164 ;
165 ;       enter with:
166 ;               nothing
167 ;       exit with:
168 ;               If nothing selected:
169 ;                   Carry Clear
170 ;                   AX==0
171 ;               If an image is selected:
172 ;                   Carry SET
173 ;                   AX==#image
174 ;                   BX==pointer to descriptor
175 ;                   
176 ;
177 ;       side effect:
178 ;               The selected image is hi-lited if the menu is displayed
179 ;
180 find_image:
181         push    cx
182         push    si
183         push    di
184         
185         mov     cx,#IMAGES      ! test all names
186         mov     si,#DESCR0
187         push    si
188 fi_nextn:
189         mov     di,#cmdline
190 fi_nextc:
191         mov     al,(si)         ! get next character in descr
192                                 ! get the character
193 #ifdef LCF_IGNORECASE
194         call    upcase
195 #endif
196         mov     ah,al
197         mov     al,(di)         ! get next char in cmdline
198 #ifdef LCF_IGNORECASE
199         call    upcase
200 #endif
201         or      ah,ah           ! NUL in descriptor name
202         jz      fi_dscend
203         cmp     al,ah           ! character equal ?
204         jne     fi_skipn                ! no -> try next one
205         inc     si              ! test next character
206         inc     di
207         jmp     fi_nextc
208 fi_dscend:      
209         cmp     al,#32          ! space or NUL -> equal
210         je      fi_found
211         or      al,al
212         jz      fi_found
213
214 fi_skipn:
215         pop     si
216         add     si,#id_size     ! test next name
217         push    si
218         loop    fi_nextn
219
220         pop     si
221         xor     ax,ax           ; clears the carry
222 fi_exit:
223         pop     di
224         pop     si
225         pop     cx
226         ret
227         
228 fi_found:
229         pop     bx              ! BX is matched descriptor
230         mov     ax,bx
231         sub     ax,#DESCR0
232         mov     cl,#id_size
233         div     cl
234         cbw
235         mov     di,[dimage]
236         cmp     ax,di
237         je      fi_nochange
238         mov     [dimage],ax
239         cmp     byte [abs_cx+1],#0      ! see if menu is displayed
240         je      fi_nochange
241         xchg    ax,di
242         call    lowlite
243         xchg    ax,di
244         call    hilite
245 fi_nochange:
246         stc
247         jmp     fi_exit
248 #endif
249
250
251 ; menu_delline:
252 ;       delete the current command line
253 ;                               common code from original second.S
254 ;
255 ;       enter with:
256 ;               BX = command line pointer
257 ;
258 ;       exit with:
259 ;               BX = updated command line pointer
260 ;
261 ;
262 menu_delline:
263         cmp     bx,#cmdline     ! done ?
264         je      mdel9           ! yes -> done
265         push    bx              ! display BS,SPC,BS
266         mov     bx,#bs
267         call    say
268         pop     bx
269         dec     bx              ! move the pointer
270         jmp     menu_delline            ! next one
271 mdel9:  ret
272
273
274 ; menu_setcmd:
275 ;       set currently selected image to be the command line
276 ;
277 ;       enter with:
278 ;               AX = image# to select
279 ;               BX = cmdline pointer
280 ;
281 ;       exit with:
282 ;               BX = updated
283 ;
284 ;
285 menu_setcmd:
286         push    si
287
288         push    ax
289
290         call    menu_delline    ; delete the current line
291
292         pop     si              ; get image# back
293
294         imul    si,#id_size
295         add     si,#DESCR0
296 mset1:  lodsb
297         or      al,al
298         jz      mset6
299         mov     (bx),al
300         inc     bx
301         push    bx
302         call    display
303         pop     bx
304         jmp     mset1
305         
306 mset6:
307         pop     si      
308         ret
309
310
311 ; arrow
312 ;
313 ;   Code that handles the arrow keys:  left, up, down, right
314 ;
315 ;
316 arrow:  cbw                     ; signed delta vector in AL
317         mov     dx,[dimage]     ;
318         add     dx,ax           ; new position
319         or      dx,dx
320         jns     arr1
321 arr0:   xor     dx,dx           ; set to zero if neg.
322 arr1:   mov     ax,[nimage]
323         cmp     dx,ax           ; compare to max.
324         jb      arr2
325         mov     dx,ax
326         dec     dx
327 arr2:                   ; we know the one to hi-lite is in range
328         mov     ax,[dimage]
329         cmp     ax,dx
330         je      arr6
331
332         call    lowlite         ; un-hilite the old
333         xchg    ax,dx
334         call    hilite
335
336         call    menu_setcmd     ; set new command line
337 arr6:
338         jmp     arr_vector
339
340         
341 null:   mov     al,#1
342         cmp     ah,#0x50                ; down arrow
343         je      arrow
344
345         neg     al
346         cmp     ah,#0x48                ; up arrow
347         je      arrow
348
349         mov     dx,[nimage]
350         cmp     ah,#0x4f                ; end
351         je      arr1
352
353         cmp     ah,#0x47                ; home
354         je      arr0
355
356         mov     al,[nrow]
357         xchg    ax,dx
358         mov     ax,[dimage]
359         div     dl                      
360         xchg    ax,dx                   ; DL = cur col.
361
362         cmp     ah,#0x4d                ; right arrow
363         jne     arr8
364         inc     dx                      ; similar to  dec al
365         cmp     dl,[ncol]               ; cmp (CUR COL + 1) : (NCOL)
366         jb      arrow
367         jmp     arr9
368         
369 arr8:
370         cmp     ah,#0x49                ; pg up
371         jne     arr84
372         neg     dh                      ; remainder [0..(nrow-1)]
373         mov     al,dh
374 arrow1: jmp     arrow
375
376 arr84:
377         cmp     ah,#0x51                ; pg dn
378         jne     arr88
379         not     dh
380         add     al,dh
381         jmp     arrow
382
383 arr88:
384         neg     al
385         cmp     ah,#0x4b                ; left arrow
386         jne     arr9
387         or      dl,dl
388         jnz     arrow1
389
390 arr9:
391         cmp     ah,#0x53                ; DEL
392         jne     arr_vector
393         br      delch                   ; treat as 0177 (rubout)
394
395 arr_vector:
396         br      input           ; ignore the rest
397
398 ; menu_exit:
399 ;       erase the menu box to black
400 ;
401 menu_exit:
402         push    es
403         pusha
404 #if DEBUG_NEW
405         call    me1
406         .ascii  "menu_exit entered"
407         .byte   10,0
408 me1:    pop     bx
409         call    say
410 ;;      call    pause
411 #endif
412         xor     ax,ax
413         cmp     word [abs_cx],ax
414         mov     word [suppress],ax
415         mov     word [abs_cx],ax
416         je      mn_exit_ret
417         call    _done4
418 #if DEBUG_NEW
419         call    me2
420         .ascii  "called done4"
421         .byte   10,0
422 me2:    pop     bx
423         call    say
424 ;;      call    pause
425 #endif
426 mn_exit_ret:
427 #if DEBUG_NEW
428         call    me3
429         .ascii  "exit from menu_exit"
430         .byte   10,0
431 me3:    pop     bx
432         call    say
433 ;;      call    pause
434 #endif
435         popa
436         pop     es
437         ret
438
439 #if 0
440 ; menu_form_feed:
441 ;       simulate a FF on the console
442 ;
443 menu_form_feed:
444         ret
445 #endif
446
447 ; timer_display:
448 ;       check the timer 'cntdown' and display changes
449 ;
450 timer_display:
451         push    es
452         pusha
453
454         test    byte [KEYTABLE+256+mt_t_row+1],#0xff    ; see if not initialized
455         js      timer99
456
457         mov     dx,#0x2d2d      ; get "--" means disabled
458         mov     [tim_min],dx
459         mov     [tim_sec],dx
460         mov     ax,[cntdown]    ; get timer countdown location
461         cmp     ax,[tim_tick]
462         je      timer99
463         mov     [tim_tick],ax   ; save last tick count  
464         inc     ax
465         jz      timer8
466
467         mul     c55             ; get time remaining in ms.
468         div     c1000           ; convert to seconds
469         cmp     ax,[tim_old]    
470         je      timer99
471         mov     [tim_old],ax    ; save seconds remaining
472         xor     dx,dx
473         div     c60             ; minutes in AX, seconds in DX  
474         aam
475         add     ax,#0x3030
476         xchg    ah,al
477         mov     [tim_min],ax    ; put characters in buffer
478         xchg    ax,dx
479         aam
480         add     ax,#0x3030
481         xchg    ah,al
482         mov     [tim_sec],ax    ; put characters in buffer
483
484 timer8:
485         push    ds              ;sch-hi
486         push    #KEYTABLE+256+mt_t_fg
487         push    #5              ; len
488         push    ds              ; cp -hi
489         push    #tim_min
490         push    word [KEYTABLE+256+mt_t_row]
491         push    word [KEYTABLE+256+mt_t_col]
492         call    _text
493         add     sp,#14
494 timer99:
495         popa
496         pop     es
497         ret
498
499 tim_min: db     0,0
500         .ascii  ":"
501 tim_sec: db     0,0
502
503 tim_old:  dw    0               ; last # seconds
504 tim_tick: dw    0               ; last timer tick value examined
505
506 c55:    .word   2197            ;was 55, now 54.925*40
507 c1000:  .word   40000           ;was 1000, now 40*1000
508 c60:    .word   60
509
510
511
512 ; hilite/lowlite
513 ;       enter with:
514 ;               AX = number [0..(nimage-1)] of entry to hilite
515 ;
516 hilite:
517         push    es
518         pusha
519         mov     [dimage],ax             ;remember one hilited
520         push    cs
521         push    #KEYTABLE+256+mt_h_fg
522         jmp     lowlite1
523
524 lowlite:
525         push    es
526         pusha
527         push    cs                      ; sch hi
528         push    #KEYTABLE+256+mt_fg     ; sch low
529
530 lowlite1:
531         cmp     BYTE [abs_cx+1],#0
532         je      lowlite9
533
534         mov     bx,ax           ;save argument in BX
535         mov     al,#0x20        ; SP
536         mov     cx,[limage]
537         inc     cx
538         inc     cx
539         mov     di,#im_name
540         push    cx                      ; len
541         push    ds                      ; cp hi
542         push    di                      ; cp low
543
544         push    ds
545         pop     es
546         rep
547           stosb
548         imul    si,bx,#id_size
549         add     si,#DESCR0
550         mov     di,#im_name+1
551 lowlite2:
552         lodsb
553         or      al,al
554         jz      lowlite3
555         stosb
556         jmp     lowlite2
557 lowlite3:
558
559         mov     cx,[KEYTABLE+256+mt_col]
560         mov     ax,[KEYTABLE+256+mt_row]
561         mov     si,[nrow]
562 lowlite4:
563         cmp     bx,si
564         jb      lowlite5
565         add     cx,[KEYTABLE+256+mt_xpitch]
566         sub     bx,si
567         jmp     lowlite4
568 lowlite5:
569 #ifdef PIXADDRESS
570         shl     bx,#4           ;use pixel addressing
571 #endif
572         add     ax,bx
573         push    ax
574         push    cx
575         call    _text
576         add     sp,#10
577 lowlite9:
578         add     sp,#4
579         popa
580         pop     es
581         ret
582
583
584 im_name:  .blkb MAX_IMAGE_NAME+3
585
586         .even
587 dimage: dw      0       ; default image
588 #if defined(LCF_VIRTUAL) || defined(LCF_NOKEYBOARD)
589 vimage: dw      0       ; vmdefault image
590 #endif
591 nimage: dw      0       ; number of images
592 limage: dw      0       ; longest length of image name
593 nrow:   dw      0       ; number of rows of selections
594 ;nrow   equ     KEYTABLE+256+mt_maxcol
595 ;ncol:  dw      0       ; number of columns (default=2)
596 ;ncol   equ     KEYTABLE+256+mt_ncol
597 abs_cx: dw      0       ; upper left of scrolling area
598
599 ; end of bitmap.S