6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Sep 19, 2024 11:56 pm

All times are UTC




Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4
Author Message
PostPosted: Sat Jan 13, 2018 12:29 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
The custom syntax makes it harder to reuse the code in existing projects without a porting step. I was looking at this as a potential way to sidestep the parsing and formatting required for the woz floating point code.


Top
 Profile  
Reply with quote  
PostPosted: Sat Jan 13, 2018 6:52 pm 
Offline
User avatar

Joined: Tue Mar 02, 2004 8:55 am
Posts: 996
Location: Berkshire, UK
In WDC assembly syntax a leading '<' in the operand (as in 'LDA <exp') forces zero/direct page and '>' forces absolute long in 65c816 mode.

Having '<exp' interpret as '#<exp' is rather weird. I don't think I've ever used a 6502 assembler that does that.

_________________
Andrew Jacobs
6502 & PIC Stuff - http://www.obelisk.me.uk/
Cross-Platform 6502/65C02/65816 Macro Assembler - http://www.obelisk.me.uk/dev65/
Open Source Projects - https://github.com/andrew-jacobs


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 19, 2018 1:19 pm 
Offline

Joined: Mon Oct 19, 2015 7:04 am
Posts: 68
Location: France
Hello,
Three years ago I used fltpt65 for my calculator project ; I ported it to the ca65 assembler, fixed some bugs and added a few functions. The archive is named fltptC65 which implies it makes some use of the 65C02 instructions - but the "readme" file will tell you more :
Attachment:
fltpt_c65.zip [25.58 KiB]
Downloaded 201 times

"readme" file contents :
-------------------------------------------------------------------------------
fltptC65 - A slightly enhanced fltpt65 (original from C. R. Bond)
2017 - Marc Ferrer

INTRODUCTION :
A few years ago I built a 65C02-based RPN programmable calculator. I used C.R. Bond's floating-point package to which I added a few mathematical functions. (also fixed a few bugs, please see below)
The core arithmetic routines are reliable enough that they've allowed my calculator to perform flawlessly tens of billions of calculations during the last 3 years.
(multi-precision constants computations, pi, e ...)

IMPORTANT NOTES :
- Assembles with ca65 assembler.
- Uses 65C02 instructions.
- Provided as is, no warranty.
- There are surely many improvement paths I didn't look for.

ADDED FUNCTIONS :
pow2 ........ Squares the argument
isint ......... Checks if the argument is an integer
cubrt ........ Cubic root computation
p10ow ...... (10 ** argument) computation
fact .......... Factorial computation (range : 0 to 449)
ncr ........... Combinations computation
npr ........... Permutations computation
hr2hms ...... Decimal hour to Hour/Minute/Second conversion
hms2hr ...... Hour/Minute/Second to decimal hour conversion
p2r ........... Polar to rectangular coordinate conversion
r2p ........... Rectangular to polar coordinate conversion

NOTES :
The last 2 functions use extra F.P. registers (ST_X and ST_Y) which
are not part of the original fltpt65 environment !
Anyway you can easily tailor them to your own project.

The last 7 functions use a new w5 F.P. working register. It should
be possible to optimize them in order to avoid that.

FIXED BUGS :
1) Multiplication (mul) :
- Incorrect results when multiplying 2 numbers with
exponents having same absolute values but opposite signs.
- If w1 = 0 or w2 = 0, we got a result with a computed zero mantissa
but the exponent field isn't set to 0.
2) Arc tangent (atan) :
- Trapped in an endless loop if argument = 0.
3) Integer part (int) :
- If argument exponent = +010, the mantissa's 2nd digit is zeroed
instead of the 12th one.

KNOWN BUGS (to me) :
1) Logarithm (ln) :
- Gives wrong results with arguments of magnitude > 10^10.
-------------------------------------------------------------------------------
Last note not included in the readme file : the cycle counts I mentioned in some comments may be inaccurate. (I recently read about a new version of Michal Kowalski's simulator which has fixed that.)

Hoping it'll be of some use,
Marc


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 19, 2018 2:34 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
Thanks for posting.

I just finished a port to the Ophis assembler and introduced some 65c02 instructions, as well as macros to reduce the boiler plate code. I might work in your extra functions later.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jan 23, 2018 6:47 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
I've been going over this code with a fine tooth comb to really understand it. I've noticed there's a lot of boiler plate loading up registers as arguments, calling a subroutine copy2w, and then using those registers for a byte move using indirect addressing mode. Here's a sample of those code in question.
Code:
    lda <w3
    ldy >w3
    ldx #<w4
    jsr copy2w      ; save tangent for (possible) later use
...
    ; copy number from (ptr1) to (ptr2)
    ; enter with src register page in 'y', src register offset in 'a',
    ;   dest register offset in 'x' (assumed destination page is for 'wx' regs).
copy2w:
   sty ptr1+1
   sta ptr1
   stx ptr2
   lda #<w1/256      ; get page used for working registers
   sta ptr2+1
   ldy #7
*   lda (ptr1),y
   sta (ptr2),y
   dey
   bpl -
   rts

There another subroutine which is almost the same, but copies to the r registers. This seems a bit convoluted as it takes nine bytes for the setup, and then seven instructions to store and return from the subroutine. In addition a indirect addressing takes a cycle time longer than absolute addressing. So I replaced all instances of this code with a macro invocation that expands to a copy loop as follows:
Code:
; The scheme used to copy values between registers was overly complex.
; It loaded three registers then jsr-ed to a common copy routine. The
; savings was minimal versus inlining the code via a macro.
.macro copyReg
   ldx #[reglen-1]
_loop:
   lda _1,x
   sta _2,x
   dex
   bpl _loop
.macend
...
   `copyReg w3, w4

Unless I am missing something the expanded macro is only two bytes larger than the subroutine call, but is much faster because of the reduced overhead.

Update: This code has a dependency for the ra registers to be at $0400, and I am not sure why. I found one hard code magic number, but that didn't resolve the dependency. It's strange.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jan 26, 2018 11:28 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
I think I've worked out all the magic number dependencies, as well as the requirement that certain variables be on the same page. I reworked the code to use macros which clarifies the code flow considerably, and started separating symbols into local scope versus external entry points.

Updated source is here: https://github.com/Martin-H1/Lisp65/blob/master/bcdmath.asm

It works pretty well, and BCD is a snap to print versus the binary format.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 06, 2018 7:32 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8387
Location: Midwestern USA
Martin_H wrote:

Looks as though the page went 404.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 06, 2018 7:42 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Looks like Martin has moved some code around. Have a look around
https://github.com/Martin-H1/Math65


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 06, 2018 7:48 am 
Offline

Joined: Sat Jul 28, 2012 11:41 am
Posts: 442
Location: Wiesbaden, Germany
BigEd wrote:
Looks like Martin has moved some code around. Have a look around
https://github.com/Martin-H1/Math65
That is 6 month old and most probably does not have the changes.

edit: Sorry, my bad. The post BDD was referring to is 6 month old. So it should be up to date.

_________________
6502 sources on GitHub: https://github.com/Klaus2m5


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 3:20 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
BigEd wrote:
Looks like Martin has moved some code around. Have a look around
https://github.com/Martin-H1/Math65

Yes, I moved it because it the code and the unit tests were adding confusing noise to my Lisp65 repo. I've also collected two different float packages, and started porting an IEEE version as well. So I decided to given all of them their own repo. I forgot to update the link here.


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 07, 2018 3:24 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
No problem - a bit of link rot is bound to happen, and almost always a little searching can fix it.


Top
 Profile  
Reply with quote  
PostPosted: Fri May 01, 2020 12:58 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
I'm getting a bit of repo sprawl, so I'm creating monorepos of all my code based upon the architecture (e.g. Arduino, 6502). It will be hierarchical, so all projects for 6502 will be in sub-directories under that repo. Math65 will be here:

https://github.com/Martin-H1/6502/tree/master/Math65

Ultimately I might want to create a common macros directory and link between projects rather than copying and pasting like I am currently.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 57 posts ]  Go to page Previous  1, 2, 3, 4

All times are UTC


Who is online

Users browsing this forum: No registered users and 22 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: