1 ;-----------------------------------------------------------------------
\r
4 ; Point functions all MODE X 256 Color resolutions
\r
10 ; ****** XLIB - Mode X graphics library ****************
\r
11 ; ****** ****************
\r
12 ; ****** Written By Themie Gouthas ****************
\r
14 ; egg@dstos3.dsto.gov.au
\r
15 ; teg@bart.dsto.gov.au
\r
16 ;-----------------------------------------------------------------------
\r
20 This code is my interpretation of a simple "C" flood filling algorithm
\r
23 * A Seed Fill Algorithm
\r
25 * from "Graphics Gems", Academic Press, 1990
\r
27 The original C source is readily available at numerous internet archive
\r
30 Its been modified and optimized for tweaked 13h modes (Mode X derrivatives).
\r
31 The most fundamental change is that it fills a column at a time rather
\r
32 than a row at a time to minimize the number of plane setting "out"s.
\r
33 And of course the border fill variant was a logical and useful further
\r
36 Both functions return the number of pixels filled..
\r
38 WARNING: These fill functions make heavy use of the stack and no stack
\r
39 checking is performed, so caution is advised.
\r
50 ARG X:word,Y:word,PgOfs:word,Color:word
\r
51 LOCAL len:word,y1:word,y2:word,deltax:word,floodval:word,\
\r
52 stackptr:word,FillCount:word=STK
\r
59 mov ax,[_ScrnLogicalByteWidth]
\r
60 mul si ;offset of pixel's scan line in page
\r
63 shr di,2 ;X/4 = offset of pixel in scan line
\r
64 add di,ax ;offset of pixel in page
\r
65 add di,[PgOfs] ;offset of pixel in display memory
\r
67 mov es,ax ;point ES:DI to the pixel's address
\r
69 ;---- Select read plane ------
\r
72 and ah,011b ;AH = pixel's plane
\r
73 mov al,READ_MAP ;AL = index in GC of the Read Map reg
\r
74 mov dx,GC_INDEX ;set the Read Map to read the pixel's
\r
77 mov al,es:[di] ;read the pixel's color
\r
78 cmp al,byte ptr Color ;Is dest pixel the same color as the flood?
\r
79 je @@Done2 ; if it is abort.
\r
81 mov cx,_LeftClip ; Is the dest. pixel out of the clipping window?
\r
82 sal cx,2 ; if not abort.
\r
91 mov floodval,ax ; store the color to flood
\r
93 ;-- Push fill segment ---
\r
98 mov cx,1 ; deltaX (either 1 or -1 indicating direction)
\r
102 mov deltax,-1 ; Initialize first column scan
\r
103 mov y1,si ; then bypass some of the preliminary crap in
\r
104 mov y2,si ; the main fill loop
\r
107 @@Done2:mov ax,[FillCount]
\r
118 pop cx ; get fill segment from stack
\r
119 mov deltax,cx ; ie deltaX, Y1, Y2, X
\r
126 sub ax,si ; Acculmulate number of filled pixels
\r
133 add bx,cx ; move to new column according to deltaX
\r
135 mov ax,bx ; Make sure the column is within the clipping
\r
136 sar ax,2 ; rectangle
\r
144 ;---- Select read plane ------
\r
147 and ah,011b ;AH = pixel's plane
\r
148 mov al,READ_MAP ;AL = index in GC of the Read Map reg
\r
149 mov dx,GC_INDEX ;set the Read Map to read the pixel's
\r
154 ;---- Select write plane ------
\r
157 and cl,011b ;CL = pixel's plane
\r
158 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
\r
159 shl ah,cl ;set only the bit for the pixel's
\r
161 mov dx,SC_INDEX ;set the Map Mask to enable only the
\r
162 out dx,ax ; pixel's plane
\r
164 mov ax,_ScrnLogicalByteWidth ; store logical width in CX
\r
165 mov cx,ax ; get offset of scan row
\r
166 mul si ; set ES:DI ->
\r
167 mov di,bx ; address of pixel at x,y1
\r
170 add di,PgOfs ;ES:DI->first pixel of column segment to fill
\r
171 mov dx,di ; save y1 offset for after upward fill
\r
173 mov al,byte ptr Color
\r
174 mov ah,byte ptr floodval
\r
177 cmp si,_TopClip ; Dont fill beyond clip boundaries
\r
178 jl @@UpwardFillDone
\r
180 cmp es:[di],ah ; if flood pixel color then replace
\r
181 jne @@UpwardFillDone ; with new color otherwise column is done
\r
186 jmp short @@FillColUpward
\r
198 push bx ; queue an upward leak check
\r
216 mov ah,byte ptr floodval
\r
217 mov al,byte ptr Color
\r
221 jg @@DownwardFillDone
\r
223 jne @@DownwardFillDone
\r
227 jmp short @@DownwardFill
\r
229 @@DownwardFillDone:
\r
231 push bx ; queue an upward leak check
\r
246 push bx ; queue a downward leak check
\r
257 mov ah,byte ptr floodval
\r
266 cmp byte ptr es:[di],ah
\r
286 _x_boundary_fill proc
\r
287 ARG X:word,Y:word,PgOfs:word,BoundaryColor:word,Color:word
\r
288 LOCAL len:word,y1:word,y2:word,deltax:word,y1_offs:word,\
\r
289 stackptr:word,FillCount:word=STK
\r
296 mov ax,[_ScrnLogicalByteWidth]
\r
297 mul si ;offset of pixel's scan line in page
\r
300 shr di,2 ;X/4 = offset of pixel in scan line
\r
301 add di,ax ;offset of pixel in page
\r
302 add di,[PgOfs] ;offset of pixel in display memory
\r
304 mov es,ax ;point ES:DI to the pixel's address
\r
306 ;---- Select read plane ------
\r
309 and ah,011b ;AH = pixel's plane
\r
310 mov al,READ_MAP ;AL = index in GC of the Read Map reg
\r
311 mov dx,GC_INDEX ;set the Read Map to read the pixel's
\r
314 mov al,es:[di] ;read the pixel's color
\r
315 cmp al,byte ptr Color ;Is dest pixel the same color as the flood?
\r
318 cmp al,byte ptr BoundaryColor ;Is dest pixel the same color
\r
319 je @@Done2 ; as the boundary color?
\r
322 mov cx,_LeftClip ; Is the dest. pixel out of the clipping window?
\r
338 mov al,byte ptr BoundaryColor
\r
339 mov byte ptr [Color+1],al
\r
346 @@Done2:mov ax,[FillCount]
\r
366 sub ax,si ; Acculmulate number of filled pixels
\r
374 mov ax,bx ; Make sure the column is within the clipping
\r
375 sar ax,2 ; rectangle
\r
382 ;---- Select read plane ------
\r
385 and ah,011b ;AH = pixel's plane
\r
386 mov al,READ_MAP ;AL = index in GC of the Read Map reg
\r
387 mov dx,GC_INDEX ;set the Read Map to read the pixel's
\r
392 ;---- Select write plane ------
\r
395 and cl,011b ;CL = pixel's plane
\r
396 mov ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
\r
397 shl ah,cl ;set only the bit for the pixel's
\r
399 mov dx,SC_INDEX ;set the Map Mask to enable only the
\r
400 out dx,ax ; pixel's plane
\r
402 mov ax,_ScrnLogicalByteWidth ; store logical width in CX
\r
403 mov cx,ax ; get offset of scan row
\r
404 mul si ; set ES:DI ->
\r
405 mov di,bx ; address of pixel at x,y1
\r
409 mov y1_offs,di ; save y1 offset for after upward fill
\r
411 mov ax,Color ; al = Color ah = BoundaryColor
\r
414 cmp si,_TopClip ; Dont fill beyond clip boundaries
\r
415 jl @@UpwardFillDone
\r
419 je @@UpwardFillDone
\r
422 je @@UpwardFillDone
\r
427 jmp short @@FillColUpward
\r
439 push bx ; queue an upward leak check
\r
457 mov ax,Color ; al = Color ah = BoundaryColor
\r
461 jg @@DownwardFillDone
\r
464 je @@DownwardFillDone
\r
467 je @@DownwardFillDone
\r
472 jmp short @@DownwardFill
\r
474 @@DownwardFillDone:
\r
476 push bx ; queue an upward leak check
\r
491 push bx ; queue a downward leak check
\r
502 mov ax,Color ; al = Color ah = BoundaryColor
\r
510 mov dl,byte ptr es:[di]
\r
531 _x_boundary_fill endp
\r