From 7f571f805cb1bf7f7d20e65ac0ec9e0d70105e5a Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 6 Apr 2026 03:11:25 -0400 Subject: Rewrite poll_keyboard() in asm. 6667 bytes free. --- src/pollkbd.s | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/pollkbd.s (limited to 'src/pollkbd.s') diff --git a/src/pollkbd.s b/src/pollkbd.s new file mode 100644 index 0000000..795e6f7 --- /dev/null +++ b/src/pollkbd.s @@ -0,0 +1,91 @@ +; in C: +;; void poll_keyboard(void) { +;; char c; +;; +;; if(!keypress()) return; +;; +;; /* have to latch start status because doing a keyclick clears CONSOL */ +;; if(GTIA_READ.consol == 6) start_latch = 1; +;; +;; c = kgetc(); +;; if(!c) return; +;; +;; /* maybe this shouldn't happen until user presses Enter in the edbox? +;; would let lurkers lurk and read scrollback... */ +;; if(irc_away) { +;; txbuf_send_str("AWAY"); +;; irc_away = 0; +;; } +;; +;; if(start_latch) { /* start pressed */ +;; start_keystroke(c); +;; } else { +;; edbox_keystroke(c); +;; OS.cdtmv3 = hz / 2; +;; } +;; } + +; compiles to ~128 bytes. + + .include "atari.inc" + + .export _poll_keyboard + .import _keypress, _kgetc, _start_latch, _start_keystroke + .import _edbox_keystroke, _hz, _txbuf_send_str, _irc_away + + .rodata +away: + .byte "AWAY",0 + + .code +_poll_keyboard: + ;; if(!keypress()) return; + jsr _keypress + beq @ret ; Z flag set = no keypress + + ;; if(GTIA_READ.consol == 6) start_latch = 1; + lda CONSOL + cmp #6 + bne @nostart + sta _start_latch ; 6, not 1 (doesn't matter so long as it's non-zero) + +@nostart: + ; c = kgetc(); + jsr _kgetc ; note that _kgetc can set _start_latch too + tax ; just to set Z flag based on return value in A + ; if(!c) return; + beq @ret ; if _kgetc returned 0, we're done + + ; if(irc_away) { + ldx _irc_away + beq @noaway + ; irc_away = 0; + ldx #0 + stx _irc_away + ; txbuf_send_str("AWAY"); + pha ; _txbuf_send_str will clobber A so stash it + lda #away + jsr _txbuf_send_str + ; } + pla +@noaway: + ; if(start_latch) { /* start pressed */ + ldx _start_latch + beq @nolatch + ; start_keystroke(c); + ldx #0 + jmp _start_keystroke +@nolatch: + ; } else { + ;;;; ldx #0 ; X already 0 + ; edbox_keystroke(c); + jsr _edbox_keystroke + ; OS.cdtmv3 = hz / 2; + lda _hz + lsr + sta CDTMV3 + ; } + +@ret: + rts -- cgit v1.2.3