10
20 :
30
40 OSWRCH=&FFEE
50 :
60
70 PRPAD=&70:PRTEMP=&71:NUM=&74
80 :
90 DIM mc% 60
100 FOR P=0 TO 1
110 P%=mc%:O%=P%
120 [OPT P*3+4
130 \ Print arbitary size decimal number
140 \ ==================================
150 \ Prints decimal number by pushing digits in reverse order onto stack.
160 \
170 \ See forum.6502.org/viewtopic.php?f=2&t=4894
180 \ and groups.google.com/g/comp.sys.apple2/c/_y27d_TxDHA
190 \
200 \ On entry X=>base of four zero page locations
210 \ Y= number of digits to pad to, 0 for no padding
220 \ On exit 0,X to 3,X are set to zero
230 \ X preserved
240 \ A,Y corrupted
250 \ Uses PRPAD = to hold pad count
260 \ PRTEMP = bit counter
270 \ Size 55 bytes
280 \
290 \ This can display an arbitary number of digits from an arbitary-sized
300 \ number by just increasing or decreasing the number of zero page
310 \ locations used at label PRDEC10 and the bit count at PRDECDIGIT.
320 \
330 .PRDEC STY PRPAD \ Number of padding+digit characters
340 LDY #0 \ Digit counter
350 .PRDECDIGIT LDA #32 \ 32-bit divide
360 STA PRTEMP
370 LDA #0 \ Remainder=0
380 CLV \ V=0 means divide result = 0
390 .PRDECDIV10 CMP #10/2 \ Calculate OSNUM/10
400 BCC PRDEC10
410 SBC #10/2+&80 \ Remove digit & set V=1 to show div result > 0
420 SEC \ Shift 1 into div result
430 .PRDEC10 ROL 0,X \ Shift /10 result into OSNUM
440 ROL 1,X \ The number of locations must match the bits
450 ROL 2,X \ set at PRDECDIGIT
460 ROL 3,X
470 ROL A \ Shift bits of input into acc (input mod 10)
480 DEC PRTEMP
490 BNE PRDECDIV10 \ Continue 32-bit divide
500 ORA #ASC"0" \ Convert to ASCII character
510 PHA \ Push low digit 0-9 to print
520 INY \ Increase number of digits
530 BVS PRDECDIGIT \ If V=1, result of /10 was >0, do next digit
540 LDA #ASC" " \ Pad with spaces
550 .PRDECLP1 CPY PRPAD
560 BCS PRDECLP2 \ Enough padding pushed
570 PHA \ Push leading space characters
580 INY
590 BNE PRDECLP1
600 .PRDECLP2 PLA \ Pop character left to right
610 JSR OSWRCH \ Print it
620 DEY
630 BNE PRDECLP2
640 RTS
650 \ -----------------------------------------------------------------
660 ]:NEXT
670 :
680 REPEAT
690 INPUT "Enter test number: "A%
700 INPUT "Number of padding digits: "B%
710 PRINT "PRDEC: ";:!NUM=A%:X%=NUM:Y%=B%:CALL PRDEC:PRINT
720 UNTIL FALSE