diff --git a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt index 00ff0c12c..7a29e3b23 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/assignment/AugmentableAssignmentAsmGen.kt @@ -235,46 +235,61 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, println("warning: slow stack evaluation used (2): $name $operator= ${value::class.simpleName} at ${value.position}") // TODO asmgen.translateExpression(value) when (operator) { - "**" -> TODO("pow") + "**" -> { + asmgen.out(""" + jsr c64flt.pop_float_fac1 + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.CONUPK + jsr c64flt.FPWRT + """) + } "+" -> { asmgen.out(""" - jsr c64flt.pop_float_fac1 - stx P8ZP_SCRATCH_REG_X - lda #<$name - ldy #>$name - jsr c64flt.FADD - ldx #<$name - ldy #>$name - jsr c64flt.MOVMF - ldx P8ZP_SCRATCH_REG_X - """) + jsr c64flt.pop_float_fac1 + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.FADD + """) } "-" -> { asmgen.out(""" - jsr c64flt.pop_float_fac1 - stx P8ZP_SCRATCH_REG_X - lda #<$name - ldy #>$name - jsr c64flt.FSUB - ldx #<$name - ldy #>$name - jsr c64flt.MOVMF - ldx P8ZP_SCRATCH_REG_X - """) + jsr c64flt.pop_float_fac1 + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.FSUB + """) + } + "*" -> { + asmgen.out(""" + jsr c64flt.pop_float_fac1 + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.FMULT + """) } - "*" -> TODO("mul")// asmgen.out(" jsr prog8_lib.mul_byte") // the optimized routines should have been checked earlier "/" -> { - TODO("div") - // asmgen.out(if(types==DataType.UBYTE) " jsr prog8_lib.idiv_ub" else " jsr prog8_lib.idiv_b") - } - "%" -> { - TODO("float remainder???") -// if(types==DataType.BYTE) -// throw AssemblyError("remainder of signed integers is not properly defined/implemented, use unsigned instead") -// asmgen.out(" jsr prog8_lib.remainder_ub") + asmgen.out(""" + jsr c64flt.pop_float_fac1 + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.FDIV + """) } else -> throw AssemblyError("invalid operator for in-place float modification $operator") } + // store Fac1 back into memory + asmgen.out(""" + ldx #<$name + ldy #>$name + jsr c64flt.MOVMF + ldx P8ZP_SCRATCH_REG_X + """) } private fun inplaceModification_float_variable_to_variable(name: String, operator: String, ident: IdentifierReference) { @@ -284,81 +299,145 @@ internal class AugmentableAssignmentAsmGen(private val program: Program, val otherName = asmgen.asmVariableName(ident) when (operator) { - "**" -> TODO("pow") - "+" -> TODO("+") - "-" -> TODO("-") + "**" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.CONUPK + lda #<$otherName + ldy #>$otherName + jsr c64flt.FPWR + """) + } + "+" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.MOVFM + lda #<$otherName + ldy #>$otherName + jsr c64flt.FADD + """) + } + "-" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$otherName + ldy #>$otherName + jsr c64flt.MOVFM + lda #<$name + ldy #>$name + jsr c64flt.FSUB + """) + } "*" -> { asmgen.out(""" - stx P8ZP_SCRATCH_REG_X - lda #<$name - ldy #>$name - jsr c64flt.MOVFM - lda #<$otherName - ldy #>$otherName - jsr c64flt.FMULT - ldx #<$name - ldy #>$name - jsr c64flt.MOVMF - ldx P8ZP_SCRATCH_REG_X - """) + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.MOVFM + lda #<$otherName + ldy #>$otherName + jsr c64flt.FMULT + """) + } + "/" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$otherName + ldy #>$otherName + jsr c64flt.MOVFM + lda #<$name + ldy #>$name + jsr c64flt.FDIV + """) } - "/" -> TODO("div") - "%" -> TODO("float remainder???") else -> throw AssemblyError("invalid operator for in-place float modification $operator") } + // store Fac1 back into memory + asmgen.out(""" + ldx #<$name + ldy #>$name + jsr c64flt.MOVMF + ldx P8ZP_SCRATCH_REG_X + """) } private fun inplaceModification_float_litval_to_variable(name: String, operator: String, value: Double) { val constValueName = asmgen.getFloatAsmConst(value) when (operator) { - "**" -> TODO("pow") + "**" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.CONUPK + lda #<$constValueName + ldy #>$constValueName + jsr c64flt.FPWR + """) + } "+" -> { if (value == 0.0) return asmgen.out(""" - stx P8ZP_SCRATCH_REG_X - lda #<$name - ldy #>$name - jsr c64flt.MOVFM - lda #<$constValueName - ldy #>$constValueName - jsr c64flt.FADD - ldx #<$name - ldy #>$name - jsr c64flt.MOVMF - ldx P8ZP_SCRATCH_REG_X - """) + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.MOVFM + lda #<$constValueName + ldy #>$constValueName + jsr c64flt.FADD + """) } "-" -> { if (value == 0.0) return asmgen.out(""" - stx P8ZP_SCRATCH_REG_X - lda #<$constValueName - ldy #>$constValueName - jsr c64flt.MOVFM - lda #<$name - ldy #>$name - jsr c64flt.FSUB - ldx #<$name - ldy #>$name - jsr c64flt.MOVMF - ldx P8ZP_SCRATCH_REG_X - """) + stx P8ZP_SCRATCH_REG_X + lda #<$constValueName + ldy #>$constValueName + jsr c64flt.MOVFM + lda #<$name + ldy #>$name + jsr c64flt.FSUB + """) + } + "*" -> { + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$name + ldy #>$name + jsr c64flt.MOVFM + lda #<$constValueName + ldy #>$constValueName + jsr c64flt.FMULT + """) } - "*" -> TODO("mul") "/" -> { if (value == 0.0) throw AssemblyError("division by zero") - TODO("div") - } - "%" -> { - if (value == 0.0) - throw AssemblyError("division by zero") - TODO("float remainder???") + asmgen.out(""" + stx P8ZP_SCRATCH_REG_X + lda #<$constValueName + ldy #>$constValueName + jsr c64flt.MOVFM + lda #<$name + ldy #>$name + jsr c64flt.FDIV + """) } else -> throw AssemblyError("invalid operator for in-place float modification $operator") } + // store Fac1 back into memory + asmgen.out(""" + ldx #<$name + ldy #>$name + jsr c64flt.MOVMF + ldx P8ZP_SCRATCH_REG_X + """) } private fun inplaceModification_byte_value_to_memory(pointervar: IdentifierReference, operator: String, value: Expression) { diff --git a/examples/arithmetic/minus.p8 b/examples/arithmetic/minus.p8 index fcc560410..520ac9192 100644 --- a/examples/arithmetic/minus.p8 +++ b/examples/arithmetic/minus.p8 @@ -2,8 +2,6 @@ %import c64textio %zeropage basicsafe -; TODO implement float MINUS asm generation - main { sub start() { diff --git a/examples/arithmetic/plus.p8 b/examples/arithmetic/plus.p8 index 15fb0d4a1..577f4195d 100644 --- a/examples/arithmetic/plus.p8 +++ b/examples/arithmetic/plus.p8 @@ -2,8 +2,6 @@ %import c64textio %zeropage basicsafe -; TODO implement float PLUS asm generation - main { sub start() { diff --git a/examples/test.p8 b/examples/test.p8 new file mode 100644 index 000000000..83ba84883 --- /dev/null +++ b/examples/test.p8 @@ -0,0 +1,15 @@ +%import c64flt +%zeropage basicsafe + +main { + sub start() { + float f1 = 2.2 + float f2 = 1.0 + float f4 = 4.0 + float f5 = 5.0 + + f1 /= f2+f4 + c64flt.print_f(f1) + c64.CHROUT('\n') + } +}