mirror of
https://github.com/irmen/prog8.git
synced 2025-02-23 07:29:12 +00:00
moved all *integer* builtin trig functions (sin8u, cos8u etc) as regular asmsubs in math module
This commit is contained in:
parent
51bf33040a
commit
ab1766a559
@ -85,10 +85,6 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
|
|||||||
"min", "max" -> funcMinMax(fcall, func, resultToStack, resultRegister, sscope)
|
"min", "max" -> funcMinMax(fcall, func, resultToStack, resultRegister, sscope)
|
||||||
"sum" -> funcSum(fcall, resultToStack, resultRegister, sscope)
|
"sum" -> funcSum(fcall, resultToStack, resultRegister, sscope)
|
||||||
"any", "all" -> funcAnyAll(fcall, func, resultToStack, resultRegister, sscope)
|
"any", "all" -> funcAnyAll(fcall, func, resultToStack, resultRegister, sscope)
|
||||||
"sin8", "sin8u", "sin16", "sin16u",
|
|
||||||
"sinr8", "sinr8u", "sinr16", "sinr16u",
|
|
||||||
"cos8", "cos8u", "cos16", "cos16u",
|
|
||||||
"cosr8", "cosr8u", "cosr16", "cosr16u" -> funcSinCosInt(fcall, func, resultToStack, resultRegister, sscope)
|
|
||||||
"sgn" -> funcSgn(fcall, func, resultToStack, resultRegister, sscope)
|
"sgn" -> funcSgn(fcall, func, resultToStack, resultRegister, sscope)
|
||||||
"sin", "cos", "tan", "atan",
|
"sin", "cos", "tan", "atan",
|
||||||
"ln", "log2", "sqrt", "rad",
|
"ln", "log2", "sqrt", "rad",
|
||||||
@ -391,23 +387,6 @@ internal class BuiltinFunctionsAsmGen(private val program: Program,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun funcSinCosInt(fcall: IFunctionCall, func: FSignature, resultToStack: Boolean, resultRegister: RegisterOrPair?, scope: Subroutine?) {
|
|
||||||
translateArguments(fcall.args, func, scope)
|
|
||||||
if(resultToStack)
|
|
||||||
asmgen.out(" jsr prog8_lib.func_${func.name}_stack")
|
|
||||||
else
|
|
||||||
when(func.name) {
|
|
||||||
"sin8", "sin8u", "sinr8", "sinr8u", "cos8", "cos8u", "cosr8", "cosr8u" -> {
|
|
||||||
asmgen.out(" jsr prog8_lib.func_${func.name}_into_A")
|
|
||||||
assignAsmGen.assignRegisterByte(AsmAssignTarget.fromRegisters(resultRegister ?: RegisterOrPair.A, false, scope, program, asmgen), CpuRegister.A)
|
|
||||||
}
|
|
||||||
"sin16", "sin16u", "sinr16", "sinr16u", "cos16", "cos16u", "cosr16", "cosr16u" -> {
|
|
||||||
asmgen.out(" jsr prog8_lib.func_${func.name}_into_AY")
|
|
||||||
assignAsmGen.assignRegisterpairWord(AsmAssignTarget.fromRegisters(resultRegister ?: RegisterOrPair.AY, false, scope, program, asmgen), RegisterOrPair.AY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun funcReverse(fcall: IFunctionCall) {
|
private fun funcReverse(fcall: IFunctionCall) {
|
||||||
val variable = fcall.args.single()
|
val variable = fcall.args.single()
|
||||||
if (variable is IdentifierReference) {
|
if (variable is IdentifierReference) {
|
||||||
|
@ -12,28 +12,14 @@ internal class BuiltinFuncGen(private val codeGen: CodeGen, private val exprGen:
|
|||||||
|
|
||||||
fun translate(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
fun translate(call: PtBuiltinFunctionCall, resultRegister: Int): VmCodeChunk {
|
||||||
return when(call.name) {
|
return when(call.name) {
|
||||||
"cmp" -> TODO()
|
"cmp" -> TODO("cmp() can't be used on vm because no processor status bits implemented")
|
||||||
"max" -> TODO()
|
"max" -> TODO()
|
||||||
"min" -> TODO()
|
"min" -> TODO()
|
||||||
"sum" -> TODO()
|
"sum" -> TODO()
|
||||||
"abs" -> TODO()
|
"abs" -> TODO()
|
||||||
"sgn" -> funcSgn(call, resultRegister)
|
"sgn" -> funcSgn(call, resultRegister)
|
||||||
"sin" -> TODO("floats not yet implemented")
|
"sin" -> TODO("floats not yet implemented")
|
||||||
"sin8" -> TODO()
|
|
||||||
"sin16" -> TODO()
|
|
||||||
"sin16u" -> TODO()
|
|
||||||
"sinr8" -> TODO()
|
|
||||||
"sinr8u" -> TODO()
|
|
||||||
"sinr16" -> TODO()
|
|
||||||
"sinr16u" -> TODO()
|
|
||||||
"cos" -> TODO("floats not yet implemented")
|
"cos" -> TODO("floats not yet implemented")
|
||||||
"cos8" -> TODO()
|
|
||||||
"cos16" -> TODO()
|
|
||||||
"cos16u" -> TODO()
|
|
||||||
"cosr8" -> TODO()
|
|
||||||
"cosr8u" -> TODO()
|
|
||||||
"cosr16" -> TODO()
|
|
||||||
"cosr16u" -> TODO()
|
|
||||||
"tan" -> TODO("floats not yet implemented")
|
"tan" -> TODO("floats not yet implemented")
|
||||||
"atan" -> TODO("floats not yet implemented")
|
"atan" -> TODO("floats not yet implemented")
|
||||||
"ln" -> TODO("floats not yet implemented")
|
"ln" -> TODO("floats not yet implemented")
|
||||||
|
@ -4,4 +4,180 @@
|
|||||||
|
|
||||||
math {
|
math {
|
||||||
%asminclude "library:math.asm"
|
%asminclude "library:math.asm"
|
||||||
|
|
||||||
|
asmsub sin8u(ubyte angle @A) clobbers(Y) -> ubyte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecos8u,y
|
||||||
|
rts
|
||||||
|
_sinecos8u .byte trunc(128.0 + 127.5 * sin(range(256+64) * rad(360.0/256.0)))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cos8u(ubyte angle @A) clobbers(Y) -> ubyte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sin8u._sinecos8u+64,y
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sin8(ubyte angle @A) clobbers(Y) -> byte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecos8,y
|
||||||
|
rts
|
||||||
|
_sinecos8 .char trunc(127.0 * sin(range(256+64) * rad(360.0/256.0)))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cos8(ubyte angle @A) clobbers(Y) -> byte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sin8._sinecos8+64,y
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sin16(ubyte angle @A) -> word @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecos8lo,y
|
||||||
|
pha
|
||||||
|
lda _sinecos8hi,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
_ := trunc(32767.0 * sin(range(256+64) * rad(360.0/256.0)))
|
||||||
|
_sinecos8lo .byte <_
|
||||||
|
_sinecos8hi .byte >_
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cos16(ubyte angle @A) -> word @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sin16._sinecos8lo+64,y
|
||||||
|
pha
|
||||||
|
lda sin16._sinecos8hi+64,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sin16u(ubyte angle @A) -> uword @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecos8ulo,y
|
||||||
|
pha
|
||||||
|
lda _sinecos8uhi,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
_ := trunc(32768.0 + 32767.5 * sin(range(256+64) * rad(360.0/256.0)))
|
||||||
|
_sinecos8ulo .byte <_
|
||||||
|
_sinecos8uhi .byte >_
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cos16u(ubyte angle @A) -> uword @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sin16u._sinecos8ulo+64,y
|
||||||
|
pha
|
||||||
|
lda sin16u._sinecos8uhi+64,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sinr8u(ubyte radians @A) clobbers(Y) -> ubyte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecosR8u,y
|
||||||
|
rts
|
||||||
|
_sinecosR8u .byte trunc(128.0 + 127.5 * sin(range(180+45) * rad(360.0/180.0)))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cosr8u(ubyte radians @A) clobbers(Y) -> ubyte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sinr8u._sinecosR8u+45,y
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sinr8(ubyte radians @A) clobbers(Y) -> byte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecosR8,y
|
||||||
|
rts
|
||||||
|
_sinecosR8 .char trunc(127.0 * sin(range(180+45) * rad(360.0/180.0)))
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cosr8(ubyte radians @A) clobbers(Y) -> byte @A {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sinr8._sinecosR8+45,y
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sinr16(ubyte radians @A) -> word @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecosR8lo,y
|
||||||
|
pha
|
||||||
|
lda _sinecosR8hi,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
_ := trunc(32767.0 * sin(range(180+45) * rad(360.0/180.0)))
|
||||||
|
_sinecosR8lo .byte <_
|
||||||
|
_sinecosR8hi .byte >_
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cosr16(ubyte radians @A) -> word @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sinr16._sinecosR8lo+45,y
|
||||||
|
pha
|
||||||
|
lda sinr16._sinecosR8hi+45,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub sinr16u(ubyte radians @A) -> uword @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda _sinecosR8ulo,y
|
||||||
|
pha
|
||||||
|
lda _sinecosR8uhi,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
_ := trunc(32768.0 + 32767.5 * sin(range(180+45) * rad(360.0/180.0)))
|
||||||
|
_sinecosR8ulo .byte <_
|
||||||
|
_sinecosR8uhi .byte >_
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
asmsub cosr16u(ubyte radians @A) -> uword @AY {
|
||||||
|
%asm {{
|
||||||
|
tay
|
||||||
|
lda sinr16u._sinecosR8ulo+45,y
|
||||||
|
pha
|
||||||
|
lda sinr16u._sinecosR8uhi+45,y
|
||||||
|
tay
|
||||||
|
pla
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,294 +84,6 @@ func_all_w_stack .proc
|
|||||||
rts
|
rts
|
||||||
.pend
|
.pend
|
||||||
|
|
||||||
func_sin8_into_A .proc
|
|
||||||
tay
|
|
||||||
lda _sinecos8,y
|
|
||||||
rts
|
|
||||||
_sinecos8 .char trunc(127.0 * sin(range(256+64) * rad(360.0/256.0)))
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr8_into_A .proc
|
|
||||||
tay
|
|
||||||
lda _sinecosR8,y
|
|
||||||
rts
|
|
||||||
_sinecosR8 .char trunc(127.0 * sin(range(180+45) * rad(360.0/180.0)))
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin8u_into_A .proc
|
|
||||||
tay
|
|
||||||
lda _sinecos8u,y
|
|
||||||
rts
|
|
||||||
_sinecos8u .byte trunc(128.0 + 127.5 * sin(range(256+64) * rad(360.0/256.0)))
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr8u_into_A .proc
|
|
||||||
tay
|
|
||||||
lda _sinecosR8u,y
|
|
||||||
rts
|
|
||||||
_sinecosR8u .byte trunc(128.0 + 127.5 * sin(range(180+45) * rad(360.0/180.0)))
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin8_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8_into_A._sinecos8,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr8_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8_into_A._sinecosR8,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin8u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8u_into_A._sinecos8u,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr8u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8u_into_A._sinecosR8u,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos8_into_A .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8_into_A._sinecos8+64,y
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr8_into_A .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8_into_A._sinecosR8+45,y
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos8u_into_A .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8u_into_A._sinecos8u+64,y
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr8u_into_A .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8u_into_A._sinecosR8u+45,y
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos8_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8_into_A._sinecos8+64,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr8_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8_into_A._sinecosR8+45,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos8u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin8u_into_A._sinecos8u+64,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr8u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr8u_into_A._sinecosR8u+45,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin16_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda _sinecos8lo,y
|
|
||||||
pha
|
|
||||||
lda _sinecos8hi,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
_ := trunc(32767.0 * sin(range(256+64) * rad(360.0/256.0)))
|
|
||||||
_sinecos8lo .byte <_
|
|
||||||
_sinecos8hi .byte >_
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr16_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda _sinecosR8lo,y
|
|
||||||
pha
|
|
||||||
lda _sinecosR8hi,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
_ := trunc(32767.0 * sin(range(180+45) * rad(360.0/180.0)))
|
|
||||||
_sinecosR8lo .byte <_
|
|
||||||
_sinecosR8hi .byte >_
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin16u_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda _sinecos8ulo,y
|
|
||||||
pha
|
|
||||||
lda _sinecos8uhi,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
_ := trunc(32768.0 + 32767.5 * sin(range(256+64) * rad(360.0/256.0)))
|
|
||||||
_sinecos8ulo .byte <_
|
|
||||||
_sinecos8uhi .byte >_
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr16u_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda _sinecosR8ulo,y
|
|
||||||
pha
|
|
||||||
lda _sinecosR8uhi,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
_ := trunc(32768.0 + 32767.5 * sin(range(180+45) * rad(360.0/180.0)))
|
|
||||||
_sinecosR8ulo .byte <_
|
|
||||||
_sinecosR8uhi .byte >_
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin16_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16_into_AY._sinecos8lo,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sin16_into_AY._sinecos8hi,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr16_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16_into_AY._sinecosR8lo,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sinr16_into_AY._sinecosR8hi,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sin16u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16u_into_AY._sinecos8ulo,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sin16u_into_AY._sinecos8uhi,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_sinr16u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8ulo,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8uhi,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos16_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16_into_AY._sinecos8lo+64,y
|
|
||||||
pha
|
|
||||||
lda func_sin16_into_AY._sinecos8hi+64,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr16_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16_into_AY._sinecosR8lo+45,y
|
|
||||||
pha
|
|
||||||
lda func_sinr16_into_AY._sinecosR8hi+45,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos16u_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16u_into_AY._sinecos8ulo+64,y
|
|
||||||
pha
|
|
||||||
lda func_sin16u_into_AY._sinecos8uhi+64,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr16u_into_AY .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8ulo+45,y
|
|
||||||
pha
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8uhi+45,y
|
|
||||||
tay
|
|
||||||
pla
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos16_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16_into_AY._sinecos8lo+64,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sin16_into_AY._sinecos8hi+64,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr16_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16_into_AY._sinecosR8lo+45,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sinr16_into_AY._sinecosR8hi+45,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cos16u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sin16u_into_AY._sinecos8ulo+64,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sin16u_into_AY._sinecos8uhi+64,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
func_cosr16u_stack .proc
|
|
||||||
tay
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8ulo+45,y
|
|
||||||
sta P8ESTACK_LO,x
|
|
||||||
lda func_sinr16u_into_AY._sinecosR8uhi+45,y
|
|
||||||
sta P8ESTACK_HI,x
|
|
||||||
dex
|
|
||||||
rts
|
|
||||||
.pend
|
|
||||||
|
|
||||||
abs_b_stack .proc
|
abs_b_stack .proc
|
||||||
; -- push abs(A) on stack (as byte)
|
; -- push abs(A) on stack (as byte)
|
||||||
jsr abs_b_into_A
|
jsr abs_b_into_A
|
||||||
|
@ -10,21 +10,21 @@ import prog8.compiler.BuiltinFunctions
|
|||||||
class TestBuiltinFunctions: FunSpec({
|
class TestBuiltinFunctions: FunSpec({
|
||||||
|
|
||||||
test("pure func with fixed type") {
|
test("pure func with fixed type") {
|
||||||
val func = BuiltinFunctions.getValue("sin8u")
|
val func = BuiltinFunctions.getValue("sgn")
|
||||||
func.name shouldBe "sin8u"
|
func.name shouldBe "sgn"
|
||||||
func.parameters.size shouldBe 1
|
func.parameters.size shouldBe 1
|
||||||
func.parameters[0].name shouldBe "angle8"
|
func.parameters[0].name shouldBe "value"
|
||||||
func.parameters[0].possibleDatatypes shouldBe arrayOf(DataType.UBYTE)
|
func.parameters[0].possibleDatatypes shouldBe NumericDatatypes
|
||||||
func.pure shouldBe true
|
func.pure shouldBe true
|
||||||
func.hasReturn shouldBe true
|
func.hasReturn shouldBe true
|
||||||
func.returnType shouldBe DataType.UBYTE
|
func.returnType shouldBe DataType.BYTE
|
||||||
|
|
||||||
val conv = func.callConvention(listOf(DataType.UBYTE))
|
val conv = func.callConvention(listOf(DataType.UBYTE))
|
||||||
conv.params.size shouldBe 1
|
conv.params.size shouldBe 1
|
||||||
conv.params[0].dt shouldBe DataType.UBYTE
|
conv.params[0].dt shouldBe DataType.UBYTE
|
||||||
conv.params[0].reg shouldBe RegisterOrPair.A
|
conv.params[0].reg shouldBe RegisterOrPair.A
|
||||||
conv.params[0].variable shouldBe false
|
conv.params[0].variable shouldBe false
|
||||||
conv.returns.dt shouldBe DataType.UBYTE
|
conv.returns.dt shouldBe DataType.BYTE
|
||||||
conv.returns.floatFac1 shouldBe false
|
conv.returns.floatFac1 shouldBe false
|
||||||
conv.returns.reg shouldBe RegisterOrPair.A
|
conv.returns.reg shouldBe RegisterOrPair.A
|
||||||
}
|
}
|
||||||
|
@ -334,7 +334,7 @@ class TestOptimization: FunSpec({
|
|||||||
main {
|
main {
|
||||||
sub start() {
|
sub start() {
|
||||||
ubyte r
|
ubyte r
|
||||||
ubyte @shared bb = (cos8(r)/2 + 100) as ubyte
|
ubyte @shared bb = (sgn(r)*2 + 100) as ubyte
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@ -343,8 +343,8 @@ class TestOptimization: FunSpec({
|
|||||||
ubyte r
|
ubyte r
|
||||||
r = 0
|
r = 0
|
||||||
ubyte bb
|
ubyte bb
|
||||||
prog8_lib.retval_interm_b = cos8(r)
|
prog8_lib.retval_interm_b = sgn(r)
|
||||||
prog8_lib.retval_interm_b >>= 1
|
prog8_lib.retval_interm_b <<= 1
|
||||||
prog8_lib.retval_interm_b += 100
|
prog8_lib.retval_interm_b += 100
|
||||||
bb = prog8_lib.retval_interm_b
|
bb = prog8_lib.retval_interm_b
|
||||||
return
|
return
|
||||||
@ -604,7 +604,7 @@ class TestOptimization: FunSpec({
|
|||||||
uword @shared zz
|
uword @shared zz
|
||||||
zz += 60 ; NOT ok to remove initializer, should evaluate to 60
|
zz += 60 ; NOT ok to remove initializer, should evaluate to 60
|
||||||
ubyte @shared xx
|
ubyte @shared xx
|
||||||
xx = 6+sin8u(xx) ; is not an initializer because it references xx
|
xx = 6+abs(xx) ; is not an initializer because it references xx
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
@ -617,7 +617,7 @@ class TestOptimization: FunSpec({
|
|||||||
zz = 60
|
zz = 60
|
||||||
ubyte xx
|
ubyte xx
|
||||||
xx = 0
|
xx = 0
|
||||||
xx = sin8u(xx)
|
xx = abs(xx)
|
||||||
xx += 6
|
xx += 6
|
||||||
*/
|
*/
|
||||||
val stmts = result.program.entrypoint.statements
|
val stmts = result.program.entrypoint.statements
|
||||||
|
@ -267,8 +267,8 @@ class TestPipes: FunSpec({
|
|||||||
uword @shared ww = startvalue(99) |> addword()
|
uword @shared ww = startvalue(99) |> addword()
|
||||||
|> addword()
|
|> addword()
|
||||||
|
|
||||||
ubyte @shared cc = 30 |> sin8u() |> cos8u()
|
ubyte @shared cc = 30 |> abs() |> sqrt16()
|
||||||
cc = cc |> sin8u() |> cos8u()
|
cc = cc |> abs() |> sqrt16()
|
||||||
}
|
}
|
||||||
|
|
||||||
sub startvalue(ubyte arg) -> uword {
|
sub startvalue(ubyte arg) -> uword {
|
||||||
@ -308,9 +308,9 @@ class TestPipes: FunSpec({
|
|||||||
value.source shouldBe NumericLiteral(DataType.UBYTE, 30.0, Position.DUMMY)
|
value.source shouldBe NumericLiteral(DataType.UBYTE, 30.0, Position.DUMMY)
|
||||||
value.segments.size shouldBe 2
|
value.segments.size shouldBe 2
|
||||||
call = value.segments[0] as IFunctionCall
|
call = value.segments[0] as IFunctionCall
|
||||||
call.target.nameInSource shouldBe listOf("sin8u")
|
call.target.nameInSource shouldBe listOf("abs")
|
||||||
call = value.segments[1] as IFunctionCall
|
call = value.segments[1] as IFunctionCall
|
||||||
call.target.nameInSource shouldBe listOf("cos8u")
|
call.target.nameInSource shouldBe listOf("sqrt16")
|
||||||
|
|
||||||
assigncc = stmts[6] as Assignment
|
assigncc = stmts[6] as Assignment
|
||||||
val pipecc = assigncc.value as PipeExpression
|
val pipecc = assigncc.value as PipeExpression
|
||||||
@ -333,8 +333,8 @@ class TestPipes: FunSpec({
|
|||||||
uword @shared ww = startvalue(99) |> addword()
|
uword @shared ww = startvalue(99) |> addword()
|
||||||
|> addword()
|
|> addword()
|
||||||
|
|
||||||
ubyte @shared cc = 30 |> sin8u() |> cos8u() ; will be optimized away into a const number
|
ubyte @shared cc = 80 |> abs() |> sqrt16() ; will be optimized away into a const number
|
||||||
cc = cc |> sin8u() |> cos8u()
|
cc = cc |> abs() |> sqrt16()
|
||||||
}
|
}
|
||||||
|
|
||||||
sub startvalue(ubyte arg) -> uword {
|
sub startvalue(ubyte arg) -> uword {
|
||||||
@ -366,16 +366,16 @@ class TestPipes: FunSpec({
|
|||||||
|
|
||||||
var assigncc = stmts[5] as Assignment
|
var assigncc = stmts[5] as Assignment
|
||||||
val value = assigncc.value as NumericLiteral
|
val value = assigncc.value as NumericLiteral
|
||||||
value.number shouldBe 190.0
|
value.number shouldBe 8.0
|
||||||
|
|
||||||
assigncc = stmts[6] as Assignment
|
assigncc = stmts[6] as Assignment
|
||||||
val pipecc = assigncc.value as PipeExpression
|
val pipecc = assigncc.value as PipeExpression
|
||||||
pipecc.source shouldBe instanceOf<BuiltinFunctionCall>()
|
pipecc.source shouldBe instanceOf<BuiltinFunctionCall>()
|
||||||
(pipecc.source as BuiltinFunctionCall).target.nameInSource shouldBe listOf("sin8u")
|
(pipecc.source as BuiltinFunctionCall).target.nameInSource shouldBe listOf("abs")
|
||||||
|
|
||||||
pipecc.segments.size shouldBe 1
|
pipecc.segments.size shouldBe 1
|
||||||
pipecc.segments[0] shouldBe instanceOf<BuiltinFunctionCall>()
|
pipecc.segments[0] shouldBe instanceOf<BuiltinFunctionCall>()
|
||||||
(pipecc.segments[0] as BuiltinFunctionCall).target.nameInSource shouldBe listOf("cos8u")
|
(pipecc.segments[0] as BuiltinFunctionCall).target.nameInSource shouldBe listOf("sqrt16")
|
||||||
}
|
}
|
||||||
|
|
||||||
test("incorrect type in pipe expression") {
|
test("incorrect type in pipe expression") {
|
||||||
@ -455,7 +455,7 @@ class TestPipes: FunSpec({
|
|||||||
uword ww = startvalue() |> addword()
|
uword ww = startvalue() |> addword()
|
||||||
|> addword()
|
|> addword()
|
||||||
|
|
||||||
ubyte cc = 30 |> sin8u(99) |> cos8u(22)
|
ubyte cc = 30 |> abs(99) |> sqrt16(22)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub startvalue(ubyte arg) -> uword {
|
sub startvalue(ubyte arg) -> uword {
|
||||||
@ -469,7 +469,7 @@ class TestPipes: FunSpec({
|
|||||||
compileText(C64Target(), optimize = false, text, writeAssembly = false, errors=errors) shouldBe null
|
compileText(C64Target(), optimize = false, text, writeAssembly = false, errors=errors) shouldBe null
|
||||||
errors.errors.size shouldBe 3
|
errors.errors.size shouldBe 3
|
||||||
errors.errors[0] shouldContain ":4:32: invalid number of arguments"
|
errors.errors[0] shouldContain ":4:32: invalid number of arguments"
|
||||||
errors.errors[1] shouldContain ":7:44: invalid number of arguments"
|
errors.errors[1] shouldContain ":7:42: invalid number of arguments"
|
||||||
errors.errors[2] shouldContain ":7:57: invalid number of arguments"
|
errors.errors[2] shouldContain ":7:56: invalid number of arguments"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -338,71 +338,6 @@ main {
|
|||||||
txt.print_b(bb)
|
txt.print_b(bb)
|
||||||
txt.nl()
|
txt.nl()
|
||||||
|
|
||||||
ub = 0
|
|
||||||
uw = sin16u(ub)
|
|
||||||
txt.print_uw(uw)
|
|
||||||
txt.nl()
|
|
||||||
uw = zero+sin16u(ub)*1+zero
|
|
||||||
txt.print_uw(uw)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub = 0
|
|
||||||
uw = cos16u(ub)
|
|
||||||
txt.print_uw(uw)
|
|
||||||
txt.nl()
|
|
||||||
uw = zero+cos16u(ub)*1+zero
|
|
||||||
txt.print_uw(uw)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub = 0
|
|
||||||
ww = sin16(ub)
|
|
||||||
txt.print_w(ww)
|
|
||||||
txt.nl()
|
|
||||||
ww = zero+sin16(ub)*1+zero
|
|
||||||
txt.print_w(ww)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub = 0
|
|
||||||
ww = cos16(ub)
|
|
||||||
txt.print_w(ww)
|
|
||||||
txt.nl()
|
|
||||||
uw = 0
|
|
||||||
ww = zero+cos16(ub)*1+zero
|
|
||||||
txt.print_w(ww)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub2 = 0
|
|
||||||
ub = sin8u(ub2)
|
|
||||||
txt.print_ub(ub)
|
|
||||||
txt.nl()
|
|
||||||
ub = zero+sin8u(ub2)*1+zero
|
|
||||||
txt.print_ub(ub)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub2 = 0
|
|
||||||
ub = cos8u(ub2)
|
|
||||||
txt.print_ub(ub)
|
|
||||||
txt.nl()
|
|
||||||
ub = zero+cos8u(ub2)*1+zero
|
|
||||||
txt.print_ub(ub)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub2 = 0
|
|
||||||
bb = sin8(ub2)
|
|
||||||
txt.print_b(bb)
|
|
||||||
txt.nl()
|
|
||||||
bb = zero+sin8(ub2)*1+zero
|
|
||||||
txt.print_b(bb)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
ub2 = 0
|
|
||||||
bb = cos8(ub2)
|
|
||||||
txt.print_b(bb)
|
|
||||||
txt.nl()
|
|
||||||
bb = zero+cos8(ub2)*1+zero
|
|
||||||
txt.print_b(bb)
|
|
||||||
txt.nl()
|
|
||||||
|
|
||||||
bb = -100
|
bb = -100
|
||||||
bb = abs(bb)
|
bb = abs(bb)
|
||||||
txt.print_b(bb)
|
txt.print_b(bb)
|
||||||
|
@ -22,7 +22,7 @@ class TestIntermediateAst: FunSpec({
|
|||||||
ubyte cc
|
ubyte cc
|
||||||
ubyte[] array = [1,2,3]
|
ubyte[] array = [1,2,3]
|
||||||
cc = 11 in array
|
cc = 11 in array
|
||||||
cc = cc |> sin8u() |> cos8u()
|
cc = cc |> lsb() |> sqrt16()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
@ -113,23 +113,7 @@ private val functionSignatures: List<FSignature> = listOf(
|
|||||||
// normal functions follow:
|
// normal functions follow:
|
||||||
FSignature("sgn" , true, listOf(FParam("value", NumericDatatypes)), true, DataType.BYTE, ::builtinSgn ),
|
FSignature("sgn" , true, listOf(FParam("value", NumericDatatypes)), true, DataType.BYTE, ::builtinSgn ),
|
||||||
FSignature("sin" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::sin) },
|
FSignature("sin" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::sin) },
|
||||||
FSignature("sin8" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.BYTE, ::builtinSin8 ),
|
|
||||||
FSignature("sin8u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UBYTE, ::builtinSin8u ),
|
|
||||||
FSignature("sin16" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.WORD, ::builtinSin16 ),
|
|
||||||
FSignature("sin16u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UWORD, ::builtinSin16u ),
|
|
||||||
FSignature("sinr8" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.BYTE, ::builtinSinR8 ),
|
|
||||||
FSignature("sinr8u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UBYTE, ::builtinSinR8u ),
|
|
||||||
FSignature("sinr16" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.WORD, ::builtinSinR16 ),
|
|
||||||
FSignature("sinr16u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UWORD, ::builtinSinR16u ),
|
|
||||||
FSignature("cos" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::cos) },
|
FSignature("cos" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::cos) },
|
||||||
FSignature("cos8" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.BYTE, ::builtinCos8 ),
|
|
||||||
FSignature("cos8u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UBYTE, ::builtinCos8u ),
|
|
||||||
FSignature("cos16" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.WORD, ::builtinCos16 ),
|
|
||||||
FSignature("cos16u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UWORD, ::builtinCos16u ),
|
|
||||||
FSignature("cosr8" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.BYTE, ::builtinCosR8 ),
|
|
||||||
FSignature("cosr8u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UBYTE, ::builtinCosR8u ),
|
|
||||||
FSignature("cosr16" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.WORD, ::builtinCosR16 ),
|
|
||||||
FSignature("cosr16u" , true, listOf(FParam("angle8", arrayOf(DataType.UBYTE))), true, DataType.UWORD, ::builtinCosR16u ),
|
|
||||||
FSignature("tan" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::tan) },
|
FSignature("tan" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::tan) },
|
||||||
FSignature("atan" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::atan) },
|
FSignature("atan" , true, listOf(FParam("rads", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::atan) },
|
||||||
FSignature("ln" , true, listOf(FParam("value", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::log) },
|
FSignature("ln" , true, listOf(FParam("value", arrayOf(DataType.FLOAT))), true, DataType.FLOAT) { a, p, prg -> oneDoubleArg(a, p, prg, Math::log) },
|
||||||
@ -220,6 +204,8 @@ fun builtinFunctionReturnType(function: String, args: List<Expression>, program:
|
|||||||
return InferredTypes.InferredType.void()
|
return InferredTypes.InferredType.void()
|
||||||
|
|
||||||
// function has return values, but the return type depends on the arguments
|
// function has return values, but the return type depends on the arguments
|
||||||
|
if(args.isEmpty())
|
||||||
|
return InferredTypes.InferredType.unknown()
|
||||||
return when (function) {
|
return when (function) {
|
||||||
"abs" -> {
|
"abs" -> {
|
||||||
val dt = args.single().inferType(program)
|
val dt = args.single().inferType(program)
|
||||||
@ -386,7 +372,6 @@ private fun builtinLen(args: List<Expression>, position: Position, program: Prog
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private fun builtinMkword(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
private fun builtinMkword(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
||||||
if (args.size != 2)
|
if (args.size != 2)
|
||||||
throw SyntaxError("mkword requires msb and lsb arguments", position)
|
throw SyntaxError("mkword requires msb and lsb arguments", position)
|
||||||
@ -396,134 +381,6 @@ private fun builtinMkword(args: List<Expression>, position: Position, program: P
|
|||||||
return NumericLiteral(DataType.UWORD, result.toDouble(), position)
|
return NumericLiteral(DataType.UWORD, result.toDouble(), position)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun builtinSin8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sin8 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.BYTE, truncate(127.0 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSin8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sin8u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UBYTE, truncate(128.0 + 127.5 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSinR8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sinr8 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.BYTE, truncate(127.0 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSinR8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sinr8u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UBYTE, truncate(128.0 + 127.5 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCos8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cos8 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.BYTE, truncate(127.0 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCos8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cos8u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UBYTE, truncate(128.0 + 127.5 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCosR8(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cosr8 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.BYTE, truncate(127.0 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCosR8u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cosr8u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UBYTE, truncate(128.0 + 127.5 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSin16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sin16 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.WORD, truncate(32767.0 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSin16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sin16u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UWORD, truncate(32768.0 + 32767.5 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSinR16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sinr16 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.WORD, truncate(32767.0 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSinR16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("sinr16u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UWORD, truncate(32768.0 + 32767.5 * sin(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCos16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cos16 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.WORD, truncate(32767.0 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCos16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cos16u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number /256.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UWORD, truncate(32768.0 + 32767.5 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCosR16(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cosr16 requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.WORD, truncate(32767.0 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinCosR16u(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
|
||||||
if (args.size != 1)
|
|
||||||
throw SyntaxError("cosr16u requires one argument", position)
|
|
||||||
val constval = args[0].constValue(program) ?: throw NotConstArgumentException()
|
|
||||||
val rad = constval.number / 180.0 * 2.0 * PI
|
|
||||||
return NumericLiteral(DataType.UWORD, truncate(32768.0 + 32767.5 * cos(rad)), position)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun builtinSgn(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
private fun builtinSgn(args: List<Expression>, position: Position, program: Program): NumericLiteral {
|
||||||
if (args.size != 1)
|
if (args.size != 1)
|
||||||
throw SyntaxError("sgn requires one argument", position)
|
throw SyntaxError("sgn requires one argument", position)
|
||||||
@ -531,8 +388,6 @@ private fun builtinSgn(args: List<Expression>, position: Position, program: Prog
|
|||||||
return NumericLiteral(DataType.BYTE, constval.number.sign, position)
|
return NumericLiteral(DataType.BYTE, constval.number.sign, position)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun numericLiteral(value: UInt, position: Position): NumericLiteral = numericLiteral(value.toInt(), position)
|
|
||||||
|
|
||||||
private fun numericLiteral(value: Number, position: Position): NumericLiteral {
|
private fun numericLiteral(value: Number, position: Position): NumericLiteral {
|
||||||
val floatNum=value.toDouble()
|
val floatNum=value.toDouble()
|
||||||
val tweakedValue: Number =
|
val tweakedValue: Number =
|
||||||
|
@ -745,35 +745,9 @@ ceil(x)
|
|||||||
Rounds the floating point up to an integer towards positive infinity.
|
Rounds the floating point up to an integer towards positive infinity.
|
||||||
|
|
||||||
cos(x)
|
cos(x)
|
||||||
Cosine. (floating point version)
|
Cosine. (floating point)
|
||||||
|
If you want a fast integer cosine, have a look at examples/cx16/sincos.p8
|
||||||
cos8u(x)
|
that contains various lookup tables generated by the 64tass assembler.
|
||||||
Fast 8-bit ubyte cosine of angle 0..255, result is in range 0..255
|
|
||||||
|
|
||||||
cos8(x)
|
|
||||||
Fast 8-bit byte cosine of angle 0..255, result is in range -127..127
|
|
||||||
|
|
||||||
cos16u(x)
|
|
||||||
Fast 16-bit uword cosine of angle 0..255, result is in range 0..65535
|
|
||||||
|
|
||||||
cos16(x)
|
|
||||||
Fast 16-bit word cosine of angle 0..255, result is in range -32767..32767
|
|
||||||
|
|
||||||
cosr8u(x)
|
|
||||||
Fast 8-bit ubyte cosine of angle 0..179 (each is a 2 degree step), result is in range 0..255
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
cosr8(x)
|
|
||||||
Fast 8-bit byte cosine of angle 0..179 (each is a 2 degree step), result is in range -127..127
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
cosr16u(x)
|
|
||||||
Fast 16-bit uword cosine of angle 0..179 (each is a 2 degree step), result is in range 0..65535
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
cosr16(x)
|
|
||||||
Fast 16-bit word cosine of angle 0..179 (each is a 2 degree step), result is in range -32767..32767
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
deg(x)
|
deg(x)
|
||||||
Radians to degrees.
|
Radians to degrees.
|
||||||
@ -794,39 +768,13 @@ round(x)
|
|||||||
Rounds the floating point to the closest integer.
|
Rounds the floating point to the closest integer.
|
||||||
|
|
||||||
sin(x)
|
sin(x)
|
||||||
Sine. (floating point version)
|
Sine. (floating point)
|
||||||
|
If you want a fast integer sine, have a look at examples/cx16/sincos.p8
|
||||||
|
that contains various lookup tables generated by the 64tass assembler.
|
||||||
|
|
||||||
sgn(x)
|
sgn(x)
|
||||||
Get the sign of the value. Result is -1, 0 or 1 (negative, zero, positive).
|
Get the sign of the value. Result is -1, 0 or 1 (negative, zero, positive).
|
||||||
|
|
||||||
sin8u(x)
|
|
||||||
Fast 8-bit ubyte sine of angle 0..255, result is in range 0..255
|
|
||||||
|
|
||||||
sin8(x)
|
|
||||||
Fast 8-bit byte sine of angle 0..255, result is in range -127..127
|
|
||||||
|
|
||||||
sin16u(x)
|
|
||||||
Fast 16-bit uword sine of angle 0..255, result is in range 0..65535
|
|
||||||
|
|
||||||
sin16(x)
|
|
||||||
Fast 16-bit word sine of angle 0..255, result is in range -32767..32767
|
|
||||||
|
|
||||||
sinr8u(x)
|
|
||||||
Fast 8-bit ubyte sine of angle 0..179 (each is a 2 degree step), result is in range 0..255
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
sinr8(x)
|
|
||||||
Fast 8-bit byte sine of angle 0..179 (each is a 2 degree step), result is in range -127..127
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
sinr16u(x)
|
|
||||||
Fast 16-bit uword sine of angle 0..179 (each is a 2 degree step), result is in range 0..65535
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
sinr16(x)
|
|
||||||
Fast 16-bit word sine of angle 0..179 (each is a 2 degree step), result is in range -32767..32767
|
|
||||||
Angles 180..255 will yield a garbage result!
|
|
||||||
|
|
||||||
sqrt16(w)
|
sqrt16(w)
|
||||||
16 bit unsigned integer Square root. Result is unsigned byte.
|
16 bit unsigned integer Square root. Result is unsigned byte.
|
||||||
To do the reverse, squaring an integer, just write ``x*x``.
|
To do the reverse, squaring an integer, just write ``x*x``.
|
||||||
|
@ -4,6 +4,7 @@ TODO
|
|||||||
For next release
|
For next release
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
- vm: add support for all builtin functions
|
- vm: add support for all builtin functions
|
||||||
|
- can't use abs() etc in pipe expression because return type depends on argument type
|
||||||
- pipe operator: allow non-unary function calls in the pipe that specify the other argument(s) in the calls.
|
- pipe operator: allow non-unary function calls in the pipe that specify the other argument(s) in the calls.
|
||||||
- createAssemblyAndAssemble(): make it possible to actually get rid of the VarDecl nodes by fixing the rest of the code mentioned there.
|
- createAssemblyAndAssemble(): make it possible to actually get rid of the VarDecl nodes by fixing the rest of the code mentioned there.
|
||||||
- allow "xxx" * constexpr (where constexpr is not a number literal), now gives expression error not same type
|
- allow "xxx" * constexpr (where constexpr is not a number literal), now gives expression error not same type
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
%import graphics
|
%import graphics
|
||||||
|
%import math
|
||||||
|
|
||||||
; Note: this program is compatible with C64 and CX16.
|
; Note: this program is compatible with C64 and CX16.
|
||||||
|
|
||||||
@ -45,12 +46,12 @@ main {
|
|||||||
; rotate around origin (0,0,0)
|
; rotate around origin (0,0,0)
|
||||||
|
|
||||||
; set up the 3d rotation matrix values
|
; set up the 3d rotation matrix values
|
||||||
word wcosa = cos8(ax)
|
word wcosa = math.cos8(ax)
|
||||||
word wsina = sin8(ax)
|
word wsina = math.sin8(ax)
|
||||||
word wcosb = cos8(ay)
|
word wcosb = math.cos8(ay)
|
||||||
word wsinb = sin8(ay)
|
word wsinb = math.sin8(ay)
|
||||||
word wcosc = cos8(az)
|
word wcosc = math.cos8(az)
|
||||||
word wsinc = sin8(az)
|
word wsinc = math.sin8(az)
|
||||||
|
|
||||||
word wcosa_sinb = wcosa*wsinb / 128
|
word wcosa_sinb = wcosa*wsinb / 128
|
||||||
word wsina_sinb = wsina*wsinb / 128
|
word wsina_sinb = wsina*wsinb / 128
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
%import textio
|
%import textio
|
||||||
|
%import math
|
||||||
%import test_stack
|
%import test_stack
|
||||||
|
|
||||||
|
|
||||||
@ -105,12 +106,12 @@ main {
|
|||||||
; rotate around origin (0,0,0)
|
; rotate around origin (0,0,0)
|
||||||
|
|
||||||
; set up the 3d rotation matrix values
|
; set up the 3d rotation matrix values
|
||||||
word wcosa = cos8(ax)
|
word wcosa = math.cos8(ax)
|
||||||
word wsina = sin8(ax)
|
word wsina = math.sin8(ax)
|
||||||
word wcosb = cos8(ay)
|
word wcosb = math.cos8(ay)
|
||||||
word wsinb = sin8(ay)
|
word wsinb = math.sin8(ay)
|
||||||
word wcosc = cos8(az)
|
word wcosc = math.cos8(az)
|
||||||
word wsinc = sin8(az)
|
word wsinc = math.sin8(az)
|
||||||
|
|
||||||
word wcosa_sinb = wcosa*wsinb / 128
|
word wcosa_sinb = wcosa*wsinb / 128
|
||||||
word wsina_sinb = wsina*wsinb / 128
|
word wsina_sinb = wsina*wsinb / 128
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%import textio
|
%import textio
|
||||||
|
%import math
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
@ -43,12 +44,12 @@ main {
|
|||||||
; rotate around origin (0,0,0)
|
; rotate around origin (0,0,0)
|
||||||
|
|
||||||
; set up the 3d rotation matrix values
|
; set up the 3d rotation matrix values
|
||||||
word wcosa = cos8(ax)
|
word wcosa = math.cos8(ax)
|
||||||
word wsina = sin8(ax)
|
word wsina = math.sin8(ax)
|
||||||
word wcosb = cos8(ay)
|
word wcosb = math.cos8(ay)
|
||||||
word wsinb = sin8(ay)
|
word wsinb = math.sin8(ay)
|
||||||
word wcosc = cos8(az)
|
word wcosc = math.cos8(az)
|
||||||
word wsinc = sin8(az)
|
word wsinc = math.sin8(az)
|
||||||
|
|
||||||
word wcosa_sinb = wcosa*wsinb / 128
|
word wcosa_sinb = wcosa*wsinb / 128
|
||||||
word wsina_sinb = wsina*wsinb / 128
|
word wsina_sinb = wsina*wsinb / 128
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%import palette
|
%import palette
|
||||||
%import conv
|
%import conv
|
||||||
%import textio
|
%import textio
|
||||||
|
%import math
|
||||||
|
|
||||||
; "unlimited sprites / bobs" demo effect.
|
; "unlimited sprites / bobs" demo effect.
|
||||||
; Note that everything is prog8, no inline assembly used/required.
|
; Note that everything is prog8, no inline assembly used/required.
|
||||||
@ -97,8 +98,8 @@ main {
|
|||||||
sub blit(ubyte vmembase) {
|
sub blit(ubyte vmembase) {
|
||||||
ubyte bank = vmembase>=32
|
ubyte bank = vmembase>=32
|
||||||
uword vmem = vmembase * 2048 ; mkword(vmembase,0) * 8
|
uword vmem = vmembase * 2048 ; mkword(vmembase,0) * 8
|
||||||
uword blit_x = (cos8u(msb(anim1)) as uword) + sin8u(msb(anim2))/6
|
uword blit_x = (math.cos8u(msb(anim1)) as uword) + math.sin8u(msb(anim2))/6
|
||||||
ubyte blit_y = sin8u(msb(anim3))/2 + cos8u(msb(anim4))/5
|
ubyte blit_y = math.sin8u(msb(anim3))/2 + math.cos8u(msb(anim4))/5
|
||||||
vmem += blit_x/8 + (blit_y as uword) * 40
|
vmem += blit_x/8 + (blit_y as uword) * 40
|
||||||
|
|
||||||
bitshift(lsb(blit_x) & 7)
|
bitshift(lsb(blit_x) & 7)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%import conv
|
%import conv
|
||||||
|
%import math
|
||||||
|
|
||||||
; TODO add all other Elite's ships, show their name, advance to next ship on keypress
|
; TODO add all other Elite's ships, show their name, advance to next ship on keypress
|
||||||
|
|
||||||
@ -90,12 +91,12 @@ _ones pla
|
|||||||
; rotate around origin (0,0,0)
|
; rotate around origin (0,0,0)
|
||||||
|
|
||||||
; set up the 3d rotation matrix values
|
; set up the 3d rotation matrix values
|
||||||
word wcosa = cos8(ax)
|
word wcosa = math.cos8(ax)
|
||||||
word wsina = sin8(ax)
|
word wsina = math.sin8(ax)
|
||||||
word wcosb = cos8(ay)
|
word wcosb = math.cos8(ay)
|
||||||
word wsinb = sin8(ay)
|
word wsinb = math.sin8(ay)
|
||||||
word wcosc = cos8(az)
|
word wcosc = math.cos8(az)
|
||||||
word wsinc = sin8(az)
|
word wsinc = math.sin8(az)
|
||||||
|
|
||||||
word wcosa_sinb = wcosa*wsinb / 128
|
word wcosa_sinb = wcosa*wsinb / 128
|
||||||
word wsina_sinb = wsina*wsinb / 128
|
word wsina_sinb = wsina*wsinb / 128
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
%import textio
|
%import textio
|
||||||
|
%import math
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
@ -34,12 +35,12 @@ main {
|
|||||||
; rotate around origin (0,0,0)
|
; rotate around origin (0,0,0)
|
||||||
|
|
||||||
; set up the 3d rotation matrix values
|
; set up the 3d rotation matrix values
|
||||||
word wcosa = cos8(ax)
|
word wcosa = math.cos8(ax)
|
||||||
word wsina = sin8(ax)
|
word wsina = math.sin8(ax)
|
||||||
word wcosb = cos8(ay)
|
word wcosb = math.cos8(ay)
|
||||||
word wsinb = sin8(ay)
|
word wsinb = math.sin8(ay)
|
||||||
word wcosc = cos8(az)
|
word wcosc = math.cos8(az)
|
||||||
word wsinc = sin8(az)
|
word wsinc = math.sin8(az)
|
||||||
|
|
||||||
word wcosa_sinb = wcosa*wsinb / 128
|
word wcosa_sinb = wcosa*wsinb / 128
|
||||||
word wsina_sinb = wsina*wsinb / 128
|
word wsina_sinb = wsina*wsinb / 128
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
%import palette
|
%import palette
|
||||||
|
%import math
|
||||||
%option no_sysinit
|
%option no_sysinit
|
||||||
|
|
||||||
; Vertical rasterbars a.k.a. "Kefren bars"
|
; Vertical rasterbars a.k.a. "Kefren bars"
|
||||||
@ -59,7 +60,7 @@ irq {
|
|||||||
cx16.FB_fill_pixels(320, 1, 0)
|
cx16.FB_fill_pixels(320, 1, 0)
|
||||||
} else {
|
} else {
|
||||||
; add new bar
|
; add new bar
|
||||||
cx16.FB_cursor_position(sin8u(anim1)/2 + cos8u(anim2)/2 + $0010, 0)
|
cx16.FB_cursor_position(math.sin8u(anim1)/2 + math.cos8u(anim2)/2 + $0010, 0)
|
||||||
cx16.FB_set_pixels(pixels, len(pixels))
|
cx16.FB_set_pixels(pixels, len(pixels))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
%import textio
|
%import textio
|
||||||
%import palette
|
%import palette
|
||||||
|
%import math
|
||||||
|
|
||||||
; horizontal raster bars
|
; horizontal raster bars
|
||||||
; also see: kefrenbars.p8
|
; also see: kefrenbars.p8
|
||||||
@ -48,7 +49,7 @@ irq {
|
|||||||
|
|
||||||
if color_idx==0 {
|
if color_idx==0 {
|
||||||
yanim++
|
yanim++
|
||||||
next_irq_line = $0030 + sin8u(yanim)
|
next_irq_line = $0030 + math.sin8u(yanim)
|
||||||
} else {
|
} else {
|
||||||
next_irq_line += barheight
|
next_irq_line += barheight
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
%import graphics
|
%import graphics
|
||||||
|
%import math
|
||||||
|
|
||||||
|
; Draw sine and cosine graphs. The sine and cosine functions are table lookups
|
||||||
|
; where the tables are generated by 64tass list functions.
|
||||||
|
|
||||||
; Note: this program is compatible with CX16 only.
|
; Note: this program is compatible with CX16 only.
|
||||||
; it doesn't work correctly on C64 because the bitmap screen data overlaps
|
; it doesn't work correctly on C64 because the bitmap screen data overlaps
|
||||||
@ -35,16 +39,16 @@ main {
|
|||||||
ubyte pixelxb
|
ubyte pixelxb
|
||||||
|
|
||||||
for pixelxb in 0 to 255 {
|
for pixelxb in 0 to 255 {
|
||||||
pixelyb = cos8u(pixelxb) / 2
|
pixelyb = math.cos8u(pixelxb) / 2
|
||||||
graphics.plot(pixelxb, pixelyb)
|
graphics.plot(pixelxb, pixelyb)
|
||||||
pixelyb = sin8u(pixelxb) / 2
|
pixelyb = math.sin8u(pixelxb) / 2
|
||||||
graphics.plot(pixelxb, pixelyb)
|
graphics.plot(pixelxb, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
for pixelxb in 0 to 255 {
|
for pixelxb in 0 to 255 {
|
||||||
pixelyw = cos16u(pixelxb) / 1024 + 120
|
pixelyw = math.cos16u(pixelxb) / 1024 + 120
|
||||||
graphics.plot(pixelxb, pixelyw)
|
graphics.plot(pixelxb, pixelyw)
|
||||||
pixelyw = sin16u(pixelxb) / 1024 + 120
|
pixelyw = math.sin16u(pixelxb) / 1024 + 120
|
||||||
graphics.plot(pixelxb, pixelyw)
|
graphics.plot(pixelxb, pixelyw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,16 +61,16 @@ main {
|
|||||||
ubyte pixelxb
|
ubyte pixelxb
|
||||||
|
|
||||||
for pixelxb in 0 to 179 {
|
for pixelxb in 0 to 179 {
|
||||||
pixelyb = cosr8u(pixelxb) / 2
|
pixelyb = math.cosr8u(pixelxb) / 2
|
||||||
graphics.plot(pixelxb, pixelyb)
|
graphics.plot(pixelxb, pixelyb)
|
||||||
pixelyb = sinr8u(pixelxb) / 2
|
pixelyb = math.sinr8u(pixelxb) / 2
|
||||||
graphics.plot(pixelxb, pixelyb)
|
graphics.plot(pixelxb, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
for pixelxb in 0 to 179 {
|
for pixelxb in 0 to 179 {
|
||||||
pixelyw = cosr16u(pixelxb) / 1024 + 120
|
pixelyw = math.cosr16u(pixelxb) / 1024 + 120
|
||||||
graphics.plot(pixelxb, pixelyw)
|
graphics.plot(pixelxb, pixelyw)
|
||||||
pixelyw = sinr16u(pixelxb) / 1024 + 120
|
pixelyw = math.sinr16u(pixelxb) / 1024 + 120
|
||||||
graphics.plot(pixelxb, pixelyw)
|
graphics.plot(pixelxb, pixelyw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,27 +82,27 @@ main {
|
|||||||
|
|
||||||
; circles with "degrees" from 0 to 255
|
; circles with "degrees" from 0 to 255
|
||||||
for r in 0 to 255 {
|
for r in 0 to 255 {
|
||||||
pixelxw = ((sin8(r)/2 as word) + 80) as uword
|
pixelxw = ((math.sin8(r)/2 as word) + 80) as uword
|
||||||
pixelyb = (cos8(r)/2 + height/2) as ubyte
|
pixelyb = (math.cos8(r)/2 + height/2) as ubyte
|
||||||
graphics.plot(pixelxw, pixelyb)
|
graphics.plot(pixelxw, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
for r in 0 to 255 {
|
for r in 0 to 255 {
|
||||||
pixelxw = (sin16(r)/1024 + 80) as uword
|
pixelxw = (math.sin16(r)/1024 + 80) as uword
|
||||||
pixelyb = (cos16(r)/1024 + height/2) as ubyte
|
pixelyb = (math.cos16(r)/1024 + height/2) as ubyte
|
||||||
graphics.plot(pixelxw, pixelyb)
|
graphics.plot(pixelxw, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
; circles with half-degrees from 0 to 179 (=full degrees 0..358 with steps of 2 degrees)
|
; circles with half-degrees from 0 to 179 (=full degrees 0..358 with steps of 2 degrees)
|
||||||
for r in 0 to 179 {
|
for r in 0 to 179 {
|
||||||
pixelxw = (sinr8(r) as word /2 + 220) as uword
|
pixelxw = (math.sinr8(r) as word /2 + 220) as uword
|
||||||
pixelyb = (cosr8(r)/2 + height/2) as ubyte
|
pixelyb = (math.cosr8(r)/2 + height/2) as ubyte
|
||||||
graphics.plot(pixelxw, pixelyb)
|
graphics.plot(pixelxw, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
for r in 0 to 179 {
|
for r in 0 to 179 {
|
||||||
pixelxw = (sinr16(r) as word /1024 + 220) as uword
|
pixelxw = (math.sinr16(r) as word /1024 + 220) as uword
|
||||||
pixelyb = (cosr16(r)/1024 + height/2) as ubyte
|
pixelyb = (math.cosr16(r)/1024 + height/2) as ubyte
|
||||||
graphics.plot(pixelxw, pixelyb)
|
graphics.plot(pixelxw, pixelyb)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
%import gfx2
|
%import gfx2
|
||||||
%import textio
|
%import textio
|
||||||
%import test_stack
|
%import test_stack
|
||||||
|
%import math
|
||||||
|
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
@ -170,10 +172,10 @@ main {
|
|||||||
|
|
||||||
ubyte i
|
ubyte i
|
||||||
for i in 0 to 254 step 4 {
|
for i in 0 to 254 step 4 {
|
||||||
uword x1 = ((gfx2.width-256)/2 as uword) + sin8u(i)
|
uword x1 = ((gfx2.width-256)/2 as uword) + math.sin8u(i)
|
||||||
uword y1 = (gfx2.height-128)/2 + cos8u(i)/2
|
uword y1 = (gfx2.height-128)/2 + math.cos8u(i)/2
|
||||||
uword x2 = ((gfx2.width-64)/2 as uword) + sin8u(i)/4
|
uword x2 = ((gfx2.width-64)/2 as uword) + math.sin8u(i)/4
|
||||||
uword y2 = (gfx2.height-64)/2 + cos8u(i)/4
|
uword y2 = (gfx2.height-64)/2 + math.cos8u(i)/4
|
||||||
gfx2.line(x1, y1, x2, y2, i+1)
|
gfx2.line(x1, y1, x2, y2, i+1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
%import graphics
|
%import graphics
|
||||||
%import test_stack
|
%import test_stack
|
||||||
|
%import math
|
||||||
|
|
||||||
; Note: this program is compatible with C64 and CX16.
|
; Note: this program is compatible with C64 and CX16.
|
||||||
|
|
||||||
@ -38,10 +39,10 @@ main {
|
|||||||
sub draw_lines() {
|
sub draw_lines() {
|
||||||
ubyte i
|
ubyte i
|
||||||
for i in 0 to 255 step 4 {
|
for i in 0 to 255 step 4 {
|
||||||
uword x1 = ((graphics.WIDTH-256)/2 as uword) + sin8u(i)
|
uword x1 = ((graphics.WIDTH-256)/2 as uword) + math.sin8u(i)
|
||||||
uword y1 = (graphics.HEIGHT-128)/2 + cos8u(i)/2
|
uword y1 = (graphics.HEIGHT-128)/2 + math.cos8u(i)/2
|
||||||
uword x2 = ((graphics.WIDTH-64)/2 as uword) + sin8u(i)/4
|
uword x2 = ((graphics.WIDTH-64)/2 as uword) + math.sin8u(i)/4
|
||||||
uword y2 = (graphics.HEIGHT-64)/2 + cos8u(i)/4
|
uword y2 = (graphics.HEIGHT-64)/2 + math.cos8u(i)/4
|
||||||
graphics.line(x1, lsb(y1), x2, lsb(y2))
|
graphics.line(x1, lsb(y1), x2, lsb(y2))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
%import test_stack
|
%import test_stack
|
||||||
%import textio
|
%import textio
|
||||||
|
%import math
|
||||||
|
|
||||||
; converted from plasma test program for cc65.
|
; converted from plasma test program for cc65.
|
||||||
; which is (w)2001 by groepaz/hitmen
|
; which is (w)2001 by groepaz/hitmen
|
||||||
@ -61,14 +62,14 @@ main {
|
|||||||
ubyte @zp y
|
ubyte @zp y
|
||||||
|
|
||||||
for y in 24 downto 0 {
|
for y in 24 downto 0 {
|
||||||
ybuf[y] = sin8u(c1a) + sin8u(c1b)
|
ybuf[y] = math.sin8u(c1a) + math.sin8u(c1b)
|
||||||
c1a += 4
|
c1a += 4
|
||||||
c1b += 9
|
c1b += 9
|
||||||
}
|
}
|
||||||
c1A += 3
|
c1A += 3
|
||||||
c1B -= 5
|
c1B -= 5
|
||||||
for x in 39 downto 0 {
|
for x in 39 downto 0 {
|
||||||
xbuf[x] = sin8u(c2a) + sin8u(c2b)
|
xbuf[x] = math.sin8u(c2a) + math.sin8u(c2b)
|
||||||
c2a += 3
|
c2a += 3
|
||||||
c2b += 7
|
c2b += 7
|
||||||
}
|
}
|
||||||
@ -98,7 +99,7 @@ main {
|
|||||||
ubyte[8] bittab = [ $01, $02, $04, $08, $10, $20, $40, $80 ]
|
ubyte[8] bittab = [ $01, $02, $04, $08, $10, $20, $40, $80 ]
|
||||||
ubyte c
|
ubyte c
|
||||||
for c in 0 to 255 {
|
for c in 0 to 255 {
|
||||||
ubyte @zp s = sin8u(c)
|
ubyte @zp s = math.sin8u(c)
|
||||||
ubyte i
|
ubyte i
|
||||||
for i in 0 to 7 {
|
for i in 0 to 7 {
|
||||||
ubyte b=0
|
ubyte b=0
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
|
%import math
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ irq {
|
|||||||
c64.EXTCOL = 0
|
c64.EXTCOL = 0
|
||||||
color = 0
|
color = 0
|
||||||
yanim += 2
|
yanim += 2
|
||||||
c64.RASTER = sin8u(yanim)/2+30 ; new start of raster Irq
|
c64.RASTER = math.sin8u(yanim)/2+30 ; new start of raster Irq
|
||||||
}
|
}
|
||||||
c64.SCROLY &= $7f ; set high bit of the raster pos to zero
|
c64.SCROLY &= $7f ; set high bit of the raster pos to zero
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
%import math
|
||||||
%import textio
|
%import textio
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
@ -12,8 +13,8 @@ main {
|
|||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
repeat {
|
repeat {
|
||||||
ubyte x = msb(sin8u(msb(anglex)) * screenwidth)
|
ubyte x = msb(math.sin8u(msb(anglex)) * screenwidth)
|
||||||
ubyte y = msb(cos8u(msb(angley)) * screenheight)
|
ubyte y = msb(math.cos8u(msb(angley)) * screenheight)
|
||||||
txt.setcc(x, y, 81, color)
|
txt.setcc(x, y, 81, color)
|
||||||
anglex+=366
|
anglex+=366
|
||||||
angley+=291
|
angley+=291
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
%import syslib
|
%import syslib
|
||||||
|
%import math
|
||||||
%zeropage basicsafe
|
%zeropage basicsafe
|
||||||
|
|
||||||
|
|
||||||
@ -53,8 +54,8 @@ irq {
|
|||||||
ubyte @zp spri
|
ubyte @zp spri
|
||||||
for spri in 7 downto 0 {
|
for spri in 7 downto 0 {
|
||||||
c64.EXTCOL++
|
c64.EXTCOL++
|
||||||
uword @zp x = sin8u(angle1-spri*16) as uword + 50
|
uword @zp x = math.sin8u(angle1-spri*16) as uword + 50
|
||||||
ubyte @zp y = sin8u(angle2-spri*16) / 2 + 70
|
ubyte @zp y = math.sin8u(angle2-spri*16) / 2 + 70
|
||||||
c64.SPXYW[spri] = mkword(y, lsb(x))
|
c64.SPXYW[spri] = mkword(y, lsb(x))
|
||||||
c64.MSIGX <<= 1
|
c64.MSIGX <<= 1
|
||||||
if msb(x) c64.MSIGX++
|
if msb(x) c64.MSIGX++
|
||||||
|
@ -14,10 +14,10 @@
|
|||||||
<keywords keywords="&;->;@;\$;and;as;asmsub;break;clobbers;do;downto;else;false;for;goto;if;if_cc;if_cs;if_eq;if_mi;if_ne;if_neg;if_nz;if_pl;if_pos;if_vc;if_vs;if_z;in;inline;not;or;repeat;return;romsub;step;sub;to;true;until;when;while;xor;~" ignore_case="false" />
|
<keywords keywords="&;->;@;\$;and;as;asmsub;break;clobbers;do;downto;else;false;for;goto;if;if_cc;if_cs;if_eq;if_mi;if_ne;if_neg;if_nz;if_pl;if_pos;if_vc;if_vs;if_z;in;inline;not;or;repeat;return;romsub;step;sub;to;true;until;when;while;xor;~" ignore_case="false" />
|
||||||
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%zeropage;%zpreserved;iso:;petscii:;sc:" />
|
<keywords2 keywords="%address;%asm;%asmbinary;%asminclude;%breakpoint;%import;%launcher;%option;%output;%zeropage;%zpreserved;iso:;petscii:;sc:" />
|
||||||
<keywords3 keywords="@requirezp;@shared;@zp;byte;const;float;str;ubyte;uword;void;word" />
|
<keywords3 keywords="@requirezp;@shared;@zp;byte;const;float;str;ubyte;uword;void;word" />
|
||||||
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;callfar;callrom;ceil;cmp;cos;cos16;cos16u;cos8;cos8u;cosr16;cosr16u;cosr8;cosr8u;deg;floor;len;ln;log2;lsb;max;memory;min;mkword;msb;peek;peekw;poke;pokew;pop;popw;push;pushw;rad;reverse;rnd;rndf;rndw;rol;rol2;ror;ror2;round;rrestore;rrestorex;rsave;rsavex;sgn;sin;sin16;sin16u;sin8;sin8u;sinr16;sinr16u;sinr8;sinr8u;sizeof;sort;sqrt;sqrt16;sum;swap;tan;|>" />
|
<keywords4 keywords="abs;acos;all;any;asin;atan;avg;callfar;callrom;ceil;cmp;cos;deg;floor;len;ln;log2;lsb;max;memory;min;mkword;msb;peek;peekw;poke;pokew;pop;popw;push;pushw;rad;reverse;rnd;rndf;rndw;rol;rol2;ror;ror2;round;rrestore;rrestorex;rsave;rsavex;sgn;sin;sizeof;sort;sqrt;sqrt16;sum;swap;tan;|>" />
|
||||||
</highlighting>
|
</highlighting>
|
||||||
<extensionMap>
|
<extensionMap>
|
||||||
<mapping ext="p8" />
|
<mapping ext="p8" />
|
||||||
<mapping ext="prog8" />
|
<mapping ext="prog8" />
|
||||||
</extensionMap>
|
</extensionMap>
|
||||||
</filetype>
|
</filetype>
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<Keywords name="Keywords1">void const
str
byte ubyte
word uword
float
zp shared requirezp</Keywords>
|
<Keywords name="Keywords1">void const
str
byte ubyte
word uword
float
zp shared requirezp</Keywords>
|
||||||
<Keywords name="Keywords2">%address
%asm
%asmbinary
%asminclude
%breakpoint
%import
%launcher
%option
%output
%zeropage
%zpreserved</Keywords>
|
<Keywords name="Keywords2">%address
%asm
%asmbinary
%asminclude
%breakpoint
%import
%launcher
%option
%output
%zeropage
%zpreserved</Keywords>
|
||||||
<Keywords name="Keywords3">inline sub asmsub romsub
clobbers
asm
if
when else
if_cc if_cs if_eq if_mi if_neg if_nz if_pl if_pos if_vc if_vs if_z
for in step do while repeat
break return goto</Keywords>
|
<Keywords name="Keywords3">inline sub asmsub romsub
clobbers
asm
if
when else
if_cc if_cs if_eq if_mi if_neg if_nz if_pl if_pos if_vc if_vs if_z
for in step do while repeat
break return goto</Keywords>
|
||||||
<Keywords name="Keywords4">abs acos all any asin atan avg callfar callrom ceil cmp cos cos16 cos16u cos8 cos8u cosr8 cosr8u cosr16 cosr16u deg floor len ln log2 lsb lsl lsr max memory min mkword msb peek peekw poke pokew push pushw pop popw rsave rsavex rrestore rrestorex rad reverse rnd rndf rndw rol rol2 ror ror2 round sgn sin sin16 sin16u sin8 sin8u sinr8 sinr8u sinr16 sinr16u sizeof sort sqrt sqrt16 sum swap tan</Keywords>
|
<Keywords name="Keywords4">abs acos all any asin atan avg callfar callrom ceil cmp cos deg floor len ln log2 lsb lsl lsr max memory min mkword msb peek peekw poke pokew push pushw pop popw rsave rsavex rrestore rrestorex rad reverse rnd rndf rndw rol rol2 ror ror2 round sgn sin sizeof sort sqrt sqrt16 sum swap tan</Keywords>
|
||||||
<Keywords name="Keywords5">true false
not and or xor
as to downto |></Keywords>
|
<Keywords name="Keywords5">true false
not and or xor
as to downto |></Keywords>
|
||||||
<Keywords name="Keywords6"></Keywords>
|
<Keywords name="Keywords6"></Keywords>
|
||||||
<Keywords name="Keywords7"></Keywords>
|
<Keywords name="Keywords7"></Keywords>
|
||||||
|
@ -7,8 +7,8 @@
|
|||||||
" Built-in functions
|
" Built-in functions
|
||||||
|
|
||||||
" Math functions
|
" Math functions
|
||||||
syn keyword prog8BuiltInFunc abs atan ceil cos cos8u cos8 cos16u cos16 cosr8 cosr8u cosr16 cosr16u deg floor
|
syn keyword prog8BuiltInFunc abs atan ceil cos deg floor
|
||||||
syn keyword prog8BuiltInFunc ln log2 rad round sin sgn sin8u sin8 sin16u sin16 sinr8 sinr8u sinr16 sinr16u
|
syn keyword prog8BuiltInFunc ln log2 rad round sin sgn
|
||||||
syn keyword prog8BuiltInFunc sqrt16 sqrt tan
|
syn keyword prog8BuiltInFunc sqrt16 sqrt tan
|
||||||
|
|
||||||
" Array functions
|
" Array functions
|
||||||
|
Loading…
x
Reference in New Issue
Block a user