# HG changeset patch # User William Astle # Date 1682215565 21600 # Node ID bb9fe2bd4894011b1a1af75f50dbc93849ad617a # Parent 2205c3c59a3345dec6f6b4e4bd3706d947dff030 Fix display of integer values diff -r 2205c3c59a33 -r bb9fe2bd4894 src/lwbasic.s --- a/src/lwbasic.s Sat Apr 22 08:47:54 2023 -0600 +++ b/src/lwbasic.s Sat Apr 22 20:06:05 2023 -0600 @@ -1562,12 +1562,17 @@ lda #0x20 ; default sign (positive) ldb val0.int ; is it negative? bpl cmd_printint0 ; brif not + ldd zero ; + subd val0.int+2 + std val0.int+2 + ldd zero + sbcb val0.int+1 + sbca val0.int + std val0.int 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 - tsta ; negative value? - bmi cmd_printint3 ; brif so - start with addition loop ; subtraction loop - positive residue cmd_printint1 lda #'0-1 ; initialize digit sta ,y @@ -1580,26 +1585,17 @@ sbca ,u std val0.int bcc cmd_printint2 ; brif we didn't go negative + ldd val0.int+2 ; undo last subtract + addd 2,u + std val0.int+2 + ldd val0.int + adcb 1,u + adca ,u + std val0.int leay 1,y ; move to next digit in buffer leau 4,u ; move to next constant leax -1,x ; done all constants? - beq cmd_printint5 ; brif so - handle cleanup -; addition loop - negative residue -cmd_printint3 lda #'0-1 ; initialize digit - sta ,y -cmd_printint4 inc ,y ; bump digit - ldd val0.int+2 ; add the constant to the residue - addd 2,u - std val0.int+2 - ldd val0.int - adcb 1,u - adca ,u - std val0.int - bcc cmd_printint3 ; brif we didn't go positive (subtraction loop) - leay 1,y ; move to next digit - leau 4,u ; move to next constant - leax -1,x ; done all digits? - bne cmd_printint1 ; brif not - go do a subtraction loop + 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 @@ -1607,7 +1603,7 @@ 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 + 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 @@ -1729,7 +1725,8 @@ bra eval_number0 ; deal with next input eval_number2 cmpa #'+ ; unary +? beq eval_number0 ; brif so - skip it -eval_number5 beq eval_float ; brif decimal - force float +eval_number5 cmpa #'. ; decimal point? + beq eval_float ; brif decimal - force float cmpa #'0 ; is it a number? blo eval_numberr ; brif below digit cmpa #'9 ; is it still a number?