aboutsummaryrefslogtreecommitdiff
path: root/printint.s
diff options
context:
space:
mode:
Diffstat (limited to 'printint.s')
-rw-r--r--printint.s37
1 files changed, 37 insertions, 0 deletions
diff --git a/printint.s b/printint.s
new file mode 100644
index 0000000..6d65f93
--- /dev/null
+++ b/printint.s
@@ -0,0 +1,37 @@
+
+; use FP math pack to print 8- or 16-bit integers in decimal.
+
+;;; Subroutine: printdecb
+;;; Print byte in accumulator, in decimal
+;;; Trashes all regs/flags
+printdecb:
+ ldx #0
+ ; fall thru to printdecw
+
+;;; Subroutine: printdecw
+;;; Print word in A/X, in decimal (X is high byte)
+;;; Trashes all regs/flags
+; one annoyance here: we need (zp),y addressing because FASC actually
+; updates INBUFF to point to the first non-zero ASCII digit (this is
+; how we skip leading zeroes), but we don't have a "printchry" that
+; preserves Y, so we end up using X for a counter and copying it to Y
+; every loop iteration...
+; also, why did I pick A/X instead of X/Y like FLD(0|1)R uses? in case
+; someone ever wants to call this from C code in cc65...
+printdecw:
+ sta FR0
+ stx FR0+1
+ jsr IFP
+ jsr FASC
+ ldx #0
+pwloop:
+ txa
+ tay
+ lda (INBUFF),y
+ php
+ and #$7f
+ jsr printchrx
+ inx
+ plp
+ bpl pwloop
+ rts