diff options
| -rw-r--r-- | src/complete.c | 6 | ||||
| -rw-r--r-- | src/irc.c | 16 | ||||
| -rw-r--r-- | src/jifsec.s | 74 |
3 files changed, 82 insertions, 14 deletions
diff --git a/src/complete.c b/src/complete.c index fa3a240..0a7055b 100644 --- a/src/complete.c +++ b/src/complete.c @@ -32,7 +32,8 @@ static void add_list(const char *n) { strncpy(add_to[pm_nick_pos], n, 24); pm_nick_pos++; - pm_nick_pos %= MAX_PM_NICKS; + if(pm_nick_pos == MAX_PM_NICKS) + pm_nick_pos = 0; } void comp_add_pm_nick(const char *n) { @@ -125,7 +126,8 @@ void comp_complete_done(void) { } void comp_continue(void) { - search_pos %= MAX_PM_NICKS; + if(search_pos == MAX_PM_NICKS) + search_pos = 0; while(search_pos < MAX_PM_NICKS) { if(match(prefix, list[search_pos])) { edbox_set(list[search_pos]); @@ -119,8 +119,8 @@ static void do_priv_nick(void) { the compiled code smaller, but it grew by ~50 bytes. avoid. */ static void print_ping_time(char *p) { + extern void print_jif_sec(unsigned int j); static unsigned int now, pingtime; - static unsigned int sec, frac; now = read_rtclok(); pingtime = (unsigned int)a2uint(p); @@ -128,19 +128,10 @@ static void print_ping_time(char *p) { /* correct for rtclock rollover (every ~9 mins) */ if(now < pingtime) now |= 0x8000; - pingtime = now - pingtime; - - sec = pingtime / timers.hz; - frac = pingtime % timers.hz; - frac *= 100; - frac /= timers.hz; - scr_print_active("*** "); scr_print_active(msg_src); scr_print_active(" lag: "); - scr_act_printnum(sec); - scr_putc_active('.'); - scr_act_printnum(frac); + print_jif_sec(now - pingtime); scr_putc_active('s'); } @@ -791,7 +782,8 @@ static void hunt_screen(signed char dir) { s += dir; if(s < 0) s = MAX_SCREENS - 1; - s %= MAX_SCREENS; + if(s == MAX_SCREENS) + s = 0; } while(scr_status[s] == SCR_UNUSED); scr_display(s); 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 |
