Advertisement
Zeda

8-bit Sine and Cosine (LUT)

Feb 22nd, 2012
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sine:
  2. ;Inputs:
  3. ;     A is a signed 8-bit value
  4. ;Output:
  5. ;     BC is the result (B is either FF or 00)
  6. ;Notes: I use this in Grammer, so certain things are here to work with Grammer and no other reason.
  7. ;       To compute cosine, just add 40h to the input.
  8.  ld d,a
  9.  bit 6,a
  10.  jr z,$+5
  11.    cpl
  12.    xor 80h
  13.  and 63
  14.  ld c,a
  15.  ld hl,sinTable
  16.  ld b,0
  17.  add hl,bc
  18.  ld c,(hl)
  19.  rlc d
  20.  ret nc        ;123
  21.  xor a
  22.  sub c
  23.  ld c,a
  24.  sbc a,a
  25.  sub b
  26.  ld b,a
  27.  ret
  28. sinTable:
  29.  .db 0,3,6,9,13,16,19,22,25,28,31,34,37,40,43,46
  30.  .db 49,52,55,58,60,63,66,68,71,74,76,79,81,84,86,88
  31.  .db 91,93,95,97,99,101,103,105,106,108,110,111,113,114,116,117
  32.  .db 118,119,121,122,122,123,124,125,126,126,127,127,127,128,128,128
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement