fix floats.parse_f() to use new kernal routine address for VAL

gives error message if it detects issues f.ex. with new kernal version that moves the routine
This commit is contained in:
Irmen de Jong 2023-11-27 23:58:28 +01:00
parent ae2d96c455
commit ee4da1a757
4 changed files with 22 additions and 39 deletions

View File

@ -139,13 +139,27 @@ asmsub FREADUY (ubyte value @Y) {
asmsub parse_f(str value @AY) -> float @FAC1 {
; -- parse a string value of a number to float in FAC1
; warning: uses an internal BASIC routine that may be rom version dependent
; ($ddf2 is inside the routine for VAL at $ddef)
; ($deb6 is inside the routine for VAL at $deb3) See basic.sym from x16-rom
; If at any time in the future the official VAL_1() routine from the kernal starts working, we should use that instead!
%asm {{
sta $a9
sty $aa
jsr prog8_lib.strlen
lda $deb6
cmp #$d0 ; sanity check for kernal routine correct
bne + ;
tya
jmp $ddf2
jmp $deb6 ; kernal version dependent :(
+ ; print error message if routine is borked in kernal, and exit program
ldy #0
- lda _msg,y
beq +
jsr cbm.CHROUT
iny
bne -
+ jmp sys.exit
_msg .text 13,"?val kaputt",13,0
}}
}

View File

@ -1458,7 +1458,7 @@ save_SCRATCH_ZPWORD2 .word 0
}}
}
inline asmsub exit(ubyte returnvalue @A) {
asmsub exit(ubyte returnvalue @A) {
; -- immediately exit the program with a return code in the A register
%asm {{
jsr cbm.CLRCHN ; reset i/o channels

View File

@ -2,10 +2,6 @@
TODO
====
- fix floats.parse_f - did the routine move in kernal rom?
VAL at $ddef. Looks like it's now $deb3 (see basic.sym from x16-rom)
so assuming its internals hasen't changed you need to change the $ddf2 to $deb6?
- [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....
...

View File

@ -4,39 +4,12 @@
main {
sub start() {
ubyte[100] storage = 0
txt.print("sizeof float = ")
txt.print_ub(sizeof(0.0))
txt.print("\nsizeof word = ")
txt.print_ub(sizeof($0000))
txt.print("\nsizeof byte = ")
txt.print_ub(sizeof($00))
txt.print("\nsizeof bool = ")
txt.print_ub(sizeof(true))
txt.print("enter number: ")
str buffer = "???????????????????????????"
void txt.input_chars(buffer)
float value = floats.parse_f(buffer)
txt.nl()
poke(&storage+10, 123)
pokew(&storage+11, 54321)
txt.print_ub(peek(&storage+10))
txt.spc()
txt.print_uw(peekw(&storage+11))
txt.nl()
pokef(&storage+10, 3.14)
pokef($4000, 123.456)
floats.print_f(peekf(&storage+10))
txt.nl()
floats.print_f(peekf($4000))
txt.nl()
pokef(&storage+10, 3.1415927)
floats.print_f(peekf(&storage+10))
txt.nl()
for cx16.r2L in 0 to 20 {
txt.print_ubhex(storage[cx16.r2L], false)
txt.spc()
}
floats.print_f(value)
txt.nl()
}
}