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-31 14:04:44 $
17 ; Routines to access ModeX VGA memory
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.2 2001/01/29 13:35:08 bradleyb
21 ; Fixed build system, minor fixes
23 ; Revision 1.1.1.1 2001/01/19 03:30:15 bradleyb
26 ; Revision 1.1.1.1 1999/06/14 21:57:56 donut
27 ; Import of d1x 1.37 source.
29 ; Revision 1.19 1995/03/01 15:37:46 john
30 ; Better ModeX support.
32 ; Revision 1.18 1994/11/24 13:24:20 john
33 ; Made sure that some rep movs had the cld set first.
34 ; Took some unused functions out.
36 ; Revision 1.17 1994/09/22 18:15:02 john
37 ; Made flip page wait for retrace.
39 ; Revision 1.16 1994/09/22 16:08:27 john
40 ; Fixed some palette stuff.
42 ; Revision 1.15 1994/07/13 12:03:05 john
43 ; Added assembly modex line-drawer.
45 ; Revision 1.14 1994/05/06 12:50:34 john
46 ; Added supertransparency; neatend things up; took out warnings.
48 ; Revision 1.13 1994/05/03 19:39:04 john
49 ; *** empty log message ***
51 ; Revision 1.12 1994/02/18 15:32:32 john
52 ; *** empty log message ***
54 ; Revision 1.11 1993/12/21 11:40:36 john
55 ; *** empty log message ***
57 ; Revision 1.10 1993/12/09 15:02:26 john
58 ; Changed palette stuff majorly
60 ; Revision 1.9 1993/12/03 12:11:32 john
61 ; fixed cx/ecx loop bugs.
63 ; Revision 1.8 1993/11/16 11:28:18 john
64 ; *** empty log message ***
66 ; Revision 1.7 1993/10/15 16:23:23 john
69 ; Revision 1.6 1993/09/28 19:07:19 john
70 ; stripped the waitforretrace out of fade to speed things up.
72 ; Revision 1.5 1993/09/26 18:58:58 john
75 ; Revision 1.4 1993/09/21 14:01:15 john
76 ; turned off video before mode set to reduce flicker.
78 ; Revision 1.3 1993/09/08 11:38:36 john
79 ; changed rcs stuff at beginning.
88 %include "dos_vgaregs.inc"
89 %include "dos_tweak.inc"
92 extern _gr_video_memory
94 global _modex_line_vertincr
95 global _modex_line_incr1
96 global _modex_line_incr2
100 global _modex_line_y2
101 global _modex_line_Color
103 _modex_line_vertincr dd 0
104 _modex_line_incr1 dd 0
105 _modex_line_incr2 dd 0
110 _modex_line_Color db 0
113 _modex_line_routine dd 0
116 %define LEFT_MASK1 1000b
117 %define LEFT_MASK2 1100b
118 %define LEFT_MASK3 1110b
119 %define RIGHT_MASK1 0001b
120 %define RIGHT_MASK2 0011b
121 %define RIGHT_MASK3 0111b
122 %define ALL_MASK 1111b
124 tmppal times 768 db 0
129 MaskTable1 db ALL_MASK & RIGHT_MASK1
130 db ALL_MASK & RIGHT_MASK2
131 db ALL_MASK & RIGHT_MASK3
133 db LEFT_MASK3 & RIGHT_MASK1
134 db LEFT_MASK3 & RIGHT_MASK2
135 db LEFT_MASK3 & RIGHT_MASK3
137 db LEFT_MASK2 & RIGHT_MASK1
138 db LEFT_MASK2 & RIGHT_MASK2
139 db LEFT_MASK2 & RIGHT_MASK3
141 db LEFT_MASK1 & RIGHT_MASK1
142 db LEFT_MASK1 & RIGHT_MASK2
143 db LEFT_MASK1 & RIGHT_MASK3
146 MaskTable2 db ALL_MASK,RIGHT_MASK1
147 db ALL_MASK,RIGHT_MASK2
148 db ALL_MASK,RIGHT_MASK3
150 db LEFT_MASK3,RIGHT_MASK1
151 db LEFT_MASK3,RIGHT_MASK2
152 db LEFT_MASK3,RIGHT_MASK3
153 db LEFT_MASK3,ALL_MASK
154 db LEFT_MASK2,RIGHT_MASK1
155 db LEFT_MASK2,RIGHT_MASK2
156 db LEFT_MASK2,RIGHT_MASK3
157 db LEFT_MASK2,ALL_MASK
158 db LEFT_MASK1,RIGHT_MASK1
159 db LEFT_MASK1,RIGHT_MASK2
160 db LEFT_MASK1,RIGHT_MASK3
161 db LEFT_MASK1,ALL_MASK
182 global _gr_sync_display
188 jnz VS2A ; Loop until not in vertical retrace
191 jz VS2B ; Loop until in vertical retrace
195 ; gr_modex_uscanline(int x1,int x2,int y,int color);
196 global _gr_modex_uscanline
203 mov ecx,[esp+20];color
206 ; EAX = X1 (X1 and X2 don't need to be sorted)
213 ;mov ebx, _RowOffset[ebx*4]
214 mov edi, [_gr_var_bwidth]
216 add edi, [_gr_video_memory]
226 ; BX = LeftRight switch command. (4bit)
230 ; EDI = Offset into video memory
233 ; ECX = X2/4 - X1/4 - 1
236 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
242 mov al, [MaskTable1+ebx]
245 mov [edi], al ; Write the one pixel
254 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
256 mov cx, word [MaskTable2+ebx*2]
264 mov [edi], bl ; Write the left pixel
267 mov [edi+1], bl ; Write the right pixel
272 ;========================= MANY GROUPS OF 4 TO DRAW ======================
281 ; AL,AH = color of pixel
282 jmp dword [DrawTable+ebx*4]
285 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
292 rep stosw ; Write the middle pixels
294 stosb ; Write the middle odd pixel
300 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
301 mov al, byte [MaskTable2+ebx*2]
303 mov [edi], ah ; Write leftmost pixels
311 rep stosw ; Write the middle pixels
313 stosb ; Write the middle odd pixel
319 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
320 mov bx, word [MaskTable2+ebx*2]
323 mov [edi], ah ; Write leftmost pixels
330 rep stosw ; Write the middle pixels
332 stosb ; Write the middle odd pixel
335 mov [edi], ah ; Write the rightmost pixels
340 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
341 mov bx, word [MaskTable2+ebx*2]
348 rep stosw ; Write the middle pixels
350 stosb ; Write the middle odd pixel
353 mov [edi], ah ; Write the rightmost pixels
359 global _gr_modex_setmode
376 ;call turn_screen_off
378 push ecx ; some bios's dont preserve cx
381 ;mov bl, 31h ; disable palette loading at mode switch
383 mov ax,13h ; let the BIOS set standard 256-color
384 int 10h ; mode (320x200 linear)
386 ;mov bl, 31h ; enable palette loading at mode switch
393 out dx,ax ; disable chain4 mode
397 out dx,ax ; synchronous reset while setting Misc
398 ; Output for safety, even though clock
401 mov esi, dword [ModeTable+ecx*4]
408 out dx,al ; select the dot clock and Horiz
422 out dx,ax ; undo reset (restart sequencer)
424 mov dx,CRTC_INDEX ; reprogram the CRT Controller
425 mov al,11h ; VSync End reg contains register write
426 out dx,al ; protect bit
427 inc dx ; CRT Controller Data register
428 in al,dx ; get current VSync End register setting
429 and al,07fh ; remove write protect on various
430 out dx,al ; CRTC registers
431 dec dx ; CRT Controller Index
438 lodsw ; get the next CRT Index/Data pair
439 out dx,ax ; set the next CRT Index/Data pair
444 out dx,ax ; enable writes to all four planes
445 mov edi, [_gr_video_memory] ; point ES:DI to display memory
446 xor eax,eax ; clear to zero-value pixels
447 mov ecx,4000h ; # of dwords in display memory
448 rep stosd ; clear all of display memory
450 ; Set pysical screen dimensions
453 lodsw ; Load scrn pixel width
478 lodsw ; Load Screen Phys. Height
489 global _gr_modex_setplane
497 and cl,011b ;CL = plane
498 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
499 shl ah,cl ;set only the bit for the required
501 mov dx,SC_INDEX ;set the Map Mask to enable only the
502 out dx,ax ; pixel's plane
505 mov ah,cl ;AH = plane
506 mov al,READ_MAP ;AL = index in GC of the Read Map reg
507 mov dx,GC_INDEX ;set the Read Map to read the pixel's
511 global _gr_modex_setstart
522 ; EBX = Wait for retrace
524 mov ecx, [_gr_var_bwidth]
544 out dx, ax ; Start address low
546 out dx, ax ; Start address high
555 jz WaitVS ; Loop until in vertical retrace
566 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
570 imul eax, [_gr_var_bwidth]
572 add ebx, [_gr_video_memory]
576 ;-----------------------------------------------------------------------
578 ; Line drawing function for all MODE X 256 Color resolutions
579 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
581 global _gr_modex_line
586 mov dx,SC_INDEX ; setup for plane mask access
588 ; check for vertical line
590 mov esi,[_gr_var_bwidth]
591 mov ecx,[_modex_line_x2]
592 sub ecx,[_modex_line_x1]
601 mov ebx,[_modex_line_x2]
602 xchg ebx,[_modex_line_x1]
603 mov [_modex_line_x2],ebx
605 mov ebx,[_modex_line_y2]
606 xchg ebx,[_modex_line_y1]
607 mov [_modex_line_y2],ebx
609 ; calc dy = abs(y2 - y1)
612 mov ebx,[_modex_line_y2]
613 sub ebx,[_modex_line_y1]
621 ; select appropriate routine for slope of line
624 mov [_modex_line_vertincr],esi
625 mov dword [_modex_line_routine],LoSlopeLine
628 mov dword [_modex_line_routine],HiSlopeLine
631 ; calc initial decision variable and increments
635 mov [_modex_line_incr1],ebx
639 mov [_modex_line_incr2],ebx
641 ; calc first pixel address
644 mov eax,[_modex_line_y1]
645 mov ebx,[_modex_line_x1]
650 mov ah,al ; duplicate nybble
656 jmp near dword [_modex_line_routine]
658 ; routine for verticle lines
661 mov eax,[_modex_line_y1]
662 mov ebx,[_modex_line_y2]
671 mov ebx,[_modex_line_x1]
680 mov ax, word [_modex_line_Color]
690 ; routine for horizontal line
694 mov eax,[_modex_line_y1]
695 mov ebx,[_modex_line_x1]
698 mov edi,ebx ; set dl = first byte mask
702 mov ecx,[_modex_line_x2] ; set dh = last byte mask
708 ; determine byte offset of first and last pixel in line
710 mov eax,[_modex_line_x2]
711 mov ebx,[_modex_line_x1]
713 shr eax,2 ; set ax = last byte column
714 shr ebx,2 ; set bx = first byte column
715 mov ecx,eax ; cx = ax - bx
718 mov eax,edx ; mov end byte masks to ax
719 mov dx,SC_INDEX ; setup dx for VGA outs
720 mov bl,[_modex_line_Color]
722 ; set pixels in leftmost byte of line
724 or ecx,ecx ; is start and end pt in same byte
726 and ah,al ; combine start and end masks
737 ; draw remainder of the line
747 ; set pixels in rightmost byte of line
756 ; routine for dy >= dx (slope <= 1)
760 mov bh,byte [_modex_line_Color]
769 ; bit mask not shifted out
773 add esi,[_modex_line_incr1]
781 add esi,[_modex_line_incr2]
784 add edi,[_modex_line_vertincr]
788 ; bit mask shifted out
795 add esi,[_modex_line_incr1]
800 add esi,[_modex_line_incr2]
801 add edi,[_modex_line_vertincr]
805 ; routine for dy > dx (slope > 1)
808 mov ebx,[_modex_line_vertincr]
812 mov al,[_modex_line_Color]
821 add esi,[_modex_line_incr1]
826 add esi,[_modex_line_incr2]