better pokef() code

This commit is contained in:
Irmen de Jong 2023-11-28 22:50:30 +01:00
parent 8dfa0bc38c
commit 1e299bf360
4 changed files with 54 additions and 22 deletions

View File

@ -3107,6 +3107,17 @@ $repeatLabel""")
return "prog8_label_asm_${generatedLabelSequenceNumber}_$postfix"
}
fun assignConstFloatToPointerAY(number: PtNumber) {
val floatConst = allocator.getFloatAsmConst(number.number)
out("""
pha
lda #<$floatConst
sta P8ZP_SCRATCH_W1
lda #>$floatConst
sta P8ZP_SCRATCH_W1+1
pla
jsr floats.copy_float""")
}
}
/**

View File

@ -767,18 +767,38 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
}
private fun funcPokeF(fcall: PtBuiltinFunctionCall) {
val tempvar = asmgen.getTempVarName(DataType.FLOAT)
asmgen.assignExpressionTo(fcall.args[1],
AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, fcall.definingISub(), fcall.position, tempvar, null, null, null, null))
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
asmgen.out("""
pha
lda #<$tempvar
sta P8ZP_SCRATCH_W1
lda #>$tempvar
sta P8ZP_SCRATCH_W1+1
pla
jsr floats.copy_float""")
when(val number = fcall.args[1]) {
is PtIdentifier -> {
val varName = asmgen.asmVariableName(number)
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
asmgen.out("""
pha
lda #<$varName
sta P8ZP_SCRATCH_W1
lda #>$varName
sta P8ZP_SCRATCH_W1+1
pla
jsr floats.copy_float""")
}
is PtNumber -> {
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
asmgen.assignConstFloatToPointerAY(number)
}
else -> {
val tempvar = asmgen.getTempVarName(DataType.FLOAT)
asmgen.assignExpressionTo(fcall.args[1],
AsmAssignTarget(TargetStorageKind.VARIABLE, asmgen, DataType.FLOAT, fcall.definingISub(), fcall.position, tempvar, null, null, null, null))
asmgen.assignExpressionToRegister(fcall.args[0], RegisterOrPair.AY)
asmgen.out("""
pha
lda #<$tempvar
sta P8ZP_SCRATCH_W1
lda #>$tempvar
sta P8ZP_SCRATCH_W1+1
pla
jsr floats.copy_float""")
}
}
}
private fun funcPokeW(fcall: PtBuiltinFunctionCall) {

View File

@ -28,7 +28,8 @@ romsub $fe00 = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101
romsub $fe03 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
romsub $fe06 = FOUT() clobbers(X) -> uword @ AY ; fac1 -> string, address returned in AY
; romsub $fe09 = VAL_1() clobbers(A,X,Y) ; convert ASCII string to floating point [not yet implemented!!!] see parse_f() instead
; romsub $fe09 = VAL_1() clobbers(A,X,Y) ; convert ASCII string to floating point [not yet implemented!!!] see parse_f() instead.
; once it is supported it works like this: call with "index" zp var ($a9/$aa) contains pointer to string, A = length of string. Float returned in FAC1.
; GETADR: fac1 -> unsigned word in Y/A (might throw ILLEGAL QUANTITY) (result also in $14/15)
; (tip: use GETADRAY to get A/Y output; lo/hi switched to normal little endian order)

View File

@ -1,18 +1,18 @@
%import textio
%import floats
%zeropage basicsafe
main {
sub start() {
uword size1 = sizeof(22222)
txt.print_uw(size1)
poke($4000,123)
txt.print_ub(peek($4000))
txt.nl()
uword size2 = sizeof(2.2)
txt.print_uw(size2)
pokew($4002, 55555)
txt.print_uw(peekw($4002))
txt.nl()
cx16.r0 = sizeof(22222)
txt.print_uw(cx16.r0)
txt.nl()
cx16.r0 = sizeof(2.2)
txt.print_uw(cx16.r0)
float value=123.45678
pokef($4004, value)
floats.print_f(peekf($4004))
txt.nl()
}
}