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
@@ -222,7 +222,7 @@ Floating point mathematical routines - not official, but well known and broadly
|
|||||||
| `$BB0F` | `div_MEM_FAC1` | DONE | |
|
| `$BB0F` | `div_MEM_FAC1` | DONE | |
|
||||||
| `$BB12` | `div_FAC2_FAC1` | DONE | |
|
| `$BB12` | `div_FAC2_FAC1` | DONE | |
|
||||||
| `$BBA2` | `mov_MEM_FAC1` | DONE | |
|
| `$BBA2` | `mov_MEM_FAC1` | DONE | |
|
||||||
| `$BBA6` | `get_FAC2_via_INDEX` | NOT DONE | |
|
| `$BBA6` | `get_FAC1_via_INDEX` | DONE | |
|
||||||
| `$BBC7` | `mov_r_FAC1_TMP2` | PARTIAL | not fully tested yet |
|
| `$BBC7` | `mov_r_FAC1_TMP2` | PARTIAL | not fully tested yet |
|
||||||
| `$BBCA` | `mov_r_FAC1_TMP1` | PARTIAL | not fully tested yet |
|
| `$BBCA` | `mov_r_FAC1_TMP1` | PARTIAL | not fully tested yet |
|
||||||
| `$BBD0` | `mov_r_FAC1_VAR` | PARTIAL | not fully tested yet |
|
| `$BBD0` | `mov_r_FAC1_VAR` | PARTIAL | not fully tested yet |
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
;; #LAYOUT# STD * #TAKE
|
|
||||||
;; #LAYOUT# X16 BASIC_0 #TAKE-OFFSET 2000
|
|
||||||
;; #LAYOUT# * BASIC_0 #TAKE
|
|
||||||
;; #LAYOUT# * * #IGNORE
|
|
||||||
|
|
||||||
;
|
|
||||||
; Math package - XXX
|
|
||||||
;
|
|
||||||
; See also:
|
|
||||||
; - https://sourceforge.net/p/acme-crossass/code-0/38/tree/trunk/ACME_Lib/cbm/c64/float.a?force=True
|
|
||||||
;
|
|
||||||
|
|
||||||
; XXX implement, test
|
|
||||||
|
|
||||||
get_FAC1_via_INDEX:
|
|
||||||
|
|
||||||
+STUB_IMPLEMENTATION
|
|
||||||
+12
-14
@@ -32,11 +32,9 @@ FCOMP:
|
|||||||
php
|
php
|
||||||
|
|
||||||
ldy #$01
|
ldy #$01
|
||||||
lda #$7F ; Expand sign of RAM float into A as $FF or $00
|
lda (INDEX+2),Y
|
||||||
cmp (INDEX+2),Y
|
eor FAC1_sign ; Check if signs are different
|
||||||
adc #$80
|
bmi FCOMP_greater_than ; FAC < or > RAM, will be swapped to correct
|
||||||
cmp FAC1_sign
|
|
||||||
bne FCOMP_greater_than ; FAC < or > RAM, will be swapped to correct
|
|
||||||
|
|
||||||
dey
|
dey
|
||||||
lda (INDEX+2),Y ; Exponent of RAM float into A
|
lda (INDEX+2),Y ; Exponent of RAM float into A
|
||||||
@@ -76,17 +74,17 @@ FCOMP_equal:
|
|||||||
|
|
||||||
|
|
||||||
FCOMP_less_than:
|
FCOMP_less_than:
|
||||||
lda #$FF
|
lda FAC1_sign
|
||||||
cmp FAC1_sign
|
bpl FCOMP_FF
|
||||||
bne @1
|
FCOMP_01:
|
||||||
lda #$01
|
lda #$01
|
||||||
@1: plp
|
plp
|
||||||
rts
|
rts
|
||||||
|
|
||||||
FCOMP_greater_than:
|
FCOMP_greater_than:
|
||||||
lda #$01
|
lda FAC1_sign
|
||||||
cmp FAC1_sign
|
bpl FCOMP_01
|
||||||
bcs @1
|
FCOMP_FF:
|
||||||
lda #$FF
|
lda #$FF
|
||||||
@1: plp
|
plp
|
||||||
rts
|
rts
|
||||||
@@ -20,7 +20,11 @@ sgn_FAC1_A:
|
|||||||
lda FAC1_exponent
|
lda FAC1_exponent
|
||||||
beq @1
|
beq @1
|
||||||
lda FAC1_sign
|
lda FAC1_sign
|
||||||
bne @1
|
bmi @2
|
||||||
lda #$01
|
lda #$01
|
||||||
@1:
|
@1:
|
||||||
rts
|
rts
|
||||||
|
|
||||||
|
@2:
|
||||||
|
lda #$FF
|
||||||
|
rts
|
||||||
@@ -33,20 +33,10 @@ get_FAC2_via_INDEX:
|
|||||||
|
|
||||||
dey
|
dey
|
||||||
lda (INDEX), y
|
lda (INDEX), y
|
||||||
|
sta FAC2_sign
|
||||||
ora #$80 ; clear the sign bit
|
ora #$80 ; clear the sign bit
|
||||||
sta FAC2_mantissa+0
|
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
|
; Copy the exponent
|
||||||
|
|
||||||
dey
|
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
|
||||||
File renamed without changes.
@@ -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
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
$04 + LDA ($22),Y + STA $65 + DEY + LDA ($22),Y + STA $64 + DEY + LDA ($22),Y + STA $63 + DEY + LDA ($22),Y + STA $66 + ORA #$80 + STA $62 + DEY + LDA ($22),Y + STA $61 + STY $70 + RTS
|
||||||
|
|
||||||
|
Load FAC1 (well known zero page locations) from memory using well known vector in zero page (INDEX)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
JSR $BBA2 + JMP fragment
|
||||||
|
|
||||||
|
Call to well known floating point function + fragment
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
60 20 2B BC 85
|
||||||
|
|
||||||
|
RTS + JSR $BC2B + STA fragment
|
||||||
|
|
||||||
|
Fragments + call to well known floating point function
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
$6E + ORA #$80 + STA $6A + DEY + LDA ($22),Y + STA $69 + LDA $61 + RTS
|
||||||
|
|
||||||
|
Fragment of copying using a well known index vector from a mem float into FAC2
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
LDY #$04 + LDA ($22),Y + STA $6D + DEY + LDA ($22),Y + STA $6C + DEY + LDA ($22),Y + STA $6B + DEY + LDA ($22),Y + STA $6E
|
||||||
|
|
||||||
|
Load parts of the mantissa of FAC2 and its sign (well known zero page locations) from memory using well known vector in zero page (INDEX)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
LDA #$A8 + LDY #$AE + JSR $BBA2 + JMP fragment
|
||||||
|
|
||||||
|
Loading well known address of math constant pi into AY and call well known floating point function (mov_MEM_FAC1)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
LDA ($24),Y + EOR $66 + BMI fragment
|
||||||
|
|
||||||
|
Compare signs of FAC1 and float pointed to by index vector
|
||||||
+13
-3
@@ -139,12 +139,22 @@ r A=$E0
|
|||||||
r Y=$B9
|
r Y=$B9
|
||||||
r PC=$BBA2
|
r PC=$BBA2
|
||||||
ret
|
ret
|
||||||
fill $1001 $1006 80 80 00 00 00 FF
|
fill $1001 $1006 80 80 00 00 00 80
|
||||||
print "COMPARE"
|
print "COMPARE"
|
||||||
compare $61 $66 $1001
|
compare $61 $66 $1001
|
||||||
compare $70 $70 $1003 ; FACOV = 0
|
compare $70 $70 $1003 ; FACOV = 0
|
||||||
print "END"
|
print "END"
|
||||||
|
|
||||||
|
print "TEST: get_FAC1_via_INDEX -0.5"
|
||||||
|
fill $61 $66 FF FF FF FF FF AA
|
||||||
|
fill $22 $23 E0 B9
|
||||||
|
r PC=$BBA6
|
||||||
|
ret
|
||||||
|
fill $1001 $1006 80 80 00 00 00 80
|
||||||
|
print "COMPARE"
|
||||||
|
compare $61 $66 $1001
|
||||||
|
print "END"
|
||||||
|
|
||||||
print "TEST: mov MEM FAC2 const 1.0"
|
print "TEST: mov MEM FAC2 const 1.0"
|
||||||
fill $69 $6E FF FF FF FF FF AA
|
fill $69 $6E FF FF FF FF FF AA
|
||||||
r A=$BC
|
r A=$BC
|
||||||
@@ -162,7 +172,7 @@ r A=$E0
|
|||||||
r Y=$B9
|
r Y=$B9
|
||||||
r PC=$BA8C
|
r PC=$BA8C
|
||||||
ret
|
ret
|
||||||
fill $1001 $1006 80 80 00 00 00 FF
|
fill $1001 $1006 80 80 00 00 00 80
|
||||||
print "COMPARE"
|
print "COMPARE"
|
||||||
compare $69 $6E $1001
|
compare $69 $6E $1001
|
||||||
print "END"
|
print "END"
|
||||||
@@ -172,7 +182,7 @@ fill $69 $6E FF FF FF FF FF AA
|
|||||||
fill $22 $23 E0 B9
|
fill $22 $23 E0 B9
|
||||||
r PC=$BA90
|
r PC=$BA90
|
||||||
ret
|
ret
|
||||||
fill $1001 $1006 80 80 00 00 00 FF
|
fill $1001 $1006 80 80 00 00 00 80
|
||||||
print "COMPARE"
|
print "COMPARE"
|
||||||
compare $69 $6E $1001
|
compare $69 $6E $1001
|
||||||
print "END"
|
print "END"
|
||||||
|
|||||||
Reference in new issue
Block a user