mirror of
https://github.com/irmen/prog8.git
synced 2025-08-05 06:28:20 +00:00
fix C64 floating point sign issue
This commit is contained in:
@@ -175,17 +175,14 @@ internal class AnyExprAsmGen(
|
||||
private fun assignFloatOperandsToFACandARG(left: PtExpression, right: PtExpression) {
|
||||
when(asmgen.options.compTarget.name) {
|
||||
C64Target.NAME -> {
|
||||
// c64 has a quirk: always make sure FAC2 is loaded last (done using CONUPK) otherwise the result will be corrupt on C64
|
||||
// this requires some more forced copying around of float values in certain cases
|
||||
if (right.isSimple()) {
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1, true)
|
||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.FAC2, true)
|
||||
} else {
|
||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.FAC1, true)
|
||||
asmgen.pushFAC1()
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1, true)
|
||||
asmgen.popFAC2()
|
||||
}
|
||||
// C64 math library has a quirk: you have always make sure FAC2/ARG is loaded last (done using CONUPK)
|
||||
// otherwise the result of certain floating point operations such as FDIVT will be wrong.
|
||||
// see https://www.c64-wiki.com/wiki/CONUPK
|
||||
// Unfortunately this means we have to push and pop an intermediary floating point value to and from memory.
|
||||
asmgen.assignExpressionToRegister(right, RegisterOrPair.FAC1, true)
|
||||
asmgen.pushFAC1()
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1, true)
|
||||
asmgen.popFAC2()
|
||||
}
|
||||
Cx16Target.NAME -> {
|
||||
asmgen.assignExpressionToRegister(left, RegisterOrPair.FAC1, true)
|
||||
|
@@ -1,19 +1,22 @@
|
||||
%import textio
|
||||
%import floats
|
||||
%zeropage basicsafe
|
||||
%option no_sysinit
|
||||
|
||||
main {
|
||||
sub start() {
|
||||
cx16.r0L = returns3()
|
||||
cx16.r0L, cx16.r1L, cx16.r2L, cx16.r3L = returns3()
|
||||
txt.print_uwhex()
|
||||
txt.print_uwhex(1, true, 2, 3)
|
||||
}
|
||||
word x1 = -118
|
||||
floats.print(x1 as float)
|
||||
txt.nl()
|
||||
floats.print(x1 as float/1.9)
|
||||
txt.nl()
|
||||
xf1 = x1/1.9
|
||||
floats.print(xf1)
|
||||
txt.nl()
|
||||
|
||||
asmsub returns3() -> ubyte @A, ubyte @X, bool @Pc {
|
||||
%asm {{
|
||||
rts
|
||||
}}
|
||||
float @shared xf1 = -118
|
||||
floats.print(xf1/1.9)
|
||||
txt.nl()
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user