home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / UTILS / DIRUTL / D-31.ASM < prev    next >
Assembly Source File  |  2000-06-30  |  26KB  |  1,293 lines

  1.  
  2. ; D.ASM v3.1  -  05/05/84
  3. ;
  4. ;        RESTRICTED DIRECTORY LIST PROGRAM
  5. ;
  6. ; D.COM is a directory list program, which writes 4 or 5 entries on a
  7. ; line, separated by colons.
  8. ;
  9. ;
  10. ;   (THIS IS THE 'WHATSNEW' PROGRAM SEEN ON MANY RCPM SYSTEMS)
  11. ;
  12. ;
  13. ; The command contains an internal table of file names, which are not to
  14. ; be shown when just "D" is typed.  (NOTE typing "D *.*" always shows
  15. ; all files)
  16. ;
  17. ; Why is this useful:  A typical CP/M disk contains many utility files,
  18. ; such as ED.COM, ASM,COM, PIP.COM, STAT.COM, etc.  When you do a direc-
  19. ; tory listing, you typically are not interested in seeing all those
  20. ; files, but rather just the "current" or "active" files.  This is what
  21. ; "D.COM" can do.
  22. ;
  23. ; NOTE: Direct CBIOS calls are used for input and output in order to
  24. ;    avoid echoing of inputted characters.  This keeps a noisy phone
  25. ;    line from causing garbage characters in the display.
  26. ;-----------------------------------------------------------------------
  27. ;
  28. ; 05/05/84  Line with the "use FILE xxx*.*" now only appears on the line
  29. ;   v3.1    with the message about moved or deleted files.
  30. ;                    - Irv Hoff
  31. ;    
  32. ; 05/01/84  Changed the "Deleted files since --- " to "Files moved else-
  33. ;   v3.0    where or deleted", then added a line "use FILE xxx*.* to see
  34. ;        if available."  With 20-40 megabyte disk systems now common,
  35. ;        this is a convenient way to locate files which are no longer
  36. ;        in the "Whatsnew" user area.  It was misleading when reading
  37. ;        the files had been deleted when most have merely been moved.
  38. ;        (Every SYSOP needs FILE.COM on his system.)  SD xxx*.* $U0AD
  39. ;        may also be used, but gives information that is superfluous.
  40. ;        Standardized the format.    - Irv Hoff
  41. ;
  42. ; 08/12/82  Added SUB file option to allow writing each new filename
  43. ;   v2.9    that appears in the "New Files" display to a .SUB file of
  44. ;        the form:
  45. ;            XSUB
  46. ;            PIP
  47. ;            $1=$2 Fn.Ft$3
  48. ;            $1=$2 Fn.Ft$3
  49. ;
  50. ;        etc., to allow a simple archive of new files to be performed
  51. ;        by: SUBMIT D A:=B: [G1].  Also repaired bug in EXIT routine
  52. ;        and removed character 'gobbler' routine so that the program
  53. ;        will work better with 'type-ahead' BIOSes.
  54. ;                    - Dave Hardy
  55. ;
  56. ; 11/23/78  Originally written by Ward Christensen.
  57. ;
  58. ;=======================================================================
  59. ;
  60. ; Use:    D *.*    prints all names, 5 across.
  61. ;
  62. ;    D *.ASM prints selected files just like DIR.
  63. ;
  64. ;    D SET builds a table (in D.COM) of all names currently on the
  65. ;        disk. (see *NOTE).
  66. ;
  67. ;    D SET <DATE>  adds the date for printing whenever is called by
  68. ;        'A>D<CR>' with no options.  If the date field is left
  69. ;        blank, it will be ignored.  Note that the date must be
  70. ;        8 characters or less (see *NOTE).
  71. ;
  72. ;    D TIT <TITLE FOR DISK> sets an internal disk title which prints
  73. ;        out each time the program is run (if a title has been
  74. ;        set).  (maximum of about 70 characters, please, although
  75. ;        it will handle a full CP/M input line.
  76. ;
  77. ;        NOTE: To get rid of title (and accompanying
  78. ;        print put type 'D TIT' and the title is
  79. ;        set to null.
  80. ;
  81. ;    D ADD FN.FT adds a name to the table in D.COM, so FN.FT will not
  82. ;        be listed by the 'D' command (see *NOTE).
  83. ;
  84. ;    D DEL FN.FT deletes a name from the table in D.COM, so if FN.FT
  85. ;        is in the directory, it will be listed by 'D' (see NOTE)
  86. ;
  87. ;    D SUB causes a file named 'D.SUB' to be generated on the current-
  88. ;        ly logged-in drive.  The file contains all of the 'New
  89. ;        Files' names, and is of the form:
  90. ;
  91. ;            XSUB
  92. ;            PIP
  93. ;            $1<fn1.ft>$2
  94. ;            $1<fn2.ft>$2
  95. ;            $1<fn3.ft>$2
  96. ;
  97. ;        etc.  D.SUB can be used to archive 'New Files' with a
  98. ;        simple command line like:  SUBMIT D B:=A: [G5] which
  99. ;        would PIP all of the new files from B5: to A:
  100. ;
  101. ;    D     lists the directory, showing only those files NOT in D.COM
  102. ;        as put there by 'D SET' or 'D ADD FN.FT'
  103. ;
  104. ;            *NOTE:    the program must write itself
  105. ;                back to disk, modified, so your
  106. ;                disk must not be write protected.
  107. ;
  108. ;-----------------------------------------------------------------------
  109. ;
  110. ;        Examples:  Suppose your disk has:
  111. ;
  112. ;    D.COM      \
  113. ;    ASM.COM    \
  114. ;    ED.COM        on it initially.
  115. ;    LOAD.COM   /
  116. ;    DDT.COM   /
  117. ;
  118. ;        You would type:  D SET to set these names into the
  119. ;        D.COM program.
  120. ;
  121. ;        Typing "D" would then list:
  122. ;
  123. ;    -->New files
  124. ;    A: ++ NONE ++
  125. ;
  126. ;    -->Deleted files
  127. ;    A: ++ NONE ++
  128. ;
  129. ;        Suppose you:  A>ED TEST.ASM, A>ASM TEST and LOAD TEST.
  130. ;        Typing D would then list:
  131. ;
  132. ;    -->New files
  133. ;    A: TEST    ASM : TEST     BAK : TEST    HEX : TEST    COM
  134. ;
  135. ;    -->Deleted files
  136. ;    A: ++ NONE ++
  137. ;
  138. ;        i.e., it tells you of the "current" files on the disk.
  139. ;        Now, supposing you wanted to add TEST.COM as a "regular"
  140. ;        file on your disk.  Type:
  141. ;
  142. ;    D ADD TEST.COM
  143. ;
  144. ;        Now, typing D will show:
  145. ;
  146. ;    -->New files
  147. ;    A: TEST    ASM : TEST     BAK : TEST    HEX
  148. ;
  149. ;    -->Deleted files
  150. ;    A: ++NONE++
  151. ;
  152. ;        i.e., TEST.COM is now considered a "permanent" file.
  153. ;
  154. ;        Now, suppose you accidentally erased ASM.COM from your
  155. ;        disk.  Typing D gives:
  156. ;
  157. ;    -->New files
  158. ;    A: TEST    ASM : TEST     BAK : TEST    HEX
  159. ;
  160. ;    -->Deleted files
  161. ;    A: ASM       COM
  162. ;
  163. ;        showing you are missing one of the "regular" files.  If,
  164. ;        in fact, you didn't want ASM.COM to be on the disk, type:
  165. ;
  166. ;    D DEL ASM.COM
  167. ;
  168. ;        which will delete the name from the D.COM table, so
  169. ;        ASM.COM will not up as "deleted".
  170. ;
  171. ;=======================================================================
  172. ;
  173. ;           SPECIAL NOTES FOR REMOTE SYSTEM USE:
  174. ;
  175. ; If you keep a dedicated copy of this program on each drive of your re-
  176. ; mote system, you can 'dedicate' each copy of this program to a drive
  177. ; by filling in the byte at 103H with the drive number.  This prevents
  178. ; such things as:
  179. ;
  180. ;    A>D B:
  181. ;        or
  182. ;    B>A:D
  183. ;
  184. ; Do this by using the command:
  185. ;
  186. ;    A>D LOK A:    to lock to a drive
  187. ;        or
  188. ;    A>D LOK     to unlock
  189. ;
  190. ; If the conditional 'NOSYS' is set YES, $SYS files in CP/M 2.x will be
  191. ; ignored in both directory listings and when the "ADD" option is in-
  192. ; voked, unless the override char is specified.  This allows D.COM to be
  193. ; used as a "WHAT'S NEW" program for remote CP/M systems, where the $SYS
  194. ; files must not be listed.
  195. ;
  196. ; Examples:
  197. ;
  198. ;    A>D *.* S     displays everything
  199. ;    A>D SET S     puts ALL files in table
  200. ;    A>D SET 12/23/80 sets date for reference
  201. ;
  202. ;        (if you use 'D SET S', you lose the date option..
  203. ;
  204. ; If you use this program on a remote system, you will likely want to
  205. ; change the commands (ADD, DEL, and SET) for security.  You will also
  206. ; want to change the $SYS suppress override character.    You may also
  207. ; want to change the name of the program to make the name itself more
  208. ; informative, e.g. "D.COM".
  209. ;
  210. ;
  211. ; -->IMPORTANT: If you want the program to be 'TAG'ed after every D SET
  212. ;        (so it cannot be taken by XMODEM), see the note at label
  213. ;        "WRBACK" for setting the F1 bit in the filename itself.
  214. ;
  215. ;
  216. ; Note that this program defines its own name for write-back purposes
  217. ; under the label "WRBACK".
  218. ;
  219. ;=======================================================================
  220. ;
  221. ; Define some stuff
  222. ;
  223. YES:    EQU    0FFH
  224. NO:    EQU    0
  225. ;
  226. ;
  227. BIAS:    EQU    0        ;for std cp/m or 4200h for altcpm
  228. BDOS:    EQU    5+BIAS        ;cp/m's BDOS access jump
  229. CPMBUFF:EQU    80H+BIAS    ;cp/m command line buffer
  230. CR:    EQU    0DH        ;carriage return
  231. FCB:    EQU    5CH+BIAS    ;cp/m's file control block
  232. FCBRNO:    EQU    FCB+32        ;rec # in fcb
  233. LF:    EQU    0AH        ;line feed
  234. ;
  235. ;
  236. ; Set the following for your system:
  237. ;
  238. NOSYS    EQU    YES        ;yes=ignore $sys files
  239. FENCE    EQU    ':'        ;file name separator
  240. NPL    EQU    4        ;file names per line
  241. ;
  242. ;
  243. ; The leader string for the SUB file (XSUB, PIP) is located at label
  244. ; SUBF4.
  245. ;
  246. ;
  247.     ORG    100H+BIAS
  248. ;
  249. ;
  250. DENTRY:    JMP    AROUND
  251. ;
  252. DRIVE:    DB    0        ;<---drv # is put here if dedicated
  253.                 ;(this can be done with the lok command)
  254. ;
  255. ;Initialize the local stack
  256. ;
  257. AROUND:    LXI    H,0        ;hl=0
  258.     DAD    SP        ;hl=stack
  259.     SHLD    STACK        ;save stack pointer
  260.     LXI    SP,STACK    ;init local stack
  261. ;
  262. ;
  263. ;Initialize direct CBIOS calls
  264. ;
  265.     LHLD    1+BIAS
  266.     LXI    D,3
  267.     DAD    D        ;hl=constat
  268.     SHLD    TYPES+1
  269.     DAD    D        ;hl=conin
  270.     SHLD    CIC+1
  271.     DAD    D        ;hl=conout
  272.     SHLD    TYPEC+1
  273. ;
  274. ;
  275. ; Print ID message
  276. ;
  277.     CALL    ILPRT        ;print:
  278.     DB    'D v3.1',CR,LF
  279.     DB    'CTL-S pauses, CTL-C aborts',CR,LF,0
  280. ;
  281. ;
  282. ; Print Disk Title
  283. ;
  284. PTITL:    LXI    H,DTITLE    ;get title address
  285.     MOV    A,M        ;load it
  286.     ORA    A        ;end of string
  287.     JZ    CONT        ;don't print title
  288.     CALL    ILPRT        ;print heading
  289.     DB    'Title: ',0
  290.     LXI    H,DTITLE    ;load it again
  291. ;
  292. LOOP1:    MOV    A,M
  293.     ORA    A        ;zero?
  294.     JZ    ENDPRT        ;all done
  295.     CALL    TYPE        ;type this char
  296.     INX    H        ;next char
  297.     JMP    LOOP1        ;repeat ...
  298.  
  299. DTITLE:    DB    0        ;storage for
  300.     DS    7FH        ;title
  301. ;
  302. ENDPRT:    CALL    CRLF
  303. ;
  304. ;
  305. ; Set file control block
  306. ;
  307. CONT:    LDA    DRIVE
  308.     ORA    A        ;non-dedicated?
  309.     JZ    NOND        ;jump if so
  310.     STA    FCB
  311. ;
  312. NOND:    LHLD    FCB+17        ;get $sys override characters
  313.     SHLD    SYSTOO        ;and save for later
  314.     LDA    FCB+19
  315.     STA    SYSTOO+2
  316. ;
  317. ;
  318. ; See if request to add name to list
  319. ;
  320.     LXI    H,FCB+1
  321.     CALL    ADDCM2
  322. ;
  323. ADDCM:    DB    'ADD        '    ;11 characters (padded with spaces)
  324. ;
  325. ADDCM2:    POP    D        ;make de point to add command
  326.     LXI    B,ADDCM2-ADDCM    ;bc gets length of string
  327.     CALL    COMPR
  328.     JNZ    NOADD
  329. ;
  330. ;
  331. ; Got request to add name to table
  332. ;
  333.     CALL    DELNAM        ;first, delete the name
  334.     CALL    FINDFF        ;find end of table
  335.     XCHG            ;addr to de
  336. ;
  337. ;
  338. ; Move name to table
  339. ;
  340.     LXI    H,FCB+17
  341.     LXI    B,11
  342.     CALL    MOVER
  343.     MVI    A,0FFH
  344.     STAX    D        ;set new end
  345.     JMP    WRBACK        ;write program back
  346. ;
  347. ;
  348. ; See if request to add title to disk
  349. ;
  350. NOADD:    LXI    H,FCB+1
  351.     CALL    NOADD1A
  352. NOADD1B:
  353.     DB    'TIT'        ;total of this and the next line must..
  354. TITLEN:    DB    '        '    ;be 11, change for a longer title name
  355. ;
  356. NOADD1A:
  357.     POP    D        ;get to
  358.     LXI    B,NOADD1A-NOADD1B
  359.     CALL    COMPR
  360.     JNZ    NOADD2A
  361. ;
  362. ;
  363. ; Process the title or erase it, if none given
  364. ;
  365.     LXI    H,CPMBUFF    ;get length
  366.     MOV    A,M        ;move it to a
  367.     SUI    TITLEN-NOADD1B+1;but don't include the title command
  368.     JZ    TITNO        ;no title?
  369.     LXI    H,CPMBUFF+TITLEN-NOADD1B+2
  370.     LXI    B,0000
  371.     MOV    C,A        ;put length in bc
  372.     LXI    D,DTITLE    ;place to store
  373.     CALL    MOVER        ;move title in storage
  374.     MVI    A,00        ;and mark end
  375.     STAX    D        ;of string
  376.     JMP    WRBACK        ;and write back to disk
  377. ;...
  378. ;
  379. ;    
  380. ; No title - Clear title
  381. ;
  382. TITNO:    LXI    H,DTITLE    ;load in space
  383.     MVI    M,00        ;store end of string
  384.     JMP    WRBACK        ;and write back to disk
  385. ;.....
  386. ;
  387. ;
  388. ; See if request to lock D.COM to a drive
  389. ;
  390. NOADD2A:
  391.     LXI    H,FCB+1
  392.     CALL    NOADD3
  393. ;
  394. NOADD2:    DB    'LOK        '
  395. ;
  396. NOADD3:    POP    D        ;get to
  397.     LXI    B,NOADD3-NOADD2
  398.     CALL    COMPR
  399.     JNZ    NOLOK
  400. ;
  401. ;
  402. ; Got request to lock
  403. ;
  404.     LDA    FCB+16
  405.     STA    DRIVE
  406.     STA    FCB
  407.     JMP    WRBACK
  408. ;.....
  409. ;
  410. ;
  411. ; See if request to DEL name from list
  412. ;
  413. NOLOK:    LXI    H,FCB+1
  414.     CALL    NOLOK3
  415. NOLOK2:    DB    'DEL        '    ;must be 11 total
  416. ;
  417. NOLOK3:    POP    D        ;get to
  418.     LXI    B,NOLOK3-NOLOK2
  419.     CALL    COMPR
  420.     JNZ    NODEL
  421. ;
  422. ;
  423. ; Got request to delete a name from the file
  424. ;
  425.     CALL    DELNAM        ;delete the name
  426.     JNC    WRBACK        ;write back if ok
  427.     CALL    MSGXIT
  428.     DB    '++ NAME NOT IN TABLE ++$'
  429. ;.....
  430. ;
  431. ;
  432. ; See if request is to make SUB file
  433. ;
  434. NODEL:    LXI    H,FCB+1
  435.     CALL    SUBF3
  436. SUBF2:    DB    'SUB        '    ;must be 11 total
  437. ;
  438. SUBF3:    POP    D
  439.     LXI    B,SUBF3-SUBF2
  440.     CALL    COMPR
  441.     JNZ    NOSUB
  442. ;
  443. ;
  444. ; Got request to make SUB file, so say so, and set flag to force it
  445. ;
  446.     CALL    SAYSUB        ;tell console that sub file will be made
  447.     DB    'Writing SUBMIT file...',CR,LF,'$'
  448. ;
  449. SAYSUB:    POP    D
  450.     MVI    C,9
  451.     CALL    BDOS
  452.     MVI    A,0FFH        ;tell prgm to make sub file
  453.     STA    SUBFLG
  454.     LXI    H,SUBBUF    ;write sub file start into file buffer
  455.     CALL    SUBF5        ;(xsub, pip, etc.)
  456. ;
  457. SUBF4:    DB    'XSUB',CR,LF,'PIP',CR,LF
  458. ;
  459. SUBF5:    POP    D        ;use mover routine to copy to sub buffer
  460.     XCHG
  461.     LXI    B,SUBF5-SUBF4
  462.     CALL    MOVER
  463.     XCHG
  464.     SHLD    SUBPTR        ;save sub file buffer pointer
  465.     LXI    H,FCB+1        ;then fill tail in with spaces to make
  466.     MVI    C,11        ;  program think that no options chosen
  467. ;
  468. NXSPC:    MVI    M,' '
  469.     DCR    C
  470.     INX    H
  471.     JNZ    NXSPC
  472.     MVI    C,36H        ;initialize local fcb
  473.     LXI    H,LFCB        ;(no default, because commands there)
  474. ;
  475. NXFCB:    MVI    M,0
  476.     DCR    C
  477.     INX    H
  478.     JNZ    NXFCB
  479.     LXI    D,LFCB+1    ;set up local fcb to write d.sub file
  480.     CALL    UWR2
  481. ;
  482. UWR1:    DB    'D       SUB',0
  483. ;
  484. UWR2:    POP    H
  485.     LXI    B,UWR2-UWR1
  486.     CALL    MOVER
  487.     MVI    C,ERASE        ;erase old file, if it exists
  488.     LXI    D,LFCB
  489.     CALL    BDOS
  490.     XRA    A
  491.     STA    LFCB        ;set up to write to default drive
  492.     STA    FCBRNO        ;initialize record number
  493.     MVI    C,MAKE        ;create the file
  494.     LXI    D,LFCB
  495.     CALL    BDOS
  496.     JMP    NOSET        ;then jump off to display names as usual
  497. ;.....
  498. ;
  499. ;
  500. ; See if request to set up table from directory
  501. ;
  502. NOSUB:    LXI    H,FCB+1
  503.     CALL    NODEL3
  504. NODEL2:    DB    'SET        '    ;must total 11
  505. ;
  506. NODEL3:    POP    D        ;get to
  507.     LXI    B,NODEL3-NODEL2
  508.     CALL    COMPR
  509.     JNZ    NOSET
  510. ;
  511. ;
  512. ; Got request to setup table.  Move the date (may be blank).
  513. ;
  514.     LXI    H,FCB+17
  515.     LXI    D,DATE
  516.     LXI    B,8
  517.     CALL    MOVER
  518. ;
  519.     LXI    H,FCB+17
  520.     LXI    D,DATE1
  521.     LXI    B,8
  522.     CALL    MOVER
  523. ;
  524.     MVI    A,1        ;turn on..
  525.     STA    SETFLG        ;..set flag
  526.     MVI    A,0FFH        ;clear..
  527.     STA    NAMES        ;..names table
  528.     CALL    FILLQ        ;make fcb '????????.???'
  529. ;
  530. NOSET:    LDA    FCB+1        ;get prtflg
  531.     SUI    ' '
  532.     STA    PRTFLG
  533.     PUSH    PSW
  534.     CZ    HEAD1
  535.     POP    PSW
  536.     JNZ    GOTNAM
  537.     CALL    FILLQ        ;make name ????????.???
  538. ;
  539. GOTNAM:    LDA    FCB
  540.     ORA    A
  541.     JZ    NODISK
  542.     DCR    A
  543.     MOV    E,A
  544.     MVI    C,SELDSK
  545.     CALL    BDOS
  546. ;
  547. NODISK:    MVI    B,NPL        ;names per line
  548.     CALL    LINMRK
  549.     MVI    C,SRCHF
  550.     JMP    CALLIT
  551. ;
  552. LINE:    MVI    B,NPL        ;names per line
  553.     CALL    LINMRK
  554. ;
  555. NEXT:    MVI    C,SRCHN
  556. ;
  557. CALLIT:    PUSH    B
  558.     LXI    D,FCB
  559.     CALL    BDOS
  560.     INR    A
  561.     JZ    CKNONE
  562.     DCR    A
  563.     ANI    3
  564.     MOV    L,A
  565.     MVI    H,0
  566.     DAD    H
  567.     DAD    H
  568.     DAD    H
  569.     DAD    H
  570.     DAD    H
  571.     LXI    D,81H+BIAS
  572.     DAD    D
  573. ;
  574. ;
  575. ; Check for $SYS attribute, then clear all attributes
  576. ;
  577.     PUSH    H
  578.     LXI    D,9        ;sys att offset
  579.     DAD    D
  580.     MOV    A,M
  581.     ANI    80H
  582.     STA    SYSFLG
  583.     POP    H        ;retrieve filename ptr
  584.     PUSH    H
  585.     MVI    E,11        ;11 chars in filename
  586. ;
  587. ATTLP:    MOV    A,M        ;pick up char
  588.     ANI    7FH        ;kill attribute
  589.     MOV    M,A        ;put back down
  590.     INX    H
  591.     DCR    E
  592.     JNZ    ATTLP
  593.     POP    H
  594. ;
  595. ;
  596. ; See if name is to be printed
  597. ;
  598.     XCHG            ;name pointer to de
  599.     LDA    SETFLG        ;request to setup table?
  600.     ORA    A
  601.     JNZ    SETUP        ;go set entry into table
  602.     LDA    PRTFLG
  603.     ORA    A
  604.     JNZ    GOPRNT        ;explicit request for all
  605.     PUSH    D
  606.     LXI    H,NAMES
  607. ;
  608. CKNEXT:    POP    D        ;get name pointer
  609.     POP    B
  610.     PUSH    B
  611.     MOV    A,M        ;end of table?
  612.     INR    A        ;was it 0ffh?
  613.     JZ    GOPRNT
  614.     MVI    B,0
  615.     MVI    C,11        ;name length
  616.     PUSH    D
  617. ;
  618. CKLP:    LDAX    D
  619.     CMP    M
  620.     JNZ    NOMACH
  621.     INX    D
  622.     INX    H
  623.     DCR    C
  624.     JNZ    CKLP        ;loop for 11 chars
  625. ;
  626. ;
  627. ; Got match, mark it found but do not print it
  628. ;
  629.     LXI    D,-11        ;point back to name
  630.     DAD    D
  631.     MVI    M,0        ;mark it found
  632.     POP    D        ;pop pointer
  633.     POP    B
  634.     JMP    NEXT        ;skip the name
  635. ;
  636. ;
  637. ; Name didn't match, try next
  638. ;
  639. NOMACH:    DAD    B        ;point to next name
  640.     JMP    CKNEXT
  641. ;
  642. ;
  643. ; Print the name
  644. ;
  645. GOPRNT:
  646.      IF    NOSYS
  647.     CALL    SYSCK
  648.     JZ    DONAME
  649.     LDA    SYSFLG
  650.     RAL
  651.     POP    B
  652.     JC    NEXT
  653.     PUSH    B
  654.      ENDIF            ;NOSYS
  655. ;
  656. ;
  657. DONAME:    LDA    SUBFLG        ;see if sub file is to be made
  658.     ORA    A
  659.     CNZ    NAMSUB        ;write the name into the sub buffer
  660.     MVI    A,1        ;say we got one
  661.     STA    GOTFLG
  662.     MVI    C,8
  663.     XCHG            ;name back to hl
  664.     CALL    TYPMEM
  665.     MVI    A,'.'
  666.     CALL    TYPE
  667.     MVI    C,3
  668.     CALL    TYPMEM
  669.     POP    B
  670.     CALL    SPACE
  671.     MVI    A,FENCE
  672.     DCR    B
  673.     PUSH    PSW
  674.     CNZ    TYPE
  675.     CALL    SPACE
  676.     POP    PSW
  677.     JNZ    NEXT
  678.     CALL    CRLF
  679.     JMP    LINE
  680. ;.....
  681. ;
  682. ;
  683. ; Write the filename pointed to by DE into the SUB file buffer in the
  684. ; format: $1<fn.ft>$2<cr><lf>
  685. ;
  686. NAMSUB:    PUSH    H        ;save hl (whatever's in it)
  687.     PUSH    D        ;save filename pointer
  688.     PUSH    B        ;save bc (whatever's in it)
  689.     LHLD    SUBPTR        ;hl to sub buffer (de to filename)
  690.     MVI    C,8        ;8 characters in filename
  691.     MVI    M,'$'        ;first write '$1'
  692.     CALL    INCPTR        ;increment file buffer pointer and..
  693.     MVI    M,'1'        ;..write if full
  694.     CALL    INCPTR
  695. ;
  696. SNAM:    LDAX    D        ;get a character of the name
  697.     CPI    ' '           ;do not transfer spaces to sub buffer
  698.     JZ    SNAM2
  699.     ANI    7FH        ;trim off any nasty attributes
  700.     MOV    M,A        ;put the character into the sub buffer
  701.     CALL    INCPTR        ;point to next sub location
  702. ;
  703. SNAM2:    INX    D        ;point to next character of filename
  704.     DCR    C        ;decrement filename counter
  705.     JNZ    SNAM        ;continue until all 8 characters read
  706.     MVI    M,'.'        ;put a '.' separator into the sub buffer
  707.     CALL    INCPTR        ;point to next location in sub buffer
  708.     MVI    C,3    ;now do the 3 character long filetype
  709. ;
  710. SNAM3:    LDAX    D
  711.     CPI    ' '
  712.     JZ    SNAM4
  713.     ANI    7FH
  714.     MOV    M,A
  715.     CALL    INCPTR
  716. ;
  717. SNAM4:    INX    D
  718.     DCR    C
  719.     JNZ    SNAM3
  720.     MVI    M,'$'        ;then write '$2<cr><lf>' on the end..
  721.     CALL    INCPTR        ;.. of the name
  722.     MVI    M,'2'
  723.     CALL    INCPTR
  724.     MVI    M,CR
  725.     CALL    INCPTR
  726.     MVI    M,LF
  727.     CALL    INCPTR
  728.     SHLD    SUBPTR        ;save the new sub buffer pointer
  729.     POP    B        ;restore all the registers
  730.     POP    D
  731.     POP    H
  732.     RET            ;then return back to doname
  733. ;.....
  734. ;
  735. ;
  736. ; Increment the HL file buffer pointer, and write the buffer if full
  737. ;
  738. INCPTR:    INX    H        ;see if buffer is full
  739.     MVI    A,(SUBBUF+80H) AND 0FFH
  740.     CMP    L        ;(see if lsh of hl = lsh of subbuf+80h)
  741.     RNZ            ;return if buffer not full
  742. WRTSBF:    LXI    H,SUBBUF    ;reset pointer to start of buffer
  743. ;
  744. WRTSB2:    PUSH    H
  745.     PUSH    D
  746.     PUSH    B
  747.     LXI    D,SUBBUF    ;set dma address to sub buffer
  748.     MVI    C,SETDMA
  749.     CALL    BDOS
  750.     LXI    D,LFCB        ;write the buffer to disk
  751.     MVI    C,WRITE
  752.     CALL    BDOS
  753.     LXI    D,CPMBUFF    ;now set dma address back to default so
  754.     MVI    C,SETDMA    ;..other routines can read directory
  755.     CALL    BDOS
  756.     POP    B
  757.     POP    D
  758.     POP    H
  759.     ORA    A        ;notify console and abort if write error
  760.     JNZ    WRERR
  761.     RET
  762. ;
  763. CKNONE:    LDA    GOTFLG        ;some new files found?
  764.     ORA    A
  765.     JNZ    NOTFND        ;jump if yes
  766.     LDA    PRTFLG        ;print names?
  767.     ORA    A
  768.     JNZ    NOTFND        ;jump if yes
  769.     CALL    ILPRT
  770.     DB    '++ NONE ++',CR,LF,0
  771. ;
  772. ;
  773. ; Print the files not found
  774. ;
  775. NOTFND:    LDA    SETFLG        ;is this 'D SET'?
  776.     ORA    A
  777.     JNZ    FINI        ;done if so
  778.     LDA    PRTFLG        ;are we printing?
  779.     ORA    A
  780.     JNZ    CKNON2        ;done if not
  781. ;
  782. ; If this D.COM is dedicated ("DRIVE" is non-zero), then be sure to
  783. ; print the "FILES NOT FOUND".
  784. ;
  785.     LDA    DRIVE
  786.     ORA    A
  787.     JNZ    NOCHK
  788.     LDA    FCB        ;drive specified?
  789.     ORA    A
  790.     JNZ    FINI        ;skip not found if so
  791. ;
  792. NOCHK:    CALL    HEAD3        ;print not fnd header
  793.     LXI    H,NAMES        ;start of table
  794.     LXI    D,11
  795. ;
  796. LINE2:    MVI    B,NPL
  797.     CALL    LINMRK
  798. ;
  799. NEXT2:    MOV    A,M        ;first char of name
  800.     ORA    A        ;marked found?
  801.     JZ    NOPRNT        ;jump if so
  802.     INR    A        ;check for table end
  803.     JZ    CKNON2        ;jump if end
  804.     MVI    A,1
  805.     STA    GOTNF
  806.     MVI    C,8
  807.     CALL    TYPMEM
  808.     MVI    A,'.'
  809.     CALL    TYPE
  810.     MVI    C,3
  811.     CALL    TYPMEM
  812.     CALL    SPACE
  813.     MVI    A,FENCE
  814.     DCR    B
  815.     PUSH    PSW
  816.     CNZ    TYPE
  817.     CALL    SPACE
  818.     POP    PSW
  819.     JNZ    NEXT2
  820.     CALL    CRLF
  821.     JMP    LINE2
  822. ;
  823. NOPRNT:    DAD    D
  824.     JMP    NEXT2
  825. ;.....
  826. ;
  827. ;
  828. ; Print header
  829. ;
  830. HEAD1:    CALL    ILPRT        ;print:
  831.     DB    CR,LF,'-->New files',0
  832.     LDA    DATE
  833.     CPI    ' '
  834.     JZ    HEAD2
  835.     CALL    SYSCK
  836.     JZ    HEAD2
  837.     CALL    ILPRT        ;print:
  838.     DB    ' since '
  839. ;
  840. DATE:    DB    '        '    ;eight spaces
  841.     DB    0        ;string terminator
  842.     JMP    CRLF
  843. ;
  844. HEAD2:    MVI    A,':'
  845.     CALL    TYPE
  846.     JMP    CRLF
  847. ;.....
  848. ;
  849. ;
  850. HEAD3:    CALL    ILPRT        ;print:
  851.     DB    CR,LF,CR,LF,'-->Files moved elsewhere or deleted',0
  852.     LDA    DATE
  853.     CPI    ' '
  854.     JZ    HEAD5
  855.     CALL    SYSCK
  856.     JZ    HEAD5
  857.     CALL    ILPRT        ;print:
  858.     DB    ' since '
  859. ;
  860. DATE1:    DB    '        '    ;eight spaces
  861.     DB    0        ;string terminator
  862. ;
  863. HEAD4:  CALL    ILPRT
  864.     DB    CR,LF,'   (use FILE xxx*.* to see if available)'
  865.     DB    CR,LF,0
  866.     RET
  867. ;
  868. HEAD5:    MVI    A,':'
  869.     CALL    TYPE
  870.     JMP    HEAD4
  871. ;.....
  872. ;
  873. ;
  874. CKNON2:    LDA    GOTNF
  875.     ORA    A
  876.     JNZ    FINI        ;jmp if got no 'NOT FOUND's
  877.     LDA    PRTFLG
  878.     ORA    A
  879.     JNZ    FINI
  880.     CALL    ILPRT        ;print: (then fall into 'FINI')
  881.     DB    '++ NONE ++',CR,LF,0
  882. ;
  883. ;
  884. ; Finished.  If building table, write back.  If making a SUB file, then
  885. ; flush the file buffer and close it.
  886. ;
  887. FINI:    LDA    SUBFLG        ;see if sub file is to be written
  888.     ORA    A
  889.     JNZ    WRTSUB        ;jump if so,
  890.     LDA    SETFLG        ;else see if set was performed
  891.     ORA    A
  892.     JZ    EXIT        ;jump out if not,
  893.     JMP    WRBACK        ;else write the program back to disk
  894. ;
  895. ;
  896. ; Write the SUB file to the currently logged in disk as 'D.SUB'
  897. ;
  898. WRTSUB:    LHLD    SUBPTR        ;fill rest of last sector with eof's
  899.     XCHG
  900.     LXI    H,SUBBUF+7FH
  901. ;
  902. WNXTS:    MVI    M,1AH
  903.     MOV    A,L
  904.     DCX    H
  905.     CMP    E
  906.     JNZ    WNXTS
  907.     CALL    WRTSB2        ;write the last sector to disk
  908.     MVI    C,CLOSE        ;close the file
  909.     LXI    D,LFCB
  910.     CALL    BDOS
  911.     INR    A        ;if close error, then notify console..
  912.     JZ    BADWCL        ;..and abort
  913.     JMP    EXIT        ;exit back to cp/m
  914. ;
  915. BADWCL:    CALL    MSGXIT
  916.     DB    'BAD CLOSE, SUB file incomplete$'
  917. ;
  918. ;
  919. ; Set up the name in the table
  920. ;
  921. SETUP:
  922.      IF    NOSYS
  923.     CALL    SYSCK
  924.     JZ    SETU2
  925.     LDA    SYSFLG
  926.     RAL
  927.     JC    SETSKP
  928.      ENDIF            ;NOSYS
  929. ;
  930. SETU2:    CALL    FINDFF        ;find end of table
  931.     XCHG            ;setup for move
  932. ;
  933. ;
  934. ; (HL = name, DE = end of table)
  935. ;
  936.     LXI    B,11
  937.     CALL    MOVER
  938.     MVI    A,0FFH        ;get table end flag
  939.     STAX    D        ;store it
  940. ;
  941. SETSKP:    POP    B        ;delete stack garbage
  942.     JMP    NEXT        ;get next entry
  943. ;
  944. ;
  945. ; Routine to type 'C' characters from memory (HL)
  946. ;
  947. TYPMEM:    MOV    A,M
  948.     CALL    TYPE
  949.     INX    H
  950.     DCR    C
  951.     JNZ    TYPMEM
  952.     RET
  953. ;.....
  954. ;
  955. ;
  956. ; Inline print routine - prints string pointed to by stack until a zero
  957. ; is found.  Returns to caller at next address after the zero terminator.
  958. ;
  959. ILPRT:    XTHL            ;save hl, get msg adrs
  960. ;
  961. ILPLP:    MOV    A,M        ;get char
  962.     CALL    TYPE        ;output it
  963.     INX    H        ;point to next
  964.     MOV    A,M        ;test
  965.     ORA    A        ;..for end
  966.     JNZ    ILPLP
  967.     XTHL            ;restore hl, ret addr
  968.     RET            ;ret past msg
  969. ;.....
  970. ;
  971. ;
  972. CRLF:    CALL    ILPRT    ;print:
  973.     DB    CR,LF,0
  974.     RET
  975. ;.....
  976. ;
  977. ;
  978. SPACE:    MVI    A,' '
  979. ;
  980. ;
  981. ; Print character in A to console
  982. ;
  983. TYPE:    PUSH    B
  984.     PUSH    D
  985.     PUSH    H
  986.     MOV    C,A        ;char to c for cbios
  987. ;
  988. TYPEC:    CALL    $-$        ;supplied at start
  989. ;
  990. ;
  991. ; See if console key pressed
  992. ;
  993. TYPES:    CALL    $-$        ;supplied at start
  994.     ORA    A        ;key pressed?
  995.     CNZ    CKKB        ;yes, see which one
  996.     POP    H
  997.     POP    D
  998.     POP    B
  999.     RET
  1000. ;.....
  1001. ;
  1002. ;
  1003. CKKB:    CALL    CI        ;get char
  1004.     CPI    'S'-40H        ;pause?
  1005.     CZ    CI        ;yes, get next char
  1006.     CPI    'C'-40H        ;abort?
  1007.     RNZ            ;no, return
  1008.     CALL    MSGXIT
  1009.     DB    CR,LF,'++ ABORTED ++$'
  1010. ;.....
  1011. ;
  1012. ;
  1013. ; Move (BC) bytes from (HL) to (DE)
  1014. ;
  1015. MOVER:    MOV    A,M
  1016.     STAX    D
  1017.     INX    D
  1018.     INX    H
  1019.     DCX    B
  1020.     MOV    A,B
  1021.     ORA    C
  1022.     JNZ    MOVER
  1023.     RET
  1024. ;.....
  1025. ;
  1026. ;
  1027. ; Compare routine
  1028. ;
  1029. COMPR:    LDAX    D
  1030.     CMP    M
  1031.     RNZ
  1032.     INX    D
  1033.     INX    H
  1034.     DCX    B
  1035.     MOV    A,B
  1036.     ORA    C
  1037.     JNZ    COMPR
  1038.     RET            ;equal means z=1
  1039. ;.....
  1040. ;
  1041. ;
  1042. ; Routine to find 0FFH at end of table
  1043. ;
  1044. FINDFF:    LXI    H,NAMES
  1045. ;
  1046. FINDLP:    MOV    A,M
  1047.     INX    H
  1048.     INR    A        ;0ffh?
  1049.     JNZ    FINDLP
  1050.     DCX    H        ;back up to table end
  1051.     RET
  1052. ;.....
  1053. ;
  1054. ;
  1055. ; Delete the name from the table
  1056. ;
  1057. DELNAM:    LXI    H,NAMES
  1058. ;
  1059. DELLP:    MOV    A,M
  1060.     CPI    YES
  1061.     STC
  1062.     RZ            ;not found
  1063.     LXI    D,FCB+17
  1064.     LXI    B,11
  1065.     CALL    COMPR
  1066.     JZ    DELETE
  1067.     DAD    B        ;calc next
  1068.     JMP    DELLP
  1069. ;.....
  1070. ;
  1071. ;
  1072. ; Delete the name
  1073. ;
  1074. DELETE:    XCHG            ;next name to de
  1075.     LXI    H,-11        ;to back up..
  1076.     DAD    D        ;..to name to del
  1077. ;
  1078. DELCH:    LDAX    D
  1079.     MOV    M,A
  1080.     INX    H
  1081.     INX    D
  1082.     INR    A        ;moved the 0ffh?
  1083.     JNZ    DELCH
  1084.     ORA    A        ;show found
  1085.     RET
  1086. ;.....
  1087. ;
  1088. ;
  1089. ; Fill FCB with all '?'
  1090. ;
  1091. FILLQ:    LXI    H,FCB+1
  1092.     MVI    B,8+3
  1093.     MVI    A,'?'
  1094. ;
  1095. QMLOOP:    MOV    M,A
  1096.     INX    H
  1097.     DCR    B
  1098.     JNZ    QMLOOP
  1099.     RET
  1100. ;.....
  1101. ;
  1102. ;
  1103. ; Write back the program - note that you may set any of the CP/M 2.x
  1104. ; attribute bits in the file name (be sure to define all 11 characters
  1105. ; of the name).
  1106. ;
  1107. WRBACK:    LXI    D,FCB+1
  1108.     CALL    WRBK2
  1109. ;
  1110. WRBK1:    DB    'D'+80H        ;<--put 'D'+80h here to set tag
  1111.     DB    '       COM'     ;see comment above
  1112.     DB    0        ;extent number
  1113. ;
  1114. WRBK2:    POP    H
  1115.     LXI    B,WRBK2-WRBK1
  1116.     CALL    MOVER
  1117.     MVI    C,ERASE
  1118.     LXI    D,FCB
  1119.     CALL    BDOS
  1120.     XRA    A        ;get 0
  1121.     STA    SETFLG        ;clear the flags..
  1122.     STA    GOTFLG
  1123.     STA    GOTNF
  1124.     STA    SYSTOO
  1125.     STA    FCBRNO        ;zero record number
  1126.     MVI    C,MAKE
  1127.     LXI    D,FCB
  1128.     CALL    BDOS
  1129. ;
  1130. ;
  1131. ; Before writing back, find end of table
  1132. ;
  1133.     CALL    FINDFF
  1134.     MOV    B,H        ;b=end page
  1135.     INR    B        ;for compare
  1136.     LXI    D,100H+BIAS    ;starting addr
  1137. ;
  1138. WRLP:    PUSH    B
  1139.     PUSH    D
  1140.     PUSH    H
  1141.     MVI    C,SETDMA
  1142.     CALL    BDOS
  1143.     MVI    C,WRITE
  1144.     LXI    D,FCB
  1145.     CALL    BDOS
  1146.     POP    H
  1147.     POP    D
  1148.     POP    B
  1149.     ORA    A        ;successful write?
  1150.     JNZ    WRERR        ;..no
  1151.     LXI    H,80H        ;point to..
  1152.     DAD    D        ;..next block
  1153.     XCHG            ;addr to de
  1154.     MOV    A,D        ;get page
  1155.     CMP    B        ;past table end?
  1156.     JC    WRLP        ;loop until done
  1157.     MVI    C,CLOSE
  1158.     LXI    D,FCB
  1159.     CALL    BDOS
  1160.     INR    A        ;successful close?
  1161.     JZ    BADCLS        ;..no, print err msg
  1162.     CALL    MSGXIT        ;ok, exit w/msg
  1163.     DB    '++ DONE ++$'
  1164. ;.....
  1165. ;
  1166. ;
  1167. WRERR:    CALL    MSGXIT
  1168.     DB    '++ WRITE ERROR ++$'
  1169. ;.....
  1170. ;
  1171. ;
  1172. BADCLS:    CALL    MSGXIT
  1173.     DB    '++ BAD CLOSE, D.COM CLOBBERED ++$'
  1174. ;.....
  1175. ;
  1176. ;
  1177. ; Get console input via direct CBIOS call
  1178. ;
  1179. CI:    PUSH    B        ;console input
  1180.     PUSH    D
  1181.     PUSH    H
  1182. ;
  1183. CIC:    CALL    $-$        ;supplied at start
  1184.     POP    H
  1185.     POP    D
  1186.     POP    B
  1187.     RET
  1188. ;.....
  1189. ;
  1190. ;
  1191. ; Exit with message (error or informational)
  1192. ;
  1193. MSGXIT:    POP    D        ;get msg
  1194.     MVI    C,PRINT
  1195.     CALL    BDOS
  1196. ;
  1197. ;
  1198. ; Exit, restoring DMA and stack, then return to CCP
  1199. ;
  1200. EXIT:    LXI    D,CPMBUFF    ;reset dma adr to normal
  1201.     MVI    C,SETDMA
  1202.     CALL    BDOS
  1203.     LHLD    STACK        ;get old stack
  1204.     SPHL            ;restore it
  1205.     RET            ;return to ccp
  1206. ;.....
  1207. ;
  1208. ;
  1209. LINMRK:    PUSH    B
  1210.     PUSH    D
  1211.     PUSH    H
  1212.     LDA    FCB        ;get drive name from fcb
  1213.     ORA    A        ;any there?
  1214.     JNZ    GOTDRV        ;yes, go print it
  1215.     MVI    C,CURDSK    ;else get current disk
  1216.     CALL    BDOS
  1217.     INR    A        ;make 'A'=1
  1218. ;
  1219. GOTDRV:    ADI    40H        ;make ascii
  1220.     CALL    TYPE        ;print drive name
  1221.     CALL    ILPRT        ;print
  1222.     DB    ': ',0
  1223.     POP    H
  1224.     POP    D
  1225.     POP    B
  1226.     RET
  1227. ;.....
  1228. ;
  1229. ;
  1230. ; Test for system file override
  1231. ;
  1232. SYSCK:    PUSH    H
  1233.     PUSH    D
  1234.     PUSH    B
  1235.     LXI    H,SYSTOO
  1236.     LXI    D,SYSOK
  1237.     MVI    B,3
  1238. ;
  1239. RSYSCK:    LDAX    D
  1240.     CMP    M
  1241.     INX    H
  1242.     INX    D
  1243.     JNZ    SYSOUT
  1244.     DCR    B
  1245.     JNZ    RSYSCK
  1246. ;
  1247. SYSOUT:    POP    B
  1248.     POP    D
  1249.     POP    H
  1250.     RET
  1251. ;.....
  1252. ;
  1253. ;
  1254.     DS    64        ;room for stack
  1255. STACK:    DS    2        ;old stack stored here
  1256. SUBFLG    DB    00H        ;flag to order sub file built
  1257. SUBPTR    DW    0000H        ;pointer to end of sub file
  1258. GOTFLG:    DB    0
  1259. GOTNF:    DB    0
  1260. SYSTOO:    DB    0,0,0
  1261. SYSOK:    DB    'S  '          ;sys suppression override chars
  1262. SETFLG:    DB    0        ;1 => setup table
  1263. PRTFLG:    DB    0        ;print only some
  1264. SYSFLG:    DB    0        ;$sys attrib indicator
  1265. LFCB    DS    36H        ;local fcb used by sub file
  1266. SUBBUF    DS    128        ;buffer used by sub file write routines
  1267. NAMES    EQU    $        ;names not to print are stored here..
  1268.                 ;..(i.e., the current dir)
  1269. ;
  1270. ; Note the names are initially built by the "D SET" command
  1271. ;
  1272.     DB    0FFH    ;end of table
  1273. ;
  1274. ;
  1275. ; Miscellaneous BDOS equates
  1276. ;
  1277. RDCON    EQU    1
  1278. DIO    EQU    6
  1279. PRINT    EQU    9
  1280. CONST    EQU    11
  1281. SELDSK    EQU    14
  1282. CLOSE    EQU    16
  1283. SRCHF    EQU    17
  1284. SRCHN    EQU    18
  1285. ERASE    EQU    19
  1286. READ    EQU    20
  1287. WRITE    EQU    21
  1288. MAKE    EQU    22
  1289. CURDSK    EQU    25
  1290. SETDMA    EQU    26
  1291. ;
  1292.     END
  1293.