diff options
| -rw-r--r-- | src/irc.c | 22 | ||||
| -rw-r--r-- | src/permute.s | 78 |
2 files changed, 79 insertions, 21 deletions
@@ -363,27 +363,7 @@ static void do_mode(void) { do_catchall(0); } -/* permutes last character (doesn't add one), so for "Bob" you get: - Bo_, Bo1 through Bo9, BoA through BoZ - Gives a total of 36 replacement nicks to try. - Eventually we run out and start repeating, but by then the IRC - server will have disconnected us. - */ -static void permute_nick(void) { - static char *last; - - last = conf->nick + strlen(conf->nick) - 1; - - if((*last >= '1' && *last < '9') || (*last >= 'A' && *last < 'Z')) { - (*last)++; - } else { - switch(*last) { - case '_': *last = '1'; break; - case '9': *last = 'A'; break; - default: *last = '_'; break; - } - } -} +extern void permute_nick(void); /* see: https://defs.ircdocs.horse/ */ static void do_forward_chan(void) { diff --git a/src/permute.s b/src/permute.s new file mode 100644 index 0000000..d4206ea --- /dev/null +++ b/src/permute.s @@ -0,0 +1,78 @@ + .export _permute_nick + .importzp ptr1 + +;permutes last character (doesn't add one), so for "Bob" you get: +;Bo_, Bo1 through Bo9, BoA through BoZ +;Gives a total of 36 replacement nicks to try. +;Eventually we run out and start repeating, but by then the IRC +;server will have disconnected us. + +;; static void permute_nick(void) { +;; static char *last; +;; +;; last = conf->nick + strlen(conf->nick) - 1; +;; +;; if((*last >= '1' && *last < '9') || (*last >= 'A' && *last < 'Z')) { +;; (*last)++; +;; } else { +;; switch(*last) { +;; case '_': *last = '1'; break; +;; case '9': *last = 'A'; break; +;; default: *last = '_'; break; +;; } +;; } +;; } + +;; WARNING: the address of conf->nick is hardcoded here as $0480. +;; So is its length (25). + + nick = $0480 + +_permute_nick: + ldy #0 +@l1: + lda nick,y + beq perm + iny + cpy #$18 ; stop after 24 chars + bne @l1 + +perm: + dey ; last non-null character. + lda nick,y + + tax + + cpx #'1' + bcc nonnum + cpx #'8'+1 + bcc inc_and_ret + +nonnum: + cpx #'A' + bcc nonaplha + cpx #'Z' + bcc inc_and_ret + +nonaplha: + cpx #'_' + bne non_uscore + ldx #'1' + bne ret + +non_uscore: + cpx #'9' + bne non_9 + ldx #'A' + bne ret + +non_9: + ldx #'_' + bne ret + +inc_and_ret: + inx +ret: + txa + sta nick,y + rts |
