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 / DUT.MAC < prev    next >
Text File  |  2000-06-30  |  12KB  |  750 lines

  1. ; DUT - Disk Utility for TurboDOS
  2. ; 11/29/85 by ESKAY
  3. ; All Lefts Reversed
  4. ;
  5. cr    equ    0dh
  6. lf    equ    0ah
  7. ;
  8. cfunc    equ    5
  9. tfunc    equ    50h
  10. ;
  11. .z80
  12. .request syslib
  13. ;
  14.     cseg
  15. ;
  16. start:    jr    begin
  17. ;
  18. cls:    db    1bh,'E',0,0,0,0        ; clear screen
  19. curpos:    db    1bh,'F',0,0,0,0        ; cursor pos
  20. xory:    db    0            ; 0=xy, nz=yx
  21. coffs:    db    32            ; cursor offset
  22. ;
  23. begin:    ld    sp,stack        ; set up local stack
  24.     ld    c,25
  25.     call    bdos##
  26.     ld    (curdsk),a
  27.     call    clrscr            ; clear the screen
  28.     ld    bc,9*256+0        ; line 9 col 0
  29.     call    gotoxy
  30.     call    print##            ; display banner
  31.     cr,lf
  32.     9,9,'+--------------------------------------------+',cr,lf
  33.     9,9,'| DUT vers 1.50     11/29/85      (c)  ESKAY |',cr,lf
  34.     9,9,'| Disk editor for TurboDOS - Type H for HELP |',cr,lf
  35.     9,9,'+--------------------------------------------+',cr,lf,lf,0
  36.     ld    c,12            ; get priv level
  37.     call    tfunc
  38.     bit    7,b
  39.     jr    nz,.isp            ; continue if privileged
  40.     call    print##
  41.     cr,lf,7
  42.     'ERROR: non-privileged logon',cr,lf,0
  43.     di
  44.     halt                ; crash slave on the poor sucker
  45. ;
  46. .isp:    call    opnnew            ; open new $.DSK
  47. loop:    call    disdrv            ; display drive
  48.     ld    bc,22*256+27        ; line 22 column 27
  49.     call    gotoxy
  50.     call    print##
  51.     'Enter command (H=HELP)  [_]',8,8,0
  52.     call    capin##            ; get command character
  53.     call    cout##            ; echo it
  54.     call    clrerr            ; clear error line
  55.     call    getca            ; get command address
  56.     jr    nz,.bcmd        ; skip if bad command
  57.     jp    (hl)
  58. ;
  59. .bcmd:    ld    bc,23*256+29
  60.     call    gotoxy
  61.     call    print##
  62.     'Invalid command - H=HELP',7,0
  63.     jr    loop
  64. ;
  65. ; read next record
  66. ;
  67. nxtrec:    call    incgrp            ; increment group
  68.     jp    .ggrp.
  69. ;
  70. ; read previous record
  71. ;
  72. prvrec:    call    decgrp
  73.     jp    .ggrp.
  74. ;
  75. incgrp:    ld    hl,(curgrp)
  76.     ld    a,(grpsz)
  77.     ld    b,a
  78.     ld    a,(cursec)
  79.     inc    a
  80.     cp    b
  81.     jr    nz,.igrn.
  82.     ld    de,(maxgrp)
  83.     call    comphd##
  84.     inc    hl
  85.     jr    nz,..ngrz
  86.     ld    hl,0
  87. ..ngrz:    xor    a
  88.     ld    (curgrp),hl
  89. .igrn.:    ld    (cursec),a
  90.     ret
  91. ;
  92. decgrp:    ld    hl,(curgrp)
  93.     ld    a,(cursec)
  94.     dec    a
  95.     jp    p,.dgrn.
  96.     ld    a,h
  97.     or    l
  98.     dec    hl
  99.     jr    nz,.dgr1.
  100.     ld    hl,(maxgrp)
  101. .dgr1.:    ld    (curgrp),hl
  102.     ld    a,(grpsz)
  103.     dec    a
  104. .dgrn.:    ld    (cursec),a
  105.     ret    
  106. ;
  107. ; help
  108. ;
  109. help:    call    clrscr
  110.     call    print##
  111.     'DUT vers 1.40 (c) 1985 ESKAY',cr,lf,lf
  112.     'Command list (see manual for details):',cr,lf,lf,lf
  113.     9,'D  - (re)display current buffer',cr,lf
  114.     9,'F  - Find the start of a file',cr,lf
  115.     9,'G  - Goto group address',cr,lf
  116.     9,'>  - next group (also .)',cr,lf
  117.     9,'<  - previous group (also ,)',cr,lf
  118.     9,'Q  - exit to TurboDOS',cr,lf
  119.     9,'+  - increment current sector and display (also =)',cr,lf
  120.     9,'-  - decrement current sector and display',cr,lf
  121.     9,'!  - step to first data group',cr,lf
  122.     9,'? or H = this list',cr,lf,0
  123.     ld    bc,22*256+27
  124.     call    gotoxy
  125.     call    print##
  126.     'Press any key to continue',0
  127.     call    cin##
  128.     call    clrscr
  129.     jp    loop
  130. ;
  131. ; go to group
  132. ;
  133. .gthi:    ld    bc,23*256+20
  134.     call    gotoxy
  135.     call    print##
  136.     'ERROR: too high!',7,0
  137. ;
  138. goto:    ld    bc,22*256+10        ; row 16 col 10
  139.     call    gotoxy
  140.     call    print##
  141.     'Enter GROUP NUMBER (0000..',0
  142.     ld    hl,(maxgrp)
  143.     dec    hl
  144.     call    phl4hc##
  145.     call    print##
  146.     ') in hex : [____]',8,8,8,8,8,0
  147.     call    bbline##
  148.     or    a
  149.     jr    z,.gotx.        ; aborted
  150.     call    eval16##
  151.     ld    hl,(maxgrp)
  152.     call    comphd##        ; too high?
  153.     jr    c,.gthi            ; too high!
  154. grpntr:    ld    (curgrp),de
  155.     ex    de,hl
  156.     xor    a
  157.     ld    (cursec),a
  158. ggdis1:    call    clcgrp
  159.     ld    (dskfcb+35),a
  160.     ld    (dskfcb+33),hl
  161. .ggdis:    ld    de,dskfcb
  162.     ld    c,33
  163.     call    bdos##
  164. result::nop                ; check rr result
  165.     jp    disbuf
  166. ;
  167. .gotx.:    ld    bc,22*256+0
  168.     call    gotoxy
  169.     call    clreol
  170.     call    clrerr
  171.     jp    loop
  172. ;
  173. ; find a file
  174. ;
  175. filfnd:    ld    bc,22*256+20
  176.     call    gotoxy
  177.     call    print##
  178.     'Enter filename to be found : ',0
  179.     ld    a,1
  180.     call    bbline##
  181.     or    a
  182.     jr    z,.filx.        ; abort
  183.     ld    de,5ch            ; point to fcb area
  184.     call    fname##            ; parse file name
  185.     ld    a,c            ; get specified user
  186.     cp    0ffh            ; none?
  187.     jr    z,..nus.        ;   skip if no user
  188.     ld    e,c
  189.     ld    c,32
  190.     call    bdos##
  191. ..nus.:    ld    de,fndbuf        ; set up temporary dma
  192.     ld    c,26
  193.     call    bdos##
  194.     ld    de,5ch
  195.     ld    c,17            ; search first
  196.     call    bdos##
  197.     push    af
  198.     ld    de,80h
  199.     ld    c,26
  200.     call    bdos##
  201.     pop    af
  202.     inc    a
  203.     jr    nz,..ff..        ; found file
  204.     call    print##
  205.     'FILE NOT FOUND - press any key       ',7,0
  206.     call    cin##
  207.     jr    .filx.
  208. ;
  209. ..ff..:    ld    de,fndbuf
  210.     ld    hl,-16
  211.     ld    bc,32
  212. ..fl..:    add    hl,bc
  213.     dec    a
  214.     jr    nz,..fl..
  215.     add    hl,de
  216.     ld    e,(hl)
  217.     inc    hl
  218.     ld    d,(hl)
  219.     jp    grpntr
  220. ;
  221. .filx.:    ld    bc,22*256+0
  222.     call    gotoxy
  223.     call    clreol
  224.     jp    loop
  225. ;
  226. ; go to next group
  227. ;
  228. nxtgrp:    ld    hl,(curgrp)
  229.     inc    hl
  230.     ld    (curgrp),hl
  231.     push    hl
  232.     dec    hl
  233.     ld    de,(maxgrp)
  234.     or    a
  235.     sbc    hl,de
  236.     ld    a,h
  237.     or    l
  238.     pop    hl
  239.     jr    nz,.ggrp.
  240.     ld    hl,0
  241.     ld    (curgrp),hl
  242. .ggrp.::    call    clcgrp            ; calc sector from group
  243.     ld    (dskfcb+35),a
  244.     ld    b,a
  245.     ld    a,(cursec)
  246.     ld    e,a
  247.     ld    d,0
  248.     add    hl,de
  249.     ld    (dskfcb+33),hl
  250.     ld    a,b
  251.     jr    nc,..novf
  252.     inc    a
  253. ..novf:    ld    (dskfcb+35),a
  254.     jp    .ggdis            ; set file pointer and display
  255. ;
  256. prvgrp:    ld    hl,(curgrp)
  257.     ld    a,h
  258.     or    l
  259.     jr    nz,.pg.
  260.     ld    hl,(maxgrp)
  261.     jr    .pg1.
  262. ;
  263. .pg.:    dec    hl
  264. .pg1.:    ld    (curgrp),hl
  265.     jr    .ggrp.
  266. ;
  267. ; step to first data group
  268. ;
  269. frstdt:    ld    hl,(dirsiz)
  270.     ld    (curgrp),hl
  271.     xor    a
  272.     ld    (cursec),a
  273.     ld    (dskfcb+35),a
  274.     call    clcgrp
  275.     ld    (dskfcb+33),hl
  276.     jp    .ggdis
  277. ;
  278. ; edit command
  279. ;
  280. edit:    ld    a,(dison)
  281.     dec    a
  282.     jr    z,.eact.
  283.     ld    a,7
  284.     call    cout##
  285.     jp    loop
  286. ;
  287. .eact.:    ld    bc,3*256+6        ; beginning of field
  288.     ld    (editpt),bc
  289. edlp:    ld    bc,(editpt)
  290.     call    gotoxy
  291.     call    capin##
  292.     cp    3            ; exit
  293.     jp    z,loop
  294.     cp    'E'-40h            ; ^E = up
  295.     jr    z,.edup.
  296.     cp    'X'-40h            ; ^X = down
  297.     jr    z,.eddn.
  298.     cp    'S'-40h            ; ^S = left
  299.     jr    z,.edlf.
  300.     cp    'D'-40h            ; ^D = right
  301.     jr    z,.edrt.
  302.     cp    27h            ; check '
  303.     jp    z,.edasc        ; edit ascii
  304.     call    nybble            ; see if nybble
  305.     jp    nc,.edda.        ; it is, edit data
  306.     ld    a,7
  307.     call    cout##
  308.     jr    edlp
  309. ;
  310. .edup.:    ld    a,(editpt+1)        ; get row
  311.     dec    a
  312.     cp    2
  313.     jr    nz,.esnt.
  314.     ld    a,10            ; set bottom
  315. .esnt.:    ld    (editpt+1),a
  316.     jr    edlp
  317. ;
  318. .eddn.:    ld    a,(editpt+1)
  319.     inc    a
  320.     cp    11
  321.     jr    nz,.esnt.
  322.     ld    a,3
  323.     jr    .esnt.
  324. ;
  325. .edlf.:    ld    a,(editpt)
  326.     sub    3
  327.     cp    3
  328.     jr    nz,.eslt.
  329.     ld    a,51
  330. .eslt.:    ld    (editpt),a
  331.     jp    edlp
  332. ;
  333. .edrt.:    ld    a,(editpt)
  334.     add    a,3
  335.     cp    54
  336.     jr    nz,.eslt.
  337.     ld    a,6
  338.     jr    .eslt.
  339. ;
  340. .edasc:    call    cin##            ; get ascii character
  341.     call    pa2hc##
  342.     jr    ..asci
  343. ;
  344. .edda.:    call    hexo            ; display high nybble
  345.     cp    'A'
  346.     jr    c,...x
  347.     sub    7
  348. ...x:    and    0fh
  349.     rla
  350.     rla
  351.     rla
  352.     rla
  353.     ld    b,a            ; save it
  354. .ede..:    call    capin##
  355.     call    nybble
  356.     jr    c,.ede..
  357.     call    hexo
  358.     cp    'A'
  359.     jr    c,...y
  360.     sub    7
  361. ...y:    and    0fh
  362.     or    b            ; a has byte now
  363. ..asci:    push    af
  364.     call    calcbp            ; calculate buffer pointer
  365.     pop    af
  366.     ld    (hl),a
  367.     ld    a,l
  368.     and    0fh
  369.     add    a,55
  370.     ld    bc,(editpt)
  371.     ld    c,a
  372.     call    gotoxy
  373.     ld    a,(hl)
  374.     and    7fh
  375.     cp    7fh
  376.     jr    z,.ed...
  377.     cp    ' '
  378.     jr    nc,.edn..
  379.     cp    7fh
  380. .ed...:    ld    a,'.'
  381. .edn..:    call    cout##
  382.     jp    .edrt.            ; go to next hex on same line
  383. ;
  384. ; write buffer
  385. ;
  386. write:    ld    de,dskfcb
  387.     ld    c,34
  388.     call    bdos##
  389.     jp    loop
  390. ;
  391. ; advance and display directory buffer
  392. ;
  393. advdir:
  394.  
  395.  
  396.  
  397.  
  398. ;
  399. ; display buffer command
  400. ;
  401. disbuf:    call    clrscr
  402.     ld    a,1
  403.     ld    (dison),a
  404.     call    print##
  405.     'RELATIVE SECTOR : ',0
  406.     ld    hl,(dskfcb+33)
  407.     inc    hl
  408.     ld    a,(dskfcb+35)
  409.     ld    e,a
  410.     call    p24b
  411.     ld    bc,0*256+25
  412.     call    gotoxy
  413.     call    print##
  414.     ' OF ',0
  415.     ld    hl,(maxrec)
  416.     inc    hl
  417.     ld    a,(maxrec+2)
  418.     ld    e,a
  419.     call    p24b
  420.     ld    bc,0*256+38
  421.     call    gotoxy
  422.     call    print##
  423.     'GROUP:SECTOR : ',0
  424.     ld    hl,(curgrp)
  425.     call    phl4hc##
  426.     ld    a,':'
  427.     call    cout##
  428.     ld    a,(cursec)
  429.     call    pa2hc##
  430.     call    disdrv            ; display drive
  431.     call    dispbf            ; display buffer contents
  432.     jp    loop            ; and go back for next command
  433. ;
  434. quit:    call    clrscr
  435.     ld    bc,23*256+0
  436.     call    gotoxy
  437.     rst    0
  438. ;
  439. ; subroutines
  440. ;
  441. ; calculate buffer from screen address
  442. ;
  443. calcbp::
  444.     ld    hl,(editpt)
  445.     ld    a,l            ; get column
  446.     ld    b,0
  447.     sub    6
  448. .div3.:    inc    b
  449.     sub    3
  450.     jr    nc,.div3.
  451.     ld    l,b
  452.     ld    a,h
  453.     ld    h,0
  454.     sub    3
  455.     rla
  456.     rla
  457.     rla
  458.     rla
  459.     add    a,7fh
  460.     add    a,l
  461.     ld    l,a
  462.     ret
  463. ;
  464. ; test a if valid nybble
  465. ;
  466. nybble:    cp    '0'
  467.     ret    c
  468.     cp    'F'+1
  469.     ccf
  470.     ret    c
  471.     cp    '9'+1
  472.     ccf
  473.     ret    nc
  474.     sub    7
  475.     cp    '9'+1
  476.     ret
  477. ;
  478. ; hex out
  479. ;
  480. hexo:    cp    '9'+1
  481.     jp    c,cout##
  482.     add    a,7
  483.     jp    cout##
  484. ;
  485. ; calc sector from group
  486. ;
  487. clcgrp::
  488.     ld    a,(grpmul)
  489.     ld    b,a
  490.     xor    a
  491. .ggrm.:    rl    l
  492.     rl    h
  493.     rla
  494.     djnz    .ggrm.
  495.     ret
  496. ;
  497. ; open $.DSK, $.DIR
  498. ;
  499. opnnew:    ld    de,dskfcb
  500.     call    initfcb##
  501.     ld    c,35            ; get file size
  502.     call    bdos##
  503.     ld    hl,(dskfcb+33)
  504.     ld    a,(dskfcb+35)
  505.     dec    hl
  506.     ld    (maxrec),hl
  507.     ld    (maxrec+2),a
  508.     call    f$open##
  509.     ld    de,80h
  510.     ld    c,26
  511.     call    bdos##
  512.     ld    de,dskfcb
  513.     ld    hl,0
  514.     ld    (dskfcb+32),hl
  515.     ld    (dskfcb+34),hl
  516.     call    f$read##
  517.     ld    c,19
  518.     ld    a,(curdsk)
  519.     ld    e,a
  520.     call    tfunc
  521.     dec    hl
  522.     ld    (maxgrp),hl
  523.     and    0fh
  524.     ld    (grpmul),a
  525.     sub    2
  526.     ld    b,a
  527.     ld    a,4
  528. .sla.:    or    a
  529.     rla
  530.     djnz    .sla.
  531.     ld    (grpsz),a
  532.     ld    a,c
  533.     ld    (dirsiz),a
  534.     ret
  535. ;
  536. ; display drive
  537. ;
  538. disdrv:    ld    bc,0*256+70
  539.     call    gotoxy
  540.     call    print##
  541.     'DRIVE ',0
  542.     ld    a,(curdsk)
  543.     add    a,'A'
  544.     call    cout##
  545.     ld    a,':'
  546.     jp    cout##
  547. ;
  548. ; display buffer on screen (80H)
  549. ;
  550. dispbf:    ld    de,0
  551.     ld    bc,3*256+0        ; row 3 col 0
  552. disobf:    call    gotoxy
  553.     add    hl,de
  554.     ld    hl,80h            ; point to buffer
  555. .disl.:    push    hl            ; save hl
  556.     ld    b,16            ; display 16 hex bytes
  557.     push    hl
  558.     res    7,l
  559.     ld    h,0
  560.     call    phl4hc##        ; display relative address
  561.     pop    hl
  562.     call    space2            ; 2 spaces
  563. .h16l.:    ld    a,(hl)            ; get byte
  564.     call    pa2hc##            ; print hex
  565.     call    space
  566.     inc    hl
  567.     djnz    .h16l.            ; complete 16 bytes
  568.     pop    hl            ; get addr back
  569.     ld    b,16            ; 16 bytes again
  570.     call    space
  571. .a16l.:    ld    a,(hl)            ; get byte
  572.     and    7fh            ; strip hi bit
  573.     cp    7fh
  574.     jr    z,.a16..
  575.     cp    ' '            ; dot if control
  576.     jr    nc,.a16n.
  577. .a16..:    ld    a,'.'
  578. .a16n.:    call    cout##
  579.     inc    hl
  580.     djnz    .a16l.            ; loop until done
  581.     call    crlf##            ; new line
  582.     ld    a,l            ; get low byte of buffer addr
  583.     or    a            ; zero?
  584.     ret    z            ;   yes, done
  585.     jr    .disl.            ;     else do next line
  586. ;
  587. ; get command address or NZ
  588. ;
  589. getca:    ld    hl,cmdtbl
  590.     ld    b,a
  591. .gca.:    ld    a,(hl)
  592.     or    a
  593.     jr    z,.gcx.
  594.     cp    b
  595.     jr    z,.gcg.
  596.     inc    hl
  597.     inc    hl
  598.     inc    hl
  599.     jr    .gca.
  600. ;
  601. .gcg.:    inc    hl
  602.     ld    a,(hl)
  603.     inc    hl
  604.     ld    h,(hl)
  605.     ld    l,a
  606.     xor    a
  607.     ret
  608. ;
  609. .gcx.:    dec    a
  610.     ret
  611. ;
  612. clrerr:    push    af
  613.     push    bc
  614.     ld    bc,23*256+0        ; row 23 col 0
  615.     call    gotoxy
  616.     pop    bc
  617.     pop    af
  618. ;
  619. clreol:    push    af
  620.     push    bc
  621.     ld    b,79
  622.     ld    a,' '
  623. .clel.:    call    cout##
  624.     djnz    .clel.
  625.     pop    bc
  626.     pop    af
  627.     ret
  628. ;
  629. space2:    call    space
  630. space:    ld    a,' '
  631.     jp    cout##
  632. ;
  633. ; position cursor. b=x, c=y
  634. ;
  635. gotoxy:    push    hl
  636.     ld    hl,curpos
  637.     call    pstrg
  638.     ld    a,(xory)        ; check xy or yx
  639.     or    a            ; if zero, then xy
  640.     jr    z,..xy
  641.     ld    a,b
  642.     ld    b,c
  643.     ld    c,a            ; exchange b and c
  644. ..xy:    ld    a,(coffs)        ; get cursor offset
  645.     push    af            ; save for next
  646.     add    a,b
  647.     call    cout##
  648.     pop    af
  649.     add    a,c
  650.     call    cout##
  651.     pop    hl
  652.     ret
  653. ;
  654. clrscr:    push    hl
  655.     ld    hl,cls
  656.     call    pstrg
  657.     pop    hl
  658.     ret
  659. ;
  660. pstrg:    ld    a,(hl)
  661.     or    a
  662.     ret    z
  663.     call    cout##
  664.     inc    hl
  665.     jr    pstrg
  666. ;
  667. p24b:    ld    ix,n24b
  668.     push    ix
  669.     ld    b,12
  670.     xor    a
  671. .p24l:    ld    (ix+0),a
  672.     inc    ix
  673.     djnz    .p24l
  674.     pop    ix
  675.     ld    a,3
  676.     call    hxdc24##
  677.     ld    hl,n24b
  678.     jp    pstr##
  679. ;
  680.     dseg
  681. ;
  682. ; command table
  683. ;
  684. cmdtbl:    db    'Q'            ; exit
  685.     dw    quit
  686.     db    'D'            ; display buffer
  687.     dw    disbuf
  688.     db    '+'            ; next record
  689.     dw    nxtrec
  690.     db    '='
  691.     dw    nxtrec
  692.     db    '-'            ; previous record
  693.     dw    prvrec
  694.     db    'H'
  695.     dw    help
  696.     db    '?'
  697.     dw    help
  698.     db    'G'            ; go to group
  699.     dw    goto
  700.     db    'F'            ; find file
  701.     dw    filfnd
  702.     db    '<'            ; previous group
  703.     dw    prvgrp
  704.     db    '>'            ; next group
  705.     dw    nxtgrp
  706.     db    ','
  707.     dw    prvgrp
  708.     db    '.'
  709.     dw    nxtgrp
  710.     db    '!'            ; first data grp
  711.     dw    frstdt
  712.     db    'E'            ; edit
  713.     dw    edit
  714.     db    'W'            ; write
  715.     dw    write
  716.     db    0
  717. ;
  718. curdsk:    db    0
  719. dirsiz:    dw    0
  720. maxrec:    ds    3
  721. curgrp:    dw    0
  722. cursec:    db    0
  723. maxgrp:    dw    0
  724. grpsz:    db    0
  725. grpmul:    db    0
  726. ;
  727. n24b:    db    0,0,0,0,0,0,0,0,0,0,0,0
  728. ;
  729. dison:    db    0
  730. editpt:    dw    0
  731. ;
  732. dskfcb:    db    0,'$       DSK',0,0,0,0
  733.     ds    24
  734. ;
  735. fndbuf:    ds    128
  736.     ds    100
  737. stack    equ    $
  738.     end
  739. ld    a,(hl)
  740.     or    a
  741.     ret    z
  742.     call    cout##
  743.     inc    hl
  744.     jr    pstrg
  745. ;
  746. p24b:    ld    ix,n24b
  747.     push    ix
  748.     ld    b,12
  749.     xor    a
  750. .p24l:    ld    (ix+0),