home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / PROGPACK / BITMATH.LBR / BITMATH.HZP / BITMATH.HLP
Text File  |  1989-10-31  |  4KB  |  144 lines

  1. BITMATH Introduction
  2. Set, Reset, or Test a bit in the byte at HL.........SET_M, RES_M, TST_M
  3. Logical AND, OR, XOR with (HL), result in (HL)....ANDM2M, ORM2M, XORM2M
  4. Reverse the bit order in the byte at HL..........................MIRROR
  5. Set bit n in A, reset others......................................EXP_A
  6. Return LOG(A) in A, ignoring all but highest bit.................LOG2_A
  7. Set up to 8 least significant bits in A, others reset.............MASK8
  8. Set up to 16 least significant bits in BC, others reset..........MASK16
  9. BITMATH Introduction
  10.  
  11. This a collection of routines to manipulate the bits in a byte at HL,
  12. and routines to perform certain binary pseudo-exponential operations
  13. to create bit patterns for logical masking. Examples are:
  14.  
  15.     Input        Output        Function/Routine
  16.     05h        00100000b        EXP_A
  17.     001xxxxx    05h            LOG2_A
  18.     05h        00111111b        MASK8
  19.     0Bh        00001111 11111111    MASK16
  20.     01011101    10111010        MIRROR
  21.  
  22. The MASKn functions are really [EXP(A+1) - 1], a function encountered
  23. in Directory and DPB calculations. (EXP(n) = "raise 2 to power n")
  24.  
  25. LOG2_A is the inverse operation to MASK8, not a true binary LOG.
  26. It ignores all but the highest order bit in (input).
  27.  
  28. The MIRROR function is used to convert bytes between low-bit-first
  29. and high-bit-first for display convenience.
  30. Set, Reset, or Test a bit in the byte at HL
  31.  
  32.      Routines:            SET_M, RES_M, TST_M
  33.  
  34.      Function:            Set, Reset, or Test a bit 
  35.                 in the byte at HL
  36.  
  37.      Inputs:            A  = bit number (0-7)
  38.                 HL = address of the byte
  39.  
  40.      Outputs:            The bit is set, reset, or tested
  41.  
  42.      Registers Affected:      AF,BC
  43.  
  44.     FLAGS:  if Z, c = a = 0, else NZ, c = a = 0ffh
  45. NOTE: the z/nz returns are significant only for TST_M
  46. Logical AND, OR, XOR with (HL), result in (HL)
  47.  
  48.      Routine:            ANDM2M, ORM2M, XORM2M
  49.  
  50.      Function:            as above, and implied in names
  51.  
  52.      Inputs:            A = byte to combine with (HL)
  53.                 HL = address of memory operand
  54.  
  55.      Outputs:            byte in memory is modified
  56.  
  57.      Registers Affected:    AF
  58.  
  59. Reverse the bit order in the byte at HL. (mirror image)
  60.  
  61.  
  62.      Routine:            MIRROR
  63.  
  64.      Function:            Invert the order of the bits at (hl)
  65.                 by swapping bits 0-7,1-6,2-5,3-4
  66.  
  67.      Inputs:            HL = addr of byte to invert
  68.  
  69.      Outputs:            mirror image in (HL)
  70.  
  71.      Registers Affected:    AF
  72.                 all other registers preserved
  73.  
  74. Set bit n in A, reset others.
  75.  
  76.      Routine:            EXP_A
  77.  
  78.      Function:            Set a single bit in reg A,
  79.                 reset all others.
  80.  
  81.      Inputs:            A = bit position to set (0-7)
  82.  
  83.      Outputs:            A = requested bit set, others 0
  84.  
  85.      Registers Affected:    all other registers preserved.
  86.                 flags are undefined
  87.  
  88. Return LOG(A) in A, ignoring all but highest bit.
  89.  
  90.      Routine:            LOG2_A:
  91.  
  92.      Function:            Convert a byte to the ordinal number
  93.                 in binary corresponding to the bit 
  94.                 position of the highest bit set in 
  95.                 the byte. This is a special case of
  96.                 log n, where n= 0...7
  97.  
  98.      Inputs:            A = the byte to convert
  99.  
  100.      Outputs:            A contains the log of A (bit position)
  101.  
  102.      Registers Affected:    AF
  103.                 Other registers preserved
  104. Set up to 8 least significant bits in A, others reset.
  105.  
  106.      Routine:            MASK8
  107.  
  108.      Function:            Set n least significant bits in reg A.
  109.                 Remaining bits are reset.
  110.                 n is specified as a number, (0-7) which
  111.                 defines the highest bit set.
  112.  
  113.      Inputs:            A = highest bit to set (0-7)
  114.  
  115.      Outputs:            A = filled with 1's from position
  116.                 0 up through position specified
  117.  
  118.      Registers Affected:    AF
  119.  
  120. Set up to 16 least significant bits in BC, others reset.
  121.  
  122.      Routine:            MASK16
  123.  
  124.      Function:            Set the n least significant bits in
  125.                 register pair BC according to the
  126.                 value n(0..15) in A.
  127.  
  128.      Inputs:            A = highest bit set position
  129.  
  130.      Outputs:            BC contains the mask
  131.  
  132.      Registers Affected:    BC is used
  133.                 A is not preserved
  134.  
  135.      Other Routines Called:    MASK8
  136.