aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-04-06 07:41:01 -0400
committerB. Watson <urchlay@slackware.uk>2026-04-06 07:41:13 -0400
commit965524520500cc6a81dddb95ca427cb1a6830f96 (patch)
tree1069aeb081ca487a6c8c75c226b1559e939f7c08 /src
parent2953b35cea6515a5de73bba798583bbb4146bdce (diff)
downloadfujinet-chat-965524520500cc6a81dddb95ca427cb1a6830f96.tar.gz
Rewrite txbuf_append_str() in asm. 6826 bytes free.
Diffstat (limited to 'src')
-rw-r--r--src/main.c6
-rw-r--r--src/txbuf.s29
2 files changed, 25 insertions, 10 deletions
diff --git a/src/main.c b/src/main.c
index 66ced7f..1f533b3 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,12 +33,6 @@ void txbuf_init(void) {
txbuflen = tx_buf[0] = 0;
}
-void txbuf_append_str(const char *str) {
- while(*str) {
- txbuf_append_chr(*str++);
- }
-}
-
void txbuf_append_str2(const char *s1, const char *s2) {
txbuf_append_str(s1);
txbuf_append_str(s2);
diff --git a/src/txbuf.s b/src/txbuf.s
index 4783660..bc1d1c2 100644
--- a/src/txbuf.s
+++ b/src/txbuf.s
@@ -7,7 +7,7 @@
tx_buf = $a200 ; MUST agree with src/rxtxbuf.h!
.import _txbuflen
- .export _txbuf_append_chr
+ .export _txbuf_append_chr, _txbuf_append_str
.importzp sreg ; avoid ptr1 & friends, callers may use
_txbuf_append_chr:
@@ -23,7 +23,28 @@ _txbuf_append_chr:
txa
sta (sreg),y
inc _txbuflen
- bne @ret
+ bne ret
inc _txbuflen+1
-@ret:
- rts
+ret:
+ rts ; always returns with Y == 0
+
+;; void txbuf_append_str(const char *str) {
+;; while(*str) {
+;; txbuf_append_chr(*str++);
+;; }
+;; }
+
+; compiles to 52 bytes.
+; this routine is 22 bytes, ~57% smaller.
+_txbuf_append_str:
+ sta sreg+2
+ stx sreg+3
+ ldy #0
+@loop:
+ lda (sreg+2),y
+ beq ret
+ jsr _txbuf_append_chr
+ inc sreg+2
+ bne @loop
+ inc sreg+3
+ bne @loop