accumulated fixes in 2.22p5

This commit is contained in:
Klaus2m5 2020-01-13 14:33:59 +01:00
parent d9f570859a
commit be931e5040
2 changed files with 146 additions and 30 deletions

View File

@ -414,3 +414,19 @@ LAB_174D
LAB_no_ELSE
JMP LAB_15C2 ; return to the interpreter inner loop
; *** end patch allow NEXT, LOOP & RETURN to find FOR, DO or GOSUB structure on stack
11. Additional bugs brought up by users Ruud and dclxvi of the 6502.org forum
See http://forum.6502.org/viewtopic.php?f=5&t=5500
sanity check for RAM top allows values below RAM base
http://forum.6502.org/viewtopic.php?f=5&t=5606
#1 TO expression with a subtract may evaluate with the sign bit flipped
#3 call to LAB_1B5B may return to an address -$100 (page not incremented)
#4 string concatenate followed by MINUS or NOT() crashes EhBASIC
#5 garbage collection may cause an overlap with temporary strings
#6 floating point multiply rounding bug
#7 VAL() may cause string variables to be trashed
All above have been fixed in 2.22p5. See the thread for additional quirks.

View File

@ -1,5 +1,5 @@
; Enhanced BASIC to assemble under 6502 simulator, $ver 2.22p4
; Enhanced BASIC to assemble under 6502 simulator, $ver 2.22p5
; $E7E1 $E7CF $E7C6 $E7D3 $E7D1 $E7D5 $E7CF $E81E $E825
@ -29,6 +29,17 @@
; is > 0 and < 1E-16
; added additional stack floor protection for background interrupts
; fixed conditional LOOP & NEXT cannot find their data strucure on stack
; 2.22p5 fixes issues reported by users Ruud and dclxvi on the 6502.org forum
; 5.0 http://forum.6502.org/viewtopic.php?f=5&t=5500
; sanity check for RAM top allows values below RAM base
; 5.1-7 http://forum.6502.org/viewtopic.php?f=5&t=5606
; 1-7 coresponds to the bug# in the thread
; 5.1 TO expression with a subtract may evaluate with the sign bit flipped
; 5.3 call to LAB_1B5B may return to an address -$100 (page not incremented)
; 5.4 string concatenate followed by MINUS or NOT() crashes EhBASIC
; 5.5 garbage collection may cause an overlap with temporary strings
; 5.6 floating point multiply rounding bug
; 5.7 VAL() may cause string variables to be trashed
; zero page use ..
@ -567,7 +578,12 @@ LAB_2DAA
LAB_2DB6
LDA Itempl ; get temporary integer low byte
LDY Itemph ; get temporary integer high byte
CPY #<Ram_base+1 ; compare with start of RAM+$100 high byte
; *** begin patch 2.22p5.0 RAM top sanity check ***
; *** replace
; CPY #<Ram_base+1 ; compare with start of RAM+$100 high byte
; +++ with
CPY #>Ram_base+1 ; compare with start of RAM+$100 high byte
; *** end patch 2.22p5.0 ***
BCC LAB_GMEM ; if too small go try again
@ -1494,6 +1510,10 @@ LAB_FOR
JSR LAB_CTNM ; check if source is numeric, else do type mismatch
JSR LAB_EVNM ; evaluate expression and check is numeric,
; else do type mismatch
; *** begin patch 2.22p5.1 TO expression may get sign bit flipped
; *** add
JSR LAB_27BA ; round FAC1
; *** end patch 2.22p5.1 TO expression may get sign bit flipped
LDA FAC1_s ; get FAC1 sign (b7)
ORA #$7F ; set all non sign bits
AND FAC1_1 ; and FAC1 mantissa1
@ -1525,6 +1545,13 @@ LAB_15B3
; here (+/-1) is then compared to that result and if they
; are the same (+ve and FOR > TO or -ve and FOR < TO) then
; the loop is done
; *** begin patch 2.22p5.3 potential return address -$100 (page not incremented) ***
; *** add
.IF [* & $FF] == $FD
NOP ; return address of JSR +1 (on next page)
.ENDIF
; *** end patch 2.22p5.3 potential return address -$100 (page not incremented) ***
JSR LAB_1B5B ; push sign, round FAC1 and put on stack
LDA Frnxth ; get var pointer for FOR/NEXT high byte
PHA ; push on stack
@ -3073,6 +3100,12 @@ LAB_1B43
LDA LAB_OPPT+1,Y ; get function vector low byte
PHA ; onto stack
; now push sign, round FAC1 and put on stack
; *** begin patch 2.22p5.3 potential return address -$100 (page not incremented) ***
; *** add
.IF [* & $FF] == $FD
NOP ; return address of JSR +1 (on next page)
.ENDIF
; *** end patch 2.22p5.3 potential return address -$100 (page not incremented) ***
JSR LAB_1B5B ; function will return here, then the next RTS will call
; the function
LDA comp_f ; get compare function flag
@ -3099,8 +3132,14 @@ LAB_1B5B
; round FAC1 and put on stack
LAB_1B66
; *** begin patch 2.22p5.1 TO expression may get sign bit flipped
; *** replace
;LAB_1B66
; JSR LAB_27BA ; round FAC1
; *** with
JSR LAB_27BA ; round FAC1
LAB_1B66
; *** end patch 2.22p5.1 TO expression may get sign bit flipped
LDA FAC1_3 ; get FAC1 mantissa3
PHA ; push on stack
LDA FAC1_2 ; get FAC1 mantissa2
@ -3293,8 +3332,22 @@ TK_GT_PLUS = TK_GT-TK_PLUS
LDY #TK_GT_PLUS*3 ; set offset from base to > operator
LAB_1C13
PLA ; dump return address low byte
; *** begin patch 2.22p5.4 concatenate MINUS or NOT() crashes EhBASIC ***
; *** replace
; PLA ; dump return address high byte
; JMP LAB_1B1D ; execute function then continue evaluation
; *** with
TAX ; save to trap concatenate
PLA ; dump return address high byte
CPX #<[LAB_224Da+2] ; from concatenate low return address?
BNE LAB_1C13b ; No - continue!
CMP #>[LAB_224Da+2] ; from concatenate high return address?
BEQ LAB_1C13a ; Yes - error!
LAB_1C13b
JMP LAB_1B1D ; execute function then continue evaluation
LAB_1C13a
JMP LAB_1ABC ; throw "type mismatch error" then warm start
; *** end patch 2.22p5.4 concatenate MINUS or NOT() crashes EhBASIC ***
; variable name set-up
; get (var), return value in FAC_1 and $ flag
@ -4581,6 +4634,10 @@ LAB_214B
STA Sstorh ; set string storage high byte
LDY #$00 ; clear index
STY garb_h ; clear working pointer high byte (flag no strings to move)
; *** begin patch 2.22p5.5 garbage collection may overlap temporary strings
; *** add
STY garb_l ; clear working pointer low byte (flag no strings to move)
; *** begin patch 2.22p5.5 garbage collection may overlap temporary strings
LDA Earryl ; get array mem end low byte
LDX Earryh ; get array mem end high byte
STA Histrl ; save as highest string low byte
@ -4734,7 +4791,13 @@ LAB_2211
LAB_2216
DEC g_step ; decrement step size (now $03 for descriptor stack)
LDX garb_h ; get string to move high byte
; *** begin patch 2.22p5.5 garbage collection may overlap temporary strings
; *** replace
; LDX garb_h ; get string to move high byte
; *** with
LDA garb_h ; any string to move?
ORA garb_l
; *** end patch 2.22p5.5 garbage collection may overlap temporary strings
BEQ LAB_2211 ; exit if nothing to move
LDY g_indx ; get index byte back (points to descriptor)
@ -4770,6 +4833,10 @@ LAB_224D
PHA ; put on stack
LDA des_pl ; get descriptor pointer low byte
PHA ; put on stack
; *** begin patch 2.22p5.4 concatenate MINUS or NOT() crashes EhBASIC ***
; *** add extra label to verify originating function
LAB_224Da
; *** end patch 2.22p5.4 concatenate MINUS or NOT() crashes EhBASIC ***
JSR LAB_GVAL ; get value from line
JSR LAB_CTST ; check if source is string, else do type mismatch
PLA ; get descriptor pointer low byte back
@ -5185,29 +5252,52 @@ LAB_VAL
JMP LAB_24F1 ; clear FAC1 exponent and sign and return
LAB_23C5
LDX Bpntrl ; get BASIC execute pointer low byte
LDY Bpntrh ; get BASIC execute pointer high byte
STX Btmpl ; save BASIC execute pointer low byte
STY Btmph ; save BASIC execute pointer high byte
LDX ut1_pl ; get string pointer low byte
STX Bpntrl ; save as BASIC execute pointer low byte
CLC ; clear carry
ADC ut1_pl ; add string length
STA ut2_pl ; save string end low byte
LDA ut1_ph ; get string pointer high byte
STA Bpntrh ; save as BASIC execute pointer high byte
ADC #$00 ; add carry to high byte
STA ut2_ph ; save string end high byte
LDY #$00 ; set index to $00
LDA (ut2_pl),Y ; get string end +1 byte
PHA ; push it
TYA ; clear A
STA (ut2_pl),Y ; terminate string with $00
; *** begin patch 2.22p5.7 VAL() may cause string variables to be trashed
; *** replace
; LDX Bpntrl ; get BASIC execute pointer low byte
; LDY Bpntrh ; get BASIC execute pointer high byte
; STX Btmpl ; save BASIC execute pointer low byte
; STY Btmph ; save BASIC execute pointer high byte
; LDX ut1_pl ; get string pointer low byte
; STX Bpntrl ; save as BASIC execute pointer low byte
; CLC ; clear carry
; ADC ut1_pl ; add string length
; STA ut2_pl ; save string end low byte
; LDA ut1_ph ; get string pointer high byte
; STA Bpntrh ; save as BASIC execute pointer high byte
; ADC #$00 ; add carry to high byte
; STA ut2_ph ; save string end high byte
; LDY #$00 ; set index to $00
; LDA (ut2_pl),Y ; get string end +1 byte
; PHA ; push it
; TYA ; clear A
; STA (ut2_pl),Y ; terminate string with $00
; JSR LAB_GBYT ; scan memory
; JSR LAB_2887 ; get FAC1 from string
; PLA ; restore string end +1 byte
; LDY #$00 ; set index to zero
; STA (ut2_pl),Y ; put string end byte back
; *** with
PHA ; save length
INY ; string length +1
TYA
JSR LAB_MSSP ; allocate temp string +1 bytes long
PLA ; get length back
JSR LAB_229C ; copy string (ut1_pl) -> (Sutill) for A bytes
LDA #0 ; add delimiter to end of string
TAY
STA (Sutill),Y
LDX Bpntrl ; save BASIC execute pointer low byte
LDY Bpntrh
STX Btmpl
STY Btmph
LDX str_pl ; point to temporary string
LDY str_ph
STX Bpntrl
STY Bpntrh
JSR LAB_GBYT ; scan memory
JSR LAB_2887 ; get FAC1 from string
PLA ; restore string end +1 byte
LDY #$00 ; set index to zero
STA (ut2_pl),Y ; put string end byte back
; *** end patch 2.22p5.7 VAL() may cause string variables to be trashed
; restore BASIC execute pointer from temp (Btmpl/Btmph)
@ -5762,13 +5852,23 @@ LAB_MULTIPLY
LAB_2622
BNE LAB_2627 ; branch if byte <> zero
JMP LAB_2569 ; shift FCAtemp << A+8 times
; *** begin patch 2.22p5.6 floating point multiply rounding bug
; *** replace
; JMP LAB_2569 ; shift FCAtemp << A+8 times
;
; ; else do shift and add
;LAB_2627
; LSR ; shift byte
; ORA #$80 ; set top bit (mark for 8 times)
; *** with
SEC
JMP LAB_2569 ; shift FACtemp << A+8 times
; else do shift and add
LAB_2627
LSR ; shift byte
ORA #$80 ; set top bit (mark for 8 times)
SEC ; set top bit (mark for 8 times)
ROR
; *** end patch 2.22p5.6 floating point multiply rounding bug
LAB_262A
TAY ; copy result
BCC LAB_2640 ; skip next if bit was zero
@ -7897,7 +7997,7 @@ LAB_MSZM
LAB_SMSG
.byte " Bytes free",$0D,$0A,$0A
.byte "Enhanced BASIC 2.22p4",$0A,$00
.byte "Enhanced BASIC 2.22p5",$0A,$00
; numeric constants and series