10
20
30
40
50
60
70
80
90 :
100
110 OSWRCH=&FFEE
120 :
130
140 pad=&70:num=&71
150 :
160 DIM mc% 299
170 FOR P=0 TO 1
180 P%=mc%:O%=P%
190 [OPT P*3+4
200 :
210 \ ---------------------------
220 \ Print 16-bit decimal number
230 \ ---------------------------
240 \ On entry num=number to print
250 \ pad=0 or pad character (eg '0' or ' ')
260 \ On entry at PrDec16Lp1
270 \ Y=(number of digits)*2-2, eg 8 for 5 digits
280 \ On exit A,X,Y,num,pad corrupted
290 \ Size 69 bytes
300 \ -----------------------------------------------------------------
310 .PrDec16
320 LDY #8 :\ Offset to powers of ten
330 .PrDec16Lp1
340 LDX #&FF:SEC :\ Start with digit=-1
350 .PrDec16Lp2
360 LDA num+0:SBC PrDec16Tens+0,Y:STA num+0 :\ Subtract current tens
370 LDA num+1:SBC PrDec16Tens+1,Y:STA num+1
380 INX:BCS PrDec16Lp2 :\ Loop until <0
390 LDA num+0:ADC PrDec16Tens+0,Y:STA num+0 :\ Add current tens back in
400 LDA num+1:ADC PrDec16Tens+1,Y:STA num+1
410 TXA:BNE PrDec16Digit :\ Not zero, print it
420 LDA pad:BNE PrDec16Print:BEQ PrDec16Next :\ pad<>0, use it
430 .PrDec16Digit
440 LDX #ASC"0":STX pad :\ No more zero padding
450 ORA #ASC"0" :\ Print this digit
460 .PrDec16Print
470 JSR OSWRCH
480 .PrDec16Next
490 DEY:DEY:BPL PrDec16Lp1 :\ Loop for next digit
500 RTS
510 :
520 .PrDec16Tens
530 EQUW 1
540 EQUW 10
550 EQUW 100
560 EQUW 1000
570 EQUW 10000
580 \ -----------------------------------------------------------------
590
600
610 \ ---------------------------
620 \ Print 24-bit decimal number
630 \ ---------------------------
640 \ On entry num=number to print
650 \ pad=0 or pad character (eg '0' or ' ')
660 \ On entry at PrDec24Lp1
670 \ Y=(number of digits)*3-3, eg 21 for 8 digits
680 \ On exit A,X,Y,num,pad corrupted
690 \ Size 98 bytes
700 \ -----------------------------------------------------------------
710 .PrDec24
720 LDY #21 :\ Offset to powers of ten
730 .PrDec24Lp1
740 LDX #&FF:SEC :\ Start with digit=-1
750 .PrDec24Lp2
760 LDA num+0:SBC PrDec24Tens+0,Y:STA num+0 :\ Subtract current tens
770 LDA num+1:SBC PrDec24Tens+1,Y:STA num+1
780 LDA num+2:SBC PrDec24Tens+2,Y:STA num+2
790 INX:BCS PrDec24Lp2 :\ Loop until <0
800 LDA num+0:ADC PrDec24Tens+0,Y:STA num+0 :\ Add current tens back in
810 LDA num+1:ADC PrDec24Tens+1,Y:STA num+1
820 LDA num+2:ADC PrDec24Tens+2,Y:STA num+2
830 TXA:BNE PrDec24Digit :\ Not zero, print it
840 LDA pad:BNE PrDec24Print:BEQ PrDec24Next :\ pad<>0, use it
850 .PrDec24Digit
860 LDX #ASC"0":STX pad :\ No more zero padding
870 ORA #ASC"0" :\ Print this digit
880 .PrDec24Print
890 JSR OSWRCH
900 .PrDec24Next
910 DEY:DEY:DEY:BPL PrDec24Lp1 :\ Loop for next digit
920 RTS
930 :
940 .PrDec24Tens
950 EQUW 1 :EQUB 1 DIV 65536
960 EQUW 10 :EQUB 10 DIV 65536
970 EQUW 100 :EQUB 100 DIV 65536
980 EQUW 1000 :EQUB 1000 DIV 65536
990 EQUW 10000 :EQUB 10000 DIV 65536
1000 EQUW 100000 :EQUB 100000 DIV 65536
1010 EQUW 1000000 :EQUB 1000000 DIV 65536
1020 EQUW 10000000:EQUB 10000000 DIV 65536
1030 \ -----------------------------------------------------------------
1040
1050
1060 \ ---------------------------
1070 \ Print 32-bit decimal number
1080 \ ---------------------------
1090 \ On entry num=number to print
1100 \ pad=0 or pad character (eg '0' or ' ')
1110 \ On entry at PrDec32Lp1
1120 \ Y=(number of digits)*4-4, eg 36 for 10 digits
1130 \ On exit A,X,Y,num,pad corrupted
1140 \ Size 129 bytes
1150 \ -----------------------------------------------------------------
1160 .PrDec32
1170 LDY #36 :\ Offset to powers of ten
1180 .PrDec32Lp1
1190 LDX #&FF:SEC :\ Start with digit=-1
1200 .PrDec32Lp2
1210 LDA num+0:SBC PrDec32Tens+0,Y:STA num+0 :\ Subtract current tens
1220 LDA num+1:SBC PrDec32Tens+1,Y:STA num+1
1230 LDA num+2:SBC PrDec32Tens+2,Y:STA num+2
1240 LDA num+3:SBC PrDec32Tens+3,Y:STA num+3
1250 INX:BCS PrDec32Lp2 :\ Loop until <0
1260 LDA num+0:ADC PrDec32Tens+0,Y:STA num+0 :\ Add current tens back in
1270 LDA num+1:ADC PrDec32Tens+1,Y:STA num+1
1280 LDA num+2:ADC PrDec32Tens+2,Y:STA num+2
1290 LDA num+3:ADC PrDec32Tens+3,Y:STA num+3
1300 TXA:BNE PrDec32Digit :\ Not zero, print it
1310 LDA pad:BNE PrDec32Print:BEQ PrDec32Next :\ pad<>0, use it
1320 .PrDec32Digit
1330 LDX #ASC"0":STX pad :\ No more zero padding
1340 ORA #ASC"0" :\ Print this digit
1350 .PrDec32Print
1360 JSR OSWRCH
1370 .PrDec32Next
1380 DEY:DEY:DEY:DEY:BPL PrDec32Lp1 :\ Loop for next digit
1390 RTS
1400 :
1410 .PrDec32Tens
1420 EQUD 1
1430 EQUD 10
1440 EQUD 100
1450 EQUD 1000
1460 EQUD 10000
1470 EQUD 100000
1480 EQUD 1000000
1490 EQUD 10000000
1500 EQUD 100000000
1510 EQUD 1000000000
1520 \ -----------------------------------------------------------------
1530
1540 ]:NEXT
1550 :
1560 REPEAT
1570 INPUT "Enter test number: "A%
1580 INPUT "Enter pad character: "B%
1590 PRINT "PrDec16: ";:?pad=B%:!num=A%:CALL PrDec16:PRINT
1600 PRINT "PrDec24: ";:?pad=B%:!num=A%:CALL PrDec24:PRINT
1610 PRINT "PrDec32: ";:?pad=B%:!num=A%:CALL PrDec32:PRINT
1620 UNTIL FALSE