Skip to content

Commit 2a0ea21

Browse files
committed
Optimize read_word, returns 0 on null string.
1 parent 06c7da2 commit 2a0ea21

3 files changed

Lines changed: 24 additions & 17 deletions

File tree

src/interp/val.asm

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
jsr get_str_eol
4646
jsr read_word
4747
bcc :+
48-
lda #18
49-
sta IOERROR
48+
ldy #18
49+
sty IOERROR
5050
: jmp next_instruction
5151
.endproc
5252

@@ -57,10 +57,6 @@ SKBLANK = $DBA1
5757
; Skips white space at start
5858
jsr SKBLANK
5959

60-
; Clears result
61-
ldx #0
62-
stx tmp1
63-
6460
; Reads a '+' or '-'
6561
lda (INBUFF), y
6662
cmp #'+'
@@ -77,34 +73,39 @@ SKBLANK = $DBA1
7773
skip: iny
7874
convert:
7975
sty tmp2+1 ; Store starting Y position - used to check if read any digits
76+
; Clears result
77+
lda #0
78+
tax
8079
loop:
80+
; Store A/X
81+
sta tmp1
82+
stx tmp1+1
83+
8184
; Reads one character
8285
lda (INBUFF), y
8386
sec
8487
sbc #'0'
8588
cmp #10
89+
sta tmp2 ; save digit
90+
lda tmp1 ; and restore A
91+
8692
bcs xit_n ; Not a number
8793

8894
iny ; Accept
8995

90-
sta tmp2 ; and save digit
96+
cpx #26 ; Reject numbers > $1A00 (6656)
97+
bcs ebig
9198

9299
; Multiply "tmp1" by 10 - uses A,X, keeps Y
93-
lda tmp1
94-
stx tmp1+1
95-
96100
asl
97101
rol tmp1+1
98-
bcs ebig
99102
asl
100103
rol tmp1+1
101-
bcs ebig
102104

103105
adc tmp1
104106
sta tmp1
105107
txa
106108
adc tmp1+1
107-
bcs ebig
108109

109110
asl tmp1
110111
rol a
@@ -114,7 +115,6 @@ loop:
114115
; Add new digit
115116
lda tmp2
116117
adc tmp1
117-
sta tmp1
118118
bcc loop
119119
inx
120120
bne loop
@@ -124,9 +124,8 @@ ebig:
124124
xit: rts
125125

126126
xit_n: cpy tmp2+1
127-
beq ebig ; No digits read
127+
beq xit ; No digits read
128128

129-
lda tmp1
130129
clc
131130
rts
132131
.endproc

testsuite/tests/stmt-input.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ input "Prompt:", a
88
? err(), a
99
input a
1010
? err(), a
11+
input a
12+
? err(), a
13+
input a
14+
? err(), a
1115
input s$
1216
? err(), s$
1317
input s$

testsuite/tests/stmt-input.chk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@ Input:
55
2345
66
3456
77

8+
65535
9+
65536
810
hello
911
.
1012
Output:
1113
Start
1214
?1 1234
1315
1 2345
1416
Prompt: 1 3456
15-
?18 18
17+
?18 0
18+
?1 -1
19+
?18 0
1620
?1 hello
1721
?136

0 commit comments

Comments
 (0)