mirror of
https://github.com/irmen/prog8.git
synced 2025-01-08 22:32:06 +00:00
added Linear Interpolation (LERP) functions: math.lerp(), floats.lerp(), floats.lerp_fast()
This commit is contained in:
parent
4a47e15b1c
commit
9005c7994a
@ -645,4 +645,12 @@ log2_tab
|
|||||||
cx16.r15 ^= $ffff
|
cx16.r15 ^= $ffff
|
||||||
cx16.r14 ^= $ffff
|
cx16.r14 ^= $ffff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub lerp(ubyte v0, ubyte v1, ubyte t) -> ubyte {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the interval [0, 255]
|
||||||
|
; guarantees v = v1 when t = 255
|
||||||
|
return v0 + msb(t as uword * (v1 - v0) + 255)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,4 +256,18 @@ inline asmsub pop() -> float @FAC1 {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub lerp(float v0, float v1, float t) -> float {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; Precise method, which guarantees v = v1 when t = 1.
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the closed unit interval [0, 1]
|
||||||
|
return (1 - t) * v0 + t * v1
|
||||||
|
}
|
||||||
|
|
||||||
|
sub lerp_fast(float v0, float v1, float t) -> float {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; Imprecise (but slightly faster) method, which does not guarantee v = v1 when t = 1
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the closed unit interval [0, 1]
|
||||||
|
return v0 + t * (v1 - v0)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -203,4 +203,18 @@ sub pop() -> float {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub lerp(float v0, float v1, float t) -> float {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; Precise method, which guarantees v = v1 when t = 1.
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the closed unit interval [0, 1]
|
||||||
|
return (1 - t) * v0 + t * v1
|
||||||
|
}
|
||||||
|
|
||||||
|
sub lerp_fast(float v0, float v1, float t) -> float {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; Imprecise (but slightly faster) method, which does not guarantee v = v1 when t = 1
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the closed unit interval [0, 1]
|
||||||
|
return v0 + t * (v1 - v0)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -398,4 +398,12 @@ math {
|
|||||||
cx16.r15 ^= $ffff
|
cx16.r15 ^= $ffff
|
||||||
cx16.r14 ^= $ffff
|
cx16.r14 ^= $ffff
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
sub lerp(ubyte v0, ubyte v1, ubyte t) -> ubyte {
|
||||||
|
; Linear interpolation (LERP)
|
||||||
|
; returns an interpolation between two inputs (v0, v1) for a parameter t in the interval [0, 255]
|
||||||
|
; guarantees v = v1 when t = 255
|
||||||
|
return v0 + msb(t as uword * (v1 - v0) + 255)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ replace zsound example by a zsmkit example
|
|||||||
contribute a short how-to to the zsmkit repo for building a suitable blob
|
contribute a short how-to to the zsmkit repo for building a suitable blob
|
||||||
write a howto for integrating third party library code like zsmkit and vtui
|
write a howto for integrating third party library code like zsmkit and vtui
|
||||||
|
|
||||||
|
can we make it so that math is not always included on 6502 target? (what does it need, move that to another library perhaps?)
|
||||||
|
|
||||||
|
|
||||||
Improve register load order in subroutine call args assignments:
|
Improve register load order in subroutine call args assignments:
|
||||||
in certain situations, the "wrong" order of evaluation of function call arguments is done which results
|
in certain situations, the "wrong" order of evaluation of function call arguments is done which results
|
||||||
in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!)
|
in overwriting registers that already got their value, which requires a lot of stack juggling (especially on plain 6502 cpu!)
|
||||||
|
@ -1,60 +1,20 @@
|
|||||||
|
%import math
|
||||||
%import textio
|
%import textio
|
||||||
%import diskio
|
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
txt.print_ub(exists_byte("test.prg"))
|
ubyte v1 = 100
|
||||||
txt.spc()
|
ubyte v2 = 200
|
||||||
txt.print_ub(exists_byte("doesntexist.xxx"))
|
|
||||||
txt.nl()
|
|
||||||
txt.print_bool(exists_bool("test.prg"))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_bool(exists_bool("doesntexist.xxx"))
|
|
||||||
txt.nl()
|
|
||||||
txt.print_bool(exists1("test.prg"))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_bool(exists1("doesntexist.xxx"))
|
|
||||||
txt.nl()
|
|
||||||
txt.print_bool(exists2("test.prg"))
|
|
||||||
txt.spc()
|
|
||||||
txt.print_bool(exists2("doesntexist.xxx"))
|
|
||||||
txt.nl()
|
|
||||||
}
|
|
||||||
|
|
||||||
sub exists1(str filename) -> bool {
|
for cx16.r0L in 0 to 255 step 16 {
|
||||||
; -- returns true if the given file exists on the disk, otherwise false
|
txt.print_ub(math.lerp(v1, v2, cx16.r0L))
|
||||||
if exists_byte(filename)!=0 {
|
txt.nl()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
return false
|
txt.print_ub(math.lerp(v1, v2, 255))
|
||||||
|
txt.nl()
|
||||||
}
|
}
|
||||||
|
|
||||||
sub exists2(str filename) -> bool {
|
|
||||||
; -- returns true if the given file exists on the disk, otherwise false
|
|
||||||
if exists_bool(filename) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
sub exists_bool(str name) -> bool {
|
|
||||||
%ir {{
|
|
||||||
loadm.w r65535,main.exists_bool.name
|
|
||||||
syscall 52 (r65535.w): r0.b
|
|
||||||
returnr.b r0
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
|
|
||||||
sub exists_byte(str name) -> ubyte {
|
|
||||||
%ir {{
|
|
||||||
loadm.w r65535,main.exists_byte.name
|
|
||||||
syscall 52 (r65535.w): r0.b
|
|
||||||
returnr.b r0
|
|
||||||
}}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user