From 6c8b18ddbdc79fc0d81a4fad04e618cf68862660 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 28 Dec 2020 00:19:58 +0100 Subject: [PATCH] fixed crash on cx16 in word to float conversion --- compiler/res/prog8lib/cx16/floats.p8 | 8 ++++---- examples/test.p8 | 11 ++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index 60867ad1d..bcd521897 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -99,9 +99,9 @@ _flt65536 .byte 145,0,0,0,0 ; 65536.0 asmsub GIVAYFAY (uword value @ AY) clobbers(A,X,Y) { ; ---- signed 16 bit word in A/Y (lo/hi) to float in fac1 %asm {{ - sta P8ZP_SCRATCH_W2 + sta P8ZP_SCRATCH_B1 tya - ldy P8ZP_SCRATCH_W2 + ldy P8ZP_SCRATCH_B1 jmp GIVAYF ; this uses the inverse order, Y/A }} } @@ -110,9 +110,9 @@ asmsub FTOSWRDAY () clobbers(X) -> uword @ AY { ; ---- fac1 to signed word in A/Y %asm {{ jsr FTOSWORDYA ; note the inverse Y/A order - sta P8ZP_SCRATCH_REG + sta P8ZP_SCRATCH_B1 tya - ldy P8ZP_SCRATCH_REG + ldy P8ZP_SCRATCH_B1 rts }} } diff --git a/examples/test.p8 b/examples/test.p8 index 0c8439b8f..df846f24a 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -10,15 +10,16 @@ main { sub start () { word ww - float x_f = -300.0 float y_f + float fl for ww in -300 to 300 { ; TODO fix crash if ww is not defined - ;fl = ww as float ; TODO doesn't work??? - y_f = cos(x_f/30.0)*60 - x_f/1.7 - ; gfx2.plot(ww + 320 as uword, (y_f + 240) as uword, 1) - x_f += 1.0 + fl = ww as float + floats.print_f(fl) + txt.chrout(' ') } + test_stack.test() + }