home *** CD-ROM | disk | FTP | other *** search
/ The Don Maslin Archive / maslin_archive.zip / AARDVARK_Tape_Backups / maslin_c_d_3oct95 / ddrive / hold / msutils.lbr / undel.s < prev    next >
Text File  |  1992-05-18  |  9KB  |  397 lines

  1. *######################################################################
  2. *          PROGRAM UNDEL...Undelete File Utility
  3. *
  4. *                         Dr. David C. Wilcox
  5. *                         DCW Industries, Inc.
  6. *                5354 Palm Drive, La Canada, CA  91011
  7. *                            818/790-3844
  8. *
  9. *                          February 1, 1986
  10. *######################################################################
  11. boot    equ    0        *warm boot
  12. msgf    equ    9        *write console message
  13. rdcf    equ    10        *read console line
  14. verf    equ    12        *read CP/M version
  15. self    equ    14        *select disk
  16. clof    equ    16        *close file
  17. sfef    equ    17        *find first occurance
  18. sfnf    equ    18        *find next occurance
  19. makf    equ    22        *create file
  20. dmaf    equ    26        *set DMA
  21. dpbf    equ    31        *get dpb fwa
  22. rsdf    equ    37        *reset (log-out) disk drive
  23. lf    equ    10        *line feed
  24. cr    equ    13        *carriage return
  25. bdos    equ    $0002        *BDOS entry point
  26. *######################################################################
  27. *  Special registers:
  28. *
  29. *    a6 = address of DMA buffer
  30. *    d6 = directory-entry buffer index (dbndx)
  31. *    d7 = temporary count index (dbtmp)
  32. *######################################################################
  33. *
  34. *  Locate DMA (for portability)
  35. *
  36.     link    a6,#0        *mark stack frame
  37.     move.l    8(a6),a0    *get base page address
  38.     lea    $80(a0),a6    *get address of DMA and save it in a6
  39. *
  40. *  Clear data registers
  41. *
  42.     clr.l    d3
  43.     clr.l    d4
  44.     clr.l    d5
  45. *
  46. *  Set up local stack
  47. *
  48.     movea.l    #stack,a7
  49. *
  50. *  Get the filename
  51. *
  52.     movea.l    a6,a2        *load DMA address
  53.     suba.w    #$23,a2        *adjust to FCB+1
  54.     movea.l    #fcb+1,a1
  55.     move.w    #11,d2
  56.     jsr    mmc
  57. *
  58. *  Select disk
  59. *
  60.     movea.l    a6,a0        *load DMA address
  61.     suba.w    #$24,a0        *adjust to FCB
  62.     move.b    (a0),d0
  63.     or.b    d0,d0
  64.     beq    ref1        *if no selection
  65. *
  66.     subq    #1,d0
  67.     move.w    d0,d1
  68.     move.w    #self,d0
  69.     trap    #bdos
  70. *
  71. ref1:    move.l    #0,d6        *reset directory-entry buffer
  72. *
  73.     move.l    #cdpb,d1    *get extent mask
  74.     move.w    #dpbf,d0
  75.     trap    #bdos
  76.     movea.l    #cdpb+4,a2
  77.     move.b    (a2),d0
  78.     not.b    d0
  79.     move.b    d0,mfna
  80. *
  81.     move.l    a6,d1         *set dma
  82.     move.w    #dmaf,d0
  83.     trap    #bdos
  84. *
  85.     move.w    #sfef,d0    *find first occurance
  86.     move.l    #fcb,d1
  87.     trap    #bdos
  88.     cmpi.b    #$ff,d0
  89.     beq    ref5        *if file not found
  90. *
  91. ref2:    jsr    ffa        *set a2=fnt address
  92.     movea.l    a2,a5
  93.     movea.l    #fcb+1,a1
  94.     adda    #1,a2
  95.     move.l    #8,d2
  96.     jsr    kst        *compare strings
  97.     bne    ref3        *if not our filename
  98. *
  99. *    we have a directory entry with matching filename.
  100. *
  101.     movea.l    a5,a1
  102.     move.b    d6,d0         *get buffer index
  103.     addq.b    #1,d6        *advance buffer index
  104.     mulu    #32,d0        *set a2=next buffer location
  105.     movea.l    #mbuff,a2
  106.     adda.l    d0,a2
  107. *
  108.     exg    a1,a2        *save the directory entry
  109.     move.w    #32,d2
  110.     jsr    mmc
  111. *
  112. *    search for next occurence.
  113. *
  114. ref3:    movea.l    a5,a1
  115.     move.w    #sfnf,d0
  116.     trap    #bdos
  117.     cmpi.b    #$ff,d0
  118.     bne    ref2        *loop to end of directory
  119. *
  120. *    we have searched the entire directory.
  121. *
  122.     move.b    d6,d0        *check file found
  123.     or.b    d0,d0
  124.     beq    ref5        *if file not found
  125. *
  126. *    if file not erased, then don't restore it.
  127. *
  128.     jsr    cfe        *check file erased
  129.     bne    ref7        *if file not erased
  130. *
  131. *    if multiple erased files, issue a warning
  132. *
  133.     jsr    cme        *check multiple entries
  134.     bne    ref8        *if more than one file
  135. *
  136. *    restore the file
  137. *
  138.     jsr    rae        *restore all extents
  139. ref4:    move.w    #boot,d0    *warmboot
  140.     trap    #bdos
  141. *
  142. *    file not found.
  143. *
  144. ref5:    move.l    #refa,d1    *"file not found"
  145. ref6:    move.w    #msgf,d0
  146.     trap    #bdos
  147.     jmp    ref4
  148. *
  149. *    file not erased
  150. *
  151. ref7:    move.l    #refb,d1    *"file not erased"
  152.     jmp    ref6
  153. *
  154. *    multiple identical extent numbers found
  155. *
  156. ref8:    move.l    #refc,d1    *"multiple files found"
  157.     move.b    #msgf,d0
  158.     trap    #bdos
  159.     move.w    #rdcf,d0    *read response
  160.     move.l    #cbuff,d1
  161.     trap    #bdos
  162.     movea.l    #cbuff+2,a0
  163.     move.b    (a0),d0
  164.     andi.b    #$5f,d0
  165.     cmpi.b    #'Y',d0
  166.     bne    ref4        *if not "yes"
  167. *
  168. *    close each extent under a unique name.
  169. *
  170.     jsr    mfn        *modify all file names
  171.     jsr    rae        *restore all
  172.     jsr    dfn        *display new filenames
  173.     jmp    ref4
  174. *
  175. *    MFN - Modify all filenames.
  176. *    insert unique 2nd character into each filename
  177. *    set 3rd filename char to "A" for phy ext 0, "B" for 1,
  178. *    mark all extents 00.
  179. *
  180. mfn:    move.b    d6,d7
  181.     movea.l    #mbuff+2,a2    *2nd char
  182.     movea.l    #mbuff+$0c,a1    *ext
  183.     move.b    #'A',d0
  184. *
  185. mfn1:    move.b    d0,(a2)        *insert new 2nd char
  186.     addq.b    #1,d0
  187.     move.b    d0,chtmp
  188.     move.b    (a1),d0        *set 3rd char = "ext"
  189.     andi.b    #$ff,d0
  190. mfna    equ    *-1
  191.     addi.b    #'A',d0
  192.     adda    #1,a2
  193.     move.b    d0,(a2)
  194.     suba    #1,a2
  195.     eor.b    d0,d0        *set extent = 00
  196.     move.b    d0,(a1)
  197. *
  198.     adda    #32,a1
  199.     adda    #32,a2
  200. *
  201.     subq.b    #1,d7
  202.     movea.l    #chtmp,a0
  203.     move.b    (a0),d0
  204.     or.b    d7,d7
  205.     bne    mfn1        *loop over all extents
  206.     rts
  207. *
  208. *    RAE - Restore all extents
  209. *
  210. rae:    move.b    #0,fcb
  211.     move.b    d6,d0
  212.     move.b    d0,d5
  213.     movea.l    #mbuff+1,a2
  214. *
  215. rae1:    move.w    #15,d2
  216.     movea.l    #fcb+1,a1
  217.     jsr    mmc        *move filename
  218.     movea.l    a2,a4
  219.     move.l    #fcb,d1
  220.     move.w    #makf,d0    *create directory entry
  221.     trap    #bdos
  222.     movea.l    #fcb+$0e,a0     *clear "not-written" bit
  223.     move.b    (a0),d0
  224.     andi.b    #$7f,d0
  225.     move.b    d0,fcb+$0e
  226.     movea.l    a4,a2        *point to rbt image
  227.     suba    #1,a2        *get record count
  228.     move.b    (a2)+,d0
  229.     movea.l    #fcb+15,a1
  230.     move.b    d0,(a1)+
  231.     move.w    #16,d2
  232.     jsr    mmc
  233.     move.l    #fcb,d1        *close current extent
  234.     move.w    #clof,d0
  235.     trap    #bdos
  236.     move.w    d5,d1
  237.     adda    #1,a2
  238.     subq    #1,d5
  239.     bne    rae1        *loop over all extents
  240.     rts
  241. *
  242. *    DFN - Display new filenames.
  243. *
  244. dfn:    move.l    #dfna,d1    *"file names created"
  245.     move.w    #msgf,d0
  246.     trap    #bdos
  247.     move.w    d6,d0
  248.     movea.l    #mbuff+1,a2
  249. *
  250. dfn1:    movea.l    a2,a3
  251.     move.b    d0,d7
  252.     movea.l    #dfnb,a1    *move file name
  253.     move.w    #8,d2
  254.     jsr    mmc
  255.     addq    #1,(a1)        *move file type
  256.     move.w    #3,d2
  257.     jsr    mmc
  258.     move.l    #dfnb,d1
  259.     move.w    #msgf,d0
  260.     trap    #bdos
  261.     movea.l    a3,a2
  262.     adda    #32,a2
  263.     move.b    d7,d0
  264.     subq    #1,d0
  265.     bne    dfn1        *loop for all extents
  266.     rts
  267. *
  268. *    CME - Check multiple erased entries
  269. *    exit    z = true, if one file found
  270. *           d3 = file count
  271. *
  272. cme:    move.b    d6,d3
  273.     movea.l    #mbuff+$0c,a2    *point to ext bytes
  274. *
  275. cme1:    move.b    (a2),d0        *current extent number -> d0
  276.     jsr    cie        *count identical extents
  277.     beq    cme11
  278.     rts            *if multiple files found
  279. *
  280. cme11:    adda    #32,a2
  281.     subq    #1,d3
  282.     bne    cme1        *loop over all extents
  283.     rts
  284. *
  285. *    CIE - Count identical extents
  286. *    entry    d0 = current extent
  287. *    exit     z = true, if one such extent found
  288. *        d4 = extent count
  289. *
  290. cie:    movea.l    a2,a3
  291.     move.l    #0,d4
  292.     move.b    d6,d2
  293.     movea.l    #mbuff+$0c,a2
  294. *
  295. cie1:    move.b    (a2),d1
  296.     cmp.b    d0,d1
  297.     bne    cie2        *if not same extent
  298.     addq    #1,d4        *advance extent count
  299. *
  300. cie2:    adda    #32,a2
  301.     subq    #1,d2
  302.     bne    cie1        *loop over all extents
  303. *
  304.     move.b    d4,d0        *check extents found
  305.     movea.l    a3,a2
  306.     cmpi.b    #1,d0
  307.     rts
  308. *
  309. *    CFE - Check file erased
  310. *    exit    z = true, if file erased
  311. *
  312. cfe:    move.b    d6,d2
  313.     movea.l    #mbuff,a2
  314. *
  315. cfe1:    cmpi.b    #$e5,(a2)
  316.     beq    skip
  317.     rts            *if unerased extent found
  318. *
  319. skip:    adda    #32,a2
  320.     subq    #1,d2
  321.     bne    cfe1        *loop over all extents
  322.     rts
  323. *
  324. *    FFA - Form file address
  325. *    entry    d0 = FNT ordinal
  326. *    exit    a2 = FNT address
  327. *
  328. ffa:    or.b    d0,d0
  329.     mulu    #32,d0        * Multiply by 32
  330.     movea.l    a6,a2
  331.     adda    d0,a2
  332.     rts
  333. *
  334. *    KST - Compare strings
  335. *    entry    a2 = string 1 fwa
  336. *        a1 = string 2 fwa
  337. *        d2 = string compare length
  338. *    exit    z  = true, if string 1 equal string 2
  339. *
  340. kst:    cmpm.b    (a1)+,(a2)+    *First check filename
  341.     beq    kstnxt
  342.     rts            *if mismatch
  343. *
  344. kstnxt:    subq    #1,d2
  345.     bne    kst        *loop over compare length
  346.     move.w    #3,d2        *Now check the extension
  347. kst2:    move.b    (a2)+,d0
  348.     andi.b    #$7f,d0
  349.     cmp.b    (a1)+,d0
  350.     beq    kstnx2
  351.     rts            *if mismatch
  352. *
  353. kstnx2:    subq    #1,d2
  354.     bne    kst2        *loop over compare length
  355.     rts
  356. *
  357. *    MMC - Move memory
  358. *    entry    a2 = source fwa
  359. *        a1 = destination fwa
  360. *        d2 = byte count
  361. *
  362. mmc:    move.b    (a2)+,(a1)+
  363.     subq    #1,d2
  364.     bne    mmc        *loop for d2 bytes
  365.     rts
  366. *######################################################################
  367. *                         console messages
  368. *######################################################################
  369.     even
  370. refa:    dc.b    'File not found.$'
  371. refb:    dc.b    'File not erased.$'
  372. refc:    dc.b    'Multiple files found.'
  373.     dc.b    cr,lf,'Restore all? (Y/N):$'
  374. dfna:    dc.b    cr,lf,'File names created:',cr,lf,'$'
  375. dfnb:    dc.b    '     .   ',cr,lf,'$'
  376. *######################################################################
  377. *                          data space
  378. *######################################################################
  379.     even
  380. cdpb:    dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  381. chtmp:    dc.b    0                *temp for 2nd char
  382.     even
  383. fcb:    dc.b    '?'
  384.     dc.b    0,0,0,0,0,0,0,0
  385.     dc.b    0,0,0
  386. ext:    dc.b    0,0,0,0
  387.     dc.b    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  388. nr:    dc.b    0,0,0,0
  389. cbuff:    dc.b    64                *console input buffer
  390.     ds.b    64+2
  391.     ds.l    32
  392. stack    equ    *
  393.     even
  394. mbuff    equ    *+128
  395. *######################################################################
  396.     end
  397.