diff --git a/STATUS.md b/STATUS.md index 3bd045d0..73c892fc 100644 --- a/STATUS.md +++ b/STATUS.md @@ -193,9 +193,10 @@ Floating point mathematical routines - not official, but well known and broadly | `$BB0F` | `FDIV` | PARTIAL | needs `FDIVT` | | `$BB12` | `FDIVT` | NOT DONE | divide FAC2 by FAC1, ignores sign | | `$BBA2` | `MOVFM` | PARTIAL | not fully tested yet | -| `$BBD4` | `MOVMF` | NOT DONE | copy FAC1 to memory location, rounds if asked | +| `$BBD4` | `MOVFM2` | NOT DONE | copy FAC1 to memory location, rounds if asked | | `$BBFC` | `MOVEF` | NOT DONE | copy FAC2 to FAC1 | -| `$BC0F` | `MOVFA` | NOT DONE | copy FAC1 to FAC2, skips rounding | +| `$BC0C` | `MOVAF` | PARTIAL | not fully tested | +| `$BC0F` | `MOVFA` | DONE | | | `$BC1B` | `ROUND` | PARTIAL | not tested | | `$BC2B` | `SIGN` | NOT DONE | evaluate FAC1 sign | | `$BC39` | `SGN` | NOT DONE | evaluate FAC1 sign, to FAC1 | diff --git a/c64/basic/,stubs_math/bbd4.MOVMF.s b/c64/basic/,stubs_math/bbd4.MOVMF2.s similarity index 89% rename from c64/basic/,stubs_math/bbd4.MOVMF.s rename to c64/basic/,stubs_math/bbd4.MOVMF2.s index 4a7a3d60..850adaa5 100644 --- a/c64/basic/,stubs_math/bbd4.MOVMF.s +++ b/c64/basic/,stubs_math/bbd4.MOVMF2.s @@ -14,12 +14,11 @@ // - .A - FAC1 exponent // // See also: -// - [CM64] Computes Mapping the Commodore 64 - page 114 // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // // XXX provide implementation -MOVFM: +MOVFM2: STUB_IMPLEMENTATION() diff --git a/c64/basic/math/MOVFA.s b/c64/basic/math/MOVFA.s new file mode 100644 index 00000000..afc70c4e --- /dev/null +++ b/c64/basic/math/MOVFA.s @@ -0,0 +1,51 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - move FAC1 to FAC2 +// +// Output (all found by experimentation): +// - .A - FAC1 exponent +// - .X - always 0 +// +// Preserves (found by experimentation): +// - .Y +// +// Note: +// - observed that original ROM always clears FACOV, not sure why +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 115 +// - https://www.c64-wiki.com/wiki/BASIC-ROM +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// + +MOVFA: + + // Copy the exponent + lda FAC1_exponent + sta FAC2_exponent + beq !+ // for 0 no need to copy mantissa and sign + + // Copy the mantissa + lda FAC1_mantissa+0 + sta FAC2_mantissa+0 + lda FAC1_mantissa+1 + sta FAC2_mantissa+1 + lda FAC1_mantissa+2 + sta FAC2_mantissa+2 + lda FAC1_mantissa+3 + sta FAC2_mantissa+3 + + // Copy the sign + lda FAC1_sign + sta FAC2_sign + + lda FAC1_exponent +!: + // Duplicate the original ROM behaviour + ldx #$00 + stx FACOV + + rts diff --git a/c64/basic/math/MOVFM.s b/c64/basic/math/MOVFM.s index 844aa6da..93090f85 100644 --- a/c64/basic/math/MOVFM.s +++ b/c64/basic/math/MOVFM.s @@ -21,7 +21,7 @@ // XXX test this -MOVMF: +MOVFM: // Checked in the available documentation: // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic diff --git a/c64/basic/math/ROUND.s b/c64/basic/math/ROUND.s index b7706782..c044abf4 100644 --- a/c64/basic/math/ROUND.s +++ b/c64/basic/math/ROUND.s @@ -43,7 +43,7 @@ ROUND: inc FAC1_exponent bne round_zero_FACOV - // If w are here, it means the exponent wrapped around to $00; put it back to $FF + // If we are here, it means the exponent wrapped around to $00; put it back to $FF dec FAC1_exponent diff --git a/c64/basic/math/bba2.MOVFM.jmp.s b/c64/basic/math/bba2.MOVFM.jmp.s index d62c457d..424296fb 100644 --- a/c64/basic/math/bba2.MOVFM.jmp.s +++ b/c64/basic/math/bba2.MOVFM.jmp.s @@ -4,4 +4,4 @@ // Just a compatibility jump - our routine is longer than original one - jmp MOVMF + jmp MOVFM diff --git a/c64/basic/,stubs_math/bc0f.MOVFA.s b/c64/basic/math/bc0c.MOVAF.s similarity index 55% rename from c64/basic/,stubs_math/bc0f.MOVFA.s rename to c64/basic/math/bc0c.MOVAF.s index fbc9087e..9f0d836e 100644 --- a/c64/basic/,stubs_math/bc0f.MOVFA.s +++ b/c64/basic/math/bc0c.MOVAF.s @@ -3,15 +3,20 @@ // #LAYOUT# * * #IGNORE // -// Math package - copy FAC1 to FAC2, skips rounding +// Math package - round and move FAC1 to FAC2 +// +// Output: +// - .A - FAC1 exponent // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 115 +// - https://www.c64-wiki.com/wiki/BASIC-ROM // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic -// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // -// XXX provide implementation +MOVAF: -MOVFA: - STUB_IMPLEMENTATION() + // First round FAC1 + jsr ROUND + + // FALLTROUGH to MOVFA \ No newline at end of file diff --git a/c64/basic/,stubs_math/bc0f.interop b/c64/basic/math/bc0c.interop similarity index 100% rename from c64/basic/,stubs_math/bc0f.interop rename to c64/basic/math/bc0c.interop diff --git a/c64/basic/math/bc0f.MOVFA.jmp.s b/c64/basic/math/bc0f.MOVFA.jmp.s new file mode 100644 index 00000000..e4efb535 --- /dev/null +++ b/c64/basic/math/bc0f.MOVFA.jmp.s @@ -0,0 +1,7 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// Just a compatibility jump - our routine is longer than original one + + jmp MOVFA diff --git a/c64/basic/math/bc0f.interop b/c64/basic/math/bc0f.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/math/bc0f.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example