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 dey
cmp #0 cmp #0
beq + beq +
cpy #255 cpy #255
bne - bne -
lda #1 lda #1
sta c64.ESTACK_LO+1,x sta c64.ESTACK_LO+1,x
rts rts
@ -739,3 +739,45 @@ sign_f .proc
dex dex
rts rts
.pend .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 { } else {
asmgen.translateExpression(index) asmgen.translateExpression(index)
asmgen.out(""" asmgen.out("""
inx lda #<${targetName}
lda $ESTACK_LO_HEX,x sta ${C64Zeropage.SCRATCH_W1}
asl a lda #>${targetName}
asl a sta ${C64Zeropage.SCRATCH_W1 + 1}
clc jsr c64flt.set_0_array_float
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
} }
} }
else -> throw AssemblyError("no asm gen for assign float 0.0 to $target") 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 { } else {
asmgen.translateArrayIndexIntoA(targetArrayIdx) asmgen.translateArrayIndexIntoA(targetArrayIdx)
asmgen.out(""" asmgen.out("""
sta ${C64Zeropage.SCRATCH_REG} lda #<${constFloat}
asl a sta ${C64Zeropage.SCRATCH_W1}
asl a lda #>${constFloat}
clc sta ${C64Zeropage.SCRATCH_W1 + 1}
adc ${C64Zeropage.SCRATCH_REG} lda #<${arrayVarName}
tay sta ${C64Zeropage.SCRATCH_W2}
lda $constFloat lda #>${arrayVarName}
sta $arrayVarName,y sta ${C64Zeropage.SCRATCH_W2 + 1}
lda $constFloat+1 jsr c64flt.set_array_float
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
} }
} }
else -> throw AssemblyError("no asm gen for assign float $float to $target") 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 -> { is RegisterExpr -> {
// TODO optimize common cases
asmgen.translateArrayIndexIntoA(targetArrayIdx) asmgen.translateArrayIndexIntoA(targetArrayIdx)
incrDecrArrayvalueWithIndexA(incr, arrayDt, what) incrDecrArrayvalueWithIndexA(incr, arrayDt, what)
} }
is IdentifierReference -> { is IdentifierReference -> {
// TODO optimize common cases
asmgen.translateArrayIndexIntoA(targetArrayIdx) asmgen.translateArrayIndexIntoA(targetArrayIdx)
incrDecrArrayvalueWithIndexA(incr, arrayDt, what) incrDecrArrayvalueWithIndexA(incr, arrayDt, what)
} }
else -> { else -> {
// TODO optimize common cases
asmgen.translateArrayIndexIntoA(targetArrayIdx) asmgen.translateArrayIndexIntoA(targetArrayIdx)
incrDecrArrayvalueWithIndexA(incr, arrayDt, what) incrDecrArrayvalueWithIndexA(incr, arrayDt, what)
} }

View File

@ -1,9 +1,20 @@
%import c64lib %import c64lib
%import c64utils %import c64utils
%import c64flt
%zeropage basicsafe
main { main {
sub start() { 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])
} }
} }