Prev: CD3A Up: Map Next: CDEC
CDD6: Multiplier
Multiplies C by the top three bits of A then divides by 8 with rounding, on exit.
Used by the routines at CBD6 and main_loop_10.
Input
A Multiplier (number to multiply by) e.g. $A0, $E7, $20, $C0, $E6
C Multiplicand (value to multiply) e.g. $05, $02, $05, $03, $FE O:A Result e.g. $03, $02, $01, $02, $FE
multiply CDD6 LD B,$03 3 iterations only
CDD8 LD E,A Copy of multiplier to destroy
CDD9 XOR A Initialise total
mult_loop CDDA RL E Shift the most significant bit out of multiplier
CDDC JR NC,mult_continue If the MSB was set then total += multiplicand
CDDE ADD A,C
mult_continue CDDF ADD A,A total <<= 1
CDE0 DJNZ mult_loop While iterations remain, goto mult_loop
CDE2 RRA Undo final shift
CDE3 SRA A Divide by 8 with rounding
CDE5 SRA A
CDE7 SRA A
CDE9 ADC A,$00
CDEB RET Return
Prev: CD3A Up: Map Next: CDEC