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 / CPM / UTILS / DIRUTL / DIRF.MAC < prev    next >
Text File  |  2000-06-30  |  5KB  |  204 lines

  1. ;        DIRF.MAC (Z80 VERSION) ver 1.3
  2. ;              by Keith Petersen, W8SDZ
  3. ;             (revised 12/19/80)
  4. ;
  5. ;      DIRECTORY FUNCTION FOR CP/M 1.4 OR 2.x PROGRAMS
  6. ;
  7. ;--->NOTE: Assemble with Microsoft M80 assembler
  8. ;
  9. ;This file contains routines which can be included in any
  10. ;CP/M program to allow listing the directory.  No sorting
  11. ;is done because that would require use of more memory above
  12. ;the program.  These routines use the 80h default buffer for
  13. ;all operations so if you have data there be sure to move it
  14. ;before running this directory function.  Assume all registers
  15. ;destroyed when calling 'DIRF'.
  16. ;
  17. ;This module may be assembled as a stand-alone program for
  18. ;testing.  L80 link command for testing:   L80 DIRF,DIRF,/N/E
  19. ;Execute program from CP/M, not L80.  It will return to the
  20. ;CCP after finishing.
  21. ;
  22.     .Z80           ;Z80 SWITCH FOR ASSEMBLER
  23.     ENTRY    DIRF       ;DEFINE DIRF AS PUBLIC
  24. ;
  25. NPL    EQU    4       ;NUMBER OF NAMES PER LINE
  26. TAB    EQU    9       ;HORIZONTAL TAB
  27. CR    EQU    0DH       ;CARRIAGE RETURN
  28. LF    EQU    0AH       ;LINE FEED
  29. ;
  30. ;BDOS Equates
  31. ;
  32. RDCHR    EQU    1       ;READ CHAR FROM CONSOLE
  33. WRCHR    EQU    2       ;WRITE CHR TO CONSOLE
  34. PRINT    EQU    9       ;PRINT CONSOLE BUFF
  35. CONST    EQU    11       ;CHECK CONS STAT
  36. FSRCHF    EQU    17       ;0FFH=NOT FOUND
  37. FSRCHN    EQU    18       ;   "       "
  38. CURDSK    EQU    25       ;GET CURRENT DISK NAME
  39. BDOS    EQU    5
  40. FCB    EQU    5CH
  41. ;
  42. ;First, we preserve old stack pointer and set a new one
  43. ;because some functions take more stack space than may
  44. ;be available in the calling program.
  45. DIRF:    LD    HL,0
  46.     ADD    HL,SP       ;GET OLD STACK POINTER
  47.     LD    (STACK),HL ;SAVE FOR LATER
  48.     LD    SP,STACK   ;SET NEW STACK POINTER
  49. ;
  50. ;Check FCB for drive request
  51.     LD    A,(FCB)       ;GET DRIVE NAME FROM FCB
  52.     OR    A       ;ANY REQUESTED? (0=NO)
  53.     JR    NZ,GOTDRV  ;NOT ZERO MEANS WE HAVE NAME
  54. ;
  55. ;Get drive name
  56.     LD    C,CURDSK   ;GET CURRENT DRIVE NAME
  57.     CALL    BDOS
  58.     INC    A       ;MAKE 'A' RELATIVE TO 1 NOT 0
  59. ;
  60. ;Print signon message and drive name
  61. GOTDRV:    ADD    A,40H       ;MAKE IT ASCII
  62.     LD    (DNAME),A  ;SAVE IT IN MESSAGE
  63.     LD    DE,MSG       ;POINT TO MESSAGE
  64.     LD    C,PRINT       ;PRINT IT
  65.     CALL    BDOS
  66. ;
  67. ;Make FCB all '?' to match any file
  68.     LD    HL,FCB+1
  69.     LD    B,11       ;FN+FT COUNT
  70. ;
  71. QLOOP:    LD    (HL),'?'   ;STORE '?' IN FCB
  72.     INC    HL
  73.     DEC    B
  74.     JR    NZ,QLOOP
  75. ;
  76. ;Initialize number of names per line counter
  77.     LD    A,NPL       ;NR. NAMES PER LINE
  78.     LD    (NNAMS),A  ;INIT COUNTER
  79. ;
  80. ;Look up the FCB in the directory
  81.     LD    C,FSRCHF   ;GET 'SEARCH FIRST' FNC
  82.     LD    DE,FCB
  83.     CALL    BDOS       ;READ FIRST
  84.     INC    A       ;WERE THERE ANY?
  85.     JR    NZ,SOME       ;GOT SOME
  86.     CALL    ERXIT
  87.     DEFB    '++NO FILE$'
  88. ;
  89. ;Read more directory entries
  90. MORDIR:    LD    C,FSRCHN   ;SEARCH NEXT
  91.     LD    DE,FCB
  92.     CALL    BDOS       ;READ DIR ENTRY
  93.     INC    A       ;CHECK FOR END (0FFH)
  94.     JP    Z,EXIT       ;NO MORE - EXIT
  95. ;
  96. ;Point to directory entry
  97. SOME:    DEC    A       ;UNDO PREV 'INC A'
  98.     AND    3       ;MAKE MODULUS 4
  99.     ADD    A,A       ;MULTIPLY...
  100.     ADD    A,A       ;..BY 32 BECAUSE
  101.     ADD    A,A       ;..EACH DIRECTORY
  102.     ADD    A,A       ;..ENTRY IS 32
  103.     ADD    A,A       ;..BYTES LONG
  104.     LD    HL,81H       ;POINT TO BUFFER (SKIP TO FN/FT)
  105.     ADD    A,L       ;POINT TO ENTRY
  106.     LD    L,A       ;SAVE - HL NOW = ENTRY ADRS
  107. ;
  108. ;Check for console break
  109.     PUSH    HL       ;SAVE NAME POINTER
  110.     LD    C,CONST       ;CK STATUS OF KBD
  111.     CALL    BDOS
  112.     POP    HL       ;RESTORE NAME POINTER
  113.     OR    A       ;ANY KEY PRESSED?
  114.     JP    NZ,ABORT   ;YES, ABORT
  115. ;
  116. ;Print an entry
  117.     LD    B,8       ;FILE NAME LENGTH
  118.     CALL    TYPEIT       ;TYPE FILENAME
  119.     LD    A,'.'       ;PERIOD AFTER FN
  120.     CALL    TYPE
  121.     LD    B,3       ;GET THE FILETYPE
  122.     CALL    TYPEIT
  123.     LD    HL,NNAMS   ;POINT TO NAMES COUNTER
  124.     DEC    (HL)       ;ONE LESS ON THIS LINE
  125.     PUSH    AF
  126.     CALL    NZ,FENCE   ;NO CR-LF NEEDED, DO FENCE
  127.     POP    AF
  128.     CALL    Z,CRLF       ;CR-LF NEEDED
  129.     JP    MORDIR
  130. ;
  131. ;Print two spaces, fence character, then two more spaces
  132. FENCE:    CALL    TWOSPC
  133.     LD    A,':'       ;FENCE CHARACTER
  134.     CALL    TYPE
  135. ;
  136. ;Print two spaces
  137. TWOSPC:    CALL    SPACE
  138. ;
  139. ;Print one space
  140. SPACE:    LD    A,' '
  141. ;
  142. ;Type char in A register
  143. TYPE:    PUSH    BC
  144.     PUSH    DE
  145.     PUSH    HL
  146.     LD    E,A       ;CHAR TO E FOR CP/M
  147.     LD    C,WRCHR       ;WRITE CHAR TO CONSOLE FUNC
  148.     CALL    BDOS
  149.     POP    HL
  150.     POP    DE
  151.     POP    BC
  152.     RET    
  153. ;
  154. ;Type (B) characters from memory (HL)
  155. TYPEIT:    LD    A,(HL)
  156.     AND    7FH       ;REMOVE CP/M 2.x ATTRIBUTES
  157.     CALL    TYPE
  158.     INC    HL
  159.     DEC    B
  160.     JR    NZ,TYPEIT
  161.     RET    
  162. ;
  163. ;CR-LF routine. HL=NNAMS upon entry
  164. CRLF:    LD    A,CR       ;CR
  165.     CALL    TYPE
  166.     LD    A,LF       ;LF
  167.     CALL    TYPE
  168.     LD    (HL),NPL   ;NUMBER OF NAMES PER LINE
  169.     RET    
  170. ;
  171. ;Error exit
  172. ERXIT:    POP    DE       ;GET MSG
  173.     LD    C,PRINT
  174.     JR    CALLB       ;PRINT MSG, EXIT
  175. ;
  176. ;Abort - read char entered to clear it from CP/M buffer
  177. ABORT:    LD    C,RDCHR       ;DELETE THE CHAR
  178. ;
  179. ;Fall into CALLB
  180. ;
  181. CALLB:    CALL    BDOS
  182. ;
  183. ;Fall into EXIT
  184. ;
  185. ;Exit - All done, return to caller
  186. EXIT:    LD    HL,(STACK) ;GET OLD STACK
  187.     LD    SP,HL       ;MOVE TO STACK
  188.     RET           ;...AND RETURN
  189. ;
  190. MSG:    DEFB    TAB,TAB,'    Directory for drive '
  191. DNAME:    DEFB    'X:',CR,LF,'$'
  192. ;
  193. ;Temporary storage area
  194. ;
  195. NNAMS:    DEFS    1       ;NAMES PER LINE COUNTER
  196.     DEFS    40       ;ROOM FOR STACK
  197. STACK:    DEFS    2       ;OLD STACK STORED HERE
  198. ;
  199. ;END OF DIRECTORY MODULE
  200. ;
  201. ;Temporary end statement used only for testing DIRF module.
  202. ;Remove before including module in other programs.
  203.     END    DIRF
  204.