diff --git a/STATUS.md b/STATUS.md index 932b3690..411aca8f 100644 --- a/STATUS.md +++ b/STATUS.md @@ -186,12 +186,12 @@ Floating point mathematical routines - not official, but well known and broadly | `$B9EA` | `LOG` | NOT DONE | XXX - no stub added yet | | `$BA28` | `FMUL` | PARTIAL | needs `FMULT` | | `$BA2B` | `FMULT` | NOT DONE | multiplies FAC1 by FAC2 | -| `$BA8C` | `CONUPK` | PARTIAL | not tested yet | +| `$BA8C` | `CONUPK` | PARTIAL | not fully tested yet | | `$BAE2` | `MUL10` | NOT DONE | multiply FAC1 by 10 | | `$BAFE` | `DIV10` | NOT DONE | divide FAC1 by 10, result is always positive | | `$BB0F` | `FDIV` | PARTIAL | needs `FDIVT` | | `$BB12` | `FDIVT` | NOT DONE | divide FAC2 by FAC1, ignores sign | -| `$BBA2` | `MOVFM` | NOT DONE | fetch FAC1 from RAM location | +| `$BBA2` | `MOVFM` | PARTIAL | not fully tested yet | | `$BBD4` | `MOVMF` | 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 | diff --git a/c64/basic/,stubs_math/b853.FSUBT.s b/c64/basic/,stubs_math/b853.FSUBT.s index 6e19e784..58b4a4db 100644 --- a/c64/basic/,stubs_math/b853.FSUBT.s +++ b/c64/basic/,stubs_math/b853.FSUBT.s @@ -9,7 +9,7 @@ // - .A - must load FAC1 exponent ($61) beforehand to set the zero flag // // Note: -// - load FAC2 after FAC1, or mimic the Kernals sign comparison +// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?) // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 112 diff --git a/c64/basic/,stubs_math/b86a.FADDT.s b/c64/basic/,stubs_math/b86a.FADDT.s index a1cf6d08..c48274a3 100644 --- a/c64/basic/,stubs_math/b86a.FADDT.s +++ b/c64/basic/,stubs_math/b86a.FADDT.s @@ -9,7 +9,7 @@ // - .A - must load FAC1 exponent ($61) beforehand to set the zero flag // // Note: -// - load FAC2 after FAC1, or mimic the Kernals sign comparison +// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?) // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 112 diff --git a/c64/basic/,stubs_math/ba2b.FMULT.s b/c64/basic/,stubs_math/ba2b.FMULT.s index 1a3ef3ab..0344f167 100644 --- a/c64/basic/,stubs_math/ba2b.FMULT.s +++ b/c64/basic/,stubs_math/ba2b.FMULT.s @@ -9,7 +9,7 @@ // - .A - must load FAC1 exponent ($61) beforehand to set the zero flag // // Note: -// - load FAC2 after FAC1, or mimic the Kernals sign comparison +// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?) // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 113 XXX address does not match diff --git a/c64/basic/,stubs_math/bba2.MOVFM.s b/c64/basic/,stubs_math/bba2.MOVFM.s deleted file mode 100644 index 8be43857..00000000 --- a/c64/basic/,stubs_math/bba2.MOVFM.s +++ /dev/null @@ -1,25 +0,0 @@ -// #LAYOUT# STD * #TAKE -// #LAYOUT# * BASIC_0 #TAKE -// #LAYOUT# * * #IGNORE - -// -// Math package - copy FAC1 to memory location, rounds if asked -// -// Input: -// - .X - address low byte -// - .Y - address high byte -// - $70 - if MSB is set performs rouding -// -// Output: -// - .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 - -MOVMF: - STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bbd4.MOVMF.s b/c64/basic/,stubs_math/bbd4.MOVMF.s index a144da44..4a7a3d60 100644 --- a/c64/basic/,stubs_math/bbd4.MOVMF.s +++ b/c64/basic/,stubs_math/bbd4.MOVMF.s @@ -3,17 +3,18 @@ // #LAYOUT# * * #IGNORE // -// Math package - fetch FAC1 from RAM location +// Math package - copy FAC1 to memory location, rounds if asked // // Input: -// - .A - address low byte +// - .X - address low byte // - .Y - address high byte +// - $70 - if MSB is set performs rouding // // Output: -// - .A - FAC1 exponent, affects status flags -// - .Y - always 0 +// - .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 // diff --git a/c64/basic/,stubs_math/bf7b.FPWRT.s b/c64/basic/,stubs_math/bf7b.FPWRT.s index 7dfbc8c9..5c58e9f1 100644 --- a/c64/basic/,stubs_math/bf7b.FPWRT.s +++ b/c64/basic/,stubs_math/bf7b.FPWRT.s @@ -9,7 +9,7 @@ // - .A - must load FAC1 exponent ($61) beforehand to set the zero flag // // Note: -// - load FAC2 after FAC1, or mimic the Kernals sign comparison +// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?) // - uses exp(x*log(y)) formula to calculate y^x; slow and inaccurate // // See also: diff --git a/c64/basic/math/ba8c.CONUPK.s b/c64/basic/math/ba8c.CONUPK.s index 9583c4a9..a6ad4722 100644 --- a/c64/basic/math/ba8c.CONUPK.s +++ b/c64/basic/math/ba8c.CONUPK.s @@ -11,10 +11,10 @@ // // Output: // - .A - FAC1 exponent (yes, really - Codebase64 is right) -// - .Y - XXX 0? +// - .Y - 0 (experimentation with original ROM) // // Preserves: -// - .X - (experimentation with original routine) +// - .X - (experimentation with original ROM) // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 114 @@ -26,11 +26,11 @@ CONUPK: - // Not sure which temporary variables are used for storage by the original ROMs, - // but $22/$23 (INDEX+0 and INDEX+1) seem to be good candidates, at least some - // math routines use them as pointer storage, see: + // Checked in the available documentation: // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3 + // that $22/$23 (INDEX+0 and INDEX+1) are at least sometimes used for pointer storage. + // Confirmed by experimenting with original ROM that this is the case here too. sty INDEX+1 sta INDEX+0 @@ -38,8 +38,6 @@ CONUPK: // 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 - ldy #$04 - // Copy the mantissa - reverse byte order ldy #$04 diff --git a/c64/basic/,stubs_math/ba8c.CONUPK.s b/c64/basic/math/bba2.MOVFM.s similarity index 57% rename from c64/basic/,stubs_math/ba8c.CONUPK.s rename to c64/basic/math/bba2.MOVFM.s index 9b042643..f0dbb066 100644 --- a/c64/basic/,stubs_math/ba8c.CONUPK.s +++ b/c64/basic/math/bba2.MOVFM.s @@ -2,35 +2,32 @@ // #LAYOUT# * BASIC_0 #TAKE // #LAYOUT# * * #IGNORE -// -// Math package - fetch FAC2 from RAM location +// Math package - fetch FAC1 from RAM location // // Input: // - .A - address low byte // - .Y - address high byte // // Output: -// - .A - FAC1 exponent (yes, really - Codebase64 is right) -// - .Y - 0 (tested with original ROMs) +// - .A - FAC1 exponent, affects status flags +// - .Y - always 0 // // Preserves: -// - .X (tested with original ROMs) +// - .X - (experimentation with original ROM) // // 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 test this -CONUPK: +MOVMF: - // Noticed in the avilable materials: + // Checked in the available documentation: // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.lemon64.com/forum/viewtopic.php?t=67576&sid=d41e77cdddd28d6f9c9d52ce5b4e8dc3 - // that at least some math routines use $22/$23 (INDEX+0 and INDEX+1) for pointer storage, - // confirmed that this routine is not an exception + // that $22/$23 (INDEX+0 and INDEX+1) are at least sometimes used for pointer storage. + // Confirmed by experimenting with original ROM that this is the case here too. sty INDEX+1 sta INDEX+0 @@ -38,26 +35,24 @@ CONUPK: // 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 - ldy #$04 - // Copy the mantissa - reverse byte order ldy #$04 lda (INDEX), y - sta FAC2_mantissa+3 + sta FAC1_mantissa+3 dey lda (INDEX), y - sta FAC2_mantissa+2 + sta FAC1_mantissa+2 dey lda (INDEX), y - sta FAC2_mantissa+1 + sta FAC1_mantissa+1 dey lda (INDEX), y ora #$80 // clear the sign bit - sta FAC2_mantissa+0 + sta FAC1_mantissa+0 // Copy the sign @@ -68,13 +63,21 @@ CONUPK: !: lda $00 - sta FAC2_sign + sta FAC1_sign // Copy the exponent dey lda (INDEX), y - sta FAC2_exponent + sta FAC1_exponent + + // Set low order mantissa - to my surprise original ROM seems to put 0 to FACOW - XXX why??? + // Since we do not know the original value (lost due to variable format having one byte shorter + // mantissa than FAC1), it is probably best to put some approximate value here; putting $80 + // would be risky in case rouding is performed later, $7F seems to be sane choice + + lda #$7F + sta FACOV // Return the FAC1 exponent diff --git a/c64/basic/,stubs_math/bba2.interop b/c64/basic/math/bba2.interop similarity index 100% rename from c64/basic/,stubs_math/bba2.interop rename to c64/basic/math/bba2.interop