home *** CD-ROM | disk | FTP | other *** search
- ;
- ; gr_drive.asm
- ;
- ; Purpose: Graphics primitives.
- ;
- ; Blackstar C Function Libarary
- ; (c) Copyright 1985,1989 Sterling Castle Software
- ;
-
- include model
- include blackstr.mac
-
-
- dseg 'DATA'
-
- ;--------------------------
- ; graphics variables
- ;--------------------------
- wrdot equ 12
- rddot equ 13
- video equ 010h ;video interrupt number
-
- gbuf db 255 dup (0)
-
- ifdef asm_386
- ptptr dd $
- dele dd ?
- delp dd ?
- dels dd ?
- delsx dd ? ;deltas for straight and diagonal
- delsy dd ?
- delse dd ? ;error delta
- deldx dd ? ;diagonal deltas
- deldy dd ?
- delde dd ?
- else
- ptptr dw $
- dele dw ?
- delp dw ?
- dels dw ?
- delsx dw ? ;deltas for straight and diagonal
- delsy dw ?
- delse dw ? ;error delta
- deldx dw ? ;diagonal deltas
- deldy dw ?
- delde dw ?
- endif
-
- public _grx_,_gry_,_grcols_,_grrows_,_grmode_
- public _grbcolr_,_grbcol_,_grfcol_,_grfcolr_
- public _grxorf_,_grfpal_,_grbpal_
- public _gr_minx_,_gr_miny_,_gr_maxx_,_gr_maxy_
- public _gr_seg_,_gr_off_,_gr_buf_,_gr_bytes_
-
- ;--------------
- ; ints
- ;--------------
- ifdef asm_386
- alias gr_minx_ DWORD
- _gr_minx_ dd 0 ;minimum x
- alias gr_maxx_ DWORD
- _gr_maxx_ dd 0 ;max x
- alias gr_miny_ DWORD
- _gr_miny_ dd 0 ;minimum y
- alias gr_maxy_ DWORD
- _gr_maxy_ dd 0 ;max y
- alias gr_bytes_ DWORD
- _gr_bytes_ dd 16384 ;# bytes in buffer
- alias grx_ DWORD
- _grx_ dd 0 ;graphics cursor y position
- alias gry_ DWORD
- _gry_ dd 0 ;graphics cursor y position
- alias grrows_ DWORD
- _grrows_ dd 0 ;maximum value in x position
- alias grcols_ DWORD
- _grcols_ dd 0 ;maximum value in y position
- alias grmode_ DWORD
- _grmode_ dd 0 ;graphics mode
- else
- alias gr_minx_ WORD
- _gr_minx_ dw 0 ;minimum x
- alias gr_maxx_ WORD
- _gr_maxx_ dw 0 ;max x
- alias gr_miny_ WORD
- _gr_miny_ dw 0 ;minimum y
- alias gr_maxy_ WORD
- _gr_maxy_ dw 0 ;max y
- alias gr_bytes_ WORD
- _gr_bytes_ dw 16384 ;# bytes in buffer
- alias grx_ WORD
- _grx_ dw 0 ;graphics cursor y position
- alias gry_ WORD
- _gry_ dw 0 ;graphics cursor y position
- alias grrows_ WORD
- _grrows_ dw 0 ;maximum value in x position
- alias grcols_ WORD
- _grcols_ dw 0 ;maximum value in y position
- alias grmode_ WORD
- _grmode_ dw 0 ;graphics mode
- endif
-
- ; Need a pointer to the display buffer for large models
- ; as well as the seg and offset values for small models
- ;------------------
- ; char * gr_buf_
- ;------------------
- ifdef asm_386 ;LARGE_DATAgenerate regen buffer address
- alias gr_buf_ DWORD
- alias _gr_buf_ DWORD
- else
- alias gr_buf_ WORD
- alias _gr_buf_ WORD
- endif
-
- ifdef asm_386
- alias gr_off_ DWORD
- _gr_off_ dd 0 ;buffer offset
- else
- alias gr_off_ WORD
- _gr_off_ dw 0 ;buffer offset
- endif
-
- alias gr_seg_ WORD
- ifdef asm_386
- _gr_seg_ dw 1ch ;Pharlap's graphics segment
- else
- _gr_seg_ dw 0b800h ;graphics segment
- endif
-
- alias grxorf_ BYTE
- _grxorf_ db 0 ;xor flag for set point
- alias grbcolr_ BYTE
- _grbcolr_ db 0 ;graphics background color
- alias grbcol_ BYTE
- _grbcol_ db 0 ;graphics background color for gr_wfill
- alias grfcolr_ BYTE
- _grfcolr_ db 0 ;graphics foreground color value
- alias grfcol_ BYTE
- _grfcol_ db 0 ;graphics foreground color for gr_pt
-
- ;--------------------
- ; char * grfpal_
- ;--------------------
- ifdef asm386 ;LARGE_DATA
- alias grfpal_ DWORD
- _grfpal_ dd 0 ;foreground color palette
- alias grbpal_ DWORD
- _grbpal_ dd 0 ;background color palette
- else
- alias grfpal_ WORD
- _grfpal_ dw 0 ;foreground color palette
- alias grbpal_ WORD
- _grbpal_ dw 0 ;background color palette
- endif
- enddseg
-
-
- cseg gr_pt__
-
- ;-----------------
- ; Macros
- ;-----------------
- ;
-
- mwrdot macro ;write a dot (ecx,edx is x,y)
- mov ah,wrdot
- mov bh,0
- int video
- endm
-
- mrddot macro ;read a dot macro
- mov ah,rddot
- mov bh,0 ;do this for EGA
- int video
- mov ah,0
- endm
-
- ;-----------------
- ; gr_pt_(x,y) set point at x,y
- ;------------------
- ; Useage: gr_pt_(x,y);
- ;
- ; int gr_pt_(int x, int y);
-
- public gr_pt_
-
- gr_pt_ proc
- parm386<<x,dword>,<y,dword>>
- parm86 <<x,word>,<y,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov al,_grfcol_ ;foreground color
- or al,_grxorf_ ;xor it?
- mov ecx,x
- mov edx,y
- mwrdot ;do write dot command
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- gr_pt_ endp
-
-
- ;--------------------
- ; gr_gpt_(x,y) get color of point at x,y
- ;--------------------
- ; Usage: gr_gpt_(x,y);
- ;
- ; int gr_gpt_(int x, int y);
-
- public gr_gpt_
-
- gr_gpt_ proc
- parm386<<xa,dword>,<ya,dword>>
- parm86 <<xa,word>,<ya,word>>
- prolog
-
- mov ecx,xa ;x co-ordinate
- mov edx,ya ;y co-ordinate
- mrddot ;read dot command
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- gr_gpt_ endp
-
-
- ;--------------------
- ; gr_gwin_(buff) get current graphics windo to buff
- ;--------------------
- ; Usage: gr_gwin_(buff)
- ;
- ; int gr_gwin_(char *buff);
-
- public gr_gwin_
-
- gr_gwin_ proc
- parms<<buff,ptr>>
- prolog
- push es
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- loadptr les,edi,buff ;buffer addr
- mov edx,_gr_miny_
- grwi0: mov ecx,_gr_minx_ ;start at diag pt
-
- grwi1: mrddot ;read the dot
- mov es:[edi],al ;store in buff
- inc edi
- inc ecx
- cmp ecx,_gr_maxx_ ;done a line?
- jle grwi1
- inc edx
- cmp edx,_gr_maxy_ ;done all lines?
- jle grwi0
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- pop es ;restore es
- epilog
- gr_gwin_ endp
-
-
- ;--------------------
- ; gr_pwin_(buff) put buff to current graphics
- ;--------------------
- ; Usage: gr_pwin_(buff)
- ;
- ; int gr_pwin_(char *buff);
-
- public gr_pwin_
-
- gr_pwin_ proc
- parms<<buffa,ptr>>
- prolog
- push es
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- loadptr les,edi,buffa ;buffer address
- mov edx,_gr_miny_
- grpi0: mov ecx,_gr_minx_ ;start at diag pt
-
- grpi1: mov al,es:[edi] ;get value for dot
- mwrdot ;write the dot
- inc edi ;point edi to next value to write
- inc ecx
- cmp ecx,_gr_maxx_ ;done a line?
- jle grpi1
- inc edx
- cmp edx,_gr_maxy_ ;done all lines?
- jle grpi0
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- pop es ;restore es
- epilog
- gr_pwin_ endp
-
-
-
- ;-----------------------
- ; gr_ln_(x1,y1,x2,y2) draw a line from x1,y1 to x2,y2
- ;-----------------------
- ; Useage: gr_ln_(x1,y1,x2,y2)
- ;
- ; int gr_ln_(int x1, int y1, int x2, int y2);
-
- public gr_ln_
-
- gr_ln_ proc
- parm386<<x1,dword>,<y1,dword>,<x2,dword>,<y2,dword>>
- parm86<<x1,word>,<y1,word>,<x2,word>,<y2,word>>
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov esi,1 ;start with 1 increments
- mov edi,1
- mov edx,y2 ;find y2-y1
- sub edx,y1
- jge line1 ;skip if y2>=y1
-
- neg edi ;negative increments for y
- neg edx ;absolute value of y2-y1
-
- line1: mov deldy,edi ;store y update for diagonal moves
- mov ecx,x2 ;find x2-x1
- sub ecx,x1
- jge line2 ;skip if x2>x1
-
- neg esi ;negative increment for x
- neg ecx ;absolute value of x2-x1
-
- line2: mov deldx,esi ;store x update for diagonal moves
- cmp ecx,edx ;edx or dy bigger?
- jge setdiag ;ok
-
- mov esi,0 ;kill x increment
- xchg ecx,edx ;and use the y
- jmp line3
-
- setdiag:mov edi,0 ;kill y increment (will use x )
-
- line3: mov dels,ecx ;change in straight
- mov delp,edx ;change in perpendicular
- mov delsx,esi ;x update in straght
- mov delsy,edi ;y update in straight
-
- mov esi,x1 ;x1 to esi
- mov edi,y1 ;y1 to edi
- mov eax,delp
- sal eax,1 ;2 * delp
- mov delse,eax ;error change if straight move
- sub eax,ecx ;2*delp - dels
- mov ebx,eax ;initial value
- sub eax,ecx ;2*delp - 2*dels
- mov delde,eax ;change if diagonal move
- inc ecx ;adjust count
-
- lineit: push ebx ;save error term
- push ecx
- push edi ;y
- push esi ;x
-
- ifdef Large_code
- push cs
- endif
-
- call gr_pt_ ;set it
- add esp,2*Word_size ;remove from stack
- pop ecx
- pop ebx
- cmp ebx,0 ;straight or diagonal
- jge linedi
-
- linest: add esi,delsx ;update x
- add edi,delsy ;update y
- add ebx,delse ;update error term
- loop lineit
- jmp line_x ;and exit
-
- linedi: add esi,deldx ;update x
- add edi,deldy ;update y
- add ebx,delde ;update error term
- loop lineit
-
- line_x:
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- gr_ln_ endp
-
-
-
- ;-------------------------
- ; gr_wfill_ fill a window
- ;-------------------------
- ; Usage: gr_wfill_()
- ;
- ; int gr_wfill(void);
-
- public gr_wfill_
-
- gr_wfill_ proc
- prolog
-
- ifdef Large_data
- mov ax,seg dgroup
- mov ds,ax
- endif
-
- mov ecx,_gr_minx_
- wfill: mov edx,_gr_miny_
-
- wfill1: mov al,_grfcol_
- mwrdot
- inc edx
- cmp edx,_gr_maxy_
- jl wfill1
-
- wfill2: inc ecx
- cmp ecx,_gr_maxx_
- jl wfill
-
- ifdef asm_386
- movsx eax,ax
- endif
-
- epilog
- gr_wfill_ endp
-
- endcseg gr_pt__
- end
-
-
-