mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 07:31:48 +00:00
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
This commit is contained in:
parent
bcc4bf5c2b
commit
e35cfd4971
@ -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
|
||||
|
@ -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 <R47 kernals it uses an internal BASIC routine that is ROM version dependent,
|
||||
; ($deb6 is inside the routine for VAL at $deb3) See basic.sym from x16-rom
|
||||
@ -175,7 +175,7 @@ _msg .text 13,"?val kaputt",13,0
|
||||
|
||||
&uword AYINT_facmo = $c6 ; $c6/$c7 contain result of AYINT
|
||||
|
||||
sub rndf() -> float {
|
||||
sub rnd() -> float {
|
||||
%asm {{
|
||||
lda #1
|
||||
jmp RND_0
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}}
|
||||
|
@ -27,7 +27,7 @@ class TestTypecasts: FunSpec({
|
||||
main {
|
||||
sub start() {
|
||||
float fl
|
||||
floats.print_f(lsb(fl))
|
||||
floats.print(lsb(fl))
|
||||
}
|
||||
}"""
|
||||
val errors = ErrorReporterForTests()
|
||||
|
@ -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()
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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')
|
||||
}
|
||||
}
|
||||
|
@ -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<twodottwo {
|
||||
f+=0.1
|
||||
floats.print_f(f)
|
||||
floats.print(f)
|
||||
}
|
||||
floats.print_f(f)
|
||||
floats.print(f)
|
||||
txt.print(" 2.2\n")
|
||||
}
|
||||
}
|
||||
|
@ -233,13 +233,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()
|
||||
|
||||
@ -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()
|
||||
|
||||
|
@ -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.
|
||||
|
@ -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)?
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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")
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
}
|
||||
|
||||
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user