diff options
| -rw-r--r-- | src/cmd.c | 4 | ||||
| -rw-r--r-- | src/irc.c | 17 | ||||
| -rw-r--r-- | src/main.c | 3 | ||||
| -rw-r--r-- | src/printnum.s | 80 | ||||
| -rw-r--r-- | src/screen.h | 4 |
5 files changed, 91 insertions, 17 deletions
@@ -11,6 +11,8 @@ /* A "command" is actually anything the user types, whether or not it starts with a / character. */ +extern void num_to_numbuf(unsigned int n); /* printnum.s */ + char *command, *arg1, *arg2, *arg3; static char *target; @@ -249,7 +251,7 @@ unsigned int read_rtclok(void) { } static void rtclok_to_numbuf(void) { - itoa(read_rtclok(), numbuf, 10); + num_to_numbuf(read_rtclok()); } void cmd_server_ping(void) { @@ -133,19 +133,10 @@ static void print_ping_time(char *p) { scr_print_active("*** "); scr_print_active(msg_src); scr_print_active(" lag: "); - itoa(sec, numbuf, 10); - scr_print_active(numbuf); + scr_act_printnum(sec); scr_putc_active('.'); - itoa(frac, numbuf, 10); - scr_print_active(numbuf); + scr_act_printnum(frac); scr_putc_active('s'); - - /* - // for debugging: - scr_putc_active(' '); - itoa(pingtime, numbuf, 10); - scr_print_active(numbuf); - */ } static void do_server_pong(void) { @@ -679,12 +670,10 @@ static void irc_split_Lines(void) { } } -/* TODO: there needs to be a scr_printnum() */ void print_errnum(void) { extern unsigned char err; scr_print_current("Error #"); - itoa(err, numbuf, 10); - scr_print_current(numbuf); + scr_cur_printnum(err); } static void start_minute_timer() { @@ -147,8 +147,7 @@ void reconnect(void) { if(reconnect_timeout) { OS.cdtmv3 = reconnect_timeout * hz; scr_print_current(" or wait "); - itoa(reconnect_timeout, numbuf, 10); - scr_print_current(numbuf); + scr_cur_printnum(reconnect_timeout); scr_print_current(" sec"); if(reconnect_timeout < 64) reconnect_timeout <<= 1; diff --git a/src/printnum.s b/src/printnum.s new file mode 100644 index 0000000..8b97db9 --- /dev/null +++ b/src/printnum.s @@ -0,0 +1,80 @@ +; print a number to the screen. +; based on Ullrich von Bassewitz's itoa.s from the cc65 lib src. +; it's modified to: +; - only support base 10. +; - only support unsigned int. +; - print the result directly to the fnchat screen, or +; - store the result directly in numbuf. + + .importzp sreg + .import _scr_putc_active, _scr_current, _scr_active, _numbuf + .export _scr_cur_printnum, _scr_act_printnum, _num_to_numbuf + + ; sreg+2 bit 7 is a flag that means "print" if set, or "store in numbuf: + ; if clear. also, the bottom bits of sreg+2 are the buffer position, when + ; bit 7 is clear. + +_num_to_numbuf: + ldy #0 + sty sreg+2 + beq printnum + +_scr_cur_printnum: + ldy _scr_current + sty _scr_active + +_scr_act_printnum: + ldy #$80 + sty sreg+2 + +printnum: + sta sreg + stx sreg+1 + + lda #0 + pha ; sentinel + +divloop: + ldy #$10 ; 16-bit remainder + lda #0 + +shift: + asl sreg + rol sreg+1 + rol a + cmp #$0a ; radix + bcc nosub + sbc #$0a + inc sreg + +nosub: + dey + bne shift + + ora #$30 ; make it an ASCII digit + pha ; save digit on stack + + ; are we done yet? + lda sreg + ora sreg+1 + bne divloop ; nope! + + ; get the results from the stack and print. +digitloop: + pla + beq done ; found sentinel? we're done. + ldy sreg+2 + bpl store + jsr _scr_putc_active + jmp digitloop + +store: + sta _numbuf,y + iny + lda #0 + sta _numbuf,y + sty sreg+2 + beq digitloop ; branch always + +done: + rts diff --git a/src/screen.h b/src/screen.h index af95690..34f069f 100644 --- a/src/screen.h +++ b/src/screen.h @@ -107,6 +107,10 @@ char *scr_get_cur_name(void); /* XXX: this really should be in a utils.c or common.c... */ void scr_waitvcount(u8 c); +/* print decimal numbers (see printnum.s) */ +void scr_cur_printnum(u16 c); +void scr_act_printnum(u16 c); + /**** end of public API ****/ /* notes: |
