changeset 86:de42b8f77bc2

Fix problems related to parsing numbers (exponent, integers)
author William Astle <lost@l-w.ca>
date Mon, 16 Oct 2023 00:52:50 -0600
parents 663d8e77b579
children 3bfd978ddb39
files src/number.s
diffstat 1 files changed, 22 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/number.s	Sun Oct 15 22:15:36 2023 -0600
+++ b/src/number.s	Mon Oct 16 00:52:50 2023 -0600
@@ -127,11 +127,11 @@
 ; 4b. Set the exponent correctly then normalize the result to val0
 val_parsenum    lbeq SNERROR                    ; brif no numberr to parse
                 ldd zero                        ; zero out digit accumulator
-                stx fpa0+fpa.sig
-                stx fpa0+fpa.sig+2
-                stx fpa0+fpa.sig+4
-                stx fpa0+fpa.sig+6
-                stx fpa0+fpa.sig+8
+                std fpa0+fpa.sig
+                std fpa0+fpa.sig+2
+                std fpa0+fpa.sig+4
+                std fpa0+fpa.sig+6
+                std fpa0+fpa.sig+8
                 sta fpa0+fpa.sign               ; set number sign to positive
                 std fpaextra+4                  ; clear out decimal exponent and sign
                 std fpaextra                    ; set digit count and decimal flag to zero and no decimal
@@ -173,7 +173,7 @@
                 stb fpaextra+2
                 bra val_parsenum2               ; go handle another digit or whatever
 val_parsenum5   cmpa #'.                        ; decimal?
-                bne val_parsenum3               ; brif not
+                bne val_parsenum6               ; brif not
                 com fpaextra                    ; flag decimal seen
                 lbeq SNERROR                    ; brif already seen a decimal point - syntax error
                 bra val_parsenum2               ; go parse more digits
@@ -211,13 +211,13 @@
 ; By ensuring there were no leading zeroes converted, the result is already pre-normalized without losing precision due
 ; to an aribtrary number of leading zeroes.
                 cmpb fpaextra                   ; is the exponent less than the number of digits?
-                blt val_parsenum13              ; brif so - return floating point (signed comparison!)
+                bgt val_parsenum13              ; brif so - return floating point (signed comparison!)
                 cmpb #10                        ; is exponent in the range for a binary integer?
                 bgt val_parsenum13              ; brif not - return floating point
 ; Compare with 2147483648, the maximum *negative* value; note that this is a floating point comparison because we
 ; already normalized everything above and it handles exponents properly
-                lda fpa0+fpa.exp                ; compare exponents (unbiased)
-                cmpa #9
+                lda fpa0+fpa.exp                ; compare exponents (unbiased), exponent adjusted for above code
+                cmpa #10
                 bne val_parsenum12
                 ldx fpa0+fpa.sig                ; compare top of significand
                 cmpx #0x2147
@@ -233,14 +233,14 @@
                 bpl val_parsenum14              ; brif not - doesn't fit in integer
 val_parsenum13  lda #valtype_float              ; set return value to floating point
                 sta val0+val.type
-                lda fpa0+fpa.exp                ; put the bias into the exponent
-                adda #64
+                lda fpa0+fpa.exp                ; put the bias into the exponent but subtract one for leading digit
+                adda #63
                 sta fpa0+fpa.exp
                 ldy #val0+val.value             ; normalize/round and return the result
                 jmp fps_normalize
 val_parsenum14  lda #valtype_int                ; set value type to integer
                 sta val0+val.type
-                ldb #9                          ; exponent needed for decimal point to the right of significand
+                ldb #10                         ; exponent needed for decimal point to the right of significand
                 subb fpa0+fpa.exp               ; number of digit shifts needed to denormalize
                 beq val_parsenum16              ; brif already denormalized
                 lslb                            ; do 4 shifts per digit
@@ -253,17 +253,17 @@
                 decb                            ; done all shifts?
                 bne val_parsenum15
 ; Now convert BCD digit sequence in fpa0 significand to binary value in val0
-val_parsenum16  ldb #40                         ; 40 bit shifts needed for whole significand
+val_parsenum16  ldb #32                         ; 40 bit shifts needed for whole significand
                 stb fpa0+fpa.extra              ; use extra precision byte as counter
-val_parsenum17  lsl fpa0+fpa.sig+4              ; shift a bit into the binary result
-                rol fpa0+fpa.sig+3
-                rol fpa0+fpa.sig+2
-                rol fpa0+fpa.sig+1
-                rol fpa0+fpa.sig
-                rol val0+val.int+3
-                rol val0+val.int+2
-                rol val0+val.int+1
-                rol val0+val.int
+val_parsenum17  lsr fpa0+fpa.sig                ; shift a bit into the binary result
+                ror fpa0+fpa.sig+1
+                ror fpa0+fpa.sig+2
+                ror fpa0+fpa.sig+3
+                ror fpa0+fpa.sig+4
+                ror val0+val.int
+                ror val0+val.int+1
+                ror val0+val.int+2
+                ror val0+val.int+3
                 ldx #fpa0+fpa.sig               ; point to BCD digits
 val_parsenum18  lda ,x                          ; get byte to check
                 beq val_parsenum20              ; short circuit check if digits are 0