some work towards division
This commit is contained in:
1 parent
f1d2f8d53d
commit
d762c49312
2 files changed
+62
-10
No files matched your search
@@ -4,13 +4,17 @@
|
||||
// #LAYOUT# * * #IGNORE
|
||||
|
||||
//
|
||||
// Math package - divide FAC2 (dividend) by FAC1 (divisor), ignores sign
|
||||
// Math package - divide FAC2 (dividend) by FAC1 (divisor)
|
||||
//
|
||||
// Input:
|
||||
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag
|
||||
// - .A - must load FAC1 exponent ($61) beforehand to set the zero flag (but our routine does not need this)
|
||||
//
|
||||
// Output:
|
||||
// - leaves the quotient FAC1 and the remainder in FAC2
|
||||
// - FAC1
|
||||
//
|
||||
// Note:
|
||||
// - some documentation suggest this is a division leaving quotient and remainder (left in FAC2),
|
||||
// but it seems (experimentation) that this is not true
|
||||
//
|
||||
// See also:
|
||||
// - [CM64] Computes Mapping the Commodore 64 - page 114
|
||||
@@ -18,19 +22,61 @@
|
||||
// - https://codebase64.org/doku.php?id=base:kernal_floating_point_mathematics
|
||||
//
|
||||
|
||||
// XXX provide implementation
|
||||
// XXX finish the implementation
|
||||
|
||||
div_FAC2_FAC1:
|
||||
|
||||
// 'Pamiętaj, cholero - nie dziel przez zero!' - ancient polish proverb
|
||||
|
||||
lda FAC1_exponent
|
||||
beq_16 do_DIVISION_BY_ZERO_error
|
||||
|
||||
// Handle special case - dividing 0 by non-zero value
|
||||
|
||||
lda FAC2_exponent
|
||||
beq div_FAC2_FAC1_setexp_quit
|
||||
|
||||
// Multiply signs
|
||||
|
||||
lda FAC1_sign
|
||||
eor FAC2_sign
|
||||
sta FAC1_sign
|
||||
|
||||
// Subtract the exponents XXX what about bias?
|
||||
|
||||
lda FAC2_exponent
|
||||
sec
|
||||
sbc FAC1_exponent
|
||||
bcs !+
|
||||
|
||||
// Result too low, set 0 and quit
|
||||
|
||||
lda #$00
|
||||
|
||||
div_FAC2_FAC1_setexp_quit:
|
||||
|
||||
sta FAC1_exponent
|
||||
rts
|
||||
|
||||
!:
|
||||
adc #$07 // add 8, as the carry is set here
|
||||
bcs_16 set_FAC1_max // overflow
|
||||
sta FAC1_exponent
|
||||
|
||||
// Divide the mantissas
|
||||
|
||||
// XXX
|
||||
|
||||
|
||||
|
||||
|
||||
STUB_IMPLEMENTATION()
|
||||
|
||||
|
||||
|
||||
// XXX adapt, move this to a separate file
|
||||
|
||||
|
||||
|
||||
// XXX move this to a separate file
|
||||
|
||||
// Unsigned integer 32-bit mantissa division, based on code by Verz
|
||||
// Unsigned integer 32-bit division, based on code by Verz
|
||||
// divident: FAC2_mantissa, divisor: FAC1_mantissa, result: FAC2_mantissa, remainder: RESHO
|
||||
// temporary storage: INDEX+1, INDEX+2, INDEX+3
|
||||
//
|
||||
@@ -106,3 +152,9 @@ div_mantissas_skip:
|
||||
bne div_mantissas_loop
|
||||
|
||||
rts
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ std::vector<ConstEntry> GLOBAL_constants =
|
||||
ConstEntry( "LOG_2", std::log(2.0) ),
|
||||
ConstEntry( "INV_LOG_2", 1.0 / std::log(2.0) ),
|
||||
|
||||
// Constants for sine approximation, minimized abs. error, degree 11, from:
|
||||
// Constants for sine approximation, minimized abs. error, degree 11, for [0, pi/2], from:
|
||||
// - https://publik-void.github.io/sin-cos-approximations/
|
||||
|
||||
ConstEntry( "POLY_SIN_1", -2.3794713545277060334805162803882547e-8 ),
|
||||
|
||||
Reference in new issue
Block a user