Skip to content

Commit

Permalink
[BASIC] Fix 1E39 bug (Issue X16Community#247) (X16Community#357)
Browse files Browse the repository at this point in the history
* Fix 1E39 bug (Issue X16Community#247)

* Remove register Y indexing.

* Almost fixed the 1E39 bug.

* [BASIC] Fix 1E39 bug from C64.

* [BASIC] Fix 1E39 bug.

* [BASIC] Fix 1E39 bug.

* remove superfluous store to index2

---------

Co-authored-by: mooinglemur <[email protected]>
  • Loading branch information
calmsacibis995 and mooinglemur authored Sep 11, 2024
1 parent 3c03483 commit a8981d4
Showing 1 changed file with 43 additions and 22 deletions.
65 changes: 43 additions & 22 deletions basic/code17.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,57 @@ conint jsr posint
bne gofuc
ldx faclo
jmp chrgot
val jsr len1
val_str bne @1

; the "val" function takes a string and turns it into a number by interpreting
; the ascii digits etc. Except for the problem that a terminator must be
; supplied by replacing the character beyond the string, VAL is merely a call
; to floating point input ("finh").
val jsr len1 ;get length
val_str bne @1 ;return 0 if len=0
jmp zerofc
@1: ldx txtptr
@1: ldx txtptr ;save current txtptr
ldy txtptr+1
stx strng2
sty strng2+1
ldx index1
stx txtptr
clc
adc index1
sta index2
ldx index1+1
stx txtptr+1
bcc val2
inx
val2 stx index2+1
lda (index2)
phy
phx
ldx index1 ;save current index1
ldy index1+1
phy
phx
pha
lda #0
sta (index2)
inc
beq val_strlong
jsr strspa ;allocate memory for string (this destroys index1, but we saved it to stack)
plx ;restore saved string length
pla
sta index1 ;restore saved index1
pla
sta index1+1
lda dsctmp+1 ;fetch string space pointer
sta txtptr ;update txtptr with dsctmp
lda dsctmp+2
sta txtptr+1
ldy #0 ;initalize Y to begin copying the string
@2: lda (index1),y ;load current byte
sta (txtptr),y ;store it in allocated memory
iny
dex
bne @2 ;loop until string is copied
lda #0 ;load null terminator byte
sta (txtptr),y ;write it to the end of the string
jsr chrgot
jsr finh
pla
sta (index2)
st2txt ldx strng2
plx ;restore saved txtptr
ply
stx txtptr
sty txtptr+1
rts ;done!
st2txt ldx strng2 ;restore text pointer
ldy strng2+1
stx txtptr
sty txtptr+1
valrts rts
valrts rts ;done!
val_strlong ldx #errls
jmp error
getnum jsr frmadr
combyt jsr chkcom
jmp getbyt
Expand Down

0 comments on commit a8981d4

Please sign in to comment.