From 295b0510dce97843127706ef79bb10e5664bb692 Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Sat, 31 Aug 2024 23:43:57 +0300 Subject: [PATCH 1/7] Fix 1E39 bug (Issue #247) --- basic/code17.s | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index e5789fd0..dfc51a11 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -4,36 +4,45 @@ 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 val1 ;return 0 if len=0 jmp zerofc -@1: ldx txtptr +val1 ldx txtptr ldy txtptr+1 stx strng2 sty strng2+1 ldx index1 stx txtptr + lda index1 ;load the low byte of index1 clc - adc index1 - sta index2 + adc len1 ;add len to index1 and put in strng2 + sta strng2 + lda index1+1 ;load the high byte of index1 + adc #0 + sta strng2+1 ;store result in high byte of strng2 ldx index1+1 stx txtptr+1 bcc val2 inx -val2 stx index2+1 - lda (index2) +val2 stx strng2+1 + lda (strng2),y ;replace character after string with $00 (fake eol) pha lda #0 - sta (index2) + sta (strng2),y jsr chrgot - jsr finh - pla - sta (index2) -st2txt ldx strng2 + jsr finh ;go do evaluation + pla ;get pres'd character. + sta (strng2),y ;restore zeroed-out character +st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr sty txtptr+1 -valrts rts +valrts rts ;done! getnum jsr frmadr combyt jsr chkcom jmp getbyt From 4099173dc01f814c88cb2b34303d28675aa7007f Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Mon, 2 Sep 2024 17:00:51 +0300 Subject: [PATCH 2/7] Remove register Y indexing. --- basic/code17.s | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index dfc51a11..db294e5b 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -30,14 +30,14 @@ val1 ldx txtptr bcc val2 inx val2 stx strng2+1 - lda (strng2),y ;replace character after string with $00 (fake eol) + lda (strng2) ;replace character after string with $00 (fake eol) pha lda #0 - sta (strng2),y + sta (strng2) jsr chrgot jsr finh ;go do evaluation pla ;get pres'd character. - sta (strng2),y ;restore zeroed-out character + sta (strng2) ;restore zeroed-out character st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr From fd74caa1911e18c33dbb965a2efa6e218db86a2e Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Tue, 3 Sep 2024 13:52:32 +0300 Subject: [PATCH 3/7] Almost fixed the 1E39 bug. --- basic/code17.s | 45 +++++++++++++++++++++++---------------------- cfg/x16.cfginc | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index db294e5b..57565abb 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -5,6 +5,9 @@ conint jsr posint ldx faclo jmp chrgot +len2 .res 1 +val_strptr .res 2 + ; 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 @@ -12,37 +15,35 @@ conint jsr posint val jsr len1 ;get length val_str bne val1 ;return 0 if len=0 jmp zerofc -val1 ldx txtptr +val1 lda len1 + clc + adc #1 + sta len2 + jsr val_alloc + ldx txtptr ldy txtptr+1 - stx strng2 - sty strng2+1 - ldx index1 + ldx #0 +val2 lda (txtptr),y + sta val_strptr + iny + dex + bne val2 + lda #0 + sta val_strptr + ldx val_strptr stx txtptr - lda index1 ;load the low byte of index1 - clc - adc len1 ;add len to index1 and put in strng2 - sta strng2 - lda index1+1 ;load the high byte of index1 - adc #0 - sta strng2+1 ;store result in high byte of strng2 - ldx index1+1 + ldx val_strptr+1 stx txtptr+1 - bcc val2 - inx -val2 stx strng2+1 - lda (strng2) ;replace character after string with $00 (fake eol) - pha - lda #0 - sta (strng2) jsr chrgot - jsr finh ;go do evaluation - pla ;get pres'd character. - sta (strng2) ;restore zeroed-out character + jsr finh st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr sty txtptr+1 valrts rts ;done! +val_alloc lda len2 + jsr strspa + rts getnum jsr frmadr combyt jsr chkcom jmp getbyt diff --git a/cfg/x16.cfginc b/cfg/x16.cfginc index 2aaa0763..5ce819d0 100644 --- a/cfg/x16.cfginc +++ b/cfg/x16.cfginc @@ -18,7 +18,7 @@ ZPDOS: start = $0091, size = $000B; # DOS /* start = $009C, size = $000B; # reserved for DOS or BASIC growth */ ZPAUDIO: start = $00A7, size = $0002; # AUDIO ZPMATH: start = $00A9, size = $002B; # MATH -ZPBASIC: start = $00D4, size = $002B; # BASIC (last byte used: $FE) +ZPBASIC: start = $00D4, size = $002E; # BASIC (last byte used: $FE) /* $0200-$02FF: always-available variables and RAM code */ KVAR: start = $0200, size = $0095; # KERNAL From 324b97762ba9baf7cd0cce32a4839107bc2b3fbf Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Wed, 4 Sep 2024 11:29:42 +0300 Subject: [PATCH 4/7] [BASIC] Fix 1E39 bug from C64. --- basic/code17.s | 63 +++++++++++++++++++++++++++++++------------------- cfg/x16.cfginc | 2 +- 2 files changed, 40 insertions(+), 25 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index 57565abb..b6bcafcc 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -5,45 +5,60 @@ conint jsr posint ldx faclo jmp chrgot -len2 .res 1 -val_strptr .res 2 - ; 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 val1 ;return 0 if len=0 +val jsr len1 ;get length +val_str bne @1 ;return 0 if len=0 jmp zerofc -val1 lda len1 - clc - adc #1 - sta len2 - jsr val_alloc - ldx txtptr +@1: cmp #254 ;check if string is =>255 chars (including null) + bne zerofc ;yes, return 0 + ldx txtptr ;save current txtptr ldy txtptr+1 - ldx #0 -val2 lda (txtptr),y - sta val_strptr + phy + phx + stx index2+1 + ldx index1 ;save current index1 + ldy index1+1 + phy + phx + pha + inc + 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 val2 - lda #0 - sta val_strptr - ldx val_strptr - stx txtptr - ldx val_strptr+1 - stx txtptr+1 + 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 + plx ;restore saved txtptr + ply + stx txtptr + sty txtptr+1 + plx ;restore saved index1 + ply + stx index1 + sty index1+1 + rts ;done! st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr sty txtptr+1 valrts rts ;done! -val_alloc lda len2 - jsr strspa - rts getnum jsr frmadr combyt jsr chkcom jmp getbyt diff --git a/cfg/x16.cfginc b/cfg/x16.cfginc index 5ce819d0..2aaa0763 100644 --- a/cfg/x16.cfginc +++ b/cfg/x16.cfginc @@ -18,7 +18,7 @@ ZPDOS: start = $0091, size = $000B; # DOS /* start = $009C, size = $000B; # reserved for DOS or BASIC growth */ ZPAUDIO: start = $00A7, size = $0002; # AUDIO ZPMATH: start = $00A9, size = $002B; # MATH -ZPBASIC: start = $00D4, size = $002E; # BASIC (last byte used: $FE) +ZPBASIC: start = $00D4, size = $002B; # BASIC (last byte used: $FE) /* $0200-$02FF: always-available variables and RAM code */ KVAR: start = $0200, size = $0095; # KERNAL From fc30470aa1928e8ff9855f253d4bee6951f7906b Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Wed, 4 Sep 2024 11:33:57 +0300 Subject: [PATCH 5/7] [BASIC] Fix 1E39 bug. --- basic/code17.s | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index b6bcafcc..1a80366d 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -13,7 +13,7 @@ val jsr len1 ;get length val_str bne @1 ;return 0 if len=0 jmp zerofc @1: cmp #254 ;check if string is =>255 chars (including null) - bne zerofc ;yes, return 0 + bne val_strlong ;yes, return 0 ldx txtptr ;save current txtptr ldy txtptr+1 phy @@ -53,12 +53,13 @@ val_str bne @1 ;return 0 if len=0 ply stx index1 sty index1+1 - rts ;done! -st2txt ldx strng2 ;restore text pointer + rts ;done! +st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr sty txtptr+1 -valrts rts ;done! +valrts rts ;done! +val_strlong jmp zerofc getnum jsr frmadr combyt jsr chkcom jmp getbyt From 4ad006ca05097c74caaed98592a6f5d32f015434 Mon Sep 17 00:00:00 2001 From: Stefanos Stefanidis Date: Thu, 5 Sep 2024 10:40:08 +0300 Subject: [PATCH 6/7] [BASIC] Fix 1E39 bug. --- basic/code17.s | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/basic/code17.s b/basic/code17.s index 1a80366d..60c440b1 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -12,9 +12,7 @@ conint jsr posint val jsr len1 ;get length val_str bne @1 ;return 0 if len=0 jmp zerofc -@1: cmp #254 ;check if string is =>255 chars (including null) - bne val_strlong ;yes, return 0 - ldx txtptr ;save current txtptr +@1: ldx txtptr ;save current txtptr ldy txtptr+1 phy phx @@ -25,6 +23,7 @@ val_str bne @1 ;return 0 if len=0 phx pha 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 @@ -49,17 +48,14 @@ val_str bne @1 ;return 0 if len=0 ply stx txtptr sty txtptr+1 - plx ;restore saved index1 - ply - stx index1 - sty index1+1 rts ;done! st2txt ldx strng2 ;restore text pointer ldy strng2+1 stx txtptr sty txtptr+1 valrts rts ;done! -val_strlong jmp zerofc +val_strlong ldx #errls + jmp error getnum jsr frmadr combyt jsr chkcom jmp getbyt From 605b1f7120303ef0153a2a1b224cb78436a0237b Mon Sep 17 00:00:00 2001 From: mooinglemur Date: Tue, 10 Sep 2024 19:41:07 -0700 Subject: [PATCH 7/7] remove superfluous store to index2 --- basic/code17.s | 1 - 1 file changed, 1 deletion(-) diff --git a/basic/code17.s b/basic/code17.s index 60c440b1..3df682bb 100644 --- a/basic/code17.s +++ b/basic/code17.s @@ -16,7 +16,6 @@ val_str bne @1 ;return 0 if len=0 ldy txtptr+1 phy phx - stx index2+1 ldx index1 ;save current index1 ldy index1+1 phy