From e35cfd497158eae9f6f4d96c0407702aee3ddc5f Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 29 Dec 2023 03:12:44 +0100 Subject: [PATCH] get rid of the redundant 'f' suffix of several funtions in floats module (breaking change!) Unfortunately a few routines (minf, maxf, clampf) remain unchanged, because removing the 'f' would make them clash with a builtin function. floats.rndf -> floats.rnd floats.parse_f -> floats.parse floats.rndseedf -> floats.rndseed floats.print_f -> floats.print floats.str_f -> floats.tostr --- compiler/res/prog8lib/c64/floats.p8 | 6 ++--- compiler/res/prog8lib/cx16/floats.p8 | 4 ++-- compiler/res/prog8lib/floats_functions.p8 | 8 +++---- compiler/res/prog8lib/virtual/floats.p8 | 22 +++++++++---------- compiler/test/TestTypecasts.kt | 2 +- compiler/test/arithmetic/builtins.p8 | 2 +- compiler/test/arithmetic/div.p8 | 6 ++--- compiler/test/arithmetic/minus.p8 | 6 ++--- compiler/test/arithmetic/mult.p8 | 6 ++--- compiler/test/arithmetic/plus.p8 | 6 ++--- compiler/test/arithmetic/postincrdecr.p8 | 4 ++-- compiler/test/comparisons/more_compares.p8 | 12 +++++----- .../test/comparisons/optimized_compares.p8 | 12 +++++----- docs/source/libraries.rst | 10 ++++----- docs/source/todo.rst | 7 +++++- examples/bench8/crc16.p8 | 5 +++-- examples/bench8/crc32.p8 | 3 ++- examples/bench8/crc8.p8 | 5 +++-- examples/bench8/pow.p8 | 4 ++-- examples/bench8/sieve-bit.p8 | 4 ++-- examples/bench8/sieve.p8 | 4 ++-- examples/cx16/diskspeed.p8 | 2 +- examples/cx16/floatparse.p8 | 6 ++--- examples/cx16/mandelbrot.p8 | 2 +- examples/cx16/pcmaudio/play-adpcm.p8 | 2 +- examples/mandelbrot.p8 | 2 +- 26 files changed, 80 insertions(+), 72 deletions(-) diff --git a/compiler/res/prog8lib/c64/floats.p8 b/compiler/res/prog8lib/c64/floats.p8 index 7a8514679..d5682e385 100644 --- a/compiler/res/prog8lib/c64/floats.p8 +++ b/compiler/res/prog8lib/c64/floats.p8 @@ -45,7 +45,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. Also see parse_f() +romsub $b7b5 = FREADSTR(ubyte length @ A) clobbers(A,X,Y) ; str -> fac1, $22/23 must point to string, A=string length. Also see parse() 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) @@ -157,7 +157,7 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY { &uword AYINT_facmo = $64 ; $64/$65 contain result of AYINT -sub rndf() -> float { +sub rnd() -> float { %asm {{ lda #1 jsr FREADSA @@ -165,7 +165,7 @@ sub rndf() -> float { }} } -asmsub parse_f(str value @AY) -> float @FAC1 { +asmsub parse(str value @AY) -> float @FAC1 { %asm {{ sta $22 sty $23 diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index 5e764d517..2eabdad2d 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -135,7 +135,7 @@ asmsub FREADUY (ubyte value @Y) { }} } -asmsub parse_f(str value @AY) -> float @FAC1 { +asmsub parse(str value @AY) -> float @FAC1 { ; -- parse a string value of a number to float in FAC1 ; warning: on older float { +sub rnd() -> float { %asm {{ lda #1 jmp RND_0 diff --git a/compiler/res/prog8lib/floats_functions.p8 b/compiler/res/prog8lib/floats_functions.p8 index d9d877c0c..6af57c04a 100644 --- a/compiler/res/prog8lib/floats_functions.p8 +++ b/compiler/res/prog8lib/floats_functions.p8 @@ -2,10 +2,10 @@ floats { ; the floating point functions shared across compiler targets %option merge, no_symbol_prefixing, ignore_unused -asmsub print_f(float value @FAC1) clobbers(A,X,Y) { +asmsub print(float value @FAC1) clobbers(A,X,Y) { ; ---- prints the floating point value (without a newline). No leading space (unlike BASIC)! %asm {{ - jsr str_f + jsr tostr ldy #0 - lda (P8ZP_SCRATCH_W1),y beq + @@ -16,7 +16,7 @@ asmsub print_f(float value @FAC1) clobbers(A,X,Y) { }} } -asmsub str_f(float value @FAC1) clobbers(X) -> str @AY { +asmsub tostr(float value @FAC1) clobbers(X) -> str @AY { ; ---- converts the floating point value to a string. No leading space! %asm {{ jsr FOUT @@ -179,7 +179,7 @@ sub ceil(float value) -> float { }} } -sub rndseedf(float seed) { +sub rndseed(float seed) { if seed>0 seed = -seed ; make sure fp seed is always negative diff --git a/compiler/res/prog8lib/virtual/floats.p8 b/compiler/res/prog8lib/virtual/floats.p8 index b7acbf724..b74c30c9f 100644 --- a/compiler/res/prog8lib/virtual/floats.p8 +++ b/compiler/res/prog8lib/virtual/floats.p8 @@ -9,31 +9,31 @@ floats { const float TWOPI = 2*π -sub print_f(float value) { +sub print(float value) { ; ---- prints the floating point value (without a newline and no leading spaces). %ir {{ - loadm.f fr65535,floats.print_f.value + loadm.f fr65535,floats.print.value syscall 25 (fr65535.f) return }} } -sub str_f(float value) -> str { +sub tostr(float value) -> str { ; ---- converts the floating point value to a string (no leading spaces) str @shared buffer=" "*20 %ir {{ - load.w r65535,floats.str_f.buffer - loadm.f fr65535,floats.str_f.value + load.w r65535,floats.tostr.buffer + loadm.f fr65535,floats.tostr.value syscall 47 (r65535.w, fr65535.f) - load.w r0,floats.str_f.buffer + load.w r0,floats.tostr.buffer returnr.w r0 }} } -sub parse_f(str value) -> float { +sub parse(str value) -> float { ; -- parse a string value of a number to float %ir {{ - loadm.w r65535,floats.parse_f.value + loadm.w r65535,floats.parse.value syscall 45 (r65535.w): fr0.f returnr.f fr0 }} @@ -131,16 +131,16 @@ sub ceil(float value) -> float { }} } -sub rndf() -> float { +sub rnd() -> float { %ir {{ syscall 35 () : fr0.f returnr.f fr0 }} } -sub rndseedf(float seed) { +sub rndseed(float seed) { %ir {{ - loadm.f fr65535,floats.rndseedf.seed + loadm.f fr65535,floats.rndseed.seed syscall 32 (fr65535.f) return }} diff --git a/compiler/test/TestTypecasts.kt b/compiler/test/TestTypecasts.kt index fa3508beb..52e5fa844 100644 --- a/compiler/test/TestTypecasts.kt +++ b/compiler/test/TestTypecasts.kt @@ -27,7 +27,7 @@ class TestTypecasts: FunSpec({ main { sub start() { float fl - floats.print_f(lsb(fl)) + floats.print(lsb(fl)) } }""" val errors = ErrorReporterForTests() diff --git a/compiler/test/arithmetic/builtins.p8 b/compiler/test/arithmetic/builtins.p8 index 57c55e11b..e01c48cdf 100644 --- a/compiler/test/arithmetic/builtins.p8 +++ b/compiler/test/arithmetic/builtins.p8 @@ -460,7 +460,7 @@ main { reverse(flarr) for ub in 0 to len(flarr)-1 { - floats.print_f(flarr[ub]) + floats.print(flarr[ub]) txt.chrout(',') } txt.nl() diff --git a/compiler/test/arithmetic/div.p8 b/compiler/test/arithmetic/div.p8 index 6478d415f..57480a948 100644 --- a/compiler/test/arithmetic/div.p8 +++ b/compiler/test/arithmetic/div.p8 @@ -93,11 +93,11 @@ main { txt.print("err! ") txt.print("float ") - floats.print_f(a1) + floats.print(a1) txt.print(" / ") - floats.print_f(a2) + floats.print(a2) txt.print(" = ") - floats.print_f(r) + floats.print(r) cbm.CHROUT('\n') } } diff --git a/compiler/test/arithmetic/minus.p8 b/compiler/test/arithmetic/minus.p8 index 8bcf82b70..4297f5424 100644 --- a/compiler/test/arithmetic/minus.p8 +++ b/compiler/test/arithmetic/minus.p8 @@ -105,11 +105,11 @@ main { } txt.print(" float ") - floats.print_f(a1) + floats.print(a1) txt.print(" - ") - floats.print_f(a2) + floats.print(a2) txt.print(" = ") - floats.print_f(r) + floats.print(r) cbm.CHROUT('\n') } } diff --git a/compiler/test/arithmetic/mult.p8 b/compiler/test/arithmetic/mult.p8 index b3d025a03..4aba25aef 100644 --- a/compiler/test/arithmetic/mult.p8 +++ b/compiler/test/arithmetic/mult.p8 @@ -95,11 +95,11 @@ main { txt.print("err! ") txt.print("float ") - floats.print_f(a1) + floats.print(a1) txt.print(" * ") - floats.print_f(a2) + floats.print(a2) txt.print(" = ") - floats.print_f(r) + floats.print(r) cbm.CHROUT('\n') } } diff --git a/compiler/test/arithmetic/plus.p8 b/compiler/test/arithmetic/plus.p8 index e3addcf3f..0097641a2 100644 --- a/compiler/test/arithmetic/plus.p8 +++ b/compiler/test/arithmetic/plus.p8 @@ -99,11 +99,11 @@ main { txt.print("err! ") txt.print("float ") - floats.print_f(a1) + floats.print(a1) txt.print(" + ") - floats.print_f(a2) + floats.print(a2) txt.print(" = ") - floats.print_f(r) + floats.print(r) cbm.CHROUT('\n') } } diff --git a/compiler/test/arithmetic/postincrdecr.p8 b/compiler/test/arithmetic/postincrdecr.p8 index 4a07baca1..ae669f66c 100644 --- a/compiler/test/arithmetic/postincrdecr.p8 +++ b/compiler/test/arithmetic/postincrdecr.p8 @@ -132,9 +132,9 @@ main { else txt.print("err! ") txt.print(" float ") - floats.print_f(value) + floats.print(value) cbm.CHROUT(',') - floats.print_f(expected) + floats.print(expected) cbm.CHROUT('\n') } } diff --git a/compiler/test/comparisons/more_compares.p8 b/compiler/test/comparisons/more_compares.p8 index 0e293eb17..49d907918 100644 --- a/compiler/test/comparisons/more_compares.p8 +++ b/compiler/test/comparisons/more_compares.p8 @@ -296,12 +296,12 @@ main { txt.print(" 8000\n") f = 0.0 - floats.print_f(f) + floats.print(f) while f<2.2 { f+=0.1 - floats.print_f(f) + floats.print(f) } - floats.print_f(f) + floats.print(f) txt.print(" 2.2\n") } @@ -594,12 +594,12 @@ main { txt.print(" 8000\n") f = 0.0 - floats.print_f(f) + floats.print(f) while f=value(-19) + xx = b2>=svalue(-19) txt.print_ub(xx) txt.spc() - xx = b2>=value(-20) + xx = b2>=svalue(-20) txt.print_ub(xx) txt.spc() - xx = b2>=value(-21) + xx = b2>=svalue(-21) txt.print_ub(xx) txt.spc() @@ -323,13 +323,13 @@ main { txt.print_ub(xx) txt.spc() - xx = b2<=value(-19) + xx = b2<=svalue(-19) txt.print_ub(xx) txt.spc() - xx = b2<=value(-20) + xx = b2<=svalue(-20) txt.print_ub(xx) txt.spc() - xx = b2<=value(-21) + xx = b2<=svalue(-21) txt.print_ub(xx) txt.spc() diff --git a/docs/source/libraries.rst b/docs/source/libraries.rst index 9653b1661..ff439e2cc 100644 --- a/docs/source/libraries.rst +++ b/docs/source/libraries.rst @@ -360,11 +360,11 @@ point variables. This includes ``print_f``, the routine used to print floating ``clampf (value, minimum, maximum)`` returns the value restricted to the given minimum and maximum. -``print_f (x)`` +``print (x)`` Prints the floating point number x as a string. There's no leading whitespace (unlike cbm BASIC when printing a floating point number) -``str_f (x)`` +``tostr (x)`` Converts the floating point number x to a string (returns address of the string buffer) There's no leading whitespace. @@ -380,13 +380,13 @@ point variables. This includes ``print_f``, the routine used to print floating ``tan (x)`` Tangent. -``rndf ()`` +``rnd ()`` returns the next random float between 0.0 and 1.0 from the Pseudo RNG sequence. -``rndseedf (seed)`` +``rndseed (seed)`` Sets a new seed for the float pseudo-RNG sequence. Use a negative non-zero number as seed value. -``parse_f (stringvalue)`` +``parse (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. diff --git a/docs/source/todo.rst b/docs/source/todo.rst index f8ddf740f..d33c3fc21 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,6 +2,12 @@ TODO ==== +- fix "txy" and "tyx" non-existing instructions (assembler/experiment/* causes them to be used) +- fix a1%a2 being parsed as directive +- fix bitshift.p8 +- add crc8 and crc16 and crc32 to math +- fix crc* bench routines to no longer depend on the kernal rom version (use a bin file) + - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 .... ... @@ -48,7 +54,6 @@ Compiler: Libraries: -- get rid of the "f" suffix of several funtions in floats_functions (breaking change) - once a VAL_1 implementation is merged into the X16 kernal properly, remove all the workarounds in cx16 floats.parse_f() . Prototype parse routine in examples/cx16/floatparse.p8 - fix the problems in atari target, and flesh out its libraries. - c128 target: make syslib more complete (missing kernal routines)? diff --git a/examples/bench8/crc16.p8 b/examples/bench8/crc16.p8 index 87a7200bd..ab741e818 100644 --- a/examples/bench8/crc16.p8 +++ b/examples/bench8/crc16.p8 @@ -19,12 +19,13 @@ main { } sub start() { - txt.print("calculating (expecting $ffd0)...") + txt.print("calculating (expecting $ffd0)...\n") + txt.print(" if mismatch: first check if kernal is maybe updated?\n") cbm.SETTIM(0,0,0) uword crc = crc16($e000, $2000) txt.print_uwhex(crc, true) txt.nl() - floats.print_f(cbm.RDTIM16() / 60.0) + floats.print(cbm.RDTIM16() / 60.0) txt.print(" seconds") sys.wait(9999) } diff --git a/examples/bench8/crc32.p8 b/examples/bench8/crc32.p8 index a7d7ad20e..22ec8b854 100644 --- a/examples/bench8/crc32.p8 +++ b/examples/bench8/crc32.p8 @@ -31,12 +31,13 @@ main { sub start() { txt.print("calculating (expecting $e1fa84c6)...\n") + txt.print(" if mismatch: first check if kernal is maybe updated?\n") cbm.SETTIM(0,0,0) crc32($e000, $2000) txt.print_uwhex(cx16.r0, true) txt.print_uwhex(cx16.r1, false) txt.nl() - floats.print_f(cbm.RDTIM16() / 60.0) + floats.print(cbm.RDTIM16() / 60.0) txt.print(" seconds") sys.wait(9999) } diff --git a/examples/bench8/crc8.p8 b/examples/bench8/crc8.p8 index aaa64e4d1..73613d461 100644 --- a/examples/bench8/crc8.p8 +++ b/examples/bench8/crc8.p8 @@ -19,12 +19,13 @@ main { } sub start() { - txt.print("calculating (expecting $a2)...") + txt.print("calculating (expecting $a2)...\n") + txt.print(" if mismatch: first check if kernal is maybe updated?\n") cbm.SETTIM(0,0,0) ubyte crc = crc8($e000, $2000) txt.print_ubhex(crc, true) txt.nl() - floats.print_f(cbm.RDTIM16() / 60.0) + floats.print(cbm.RDTIM16() / 60.0) txt.print(" seconds") sys.wait(9999) } diff --git a/examples/bench8/pow.p8 b/examples/bench8/pow.p8 index 585407b2a..a992ce866 100644 --- a/examples/bench8/pow.p8 +++ b/examples/bench8/pow.p8 @@ -33,9 +33,9 @@ main { res += array[j] } - floats.print_f(res) + floats.print(res) txt.nl() - floats.print_f(cbm.RDTIM16() / 60.0) + floats.print(cbm.RDTIM16() / 60.0) txt.print(" seconds") sys.wait(9999) } diff --git a/examples/bench8/sieve-bit.p8 b/examples/bench8/sieve-bit.p8 index 27692dbd0..e45f32a87 100644 --- a/examples/bench8/sieve-bit.p8 +++ b/examples/bench8/sieve-bit.p8 @@ -22,9 +22,9 @@ main { txt.print(" primes\n") float time = cbm.RDTIM16() as float / 60.0 - floats.print_f(time) + floats.print(time) txt.print(" sec total = ") - floats.print_f(time/N_ITER) + floats.print(time/N_ITER) txt.print(" sec per iteration\n") sys.wait(9999) } diff --git a/examples/bench8/sieve.p8 b/examples/bench8/sieve.p8 index 31135ca48..0a5ba03e1 100644 --- a/examples/bench8/sieve.p8 +++ b/examples/bench8/sieve.p8 @@ -43,9 +43,9 @@ main { txt.print(" primes\n") float time = cbm.RDTIM16() as float / 60.0 - floats.print_f(time) + floats.print(time) txt.print(" sec total = ") - floats.print_f(time/ITERS) + floats.print(time/ITERS) txt.print(" sec per iteration\n") sys.wait(9999) } diff --git a/examples/cx16/diskspeed.p8 b/examples/cx16/diskspeed.p8 index be6ef0281..19a95376e 100644 --- a/examples/cx16/diskspeed.p8 +++ b/examples/cx16/diskspeed.p8 @@ -16,7 +16,7 @@ main { txt.nl() txt.print_uw(jiffies) txt.print(" jiffies = ") - floats.print_f(speed) + floats.print(speed) txt.print(" bytes/sec\n") } diff --git a/examples/cx16/floatparse.p8 b/examples/cx16/floatparse.p8 index e756f1d6a..9d9de291e 100644 --- a/examples/cx16/floatparse.p8 +++ b/examples/cx16/floatparse.p8 @@ -41,7 +41,7 @@ main { sub f(str string) { cbm.SETTIM(0,0,0) repeat 100 - float value1 = floats.parse_f(string) + float value1 = floats.parse(string) txt.print("1=") txt.print_uw(cbm.RDTIM16()) txt.spc() @@ -53,10 +53,10 @@ main { txt.print_uw(cbm.RDTIM16()) txt.nl() - floats.print_f(value1) + floats.print(value1) txt.spc() txt.spc() - floats.print_f(value2) + floats.print(value2) txt.nl() } diff --git a/examples/cx16/mandelbrot.p8 b/examples/cx16/mandelbrot.p8 index 78f02a87f..d9ab62780 100644 --- a/examples/cx16/mandelbrot.p8 +++ b/examples/cx16/mandelbrot.p8 @@ -41,7 +41,7 @@ main { float duration = (cbm.RDTIM16() as float) / 60 txt.print("\nfinished in ") - floats.print_f(duration) + floats.print(duration) txt.print(" seconds!\n") } } diff --git a/examples/cx16/pcmaudio/play-adpcm.p8 b/examples/cx16/pcmaudio/play-adpcm.p8 index c5f283a3c..64613494b 100644 --- a/examples/cx16/pcmaudio/play-adpcm.p8 +++ b/examples/cx16/pcmaudio/play-adpcm.p8 @@ -76,7 +76,7 @@ main { sub decoding_report(float pcm_words_per_block) { const float REFRESH_RATE = 25.0e6/(525.0*800) ; Vera VGA refresh rate is not precisely 60 hz! float duration_secs = (cbm.RDTIM16() as float) / REFRESH_RATE - floats.print_f(duration_secs) + floats.print(duration_secs) txt.print(" seconds (approx)\n") float src_per_second = adpcm_size as float / duration_secs txt.print_uw(src_per_second as uword) diff --git a/examples/mandelbrot.p8 b/examples/mandelbrot.p8 index f220c26f5..7e005f08f 100644 --- a/examples/mandelbrot.p8 +++ b/examples/mandelbrot.p8 @@ -43,7 +43,7 @@ main { float duration = (cbm.RDTIM16() as float) / 60 txt.plot(0, 21) txt.print("finished in ") - floats.print_f(duration) + floats.print(duration) txt.print(" seconds!\n") ; test_stack.test()