From 8f9f947c422d1743196e774fda118c5e4f1b2a57 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 5 Sep 2020 02:05:28 +0200 Subject: [PATCH] fix some issues with float const 0.0 and 1.0 --- compiler/res/prog8lib/c64floats.asm | 19 +++++++++++-------- compiler/res/prog8lib/c64flt.p8 | 7 ++----- compiler/res/prog8lib/cx16flt.p8 | 7 ++----- examples/cube3d-float.p8 | 4 ++-- examples/test.p8 | 17 +++++++---------- 5 files changed, 24 insertions(+), 30 deletions(-) diff --git a/compiler/res/prog8lib/c64floats.asm b/compiler/res/prog8lib/c64floats.asm index 2a39f3610..5d0f501e7 100644 --- a/compiler/res/prog8lib/c64floats.asm +++ b/compiler/res/prog8lib/c64floats.asm @@ -1,5 +1,8 @@ ; --- low level floating point assembly routines for the C64 +FL_ONE_const .byte 129 ; 1.0 +FL_ZERO_const .byte 0,0,0,0,0 ; 0.0 + ub2float .proc ; -- convert ubyte in SCRATCH_ZPB1 to float at address A/Y @@ -233,8 +236,8 @@ inc_var_f .proc sty P8ZP_SCRATCH_W1+1 stx P8ZP_SCRATCH_REG_X jsr MOVFM - lda #ONE + lda #FL_ONE_const jsr FADD ldx P8ZP_SCRATCH_W1 ldy P8ZP_SCRATCH_W1+1 @@ -248,8 +251,8 @@ dec_var_f .proc sta P8ZP_SCRATCH_W1 sty P8ZP_SCRATCH_W1+1 stx P8ZP_SCRATCH_REG_X - lda #ONE + lda #FL_ONE_const jsr MOVFM lda P8ZP_SCRATCH_W1 ldy P8ZP_SCRATCH_W1+1 @@ -573,8 +576,8 @@ func_ceil .proc jsr FCOMP cmp #0 beq + - lda #ONE + lda #FL_ONE_const jsr FADD + jmp push_fac1_as_result .pend @@ -665,8 +668,8 @@ _largest_pos_float .byte 255,127,255,255,255 ; largest positive float .pend func_sum_f .proc - lda #ZERO + lda #FL_ZERO_const jsr MOVFM jsr prog8_lib.pop_array_and_lengthmin1Y stx P8ZP_SCRATCH_REG_X diff --git a/compiler/res/prog8lib/c64flt.p8 b/compiler/res/prog8lib/c64flt.p8 index 76b420bda..18b2374a7 100644 --- a/compiler/res/prog8lib/c64flt.p8 +++ b/compiler/res/prog8lib/c64flt.p8 @@ -9,11 +9,8 @@ c64flt { ; ---- this block contains C-64 floating point related functions ---- - ; TODO fix var storage in ASM when declared const: - float PI = 3.141592653589793 - float TWOPI = 6.283185307179586 - float ZERO = 0.0 - float ONE = 1.0 + const float PI = 3.141592653589793 + const float TWOPI = 6.283185307179586 ; ---- C64 basic and kernal ROM float constants and functions ---- diff --git a/compiler/res/prog8lib/cx16flt.p8 b/compiler/res/prog8lib/cx16flt.p8 index bca617e12..9da3724a8 100644 --- a/compiler/res/prog8lib/cx16flt.p8 +++ b/compiler/res/prog8lib/cx16flt.p8 @@ -9,11 +9,8 @@ c64flt { ; ---- this block contains C-64 floating point related functions ---- - ; TODO fix var storage in ASM when declared const: - float PI = 3.141592653589793 - float TWOPI = 6.283185307179586 - float ZERO = 0.0 - float ONE = 1.0 + const float PI = 3.141592653589793 + const float TWOPI = 6.283185307179586 ; ---- ROM float functions ---- diff --git a/examples/cube3d-float.p8 b/examples/cube3d-float.p8 index 18e6bfda6..82432f460 100644 --- a/examples/cube3d-float.p8 +++ b/examples/cube3d-float.p8 @@ -70,8 +70,8 @@ main { ; plot the points of the 3d cube ; first the points on the back, then the points on the front (painter algorithm) ubyte @zp i - float @zp rz ; TODO compiler warning that float can't be in ZP? - float @zp persp + float rz + float persp ubyte sx ubyte sy diff --git a/examples/test.p8 b/examples/test.p8 index 6fa3cbc5d..6d8ea5f14 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,7 +1,13 @@ -%import cx16textio +%import c64textio +%import c64flt +%option enable_floats %zeropage basicsafe +; TODO fix compilation when zeropage is not basicsafe on cx16 + main { + + sub start() { ;asmsub clear_screen (ubyte char @ A, ubyte color @ Y) clobbers(A) { ...} @@ -10,15 +16,6 @@ main { ; sub color(...) {} ; sub other(ubyte color) {} ; TODO don't cause name conflict - ; TODO fix var storage in ASM when declared const: - float PI = 3.141592653589793 - float TWOPI = 6.283185307179586 - float ZERO = 0.0 - float ONE = 1.0 - - - float @zp rz ; TODO compiler warning that float can't be in ZP? - }