mirror of
https://github.com/irmen/prog8.git
synced 2025-02-09 07:31:34 +00:00
Add 24-bit integer-to-float routine and floating-point jiffy clock reader (#150)
* feat: add routine to convert 24-bit integer from A/X/Y to float in FAC1 * fix: remove duplicate definition * fix: shift to appropriate exponent
This commit is contained in:
parent
5cda750e5e
commit
16a2b2f566
@ -36,7 +36,7 @@ romsub $b1bf = AYINT() clobbers(A,X,Y) ; fac1-> signed word in 100-101
|
|||||||
; there is also floats.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
|
; there is also floats.GIVUAYFAY - unsigned word in A/Y (lo/hi) to fac1
|
||||||
; there is also floats.FREADS32 that reads from 98-101 ($62-$65) MSB FIRST
|
; there is also floats.FREADS32 that reads from 98-101 ($62-$65) MSB FIRST
|
||||||
; there is also floats.FREADUS32 that reads from 98-101 ($62-$65) MSB FIRST
|
; there is also floats.FREADUS32 that reads from 98-101 ($62-$65) MSB FIRST
|
||||||
; there is also floats.FREADS24AXY that reads signed int24 into fac1 from A/X/Y (lo/mid/hi bytes)
|
; there is also floats.FREAD{S,U}24AXY that read (un)signed int24 into fac1 from A/X/Y (lo/mid/hi bytes)
|
||||||
romsub $b391 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
|
romsub $b391 = GIVAYF(ubyte lo @ Y, ubyte hi @ A) clobbers(A,X,Y)
|
||||||
|
|
||||||
romsub $b3a2 = FREADUY(ubyte value @ Y) clobbers(A,X,Y) ; 8 bit unsigned Y -> float in fac1
|
romsub $b3a2 = FREADUY(ubyte value @ Y) clobbers(A,X,Y) ; 8 bit unsigned Y -> float in fac1
|
||||||
@ -104,7 +104,6 @@ asmsub FREADUS32 () clobbers(A,X,Y) {
|
|||||||
|
|
||||||
asmsub FREADS24AXY (ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A,X,Y) {
|
asmsub FREADS24AXY (ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A,X,Y) {
|
||||||
; ---- fac1 = signed int24 (A/X/Y contain lo/mid/hi bytes)
|
; ---- fac1 = signed int24 (A/X/Y contain lo/mid/hi bytes)
|
||||||
; note: there is no FREADU24AXY (unsigned), use FREADUS32 instead.
|
|
||||||
%asm {{
|
%asm {{
|
||||||
sty $62
|
sty $62
|
||||||
stx $63
|
stx $63
|
||||||
@ -119,6 +118,38 @@ asmsub FREADS24AXY (ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A,X,Y)
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asmsub FREADU24AXY(ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A, X, Y) -> float @FAC1 {
|
||||||
|
%asm{{
|
||||||
|
FAC = $61
|
||||||
|
sty FAC+1
|
||||||
|
stx FAC+2
|
||||||
|
sta FAC+3
|
||||||
|
|
||||||
|
cpy #$00
|
||||||
|
bne +
|
||||||
|
cpx #$00
|
||||||
|
bne +
|
||||||
|
cmp #$00
|
||||||
|
beq ++
|
||||||
|
|
||||||
|
+ ldx #$98
|
||||||
|
bit FAC+1
|
||||||
|
bmi +
|
||||||
|
|
||||||
|
- dex
|
||||||
|
asl FAC+3
|
||||||
|
rol FAC+2
|
||||||
|
rol FAC+1
|
||||||
|
bpl -
|
||||||
|
|
||||||
|
+ stx FAC
|
||||||
|
lda #$00
|
||||||
|
sta FAC+4
|
||||||
|
sta FAC+5
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
||||||
; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1
|
; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1
|
||||||
%asm {{
|
%asm {{
|
||||||
@ -177,6 +208,13 @@ asmsub normalize(float value @FAC1) -> float @ FAC1 {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; get the jiffy clock as a float
|
||||||
|
asmsub time() -> float @ FAC1 {
|
||||||
|
%asm {{
|
||||||
|
jsr cbm.RDTIM
|
||||||
|
jmp floats.FREADU24AXY
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
%asminclude "library:c64/floats.asm"
|
%asminclude "library:c64/floats.asm"
|
||||||
%asminclude "library:c64/floats_funcs.asm"
|
%asminclude "library:c64/floats_funcs.asm"
|
||||||
|
@ -90,6 +90,37 @@ asmsub FREADSA (byte value @A) clobbers(A,X,Y) {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
asmsub FREADU24AXY(ubyte lo @ A, ubyte mid @ X, ubyte hi @ Y) clobbers(A, X, Y) -> float @FAC1 {
|
||||||
|
%asm{{
|
||||||
|
FAC = $C3
|
||||||
|
sty FAC+1
|
||||||
|
stx FAC+2
|
||||||
|
sta FAC+3
|
||||||
|
|
||||||
|
cpy #$00
|
||||||
|
bne +
|
||||||
|
cpx #$00
|
||||||
|
bne +
|
||||||
|
cmp #$00
|
||||||
|
beq ++
|
||||||
|
|
||||||
|
+ ldx #$98
|
||||||
|
bit FAC+1
|
||||||
|
bmi +
|
||||||
|
|
||||||
|
- dex
|
||||||
|
asl FAC+3
|
||||||
|
rol FAC+2
|
||||||
|
rol FAC+1
|
||||||
|
bpl -
|
||||||
|
|
||||||
|
+ stx FAC
|
||||||
|
stz FAC+4
|
||||||
|
stz FAC+5
|
||||||
|
rts
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
asmsub GIVUAYFAY (uword value @ AY) clobbers(A,X,Y) {
|
||||||
; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1
|
; ---- unsigned 16 bit word in A/Y (lo/hi) to fac1
|
||||||
%asm {{
|
%asm {{
|
||||||
@ -157,7 +188,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)
|
&uword AYINT_facmo = $c6 ; $c6/$c7 contain result of AYINT (See "basic.sym" kernal symbol file)
|
||||||
|
|
||||||
sub rnd() -> float {
|
sub rnd() -> float {
|
||||||
@ -173,6 +203,14 @@ asmsub normalize(float value @FAC1) -> float @ FAC1 {
|
|||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
; get the jiffy clock as a float
|
||||||
|
asmsub time() -> float @ FAC1 {
|
||||||
|
%asm {{
|
||||||
|
jsr cbm.RDTIM
|
||||||
|
jmp floats.FREADU24AXY
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
%asminclude "library:c64/floats.asm"
|
%asminclude "library:c64/floats.asm"
|
||||||
%asminclude "library:c64/floats_funcs.asm"
|
%asminclude "library:c64/floats_funcs.asm"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user