diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-04-08 06:05:21 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-04-08 06:05:32 -0400 |
| commit | de399537f2e3aa542e716ad50d301062152588f0 (patch) | |
| tree | d37ef84f593255ad590ef79a11cbf451daa49e9f /src/jifsec.s | |
| parent | 7bbd819c8d2acbcc800f33644571b8d683924bb9 (diff) | |
| download | fujinet-chat-de399537f2e3aa542e716ad50d301062152588f0.tar.gz | |
Rewrite guts of print_ping_time() in asm, banish C division and modulus operators. 7359 bytes free.
Diffstat (limited to 'src/jifsec.s')
| -rw-r--r-- | src/jifsec.s | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/jifsec.s b/src/jifsec.s new file mode 100644 index 0000000..4972cdf --- /dev/null +++ b/src/jifsec.s @@ -0,0 +1,74 @@ +; print jiffies as seconds, with possible decimal point, to the +; active screen. +; unsigned divide based on Ullrich von Bassewitz's runtime/udiv.s. +; uses FR0 as a temp, rather than any of cc65's ZP storage, +; to avoid clobbering. + + FR0 = $d4 + acc16 = FR0 ; 16 bits + remainder = FR0+2 ; 8 bits + temp = FR0+3 ; 16 bits + + _hz = $f0 ; must agree with timers.h! + + .import _scr_act_printnum, _scr_putc_active + .import mulax10 + + ; extern void print_jif_sec(unsigned int jiffies); + .export _print_jif_sec + +_print_jif_sec: + jsr divbyhz + lda acc16 + ldx acc16+1 + jsr _scr_act_printnum ; print the seconds (it's OK if it's 0) + lda remainder + bne @printfrac + rts ; if it was an even number of seconds, we're done +@printfrac: + lda #'.' ; otherwise, we need a decimal point... + jsr _scr_putc_active + lda remainder + ldx #0 + jsr mulax10 + jsr mulax10 + sta acc16 + stx acc16+1 + jsr divbyhz ; remainder /= hz + lda acc16 + cmp #$0a ; does it need a leading zero? + bcs @no_0 + lda #'0' + jsr _scr_putc_active + lda acc16 ; clobbered by printing, reload +@no_0: + ldx acc16+1 + jmp _scr_act_printnum ; print it, we're done + +; divide 16-bit a/x by 8-bit _hz. +; result in acc16, remainder in remainder. +divbyhz: + sty temp + sta acc16 + stx acc16+1 + lda #0 + ldy #16 + +@L0: + asl acc16 + rol acc16+1 + rol a + bcs @L1 + + cmp _hz + bcc @L2 +@L1: + sbc _hz + inc acc16 + +@L2: + dey + bne @L0 + sta remainder + ldy temp + rts |
