Page 1 of 1

6502 MS Basic in details (FLOAT2-FOUT functions)

Posted: Fri Oct 06, 2017 3:04 pm
by Ax2013
Hi,

Maybe someone whom knows 6502 MS BASIC very well could assist me. I try to debug what FLOAT2 and FOUT functions do.
FLOAT2 input:
FAC+1 LO byte of mantissa
FAC+2 HI byte of mantissa
X = exponent, but in which format? For integer $90?

FLOAT2 output:
FAC ?
FAC+1 ?
FAC+2 ?
FAC+3 ?

My main question: what is the content of FAC bytes after FLOAT2 being executed?

Axel.

Re: 6502 MS Basic and FLOAT2-FOUT functions

Posted: Tue Oct 10, 2017 1:40 pm
by JeeK
Ax2013 wrote:
Hi,

Maybe someone whom knows 6502 MS BASIC very well could assist me. I try to debug what FLOAT2 and FOUT functions do.
FLOAT2 input:
FAC+1 LO byte of mantissa
FAC+2 HI byte of mantissa
X = exponent, but in which format? For integer $90?

FLOAT2 output:
FAC ?
FAC+1 ?
FAC+2 ?
FAC+3 ?

My main question: what is the content of FAC bytes after FLOAT2 being executed?
If you are referring to https://github.com/mist64/msbasic/blob/master/float.s
In case you consider the non-small format you have also FAC+4.
Because FAC1 will get normalized
  • FAC will contain the exponent in excess notation (e.g. https://www.c64-wiki.com/wiki/Floating_point_arithmetic), in case of an 16 bit integer you will have to use $90 ($80 excess + two's exponent $10).
  • FAC+1 ... FAC+3(4) contains the mantissa which will get the leading 1 bit shifted to the left (with the exponent adjusted accordingly) with the imaginary "0." in front of it. In the expanded float representation in the FAC the leading 1 bit is kept in place (for the compact format this bit contains the sign). A negative two's complement value is turned into a positive one and the sign is stored in an extra byte (FACSIGN).
If the starting value is e.g. X=$90 and FAC+1/FAC+2 $00/$42 we should get

Code: Select all

 FAC = $87
 FAC+1 = $84
 FAC+2 = 0
 FAC+3 = 0
 FAC+4 = 0
 FACSIGN = 0
= 0.10000100 00000000 00000000 00000000 * 2^7
    FAC+1    FAC+2    FAC+3    FAC+4

Re: 6502 MS Basic and FLOAT2-FOUT functions

Posted: Fri Oct 13, 2017 5:48 pm
by Ax2013
Thanks for the explanation!

br,

Axel.

Re: 6502 MS Basic in details (FLOAT2-FOUT functions)

Posted: Sun Oct 22, 2017 4:15 pm
by Ax2013
#JeeK, do you happen to know what are the proper parameters when calling LIST function? It does actually work just by "jsr LIST" but there are at least Z and C flags and Reg-A involved. I'm writing SAVE and LOAD functions. I was going to use LIST cmd without screen output for SAVE and GETC (also without screen output) for LOAD. Any other ideas are welcome.

Axel.

Re: 6502 MS Basic in details (FLOAT2-FOUT functions)

Posted: Tue Nov 21, 2017 9:30 pm
by JeeK
Ax2013 wrote:
#JeeK, do you happen to know what are the proper parameters when calling LIST function? It does actually work just by "jsr LIST" but there are at least Z and C flags and Reg-A involved. I'm writing SAVE and LOAD functions. I was going to use LIST cmd without screen output for SAVE and GETC (also without screen output) for LOAD. Any other ideas are welcome.

Axel.
You want to put a LIST output to a file (with something like a SAVE)? Also the reverse task with some LOAD which takes a textual LIST output?

LIST is problematic to call because it ends always in a warm start, never comes back to the caller.
On a C64 you might catch up the warm start vector $300 to get the control back after a list call.
Calling LIST similar to a call without a parameter you might use

JSR $A613 ; find first line
JSR $A6C3 ; do list from beginning

If you save the contents of $0300/$0301, let it point to your resume code before calling the above code, LIST branches
to your resume code which in turn should restore $0300/$0301 and may finally returns to the caller using a RTS.
(didn't try it, just the JSR sequence above)