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 10:08:01 $
17 ; Routines to access ModeX VGA memory
19 ; $Log: not supported by cvs2svn $
20 ; Revision 1.3 2001/10/19 09:01:56 bradleyb
21 ; Moved arch/sdl_* to arch/sdl
23 ; Revision 1.3 2001/01/31 14:04:44 bradleyb
24 ; Fix compiler warnings
26 ; Revision 1.2 2001/01/29 13:35:08 bradleyb
27 ; Fixed build system, minor fixes
29 ; Revision 1.1.1.1 2001/01/19 03:30:15 bradleyb
32 ; Revision 1.1.1.1 1999/06/14 21:57:56 donut
33 ; Import of d1x 1.37 source.
35 ; Revision 1.19 1995/03/01 15:37:46 john
36 ; Better ModeX support.
38 ; Revision 1.18 1994/11/24 13:24:20 john
39 ; Made sure that some rep movs had the cld set first.
40 ; Took some unused functions out.
42 ; Revision 1.17 1994/09/22 18:15:02 john
43 ; Made flip page wait for retrace.
45 ; Revision 1.16 1994/09/22 16:08:27 john
46 ; Fixed some palette stuff.
48 ; Revision 1.15 1994/07/13 12:03:05 john
49 ; Added assembly modex line-drawer.
51 ; Revision 1.14 1994/05/06 12:50:34 john
52 ; Added supertransparency; neatend things up; took out warnings.
54 ; Revision 1.13 1994/05/03 19:39:04 john
55 ; *** empty log message ***
57 ; Revision 1.12 1994/02/18 15:32:32 john
58 ; *** empty log message ***
60 ; Revision 1.11 1993/12/21 11:40:36 john
61 ; *** empty log message ***
63 ; Revision 1.10 1993/12/09 15:02:26 john
64 ; Changed palette stuff majorly
66 ; Revision 1.9 1993/12/03 12:11:32 john
67 ; fixed cx/ecx loop bugs.
69 ; Revision 1.8 1993/11/16 11:28:18 john
70 ; *** empty log message ***
72 ; Revision 1.7 1993/10/15 16:23:23 john
75 ; Revision 1.6 1993/09/28 19:07:19 john
76 ; stripped the waitforretrace out of fade to speed things up.
78 ; Revision 1.5 1993/09/26 18:58:58 john
81 ; Revision 1.4 1993/09/21 14:01:15 john
82 ; turned off video before mode set to reduce flicker.
84 ; Revision 1.3 1993/09/08 11:38:36 john
85 ; changed rcs stuff at beginning.
94 %include "vgaregs.inc"
98 extern _gr_video_memory
100 global _modex_line_vertincr
101 global _modex_line_incr1
102 global _modex_line_incr2
103 global _modex_line_x1
104 global _modex_line_x2
105 global _modex_line_y1
106 global _modex_line_y2
107 global _modex_line_Color
109 _modex_line_vertincr dd 0
110 _modex_line_incr1 dd 0
111 _modex_line_incr2 dd 0
116 _modex_line_Color db 0
119 _modex_line_routine dd 0
122 %define LEFT_MASK1 1000b
123 %define LEFT_MASK2 1100b
124 %define LEFT_MASK3 1110b
125 %define RIGHT_MASK1 0001b
126 %define RIGHT_MASK2 0011b
127 %define RIGHT_MASK3 0111b
128 %define ALL_MASK 1111b
130 tmppal times 768 db 0
135 MaskTable1 db ALL_MASK & RIGHT_MASK1
136 db ALL_MASK & RIGHT_MASK2
137 db ALL_MASK & RIGHT_MASK3
139 db LEFT_MASK3 & RIGHT_MASK1
140 db LEFT_MASK3 & RIGHT_MASK2
141 db LEFT_MASK3 & RIGHT_MASK3
143 db LEFT_MASK2 & RIGHT_MASK1
144 db LEFT_MASK2 & RIGHT_MASK2
145 db LEFT_MASK2 & RIGHT_MASK3
147 db LEFT_MASK1 & RIGHT_MASK1
148 db LEFT_MASK1 & RIGHT_MASK2
149 db LEFT_MASK1 & RIGHT_MASK3
152 MaskTable2 db ALL_MASK,RIGHT_MASK1
153 db ALL_MASK,RIGHT_MASK2
154 db ALL_MASK,RIGHT_MASK3
156 db LEFT_MASK3,RIGHT_MASK1
157 db LEFT_MASK3,RIGHT_MASK2
158 db LEFT_MASK3,RIGHT_MASK3
159 db LEFT_MASK3,ALL_MASK
160 db LEFT_MASK2,RIGHT_MASK1
161 db LEFT_MASK2,RIGHT_MASK2
162 db LEFT_MASK2,RIGHT_MASK3
163 db LEFT_MASK2,ALL_MASK
164 db LEFT_MASK1,RIGHT_MASK1
165 db LEFT_MASK1,RIGHT_MASK2
166 db LEFT_MASK1,RIGHT_MASK3
167 db LEFT_MASK1,ALL_MASK
188 global _gr_sync_display
194 jnz VS2A ; Loop until not in vertical retrace
197 jz VS2B ; Loop until in vertical retrace
201 ; gr_modex_uscanline(int x1,int x2,int y,int color);
202 global _gr_modex_uscanline
209 mov ecx,[esp+20];color
212 ; EAX = X1 (X1 and X2 don't need to be sorted)
219 ;mov ebx, _RowOffset[ebx*4]
220 mov edi, [_gr_var_bwidth]
222 add edi, [_gr_video_memory]
232 ; BX = LeftRight switch command. (4bit)
236 ; EDI = Offset into video memory
239 ; ECX = X2/4 - X1/4 - 1
242 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
248 mov al, [MaskTable1+ebx]
251 mov [edi], al ; Write the one pixel
260 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
262 mov cx, word [MaskTable2+ebx*2]
270 mov [edi], bl ; Write the left pixel
273 mov [edi+1], bl ; Write the right pixel
278 ;========================= MANY GROUPS OF 4 TO DRAW ======================
287 ; AL,AH = color of pixel
288 jmp dword [DrawTable+ebx*4]
291 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
298 rep stosw ; Write the middle pixels
300 stosb ; Write the middle odd pixel
306 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
307 mov al, byte [MaskTable2+ebx*2]
309 mov [edi], ah ; Write leftmost pixels
317 rep stosw ; Write the middle pixels
319 stosb ; Write the middle odd pixel
325 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
326 mov bx, word [MaskTable2+ebx*2]
329 mov [edi], ah ; Write leftmost pixels
336 rep stosw ; Write the middle pixels
338 stosb ; Write the middle odd pixel
341 mov [edi], ah ; Write the rightmost pixels
346 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
347 mov bx, word [MaskTable2+ebx*2]
354 rep stosw ; Write the middle pixels
356 stosb ; Write the middle odd pixel
359 mov [edi], ah ; Write the rightmost pixels
365 global _gr_modex_setmode
382 ;call turn_screen_off
384 push ecx ; some bios's dont preserve cx
387 ;mov bl, 31h ; disable palette loading at mode switch
389 mov ax,13h ; let the BIOS set standard 256-color
390 int 10h ; mode (320x200 linear)
392 ;mov bl, 31h ; enable palette loading at mode switch
399 out dx,ax ; disable chain4 mode
403 out dx,ax ; synchronous reset while setting Misc
404 ; Output for safety, even though clock
407 mov esi, dword [ModeTable+ecx*4]
414 out dx,al ; select the dot clock and Horiz
428 out dx,ax ; undo reset (restart sequencer)
430 mov dx,CRTC_INDEX ; reprogram the CRT Controller
431 mov al,11h ; VSync End reg contains register write
432 out dx,al ; protect bit
433 inc dx ; CRT Controller Data register
434 in al,dx ; get current VSync End register setting
435 and al,07fh ; remove write protect on various
436 out dx,al ; CRTC registers
437 dec dx ; CRT Controller Index
444 lodsw ; get the next CRT Index/Data pair
445 out dx,ax ; set the next CRT Index/Data pair
450 out dx,ax ; enable writes to all four planes
451 mov edi, [_gr_video_memory] ; point ES:DI to display memory
452 xor eax,eax ; clear to zero-value pixels
453 mov ecx,4000h ; # of dwords in display memory
454 rep stosd ; clear all of display memory
456 ; Set pysical screen dimensions
459 lodsw ; Load scrn pixel width
484 lodsw ; Load Screen Phys. Height
495 global _gr_modex_setplane
503 and cl,011b ;CL = plane
504 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
505 shl ah,cl ;set only the bit for the required
507 mov dx,SC_INDEX ;set the Map Mask to enable only the
508 out dx,ax ; pixel's plane
511 mov ah,cl ;AH = plane
512 mov al,READ_MAP ;AL = index in GC of the Read Map reg
513 mov dx,GC_INDEX ;set the Read Map to read the pixel's
517 global _gr_modex_setstart
528 ; EBX = Wait for retrace
530 mov ecx, [_gr_var_bwidth]
550 out dx, ax ; Start address low
552 out dx, ax ; Start address high
561 jz WaitVS ; Loop until in vertical retrace
572 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
576 imul eax, [_gr_var_bwidth]
578 add ebx, [_gr_video_memory]
582 ;-----------------------------------------------------------------------
584 ; Line drawing function for all MODE X 256 Color resolutions
585 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
587 global _gr_modex_line
592 mov dx,SC_INDEX ; setup for plane mask access
594 ; check for vertical line
596 mov esi,[_gr_var_bwidth]
597 mov ecx,[_modex_line_x2]
598 sub ecx,[_modex_line_x1]
607 mov ebx,[_modex_line_x2]
608 xchg ebx,[_modex_line_x1]
609 mov [_modex_line_x2],ebx
611 mov ebx,[_modex_line_y2]
612 xchg ebx,[_modex_line_y1]
613 mov [_modex_line_y2],ebx
615 ; calc dy = abs(y2 - y1)
618 mov ebx,[_modex_line_y2]
619 sub ebx,[_modex_line_y1]
627 ; select appropriate routine for slope of line
630 mov [_modex_line_vertincr],esi
631 mov dword [_modex_line_routine],LoSlopeLine
634 mov dword [_modex_line_routine],HiSlopeLine
637 ; calc initial decision variable and increments
641 mov [_modex_line_incr1],ebx
645 mov [_modex_line_incr2],ebx
647 ; calc first pixel address
650 mov eax,[_modex_line_y1]
651 mov ebx,[_modex_line_x1]
656 mov ah,al ; duplicate nybble
662 jmp near dword [_modex_line_routine]
664 ; routine for verticle lines
667 mov eax,[_modex_line_y1]
668 mov ebx,[_modex_line_y2]
677 mov ebx,[_modex_line_x1]
686 mov ax, word [_modex_line_Color]
696 ; routine for horizontal line
700 mov eax,[_modex_line_y1]
701 mov ebx,[_modex_line_x1]
704 mov edi,ebx ; set dl = first byte mask
708 mov ecx,[_modex_line_x2] ; set dh = last byte mask
714 ; determine byte offset of first and last pixel in line
716 mov eax,[_modex_line_x2]
717 mov ebx,[_modex_line_x1]
719 shr eax,2 ; set ax = last byte column
720 shr ebx,2 ; set bx = first byte column
721 mov ecx,eax ; cx = ax - bx
724 mov eax,edx ; mov end byte masks to ax
725 mov dx,SC_INDEX ; setup dx for VGA outs
726 mov bl,[_modex_line_Color]
728 ; set pixels in leftmost byte of line
730 or ecx,ecx ; is start and end pt in same byte
732 and ah,al ; combine start and end masks
743 ; draw remainder of the line
753 ; set pixels in rightmost byte of line
762 ; routine for dy >= dx (slope <= 1)
766 mov bh,byte [_modex_line_Color]
775 ; bit mask not shifted out
779 add esi,[_modex_line_incr1]
787 add esi,[_modex_line_incr2]
790 add edi,[_modex_line_vertincr]
794 ; bit mask shifted out
801 add esi,[_modex_line_incr1]
806 add esi,[_modex_line_incr2]
807 add edi,[_modex_line_vertincr]
811 ; routine for dy > dx (slope > 1)
814 mov ebx,[_modex_line_vertincr]
818 mov al,[_modex_line_Color]
827 add esi,[_modex_line_incr1]
832 add esi,[_modex_line_incr2]