home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
norge.freeshell.org (192.94.73.8)
/
192.94.73.8.tar
/
192.94.73.8
/
pub
/
computers
/
cpm
/
alphatronic
/
CGRAPH.ZIP
/
CIRCLE.DOC
< prev
next >
Wrap
Text File
|
1998-07-30
|
6KB
|
324 lines
The following is an update to the CIRCLE subroutine which is a part
of the PLOT.MAC source code. This version produces a circle with less
"jitter" due to round-up procedures in the polar to cartesian coordinate
conversions. The SIN and COS tables have also been rewritten as complete
90 degree sets which are reciprocals of each other. This routine was used
with a digital plotter, the DP-2, by HIPL0T. It will run a little slower
than the subroutine which is in the source code PLOT.MAC, but is compatible
with it.
;
; ************************************************************************
;
; CIRCLE Subroutine:
;
CIRCLE:
IF PAS.Z
;
ENTRY CIRCLE
PUSH IX
PUSH IY
LD A,3 ; 3 parameters
CALL Z.LNK
ENDIF
;
IF BASIC
;
LD B,3
CALL B.LNK
ENDIF
;
CALL PENUP ;move to starting position
LD HL,(P1)
LD DE,(P3)
ADD HL,DE
LD (X1),HL
LD HL,(P2)
LD (Y1),HL
CALL MOVE
CALL PENDWN
;
LD IX,SINTBL
LD IY,COSTBL
;
LD C,0 ;C=quadrant counter
CIRC0:
LD B,90 ;B=degree counter
CIRC1:
PUSH BC
CALL POLAR ;convert to polar coordinates
POP BC
PUSH BC
LD A,C
CP 0 ;quadrant 0
CALL Z,XPRCOS
CALL Z,YPRSIN
CP 1 ;quadrant 1
CALL Z,XMRCOS
CALL Z,YPRSIN
CP 2 ;quadrant 2
CALL Z,XMRCOS
CALL Z,YMRSIN
CP 3 ;quadrant 3
CALL Z,XPRCOS
CALL Z,YMRSIN
CP 4 ;octant # 4
CALL Z,XMRCOS
CALL Z,YMRSIN
BIT 0,A
CALL Z,MOVEUP ;even quadrant
CALL NZ,MOVEDN ;odd quadrant
POP BC
DEC B
JP P,CIRC1
BIT 0,C
CALL Z,INDXDN ;even quadrant
CALL NZ,INDXUP ;odd quadrant
INC C
LD A,C
CP 4 ;four quadrants
JR NZ,CIRC0
;
CALL PENUP
;
IF PAS.Z
POP IY
POP IX
XOR A
ENDIF
;
RET
;
MOVEUP:
PUSH AF ;save flags
CALL MOVE ;draw line
POP AF ;restore flags
INDXUP:
DEC IX ;point to next sin()
DEC IX
INC IY ;point to next cos()
INC IY
RET
MOVEDN:
PUSH AF ;save flags
CALL MOVE ;draw line
POP AF ;restore flags
INDXDN:
INC IX ;point to next sin()
INC IX
DEC IY ;point to next cos()
DEC IY
RET
;
XPRCOS: ; x + r*cos()
PUSH AF ;save flags
LD DE,(RCOS)
LD HL,(P1)
ADD HL,DE
JR XMRCS1
XMRCOS: ; x - r*cos()
PUSH AF
LD DE,(RCOS)
LD HL,(P1)
OR A
SBC HL,DE
XMRCS1: LD (X1),HL
POP AF
RET
;
YPRSIN: ; y + r*sin()
PUSH AF ;save flags
LD DE,(RSIN)
LD HL,(P2)
ADD HL,DE
JR YMRSN1
YMRSIN: ; y - r*sin()
PUSH AF
LD DE,(RSIN)
LD HL,(P2)
OR A
SBC HL,DE
YMRSN1: LD (Y1),HL
POP AF
RET
;
POLAR:
LD D,(IX+1) ;get sin()
LD E,(IX)
LD BC,(P3) ;radius
CALL MULT
BIT 7,H ;round up if set
JR Z,PLR1
INC DE
PLR1: LD (RSIN),DE ;r*sin()
LD D,(IY+1) ;get cos()
LD E,(IY)
LD BC,(P3)
CALL MULT
BIT 7,H ;round up if set
JR Z,PLR2
INC DE
PLR2: LD (RCOS),DE ;r*cos()
RET
;
RSIN: DEFW 0
RCOS: DEFW 0
;
;
; MULT: from ELECTRONICS/Mar 24, 1983 Designer's Casebook
; article by Bernard Coupe
; performs a 2-byte by 2-byte integer multiply
; (BC)*(DE)-->(DE),(HL)
;
MULT:
LD A,E ;load lowest-order byte of multiplier
CALL BCMULT ;do 1-byte multiply
PUSH HL ;save lowest-order bytes of product
PUSH AF ;save highest-order bytes of product
LD A,D ;take multiplier
CALL BCMULT+2 ;do second 1-byte multiply
LD D,A ;position highest-order byte of product
POP AF ;get highest-order byte of first product
ADD A,H ;update third byte of product
LD H,L ;relocate lowest-order bytes of second prod
LD L,E ;reset L at 0
LD E,A ;put third byte of product in E
JR NC,NC1 ;do not increment D if no carry
INC D ;update D if carry
NC1: POP BC ;get lowest-order 2 bytes of first prod
ADD HL,BC ;get final product lowest-order 2 bytes
RET NC ;done if no carry
INC DE ;update highest-order 2 bytes
RET
;
; A-HL will contain A*BC
; BC and D not affected
;
MULMAC MACRO
LOCAL ZERO
JR NC,ZERO ;zero skip
ADD HL,BC ; one add multiplicand
ADC A,E ; add carry to third byte of product
ZERO: ADD HL,HL ;shift product left
ADC A,A
ENDM
;
BCMULT: LD E,0 ; 0->E for first product
LD H,E ; zero partial product
LD L,E
ADD A,A ; get first multiplier bit
MULMAC
MULMAC
MULMAC
MULMAC
MULMAC
MULMAC
MULMAC
RET NC ; done if no carry
ADD HL,BC ; or do last add
ADC A,E
RET ;and return
;
PAGE 60
; COSTBL and SINTBL are tables of cosine and sine values
; specified as 16-bit unsigned positive fractions. Each
; table is 90 units (degrees) long, and are reciprocals.
;
COSTBL:
DEFW 65535 ;0 degrees, SINTBL 90 degrees
DEFW 65526 ;1
DEFW 65496 ;2
DEFW 65446 ;3
DEFW 65376 ;4
DEFW 65287 ;5
DEFW 65177 ;6
DEFW 65048 ;7
DEFW 64898 ;8
DEFW 64729 ;9
DEFW 64540 ;10
DEFW 64332 ;11
DEFW 64104 ;12
DEFW 63856 ;13
DEFW 63589 ;14
DEFW 63303 ;15
DEFW 62997 ;16
DEFW 62672 ;17
DEFW 62328 ;18
DEFW 61966 ;19
DEFW 61584 ;20
DEFW 61183 ;21
DEFW 60764 ;22
DEFW 60326 ;23
DEFW 59870 ;24
DEFW 59396 ;25
DEFW 58903 ;26
DEFW 58393 ;27
DEFW 57865 ;28
DEFW 57319 ;29
DEFW 56756 ;30
DEFW 56175 ;31
DEFW 55578 ;32
DEFW 54963 ;33
DEFW 54332 ;34
DEFW 53684 ;35
DEFW 53020 ;36
DEFW 52339 ;37
DEFW 51643 ;38
DEFW 50931 ;39
DEFW 50203 ;40
DEFW 49461 ;41
DEFW 48703 ;42
DEFW 47930 ;43
DEFW 47143 ;44
DEFW 46341 ;45
;
PAGE 60
;
DEFW 45525 ;46
DEFW 44695 ;47
DEFW 43852 ;48
DEFW 42995 ;49
DEFW 42126 ;50
DEFW 41243 ;51
DEFW 40348 ;52
DEFW 39441 ;53
DEFW 38521 ;54
DEFW 37590 ;55
DEFW 36647 ;56
DEFW 35693 ;57
DEFW 34729 ;58
DEFW 33754 ;59
DEFW 32768 ;60
DEFW 31772 ;61
DEFW 30767 ;62
DEFW 29753 ;63
DEFW 28729 ;64
DEFW 27697 ;65
DEFW 26656 ;66
DEFW 25607 ;67
DEFW 24550 ;68
DEFW 23486 ;69
DEFW 22415 ;70
DEFW 21336 ;71
DEFW 20252 ;72
DEFW 19161 ;73
DEFW 18064 ;74
DEFW 16962 ;75
DEFW 15855 ;76
DEFW 14742 ;77
DEFW 13626 ;78
DEFW 12505 ;79
DEFW 11380 ;80
DEFW 10252 ;81
DEFW 9121 ;82
DEFW 7987 ;83
DEFW 6850 ;84
DEFW 5712 ;85
DEFW 4572 ;86
DEFW 3430 ;87
DEFW 2287 ;88
DEFW 1144 ;89
SINTBL: DEFW 0 ;90 COSTBL, SINTBL 0 degrees
;
PAGE 60
;*************************************************************************