From 1b300aa39bff9c147c4246764e2e9815d0d94cfa Mon Sep 17 00:00:00 2001 From: FeralChild64 Date: Thu, 30 Jan 2020 21:26:01 +0100 Subject: [PATCH] implemented NORMAL math routine, added more stubs --- STATUS.md | 26 ++++---- c64/basic/,stubs_math/b391.GIVAYF.s | 20 ++++++ c64/basic/,stubs_math/b391.interop | 3 + c64/basic/,stubs_math/b7b5.STRVAL.s | 19 ++++++ c64/basic/,stubs_math/b7b5.interop | 3 + c64/basic/,stubs_math/b9ea.LOG.s | 18 +++++ c64/basic/,stubs_math/b9ea.interop | 3 + c64/basic/,stubs_math/bc2b.SIGN.s | 4 +- c64/basic/,stubs_math/bc39.SGN.s | 20 ++++++ c64/basic/,stubs_math/bc39.interop | 3 + c64/basic/,stubs_math/bc58.ABS.s | 17 +++++ c64/basic/,stubs_math/bc58.interop | 3 + c64/basic/,stubs_math/bc9b.QINT.s | 19 ++++++ c64/basic/,stubs_math/bc9b.interop | 3 + c64/basic/,stubs_math/bccc.INT.s | 17 +++++ c64/basic/,stubs_math/bccc.interop | 3 + c64/basic/,stubs_math/bcf3.FIN.s | 23 +++++++ c64/basic/,stubs_math/bcf3.interop | 3 + c64/basic/,stubs_math/bddd.FOUT.s | 21 ++++++ c64/basic/,stubs_math/bddd.interop | 3 + c64/basic/,stubs_math/bf71.SQR.s | 20 ++++++ c64/basic/,stubs_math/bf71.interop | 3 + c64/basic/,stubs_math/bf74.SQR2.s | 20 ++++++ c64/basic/,stubs_math/bf74.interop | 3 + c64/basic/,stubs_math/bfed.EXP.s | 18 +++++ c64/basic/,stubs_math/bfed.interop | 3 + c64/basic/,stubs_math/e30e.ATN.s | 17 +++++ c64/basic/,stubs_math/e30e.interop | 3 + c64/basic/math/NORMAL.s | 100 ++++++++++++++++++++++++++++ c64/basic/math/b8fe.NORMAL.jmp.s | 7 ++ c64/basic/math/b8fe.interop | 3 + 31 files changed, 414 insertions(+), 14 deletions(-) create mode 100644 c64/basic/,stubs_math/b391.GIVAYF.s create mode 100644 c64/basic/,stubs_math/b391.interop create mode 100644 c64/basic/,stubs_math/b7b5.STRVAL.s create mode 100644 c64/basic/,stubs_math/b7b5.interop create mode 100644 c64/basic/,stubs_math/b9ea.LOG.s create mode 100644 c64/basic/,stubs_math/b9ea.interop create mode 100644 c64/basic/,stubs_math/bc39.SGN.s create mode 100644 c64/basic/,stubs_math/bc39.interop create mode 100644 c64/basic/,stubs_math/bc58.ABS.s create mode 100644 c64/basic/,stubs_math/bc58.interop create mode 100644 c64/basic/,stubs_math/bc9b.QINT.s create mode 100644 c64/basic/,stubs_math/bc9b.interop create mode 100644 c64/basic/,stubs_math/bccc.INT.s create mode 100644 c64/basic/,stubs_math/bccc.interop create mode 100644 c64/basic/,stubs_math/bcf3.FIN.s create mode 100644 c64/basic/,stubs_math/bcf3.interop create mode 100644 c64/basic/,stubs_math/bddd.FOUT.s create mode 100644 c64/basic/,stubs_math/bddd.interop create mode 100644 c64/basic/,stubs_math/bf71.SQR.s create mode 100644 c64/basic/,stubs_math/bf71.interop create mode 100644 c64/basic/,stubs_math/bf74.SQR2.s create mode 100644 c64/basic/,stubs_math/bf74.interop create mode 100644 c64/basic/,stubs_math/bfed.EXP.s create mode 100644 c64/basic/,stubs_math/bfed.interop create mode 100644 c64/basic/,stubs_math/e30e.ATN.s create mode 100644 c64/basic/,stubs_math/e30e.interop create mode 100644 c64/basic/math/NORMAL.s create mode 100644 c64/basic/math/b8fe.NORMAL.jmp.s create mode 100644 c64/basic/math/b8fe.interop diff --git a/STATUS.md b/STATUS.md index 411aca8f..8d4e76d4 100644 --- a/STATUS.md +++ b/STATUS.md @@ -177,13 +177,14 @@ Floating point mathematical routines - not official, but well known and broadly | Address | Name | Status | Remarks | | :-------: | :----------- | :------: | :------------------------------------------------: | | `$B1AA` | `FACINX` | NOT DONE | convert FAC1 to 16-bit signed integer | -| `$B391` | `GIVAYF` | NOT DONE | XXX - no stub added yet | -| `$B7B5` | `STRVAL` | NOT DONE | XXX - no stub added yet | +| `$B391` | `GIVAYF` | NOT DONE | 16-bit signed integer to FAC1 | +| `$B7B5` | `STRVAL` | NOT DONE | imports string to FAC1 | | `$B850` | `FSUB` | PARTIAL | needs `FSUBT` | | `$B853` | `FSUBT` | NOT DONE | subtract FAC1 from FAC2 | | `$B867` | `FADD` | PARTIAL | needs `FADDT` | | `$B86A` | `FADDT` | NOT DONE | add FAC2 to FAC1 | -| `$B9EA` | `LOG` | NOT DONE | XXX - no stub added yet | +| `$B8FE` | `NORMAL` | PARTIAL | not tested yet | +| `$B9EA` | `LOG` | NOT DONE | natural logarigthm | | `$BA28` | `FMUL` | PARTIAL | needs `FMULT` | | `$BA2B` | `FMULT` | NOT DONE | multiplies FAC1 by FAC2 | | `$BA8C` | `CONUPK` | PARTIAL | not fully tested yet | @@ -196,24 +197,25 @@ Floating point mathematical routines - not official, but well known and broadly | `$BBFC` | `MOVEF` | NOT DONE | copy FAC2 to FAC1 | | `$BC0F` | `MOVFA` | NOT DONE | copy FAC1 to FAC2, skips rounding | | `$BC2B` | `SIGN` | NOT DONE | evaluate FAC1 sign | -| `$BC39` | `SGN` | NOT DONE | XXX - no stub added yet | -| `$BC58` | `ABS` | NOT DONE | XXX - no stub added yet | +| `$BC39` | `SGN` | NOT DONE | evaluate FAC1 sign, to FAC1 | +| `$BC58` | `ABS` | NOT DONE | absolute value | | `$BC5B` | `FCOMP` | NOT DONE | compare FAC1 with RAM location | -| `$BC9B` | `QINT` | NOT DONE | XXX - no stub added yet | -| `$BCCC` | `INT` | NOT DONE | XXX - no stub added yet | -| `$BCF3` | `FIN` | NOT DONE | XXX - no stub added yet | -| `$BDDD` | `FOUT` | NOT DONE | XXX - no stub added yet | -| `$BF71` | `SQR` | NOT DONE | XXX - no stub added yet | +| `$BC9B` | `QINT` | NOT DONE | convert FAC1 to 32 bit signed integer | +| `$BCCC` | `INT` | NOT DONE | rounds away the decimal to make an integer | +| `$BCF3` | `FIN` | NOT DONE | imports string to FAC1, ignores spaces | +| `$BDDD` | `FOUT` | NOT DONE | outputs FAC1 to string at $0100 | +| `$BF71` | `SQR` | NOT DONE | square root of FAC1 | +| `$BF74` | `SQR2` | NOT DONE | square root of FAC2 | | `$BF78` | `FPWR` | NOT DONE | set FAC1 as RAM raised to the power of FAC1 | | `$BF7B` | `FPWRT` | NOT DONE | set FAC1 as FAC2 raised to the power of FAC1 | | `$BFB4` | `NEGOP` | DONE | | -| `$BFED` | `EXP` | NOT DONE | XXX - no stub added yet | +| `$BFED` | `EXP` | NOT DONE | exponential function, e raised to FAC1 power | | `$E043` | `POLY1` | NOT DONE | evaluate polynomial with odd powers only | | `$E059` | `POLY2` | NOT DONE | evaluate polynomial with odd and even powers | | `$E264` | `COS` | NOT DONE | cosine of FAC1 in radians | | `$E26B` | `SIN` | NOT DONE | sine of FAC1 in radians | | `$E2B4` | `TAN` | NOT DONE | tangent of FAC1 in radians | -| `$E30E` | `ATN` | NOT DONE | XXX - no stub added yet | +| `$E30E` | `ATN` | NOT DONE | arc tangent of FAC1 |
diff --git a/c64/basic/,stubs_math/b391.GIVAYF.s b/c64/basic/,stubs_math/b391.GIVAYF.s new file mode 100644 index 00000000..44650977 --- /dev/null +++ b/c64/basic/,stubs_math/b391.GIVAYF.s @@ -0,0 +1,20 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - 16-bit signed integer to FAC1 +// +// Output: +// - .A - address high byte (XXX really, not the opposite?) +// - .Y - address low byte +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 107 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// + +// XXX provide implementation + +GIVAYF: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/b391.interop b/c64/basic/,stubs_math/b391.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/b391.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/b7b5.STRVAL.s b/c64/basic/,stubs_math/b7b5.STRVAL.s new file mode 100644 index 00000000..35ae53d4 --- /dev/null +++ b/c64/basic/,stubs_math/b7b5.STRVAL.s @@ -0,0 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - imports string to FAC1 - XXX: what about spaces? +// +// Input: +// - .A needs to be loaded with string length +// - string address in $22/$23 +// +// See also: +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// + +// XXX provide implementation + +STRVAL: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/b7b5.interop b/c64/basic/,stubs_math/b7b5.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/b7b5.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/b9ea.LOG.s b/c64/basic/,stubs_math/b9ea.LOG.s new file mode 100644 index 00000000..3fc121a7 --- /dev/null +++ b/c64/basic/,stubs_math/b9ea.LOG.s @@ -0,0 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - natural logarigthm +// +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 113 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +LOG: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/b9ea.interop b/c64/basic/,stubs_math/b9ea.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/b9ea.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bc2b.SIGN.s b/c64/basic/,stubs_math/bc2b.SIGN.s index e0a98612..151b25d5 100644 --- a/c64/basic/,stubs_math/bc2b.SIGN.s +++ b/c64/basic/,stubs_math/bc2b.SIGN.s @@ -3,10 +3,10 @@ // #LAYOUT# * * #IGNORE // -// Math package - evaluate FAC1 sign +// Math package - evaluate FAC1 sign, to .A // // Output: -// - .A - $00 for equal, $01 for FAC1 > RAM, $FF for FAC1 < RAM +// - .A - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0 // // See also: // - [CM64] Computes Mapping the Commodore 64 - page 115 diff --git a/c64/basic/,stubs_math/bc39.SGN.s b/c64/basic/,stubs_math/bc39.SGN.s new file mode 100644 index 00000000..1b53f34c --- /dev/null +++ b/c64/basic/,stubs_math/bc39.SGN.s @@ -0,0 +1,20 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - evaluate FAC1 sign, to FAC1 +// +// Output: +// - FAC1 - 0 for FAC1 equal 0, 1 for FAC1 > 0, -1 for FAC1 < 0 +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 115 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +SGN: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bc39.interop b/c64/basic/,stubs_math/bc39.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bc39.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bc58.ABS.s b/c64/basic/,stubs_math/bc58.ABS.s new file mode 100644 index 00000000..a152eb7e --- /dev/null +++ b/c64/basic/,stubs_math/bc58.ABS.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - absolute value +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 115 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +ABS: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bc58.interop b/c64/basic/,stubs_math/bc58.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bc58.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bc9b.QINT.s b/c64/basic/,stubs_math/bc9b.QINT.s new file mode 100644 index 00000000..8414d0bd --- /dev/null +++ b/c64/basic/,stubs_math/bc9b.QINT.s @@ -0,0 +1,19 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - convert FAC1 to 32 bit signed integer +// +// Output: +// - $62-$65, big-endian order +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 115 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// + +// XXX provide implementation + +QINT: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bc9b.interop b/c64/basic/,stubs_math/bc9b.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bc9b.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bccc.INT.s b/c64/basic/,stubs_math/bccc.INT.s new file mode 100644 index 00000000..a693a85d --- /dev/null +++ b/c64/basic/,stubs_math/bccc.INT.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - rounds away the decimal to make an integer +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 116 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +INT: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bccc.interop b/c64/basic/,stubs_math/bccc.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bccc.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bcf3.FIN.s b/c64/basic/,stubs_math/bcf3.FIN.s new file mode 100644 index 00000000..2b85c855 --- /dev/null +++ b/c64/basic/,stubs_math/bcf3.FIN.s @@ -0,0 +1,23 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - imports string to FAC1, ignores spaces +// +// +// Input: +// - .A needs to be loaded with first char of the string +// - Carry flag must be clear +// - string address in $7A/$7B +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 116 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +FIN: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bcf3.interop b/c64/basic/,stubs_math/bcf3.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bcf3.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bddd.FOUT.s b/c64/basic/,stubs_math/bddd.FOUT.s new file mode 100644 index 00000000..c0597d05 --- /dev/null +++ b/c64/basic/,stubs_math/bddd.FOUT.s @@ -0,0 +1,21 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - outputs FAC1 to string at $0100 +// +// Output: +// - .A - address low byte +// - .Y - address high byte +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 116 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +FOUT: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bddd.interop b/c64/basic/,stubs_math/bddd.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bddd.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bf71.SQR.s b/c64/basic/,stubs_math/bf71.SQR.s new file mode 100644 index 00000000..4e1a3115 --- /dev/null +++ b/c64/basic/,stubs_math/bf71.SQR.s @@ -0,0 +1,20 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - square root of FAC1 +// +// Note: +// - transfers FAC1 to FAC2 and falls through to SQR2 +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 117 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +SQR: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bf71.interop b/c64/basic/,stubs_math/bf71.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bf71.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bf74.SQR2.s b/c64/basic/,stubs_math/bf74.SQR2.s new file mode 100644 index 00000000..abf1fc2d --- /dev/null +++ b/c64/basic/,stubs_math/bf74.SQR2.s @@ -0,0 +1,20 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - square root of FAC2 +// +// Note: +// - loads .5 into FAC1 and falling through to the exponentiation routine +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 117 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +SQR2: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bf74.interop b/c64/basic/,stubs_math/bf74.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bf74.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/bfed.EXP.s b/c64/basic/,stubs_math/bfed.EXP.s new file mode 100644 index 00000000..7ad24634 --- /dev/null +++ b/c64/basic/,stubs_math/bfed.EXP.s @@ -0,0 +1,18 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - exponential function, e raised to FAC1 power +// +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 117 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +EXP: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/bfed.interop b/c64/basic/,stubs_math/bfed.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/bfed.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/,stubs_math/e30e.ATN.s b/c64/basic/,stubs_math/e30e.ATN.s new file mode 100644 index 00000000..642cea97 --- /dev/null +++ b/c64/basic/,stubs_math/e30e.ATN.s @@ -0,0 +1,17 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - arc tangent of FAC1 +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 211 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX provide implementation + +ATN: + STUB_IMPLEMENTATION() diff --git a/c64/basic/,stubs_math/e30e.interop b/c64/basic/,stubs_math/e30e.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/,stubs_math/e30e.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example diff --git a/c64/basic/math/NORMAL.s b/c64/basic/math/NORMAL.s new file mode 100644 index 00000000..f1e8fb61 --- /dev/null +++ b/c64/basic/math/NORMAL.s @@ -0,0 +1,100 @@ +// #LAYOUT# STD * #TAKE +// #LAYOUT# * BASIC_0 #TAKE +// #LAYOUT# * * #IGNORE + +// +// Math package - normalize FAC1 +// +// See also: +// - [CM64] Computes Mapping the Commodore 64 - page 113 +// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic +// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics +// + +// XXX test this + +NORMAL: + + lda FAC1_exponent + beq normal_end // branch if our float is 0 + + lda FAC1_mantissa+3 + beq normal_by_byte // branch if we can move the whole byte + + and #$80 + bne normal_end // branch if already normalized + + // FALLTROUGH + +normal_by_bit: + + // First check the current exponent + + lda FAC1_exponent + cmp #$01 + bne !+ + + // Exponent is 1 - just mark the whole number as 0 and finish + + lda #$00 + sta FAC1_exponent + rts +!: + // Multiply the mantissa by 2 + + clc + rol FACOV + rol FAC1_mantissa+0 + rol FAC1_mantissa+1 + rol FAC1_mantissa+2 + rol FAC1_mantissa+3 + + bcc NORMAL // branch if next iteration needed + rts + +normal_by_byte: + + // First decrement the exponent by 8, but not below 0 + + lda FAC1_exponent + sec + sbc #$08 + bcs !+ + lda #$00 +!: + sta FAC1_exponent + beq normal_end // branch if our float reached 0 + + // Now multiply the mantissa by 8 by moving the whole bytes + + lda FAC1_mantissa+2 + sta FAC1_mantissa+3 + lda FAC1_mantissa+1 + sta FAC1_mantissa+2 + lda FAC1_mantissa+0 + sta FAC1_mantissa+1 + + lda FACOV + sta FAC1_mantissa+0 + + lda #$00 + sta FACOV + + // Now check if mantissa is not 0 + + ora FAC1_mantissa+0 + ora FAC1_mantissa+1 + ora FAC1_mantissa+2 + ora FAC1_mantissa+3 + + bne NORMAL // not 0 - branch to next iteration + + // Our mantissa reached 0 - mark exponent as 0 and finish + + sta FAC1_exponent + + // FALLTROUGH + +normal_end: + + rts diff --git a/c64/basic/math/b8fe.NORMAL.jmp.s b/c64/basic/math/b8fe.NORMAL.jmp.s new file mode 100644 index 00000000..7c5c26b8 --- /dev/null +++ b/c64/basic/math/b8fe.NORMAL.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 NORMAL diff --git a/c64/basic/math/b8fe.interop b/c64/basic/math/b8fe.interop new file mode 100644 index 00000000..0d18777c --- /dev/null +++ b/c64/basic/math/b8fe.interop @@ -0,0 +1,3 @@ +This is an important floating point math routine, documented in many places. + +XXX - try to find real-life example