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 $
13 ; $Revision: 1.1.1.1 $
15 ; $Date: 2001-01-19 03:33:51 $
17 ; Routines to access ModeX VGA memory
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.1.1.1 1999/06/14 21:57:56 donut
21 ; Import of d1x 1.37 source.
23 ; Revision 1.19 1995/03/01 15:37:46 john
24 ; Better ModeX support.
26 ; Revision 1.18 1994/11/24 13:24:20 john
27 ; Made sure that some rep movs had the cld set first.
28 ; Took some unused functions out.
30 ; Revision 1.17 1994/09/22 18:15:02 john
31 ; Made flip page wait for retrace.
33 ; Revision 1.16 1994/09/22 16:08:27 john
34 ; Fixed some palette stuff.
36 ; Revision 1.15 1994/07/13 12:03:05 john
37 ; Added assembly modex line-drawer.
39 ; Revision 1.14 1994/05/06 12:50:34 john
40 ; Added supertransparency; neatend things up; took out warnings.
42 ; Revision 1.13 1994/05/03 19:39:04 john
43 ; *** empty log message ***
45 ; Revision 1.12 1994/02/18 15:32:32 john
46 ; *** empty log message ***
48 ; Revision 1.11 1993/12/21 11:40:36 john
49 ; *** empty log message ***
51 ; Revision 1.10 1993/12/09 15:02:26 john
52 ; Changed palette stuff majorly
54 ; Revision 1.9 1993/12/03 12:11:32 john
55 ; fixed cx/ecx loop bugs.
57 ; Revision 1.8 1993/11/16 11:28:18 john
58 ; *** empty log message ***
60 ; Revision 1.7 1993/10/15 16:23:23 john
63 ; Revision 1.6 1993/09/28 19:07:19 john
64 ; stripped the waitforretrace out of fade to speed things up.
66 ; Revision 1.5 1993/09/26 18:58:58 john
69 ; Revision 1.4 1993/09/21 14:01:15 john
70 ; turned off video before mode set to reduce flicker.
72 ; Revision 1.3 1993/09/08 11:38:36 john
73 ; changed rcs stuff at beginning.
82 %include "dos_vgaregs.inc"
83 %include "dos_tweak.inc"
86 extern _gr_video_memory
88 global _modex_line_vertincr
89 global _modex_line_incr1
90 global _modex_line_incr2
95 global _modex_line_Color
97 _modex_line_vertincr dd 0
98 _modex_line_incr1 dd 0
99 _modex_line_incr2 dd 0
104 _modex_line_Color db 0
107 _modex_line_routine dd 0
110 %define LEFT_MASK1 1000b
111 %define LEFT_MASK2 1100b
112 %define LEFT_MASK3 1110b
113 %define RIGHT_MASK1 0001b
114 %define RIGHT_MASK2 0011b
115 %define RIGHT_MASK3 0111b
116 %define ALL_MASK 1111b
118 tmppal times 768 db 0
123 MaskTable1 db ALL_MASK & RIGHT_MASK1
124 db ALL_MASK & RIGHT_MASK2
125 db ALL_MASK & RIGHT_MASK3
127 db LEFT_MASK3 & RIGHT_MASK1
128 db LEFT_MASK3 & RIGHT_MASK2
129 db LEFT_MASK3 & RIGHT_MASK3
131 db LEFT_MASK2 & RIGHT_MASK1
132 db LEFT_MASK2 & RIGHT_MASK2
133 db LEFT_MASK2 & RIGHT_MASK3
135 db LEFT_MASK1 & RIGHT_MASK1
136 db LEFT_MASK1 & RIGHT_MASK2
137 db LEFT_MASK1 & RIGHT_MASK3
140 MaskTable2 db ALL_MASK,RIGHT_MASK1
141 db ALL_MASK,RIGHT_MASK2
142 db ALL_MASK,RIGHT_MASK3
144 db LEFT_MASK3,RIGHT_MASK1
145 db LEFT_MASK3,RIGHT_MASK2
146 db LEFT_MASK3,RIGHT_MASK3
147 db LEFT_MASK3,ALL_MASK
148 db LEFT_MASK2,RIGHT_MASK1
149 db LEFT_MASK2,RIGHT_MASK2
150 db LEFT_MASK2,RIGHT_MASK3
151 db LEFT_MASK2,ALL_MASK
152 db LEFT_MASK1,RIGHT_MASK1
153 db LEFT_MASK1,RIGHT_MASK2
154 db LEFT_MASK1,RIGHT_MASK3
155 db LEFT_MASK1,ALL_MASK
176 global _gr_sync_display
182 jnz VS2A ; Loop until not in vertical retrace
185 jz VS2B ; Loop until in vertical retrace
189 ; gr_modex_uscanline(int x1,int x2,int y,int color);
190 global _gr_modex_uscanline
197 mov ecx,[esp+20];color
200 ; EAX = X1 (X1 and X2 don't need to be sorted)
207 ;mov ebx, _RowOffset[ebx*4]
208 mov edi, [_gr_var_bwidth]
210 add edi, [_gr_video_memory]
220 ; BX = LeftRight switch command. (4bit)
224 ; EDI = Offset into video memory
227 ; ECX = X2/4 - X1/4 - 1
230 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
236 mov al, [MaskTable1+ebx]
239 mov [edi], al ; Write the one pixel
248 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
250 mov cx, word [MaskTable2+ebx*2]
258 mov [edi], bl ; Write the left pixel
261 mov [edi+1], bl ; Write the right pixel
266 ;========================= MANY GROUPS OF 4 TO DRAW ======================
275 ; AL,AH = color of pixel
276 jmp dword [DrawTable+ebx*4]
279 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
286 rep stosw ; Write the middle pixels
288 stosb ; Write the middle odd pixel
294 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
295 mov al, byte [MaskTable2+ebx*2]
297 mov [edi], ah ; Write leftmost pixels
305 rep stosw ; Write the middle pixels
307 stosb ; Write the middle odd pixel
313 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
314 mov bx, word [MaskTable2+ebx*2]
317 mov [edi], ah ; Write leftmost pixels
324 rep stosw ; Write the middle pixels
326 stosb ; Write the middle odd pixel
329 mov [edi], ah ; Write the rightmost pixels
334 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
335 mov bx, word [MaskTable2+ebx*2]
342 rep stosw ; Write the middle pixels
344 stosb ; Write the middle odd pixel
347 mov [edi], ah ; Write the rightmost pixels
353 global _gr_modex_setmode
370 ;call turn_screen_off
372 push ecx ; some bios's dont preserve cx
375 ;mov bl, 31h ; disable palette loading at mode switch
377 mov ax,13h ; let the BIOS set standard 256-color
378 int 10h ; mode (320x200 linear)
380 ;mov bl, 31h ; enable palette loading at mode switch
387 out dx,ax ; disable chain4 mode
391 out dx,ax ; synchronous reset while setting Misc
392 ; Output for safety, even though clock
395 mov esi, dword [ModeTable+ecx*4]
402 out dx,al ; select the dot clock and Horiz
416 out dx,ax ; undo reset (restart sequencer)
418 mov dx,CRTC_INDEX ; reprogram the CRT Controller
419 mov al,11h ; VSync End reg contains register write
420 out dx,al ; protect bit
421 inc dx ; CRT Controller Data register
422 in al,dx ; get current VSync End register setting
423 and al,07fh ; remove write protect on various
424 out dx,al ; CRTC registers
425 dec dx ; CRT Controller Index
432 lodsw ; get the next CRT Index/Data pair
433 out dx,ax ; set the next CRT Index/Data pair
438 out dx,ax ; enable writes to all four planes
439 mov edi, [_gr_video_memory] ; point ES:DI to display memory
440 xor eax,eax ; clear to zero-value pixels
441 mov ecx,4000h ; # of dwords in display memory
442 rep stosd ; clear all of display memory
444 ; Set pysical screen dimensions
447 lodsw ; Load scrn pixel width
472 lodsw ; Load Screen Phys. Height
483 global _gr_modex_setplane
491 and cl,011b ;CL = plane
492 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
493 shl ah,cl ;set only the bit for the required
495 mov dx,SC_INDEX ;set the Map Mask to enable only the
496 out dx,ax ; pixel's plane
499 mov ah,cl ;AH = plane
500 mov al,READ_MAP ;AL = index in GC of the Read Map reg
501 mov dx,GC_INDEX ;set the Read Map to read the pixel's
505 global _gr_modex_setstart
516 ; EBX = Wait for retrace
518 mov ecx, [_gr_var_bwidth]
538 out dx, ax ; Start address low
540 out dx, ax ; Start address high
549 jz WaitVS ; Loop until in vertical retrace
560 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
564 imul eax, [_gr_var_bwidth]
566 add ebx, [_gr_video_memory]
570 ;-----------------------------------------------------------------------
572 ; Line drawing function for all MODE X 256 Color resolutions
573 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
575 global _gr_modex_line
580 mov dx,SC_INDEX ; setup for plane mask access
582 ; check for vertical line
584 mov esi,[_gr_var_bwidth]
585 mov ecx,[_modex_line_x2]
586 sub ecx,[_modex_line_x1]
595 mov ebx,[_modex_line_x2]
596 xchg ebx,[_modex_line_x1]
597 mov [_modex_line_x2],ebx
599 mov ebx,[_modex_line_y2]
600 xchg ebx,[_modex_line_y1]
601 mov [_modex_line_y2],ebx
603 ; calc dy = abs(y2 - y1)
606 mov ebx,[_modex_line_y2]
607 sub ebx,[_modex_line_y1]
615 ; select appropriate routine for slope of line
618 mov [_modex_line_vertincr],esi
619 mov dword [_modex_line_routine],LoSlopeLine
622 mov dword [_modex_line_routine],HiSlopeLine
625 ; calc initial decision variable and increments
629 mov [_modex_line_incr1],ebx
633 mov [_modex_line_incr2],ebx
635 ; calc first pixel address
638 mov eax,[_modex_line_y1]
639 mov ebx,[_modex_line_x1]
644 mov ah,al ; duplicate nybble
650 jmp near dword [_modex_line_routine]
652 ; routine for verticle lines
655 mov eax,[_modex_line_y1]
656 mov ebx,[_modex_line_y2]
665 mov ebx,[_modex_line_x1]
674 mov ax, word [_modex_line_Color]
684 ; routine for horizontal line
688 mov eax,[_modex_line_y1]
689 mov ebx,[_modex_line_x1]
692 mov edi,ebx ; set dl = first byte mask
696 mov ecx,[_modex_line_x2] ; set dh = last byte mask
702 ; determine byte offset of first and last pixel in line
704 mov eax,[_modex_line_x2]
705 mov ebx,[_modex_line_x1]
707 shr eax,2 ; set ax = last byte column
708 shr ebx,2 ; set bx = first byte column
709 mov ecx,eax ; cx = ax - bx
712 mov eax,edx ; mov end byte masks to ax
713 mov dx,SC_INDEX ; setup dx for VGA outs
714 mov bl,[_modex_line_Color]
716 ; set pixels in leftmost byte of line
718 or ecx,ecx ; is start and end pt in same byte
720 and ah,al ; combine start and end masks
731 ; draw remainder of the line
741 ; set pixels in rightmost byte of line
750 ; routine for dy >= dx (slope <= 1)
754 mov bh,byte [_modex_line_Color]
763 ; bit mask not shifted out
767 add esi,[_modex_line_incr1]
775 add esi,[_modex_line_incr2]
778 add edi,[_modex_line_vertincr]
782 ; bit mask shifted out
789 add esi,[_modex_line_incr1]
794 add esi,[_modex_line_incr2]
795 add edi,[_modex_line_vertincr]
799 ; routine for dy > dx (slope > 1)
802 mov ebx,[_modex_line_vertincr]
806 mov al,[_modex_line_Color]
815 add esi,[_modex_line_incr1]
820 add esi,[_modex_line_incr2]