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