home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol024 / findbad.mac < prev    next >
Text File  |  1984-04-29  |  6KB  |  429 lines

  1.     .COMMENT \
  2. ***************************************************
  3. *
  4. *    THIS WAS ORIGINALLY UPGRADED BY RAY PENLEY
  5. *  TO CPM 2.2 .
  6. *  DAN LUNSFORD THEN CONVERTED IT TO Z80 AND ADDED
  7. *  THAT SNEAKY USER 31 LOCATION FOR THE [UNUSED].BAD.
  8. *  SO NOW WE HAVE A SLICK WAY TO STRETCH OUR DISKS.
  9. *****************************************************
  10.    This is an adaptation of the FINDBAD
  11. program appearing in the September, 1980 issue
  12. of INTERFACE AGE magazine.  This program will
  13. read a CP/M disk and isolate any bad sectors
  14. in a reserved file, so CP/M doesn't see them 
  15. any more.
  16.  
  17.    The original of this program was written for
  18. CP/M V1.4, but failed under V2.0 and above.
  19. This version is EXPLICITLY for V2.2 and the Z80
  20. and will not run under earlier versions or an 8080.
  21.  
  22.    The reserved file is made totally invisible by
  23. being relegated to USER 31, which is not accessible
  24. from the CCP, or indeed, to just about anything.
  25.  
  26.    Planned enhancements to this program include
  27. adaptation to disks other than floppys.  I want to 
  28. get it to handle hard disks, etc.  This means messing
  29. with the disk parameter blocks.  
  30.     \
  31.     .z80
  32.  
  33. boot    equ    0
  34. bdos    equ    5
  35. tbuff    equ    80h
  36.  
  37. tracks    equ    77
  38. sects    equ    26
  39. dbase    equ    2
  40. bbase    equ    2
  41. maxb    equ    241
  42. block    equ    8
  43.  
  44. deletf    equ    19
  45. makef    equ    22
  46. openf    equ    15
  47. selecf    equ    14
  48. closef    equ    16
  49. prstrf    equ    9
  50. usrcdf    equ    32
  51. versf    equ    12
  52.  
  53. cr    equ    0dh
  54. lf    equ    0ah
  55. tab    equ    09h
  56.  
  57. fill    macro    nbytes,fillb
  58.     .xlist
  59.     rept    nbytes
  60.     defb    fillb
  61.     endm
  62.     .list
  63.     endm
  64.  
  65. defz    macro    nbytes
  66.     fill    nbytes,0
  67.     endm
  68.  
  69. start:    ld    sp,dm+1000
  70.     call    ibios
  71.     call    findb
  72.     jr    z,nobad
  73.     call    openb
  74.     call    setdm
  75.     call    closeb
  76.     call    setnum
  77. nobad:    ld    de,endmsg
  78. pmsg:    ld    c,prstrf
  79.     call    bdos
  80.     ld    c,usrcdf    ;restore invoking user number
  81.     ld    a,(usrcde)
  82.     ld    e,a
  83.     call    bdos
  84.     jp    boot
  85.  
  86. ibios:    ld    hl,(boot+1)
  87.     inc    hl
  88.     inc    hl
  89.     inc    hl
  90.     ld    de,jpvec
  91.     ld    bc,39
  92.     ldir
  93.     ld    c,versf
  94.     call    bdos
  95.     ld    a,l
  96.     or     a
  97.     jr    z,vererr
  98.     ld    a,(tbuff)
  99.     cp    2
  100.     ret    c
  101.     jr    z,error1
  102.     ld    hl,(tbuff+2)
  103.     ld    a,h
  104.     cp    ":"
  105.     jr    nz,error1
  106.     ld    a,l
  107.     cp    "A"
  108.     jr    c,error1
  109.     cp    "E"
  110.     jr    nc,error1
  111.     and    7
  112.     dec    a
  113.     ld    e,a
  114.     ld    d,0
  115.     ld    c,selecf
  116.     call    bdos
  117.     ld    e,0ffh
  118.     ld    c,usrcdf    ; save invoking user number
  119.     call    bdos
  120.     ld    (usrcde),a
  121.     ld    e,31
  122.     ld    c,usrcdf    ;set user number to 31
  123.     call    bdos
  124.     ret
  125.  
  126. vererr:    ld    de,vermsg
  127.     jp    pmsg
  128.  
  129. vermsg:    defb    cr,lf,"This version of FINDBAD requires"
  130.     defb    "CP/M 2.0 or higher",cr,lf,"$"
  131.  
  132. error1:    ld    de,ermsg1
  133.     jp    pmsg
  134.  
  135. ermsg1:    defb    cr,lf,"Error in command line"
  136.     defb    cr,lf,"Must be 'FINDBAD' or 'FINDBAD X:'"
  137.     defb    cr,lf,"$"
  138.  
  139. findb:    call    chksys
  140.     call    chkdir
  141.     ld    b,bbase
  142. findba:    call    readb
  143.     call    nz,setbd
  144.     inc    b
  145.     ld    a,b
  146.     cp    maxb
  147.     jr    c,findba
  148.     ld    hl,(dmcnt)
  149.     ld    a,h
  150.     or    l
  151.     ret
  152.  
  153. chksys:    ld    hl,1
  154. chksy1:    call    reads
  155.     jr    nz,syserr
  156.     ld    a,h
  157.     cp    2
  158.     jr    c,chksy1
  159.     ret
  160. syserr:    ld    de,ermsg9
  161.     ld    c,prstrf
  162.     call    bdos
  163.     ret
  164.  
  165. ermsg9:    defb    cr,lf,"***WARNING*** System tracks bad***$"
  166.  
  167. chkdir:    ld    b,0
  168. chkdi1:    call    readb
  169.     jr    nz,direrr
  170.     inc    b
  171.     ld    a,b
  172.     cp    bbase
  173.     jr    c,chkdi1
  174.     ret
  175. direrr:    ld    de,ermsg2
  176.     jp    pmsg
  177.  
  178. ermsg2:    defb    cr,lf,"***Bad directory area-halting***"
  179.     defb    cr,lf,"$"
  180.  
  181. readb:    call    cnvrtb
  182.     ld    c,block
  183. readba:    call    reads
  184.     ret    nz
  185.     dec    c
  186.     jr    nz,readba
  187.     ret
  188.  
  189. cnvrtb:    push    bc
  190.     ld    l,b
  191.     ld    h,0
  192.     add    hl,hl
  193.     add    hl,hl
  194.     add    hl,hl
  195.     ld    de,dbase*256
  196.     ld    bc,-sects
  197. cnvrtc:    ld    a,h
  198.     or    a
  199.     jr    nz,cnvrtt
  200.     ld    a,l
  201.     cp    sects
  202.     jr    c,cnvrts
  203. cnvrtt:    add    hl,bc
  204.     inc    d
  205.     jr    cnvrtc
  206. cnvrts:    ld    e,l
  207.     inc    e
  208.     ex    de,hl
  209.     pop    bc
  210.     ret
  211.  
  212. reads:    push    bc
  213.     push    hl
  214.     call    itoa
  215.     push    hl
  216.     ld    c,h
  217.     call    settrk
  218.     pop    bc
  219.     call    setsec
  220.     call    dread
  221.     or    a
  222.     pop    hl
  223.     pop    bc
  224.     push    af
  225.     inc    l
  226.     ld    a,l
  227.     cp    sects+1
  228.     jr    c,readsr
  229.     ld    l,1
  230.     inc    h
  231. readsr:    pop    af
  232.     ret
  233.  
  234. itoa:    ex    de,hl
  235.     ld    bc,lpmap-1
  236.     ld    l,e
  237.     ld    h,0
  238.     add    hl,bc
  239.     ld    e,(hl)
  240.     ex    de,hl
  241.     ret
  242.  
  243. lpmap:    defb    1,7,13,19,25,5,11,17,23,3,9,15,21
  244.     defb    2,8,14,20,26,6,12,18,24,4,10,16,22
  245.  
  246. setbd:    ld    hl,(dmcnt)
  247.     ld    de,block
  248.     add    hl,de
  249.     ld    (dmcnt),hl
  250.     ld    hl,(dmptr)
  251.     ld    (hl),b
  252.     inc    hl
  253.     ld    (dmptr),hl
  254.     ret
  255.  
  256. openb:    ld    de,bfcb
  257.     push    de
  258.     push    de
  259.     ld    c,deletf
  260.     call    bdos
  261.     pop    de
  262.     ld    c,makef
  263.     call    bdos
  264.     pop    de
  265.     ld    c,openf
  266.     call    bdos
  267.     cp    255
  268.     ret    nz
  269.     ld    de,ermsg3
  270.     jp    pmsg
  271.  
  272. ermsg3:    defb    cr,lf,"Can't create [UNUSED].BAD",cr,lf,"$"
  273.  
  274. setdm:    ld    hl,dm
  275.     ld    (dmptr),hl
  276.     ld    hl,(dmcnt)
  277. setdm0:    ld    a,h
  278.     or    a
  279.     jr    nz,gobig
  280.     ld    a,l
  281.     cp    129
  282.     jr    c,setdme
  283. gobig:    ld    de,-128
  284.     add    hl,de
  285.     push    hl
  286.     ld    a,128
  287.     call    setdme
  288.     ex    de,hl
  289.     ld    (dmptr),hl
  290.     call    closeb
  291.     ld    a,(fnum)
  292.     inc    a
  293.     ld    (fnum),a
  294.     ld    (bfcb+8),a
  295.     call    openb
  296.     pop    hl
  297.     jr    setdm0
  298. setdme:    ld    hl,(dmptr)
  299.     ex    de,hl
  300.     ld    hl,bfcb+16
  301.     ld    b,16
  302.     ld    (bfcb+15),a
  303. setdml:    ld    a,(de)
  304.     ld    (hl),a
  305.     inc    de
  306.     inc    hl
  307.     djnz    setdml
  308.     ret
  309.  
  310. closeb:    xor    a
  311.     ld    (bfcb+14),a
  312.     ld    de,bfcb
  313.     ld    c,closef
  314.     call    bdos
  315.     ret
  316.  
  317. setnum:    ld    hl,(dmcnt)
  318.     add    hl,hl
  319.     add    hl,hl
  320.     add    hl,hl
  321.     add    hl,hl
  322.     add    hl,hl
  323.     ld    de,255
  324.     add    hl,de
  325.     ld    l,h
  326.     ld    h,0
  327.     ld    de,numbad
  328.     call    dncv
  329.     ret
  330.  
  331. dncv:    ld    b," "
  332.     ld    a,h
  333.     or    a
  334.     jp    p,h3
  335.     ld    b,"-"
  336.     ld    a,l
  337.     neg
  338.     ld    l,a
  339.     ld    a,h
  340.     cpl
  341.     jr    nz,h2
  342.     inc a
  343. h2:    ld    h,a
  344. h3:    ld    (dcnvhl),hl
  345.     ld    a," "
  346.     ld    (de),a
  347.     ld    a,b
  348.     ld    (dcnvpm),a
  349.     ex    de,hl
  350.     ld    (dcnvad),hl
  351.     xor    a
  352.     ld    (dcnvfl),a
  353.     ld    bc,-10000
  354.     call    dfl8
  355.     call    dstc
  356.     ld    bc,-1000
  357.     call    dfl8
  358.     call    dstc
  359.     ld    bc,-100
  360.     call    dfl8
  361.     call    dstc
  362.     ld    bc,-10
  363.     call    dfl8
  364.     call    dstc
  365.     ld    a,(dcnvhl)
  366.     or    "0"
  367.     ld    e,a
  368. dstc:    ld    hl,(dcnvad)
  369.     ld    a,(dcnvfl)
  370.     or    a
  371.     jr    nz,dstc3
  372. dstc1:    add    a,e
  373.     ld    (dcnvfl),a
  374.     jr    nz,dstc2
  375.     ld    a," "
  376.     jr    dstc4
  377. dstc2:    ld    a,(dcnvpm)
  378.     ld    (hl),a
  379. dstc3:    ld    a,"0"
  380.     or    e
  381. dstc4:    inc    hl
  382.     ld    (hl),a
  383.     ld    (dcnvad),hl
  384.     ret
  385.  
  386. dcnvfl:    defb    0
  387. dcnvhl:    defw    0
  388. dcnvad:    defw    0
  389. dcnvpm:    defb    0
  390.  
  391. dfl8:    ld    hl,(dcnvhl)
  392.     ld    e,0
  393. df1:    add    hl,bc
  394.     bit    7,h
  395.     ret    nz
  396.     inc    e
  397.     ld    (dcnvhl),hl
  398.     jr    df1
  399.  
  400. usrcde:    defb    0
  401.  
  402. bfcb:    defb    0,"[UNUSED]BAD",0,0,0,0
  403.     defz    17
  404.  
  405. endmsg:    defb    cr,lf,tab
  406. numbad:    defb    "    No bad blocks found",cr,lf,"$"
  407. fnum:    defb    "0"
  408. dmcnt:    defw    0
  409. dmptr:    defw    dm
  410.  
  411. dm:    defz    256
  412.  
  413. jpvec:    defs    39
  414. const    equ    jpvec
  415. conin    equ    jpvec+3
  416. conout    equ    jpvec+6
  417. list    equ    jpvec+9
  418. punch    equ    jpvec+12
  419. reader    equ    jpvec+15
  420. home    equ    jpvec+18
  421. seldsk    equ    jpvec+21
  422. settrk    equ    jpvec+24
  423. setsec    equ    jpvec+27
  424. setdma    equ    jpvec+30
  425. dread    equ    jpvec+33
  426. dwrite    equ    jpvec+36
  427.  
  428.     end    start
  429.