home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol177 / my-ldir.zq0 / MY-LDIR.Z80
Encoding:
Text File  |  1985-02-10  |  11.9 KB  |  568 lines

  1. ;LDIR.Z80 by Trevor Marshall.....Stolen  from SD-50.ASM
  2. ; v1.0 7/23/83
  3. ;Created to give a library module for many purposes..including cataloging
  4. ;Send any fixes to Thousand Oaks Tech RBBS (805) 492 5472
  5. ;
  6. FALSE    EQU    0
  7. TRUE    EQU    NOT FALSE
  8. ;********************************
  9. ;*                *
  10. ;*  USER OPTION SPECIFICATIONS     *
  11. ;*                *
  12. ;********************************
  13. ;
  14. NPL    EQU    4        ;# of names per line (max of 3 for 64x16)
  15. ;(max    of 4 for 80x24)
  16.  
  17. ; BDOS    equates
  18.  
  19. CPM    EQU    5
  20. BDOS    EQU    5
  21. FCB    EQU    5CH        ;FCB1
  22.  
  23. RDCHR    EQU    1        ;Read char from    console
  24. WRCHR    EQU    2        ;Write char to console
  25. CONST    EQU    11        ;Check cons stat
  26. RESET    EQU    13        ;Reset disk system
  27. SELDSK    EQU    14        ;Select    disk
  28. OPEN    EQU    15        ;0FFH=not found
  29. CLOSE    EQU    16        ;   "    "
  30. SEARCH    EQU    17        ;   "    "
  31. NEXT    EQU    18        ;   "    "
  32. READ    EQU    20        ;not 0 = EOF
  33. WRITE    EQU    21        ;not 0 = disk full
  34. MAKE    EQU    22        ;0FFH =    directory full
  35. CURDSK    EQU    25        ;Get currently logged disk name
  36. SETDMA    EQU    26        ;Set current DMA
  37. GALLOC    EQU    27        ;Get address of    allocation vector
  38. CURDPB    EQU    31        ;Get current disk parameters
  39. CURUSR    EQU    32        ;Get currently logged user number (2.x only)
  40. ;
  41. START:
  42.     LD    HL,0
  43.     LD    (LBTOTL),HL
  44.     LD    (LMTOTL),HL
  45. ;On entry the filenames are in FCB1...make them .LBR
  46.     LD    HL,FCB+9
  47.     LD    (HL),'L'
  48.     INC    HL
  49.     LD    (HL),'B'
  50.     INC    HL
  51.     LD    (HL),'R'
  52. ;
  53.     LD    DE,80H    ;set def dir bfr
  54.     LD    C,SETDMA
  55.     CALL    CPM
  56. ;
  57.     LD    DE,FCB    ;Now ask for matching directory entries
  58.     LD    C,SEARCH ;look for the first
  59.     CALL    CPM
  60.     INC    A
  61.     JR    NZ,SOME.THERE
  62.     LD    HL,NOT.FOUND    ;else quit
  63.     LD    B,22
  64.     CALL    TYPEIT    
  65.     JP    EXIT
  66. SOME.THERE: ;calculate filename address
  67.     DEC    A    ;inced above
  68.     RLC    A    ;A*2
  69.     RLC    A
  70.     RLC    A
  71.     RLC    A    ;A*16
  72.     RLC    A    ;A*32
  73.     ADD    80H    ;now pointing at name
  74.     LD    D,0
  75.     LD    E,A    ;get it to DE
  76.     INC    DE    ;point at the name
  77. ;See if it is the 0 extent, if not skip this name
  78.     LD    HL,11    ;point at extent
  79.     ADD    HL,DE
  80.     LD    A,(HL)    ;get it
  81.     OR    A
  82.     JR    NZ,GET.NEXT
  83.     XOR    A
  84.     LD    (LNCNT),A
  85.     CALL    LBRTST    ;Else print the details
  86. ;Done one file, now look for more
  87. GET.NEXT: LD    DE,80H     ;first reset the DMA to 80h
  88.     LD    C,SETDMA
  89.     CALL    CPM
  90. ;
  91.     LD    C,NEXT
  92.     LD    DE,FCB
  93.     CALL    BDOS
  94.     INC    A
  95.     JR    NZ,SOME.THERE    ;else exit
  96. EXIT:    CALL    LBEXIT    ;after printing the summaries
  97. ERROR.EXIT: JP    0
  98. NOT.FOUND: DB    '++ Library not found ++',0dh,0ah
  99.  
  100. ;************** UTILITY SUBROUTINES *************************
  101. ;*    Print    HL in decimal with leading zero    suppression
  102. DECPRT:    SUB    A        ;Clear leading zero flag
  103.     LD    (LZFLG),A
  104.     LD    DE,-1000    ;Print 1000's digit
  105.     CALL    DIGIT
  106.     LD    DE,-100        ;Etc.
  107.     CALL    DIGIT
  108.     LD    DE,-10
  109.     CALL    DIGIT
  110.     LD    A,'0'        ;Get 1's digit
  111.     ADD    L
  112.     JP    TYPE
  113. DIGIT:    LD    B,'0'        ;Start off with    ASCII 0
  114. DIGLP:    PUSH    HL        ;Save current remainder
  115.     ADD    HL,DE        ;Subtract
  116.     JP    NC,DIGEX    ;Quit on overflow
  117.     POP    AF        ;Throw away remainder
  118.     INC    B        ;Bump digit
  119.     JP    DIGLP        ;Loop back
  120. DIGEX:    POP    HL        ;Restore pointer
  121.     LD    A,B
  122.     CP    '0'        ;Zero digit?
  123.     JP    NZ,DIGNZ    ;No, type it
  124.     LD    A,(LZFLG)    ;Leading zero?
  125.     OR    A
  126.     LD    A,'0'
  127.     JP    NZ,TYPE        ;Print digit
  128.     LD    A,(SUPSPC)    ;Get space suppression flag
  129.     OR    A        ;See if    printing file totals
  130.     RET    Z        ;Yes, don't give leading spaces
  131.     JP    SPACE        ;Leading zero...print space
  132. DIGNZ:    LD    (LZFLG),A    ;Set leading zero flag so next zero prints
  133.     JP    TYPE        ;And print digit
  134. ;
  135. ;--------------
  136. CRLF:    LD    A,0DH        ;Send CR
  137.     CALL    TYPE
  138.     LD    A,0AH        ;Send LF
  139.     JP    TYPE        ;Exit to caller    from TYPE
  140. ;----------
  141. FPAD:    CALL    TYPE        ;Print it, fall    into space
  142. SPACE:    LD    A,' '        ;Fall through to TYPE
  143. ;*    Output character in A to console, and optionally to printer and/or
  144. ;*    the output file.
  145. TYPE:    PUSH    BC
  146.     PUSH    DE
  147.     PUSH    HL
  148.     LD    C,2
  149.     LD    E,A
  150.     CALL    CPM
  151.     POP    HL
  152.     POP    DE
  153.     POP    BC
  154.     RET    
  155. ;*    Print    a string at HL of length B
  156. TYPEIT:    LD    A,(HL)
  157.     CALL    TYPE
  158.     INC    HL
  159.     DEC    B
  160.     JP    NZ,TYPEIT
  161.     RET    
  162. ;*    Print    string terminated with last byte high on console.
  163. PRINT:    LD    A,(DE)
  164.     PUSH    AF
  165.     AND    7FH
  166.     CALL    TYPE
  167.     POP    AF
  168.     OR    A
  169.     RET    M
  170.     INC    DE
  171.     JP    PRINT
  172.  
  173. ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  174. ;
  175. ;    SUBROUTINES to read library file directory
  176. ;
  177. ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  178. ;
  179. ;Compare routine
  180. COMPR:    PUSH    HL        ;Save table addr
  181.     LD    E,(HL)        ;Load low order
  182.     INC    HL
  183.     LD    D,(HL)        ;Load high order
  184.     INC    HL
  185.     LD    C,(HL)
  186.     INC    HL
  187.     LD    B,(HL)
  188. ; BC,DE now point to entries to be compared for L characters
  189. COMP:    EX    DE,HL
  190.     LD    E,A        ;Get count
  191. CMPLP:    LD    A,(HL)
  192.     AND    7FH
  193.     LD    D,A
  194.     LD    A,(BC)
  195.     AND    7FH
  196.     CP    D
  197.     INC    HL
  198.     INC    BC
  199.     JP    NZ,NOTEQL    ;Quit on mismatch
  200.     DEC    E        ;Or end    of count
  201.     JP    NZ,CMPLP
  202. NOTEQL:    POP    HL
  203.     RET            ;Cond code tells all, Z=match
  204. ;
  205. ENTRYL    ;Entry here from below, on multiple file looping
  206.     LD    HL,(LCOUNT)
  207.     LD    A,H        ;Is this the last file?
  208.     OR    L
  209.     RET    Z    ;if so return to mainline code
  210.     DEC    HL        ;Dock file count
  211.     LD    (LCOUNT),HL
  212.     PUSH    BC
  213.     LD    HL,(NEXTL)
  214.     LD    A,11
  215.     CALL    COMPR        ;Does this entry match next one?
  216.     POP    BC
  217.     JP    NZ,LBRTST    ;No, print it
  218.     INC    HL
  219.     INC    HL        ;Skip since highest extent comes last in list
  220.     LD    (NEXTL),HL
  221.     JP    ENTRYL        ;Loop back for next lowest extent
  222. ;
  223. ;    Exit Library member printing
  224. ;
  225. LBEXIT    LD    HL,(LMTOTL)
  226.     LD    A,H
  227.     OR    L
  228.     RET    Z
  229.     PUSH    HL        ;Save Member count
  230.     XOR    A        ;Get a zero to...
  231.     LD    (SUPSPC),A    ;Suppress leading spaces in totals
  232.     CALL    CRLF
  233.     CALL    CRLF
  234.     LD    DE,CONTM    ;Print "There are "
  235.     CALL    PRINT
  236.     POP    HL        ;GET TOTAL MEMBER COUNT BACK
  237.     CALL    DECPRT
  238.     LD    DE,MFILES    ;PRINT "Members in "
  239.     CALL    PRINT
  240.     LD    HL,(LBTOTL)
  241.     CALL    DECPRT
  242.     LD    DE,LIBR
  243.     CALL    PRINT
  244. ;
  245.     LD    DE,LLENMSG
  246.     CALL    PRINT        ;Print " with "
  247.     LD    HL,(L2LENLOC)    ;GET TOTAL LENGTH OF .LBR (IN SECTORS)   *****
  248.     PUSH    HL
  249.     XOR    A
  250.     LD    (SUPSPC),A    ;SUPRESS LEADING SPACES
  251. ;Now have the # of sectors in HL..will cahnge it to kBytes
  252.     LD    A,L    ;save the old LSByte
  253.     RR    H
  254.     RR    L    ;/2
  255.     OR    A
  256.     RR    H
  257.     RR    L    ;/4
  258.     OR    A
  259.     RR    H
  260.     RR    L    ;/8 now in k
  261.     AND    A,00000111B ;do we have a remainder?
  262.     JR    Z,PUT.IT3
  263.     INC    HL    ;Remainder -> INC HL (Also handles < 1k )
  264. PUT.IT3: CALL    DECPRT
  265.     LD    HL,0
  266.     LD    (LLENLOC),HL    ;ZERO OLD COUNT                          *****
  267.     LD    (L2LENLOC),HL
  268.     POP    HL
  269.     LD    DE,LLENMSG2
  270.     CALL    PRINT        ;Print " sectors total."
  271.     RET    
  272. ;
  273. ;* Valid library..dump it out
  274. ; on entry DE points to FCB+1 (start of the name)
  275. LBRTST:
  276.     PUSH    DE
  277.     LD    HL,MNPL
  278.     LD    A,(LNCNT)
  279.     CP    (HL)
  280.     CALL    NZ,CRLF
  281.     CALL    CRLF
  282.     LD    HL,LFMSEP    ;say 'Library file members for:'
  283.     LD    B,31
  284.     CALL    TYPEIT
  285.     POP    HL    ;get ptr to start of name
  286.     PUSH    HL    ;save it again
  287.     LD    B,8        ;File name length
  288.     CALL    TYPEIT
  289.     LD    A,'.'        ;Period    after FN
  290.     CALL    TYPE
  291.     LD    B,3        ;Display 3 characters of filetype
  292.     CALL    TYPEIT
  293.     CALL    CRLF
  294.     POP    HL    ;get name again
  295. ;
  296. ; Saves the library file name into LBRFCB
  297. ; first set the drive #
  298.     LD    A,(FCB)    ;from FCB1
  299.     LD    DE,LBRFCB    ;TO
  300.     LD    (DE),A
  301.     INC    DE
  302.     LD    B,11        ;name+extent
  303.     CALL    MOVE        ;DO THE MOVE from (HL) to (DE)
  304.     EX    DE,HL
  305.     LD    B,25        ;then zero rest of FCB
  306. CLMFCB    LD    (HL),0
  307.     INC    HL
  308.     DEC    B
  309.     JP    NZ,CLMFCB
  310.     CALL    SETLDMA        ;set DMA to lib bffr
  311.     LD    DE,LBRFCB    ;POINT TO FILE
  312.     LD    C,OPEN        ;GET FUNCTION
  313.     CALL    CPM        ;OPEN IT
  314.     LD    C,READ
  315.     LD    DE,LBRFCB
  316.     CALL    CPM
  317. ;    CALL    SETFOP
  318.     LD    HL,LBBUF
  319.     LD    A,(HL)
  320.     OR    A
  321.     JP    Z,CKLDIR    ;check directory present and type it
  322. BADLBR    LD    HL,NLBRF    ;say 'NOT a library file'
  323.     LD    B,25
  324.     CALL    TYPEIT
  325. LMLEXI    CALL    LBCLOSE        ;close the file
  326.     PUSH    DE
  327.     PUSH    HL
  328.     LD    HL,MNPL
  329.     LD    A,(LNCNT)
  330.     CP    (HL)
  331.     CALL    NZ,CRLF
  332.     LD    DE,ILFMSG
  333.     CALL    PRINT        ;PRINT "This library contains "
  334.     LD    HL,(LLENLOC)
  335.     PUSH    HL
  336.     XOR    A
  337.     LD    (SUPSPC),A    ;SUPRESS LEADING SPACES
  338. ;Now have the # of sectors in HL..will cahnge it to kBytes
  339.     LD    A,L    ;save LSByte
  340.     RR    H
  341.     RR    L    ;/2
  342.     OR    A
  343.     RR    H
  344.     RR    L    ;/4
  345.     OR    A
  346.     RR    H
  347.     RR    L    ;/8 now in k
  348.     AND    A,00000111B ;do we have a remainder?
  349.     JR    Z,PUT.IT2
  350.     INC    HL    ;Also handles <1k
  351. PUT.IT2: CALL    DECPRT
  352.     POP    DE
  353.     LD    HL,(L2LENLOC)
  354.     ADD    HL,DE
  355.     LD    (L2LENLOC),HL
  356.     LD    HL,0
  357.     LD    (LLENLOC),HL
  358.     LD    DE,ILFMS2
  359.     CALL    PRINT        ;PRINT "kbytes total."
  360.     POP    HL
  361.     POP    DE
  362.     LD    A,0FFH
  363.     LD    (SUPSPC),A    ;PUT BACK LEADING SPACES
  364.     JP    ENTRYL
  365.  
  366. NLBRF    DEFB    '++Not a LIBRARY file.++',13,10
  367. ;
  368. ;    Close the library file
  369. ;
  370. LBCLOSE LD    DE,LBRFCB
  371.     LD    C,CLOSE
  372.     CALL    CPM
  373.     RET    
  374. ;
  375. ; SETLDMA - Set the Library file DMA adderss
  376. ;
  377. SETLDMA LD    DE,LBBUF
  378.     LD    C,SETDMA
  379.     CALL    CPM
  380.     RET    
  381. ;
  382. ; CKLDIR - check to see if there indeed is a LBR file
  383. ;      directory and barf if not!
  384. ;
  385. CKLDIR:    LD    B,11        ;len of file name
  386.     LD    A,' '        ;space
  387.     INC    HL
  388. CKDLP:    CP    (HL)
  389.     JP    NZ,BADLBR
  390.     DEC    B
  391.     INC    HL
  392.     JP    NZ,CKDLP
  393. ;
  394. ; The first entry in the LBR directory is indeed blank.
  395. ; Now see if the directory size is >0
  396. ;
  397.     LD    E,(HL)        ;file starting location low
  398.     INC    HL        ;must be zero here
  399.     LD    A,(HL)        ;file starting location high
  400.     OR    E        ;must be zero here also
  401.     JP    NZ,BADLBR
  402.     INC    HL
  403.     LD    E,(HL)        ;get library size low
  404.     INC    HL        ;point to library size high
  405.     LD    D,(HL)        ;get library size high
  406.     LD    A,D
  407.     OR    E        ;library must have some size
  408.     JP    Z,BADLBR
  409.     DEC    DE
  410.     EX    DE,HL
  411.     LD    (SLFILE),HL
  412.     LD    HL,(LBTOTL)
  413.     INC    HL
  414.     LD    (LBTOTL),HL
  415.     LD    A,(MNPL)
  416.     LD    (LNCNT),A    ;Reset names per line counter
  417.     LD    B,3
  418.     LD    HL,17
  419.     ADD    HL,DE
  420.     LD    A,(MNPL)
  421.     LD    (LNCNT),A    ;Reset names per line counter
  422.     JP    LMTEST
  423. LFMLOP    LD    HL,(SLFILE)    ;GET
  424.     LD    A,L
  425.     OR    H
  426.     JP    Z,LMLEXI
  427.     DEC    HL
  428.     LD    (SLFILE),HL
  429.     CALL    SETLDMA
  430.     LD    C,READ
  431.     LD    DE,LBRFCB
  432.     CALL    CPM
  433. ;    CALL    SETFOP
  434.     LD    B,4        ;GET FILE COUNT PER SECTOR
  435.     LD    HL,LBBUF    ;GET BUFFER STARTING ADDRESS
  436. LMTEST    LD    A,(HL)        ;Get member open flag
  437.     OR    A        ;TEST FOR OPEN
  438.     JP    Z,PRMNAM
  439. LMTESA    LD    DE,32        ;Member not open get offset
  440.     ADD    HL,DE        ;to next and add it in.
  441.     DEC    B        ;is buffer empty ?
  442.     JP    NZ,LMTEST    ;No so test next entry
  443.     JP    LFMLOP        ;Yes get next buffer...
  444. PRMNAM    PUSH    HL        ;Print member NAME and SIZE
  445.     PUSH    BC
  446.     LD    HL,LNCNT
  447.     LD    A,(MNPL)
  448.     CP    (HL)
  449.     JP    NZ,PRMNA1
  450. ;
  451.  IF NPL <= 3
  452.     LD    A,3        ;If printing less than 4 wide
  453.     CP    (HL)
  454.     JP    C,PRMNA1
  455.     LD    A,(LBRFCB)    ;.. precede new    line with drive    name
  456.     ADD    'A'-1
  457.     CALL    TYPE
  458.     LD    A,':'        ;Tag header with a colon and a space
  459.     CALL    FPAD        ;..and exit back to ENTRY
  460.  ENDIF
  461. ;
  462. PRMNA1    POP    BC
  463.     POP    HL
  464.     PUSH    HL
  465.     PUSH    BC
  466.     INC    HL
  467.     LD    B,8        ;File name length
  468.     CALL    TYPEIT
  469.     LD    A,'.'        ;Period    after FN
  470.     CALL    TYPE
  471.     LD    B,3        ;Display 3 characters of filetype
  472.     CALL    TYPEIT
  473.     INC    HL
  474.     INC    HL
  475.     LD    E,(HL)
  476.     INC    HL
  477.     LD    D,(HL)
  478.     EX    DE,HL
  479. ;If    report size enabled, output the size of the individual file.
  480.     PUSH    DE
  481.     PUSH    HL
  482.     PUSH    HL
  483.     LD    HL,(LLENLOC)
  484.     PUSH    HL
  485.     POP    DE
  486.     POP    HL
  487.     ADD    HL,DE
  488.     LD    (LLENLOC),HL
  489.     POP    HL
  490.     POP    DE
  491. ;Now have the # of sectors in HL..will cahnge it to kBytes
  492.     XOR    A
  493.     LD    A,L    ;save LSByte
  494.     RR    H
  495.     RR    L    ;/2
  496.     OR    A
  497.     RR    H
  498.     RR    L    ;/4
  499.     OR    A
  500.     RR    H
  501.     RR    L    ;/8 now in k
  502.     AND    A,00000111B ;do we have a remainder?
  503.     JR    Z,PUT.IT ;if not then print it
  504.     INC    HL    ;Also handles <1k
  505. PUT.IT:    CALL    DECPRT        ;..go print it
  506.     LD    A,'k'        ;..and follow with k
  507.     CALL    TYPE
  508.     LD    A,','
  509.     CALL    TYPE
  510. ;* At least one more file to output - can we put    it on the current line?
  511.     LD    HL,(LMTOTL)
  512.     INC    HL
  513.     LD    (LMTOTL),HL
  514.     LD    A,(LNCNT)
  515.     DEC    A
  516.     LD    (LNCNT),A
  517.     PUSH    AF
  518.     CALL    NZ,SPACE ;If room left, output the space character
  519.     POP    AF
  520.     POP    BC
  521.     POP    HL
  522.     JP    NZ,LMTESA    ;.. and    go output another file
  523. ;*Current line full, start a new one.
  524.     LD    A,(MNPL)
  525.     LD    (LNCNT),A    ;Reset names per line counter
  526.     CALL    CRLF        ;Space down to next line
  527.     JP    LMTESA
  528. ;
  529. ; Move characters from 'HL' to 'DE' length in 'B'
  530. ;
  531. MOVE:    LD    A,(HL)        ;GET A CHAR
  532.     LD    (DE),A        ;STORE IT
  533.     INC    HL        ;TO NEXT "FROM"
  534.     INC    DE        ;TO NEXT "TO"
  535.     DEC    B        ;MORE?
  536.     JP    NZ,MOVE        ;   YES, LOOP
  537.     RET            ;   NO, RETURN
  538. ;
  539. ;
  540. ;*    Initialized data area
  541.  
  542. LFMSEP    db    '    Library file members for : '
  543. LBRTYP    db    'LBR'
  544. CONTM    DEFB    '    There are',' '+80H
  545. MFILES    DEFB    ' Member Files in',' '+80H
  546. LIBR    DEFB    ' Library(s',')'+80H
  547. LLENMSG DEFB    ' totalling',' '+80H
  548. LLENMSG2 DEFB    ' kBytes','.'+80H
  549. ILFMSG    DEFB    '    This library contains',' '+80H
  550. ILFMS2    DEFB    ' kBytes','.'+80H
  551. ;* Uninitialized    data area
  552. LZFLG    DEFS    1        ;0 when    printing leading zeros
  553. SUPSPC    DEFS    1        ;Leading space flag for    decimal    routine
  554. ;
  555. LLENLOC DEFW    0        ;RUNNING TOTAL OF LBR LENGTH (SECS)     *****
  556. L2LENLOC DEFW    0        ;""
  557. LMTOTL    DEFW    0
  558. LBTOTL    DEFW    0
  559. LNCNT    DEFB    0
  560. LCOUNT    DEFW    0
  561. NEXTL    DEFW    0
  562. SLFILE    DEFW    0
  563. LBRFCB:    DEFS    36
  564. LBBUF    DEFS    80H
  565. MNPL:    DW    NPL    ;entries per line
  566. ;
  567.     END    
  568.