Skip to content

Commit 2d47fe5

Browse files
committed
Simplify variable name check, 6 bytes shorter.
1 parent 00a267b commit 2d47fe5

1 file changed

Lines changed: 7 additions & 12 deletions

File tree

src/vars.asm

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,16 @@ var_namelen= len
5656
; Checks if a character is valid for a variable name
5757
.proc check_char
5858
cmp #'0'
59-
bcc bad_char
59+
bcc ret_sec
6060
cmp #'9'+1
6161
bcc exit
6262
first:
6363
cmp #'_'
64-
beq char_ok
65-
cmp #'A'
66-
bcc bad_char
67-
cmp #'Z'+1
64+
beq ret_clc
65+
sbc #'A'-1
66+
cmp #26
6867
exit:
6968
rts
70-
bad_char:
71-
sec
72-
rts
73-
char_ok:
74-
clc
75-
rts
7669
.endproc
7770

7871
; Search the list of variables by name,
@@ -117,6 +110,7 @@ cmp_loop:
117110

118111
found:
119112
lda (var), y
113+
::ret_clc:
120114
clc
121115
rts
122116

@@ -153,7 +147,8 @@ search_start:
153147
cpx #0
154148
bne search_loop
155149

156-
not_found:
150+
; Variable name not found, exit with C=1
151+
::ret_sec:
157152
sec
158153
rts
159154
.endproc

0 commit comments

Comments
 (0)