JoSch Posted May 13, 2016 Share Posted May 13, 2016 Does anybody know of a library of fixed point arithmetic for, say, Action, CC65 or Assembler? The library should have the most important functions like sin, log etc. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted May 13, 2016 Share Posted May 13, 2016 have a look at codebase64.org and download MADS at mads.atari8.info in the example folder are some nice routines, too. 1 Quote Link to comment Share on other sites More sharing options...
JoSch Posted May 13, 2016 Author Share Posted May 13, 2016 I looked there already. I couldn't find anything on codebase64.org or in MADS. All they have are floating point libraries, but no fixed point libraries. Quote Link to comment Share on other sites More sharing options...
popmilo Posted May 14, 2016 Share Posted May 14, 2016 In here are many small parts of what you want: http://codebase64.org/doku.php?id=base:6502_6510_maths I'm afraid there's no "all in one" library. Functions like sin, log etc. are usually done with tables. Working with fixed point math is like working with integers. You just take the part of result you want. Plenty of integer routines on the codebase64... 1 Quote Link to comment Share on other sites More sharing options...
JoSch Posted May 14, 2016 Author Share Posted May 14, 2016 Yes, I know them. I just had hoped somebody had a library handy. Well, back to the drawing board Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted May 14, 2016 Share Posted May 14, 2016 (edited) From what I recall of Elite, your X, Y and Z position in space uses a fixed point representation of 3 bytes each. This is little more magic than using the low byte as the fractional part (0/256 -> 255/256) and the middle byte as the low integer (0 -> 255) and the high byte as high integer part (256 × (0 -> 255)).Operations work similar to usual integer math but after a multiply you take the result from the 2nd byte upwards, effectively dividing your result by 256. The top three rows show the breakdown of 2 values to be multiplied and the result. On the right are the same bytes represented as an 24-bit integer. The lower line then splits the result from multiplying those back into its component bytes. This shows us the that result is obtained by (effectively) dividing by 256. Similarly, a division is done by first multiplying the dividend by 256 (copy it one byte higher). Note though the precision loss. A12 is A10 / A11 but A14 is the actual value represented by the final value. This gives a range of 0 -> 65535+(255/256). But IIRC Elite might treat this a signed and the 8th bit of the high byte is the sign bit. Hence you'd then have a range of around the +/- 32768 range. Edited May 14, 2016 by Wrathchild 1 Quote Link to comment Share on other sites More sharing options...
JoSch Posted May 14, 2016 Author Share Posted May 14, 2016 (edited) I don't want to offend anyone, who wants to help, but I had asked for a library, not explanations of fixed point. The four base operation are not the problem. The problem are all the stuff like sin, log etc. But there seem to be no library for that stuff, so I will have to program that myself. Edited May 14, 2016 by JoSch Quote Link to comment Share on other sites More sharing options...
Wrathchild Posted May 14, 2016 Share Posted May 14, 2016 None taken, I tried by looking at the sources (the BBC ones are also available) but lifting the routines from those doesn'the appear straight forward, should have mentioned that Quote Link to comment Share on other sites More sharing options...
JoSch Posted May 14, 2016 Author Share Posted May 14, 2016 That's my problem, too. Quote Link to comment Share on other sites More sharing options...
popmilo Posted May 14, 2016 Share Posted May 14, 2016 The problem are all the stuff like sin, log etc. But there seem to be no library for that stuff, so I will have to program that myself. What's the purpose if I may ask ? Trig. functions are used often in demos, games etc. but I can't think of where one would use Log ? (beside to do fast mul-div ...) Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted May 15, 2016 Share Posted May 15, 2016 (edited) The problem are all the stuff like sin, log etc. You can find the cc65-fixed-point-part for sin/cos here: https://github.com/cc65/cc65/blob/master/libsrc/common/cc65_sincos.s Edited May 15, 2016 by Irgendwer 3 Quote Link to comment Share on other sites More sharing options...
JoSch Posted May 17, 2016 Author Share Posted May 17, 2016 What's the purpose if I may ask ? Trig. functions are used often in demos, games etc. but I can't think of where one would use Log ? (beside to do fast mul-div ...) Well, log will not be needed directly, but IIRC there are implementations of sqrt, which use that. My point really was to have a complete library. You can find the cc65-fixed-point-part for sin/cos here: https://github.com/cc65/cc65/blob/master/libsrc/common/cc65_sincos.s Nice find. I didn't see that. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.