From 688dce6145e97accf38971e52a86a5e051084333 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Thu, 7 Nov 2024 22:17:23 +0100 Subject: [PATCH] floats: added AYINT2 as a safe wrapper for AYINT. Internal float to word cast now also uses that. --- .gitignore | 6 ++++-- compiler/res/prog8lib/c64/floats.asm | 8 ++------ compiler/res/prog8lib/c64/floats.p8 | 19 ++++++++++++++++--- compiler/res/prog8lib/cx16/floats.p8 | 18 ++++++++++++++++-- docs/source/todo.rst | 6 +++++- examples/test.p8 | 17 ++++++++++++----- 6 files changed, 55 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index f24d5e1df..125d5d635 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,12 @@ .idea/workspace.xml .idea/discord.xml .idea/developer-tools.xml +.idea/usage.statistics.xml +.idea/shelf/ build/ dist/ output/ +out/ .*cache/ *.directory *.prg @@ -12,7 +15,6 @@ output/ *.vm.txt *.vice-mon-list docs/build -out/ parser/**/*.interp parser/**/*.tokens parser/**/*.java @@ -23,6 +25,7 @@ compiler/src/prog8/buildversion/* .eggs/ /MANIFEST .tox/ +.kotlin/ __pycache__/ parser.out parsetab.py @@ -31,7 +34,6 @@ parsetab.py compiler/lib/ .gradle -/prog8compiler.jar sd*.img *.d64 diff --git a/compiler/res/prog8lib/c64/floats.asm b/compiler/res/prog8lib/c64/floats.asm index 46a2b110f..d6dea273b 100644 --- a/compiler/res/prog8lib/c64/floats.asm +++ b/compiler/res/prog8lib/c64/floats.asm @@ -120,12 +120,8 @@ cast_FAC1_as_uw_into_ya .proc ; also used for float 2 ub .pend cast_FAC1_as_w_into_ay .proc ; also used for float 2 b - ; -- cast fac1 to word into A/Y - ; clobbers X - jsr AYINT - ldy floats.AYINT_facmo - lda floats.AYINT_facmo+1 - rts + ; -- cast fac1 to word into A/Y. clobbers X + jmp AYINT2 .pend diff --git a/compiler/res/prog8lib/c64/floats.p8 b/compiler/res/prog8lib/c64/floats.p8 index 80f1dbcc7..c3ec839b1 100644 --- a/compiler/res/prog8lib/c64/floats.p8 +++ b/compiler/res/prog8lib/c64/floats.p8 @@ -29,7 +29,7 @@ extsub $bbd4 = MOVMF(uword mflpt @ XY) clobbers(A,Y) ; store fac1 to memo extsub $b7f7 = GETADR() clobbers(X) -> ubyte @ Y, ubyte @ A extsub $bc9b = QINT() clobbers(A,X,Y) ; fac1 -> 4-byte signed integer in 98-101 ($62-$65), with the MSB FIRST. -extsub $b1bf = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101 ($64-$65) MSB FIRST. (might throw ILLEGAL QUANTITY) +extsub $b1bf = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101 ($64-$65) MSB FIRST. (might throw ILLEGAL QUANTITY) DON'T USE THIS, USE WRAPPER 'AYINT2' INSTEAD. ; GIVAYF: signed word in Y/A (note different lsb/msb order) -> float in fac1 ; (tip: use floats.GIVAYFAY to use A/Y input; lo/hi switched to normal order) @@ -80,6 +80,20 @@ extsub $e2b4 = TAN() clobbers(A,X,Y) ; fac1 = TAN(fac1) extsub $e30e = ATN() clobbers(A,X,Y) ; fac1 = ATN(fac1) +asmsub AYINT2() clobbers(X) -> word @AY { + ; fac1-> signed word in AY. Safe wrapper around the AYINT kernal routine (not reading internal memory locations) + ; (might throw ILLEGAL QUANTITY) + %asm {{ + jsr AYINT + ldx #floats_temp_var + jsr MOVMF + lda floats_temp_var+4 + ldy floats_temp_var+3 + rts + }} +} + asmsub FREADS32() clobbers(A,X,Y) { ; ---- fac1 = signed int32 from $62-$65 big endian (MSB FIRST) %asm {{ @@ -154,7 +168,7 @@ asmsub FREADU24AXY(ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A, X, Y) asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) { ; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1 %asm {{ - sty $62 + sty $62 ; facmo sta $63 ldx #$90 sec @@ -183,7 +197,6 @@ asmsub GETADRAY () clobbers(X) -> uword @ AY { }} } -&uword AYINT_facmo = $64 ; $64/$65 contain result of AYINT sub rnd() -> float { %asm {{ diff --git a/compiler/res/prog8lib/cx16/floats.p8 b/compiler/res/prog8lib/cx16/floats.p8 index df07b2331..a4c36ef87 100644 --- a/compiler/res/prog8lib/cx16/floats.p8 +++ b/compiler/res/prog8lib/cx16/floats.p8 @@ -14,7 +14,7 @@ floats { ; note: fac1/2 might get clobbered even if not mentioned in the function's name. ; note: for subtraction and division, the left operand is in fac2, the right operand in fac1. -extsub $fe00 = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 'facmo' and 'faclo', MSB FIRST. (might throw ILLEGAL QUANTITY) See "basic.sym" kernal symbol file for their memory locations. +extsub $fe00 = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 'facmo' and 'faclo', MSB FIRST. DON'T USE THIS, USE WRAPPER 'AYINT2' INSTEAD. (might throw ILLEGAL QUANTITY) ; GIVAYF: signed word in Y/A (note different lsb/msb order) -> float in fac1 ; there is also floats.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1 @@ -77,6 +77,19 @@ extsub $fe8d = QINT() clobbers(A,X,Y) ; facho:facho+1:fach extsub $fe90 = FINLOG(byte value @A) clobbers (A, X, Y) ; fac1 += signed byte in A +asmsub AYINT2() clobbers(X) -> word @AY { + ; fac1-> signed word in AY. Safe wrapper around the AYINT kernal routine (not reading internal memory locations) + ; (might throw ILLEGAL QUANTITY) + %asm {{ + jsr AYINT + ldx #floats_temp_var + jsr MOVMF + lda floats_temp_var+4 + ldy floats_temp_var+3 + rts + }} +} asmsub FREADSA (byte value @A) clobbers(A,X,Y) { ; ---- 8 bit signed A -> float in fac1 @@ -124,6 +137,8 @@ asmsub FREADU24AXY(ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A, X, Y) asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) { ; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1 + ; See "basic.sym" kernal symbol file for the facmo memory location. + ; TODO find a way to not depend on that internal fac memory location. MOVFM doesn't work. %asm {{ sty $c4 ; facmo sta $c5 ; facmo+1 @@ -190,7 +205,6 @@ _msg .text 13,"?rom 47+ required for val1",13,0 }} } -&uword AYINT_facmo = $c6 ; $c6/$c7 contain result of AYINT (See "basic.sym" kernal symbol file) sub rnd() -> float { %asm {{ diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 9612fc6b4..dc5847ab0 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -1,13 +1,17 @@ TODO ==== + for releasenotes: gfx2.width and gfx2.height got renamed as gfx_lores.WIDTH/HEIGHT or gfx_hires4.WIDTH/HEIGTH constants. Screen mode routines also renamed. regenerate symbol dump files improve ability to create library files in prog8; for instance there's still stuff injected into the start of the start() routine AND there is separate setup logic going on before calling it. Make up our mind! Maybe all setup does need to be put into start() ? because the program cannot function correctly when the variables aren't initialized properly bss is not cleared etc. etc. -Add a -library $xxxx command line option to preselect every setting that is required to make a library at $xxxx rather than a normal loadable and runnable program +Add a -library $xxxx command line option to preselect every setting that is required to make a library at $xxxx rather than a normal loadable and runnable program? +Need to add some way to generate a stable jump table at a given address. +Why are blocks without an addr moved BEHIND a block with an address? That's done in the StatementReorderer. + Improve register load order in subroutine call args assignments: in certain situations, the "wrong" order of evaluation of function call arguments is done which results diff --git a/examples/test.p8 b/examples/test.p8 index b0610c40b..6c3f0b805 100644 --- a/examples/test.p8 +++ b/examples/test.p8 @@ -1,13 +1,20 @@ %import textio -%zeropage dontuse +%import floats %option no_sysinit -%address $5000 -%launcher none +%zeropage basicsafe main { sub start() { - txt.print("address of start: ") - txt.print_uwhex(&start, true) + float @shared fl1 = 4444.234 + float @shared fl2 = -9999.111 + float @shared fl3 = fl1+fl2 + floats.print(fl1) + txt.spc() + floats.print(fl2) + txt.spc() + floats.print(fl3) + txt.nl() + txt.print_w(fl3 as word) txt.nl() } }