added floats.parse_f()

This commit is contained in:
Irmen de Jong 2023-08-16 14:47:20 +02:00
parent 66857ca477
commit 77f3852cdc
7 changed files with 50 additions and 43 deletions

View File

@ -1,24 +0,0 @@
<component name="libraryTable">
<library name="io.kotest.property.jvm" type="repository">
<properties maven-id="io.kotest:kotest-property-jvm:5.6.2" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/io/kotest/kotest-property-jvm/5.6.2/kotest-property-jvm-5.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/com/github/curious-odd-man/rgxgen/1.4/rgxgen-1.4.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.8.10/kotlin-stdlib-jdk8-1.8.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.8.10/kotlin-stdlib-1.8.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.8.10/kotlin-stdlib-jdk7-1.8.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/kotest/kotest-common-jvm/5.6.2/kotest-common-jvm-5.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/kotest/kotest-assertions-shared-jvm/5.6.2/kotest-assertions-shared-jvm-5.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/kotest/kotest-assertions-api-jvm/5.6.2/kotest-assertions-api-jvm-5.6.2.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlinx/kotlinx-coroutines-jdk8/1.7.0/kotlinx-coroutines-jdk8-1.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.8.10/kotlin-stdlib-common-1.8.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/io/github/java-diff-utils/java-diff-utils/4.12/java-diff-utils-4.12.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-reflect/1.8.10/kotlin-reflect-1.8.10.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlinx/kotlinx-coroutines-core-jvm/1.7.0/kotlinx-coroutines-core-jvm-1.7.0.jar!/" />
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/23.0.0/annotations-23.0.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -46,7 +46,7 @@ romsub $b391 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
romsub $b3a2 = FREADUY(ubyte value @ Y) clobbers(A,X,Y) ; 8 bit unsigned Y -> float in fac1
romsub $bc3c = FREADSA(byte value @ A) clobbers(A,X,Y) ; 8 bit signed A -> float in fac1
romsub $b7b5 = FREADSTR(ubyte length @ A) clobbers(A,X,Y) ; str -> fac1, $22/23 must point to string, A=string length
romsub $b7b5 = FREADSTR(ubyte length @ A) clobbers(A,X,Y) ; str -> fac1, $22/23 must point to string, A=string length. Also see parse_f()
romsub $aabc = FPRINTLN() clobbers(A,X,Y) ; print string of fac1, on one line (= with newline) destroys fac1. (consider FOUT + STROUT as well)
romsub $bddd = FOUT() clobbers(X) -> uword @ AY ; fac1 -> string, address returned in AY ($0100)
@ -165,6 +165,16 @@ sub rndf() -> float {
}}
}
asmsub parse_f(str value @AY) -> float @FAC1 {
%asm {{
sta $22
sty $23
jsr prog8_lib.strlen
tya
jmp FREADSTR
}}
}
%asminclude "library:c64/floats.asm"
%asminclude "library:c64/floats_funcs.asm"

View File

@ -28,7 +28,7 @@ romsub $fe00 = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101
romsub $fe03 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
romsub $fe06 = FOUT() clobbers(X) -> uword @ AY ; fac1 -> string, address returned in AY
; romsub $fe09 = VAL_1() clobbers(A,X,Y) ; convert ASCII string to floating point [not yet implemented!!!]
; romsub $fe09 = VAL_1() clobbers(A,X,Y) ; convert ASCII string to floating point [not yet implemented!!!] see parse_f() instead
; GETADR: fac1 -> unsigned word in Y/A (might throw ILLEGAL QUANTITY) (result also in $14/15)
; (tip: use GETADRAY to get A/Y output; lo/hi switched to normal little endian order)
@ -136,6 +136,19 @@ 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)
%asm {{
sta $a9
sty $aa
jsr prog8_lib.strlen
tya
jmp $ddf2
}}
}
&uword AYINT_facmo = $c6 ; $c6/$c7 contain result of AYINT

View File

@ -16,6 +16,15 @@ sub print_f(float value) {
}}
}
sub parse_f(str value) -> float {
; -- parse a string value of a number to float
%ir {{
loadm.w r65535,floats.parse_f.value
syscall 45 (r65535.w): fr0.f
returnr.f fr0
}}
}
sub pow(float value, float power) -> float {
%ir {{
loadm.f fr0,floats.pow.value

View File

@ -312,13 +312,10 @@ point variables. This includes ``print_f``, the routine used to print floating
``rndseedf (seed)``
Sets a new seed for the float pseudo-RNG sequence. Use a negative non-zero number as seed value.
.. attention::
A "parse" routine to convert a string into a floating point number is suspiciously absent.
This is because unfortunately there is no such routine available on each of the compiler targets.
Only the C64 target has the ``floats.FREADSTR()`` kernal routine that parses a string into a float into FAC1,
but the X16 has no equivalent in the kernal rom at this time.
The same is true for parsing an *integer* number however you can use the parse routines in the ``conv`` module as
a stepping stone to eventually load the number into FAC1 using one of the available kernal routines.
``parse_f (stringvalue)``
Parses the string value as floating point number.
Warning: this routine may stop working on the Commander X16 when a new ROM version is released,
because it uses an internal BASIC routine. Then it will require a fix.
graphics

View File

@ -1,16 +1,11 @@
%import textio
%import string
%import floats
%zeropage basicsafe
main {
sub start() {
ubyte value = 1
uword wvalue = 1
ubyte zero = 0
txt.print_ub(value<<zero) ; TODO fix result 6502 codegen! should be 1.
txt.print_uw(wvalue<<zero) ; TODO fix result 6502 codegen! should be 1.
ubyte value2 = value<<zero ; result is ok, 1
uword wvalue2 = wvalue<<zero ; result is ok, 1
txt.print_ub(value2)
txt.print_uw(wvalue2)
float fl = floats.parse_f("-123.45678e20")
floats.print_f(fl)
}
}

View File

@ -52,6 +52,7 @@ SYSCALLS:
42 = CLAMP_UWORD
43 = CLAMP_FLOAT
44 = ATAN
45 = STR_TO_FLOAT
*/
enum class Syscall {
@ -99,7 +100,8 @@ enum class Syscall {
CLAMP_WORD,
CLAMP_UWORD,
CLAMP_FLOAT,
ATAN
ATAN,
STR_TO_FLOAT
;
companion object {
@ -366,6 +368,11 @@ object SysCalls {
}
return returnValue(callspec.returns!!, value, vm)
}
Syscall.STR_TO_FLOAT -> {
val stringAddr = getArgValues(callspec.arguments, vm).single() as UShort
val memstring = vm.memory.getString(stringAddr.toInt())
returnValue(callspec.returns!!, memstring.toFloat(), vm)
}
Syscall.COMPARE_STRINGS -> {
val (firstV, secondV) = getArgValues(callspec.arguments, vm)
val firstAddr = firstV as UShort