aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2026-04-06 03:11:25 -0400
committerB. Watson <urchlay@slackware.uk>2026-04-06 03:11:32 -0400
commit7f571f805cb1bf7f7d20e65ac0ec9e0d70105e5a (patch)
tree18301d29de78899d980d1a7b70d53f5a5bd7aac9 /src
parent08bba9cd8f0dfd5269287331b2baae1c388d79dd (diff)
downloadfujinet-chat-7f571f805cb1bf7f7d20e65ac0ec9e0d70105e5a.tar.gz
Rewrite poll_keyboard() in asm. 6667 bytes free.
Diffstat (limited to 'src')
-rw-r--r--src/irc.c29
-rw-r--r--src/kgetc.s2
-rw-r--r--src/pollkbd.s91
3 files changed, 96 insertions, 26 deletions
diff --git a/src/irc.c b/src/irc.c
index e581e94..b12c8da 100644
--- a/src/irc.c
+++ b/src/irc.c
@@ -48,6 +48,9 @@ char last_chan[33]; /* without a screen */
static int minutes, last_read_min;
+/* see pollkbd.s */
+extern void poll_keyboard(void);
+
/*
static void join_channel(void) {
txbuf_set_str2("JOIN ", channel);
@@ -1003,32 +1006,6 @@ void start_keystroke(char c) {
}
}
-static 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;
- }
-}
-
/* only exits on error (e.g. connection closed, which might be via /QUIT). */
void irc_loop(void) {
/* this stuff happens on every connect. */
diff --git a/src/kgetc.s b/src/kgetc.s
index c11cb6d..524e348 100644
--- a/src/kgetc.s
+++ b/src/kgetc.s
@@ -33,6 +33,8 @@
XCH_CAPS = $8a ; must agree with keytab.h
+ ; note: _keypress returns true/false, but also the Z
+ ; flag reflects the return status (Z clear for true).
_keypress:
ldx CH
cpx #$ff
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
+ ldx #>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