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 / TURBODSG / DCHECK.MAC < prev    next >
Text File  |  2000-06-30  |  6KB  |  427 lines

  1. ; DCHECK v1.00 - DUPCHECK two better - by ESKAY
  2. ;
  3. cr    equ    0dh
  4. lf    equ    0ah
  5. ;
  6. .z80
  7. .request syslib
  8. ;
  9. start:    ld    sp,stack
  10.     call    print##
  11.     cr,lf,lf,lf
  12.     '              ------------------------------------------------',cr,lf
  13.     '             | DCHECK v1.00        22 Jun 85         by ESKAY |',cr,lf
  14.     '             | Disk Check Program displays missing and double |',cr,lf
  15.     '             | allocation  blocks  and  affected  file names. |',cr,lf
  16.     '              ------------------------------------------------'
  17.     cr,lf,lf,0
  18.     ld    a,(5ch)
  19.     or    a
  20.     jr    nz,havdrv
  21.     call    print##
  22.     'ERROR: no drive specified',cr,lf,7,0
  23.     rst    0
  24. ;
  25. havdrv:    ld    c,14        ; select the drive
  26.     ld    e,a
  27.     dec    e
  28.     call    bdos##
  29.     ld    c,19
  30.     call    50h        ; return alloc info
  31.     cp    0ffh
  32.     jr    nz,netok
  33.     call    print##
  34.     'Network error',7,cr,lf,0
  35.     rst    0
  36. ;
  37. netok:    ld    a,h
  38.     or    a
  39.     jr    nz,alocok
  40.     call    print##
  41.     'ERROR: cannot process small drives',cr,lf,7,0
  42.     rst    0
  43. ;
  44. alocok:    call    print##
  45.     'Loading allocation map...',cr,lf,0
  46.     call    codend##
  47.     ld    (bitmap),hl
  48.     push    hl
  49.     pop    ix
  50.     ld    bc,4000h
  51. ..zl:    ld    (hl),0
  52.     inc    hl
  53.     dec    bc
  54.     ld    a,b
  55.     or    c
  56.     jr    nz,..zl
  57.     ld    de,dirfcb
  58.     call    f$open##
  59. rlp:    call    f$read##
  60.     ld    iy,80h
  61. ..rl1:    ld    a,(iy+15)
  62.     cp    0ffh            ; dirlbl?
  63.     jr    z,..sklb        ;   yes
  64.     cp    0feh            ; bitmap?
  65.     jr    nz,endmap        ;   no, end of map
  66.     inc    iy
  67.     ld    ix,(bitmap)
  68.     ld    b,14            ; 14 bytes to move
  69.     call    movxy
  70.     inc    iy
  71.     ld    b,16
  72.     call    movxy
  73.     ld    a,(iy)
  74.     cp    0e5h
  75.     ld    (bitmap),ix
  76.     jr    z,..rl1
  77.     jr    rlp
  78. ;
  79. ..sklb:    ld    iy,0a0h
  80.     jr    ..rl1
  81. ;
  82.  
  83. movxy:    ld    a,(iy)
  84.     ld    (ix),a
  85.     inc    ix
  86.     inc    iy
  87.     djnz    movxy
  88.     ret
  89. ;
  90. ; bit map read into ram
  91. ;
  92. endmap:    push    ix
  93.     pop    hl
  94.     ld    l,0
  95.     inc    h
  96.     ld    (newmap),hl
  97.     ld    de,dirfcb
  98.     call    f$close##
  99.     call    print##
  100.     'Checking for unallocated blocks...',cr,lf,0
  101.     ld    a,'?'
  102.     ld    (dirfcb),a
  103.     call    codend##
  104.     ld    (bitmap),hl
  105.     ld    de,dirfcb
  106.     ld    c,17
  107.     call    bdos##
  108. loop:    ld    de,dirfcb
  109.     ld    c,18
  110.     call    bdos##
  111.     cp    0ffh
  112.     jp    z,done
  113.     ld    b,a
  114.     or    a
  115.     jr    nz,..ski
  116.     ld    hl,(testc)
  117.     inc    hl
  118.     ld    (testc),hl
  119. ..ski:    inc    b
  120.     ld    a,80h
  121.     ld    c,20h
  122. ..c:    dec    b
  123.     jr    z,..dn
  124.     add    a,c
  125.     jr    ..c
  126. ..dn:    ld    l,a
  127.     ld    h,0
  128.     ld    a,(hl)
  129.     cp    0e5h
  130.     jr    z,loop
  131.     push    hl
  132.     push    hl
  133.     pop    hl
  134.     ld    (fnptr),hl
  135.     pop    de
  136.     ld    b,8
  137.     ld    de,10h
  138.     add    hl,de
  139. ..ram:    ld    e,(hl)
  140.     inc    hl
  141.     ld    d,(hl)
  142.     inc    hl
  143.     ld    a,d
  144.     or    e
  145.     jr    nz,..ram1
  146.     djnz    ..ram
  147.     jr    ..ramq
  148. ;
  149. ..ram1:    ex    de,hl
  150.     push    de
  151.     push    bc
  152.     call    bitchk
  153.     pop    bc
  154.     pop    hl
  155.     djnz    ..ram
  156. ..ramq:    xor    a
  157.     ld    (noprev),a
  158.     ld    (double),a
  159.     jp    loop
  160. ;
  161. bitchk:    ld    (blocka),hl
  162.     call    bitclc
  163.     ld    b,a
  164.     inc    b
  165.     ld    a,1
  166. ..bitc:    dec    b
  167.     jr    z,..bitd
  168.     add    a,a
  169.     jr    ..bitc
  170. ;
  171. ..bitd:    ld    de,(newmap)
  172.     push    hl
  173.     add    hl,de
  174.     ld    b,a
  175.     ld    a,(hl)
  176.     and    b
  177.     call    nz,barfdb        ; double alloc
  178.     ld    a,b
  179.     or    (hl)
  180.     ld    (hl),a
  181.     pop    hl
  182.     ld    de,(bitmap)
  183.     add    hl,de
  184.     ld    a,(hl)
  185.     and    b
  186.     ret    nz
  187.     ld    a,1
  188.     ld    (noprev),a
  189.     push    de
  190.     push    hl
  191.     ld    hl,(blocka)
  192.     call    print##
  193.     cr,lf
  194.     'Unallocated block # ',0
  195.     call    phl4hc##
  196.     call    print##
  197.     ' in file ',0
  198.     ld    de,(fnptr)
  199.     ld    a,(de)
  200.     inc    de
  201.     call    pafdc##
  202.     ld    c,25
  203.     call    bdos##
  204.     add    a,'A'
  205.     call    cout##
  206.     ld    a,':'
  207.     call    cout##
  208.     call    pfn1##
  209.     pop    hl
  210.     pop    de
  211.     ret
  212. ;
  213. barfdb:    ld    a,1
  214.     ld    (double),a
  215.     push    de
  216.     push    hl
  217.     ld    de,(blocka)
  218.     ld    hl,(dptr)
  219.     ld    (hl),e
  220.     inc    hl
  221.     ld    (hl),d
  222.     inc    hl
  223.     ld    (dptr),hl
  224.     ld    hl,dnum
  225.     inc    (hl)
  226.     pop    hl
  227.     pop    de
  228.     ret
  229. ;
  230. done:    ld    a,(dnum)
  231.     or    a
  232.     jr    nz,dodbls
  233.     call    print##
  234.     cr,lf
  235.     'No duplicate blocks found.',cr,lf,lf,0
  236.     rst    0
  237. ;
  238. ; go through directory again (with sfirst/snext) and display
  239. ; names of all files and the allocation block address in
  240. ; question if it is a multiple.
  241. ;
  242. dodbls:    call    print##
  243.     cr,lf
  244.     'Checking for multiple allocation blocks...',cr,lf,0
  245.     ld    de,dirfcb
  246.     ld    c,17
  247.     call    bdos##        ; swallow dir label
  248. dodlp:    ld    de,dirfcb
  249.     ld    c,18
  250.     call    bdos##
  251.     cp    0ffh
  252.     jp    z,finish
  253.     ld    b,a
  254.     inc    b
  255.     ld    a,80h
  256.     ld    c,20h
  257. ..c1:    dec    b
  258.     jr    z,..dn1
  259.     add    a,c
  260.     jr    ..c1
  261. ;
  262. ..dn1:    ld    l,a
  263.     ld    h,0
  264.     ld    a,(hl)
  265.     cp    0e5h        ; erased?
  266.     jr    z,dodlp        ;   yes, do next
  267.     push    hl        ; save filename ptr
  268.     ld    de,16
  269.     add    hl,de        ; point to allocation blocks
  270.     ld    b,8        ; up to 8 to check
  271. alckl:    ld    e,(hl)
  272.     inc    hl
  273.     ld    d,(hl)
  274.     inc    hl
  275.     call    chkdup        ; check if it's a dupe
  276.     jr    c,isdp        ;   if it is, show filename
  277.     djnz    alckl
  278.     pop    hl
  279.     jr    dodlp
  280. ;
  281. isdp:    call    print##
  282.     cr,lf
  283.     'Multiple alloc : ',0
  284.     pop    de        ; get filename ptr
  285.     push    de
  286.     ld    a,(de)        ; get user area
  287.     cp    10
  288.     jr    nc,..nt10
  289.     ld    a,' '
  290.     call    cout##
  291. ..nt10:    ld    a,(de)
  292.     inc    de
  293.     call    pafdc##
  294.     ld    c,25
  295.     call    bdos##
  296.     add    a,'A'
  297.     call    cout##
  298.     ld    a,':'
  299.     call    cout##
  300.     call    pfn1##
  301.     call    print##
  302.     '  -  ',7,0
  303.     pop    hl
  304.     ld    de,16
  305.     add    hl,de
  306.     ld    b,8
  307. ..dall:    ld    e,(hl)
  308.     inc    hl
  309.     ld    d,(hl)
  310.     inc    hl
  311.     ld    a,d
  312.     or    e
  313.     jp    z,dodlp
  314.     ex    de,hl
  315.     call    phl4hc##
  316.     ex    de,hl
  317.     ld    a,' '
  318.     call    cout##
  319.     djnz    ..dall
  320.     jp    dodlp
  321. ;
  322. ; check for duplicate, preserve hl,de,bc
  323. ;
  324. chkdup:    push    hl
  325.     push    de
  326.     push    bc
  327.     ld    a,d
  328.     or    e
  329.     jr    z,chkdux
  330.     ld    hl,doubla    ; pointer to list
  331.     ld    a,(dnum)    ; length of list in words
  332.     ld    b,a        ; counter
  333. chkdu1:    ld    a,(hl)
  334.     inc    hl
  335.     cp    e
  336.     jr    z,chkdum
  337.     inc    hl
  338.     jr    chkdu2
  339. ;
  340. chkdum:    ld    a,(hl)
  341.     inc    hl
  342.     cp    d
  343.     jr    z,chkduf
  344. chkdu2:    djnz    chkdu1
  345.     xor    a
  346.     jr    chkdux
  347. ;
  348. chkduf:    scf
  349. chkdux:    pop    bc
  350.     pop    de
  351.     pop    hl
  352.     ret
  353. ;
  354. ; this routine is passed a bitmap address in HL.
  355. ; In HL, the relative byte address is returned, A has the bit number.
  356. ;
  357. bitclc:    ld    a,l
  358.     and    7
  359.     push    af
  360.     ld    a,l
  361.     and    0f8h
  362.     ld    l,a
  363.     pop    af
  364.     or    a
  365.     srl    h
  366.     rr    l
  367.     srl    h
  368.     rr    l
  369.     srl    h
  370.     rr    l
  371.     ret
  372. ;
  373. ; done after finding stuff
  374. ;
  375. finish:    call    print##
  376.     cr,lf,lf
  377.     '*** AFFECTED BLOCK ADDRESS(ES):',cr,lf,0
  378.     ld    a,(dnum)
  379.     ld    b,a
  380.     ld    hl,doubla
  381. finilp:    ld    e,(hl)
  382.     inc    hl
  383.     ld    d,(hl)
  384.     inc    hl
  385.     ex    de,hl
  386.     ld    a,b
  387.     and    7
  388.     call    z,crlf##
  389.     call    phl4hc##
  390.     ex    de,hl
  391.     call    print
  392.     '  ',0
  393.     djnz    finilp
  394.     call    print##
  395.     cr,lf,lf
  396.     'DCHECK completed - check all multiply allocated files,  then',cr,lf
  397.     'cause everyone to log off.  Delete bad files and IMMEDIATELY',cr,lf
  398.     'execute the FIXMAP command to prevent further damage.',cr,lf,lf,0
  399.     rst    0
  400. ;
  401. noprev:    db    0
  402. double:    db    0
  403. lps:    db    20
  404. testc:    dw    0
  405. newmap:    dw    0        ; new bitmap
  406. bitmap:    dw    0        ; bitmap base
  407. blocka:    dw    0        ; block to be tested
  408. dirfcb:    db    0,'$       DIR',0,0,0,0
  409.     ds    22
  410. ;
  411. ; storage for doubles:
  412. ;
  413. dnum:    db    0
  414. dptr:    dw    doubla
  415. doubla:    ds    200        ; enough!
  416. ;
  417. fnptr:    dw    0
  418. ;
  419.     ds    100
  420. stack    equ    $
  421.     end
  422.  bit number.
  423. ;
  424. bitclc:    ld    a,l
  425.     and    7
  426.     push    af
  427.