mirror of
https://github.com/irmen/prog8.git
synced 2025-01-12 19:29:50 +00:00
cleaning up and correcting cc for builtin functions
This commit is contained in:
parent
1eecdd6fa3
commit
aaa20093ef
@ -1243,75 +1243,6 @@ mul_word_100 .proc
|
||||
|
||||
; ----------- end optimized multiplications -----------
|
||||
|
||||
sign_ub_into_A .proc
|
||||
cmp #0
|
||||
bne _pos
|
||||
rts
|
||||
_pos lda #1
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_ub_cc .proc
|
||||
jsr sign_ub_into_A
|
||||
sta P8ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_uw_into_A .proc
|
||||
cpy #0
|
||||
beq _possibly_zero
|
||||
_pos lda #1
|
||||
rts
|
||||
_possibly_zero cmp #0
|
||||
bne _pos
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_uw_cc .proc
|
||||
jsr sign_uw_into_A
|
||||
sta P8ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_b_into_A .proc
|
||||
cmp #0
|
||||
beq _zero
|
||||
bmi _neg
|
||||
lda #1
|
||||
_zero rts
|
||||
_neg lda #-1
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_b_cc .proc
|
||||
jsr sign_b_into_A
|
||||
sta P8ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.pend
|
||||
|
||||
sign_w_into_A .proc
|
||||
cpy #0
|
||||
beq _possibly_zero
|
||||
bmi _neg
|
||||
_pos lda #1
|
||||
rts
|
||||
_neg lda #-1
|
||||
rts
|
||||
_possibly_zero cmp #0
|
||||
bne _pos
|
||||
rts
|
||||
.pend
|
||||
|
||||
|
||||
sign_w_cc .proc
|
||||
jsr sign_w_into_A
|
||||
sta P8ESTACK_LO,x
|
||||
dex
|
||||
rts
|
||||
.pend
|
||||
|
||||
; bit shifts.
|
||||
; anything below 3 is done inline. anything above 7 is done via other optimizations.
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -70,7 +70,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
}
|
||||
"read_flags" -> {
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_read_flags")
|
||||
asmgen.out(" jsr prog8_lib.func_read_flags_stack")
|
||||
else
|
||||
asmgen.out(" php | pla")
|
||||
}
|
||||
@ -83,9 +83,12 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
"memcopy", "memset", "memsetw" -> funcMemSetCopy(fcall, func)
|
||||
"substr", "leftstr", "rightstr" -> {
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}_cc") // TODO
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}")
|
||||
}
|
||||
"exit" -> {
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jmp prog8_lib.func_exit")
|
||||
}
|
||||
"exit" -> asmgen.out(" jmp prog8_lib.func_exit")
|
||||
else -> TODO("missing asmgen for builtin func ${func.name}")
|
||||
}
|
||||
}
|
||||
@ -118,7 +121,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
if((count!=null && count <= 255) || countDt.istype(DataType.UBYTE) || countDt.istype(DataType.BYTE)) {
|
||||
// fast memcopy of up to 255
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jsr prog8_lib.func_memcopy255_cc")
|
||||
asmgen.out(" jsr prog8_lib.func_memcopy255")
|
||||
return
|
||||
}
|
||||
|
||||
@ -142,7 +145,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
}
|
||||
"memsetw" -> {
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jsr prog8_lib.func_memsetw_cc")
|
||||
asmgen.out(" jsr prog8_lib.func_memsetw")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -151,27 +154,27 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val countDt = fcall.args[2].inferType(program)
|
||||
if((count!=null && count <= 255) || countDt.istype(DataType.UBYTE) || countDt.istype(DataType.BYTE)) {
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jsr prog8_lib.func_memcopy255_cc")
|
||||
asmgen.out(" jsr prog8_lib.func_memcopy255")
|
||||
return
|
||||
}
|
||||
}
|
||||
translateArguments(fcall.args, func)
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}_cc")
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}")
|
||||
}
|
||||
}
|
||||
|
||||
private fun funcStrcmp(fcall: IFunctionCall, func: FSignature, resultToStack: Boolean) {
|
||||
translateArguments(fcall.args, func)
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_strcmp_cc") // TODO
|
||||
asmgen.out(" jsr prog8_lib.func_strcmp_stack")
|
||||
else
|
||||
asmgen.out(" jsr prog8_lib.func_strcmp_into_A") // TODO
|
||||
asmgen.out(" jsr prog8_lib.func_strcmp")
|
||||
}
|
||||
|
||||
private fun funcSqrt16(fcall: IFunctionCall, func: FSignature, resultToStack: Boolean) {
|
||||
translateArguments(fcall.args, func)
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_sqrt16")
|
||||
asmgen.out(" jsr prog8_lib.func_sqrt16_stack")
|
||||
else
|
||||
asmgen.out(" jsr prog8_lib.func_sqrt16_into_A")
|
||||
}
|
||||
@ -179,7 +182,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
private fun funcSinCosInt(fcall: IFunctionCall, func: FSignature, resultToStack: Boolean) {
|
||||
translateArguments(fcall.args, func)
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}_cc") // TODO
|
||||
asmgen.out(" jsr prog8_lib.func_${func.name}_stack")
|
||||
else
|
||||
when(func.name) {
|
||||
"sin8", "sin8u", "cos8", "cos8u" -> asmgen.out(" jsr prog8_lib.func_${func.name}_into_A")
|
||||
@ -195,36 +198,31 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val numElements = decl.arraysize!!.constIndex()
|
||||
when (decl.datatype) {
|
||||
DataType.ARRAY_UB, DataType.ARRAY_B -> {
|
||||
// TODO cc
|
||||
asmgen.out("""
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr prog8_lib.reverse_b_cc
|
||||
""")
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr prog8_lib.func_reverse_b""")
|
||||
}
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||
// TODO cc
|
||||
asmgen.out("""
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr prog8_lib.reverse_w_cc
|
||||
""")
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr prog8_lib.func_reverse_w""")
|
||||
}
|
||||
DataType.ARRAY_F -> {
|
||||
asmgen.out("""
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr floats.func_reverse_f
|
||||
""")
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
jsr floats.func_reverse_f""")
|
||||
}
|
||||
else -> throw AssemblyError("weird type")
|
||||
}
|
||||
@ -239,28 +237,22 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val numElements = decl.arraysize!!.constIndex()
|
||||
when (decl.datatype) {
|
||||
DataType.ARRAY_UB, DataType.ARRAY_B -> {
|
||||
// TODO cc
|
||||
asmgen.out("""
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
sta P8ZP_SCRATCH_B1
|
||||
""")
|
||||
asmgen.out(if (decl.datatype == DataType.ARRAY_UB) " jsr prog8_lib.sort_ub_cc" else " jsr prog8_lib.sort_b_cc")
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements""")
|
||||
asmgen.out(if (decl.datatype == DataType.ARRAY_UB) " jsr prog8_lib.func_sort_ub" else " jsr prog8_lib.func_sort_b")
|
||||
}
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> {
|
||||
// TODO cc
|
||||
asmgen.out("""
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements
|
||||
sta P8ZP_SCRATCH_B1
|
||||
""")
|
||||
asmgen.out(if (decl.datatype == DataType.ARRAY_UW) " jsr prog8_lib.sort_uw_cc" else " jsr prog8_lib.sort_w_cc")
|
||||
lda #<$varName
|
||||
ldy #>$varName
|
||||
sta P8ZP_SCRATCH_W1
|
||||
sty P8ZP_SCRATCH_W1+1
|
||||
lda #$numElements""")
|
||||
asmgen.out(if (decl.datatype == DataType.ARRAY_UW) " jsr prog8_lib.func_sort_uw" else " jsr prog8_lib.func_sort_w")
|
||||
}
|
||||
DataType.ARRAY_F -> throw AssemblyError("sorting of floating point array is not supported")
|
||||
else -> throw AssemblyError("weird type")
|
||||
@ -299,9 +291,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UWORD -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.ror2_array_uw")
|
||||
asmgen.out(" jsr prog8_lib.ror2_array_uw_cc")
|
||||
}
|
||||
is IdentifierReference -> {
|
||||
val variable = asmgen.asmVariableName(what)
|
||||
@ -321,15 +314,17 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UBYTE -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.ror_array_ub")
|
||||
asmgen.out(" jsr prog8_lib.ror_array_ub_cc")
|
||||
}
|
||||
is DirectMemoryRead -> {
|
||||
if (what.addressExpression is NumericLiteralValue) {
|
||||
val number = (what.addressExpression as NumericLiteralValue).number
|
||||
asmgen.out(" ror ${number.toHex()}")
|
||||
} else {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.addressExpression)
|
||||
asmgen.out("""
|
||||
inx
|
||||
@ -351,9 +346,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UWORD -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.ror_array_uw")
|
||||
asmgen.out(" jsr prog8_lib.ror_array_uw_cc")
|
||||
}
|
||||
is IdentifierReference -> {
|
||||
val variable = asmgen.asmVariableName(what)
|
||||
@ -373,17 +369,19 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UBYTE -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.rol2_array_ub")
|
||||
asmgen.out(" jsr prog8_lib.rol2_array_ub_cc")
|
||||
}
|
||||
is DirectMemoryRead -> {
|
||||
if (what.addressExpression is NumericLiteralValue) {
|
||||
val number = (what.addressExpression as NumericLiteralValue).number
|
||||
asmgen.out(" lda ${number.toHex()} | cmp #\$80 | rol a | sta ${number.toHex()}")
|
||||
} else {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.addressExpression)
|
||||
asmgen.out(" jsr prog8_lib.rol2_mem_ub")
|
||||
asmgen.out(" jsr prog8_lib.rol2_mem_ub_cc")
|
||||
}
|
||||
}
|
||||
is IdentifierReference -> {
|
||||
@ -396,9 +394,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UWORD -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.rol2_array_uw")
|
||||
asmgen.out(" jsr prog8_lib.rol2_array_uw_cc")
|
||||
}
|
||||
is IdentifierReference -> {
|
||||
val variable = asmgen.asmVariableName(what)
|
||||
@ -418,15 +417,17 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UBYTE -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.rol_array_ub")
|
||||
asmgen.out(" jsr prog8_lib.rol_array_ub_cc")
|
||||
}
|
||||
is DirectMemoryRead -> {
|
||||
if (what.addressExpression is NumericLiteralValue) {
|
||||
val number = (what.addressExpression as NumericLiteralValue).number
|
||||
asmgen.out(" rol ${number.toHex()}")
|
||||
} else {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.addressExpression)
|
||||
asmgen.out("""
|
||||
inx
|
||||
@ -448,9 +449,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
DataType.UWORD -> {
|
||||
when (what) {
|
||||
is ArrayIndexedExpression -> {
|
||||
// TODO cc
|
||||
asmgen.translateExpression(what.arrayvar)
|
||||
asmgen.translateExpression(what.indexer)
|
||||
asmgen.out(" jsr prog8_lib.rol_array_uw")
|
||||
asmgen.out(" jsr prog8_lib.rol_array_uw_cc")
|
||||
}
|
||||
is IdentifierReference -> {
|
||||
val variable = asmgen.asmVariableName(what)
|
||||
@ -476,19 +478,19 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val dt = fcall.args.single().inferType(program)
|
||||
if(resultToStack) {
|
||||
when (dt.typeOrElse(DataType.STRUCT)) {
|
||||
DataType.UBYTE -> asmgen.out(" jsr math.sign_ub_cc")
|
||||
DataType.BYTE -> asmgen.out(" jsr math.sign_b_cc")
|
||||
DataType.UWORD -> asmgen.out(" jsr math.sign_uw_cc")
|
||||
DataType.WORD -> asmgen.out(" jsr math.sign_w_cc")
|
||||
DataType.UBYTE -> asmgen.out(" jsr prog8_lib.func_sign_ub_stack")
|
||||
DataType.BYTE -> asmgen.out(" jsr prog8_lib.func_sign_b_stack")
|
||||
DataType.UWORD -> asmgen.out(" jsr prog8_lib.func_sign_uw_stack")
|
||||
DataType.WORD -> asmgen.out(" jsr prog8_lib.func_sign_w_stack")
|
||||
DataType.FLOAT -> asmgen.out(" jsr floats.func_sign_f_stack")
|
||||
else -> throw AssemblyError("weird type $dt")
|
||||
}
|
||||
} else {
|
||||
when (dt.typeOrElse(DataType.STRUCT)) {
|
||||
DataType.UBYTE -> asmgen.out(" jsr math.sign_ub_into_A")
|
||||
DataType.BYTE -> asmgen.out(" jsr math.sign_b_into_A")
|
||||
DataType.UWORD -> asmgen.out(" jsr math.sign_uw_into_A")
|
||||
DataType.WORD -> asmgen.out(" jsr math.sign_w_into_A")
|
||||
DataType.UBYTE -> asmgen.out(" jsr prog8_lib.func_sign_ub_into_A")
|
||||
DataType.BYTE -> asmgen.out(" jsr prog8_lib.func_sign_b_into_A")
|
||||
DataType.UWORD -> asmgen.out(" jsr prog8_lib.func_sign_uw_into_A")
|
||||
DataType.WORD -> asmgen.out(" jsr prog8_lib.func_sign_w_into_A")
|
||||
DataType.FLOAT -> asmgen.out(" jsr floats.func_sign_f_into_A")
|
||||
else -> throw AssemblyError("weird type $dt")
|
||||
}
|
||||
@ -500,8 +502,8 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val dt = fcall.args.single().inferType(program)
|
||||
if(resultToStack) {
|
||||
when (dt.typeOrElse(DataType.STRUCT)) {
|
||||
DataType.ARRAY_B, DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_${function.name}_b_cc")
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${function.name}_w_cc")
|
||||
DataType.ARRAY_B, DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_${function.name}_b_stack")
|
||||
DataType.ARRAY_UW, DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${function.name}_w_stack")
|
||||
DataType.ARRAY_F -> asmgen.out(" jsr floats.func_${function.name}_f_stack")
|
||||
else -> throw AssemblyError("weird type $dt")
|
||||
}
|
||||
@ -520,10 +522,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val dt = fcall.args.single().inferType(program)
|
||||
if(resultToStack) {
|
||||
when (dt.typeOrElse(DataType.STRUCT)) {
|
||||
DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_${function.name}_ub_cc")
|
||||
DataType.ARRAY_B -> asmgen.out(" jsr prog8_lib.func_${function.name}_b_cc")
|
||||
DataType.ARRAY_UW -> asmgen.out(" jsr prog8_lib.func_${function.name}_uw_cc")
|
||||
DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${function.name}_w_cc")
|
||||
DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_${function.name}_ub_stack")
|
||||
DataType.ARRAY_B -> asmgen.out(" jsr prog8_lib.func_${function.name}_b_stack")
|
||||
DataType.ARRAY_UW -> asmgen.out(" jsr prog8_lib.func_${function.name}_uw_stack")
|
||||
DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_${function.name}_w_stack")
|
||||
DataType.ARRAY_F -> asmgen.out(" jsr floats.func_${function.name}_f_stack")
|
||||
else -> throw AssemblyError("weird type $dt")
|
||||
}
|
||||
@ -544,10 +546,10 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val dt = fcall.args.single().inferType(program)
|
||||
if(resultToStack) {
|
||||
when (dt.typeOrElse(DataType.STRUCT)) {
|
||||
DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_sum_ub_cc")
|
||||
DataType.ARRAY_B -> asmgen.out(" jsr prog8_lib.func_sum_b_cc")
|
||||
DataType.ARRAY_UW -> asmgen.out(" jsr prog8_lib.func_sum_uw_cc")
|
||||
DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_sum_w_cc")
|
||||
DataType.ARRAY_UB, DataType.STR -> asmgen.out(" jsr prog8_lib.func_sum_ub_stack")
|
||||
DataType.ARRAY_B -> asmgen.out(" jsr prog8_lib.func_sum_b_stack")
|
||||
DataType.ARRAY_UW -> asmgen.out(" jsr prog8_lib.func_sum_uw_stack")
|
||||
DataType.ARRAY_W -> asmgen.out(" jsr prog8_lib.func_sum_w_stack")
|
||||
DataType.ARRAY_F -> asmgen.out(" jsr floats.func_sum_f_stack")
|
||||
else -> throw AssemblyError("weird type $dt")
|
||||
}
|
||||
@ -567,18 +569,14 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val name = asmgen.asmVariableName(fcall.args[0] as IdentifierReference)
|
||||
val type = fcall.args[0].inferType(program)
|
||||
when {
|
||||
type.istype(DataType.STR) -> {
|
||||
asmgen.out(" lda #<$name | ldy #>$name | jsr prog8_lib.strlen")
|
||||
if(resultToStack)
|
||||
asmgen.out(" sta P8ESTACK_LO,x | dex")
|
||||
}
|
||||
type.istype(DataType.UWORD) -> {
|
||||
asmgen.out(" lda $name | ldy $name+1 | jsr prog8_lib.strlen")
|
||||
if(resultToStack)
|
||||
asmgen.out(" sta P8ESTACK_LO,x | dex")
|
||||
}
|
||||
type.istype(DataType.STR) -> asmgen.out(" lda #<$name | ldy #>$name")
|
||||
type.istype(DataType.UWORD) -> asmgen.out(" lda $name | ldy $name+1")
|
||||
else -> throw AssemblyError("strlen requires str or uword arg")
|
||||
}
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_strlen_stack")
|
||||
else
|
||||
asmgen.out(" jsr prog8_lib.func_strlen_into_A")
|
||||
}
|
||||
|
||||
private fun funcSwap(fcall: IFunctionCall) {
|
||||
@ -943,15 +941,15 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val dt = fcall.args.single().inferType(program).typeOrElse(DataType.STRUCT)
|
||||
if(resultToStack) {
|
||||
when (dt) {
|
||||
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.abs_b_cc")
|
||||
in WordDatatypes -> asmgen.out(" jsr prog8_lib.abs_w_cc")
|
||||
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.abs_b_stack")
|
||||
in WordDatatypes -> asmgen.out(" jsr prog8_lib.abs_w_stack")
|
||||
DataType.FLOAT -> asmgen.out(" jsr floats.abs_f_stack")
|
||||
else -> throw AssemblyError("weird type")
|
||||
}
|
||||
} else {
|
||||
when (dt) {
|
||||
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.abs_b_into_A_cc")
|
||||
in WordDatatypes -> asmgen.out(" jsr prog8_lib.abs_w_into_AY_cc")
|
||||
in ByteDatatypes -> asmgen.out(" jsr prog8_lib.abs_b_into_A")
|
||||
in WordDatatypes -> asmgen.out(" jsr prog8_lib.abs_w_into_AY")
|
||||
DataType.FLOAT -> asmgen.out(" jsr floats.abs_f_fac1")
|
||||
else -> throw AssemblyError("weird type")
|
||||
}
|
||||
@ -962,13 +960,13 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
when(func.name) {
|
||||
"rnd" -> {
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_rnd")
|
||||
asmgen.out(" jsr prog8_lib.func_rnd_stack")
|
||||
else
|
||||
asmgen.out(" jsr math.randbyte")
|
||||
}
|
||||
"rndw" -> {
|
||||
if(resultToStack)
|
||||
asmgen.out(" jsr prog8_lib.func_rndw")
|
||||
asmgen.out(" jsr prog8_lib.func_rndw_stack")
|
||||
else
|
||||
asmgen.out(" jsr math.randword")
|
||||
}
|
||||
@ -1080,7 +1078,7 @@ internal class BuiltinFunctionsAsmGen(private val program: Program, private val
|
||||
val value = it.first.first
|
||||
when {
|
||||
conv.variable -> {
|
||||
val varname = "prog8_lib.func_${signature.name}_cc._arg_${paramName}" // TODO after all builtin funcs have been changed into _cc, remove that suffix again
|
||||
val varname = "prog8_lib.func_${signature.name}._arg_${paramName}"
|
||||
val src = when (conv.dt) {
|
||||
DataType.FLOAT -> getSourceForFloat(value)
|
||||
in PassByReferenceDatatypes -> {
|
||||
|
@ -785,11 +785,13 @@ memsetw(address, numwords, wordvalue)
|
||||
leftstr(source, target, length)
|
||||
Copies the left side of the source string of the given length to target string.
|
||||
It is assumed the target string buffer is large enough to contain the result.
|
||||
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||
|
||||
rightstr(source, target, length)
|
||||
Copies the right side of the source string of the given length to target string.
|
||||
It is assumed the target string buffer is large enough to contain the result.
|
||||
Also, you have to make sure yourself that length is smaller or equal to the length of the source string.
|
||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||
|
||||
strlen(str)
|
||||
@ -806,6 +808,7 @@ substr(source, target, start, length)
|
||||
Copies a segment from the source string, starting at the given index,
|
||||
and of the given length to target string.
|
||||
It is assumed the target string buffer is large enough to contain the result.
|
||||
Also, you have to make sure yourself that start and length are within bounds of the strings.
|
||||
Modifies in-place, doesn't return a value (so can't be used in an expression).
|
||||
|
||||
Miscellaneous
|
||||
|
441
examples/test.p8
441
examples/test.p8
@ -4,92 +4,415 @@
|
||||
%zeropage basicsafe
|
||||
|
||||
; builtin functions converted to new call convention:
|
||||
;
|
||||
; all functions operating on floating-point and fp arrays.
|
||||
;
|
||||
; mkword
|
||||
; lsb
|
||||
; msb
|
||||
; swap
|
||||
|
||||
; abs
|
||||
; sgn
|
||||
; sqrt16
|
||||
; rnd, rndw
|
||||
; sin8, sin8u, cos8, cos8u
|
||||
; sin16, sin16u, cos16, cos16u
|
||||
; max, min
|
||||
; any, all
|
||||
; sum
|
||||
; sort
|
||||
; reverse
|
||||
|
||||
; exit
|
||||
; read_flags
|
||||
; memset, memsetw, memcopy
|
||||
; leftstr, rightstr, substr
|
||||
; strlen, strcmp
|
||||
|
||||
; TODO: in-place rols and rors
|
||||
|
||||
main {
|
||||
|
||||
sub start() {
|
||||
ubyte[] barr = [1,2,3,4,5,0,4,3,2,1]
|
||||
const uword ADDR = $0400
|
||||
const uword ADDR2 = $4000
|
||||
|
||||
; memset(ADDR2, 40*25, '*')
|
||||
; memset(ADDR2, 40, '1')
|
||||
; memset(ADDR2+24*40, 39, '2')
|
||||
; memsetw(ADDR2, 40*25/2, $3132)
|
||||
; memsetw(ADDR2, 20, $4142)
|
||||
; memsetw(ADDR2+24*40, 19, $4241)
|
||||
; memcopy(ADDR2, ADDR, 200)
|
||||
|
||||
str result = "." *10
|
||||
str s1 = "irmen"
|
||||
str s2 = "hello"
|
||||
|
||||
ubyte ub
|
||||
byte bb
|
||||
ubyte zero=0
|
||||
|
||||
|
||||
|
||||
bb = strcmp(s1, s2)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
txt.print_ub(s1==s2)
|
||||
txt.chrout('\n')
|
||||
txt.print_ub(s1<s2)
|
||||
txt.chrout('\n')
|
||||
bb = zero+strcmp(s1,s2)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
|
||||
ub = strlen(s1)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+strlen(s1)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
leftstr(s1, result, 3)
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
leftstr(s1, result, len(s1))
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
|
||||
result = "."*10 ; TODO doesn't work??
|
||||
rightstr(s2, result, 3)
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
rightstr(s2, result, len(s1))
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
|
||||
result = "."*10 ; TODO doesn't work??
|
||||
substr(s2, result, 1, 3)
|
||||
txt.print(result)
|
||||
txt.chrout('\n')
|
||||
|
||||
testX()
|
||||
|
||||
}
|
||||
|
||||
sub integers() {
|
||||
ubyte[] ubarr = [1,2,3,4,5,0,4,3,2,1, 255, 255, 255]
|
||||
byte[] barr = [1,2,3,4,5,-4,0,-3,2,1, -128, -128, -127]
|
||||
uword[] uwarr = [100,200,300,400,0,500,400,300,200,100]
|
||||
word[] warr = [100,200,300,400,500,0,-400,-300,200,100,-99, -4096]
|
||||
|
||||
ubyte zero=0
|
||||
ubyte ub
|
||||
ubyte ub2
|
||||
byte bb
|
||||
uword uw
|
||||
word ww
|
||||
|
||||
ub = $fe
|
||||
ub2 = $34
|
||||
uw = mkword(ub, ub2)
|
||||
txt.print_uwhex(uw, true)
|
||||
txt.chrout('\n')
|
||||
uw = zero+mkword(ub, ub2)*1+zero
|
||||
txt.print_uwhex(uw, true)
|
||||
txt.chrout('\n')
|
||||
repeat(20) {
|
||||
txt.chrout('\n')
|
||||
}
|
||||
|
||||
uw = $fe34
|
||||
ub = msb(uw)
|
||||
txt.print_ubhex(ub, true)
|
||||
ub = read_flags()
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+msb(uw)*1+zero
|
||||
txt.print_ubhex(ub, true)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = $fe34
|
||||
ub = lsb(uw)
|
||||
txt.print_ubhex(ub, true)
|
||||
txt.chrout('\n')
|
||||
ub = zero+lsb(uw)*1+zero
|
||||
txt.print_ubhex(ub, true)
|
||||
ub = zero+read_flags()*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
|
||||
ub = rnd()
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+rnd()*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = rndw()
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+rndw()*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
|
||||
; ub = min(barr)
|
||||
;
|
||||
; ub = zero+min(barr)*1+zero
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = max(barr)
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = zero+max(barr)*1+zero
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; uw = sum(barr)
|
||||
; txt.print_uw(uw)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; uw = zero+sum(barr)*1+zero
|
||||
; txt.print_uw(uw)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = any(barr)
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = zero+any(barr)*1
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = all(barr)
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
;
|
||||
; ub = zero+all(barr)*1
|
||||
; txt.print_ub(ub)
|
||||
; txt.chrout('\n')
|
||||
uw = 50000
|
||||
ub = sqrt16(uw)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+sqrt16(uw)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
bb = -100
|
||||
bb = sgn(bb)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = -100
|
||||
bb = zero+sgn(bb)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = 100
|
||||
bb = sgn(ub)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
ub = 100
|
||||
bb = zero+sgn(ub)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = -1000
|
||||
bb = sgn(ww)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+sgn(ww)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = 1000
|
||||
bb = sgn(uw)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+sgn(uw)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = 0
|
||||
uw = sin16u(ub)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+sin16u(ub)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = 0
|
||||
uw = cos16u(ub)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+cos16u(ub)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = 0
|
||||
ww = sin16(ub)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = zero+sin16(ub)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = 0
|
||||
ww = cos16(ub)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
uw = 0
|
||||
ww = zero+cos16(ub)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub2 = 0
|
||||
ub = sin8u(ub2)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+sin8u(ub2)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub2 = 0
|
||||
ub = cos8u(ub2)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+cos8u(ub2)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub2 = 0
|
||||
bb = sin8(ub2)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+sin8(ub2)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub2 = 0
|
||||
bb = cos8(ub2)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+cos8(ub2)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
bb = -100
|
||||
bb = abs(bb)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = -100
|
||||
bb = zero+abs(bb)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = -1000
|
||||
ww = abs(ww)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = -1000
|
||||
ww = zero+abs(ww)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = min(ubarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+min(ubarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
bb = min(barr)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+min(barr)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = min(uwarr)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+min(uwarr)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = min(warr)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = zero+min(warr)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = max(ubarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+max(ubarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
bb = max(barr)
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
bb = zero+max(barr)*1+zero
|
||||
txt.print_b(bb)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = max(uwarr)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+max(uwarr)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = max(warr)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = zero+max(warr)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = any(ubarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+any(ubarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = any(barr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+any(barr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = any(uwarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+any(uwarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = any(warr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+any(warr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = all(ubarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+all(ubarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = all(barr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+all(barr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = all(uwarr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+all(uwarr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
ub = all(warr)
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
ub = zero+all(warr)*1+zero
|
||||
txt.print_ub(ub)
|
||||
txt.chrout('\n')
|
||||
|
||||
|
||||
uw = sum(ubarr)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+sum(ubarr)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = sum(barr)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = zero+sum(barr)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
uw = sum(uwarr)
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
uw = zero+sum(uwarr)*1+zero
|
||||
txt.print_uw(uw)
|
||||
txt.chrout('\n')
|
||||
|
||||
ww = sum(warr)
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
ww = zero+sum(warr)*1+zero
|
||||
txt.print_w(ww)
|
||||
txt.chrout('\n')
|
||||
|
||||
sort(ubarr)
|
||||
sort(barr)
|
||||
sort(uwarr)
|
||||
sort(warr)
|
||||
reverse(ubarr)
|
||||
reverse(barr)
|
||||
reverse(uwarr)
|
||||
reverse(warr)
|
||||
|
||||
testX()
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user