home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / cpm68k / msutils.lbr / DEL.SQ / DEL.S
Encoding:
Text File  |  1988-02-18  |  9.1 KB  |  342 lines

  1. *#######################################################################
  2. *          PROGRAM DEL...Delete File Utility
  3. *
  4. *            Dr. David C. Wilcox
  5. *            DCW Industries, Inc.
  6. *         5354 Palm Dr., La Canada, CA  91011
  7. *               818/790-3844
  8. *
  9. *             January 24, 1986
  10. *#######################################################################
  11. boot    equ    00        *Warm Boot
  12. inchar    equ    01        *Console Input
  13. outchar    equ    02        *Console Output
  14. print    equ    09        *Print String
  15. sfirst    equ    17        *Search for First
  16. snext    equ    18        *Search for Next
  17. delete    equ    19        *Delete File
  18. current    equ    25        *Return Current Disk
  19. setdma    equ    26        *Set DMA Address
  20. null    equ    00        *Ascii NUL
  21. ctrlc    equ    03        *Ascii ETX
  22. tab    equ    09        *Horizontal Tab
  23. lf    equ    10        *Line Feed
  24. cr    equ    13        *Carriage Return
  25. space    equ    32        *Space
  26. upmask    equ    $5f        *Upper Case Mask
  27. bdos    equ    $0002        *BDOS Entry Point
  28. *#######################################################################
  29. *  Special registers:
  30. *
  31. *    a6 = address of first parsed FCB
  32. *    d3 = drive designation
  33. *    d4 = number of file matches counter
  34. *    d5 = R/O bit
  35. *    d6 = SYS bit
  36. *#######################################################################
  37. *
  38. *  Locate FCB (for portability)
  39. *
  40.     link    a6,#0        *Mark stack frame
  41.     move.l    8(a6),a0    *Get base page address
  42.     lea    $5c(a0),a6    *Get address of FCB and save it in a6
  43. *
  44. *  Clear data registers and determine drive specification
  45. *
  46.     jsr    clear
  47.     jsr    getdrv
  48. *
  49. *  Check for no file specified
  50. *
  51.     cmpi.b    #space,1(a6)    *Is 1st char in filespec a space?
  52.     bne    begin
  53.     jsr    delall        *If so, call delall
  54. *
  55. *  Begin search for file name matches
  56. *
  57. begin:
  58.     move.l    #mydma,d1    *===================
  59.     move.w    #setdma,d0    *Set the DMA Address
  60.     trap    #bdos        *===================
  61.     move.l    a6,d1        *Load the FCB
  62.     move.w    #sfirst,d0    *and search for the first match
  63.     trap    #bdos
  64.     cmpi.b    #$ff,d0        *Is there no match?
  65.     beq    quit        *No match if it's zero so quit
  66. *
  67. *  Search for filename matches
  68. *
  69. search:
  70.     mulu    #32,d0        *Adjust for DMA offset of matching entry
  71.     move.l    #mydma,a3    *Point to mydma
  72.     adda.w    d0,a3        *and add the offset
  73.     movea.l    #bufadr,a4    *Point to buffer
  74.     move.l    (a4),a5
  75.     move.w    #32,d1        *Initialize the counter
  76. copy35:
  77.     move.b    (a3)+,(a5)+    *Copy contents of a3 to a5
  78.     subq    #1,d1        *Decrement the counter
  79.     bne    copy35        *and keep looping until it's zero
  80.     move.l    a5,bufadr    *Save buffer address
  81.     addq    #1,d4        *Increment file match counter
  82.     move.l    a6,d1        *=========================
  83.     move.w    #snext,d0    *Search for next occurance
  84.     trap    #bdos        *=========================
  85.     cmpi.b    #$ff,d0        *Is there no match?
  86.     bne    search        *Keep searching until all are found
  87.     movea.l    #buffer,a5    *Point to the original buffer
  88.     move.l    a5,bufadr    *Save buffer address
  89. *
  90. *  Prepare for Deletion
  91. *
  92. prepfil:
  93.     jsr    drivepr        *Display drive identifier
  94.     move.w    #8,d2        *Initialize filename character counter
  95.     movea.l    a5,a4        *Save a5
  96.     adda.l    #1,a5        *Skip drive designation
  97.     jsr    readmem        *Read and display filename
  98.     move.b    #'.',d1        *Send a "." to the console
  99.     jsr    conout
  100.     move.w    #3,d2        *Initialize filetype character counter
  101.     jsr    readmem        *Read and display filetype
  102.     move.b    #space,d1    *Send a space to the console
  103.     jsr    conout
  104.     move.b    #space,d1    *and then send another
  105.     jsr    conout
  106.     movea.l    a4,a5        *Retrieve a5
  107.     adda.l    #9,a5        *and...
  108.     btst    #7,(a5)        *test the R/O bit
  109.     beq    syschk        *If not set, skip to SYS check
  110.     move.b    #$ff,d5        *If file is R/O...store $ff in d5
  111. syschk:
  112.     adda.l    #1,a5
  113.     btst    #7,(a5)        *test the SYS bit
  114.     beq    pretest        *If not set, skip to pretest
  115.     move.b    #$ff,d6        *If file is SYS...store $ff in d6
  116. *
  117. *  Check to see if it's either R/O or SYS
  118. *
  119. pretest:
  120.     or.b    d5,d6        *Or the R/O and SYS bits
  121.     bne.b    mortest        *Additional testing needed if nonzero
  122.     move.b    #tab,d1        *Send a tab to console
  123.     jsr    conout
  124.     jmp    query        *and skip to "Delete..." query
  125. mortest:
  126.     move.b    #'(',d1        *Send left paren to console
  127.     jsr    conout
  128. *
  129. *  Check to see if it's R/O
  130. *
  131. rotest:
  132.     tst.b    d5        *Test for Read Only
  133.     beq    systest        *If not R/O jump to systest
  134.     move.l    #msgro,d1    *Display "R/O"
  135.     jsr    pstring
  136.     move.b    #')',d1        *Send right paren to console
  137.     jsr    conout
  138.     jsr    crlf        *and finish with a cr/lf
  139.     jmp    nexfile        *then skip around delete file logic
  140. *
  141. *  Check to see if it's SYS
  142. *
  143. systest:
  144.     move.l    #msgsys,d1    *Display "SYS"
  145.     jsr    pstring
  146.     move.b    #')',d1        *Send right paren to console
  147.     jsr    conout
  148.     move.b    #tab,d1        *Followed by a tab
  149.     jsr    conout
  150. *
  151. *  Proceed with Deletion
  152. *
  153. query:
  154.     move.l    #msgdel,d1    *Display the "Delete..." query
  155.     jsr    pstring
  156.     move.w    #inchar,d0    *Fetch the keyboard response
  157.     trap    #bdos
  158.     move.b    d0,d2        *Save it
  159.     jsr    crlf        *Send a cr/lf to console
  160.     move.b    d2,d0        *Retrieve the response
  161.     andi.b    #upmask,d0    *Make it upper case
  162.     cmpi.b    #ctrlc,d0    *Check for a ^C
  163.     beq    quit        *If it is...quit
  164.     cmpi.b    #'Y',d0        *Check for a "Y"
  165.     bne    nexfile
  166.     jsr    delfile        *If it is, call the delete file routine
  167. *
  168. *  Prepare for next file
  169. *
  170. nexfile:
  171.     clr.l    d5        *Zero out the R/O
  172.     clr.l    d6        *and SYS bits
  173.     subq    #1,d4        *Decrement file match counter
  174.     beq    quit        *If last file...quit
  175.     movea.l    #bufadr,a4    *Point to buffer
  176.     move.l    (a4),a5
  177.     adda.l    #32,a5        *Add 32 bytes => point to next match
  178.     move.l    a5,bufadr    *Save buffer address
  179.     jmp    prepfil        *Loop back for the next file
  180. *#######################################################################
  181. *                           Subroutines
  182. *#######################################################################
  183. *
  184. *  Clear data registers
  185. *
  186. clear:
  187.     clr.l    d1
  188.     clr.l    d2
  189.     clr.l    d3
  190.     clr.l    d4
  191.     clr.l    d5
  192.     clr.l    d6
  193.     rts
  194. *
  195. *  Send a character to the console
  196. *
  197. conout:
  198.     move.w    #outchar,d0
  199.     trap    #bdos
  200.     rts
  201. *
  202. *  Send a carriage return and a line feed to the console
  203. *
  204. crlf:
  205.     move.b    #cr,d1
  206.     jsr    conout
  207.     move.b    #lf,d1
  208.     jsr    conout
  209.     rts
  210. *
  211. *  Display default delete-file message on the console
  212. *
  213. delall:
  214.     move.l    #msgal1,d1    *Display '*.*..." query
  215.     jsr    pstring
  216.     jsr    drivepr
  217.     move.l    #msgal2,d1
  218.     jsr    pstring
  219.     move.w    #inchar,d0    *Fetch keyboard response
  220.     trap    #bdos
  221.     move.b    d0,d2        *Save it
  222.     jsr    crlf        *Send a cr/lf to console
  223.     move.b    d2,d0        *Retrieve the response
  224.     andi.b    #upmask,d0    *Make it upper case
  225.     cmpi.b    #'Y',d0        *Test for "Y"
  226.     bne.b    abort        *If not...abort
  227.     movea.l    a6,a5        *Point to first character in filename
  228.     addq    #1,a5
  229.     move.w    #11,d2        *Initialize the counter
  230. loop1:
  231.     move.b    #'?',(a5)+    *Make compare file "????????.???"
  232.     subq    #1,d2
  233.     bne.b    loop1
  234.     move.w    #24,d2        *Reinitialize counter
  235. loop2:
  236.     move.b    #null,(a5)+    *Fill the rest of FCB with NULS
  237.     subq    #1,d2
  238.     bne.b    loop2
  239.     rts
  240. *
  241. *  Delete a File
  242. *
  243. delfile:
  244.     movea.l    #bufadr,a0    *Point to buffer
  245.     move.l    (a0),a1
  246.     move.b    (a6),(a1)    *Make sure we have the correct drive
  247.           move.w    a1,d1        *Load the FCB
  248.     move.w    #delete,d0    *Delete the file
  249.     trap    #bdos
  250.     rts
  251. *
  252. *  Display drive identifier
  253. *
  254. drivepr:
  255.     move.b    d3,d1
  256.     jsr    conout
  257.     move.b    #':',d1
  258.     jsr    conout
  259.     rts
  260. *
  261. *  Determine drive number and make it ascii
  262. *
  263. getdrv:
  264.     move.b    (a6),d1        *Get drive number from FCB
  265.     cmpi.b    #0,d1        *Is it the default drive?
  266.     bne    ascii
  267.     jsr    logged        *If so, get physical drive number
  268. ascii:    addi.b    #64,d1        *Make it ascii
  269.     move.b    d1,d3        *and save it in d3
  270.     rts
  271. *
  272. *  Determine which is the logged drive
  273. *
  274. logged:
  275.     move.w    #current,d0    *Get current drive number
  276.     trap    #bdos
  277.     addq.b    #1,d0        *Increment for consistency with getdrv
  278.     move.w    d0,d1        *and save it in d1 for getdrv
  279.     rts
  280. *
  281. *  Send a String to the Console
  282. *
  283. pstring:
  284.     move.w    #print,d0
  285.     trap    #bdos
  286.     rts
  287. *
  288. *  Quit to CP/M
  289. *
  290. quit:
  291.     cmpi.b    #ctrlc,d0    *Is it a ^C?
  292.     beq    abort        *If so...display abort message
  293.     cmpi.b    #$ff,d0        *Is it a ff hex?
  294.     beq    nomatch        *If so...display "no match..." message
  295.     move.b    #boot,d0    *Otherwise...exit to CP/M
  296.     trap    #bdos
  297. abort:
  298.     move.l    #msgabt,d1    *Display "Program aborted" message
  299.     jsr    pstring
  300.     move.b    #boot,d0    *and exit to CP/M
  301.     trap    #bdos
  302. nomatch:
  303.     move.l    #msgnom,d1    *Display "No match..." message
  304.     jsr    pstring
  305.     move.b    #boot,d0    *and exit to CP/M
  306.     trap    #bdos
  307. *
  308. *  Read a string from memory and display it on the console
  309. *
  310. readmem:
  311.     move.b    (a5)+,d1    *Fetch character from memory
  312.     jsr    conout        *and send it to the console
  313.     subq    #1,d2
  314.     bne    readmem        *and keep looping until counter is zero
  315.     rts
  316. *#######################################################################
  317. *                     Console Messages
  318. *#######################################################################
  319. msgdel     dc.b    tab,'Delete...(y/n)? $'
  320. msgabt     dc.b    'Program aborted',cr,lf,'$'
  321. msgnom     dc.b    'No matching files on this disk',cr,lf,'$'
  322. msgal1     dc.b    'Use  $'
  323. msgal2    dc.b    '*.*  as file match? $'
  324. msgro     dc.b    'R/O$'
  325. msgsys     dc.b    'SYS$'
  326. *#######################################################################
  327. *                   Storage Area
  328. *#######################################################################
  329.     even
  330. bufadr  dc.l    buffer
  331. mydma   dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  332.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  333.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  334.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  335.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  336.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  337.     dc.b    0,0,0,0,0,0,0,0
  338. buffer  dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  339.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  340. *#######################################################################
  341.         end
  342.