aboutsummaryrefslogtreecommitdiff
path: root/src/txbuf.s
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-04-13 18:27:08 -0400
committerB. Watson <urchlay@slackware.uk>2026-04-13 18:27:20 -0400
commit66219401006e845f1a176e6a78c4682bd9de8785 (patch)
tree2b7426294a58069b4e8c1b06229682012685fdb9 /src/txbuf.s
parent5c3a3b18659a863f4983ab1579dc68333b429e08 (diff)
downloadfujinet-chat-66219401006e845f1a176e6a78c4682bd9de8785.tar.gz
Rewrite most of the txbuf_* functions in asm. 7803 bytes free.
Diffstat (limited to 'src/txbuf.s')
-rw-r--r--src/txbuf.s33
1 files changed, 32 insertions, 1 deletions
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