home *** CD-ROM | disk | FTP | other *** search
- page 58,132
-
- ;
- ; cirline.asm
- ; contains: gcircle(),gline(),setmaxx(),setmaxy()
- ;
- include model.h
- include prologue.h
- name cirline
-
- dseg cirlin
- color dw 0
- dir dw 0
- maxxval dw 639
- maxyval dw 199
- endds
-
- dyn struc
- cury dw ?
- curx dw ?
- c1000 dw ?
- iaspect dw ?
- aspect dw ?
- yp dw ?
- xp dw ?
- db @ab dup(?) ;pushed bp & return address
- xx dw ?
- yy dw ?
- radius dw ?
- colr dw ?
- numer dw ?
- denom dw ?
- dyn ends
-
- ldyn struc
- db @ab dup(?) ;pushed bp & return address
- x1 dw ?
- y1 dw ?
- x2 dw ?
- y2 dw ?
- clr dw ?
- ldyn ends
-
- pseg circ
-
- ;==>-- void gcircle(x,y,radius,color,aspectnumer,aspectdenom)
- ;
- ;; ARGUMENTS:
- ; (int) x - Center coordinate
- ; (int) y - Center coordinate
- ; (int) radius - Radius of circle
- ; (int) color - Foreground color
- ; (int) aspectnumer - Aspect Ratio numerator
- ; (int) aspectdenom - Aspect Ratio denominator
- ;
- ;; DESCRIPTION:
- ; A graphics circle or elipse is drawn. The indicated color is
- ; used for the object, which has its center at coordinates x,y.
- ; The aspect ratio may be 1 for a circle, < 1 for an elipse
- ; wider than it is high, or > 1 for a thin, high elipse, and it
- ; is computed internally as aspect_numer/aspect_denom.
- ;
- ;; AUTHOR:
- ; Adapted from pp 140-154 of "The Serious Assembler" (c) 1985
- ; by Charles A. Crayne and Dian Girard
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc gcircle,,,,14
- mov ax,[bp].colr
- and ax,00ffh ;15 is greatest color.
- mov color,ax ;local store color
- mov ax,[bp].numer ;aspect numerator
- cmp ax,0 ;can't use 0 here or negatives.
- jg ok1
- jmp cxit
- ok1: cmp [bp].denom,0 ;..or here..
- jg ok2
- jmp cxit
- ok2: mov [bp].c1000,1000 ;scale factor = 1000
- imul [bp].c1000
- idiv [bp].denom ;ax=aspect*1000
- mov [bp].aspect,ax ; save aspect
- mov ax,[bp].denom ;get denom
- imul [bp].c1000 ;sacle it..
- idiv [bp].numer ;ax = inv aspect * 1000
- mov [bp].iaspect,ax ;save it..
- ;
- ; y=y+1 x=x-tan(inv aspect)
- ;
- mov ax,[bp].radius ;get radius
- cmp ax,1
- jg ok3
- jmp cxit ;don't do it if it doesn't exist
- ok3: mov [bp].xp,ax ;1st previous x
- imul [bp].c1000 ;scale
- mov [bp].cury,0 ;zero initial y value
- circa: push ax
- push dx
- add ax,500 ;round it
- adc dx,0
- idiv [bp].c1000 ;rescale x
- mov bx,ax ;1st quad
- push bx ;new calculated x
- circaa: add ax,[bp].xx ;add x origin
- mov di,[bp].yy ;y origin
- sub di,[bp].cury
- mov si,ax ;get x to plot
- call point ; and plot it
- sub si,bx ;get 2nd quadrant
- sub si,bx ; x+origin
- call point
- add di,[bp].cury ;get 3rd quadrant
- add di,[bp].cury ;y+origin
- call point
- add si,bx ;get 4th quadrant
- add si,bx ;x+origin
- call point
- inc bx
- cmp bx,[bp].xp ;x gap ?
- jae circb ; no..
- mov ax,bx ;set intermediate point
- jmp circaa ;go plot it..
-
- circb: pop bx ;calculated x
- mov [bp].xp,bx ;previous x
- inc [bp].cury ;new y
- mov ax,[bp].cury ;y
- imul [bp].iaspect
- idiv bx ;tan*inv aspect
- xor dx,dx ; remainder
- mov [bp].curx,ax ;curx=tan*inv aspect
- idiv [bp].iaspect ;ax=tan
- cmp ax,1 ;tan=1 ?
- pop dx
- pop ax
- jae circc ;go to next sector
- neg [bp].curx ;to dec x
- add ax,[bp].curx ;new x value
- adc dx,-1 ;negative carry
- jmp short circa ;plot new point
- ;
- ; Plot 45 to 90 degrees.
- ;
- circc: mov ax,[bp].cury ;next y
- mov [bp].yp,ax ;init previous x
- imul [bp].c1000 ;dx:ax=y*1000
- mov [bp].cury,bx ;last x value
- dec [bp].cury ;next x
- circd: push ax
- push dx
- add ax,500 ;round
- adc dx,0
- idiv [bp].c1000
- mov bx,ax ;1st quad
- push bx
- circda: add ax,[bp].yy ;add y origin
- mov si,[bp].xx ;x origin
- add si,[bp].cury
- mov di,ax ;y
- call point
- sub si,[bp].cury ;2nd quadrant
- sub si,[bp].cury ;x
- call point
- sub di,bx ;3rd quadrant
- sub di,bx ;y
- call point
- add si,[bp].cury ;4th quad
- add si,[bp].cury ;x
- call point
- dec bx
- cmp bx,[bp].yp ;gap ?
- jbe circe ;no
- mov ax,bx
- jmp circda ;plot intermediate point
- circe: pop bx
- mov [bp].yp,bx ;save previous 7
- sub di,[bp].yy ;y-y orign
- neg di ;y origin adjust
- xchg si,di ;si=y
- cmp [bp].cury,0 ;90 degree ?
- js circg ;yes,exit
- dec [bp].cury ;new x
- mov ax,[bp].cury
- imul [bp].aspect ;aspect*1000
- idiv si
- mov [bp].curx,ax ;delta y
- pop dx
- pop ax
- xor bx,bx
- cmp [bp].curx,0 ;sign check
- jns circf ;positive
- mov bx,-1 ;negative carry
- circf: add ax,[bp].curx ;new xvalue
- adc dx,bx ;hi word carry
- jmp circd ;plot next point
- circg:
- cxit: add sp,4
- cproce
-
-
- ;==>-- void gline(x1,y1,x2,y2,color)
- ;
- ;; ARGUMENTS:
- ; (int) x1 - x co-ordinate of end 1
- ; (int) y1 - y co-ordinate of end 1
- ; (int) x2 - x co-ordinate of end 2
- ; (int) y2 - y co-ordinate of end 2
- ; (int) color - color 0..2
- ;
- ;; DESCRIPTION:
- ; A line is drawn between two end points defined by the coordinate
- ; sets x1,y1 and x2,y2. The specified color is used as a selection
- ; of one of three colors for the palette.
- ;
- ;; AUTHOR:
- ; Adapted from pp 140-154 of "The Serious Assembler" (c) 1985
- ; by Charles A. Crayne and Dian Girard
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc gline
- mov ax,[bp].clr ;color
- mov color,ax ;put where point can get it
- mov si,[bp].x1 ;get coordinates to registers.
- mov di,[bp].y1
- mov ax,[bp].x2
- mov bx,[bp].y2
- mov dx,0
- cmp si,ax
- jbe noxchg
- xchg si,ax
- xchg di,bx
- noxchg: sub ax,si
- mov bp,ax
- sub bx,di
- mov cx,1
- jns notneg
- neg cx
- neg bx
- notneg: mov dir,cx
- mov ax,bx ;save y diff constant in ax
- call point
- cmp bp,bx
- jle case1 ;delta x le delta y
- jmp short case2 ;delta x gt delta y
- case1: cmp dir,1
- jne case3 ;negative y
- mov cx,ax
- lp1: dec cx
- js lxit
- inc di
- add dx,bp
- cmp ax,dx
- ja skp1
- sub dx,ax
- inc si
- skp1: call point
- jmp short lp1
-
- case3: mov cx,ax
- lp3: dec cx
- js lxit
- dec di
- add dx,bp
- cmp ax,dx
- ja skp3
- sub dx,ax
- inc si
- skp3: call point
- jmp short lp3
-
- case2: cmp dir,1
- jne case4 ;negative y
- mov cx,bp
- lp2: dec cx
- js lxit
- inc si
- add dx,ax
- cmp bp,dx
- ja skp2
- sub dx,bp
- inc di
- skp2: call point
- jmp short lp2
- case4: mov cx,bp
- lp4: dec cx
- js lxit
- inc si
- add dx,ax
- cmp bp,dx
- ja skp4
- sub dx,bp
- dec di
- skp4: call point
- jmp short lp4
- lxit:
- cproce
-
- ;==>-- void setmaxx(max)
- ;
- ;; ARGUMENTS:
- ; (int) max - set maximum value for x-axis
- ;
- ;; DESCRIPTION:
- ; This function sets a local variable that is used to determine
- ; when an x value is out of range.
- ;
- ;; SIDE EFFECTS:
- ; local variable is modified.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc setmaxx
- mov ax,parm1_
- mov maxxval,ax
- cproce
-
- ;==>-- void setmaxy(max)
- ;
- ;; ARGUMENTS:
- ; (int) max - set maximum value for y-axis
- ;
- ;; DESCRIPTION:
- ; This function sets a local variable that is used to determine
- ; when an y value is out of range.
- ;
- ;; SIDE EFFECTS:
- ; local variable is modified.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;;;
- cproc setmaxy
- mov ax,parm1_
- mov maxyval,ax
- cproce
- ;
- ; Plot one point.
- ;
- point proc near
- push bp
- push ax
- push bx
- push cx
- push dx
- push si
- push di
- cmp si,0 ;left side
- jl ptxit
- cmp di,0 ;top edge
- jl ptxit
- cmp si,maxxval
- jg ptxit
- cmp di,maxyval
- jg ptxit
- mov dx,di ;row
- mov cx,si ;col
- mov ax,color ;color
- mov ah,12 ;function to write DOT
- xor bh,bh
- int 10h ;write it !
- ptxit: pop di
- pop si
- pop dx
- pop cx
- pop bx
- pop ax
- pop bp
- ret
- point endp
- endps
- end
-