Yes, this works
Code: Select all
LD HL,string
LD (16406),HL ;CH_ADD
LD A,(HL)
CALL $14D9 ;DEC-TO-FP
CALL $15DB ;PRINT-FP
RET
string: DEFB $1F,$1B,$1D,$20,$1D,$21,$25,$1E,$23 ;"3.1415927"
A few years ago I was trying to figure out DEC-TO-FP, but never could make it work. Now with olofsen's LD A suggestion and swensont's updating of CH_ADD, success!
By the way, 3.1415927 is what is printed by PRINT PI, but internally is it slightly different. Maybe more digits that aren't printed. "3.1415972" is 82 49 0F DA D3 while PI is 82 49 0F DA A2
Original problem:
how to convert a decimal number as a string, into an FP number...
From
Logan:
14D9 DEC-TO-FP
15DB PRINT-FP
DEC-TO-FP THE 'DECIMAL TO FLOATING-POINT' SUBROUTINE
This subroutine reads the decimal number digit by digit and gives its result as a 'last value' on the calculator stack.
PRINT-FP THE 'PRINT A FLOATING-POINT NUMBER' SUBROUTINE
The subroutine prints X, the 'last value' on the calculator stack.
Like most commented code, i find Logan's comments sometimes mysterious. Here's what I was able to work out about how to use PRINT-FP
1. Put the number on the stack (in floating-point format). This is the CALC stack, not the machine stack
2. Optionally, load DF_CC with the display file address where printing is wanted. You could just let it use the current value. After RUN it is the first character position of the screen
3. Call PRINT-FP
Moggy's comment was quite interesting
0B6B PR-STR-4
This prints a string from the CALC processor. I wonder why the CALC has the ability to do this as it would be easier to just use PRINT "3.14". Or in assembly, copy the string to the Display File. But maybe it makes the CALC a general purpose processor implemented in software (and thus independent of the Z80)