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 / ARRAYC.ZZ0 / ARRAYC.Z80
Text File  |  2000-06-30  |  4KB  |  148 lines

  1. ;Library Name: ARRAYLIB
  2. ;Module Name: AXLATE
  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 axlate
  28. ;This module contains the following routines:
  29.     public arxltbit,arrxltrc
  30. ;..and uses the following external routines:
  31.     ext mulhd    ;from SYSLIB or HD180
  32.  
  33. arxltbit:
  34. ;translates a row,bit address to a column address
  35. ; and a bit position for a row in the matrix.
  36. ;on input,
  37. ;    b    = row number
  38. ;    c    = bit number (0...max allowed)
  39. ;on exit,
  40. ;    b    = row number
  41. ;    c    = column number
  42. ;    e    = bit position (0-7) in column (c)
  43. ;    a    = e
  44. ;other registers are preserved
  45. ;
  46. ;this is an integer division by 8 (bits/byte),
  47. ; accomplished by shifting c right 3 times.
  48. ;the bit position is the 3 least significant bits
  49. ; of reg c, which are first saved in reg e.
  50.  
  51.     ld    a,c
  52.     and    a,7    ;bit position
  53.     ld    e,a    ;offset, for return
  54.     srl    c    ;divide by 8 (bits/byte)
  55.     srl    c
  56.     srl    c
  57.     ld    a,(hicol)
  58.     cp    a,c    ;=< max num of columns?
  59.     ld    a,e
  60.     ret        ;ret cy set if out of range
  61.  
  62. ;**********************************************
  63.  
  64. arrxltrc:
  65. ;translate row/column input data to the absolute
  66. ;address of the byte being specified.
  67. ;on input,
  68. ;    b    = row number
  69. ;    c    = column number
  70. ;on exit,
  71. ;    hl    = address of the byte
  72. ;error condition:
  73. ;    no error: a=0, z, nc
  74. ;    if error: a = error code, carry set
  75. ;    a    = 1 if bitmap not yet defined
  76. ;    a    = 2 if address is out of range
  77. ;bc and de are preserved
  78.  
  79.     push    bc
  80.     push    de
  81.     ld    hl,rownum    ;save requested indexes
  82.     ld    (hl),b        ;in local memory
  83.     inc    hl
  84.     inc    hl
  85.     ld    (hl),c
  86.  
  87. ;test for row number beyond array
  88.     ld    a,(hirow)
  89.     cp    a,b        ;b must be =< (hirow)
  90.     ld    a,2        ;in case of error, code 2
  91.     jr    c,xerror    ;if address out of bounds
  92.  
  93. ;test for undefined bitmap
  94.     ld    hl,(bitmap)
  95.     ld    a,h
  96.     or    a,l        ;test. 0 if undefined
  97.     ld    a,1        ;error code
  98.     jr    z,xerror    ;if bitmap undefined
  99.  
  100.     ld    de,(hicol)    ;highest column number
  101.     inc    de        ;number of columns
  102.  
  103. ;calculate relative address of array element
  104.     ld    hl,(rownum)    ;row number
  105.     call    mulhd        ;multiply row number by cols/row
  106.                 ;overflow test not needed, high bytes are 00.
  107.     ld    bc,(colnum)
  108.     add    hl,bc        ;relative addr of element
  109.  
  110. ;calc absolute address of the array element
  111.     ld    de,(bitmap)    ;base addr of bitmap
  112.     add    hl,de        ;absolute addr of target byte
  113.     xor    a        ;reset carry
  114.     pop    de
  115.     pop    bc
  116.     ret            ;normal return
  117.  
  118. xerror:    pop    de
  119.     pop    bc
  120.     scf
  121.     ret            ;error return, cy set
  122.  
  123. rownum:    dw    0
  124. colnum:    dw    0
  125.  
  126. ;**********************************************
  127.  
  128.     IF    ZAS
  129.     COMMON            ;common block for ZAS
  130.     ELSE
  131.     COMMON    /ADATA/        ;common block for M80, SLR
  132.     ENDIF
  133.  
  134. ;COMMON data area - contains default values for a 64
  135. ;byte array useful for disk/user bitmapping.
  136. bitmap:    ds    2    ;..filled in by ARRAYDEF
  137. hicol:    ds    2    ;default is 4 columns: 0,1,2,3
  138. hirow:    ds    2    ;default is 16 rows (0....15)
  139. dumaplen:
  140.     ds    2    ;default is (3+1)*(15+1)
  141.  
  142. maxdu:    ds    2    ;transient d/u data
  143. curloc:    ds    2    ;NDR entry pointer
  144.  
  145. ;**********************************************
  146.  
  147.     end
  148.