Skip to content

Commit 1d5a55e

Browse files
committed
Optimize a few bytes from read_hex.
1 parent 33b1323 commit 1d5a55e

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/actions.asm

+17-15
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,23 @@ xit: sec
186186
beq read_hex
187187

188188
jsr read_word
189-
bcs E_EOL::xit
190189

191190
.ifdef FASTBASIC_FP
191+
bcs E_EOL::xit
192+
192193
; In FP version, fails if number is followed by decimal dot
193194
sta tmp1
194195
lda (bptr), y
195196
cmp #'.'
196197
beq E_EOL::xit
197198
lda tmp1
198-
.endif ; FASTBASIC_FP
199199

200200
sty bpos
201201
jmp emit_AX
202+
.else
203+
bcc xit_emit
204+
rts
205+
.endif ; FASTBASIC_FP
202206

203207
read_hex:
204208
nloop:
@@ -209,11 +213,11 @@ nloop:
209213
sbc #'0'
210214
cmp #10
211215
bcc digit
212-
cmp #'A'-'0'
213-
bcc xit
214-
sbc #'A'-'0'-10
215-
cmp #16
216+
217+
sbc #'A'-'0'
218+
cmp #6
216219
bcs xit ; Not an hex number
220+
adc #10 ; set to range 10-15
217221

218222
digit:
219223
sta tmp1 ; and save digit
@@ -225,14 +229,11 @@ digit:
225229

226230
; Multiply tmp by 16
227231
txa
228-
asl
229-
rol tmp1+1
230-
asl
231-
rol tmp1+1
232-
asl
233-
rol tmp1+1
234-
asl
232+
ldx #4
233+
: asl
235234
rol tmp1+1
235+
dex
236+
bne :-
236237

237238
; Add new digit
238239
ora tmp1
@@ -249,10 +250,11 @@ xit:
249250
; cpy bpos ; Check that we consumed at least one character
250251
; beq ret ; Exit with C = 1 (if Y == bpos, C = 1)
251252

252-
sty bpos
253-
254253
txa
255254
ldx tmp1+1
255+
xit_emit:
256+
257+
sty bpos
256258
jmp emit_AX
257259
.endproc
258260

0 commit comments

Comments
 (0)