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 / ZSYS / SIMTEL20 / ZCPR3 / XDIR.MQC / XDIR.MAC
Text File  |  2000-06-30  |  39KB  |  1,888 lines

  1. ;
  2. ;  PROGRAM:  XDIR III
  3. ;  AUTHOR:  RICHARD CONN
  4. ;  VERSION:  2.0
  5. ;  DATE:  9 APR 84
  6. ;  PREVIOUS VERSIONS:  1.6 (19 NOV 83)
  7. ;  PREVIOUS VERSIONS:  1.5 (9 JAN 83), 1.4 (6 JAN 83), 1.3 (7 DEC 82)
  8. ;  PREVIOUS VERSIONS:  1.2 (2 NOV 82), 1.1 (30 OCT 82), 1.0 (20 OCT 82)
  9. ;
  10. vers    equ    20
  11. z3env    SET    0f400h
  12.  
  13. ;
  14. ;  XDIR III -- Extended Disk Directory Program
  15. ;        ZCPR3 Version
  16. ;
  17. ;    XDIR III produces a formatted, alphabetized listing of the contents
  18. ; of the disk directory of the implied (current logged-in) or specified disk.
  19. ;
  20. ;    XDIR III is invoked by a command line of the following form --
  21. ;
  22. ;        XDIR dir:filename.typ ooo...
  23. ; or
  24. ;
  25. ;        XDIR /oooo...
  26. ;
  27. ; where:
  28. ;    dir is an optional directory name or a disk/user specification (du)
  29. ;    if dir is omitted, XDIR III defaults to the current disk/user
  30. ;    filename.typ is an ambiguous file name and type (* and ? may be used)
  31. ;    o are option letters as follows:
  32. ;        Aa - Set the attributes of the files to be displayed;
  33. ;            a=S for System Files, a=N for Non-System Files
  34. ;            a=A for All Files (System and Non-System)
  35. ;        D  - Send Output to Disk as well as screen
  36. ;        Ff - Engage File Name Buffer Facility
  37. ;            f=L to Log File Names to Disk
  38. ;            f=P to Print Names Logged to Disk
  39. ;            f=S to Scan Disk for File Names and Compare to Logged
  40. ;        I  - Inspect files selected by FL option for inclusion
  41. ;        N  - Negate selection; select those files which do NOT
  42. ;            match the ambiguous file name
  43. ;        Oo - Set Output Parameters;
  44. ;            o=A to Toggle File Attributes, o=F to Form Feed at end
  45. ;            o=G to Toggle Grouping, o=H to Toggle Hor/Vert
  46. ;        P  - Print display as well as show it on the screen
  47. ;        PF - Same as POF
  48. ;        U  - Select All User Areas
  49. ;
  50. ; Options may be combined as desired; note that AA is the same as AS and AN,
  51. ; but AS by itself negates AN and vice-versa, with AN taking precident
  52. ;
  53.  
  54.  
  55. ;
  56. ;  CP/M Equates
  57. ;
  58. base    equ    0
  59. wboot    equ    base
  60. bdose    equ    base+5
  61. fcb    equ    base+5ch
  62. buff    equ    base+80h
  63. ctrlc    equ    'C'-'@'
  64. cr    equ    0dh
  65. ff    equ    0ch
  66. lf    equ    0ah
  67. esize    equ    16    ; size of directory entries
  68. optch    equ    '/'    ; option char
  69. maxent    equ    54    ; maximum number of entries/screen
  70.  
  71. ;
  72. ;  External Routines
  73. ;
  74.     ext    bdos    ; BDOS
  75.     ext    dutdir    ; convert DU to DIR form
  76.     ext    z3log    ; log into DU or DIR
  77.     ext    z3init    ; init buffers
  78.     ext    dbuffer    ; disk routines
  79.     ext    dfree
  80.     ext    diralpha
  81.     ext    dirsload
  82.     ext    dirpack
  83.     ext    dirnpack
  84.     ext    dirsel
  85.     ext    dparam
  86.     ext    fsize
  87.     ext    fo0$open    ; byte-oriented file output
  88.     ext    fo0$close
  89.     ext    f0$put
  90.     ext    fo1$open
  91.     ext    fo1$close
  92.     ext    f1$put
  93.     ext    fi1$open
  94.     ext    fi1$close
  95.     ext    f1$get
  96.     ext    bbline    ; input line editor
  97.     ext    retud    ; get current user and disk
  98.     ext    print    ; print routines
  99.     ext    pstr
  100.     ext    lpstr
  101.     ext    lcrlf
  102.     ext    caps    ; capitalize char
  103.     ext    cin    ; console in char
  104.     ext    lout    ; print char
  105.     ext    cout    ; console out char
  106.     ext    crlf    ; new line
  107.     ext    madc    ; a as dec chars in memory
  108.     ext    mhldc    ; hl as dec chars in memory
  109.     ext    fillb    ; memory fill
  110.     ext    moveb    ; memory move
  111.     ext    codend    ; beginning of buffer area
  112.  
  113. ;
  114. ; Environment Definition
  115. ;
  116.     if    z3env ne 0
  117. ;
  118. ; External ZCPR3 Environment Descriptor
  119. ;
  120.     jmp    start
  121.     db    'Z3ENV'    ;This is a ZCPR3 Utility
  122.     db    1    ;External Environment Descriptor
  123. z3eadr:
  124.     dw    z3env
  125. start:
  126.     lhld    z3eadr    ;pt to ZCPR3 environment
  127. ;
  128.     else
  129. ;
  130. ; Internal ZCPR3 Environment Descriptor
  131. ;
  132.     MACLIB    Z3BASE.LIB
  133.     MACLIB    SYSENV.LIB
  134. z3eadr:
  135.     jmp    start
  136.     SYSENV
  137. start:
  138.     lxi    h,z3eadr    ;pt to ZCPR3 environment
  139.     endif
  140.  
  141. ;
  142. ; Start of Program -- Initialize ZCPR3 Environment
  143. ;
  144.     call    z3init    ;initialize the ZCPR3 Env and the VLIB Env
  145.     jmp    start0
  146. ;
  147. ;  Other Buffers (Set by GENINS)
  148. ;
  149. igrp:    db    0ffh    ; Group by file type and name
  150. ifmt:    db    0    ; vertical format
  151. iatt:    db    10000000b    ; Non-System files only
  152. iscn:    db    0    ; 0=dir display, 0ffh=scan for files by default
  153. fenab:    db    0ffh    ; enable F options (0=no)
  154. lenab:    db    0ffh    ; enable FL option (0=no)
  155. asenab:    db    0ffh    ; enable AS option (0=no)
  156. irs:    db    0ffh    ; enable attribute display (0=no)
  157. iff:    db    0    ; enable form feed at end (0=no)
  158.  
  159. ;
  160. ;  Command Line Option Table
  161. ;
  162. optab:
  163.     db    'A'
  164.     dw    opta
  165.     db    'D'
  166.     dw    optd
  167.     db    'F'
  168.     dw    optf
  169.     db    'I'
  170.     dw    opti
  171.     db    'N'
  172.     dw    optn
  173.     db    'O'
  174.     dw    opto
  175.     db    'P'
  176.     dw    optp
  177.     db    'U'
  178.     dw    optu
  179.     db    0
  180.  
  181. ;
  182. ;  **** Start of XDIR III ****
  183. ;
  184. start0:
  185.  
  186. ;
  187. ;  Save stack ptr for return later
  188. ;
  189.     lxi    h,0    ; get stack
  190.     dad    sp
  191.     shld    stack    ; save stack ptr for return
  192.     call    codend    ; determine free space (CODEND also pts to Command
  193.             ;   Line Save Area)
  194.     lxi    d,100h    ; block size to save
  195.     dad    d
  196.     dad    d    ; allow for 256-byte stack
  197.     shld    buffer    ; start of free buffer area
  198.     sphl        ; set stack ptr
  199.  
  200. ;
  201. ;  Save command line in CMDLNE buffer
  202. ;
  203.     call    codend    ; pt to command line buffer
  204.     xchg        ; ... in DE
  205.     lxi    h,buff+1    ; copy input line into command line buffer
  206. start1:
  207.     mov    a,m    ; get byte
  208.     stax    d    ; put byte
  209.     inx    h    ; pt to next
  210.     inx    d
  211.     ora    a    ; end of line?
  212.     jnz    start1
  213.  
  214. ;
  215. ;  Get and save current user number
  216. ;
  217. noext:
  218.     call    retud    ; get current user and disk
  219.     mov    a,b    ; get disk into A
  220.     sta    curdisk    ; current disk number
  221.     mov    a,c    ; set current user
  222.     sta    curuser
  223.  
  224. ;
  225. ;  Log into DU or DIR
  226. ;
  227.     lxi    d,fcb    ; use data determined by ZCPR3
  228.     call    z3log    ; ZCPR3 command line interpretation
  229.     call    retud    ; get current user and disk
  230.     mov    a,c    ; set current user
  231.     sta    aflg
  232.     mov    a,b    ; set disk
  233.     sta    disk
  234.  
  235. ;
  236. ;  Set flag values
  237. ;
  238.     lda    irs    ; get RS display option
  239.     sta    rsflg    ; set RS display option
  240.     lda    iff    ; get form feed option
  241.     sta    ffflg    ; set form feed option
  242.     lda    igrp    ; set grouping (file name/type or type/name)
  243.     sta    gflg
  244.     lda    ifmt    ; set listing format (vertical or horizontal, 0=vert)
  245.     sta    hflg
  246.     lda    iatt    ; set file attributes
  247.     mov    c,a    ; save in c
  248.     lda    aflg    ; get current user number
  249.     ora    c    ; mask in file attributes
  250.     sta    aflg    ; save flag
  251.     lda    iscn    ; set initial function (Scan or Dir)
  252.     sta    fflg
  253.     xra    a    ; A=0
  254.     sta    nflg    ; set no negation
  255.     sta    dflg    ; set no disk output
  256.     sta    pflg    ; set no printer output
  257.     sta    iflg    ; set no file name inspection (for /FP)
  258.  
  259. ;
  260. ;  Assume wild file name
  261. ;
  262.     lxi    h,fcb+1    ; store '?' chars
  263.     mvi    b,11    ; 11 chars
  264.     mov    a,m    ; check for entry specified
  265.     cpi    ' '    ; test for space (means no entry)
  266.     mvi    a,'?'    ; prepare for '?' fill
  267.     cz    fillb
  268.     mov    a,m    ; check for option caught
  269.     cpi    optch    ; test for option flag
  270.     mvi    a,'?'    ; prepare for '?' fill
  271.     cz    fillb
  272.  
  273. ;
  274. ;  Scan command line for options
  275. ;
  276.     call    codend    ; pt to first char
  277.     call    sblank    ; skip over blanks
  278.     ora    a    ; end of line?
  279.     jz    xdir    ; begin main processing
  280.     inx    h    ; prep for invalid option
  281.     cpi    optch    ; option?
  282.     jz    opt    ; process options
  283.     dcx    h    ; ok to process for dir:filename.typ form
  284. ;
  285. ;  skip over character of file name
  286. ;
  287. skipo1:
  288.     mov    a,m    ; get char
  289.     inx    h    ; pt to next
  290.     cpi    ' '
  291.     jz    skipo2
  292.     ora    a
  293.     jnz    skipo1
  294.     jmp    xdir    ; run XDIR if no options follow
  295. ;
  296. ;  Scan complete -- look for possible following option char
  297. ;
  298. skipo2:
  299.     call    sblank    ; skip over blanks
  300.     mov    a,m    ; option char follows?
  301.     cpi    optch
  302.     jnz    opt
  303.     inx    h    ; skip over option char
  304. ;
  305. ;  Look for options -- main loop; HL pts to next char
  306. ;
  307. opt:
  308.     mov    a,m    ; get option char
  309.     inx    h    ; pt to next
  310.     ora    a    ; end of line?
  311.     jz    xdir    ; begin main processing
  312.     cpi    ' '    ; skip over spaces
  313.     jz    opt
  314.     cpi    optch    ; option char?
  315.     jz    opterr    ; loop back if so
  316.     lxi    d,optab    ; pt to option table
  317.     mov    b,a    ; option char in b
  318. ;
  319. ;  Scan option table
  320. ;
  321. opt1:
  322.     ldax    d    ; get option table char
  323.     ora    a    ; end of table?
  324.     jz    opterr    ; invalid option error
  325.     cmp    b    ; compare to passed option
  326.     jz    opt2    ; process if match
  327.     inx    d    ; skip address
  328.     inx    d
  329.     inx    d    ; pt to next opt char
  330.     jmp    opt1
  331. ;
  332. ;  Process option found
  333. ;
  334. opt2:
  335.     inx    d    ; pt to low-order address
  336.     ldax    d    ; get it
  337.     mov    c,a    ; low in C
  338.     inx    d    ; pt to high-order address
  339.     ldax    d    ; get it
  340.     mov    b,a    ; high in B
  341.     push    b    ; BC on stack
  342.     ret        ; Process option routine
  343. ;
  344. ;  Option A -- File Attributes
  345. ;
  346. opta:
  347.     mov    a,m    ; get next option letter
  348.     cpi    'N'    ; Non-System files?
  349.     jz    optan
  350.     cpi    'S'    ; System files?
  351.     jz    optas
  352.     cpi    'A'    ; All files?
  353.     jnz    opterr    ; error if not
  354. ;
  355. ;  Option AA -- All Files
  356. ;
  357. optaa:
  358.     lda    asenab    ; enable system files?
  359.     ora    a    ; 0=no
  360.     jz    optan
  361.     mvi    c,11000000b    ; System and Non-system
  362. optaret:
  363.     lda    aflg    ; get flag
  364.     ani    3fh    ; leave in user selection
  365.     ora    c    ; mask in sys/non-sys
  366.     sta    aflg    ; restore flag
  367.     inx    h    ; pt to next
  368.     jmp    opt
  369. ;
  370. ;  Option AS -- System Files
  371. ;
  372. optas:
  373.     lda    asenab    ; enable system files?
  374.     ora    a    ; 0=no
  375.     jz    optan
  376.     mvi    c,01000000b    ; System Only
  377.     jmp    optaret
  378. ;
  379. ;  Option AN -- Non-System Files
  380. ;
  381. optan:
  382.     mvi    c,10000000b    ; Non-system Only
  383.     jmp    optaret
  384.  
  385. ;
  386. ;  Option F - select file name buffer functions
  387. ;
  388. optf:
  389.     mvi    a,0ffh    ; set flag
  390.     sta    fflg
  391.     mov    a,m    ; get option char
  392.     sta    fopt
  393.     cpi    'L'    ; log file names to disk
  394.     jz    optfok
  395.     cpi    'P'    ; print names of files
  396.     jz    optfok
  397.     cpi    'S'    ; scan disk for files
  398.     jz    optfok
  399.     jmp    opterr    ; error otherwise
  400. optfok:
  401.     inx    h    ; pt to next option letter
  402.     jmp    opt
  403.  
  404. ;
  405. ;  Option I -- enable it; inspect for FL option only
  406. ;
  407. opti:
  408.     mvi    a,0ffh    ; ON
  409.     sta    iflg
  410.     jmp    opt
  411.  
  412. ;
  413. ;  Option D -- enable it; Disk output
  414. ;
  415. optd:
  416.     mvi    a,0ffh    ; ON
  417.     sta    dflg
  418.     jmp    opt
  419.  
  420. ;
  421. ;  Option P -- enable it; Printer output
  422. ;
  423. optp:
  424.     mvi    a,0ffh    ; ON
  425.     sta    pflg
  426.     mov    a,m    ; get possible 2nd letter
  427.     cpi    'F'    ; set form feed if F
  428.     jnz    opt    ; process as next option letter if not F
  429.     inx    h    ; pt to next
  430.     jmp    optof
  431.  
  432. ;
  433. ;  Option O -- control Output parameters
  434. ;
  435. opto:
  436.     mov    a,m    ; get 2nd letter
  437.     inx    h    ; pt to next
  438.     cpi    'A'    ; attributes?
  439.     jz    optoa
  440.     cpi    'F'    ; form feed?
  441.     jz    optof
  442.     cpi    'G'    ; grouping?
  443.     jz    optog
  444.     cpi    'H'    ; horizontal/vertical?
  445.     jz    optoh
  446.     dcx    h    ; adjust back
  447.     jmp    opterr
  448. ;
  449. ;  Toggle File Attributes Flag
  450. ;
  451. optoa:
  452.     lda    rsflg    ; flip flag
  453.     cma
  454.     sta    rsflg
  455.     jmp    opt
  456. ;
  457. ;  Toggle Form Feed Flag
  458. ;
  459. optof:
  460.     lda    ffflg    ; flip flag
  461.     cma
  462.     sta    ffflg
  463.     jmp    opt
  464. ;
  465. ;  Toggle Grouping
  466. ;
  467. optog:
  468.     lda    gflg    ; flip flag
  469.     cma
  470.     sta    gflg    ; 0=file name and type
  471.     jmp    opt
  472. ;
  473. ;  Toggle Horizontal/Vertical Listing
  474. ;
  475. optoh:
  476.     lda    hflg    ; flip flag
  477.     cma
  478.     sta    hflg    ; 0=vertical
  479.     jmp    opt
  480.  
  481. ;
  482. ;  Option N -- enable it; Negate Selection
  483. ;
  484. optn:
  485.     mvi    a,0ffh    ; ON
  486.     sta    nflg
  487.     jmp    opt
  488.  
  489. ;
  490. ;  Option U - enable it; Select All User Areas
  491. ;
  492. optu:
  493.     lda    aflg    ; get current attributes flag
  494.     ori    20h    ; select all user areas
  495.     sta    aflg    ; put flag back
  496.     jmp    opt
  497.  
  498. ;
  499. ;  Option error message
  500. ;
  501. opterr:
  502.     xra    a    ; set no disk or printer output
  503.     sta    dflg
  504.     sta    pflg
  505.     call    banner    ; print banner
  506.     call    print
  507.     db    cr,lf,'Syntax:'
  508.     db    cr,lf,'    XDIR dir:filename.typ ooo...'
  509.     db    cr,lf,'or    XDIR /oooo...'
  510.     db    cr,lf,'Options:'
  511.     db    cr,lf,'    Aa - File Attributes'
  512.     db    cr,lf,'      a=S for System, a=N for Non-System'
  513.     db    cr,lf,'      a=A for All Files (System and Non-System)'
  514.     db    cr,lf,'    D  - Send Output to Disk File XDIR.DIR'
  515.     db    cr,lf,'    Ff - Enable a File Buffer Function'
  516.     db    cr,lf,'      f=L for Log Names to FNAMES.DIR'
  517.     db    cr,lf,'      f=P to Print Names stored in FNAMES.DIR'
  518.     db    cr,lf,'      f=S to Scan Disk and Compare to FNAMES.DIR'
  519.     db    cr,lf,'    I  - Inspect Logged Files (FL Option Only)'
  520.     db    cr,lf,'    N  - Negate Selection'
  521.     db    cr,lf,'    Oo - Toggle Output Features'
  522.     db    cr,lf,'      o=A for File Attributes, o=F for Form Feed'
  523.     db    cr,lf,'      o=G for Grouping, o=H for Horiz/Vert Format'
  524.     db    cr,lf,'    P  - Send Display to Printer'
  525.     db    cr,lf,'    PF - Same as POF'
  526.     db    cr,lf,'    U  - Select All User Areas'
  527.     db    0
  528.  
  529. ;
  530. ;  Return to CP/M
  531. ;
  532. return:
  533.     lda    dflg    ; disk output?
  534.     ora    a    ; 0=no
  535.     cnz    fo0$close    ; close file if so
  536.     lhld    stack    ; get old stack ptr
  537.     sphl
  538.     ret        ; return to CP/M
  539.  
  540. ;
  541. ;  Memory Overflow Error
  542. ;
  543. memerr:
  544.     call    printx
  545.     db    cr,lf,'TPA Error',0
  546.     jmp    return
  547.  
  548. ;
  549. ;  Print banner of XDIR III
  550. ;
  551. banner:
  552.     call    printx
  553.     db    'XDIR III, Version '
  554.     db    vers/10+'0','.',(vers mod 10)+'0',0
  555.     ret
  556.  
  557. ;
  558. ;  Begin XDIR III processing
  559. ;
  560. xdir:
  561.  
  562. ;
  563. ;  This section disables the /Ff option and /FL option if default set
  564. ;
  565.     lda    fenab    ; enable FFLG? (/Ff option)
  566.     ora    a    ; 0=no
  567.     jnz    xdst1
  568.     xra    a    ; turn off FFLG
  569.     sta    fflg
  570. xdst1:
  571.     lda    lenab    ; enable FL option?
  572.     ora    a    ; 0=no
  573.     jnz    xdst2
  574.     lda    fflg    ; FFLG on?
  575.     ora    a    ; 0=no
  576.     jz    xdst2
  577.     lda    fopt    ; check for L
  578.     cpi    'L'
  579.     jnz    xdst2
  580.     mvi    a,'P'    ; switch L to P
  581.     sta    fopt
  582. xdst2:
  583.     lda    fflg    ; file name buffer option?
  584.     ora    a    ; 0=no
  585.     jz    xdirst
  586.     xra    a    ; A=0
  587.     sta    gflg    ; group by file name and type
  588.     lda    fopt    ; print immediately if P option
  589.     cpi    'P'    ; print?
  590.     jnz    xdirst
  591.     call    banner    ; print banner
  592.     jmp    xdirfp    ; print file names
  593.  
  594. ;  Check for Print Option and Ask for and Print Header if so
  595. xdirst:
  596.     lda    pflg    ; printer output?
  597.     ora    a    ; 0=no
  598.     jz    xdirgo
  599.     call    print    ; message to user
  600.     db    cr,lf,'Please Input Header: ',0
  601.     xra    a    ; no caps
  602.     call    bbline    ; input line from user
  603.     ora    a    ; no chars?
  604.     jz    xdirgo
  605.     call    lcrlf    ; new line
  606.     call    lpstr    ; print header line
  607.     call    lcrlf    ; new line
  608.  
  609. ;  Get Files from Disk
  610. xdirgo:
  611.     lhld    buffer    ; end of code
  612.     call    dbuffer    ; set buffers
  613.     jz    memerr    ; memory overflow error?
  614.     push    h    ; save regs
  615.     push    d
  616.     call    dfree    ; compute amount of free space on disk
  617.     xchg        ; amount in hl
  618.     shld    freesiz    ; save free space count
  619.     pop    d    ; get regs
  620.     pop    h
  621.     call    dirsload    ; load with sizing information
  622.     jz    memerr    ; memory overflow error?
  623.     push    h    ; save hl
  624.     mov    h,b    ; HL=number of files loaded
  625.     mov    l,c
  626.     shld    totfil    ; save total count
  627.     push    b    ; save bc
  628.     lda    curdisk    ; prepare to relog in disk
  629.     mov    e,a
  630.     mvi    c,14    ; select disk
  631.     call    bdos
  632.     lda    curuser    ; prepare to relog in user
  633.     mov    e,a
  634.     mvi    c,32    ; select user
  635.     call    bdos
  636.  
  637. ;  Open disk file if necessary for disk output
  638.     lda    dflg    ; disk output?
  639.     ora    a    ; 0=no
  640.     jz    xdir0
  641.     lxi    d,dskfcb    ; open disk file for char output
  642.     call    fo0$open    ; open file for output
  643. xdir0:
  644.     pop    b    ; get count
  645.     pop    h    ; get ptr
  646.  
  647. ;  Continue processing; select desired files
  648.     lda    aflg    ; get file attributes
  649.     lxi    d,fcb    ; get ptr to fcb
  650.     call    dirsel    ; select files
  651.  
  652. ;  Now, pack and alphabetize directory
  653.     lda    nflg    ; negate selection?
  654.     ora    a    ; 0=no
  655.     cz    dirpack    ; select marked entries
  656.     cnz    dirnpack    ; select unmarked entries
  657.     lda    gflg    ; get grouping flag
  658.     call    diralpha    ; alphabetize directory
  659.     shld    firstf    ; save ptr to first file
  660.     mov    h,b    ; HL=file count
  661.     mov    l,c
  662.     shld    fcount    ; save file count
  663.     shld    countf    ; save file down count
  664.     lxi    h,0    ; set file size counter
  665.     shld    totsiz    ; save counter
  666.     lda    dflg    ; set temp flags
  667.     sta    dflgt
  668.     lda    pflg
  669.     sta    pflgt
  670.  
  671. ;
  672. ;  Major feature selection --
  673. ;    Two major features of XDIR are selected at this time:
  674. ;        1.  Directory Display Functions
  675. ;        2.  File Name Buffer Functions
  676. ;    At this point, the following key values are know:
  677. ;        FIRSTF - Pointer to First File
  678. ;        FCOUNT, COUNTF - Number of Files
  679. ;
  680.     lda    fflg    ; get flag
  681.     ora    a    ; Z=Directory Display, NZ=File Name Buffer Fcts
  682.     jnz    xdirf    ; Do File Name Buffer Fcts
  683.  
  684. ;
  685. ;  Main Directory Print Routine -- This routine displays the directory to
  686. ;  the console, printer, or disk as desired
  687. ;
  688. ;  Print header lines and one screen of entries
  689. xdir2:
  690.     lda    dflg    ; save disk and print output flags
  691.     sta    dflgs
  692.     lda    pflg
  693.     sta    pflgs
  694.     lda    dflgt    ; use temp flags
  695.     sta    dflg
  696.     lda    pflgt
  697.     sta    pflg
  698.     xra    a    ; A=0
  699.     sta    dflgt    ; clear temp flags so no banner 2nd time around
  700.     sta    pflgt
  701.  
  702. ;  Print: Main Banner
  703.     call    banner    ; print banner
  704.  
  705. ;  Print: Horizontal/Vertical Listing Message
  706.     call    printx
  707.     db    '    ',0
  708.     lda    hflg    ; get horizontal/vertical flag
  709.     ora    a    ; 0=vertical
  710.     jnz    xdir2a
  711.     call    printx
  712.     db    'Vertical',0
  713.     jmp    xdir3
  714. xdir2a:
  715.     call    printx
  716.     db    'Horizontal',0
  717.  
  718. ;  Print: Listing by File Name and Type or Type and Name Message
  719. xdir3:
  720.     call    printx
  721.     db    ' Listing by File ',0
  722.     lda    gflg    ; grouping flag
  723.     ora    a    ; 0=name and type
  724.     jnz    xdir3a
  725.     call    printx
  726.     db    'Name/Type',0
  727.     jmp    xdir4
  728. xdir3a:
  729.     call    printx
  730.     db    'Type/Name',0
  731.  
  732. ;
  733. ;  Print:  Disk and User
  734. ;
  735. xdir4:
  736.     call    printx    ; print everywhere
  737.     db    cr,lf,' Disk: ',0
  738.     lda    disk    ; get current disk
  739.     adi    'A'    ; convert to ASCII
  740.     call    coutx    ; print everywhere
  741.     call    printx    ; print everywhere
  742.     db    '  User: ',0
  743.     lda    aflg    ; get user number
  744.     ani    20h    ; all?
  745.     jz    xdir4b
  746.     call    printx
  747.     db    'All',0
  748.     jmp    xdir5
  749. xdir4b:
  750.     lda    aflg    ; get selected user
  751.     ani    1fh    ; select user number
  752.     lxi    d,numbuf    ; store number in buffer
  753.     call    madc    ; get number
  754.     mvi    b,3    ; 3 digits
  755.     call    prnumx    ; print number everywhere
  756.  
  757. ;
  758. ;  Print: Directory Name
  759. ;
  760. xdir5:
  761.     lda    aflg    ; check for all users
  762.     mov    c,a    ; save in C
  763.     ani    20h
  764.     jnz    xdir5fa
  765.     mov    a,c    ; get user
  766.     ani    1fh    ; mask for just user
  767.     mov    c,a
  768.     lda    disk    ; select disk
  769.     mov    b,a
  770.     call    dutdir    ; determine if name available
  771.     jz    xdir5fa
  772.     call    printx
  773.     db    ' Name: ',0
  774.     mvi    b,8    ; 8 chars to name
  775. xdir5n:
  776.     mov    a,m    ; get char
  777.     inx    h    ; pt to next
  778.     cpi    ' '    ; don't print spaces
  779.     cnz    coutx
  780.     dcr    b    ; count down
  781.     jnz    xdir5n
  782. ;
  783. ;  Print: Selected File Attributes
  784. ;
  785. xdir5fa:
  786.     call    printx
  787.     db    ', File Attributes: ',0
  788.     lda    aflg    ; get flag
  789.     push    psw    ; save A
  790.     ani    80h    ; Non-system?
  791.     jz    xdir5a
  792.     call    printx
  793.     db    ' Non-System',0
  794. xdir5a:
  795.     pop    psw    ; get A
  796.     ani    40h    ; System?
  797.     jz    xdir5b
  798.     call    printx
  799.     db    ' System',0
  800.  
  801. ;  See if any files selected
  802. xdir5b:
  803.     lhld    countf    ; get file down count
  804.     mov    a,h    ; any files?
  805.     ora    l
  806.     jnz    xdir6
  807.     call    printx    ; print everywhere
  808.     db    cr,lf,'No files selected -- ',0
  809.     jmp    xdir11
  810.  
  811. ;
  812. ;  This is the main looping entry point for each screen display
  813. ;
  814. xdir6:
  815.     lda    aflg    ; all users selected?
  816.     ani    20h
  817.     jnz    xdir6a
  818. ;
  819. ;  This is the header which is printed if the files in only one user area are
  820. ;    displayed
  821. ;
  822.     call    crlfx    ; new line
  823.     call    hdr2    ; pt to header
  824.     lda    rsflg
  825.     ora    a    ; Z=no
  826.     cnz    sp0    ; print RS
  827.     call    sp2    ; print leading spaces
  828.     call    hdr2    ; print header
  829.     lda    rsflg
  830.     ora    a    ; Z=no
  831.     cnz    sp0    ; print RS
  832.     call    sp2    ; print leading spaces
  833.     call    hdr2    ; print header
  834.     lda    rsflg
  835.     ora    a
  836.     cnz    sp0
  837.     call    crlfx    ; new line
  838.     call    hdr1    ; print underlines
  839.     lda    rsflg
  840.     ora    a
  841.     cnz    sp1
  842.     call    sp2    ; leading spaces
  843.     call    hdr1    ; underlines
  844.     lda    rsflg
  845.     ora    a
  846.     cnz    sp1
  847.     call    sp2    ; leading spaces
  848.     call    hdr1    ; underlines
  849.     lda    rsflg
  850.     ora    a
  851.     cnz    sp1
  852.     jmp    xdir6b
  853. ;
  854. ;  General-Purpose Header Print Routines
  855. ;
  856. sp0:
  857.     call    printx
  858.     db    ' RS',0
  859.     ret
  860. sp1:
  861.     call    printx
  862.     db    ' --',0
  863.     ret
  864. sp2:
  865.     call    printx
  866.     db    '   ',0
  867.     ret
  868. spu:
  869.     call    printx
  870.     db    ' U ',0
  871.     ret
  872. spu1:
  873.     call    printx
  874.     db    ' ',0
  875.     ret
  876. spu2:
  877.     call    printx
  878.     db    ' - ',0
  879.     ret
  880. hdr1:
  881.     call    printx
  882.     db    '-------- --- ------',0
  883.     ret
  884. hdr2:
  885.     call    printx
  886.     db    'Filename.Typ Size K',0
  887.     ret
  888. ;
  889. ;  This is the header which is printed if the files in all user areas are
  890. ;    displayed
  891. ;
  892. xdir6a:
  893.     call    crlfx
  894.     call    spu    ; print U
  895.     call    hdr2    ; print header
  896.     lda    rsflg
  897.     ora    a
  898.     cnz    sp0    ; RS
  899.     call    spu1
  900.     call    spu    ; print U
  901.     call    hdr2    ; print header
  902.     lda    rsflg
  903.     ora    a
  904.     cnz    sp0    ; RS
  905.     call    spu1
  906.     call    spu    ; print U
  907.     call    hdr2    ; print header
  908.     lda    rsflg
  909.     ora    a
  910.     cnz    sp0    ; RS
  911.     call    crlfx
  912.     call    spu2    ; 1 underscore
  913.     call    hdr1    ; underscores
  914.     lda    rsflg
  915.     ora    a
  916.     cnz    sp1
  917.     call    spu1
  918.     call    spu2    ; 1 underscore
  919.     call    hdr1    ; underscores
  920.     lda    rsflg
  921.     ora    a
  922.     cnz    sp1
  923.     call    spu1
  924.     call    spu2    ; 1 underscore
  925.     call    hdr1    ; underscores
  926.     lda    rsflg
  927.     ora    a
  928.     cnz    sp1
  929.  
  930. ;
  931. ;  Prepare Columnar Output
  932. ;
  933. xdir6b:
  934.     lda    dflgs    ; restore disk and print flags
  935.     sta    dflg
  936.     lda    pflgs
  937.     sta    pflg
  938.     lhld    countf    ; get file count down
  939.     lxi    d,maxent    ; assume maxent entries to print
  940.     mov    a,h    ; within range?
  941.     ora    a    ; outside of range if not
  942.     jnz    xdir7    ; subtract entries to print from total entries
  943.     mov    a,l    ; within range?
  944.     cpi    maxent    ; less than maxent entries left?
  945.     jnc    xdir7    ; subtract entries to print from total entries
  946.     mov    d,h    ; DE=HL=number of entries to print
  947.     mov    e,l
  948. xdir7:
  949.     mov    a,l    ; subtract entries to print (DE) from total (HL)
  950.     sub    e
  951.     mov    l,a
  952.     mov    a,h
  953.     sbb    d
  954.     mov    h,a    ; HL=result
  955.     shld    countf    ; save new down count
  956.     mov    b,h    ; BC=count
  957.     mov    c,l
  958.     lhld    firstf    ; pt to first file
  959. ;
  960. ;  At this point, BC=number of remaining entries, DE=number of entries to
  961. ;    print, and HL pts to first entry to print
  962. ;
  963.     shld    ptr1    ; save ptr to 1st entry
  964.     lda    hflg    ; horizontal listing?
  965.     ora    a    ; 0ffh = yes
  966.     jnz    xdir7c    ; don't worry about columns if horizontal
  967.     push    d    ; save count
  968.     call    divde3    ; divide DE by 3, result*esize in BC, remainder in A
  969.     lxi    d,esize    ; DE=ESIZE (size of entry)
  970.     dad    b    ; add BC as a minimum
  971.     ora    a    ; any remainder?
  972.     jz    xdir7a    ; skip if none
  973.     dad    d    ; add in ESIZE for additional length of 1st col
  974. xdir7a:
  975.     shld    ptr2    ; save ptr to col 2
  976.     dad    b    ; add BC as a minimum
  977.     cpi    2    ; if remainder 2, add ESIZE for additional
  978.     jc    xdir7b
  979.     dad    d    ; add in ESIZE
  980. xdir7b:
  981.     shld    ptr3    ; save ptr to col 3
  982.     pop    d    ; get count in de
  983. ;
  984. ;  Main entry print routine
  985. ;
  986. xdir7c:
  987.     mvi    d,1    ; set 3's counter
  988. xdir8:
  989.     lhld    ptr1    ; pt to first entry
  990.     call    prentry    ; print entry
  991.     shld    ptr1    ; put ptr
  992.     lda    hflg    ; horizontal?
  993.     ora    a    ; 0ffh = yes
  994.     jnz    xdir9
  995.     dcr    e    ; count down
  996.     jz    xdir10
  997.     lhld    ptr2    ; get ptr
  998.     call    prentry    ; print entry
  999.     shld    ptr2    ; put ptr
  1000.     dcr    e    ; count down
  1001.     jz    xdir10
  1002.     lhld    ptr3    ; get ptr
  1003.     call    prentry    ; print entry
  1004.     shld    ptr3    ; put ptr
  1005. xdir9:
  1006.     dcr    e    ; count down
  1007.     jnz    xdir8    ; continue if not zero
  1008.     shld    firstf    ; save ptr to first of next set of entries to print
  1009.     lhld    countf    ; get count of remaining entries
  1010. ;
  1011. ;  At this point, HL=number of entries left
  1012. ;
  1013.     mov    a,h    ; anything left?
  1014.     ora    l
  1015.     jz    xdir10
  1016.     lda    dflg    ; no message if disk or printer output
  1017.     mov    b,a
  1018.     lda    pflg
  1019.     ora    b
  1020.     jnz    xdir6
  1021.     call    print    ; screen break
  1022.     db    cr,lf,' --> Screen Break -- Strike any char <-- ',0
  1023.     call    cin    ; get response
  1024.     cpi    ctrlc    ; abort?
  1025.     jz    return
  1026.     jmp    xdir6    ; new screen display
  1027. ;
  1028. ;  Print end statistics and exit
  1029. ;
  1030. xdir10:
  1031.     call    crlfx    ; new line
  1032.     lhld    fcount    ; print file count
  1033.     call    prhlx    ; print it everywhere
  1034.     call    printx
  1035.     db    ' Files Using ',0
  1036.     lhld    totsiz    ; get total of file sizes
  1037.     call    prhlx    ; print it everywhere
  1038.     call    printx
  1039.     db    'K, ',0
  1040.     lhld    totfil    ; print total file count
  1041.     call    prhlx    ; print it everywhere
  1042.     call    printx
  1043.     db    ' Files on Disk and ',0
  1044.  
  1045. ;
  1046. ;  Print Amount of Free Space Left on Disk
  1047. ;    Entry Point if No Files Found
  1048. ;
  1049. xdir11:
  1050.     lhld    freesiz    ; get amount of free space
  1051.     call    prhlx    ; print it everywhere
  1052.     call    printx
  1053.     db    'K Left',0
  1054.     lda    dflg    ; if disk or printer output, new line
  1055.     mov    b,a
  1056.     lda    pflg
  1057.     ora    b
  1058.     jz    return
  1059.     call    crlfx    ; new line for disk and/or printer
  1060.     lda    pflg    ; print output
  1061.     mov    b,a
  1062.     lda    ffflg    ; form feed
  1063.     ana    b    ; if print and form feed ... NZ is set
  1064.     mvi    a,ff    ; form feed char
  1065.     cnz    lout    ; form feed to printer
  1066.     jmp    return
  1067.  
  1068. ;
  1069. ;  File Name Buffer Functions
  1070. ;
  1071. xdirf:
  1072.     call    banner    ; print banner
  1073.     lda    iscn    ; just scan?
  1074.     ora    a    ; 0=no
  1075.     jnz    xdirfs
  1076.     lda    fopt    ; get option of F command
  1077.     cpi    'L'    ; log names to disk?
  1078.     jz    xdirfl
  1079.     cpi    'S'    ; scan names on disk?
  1080.     jz    xdirfs
  1081. ;
  1082. ;  File Name Print Option; /FP option
  1083. ;
  1084. xdirfp:
  1085.     call    openin    ; open FNAMES.DIR for input
  1086. xdfp0:
  1087.     call    printx
  1088.     db    cr,lf,cr,lf
  1089.     db    'Printout of Recorded File Names --',cr,lf,'     ',0
  1090. ;
  1091. ;  Extract File Name Count
  1092. ;
  1093.     call    f1$get    ; get low count
  1094.     jnz    geterr
  1095.     mov    l,a    ; save in L
  1096.     call    f1$get    ; get high count
  1097.     jnz    geterr
  1098.     mov    h,a    ; save in H
  1099.     push    h    ; save HL
  1100.     call    prhlx    ; print HL everywhere
  1101.     call    printx
  1102.     db    ' File Names',cr,lf,0
  1103.     call    prfhdr    ; print file name header
  1104.     pop    h    ; get HL
  1105.     mvi    c,0    ; set entry counter
  1106.  
  1107. ;
  1108. ;  Loop for extracting names from FNAMES.DIR and printing them
  1109. ;
  1110. xdfp1:
  1111.     mov    a,h    ; no more entries?
  1112.     ora    l
  1113.     jz    xdfp2
  1114.     dcx    h    ; count down
  1115.     call    getdfn    ; get next disk file name from FNAMES.DIR
  1116.     call    prfnfx    ; print file name entry
  1117.     inr    c    ; increment count
  1118.     mov    a,c    ; new line time?
  1119.     ani    3
  1120.     cz    crlfx
  1121.     jmp    xdfp1
  1122. xdfp2:
  1123.     call    fi1$close
  1124.     call    crlfx    ; new line
  1125.     jmp    return
  1126.  
  1127. ;
  1128. ;  Log File Names to Disk; /FL option
  1129. ;    Structure of FNAMES.DIR file is:
  1130. ;        File Name Count, Low-Order Byte
  1131. ;        File Name Count, High-Order Byte
  1132. ;        File Names, stored as 12 bytes -- User Number, FN, and FT
  1133. ;
  1134. xdirfl:
  1135.     lxi    d,fnfcb    ; open file for output
  1136.     call    fo1$open
  1137.     jz    xdfl1
  1138.     call    printx
  1139.     db    cr,lf,'Cannot Create FNAMES.DIR',0
  1140.     jmp    return
  1141.  
  1142. ;  Log Files to Disk with possible initial inspect and select by user
  1143. xdfl1:
  1144.     lda    iflg    ; inspect?
  1145.     ora    a    ; 0=no
  1146.     cnz    flinsp    ; inspect if selected
  1147.  
  1148. ;  Print file count
  1149.     call    printx
  1150.     db    cr,lf,cr,lf
  1151.     db    'Logging File Names to Disk --',cr,lf,'     ',0
  1152.     lhld    fcount    ; get count
  1153.     call    prhlx    ; print it
  1154.     call    printx
  1155.     db    ' File Names',cr,lf,0
  1156.  
  1157. ;  Check file count and print appropriate header
  1158.     lhld    fcount    ; get number of files
  1159.     mov    a,h    ; any files?
  1160.     ora    l
  1161.     jz    xdfl1a
  1162.     call    prfhdr    ; print file name header
  1163.     jmp    xdfl1b
  1164. xdfl1a:
  1165.     call    printx    ; no files
  1166.     db    '     No Files to be Logged',0
  1167.  
  1168. ;  Store file count to disk
  1169. xdfl1b:
  1170.     mov    a,l    ; store low count
  1171.     call    f1$put
  1172.     jnz    puterr
  1173.     mov    a,h    ; store high count
  1174.     call    f1$put
  1175.     jnz    puterr
  1176.     xchg        ; ... in DE
  1177.     lhld    firstf    ; pt to first file
  1178.     mvi    c,0    ; set display counter
  1179.  
  1180. ;  Loop to store files names
  1181. xdfl2:
  1182.     mov    a,d    ; done?
  1183.     ora    e
  1184.     jz    xdfl3
  1185.     dcx    d    ; count down
  1186.  
  1187. ;  Write entry to disk
  1188.     push    d    ; save count
  1189.     push    h    ; save ptr to file
  1190.     mov    a,m    ; get user number
  1191.     call    f1$put    ; save it
  1192.     jnz    puterr
  1193.     lxi    d,numbuf    ; print user number
  1194.     push    d    ; save ptr
  1195.     call    madc
  1196.     pop    d    ; get ptr
  1197.     inx    d    ; pt to 1st digit
  1198.     ldax    d    ; get it
  1199.     call    coutx
  1200.     inx    d    ; pt to last digit
  1201.     ldax    d    ; get it
  1202.     call    coutx
  1203.     mvi    a,' '    ; <SP>
  1204.     call    coutx
  1205.     inx    h    ; pt to FN
  1206.     mvi    b,8    ; 8 chars
  1207.     call    xdput
  1208.     mvi    a,'.'
  1209.     call    coutx
  1210.     mvi    b,3    ; 3 chars
  1211.     call    xdput
  1212.     mvi    a,' '    ; print <SP>
  1213.     call    coutx
  1214.     call    coutx
  1215.     inr    c    ; increment count
  1216.     mov    a,c    ; get count
  1217.     ani    3
  1218.     cz    crlfx
  1219.     pop    h    ; get ptr to first file
  1220.     pop    d    ; get count
  1221.     push    b
  1222.     lxi    b,esize    ; pt to next file
  1223.     dad    b
  1224.     pop    b
  1225.     jmp    xdfl2
  1226.  
  1227. ;  Done with creation of FNAMES.DIR
  1228. xdfl3:
  1229.     call    fo1$close    ; close file
  1230.     call    crlfx
  1231.     jmp    return
  1232.  
  1233. ;  Write B chars pted to by HL to FNAMES.DIR and user
  1234. xdput:
  1235.     mov    a,m    ; get char
  1236.     call    coutx    ; print it everywhere
  1237.     call    f1$put    ; put it on disk
  1238.     jnz    puterr
  1239.     inx    h    ; pt to next
  1240.     dcr    b    ; count down
  1241.     jnz    xdput
  1242.     ret
  1243.  
  1244. ;
  1245. ;  Inspect Files for Logging to Disk
  1246. ;
  1247. flinsp:
  1248.     lhld    fcount    ; get count of files
  1249.     xchg        ; ... in DE
  1250.     mov    a,d    ; any files selected?
  1251.     ora    e
  1252.     rz        ; abort if none
  1253.  
  1254. ;  Inspection banner
  1255.     call    printx
  1256.     db    cr,lf,'Inspection of Files to be Logged',0
  1257.     lhld    firstf    ; pt to first file
  1258.  
  1259. ;  Main inspection loop
  1260. flil1:
  1261.     mov    a,d    ; any files selected?
  1262.     ora    e
  1263.     jz    flil3    ; done if not
  1264.     dcx    d    ; count down
  1265.     push    d    ; save count
  1266.     lxi    d,dfnbuf    ; copy file name to buffer
  1267.     mvi    b,12    ; 12 bytes
  1268.     call    moveb
  1269.     call    printx
  1270.     db    cr,lf,'Log ',0
  1271.     call    prfnfx    ; print file name for prompt
  1272.     call    printx
  1273.     db    ' to Disk (Y/N)? ',0
  1274.     call    cin    ; get response
  1275.     call    caps    ; capitalize
  1276.     call    coutx
  1277.     cpi    'N'    ; No?
  1278.     jz    flil2
  1279.     mov    a,m    ; mark user number
  1280.     ori    80h
  1281.     mov    m,a
  1282. flil2:
  1283.     lxi    d,esize    ; skip to next entry
  1284.     dad    d
  1285.     pop    d    ; get count
  1286.     jmp    flil1
  1287. flil3:
  1288.     lhld    fcount    ; get number of files
  1289.     mov    b,h    ; count in BC
  1290.     mov    c,l
  1291.     lhld    firstf    ; pt to first file
  1292.     call    dirpack    ; pack directory
  1293.     mov    h,b    ; new count in HL
  1294.     mov    l,c
  1295.     shld    fcount    ; set counts
  1296.     shld    countf
  1297.     ret
  1298.  
  1299. ;
  1300. ;  Error Message for Output
  1301. ;
  1302. puterr:
  1303.     call    printx
  1304.     db    cr,lf,'Disk Write Error',0
  1305.     jmp    return
  1306.  
  1307. ;
  1308. ;  Scan Disk for File Names; /FS option
  1309. ;
  1310. xdirfs:
  1311.     call    printx
  1312.     db    cr,lf,'File Name Scanner',0
  1313.     call    openin    ; open FNAMES.DIR for input
  1314. xdfs1:
  1315.     call    printx
  1316.     db    cr,lf,'Files Named in FNAMES.DIR missing from Disk --',cr,lf,0
  1317.  
  1318. ;  Get file name count
  1319.     call    f1$get    ; get file name count from disk
  1320.     jnz    geterr
  1321.     mov    c,a    ; store low
  1322.     call    f1$get
  1323.     jnz    geterr
  1324.     mov    b,a    ; store high
  1325.     lhld    fcount    ; get count of number of files
  1326.     xchg        ; ... in DE
  1327.     lhld    firstf    ; pt to first file
  1328.     xra    a    ; A=0
  1329.     sta    crcnt    ; set counter for CRLF
  1330.     sta    fmark    ; mark no first file yet
  1331.  
  1332. ;
  1333. ;  At this point, HL pts to first file in buffer, DE is number of files in
  1334. ;    buffer, and BC is number of files in FNAMES.DIR
  1335. ;
  1336.     mov    a,b    ; any names in FNAMES.DIR?
  1337.     ora    c
  1338.     jz    xdfs5    ; mark all names in buffer if not
  1339.     call    getdfn    ; get first disk name
  1340. xdfs2:
  1341.     mov    a,b    ; see if any more files in FNAMES.DIR
  1342.     ora    c
  1343.     jz    xdfs5    ; mark rest of files in buffer and continue
  1344.     mov    a,d    ; see if any more files in buffer
  1345.     ora    e
  1346.     jz    xdfs6    ; name rest of files in FNAMES.DIR as missing and cont
  1347.     call    compfn    ; compare to file name pted to by HL
  1348.     jz    xdfs3a    ; advance to next file if they match
  1349.     jc    xdfs3    ; mark file name pted to by HL as additional
  1350.     lda    fmark    ; first file?
  1351.     ora    a    ; 0=yes
  1352.     jnz    xdfs2a
  1353.     mvi    a,0ffh    ; set mark
  1354.     sta    fmark
  1355.     call    prfhdr    ; print header
  1356. xdfs2a:
  1357.     call    prfnfx    ; print file name in FNAMES.DIR
  1358.     dcx    b    ; count down
  1359.     mov    a,b    ; done?
  1360.     ora    c
  1361.     jz    xdfs2
  1362.     call    getdfn    ; get next name
  1363.     lda    crcnt    ; get entry counter
  1364.     inr    a    ; increment
  1365.     sta    crcnt
  1366.     ani    3    ; mask
  1367.     cz    crlfx    ; new line every 4
  1368.     jmp    xdfs2
  1369. xdfs3:
  1370.     mov    a,m    ; get user number
  1371.     ori    80h    ; mark it
  1372.     mov    m,a    ; put it back
  1373.     jmp    xdfs4
  1374. xdfs3a:
  1375.     call    getdfn    ; get next name
  1376.     dcx    b    ; count down on names
  1377. xdfs4:
  1378.     push    d    ; save count
  1379.     lxi    d,esize    ; pt to next entry
  1380.     dad    d
  1381.     pop    d    ; get count
  1382.     dcx    d    ; count down
  1383.     jmp    xdfs2    ; continue
  1384.  
  1385. ;  Mark rest of files in buffer
  1386. xdfs5:
  1387.     mov    a,d    ; check count
  1388.     ora    e
  1389.     jz    xdfs7
  1390.     dcx    d    ; count down
  1391.     mov    a,m    ; get user number
  1392.     ori    80h    ; mark it
  1393.     mov    m,a    ; put user number
  1394.     lxi    b,esize    ; skip to next file
  1395.     dad    b
  1396.     jmp    xdfs5    ; continue
  1397.  
  1398. ;  Name rest of files in FNAMES.DIR as missing
  1399. xdfs6:
  1400.     call    prfnfx    ; print file name in FNAMES.DIR
  1401.     dcx    b    ; count down
  1402.     mov    a,b    ; done?
  1403.     ora    c
  1404.     jz    xdfs7    ; next phase
  1405.     lda    crcnt    ; get entry counter
  1406.     inr    a    ; increment
  1407.     sta    crcnt
  1408.     ani    3    ; mask
  1409.     cz    crlfx    ; new line every 4
  1410.     call    getdfn    ; get next name
  1411.     jmp    xdfs6
  1412.  
  1413. ;  Part 2 of Scan - Name Additional Files
  1414. xdfs7:
  1415.     lda    fmark    ; no files printed?
  1416.     ora    a    ; 0=none
  1417.     jnz    xdfs7a
  1418.     call    printx
  1419.     db    '   No Files Missing',0
  1420. xdfs7a:
  1421.     xra    a    ; A=0
  1422.     sta    fmark    ; set mark for 2nd part
  1423.     call    printx
  1424.     db    cr,lf,'Additional Files on Disk NOT in FNAMES.DIR --',cr,lf,0
  1425.     lhld    fcount    ; get count of files
  1426.     xchg        ; ... in DE
  1427.     lhld    firstf    ; pt to first file
  1428.     xra    a    ; A=0
  1429.     sta    crcnt    ; set counter
  1430. xdfs8:
  1431.     mov    a,d    ; check count
  1432.     ora    e
  1433.     jz    xdfs9    ; done if zero
  1434.     dcx    d    ; count down
  1435.     mov    a,m    ; get user number
  1436.     ani    80h    ; marked?
  1437.     jz    xdfs8b    ; skip if not
  1438.     mov    a,m    ; get user number
  1439.     ani    7fh    ; mask
  1440.     mov    m,a    ; replace
  1441.     lda    fmark    ; first time?
  1442.     ora    a    ; 0=yes
  1443.     jnz    xdfs8a
  1444.     mvi    a,0ffh    ; set mark
  1445.     sta    fmark
  1446.     call    prfhdr    ; print header
  1447. xdfs8a:
  1448.     push    d    ; save count
  1449.     lxi    d,dfnbuf    ; copy to buffer for print
  1450.     mvi    b,12    ; 12 bytes
  1451.     call    moveb    ; copy
  1452.     pop    d
  1453.     call    prfnfx    ; print file name
  1454.     lda    crcnt    ; count down
  1455.     inr    a
  1456.     sta    crcnt
  1457.     ani    3    ; new line?
  1458.     cz    crlfx
  1459. xdfs8b:
  1460.     lxi    b,esize    ; pt to next entry
  1461.     dad    b
  1462.     jmp    xdfs8    ; continue
  1463.  
  1464. ;  Done with Scan
  1465. xdfs9:
  1466.     lda    fmark    ; no files printed?
  1467.     ora    a    ; 0=none
  1468.     jnz    xdfs9a
  1469.     call    printx
  1470.     db    '   No Additional Files',0
  1471. xdfs9a:
  1472.     jmp    return
  1473.  
  1474. ;
  1475. ;  Compare file name pted to by HL with that in DFNBUF; return with Z if same,
  1476. ;    C if (HL)<(DFNBUF)
  1477. ;
  1478. compfn:
  1479.     push    h    ; save regs
  1480.     push    d
  1481.     push    b
  1482.     lxi    d,dfnbuf    ; pt to buffer
  1483.     xchg        ; DE pts to file name, HL pts to DFNBUF
  1484.     push    h    ; save ptrs
  1485.     push    d
  1486.     mvi    b,11    ; compare FN and FT
  1487. cfn1:
  1488.     inx    h    ; pt to next
  1489.     inx    d
  1490.     mov    a,m    ; get char from DFNBUF
  1491.     ani    7fh    ; mask MSB
  1492.     mov    c,a    ; save in C
  1493.     ldax    d    ; get name in memory buffer
  1494.     ani    7fh    ; mask MSB
  1495.     cmp    c    ; compare to name in DFNBUF
  1496.     jnz    cfn2    ; not same, so exit with flag set
  1497.     dcr    b    ; count down
  1498.     jnz    cfn1
  1499.     pop    d    ; same so far, so compare user numbers
  1500.     pop    h
  1501.     mov    a,m    ; get user number
  1502.     ani    7fh    ; mask MSB
  1503.     mov    c,a    ; save in C
  1504.     ldax    d    ; get user number
  1505.     ani    7fh    ; mask MSB
  1506.     cmp    c    ; compare
  1507.     push    h    ; fill stack for ext
  1508.     push    h
  1509. cfn2:
  1510.     pop    h    ; clear stack
  1511.     pop    h
  1512.     pop    b    ; get regs and exit
  1513.     pop    d
  1514.     pop    h
  1515.     ret
  1516.  
  1517. ;
  1518. ;  General Utility Routines
  1519. ;
  1520.  
  1521. ;
  1522. ;  Print user and file name stored in DFNBUF for /Ff functions
  1523. ;
  1524. prfnfx:
  1525.     push    h    ; save regs
  1526.     push    d
  1527.     push    b
  1528.     lxi    h,dfnbuf    ; pt to first byte of buffer
  1529.     mov    a,m        ; get first byte (user number)
  1530.     lxi    d,numbuf    ; convert to chars in memory
  1531.     call    madc
  1532.     lxi    d,numbuf+1    ; pt to first char
  1533.     ldax    d    ; get it
  1534.     call    coutx
  1535.     inx    d    ; pt to 2nd char
  1536.     ldax    d    ; get it
  1537.     call    coutx
  1538.     mvi    a,' '    ; <SP>
  1539.     call    coutx
  1540.     inx    h    ; pt to FN
  1541.     mvi    b,8    ; 8 chars for FN
  1542.     call    prch
  1543.     mvi    a,'.'
  1544.     call    coutx
  1545.     mvi    b,3    ; 3 chars for FT
  1546.     call    prch
  1547.     call    prfhs    ; 2 <sp>
  1548.     pop    b    ; get regs
  1549.     pop    d
  1550.     pop    h
  1551.     ret
  1552. ;
  1553. ;  Get next User Number, FN, and FT from disk and save it in buffer
  1554. ;
  1555. getdfn:
  1556.     push    h    ; save regs
  1557.     push    d
  1558.     push    b
  1559.     lxi    h,dfnbuf    ; pt to buffer
  1560.     mvi    b,12    ; 12 bytes
  1561. getdf1:
  1562.     call    f1$get    ; get user
  1563.     jnz    geterr
  1564.     mov    m,a    ; store user
  1565.     inx    h    ; pt to next
  1566.     dcr    b    ; count down
  1567.     jnz    getdf1
  1568.     pop    b    ; restore regs
  1569.     pop    d
  1570.     pop    h
  1571.     ret
  1572. ;
  1573. ;  Print File Buffer Names Header Everywhere
  1574. ;
  1575. prfhdr:
  1576.     mvi    b,3    ; 3 times
  1577. prfhd1:
  1578.     call    prfh1    ; print header
  1579.     call    prfhs    ; print 2 spaces
  1580.     dcr    b
  1581.     jnz    prfhd1
  1582.     call    prfh1
  1583.     call    crlfx
  1584.     mvi    b,3    ; 3 times
  1585. prfhd2:
  1586.     call    prfh2    ; print header
  1587.     call    prfhs    ; print 2 spaces
  1588.     dcr    b
  1589.     jnz    prfhd2
  1590.     call    prfh2
  1591.     call    crlfx
  1592.     ret
  1593. prfhs:
  1594.     call    printx
  1595.     db    '  ',0
  1596.     ret
  1597. prfh1:
  1598.     call    printx
  1599.     db    ' U Filename.Typ',0
  1600.     ret
  1601. prfh2:
  1602.     call    printx
  1603.     db    ' - -------- ---',0
  1604.     ret
  1605. ;
  1606. ;  Get Error Message and Abort
  1607. ;
  1608. geterr:
  1609.     call    printx
  1610.     db    cr,lf,'Premature EOF',0
  1611.     jmp    return
  1612. ;
  1613. ;  Open FNAMES.DIR for byte-oriented input
  1614. ;
  1615. openin:
  1616.     lxi    d,fnfcb    ; open file
  1617.     call    fi1$open    ; open for input
  1618.     rz
  1619.     call    printx
  1620.     db    cr,lf,'FNAMES.DIR Not Found',0
  1621.     jmp    return
  1622. ;
  1623. ;  Print disk entry for normal directory display functions
  1624. ;
  1625. prentry:
  1626.     dcr    d    ; count <CRLF> counter
  1627.     jnz    prent1
  1628.     mvi    d,3    ; reset count
  1629.     call    crlfx
  1630. prent1:
  1631.     shld    entptr    ; save entry ptr
  1632.     lda    aflg    ; all users selected?
  1633.     ani    20h
  1634.     jz    prent2
  1635. ;
  1636. ;  The following prints the user number if all user numbers are selected
  1637. ;
  1638.     push    h    ; save regs
  1639.     push    d
  1640.     push    b
  1641.     mov    a,m    ; get user number
  1642.     ani    1fh    ; mask it
  1643.     lxi    d,numbuf
  1644.     call    madc    ; convert to chars in memory
  1645.     lxi    h,numbuf+1    ; pt to first char
  1646.     mov    a,m    ; get it
  1647.     call    coutx
  1648.     inx    h    ; get 2nd char
  1649.     mov    a,m
  1650.     call    coutx
  1651.     mvi    a,' '    ; print <SP>
  1652.     call    coutx
  1653.     pop    b    ; get regs
  1654.     pop    d
  1655.     pop    h
  1656. prent2:
  1657.     inx    h    ; pt to first char of file name
  1658.     mvi    b,8    ; print 8 chars
  1659.     call    prch
  1660.     mvi    a,'.'    ; print dot
  1661.     call    coutx
  1662.     push    h    ; save RS ptr
  1663.     mvi    b,3    ; print 3 chars
  1664.     call    prch
  1665.     push    d    ; save de
  1666.     lhld    entptr    ; pt to entry
  1667.     mvi    a,' '    ; skip 2 spaces
  1668.     call    coutx
  1669.     call    coutx
  1670.     call    fsize    ; compute file size
  1671.     lhld    totsiz    ; get total file size counter
  1672.     dad    d    ; add in new file
  1673.     shld    totsiz    ; save new total file size counter
  1674.     xchg        ; get file size into HL
  1675.     call    prhlx    ; print HL value
  1676.     pop    d    ; get de
  1677.     pop    h    ; pt to RS
  1678.     lda    rsflg    ; print RS fields?
  1679.     ora    a    ; Z=no
  1680.     jz    pren2a
  1681.     mvi    a,' '    ; print 1 space
  1682.     call    coutx
  1683.     mvi    b,'R'    ; letter
  1684.     call    prletx    ; print R if bit set
  1685.     inx    h
  1686.     mvi    b,'S'    ; letter
  1687.     call    prletx    ; print S if bit set
  1688.     dcx    h    ; ... for following inx h
  1689. pren2a:
  1690.     inx    h    ; point correctly
  1691.     mvi    a,' '    ; 1 space
  1692.     call    coutx
  1693.     lda    aflg    ; all users?
  1694.     ani    20h
  1695.     jnz    prent3
  1696. ;
  1697. ;  The following prints 2 additional spaces if only one user area is selected
  1698. ;
  1699.     mvi    a,' '    ; 2 more spaces for not all users
  1700.     call    coutx
  1701.     call    coutx
  1702. prent3:
  1703.     lxi    b,6    ; pt to next entry
  1704.     dad    b
  1705.     ret
  1706. ;
  1707. ;  Print B chars pted to by HL
  1708. ;
  1709. prch:
  1710.     mov    a,m    ; get char
  1711.     inx    h    ; pt to next
  1712.     ani    7fh    ; mask out msb
  1713.     cpi    ' '    ; within range?
  1714.     jnc    prch1    ; print special char if not valid char
  1715.     mvi    a,'?'    ; print ? if not valid char
  1716. prch1:
  1717.     call    coutx    ; print it
  1718.     dcr    b    ; count down
  1719.     jnz    prch
  1720.     ret
  1721. ;
  1722. ;  Extended Print Routines
  1723. ;
  1724. prletx:
  1725.     mov    a,m    ; get byte
  1726.     ani    80h    ; look at msb
  1727.     jz    prlets
  1728.     mov    a,b    ; get letter
  1729.     call    coutx
  1730.     ret
  1731. prlets:
  1732.     mvi    a,' '    ; print <sp>
  1733.     call    coutx
  1734.     ret
  1735. prhlx:
  1736.     lxi    d,numbuf    ; store in number buffer
  1737.     call    mhldc    ; hl into memory as decimal
  1738.     mvi    b,5    ; 5 digits
  1739. prnumx:
  1740.     lxi    h,numbuf    ; pt to buffer
  1741. prnum:
  1742.     mov    a,m    ; get digit
  1743.     inx    h    ; pt to next
  1744.     call    coutx    ; print everywhere
  1745.     dcr    b    ; count down
  1746.     jnz    prnum
  1747.     ret
  1748. printx:
  1749.     xthl        ; pt to string
  1750.     call    prxl    ; print string at HL
  1751.     xthl
  1752.     ret
  1753. prxl:
  1754.     mov    a,m    ; get byte
  1755.     inx    h    ; pt to next
  1756.     ora    a    ; done?
  1757.     rz
  1758.     call    coutx    ; print everywhere
  1759.     jmp    prxl
  1760. coutx:
  1761.     push    b    ; save bc
  1762.     push    psw    ; save char
  1763.     ani    7fh    ; mask out msb
  1764.     mov    b,a    ; char in B
  1765.     call    cout    ; print to screen
  1766.     lda    pflg    ; printer on?
  1767.     ora    a    ; 0=no
  1768.     mov    a,b    ; get char
  1769.     cnz    lout    ; printer output if on
  1770.     lda    dflg    ; disk on?
  1771.     ora    a    ; 0=no
  1772.     mov    a,b    ; get char
  1773.     cnz    f0$put    ; output to file
  1774.     pop    psw    ; get char
  1775.     pop    b    ; get bc
  1776.     ret
  1777. crlfx:
  1778.     push    psw    ; save A
  1779.     call    printx
  1780.     db    cr,lf,0
  1781.     pop    psw    ; get A
  1782.     ret
  1783. ;
  1784. ;  Divide DE by 3; return with BC=result*esize, a=remainder
  1785. ;
  1786. divde3:
  1787.     push    d    ; save de, hl
  1788.     push    h
  1789.     mvi    d,0    ; make sure D=0
  1790.     mov    a,e    ; value in A
  1791. divd31:
  1792.     sui    3    ; subtract 3
  1793.     jc    divd32
  1794.     jz    divd33
  1795.     inr    d    ; add 1 to result
  1796.     jmp    divd31
  1797. divd32:
  1798.     adi    3    ; add back in
  1799.     jmp    divd34
  1800. divd33:
  1801.     inr    d    ; add 1 for even division
  1802. divd34:
  1803.     sta    rem    ; save remainder
  1804.     lxi    b,esize
  1805.     lxi    h,0
  1806. divd35:
  1807.     mov    a,d    ; done?
  1808.     ora    a    ; 0=yes
  1809.     jz    divd36
  1810.     dcr    d
  1811.     dad    b    ; add in another ESIZE
  1812.     jmp    divd35
  1813. divd36:
  1814.     mov    b,h    ; BC is result
  1815.     mov    c,l
  1816.     lda    rem    ; A is remainder
  1817.     pop    h    ; restore regs
  1818.     pop    d
  1819.     ret
  1820. ;
  1821. ;  Skip blanks
  1822. ;
  1823. sblank:
  1824.     mov    a,m    ; pt to char
  1825.     cpi    ' '    ; blank?
  1826.     rnz
  1827.     inx    h    ; pt to next
  1828.     jmp    sblank
  1829.  
  1830. ;
  1831. ;  Buffers
  1832. ;
  1833. aflg:    ds    1    ; attibute flag
  1834. dflg:    ds    1    ; disk output on flag
  1835. fflg:    ds    1    ; 0=no file name buffer function
  1836. gflg:    ds    1    ; 0=group by name/type
  1837. hflg:    ds    1    ; 0=vertical list
  1838. iflg:    ds    1    ; 0=no inspect
  1839. nflg:    ds    1    ; 0=no negate
  1840. pflg:    ds    1    ; printer output on flag
  1841. fopt:    ds    1    ; file name buffer option
  1842. crcnt:    ds    1    ; entry counter
  1843. fmark:    ds    1    ; first file marker
  1844. dflgt:    ds    1    ; temp flags
  1845. pflgt:    ds    1
  1846. dflgs:    ds    1
  1847. pflgs:    ds    1
  1848. rsflg:    ds    1    ; RS Display Flag
  1849. ffflg:    ds    1    ; form feed flag
  1850. disk:    ds    1    ; selected disk
  1851. curdisk:
  1852.     ds    1    ; current disk
  1853. curuser:
  1854.     ds    1    ; current user
  1855. rem:    ds    1    ; remainder buffer
  1856. firstf:    ds    2    ; ptr to first file of group to print
  1857. totfil:    ds    2    ; total number of files on disk
  1858. fcount:    ds    2    ; count of files
  1859. countf:    ds    2    ; down count of files
  1860. freesiz:
  1861.     ds    2    ; amount of free space on disk
  1862. totsiz:
  1863.     ds    2    ; total size of all files
  1864. ptr1:    ds    2    ; col output ptrs
  1865. ptr2:    ds    2
  1866. ptr3:    ds    2
  1867. entptr:    ds    2    ; current entry ptr
  1868. numbuf:    ds    6    ; number buffer
  1869. dfnbuf:
  1870.     ds    12    ; disk file name buffer
  1871. dskfcb:
  1872.     db    0
  1873.     db    'XDIR    DIR'
  1874.     db    0,0,0,0
  1875.     ds    16
  1876.     ds    4
  1877. fnfcb:
  1878.     db    0
  1879.     db    'FNAMES  DIR'
  1880.     db    0,0,0,0
  1881.     ds    16
  1882.     ds    4
  1883. cmdlne:    ds    2    ; pointer to command line
  1884. buffer:    ds    2    ; pointer to free space buffer
  1885. stack:    ds    2    ; stack ptr
  1886.  
  1887.     end
  1888.