Mercurial > hg > index.cgi
changeset 48:39275fdc7c0b
Add routine to print unsigned integer in D to current output
author | William Astle <lost@l-w.ca> |
---|---|
date | Sat, 10 Dec 2022 00:21:02 -0700 |
parents | b98c01cd3377 |
children | f5966048a796 |
files | src/lwbasic.s |
diffstat | 1 files changed, 43 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lwbasic.s Sat Dec 10 00:19:53 2022 -0700 +++ b/src/lwbasic.s Sat Dec 10 00:21:02 2022 -0700 @@ -1298,6 +1298,49 @@ prompt fcn 'OK' ; general prompt breakmsg fcn 'BREAK' ; "BREAK" message ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Print out an unsigned 16 bit value in D to the selected output stream +print_uint16d pshs d,x,y,u ; save number and make some temporaries on the stack + leay 2,s ; point to start of buffer + ldu #10000 ; do the 10000s digit + bsr print_uint16d4 + ldu #1000 ; do the 1000s digit + bsr print_uint16d4 + ldu #100 ; do the 100s digit + bsr print_uint16d4 + ldu #10 ; do the 10s digit + bsr print_uint16d4 + puls d ; get back number residue and clean up stack + addb #0x30 ; convert 1s digit to number + stb ,y+ ; stash it + clr ,y ; NUL terminate it + leay ,s ; point to start of converted number +print_uint16d0 lda ,y+ ; get first digit + beq print_uint16d3 ; brif number was zero + cmpa #0x30 ; is it a zero? + beq print_uint16d0 ; brif so - skip it + leay -1,y ; move back to first nonzero digit +print_uint16d1 lda ,y+ ; get number digit + beq print_uint16d2 ; brif end of number + jsr writechr ; output the digit + bra print_uint16d1 ; handle next digit +print_uint16d2 leas 6,s ; clean up the stack + rts +print_uint16d3 lda #0x30 ; digit 0 (less 1 for inc below) + leas 6,s ; clean up the stack + jmp writechr ; output zero and return +print_uint16d4 lda #0x30-1 ; init digit value + pshs a,u ; save the digit position and digit value + ldd 5,s ; get back residue +print_uint16d5 inc ,s ; bump digit + subd 1,s ; subtract out place value + bcc print_uint16d5 ; brif we haven't got the right digit yet + addd 1,s ; restore residue + std 5,s ; save new residue + puls a,u ; get back digit and place value off stack + sta ,y+ ; save digit in buffer + rts + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; PRINT command cmd_print rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;