6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed May 15, 2024 2:00 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Oct 15, 2023 2:21 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
Hello there,

I had this idea to implement a very simple 6502 routine to compute step by step in BCD mode, the sine and cosine of a given angle using the CORDIC method and the common formulas Cos(A+B) and Sin(A+B). Values for the angles B would be chosen in such way that Tan(B)=1, 0.5, 0.25, 0.125 etc.

Angles would be expressed in degrees with at least three "decimal" bytes stored in memory in the big endian order.

The starting angle would be 0 degrees. Cos(0)=1 and Sin(0)=0, but they would be multiplied with the constant 0,60725293500899 simplified in the routine with three bytes 60, 72 and 53.

My question might look a little bit silly but I assume that something similar has already been implemented in the past. Would anyone know where I could find a routine that performs this ? I guess I will save some time and cells to my brain :D


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 15, 2023 3:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10800
Location: England
Welcome! As I understand it, CORDIC is a good fit for BCD calculations (and the 6502 has the handy BCD mode.)

Did you try searching the forum for previous discussions? I found this
[Contest] 6507 Calculator
Calculating log and trig - algorithms or tables
16 Bit Fixed Point Trig
Calc65: a BCD floating point package

Also, in the knowledgebase nearby on this site, we see CORDIC mentioned in
Source Code Repository
(in this case, points to a thread I've already listed above, but worth mentioning the reference section I think.)


Top
 Profile  
Reply with quote  
PostPosted: Sun Oct 15, 2023 5:05 pm 
Offline

Joined: Sun Oct 15, 2023 1:37 pm
Posts: 10
BigEd wrote:
Welcome!

Thank you! :)

Quote:
Also, in the knowledgebase nearby on this site, we see CORDIC mentioned in
Source Code Repository
(in this case, points to a thread I've already listed above, but worth mentioning the reference section I think.)


Many thanks for the suggestions.

I understand that the CORDIC reference is related to the calc65 package which is the closest thing to what I'm looking for (I now have this U2's song title ringing as an echo...). But the calc65 package is highly complex as it includes many other types of operations. Further it's a little bit different from my idea. It uses the formulas sin(x) = tan(x)/sec(x) and cos(x) = 1/sec(x). Also it seems to use an 8-byte floating point format BCD mantissa for the values. My idea was to use three BCD bytes instead of two hexadecimal bytes for the values added or subtracted. The results won't be as accurate as with the calc65 package but it will be really easy to read for a beginner in maths and programming.

If it does not exist, I will have to write it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: