1 ;THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
2 ;SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
3 ;END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
4 ;ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
5 ;IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
6 ;SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
7 ;FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
8 ;CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
9 ;AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
10 ;COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
12 ; $Source: /cvs/cvsroot/d2x/arch/dos_modex.asm,v $
15 ; $Date: 2001-01-29 13:35:08 $
17 ; Routines to access ModeX VGA memory
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1 2001/01/19 03:30:15 bradleyb
23 ; Revision 1.1.1.1 1999/06/14 21:57:56 donut
24 ; Import of d1x 1.37 source.
26 ; Revision 1.19 1995/03/01 15:37:46 john
27 ; Better ModeX support.
29 ; Revision 1.18 1994/11/24 13:24:20 john
30 ; Made sure that some rep movs had the cld set first.
31 ; Took some unused functions out.
33 ; Revision 1.17 1994/09/22 18:15:02 john
34 ; Made flip page wait for retrace.
36 ; Revision 1.16 1994/09/22 16:08:27 john
37 ; Fixed some palette stuff.
39 ; Revision 1.15 1994/07/13 12:03:05 john
40 ; Added assembly modex line-drawer.
42 ; Revision 1.14 1994/05/06 12:50:34 john
43 ; Added supertransparency; neatend things up; took out warnings.
45 ; Revision 1.13 1994/05/03 19:39:04 john
46 ; *** empty log message ***
48 ; Revision 1.12 1994/02/18 15:32:32 john
49 ; *** empty log message ***
51 ; Revision 1.11 1993/12/21 11:40:36 john
52 ; *** empty log message ***
54 ; Revision 1.10 1993/12/09 15:02:26 john
55 ; Changed palette stuff majorly
57 ; Revision 1.9 1993/12/03 12:11:32 john
58 ; fixed cx/ecx loop bugs.
60 ; Revision 1.8 1993/11/16 11:28:18 john
61 ; *** empty log message ***
63 ; Revision 1.7 1993/10/15 16:23:23 john
66 ; Revision 1.6 1993/09/28 19:07:19 john
67 ; stripped the waitforretrace out of fade to speed things up.
69 ; Revision 1.5 1993/09/26 18:58:58 john
72 ; Revision 1.4 1993/09/21 14:01:15 john
73 ; turned off video before mode set to reduce flicker.
75 ; Revision 1.3 1993/09/08 11:38:36 john
76 ; changed rcs stuff at beginning.
85 %include "vgaregs.inc"
89 extern _gr_video_memory
91 global _modex_line_vertincr
92 global _modex_line_incr1
93 global _modex_line_incr2
98 global _modex_line_Color
100 _modex_line_vertincr dd 0
101 _modex_line_incr1 dd 0
102 _modex_line_incr2 dd 0
107 _modex_line_Color db 0
110 _modex_line_routine dd 0
113 %define LEFT_MASK1 1000b
114 %define LEFT_MASK2 1100b
115 %define LEFT_MASK3 1110b
116 %define RIGHT_MASK1 0001b
117 %define RIGHT_MASK2 0011b
118 %define RIGHT_MASK3 0111b
119 %define ALL_MASK 1111b
121 tmppal times 768 db 0
126 MaskTable1 db ALL_MASK & RIGHT_MASK1
127 db ALL_MASK & RIGHT_MASK2
128 db ALL_MASK & RIGHT_MASK3
130 db LEFT_MASK3 & RIGHT_MASK1
131 db LEFT_MASK3 & RIGHT_MASK2
132 db LEFT_MASK3 & RIGHT_MASK3
134 db LEFT_MASK2 & RIGHT_MASK1
135 db LEFT_MASK2 & RIGHT_MASK2
136 db LEFT_MASK2 & RIGHT_MASK3
138 db LEFT_MASK1 & RIGHT_MASK1
139 db LEFT_MASK1 & RIGHT_MASK2
140 db LEFT_MASK1 & RIGHT_MASK3
143 MaskTable2 db ALL_MASK,RIGHT_MASK1
144 db ALL_MASK,RIGHT_MASK2
145 db ALL_MASK,RIGHT_MASK3
147 db LEFT_MASK3,RIGHT_MASK1
148 db LEFT_MASK3,RIGHT_MASK2
149 db LEFT_MASK3,RIGHT_MASK3
150 db LEFT_MASK3,ALL_MASK
151 db LEFT_MASK2,RIGHT_MASK1
152 db LEFT_MASK2,RIGHT_MASK2
153 db LEFT_MASK2,RIGHT_MASK3
154 db LEFT_MASK2,ALL_MASK
155 db LEFT_MASK1,RIGHT_MASK1
156 db LEFT_MASK1,RIGHT_MASK2
157 db LEFT_MASK1,RIGHT_MASK3
158 db LEFT_MASK1,ALL_MASK
179 global _gr_sync_display
185 jnz VS2A ; Loop until not in vertical retrace
188 jz VS2B ; Loop until in vertical retrace
192 ; gr_modex_uscanline(int x1,int x2,int y,int color);
193 global _gr_modex_uscanline
200 mov ecx,[esp+20];color
203 ; EAX = X1 (X1 and X2 don't need to be sorted)
210 ;mov ebx, _RowOffset[ebx*4]
211 mov edi, [_gr_var_bwidth]
213 add edi, [_gr_video_memory]
223 ; BX = LeftRight switch command. (4bit)
227 ; EDI = Offset into video memory
230 ; ECX = X2/4 - X1/4 - 1
233 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
239 mov al, [MaskTable1+ebx]
242 mov [edi], al ; Write the one pixel
251 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
253 mov cx, word [MaskTable2+ebx*2]
261 mov [edi], bl ; Write the left pixel
264 mov [edi+1], bl ; Write the right pixel
269 ;========================= MANY GROUPS OF 4 TO DRAW ======================
278 ; AL,AH = color of pixel
279 jmp dword [DrawTable+ebx*4]
282 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
289 rep stosw ; Write the middle pixels
291 stosb ; Write the middle odd pixel
297 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
298 mov al, byte [MaskTable2+ebx*2]
300 mov [edi], ah ; Write leftmost pixels
308 rep stosw ; Write the middle pixels
310 stosb ; Write the middle odd pixel
316 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
317 mov bx, word [MaskTable2+ebx*2]
320 mov [edi], ah ; Write leftmost pixels
327 rep stosw ; Write the middle pixels
329 stosb ; Write the middle odd pixel
332 mov [edi], ah ; Write the rightmost pixels
337 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
338 mov bx, word [MaskTable2+ebx*2]
345 rep stosw ; Write the middle pixels
347 stosb ; Write the middle odd pixel
350 mov [edi], ah ; Write the rightmost pixels
356 global _gr_modex_setmode
373 ;call turn_screen_off
375 push ecx ; some bios's dont preserve cx
378 ;mov bl, 31h ; disable palette loading at mode switch
380 mov ax,13h ; let the BIOS set standard 256-color
381 int 10h ; mode (320x200 linear)
383 ;mov bl, 31h ; enable palette loading at mode switch
390 out dx,ax ; disable chain4 mode
394 out dx,ax ; synchronous reset while setting Misc
395 ; Output for safety, even though clock
398 mov esi, dword [ModeTable+ecx*4]
405 out dx,al ; select the dot clock and Horiz
419 out dx,ax ; undo reset (restart sequencer)
421 mov dx,CRTC_INDEX ; reprogram the CRT Controller
422 mov al,11h ; VSync End reg contains register write
423 out dx,al ; protect bit
424 inc dx ; CRT Controller Data register
425 in al,dx ; get current VSync End register setting
426 and al,07fh ; remove write protect on various
427 out dx,al ; CRTC registers
428 dec dx ; CRT Controller Index
435 lodsw ; get the next CRT Index/Data pair
436 out dx,ax ; set the next CRT Index/Data pair
441 out dx,ax ; enable writes to all four planes
442 mov edi, [_gr_video_memory] ; point ES:DI to display memory
443 xor eax,eax ; clear to zero-value pixels
444 mov ecx,4000h ; # of dwords in display memory
445 rep stosd ; clear all of display memory
447 ; Set pysical screen dimensions
450 lodsw ; Load scrn pixel width
475 lodsw ; Load Screen Phys. Height
486 global _gr_modex_setplane
494 and cl,011b ;CL = plane
495 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
496 shl ah,cl ;set only the bit for the required
498 mov dx,SC_INDEX ;set the Map Mask to enable only the
499 out dx,ax ; pixel's plane
502 mov ah,cl ;AH = plane
503 mov al,READ_MAP ;AL = index in GC of the Read Map reg
504 mov dx,GC_INDEX ;set the Read Map to read the pixel's
508 global _gr_modex_setstart
519 ; EBX = Wait for retrace
521 mov ecx, [_gr_var_bwidth]
541 out dx, ax ; Start address low
543 out dx, ax ; Start address high
552 jz WaitVS ; Loop until in vertical retrace
563 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
567 imul eax, [_gr_var_bwidth]
569 add ebx, [_gr_video_memory]
573 ;-----------------------------------------------------------------------
575 ; Line drawing function for all MODE X 256 Color resolutions
576 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
578 global _gr_modex_line
583 mov dx,SC_INDEX ; setup for plane mask access
585 ; check for vertical line
587 mov esi,[_gr_var_bwidth]
588 mov ecx,[_modex_line_x2]
589 sub ecx,[_modex_line_x1]
598 mov ebx,[_modex_line_x2]
599 xchg ebx,[_modex_line_x1]
600 mov [_modex_line_x2],ebx
602 mov ebx,[_modex_line_y2]
603 xchg ebx,[_modex_line_y1]
604 mov [_modex_line_y2],ebx
606 ; calc dy = abs(y2 - y1)
609 mov ebx,[_modex_line_y2]
610 sub ebx,[_modex_line_y1]
618 ; select appropriate routine for slope of line
621 mov [_modex_line_vertincr],esi
622 mov dword [_modex_line_routine],LoSlopeLine
625 mov dword [_modex_line_routine],HiSlopeLine
628 ; calc initial decision variable and increments
632 mov [_modex_line_incr1],ebx
636 mov [_modex_line_incr2],ebx
638 ; calc first pixel address
641 mov eax,[_modex_line_y1]
642 mov ebx,[_modex_line_x1]
647 mov ah,al ; duplicate nybble
653 jmp near dword [_modex_line_routine]
655 ; routine for verticle lines
658 mov eax,[_modex_line_y1]
659 mov ebx,[_modex_line_y2]
668 mov ebx,[_modex_line_x1]
677 mov ax, word [_modex_line_Color]
687 ; routine for horizontal line
691 mov eax,[_modex_line_y1]
692 mov ebx,[_modex_line_x1]
695 mov edi,ebx ; set dl = first byte mask
699 mov ecx,[_modex_line_x2] ; set dh = last byte mask
705 ; determine byte offset of first and last pixel in line
707 mov eax,[_modex_line_x2]
708 mov ebx,[_modex_line_x1]
710 shr eax,2 ; set ax = last byte column
711 shr ebx,2 ; set bx = first byte column
712 mov ecx,eax ; cx = ax - bx
715 mov eax,edx ; mov end byte masks to ax
716 mov dx,SC_INDEX ; setup dx for VGA outs
717 mov bl,[_modex_line_Color]
719 ; set pixels in leftmost byte of line
721 or ecx,ecx ; is start and end pt in same byte
723 and ah,al ; combine start and end masks
734 ; draw remainder of the line
744 ; set pixels in rightmost byte of line
753 ; routine for dy >= dx (slope <= 1)
757 mov bh,byte [_modex_line_Color]
766 ; bit mask not shifted out
770 add esi,[_modex_line_incr1]
778 add esi,[_modex_line_incr2]
781 add edi,[_modex_line_vertincr]
785 ; bit mask shifted out
792 add esi,[_modex_line_incr1]
797 add esi,[_modex_line_incr2]
798 add edi,[_modex_line_vertincr]
802 ; routine for dy > dx (slope > 1)
805 mov ebx,[_modex_line_vertincr]
809 mov al,[_modex_line_Color]
818 add esi,[_modex_line_incr1]
823 add esi,[_modex_line_incr2]