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.
13 ; Routines to access ModeX VGA memory
23 %include "vgaregs.inc"
27 extern _gr_video_memory
29 global _modex_line_vertincr
30 global _modex_line_incr1
31 global _modex_line_incr2
36 global _modex_line_Color
38 _modex_line_vertincr dd 0
39 _modex_line_incr1 dd 0
40 _modex_line_incr2 dd 0
45 _modex_line_Color db 0
48 _modex_line_routine dd 0
51 %define LEFT_MASK1 1000b
52 %define LEFT_MASK2 1100b
53 %define LEFT_MASK3 1110b
54 %define RIGHT_MASK1 0001b
55 %define RIGHT_MASK2 0011b
56 %define RIGHT_MASK3 0111b
57 %define ALL_MASK 1111b
64 MaskTable1 db ALL_MASK & RIGHT_MASK1
65 db ALL_MASK & RIGHT_MASK2
66 db ALL_MASK & RIGHT_MASK3
68 db LEFT_MASK3 & RIGHT_MASK1
69 db LEFT_MASK3 & RIGHT_MASK2
70 db LEFT_MASK3 & RIGHT_MASK3
72 db LEFT_MASK2 & RIGHT_MASK1
73 db LEFT_MASK2 & RIGHT_MASK2
74 db LEFT_MASK2 & RIGHT_MASK3
76 db LEFT_MASK1 & RIGHT_MASK1
77 db LEFT_MASK1 & RIGHT_MASK2
78 db LEFT_MASK1 & RIGHT_MASK3
81 MaskTable2 db ALL_MASK,RIGHT_MASK1
82 db ALL_MASK,RIGHT_MASK2
83 db ALL_MASK,RIGHT_MASK3
85 db LEFT_MASK3,RIGHT_MASK1
86 db LEFT_MASK3,RIGHT_MASK2
87 db LEFT_MASK3,RIGHT_MASK3
88 db LEFT_MASK3,ALL_MASK
89 db LEFT_MASK2,RIGHT_MASK1
90 db LEFT_MASK2,RIGHT_MASK2
91 db LEFT_MASK2,RIGHT_MASK3
92 db LEFT_MASK2,ALL_MASK
93 db LEFT_MASK1,RIGHT_MASK1
94 db LEFT_MASK1,RIGHT_MASK2
95 db LEFT_MASK1,RIGHT_MASK3
96 db LEFT_MASK1,ALL_MASK
117 global _gr_sync_display
123 jnz VS2A ; Loop until not in vertical retrace
126 jz VS2B ; Loop until in vertical retrace
130 ; gr_modex_uscanline(int x1,int x2,int y,int color);
131 global _gr_modex_uscanline
138 mov ecx,[esp+20];color
141 ; EAX = X1 (X1 and X2 don't need to be sorted)
148 ;mov ebx, _RowOffset[ebx*4]
149 mov edi, [_gr_var_bwidth]
151 add edi, [_gr_video_memory]
161 ; BX = LeftRight switch command. (4bit)
165 ; EDI = Offset into video memory
168 ; ECX = X2/4 - X1/4 - 1
171 ;======================= ONE GROUP OF 4 OR LESS TO DRAW ====================
177 mov al, [MaskTable1+ebx]
180 mov [edi], al ; Write the one pixel
189 ;===================== TWO GROUPS OF 4 OR LESS TO DRAW ====================
191 mov cx, word [MaskTable2+ebx*2]
199 mov [edi], bl ; Write the left pixel
202 mov [edi+1], bl ; Write the right pixel
207 ;========================= MANY GROUPS OF 4 TO DRAW ======================
216 ; AL,AH = color of pixel
217 jmp dword [DrawTable+ebx*4]
220 DrawM: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
227 rep stosw ; Write the middle pixels
229 stosb ; Write the middle odd pixel
235 ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
236 mov al, byte [MaskTable2+ebx*2]
238 mov [edi], ah ; Write leftmost pixels
246 rep stosw ; Write the middle pixels
248 stosb ; Write the middle odd pixel
254 DrawLMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
255 mov bx, word [MaskTable2+ebx*2]
258 mov [edi], ah ; Write leftmost pixels
265 rep stosw ; Write the middle pixels
267 stosb ; Write the middle odd pixel
270 mov [edi], ah ; Write the rightmost pixels
275 DrawMR: ;AH=COLOR, EDI=DEST, CX=X2/4-X1/4-1, BX=Table Index
276 mov bx, word [MaskTable2+ebx*2]
283 rep stosw ; Write the middle pixels
285 stosb ; Write the middle odd pixel
288 mov [edi], ah ; Write the rightmost pixels
294 global _gr_modex_setmode
311 ;call turn_screen_off
313 push ecx ; some bios's dont preserve cx
316 ;mov bl, 31h ; disable palette loading at mode switch
318 mov ax,13h ; let the BIOS set standard 256-color
319 int 10h ; mode (320x200 linear)
321 ;mov bl, 31h ; enable palette loading at mode switch
328 out dx,ax ; disable chain4 mode
332 out dx,ax ; synchronous reset while setting Misc
333 ; Output for safety, even though clock
336 mov esi, dword [ModeTable+ecx*4]
343 out dx,al ; select the dot clock and Horiz
357 out dx,ax ; undo reset (restart sequencer)
359 mov dx,CRTC_INDEX ; reprogram the CRT Controller
360 mov al,11h ; VSync End reg contains register write
361 out dx,al ; protect bit
362 inc dx ; CRT Controller Data register
363 in al,dx ; get current VSync End register setting
364 and al,07fh ; remove write protect on various
365 out dx,al ; CRTC registers
366 dec dx ; CRT Controller Index
373 lodsw ; get the next CRT Index/Data pair
374 out dx,ax ; set the next CRT Index/Data pair
379 out dx,ax ; enable writes to all four planes
380 mov edi, [_gr_video_memory] ; point ES:DI to display memory
381 xor eax,eax ; clear to zero-value pixels
382 mov ecx,4000h ; # of dwords in display memory
383 rep stosd ; clear all of display memory
385 ; Set pysical screen dimensions
388 lodsw ; Load scrn pixel width
413 lodsw ; Load Screen Phys. Height
424 global _gr_modex_setplane
432 and cl,011b ;CL = plane
433 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
434 shl ah,cl ;set only the bit for the required
436 mov dx,SC_INDEX ;set the Map Mask to enable only the
437 out dx,ax ; pixel's plane
440 mov ah,cl ;AH = plane
441 mov al,READ_MAP ;AL = index in GC of the Read Map reg
442 mov dx,GC_INDEX ;set the Read Map to read the pixel's
446 global _gr_modex_setstart
457 ; EBX = Wait for retrace
459 mov ecx, [_gr_var_bwidth]
479 out dx, ax ; Start address low
481 out dx, ax ; Start address high
490 jz WaitVS ; Loop until in vertical retrace
501 ; given: ebx=x, eax=y, return cl=plane mask, ebx=address, trash eax
505 imul eax, [_gr_var_bwidth]
507 add ebx, [_gr_video_memory]
511 ;-----------------------------------------------------------------------
513 ; Line drawing function for all MODE X 256 Color resolutions
514 ; Based on code from "PC and PS/2 Video Systems" by Richard Wilton.
516 global _gr_modex_line
521 mov dx,SC_INDEX ; setup for plane mask access
523 ; check for vertical line
525 mov esi,[_gr_var_bwidth]
526 mov ecx,[_modex_line_x2]
527 sub ecx,[_modex_line_x1]
536 mov ebx,[_modex_line_x2]
537 xchg ebx,[_modex_line_x1]
538 mov [_modex_line_x2],ebx
540 mov ebx,[_modex_line_y2]
541 xchg ebx,[_modex_line_y1]
542 mov [_modex_line_y2],ebx
544 ; calc dy = abs(y2 - y1)
547 mov ebx,[_modex_line_y2]
548 sub ebx,[_modex_line_y1]
556 ; select appropriate routine for slope of line
559 mov [_modex_line_vertincr],esi
560 mov dword [_modex_line_routine],LoSlopeLine
563 mov dword [_modex_line_routine],HiSlopeLine
566 ; calc initial decision variable and increments
570 mov [_modex_line_incr1],ebx
574 mov [_modex_line_incr2],ebx
576 ; calc first pixel address
579 mov eax,[_modex_line_y1]
580 mov ebx,[_modex_line_x1]
585 mov ah,al ; duplicate nybble
591 jmp near dword [_modex_line_routine]
593 ; routine for verticle lines
596 mov eax,[_modex_line_y1]
597 mov ebx,[_modex_line_y2]
606 mov ebx,[_modex_line_x1]
615 mov ax, word [_modex_line_Color]
625 ; routine for horizontal line
629 mov eax,[_modex_line_y1]
630 mov ebx,[_modex_line_x1]
633 mov edi,ebx ; set dl = first byte mask
637 mov ecx,[_modex_line_x2] ; set dh = last byte mask
643 ; determine byte offset of first and last pixel in line
645 mov eax,[_modex_line_x2]
646 mov ebx,[_modex_line_x1]
648 shr eax,2 ; set ax = last byte column
649 shr ebx,2 ; set bx = first byte column
650 mov ecx,eax ; cx = ax - bx
653 mov eax,edx ; mov end byte masks to ax
654 mov dx,SC_INDEX ; setup dx for VGA outs
655 mov bl,[_modex_line_Color]
657 ; set pixels in leftmost byte of line
659 or ecx,ecx ; is start and end pt in same byte
661 and ah,al ; combine start and end masks
672 ; draw remainder of the line
682 ; set pixels in rightmost byte of line
691 ; routine for dy >= dx (slope <= 1)
695 mov bh,byte [_modex_line_Color]
704 ; bit mask not shifted out
708 add esi,[_modex_line_incr1]
716 add esi,[_modex_line_incr2]
719 add edi,[_modex_line_vertincr]
723 ; bit mask shifted out
730 add esi,[_modex_line_incr1]
735 add esi,[_modex_line_incr2]
736 add edi,[_modex_line_vertincr]
740 ; routine for dy > dx (slope > 1)
743 mov ebx,[_modex_line_vertincr]
747 mov al,[_modex_line_Color]
756 add esi,[_modex_line_incr1]
761 add esi,[_modex_line_incr2]