comparison 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
comparison
equal deleted inserted replaced
84:f959c92bc329 85:663d8e77b579
52 rts 52 rts
53 cmd_print1 jsr eval_expr ; evaluate the expression 53 cmd_print1 jsr eval_expr ; evaluate the expression
54 ldb val0+val.type ; get value type 54 ldb val0+val.type ; get value type
55 cmpb #valtype_int ; integer? 55 cmpb #valtype_int ; integer?
56 beq cmd_printint ; brif so - print integer 56 beq cmd_printint ; brif so - print integer
57 cmpb #valtype_float ; floatingp point?
58 beq cmd_printfps ; brif so - print floating point
57 lda #'! ; flag unknown expression type 59 lda #'! ; flag unknown expression type
58 jsr console_outchr 60 jsr console_outchr
59 jsr console_outchr 61 jsr console_outchr
60 jsr console_outchr 62 jsr console_outchr
61 cmd_printnext jsr curchar ; see what we have here 63 cmd_printnext jsr curchar ; see what we have here
62 bra cmd_print ; and go process 64 bra cmd_print ; and go process
63 cmd_printeol jmp console_outnl ; do a newline and return 65 cmd_printeol jmp console_outnl ; do a newline and return
64 cmd_printint leas -12,s ; make a buffer 66 cmd_printint jsr int_toascii ; convert val0 to string
65 leay ,s ; point to buffer 67 cmd_printstrb ldx #strbuff ; point to resulting string
66 lda #0x20 ; default sign (positive) 68 jsr console_outstr ; output the string
67 ldb val0+val.int ; is it negative? 69 bra cmd_printnext ; go handle next stuff
68 bpl cmd_printint0 ; brif not 70 cmd_printfps jsr fps_toascii ; convert val0 to string
69 jsr int32_neg ; negate the integer 71 bra cmd_printstrb ; go output the resulting string
70 lda #'- ; negative sign
71 cmd_printint0 sta ,y+ ; save sign
72 ldu #cmd_printintpc ; point to positive constant table
73 ldx #10 ; there are 10 constants to process
74 ; subtraction loop - positive residue
75 cmd_printint1 lda #'0-1 ; initialize digit
76 sta ,y
77 cmd_printint2 inc ,y ; bump digit
78 ldd val0+val.int+2 ; subtract constant
79 subd 2,u
80 std val0+val.int+2
81 ldd val0+val.int
82 sbcb 1,u
83 sbca ,u
84 std val0+val.int
85 bcc cmd_printint2 ; brif we didn't go negative
86 ldd val0+val.int+2 ; undo last subtract
87 addd 2,u
88 std val0+val.int+2
89 ldd val0+val.int
90 adcb 1,u
91 adca ,u
92 std val0+val.int
93 leay 1,y ; move to next digit in buffer
94 leau 4,u ; move to next constant
95 leax -1,x ; done all constants?
96 bne cmd_printint1 ; brif not - done all
97 cmd_printint5 clr ,y ; NUL terminate the string
98 leax 1,s ; point past the sign
99 cmd_printint6 lda ,x+ ; get digit
100 beq cmd_printint8 ; brif end of number
101 cmpa #'0 ; is it a zero?
102 beq cmd_printint6 ; brif so - skip it
103 cmd_printint7 lda ,s ; get the sign
104 sta ,--x ; put it at the start of the number
105 jsr console_outstr ; display the number
106 leas 12,s ; clean up stack
107 bra cmd_printnext ; go print the next thing
108 cmd_printint8 leax -1,x ; restore one of the zeros
109 bra cmd_printint7 ; go finish up
110 cmd_printintpc fqb 1000000000 ; 10^9
111 fqb 100000000 ; 10^8
112 fqb 10000000 ; 10^7
113 fqb 1000000 ; 10^6
114 fqb 100000 ; 10^5
115 fqb 10000 ; 10^4
116 fqb 1000 ; 10^3
117 fqb 100 ; 10^2
118 fqb 10 ; 10^1
119 fqb 1 ; 10^0
120 *pragmapop list 72 *pragmapop list