Sinus function

ZXNet echo conference «code.zx»

From Aleksey Malov To Igor Kiselev 21 July 2000

Greetings, Igor! Mon 3 Jul 2000 at 03:08:14 Igor Kiselev and All were talking on the topic Sinus function. IK> Tell me about the subject, it would be nice to have the source IK> method of calculating the sine function. If you are interested in methods for generating sine tables for all sorts of effects, then I can recommend my procedure. A little theory: This procedure does not calculate the sine table, it only unpacks it from 17 byte data table. The table stores the second derivatives of the sine function for angles from 0 to 64 degrees (the period of the function is not 360, but 256 degrees for convenience). At the entrance ;D is the most significant byte of the address of the beginning of the 512-byte signed sine table. The output is a function table (HL)+(256+HL)=255sin(L) INISIN LD HL,SINTAB-1 LD E,255 LD BC,#06FA INS INC E LD A,E AND 3 JR NZ,$+3 INC HL XOR A RLC(HL) R.L.A. RLC(HL) R.L.A. DEC A ADD A,B LD B,A ADD A,C LD C,A CALL INSSR PUSH DE LD A,128 SUB E LD E,A LD A,C CALL INSSR POP DE BIT 6,E JR Z,INS RET INSSR LD (DE),A SET 7,E N.E.G. LD(DE),A INC D SBC A,A LD(DE),A RES 7,E XOR A LD(DE),ADEC D RET SINTAB ;packed data DB #58,#56,#15,#55 DB #49,#21,#85,#52 DB #21,#54,#88,#54 DB #85,#52,#15,#48,#55 Example: sinus equ #c000 ld d,sinus/256 call inisin You can get the sine value (from -255 to +255) like this: ;in L-angle value ld h,sinus/256 ld e,(hl) inc h ld d,(hl) Congratulations, Igor! Vivid/Brainwave^X-Project was with you.