diff src/print.s @ 85:663d8e77b579

Implmement BCD floating point and update number parsing and printing Implements a BCD floating point system with 10 decimal digits of precistion and an exponent range of -63 to +63. Also include parsing integer and floating point values and printing them out.
author William Astle <lost@l-w.ca>
date Sun, 15 Oct 2023 22:15:36 -0600
parents bb50ac9fdf37
children
line wrap: on
line diff
--- a/src/print.s	Sun Oct 08 00:17:20 2023 -0600
+++ b/src/print.s	Sun Oct 15 22:15:36 2023 -0600
@@ -54,6 +54,8 @@
                 ldb val0+val.type               ; get value type
                 cmpb #valtype_int               ; integer?
                 beq cmd_printint                ; brif so - print integer
+                cmpb #valtype_float             ; floatingp point?
+                beq cmd_printfps                ; brif so - print floating point
                 lda #'!                         ; flag unknown expression type
                 jsr console_outchr
                 jsr console_outchr
@@ -61,60 +63,10 @@
 cmd_printnext   jsr curchar                     ; see what we have here
                 bra cmd_print                   ; and go process
 cmd_printeol    jmp console_outnl               ; do a newline and return
-cmd_printint    leas -12,s                      ; make a buffer
-                leay ,s                         ; point to buffer
-                lda #0x20                       ; default sign (positive)
-                ldb val0+val.int                ; is it negative?
-                bpl cmd_printint0               ; brif not
-                jsr int32_neg                   ; negate the integer
-                lda #'-                         ; negative sign
-cmd_printint0   sta ,y+                         ; save sign
-                ldu #cmd_printintpc             ; point to positive constant table
-                ldx #10                         ; there are 10 constants to process
-; subtraction loop - positive residue
-cmd_printint1   lda #'0-1                       ; initialize digit
-                sta ,y
-cmd_printint2   inc ,y                          ; bump digit
-                ldd val0+val.int+2              ; subtract constant
-                subd 2,u
-                std val0+val.int+2
-                ldd val0+val.int
-                sbcb 1,u
-                sbca ,u
-                std val0+val.int
-                bcc cmd_printint2               ; brif we didn't go negative
-                ldd val0+val.int+2              ; undo last subtract
-                addd 2,u
-                std val0+val.int+2
-                ldd val0+val.int
-                adcb 1,u
-                adca ,u
-                std val0+val.int
-                leay 1,y                        ; move to next digit in buffer
-                leau 4,u                        ; move to next constant
-                leax -1,x                       ; done all constants?
-                bne cmd_printint1               ; brif not - done all
-cmd_printint5   clr ,y                          ; NUL terminate the string
-                leax 1,s                        ; point past the sign
-cmd_printint6   lda ,x+                         ; get digit
-                beq cmd_printint8               ; brif end of number
-                cmpa #'0                        ; is it a zero?
-                beq cmd_printint6               ; brif so - skip it
-cmd_printint7   lda ,s                          ; get the sign
-                sta ,--x                        ; put it at the start of the number
-                jsr console_outstr              ; display the number
-                leas 12,s                       ; clean up stack
-                bra cmd_printnext               ; go print the next thing
-cmd_printint8   leax -1,x                       ; restore one of the zeros
-                bra cmd_printint7               ; go finish up
-cmd_printintpc  fqb 1000000000                  ; 10^9
-                fqb 100000000                   ; 10^8
-                fqb 10000000                    ; 10^7
-                fqb 1000000                     ; 10^6
-                fqb 100000                      ; 10^5
-                fqb 10000                       ; 10^4
-                fqb 1000                        ; 10^3
-                fqb 100                         ; 10^2
-                fqb 10                          ; 10^1
-                fqb 1                           ; 10^0
+cmd_printint    jsr int_toascii                 ; convert val0 to string
+cmd_printstrb   ldx #strbuff                    ; point to resulting string
+                jsr console_outstr              ; output the string
+                bra cmd_printnext               ; go handle next stuff
+cmd_printfps    jsr fps_toascii                 ; convert val0 to string
+                bra cmd_printstrb               ; go output the resulting string
                 *pragmapop list