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

  1. *#######################################################################
  2. *         PROGRAM PRO...Protect 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 25, 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. current    equ    25        *Return Current Disk
  18. setdma    equ    26        *Set DMA Address
  19. protect    equ    30        *Set File Attributes
  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. *#######################################################################
  35. *
  36. *  Locate FCB (for portability)
  37. *
  38.     link    a6,#0        *Mark stack frame
  39.     move.l    8(a6),a0    *Get base page address
  40.     lea    $5c(a0),a6    *Get address of FCB and save it in a6
  41. *
  42. *  Clear data registers and determine drive specification
  43. *
  44.     jsr    clear
  45.     jsr    getdrv
  46. *
  47. *  Check for no file specified
  48. *
  49.     cmpi.b    #space,1(a6)    *Is 1st char in filespec a space?
  50.     bne    begin
  51.     jsr    proall        *If so, call proall
  52. *
  53. *  Begin search for file name matches
  54. *
  55. begin:
  56.     move.l    #mydma,d1    *===================
  57.     move.w    #setdma,d0    *Set the DMA Address
  58.     trap    #bdos        *===================
  59.     move.l    a6,d1        *Load the FCB
  60.     move.w    #sfirst,d0    *and search for the first match
  61.     trap    #bdos
  62.     cmpi.b    #$ff,d0        *Is there no match?
  63.     beq    quit        *No match if it's zero so quit
  64. *
  65. *  Search for file name matches
  66. *
  67. search:
  68.     mulu    #32,d0        *Adjust for DMA offset of matching entry
  69.     move.l    #mydma,a3    *Point to mydma
  70.     adda.w    d0,a3        *and add the offset
  71.     movea.l    #bufadr,a4    *Point to buffer
  72.     move.l    (a4),a5
  73.     move.w    #32,d1        *Initialize the counter
  74. copy35:
  75.     move.b    (a3)+,(a5)+    *Copy contents of a3 to a5
  76.     subq    #1,d1        *Decrement the counter
  77.     bne    copy35        *and keep looping until it's zero
  78.     move.l    a5,bufadr    *Save buffer address
  79.     addq    #1,d4        *Increment file match counter
  80.     move.l    a6,d1        *=========================
  81.     move.w    #snext,d0    *Search for next occurance
  82.     trap    #bdos        *=========================
  83.     cmpi.b    #$ff,d0        *Is there no match?
  84.     bne    search        *Keep searching until all are found
  85.     movea.l    #buffer,a5    *Point to the original buffer
  86.     move.l    a5,bufadr    *Save buffer address
  87. *
  88. *  Protect Files
  89. *
  90. profile:
  91.     jsr    drivepr        *Display drive identifier
  92.     move.w    #8,d2        *Initialize file name character counter
  93.     movea.l    a5,a4        *Save a5
  94.     adda.l    #1,a5        *Skip drive designation
  95.     jsr    readmem        *Read and display file name
  96.     move.b    #'.',d1        *Send a "." to the console
  97.     jsr    conout
  98.     move.w    #3,d2        *Initialize filetype character counter
  99.     jsr    readmem        *Read and display filetype
  100.     move.b    #space,d1    *Send a space to the console
  101.     jsr    conout
  102.     move.b    #space,d1    *and then send another
  103.     jsr    conout
  104.     movea.l    a4,a5        *Retrieve a5
  105.     adda.l    #9,a5        *and...
  106.     bset    #7,(a5)        *set the R/O bit
  107.     move.b    (a6),(a4)    *make sure we get the correct drive
  108.           move.w    a4,d1        *Load the FCB
  109.     move.w    #protect,d0    *Protect the file
  110.     trap    #bdos
  111.     move.l    #msgpro,d1    *Display the "is now..." query
  112.     jsr    pstring
  113. *
  114. *  Prepare for next file
  115. *
  116. nexfile:
  117.     subq    #1,d4        *Decrement file match counter
  118.     beq    quit        *If last file...quit
  119.     movea.l    #bufadr,a4    *Point to buffer
  120.     move.l    (a4),a5
  121.     adda.l    #32,a5        *Add 32 bytes to point to next match
  122.     move.l    a5,bufadr    *Save buffer address
  123.     jmp    profile        *Loop back for the next file
  124. *#######################################################################
  125. *                           Subroutines
  126. *#######################################################################
  127. *
  128. *  Clear data registers
  129. *
  130. clear:
  131.     clr.l    d1
  132.     clr.l    d2
  133.     clr.l    d3
  134.     clr.l    d4
  135.     rts
  136. *
  137. *  Send a character to the console
  138. *
  139. conout:
  140.     move.w    #outchar,d0
  141.     trap    #bdos
  142.     rts
  143. *
  144. *  Send a carriage return and a line feed to the console
  145. *
  146. crlf:
  147.     move.b    #cr,d1
  148.     jsr    conout
  149.     move.b    #lf,d1
  150.     jsr    conout
  151.     rts
  152. *
  153. *  Display drive identifier
  154. *
  155. drivepr:
  156.     move.b    d3,d1
  157.     jsr    conout
  158.     move.b    #':',d1
  159.     jsr    conout
  160.     rts
  161. *
  162. *  Determine drive number and make it ascii
  163. *
  164. getdrv:
  165.     move.b    (a6),d1        *Get drive number from FCB
  166.     cmpi.b    #0,d1        *Is it the default drive?
  167.     bne    ascii
  168.     jsr    logged        *If so, get physical drive number
  169. ascii:    addi.b    #64,d1        *Make it ascii
  170.     move.b    d1,d3        *and save it in d3
  171.     rts
  172. *
  173. *  Determine which is the logged drive
  174. *
  175. logged:
  176.     move.w    #current,d0    *Get current drive number
  177.     trap    #bdos
  178.     addq.b    #1,d0        *Increment for consistency with getdrv
  179.     move.w    d0,d1        *and save it in d1 for getdrv
  180.     rts
  181. *
  182. *  Display default delete-file message on the console
  183. *
  184. proall:
  185.     move.l    #msgal1,d1    *Display '*.*..." query
  186.     jsr    pstring
  187.     jsr    drivepr
  188.     move.l    #msgal2,d1
  189.     jsr    pstring
  190.     move.w    #inchar,d0    *Fetch keyboard response
  191.     trap    #bdos
  192.     move.b    d0,d2        *Save it
  193.     jsr    crlf        *Send a cr/lf to console
  194.     move.b    d2,d0        *Retrieve the response
  195.     andi.b    #upmask,d0    *Make it upper case
  196.     cmpi.b    #'Y',d0        *Test for "Y"
  197.     bne.b    abort        *If not...abort
  198.     movea.l    a6,a5        *Point to first character in file name
  199.     addq    #1,a5
  200.     move.w    #11,d2        *Initialize the counter
  201. loop1:
  202.     move.b    #'?',(a5)+    *Make compare file "????????.???"
  203.     subq    #1,d2
  204.     bne.b    loop1
  205.     move.w    #24,d2        *Reinitialize counter
  206. loop2:
  207.     move.b    #null,(a5)+    *Fill the rest of FCB with NULS
  208.     subq    #1,d2
  209.     bne.b    loop2
  210.     rts
  211. *
  212. *  Send a String to the Console
  213. *
  214. pstring:
  215.     move.w    #print,d0
  216.     trap    #bdos
  217.     rts
  218. *
  219. *  Quit to CP/M
  220. *
  221. quit:
  222.     cmpi.b    #ctrlc,d0    *Is it a ^C?
  223.     beq    abort        *If so...display abort message
  224.     cmpi.b    #$ff,d0        *Is it a FF hex?
  225.     beq    nomatch        *If so...display "no match..." message
  226.     move.b    #boot,d0    *Otherwise...exit to CP/M
  227.     trap    #bdos
  228. abort:
  229.     move.l    #msgabt,d1    *Display "Program aborted" message
  230.     jsr    pstring
  231.     move.b    #boot,d0    *and exit to CP/M
  232.     trap    #bdos
  233. nomatch:
  234.     move.l    #msgnom,d1    *Display "No match..." message
  235.     jsr    pstring
  236.     move.b    #boot,d0    *and exit to CP/M
  237.     trap    #bdos
  238. *
  239. *  Read a string from memory and display it on the console
  240. *
  241. readmem:
  242.     move.b    (a5)+,d1    *Fetch character from memory
  243.     jsr    conout        *and send it to the console
  244.     subq    #1,d2
  245.     bne    readmem        *and keep looping until counter is zero
  246.     rts
  247. *#######################################################################
  248. *                 Console Messages
  249. *#######################################################################
  250. msgpro     dc.b    tab,'is now Read Only (RO)',cr,lf,'$'
  251. msgabt     dc.b    'Program aborted',cr,lf,'$'
  252. msgnom     dc.b    'No matching files on this disk',cr,lf,'$'
  253. msgal1     dc.b    'Use  $'
  254. msgal2    dc.b    '*.*  as file match? $'
  255. *#######################################################################
  256. *                    Storage Area
  257. *#######################################################################
  258.     even
  259. bufadr  dc.l    buffer
  260. mydma   dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  261.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  262.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  263.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  264.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  265.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  266.     dc.b    0,0,0,0,0,0,0,0
  267. buffer  dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  268.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  269. *#######################################################################
  270.         end
  271.