Imported Upstream version 24.0
[rrq/maintain_lilo.git] / src / display4.S
1 ;  display4.S
2 ;
3 ;  Copyright 2001-2005 John Coffman
4 ;  Copyright 2009-2013 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 ;
12 ;       Static Name Aliases
13 ;
14 ;;        segment _TEXT PARA class=CODE
15         .text
16
17 /* the following is set to 1 to test the fallback to TEXT mode */
18 #define FAIL    0
19
20         .even           ; 8
21
22 _bmp:   dd      0
23 _tp:    dd      0
24 _state: dw    -1
25 _Mode:  dw      0
26 _ypitch: dw     0
27 _shift: dw      0
28 _mask:  dd      0
29 _himask: dd     0
30 _VesaWindow:    dw      -1
31 _seg:   dw      0
32
33
34 ;
35 ;       get a single byte in AX (zero extended)
36 ;       and increment the HUGE pointer _tp
37 ;
38 ;       c = *tp++;
39 ;
40 ;
41         .even           ;   8
42 getbyte:
43         lodsb
44         push    ax
45         cmp     si,#1
46         sbb     ax,ax
47         and     ax,#0x1000
48         add     bp,ax
49         mov     ds,bp
50         pop     ax
51         sub     ah,ah
52         ret
53
54
55         .even           ;   4
56
57 d4_getrow4:
58         pusha
59         push    ds
60
61 ;       rpt = -8                ; bh
62 ;       repeat = -10            ; bl
63 ;       skip = -12              ; dh
64 ;       lp = -4                 ; es:di
65 ;       c = -6
66 ;       npix = DX               ; cx
67 ;       compr = AX
68 ;       tp was _tp              ; ds:si -- HUGE ptr  [bp:si]
69
70         mov     di,#_line       ;lp
71         push    cs
72         pop     es
73         seg     cs
74           lds     si,[_tp]        ;
75         mov     cx,dx           ;npix
76         cmp     ax,#1           ;compr
77         mov     bp,ds           ;
78         ja      d4_I600
79         je      d4_I601
80 d4_FC581:
81         call    getbyte
82         push    ax
83         sar     ax,#4
84         stosb                   ;*lp++
85         pop     ax
86         dec     cx      ;npix
87         and     al,#15  ;000fH
88         stosb                   ;*lp++
89         loop    d4_FC581
90         jmp     d4_I601
91 ;
92 ; compr == 2
93 ;        
94 d4_FC590:
95         cmp     cx,#0   ;npix
96         jle     d4_FB591
97         call    getbyte
98         mov     bh,al           ;rpt
99         mov     bl,al           ;repeat
100         or      ax,ax
101         je      d4_L676
102         sub     cx,ax   ;npix
103         call    getbyte
104         jmp     d4_L675
105 d4_FC594:
106         push    ax
107         sar     ax,#4
108         stosb                   ;*lp++
109         pop     ax
110         dec     bh      ; 2001/06/23
111         jz      d4_L676 ; 2001/06/23
112         push    ax
113         and     al,#15  ;000fH
114         stosb                   ;*lp++
115         pop     ax
116         dec     bh      ;rpt 2001/06/23
117 d4_L675:
118         or      bh,bh   ;rpt
119         jne     d4_FC594
120 d4_L676:
121         or      bl,bl   ;repeat
122         jne     d4_FC590
123 d4_FB591:
124         jcxz    d4_I600   ;npix
125         call    getbyte
126         mov     bh,al   ;rpt
127         sub     cx,ax   ;npix
128         mov     dh,al
129         inc     dh      ; 2001/06/23
130         and     dh,#2    ;skip
131         jmp     d4_L677
132 d4_FC598:
133         call    getbyte
134         push    ax
135         sar     ax,#4
136         stosb                   ;*lp++
137         pop     ax
138         dec     bh      ;rpt 2001/06/23
139         jz      d4_L678 ; 2001/06/23
140         and     al,#15  ;000fH
141         stosb                   ;*lp++
142         dec     bh      ;rpt 2001/06/23
143 d4_L677:
144         cmp     bh,#0   ;rpt
145         jne     d4_FC598
146 d4_L678:
147         or      dh,dh   ;skip
148         je      d4_I600
149         call    getbyte
150 d4_I600:
151         mov     bl,#1   ;repeat
152         cmp     cx,#0   ;npix
153         jg      d4_L676
154         call    getbyte
155         call    getbyte
156 ;;;     jmp     d4_I601
157
158 d4_I601:
159         seg     cs
160           mov     [_tp],si        ;
161         seg     cs
162           mov     [_tp+2],ds      ;
163         pop     ds
164         popa
165         ret     
166
167
168         .even           ;   4
169 d4_char10:
170         enter   #6,#0
171         pusha
172         push    ds
173
174 ;       buf =  0xA000:DI
175 ;       cgen =  ES:SI
176 ;       bits =  ax on top of stack
177 ;       points  (bp-2)
178 ;       shadow  (bp-4)
179 ;       mask    (bp-6)
180
181 ;       sch     (bp+4)  (arg);  DS:BX
182 ;       y =     BX      (arg)
183 ;       x =     DX      (arg)
184 ;       c =     AX      (arg)
185
186         push    WORD #0
187         pop     ds
188         mov     cx,WORD [0x485] ;points
189         xor     ah,ah           ;AL is char to put out
190         mov     WORD (bp-2),cx  ;points
191         imul    ax,cx           ;leave DX alone; 386 form of instruction
192         mov     si,#268 ;010cH  ; int 0x43 -> character bitmaps
193         add     ax,WORD (si)
194         mov     es,WORD (si+2)  ;cgen
195         xchg    si,ax           ;cgen
196
197 ;  call pixadr -----------------------------------
198         mov     cx,dx           ;x
199         and     cx,#7           ;mask for shift
200         sar     dx,#3           ;x
201         mov     ax,#0x00FF      ;mask
202
203         imul    di,bx,#640/8    ; DI = y * _ypitch
204         ror     ax,cl           ;AL is mask, AH is hi-mask
205         add     di,dx           ; + x
206         mov     WORD (bp-6),ax  ;save mask
207 ;-------------------------------------------------
208         mov     WORD (bp-4),#0  ;shadow
209         mov     dx,#0x03CE      ;
210         lds     bx,(bp+4)       ;sch
211 d4_FC527:
212         seg     es
213           lodsb           ;cgen -> bits
214         push    es
215         sub     ah,ah
216         push    WORD #0xA000
217         ror     ax,cl   ;rotated bits in AX
218         pop     es
219         push    ax      ;save AX rotated bits
220
221         not     ax
222         and     ax,WORD (bp-6)  ;mask complement
223         push    ax
224
225         mov     ah,BYTE (bx+2)  ;sch->bg
226         cmp     BYTE (bx),ah    ;sch->fg
227         pop     ax              ; inserted ****
228         je      d4_I529
229
230         push    ax              ;AH = bits high; AL = bits low
231         mov     ah,al           ;AH = bits low
232         mov     al,#08
233         out     dx,ax
234         mov     ah,BYTE (bx+2)  ;sch->bg
235         seg     es
236           and   BYTE (di),ah    ;buf
237         pop     ax              ; get complemented bits back
238         jcxz    d4_I529
239
240         mov     al,#08          ;AH = ~bits hi, AL = 8
241         out     dx,ax
242         mov     al,BYTE (bx+2)  ;sch->bg
243         seg     es
244           and   BYTE (di+1),al    ;buf
245         
246 d4_I529:        ; rotated bits in the stack
247         mov     al,BYTE (bx+4)  ;sch->sh
248         cmp     BYTE (bx),al    ;sch->fg
249         je      d4_I530
250         mov     ax,WORD (bp-4)  ;get shadow
251         rol     ax,#7           ;       
252         push    ax
253         mov     al,#8
254         out     dx,ax
255         mov     ah,BYTE (bx+4)  ;sch->sh
256         seg     es
257           and   BYTE (di),ah
258         pop     ax
259         jcxz    d4_I530
260
261         xchg    ah,al
262         mov     al,#8
263         out     dx,ax
264         mov     ah,BYTE (bx+4)  ;sch->sh
265         seg     es
266           and   BYTE (di+1),ah
267         
268 d4_I530:
269         pop     ax              ;rotated bits
270         mov     WORD (bp-4),ax  ; save shadow
271
272         push    ax
273         mov     ah,al
274         mov     al,#8
275         out     dx,ax
276         mov     al,BYTE (bx)    ;sch->fg
277         seg     es
278           and   BYTE (di),al
279         pop     ax
280         jcxz    d4_I531
281
282         mov     al,#8
283         out     dx,ax
284         mov     al,BYTE (bx)    ;sch->fg
285         seg     es
286           and   BYTE (di+1),al
287
288 d4_I531:
289         add     di,#640/8        ;buf
290         pop     es
291         dec     WORD (bp-2)
292         jne     d4_FC527
293
294 d4_EX519:
295         pop     ds
296         popa
297         leave
298         ret     
299
300
301         .even           ;   4
302 _text:
303         push    bp
304         mov     bp,sp
305         push    ds
306
307 ;       sch = 14
308 ;       len = 12
309 ;       cp = 8
310 ;       ypos = 6
311 ;       xpos = 4
312         mov     ax,#2
313         call    d4_setstate
314         mov     cx,WORD (bp+12) ;len
315         mov     bx,WORD (bp+6)  ;ypos
316         mov     dx,WORD (bp+4)  ;xpos
317 #ifndef PIXADDRESS
318         shl     bx,#4            ;ypos
319         shl     dx,#3            ;xpos
320 #endif
321         lds     si,(bp+8)       ;cp
322         jcxz    d4_L672
323         push    WORD (bp+16)
324         push    WORD (bp+14)    ;sch
325 d4_FC544:
326         lodsb                   ;*cp
327         seg cs
328           cmp   WORD [_Mode],#0x12
329         jbe     d4_tVga
330         call    d4_char256
331         jmp     d4_tCont
332 d4_tVga:
333         call    d4_char10
334 d4_tCont:
335         add     dx,#8   ;xpos
336         loop    d4_FC544
337         add     sp,#4
338 d4_L672:
339         xor     ax,ax
340         call    d4_setstate
341         pop     ds
342         leave   
343         ret     
344
345 #if 0
346         .even           ;   4
347
348 _setpalette:
349         push    bp
350         mov     bp,sp
351 ;       blue = 10
352 ;       green = 8
353 ;       red = 6
354 ;       color = 4
355
356         push    bx
357         mov     bh,bl
358         mov     ax,#0x1000
359         int     0x10
360
361         mov     bx,#0x3fff      ;00ffH
362         mov     al,dh
363         mul     bh
364         div     bl
365         mov     dh,al
366         xor     dl,dl
367
368         mov     al,ch
369         mul     bh
370         div     bl
371         mov     ch,al
372
373         mov     al,cl
374         mul     bh
375         div     bl
376         mov     cl,al
377
378         pop     bx              ;color
379         mov     ax,#0x1010
380         int     0x10
381         leave   
382         ret     
383 #endif
384
385
386         .even           ;   4
387 d4_putrow4:
388         pusha
389         push    ds
390
391 ;       mask = -2
392 ;       lp = -6
393 ;       tp = -10
394 ;       vp = -14
395 ;       vvp = -18
396 ;       i = -20
397 ;       nn = -22
398 ;       x2 = 8
399 ;       x1 = 6          ; DX
400 ;       y = 4           ; AX
401         push    ax      ;y
402         push    dx      ;x2-x1+1
403
404 ;begin pack4
405         push    ds
406         pop     es
407         mov     si,#_line
408         mov     di,si   ;op = lp
409         mov     ah,#640/8        ; npix/8
410 d4_FC185:
411         mov     cx,#8
412 d4_F187:
413         seg     es
414           lodsb
415         shr     al,#1
416         rcl     bl,#1    ;a
417         shr     al,#1
418         rcl     bh,#1    ;b
419         shr     al,#1
420         rcl     dl,#1    ;c
421         shr     al,#1
422         rcl     dh,#1    ;d
423         loop    d4_F187
424         mov     al,bl   ;a
425         stosb
426         mov     al,bh   ;b
427         stosb
428         mov     al,dl   ;c
429         stosb
430         mov     al,dh   ;d
431         stosb
432         dec     ah
433         jne     d4_FC185
434 d4_EX175:
435 ; end pack4
436
437         pop     bx
438         sar     bx,#3            ;nn
439         pop     di              ;y
440 ;;      imul    WORD [_ypitch]
441         imul    di,#640/8
442         push    WORD #0xA000
443         pop     es
444         mov     si,#_line       ;lp
445         mov     ax,#0x0102       ;mask
446 d4_FC563:
447         mov     dx,#964 ;03c4H
448         out     dx,ax
449         push    di
450         push    si
451         mov     cx,bx           ;nn
452         push    ax                      ;mask
453 d4_FC566:
454         lodsb
455         seg     es
456           and   BYTE (di),al
457         add     si,#3   ;tp
458         inc     di      ;vp
459         loop    d4_FC566
460
461         pop     ax              ;mask
462         pop     si
463         pop     di
464         shl     ah,#1
465         inc     si              ;lp
466         test    ah,#15          ;000fH
467         jne     d4_FC563
468
469         pop     ds
470         popa
471         ret     
472
473         .even           ;   4
474 d4_setstate:
475         push    ds
476
477         push    cs
478         pop     ds
479 #if 0
480         pusha
481         call    wout
482         call    ss1
483         .ascii  " = AX; setstate entered"
484         .byte   10,0
485 ss1:    pop     bx
486         call    say
487 ;;      call    pause
488         popa
489 #endif
490         cmp     WORD [_Mode],#0x12
491         ja      d4_SB497                ;setstate is a NOP if VESA
492
493 ;       new = 4
494         mov     dx,#974 ;03ceH
495         cmp     ax,WORD [_state]
496         je      d4_SB497
497         mov     WORD [_state],ax
498         dec     ax
499         je      d4_SC502
500         dec     ax
501         je      d4_SC503
502
503 ; state 0
504         push    dx
505         mov     ax,#3842        ;0f02H
506         mov     dx,#964 ;03c4H
507         out     dx,ax
508
509         pop     dx
510         mov     ax,#5    ;0005H
511         out     dx,ax
512
513         mov     ax,#3847        ;0f07H
514         jmp     d4_L669
515
516 ; state 1
517 d4_SC502:
518         mov     ax,#2053        ;0805H
519         jmp     d4_L670
520
521 ;  state 2
522 d4_SC503:
523         mov     ax,#2565        ;0a05H
524 d4_L670:
525         out     dx,ax
526         mov     ax,#7
527 d4_L669:
528         out     dx,ax
529         mov     ax,#3
530         out     dx,ax
531         mov     ax,#-248        ;ff08H
532         out     dx,ax
533 d4_SB497:
534 #if 0
535         pusha
536         call    ss2
537         .ascii  "setstate exit"
538         .byte   10,0
539 ss2:    pop     bx
540         call    say
541 ;;      call    pause
542         popa
543 #endif
544         pop     ds
545         ret     
546
547         .even           ;   4
548 ;
549 ;  _display4:   display the BITMAP
550 ;
551 ;  Enter with:  ES:BX points to the possible bitmap image
552 ;               DS==CS
553 ;
554 ;  Exit with:
555 ;       Carry Clear     - bitmap was displayed
556 ;       AX = 0
557 ;
558 ;       Carry Set       - error occurred
559 ;       AX = 1          "BM" signature not found
560 ;       AX = 2          not VGA adapter or display
561 ;       AX = 3          not 640x480x16 bitmap
562 ;       AX = 4          no VESA support
563 ;
564 _display4:
565 ; Line 286
566         enter   #22,#0
567         push    si
568         push    di
569
570 ;       bits = -2
571 ;       colors = -6
572 ;       i = -8
573 ;       disable = -10
574 ;       color = -14
575 ;       bmfh = -18
576 ;       bmh = -22
577 ;       name = 4
578 ; Line 296
579         mov     WORD [_bmp],bx  ;store for later
580         mov     WORD [_bmp+2],es
581 ;;;     les     bx,[_bmp]
582         mov     WORD (bp-18),bx ;bmfh
583         mov     WORD (bp-16),es
584         seg     es
585           cmp   WORD (bx),#19778        ;4d42H
586         jne     d4_I573
587         seg     es
588           cmp   WORD (bx+14+2),#0       ; hi-order part of DWORD
589         jne     d4_I573
590         seg     es
591           cmp   WORD (bx+14),#40        ; Windows bitmap header
592         je      d4_I574
593         seg     es
594           cmp   WORD (bx+14),#12        ; OS2 bitmap header (obsolete)
595         je      d4_I574
596 ; Line 297
597 d4_I573:
598         mov     ax,#1
599         stc
600         br      _display4_ret
601
602 d4_I574:
603         mov     ax,WORD [_bmp]
604         mov     dx,WORD [_bmp+2]
605         add     ax,#14  ;000eH
606 ;;      sbb     cx,cx
607 ;;      and     cx,#0x1000
608 ;;      add     dx,cx
609         mov     WORD [_tp],ax
610         mov     WORD [_tp+2],dx
611         mov     WORD (bp-22),ax ;bmh
612         mov     WORD (bp-20),dx
613 ; Line 302
614         mov     es,dx
615         mov     bx,ax
616         seg     es
617           cmp   BYTE (bx),#40           ; Windows
618         je      d4_I575
619
620 ;  OS2 bitmaps (obselete)
621         seg     es
622           mov   ax,WORD (bx+8)
623         seg     es
624           mul   WORD (bx+10)
625         mov     WORD (bp-2),ax  ;bits
626 ; Line 305
627         mov     cx,ax
628         mov     ax,#1
629         shl     ax,cl
630         cwd     
631         mov     WORD (bp-6),ax  ;colors
632 ; Line 317
633         seg     es
634           cmp   WORD (bx+4),#640        ;0280H
635         jne     d4_I576
636         seg     es
637           cmp   WORD (bx+6),#480        ;01e0H
638         jne     d4_I576
639
640         cmp     cx,#8   ;bits
641         je      d4_Vesa_Setup
642
643         cmp     cx,#4   ;bits
644         jne     d4_I576
645         jmp     d4_I575a
646
647 ; Windows bitmaps
648 d4_I575:
649         seg     es
650           mov   ax,WORD (bx+12)
651         seg     es
652           mul   WORD (bx+14)
653         mov     WORD (bp-2),ax  ;bits
654 ; Line 305
655         mov     cx,ax
656         mov     ax,#1
657         shl     ax,cl
658         cwd     
659         mov     WORD (bp-6),ax  ;colors
660 ; Line 317
661         seg     es
662 ;;;       cmp   DWORD (bx+4),#640       ;0280H
663           cmp   WORD (bx+4),#640        ;0280H
664         jne     d4_I576
665         seg     es
666 ;;;       cmp   DWORD (bx+8),#480       ;01e0H
667           cmp   WORD (bx+8),#480        ;01e0H
668         jne     d4_I576
669
670         cmp     cx,#8   ;bits
671         je      d4_Vesa_Setup
672
673         cmp     cx,#4   ;bits
674         jne     d4_I576
675 d4_I575a:
676         mov     WORD [_Mode],#18        ;0012H
677 ;;      mov     cx,#8
678 ;;      cwd     
679 ;;      idiv    cx
680 ;;      mov     WORD [_ypitch],ax
681 ; Line 318
682         br      d4_I577
683
684 d4_I576:
685 ; Line 319
686         mov     ax,#3
687         stc
688         br      _display4_ret
689
690
691 d4_Vesa_Setup:
692         mov     WORD [_Mode],#0x101     ; 640x480x256
693
694         mov     di,#MAP                 ; ES:DI -> 512 byte buffer
695         mov     DWORD (di),#SIG_VBE2    ; "VBE2"
696         mov     ax,#0x4f00              ; get mode information
697
698         push    es
699         push    ds
700         pop     es                      ; -> communication area
701         int     0x10                    ; video interrupt
702         pop     es
703 #if FAIL
704         xor     ax,ax
705 #endif
706         cmp     ax,#0x004f
707         jne     d4_I576_4               ; no VESA
708         cmp     DWORD (di),#SIG_VESA    ; "VESA"
709         jne     d4_I576_4
710
711         mov     ax,#0x4f01              ; get mode information
712         mov     cx,[_Mode]
713
714         push    es
715         push    ds
716         pop     es                      ; -> communication area
717         int     0x10                    ; video interrupt
718         pop     es
719
720         cmp     ax,#0x004f
721 ;;d4_I576_jne:
722         jne     d4_I576_4               ; no VESA
723
724         mov     ax,v_BytesPerScanLine(di)
725         mov     [_ypitch],ax
726         mov     ax,v_WinASegment(di)
727         mov     [_seg],ax
728         mov     cx,v_WinGranularity(di)
729         mov     ax,#9                   ; shift = 9
730 d4_J575:
731         jcxz    d4_K575
732         inc     ax                      ; shift++
733         shr     cx,#1
734         jmp     d4_J575
735 d4_K575:
736         mov     [_shift],ax
737         xchg    ax,cx                   ; shift to CX
738         mov     eax,#-1
739         shl     eax,cl                  ;
740         not     eax
741         mov     DWORD [_mask],eax
742         not     eax
743         and     eax,#0x00FFFFFF
744         mov     DWORD [_himask],eax     ;
745         test    BYTE v_ModeAttributes(di),#1
746         jz      d4_I576_4
747         mov     al,v_WinAAttributes(di)
748         and     al,#05
749         cmp     al,#05
750         jne     d4_I576_4
751
752 ;;;     mov     bx,#0x8000
753 ;;;     mov     WORD (bp-10),bx         ;disable
754 ;;;     or      bx,[_Mode]
755         mov     bx,[_Mode]
756
757         mov     ax,#0x4f02              ; set video mode
758         int     0x10
759         cmp     ax,#0x004f
760 ;;;     jne     d4_I576_4
761         je      d4_Line_327
762
763 d4_I576_4:
764         mov     ax,#4
765         stc
766         br      _display4_ret
767
768
769 ; Line 321
770 d4_I577:
771 ; Line 322
772 ; Line 323
773         mov     bx,#0
774         mov     ax,#6656        ;1a00H
775         int     0x10
776 #if FAIL
777         xor     ax,ax
778 #endif
779         cmp     al,#26  ;001aH
780         jne     d4_I578
781         cmp     bl,#7
782         je      d4_I579
783         cmp     bl,#8
784         je      d4_I579
785 d4_I578:
786         mov     ax,#2
787         stc
788         br      _display4_ret
789 ; Line 324
790 d4_I579:
791         mov     bx,#49  ;0031H
792         mov     ax,#4609        ;1201H
793         int     0x10
794
795 ;;;     mov     WORD (bp-10),#128       ;0080H  ;disable
796         mov     ax,WORD [_Mode]
797 ;;;     or      al,#128 ;0080H
798
799         int     0x10
800 ; Line 327
801 d4_Line_327:
802         mov     dx,#480/16
803         mov     bx,#0
804         mov     ax,#0x1124               ;set for 8x16 characters
805         int     0x10
806 ; Line 331
807 ;;;     cmp     WORD (bp-10),#0 ;disable
808 ;;;     je      d4_I580
809         mov     bx,#54  ;0036H
810         mov     ax,#4609        ;1201H
811         int     0x10
812 ; Line 333
813 d4_I580:
814         les     bx,(bp-22)      ;bmh
815         seg     es
816           mov   si,WORD (bx)
817         add     si,WORD [_tp]
818
819         push    ds
820
821         mov     ds,WORD [_tp+2]
822 ; Line 334
823         xor     bx,bx           ;i
824 d4_FC582:
825 ; Line 335
826         push    bx
827
828         seg cs
829           cmp   [_Mode],#0x12
830         ja      d4_Vesa_Palette
831
832         mov     bh,bl
833         mov     ax,#0x1000
834         int     0x10
835
836 d4_Vesa_Palette:
837         mov     bx,#0x3fff      ;00ffH
838
839         lodsb
840         mul     bh
841         div     bl
842         mov     cl,al
843
844         lodsb
845         mul     bh
846         div     bl
847         mov     ch,al
848
849         lodsb
850         mul     bh
851         div     bl
852         mov     dh,al
853         xor     dl,dl
854
855         pop     bx              ;color = i
856         mov     ax,#0x1010
857         int     0x10
858
859 ; Line 336
860         mov     di,(bp-22)      ;bmh
861           cmp   BYTE (di),#12   ; test for OS/2 bitmap
862         je      d4_F580
863         inc     si
864 d4_F580:
865 ; Line 337
866         inc     bx      ;WORD (bp-8)    ;i
867 d4_F581:
868         cmp     WORD (bp-6),bx  ;colors
869         jg      d4_FC582
870
871         pop     ds
872
873 ; Line 339
874         les     bx,(bp-18)      ;bmfh
875         seg     es
876           mov   ax,WORD (bx+10)
877         seg     es
878           mov   dx,WORD (bx+12)
879         add     ax,WORD [_bmp]
880         adc     dx,#0
881         shl     dx,#12
882         add     dx,WORD [_bmp+2]
883         mov     WORD [_tp],ax
884         mov     WORD [_tp+2],dx
885 ; Line 340
886         xor     ax,ax
887         call    d4_setstate
888 ; Line 341
889         mov     ax,#1
890         call    d4_setstate
891 ; Line 342
892         les     bx,(bp-22)      ;bmh
893 ;;      seg     es
894 ;;        mov   ax,WORD (bx+8)          ; 480
895         mov     ax,#480                 ; Windows
896 ;;      seg     es
897 ;;        mov   dx,WORD (bx+4)          ; 640
898         mov     dx,#640                 ; Windows
899         seg     es
900           cmp   BYTE (bx),#13           ; OS2 (obsolete)
901         sbb     cx,cx                   ; Win = 0  OS2 = -1 (obsolete)
902         not     cx
903         seg     es
904           and   cx,WORD (bx+16)         ; compression
905
906         mov     bx,cx                   ; compression to BX
907
908         mov     si,#d4_getrow4
909         mov     di,#d4_putrow4
910         cmp     WORD [_Mode],#0x12
911         jbe     d4_FC586
912         mov     si,#d4_getrow8
913         mov     di,#d4_putrow8
914 d4_FC586:
915         dec     ax
916         js      d4_FC587
917 ; Line 343
918         xchg    ax,bx
919 ;;;     call    d4_getrow4
920         call    si              ;getrow
921 ; Line 344
922         xchg    ax,bx
923 ;;;     call    d4_putrow4
924         call    di              ;putrow
925 ; Line 345
926         jmp     d4_FC586
927
928 d4_FC587:
929 ; Line 346
930         xor     ax,ax                   ; restore state
931         call    d4_setstate
932 ; Line 348
933
934         mov     bx,#54  ;0036H          ;enable refresh
935         mov     ax,#4608        ;1200H
936         int     0x10
937
938         xor     ax,ax           ;clears the carry
939 _display4_ret:
940         pop     di
941         pop     si
942         leave   
943         ret     
944
945         .even           ;   4
946 _done4:
947         xor     ax,ax
948         call    d4_setstate     ;restore state
949 ; Line 356
950 ; enable default palette loading
951         mov     bx,#49  ;0031H
952         mov     ax,#4608        ;1200H
953         int     0x10
954 ; Line 357
955         mov     ax,#0x0003       ; set video mode
956         int     0x10
957 ; Line 359
958         ret     
959
960
961 ; pixadr8 - pixel address in 256 color mode
962 ;
963 ;   Enter with:
964 ;       AX = y
965 ;       BX = x
966 ;
967 ;   Exit with:
968 ;       ES:DI = pointer to byte
969 ;
970 d4_pixadr8:
971         push    ax
972         push    cx
973         push    dx
974         push    ds
975
976         push    cs
977         pop     ds
978
979 ;;      seg cs
980           mul   WORD [_ypitch]
981         add     ax,bx
982         adc     dx,#0
983         mov     di,ax
984 ;;      seg cs
985           mov   cl,[_shift]
986 ;;      seg cs
987           and   di,[_mask]
988         shrd    ax,dx,cl
989 ;;      seg cs
990           cmp   ax,[_VesaWindow]
991         je      d4p8_1
992
993 ;;      seg cs
994           mov   [_VesaWindow],ax
995         xchg    ax,dx
996         push    bx
997         xor     cx,cx
998         xor     bx,bx
999         mov     ax,#0x4f05
1000         int     0x10
1001         pop     bx
1002 d4p8_1:
1003 ;;      seg cs
1004           mov   es,[_seg]
1005
1006         pop     ds
1007         pop     dx
1008         pop     cx
1009         pop     ax
1010         ret
1011
1012
1013
1014 ; putrow8
1015 ;
1016 ;   Enter with:
1017 ;       AX = y
1018 ;       BX = compression
1019 ;       DX = npix (640)
1020 ;       DS == CS
1021 ;
1022 ;  Exit with:
1023 ;       ES is trashed
1024 ;       all other registers preserved
1025 ;
1026 d4_putrow8:
1027         pusha
1028         mov     si,#_line       ; source
1029
1030         mov     cx,WORD [_mask] ; mask
1031         xor     bx,bx
1032         xor     di,di
1033 d4p8_2:
1034         test    di,cx
1035         jnz     d4p8_3
1036         call    d4_pixadr8
1037 d4p8_3:
1038         inc     bx
1039         movsb
1040         cmp     bx,dx
1041         jb      d4p8_2
1042
1043         popa
1044         ret
1045
1046
1047 ; getrow8
1048 ;
1049 ;       AX = compression
1050 ;       DX = npix (640)
1051 ;       BX = y
1052 ;
1053 ;
1054 d4_getrow8:
1055         pusha
1056         push    ds
1057
1058         push    cs
1059         pop     es
1060         mov     di,#_line               ; ES:DI setup
1061         lds     si,[_tp]                ; DS:SI is a HUGE pointer
1062         mov     bp,ds                   ; also in BP:SI
1063
1064         test    ax,ax
1065         jz      d4_get8_nocompr
1066
1067 ; get with compression
1068 ;
1069 ; DX is npix
1070 ; BH is repeat
1071 ; BL is skip
1072 ; CX is rpt
1073
1074 ;      repeat = 1;
1075         mov     bh,#1
1076
1077 ;      while (npix>0) {
1078         jmp     d4_get8_99
1079 d4_get8_1:
1080
1081 ;         while (repeat && npix>0) {
1082         jmp     d4_get8_30
1083 d4_get8_10:
1084
1085 ;            rpt = GETC(infile);
1086         call    getbyte
1087         xchg    ax,cx
1088
1089 ;            repeat = rpt;
1090         mov     bh,cl
1091
1092 ;            if (repeat) {
1093         test    bh,bh
1094         jz      d4_get8_20
1095
1096 ;               c = GETC(infile);
1097         call    getbyte
1098
1099 ;               npix -= rpt;
1100         sub     dx,cx
1101
1102 ;               while (rpt>0) {
1103 ;                  *lp++ = c;
1104 ;                  rpt--;
1105 ;               }
1106         rep
1107          stosb
1108
1109 ;            }
1110 d4_get8_20:
1111
1112 ;         }     /* end while (repeat && npix>0) */
1113 d4_get8_30:
1114         test    bh,bh           ; repeat
1115         jz      d4_get8_40
1116         cmp     dx,#0
1117         jg      d4_get8_10
1118 d4_get8_40:
1119
1120 ;         if (npix>0) { /* get some enumerated data */
1121         cmp     dx,#0
1122         jle     d4_get8_95
1123
1124 ;            rpt = GETC(infile);
1125         call    getbyte
1126         xchg    ax,cx
1127
1128 ;            npix -= rpt;
1129         sub     dx,cx
1130
1131 ;            skip = (rpt%2 != 0);
1132         mov     bl,cl
1133
1134 ;            while (rpt>0) {
1135         jcxz    d4_get8_75
1136 d4_get8_70:
1137
1138 ;               c = GETC(infile);
1139         call    getbyte
1140
1141 ;               *lp++ = c;
1142         stosb
1143 ;               rpt--;
1144 ;            }
1145         loop    d4_get8_70
1146 d4_get8_75:
1147 ;            if (skip) c = GETC(infile);
1148         shr     bl,#1
1149         jnc     d4_get8_80
1150         call    getbyte
1151 d4_get8_80:
1152
1153 ;         }
1154 d4_get8_95:
1155
1156 ;         repeat = 1;
1157         mov     bh,#1
1158
1159 ;       } /* end while (npix>0) */
1160 d4_get8_99:
1161         cmp     dx,#0
1162         jg      d4_get8_1
1163
1164 ;      GETC(infile);
1165 ;      c=GETC(infile);
1166         call    getbyte
1167         call    getbyte
1168
1169         jmp     d4_get8_exit
1170
1171
1172 ; get with no compression
1173 ;   really just a super movsb with a huge source pointer
1174
1175 d4_get8_nocompr:
1176         mov     cx,dx
1177 d4_get8_nloop:
1178         call    getbyte         ; BP==DS is required
1179         stosb
1180         loop    d4_get8_nloop
1181
1182 d4_get8_exit:
1183         seg     cs
1184           mov     [_tp],si        ;
1185         seg     cs
1186           mov     [_tp+2],ds      ;
1187
1188         pop     ds
1189         popa
1190         ret
1191
1192 ; char256
1193 ;
1194 ;   Enter with:
1195 ;       AL      character to display
1196 ;       BX      ypos
1197 ;       DX      xpos
1198 ;       (bp+4)  far pointer to 
1199 ;
1200 ;   Exit with:
1201 ;       ES is trashed
1202 ;
1203 ;
1204 ;   Stack used:
1205 ;       bp-2    points
1206 ;       bp-4    ypos
1207 ;       bp-6    xpos
1208 ;       bp-8    bits
1209 ;       bp-10   xtem
1210 ;
1211 ;   Variables:
1212 ;       DS:SI   cgen
1213 ;       SI      i
1214 ;       BX      xtem
1215 ;       ES:DI   buf
1216 ;
1217 d4_char256:
1218         enter   #10,#0
1219         pusha
1220         push    ds
1221
1222         push    WORD #0
1223         pop     ds
1224 ;   points = *(short*)0x00000485UL;     /* 40:85 */
1225         mov     cx,WORD [0x485] ;points
1226         xor     ah,ah           ;AL is char to put out
1227         mov     WORD (bp-2),cx  ;points
1228         mov     WORD (bp-4),bx  ;ypos
1229         mov     WORD (bp-6),dx  ;xpos
1230
1231 ;   cgen = *(char**)(0x43 * 4UL);       /* int 0x43 points to char bitmap */
1232 ;   cgen += (unsigned)c * points;
1233         imul    ax,cx           ;leave DX alone; 386 form of instruction
1234         mov     si,#268 ;010cH  ; int 0x43 -> character bitmaps
1235         add     ax,WORD (si)
1236         mov     ds,WORD (si+2)  ;cgen
1237         xchg    si,ax           ;cgen   in DS:SI
1238
1239 ;   shadow = 0;
1240         xor     ch,ch
1241         les     di,(bp+4)       ;sch->
1242 ;   fg = sch->fg;
1243         seg es
1244          mov    cl,(di)
1245 ;   bg = sch->bg;
1246         seg es
1247           mov   dh,(di+2)
1248 ;   sh = sch->sh;
1249         seg es
1250           mov   dl,(di+4)
1251 ;
1252 ;   while (points--) {
1253 d4_char256_10:
1254 ;      int i;
1255 ;
1256 ;      bits = *cgen++;                  ;cgen in DS:SI
1257         lodsb
1258         mov     WORD (bp-8),ax          ;bits
1259         push    si                      ; save SI
1260
1261 ;      fore = bits;             ; fore is BL
1262         xchg    bx,ax           ; fore is BL
1263
1264 ;      xtem = x;
1265         mov     ax,WORD (bp-6)
1266         mov     WORD (bp-10),ax         ;xtem
1267
1268 ;      for (i=8; i; i--) {
1269         mov     si,#8                   ;i
1270         xor     di,di                   ;buf
1271
1272 d4_char256_20:
1273         seg cs
1274           test  di,WORD [_mask]
1275         jnz     d4_char256_22
1276         push    bx
1277         mov     ax,WORD (bp-4)  ;ypos
1278         mov     bx,WORD (bp-10) ;xtem
1279         call    d4_pixadr8      ;buf to ES:DI
1280         pop     bx
1281 d4_char256_22:
1282
1283 ;         int color = 0x400;
1284         mov     ax,#0x400
1285
1286 ;         if (bg != fg) color = bg;
1287         cmp     dh,cl           ;bg:fg
1288         je      d4_char256_31
1289         mov     al,dh           ;color = bg
1290         cbw
1291 d4_char256_31:
1292
1293 ;         if ( (shadow&0200) && sh != fg) color = sh;
1294         shl     ch,#1           ;shadow
1295         jnc     d4_char256_33
1296         cmp     dl,cl           ;sh:fg
1297         je      d4_char256_33
1298         mov     al,dl           ; color = sh
1299         cbw
1300 d4_char256_33:
1301
1302 ;         if ( (fore & 0200) ) color = fg;
1303         shl     bl,#1
1304         jnc     d4_char256_35
1305         mov     al,cl           ; color = fg
1306         cbw
1307
1308 d4_char256_35:
1309
1310 ;         buf = pixadr8(xtem++, y);
1311 ;         if (color<256) *buf = color;
1312         inc     ah
1313         cmp     ah,#1
1314         ja      d4_char256_39
1315         seg es
1316           mov   BYTE (di),al
1317 d4_char256_39:
1318         inc     di
1319         inc     WORD (bp-10)    ;xtem
1320
1321 ;         shadow <<= 1;
1322 ;         fore <<= 1;
1323 ;      }
1324         dec     si              ;i
1325         jnz     d4_char256_20
1326
1327 ;      y++;
1328         inc     WORD (bp-4)     ;ypos
1329
1330 ;      shadow = bits>>1;
1331         mov     ch,BYTE (bp-8)
1332         shr     ch,#1
1333 ;   }
1334         pop     si              ;cgen
1335         dec     WORD (bp-2)
1336         jnz     d4_char256_10
1337
1338
1339
1340 d4_char256_exit:
1341         pop     ds
1342         popa
1343         leave
1344         ret
1345
1346