aboutsummaryrefslogtreecommitdiff
path: root/src/txbuf.s
diff options
context:
space:
mode:
Diffstat (limited to 'src/txbuf.s')
-rw-r--r--src/txbuf.s50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/txbuf.s b/src/txbuf.s
new file mode 100644
index 0000000..bc1d1c2
--- /dev/null
+++ b/src/txbuf.s
@@ -0,0 +1,50 @@
+;; void txbuf_append_chr(char c) {
+;; tx_buf[txbuflen++] = c;
+;; }
+
+; compiles to 45 bytes. routine below is 29 bytes (~33% smaller)
+
+ tx_buf = $a200 ; MUST agree with src/rxtxbuf.h!
+
+ .import _txbuflen
+ .export _txbuf_append_chr, _txbuf_append_str
+ .importzp sreg ; avoid ptr1 & friends, callers may use
+
+_txbuf_append_chr:
+ tax
+ lda #<tx_buf
+ clc
+ adc _txbuflen
+ sta sreg
+ lda #>tx_buf
+ adc _txbuflen+1
+ sta sreg+1
+ ldy #0
+ txa
+ sta (sreg),y
+ inc _txbuflen
+ bne ret
+ inc _txbuflen+1
+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