Jump to content
IGNORED

Math.h functions for Lynx


Bochum_Boy

Recommended Posts

There is actually a little bit trigonometry in cc65.

 

int __fastcall__ cc65_sin (unsigned x);
/* Return the sine of the argument, which must be in range 0..360. The result
 * is in 8.8 fixed point format, which means that 1.0 = $100 and -1.0 = $FF00.
 */

int __fastcall__ cc65_cos (unsigned x);
/* Return the cosine of the argument, which must be in range 0..360. The result
 * is in 8.8 fixed point format, which means that 1.0 = $100 and -1.0 = $FF00.
 */
 

But no tan I am afraid.

Link to comment
Share on other sites

CC65 is very convenient because it automatically handles all the signed formats for you without you doing anything (which, in ASM, is a lot of work and it's not pretty).

 

This kind of prototyping is best done in something with debugger like Visual Studio:

1. Create function that computes tan () for the full range of values that you can encounter

2. Convert to short int and print it out

3. Copy paste the printout into CC65 as a table

 

I would reckon that 16 bits per value should be really enough, given the low resolution of Lynx. If you need to save couple hundred bytes, just halve the array and invert it.

 

Of course, only you know the input range, so you might be able to get away with just 8 bits of precision, especially if you store only 50% of the range.

 

At a slight complication, you might store double precision for a most common sub-range of the main range and keep the precision lower for the rest. But, really, 360 Bytes is nothing...

Link to comment
Share on other sites

I don't program for retro consoles so this might be a naive suggestion, but could you just approximate it with its 5th degree taylor expansion?

 

if x is between 0 to pi/2 use    tan x = x + 1/3 x3 + 2/15 x5

 

if x is between pi/2 to pi use   tan x = x-pi + 1/3 (x-pi)3 + 2/15 (x-pi)5

 

(= is approximately here)

 

any error should only be noticeable very close to pi/2 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...