mirror of
https://github.com/irmen/prog8.git
synced 2025-01-26 19:30:59 +00:00
fix cx16 rom v39 float changes
This commit is contained in:
parent
3e3b0bcd8b
commit
64c85b9617
@ -8,7 +8,9 @@
|
|||||||
%option enable_floats
|
%option enable_floats
|
||||||
|
|
||||||
floats {
|
floats {
|
||||||
; ---- this block contains C-64 floating point related functions ----
|
; ---- this block contains C-64 compatible floating point related functions ----
|
||||||
|
; the addresses are from cx16 V39 emulator and roms! they won't work on older versions.
|
||||||
|
|
||||||
|
|
||||||
const float PI = 3.141592653589793
|
const float PI = 3.141592653589793
|
||||||
const float TWOPI = 6.283185307179586
|
const float TWOPI = 6.283185307179586
|
||||||
@ -40,39 +42,38 @@ romsub $fe12 = FADD(uword mflpt @ AY) clobbers(A,X,Y) ; fac1 += mflpt valu
|
|||||||
romsub $fe15 = FADDT() clobbers(A,X,Y) ; fac1 += fac2
|
romsub $fe15 = FADDT() clobbers(A,X,Y) ; fac1 += fac2
|
||||||
romsub $fe1b = ZEROFC() clobbers(A,X,Y) ; fac1 = 0
|
romsub $fe1b = ZEROFC() clobbers(A,X,Y) ; fac1 = 0
|
||||||
romsub $fe1e = NORMAL() clobbers(A,X,Y) ; normalize fac1 (?)
|
romsub $fe1e = NORMAL() clobbers(A,X,Y) ; normalize fac1 (?)
|
||||||
|
romsub $fe21 = NEGFAC() clobbers(A,X,Y) ; fac1 = -fac1
|
||||||
romsub $fe24 = LOG() clobbers(A,X,Y) ; fac1 = LN(fac1) (natural log)
|
romsub $fe24 = LOG() clobbers(A,X,Y) ; fac1 = LN(fac1) (natural log)
|
||||||
romsub $fe27 = FMULT(uword mflpt @ AY) clobbers(A,X,Y) ; fac1 *= mflpt value from A/Y
|
romsub $fe27 = FMULT(uword mflpt @ AY) clobbers(A,X,Y) ; fac1 *= mflpt value from A/Y
|
||||||
romsub $fe2a = FMULTT() clobbers(A,X,Y) ; fac1 *= fac2
|
romsub $fe2a = FMULTT() clobbers(A,X,Y) ; fac1 *= fac2
|
||||||
romsub $fe33 = CONUPK(uword mflpt @ AY) clobbers(A,Y) ; load mflpt value from memory in A/Y into fac2
|
romsub $fe30 = CONUPK(uword mflpt @ AY) clobbers(A,X,Y) ; load mflpt value from memory in A/Y into fac2
|
||||||
romsub $fe36 = MUL10() clobbers(A,X,Y) ; fac1 *= 10
|
romsub $fe33 = MUL10() clobbers(A,X,Y) ; fac1 *= 10
|
||||||
romsub $fe3c = DIV10() clobbers(A,X,Y) ; fac1 /= 10 , CAUTION: result is always positive!
|
romsub $fe36 = DIV10() clobbers(A,X,Y) ; fac1 /= 10 , CAUTION: result is always positive!
|
||||||
romsub $fe3f = FDIV(uword mflpt @ AY) clobbers(A,X,Y) ; fac1 = mflpt in A/Y / fac1 (remainder in fac2)
|
romsub $fe39 = FDIV(uword mflpt @ AY) clobbers(A,X,Y) ; fac1 = mflpt in A/Y / fac1 (remainder in fac2)
|
||||||
romsub $fe42 = FDIVT() clobbers(A,X,Y) ; fac1 = fac2/fac1 (remainder in fac2) mind the order of the operands
|
romsub $fe3c = FDIVT() clobbers(A,X,Y) ; fac1 = fac2/fac1 (remainder in fac2) mind the order of the operands
|
||||||
|
|
||||||
romsub $fe48 = MOVFM(uword mflpt @ AY) clobbers(A,Y) ; load mflpt value from memory in A/Y into fac1
|
romsub $fe42 = MOVFM(uword mflpt @ AY) clobbers(A,X,Y) ; load mflpt value from memory in A/Y into fac1
|
||||||
romsub $fe4b = MOVMF(uword mflpt @ XY) clobbers(A,Y) ; store fac1 to memory X/Y as 5-byte mflpt
|
romsub $fe45 = MOVMF(uword mflpt @ XY) clobbers(A,X,Y) ; store fac1 to memory X/Y as 5-byte mflpt
|
||||||
romsub $fe4e = MOVFA() clobbers(A,X) ; copy fac2 to fac1
|
romsub $fe48 = MOVFA() clobbers(A,X) ; copy fac2 to fac1
|
||||||
romsub $fe51 = MOVAF() clobbers(A,X) ; copy fac1 to fac2 (rounded)
|
romsub $fe4b = MOVAF() clobbers(A,X) ; copy fac1 to fac2 (rounded)
|
||||||
romsub $fe54 = MOVEF() clobbers(A,X) ; copy fac1 to fac2
|
romsub $fe4e = MOVEF() clobbers(A,X) ; copy fac1 to fac2
|
||||||
romsub $fe5a = SIGN() -> ubyte @ A ; SIGN(fac1) to A, $ff, $0, $1 for negative, zero, positive
|
romsub $fe54 = SIGN() clobbers(X,Y) -> ubyte @ A ; SIGN(fac1) to A, $ff, $0, $1 for negative, zero, positive
|
||||||
romsub $fe5d = SGN() clobbers(A,X,Y) ; fac1 = SGN(fac1), result of SIGN (-1, 0 or 1)
|
romsub $fe57 = SGN() clobbers(A,X,Y) ; fac1 = SGN(fac1), result of SIGN (-1, 0 or 1)
|
||||||
romsub $fe60 = FREADSA(byte value @ A) clobbers(A,X,Y) ; 8 bit signed A -> float in fac1
|
romsub $fe5a = FREADSA(byte value @ A) clobbers(A,X,Y) ; 8 bit signed A -> float in fac1
|
||||||
romsub $fe6c = ABS() ; fac1 = ABS(fac1)
|
romsub $fe66 = ABS() clobbers(A,X,Y) ; fac1 = ABS(fac1)
|
||||||
romsub $fe6f = FCOMP(uword mflpt @ AY) clobbers(X,Y) -> ubyte @ A ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than
|
romsub $fe69 = FCOMP(uword mflpt @ AY) clobbers(X,Y) -> ubyte @ A ; A = compare fac1 to mflpt in A/Y, 0=equal 1=fac1 is greater, 255=fac1 is less than
|
||||||
romsub $fe78 = INT() clobbers(A,X,Y) ; INT() truncates, use FADDH first to round instead of trunc
|
romsub $fe72 = INT() clobbers(A,X,Y) ; INT() truncates, use FADDH first to round instead of trunc
|
||||||
romsub $fe7e = FINLOG(byte value @A) clobbers (A, X, Y) ; fac1 += signed byte in A
|
romsub $fe78 = FINLOG(byte value @A) clobbers (A, X, Y) ; fac1 += signed byte in A
|
||||||
romsub $fe81 = FOUT() clobbers(X) -> uword @ AY ; fac1 -> string, address returned in AY
|
romsub $fe7b = FOUT() clobbers(X) -> uword @ AY ; fac1 -> string, address returned in AY
|
||||||
romsub $fe8a = SQR() clobbers(A,X,Y) ; fac1 = SQRT(fac1)
|
romsub $fe81 = SQR() clobbers(A,X,Y) ; fac1 = SQRT(fac1)
|
||||||
romsub $fe8d = FPWRT() clobbers(A,X,Y) ; fac1 = fac2 ** fac1
|
romsub $fe84 = FPWRT() clobbers(A,X,Y) ; fac1 = fac2 ** fac1
|
||||||
; note: there is no FPWR() on the Cx16
|
romsub $fe8a = NEGOP() clobbers(A,X,Y) ; fac1 = -fac1-1
|
||||||
romsub $fe93 = NEGOP() clobbers(A) ; switch the sign of fac1
|
romsub $fe8d = EXP() clobbers(A,X,Y) ; fac1 = EXP(fac1) (e ** fac1)
|
||||||
romsub $fe96 = EXP() clobbers(A,X,Y) ; fac1 = EXP(fac1) (e ** fac1)
|
romsub $fe96 = RND() clobbers(A,X,Y) ; fac1 = RND(fac1) float random number generator
|
||||||
romsub $fe9f = RND2(byte value @A) clobbers(A,X,Y) ; fac1 = RND(A) float random number generator
|
romsub $fe99 = COS() clobbers(A,X,Y) ; fac1 = COS(fac1)
|
||||||
romsub $fea2 = RND() clobbers(A,X,Y) ; fac1 = RND(fac1) float random number generator
|
romsub $fe9c = SIN() clobbers(A,X,Y) ; fac1 = SIN(fac1)
|
||||||
romsub $fea5 = COS() clobbers(A,X,Y) ; fac1 = COS(fac1)
|
romsub $fe9f = TAN() clobbers(A,X,Y) ; fac1 = TAN(fac1)
|
||||||
romsub $fea8 = SIN() clobbers(A,X,Y) ; fac1 = SIN(fac1)
|
romsub $fea2 = ATN() clobbers(A,X,Y) ; fac1 = ATN(fac1)
|
||||||
romsub $feab = TAN() clobbers(A,X,Y) ; fac1 = TAN(fac1)
|
|
||||||
romsub $feae = ATN() clobbers(A,X,Y) ; fac1 = ATN(fac1)
|
|
||||||
|
|
||||||
|
|
||||||
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
||||||
|
@ -503,9 +503,9 @@ asmsub init_system() {
|
|||||||
%asm {{
|
%asm {{
|
||||||
sei
|
sei
|
||||||
cld
|
cld
|
||||||
stz $01 ; select rom bank 0 (enable kernal)
|
|
||||||
lda #$80
|
lda #$80
|
||||||
sta VERA_CTRL
|
sta VERA_CTRL
|
||||||
|
stz $01 ; select rom bank 0 (enable kernal)
|
||||||
jsr c64.IOINIT
|
jsr c64.IOINIT
|
||||||
jsr c64.RESTOR
|
jsr c64.RESTOR
|
||||||
jsr c64.CINT
|
jsr c64.CINT
|
||||||
@ -517,6 +517,8 @@ asmsub init_system() {
|
|||||||
jsr c64.CHROUT
|
jsr c64.CHROUT
|
||||||
lda #147 ; clear screen
|
lda #147 ; clear screen
|
||||||
jsr c64.CHROUT
|
jsr c64.CHROUT
|
||||||
|
ldx #4
|
||||||
|
stx $01 ; select rom bank 4 (enable basic again)
|
||||||
lda #0
|
lda #0
|
||||||
tax
|
tax
|
||||||
tay
|
tay
|
||||||
|
@ -214,7 +214,7 @@ private fun determineCompilationOptions(program: Program, compTarget: ICompilati
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (zpType==ZeropageType.FLOATSAFE && compTarget.name == Cx16Target.name) {
|
if (zpType==ZeropageType.FLOATSAFE && compTarget.name == Cx16Target.name) {
|
||||||
System.err.println("Warning: Cx16 target must use zp option basicsafe instead of floatsafe")
|
System.err.println("Warning: cx16 target must use zp option basicsafe instead of floatsafe")
|
||||||
zpType = ZeropageType.BASICSAFE
|
zpType = ZeropageType.BASICSAFE
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,6 +148,8 @@ For MacOS you can use the Homebrew system to install a recent version of OpenJDK
|
|||||||
Finally: an **emulator** (or a real machine ofcourse) to test and run your programs on.
|
Finally: an **emulator** (or a real machine ofcourse) to test and run your programs on.
|
||||||
In C64 mode, thhe compiler assumes the presence of the `Vice emulator <http://vice-emu.sourceforge.net/>`_.
|
In C64 mode, thhe compiler assumes the presence of the `Vice emulator <http://vice-emu.sourceforge.net/>`_.
|
||||||
If you're targeting the CommanderX16 instead, there's the `x16emu <https://github.com/commanderx16/x16-emulator>`_.
|
If you're targeting the CommanderX16 instead, there's the `x16emu <https://github.com/commanderx16/x16-emulator>`_.
|
||||||
|
Make sure you use cx16 emulator and roms **V39 or newer**! Starting from version 6.5, prog8 targets that system version.
|
||||||
|
Your program may work on V38 but that will only be by luck.
|
||||||
|
|
||||||
.. important::
|
.. important::
|
||||||
**Building the compiler itself:** (*Only needed if you have not downloaded a pre-built 'fat-jar'*)
|
**Building the compiler itself:** (*Only needed if you have not downloaded a pre-built 'fat-jar'*)
|
||||||
|
@ -233,6 +233,10 @@ to worry about this yourself)
|
|||||||
|
|
||||||
The largest 5-byte MFLPT float that can be stored is: **1.7014118345e+38** (negative: **-1.7014118345e+38**)
|
The largest 5-byte MFLPT float that can be stored is: **1.7014118345e+38** (negative: **-1.7014118345e+38**)
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
On the Commander X16, to use floating point operations, ROM bank 4 has to be enabled (BASIC).
|
||||||
|
Importing the ``floats`` library will do this for you if needed.
|
||||||
|
|
||||||
|
|
||||||
Arrays
|
Arrays
|
||||||
^^^^^^
|
^^^^^^
|
||||||
|
@ -2,6 +2,10 @@
|
|||||||
TODO
|
TODO
|
||||||
====
|
====
|
||||||
|
|
||||||
|
- make the floats lib set rombank 4 on cx16 and set sysinit back to rombank 0 (kernal only)
|
||||||
|
- make sure rombank is back to 4 on cx16 when program exits back to basic
|
||||||
|
- check use of float NEGOP vs NEGFAC for cx16
|
||||||
|
|
||||||
- allow inlining of subroutines with params
|
- allow inlining of subroutines with params
|
||||||
- optimize several inner loops in gfx2
|
- optimize several inner loops in gfx2
|
||||||
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
- hoist all variable declarations up to the subroutine scope *before* even the constant folding takes place (to avoid undefined symbol errors when referring to a variable from another nested scope in the subroutine)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
%import gfx2
|
%import gfx2
|
||||||
%import floats
|
%import floats
|
||||||
%import textio
|
%import textio
|
||||||
%zeropage basicsafe
|
%zeropage dontuse
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
|
@ -1,33 +1,36 @@
|
|||||||
%zeropage basicsafe
|
%import textio
|
||||||
|
%import floats
|
||||||
|
%zeropage dontuse
|
||||||
|
|
||||||
main {
|
main {
|
||||||
|
|
||||||
sub start() {
|
sub start() {
|
||||||
|
float f1 = 9.9999
|
||||||
ubyte[6] array = [ 1,2,3,
|
float f2 = 8.8888
|
||||||
; Comment here
|
float f3 = 0.1111
|
||||||
4,5,6 ]
|
|
||||||
|
|
||||||
ubyte zz = len(array)
|
|
||||||
|
|
||||||
ubyte foobar
|
|
||||||
empty2()
|
|
||||||
|
|
||||||
%asm {{
|
%asm {{
|
||||||
lda foobar
|
phx
|
||||||
|
ldy #<f1
|
||||||
|
lda #>f1
|
||||||
|
jsr $FE42
|
||||||
|
jsr $FE7B
|
||||||
|
plx
|
||||||
}}
|
}}
|
||||||
}
|
f3=cos(f3)
|
||||||
|
|
||||||
sub nix() {
|
floats.print_f(f1)
|
||||||
}
|
txt.nl()
|
||||||
|
floats.print_f(f2)
|
||||||
|
txt.nl()
|
||||||
|
floats.print_f(f3)
|
||||||
|
txt.nl()
|
||||||
|
f3 = cos(f3)
|
||||||
|
floats.print_f(f3)
|
||||||
|
|
||||||
|
txt.print("ok!\n")
|
||||||
|
|
||||||
|
sys.wait(2*60)
|
||||||
|
|
||||||
sub empty2() {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
derp {
|
|
||||||
sub nix2() {
|
|
||||||
ubyte zz
|
|
||||||
zz++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user