mirror of
https://github.com/irmen/prog8.git
synced 2024-12-23 09:32:43 +00:00
better pokef() code
This commit is contained in:
parent
8dfa0bc38c
commit
1e299bf360
@ -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""")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -767,6 +767,24 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
||||
}
|
||||
|
||||
private fun funcPokeF(fcall: PtBuiltinFunctionCall) {
|
||||
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))
|
||||
@ -780,6 +798,8 @@ internal class BuiltinFunctionsAsmGen(private val program: PtProgram,
|
||||
pla
|
||||
jsr floats.copy_float""")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun funcPokeW(fcall: PtBuiltinFunctionCall) {
|
||||
when(val addrExpr = fcall.args[0]) {
|
||||
|
@ -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)
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user