Add get_FAC1_via_INDEX
Also change to only use bit 7 as sign in FAC1 and FAC2 (as the original BASIC does) to simplify implementations.
This commit is contained in:
1 parent
919f3c84b9
commit
5a3f65efa4
18 files changed
+130
-134
No files matched your search
@@ -33,20 +33,10 @@ get_FAC2_via_INDEX:
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC2_sign
|
||||
ora #$80 ; clear the sign bit
|
||||
sta FAC2_mantissa+0
|
||||
|
||||
; Copy the sign
|
||||
|
||||
lda (INDEX), y
|
||||
bpl @1 ; assumption: non-negative numbers are more frequent
|
||||
lda #$FF
|
||||
+skip_2_bytes_trash_nvz
|
||||
@1:
|
||||
lda #$00
|
||||
|
||||
sta FAC2_sign
|
||||
|
||||
; Copy the exponent
|
||||
|
||||
dey
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Just a compatibility jump - our routine is longer than original one
|
||||
|
||||
jmp mov_MEM_FAC1
|
||||
@@ -0,0 +1,30 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
|
||||
; Math package - fetch FAC1 from RAM location
|
||||
;
|
||||
; Input:
|
||||
; - .A - address low byte
|
||||
; - .Y - address high byte
|
||||
;
|
||||
; Output:
|
||||
; - .A - FAC1 exponent, affects status flags
|
||||
; - .Y - always 0
|
||||
;
|
||||
; Preserves:
|
||||
; - .X - (experimentation with original ROM)
|
||||
;
|
||||
; See also:
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
|
||||
|
||||
|
||||
mov_MEM_FAC1:
|
||||
sty INDEX+1
|
||||
sta INDEX+0
|
||||
|
||||
; FALLTHROUGH to get_FAC1_via_INDEX
|
||||
@@ -0,0 +1,45 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Math package - Mov MEM to FAC1 with address in INDEX zero page register
|
||||
;
|
||||
; See also:
|
||||
; - https://sourceforge.net/p/acme-crossass/code-0/38/tree/trunk/ACME_Lib/cbm/c64/float.a?force=True
|
||||
;
|
||||
|
||||
get_FAC1_via_INDEX:
|
||||
|
||||
; Copy the mantissa
|
||||
|
||||
ldy #$04
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+3
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+2
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+1
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_sign
|
||||
ora #$80 ; clear the sign bit
|
||||
sta FAC1_mantissa+0
|
||||
|
||||
; Copy the exponent
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_exponent
|
||||
|
||||
; Set low order mantissa to 0 - this should give the
|
||||
; most precision while operating on integers
|
||||
|
||||
sty FACOV
|
||||
|
||||
rts
|
||||
@@ -0,0 +1,4 @@
|
||||
This is an important floating point math routine, documented in many places.
|
||||
|
||||
It's a part oof the ACME assembler SDK, see:
|
||||
- https://sourceforge.net/p/acme-crossass/code-0/38/tree/trunk/ACME_Lib/cbm/c64/float.a?force=True
|
||||
@@ -1,79 +0,0 @@
|
||||
;; #LAYOUT# STD * #TAKE
|
||||
;; #LAYOUT# * BASIC_0 #TAKE
|
||||
;; #LAYOUT# * * #IGNORE
|
||||
|
||||
; Math package - fetch FAC1 from RAM location
|
||||
;
|
||||
; Input:
|
||||
; - .A - address low byte
|
||||
; - .Y - address high byte
|
||||
;
|
||||
; Output:
|
||||
; - .A - FAC1 exponent, affects status flags
|
||||
; - .Y - always 0
|
||||
;
|
||||
; Preserves:
|
||||
; - .X - (experimentation with original ROM)
|
||||
;
|
||||
; See also:
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
|
||||
; XXX test this
|
||||
|
||||
mov_MEM_FAC1:
|
||||
|
||||
; Original routines use $22/$23 location for a vector too, see here:
|
||||
; - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
|
||||
sty INDEX+1
|
||||
sta INDEX+0
|
||||
|
||||
; Now copy the data from RAM to FAC2, for the format description see:
|
||||
; - https://www.c64-wiki.com/wiki/Floating_point_arithmetic#Representation_in_the_C-64
|
||||
|
||||
; Copy the mantissa
|
||||
|
||||
ldy #$04
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+3
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+2
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_mantissa+1
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
ora #$80 ; clear the sign bit
|
||||
sta FAC1_mantissa+0
|
||||
|
||||
; Copy the sign
|
||||
|
||||
lda (INDEX), y
|
||||
bpl @1 ; assumption: non-negative numbers are more frequent
|
||||
lda #$FF
|
||||
+skip_2_bytes_trash_nvz
|
||||
@1:
|
||||
lda #$00
|
||||
|
||||
sta FAC1_sign
|
||||
|
||||
; Copy the exponent
|
||||
|
||||
dey
|
||||
lda (INDEX), y
|
||||
sta FAC1_exponent
|
||||
|
||||
; Set low order mantissa to 0 - this should give the
|
||||
; most precision while operating on integers
|
||||
|
||||
sty FACOV
|
||||
|
||||
; Return the FAC1 exponent
|
||||
|
||||
lda FAC1_exponent
|
||||
rts
|
||||
Reference in new issue
Block a user