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 / ARRAYS10.LBR / ARRAY2.ZZ0 / ARRAY2.Z80
Text File  |  2000-06-30  |  3KB  |  109 lines

  1. ;Library Name: ARRAYLIB
  2. ;Module Name: REVERSE
  3. ;Author: Al Hawley
  4. ;Date: 31 Mar 1987
  5. ;Version number: 1.0c
  6.  
  7. ;Version History:
  8.     
  9. ;Program Function: ARRAYLIB is a collection of subroutines which
  10. ;    implement the management of byte arrays in programs written
  11. ;    for Z80 or HD64180 based computers. This module is one of the
  12. ;    set, and may require the presence of others.
  13.  
  14. ;***************************************************
  15. ;        COPYRIGHT NOTICE
  16. ;ARRAYLIB is copyright by A. E. Hawley on March 4, 1987.
  17. ;It may be freely distributed, but it must not be sold 
  18. ;either separately or as part of a package without the 
  19. ;written consent of the author.  The author may be reached 
  20. ;via electronic mail at the Ladera Z-Node in Los Angeles,
  21. ;213-670-9465, or by Voice Phone at: 213-649-3575
  22. ;
  23. ;***************************************************
  24.  
  25.     MACLIB    ARRHDR
  26.  
  27.     name reverse
  28. ;This module contains the following routines:
  29.     public arinvert
  30.  
  31. arinvert:
  32. ;invert the order of the bits in each byte of a (dumaplen)
  33. ;byte disk/user map from row 0, column 0 to the end.
  34.     ld    hl,(bitmap)    ;address of row 0, col 0
  35.     ld    a,h
  36.     or    a,l
  37.     ld    a,1        ;error code - undef array
  38.     scf            ;in case hl = 0 (undef array)
  39.     ret    z        ;return if undef array
  40.  
  41.     ld    a,(dumaplen)
  42.     ld    b,a        ;length of du map
  43. invrt1:    call    armirror    ;invert bits at (hl). bc preserved
  44.     inc    hl
  45.     djnz    invrt1
  46.     ret
  47.  
  48. ;*************************************
  49.  
  50. armirror:
  51. ;invert the order of the bits at (hl)
  52. ;input: hl = addr of byte to invert
  53. ;output: mirror image in (hl)
  54. ;  swap bits 0-7,1-6,2-5,3-4
  55. ; reg a is destroyed
  56. ;all other registers preserved
  57.  
  58. ;test for common symetrical cases and
  59. ;do nothing (it's faster)
  60.     ld    a,(hl)
  61.     or    a    ;00000000b?
  62.     ret    z
  63.     cp    0ffh    ;11111111b?
  64.     ret    z
  65. ;probably not symetrical. make mirror image.
  66.     push    bc
  67.     rra        ;lsb->cy, rotate right
  68.     rl    c    ;cy-lsb, rotate left
  69.     rra        ;..repeat 7 more times
  70.     rl    c
  71.     rra
  72.     rl    c    ;this code would be shorter
  73.     rra        ;..if done in a loop, but
  74.     rl    c    ;..also slower
  75.     rra
  76.     rl    c
  77.     rra
  78.     rl    c
  79.     rra
  80.     rl    c
  81.     rra
  82.     rl    c    ;reversed pattern in c
  83.     ld    (hl),c    ;store at memory loc
  84.     pop    bc
  85.     ret
  86.  
  87. ;**********************************************
  88.  
  89.     IF    ZAS
  90.     COMMON            ;common block for ZAS
  91.     ELSE
  92.     COMMON    /ADATA/        ;common block for M80, SLR
  93.     ENDIF
  94.  
  95. ;COMMON data area - contains default values for a 64
  96. ;byte array useful for disk/user bitmapping.
  97. bitmap:    ds    2    ;..filled in by ARRAYDEF
  98. hicol:    ds    2    ;default is 4 columns: 0,1,2,3
  99. hirow:    ds    2    ;default is 16 rows (0....15)
  100. dumaplen:
  101.     ds    2    ;default is (3+1)*(15+1)
  102.  
  103. maxdu:    ds    2    ;transient d/u data
  104. curloc:    ds    2    ;NDR entry pointer
  105.  
  106. ;**********************************************
  107.  
  108.     end
  109.