File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -192,8 +192,9 @@ xit_emit:
192192 ; Expected A = 0 on input, emits two bytes
193193.proc read_hex
194194 ; We have A==0 here
195- tax ; X = low-part of result
196- stx tmp1+1 ; tmp1+1: hi-part of result
195+ sta tmp1 ; tmp1 holds the result
196+ sta tmp1+1
197+ tax ; X=0 means no characters consumed yet
197198
198199nloop:
199200 ; Read next hex digit
@@ -203,41 +204,36 @@ nloop:
203204 cmp #10
204205 bcc digit
205206
206- sbc #'A' ^'0'
207- cmp #6
208- bcs xit ; Not an hex number
209- adc #10 ; set to range 10-15
207+ sbc #('A' ^'0' )+(256-250 )
208+ cmp #$FA
209+ bcc xit ; Not an hex number
210210
211211digit:
212- sta tmp1 ; and save digit
212+ asl
213+ asl
214+ asl
215+ asl
213216
214217 ; Multiply tmp by 16
215- txa
216- ldx #4
218+ ldx #3
217219: asl
220+ rol tmp1
218221 rol tmp1+1
219- bcs ret ; Exit with C = 1 on overflow
222+ bcs E_EOL ::xit ; Exit with C = 1 on overflow
220223 dex
221- bne :-
224+ bpl :-
222225
223- ; Add new digit
224- ora tmp1
225- tax
226- bcc nloop
227-
228- ret:
229- rts
226+ ; X = 255 here, used to check that one character was consumed
227+ bmi nloop
230228
231229xit:
232230 ; Check that we consumed at least one character after the "$"
233- dey
234- cpy bpos
235- beq ret ; Exit with C = 1 (if Y-1 == bpos, C = 1)
236- iny
231+ inx
232+ bne E_EOL ::xit ; Exit with C = 1 (if Y-1 == bpos, C = 1)
237233
238- txa
234+ lda tmp1
239235 ldx tmp1+1
240- bcs E_NUMBER_WORD ::xit_emit
236+ bcc E_NUMBER_WORD ::xit_emit
241237.endproc
242238
243239.proc E_NUMBER_BYTE
You can’t perform that action at this time.
0 commit comments