home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.update.uu.se
/
ftp.update.uu.se.2014.03.zip
/
ftp.update.uu.se
/
pub
/
rainbow
/
msdos
/
decus
/
RB140
/
grlib03a.arj
/
FILL.ASM
< prev
next >
Wrap
Assembly Source File
|
1988-12-08
|
11KB
|
476 lines
PAGE ,132
title FILL.ASM
;UPDATE HISTORY
;==============
; 14 nov 84 Convert to CI86 V2.2
; 4 Dec 84 New version to correct idiosyncrosy in graphics option
; in which REPlace & COMPlement modes didn't work properly.
; The pattern write is now done external to the Graphics option.
; 11 Dec 84 Bugfix - free memory after single point or hollow fill.
include asmc.h
SEGEND CODE
RELEASE MACRO addr
mov ax,addr
push ax
call free
add sp,2
ENDM
SEGDEF DATA
EXTRN f_col:BYTE, f_type:BYTE, f_patrn:BYTE, f_style:BYTE
EXTRN gbmod:BYTE, ymax:WORD, gp_buff:WORD, y_start:WORD
EXTRN x_start:WORD, x_stop:WORD, y_stop:WORD, l_type:BYTE
EXTRN l_col:BYTE, sh_p_lin:BYTE, curl0:BYTE, nmritl:BYTE, gbmskl:BYTE
Lymin DW 0
Lymin1 DW 0
Lymax DW 0
Lydif DW 0
Lcntr DW 0
Lcnt1 DW 0
Lnpnt DW 0
Lfpat DW 0
Lbuff DW 0
SEGEND DATA
SEGDEF CODE
PUBLIC polyfill, bar
IF @bigmodel
EXTRN gdc_nb:FAR, a_mode:FAR, malloc:FAR, cxy2cp:FAR, fifo_mt:FAR
EXTRN free:FAR, polyline:FAR, line:FAR, a_gbmsk:FAR, a_cur:FAR
EXTRN chk_col:FAR, a_patrn:FAR, eseg_sav:FAR
ELSE
EXTRN gdc_nb:NEAR, a_mode:NEAR, malloc:NEAR, cxy2cp:NEAR, fifo_mt:NEAR
EXTRN free:NEAR, polyline:NEAR, line:NEAR, a_gbmsk:NEAR, a_cur:NEAR
EXTRN chk_col:NEAR, a_patrn:NEAR, eseg_sav:NEAR
ENDIF
;************************************************************************
;* *
;* F U N C T I O N polyfill(count, array) *
;* int count, *array; *
;* *
;* purpose: Fill an area with a pattern specified by *
;* f_type and f_style which is defined as a *
;* series of 'xy' points [array] whose length *
;* is 'count' 'xy' pairs. *
;* *
;* entry: 8[bp] number of 'xy' pairs in 'array'. *
;* A[bp] pointer to the 'xy' pairs. *
;* *
;************************************************************************
PROCDEF polyfill
push si
push di
push bp
mov bp,sp
mov ax,cs:WORD PTR eseg_sav
mov es,ax
mov ax,0400H ;allocate a 1k area for temporary storage.
push ax
call malloc
add sp,2
or ax,ax
jnz Lv
jmp Lexit1
Lv:
mov Lbuff,ax
call gdc_nb
mov al,BYTE PTR f_col ;change the colour to that specified for
call chk_col ;area filling.
test BYTE PTR gbmod,2 ;are we in vector mode ?
jnz Lv1
or BYTE PTR gbmod,12H
call a_mode
Lv1: mov cx,8[bp]
dec cx
jnz L0a ;finished if it is a single point.
RELEASE Lbuff
jmp Lexit
L0a: mov Lnpnt,cx
mov al,BYTE PTR f_type ;get the fill type.
xor ah,ah
cmp ax,0 ;is it HOLLOW ?
jnz L0b
RELEASE Lbuff
jmp L9 ;finished if yes.
L0b: lea dx, f_patrn
mov bx,0
cmp ax,1 ;fill_type solid ?
jz L0c
add dx,8
mov bl,BYTE PTR f_style
cmp ax,2 ;fill_type PATTERN ?
jz L0c
add bx,8 ;offset f_style for HATCH.
L0c: mov cl,3
shl bx,cl
add dx,bx
mov Lfpat,dx
mov bx,WORD PTR ymax
mov si,10[bp]
lea di, gp_buff
mov cx,8[bp]
L0d: lodsw ;move all the 'xy' pairs to temporary storage
stosw ;in 'gp_buff' and convert all 'y' values to a
mov ax,bx ;bottom left origin.
sub ax,[si]
stosw
add si,2
loop L0d
mov Lymin,3E8H
mov Lymax,0
lea si, gp_buff
mov cx,8[bp]
L1: add si,2
lodsw
cmp ax,Lymin
jnl L2
mov Lymin,ax
L2: cmp ax,Lymax
jle L2a
mov Lymax,ax
L2a: loop L1
mov ax,Lymin
mov Lymin1,ax
mov bx,Lymax
sub bx,ax
mov Lydif,bx
jnz L2b
jmp L7
L2b: mov al,78H
out 57H,al
mov al,0ffH
out 56H,al
out 56H,al
L3: mov Lcntr,0
mov cx,Lnpnt
lea si, gp_buff
L4: push cx
mov di,si
add di,4
push si
call L10
pop si
add si,4
pop cx
loop L4
lea di, gp_buff
call L10
mov ax,Lcntr
shr ax,1
jnz L4a
jmp L6
L4a: mov Lcnt1,ax
mov si,Lymin1
mov WORD PTR y_start,si
and si,7
neg si
add si,7
add si,Lfpat
mov al,BYTE PTR [si]
mov ah,al
mov bx,Lbuff
L5: push ax
push bx
mov cx,[bx]
mov WORD PTR x_start,cx
push cx
push ax
call gdc_nb
call cxy2cp
mov al,0fdH ;select the PATTERN MULTIPLIER.
out 53H,al
mov al,0fH ;x1 pattern.
out 51H,al
mov al,0fbH ;select the PATTERN REGISTER.
out 53H,al
pop ax
pop cx
and cx,000fH
ror ax,cl
out 51H,al
mov al,4CH ;issue the FIGS command.
out 57H,al
mov al,02H
out 56H,al
mov ax,2[bx]
sub ax,WORD PTR x_start
out 56H,al
xchg al,ah
out 56H,al
xchg al,ah
neg ax
out 56H,al
xchg al,ah
out 56H,al
xchg al,ah
shl ax,1
out 56H,al
xchg al,ah
out 56H,al
mov al,6CH ;issue the DRAW command.
out 57H,al
pop bx
pop ax
add bx,4
dec Lcnt1
jz L6
jmp L5
L6: inc Lymin1
dec Lydif
jz L7
jmp L3
L7: RELEASE Lbuff
mov bx,WORD PTR ymax
lea di, gp_buff+2
mov si,di
mov cx,8[bp]
L8: mov ax,bx
sub ax,[si]
stosw
add si,4
add di,2
loop L8
L9: call gdc_nb
mov al,BYTE PTR l_type ;get current line type.
push ax
mov BYTE PTR l_type,0 ;make it a solid line.
call a_patrn ;assert it.
mov al,BYTE PTR l_col
call chk_col
pop ax
mov BYTE PTR l_type,al ;restore the old line type.
mov ax,10[bp] ;join all the points with a polyline.
push ax
mov ax,8[bp]
push ax
call polyline
pop cx
pop si
lodsw ;now join the first point to the last point.
mov WORD PTR x_start,ax
lodsw
mov WORD PTR y_start,ax
sub cx,2
jz Lexit ;finished if it was a straight line.
shl cx,1
shl cx,1
add si,cx
lodsw
mov WORD PTR x_stop,ax
lodsw
mov WORD PTR y_stop,ax
lea ax, x_start
push ax
call line
add sp,2
Lexit: mov ax,0001H
Lexit1: pop bp
pop di
pop si
ret
L10: mov bx,2[di]
sub bx,2[si]
jz L17
mov ax,Lymin1
mov cx,ax
sub cx,2[si]
sub ax,2[di]
xor ax,cx
jns L17
mov ax,[di]
sub ax,[si]
shl cx,1
imul cx
idiv bx
inc ax
sar ax,1
add ax,[si]
mov bx,[si]
mov cx,[di]
cmp bx,cx
jle L11
xchg bx,cx
L11: cmp ax,bx
jnl L12
mov ax,bx
L12: cmp ax,cx
jle L13
mov ax,cx
L13: mov di,Lbuff
mov cx,Lcntr
jcxz L16
L14: scasw
jl L15
loop L14
jmp L16
L15: mov di,Lcntr
shl di,1
add di,Lbuff
mov si,di
sub si,2
std
rep movsw
cld
L16: stosw
inc Lcntr
L17: ret
PROCEND polyfill
;************************************************************************
;* *
;* F U N C T I O N bar[array] int *array; *
;* *
;* purpose: set a user defined screen rectangle to a user *
;* defined color. *
;* entry: 0x06[bp] has the pointer to the 'xy' array *
;* *
;* 0[array] has the start x in pixels *
;* 6[array] has the start y in scan lines *
;* 4[array] has the stop x in pixels *
;* 2[array] has the stop y in scan lines *
;* f_col is the color to fill the bar with. *
;* *
;* NOTE: both 'y' values are relative to a bottom left origin *
;* *
;************************************************************************
PROCDEF bar
push si
push bp
mov bp,sp
sub sp,4 ;make room for local y start and y stop
mov si,6[bp] ;get the array pointer
mov ax,WORD PTR ymax ;adjust both 'y' values for top left origin
sub ax,2[si]
mov -2[bp],ax
mov ax,WORD PTR ymax
sub ax,6[si]
mov -4[bp],ax
mov ax,[si] ;turn bl_x address into word address.
mov cl,4
shr ax,cl
mov dx,-4[bp] ;turn tr_y into words per line * y.
mov cx,WORD PTR sh_p_lin ;high res = 6, medium res = 5.
shl dx,cl
add dx,ax ;combine x and y word addresses.
mov WORD PTR curl0,dx ;first curl0.
mov ax,-2[bp] ;find number of lines to write by:
sub ax,-4[bp] ; bl_y - tr_y
mov WORD PTR nmritl,ax
call gdc_nb
mov al,BYTE PTR f_col ;check for correct colour.
call chk_col
test BYTE PTR gbmod,2
jz Lb0
and BYTE PTR gbmod,0fdH ;put into word mode.
or BYTE PTR gbmod,010H ;put into write-enable mode.
call a_mode
Lb0: mov al,0FEH ;reset write buffer counter.
out 53H,al
out 51H,al
mov cx,10H
xor al,al
Lba: out 52H,al ;fill buffer with zero's.
loop Lba
;
;program the text mask:
;there are four possible write conditions:
;a]partially write disabled to theleft
;b]completely write enabled
;c]partially write disabled to the right
;d]partially write disabled to both left and right
Lb1: mov bx,0ffffH ;calculate the current write mask.
mov cx,[si] ;get bl_x
and cx,0fH ;eliminate all but pixel information.
shr bx,cl ;shift in a 0 for each left pixel to disable.
mov ax,[si] ;test to see if word tr_x is equal
and ax,0fff0H ;to word bl_x.
mov cx,4[si]
and cx,0fff0H
cmp ax,cx ;below?
jb Lb3 ;jump if yes.
je Lb2 ;jump if equal. do last write.
add sp,4
pop bp ;exit.
pop si
ret
Lb2: mov cx,4[si] ;get pixel info out of tr_x.
and cx,0fH
inc cx ;make endpoint inclusive of write.
mov ax,0ffffH ;shift the disable mask.
shr ax,cl ;wherever there is a one, we want to
xor ax,0ffffH ;enable writes.
and bx,ax ;combine right and left masks.
Lb3: xor bx,0ffffH ;invert so where there is a 1 we write disable.
mov WORD PTR gbmskl,bx ;make sure that the GDC isn't busy
call gdc_nb
call a_gbmsk ;and assert the write mask.
call a_cur ;assert the GDC cursor address.
mov al,4cH ;assert figs to GDC.
out 57H,al
xor al,al ;direction is down.
out 56H,al
mov ax,WORD PTR nmritl
out 56H,al ;assert number of write operations to perform.
mov al,ah
out 56H,al
mov al,22H ;assert write data command.
out 57H,al
mov al,0ffH
out 56H,al
out 56H,al
and [si],0fff0H ;strip off pixel info.
add WORD PTR [si],16 ;address the next word.
inc WORD PTR curl0
jmp Lb1 ;check for another column to clear.
PROCEND bar
include epilogue.h
END