From a6bee6a8602fef29e59086951a77a36247ae5eb1 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Fri, 3 Apr 2020 22:44:10 +0200 Subject: [PATCH] some slight tweaks to asm for setting float value in array --- compiler/res/prog8lib/c64floats.asm | 46 +++++++++++++++++- .../target/c64/codegen/AssignmentAsmGen.kt | 47 +++++++------------ .../target/c64/codegen/PostIncrDecrAsmGen.kt | 3 -- examples/test.p8 | 11 +++++ 4 files changed, 71 insertions(+), 36 deletions(-) diff --git a/compiler/res/prog8lib/c64floats.asm b/compiler/res/prog8lib/c64floats.asm index cf2197c48..cc751f333 100644 --- a/compiler/res/prog8lib/c64floats.asm +++ b/compiler/res/prog8lib/c64floats.asm @@ -658,8 +658,8 @@ func_all_f .proc dey cmp #0 beq + - cpy #255 - bne - + cpy #255 + bne - lda #1 sta c64.ESTACK_LO+1,x rts @@ -739,3 +739,45 @@ sign_f .proc dex rts .pend + + +set_0_array_float .proc + ; -- set a float in an array to zero (index on stack, array in SCRATCH_ZPWORD1) + inx + lda c64.ESTACK_LO,x + asl a + asl a + clc + adc c64.ESTACK_LO,x + tay + lda #0 + sta (c64.SCRATCH_ZPWORD1),y + iny + sta (c64.SCRATCH_ZPWORD1),y + iny + sta (c64.SCRATCH_ZPWORD1),y + iny + sta (c64.SCRATCH_ZPWORD1),y + iny + sta (c64.SCRATCH_ZPWORD1),y + rts + .pend + + +set_array_float .proc + ; -- set a float in an array to a value (index on stack, float in SCRATCH_ZPWORD1, array in SCRATCH_ZPWORD2) + inx + lda c64.ESTACK_LO,x + asl a + asl a + clc + adc c64.ESTACK_LO,x + clc + adc c64.SCRATCH_ZPWORD2 + ldy c64.SCRATCH_ZPWORD2+1 + bcc + + iny ++ jmp copy_float + ; -- copies the 5 bytes of the mflt value pointed to by SCRATCH_ZPWORD1, + ; into the 5 bytes pointed to by A/Y. Clobbers A,Y. + .pend diff --git a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt index dde640a45..a7f0b1cdd 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/AssignmentAsmGen.kt @@ -575,20 +575,12 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen } else { asmgen.translateExpression(index) asmgen.out(""" - inx - lda $ESTACK_LO_HEX,x - asl a - asl a - clc - adc $ESTACK_LO_HEX,x - tay - lda #0 - sta $targetName,y - sta $targetName+1,y - sta $targetName+2,y - sta $targetName+3,y - sta $targetName+4,y - """) // TODO use a subroutine for this + lda #<${targetName} + sta ${C64Zeropage.SCRATCH_W1} + lda #>${targetName} + sta ${C64Zeropage.SCRATCH_W1 + 1} + jsr c64flt.set_0_array_float + """) } } else -> throw AssemblyError("no asm gen for assign float 0.0 to $target") @@ -632,23 +624,16 @@ internal class AssignmentAsmGen(private val program: Program, private val asmgen } else { asmgen.translateArrayIndexIntoA(targetArrayIdx) asmgen.out(""" - sta ${C64Zeropage.SCRATCH_REG} - asl a - asl a - clc - adc ${C64Zeropage.SCRATCH_REG} - tay - lda $constFloat - sta $arrayVarName,y - lda $constFloat+1 - sta $arrayVarName+1,y - lda $constFloat+2 - sta $arrayVarName+2,y - lda $constFloat+3 - sta $arrayVarName+3,y - lda $constFloat+4 - sta $arrayVarName+4,y - """) // TODO use a subroutine for this + lda #<${constFloat} + sta ${C64Zeropage.SCRATCH_W1} + lda #>${constFloat} + sta ${C64Zeropage.SCRATCH_W1 + 1} + lda #<${arrayVarName} + sta ${C64Zeropage.SCRATCH_W2} + lda #>${arrayVarName} + sta ${C64Zeropage.SCRATCH_W2 + 1} + jsr c64flt.set_array_float + """) } } else -> throw AssemblyError("no asm gen for assign float $float to $target") diff --git a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt index 4b17b4790..d4273bfd8 100644 --- a/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt +++ b/compiler/src/prog8/compiler/target/c64/codegen/PostIncrDecrAsmGen.kt @@ -104,17 +104,14 @@ internal class PostIncrDecrAsmGen(private val program: Program, private val asmg } } is RegisterExpr -> { - // TODO optimize common cases asmgen.translateArrayIndexIntoA(targetArrayIdx) incrDecrArrayvalueWithIndexA(incr, arrayDt, what) } is IdentifierReference -> { - // TODO optimize common cases asmgen.translateArrayIndexIntoA(targetArrayIdx) incrDecrArrayvalueWithIndexA(incr, arrayDt, what) } else -> { - // TODO optimize common cases asmgen.translateArrayIndexIntoA(targetArrayIdx) incrDecrArrayvalueWithIndexA(incr, arrayDt, what) } diff --git a/examples/test.p8 b/examples/test.p8 index 742945455..8a150e20c 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,9 +1,20 @@ %import c64lib %import c64utils +%import c64flt +%zeropage basicsafe main { sub start() { + float[] floats = [1.1, 2.2] + ubyte index=1 + + c64flt.print_f(floats[0]) + c64flt.print_f(floats[1]) + floats[0] = 9.99 + floats[index] = 8.88 + c64flt.print_f(floats[0]) + c64flt.print_f(floats[1]) } }