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