| Routines

2D3B: THE 'INTEGER TO FLOATING-POINT' SUBROUTINE

Used by the routines at E_LINE_NO and DEC_TO_FP. This subroutine returns a 'last value' on the calculator stack that is the result of converting an integer in a BASIC line, i.e. the integer part of the decimal number or the line number, to its floating-point form. Repeated calls to CH_ADD_1 fetch each digit of the integer in turn. An exit is made when a code that does not represent a digit has been fetched.
Input
A | Code of the current character
Output
A | Code of the next non-digit character
INT_TO_FP | 2D3B | PUSH AF | Save the first digit - in A.
| 2D3C | RST $28 | Use the calculator.
| 2D3D | DEFB $A0 | stk_zero: (the 'last value' is now zero)
| 2D3E | DEFB $38 | end_calc
| 2D3F | POP AF | Restore the first digit.
Now a loop is set up. As long as the code represents a digit then the floating-point form is found and stacked under the 'last value' (V, initially zero). V is then multiplied by 10 and added to the 'digit' to form a new 'last value' which is carried back to the start of the loop.
NXT_DGT_2 | 2D40 | CALL STK_DIGIT | If the code represents a digit (D) then stack the floating-point form; otherwise return.
| 2D43 | RET C
| 2D44 | RST $28 | Use the calculator.
| 2D45 | DEFB $01 | exchange: D, V
| 2D46 | DEFB $A4 | stk_ten: D, V, 10
| 2D47 | DEFB $04 | multiply: D, 10*V
| 2D48 | DEFB $0F | addition: D+10*V
| 2D49 | DEFB $38 | end_calc: D+10*V (this is 'V' for the next pass through the loop)
| 2D4A | CALL CH_ADD_1 | The next code goes into A.
| 2D4D | JR NXT_DGT_2 | Loop back with this code.