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 / ZCPR2 / LDIRZ.MAC < prev    next >
Text File  |  2000-06-30  |  12KB  |  629 lines

  1. ;
  2. ;  PROGRAM:  LDIRZ
  3. ;  VERSION:  2.0
  4. ;  AUTHOR:  RICHARD CONN
  5. ;  DATE:  16 JAN 83
  6. ;  PREVIOUS VERSIONS:  1.0 (12 JAN 83)
  7. ;
  8. vers    equ    20
  9.  
  10. ;
  11. ;    LDIRZ prints a sorted directory of the default library file
  12. ; (installable via GENINS).  The printout gives file name and size.
  13. ; It is sorted alphabetically by file name and type.  Only one option
  14. ; is permitted, and that is a file spec (wild cards are OK).  Forms
  15. ; of the LDIRZ command are:
  16. ;
  17. ;        LDIRZ        <-- All Files
  18. ;        LDIRZ file.typ    <-- Selected Files
  19. ;        LDIRZ -library file.typ    <-- Selected Files in Library
  20. ;        LDIRZ //    <-- Help Message
  21. ;
  22.  
  23. ;
  24. ;  CP/M Constants
  25. ;
  26. cpm    equ    0    ;base
  27. bdose    equ    cpm+5
  28. fcb    equ    cpm+5ch
  29. tbuff    equ    cpm+80h
  30. cr    equ    0dh
  31. lf    equ    0ah
  32.  
  33. ;
  34. ;  SYSLIB Routines
  35. ;
  36.     ext    zgpins,print,zpfind,initfcb,f$open,f$read
  37.     ext    sort,moveb,putud,logud,shftrh,phldc,codend
  38.     ext    hmovb,crlf,cout,fname,cline
  39.  
  40. ;
  41. ;  Branch to Start of Program
  42. ;
  43.     jmp    start
  44.  
  45. ;
  46. ;******************************************************************
  47. ;
  48. ;  SINSFORM -- ZCPR2 Utility Standard General Purpose Initialization Format
  49. ;
  50. ;    This data block precisely defines the data format for
  51. ; initial features of a ZCPR2 system which are required for proper
  52. ; initialization of the ZCPR2-Specific Routines in SYSLIB.
  53. ;
  54.  
  55. ;
  56. ;  EXTERNAL PATH DATA
  57. ;
  58. EPAVAIL:
  59.     DB    0FFH    ; IS EXTERNAL PATH AVAILABLE? (0=NO, 0FFH=YES)
  60. EPADR:
  61.     DW    40H    ; ADDRESS OF EXTERNAL PATH IF AVAILABLE
  62.  
  63. ;
  64. ;  INTERNAL PATH DATA
  65. ;
  66. INTPATH:
  67.     DB    0,0    ; DISK, USER FOR FIRST PATH ELEMENT
  68.             ; DISK = 1 FOR A, '$' FOR CURRENT
  69.             ; USER = NUMBER, '$' FOR CURRENT
  70.     DB    0,0
  71.     DB    0,0
  72.     DB    0,0
  73.     DB    0,0
  74.     DB    0,0
  75.     DB    0,0
  76.     DB    0,0    ; DISK, USER FOR 8TH PATH ELEMENT
  77.     DB    0    ; END OF PATH
  78.  
  79. ;
  80. ;  MULTIPLE COMMAND LINE BUFFER DATA
  81. ;
  82. MCAVAIL:
  83.     DB    0FFH    ; IS MULTIPLE COMMAND LINE BUFFER AVAILABLE?
  84. MCADR:
  85.     DW    0FF00H    ; ADDRESS OF MULTIPLE COMMAND LINE BUFFER IF AVAILABLE
  86.  
  87. ;
  88. ;  DISK/USER LIMITS
  89. ;
  90. MDISK:
  91.     DB    4    ; MAXIMUM NUMBER OF DISKS
  92. MUSER:
  93.     DB    31    ; MAXIMUM USER NUMBER
  94.  
  95. ;
  96. ;  FLAGS TO PERMIT LOG IN FOR DIFFERENT USER AREA OR DISK
  97. ;
  98. DOK:
  99.     DB    0FFH    ; ALLOW DISK CHANGE? (0=NO, 0FFH=YES)
  100. UOK:
  101.     DB    0FFH    ; ALLOW USER CHANGE? (0=NO, 0FFH=YES)
  102.  
  103. ;
  104. ;  PRIVILEGED USER DATA
  105. ;
  106. PUSER:
  107.     DB    10    ; BEGINNING OF PRIVILEGED USER AREAS
  108. PPASS:
  109.     DB    'chdir',0    ; PASSWORD FOR MOVING INTO PRIV USER AREAS
  110.     DS    41-($-PPASS)    ; 40 CHARS MAX IN BUFFER + 1 for ending NULL
  111.  
  112. ;
  113. ;  CURRENT USER/DISK INDICATOR
  114. ;
  115. CINDIC:
  116.     DB    '$'    ; USUAL VALUE (FOR PATH EXPRESSIONS)
  117.  
  118. ;
  119. ;  DMA ADDRESS FOR DISK TRANSFERS
  120. ;
  121. DMADR:
  122.     DW    80H    ; TBUFF AREA
  123.  
  124. ;
  125. ;  NAMED DIRECTORY INFORMATION
  126. ;
  127. NDRADR:
  128.     DW    00000H    ; ADDRESS OF MEMORY-RESIDENT NAMED DIRECTORY
  129. NDNAMES:
  130.     DB    64    ; MAX NUMBER OF DIRECTORY NAMES
  131. DNFILE:
  132.     DB    'NAMES   '    ; NAME OF DISK NAME FILE
  133.     DB    'DIR'        ; TYPE OF DISK NAME FILE
  134.  
  135. ;
  136. ;  REQUIREMENTS FLAGS
  137. ;
  138. EPREQD:
  139.     DB    0FFH    ; EXTERNAL PATH?
  140. MCREQD:
  141.     DB    000H    ; MULTIPLE COMMAND LINE?
  142. MXREQD:
  143.     DB    000H    ; MAX USER/DISK?
  144. UDREQD:
  145.     DB    000H    ; ALLOW USER/DISK CHANGE?
  146. PUREQD:
  147.     DB    000H    ; PRIVILEGED USER?
  148. CDREQD:
  149.     DB    0FFH    ; CURRENT INDIC AND DMA?
  150. NDREQD:
  151.     DB    000H    ; NAMED DIRECTORIES?
  152. Z2CLASS:
  153.     DB    5    ; CLASS 5
  154.     DB    'ZCPR2'
  155.     DS    10    ; RESERVED
  156.  
  157. ;
  158. ;  END OF SINSFORM -- STANDARD DEFAULT PARAMETER DATA
  159. ;
  160. ;******************************************************************
  161. ;
  162. library:
  163.     DB    'COMMAND ' ; <---change this if you like---
  164. libtyp:
  165.     DB    'LBR'
  166. ;
  167. ;  START OF PROGRAM
  168. ;
  169. start:
  170.     call    zgpins    ; init ZCPR2 buffers
  171.     call    putud    ; save current user/disk
  172.  
  173. ;
  174. ;  Print Banner
  175. ;
  176.     call    print
  177.     db    'LDIRZ  Version '
  178.     db    vers/10+'0','.',(vers mod 10)+'0',0
  179.  
  180. ;
  181. ;  Set Default Library Name
  182. ;
  183.     lxi    h,library
  184.     lxi    d,fcb+1    ; copy into FCB
  185.     mvi    b,11    ; 11 chars
  186.     call    moveb
  187.  
  188. ;
  189. ;  Extract Information
  190. ;
  191.     lxi    h,tbuff    ; get command line from buffer
  192.     call    cline
  193.     call    sblank    ; skip to non-blank
  194.     ora    a    ; EOL?
  195.     jz    help
  196.     cpi    '/'    ; Help?
  197.     jnz    start0
  198.  
  199. ;
  200. ;  Print Help Message
  201. ;
  202. help:
  203.     call    print
  204.     db    cr,lf,'    LDIRZ prints a sorted directory of the current'
  205.     db    cr,lf,'Library File.  It is invoked by one of the forms:'
  206.     db    cr,lf,'        LDIRZ            <-- All Files'
  207.     db    cr,lf,'        LDIRZ filename.typ    <-- Selected Files'
  208.     db    cr,lf,'        LDIRZ -lib filename.typ    <-- Files from LIB'
  209.     db    cr,lf,'        LDIRZ //        <-- Print Help'
  210.     db    cr,lf,'    Wild Cards (*,?) are permitted.'
  211.     db    cr,lf,0
  212.     ret
  213.  
  214. ;
  215. ;  Check for Library Name and Set it if so
  216. ;
  217. start0:
  218.     cpi    '-'    ; library follows?
  219.     jnz    start1
  220.     inx    h    ; pt to library name
  221.     lxi    d,fcb    ; pt to FCB
  222.     call    fname    ; extract library name
  223.     call    sblank    ; skip to non-blank
  224.     lxi    d,fcb+9    ; check file type
  225.     ldax    d
  226.     cpi    ' '    ; none?
  227.     jnz    start1
  228.     push    h    ; save ptr
  229.     lxi    h,libtyp    ; default type
  230.     mvi    b,3    ; 3 chars
  231.     call    moveb    ; copy it
  232.     pop    h    ; get ptr
  233. ;
  234. ;  Check for File Spec and Set if so
  235. ;
  236. start1:
  237.     ora    a    ; any chars?
  238.     jz    start2    ; fspec is already wild
  239.     lxi    d,filesp    ; copy into file spec
  240.     call    fname    ; extract file name
  241.  
  242. ;
  243. ;  Find Library
  244. ;
  245. start2:
  246.     lxi    d,fcb        ; pt to FCB
  247.     call    initfcb
  248.     mvi    b,0ffh        ; search current
  249.     call    zpfind        ; look for library file
  250.     jnz    start3
  251.     call    print
  252.     db    cr,lf,'Library File ',0
  253.     lxi    h,fcb+1    ; pt to name
  254.     call    prfn    ; print file name
  255.     call    print
  256.     db    ' Not Found',0
  257.     ret
  258.  
  259. ;
  260. ;  Read in First Block of Library
  261. ;
  262. start3:
  263.     call    logud        ; log into directory
  264.     call    f$open        ; open file
  265.     call    f$read        ; read first block
  266.     ora    a        ; ok?
  267.     jz    readdir        ; extract directory info
  268.     call    print
  269.     db    cr,lf,'Library File ',0
  270.     lxi    h,fcb+1
  271.     call    prfn
  272.     call    print
  273.     db    ' is Empty',0
  274.     ret
  275. readdir:
  276.     lxi    h,tbuff+14    ; pt to dir size
  277.     mov    a,m
  278.     inx    h
  279.     mov    h,m        ; HL=size of directory
  280.     mov    l,a
  281.     mov    b,h        ; BC=number of blocks in dir
  282.     mov    c,l
  283.     lxi    h,0        ; set file count
  284.     shld    filecnt
  285.     call    codend        ; pt to spare buffer
  286.     shld    bufptr        ; set buffer ptr
  287.     shld    ssbstart    ; set starting address of first record
  288.     lxi    h,tbuff+32    ; pt to first entry
  289.     jmp    getentry    ; get next entry
  290. ;
  291. ;  Read Next Block
  292. ;
  293. readblock:
  294.     push    b        ; save count
  295.     lxi    d,fcb        ; pt to FCB
  296.     call    f$read        ; read block
  297.     pop    b        ; restore regs
  298.     lxi    h,tbuff        ; pt to next entry
  299.     ora    a        ; error?
  300.     jz    getentry    ; get next entry
  301.     call    print
  302.     db    cr,lf,'Premature End of Library File ',0
  303.     lxi    h,fcb+1
  304.     call    prfn
  305.     call    print
  306.     db    ' -- Aborting',0
  307.     ret
  308. ;
  309. ;  Get next entry from library directory
  310. ;    On entry, HL pts to entry, BC=count
  311. ;
  312. getentry:
  313.     push    h        ; save ptr
  314.     push    b        ; save count
  315.     mov    a,m        ; entry present?
  316.     cpi    0ffh        ; none?
  317.     jz    gete1
  318.     cpi    0        ; deleted?
  319.     jnz    gete1
  320.     inx    h        ; pt to file name
  321.     push    h        ; save ptr to entry
  322.     lxi    d,fspec        ; pt to file spec
  323.     mvi    b,11        ; check 11 bytes
  324. getent1:
  325.     ldax    d        ; check for match with wild cards
  326.     mov    c,m        ; get target char
  327.     inx    h        ; pt to next
  328.     inx    d
  329.     cpi    '?'        ; wild match?
  330.     jz    getent2
  331.     cmp    c        ; match?
  332.     jnz    gete0        ; skip if not
  333. getent2:
  334.     dcr    b        ; count down
  335.     jnz    getent1
  336.     pop    h        ; file matches -- continue
  337.     push    h        ; save ptr
  338.     lhld    filecnt        ; increment file count
  339.     inx    h
  340.     shld    filecnt
  341.     pop    h
  342.     xchg            ; ptr to file name in DE
  343.     lhld    bufptr        ; get buffer ptr
  344.     mvi    b,11        ; 11 bytes
  345.     xchg            ; HL pts to entry
  346.     call    hmovb        ; copy and affect HL and DE
  347.     inx    h        ; skip index
  348.     inx    h
  349.     mvi    b,2        ; copy size
  350.     call    hmovb
  351.     xchg            ; get buffer ptr in HL
  352.     shld    bufptr        ; save buffer ptr
  353.     xchg            ; put back in DE
  354.     lhld    bdose+1        ; memory full?
  355.     mov    a,h        ; check pages
  356.     sui    10        ; below CCP
  357.     cmp    d        ; in range?
  358.     jnz    gete1
  359.     pop    b
  360.     pop    h        ; clear stack
  361.     call    print
  362.     db    cr,lf,'Memory Overflow',0
  363.     ret
  364. gete0:
  365.     pop    h        ; clear stack
  366. gete1:
  367.     pop    b        ; get count
  368.     pop    h        ; get ptr to block
  369.     lxi    d,32        ; pt to next
  370.     dad    d
  371.     lxi    d,tbuff+80h    ; pt to end of buffer
  372.     mov    a,e        ; new block if low-order is the same
  373.     cmp    l
  374.     jnz    getentry
  375.     dcx    b        ; count down
  376.     mov    a,b        ; done?
  377.     ora    c
  378.     jnz    readblock    ; continue with next block
  379. ;
  380. ;  Done with Buffer Load
  381. ;
  382.     lhld    filecnt        ; set record count
  383.     shld    ssbcnt
  384.     lxi    d,ssb        ; pt to ssb
  385.     call    sort        ; perform sort
  386.     mov    a,l        ; get low (remainder)
  387.     ani    3        ; select remainder
  388.     sta    remain
  389.     call    shftrh        ; shift right 2 bits
  390.     call    shftrh
  391.     shld    loopcnt        ; number of loops
  392.     xchg            ; count in DE
  393.     lxi    h,0        ; compute sum
  394.     lxi    b,13        ; bytes/entry
  395. col0:
  396.     mov    a,d        ; done?
  397.     ora    e
  398.     jz    col1
  399.     dcx    d        ; count down
  400.     dad    b        ; add in size
  401.     jmp    col0
  402. col1:
  403.     xchg            ; DE is size of list
  404.     lhld    ssbstart    ; pt to first entry
  405.     shld    entry1
  406.     dad    d        ; pt to next entry
  407.     lda    remain        ; add 1?
  408.     ora    a        ; no if zero
  409.     jz    col2
  410.     dad    b        ; add in another entry
  411. col2:
  412.     shld    entry2        ; set ptr to 2nd entry
  413.     dad    d        ; pt to next entry
  414.     cpi    2        ; remainder >=2?
  415.     jc    col3
  416.     dad    b        ; add in another entry
  417. col3:
  418.     shld    entry3        ; set ptr to 3rd entry
  419.     dad    d        ; pt to last entry
  420.     cpi    3        ; add 1?
  421.     jnz    col4
  422.     dad    b        ; add in another entry
  423. col4:
  424.     shld    entry4
  425. ;
  426. ;  Directory Print -- ENTRYn pts to first element in each col, DE is
  427. ;    number of loops, and REMAIN is number of extra entries
  428. ;
  429.     lxi    h,0    ; clear sum
  430.     shld    sum
  431.     call    print
  432.     db    cr,lf
  433.     db    'Filename.Typ  Size  '
  434.     db    'Filename.Typ  Size  '
  435.     db    'Filename.Typ  Size  '
  436.     db    'Filename.Typ  Size'
  437.     db    cr,lf
  438.     db    '-------- --- -----  '
  439.     db    '-------- --- -----  '
  440.     db    '-------- --- -----  '
  441.     db    '-------- --- -----',0
  442.  
  443.     lhld    loopcnt        ; get loop count
  444.     xchg            ; ... in DE
  445. dirloop:
  446.     mov    a,d        ; Done?
  447.     ora    e
  448.     jz    dirdone
  449.     dcx    d        ; count down
  450.     call    crlf        ; new line
  451.     lhld    entry1        ; print entry
  452.     call    prentry
  453.     shld    entry1
  454.     lhld    entry2
  455.     call    prentry
  456.     shld    entry2
  457.     lhld    entry3
  458.     call    prentry
  459.     shld    entry3
  460.     lhld    entry4
  461.     call    prentry
  462.     shld    entry4
  463.     jmp    dirloop
  464. dirdone:
  465.     lda    remain        ; print last line
  466.     ora    a        ; none?
  467.     jz    done
  468.     mov    d,a        ; count in D
  469.     call    crlf        ; new line
  470.     lhld    entry1        ; print first col
  471.     call    prentry
  472.     dcr    d        ; count down
  473.     jz    done
  474.     lhld    entry2        ; print 2nd col
  475.     call    prentry
  476.     dcr    d        ; count down
  477.     jz    done
  478.     lhld    entry3        ; print 3rd col
  479.     call    prentry
  480. done:
  481.     call    crlf        ; new line
  482.     lhld    filecnt        ; print number of entries
  483.     call    phldc
  484.     call    print
  485.     db    ' Files Selected occupying a Total of ',0
  486.     lhld    sum        ; print sum of sizes
  487.     call    phldc
  488.     call    print
  489.     db    'K Bytes',0
  490.     ret
  491. ;
  492. ;  Print File Name Entry
  493. ;
  494. prentry:
  495.     push    d
  496.     push    h
  497.     push    b
  498.     call    prfn        ; print file name
  499.     lxi    d,11        ; pt to size
  500.     dad    d
  501.     mov    c,m        ; get size in BC
  502.     inx    h
  503.     mov    b,m
  504.     mov    a,c        ; part of a K?
  505.     ani    7
  506.     sta    kpart
  507.     mov    h,b        ; file size in HL
  508.     mov    l,c
  509.     call    shftrh        ; move right 3 bits for size in K
  510.     call    shftrh
  511.     call    shftrh
  512.     lda    kpart        ; add 1 for overflow?
  513.     ora    a        ; 0=no
  514.     jz    prent1
  515.     inx    h        ; add 1 K
  516. prent1:
  517.     call    phldc        ; print as decimal
  518.     mvi    a,'K'        ; print K
  519.     call    cout
  520.     mvi    a,' '        ; print 2 spaces
  521.     call    cout
  522.     call    cout
  523.     xchg            ; size in DE
  524.     lhld    sum        ; add to sum
  525.     dad    d
  526.     shld    sum
  527.     pop    b        ; get regs
  528.     pop    h
  529.     lxi    d,13        ; pt to next entry
  530.     dad    d
  531.     pop    d
  532.     ret
  533. ;
  534. ;  Print file name pted to by HL
  535. ;
  536. prfn:
  537.     push    h        ; save regs
  538.     push    b
  539.     mvi    b,8        ; 8 chars
  540.     call    prfn1
  541.     mvi    a,'.'
  542.     call    cout
  543.     mvi    b,3        ; 3 chars
  544.     call    prfn1
  545.     pop    b        ; get regs
  546.     pop    h
  547.     ret
  548. prfn1:
  549.     mov    a,m        ; print chars
  550.     inx    h        ; pt to next
  551.     call    cout
  552.     dcr    b        ; count down
  553.     jnz    prfn1
  554.     ret
  555. ;
  556. ;  Compare Routine
  557. ;    Compare (DE) to (HL) and Return with Carry if (DE) < (HL)
  558. ;
  559. compare:
  560.     push    h        ; save regs
  561.     push    d
  562.     push    b
  563.     mvi    b,11        ; 11 bytes to compare
  564. comp:
  565.     ldax    d        ; get byte
  566.     cmp    m        ; compare
  567.     jnz    compd        ; done if not same
  568.     inx    h        ; pt to next
  569.     inx    d
  570.     dcr    b        ; count down
  571.     jnz    comp
  572. compd:
  573.     pop    b        ; restore regs
  574.     pop    d
  575.     pop    h
  576.     ret
  577.  
  578. ;
  579. ;  Skip to Non-Blank
  580. ;
  581. sblank:
  582.     mov    a,m    ; skip to non-blank
  583.     inx    h
  584.     cpi    ' '
  585.     jz    sblank
  586.     dcx    h
  587.     ret
  588.  
  589. ;
  590. ;  Buffers
  591. ;
  592. ssb:                ; sort specification block
  593. ssbstart:
  594.     ds    2        ; ptr to first byte of first record
  595. ssbcnt:
  596.     ds    2        ; number of records
  597.     dw    13        ; 13 bytes/record
  598.     dw    compare        ; address of compare routine
  599.     dw    0        ; no ptr table
  600.     db    0,0        ; don't use ptrs
  601. filesp:
  602.     db    0
  603. fspec:
  604.     db    '????????'    ; file spec
  605.     db    '???'
  606.     ds    24
  607. remain:
  608.     ds    1        ; column remainder
  609. kpart:
  610.     ds    1        ; K remainder
  611. filecnt:
  612.     ds    2        ; number of files
  613. bufptr:
  614.     ds    2        ; scratch buffer ptr
  615. sum:
  616.     ds    2        ; sum of file sizes
  617. loopcnt:
  618.     ds    2        ; number of lines to print
  619. entry1:
  620.     ds    2
  621. entry2:
  622.     ds    2
  623. entry3:
  624.     ds    2
  625. entry4:
  626.     ds    2
  627.  
  628.     end
  629.