]> 4ch.mooo.com Git - 16.git/blob - 16/ted5/TED5_A.ASM
ted5 added
[16.git] / 16 / ted5 / TED5_A.ASM
1 ;====================================================
2 ;
3 ; TED5 ASM Routines
4 ;
5 ;====================================================
6         IDEAL
7         P386N
8         MODEL   medium,C
9
10 extrn   XMSdriver:DWORD
11 extrn   videomode:WORD,xmshandle:WORD,XMSlookup:WORD
12 extrn   tilenum:WORD,lasticon:WORD,firsticon:WORD
13 extrn   CGAlookup:WORD,EGA1lookup:WORD,EGA2lookup:WORD,VGAlookup:WORD
14
15         DATASEG
16
17 SCindex =       3c4h
18 SCmapmask =     2
19 GCindex =       3CEh
20 GCreadmap =     4
21 GCmode  =       5
22
23 CombTable dw    CombineCGA,CombineEGA,CombineEGA,CombineVGA
24 DrawTable dw    DrawTCGA,DrawTEGA1,DrawTEGA2,DrawTVGA
25 OverTable dw    OverlayCGA,OverlayEGA,OverlayEGA,OverlayVGA
26
27 cgacolors db    55h,0aah
28 egacolors dw    0,0ffffh
29
30 oldh    db      0
31 oldy    dw      0
32 horzadd dw      0
33 wsize   dw      1,2,4
34 hsize   dw      8,16,32
35 twidth  dw      0
36 theight dw      0
37 bmlen   dw      0
38 masklen dw      0
39
40 csize   dw      32,64,256
41 esize   dw      32,128,512
42 vsize   dw      64,256,1024
43
44 cmsize  dw      64,128,512
45 emsize  dw      40,160,640
46 vmsize  dw      128,512,2048
47
48         PUBLIC  tdata
49 tdata   db      2048 dup(?)
50 tdata1  db      2048 dup(?)
51
52 ;
53 ; XMS move structure
54 ;
55 blen    dw      0,0
56 shandle dw      0
57 soff    dd      0
58 dhandle dw      0
59 doff    dd      tdata1
60
61
62 Csparse dw      csp8,csp16,csp32
63 Esparse dw      esp8,esp16,esp32
64 Vsparse dw      vsp8,vsp16,vsp32
65
66 csp8    db      0ffh,0ffh
67         REPT    7
68         db      0c0h,0
69         ENDM
70 csp16   db      4 dup (0ffh)
71         REPT    15
72         db      0c0h
73         db      3 dup (0)
74         ENDM
75 csp32   db      8 dup (0ffh)
76         REPT    31
77         db      0c0h
78         db      7 dup(0)
79         ENDM
80
81 LABEL   esp8    BYTE
82         REPT    4
83         db      0ffh
84         db      7 dup (80h)
85         ENDM
86 LABEL   esp16   BYTE
87         REPT    4
88         db      0ffh,0ffh
89         REPT    15
90         db      80h,0
91         ENDM
92         ENDM
93 LABEL   esp32   BYTE
94         REPT    4
95         db      4 dup (0ffh)
96         REPT    31
97         db      80h,0,0,0
98         ENDM
99         ENDM
100
101 vsp8    db      8 dup(0ffh)
102         REPT    7
103         db      0ffh,7 dup(0)
104         ENDM
105 vsp16   db      16 dup(0ffh)
106         REPT    15
107         db      0ffh,15 dup(0)
108         ENDM
109 vsp32   db      32 dup(0ffh)
110         REPT    31
111         db      0ffh,31 dup(0)
112         ENDM
113
114
115         CODESEG
116 ;====================================================
117 ;
118 ; Combine tiles together (background,foreground,icons)
119 ;
120 ;====================================================
121 PUBLIC  CombineTiles
122 PROC    CombineTiles
123         ARG     tileb:WORD,tilef:WORD,tilei:WORD,tsize:WORD
124
125         push    si
126         push    di
127
128         cld
129         mov     bx,[tsize]
130         shl     bx,1
131         mov     dx,[hsize+bx-2]
132         mov     [theight],dx
133         mov     cx,[wsize+bx-2]
134         mov     [twidth],cx
135         mov     ax,[xmshandle]
136         mov     [shandle],ax            ;set XMS handle
137
138         mov     si,[videomode]
139         shl     si,1
140         mov     ax,[CombTable+si]
141         jmp     ax
142 ;
143 ; Combine CGA tiles
144 ;
145 LABEL   CombineCGA      PROC
146
147         shl     [twidth],1
148         mov     cx,[cmsize+bx-2]
149         mov     [bmlen],cx
150         mov     ax,[csize+bx-2]         ;get length of block to move
151         mov     [blen],ax
152         sub     cx,ax
153         mov     [masklen],cx
154
155 ;
156 ; Handle the background tiles first!
157 ;
158         mov     ax,[tileb]
159         cmp     ax,8000h                ;solid color?
160         jb      @@c1
161         neg     ax
162
163         mov     di,ds
164         mov     es,di
165         mov     di,OFFSET tdata
166         mov     bx,ax
167         and     bx,1
168         mov     al,[cgacolors+bx]
169
170         mov     cx,[blen]
171         rep stosb
172         jmp     SHORT @@c2
173
174 @@c1:
175         shl     ax,2
176         mov     bx,ax
177         mov     es,[XMSlookup]          ;(LONG SEG *)
178         mov     ax,[es:bx]
179         mov     [WORD PTR soff],ax
180         mov     ax,[es:bx+2]
181         mov     [WORD PTR soff+2],ax
182         cmp     ax,-1                   ;SPARSE TILE?
183         je      @@c1a
184
185         mov     ax,OFFSET tdata         ;(quickie modification since "doff"
186         mov     [WORD doff],ax          ; should always point to "tdata1")
187         mov     si,OFFSET blen
188         mov     ah,11
189         call    [DWORD XMSdriver]       ;move tile into tdata1
190         mov     ax,OFFSET tdata1
191         mov     [WORD doff],ax          ;ahhh....back to normal
192
193         jmp     @@c2
194 ;
195 ; Copy sparse tile to tdata
196 ;
197 @@c1a:
198         mov     bx,[tsize]
199         shl     bx,1
200         mov     si,[Csparse+bx-2]
201         mov     di,OFFSET tdata
202         mov     cx,[blen]
203         shr     cx,1                    ;for WORD copy
204         mov     ax,ds
205         mov     es,ax
206         rep movsw
207
208 ;
209 ; Handle foreground tiles
210 ;
211 @@c2:
212         mov     bx,[tilef]
213         cmp     bx,0
214         je      @@c3                    ;any masked tile?
215
216         shl     bx,2
217         mov     es,[XMSlookup]
218         mov     ax,[es:bx]
219         mov     [WORD PTR soff],ax
220         mov     ax,[es:bx+2]
221         mov     [WORD PTR soff+2],ax
222         cmp     ax,-1                   ;SPARSE MASKED TILE?
223         je      @@c3
224
225         mov     ax,[bmlen]
226         mov     [blen],ax               ;set masked tile length for XMS copy
227         mov     si,OFFSET blen
228         mov     ah,11
229         call    [DWORD XMSdriver]       ;move tile into tdata1
230 ;
231 ; now we have the masked tile in "tdata1".
232 ; time to mask it onto "tdata"
233 ;
234         mov     si,OFFSET tdata1
235         add     si,[masklen]            ;SI = masked tile's tiledata
236         mov     di,OFFSET tdata         ;DI = tile in "tdata"
237
238         mov     dx,[theight]
239         mov     bx,OFFSET tdata1        ;BX = mask
240 @@c2a:
241         mov     cx,[twidth]
242 @@c2b:
243         mov     al,[bx]                 ;get mask byte
244         and     [di],al                 ;and tdata with it
245         lodsb                           ;get tilem byte
246         or      [di],al                 ;OR it onto tdata
247         inc     di
248         inc     bx
249         loop    @@c2b
250         dec     dx
251         jnz     @@c2a
252 ;
253 ; Handle icons (foreground tiles)
254 ;
255 @@c3:
256         mov     bx,[tilei]
257         cmp     bx,[lasticon]
258         ja      @@cexit                 ;any icons?
259         cmp     bx,[firsticon]
260         jbe     @@cexit
261
262         shl     bx,2
263         mov     es,[XMSlookup]
264         mov     ax,[es:bx]
265         mov     [WORD PTR soff],ax
266         mov     ax,[es:bx+2]
267         mov     [WORD PTR soff+2],ax
268
269         mov     ax,[bmlen]
270         mov     [blen],ax               ;set masked tile length for XMS copy
271         mov     si,OFFSET blen
272         mov     ah,11
273         call    [DWORD XMSdriver]       ;move tile into tdata1
274 ;
275 ; now we have the masked tile in "tdata1".
276 ; time to mask it onto "tdata"
277 ;
278         mov     si,OFFSET tdata1
279         add     si,[masklen]            ;SI = masked tile's tiledata
280         mov     di,OFFSET tdata         ;DI = tile in "tdata"
281
282         mov     dx,[theight]
283         mov     bx,OFFSET tdata1        ;BX = mask
284 @@c3a:
285         mov     cx,[twidth]
286 @@c3b:
287         mov     al,[bx]                 ;get mask byte
288         and     [di],al                 ;and tdata with it
289         lodsb                           ;get tilem byte
290         or      [di],al                 ;OR it onto tdata
291         inc     di
292         inc     bx
293         loop    @@c3b
294         dec     dx
295         jnz     @@c3a
296 @@cexit:
297         pop     di
298         pop     si
299         ret
300
301 ;
302 ; Combine EGA tiles
303 ;
304 LABEL   CombineEGA      PROC
305
306         mov     cx,[emsize+bx-2]
307         mov     [bmlen],cx
308         mov     ax,[esize+bx-2]         ;get length of block to move
309         mov     [blen],ax
310         sub     cx,ax
311         mov     [masklen],cx
312
313 ;
314 ; Handle the background tiles first!
315 ;
316         mov     ax,[tileb]
317         cmp     ax,8000h                ;solid color?
318         jb      @@e1
319         neg     ax
320
321         mov     di,ds
322         mov     es,di
323         mov     di,OFFSET tdata
324         mov     dx,ax
325
326         mov     cx,[blen]               ;plane 0
327         shr     cx,3
328         mov     bx,dx
329         shr     dx,1
330         and     bx,1
331         shl     bx,1
332         mov     ax,[egacolors+bx]
333         rep stosw
334
335         mov     cx,[blen]               ;plane 1
336         shr     cx,3
337         mov     bx,dx
338         shr     dx,1
339         and     bx,1
340         shl     bx,1
341         mov     ax,[egacolors+bx]
342         rep stosw
343
344         mov     cx,[blen]               ;plane 2
345         shr     cx,3
346         mov     bx,dx
347         shr     dx,1
348         and     bx,1
349         shl     bx,1
350         mov     ax,[egacolors+bx]
351         rep stosw
352
353         mov     cx,[blen]               ;plane 3
354         shr     cx,3
355         mov     bx,dx
356         shr     dx,1
357         and     bx,1
358         shl     bx,1
359         mov     ax,[egacolors+bx]
360         rep stosw
361         jmp     SHORT @@e2
362
363 @@e1:
364         shl     ax,2
365         mov     bx,ax
366         mov     es,[XMSlookup]          ;(LONG SEG *)
367         mov     ax,[es:bx]
368         mov     [WORD PTR soff],ax
369         mov     ax,[es:bx+2]
370         mov     [WORD PTR soff+2],ax
371         cmp     ax,-1                   ;SPARSE TILE?
372         je      @@e1a
373
374         mov     ax,OFFSET tdata         ;(quickie modification since "doff"
375         mov     [WORD doff],ax          ; should always point to "tdata1")
376         mov     si,OFFSET blen
377         mov     ah,11
378         call    [DWORD XMSdriver]       ;move tile into tdata1
379         mov     ax,OFFSET tdata1
380         mov     [WORD doff],ax          ;ahhh....back to normal
381
382         jmp     @@e2
383 ;
384 ; Copy sparse tile to tdata
385 ;
386 @@e1a:
387         mov     bx,[tsize]
388         shl     bx,1
389         mov     si,[Esparse+bx-2]
390         mov     di,OFFSET tdata
391         mov     cx,[blen]
392         shr     cx,1                    ;for WORD copy
393         mov     ax,ds
394         mov     es,ax
395         rep movsw
396
397 ;
398 ; Handle foreground tiles
399 ;
400 @@e2:
401         mov     bx,[tilef]
402         cmp     bx,0
403         je      @@e3                    ;any masked tile?
404
405         shl     bx,2
406         mov     es,[XMSlookup]
407         mov     ax,[es:bx]
408         mov     [WORD PTR soff],ax
409         mov     ax,[es:bx+2]
410         mov     [WORD PTR soff+2],ax
411         cmp     ax,-1                   ;SPARSE MASKED TILE?
412         je      @@e3
413
414         mov     ax,[bmlen]
415         mov     [blen],ax               ;set masked tile length for XMS copy
416         mov     si,OFFSET blen
417         mov     ah,11
418         call    [DWORD XMSdriver]       ;move tile into tdata1
419 ;
420 ; now we have the masked tile in "tdata1".
421 ; time to mask it onto "tdata"
422 ;
423         mov     si,OFFSET tdata1
424         add     si,[masklen]            ;SI = masked tile's tiledata
425         mov     di,OFFSET tdata         ;DI = tile in "tdata"
426         mov     ah,4
427 @@e2a0:
428         mov     dx,[theight]
429         mov     bx,OFFSET tdata1        ;BX = mask
430 @@e2a:
431         mov     cx,[twidth]
432 @@e2b:
433         mov     al,[bx]                 ;get mask byte
434         and     [di],al                 ;and tdata with it
435         lodsb                           ;get tilem byte
436         or      [di],al                 ;OR it onto tdata
437         inc     di
438         inc     bx
439         loop    @@e2b
440         dec     dx
441         jnz     @@e2a
442         dec     ah
443         jnz     @@e2a0                  ;do all 4 planes!
444 ;
445 ; Handle icons (foreground tiles)
446 ;
447 @@e3:
448         mov     bx,[tilei]
449         cmp     bx,[lasticon]
450         ja      @@eexit                 ;any icons?
451         cmp     bx,[firsticon]
452         jbe     @@eexit
453
454         shl     bx,2
455         mov     es,[XMSlookup]
456         mov     ax,[es:bx]
457         mov     [WORD PTR soff],ax
458         mov     ax,[es:bx+2]
459         mov     [WORD PTR soff+2],ax
460
461         mov     ax,[bmlen]
462         mov     [blen],ax               ;set masked tile length for XMS copy
463         mov     si,OFFSET blen
464         mov     ah,11
465         call    [DWORD XMSdriver]       ;move tile into tdata1
466 ;
467 ; now we have the masked tile in "tdata1".
468 ; time to mask it onto "tdata"
469 ;
470         mov     si,OFFSET tdata1
471         add     si,[masklen]            ;SI = masked tile's tiledata
472         mov     di,OFFSET tdata         ;DI = tile in "tdata"
473         mov     ah,4
474 @@e3a0:
475         mov     dx,[theight]
476         mov     bx,OFFSET tdata1        ;BX = mask
477 @@e3a:
478         mov     cx,[twidth]
479 @@e3b:
480         mov     al,[bx]                 ;get mask byte
481         and     [di],al                 ;and tdata with it
482         lodsb                           ;get tilem byte
483         or      [di],al                 ;OR it onto tdata
484         inc     di
485         inc     bx
486         loop    @@e3b
487         dec     dx
488         jnz     @@e3a
489         dec     ah
490         jnz     @@e3a0                  ;do all 4 planes!
491 @@eexit:
492         pop     di
493         pop     si
494         ret
495
496 ;
497 ; Combine VGA tiles
498 ;
499 LABEL   CombineVGA      PROC
500
501         shl     [twidth],3
502         mov     cx,[vmsize+bx-2]
503         mov     [bmlen],cx
504         mov     ax,[vsize+bx-2]         ;get length of block to move
505         mov     [blen],ax
506         sub     cx,ax
507         mov     [masklen],cx
508
509 ;
510 ; Handle the background tiles first!
511 ;
512         mov     ax,[tileb]
513         cmp     ax,8000h                ;solid color?
514         jb      @@v1
515         neg     ax
516
517         mov     di,ds
518         mov     es,di
519         mov     di,OFFSET tdata
520         shl     ax,4
521         mov     bx,[blen]
522         shr     bx,3
523
524         mov     cx,bx
525         rep stosb
526         inc     al
527         mov     cx,bx
528         rep stosb
529         inc     al
530         mov     cx,bx
531         rep stosb
532         inc     al
533         mov     cx,bx
534         rep stosb
535         inc     al
536         mov     cx,bx
537         rep stosb
538         inc     al
539         mov     cx,bx
540         rep stosb
541         inc     al
542         mov     cx,bx
543         rep stosb
544         inc     al
545         mov     cx,bx
546         rep stosb
547
548         jmp     SHORT @@v2
549
550 @@v1:
551         shl     ax,2
552         mov     bx,ax
553         mov     es,[XMSlookup]          ;(LONG SEG *)
554         mov     ax,[es:bx]
555         mov     [WORD PTR soff],ax
556         mov     ax,[es:bx+2]
557         mov     [WORD PTR soff+2],ax
558         cmp     ax,-1                   ;SPARSE TILE?
559         je      @@v1a
560
561         mov     ax,OFFSET tdata         ;(quickie modification since "doff"
562         mov     [WORD doff],ax          ; should always point to "tdata1")
563         mov     si,OFFSET blen
564         mov     ah,11
565         call    [DWORD XMSdriver]       ;move tile into tdata1
566         mov     ax,OFFSET tdata1
567         mov     [WORD doff],ax          ;ahhh....back to normal
568
569         jmp     @@v2
570 ;
571 ; Copy sparse tile to tdata
572 ;
573 @@v1a:
574         mov     bx,[tsize]
575         shl     bx,1
576         mov     si,[Vsparse+bx-2]
577         mov     di,OFFSET tdata
578         mov     cx,[blen]
579         shr     cx,1                    ;for WORD copy
580         mov     ax,ds
581         mov     es,ax
582         rep movsw
583
584 ;
585 ; Handle foreground tiles
586 ;
587 @@v2:
588         mov     bx,[tilef]
589         cmp     bx,0
590         je      @@v3                    ;any masked tile?
591
592         shl     bx,2
593         mov     es,[XMSlookup]
594         mov     ax,[es:bx]
595         mov     [WORD PTR soff],ax
596         mov     ax,[es:bx+2]
597         mov     [WORD PTR soff+2],ax
598         cmp     ax,-1                   ;SPARSE MASKED TILE?
599         je      @@v3
600
601         mov     ax,[bmlen]
602         mov     [blen],ax               ;set masked tile length for XMS copy
603         mov     si,OFFSET blen
604         mov     ah,11
605         call    [DWORD XMSdriver]       ;move tile into tdata1
606 ;
607 ; now we have the masked tile in "tdata1".
608 ; time to mask it onto "tdata"
609 ;
610         mov     si,OFFSET tdata1
611         add     si,[masklen]            ;SI = masked tile's tiledata
612         mov     di,OFFSET tdata         ;DI = tile in "tdata"
613
614         mov     dx,[theight]
615         mov     bx,OFFSET tdata1        ;BX = mask
616 @@v2a:
617         mov     cx,[twidth]
618 @@v2b:
619         mov     al,[bx]                 ;get mask byte
620         and     [di],al                 ;and tdata with it
621         lodsb                           ;get tilem byte
622         or      [di],al                 ;OR it onto tdata
623         inc     di
624         inc     bx
625         loop    @@v2b
626         dec     dx
627         jnz     @@v2a
628 ;
629 ; Handle icons (foreground tiles)
630 ;
631 @@v3:
632         mov     bx,[tilei]
633         cmp     bx,[lasticon]
634         ja      @@vexit                 ;any icons?
635         cmp     bx,[firsticon]
636         jbe     @@vexit
637
638         shl     bx,2
639         mov     es,[XMSlookup]
640         mov     ax,[es:bx]
641         mov     [WORD PTR soff],ax
642         mov     ax,[es:bx+2]
643         mov     [WORD PTR soff+2],ax
644
645         mov     ax,[bmlen]
646         mov     [blen],ax               ;set masked tile length for XMS copy
647         mov     si,OFFSET blen
648         mov     ah,11
649         call    [DWORD XMSdriver]       ;move tile into tdata1
650 ;
651 ; now we have the masked tile in "tdata1".
652 ; time to mask it onto "tdata"
653 ;
654         mov     si,OFFSET tdata1
655         add     si,[masklen]            ;SI = masked tile's tiledata
656         mov     di,OFFSET tdata         ;DI = tile in "tdata"
657
658         mov     dx,[theight]
659         mov     bx,OFFSET tdata1        ;BX = mask
660 @@v3a:
661         mov     cx,[twidth]
662 @@v3b:
663         mov     al,[bx]                 ;get mask byte
664         and     [di],al                 ;and tdata with it
665         lodsb                           ;get tilem byte
666         or      [di],al                 ;OR it onto tdata
667         inc     di
668         inc     bx
669         loop    @@v3b
670         dec     dx
671         jnz     @@v3a
672 @@vexit:
673         pop     di
674         pop     si
675         ret
676 ENDP
677
678
679 ;====================================================
680 ;
681 ; Draw a tile in any of the video modes
682 ; NOTE: ONLY WORKS WITH TSIZE=2!
683 ;
684 ;====================================================
685 PUBLIC  DrawTile
686 PROC    DrawTile
687         ARG     x:WORD,y:WORD,tsize:WORD
688
689         push    si
690         push    di
691
692         mov     bx,[tsize]
693         shl     bx,1
694         mov     ah,[BYTE PTR hsize+bx-2]
695         mov     [oldh],ah
696         mov     cx,[wsize+bx-2]
697
698         mov     bx,[videomode]
699         shl     bx,1
700         mov     dx,[DrawTable+bx]
701
702         mov     bx,[y]
703         shl     bx,1
704         jmp     dx
705
706 label   DrawTCGA proc
707
708         mov     ax,0b800h
709         mov     es,ax
710         mov     si,OFFSET tdata
711         mov     di,[x]
712         shl     di,1
713         add     di,[CGAlookup+bx]
714         mov     bx,cx
715         shl     bx,1
716         mov     ah,[oldh]
717 @@c1:
718         mov     cx,bx
719         rep movsb
720         sub     di,bx
721         xor     di,2000h
722         mov     cx,bx
723         rep movsb
724         sub     di,bx
725         xor     di,2000h
726         add     di,80
727
728         sub     ah,2
729         jnz     @@c1
730
731         pop     di
732         pop     si
733         ret
734 ;
735 ; EGA1/2/3 TILE DRAW ROUTINES
736 ;
737 label   DrawTEGA1 proc
738         mov     [horzadd],38
739         mov     di,[EGA1lookup+bx]
740         jmp     SHORT DoDrawEGAT
741 label   DrawTEGA2 proc
742         mov     [horzadd],78
743         mov     di,[EGA2lookup+bx]
744         jmp     SHORT DoDrawEGAT
745 label   DoDrawEGAT proc
746         add     di,[x]
747         mov     [oldy],di
748         mov     si,OFFSET tdata
749         mov     bx,0a000h
750         mov     es,bx
751         mov     bx,cx
752 ;
753 ; AH : height
754 ; BX : width
755 ; ES:DI : dest
756 ; DS:SI : source
757 ;
758         cld
759         mov     dx,GCindex
760         mov     al,GCmode
761         out     dx,al
762         inc     dx
763         mov     al,0
764         out     dx,al
765 ;
766 ; Plane 0
767 ;
768         mov     dx,SCindex
769         mov     al,SCmapmask
770         out     dx,al
771         inc     dx
772         mov     al,1
773         out     dx,al
774
775         mov     dx,[horzadd]
776 @@1:
777         mov     cx,bx
778         rep movsb
779         add     di,dx
780         dec     ah
781         jne     @@1
782 ;
783 ; Plane 1
784 ;
785         mov     dx,SCindex
786         mov     al,SCmapmask
787         out     dx,al
788         inc     dx
789         mov     al,2
790         out     dx,al
791
792         mov     dx,[horzadd]
793         mov     di,[oldy]
794         mov     ah,[oldh]
795 @@2:
796         mov     cx,bx
797         rep movsb
798         add     di,dx
799         dec     ah
800         jne     @@2
801 ;
802 ; Plane 2
803 ;
804         mov     dx,SCindex
805         mov     al,SCmapmask
806         out     dx,al
807         inc     dx
808         mov     al,4
809         out     dx,al
810
811         mov     dx,[horzadd]
812         mov     di,[oldy]
813         mov     ah,[oldh]
814 @@3:
815         mov     cx,bx
816         rep movsb
817         add     di,dx
818         dec     ah
819         jne     @@3
820 ;
821 ; Plane 3
822 ;
823         mov     dx,SCindex
824         mov     al,SCmapmask
825         out     dx,al
826         inc     dx
827         mov     al,8
828         out     dx,al
829
830         mov     dx,[horzadd]
831         mov     di,[oldy]
832         mov     ah,[oldh]
833 @@4:
834         mov     cx,bx
835         rep movsb
836         add     di,dx
837         dec     ah
838         jne     @@4
839
840         pop     di
841         pop     si
842         ret
843
844 label   DrawTVGA proc
845
846         mov     ax,0a000h
847         mov     es,ax
848         mov     si,OFFSET tdata
849         mov     di,[x]
850         shl     di,3
851         add     di,[VGAlookup+bx]
852         mov     bx,cx
853         shl     bx,2
854         mov     ah,[oldh]
855 @@v1:
856         mov     cx,bx
857         rep movsw
858         add     di,304
859
860         dec     ah
861         jnz     @@v1
862
863         pop     di
864         pop     si
865         ret
866 ENDP
867
868 ;////////////////////////////////////////////////////////////////////
869 ;
870 ; TED5 screen scroll routines!
871 ;
872 ;////////////////////////////////////////////////////////////////////
873 PROC    CopyCGA
874 PUBLIC  CopyCGA
875         ARG     srcx:WORD,srcy:WORD,width:WORD,height:WORD,destx:WORD,desty:WORD
876         USES    si,di
877         push    ds
878
879         mov     ax,0b800h
880         mov     es,ax
881         mov     ds,ax
882         shl     [width],1
883         shl     [destx],1
884         shl     [srcx],1
885
886         mov     ax,[srcy]
887         cmp     ax,[desty]
888         jb      @@1
889         ja      @@2
890         mov     ax,[srcx]
891         cmp     ax,[destx]
892         jb      @@0
893 ;
894 ; Copy from sourcex to destx, right
895 ;
896         mov     dx,[height]
897         mov     bx,[srcy]       ;source & dest are the same!
898         shl     bx,1
899         cld
900
901 @@aa:
902         mov     si,[ss:CGAlookup+bx]
903         mov     di,si
904         add     si,[srcx]
905         add     di,[destx]
906         mov     cx,[width]
907         rep movsb
908         add     bx,2
909         dec     dx
910         jnz     @@aa
911         jz      @@exit
912 ;
913 ; Copy from end of sourcex to end of destx, left
914 ;
915 @@0:
916         mov     dx,[height]
917         mov     bx,[srcy]       ;source & dest are the same!
918         shl     bx,1
919
920 @@0a0:
921         mov     si,[ss:CGAlookup+bx]
922         mov     di,si
923         add     si,[srcx]
924         add     si,[width]
925         dec     si
926         add     di,[destx]
927         add     di,[width]
928         dec     di
929         mov     cx,[width]
930         std
931         rep movsb
932         cld
933         add     bx,2
934         dec     dx
935         jnz     @@0a0
936         jz      @@exit
937 ;
938 ; Copy from end of sourcey to end of desty, up
939 ;
940 @@1:
941         mov     ah,[BYTE height]
942         mov     dl,[BYTE srcy]
943         add     dl,ah
944         dec     dl
945         mov     dh,[BYTE desty]
946         add     dh,ah
947         dec     dh
948         cld
949
950 @@1a0:
951         mov     bx,[srcy]
952         add     bx,[height]
953         dec     bx
954         shl     bx,1
955         mov     si,[ss:CGAlookup+bx]
956         mov     bx,[desty]
957         add     bx,[height]
958         dec     bx
959         shl     bx,1
960         mov     di,[ss:CGAlookup+bx]
961         add     si,[srcx]
962         add     di,[destx]
963         mov     cx,[width]
964         rep movsb
965         dec     [height]
966         jnz     @@1a0
967         jz      @@exit
968 ;
969 ; Copy from sourcey to desty, down
970 ;
971 @@2:
972         mov     ah,[BYTE height]
973         mov     dl,[BYTE srcy]
974         mov     dh,[BYTE desty]
975         cld
976
977 @@2a0:
978         mov     bx,[srcy]
979         shl     bx,1
980         mov     si,[ss:CGAlookup+bx]
981         mov     bx,[desty]
982         shl     bx,1
983         mov     di,[ss:CGAlookup+bx]
984         add     si,[srcx]
985         add     di,[destx]
986         mov     cx,[width]
987         rep movsb
988         inc     [srcy]
989         inc     [desty]
990         dec     [height]
991         jnz     @@2a0
992         jz      @@exit
993 @@exit:
994         pop     ds
995         ret
996 ENDP
997
998
999 PROC    CopyEGA
1000 PUBLIC  CopyEGA
1001         ARG     srcx:WORD,srcy:WORD,width:WORD,height:WORD,destx:WORD,desty:WORD
1002         USES    si,di
1003         push    ds
1004
1005         mov     dx,GCindex
1006         mov     ax,GCmode OR 100h
1007         out     dx,ax
1008
1009         mov     ax,0a000h
1010         mov     es,ax
1011         mov     ds,ax
1012
1013         mov     ax,[srcy]
1014         cmp     ax,[desty]
1015         jb      @@1
1016         ja      @@2
1017         mov     ax,[srcx]
1018         cmp     ax,[destx]
1019         jb      @@0
1020 ;
1021 ; Copy from sourcex to destx, right
1022 ;
1023         mov     dx,[height]
1024         mov     bx,[srcy]       ;source & dest are the same!
1025         shl     bx,1
1026         cld
1027
1028         cmp     [ss:videomode],2
1029         jb      @@a
1030 @@aa:
1031         mov     si,[ss:EGA2lookup+bx]
1032         mov     di,si
1033         add     si,[srcx]
1034         add     di,[destx]
1035         mov     cx,[width]
1036         rep movsb
1037         add     bx,2
1038         dec     dx
1039         jnz     @@aa
1040         jz      @@exit
1041 @@a:
1042         mov     si,[ss:EGA1lookup+bx]
1043         mov     di,si
1044         add     si,[srcx]
1045         add     di,[destx]
1046         mov     cx,[width]
1047         rep movsb
1048         add     bx,2
1049         dec     dx
1050         jnz     @@a
1051         jz      @@exit
1052 ;
1053 ; Copy from end of sourcex to end of destx, left
1054 ;
1055 @@0:
1056         mov     dx,[height]
1057         mov     bx,[srcy]       ;source & dest are the same!
1058         shl     bx,1
1059
1060         cmp     [ss:videomode],2
1061         jb      @@0a
1062 @@0a0:
1063         mov     si,[ss:EGA2lookup+bx]
1064         mov     di,si
1065         add     si,[srcx]
1066         add     si,[width]
1067         dec     si
1068         add     di,[destx]
1069         add     di,[width]
1070         dec     di
1071         mov     cx,[width]
1072         std
1073         rep movsb
1074         cld
1075         add     bx,2
1076         dec     dx
1077         jnz     @@0a0
1078         jz      @@exit
1079 @@0a:
1080         mov     si,[ss:EGA1lookup+bx]
1081         mov     di,si
1082         add     si,[srcx]
1083         add     si,[width]
1084         dec     si
1085         add     di,[destx]
1086         add     di,[width]
1087         dec     di
1088         mov     cx,[width]
1089         std
1090         rep movsb
1091         cld
1092         add     bx,2
1093         dec     dx
1094         jnz     @@0a
1095         jz      @@exit
1096 ;
1097 ; Copy from end of sourcey to end of desty, up
1098 ;
1099 @@1:
1100         mov     ah,[BYTE height]
1101         mov     dl,[BYTE srcy]
1102         add     dl,ah
1103         dec     dl
1104         mov     dh,[BYTE desty]
1105         add     dh,ah
1106         dec     dh
1107         cld
1108
1109         cmp     [ss:videomode],2
1110         jb      @@1a
1111 @@1a0:
1112         mov     bx,[srcy]
1113         add     bx,[height]
1114         dec     bx
1115         shl     bx,1
1116         mov     si,[ss:EGA2lookup+bx]
1117         mov     bx,[desty]
1118         add     bx,[height]
1119         dec     bx
1120         shl     bx,1
1121         mov     di,[ss:EGA2lookup+bx]
1122         add     si,[srcx]
1123         add     di,[destx]
1124         mov     cx,[width]
1125         rep movsb
1126         dec     [height]
1127         jnz     @@1a0
1128         jz      @@exit
1129 @@1a:
1130         mov     bl,dl
1131         xor     bh,bh
1132         shl     bx,1
1133         mov     si,[ss:EGA1lookup+bx]
1134         mov     bl,dh
1135         xor     bh,bh
1136         shl     bx,1
1137         mov     di,[ss:EGA1lookup+bx]
1138         add     si,[srcx]
1139         add     di,[destx]
1140         mov     cx,[width]
1141         rep movsb
1142         dec     dl
1143         dec     dh
1144         dec     ah
1145         jnz     @@1a
1146         jz      @@exit
1147 ;
1148 ; Copy from sourcey to desty, down
1149 ;
1150 @@2:
1151         mov     ah,[BYTE height]
1152         mov     dl,[BYTE srcy]
1153         mov     dh,[BYTE desty]
1154         cld
1155
1156         cmp     [ss:videomode],2
1157         jb      @@2a
1158 @@2a0:
1159         mov     bx,[srcy]
1160         shl     bx,1
1161         mov     si,[ss:EGA2lookup+bx]
1162         mov     bx,[desty]
1163         shl     bx,1
1164         mov     di,[ss:EGA2lookup+bx]
1165         add     si,[srcx]
1166         add     di,[destx]
1167         mov     cx,[width]
1168         rep movsb
1169         inc     [srcy]
1170         inc     [desty]
1171         dec     [height]
1172         jnz     @@2a0
1173         jz      @@exit
1174 @@2a:
1175         mov     bl,dl
1176         xor     bh,bh
1177         shl     bx,1
1178         mov     si,[ss:EGA1lookup+bx]
1179         mov     bl,dh
1180         xor     bh,bh
1181         shl     bx,1
1182         mov     di,[ss:EGA1lookup+bx]
1183         add     si,[srcx]
1184         add     di,[destx]
1185         mov     cx,[width]
1186         rep movsb
1187         inc     dl
1188         inc     dh
1189         dec     ah
1190         jnz     @@2a
1191 @@exit:
1192         pop     ds
1193         ret
1194 ENDP
1195
1196 PROC    CopyVGA
1197 PUBLIC  CopyVGA
1198         ARG     srcx:WORD,srcy:WORD,width:WORD,height:WORD,destx:WORD,desty:WORD
1199         USES    si,di
1200         push    ds
1201
1202         mov     ax,0a000h
1203         mov     es,ax
1204         mov     ds,ax
1205         shl     [width],3
1206         shl     [destx],3
1207         shl     [srcx],3
1208
1209         mov     ax,[srcy]
1210         cmp     ax,[desty]
1211         jb      @@1
1212         ja      @@2
1213         mov     ax,[srcx]
1214         cmp     ax,[destx]
1215         jb      @@0
1216 ;
1217 ; Copy from sourcex to destx, right
1218 ;
1219         mov     dx,[height]
1220         mov     bx,[srcy]       ;source & dest are the same!
1221         shl     bx,1
1222         cld
1223
1224 @@aa:
1225         mov     si,[ss:VGAlookup+bx]
1226         mov     di,si
1227         add     si,[srcx]
1228         add     di,[destx]
1229         mov     cx,[width]
1230         rep movsb
1231         add     bx,2
1232         dec     dx
1233         jnz     @@aa
1234         jz      @@exit
1235 ;
1236 ; Copy from end of sourcex to end of destx, left
1237 ;
1238 @@0:
1239         mov     dx,[height]
1240         mov     bx,[srcy]       ;source & dest are the same!
1241         shl     bx,1
1242
1243 @@0a0:
1244         mov     si,[ss:VGAlookup+bx]
1245         mov     di,si
1246         add     si,[srcx]
1247         add     si,[width]
1248         dec     si
1249         add     di,[destx]
1250         add     di,[width]
1251         dec     di
1252         mov     cx,[width]
1253         std
1254         rep movsb
1255         cld
1256         add     bx,2
1257         dec     dx
1258         jnz     @@0a0
1259         jz      @@exit
1260 ;
1261 ; Copy from end of sourcey to end of desty, up
1262 ;
1263 @@1:
1264         mov     ah,[BYTE height]
1265         mov     dl,[BYTE srcy]
1266         add     dl,ah
1267         dec     dl
1268         mov     dh,[BYTE desty]
1269         add     dh,ah
1270         dec     dh
1271         cld
1272
1273 @@1a0:
1274         mov     bx,[srcy]
1275         add     bx,[height]
1276         dec     bx
1277         shl     bx,1
1278         mov     si,[ss:VGAlookup+bx]
1279         mov     bx,[desty]
1280         add     bx,[height]
1281         dec     bx
1282         shl     bx,1
1283         mov     di,[ss:VGAlookup+bx]
1284         add     si,[srcx]
1285         add     di,[destx]
1286         mov     cx,[width]
1287         rep movsb
1288         dec     [height]
1289         jnz     @@1a0
1290         jz      @@exit
1291 ;
1292 ; Copy from sourcey to desty, down
1293 ;
1294 @@2:
1295         mov     ah,[BYTE height]
1296         mov     dl,[BYTE srcy]
1297         mov     dh,[BYTE desty]
1298         cld
1299
1300 @@2a0:
1301         mov     bx,[srcy]
1302         shl     bx,1
1303         mov     si,[ss:VGAlookup+bx]
1304         mov     bx,[desty]
1305         shl     bx,1
1306         mov     di,[ss:VGAlookup+bx]
1307         add     si,[srcx]
1308         add     di,[destx]
1309         mov     cx,[width]
1310         rep movsb
1311         inc     [srcy]
1312         inc     [desty]
1313         dec     [height]
1314         jnz     @@2a0
1315         jz      @@exit
1316 @@exit:
1317         pop     ds
1318         ret
1319 ENDP
1320
1321 ;////////////////////////////////////////////////////////////////////
1322 ;
1323 ; OVERLAY routine
1324 ;
1325 ;////////////////////////////////////////////////////////////////////
1326 PROC    Overlay
1327 PUBLIC  Overlay
1328         ARG     tsize:WORD
1329
1330         push    di
1331         push    si
1332
1333         mov     di,OFFSET tdata
1334         mov     bx,[tsize]
1335         shl     bx,1
1336         mov     si,[videomode]
1337         shl     si,1
1338         mov     ax,[OverTable+si]
1339         jmp     ax
1340
1341 LABEL   OverlayCGA      PROC
1342
1343         mov     cx,[csize+bx-2]
1344         shr     cx,1
1345         mov     si,[Csparse+bx-2]
1346 @@c1:   lodsw
1347         or      [di],ax
1348         add     di,2
1349         loop    @@c1
1350
1351         pop     si
1352         pop     di
1353         ret
1354
1355 LABEL   OverlayEGA      PROC
1356
1357         mov     cx,[esize+bx-2]
1358         shr     cx,1
1359         mov     si,[Esparse+bx-2]
1360 @@e1:   lodsw
1361         or      [di],ax
1362         add     di,2
1363         loop    @@e1
1364
1365         pop     si
1366         pop     di
1367         ret
1368
1369 LABEL   OverlayVGA      PROC
1370
1371         mov     cx,[vsize+bx-2]
1372         shr     cx,1
1373         mov     si,[Vsparse+bx-2]
1374 @@v1:   lodsw
1375         or      [di],ax
1376         add     di,2
1377         loop    @@v1
1378
1379         pop     si
1380         pop     di
1381         ret
1382
1383 ENDP
1384
1385 END