some slight tweaks to asm for setting float value in array

This commit is contained in:
Irmen de Jong 2020-04-03 22:44:10 +02:00
parent d22780ee44
commit a6bee6a860
4 changed files with 71 additions and 36 deletions

View File

@ -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

View File

@ -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")

View File

@ -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)
}

View File

@ -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])
}
}