Floating point math on 6502, Commodore style

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
Mats
Posts: 111
Joined: 24 Aug 2003

Floating point math on 6502, Commodore style

Post by Mats »

On

http://6502.org/source/

the Wozniak software for floating point computations in Apple format (?)can be found. I have coded alternative subroutines for the Commodore format. I think the Commodore version with 32 bits for the mantissa instead of the 23 bits used by Wozniak (24 bits including the "sign bit") is more praxis oriented. The same can be said by the FLOAT and the FIX subroutines that for the Wozniak software transform to/from 16 bits signed integer while I base this on 32 bit unsigned integers. An explication of the floating point concept and my code can be found on the "free-site"

http://www.geocities.com/matsr2007/

I hope Mike will include this later in http://6502.org/source/! When (if ever) he has done so I will close the "geocities" site as I do not normally maintain any "home page".

Does anybody have access to the original Commodore source code for corresponding tasks? It would be interesting to compare how this originally was coded by Microsoft (that provided the BASIC software for the PET).
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

Somewhere on my box at home, I have the Commodore 64 version of BASIC 2.0 source listing, generated from a ROM dump and disassembler. But this can also be found online too (it's where I got it from). Try http://www.tkk.fi/Misc/cbm/docs/c64-diss.html
Mats
Posts: 111
Joined: 24 Aug 2003

Post by Mats »

Do get a ROM dump is the easy start, this one indeed finds in the Internet. The hard part is to extract some sensible portable code out of this dump!

I just udated

http://geocities.com/matsr2007/

to include a PET ROM dump in a format that is directly useable by an Assembler (".DB statements") + a desassembly of the part of the ROM where the code for these "Microsoft-computations" is positioned. I invite all "CBM hackers" to extract portable subroutines out of this!
User avatar
ptorric
Posts: 85
Joined: 13 Feb 2005
Contact:

Post by ptorric »

6502 float commodore is the same also in amiga version? (but larger, of course) i mean same format and same algorithms?
kc5tja
Posts: 1706
Joined: 04 Jan 2003

Post by kc5tja »

No; the Amiga version conforms to IEEE 754 (mathieee.library and mathieeedoub.library) and is not related, as far as I know, to the format used by the PET kernels (of which the VIC-20/C64/C128 kernels belong).
faybs
Posts: 106
Joined: 16 Oct 2006

Post by faybs »

ptorric wrote:
6502 float commodore is the same also in amiga version? (but larger, of course) i mean same format and same algorithms?
Nope, I'm afraid. The mathieee#?.library use the ieee single and double precision formats, which are not the same as Commodore's. The FFP versions of the math libraries use the following format, which is also different from the 6 byte CBM format (cut'n'paste from the RKM):

Code: Select all

FFP floating-point variables are defined within C by the float or FLOAT
directive. In assembly language they are simply defined by a DC.L/DS.L
statement. All FFP floating-point variables are defined as 32-bit entities
(longwords) with the following format:
 
         _____________________________________________
        |                                             |
        | MMMMMMMM    MMMMMMMM    MMMMMMMM    EEEEEEE |
        | 31          23          15          7       |
        |_____________________________________________|
 
 
The mantissa is considered to be a binary fixed-point fraction; except for
0, it is always normalized (the mantissa is shifted over and the exponent
adjusted, so that the mantissa has a 1 bit in its highest position).
Thus, it represents a value of less than 1 but greater than or equal to
1/2.
 
The sign bit is reset (0) for a positive value and set (1) for a negative
value.
 
The exponent is the power of two needed to correctly position the mantissa
to reflect the number's true arithmetic value.  It is held in excess-64
notation, which means that the two's-complement values are adjusted upward
by 64, thus changing $40 (-64) through $3F (+63) to $00 through $7F.  This
facilitates comparisons among floating-point values.
Mats
Posts: 111
Joined: 24 Aug 2003

Post by Mats »

Actually ,scrolling through "http://www.woz.org/" I saw a statement of Mr Wozniak himself saying that Apple decided to go for the Microsoft floating point BASIC instead of for the system Wozniak was working at. This then means that my heading should have been "Commodore and Apple style, in fact Microsoft style". And considering that Wozniak only was using 32 bits I am convinced Apple was right. There are a lot of applications that need higher accuracy. Then 40 bits are better!
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re:

Post by GARTHWILSON »

Mats wrote:
Do get a ROM dump is the easy start, this one indeed finds in the Internet. The hard part is to extract some sensible portable code out of this dump!

I just udated

http://geocities.com/matsr2007/

to include a PET ROM dump in a format that is directly useable by an Assembler (".DB statements") + a desassembly of the part of the ROM where the code for these "Microsoft-computations" is positioned. I invite all "CBM hackers" to extract portable subroutines out of this!
Mats, when I click on the link now, I just get a message that Geocities closed in 2009. Have you moved your material to another site?
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: Floating point math on 6502, Commodore style

Post by GARTHWILSON »

Thanks Ed. So the same thing is in several different places. We have not heard from Mats in six years.
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
User avatar
BigDumbDinosaur
Posts: 9425
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: Floating point math on 6502, Commodore style

Post by BigDumbDinosaur »

From his article:
  • The COMMODORE floating point format used for the PET computer deviates from the IEEE standard...
One could incorrectly deduce from this statement that the IEEE-754 standard predated Commodore's (actually, Microsoft's) excess-128 notation. Although seminal work on IEEE-754 began in 1977, the standard wasn't ratified until 1985, some seven years after excess-128 notation was introduced with PET BASIC 1.0.

Also:
  • Any application using at least a rudimentary amount of mathematics should use floating point.
I disagree. A surprisingly large amount of computation can be accomplished with integer arithmetic, especially at the operating system level. Even procedures such as converting between UNIX time_t format and Gregorian notation can be accomplished with integer arithmetic. In developing the software that models my 816NIX filesystem, I used 64 bit integer arithmetic, with final results rounded to 32 bits, since the filesystem architecture itself is 32 bit.

Otherwise, it's a good posting that tries to explain a complicated topic. Unfortunately, the embedded links are broken.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: Floating point math on 6502, Commodore style

Post by BigEd »

BigDumbDinosaur wrote:
Unfortunately, the embedded links are broken.
They all seem fine for me. If you find a broken link, try the usual tactics to resolve it to an archived or relocated copy. If it's still problematic, ask for help with the usual tactics: describe your problem and what you've tried to do.

Cheers
Ed
Post Reply