### Author Topic: Trig in ASM  (Read 3197 times)

0 Members and 1 Guest are viewing this topic.

#### ralphdspam

• LV8 Addict (Next: 1000)
• Posts: 841
• Rating: +38/-1
• My name is actually Matt.
##### Trig in ASM
« on: August 07, 2011, 05:30:32 pm »
Does anyone have fast 8.8 Fixed-Point tan and sin routines?  (Period of $FF.FF) It does not have to be exact, but it has to be relatively fast. Or would a look up table be better suited? ld a, 0 ld a, a #### ben_g • Hey cool I can set a custom title now :) • LV9 Veteran (Next: 1337) • Posts: 1002 • Rating: +125/-4 • Asm noob ##### Re: Trig in ASM « Reply #1 on: August 07, 2011, 05:34:29 pm » I use this routine for a sin in my z80 project: Quote from: Z80 Assembly SinA: ;calculates the sine of a as a fixed point number ;IN: a ;OUT: hl = sin(a) LD h, 0 LD l, a add hl, hl LD DE, sine_table ADD HL, DE LD A, (HL) INC HL LD H, (HL) LD L, A RET sine_table: .dw 0, 6, 13, 19, 25, 31, 38, 44, 50, 56, 62, 68, 74, 80, 86, 92, 98, 104, 109, 115, 121, 126, 132, 137, 142 .dw 147, 152, 157, 162, 167, 172, 177, 181, 185, 190, 194, 198, 202, 206, 209, 213, 216, 220, 223, 226, 229, 231, 234 .dw 237, 239, 241, 243, 245, 247, 248, 250, 251, 252, 253, 254, 255, 255, 256, 256, 256, 256, 256, 255, 255, 254, 253 .dw 252, 251, 250, 248, 247, 245, 243, 241, 239, 237, 234, 231, 229, 226, 223, 220, 216, 213, 209, 206, 202, 198, 194 .dw 190, 185, 181, 177, 172, 167, 162, 157, 152, 147, 142, 137, 132, 126, 121, 115, 109, 104, 98, 92, 86, 80, 74, 68 .dw 62, 56, 50, 44, 38, 31, 25, 19, 13, 6, 0, -6, -13, -19, -25, -31, -38, -44, -50, -56, -62, -68, -74, -80, -86, -92 .dw -98, -104, -109, -115, -121, -126, -132, -137, -142, -147, -152, -157, -162, -167, -172, -177, -181, -185, -190, .dw -194, -198, -202, -206, -209, -213, -216, -220, -223, -226, -229, -231, -234, -237, -239, -241, -243, -245, -247 .dw -248, -250, -251, -252, -253, -254, -255, -255, -256, -256, -256, -256, -256, -255, -255, -254, -253, -252, -251 .dw -250, -248, -247, -245, -243, -241, -239, -237, -234, -231, -229, -226, -223, -220, -216, -213, -209, -206, -202 .dw -198, -194, -190, -185, -181, -177, -172, -167, -162, -157, -152, -147, -142, -137, -132, -126, -121, -115, -109 .dw -104, -98, -92, -86, -80, -74, -68, -62, -56, -50, -44, -38, -31, -25, -19, -13, -6 Generated by the BBify'r (http://clrhome.tk/resources/bbify/) and for tan, I use sin(x)/sin(x+90°), which has the same result I hope this is what you are looking for. BTW: look up tables are big, so i would only reccomend them when you really need the speed. « Last Edit: August 07, 2011, 05:36:47 pm by ben_g » My projects - The Lost Survivors (Unreal Engine) ACTIVE [GameCommandoSquad main project] - Oxo, with single-calc multiplayer and AI (axe) RELEASED (screenshot) (topic) - An android version of oxo (java) ACTIVE - A 3D collision detection library (axe) RELEASED! (topic)(screenshot)(more recent screenshot)(screenshot of it being used in a tilemapper) Spoiler For inactive: - A first person shooter with a polygon-based 3d engine. (z80, will probably be recoded in axe using GLib) ON HOLD (screenshot) - A java MORPG. (pc) DEEP COMA(read more)(screenshot) - a minecraft game in axe DEAD (source code available) - a 3D racing game (axe) ON HOLD (outdated screenshot of asm version) This signature was last updated on 20/04/2015 and may be outdated #### Ashbad • Guest ##### Re: Trig in ASM « Reply #2 on: August 07, 2011, 05:34:36 pm » Does anyone have fast 8.8 Fixed-Point tan and sin routines? (Period of$FF.FF)
It does not have to be exact, but it has to be relatively fast.

Or would a look up table be better suited?

Just rip from Axe

#### ralphdspam

• LV8 Addict (Next: 1000)
• Posts: 841
• Rating: +38/-1
• My name is actually Matt.
##### Re: Trig in ASM
« Reply #3 on: August 09, 2011, 11:46:46 am »
Just rip from Axe
Quote from: Axe Commands: Sin
Returns the sine of the expression. One Period is [0,256] and the value returned ranges from -127 to 127.
I can probably modify the code, though.
ld a, 0
ld a, a