aboutsummaryrefslogtreecommitdiff
path: root/src/permute.s
blob: d4206ea58b18744c4ddc468e04234ad8639ac470 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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