1 ; THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
\r
2 ; SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
\r
3 ; END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
\r
4 ; ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
\r
5 ; IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
\r
6 ; SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
\r
7 ; FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
\r
8 ; CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
\r
9 ; AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
\r
10 ; COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
\r
14 _DATA SEGMENT BYTE PUBLIC USE32 'DATA'
\r
16 INCLUDE psmacros.inc
\r
22 extd _modex_line_vertincr
\r
23 extd _modex_line_incr1
\r
24 extd _modex_line_incr2
\r
25 _modex_line_routine dd ?
\r
26 extd _modex_line_x1
\r
27 extd _modex_line_y1
\r
28 extd _modex_line_x2
\r
29 extd _modex_line_y2
\r
30 extb _modex_line_Color
\r
42 tmppal db 768 dup (0)
\r
47 MaskTable1 db ALL_MASK AND RIGHT_MASK1,
\r
48 ALL_MASK AND RIGHT_MASK2,
\r
49 ALL_MASK AND RIGHT_MASK3,
\r
51 LEFT_MASK3 AND RIGHT_MASK1,
\r
52 LEFT_MASK3 AND RIGHT_MASK2,
\r
53 LEFT_MASK3 AND RIGHT_MASK3,
\r
55 LEFT_MASK2 AND RIGHT_MASK1,
\r
56 LEFT_MASK2 AND RIGHT_MASK2,
\r
57 LEFT_MASK2 AND RIGHT_MASK3,
\r
59 LEFT_MASK1 AND RIGHT_MASK1,
\r
60 LEFT_MASK1 AND RIGHT_MASK2,
\r
61 LEFT_MASK1 AND RIGHT_MASK3,
\r
64 MaskTable2 db ALL_MASK,RIGHT_MASK1,
\r
65 ALL_MASK,RIGHT_MASK2,
\r
66 ALL_MASK,RIGHT_MASK3,
\r
68 LEFT_MASK3,RIGHT_MASK1,
\r
69 LEFT_MASK3,RIGHT_MASK2,
\r
70 LEFT_MASK3,RIGHT_MASK3,
\r
71 LEFT_MASK3,ALL_MASK,
\r
72 LEFT_MASK2,RIGHT_MASK1,
\r
73 LEFT_MASK2,RIGHT_MASK2,
\r
74 LEFT_MASK2,RIGHT_MASK3,
\r
75 LEFT_MASK2,ALL_MASK,
\r
76 LEFT_MASK1,RIGHT_MASK1,
\r
77 LEFT_MASK1,RIGHT_MASK2,
\r
78 LEFT_MASK1,RIGHT_MASK3,
\r
81 DrawTable dd DrawMR,
\r
103 _TEXT SEGMENT BYTE PUBLIC USE32 'CODE'
\r
108 PUBLIC gr_sync_display_
\r
114 mov dx, VERT_RESCAN
\r
117 jnz VS2A ; Loop until not in vertical retrace
\r
120 jz VS2B ; Loop until in vertical retrace
\r
127 PUBLIC gr_modex_uscanline_
\r
129 gr_modex_uscanline_:
\r
132 ; EAX = X1 (X1 and X2 don't need to be sorted)
\r
139 ;mov ebx, _RowOffset[ebx*4]
\r
140 mov edi, _gr_var_bwidth
\r
152 ; BX = LeftRight switch command. (4bit)
\r
156 ; EDI = Offset into video memory
\r
159 ; ECX = X2/4 - X1/4 - 1
\r
162 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
\r
165 mov al, SC_MAP_MASK
\r
168 mov al, MaskTable1[ebx]
\r
171 mov [edi], al ; Write the one pixel
\r
179 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
\r
181 mov cx, WORD PTR MaskTable2[ebx*2]
\r
184 mov al, SC_MAP_MASK
\r
189 mov [edi], bl ; Write the left pixel
\r
192 mov [edi+1], bl ; Write the right pixel
\r
196 ;========================= MANY GROUPS OF 4 TO DRAW ======================
\r
199 mov al, SC_MAP_MASK
\r
205 ; AL,AH = color of pixel
\r
206 jmp NEAR32 PTR DrawTable[ebx*4]
\r
209 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
\r
216 rep stosw ; Write the middle pixels
\r
218 stosb ; Write the middle odd pixel
\r
223 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
\r
224 mov al, BYTE PTR MaskTable2[ebx*2]
\r
226 mov [edi], ah ; Write leftmost pixels
\r
234 rep stosw ; Write the middle pixels
\r
236 stosb ; Write the middle odd pixel
\r
241 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
\r
242 mov bx, WORD PTR MaskTable2[ebx*2]
\r
245 mov [edi], ah ; Write leftmost pixels
\r
252 rep stosw ; Write the middle pixels
\r
254 stosb ; Write the middle odd pixel
\r
257 mov [edi], ah ; Write the rightmost pixels
\r
261 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
\r
262 mov bx, WORD PTR MaskTable2[ebx*2]
\r
269 rep stosw ; Write the middle pixels
\r
271 stosb ; Write the middle odd pixel
\r
274 mov [edi], ah ; Write the rightmost pixels
\r
279 PUBLIC gr_modex_setmode_
\r
292 cmp ecx, LAST_X_MODE
\r
297 ;call turn_screen_off
\r
299 push ecx ; some bios's dont preserve cx
\r
302 ;mov bl, 31h ; disable palette loading at mode switch
\r
304 mov ax,13h ; let the BIOS set standard 256-color
\r
305 int 10h ; mode (320x200 linear)
\r
307 ;mov bl, 31h ; enable palette loading at mode switch
\r
314 out dx,ax ; disable chain4 mode
\r
318 out dx,ax ; synchronous reset while setting Misc
\r
319 ; Output for safety, even though clock
\r
322 mov esi, dword ptr ModeTable[ecx*4]
\r
329 out dx,al ; select the dot clock and Horiz
\r
343 out dx,ax ; undo reset (restart sequencer)
\r
345 mov dx,CRTC_INDEX ; reprogram the CRT Controller
\r
346 mov al,11h ; VSync End reg contains register write
\r
347 out dx,al ; protect bit
\r
348 inc dx ; CRT Controller Data register
\r
349 in al,dx ; get current VSync End register setting
\r
350 and al,07fh ; remove write protect on various
\r
351 out dx,al ; CRTC registers
\r
352 dec dx ; CRT Controller Index
\r
359 lodsw ; get the next CRT Index/Data pair
\r
360 out dx,ax ; set the next CRT Index/Data pair
\r
361 loop SetCRTParmsLoop
\r
365 out dx,ax ; enable writes to all four planes
\r
366 mov edi, 0A0000h ; point ES:DI to display memory
\r
367 xor ax,ax ; clear to zero-value pixels
\r
368 mov ecx,8000h ; # of words in display memory
\r
369 rep stosw ; clear all of display memory
\r
371 ; Set pysical screen dimensions
\r
374 lodsw ; Load scrn pixel width
\r
399 lodsw ; Load Screen Phys. Height
\r
401 ;call turn_screen_on
\r
411 PUBLIC gr_modex_setplane_
\r
413 gr_modex_setplane_:
\r
420 ; SELECT WRITE PLANE
\r
421 and cl,011b ;CL = plane
\r
422 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
\r
423 shl ah,cl ;set only the bit for the required
\r
425 mov dx,SC_INDEX ;set the Map Mask to enable only the
\r
426 out dx,ax ; pixel's plane
\r
428 ; SELECT READ PLANE
\r
429 mov ah,cl ;AH = plane
\r
430 mov al,READ_MAP ;AL = index in GC of the Read Map reg
\r
431 mov dx,GC_INDEX ;set the Read Map to read the pixel's
\r
439 PUBLIC gr_modex_setstart_
\r
441 gr_modex_setstart_:
\r
445 ; EBX = Wait for retrace
\r
451 mov ecx, _gr_var_bwidth
\r
460 mov bl, CC_START_LO
\r
461 mov cl, CC_START_HI
\r
464 mov dx, VERT_RESCAN
\r
471 out dx, ax ; Start address low
\r
473 out dx, ax ; Start address high
\r
479 mov dx, VERT_RESCAN
\r
482 jz WaitVS ; Loop until in vertical retrace
\r
494 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
\r
498 imul eax, _gr_var_bwidth
\r
504 ;-----------------------------------------------------------------------
\r
506 ; Line drawing function for all MODE X 256 Color resolutions
\r
507 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
\r
509 PUBLIC gr_modex_line_
\r
514 mov dx,SC_INDEX ; setup for plane mask access
\r
516 ; check for vertical line
\r
518 mov esi,_gr_var_bwidth
\r
519 mov ecx,_modex_line_x2
\r
520 sub ecx,_modex_line_x1
\r
529 mov ebx,_modex_line_x2
\r
530 xchg ebx,_modex_line_x1
\r
531 mov _modex_line_x2,ebx
\r
533 mov ebx,_modex_line_y2
\r
534 xchg ebx,_modex_line_y1
\r
535 mov _modex_line_y2,ebx
\r
537 ; calc dy = abs(y2 - y1)
\r
540 mov ebx,_modex_line_y2
\r
541 sub ebx,_modex_line_y1
\r
549 ; select appropriate routine for slope of line
\r
552 mov _modex_line_vertincr,esi
\r
553 mov _modex_line_routine,offset LoSlopeLine
\r
556 mov _modex_line_routine,offset HiSlopeLine
\r
559 ; calc initial decision variable and increments
\r
563 mov _modex_line_incr1,ebx
\r
567 mov _modex_line_incr2,ebx
\r
569 ; calc first pixel address
\r
572 mov eax,_modex_line_y1
\r
573 mov ebx,_modex_line_x1
\r
578 mov ah,al ; duplicate nybble
\r
584 jmp [_modex_line_routine]
\r
586 ; routine for verticle lines
\r
589 mov eax,_modex_line_y1
\r
590 mov ebx,_modex_line_y2
\r
599 mov ebx,_modex_line_x1
\r
608 mov ax, word ptr _modex_line_Color
\r
618 ; routine for horizontal line
\r
622 mov eax,_modex_line_y1
\r
623 mov ebx,_modex_line_x1
\r
626 mov edi,ebx ; set dl = first byte mask
\r
630 mov ecx,_modex_line_x2 ; set dh = last byte mask
\r
636 ; determine byte offset of first and last pixel in line
\r
638 mov eax,_modex_line_x2
\r
639 mov ebx,_modex_line_x1
\r
641 shr eax,2 ; set ax = last byte column
\r
642 shr ebx,2 ; set bx = first byte column
\r
643 mov ecx,eax ; cx = ax - bx
\r
646 mov eax,edx ; mov end byte masks to ax
\r
647 mov dx,SC_INDEX ; setup dx for VGA outs
\r
648 mov bl,_modex_line_Color
\r
650 ; set pixels in leftmost byte of line
\r
652 or ecx,ecx ; is start and end pt in same byte
\r
654 and ah,al ; combine start and end masks
\r
665 ; draw remainder of the line
\r
675 ; set pixels in rightmost byte of line
\r
680 mov byte ptr [edi],bl
\r
684 ; routine for dy >= dx (slope <= 1)
\r
688 mov bh,byte ptr _modex_line_Color
\r
697 ; bit mask not shifted out
\r
701 add esi,_modex_line_incr1
\r
709 add esi,_modex_line_incr2
\r
712 add edi,_modex_line_vertincr
\r
716 ; bit mask shifted out
\r
723 add esi,_modex_line_incr1
\r
728 add esi,_modex_line_incr2
\r
729 add edi,_modex_line_vertincr
\r
733 ; routine for dy > dx (slope > 1)
\r
736 mov ebx,_modex_line_vertincr
\r
740 mov al,_modex_line_Color
\r
749 add esi,_modex_line_incr1
\r
754 add esi,_modex_line_incr2
\r