From 66219401006e845f1a176e6a78c4682bd9de8785 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 13 Apr 2026 18:27:08 -0400 Subject: Rewrite most of the txbuf_* functions in asm. 7803 bytes free. --- src/irc.h | 22 ++++++++++++---------- src/main.c | 14 -------------- src/txbuf.s | 33 ++++++++++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 25 deletions(-) (limited to 'src') diff --git a/src/irc.h b/src/irc.h index 55f1d4d..013798a 100644 --- a/src/irc.h +++ b/src/irc.h @@ -10,22 +10,27 @@ extern unsigned char err; extern unsigned char trip; extern char reconnect_timeout; +/**** these are in txbuf.s: */ + /* clears the transmit buffer. */ void txbuf_init(void); - -/* these are in txbuf.s: */ +/* append \x01 (CTCP marker) character */ void txbuf_append_01(void); +/* append a space */ void txbuf_append_spc(void); +/* append an arbitrary character */ void txbuf_append_chr(char c); - /* appends a string to the transmit buffer, updates txbuflen. */ void txbuf_append_str(const char *str); -/* convenience macro */ -#define txbuf_append_str2(s1, s2) do { txbuf_append_str(s1); txbuf_append_str(s2); } while(0) - /* clears the transmit buffer, then appends a string to it. */ -/* turning into a macro bloats the code */ void txbuf_set_str(const char *str); +/* sends a string. clears transmit buffer first, then clears it again on exit. */ +void txbuf_send_str(const char *str); + +/****************************/ + +/* convenience macro */ +#define txbuf_append_str2(s1, s2) do { txbuf_append_str(s1); txbuf_append_str(s2); } while(0) /* as txbuf_set_str(), but multiple strings. */ /* making them macros actually makes the code smaller. */ @@ -36,9 +41,6 @@ void txbuf_set_str(const char *str); in the buffer, nothing gets sent. */ void txbuf_send(void); -/* sends a string. clears transmit buffer first, then clears it again on exit. */ -void txbuf_send_str(const char *str); - void print_error(unsigned char err); /* does exactly what you think */ diff --git a/src/main.c b/src/main.c index 39763c8..98a45c6 100644 --- a/src/main.c +++ b/src/main.c @@ -27,15 +27,6 @@ char reconnect_timeout = 1; extern void ih(); // defined in intr.s -void txbuf_init(void) { - txbuflen = tx_buf[0] = 0; -} - -void txbuf_set_str(const char *str) { - txbuf_init(); - txbuf_append_str(str); -} - void txbuf_send(void) { /* don't send empty buffer */ if(!txbuflen) return; @@ -51,11 +42,6 @@ void txbuf_send(void) { txbuf_init(); } -void txbuf_send_str(const char *str) { - txbuf_set_str(str); - txbuf_send(); -} - int fn_connect(void) { scr_display(SCR_SERVER); scr_print_current("Connecting to: "); diff --git a/src/txbuf.s b/src/txbuf.s index dba52c3..6f7b55d 100644 --- a/src/txbuf.s +++ b/src/txbuf.s @@ -6,11 +6,25 @@ tx_buf = $a200 ; MUST agree with src/rxtxbuf.h! - .import _txbuflen + .import _txbuflen, _txbuf_send .export _txbuf_append_chr, _txbuf_append_str .export _txbuf_append_spc, _txbuf_append_01 + .export _txbuf_init, _txbuf_set_str, _txbuf_send_str .importzp sreg ; avoid ptr1 & friends, callers may use +;; void txbuf_init(void) { +;; txbuflen = tx_buf[0] = 0; +;; } +; this asm implementation is the same size as the compiled code, +; but it only uses the Y register, which lets its callers avoid +; having to save the A register before calling it. +_txbuf_init: + ldy #0 + sty tx_buf + sty _txbuflen + sty _txbuflen+1 + rts + _txbuf_append_01: lda #$01 .byte $2c ; BIT abs, skip next instruction @@ -34,6 +48,14 @@ _txbuf_append_chr: ret: rts ; always returns with Y == 0 +;; void txbuf_set_str(const char *str) { +;; txbuf_init(); +;; txbuf_append_str(str); +;; } +_txbuf_set_str: + jsr _txbuf_init ; remember, this doesn't touch A or X! + ; fall through to _txbuf_append_str + ;; void txbuf_append_str(const char *str) { ;; while(*str) { ;; txbuf_append_chr(*str++); @@ -54,3 +76,12 @@ _txbuf_append_str: bne @loop inc sreg+3 bne @loop + rts ; safety net, the above is really a 'branch always' + +;; void txbuf_send_str(const char *str) { +;; txbuf_set_str(str); +;; txbuf_send(); +;; } +_txbuf_send_str: + jsr _txbuf_set_str + jmp _txbuf_send -- cgit v1.2.3