 Introduction
 Arithmetic      - Add, Subtract, Multiply, Divide, Mod      |
 Complement      - Negate (2's Comp) and Complement (1's)
 Logical         - And, Or, Xor
 Rotate / Shift  - Left and Right
:Introduction

These routines are for 16-bit unsigned arithmetic.  HL and DE  |
return the results as indicated, and HL and DE contain the     |
operands required (if only one operand is needed, HL is used).
Available math routines are:

  ADDHD  -- HL = HL + DE     SUBHD -- HL = HL - DE
  MULHD  -- HL = HL * DE     DIVHD -- HL = HL / DE
  SMUL   -- DE,HL = HL * DE -- 32-bit result w/MSW in DE       |
  MODHD  -- HL = HL Mod DE  -- Remainder of HL / DE            |
  SDIV   -- General Divide, HL = HL Mod DE, DE = HL Div DE     |
  NEGH   -- HL = 2's Complement of HL
  CMPH   -- HL = 1's Complement of HL
  ROTLH  -- HL is rotated left one bit position
  ROTRH  -- HL is rotated right one bit position
  SHFTLH -- HL is shifted left one bit position
  SHFTRH -- HL is shifted right one bit position
  ANDHD  -- HL = HL AND DE
  ORHD   -- HL = HL OR DE
  XORHD  -- HL = HL XOR DE

:                  Arithmetic Functions 

All of these routines operate on HL and DE, placing the result
in HL.  The Carry Flag is frequently used to indicate overflow.

ADDHD - 16-bit Addition

  ENTER: HL = Operand #1
         DE = Operand #2
  EXIT : HL = Operand #1 + Operand #2
          Carry Set (C) if Overflow, otherwise Clear (NC)
  USES : F,HL

 Usage:  This routine is not really needed since a simple
  "ADD  HL,DE" one-byte instruction accomplishes the same
  thing with only one byte instead of a 3-byte call.

SUBHD - 16-bit Subtraction

  ENTER: HL = Minuend
         DE = Subtrahend
  EXIT : HL = Minuend - Subtrahend
          Carry Set (C) if DE > HL, otherwise Clear (NC)
  USES : F,HL

 Usage:  This routine is no longer needed with Z80 processors
  since the "SBC  HL,DE" operation accomplishes the same
  function without resorting to a function call.

MULHD - 16-bit Multiplication

  ENTER: HL = Operand #1
         DE = Operand #2
  EXIT : HL = Operand #1 times Operand #2
          Carry Set (C) if result is > 65535
  USES : AF,HL                                                 |

SMUL - 16 by 16-bit Multiplication with 32-bit result          |

  ENTER: HL = Operand # 1                                      |
         DE = Operand # 2                                      |
  EXIT : HL & DE Contain 32-bit product of Multiplication      |
           with MSW in DE (0 if result <= 65535)               |
  USES : AF,BC,DE,HL                                           |

 Usage:  These general-purpose routines may be used at any time|
  to multiply two numbers.  They are optimized for speed taking|
  a constant period of time regardless of the size of numbers. |
  MULHD calls SMUL restoring BC and DE and is therefore some-  |
  what slower.                                                 |

DIVHD - 16-bit Division

  ENTER: HL = Dividend
         DE = Divisor
  EXIT : HL = HL / DE
  USES : HL

SDIV - 16-bit Division with Remainder                          |

  ENTER: HL = Dividend                                         |
         DE = Divisor                                          |
  EXIT : DE = HL Div DE (HL/DE) (Division by 0 yields 0FFFFH)  |
         HL = HL Mod DE (Remainder of the division)            |
  USES : HL,DE                                                 |

MODHD - Remainder of 16-bit Division (Mod)                     |

  ENTER: HL = Dividend                                         |
         DE = Divisor                                          |
  EXIT : HL = HL Mod DE (Remainder of the division)            |
  USES : HL                                                    |

 Usage:  DIVHD, SDIV and MODHD may be used at any time to      |
  divide two numbers.  They are optimized for speed, always    |
  taking a fixed number of calculation loops.  Both DIVHD and  |
  MODHD call SDIV and are therefore slightly slower, but       |
  preserve the DE register pair.                               |

:NEGH - Two's Complement (Negate) a 16-bit Number

  ENTER: HL = 16-bit Operand
  EXIT : HL = Two's Complement of Operand
  USES : HL

 Usage:  This routine simply used to return the 2's
         Complement of a 16-bit number.


CMPH - One's Complement a 16-bit Number

  ENTER: HL = 16-bit Operand
  EXIT : HL = One's Complement of Operand
  USES : HL

 Usage:  This routine simply used to return the 1's
         Complement of a 16-bit number.

:ANDHD - Logically AND two 16-bit values
 ORHD  - Logically OR two 16-bit values
 XORHD - Logically XOR two 16-bit values

  ENTER: HL = Operand #1
         DE = Operand #2
  EXIT : HL = Bitwise Logical AND of two Operands (ANDHD)
              Bitwise Logical OR of two Operands  (ORHD)
              Bitwise Logical XOR of two Operands (XORHD)
  USES : HL

 Usage: These routines simply perform the specified Boolean
        operation on the two supplied 16-bit values, and
        return the result.

:              Rotate and Shift Operations 

ROTLH - One bit Right Rotation of 16-bit value
ROTRH - One bit Left Rotation of 16-bit value

  ENTER: HL = 16-bit operand to rotate
  EXIT : HL = Rotated operand Left (ROTLH) or Right (ROTRH)
  USES : HL

 Usage:  These routines simply rotate the furnished 16-bit
  value left (ROTLH) or right (ROTRH) one bit position.  These
  are circular rotates, in which the most significant bit of H
  is rotated into the least significant bit position of L
  (ROTLH), and least significant bit of L is rotated into the
  most significant bit position of H (ROTRH).


SHFTLH - One bit Right Shift of 16-bit value, Zero Fill
SHFTRH - One bit Left Shift of 16-bit value, Zero Fill

  ENTER: HL = 16-bit operand to shift
  EXIT : HL = Shifted operand Left (SHFTLH) or Right (SHFTRH)
  USES : HL

 Usage:  These routines simply shift the furnished 16-bit
  value left (SHFTLH) or right (SHFTRH) one bit position filling
  the cleared position with a Zero.  In SHFTLH, HL is shifted
  left one bit position with the least significant bit of L
  filled with a Zero.  In SHFTRH, HL is shifted right one bit
  position with the most significant bit of H filled with a Zero.

  Note that SHFTLH is equivalent to the more efficient single
  byte "ADD  HL,HL" operation and SHFTRH is equivalent to the
  four byte Z80 sequence:

          SRL    H
          RR     L
