naming cleanup in math routines

This commit is contained in:
FeralChild64 committed 2020-02-01 22:01:14 +01:00
1 parent a2cd07a94c
commit 4673f825af
39 files changed
+115 -113

No files matched your search

+33 -33
View File
@@ -170,54 +170,54 @@ For the current status of the low memory location implementation andd usage chec
### Math package ### Math package
Floating point mathematical routines - not official, but well known and broadly used. Floating point mathematical routines - not official, but well known and broadly used. Note: there is an awful mess regarding naming (sometimes same name references different routines in different sources), so a custom naming scheme was applied.
<br /> <br />
| Address | Name | Status | Remarks | | Address | Name | Status | Remarks |
| :-------: | :----------- | :------: | :------------------------------------------------: | | :-------: | :----------------- | :------: | :------------------------------------------------: |
| `$B1AA` | `FACINX` | NOT DONE | convert FAC1 to 16-bit signed integer | | `$B1AA` | `FACINX` | NOT DONE | convert FAC1 to 16-bit signed integer |
| `$B391` | `GIVAYF` | NOT DONE | 16-bit signed integer to FAC1 | | `$B391` | `GIVAYF` | NOT DONE | 16-bit signed integer to FAC1 |
| `$B7B5` | `STRVAL` | NOT DONE | imports string to FAC1 | | `$B7B5` | `STRVAL` | NOT DONE | imports string to FAC1 |
| `$B850` | `FSUB` | PARTIAL | needs `FSUBT` | | `$B850` | `sub_MEM_FAC1` | PARTIAL | needs `sub_FAC2_FAC1` |
| `$B853` | `FSUBT` | NOT DONE | subtract FAC1 from FAC2 | | `$B853` | `sub_FAC2_FAC1` | PARTIAL | needs `add_FAC2_FAC1` |
| `$B867` | `FADD` | PARTIAL | needs `FADDT` | | `$B867` | `add_MEM_FAC1` | PARTIAL | needs `add_FAC2_FAC1` |
| `$B86A` | `FADDT` | NOT DONE | add FAC2 to FAC1 | | `$B86A` | `add_FAC2_FAC1` | NOT DONE | |
| `$B8FE` | `NORMAL` | PARTIAL | not tested yet | | `$B8FE` | `normal_FAC1` | PARTIAL | not tested yet |
| `$B9EA` | `LOG` | NOT DONE | natural logarigthm | | `$B9EA` | `log_FAC1` | NOT DONE | |
| `$BA28` | `FMUL` | PARTIAL | needs `FMULT` | | `$BA28` | `mul_MEM_FAC1` | PARTIAL | needs `mul_FAC2_FAC1` |
| `$BA2B` | `FMULT` | NOT DONE | multiplies FAC1 by FAC2 | | `$BA2B` | `mul_FAC2_FAC1` | NOT DONE | |
| `$BA8C` | `CONUPK` | PARTIAL | not fully tested yet | | `$BA8C` | `mov_MEM_FAC2` | PARTIAL | not fully tested yet |
| `$BAE2` | `MUL10` | NOT DONE | multiply FAC1 by 10 | | `$BAE2` | `mul10_FAC1` | NOT DONE | |
| `$BAFE` | `DIV10` | NOT DONE | divide FAC1 by 10, result is always positive | | `$BAFE` | `div10_FAC1_p` | NOT DONE | |
| `$BB0F` | `FDIV` | PARTIAL | needs `FDIVT` | | `$BB0F` | `div_MEM_FAC1` | PARTIAL | needs `div_FAC2_FAC1` |
| `$BB12` | `FDIVT` | NOT DONE | divide FAC2 by FAC1, ignores sign | | `$BB12` | `div_FAC2_FAC1` | NOT DONE | |
| `$BBA2` | `MOVFM` | PARTIAL | not fully tested yet | | `$BBA2` | `mov_MEM_FAC1` | PARTIAL | not fully tested yet |
| `$BBD4` | `MOVFM2` | 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 | | `$BBFC` | `MOVEF` | NOT DONE | copy FAC2 to FAC1 |
| `$BC0C` | `MOVAF` | PARTIAL | not fully tested | | `$BC0C` | `mov_r_FAC1_FAC2` | PARTIAL | not fully tested |
| `$BC0F` | `MOVFA` | DONE | | | `$BC0F` | `mov_FAC1_FAC2` | DONE | |
| `$BC1B` | `ROUND` | PARTIAL | not tested | | `$BC1B` | `round_FAC1` | PARTIAL | not tested |
| `$BC2B` | `SIGN` | NOT DONE | evaluate FAC1 sign | | `$BC2B` | `sgn_FAC1_A` | NOT DONE | |
| `$BC39` | `SGN` | NOT DONE | evaluate FAC1 sign, to FAC1 | | `$BC39` | `sgn_FAC1` | NOT DONE | |
| `$BC58` | `ABS` | NOT DONE | absolute value | | `$BC58` | `abs_FAC1` | NOT DONE | |
| `$BC5B` | `FCOMP` | NOT DONE | compare FAC1 with RAM location | | `$BC5B` | `FCOMP` | NOT DONE | compare FAC1 with RAM location |
| `$BC9B` | `QINT` | NOT DONE | convert FAC1 to 32 bit signed integer | | `$BC9B` | `QINT` | NOT DONE | convert FAC1 to 32 bit signed integer |
| `$BCCC` | `INT` | NOT DONE | rounds away the decimal to make an integer | | `$BCCC` | `int_FAC1` | NOT DONE | |
| `$BCF3` | `FIN` | NOT DONE | imports string to FAC1, ignores spaces | | `$BCF3` | `FIN` | NOT DONE | imports string to FAC1, ignores spaces |
| `$BDDD` | `FOUT` | NOT DONE | outputs FAC1 to string at $0100 | | `$BDDD` | `FOUT` | NOT DONE | outputs FAC1 to string at $0100 |
| `$BF71` | `SQR` | NOT DONE | square root of FAC1 | | `$BF71` | `sqr_FAC1` | NOT DONE | |
| `$BF74` | `SQR2` | NOT DONE | square root of FAC2 | | `$BF74` | `sqr_FAC2` | NOT DONE | |
| `$BF78` | `FPWR` | NOT DONE | set FAC1 as RAM raised to the power of FAC1 | | `$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 | | `$BF7B` | `FPWRT` | NOT DONE | set FAC1 as FAC2 raised to the power of FAC1 |
| `$BFB4` | `NEGOP` | DONE | | | `$BFB4` | `toggle_sign_FAC1` | DONE | |
| `$BFED` | `EXP` | NOT DONE | exponential function, e raised to FAC1 power | | `$BFED` | `exp_FAC1` | NOT DONE | |
| `$E043` | `POLY1` | NOT DONE | evaluate polynomial with odd powers only | | `$E043` | `poly1_FAC1` | NOT DONE | |
| `$E059` | `POLY2` | NOT DONE | evaluate polynomial with odd and even powers | | `$E059` | `poly2_FAC1` | NOT DONE | |
| `$E264` | `COS` | NOT DONE | cosine of FAC1 in radians | | `$E264` | `cos_FAC1` | NOT DONE | |
| `$E26B` | `SIN` | NOT DONE | sine of FAC1 in radians | | `$E26B` | `sin_FAC1` | NOT DONE | |
| `$E2B4` | `TAN` | NOT DONE | tangent of FAC1 in radians | | `$E2B4` | `tan_FAC1` | NOT DONE | |
| `$E30E` | `ATN` | NOT DONE | arc tangent of FAC1 | | `$E30E` | `atn_FAC1` | NOT DONE | |
<br /> <br />
@@ -19,5 +19,5 @@
// XXX provide implementation // XXX provide implementation
FADDT: add_FAC2_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -14,5 +14,5 @@
// XXX provide implementation // XXX provide implementation
LOG: log_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -19,5 +19,5 @@
// XXX provide implementation // XXX provide implementation
FMULT: mul_FAC2_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
MUL10: mul10_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -17,5 +17,5 @@
// XXX provide implementation // XXX provide implementation
DIV10: div10_FAC1_p:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -19,5 +19,5 @@
// XXX provide implementation // XXX provide implementation
FDIVT: div_FAC2_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -16,5 +16,5 @@
// XXX provide implementation // XXX provide implementation
SIGN: sgn_FAC1_A:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -16,5 +16,5 @@
// XXX provide implementation // XXX provide implementation
SGN: sgn_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
ABS: abs_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
INT: int_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -16,5 +16,5 @@
// XXX provide implementation // XXX provide implementation
SQR: sqr_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -16,5 +16,5 @@
// XXX provide implementation // XXX provide implementation
SQR2: sqr_FAC2:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -14,5 +14,5 @@
// XXX provide implementation // XXX provide implementation
EXP: exp_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -23,5 +23,5 @@
// XXX provide implementation // XXX provide implementation
POLY1: poly1_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -23,5 +23,5 @@
// XXX provide implementation // XXX provide implementation
POLY2: poly2_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
File renamed without changes.
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
SIN: sin_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
TAN: tan_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -13,5 +13,5 @@
// XXX provide implementation // XXX provide implementation
ATN: atn_FAC1:
STUB_IMPLEMENTATION() STUB_IMPLEMENTATION()
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
// //
// Math package - add RAM to FAC1 // Math package - subtract FAC1 from memory variable
// //
// Input: // Input:
// - .A - address low byte // - .A - address low byte
@@ -15,8 +15,8 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
// //
FADD: sub_MEM_FAC1:
jsr CONUPK jsr mov_MEM_FAC2
// FALLTROUGH to FADDT // FALLTROUGH to sub_FAC2_FAC1
File renamed without changes.
@@ -5,19 +5,20 @@
// //
// Math package - subtract FAC1 from FAC2 // Math package - subtract FAC1 from FAC2
// //
// Input:
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
//
// Note:
// - load FAC2 after FAC1, or mimic the Kernals sign comparison (XXX do we need it?)
//
// See also: // See also:
// - [CM64] Computes Mapping the Commodore 64 - page 112 // - [CM64] Computes Mapping the Commodore 64 - page 112
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
// //
// XXX provide implementation // XXX test this
FSUBT: sub_FAC2_FAC1:
STUB_IMPLEMENTATION()
// Toggle FAC1 sign
lda FAC1_sign
eor #$FF
sta FAC1_sign
// Perform addition
jmp add_FAC2_FAC1
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
// //
// Math package - subtract FAC1 from RAM // Math package - add memory variable to FAC1
// //
// Input: // Input:
// - .A - address low byte // - .A - address low byte
@@ -15,8 +15,8 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
// //
FSUB: add_MEM_FAC1:
jsr CONUPK jsr mov_MEM_FAC2
// FALLTROUGH to FSUBT // FALLTROUGH to add_FAC2_FAC1
@@ -4,4 +4,4 @@
// Just a compatibility jump - our routine is longer than original one // Just a compatibility jump - our routine is longer than original one
jmp NORMAL jmp normal_FAC1
@@ -18,8 +18,8 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
// //
FMUL: mul_MEM_FAC1:
jsr CONUPK jsr mov_MEM_FAC2
// FALLTROUGH to FMULT // FALLTROUGH to mul_FAC2_FAC1
@@ -4,4 +4,4 @@
// Just a compatibility jump - our routine is longer than original one // Just a compatibility jump - our routine is longer than original one
jmp CONUPK jmp mov_MEM_FAC2
@@ -15,8 +15,8 @@
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics // - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
// //
FDIV: div_MEM_FAC1:
jsr CONUPK jsr mov_MEM_FAC2
// FALLTROUGH to FDIVT // FALLTROUGH to div_FAC2_FAC1
@@ -4,4 +4,4 @@
// Just a compatibility jump - our routine is longer than original one // Just a compatibility jump - our routine is longer than original one
jmp MOVFM jmp mov_MEM_FAC1
@@ -14,9 +14,9 @@
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// //
MOVAF: movr_FAC1_FAC2:
// First round FAC1 // First round FAC1
jsr ROUND jsr round_FAC1
// FALLTROUGH to MOVFA // FALLTROUGH to mov_FAC1_FAC2
+7
View File
@@ -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 mov_FAC1_FAC2
-7
View File
@@ -1,7 +0,0 @@
// #LAYOUT# STD * #TAKE
// #LAYOUT# * BASIC_0 #TAKE
// #LAYOUT# * * #IGNORE
// Just a compatibility jump - our routine is longer than original one
jmp ROUND
@@ -4,4 +4,5 @@
// Just a compatibility jump - our routine is longer than original one // Just a compatibility jump - our routine is longer than original one
jmp MOVFA jmp round_FAC1
@@ -10,7 +10,7 @@
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// //
NEGOP: toggle_sign_FAC1:
lda FAC1_exponent lda FAC1_exponent
beq !+ // do not toggle the sign if value is 0 beq !+ // do not toggle the sign if value is 0
@@ -21,7 +21,7 @@
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
// //
MOVFA: mov_FAC1_FAC2:
// Copy the exponent // Copy the exponent
lda FAC1_exponent lda FAC1_exponent
@@ -21,7 +21,7 @@
// XXX test this // XXX test this
MOVFM: mov_MEM_FAC1:
// Checked in the available documentation: // Checked in the available documentation:
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
@@ -3,7 +3,7 @@
// #LAYOUT# * * #IGNORE // #LAYOUT# * * #IGNORE
// //
// Math package - fetch FAC2 from RAM location // Math package - fetch FAC2 from memory location
// //
// Input: // Input:
// - .A - address low byte // - .A - address low byte
@@ -24,7 +24,7 @@
// XXX test this // XXX test this
CONUPK: mov_MEM_FAC2:
// Checked in the available documentation: // Checked in the available documentation:
// - https://www.c64-wiki.com/wiki/Floating_point_arithmetic // - https://www.c64-wiki.com/wiki/Floating_point_arithmetic
@@ -13,20 +13,20 @@
// XXX test this // XXX test this
NORMAL: normal_FAC1:
lda FAC1_exponent lda FAC1_exponent
beq normal_end // branch if our float is 0 beq normal_FAC1_end // branch if our float is 0
lda FAC1_mantissa+3 lda FAC1_mantissa+3
beq normal_by_byte // branch if we can move the whole byte beq normal_FAC1_by_byte // branch if we can move the whole byte
and #$80 and #$80
bne normal_end // branch if already normalized bne normal_FAC1_end // branch if already normalized
// FALLTROUGH // FALLTROUGH
normal_by_bit: normal_FAC1_by_bit:
// First check the current exponent // First check the current exponent
@@ -49,10 +49,10 @@ normal_by_bit:
rol FAC1_mantissa+1 rol FAC1_mantissa+1
rol FAC1_mantissa+0 rol FAC1_mantissa+0
bcc NORMAL // branch if next iteration needed bcc normal_FAC1 // branch if next iteration needed
rts rts
normal_by_byte: normal_FAC1_by_byte:
// First decrement the exponent by 8, but not below 0 // First decrement the exponent by 8, but not below 0
@@ -63,7 +63,7 @@ normal_by_byte:
lda #$00 lda #$00
!: !:
sta FAC1_exponent sta FAC1_exponent
beq normal_end // branch if our float reached 0 beq normal_FAC1_end // branch if our float reached 0
// Now multiply the mantissa by 8 by moving the whole bytes // Now multiply the mantissa by 8 by moving the whole bytes
@@ -87,7 +87,7 @@ normal_by_byte:
ora FAC1_mantissa+2 ora FAC1_mantissa+2
ora FAC1_mantissa+3 ora FAC1_mantissa+3
bne NORMAL // not 0 - branch to next iteration bne normal_FAC1 // not 0 - branch to next iteration
// Our mantissa reached 0 - mark exponent as 0 and finish // Our mantissa reached 0 - mark exponent as 0 and finish
@@ -95,6 +95,6 @@ normal_by_byte:
// FALLTROUGH // FALLTROUGH
normal_end: normal_FAC1_end:
rts rts
@@ -12,15 +12,15 @@
// XXX test this // XXX test this
ROUND: round_FAC1:
// If number is 0, do not do anything // If number is 0, do not do anything
lda FAC1_exponent lda FAC1_exponent
beq round_done beq round_FAC1_done
lda FACOV lda FACOV
bpl round_zero_FACOV // branch if it is enough to clear FACOV bpl round_FAC1_zero_FACOV // branch if it is enough to clear FACOV
// Increment the 4 bytes of matissa // Increment the 4 bytes of matissa
@@ -28,20 +28,20 @@ ROUND:
// we could have used INW on 65C02 and above, the code would have been smaller! // we could have used INW on 65C02 and above, the code would have been smaller!
inc FAC1_mantissa+3 inc FAC1_mantissa+3
bne round_zero_FACOV bne round_FAC1_zero_FACOV
inc FAC1_mantissa+2 inc FAC1_mantissa+2
bne round_zero_FACOV bne round_FAC1_zero_FACOV
inc FAC1_mantissa+1 inc FAC1_mantissa+1
bne round_zero_FACOV bne round_FAC1_zero_FACOV
inc FAC1_mantissa+0 inc FAC1_mantissa+0
bne round_zero_FACOV bne round_FAC1_zero_FACOV
// If we are here, it means mantissa is 0; put it to minimum allowed and increment exponent // If we are here, it means mantissa is 0; put it to minimum allowed and increment exponent
lda #$80 lda #$80
sta FAC1_mantissa+0 sta FAC1_mantissa+0
inc FAC1_exponent inc FAC1_exponent
bne round_zero_FACOV bne round_FAC1_zero_FACOV
// If we 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
@@ -49,13 +49,13 @@ ROUND:
// FALLTROUGH // FALLTROUGH
round_zero_FACOV: round_FAC1_zero_FACOV:
lda #$00 lda #$00
sta FACOV sta FACOV
// FALLTROUGH // FALLTROUGH
round_done: round_FAC1_done:
rts rts