;--------------------
;     From: Michael Dehlwes
;  Subject: SIN/COS Table

Create sin-table, containing sin-values*65535 (=FFFFh) for 0 to 90 degrees.
(Small MS-DOS QBASIC program provided at end of msg)
I used 0.1-degrees-steps, you may enhance this.
If you make q-degrees-steps, use [cmp cx,(90/q)] instead of [cmp cx,900]

SineTable DW  0
DW  114
DW  228
DW  343
DW  457
DW  571
...
DW  65531
DW  65532
DW  65533
DW  65534
DW  65535
EndOfSinT DW  65535

To compute value of sin(x)*y: TableEntry[x]*y/65536
Division by 65536=take high word of doubleword
For better results: ((TableEntry[x]*y)+TableEntry[x])/65536

 90 < x < 180: sin(x)=sin(180-x)
180 < x < 270: sin(x)=-sin(x-180)
270 < x < 360: sin(x)=-sin(360-x)

cos(x)=sin(90-x)

;Draw an ellipse:
; uses vars: CenterX, CenterY, RadX, RadY
; temp vars: x,y

Draw4Points MACRO
            pop x
            pop y
            call SetPoint (CenterX+x,CenterY+y)
            call SetPoint (CenterX+x,CenterY-y)
            call SetPoint (CenterX-x,CenterY+y)
            call SetPoint (CenterX-x,CenterY-y)
            ENDM

; Calculates sin(a/(180*q))*b -> dx
SinXlat     MACRO   a,b
            local   nocarry
            mov     ax,SineTable[a]
            mul     b
            add     ax,SineTable[a]
            jnc     nocarry
            inc     dx
nocarry:
            ENDM

CosXlat     MACRO   a,b
            local   nocarry
            mov     ax,EndOfSinT[-a]
            mul     b
            add     ax,EndOfSinT[-a]
            jnc     nocarry
            inc     dx
nocarry:
            ENDM

DrawEllipse PROC
            mov     bx,0            ; start at top
drawloop:   push    bx              ; save degrees counter
            shl     bx,1            ; bx*2, for pointer op
            SinXlat bx,RadX
            push    dx
            CosXlat bx,RadY
            push    dx
            Draw4Points
            pop     bx
            inc     bx
            cmp     bx,900
            jbe     drawloop
            ret
DrawEllipse ENDP


------------- MS-DOS QBasic: MakeSinT.Bas
DEFDBL A-Z
OPEN "O", 1, "SINETABL.INC"
INPUT "Steps/degree (e.g. 10 for 1/10-degree-steps):", Steps
PRINT "Memory required for table:"; INT(180 * Steps) + 2; "bytes"
f = 3.141592654# / (180 * Steps)
FOR i = 0 TO 90 * Steps
        PRINT #1, "DW "; INT(SIN(i * f) * 65536)
NEXT
CLOSE 1
--------------

