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-10-19 09:01:56 $
17 ; Routines to access ModeX VGA memory
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.3 2001/01/31 14:04:44 bradleyb
21 ; Fix compiler warnings
23 ; Revision 1.2 2001/01/29 13:35:08 bradleyb
24 ; Fixed build system, minor fixes
26 ; Revision 1.1.1.1 2001/01/19 03:30:15 bradleyb
29 ; Revision 1.1.1.1 1999/06/14 21:57:56 donut
30 ; Import of d1x 1.37 source.
32 ; Revision 1.19 1995/03/01 15:37:46 john
33 ; Better ModeX support.
35 ; Revision 1.18 1994/11/24 13:24:20 john
36 ; Made sure that some rep movs had the cld set first.
37 ; Took some unused functions out.
39 ; Revision 1.17 1994/09/22 18:15:02 john
40 ; Made flip page wait for retrace.
42 ; Revision 1.16 1994/09/22 16:08:27 john
43 ; Fixed some palette stuff.
45 ; Revision 1.15 1994/07/13 12:03:05 john
46 ; Added assembly modex line-drawer.
48 ; Revision 1.14 1994/05/06 12:50:34 john
49 ; Added supertransparency; neatend things up; took out warnings.
51 ; Revision 1.13 1994/05/03 19:39:04 john
52 ; *** empty log message ***
54 ; Revision 1.12 1994/02/18 15:32:32 john
55 ; *** empty log message ***
57 ; Revision 1.11 1993/12/21 11:40:36 john
58 ; *** empty log message ***
60 ; Revision 1.10 1993/12/09 15:02:26 john
61 ; Changed palette stuff majorly
63 ; Revision 1.9 1993/12/03 12:11:32 john
64 ; fixed cx/ecx loop bugs.
66 ; Revision 1.8 1993/11/16 11:28:18 john
67 ; *** empty log message ***
69 ; Revision 1.7 1993/10/15 16:23:23 john
72 ; Revision 1.6 1993/09/28 19:07:19 john
73 ; stripped the waitforretrace out of fade to speed things up.
75 ; Revision 1.5 1993/09/26 18:58:58 john
78 ; Revision 1.4 1993/09/21 14:01:15 john
79 ; turned off video before mode set to reduce flicker.
81 ; Revision 1.3 1993/09/08 11:38:36 john
82 ; changed rcs stuff at beginning.
91 %include "dos_vgaregs.inc"
92 %include "dos_tweak.inc"
95 extern _gr_video_memory
97 global _modex_line_vertincr
98 global _modex_line_incr1
99 global _modex_line_incr2
100 global _modex_line_x1
101 global _modex_line_x2
102 global _modex_line_y1
103 global _modex_line_y2
104 global _modex_line_Color
106 _modex_line_vertincr dd 0
107 _modex_line_incr1 dd 0
108 _modex_line_incr2 dd 0
113 _modex_line_Color db 0
116 _modex_line_routine dd 0
119 %define LEFT_MASK1 1000b
120 %define LEFT_MASK2 1100b
121 %define LEFT_MASK3 1110b
122 %define RIGHT_MASK1 0001b
123 %define RIGHT_MASK2 0011b
124 %define RIGHT_MASK3 0111b
125 %define ALL_MASK 1111b
127 tmppal times 768 db 0
132 MaskTable1 db ALL_MASK & RIGHT_MASK1
133 db ALL_MASK & RIGHT_MASK2
134 db ALL_MASK & RIGHT_MASK3
136 db LEFT_MASK3 & RIGHT_MASK1
137 db LEFT_MASK3 & RIGHT_MASK2
138 db LEFT_MASK3 & RIGHT_MASK3
140 db LEFT_MASK2 & RIGHT_MASK1
141 db LEFT_MASK2 & RIGHT_MASK2
142 db LEFT_MASK2 & RIGHT_MASK3
144 db LEFT_MASK1 & RIGHT_MASK1
145 db LEFT_MASK1 & RIGHT_MASK2
146 db LEFT_MASK1 & RIGHT_MASK3
149 MaskTable2 db ALL_MASK,RIGHT_MASK1
150 db ALL_MASK,RIGHT_MASK2
151 db ALL_MASK,RIGHT_MASK3
153 db LEFT_MASK3,RIGHT_MASK1
154 db LEFT_MASK3,RIGHT_MASK2
155 db LEFT_MASK3,RIGHT_MASK3
156 db LEFT_MASK3,ALL_MASK
157 db LEFT_MASK2,RIGHT_MASK1
158 db LEFT_MASK2,RIGHT_MASK2
159 db LEFT_MASK2,RIGHT_MASK3
160 db LEFT_MASK2,ALL_MASK
161 db LEFT_MASK1,RIGHT_MASK1
162 db LEFT_MASK1,RIGHT_MASK2
163 db LEFT_MASK1,RIGHT_MASK3
164 db LEFT_MASK1,ALL_MASK
185 global _gr_sync_display
191 jnz VS2A ; Loop until not in vertical retrace
194 jz VS2B ; Loop until in vertical retrace
198 ; gr_modex_uscanline(int x1,int x2,int y,int color);
199 global _gr_modex_uscanline
206 mov ecx,[esp+20];color
209 ; EAX = X1 (X1 and X2 don't need to be sorted)
216 ;mov ebx, _RowOffset[ebx*4]
217 mov edi, [_gr_var_bwidth]
219 add edi, [_gr_video_memory]
229 ; BX = LeftRight switch command. (4bit)
233 ; EDI = Offset into video memory
236 ; ECX = X2/4 - X1/4 - 1
239 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
245 mov al, [MaskTable1+ebx]
248 mov [edi], al ; Write the one pixel
257 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
259 mov cx, word [MaskTable2+ebx*2]
267 mov [edi], bl ; Write the left pixel
270 mov [edi+1], bl ; Write the right pixel
275 ;========================= MANY GROUPS OF 4 TO DRAW ======================
284 ; AL,AH = color of pixel
285 jmp dword [DrawTable+ebx*4]
288 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
295 rep stosw ; Write the middle pixels
297 stosb ; Write the middle odd pixel
303 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
304 mov al, byte [MaskTable2+ebx*2]
306 mov [edi], ah ; Write leftmost pixels
314 rep stosw ; Write the middle pixels
316 stosb ; Write the middle odd pixel
322 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
323 mov bx, word [MaskTable2+ebx*2]
326 mov [edi], ah ; Write leftmost pixels
333 rep stosw ; Write the middle pixels
335 stosb ; Write the middle odd pixel
338 mov [edi], ah ; Write the rightmost pixels
343 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
344 mov bx, word [MaskTable2+ebx*2]
351 rep stosw ; Write the middle pixels
353 stosb ; Write the middle odd pixel
356 mov [edi], ah ; Write the rightmost pixels
362 global _gr_modex_setmode
379 ;call turn_screen_off
381 push ecx ; some bios's dont preserve cx
384 ;mov bl, 31h ; disable palette loading at mode switch
386 mov ax,13h ; let the BIOS set standard 256-color
387 int 10h ; mode (320x200 linear)
389 ;mov bl, 31h ; enable palette loading at mode switch
396 out dx,ax ; disable chain4 mode
400 out dx,ax ; synchronous reset while setting Misc
401 ; Output for safety, even though clock
404 mov esi, dword [ModeTable+ecx*4]
411 out dx,al ; select the dot clock and Horiz
425 out dx,ax ; undo reset (restart sequencer)
427 mov dx,CRTC_INDEX ; reprogram the CRT Controller
428 mov al,11h ; VSync End reg contains register write
429 out dx,al ; protect bit
430 inc dx ; CRT Controller Data register
431 in al,dx ; get current VSync End register setting
432 and al,07fh ; remove write protect on various
433 out dx,al ; CRTC registers
434 dec dx ; CRT Controller Index
441 lodsw ; get the next CRT Index/Data pair
442 out dx,ax ; set the next CRT Index/Data pair
447 out dx,ax ; enable writes to all four planes
448 mov edi, [_gr_video_memory] ; point ES:DI to display memory
449 xor eax,eax ; clear to zero-value pixels
450 mov ecx,4000h ; # of dwords in display memory
451 rep stosd ; clear all of display memory
453 ; Set pysical screen dimensions
456 lodsw ; Load scrn pixel width
481 lodsw ; Load Screen Phys. Height
492 global _gr_modex_setplane
500 and cl,011b ;CL = plane
501 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
502 shl ah,cl ;set only the bit for the required
504 mov dx,SC_INDEX ;set the Map Mask to enable only the
505 out dx,ax ; pixel's plane
508 mov ah,cl ;AH = plane
509 mov al,READ_MAP ;AL = index in GC of the Read Map reg
510 mov dx,GC_INDEX ;set the Read Map to read the pixel's
514 global _gr_modex_setstart
525 ; EBX = Wait for retrace
527 mov ecx, [_gr_var_bwidth]
547 out dx, ax ; Start address low
549 out dx, ax ; Start address high
558 jz WaitVS ; Loop until in vertical retrace
569 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
573 imul eax, [_gr_var_bwidth]
575 add ebx, [_gr_video_memory]
579 ;-----------------------------------------------------------------------
581 ; Line drawing function for all MODE X 256 Color resolutions
582 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
584 global _gr_modex_line
589 mov dx,SC_INDEX ; setup for plane mask access
591 ; check for vertical line
593 mov esi,[_gr_var_bwidth]
594 mov ecx,[_modex_line_x2]
595 sub ecx,[_modex_line_x1]
604 mov ebx,[_modex_line_x2]
605 xchg ebx,[_modex_line_x1]
606 mov [_modex_line_x2],ebx
608 mov ebx,[_modex_line_y2]
609 xchg ebx,[_modex_line_y1]
610 mov [_modex_line_y2],ebx
612 ; calc dy = abs(y2 - y1)
615 mov ebx,[_modex_line_y2]
616 sub ebx,[_modex_line_y1]
624 ; select appropriate routine for slope of line
627 mov [_modex_line_vertincr],esi
628 mov dword [_modex_line_routine],LoSlopeLine
631 mov dword [_modex_line_routine],HiSlopeLine
634 ; calc initial decision variable and increments
638 mov [_modex_line_incr1],ebx
642 mov [_modex_line_incr2],ebx
644 ; calc first pixel address
647 mov eax,[_modex_line_y1]
648 mov ebx,[_modex_line_x1]
653 mov ah,al ; duplicate nybble
659 jmp near dword [_modex_line_routine]
661 ; routine for verticle lines
664 mov eax,[_modex_line_y1]
665 mov ebx,[_modex_line_y2]
674 mov ebx,[_modex_line_x1]
683 mov ax, word [_modex_line_Color]
693 ; routine for horizontal line
697 mov eax,[_modex_line_y1]
698 mov ebx,[_modex_line_x1]
701 mov edi,ebx ; set dl = first byte mask
705 mov ecx,[_modex_line_x2] ; set dh = last byte mask
711 ; determine byte offset of first and last pixel in line
713 mov eax,[_modex_line_x2]
714 mov ebx,[_modex_line_x1]
716 shr eax,2 ; set ax = last byte column
717 shr ebx,2 ; set bx = first byte column
718 mov ecx,eax ; cx = ax - bx
721 mov eax,edx ; mov end byte masks to ax
722 mov dx,SC_INDEX ; setup dx for VGA outs
723 mov bl,[_modex_line_Color]
725 ; set pixels in leftmost byte of line
727 or ecx,ecx ; is start and end pt in same byte
729 and ah,al ; combine start and end masks
740 ; draw remainder of the line
750 ; set pixels in rightmost byte of line
759 ; routine for dy >= dx (slope <= 1)
763 mov bh,byte [_modex_line_Color]
772 ; bit mask not shifted out
776 add esi,[_modex_line_incr1]
784 add esi,[_modex_line_incr2]
787 add edi,[_modex_line_vertincr]
791 ; bit mask shifted out
798 add esi,[_modex_line_incr1]
803 add esi,[_modex_line_incr2]
804 add edi,[_modex_line_vertincr]
808 ; routine for dy > dx (slope > 1)
811 mov ebx,[_modex_line_vertincr]
815 mov al,[_modex_line_Color]
824 add esi,[_modex_line_incr1]
829 add esi,[_modex_line_incr2]