From c65925b0b912f4b3665291e380a195d2b27d4fe8 Mon Sep 17 00:00:00 2001 From: uz Date: Fri, 30 Oct 2009 09:58:11 +0000 Subject: [PATCH] Merged the sine/cosine routines into one file, because they're often used together, we save some code in this case, and the sine table isn't of real use for programs, because it contains some specialities. git-svn-id: svn://svn.cc65.org/cc65/trunk@4400 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/common/Makefile | 4 +- libsrc/common/cc65_cos.s | 48 --------------- libsrc/common/{cc65_sin.s => cc65_sincos.s} | 66 ++++++++++++++++++--- libsrc/common/cc65_sintab.s | 24 -------- 4 files changed, 58 insertions(+), 84 deletions(-) delete mode 100644 libsrc/common/cc65_cos.s rename libsrc/common/{cc65_sin.s => cc65_sincos.s} (51%) delete mode 100644 libsrc/common/cc65_sintab.s diff --git a/libsrc/common/Makefile b/libsrc/common/Makefile index e912795f7..381742fdf 100644 --- a/libsrc/common/Makefile +++ b/libsrc/common/Makefile @@ -99,9 +99,7 @@ S_OBJS = _cwd.o \ atexit.o \ atoi.o \ calloc.o \ - cc65_cos.o \ - cc65_sin.o \ - cc65_sintab.o \ + cc65_sincos.o \ chdir.o \ copydata.o \ creat.o \ diff --git a/libsrc/common/cc65_cos.s b/libsrc/common/cc65_cos.s deleted file mode 100644 index 06a59af35..000000000 --- a/libsrc/common/cc65_cos.s +++ /dev/null @@ -1,48 +0,0 @@ -; -; Fixed point cosine function. -; -; Returns the cosine for the given argument as angular degree. -; Valid argument range is 0..360 -; -; -; Ullrich von Bassewitz, 2009-10-29 -; - - .export _cc65_cos - - .import _cc65_sin - - - -; --------------------------------------------------------------------------- -; - -.code - -.proc _cc65_cos - -; cos(x) = sin(x+90) - - clc - adc #90 - bcc L1 - inx - -; If x is now larger than 360, we need to subtract 360. - -L1: cpx #>360 - bne L2 - cmp #<360 -L2: bcc L4 - - sbc #<360 - bcs L3 - dex -L3: dex - -L4: jmp _cc65_sin - - -.endproc - - diff --git a/libsrc/common/cc65_sin.s b/libsrc/common/cc65_sincos.s similarity index 51% rename from libsrc/common/cc65_sin.s rename to libsrc/common/cc65_sincos.s index 6d83086cf..d0b108297 100644 --- a/libsrc/common/cc65_sin.s +++ b/libsrc/common/cc65_sincos.s @@ -1,24 +1,74 @@ ; -; Fixed point sine function. +; Fixed point cosine/sine functions. ; -; Returns the cosine for the given argument as angular degree. -; Valid argument range is 0..360 +; Returns the cosine/sine for the given argument as angular degree. +; Valid argument range is 0..360 for both functions. They will return +; garbage if the argument is not in a valid range. Result is in 8.8 fixed +; point format, so $100 is 1.0 and $FF00 is -1.0. ; ; ; Ullrich von Bassewitz, 2009-10-29 ; - .export _cc65_sin + .export _cc65_cos, _cc65_sin + + +; --------------------------------------------------------------------------- +; Sinus table covering values from 0..86° as 0.8 fixed point values. Values +; for 87..90° are actually 1.0 (= $100), will therefore not fit in the table +; and are covered specially in the code below. + +.rodata + +_cc65_sintab: + .byte $00, $04, $09, $0D, $12, $16, $1B, $1F, $24, $28 + .byte $2C, $31, $35, $3A, $3E, $42, $47, $4B, $4F, $53 + .byte $58, $5C, $60, $64, $68, $6C, $70, $74, $78, $7C + .byte $80, $84, $88, $8B, $8F, $93, $96, $9A, $9E, $A1 + .byte $A5, $A8, $AB, $AF, $B2, $B5, $B8, $BB, $BE, $C1 + .byte $C4, $C7, $CA, $CC, $CF, $D2, $D4, $D7, $D9, $DB + .byte $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC, $ED, $EF + .byte $F1, $F2, $F3, $F5, $F6, $F7, $F8, $F9, $FA, $FB + .byte $FC, $FD, $FE, $FE, $FF, $FF, $FF - .import _cc65_sintab ; --------------------------------------------------------------------------- -; +; Cosine function. Is actually implemented as cos(x) = sin(x+90) .code -.proc _cc65_sin +_cc65_cos: + +; cos(x) = sin(x+90) + + clc + adc #90 + bcc @L1 + inx + +; If x is now larger than 360, we need to subtract 360. + +@L1: cpx #>360 + bne @L2 + cmp #<360 +@L2: bcc _cc65_sin + + sbc #<360 + bcs @L3 + dex +@L3: dex + +; --------------------------------------------------------------------------- +; Sine function. Uses +; +; table lookup for 0..89° +; sin(x) = sin(180-x) for 90°..179° +; sin(x) = -sin(x-180) for 180..360° +; +; Plus special handling for the values missing in the table. + +_cc65_sin: ; If the high byte is non zero, argument is > 255 @@ -108,6 +158,4 @@ L6: tay inx L7: rts -.endproc - diff --git a/libsrc/common/cc65_sintab.s b/libsrc/common/cc65_sintab.s deleted file mode 100644 index 88464817a..000000000 --- a/libsrc/common/cc65_sintab.s +++ /dev/null @@ -1,24 +0,0 @@ -; -; Sinus table -; -; Ullrich von Bassewitz, 2009-10-29 -; - - .export _cc65_sintab - - -; --------------------------------------------------------------------------- -; - -.rodata - -_cc65_sintab: - .byte $00, $04, $09, $0D, $12, $16, $1B, $1F, $24, $28 - .byte $2C, $31, $35, $3A, $3E, $42, $47, $4B, $4F, $53 - .byte $58, $5C, $60, $64, $68, $6C, $70, $74, $78, $7C - .byte $80, $84, $88, $8B, $8F, $93, $96, $9A, $9E, $A1 - .byte $A5, $A8, $AB, $AF, $B2, $B5, $B8, $BB, $BE, $C1 - .byte $C4, $C7, $CA, $CC, $CF, $D2, $D4, $D7, $D9, $DB - .byte $DE, $E0, $E2, $E4, $E6, $E8, $EA, $EC, $ED, $EF - .byte $F1, $F2, $F3, $F5, $F6, $F7, $F8, $F9, $FA, $FB - .byte $FC, $FD, $FE, $FE, $FF, $FF, $FF -- 2.39.5