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 / DIRPAT3.MQC / DIRPAT3.MAC
Text File  |  2000-06-30  |  20KB  |  1,259 lines

  1. ; DIRPAT v3.40 Copyright S. Kluger - ESKAY SOFTWARE
  2. ; All Rights Reserved
  3. ;
  4. ; A TurboDOS directory dump/patch utility
  5. ;
  6. .z80
  7. .request timedif
  8. .request syslib            ;use SYSLIB3 to assemble/link
  9. ;
  10. cr    equ    0dh
  11. lf    equ    0ah
  12. dfcb    equ    5ch
  13. dbuf    equ    80h        ;default dma
  14. ;
  15. curdk    equ    25        ;return current disk
  16. rrand    equ    33        ;read random
  17. wrand    equ    34        ;write random
  18. fsize    equ    35        ;compute filesize
  19. gtime    equ    105        ;get time
  20. parse    equ    152        ;parse filename
  21. ;
  22. tdos    equ    50h        ;TD system call entry point
  23. stabo    equ    8        ;set abort address
  24. fxmap    equ    11        ;fix disk map
  25. vers    equ    12        ;version number
  26. flush    equ    26        ;flush disk buffers
  27. lockd    equ    25        ;lock drive function
  28. fxdir    equ    42        ;fix directory
  29. ;
  30. ; SYSLIB equates
  31. ;
  32.     extrn    f$open,f$close,scanner
  33.     extrn    print,cin,cout,phl4hc,eval16,eval10
  34.     extrn    bbline,crlf,bdos,phlfdc,comphd,pa2hc
  35.     extrn    fname,capin,pstr,condin,initfcb
  36. ;
  37.     cseg
  38. ;
  39. begin:    jr    ..strt
  40. ;
  41. cls:    db    1bh,'E',0,0,0,0        ; clear screen
  42. curpos:    db    1bh,'F',0,0,0,0        ; cursor pos
  43. xory:    db    0            ; 0=xy, nz=yx
  44. coffs:    db    32            ; cursor offset
  45. timeon:    db    0ffh            ; time on/off flag
  46. wyse:    db    0            ; delay flag
  47. ;
  48. ..strt:    ld    sp,stack
  49.     ld    c,stabo
  50.     ld    de,abort
  51.     call    tdos
  52.     ld    c,gtime            ; get time
  53.     ld    de,datim
  54.     call    bdos
  55.     call    atoh
  56.     ld    (sttime+6),hl
  57.     ld    a,(mmm)
  58.     call    atoh
  59.     ld    (sttime+3),hl
  60.     ld    a,(hhh)
  61.     call    atoh
  62.     ld    (sttime),hl
  63.     ld    a,(5ch)
  64.     ld    (dirfcb),a    ; set drive
  65.     or    a
  66.     jr    nz,.ncd.
  67.     ld    c,25
  68.     call    bdos
  69.     inc    a
  70. .ncd.:    add    a,40h
  71.     ld    (cdrv),a
  72.     ld    (cdrv1),a
  73. rstrt:    call    clrscr
  74.     call    print
  75.     db    9,9,'+------------------------------------+',cr,lf
  76.     db    9,9,'| DIRPAT ver 3.40 01/23/86 (c) ESKAY |',cr,lf
  77.     db    9,9,'|  TurboDOS directory patch utility  |',cr,lf
  78.     db    9,9,'+------------------------------------+',cr,lf,lf,0
  79.     xor    a
  80.     ld    (frsttm),a
  81.     ld    (wrtn),a
  82.     ld    (hash),a
  83.     ld    (force),a
  84.     ld    (dfcb),a
  85.     ld    l,a
  86.     ld    h,a
  87.     ld    (curs),hl
  88.     ld    c,vers
  89.     call    tdos        ;get version number
  90.     ld    a,c
  91.     cp    13h
  92.     call    z,unrel
  93.     bit    7,b
  94.     jp    z,noprv        ;not privileged
  95.     call    print
  96.     db    'Do you wish to lock drive '
  97. cdrv:    db    'A: (Y/N) ? [ ]',8,8,0
  98.     ld    a,1
  99.     call    bbline
  100.     call    crlf
  101.     ld    a,(hl)
  102.     cp    'Y'
  103.     ld    a,0
  104.     jr    nz,nolock
  105.     ld    c,curdk
  106.     call    bdos
  107.     ld    e,a
  108.     ld    (curd),a
  109.     ld    d,-1
  110.     ld    c,lockd
  111.     call    tdos        ;lock this drive
  112.     or    a
  113.     jp    nz,busy
  114.     ld    a,0ffh
  115. nolock:    ld    (locked),a
  116.     ld    de,dirfcb    ;open directory file
  117.     call    f$open
  118.     or    a
  119.     jp    nz,direrr
  120.     ld    c,fsize
  121.     call    bdos
  122.     ld    hl,(rec)
  123.     ld    (tots),hl
  124.     call    fillbf
  125.     ld    a,(dbuf+12)
  126.     ld    (hash),a
  127.     ld    bc,12*256+18
  128.     call    gotoxy
  129.     call    print
  130.     'Press RETURN to display directory and begin',0
  131. ;
  132. ; This is the main command loop
  133. ;
  134. cloop:    ld    hl,(curs)    ;get current sector
  135.     ld    (rec),hl    ;stash it away
  136.     ld    a,(frsttm)
  137.     or    a
  138.     ld    a,1
  139.     ld    (frsttm),a
  140.     ld    (dcall),a
  141.     call    nz,dsply
  142.     xor    a
  143.     ld    (dcall),a
  144.     ld    bc,16*256+20
  145.     call    gotoxy
  146.     call    print
  147.     db    'Command (or ? for help) [ ]',8,8,0
  148. .gtcc.:    ld    bc,16*256+45
  149.     call    gotoxy
  150.     call    condin            ; see if input
  151.     jr    nz,.gotc.        ; yes, process it
  152.     call    putt
  153.     jr    .gtcc.
  154. ;
  155. .gotc.:    cp    'a'
  156.     jr    c,.nlcs.
  157.     and    5fh
  158. .nlcs.:    call    cout
  159.     ld    hl,fcntbl
  160.     ld    b,nmbfcn
  161. .slfcn:    cp    (hl)
  162.     inc    hl
  163.     jr    z,.gofcn
  164.     inc    hl
  165.     inc    hl
  166.     djnz    .slfcn
  167.     cp    cr
  168.     ld    a,7
  169.     call    nz,cout
  170.     jp    cloop
  171. ;
  172. .gofcn:    ld    a,(hl)
  173.     inc    hl
  174.     ld    h,(hl)
  175.     ld    l,a
  176.     jp    (hl)
  177. ;
  178. fcntbl:    db    '>'
  179.     dw    nxtact
  180.     db    '!'
  181.     dw    home
  182.     db    '?'
  183.     dw    help
  184.     db    'Q'
  185.     dw    quit
  186.     db    '+'
  187.     dw    advanc
  188.     db    '='
  189.     dw    advanc
  190.     db    '-'
  191.     dw    decrem
  192.     db    'A'
  193.     dw    again
  194.     db    'D'
  195.     dw    drives
  196.     db    'R'
  197.     dw    fillb
  198.     db    'W'
  199.     dw    purgbf
  200.     db    'G'
  201.     dw    goto
  202.     db    'H'
  203.     dw    dohash
  204.     db    'F'
  205.     dw    find
  206.     db    'L'
  207.     dw    fasc
  208.     db    'E'
  209.     dw    erasef
  210.     db    'U'
  211.     dw    unera
  212.     db    'S'
  213.     dw    edit
  214.     db    'X'
  215.     dw    hextgl
  216. nmbfcn    equ    ($-fcntbl)/3
  217. ;
  218. find:    ld    bc,16*256+20
  219.     call    gotoxy
  220.     call    print
  221.     db    '   Enter hex to be found, RET to stop',cr,lf,0
  222.     ld    de,tmpbf
  223.     ld    b,0
  224. fhl:    call    print
  225.     db    cr,lf,'Hex : ',0
  226.     ld    a,1
  227.     call    bbline
  228.     or    a
  229.     jr    z,fhd
  230.     push    de
  231.     call    eval16
  232.     ld    a,e
  233.     pop    de
  234.     ld    (de),a
  235.     inc    de
  236.     inc    b
  237.     jr    fhl
  238. ;
  239. fhd:    ld    a,b
  240.     or    a
  241.     jp    z,cloop
  242.     ld    (vecl),a
  243.     ld    hl,tmpbf
  244.     ld    (vect),hl
  245.     jr    fntry
  246. ;
  247. fasc:    ld    bc,16*256+20
  248.     call    gotoxy
  249.     call    print
  250.     db    '     Enter filename to be found : ',0
  251.     ld    a,1
  252.     call    bbline
  253.     or    a
  254.     jp    z,cloop
  255.     cp    16
  256.     jr    nc,fasc
  257.     ld    de,dfcb        ; parse filename
  258.     call    fname
  259.     jr    z,fasc
  260.     ld    a,c        ; get user number flag
  261.     cp    0ffh        
  262.     ld    a,'?'        ; preload false
  263.     jr    z,..fau.    ; skip if no user number
  264.     ld    a,c        ; else get user #
  265. ..fau.:    ld    (de),a        ; and store in fcb
  266.     ld    hl,previ
  267.     push    de
  268.     ld    bc,12
  269.     ex    de,hl
  270.     ldir
  271.     pop    de
  272. ..fa:    ld    (vect),de
  273.     ld    a,12        ; file name is 12 chars
  274.     ld    (vecl),a
  275.     ld    hl,(curs)
  276.     ld    (temp),hl
  277.     xor    a
  278. fntry:    ld    (ascis),a
  279. floop:    call    fillbf
  280. nofas:    ld    a,(vecl)
  281.     ld    c,a
  282.     ld    hl,dbuf
  283.     ld    de,(vect)
  284.     ld    b,127
  285.     call    scan
  286.     jr    z,found
  287.     ld    hl,(curs)    ;get current sector
  288.     inc    hl        ;advance to next
  289.     ld    de,(tots)    ;get total sectors
  290.     call    comphd        ;check if we're at the end
  291.     jr    z,notfd        ;not found.
  292.     ld    (curs),hl
  293.     jr    floop
  294. ;
  295. found:    ld    a,l
  296.     and    7fh
  297.     ld    (fbyt),a
  298.     ld    a,1
  299.     ld    (loctd),a
  300.     ld    hl,(curs)
  301.     jp    fillb
  302. ;
  303. notfd:    call    print
  304.     db    cr,lf,lf
  305.     db    9,9,'*** end of file ***',cr,lf,7,0
  306.     call    delay
  307.     ld    hl,(temp)
  308.     ld    (curs),hl
  309.     call    fillbf
  310.     jp    cloop
  311. ;
  312. scan:    ld    a,(ascis)
  313.     or    a
  314.     jp    nz,scanner
  315.     ld    hl,dbuf
  316. ..sl1:    res    7,(hl)
  317.     inc    l
  318.     jr    nz,..sl1
  319.     ld    hl,dbuf
  320.     ld    de,20h
  321.     ld    bc,5ch
  322. ..sm1:    push    hl
  323.     push    bc
  324. ..sm2:    ld    a,(bc)
  325.     cp    '?'
  326.     jr    z,..smw
  327.     cp    (hl)
  328.     jr    nz,..smn
  329. ..smw:    inc    hl
  330.     inc    bc
  331.     ld    a,68h
  332.     cp    c
  333.     jr    nz,..sm2
  334.     pop    bc
  335.     pop    hl
  336.     ret
  337. ;
  338. ..smn:    pop    bc
  339.     pop    hl
  340.     add    hl,de
  341.     ld    a,l
  342.     or    a
  343.     jr    nz,..sm1
  344.     inc    a
  345.     ret
  346. ;
  347. home:    ld    de,0
  348.     jp    secok
  349. ;
  350. hextgl:    ld    a,(hexfl)
  351.     cpl
  352.     ld    (hexfl),a
  353.     jp    cloop
  354. ;
  355. ; go to specified sector
  356. ;
  357. goto:    ld    bc,23*256+0
  358.     call    gotoxy
  359.     call    print
  360.     db    'Enter sector number to jump to (in decimal) : ',0
  361.     call    bbline
  362.     or    a
  363.     jp    z,cloop
  364.     ld    bc,20*256+0
  365.     call    cleol
  366.     ld    bc,23*256+0
  367.     call    cleol
  368.     call    eval10
  369.     ld    hl,(tots)
  370.     dec    hl
  371.     call    comphd
  372.     jr    nc,secok
  373.     ld    bc,20*256+27
  374.     call    gotoxy
  375.     call    print
  376.     db    'Sector number out of range',7,0
  377.     jr    goto
  378. ;
  379. secok:    dec    de
  380.     ld    (curs),de
  381.     jp    advanc
  382. ;
  383. ; display current sector
  384. ;
  385. dsply:    ld    a,1
  386.     ld    (dison),a
  387.     call    clrscr
  388.     call    print
  389.     9,'Sec [',0
  390.     ld    hl,(curs)
  391.     call    prthl
  392.     call    print
  393.     ']     Hash=O',0
  394.     ld    a,(hash)
  395.     or    a
  396.     jr    nz,..hs.
  397.     call    print
  398.     'FF',0
  399.     jr    ..hx.
  400. ;
  401. ..hs.:    call    print
  402.     'N',0
  403. ..hx.:    call    print
  404.     '     Size ',0
  405.     ld    hl,(tots)
  406.     call    prthl
  407.     call    print
  408.     ' sectors    ',0
  409.     ld    a,(wrtn)
  410.     or    a
  411.     ld    a,' '
  412.     jr    z,..nwr.
  413.     ld    a,'W'
  414. ..nwr.:    call    cout
  415.     ld    a,(locked)
  416.     or    a
  417.     ld    a,' '
  418.     jr    z,..nlk.
  419.     ld    a,'L'
  420. ..nlk.:    call    cout
  421.     call    print
  422.     db    ' '
  423. cdrv1:    db    'A:',0
  424.     ld    hl,loctd
  425.     ld    a,(hl)
  426.     ld    (hl),0
  427.     or    a
  428.     jr    z,..nlcd
  429.     call    print
  430.     '    Found: byte ',0
  431.     ld    a,(fbyt)
  432.     call    pa2hc
  433.     push    af
  434.     and    0fh
  435.     ld    b,a
  436.     pop    af
  437.     and    0f0h
  438.     rra
  439.     rra
  440.     rra
  441.     rra
  442.     add    a,3
  443.     ld    h,a
  444.     ld    c,3
  445.     ld    a,-3
  446. .clh..:    add    a,c
  447.     dec    b
  448.     jp    p,.clh..
  449.     add    a,6
  450.     ld    l,a
  451.     ld    (editpt),hl
  452.     ld    a,1
  453.     ld    (dcall),a
  454.     call    ..nlcd
  455.     xor    a
  456.     ld    (dcall),a
  457.     jp    edlp
  458.  
  459. ;
  460. ..nlcd:    ld    hl,dbuf        ;hl=buffer pointer
  461.     call    print
  462.     db    cr,lf
  463.     db    'ADDR  00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F'
  464.     db    '  0123456789ABCDEF',cr,lf,0
  465. lp10:    call    crlf
  466.     push    hl
  467.     res    7,l        ;reset bit for display
  468.     call    phl4hc        ;print address
  469.     pop    hl
  470.     call    spc
  471.     call    spc
  472.     push    hl        ;save for ascii display
  473. lpln:    ld    a,(hl)
  474.     call    pa2hc
  475.     call    spc
  476.     inc    l
  477.     ld    a,l
  478.     and    0fh        ;done this line?
  479.     jr    nz,lpln
  480.     call    spc
  481.     pop    hl        ;back for ascii
  482. asclp:    ld    a,(hl)
  483.     and    7fh
  484.     cp    7fh
  485.     jr    z,noprc
  486.     cp    ' '
  487.     jr    nc,prasc
  488. noprc:    ld    a,'.'
  489. prasc:    call    cout
  490.     inc    l
  491.     jr    z,ddone
  492.     ld    a,l
  493.     and    0fh
  494.     jr    z,lp10
  495.     jr    asclp
  496. ;    
  497. spc:    ld    a,' '
  498.     jp    cout
  499. ;
  500. ddone:    call    crlf
  501.     ld    a,(dcall)
  502.     or    a
  503.     ret    nz
  504.     jp    cloop
  505. ;
  506. decrem:    ld    hl,(curs)    ;get current sector
  507.     ld    a,h
  508.     or    l
  509.     dec    hl
  510.     jr    nz,nonda    ;skip if not at start
  511.     ld    hl,(tots)    ;get total sectors
  512.     dec    hl        ;minus 1 (0..end)
  513.     jr    nonda
  514. ;
  515. advanc:    ld    hl,(curs)    ;get current sector
  516.     inc    hl        ;advance to next
  517.     ld    de,(tots)    ;get total sectors
  518.     call    comphd        ;check if we're at the end
  519.     jr    nz,nonda    ;skip if not at end
  520. .wrp..:    ld    hl,0        ;go to start (wrap around)
  521. nonda:    ld    (curs),hl    ;save new sector
  522. fillb:    call    fillbf
  523.     jp    cloop
  524. ;
  525. ; got to next active dir sector
  526. ;
  527. nxtact:    ld    hl,(curs)
  528.     inc    hl
  529.     ld    de,(tots)
  530.     call    comphd
  531.     jr    z,.wrp..
  532.     ld    (curs),hl
  533.     call    fillbf        ;get buffer
  534.     ld    hl,80h
  535.     ld    de,20h
  536.     ld    b,4
  537. ..nx..:    ld    a,(hl)
  538.     cp    0e5h
  539.     jr    nz,fillb
  540.     add    hl,de
  541.     djnz    ..nx..
  542.     jr    nxtact
  543. ;
  544. fillbf:    ld    hl,(curs)
  545.     ld    (rec),hl
  546.     ld    c,rrand
  547. rdwr:    ld    de,dirfcb
  548.     call    bdos
  549.     or    a
  550.     ret    z
  551.     call    print
  552.     db    cr,lf,lf,7
  553.     db    'Read/write error code ',0
  554.     call    pa2hc
  555.     call    print
  556.     db    '.',cr,lf,'Ignoring error.',cr,lf,0
  557.     jp    delay
  558. ;
  559. purgbf:    ld    a,(locked)
  560.     or    a
  561.     jr    nz,purg1
  562.     ld    bc,23*256+10
  563.     call    gotoxy
  564.     call    print
  565.     db    7,'WARNING - DRIVE NOT LOCKED - PROCEED (Y/N) ? ',0
  566.     ld    a,1
  567.     call    bbline
  568.     ld    bc,23*256+0
  569.     call    cleol
  570.     ld    a,(hl)
  571.     cp    'Y'
  572.     jr    z,purg1
  573.     jp    cloop
  574. ;
  575. purg1:    ld    hl,(curs)
  576.     ld    (rec),hl
  577.     ld    c,wrand
  578.     call    rdwr
  579.     ld    a,1
  580.     ld    (wrtn),a
  581.     jp    cloop
  582. ;
  583. dohash:    ld    hl,0
  584.     ld    (curs),hl
  585.     call    fillbf
  586.     ld    bc,23*256+10
  587.     call    gotoxy
  588.     call    print
  589.     db    'Hash directory after exiting (Y=YES) ? ',0
  590.     ld    a,1
  591.     ld    (force),a
  592.     call    bbline
  593.     ld    bc,23*256+0
  594.     call    cleol
  595.     ld    a,(hl)
  596.     cp    'Y'
  597.     ld    a,80h
  598.     jr    z,yhash
  599.     xor    a
  600. yhash:    ld    (dbuf+0ch),a
  601.     ld    (hash),a
  602.     jp    purgbf
  603. ;
  604. ; delete all directory entries of a file
  605. ; (unless already deleted)
  606. ; report count
  607. ;
  608. erasef:    call    print
  609.     db    cr,lf,lf
  610.     db    'Enter filename (no user # = all entries,',cr,lf
  611.     db    'else only entries in that user) RET=quit : ',0
  612.     ld    a,0e5h
  613.     ld    (eracmd),a
  614.     ld    a,1
  615.     call    bbline
  616.     or    a
  617.     jp    z,cloop
  618.     ld    (pfcb),hl        ;save hl
  619.     ld    hl,sfcb
  620.     ld    (pfcb+2),hl
  621.     ld    c,parse
  622.     ld    de,pfcb
  623.     call    bdos
  624.     ld    a,(sfcb+15)
  625.     or    a
  626.     jr    z,nofu
  627.     ld    a,(sfcb+13)
  628.     inc    a
  629. nofu:    dec    a
  630.     ld    (sfcb),a
  631.     inc    a
  632.     jp    nz,noall
  633.     call    print
  634.     db    cr,lf
  635.     db    'WARNING - you are about to delete ALL those',cr,lf
  636.     db    'directory entries. Say "NO" to change your mind : ',0
  637.     ld    a,1
  638.     call    bbline
  639.     ld    a,(hl)
  640.     cp    'N'
  641.     jp    z,cloop
  642. noall:    ld    hl,0
  643.     ld    (curs),hl        ;set current sector to 0
  644. erasl:    call    fillbf            ;get buffer
  645.     ld    ix,dbuf            ;ix=pointer to buffer
  646.     ld    de,32            ;de=increment count
  647.     ld    c,4            ;c=field counter
  648.     xor    a
  649.     ld    (noche),a        ;set no change erase flag
  650. erasl1:    ld    hl,sfcb            ;hl=fcb ptr
  651.     ld    b,12            ;b=byte counter
  652.     push    ix            ;move ix...
  653.     pop    iy            ;...to iy
  654.     ld    a,(hl)
  655.     inc    a
  656.     jr    nz,erasl2
  657.     inc    ix
  658.     inc    hl
  659.     dec    b
  660. erasl2:    ld    a,'?'
  661.     cp    (hl)
  662.     jr    z,..qmk
  663.     ld    a,(ix+0)
  664.     and    7fh
  665.     cp    (hl)
  666.     jr    nz,eranxt
  667. ..qmk:    inc    ix
  668.     inc    hl
  669.     djnz    erasl2
  670.     ld    a,(eracmd)        ; get erase/unerase byte
  671.     ld    (iy+0),a
  672.     ld    a,0ffh
  673.     ld    (noche),a
  674. eranxt:    dec    c
  675.     jr    z,eradun
  676.     push    iy
  677.     pop    ix
  678.     add    ix,de
  679.     jr    erasl1
  680. ;
  681. eradun:    ld    hl,(curs)
  682.     ld    (rec),hl
  683.     ld    c,wrand
  684.     ld    a,(noche)
  685.     or    a
  686.     jr    z,nowrt
  687.     ld    (dcall),a
  688.     call    dsply
  689.     ld    a,(eracmd)
  690.     cp    0e5h
  691.     jr    z,..due
  692.     call    print
  693.     cr,lf
  694.     'UN-DELETE FILE(S) above? ',0
  695.     ld    a,1
  696.     call    bbline
  697.     or    a
  698.     jr    z,nowrt
  699.     ld    a,(hl)
  700.     cp    'Y'
  701.     jr    nz,nowrt
  702. ..due:    xor    a
  703.     ld    (dcall),a
  704.     call    rdwr
  705. nowrt:    ld    a,1
  706.     ld    (wrtn),a
  707.     ld    hl,(curs)    ;get current sector
  708.     inc    hl        ;advance to next
  709.     ld    (curs),hl
  710.     ld    de,(tots)    ;get total sectors
  711.     call    comphd        ;check if we're at the end
  712.     jp    z,cloop
  713.     jp    erasl
  714. ;
  715. unera:    ld    c,32
  716.     ld    e,0ffh
  717.     call    bdos
  718.     ld    (eracmd),a    ; current user #
  719.     ld    a,(locked)
  720.     or    a
  721.     jr    nz,..unel
  722.     call    print
  723.     cr,lf,lf,7
  724.     'WARNING: drive is not locked - proceed anyway? ',0
  725.     ld    a,1
  726.     call    bbline
  727.     or    a
  728.     jp    z,cloop
  729.     ld    a,(hl)
  730.     cp    'Y'
  731.     jp    nz,cloop
  732. ..unel:    call    print
  733.     cr,lf,lf
  734.     'File will be undeleted to current user area. NOTE that multiple',cr,lf
  735.     'occurrences of the same filename can ALSO be unerased causing',cr,lf
  736.     'garbled information.',cr,lf
  737.     'Enter name of file to be undeleted (RET=quit) : ',0
  738.     ld    a,1
  739.     call    bbline
  740.     or    a
  741.     jp    z,cloop
  742.     ld    (pfcb),hl
  743.     ld    hl,sfcb
  744.     ld    (pfcb+2),hl
  745.     ld    c,parse
  746.     ld    de,pfcb
  747.     call    bdos
  748.     ld    hl,sfcb
  749.     ld    (hl),65h        ; E5 and 7F
  750.     inc    hl
  751.     ld    a,'?'
  752.     ld    b,11
  753. ..xxx:    cp    (hl)
  754.     jp    nz,noall
  755.     inc    hl
  756.     djnz    ..xxx
  757.     call    print
  758.     cr,lf,7
  759.     'ERROR: cannot undelete *.*!',cr,lf,0
  760.     call    delay
  761.     jp    cloop
  762. ;
  763. help:    call    clrscr
  764.     call    print
  765.     db    cr,lf
  766.     db    'DIRPAT COMMANDS (single commands only, no stacking) :'
  767.     db    cr,lf,lf
  768.     db    '!  =  HOME (go to sector 0)',cr,lf
  769.     db    '?  =  this message',cr,lf
  770.     db    'D  =  change logged drive',cr,lf
  771.     db    'E  =  delete (Erase) all entries of one file',cr,lf
  772.     db    'F  =  find hex data in directory',cr,lf
  773.     db    'G  =  goto record (prompting for decimal number)',cr,lf
  774.     db    'H  =  set hashed status (effective after exit)',cr,lf
  775.     db    'L  =  locate a file name',cr,lf
  776.     db    'Q  =  quit to TurboDOS',cr,lf
  777.     db    'R  =  re-read current record and display',cr,lf
  778.     db    'S  =  substitute onscreen (hex/ASCII edit)',cr,lf
  779.     db    'U  =  UNDELETE a deleted file',cr,lf
  780.     db    'W  =  write current record',cr,lf
  781.     db    'X  =  toggle hex/decimal sector DISPLAY',cr,lf
  782.     db    '+  =  advance pointer to next record and display',cr,lf
  783.     db    '-  =  move pointer to previous record and display',cr,lf,lf
  784.     db    'Use this program with extreme caution!',cr,lf,lf
  785.     db    '----> press any key to continue <----',0
  786.     call    cin
  787.     call    clrscr
  788.     jp    cloop
  789. ;
  790. prthl:    ld    a,(hexfl)
  791.     or    a
  792.     jp    z,phl4hc
  793.     jp    phlfdc
  794. ;
  795. busy:    call    print
  796.     db    cr,lf,lf,7
  797.     db    'ERROR - cannot lock drive. Cause all other users to',cr,lf
  798.     db    'log off and try again',cr,lf,0
  799.     rst    0
  800. ;
  801. direrr:    call    print
  802.     db    cr,lf,lf,lf
  803.     db    'FATAL ERROR - $.DIR NOT FOUND.',cr,lf
  804.     db    'Are you not running under TurboDOS?',cr,lf,lf,0
  805. quit:    ld    de,dirfcb
  806.     call    f$close
  807.     ld    a,(wrtn)
  808.     or    a
  809.     jr    nz,fixit
  810.     jp    noth
  811. ;
  812. fixit:    ld    a,(locked)
  813.     or    a
  814.     jr    nz,fixok
  815.     call    print
  816.     db    cr,lf,lf
  817.     db    9,'WARNING - UNABLE TO FIX UNLOCKED DRIVE',cr,lf
  818.     db    9,'YOU MUST RUN FIXMAP AND FIXDIR MANUALLY',7,cr,lf,lf,0
  819.     jp    noth
  820. ;
  821. fixok:    call    print
  822.     db    cr,lf
  823.     db    'Now rebuilding disk map - stand by',0
  824.     ld    a,(curd)    ;get current disk
  825.     ld    e,a
  826.     ld    c,fxmap
  827.     call    tdos
  828.     or    a
  829.     jp    nz,nofm        ;error...
  830.     ld    a,(force)
  831.     or    a
  832.     jr    nz,forcef
  833.     ld    a,(hash)
  834.     or    a
  835.     jr    z,noth
  836. forcef:    call    print
  837.     db    cr,lf
  838.     db    'Now reorganizing directory - DO NOT ABORT',cr,lf,lf,0
  839.     ld    a,(curd)
  840.     ld    e,a
  841.     ld    c,fxdir
  842.     call    tdos
  843.     or    a
  844.     jp    nz,nofd
  845. noth:    call    print
  846.     db    cr,lf,lf
  847.     9,9,'   Time spent in DIRPAT: ',0
  848.     ld    c,gtime
  849.     ld    de,datim
  850.     call    bdos
  851.     call    atoh
  852.     ld    (entime+6),hl
  853.     ld    a,(mmm)
  854.     call    atoh
  855.     ld    (entime+3),hl
  856.     ld    a,(hhh)
  857.     call    atoh
  858.     ld    (entime),hl
  859.     call    timdif##
  860.     ld    hl,elaptm
  861.     call    pstr
  862.     call    print
  863.     cr,lf,lf
  864.     9,'     Thanks for using DIRPAT, an ESKAY product',cr,lf,lf,0
  865.     ld    c,lockd        ;unlock drive
  866.     ld    d,0
  867.     ld    a,(curd)
  868.     ld    e,a
  869.     call    tdos
  870.     ld    c,flush        ;flush buffers
  871.     ld    a,(curd)
  872.     ld    e,a
  873.     ld    d,80h
  874.     call    tdos
  875.     rst    0
  876. ;
  877. nofd:    call    print
  878.     db    cr,lf,lf,7
  879.     db    'ERROR - cannot reorganize directory, aborting',cr,lf,0
  880.     rst    0
  881. ;
  882. nofm:    call    print
  883.     db    cr,lf,lf,7
  884.     db    'ERROR - cannot fix disk map, aborting.',cr,lf,0
  885.     rst    0
  886. ;
  887. noprv:    call    print
  888.     db    cr,lf,lf,7
  889.     db    'Not authorized to use DIRPAT',cr,lf,0
  890.     rst    0
  891. ;
  892. unrel:    push    psw
  893.     call    print
  894.     db    cr,lf,7
  895.     db    'NOTE: Operation under TurboDOS 1.3 has not been fully',cr,lf
  896.     db    'tested. Directory size is reported as 0 and system may',cr,lf
  897.     db    'crash on exit. Proceed at your own risk.',cr,lf,lf,0
  898.     pop    psw
  899. abort:    ret
  900. ;
  901. delay:    push    bc
  902.     ld    a,10
  903.     ld    bc,0
  904. ....d.:    dec    c
  905.     push    hl
  906.     pop    hl
  907.     jr    nz,....d.
  908.     djnz    ....d.
  909.     dec    a
  910.     jr    nz,....d.
  911.     pop    bc
  912.     ret
  913. ;
  914. delay1:    ld    a,(wyse)
  915.     or    a
  916.     ret    z
  917.     push    bc
  918.     ld    bc,1000
  919. ...d1.:    dec    c
  920.     jr    nz,...d1.
  921.     djnz    ...d1.
  922.     pop    bc
  923.     ret
  924. ;
  925. ; a to h
  926. ;
  927. atoh:    push    af
  928.     ld    hl,3030h
  929.     and    0fh
  930.     or    h
  931.     ld    h,a
  932.     pop    af
  933.     and    0f0h
  934.     rra
  935.     rra
  936.     rra
  937.     rra
  938.     or    l
  939.     ld    l,a
  940.     ret
  941. ;
  942. ahlo:    call    atoh
  943.     ld    a,l
  944.     call    cout
  945.     ld    a,h
  946.     jp    cout
  947. ;
  948. ; edit command
  949. ;
  950. edit:    ld    a,(dison)
  951.     dec    a
  952.     jr    z,.eact.
  953.     ld    a,7
  954.     call    cout
  955.     jp    cloop
  956. ;
  957. .eact.:    ld    bc,3*256+6        ; beginning of field
  958.     ld    (editpt),bc
  959. edlp:    ld    bc,(editpt)
  960.     call    gotoxy
  961.     xor    a
  962.     ld    (frsttm),a
  963.     call    condin
  964.     jr    nz,.char.
  965.     call    putt
  966.     jr    edlp
  967. ;
  968. .char.:    cp    'a'
  969.     jr    c,..nl..
  970.     and    5fh
  971. ..nl..:    cp    3            ; exit
  972.     jp    z,cloop
  973.     cp    'E'-40h            ; ^E = up
  974.     jr    z,.edup.
  975.     cp    'X'-40h            ; ^X = down
  976.     jr    z,.eddn.
  977.     cp    'S'-40h            ; ^S = left
  978.     jr    z,.edlf.
  979.     cp    'D'-40h            ; ^D = right
  980.     jr    z,.edrt.
  981.     cp    27h            ; check '
  982.     jp    z,.edasc        ; edit ascii
  983.     call    nybble            ; see if nybble
  984.     jp    nc,.edda.        ; it is, edit data
  985.     ld    a,7
  986.     call    cout
  987.     jr    edlp
  988. ;
  989. .edup.:    ld    a,(editpt+1)        ; get row
  990.     dec    a
  991.     cp    2
  992.     jr    nz,.esnt.
  993.     ld    a,10            ; set bottom
  994. .esnt.:    ld    (editpt+1),a
  995.     jr    edlp
  996. ;
  997. .eddn.:    ld    a,(editpt+1)
  998.     inc    a
  999.     cp    11
  1000.     jr    nz,.esnt.
  1001.     ld    a,3
  1002.     jr    .esnt.
  1003. ;
  1004. .edlf.:    ld    a,(editpt)
  1005.     sub    3
  1006.     cp    3
  1007.     jr    nz,.eslt.
  1008.     ld    a,51
  1009.     ld    (editpt),a
  1010.     jr    .edup.
  1011. ;
  1012. .eslt.:    ld    (editpt),a
  1013.     jp    edlp
  1014. ;
  1015. .edrt.:    ld    a,(editpt)
  1016.     add    a,3
  1017.     cp    54
  1018.     jr    nz,.eslt.
  1019.     ld    a,6
  1020.     ld    (editpt),a
  1021.     jr    .eddn.
  1022. ;
  1023. .edasc:    call    cin            ; get ascii character
  1024.     call    pa2hc
  1025.     jr    ..asci
  1026. ;
  1027. .edda.:    call    hexo            ; display high nybble
  1028.     cp    'A'
  1029.     jr    c,...x
  1030.     sub    7
  1031. ...x:    and    0fh
  1032.     rla
  1033.     rla
  1034.     rla
  1035.     rla
  1036.     ld    b,a            ; save it
  1037. .ede..:    call    capin
  1038.     call    nybble
  1039.     jr    c,.ede..
  1040.     call    hexo
  1041.     cp    'A'
  1042.     jr    c,...y
  1043.     sub    7
  1044. ...y:    and    0fh
  1045.     or    b            ; a has byte now
  1046. ..asci:    push    af
  1047.     call    calcbp            ; calculate buffer pointer
  1048.     pop    af
  1049.     ld    (hl),a
  1050.     ld    a,l
  1051.     and    0fh
  1052.     add    a,55
  1053.     ld    bc,(editpt)
  1054.     ld    c,a
  1055.     call    gotoxy
  1056.     ld    a,(hl)
  1057.     and    7fh
  1058.     cp    7fh
  1059.     jr    z,.ed...
  1060.     cp    ' '
  1061.     jr    nc,.edn..
  1062.     cp    7fh
  1063. .ed...:    ld    a,'.'
  1064. .edn..:    call    cout
  1065.     jp    .edrt.            ; go to next hex on same line
  1066. ;
  1067. ; calculate buffer from screen address
  1068. ;
  1069. calcbp:    ld    hl,(editpt)
  1070.     ld    a,l            ; get column
  1071.     ld    b,0
  1072.     sub    6
  1073. .div3.:    inc    b
  1074.     sub    3
  1075.     jr    nc,.div3.
  1076.     ld    l,b
  1077.     ld    a,h
  1078.     ld    h,0
  1079.     sub    3
  1080.     rla
  1081.     rla
  1082.     rla
  1083.     rla
  1084.     add    a,7fh
  1085.     add    a,l
  1086.     ld    l,a
  1087.     ret
  1088. ;
  1089. ; test a if valid nybble
  1090. ;
  1091. nybble:    cp    '0'
  1092.     ret    c
  1093.     cp    'F'+1
  1094.     ccf
  1095.     ret    c
  1096.     cp    '9'+1
  1097.     ccf
  1098.     ret    nc
  1099.     sub    7
  1100.     cp    '9'+1
  1101.     ret
  1102. ;
  1103. ; hex out
  1104. ;
  1105. hexo:    cp    '9'+1
  1106.     jp    c,cout
  1107.     add    a,7
  1108.     jp    cout
  1109. ;
  1110. ; position cursor. b=x, c=y
  1111. ;
  1112. gotoxy:    push    hl
  1113.     ld    hl,curpos
  1114.     call    pstrg
  1115.     ld    a,(xory)        ; check xy or yx
  1116.     or    a            ; if zero, then xy
  1117.     jr    z,..xy
  1118.     ld    a,b
  1119.     ld    b,c
  1120.     ld    c,a            ; exchange b and c
  1121. ..xy:    call    delay1
  1122.     ld    a,(coffs)        ; get cursor offset
  1123.     push    af            ; save for next
  1124.     add    a,b
  1125.     call    cout
  1126.     call    delay1
  1127.     pop    af
  1128.     add    a,c
  1129.     call    cout
  1130.     pop    hl
  1131.     ret
  1132. ;
  1133. cleol:    push    hl
  1134.     call    gotoxy
  1135.     ld    b,79
  1136.     ld    a,' '
  1137. ..ceol:    call    cout
  1138.     djnz    ..ceol
  1139.     pop    hl
  1140.     ret
  1141. ;
  1142. clrscr:    push    hl
  1143.     ld    hl,cls
  1144.     call    pstrg
  1145.     pop    hl
  1146.     ret
  1147. ;
  1148. pstrg:    ld    a,(hl)
  1149.     or    a
  1150.     ret    z
  1151.     call    cout
  1152.     inc    hl
  1153.     jr    pstrg
  1154. ;
  1155. putt:    ld    a,(timeon)
  1156.     or    a
  1157.     ret    z
  1158.     ld    c,gtime
  1159.     ld    de,datim
  1160.     call    bdos
  1161.     ld    b,a
  1162.     ld    a,(lsec)
  1163.     cp    b
  1164.     ret    z
  1165.     ld    a,b
  1166.     ld    (lsec),a
  1167.     ld    bc,16*256+0
  1168.     call    gotoxy
  1169.     ld    a,(hhh)
  1170.     call    ahlo
  1171.     ld    a,':'
  1172.     call    cout
  1173.     ld    a,(mmm)
  1174.     call    ahlo
  1175.     ld    a,':'
  1176.     call    cout
  1177.     ld    a,(lsec)
  1178.     jp    ahlo
  1179. ;
  1180. ; select new drive
  1181. ;
  1182. drives:    call    clrscr
  1183.     call    print
  1184.     db    cr,lf,lf
  1185.     db    'Enter new drive (A..P, any other = no change) :',0
  1186.     call    capin
  1187.     cp    'A'
  1188.     jp    c,cloop
  1189.     cp    'Q'
  1190.     jp    nc,cloop
  1191.     ld    (cdrv),a
  1192.     ld    (cdrv1),a
  1193.     push    af
  1194.     ld    de,dirfcb
  1195.     call    f$close
  1196.     call    initfcb
  1197.     pop    af
  1198.     sub    40h
  1199.     ld    (dirfcb),a
  1200.     jp    rstrt
  1201. ;
  1202. ; find again (repeat "l" command)
  1203. ;
  1204. again:    ld    hl,previ
  1205.     ld    a,(hl)
  1206.     inc    a
  1207.     jp    z,cloop        ; ignore if no previous fn
  1208.     ex    de,hl
  1209.     jp    ..fa
  1210. ;
  1211.     dseg
  1212. ;
  1213. editpt:    dw    0
  1214. ;
  1215. sttime::db    '00:00:00'
  1216. entime::db    '00:00:00'
  1217. elaptm::db    '00:00:00',0
  1218. dison:    db    0
  1219. frsttm:    db    0
  1220. locked:    db    0        ;0=drive not locked
  1221. noche:    db    0        ;no change (erase)
  1222. dcall:    db    0        ;NZ=dsply called, else JMPed
  1223. curs:    dw    0        ;current sector
  1224. tots:    dw    0        ;total number of sectors
  1225. eracmd:    db    0        ;E5 if erase, user # if unera
  1226. temp:    dw    0
  1227. vect:    dw    0
  1228. vecl:    db    0
  1229. ascis:    db    0        ;0=ascii search, nz=binary
  1230. wrtn:    db    0        ;0=no changes made, else changes were made
  1231. hash:    db    0        ;0=linear, 1=hashed
  1232. curd:    db    0        ;current drive
  1233. lsec:    db    0
  1234. hexfl:    db    0
  1235. loctd:    db    0
  1236. fbyt:    db    0
  1237. force:    db    0        ;force fixdir
  1238. dirfcb:    db    0,'$       DIR',0
  1239.     db    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  1240. rec:    db    0,0,0
  1241. sfcb:    ds    36
  1242. pfcb:    ds    4
  1243. tmpbf:    ds    64        ;temp buffer space
  1244. ;
  1245. previ:    db    0ffh
  1246.     ds    11
  1247. ;
  1248. datim:    dw    0
  1249. hhh:    db    0
  1250. mmm:    db    0
  1251. ;
  1252.     ds    80
  1253. stack    equ    $
  1254.     end
  1255. 
  1256.     jp    rstrt
  1257. ;
  1258. ; find again (repeat "l" command)
  1259. ;