home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol135 / inf.mac < prev    next >
Encoding:
Text File  |  1984-04-29  |  12.6 KB  |  606 lines

  1. ;
  2. ;        inf.mac  Ver 1.3   rev  23/Jan/1983
  3. ;        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. ;
  5. ;     cp/m 2.+ disk information display program
  6. ;     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  7. ;
  8. ;This program displays all the information that CP/M has hidden
  9. ;away in the bios and other places. This is very useful if
  10. ;testing a new drive or CP/M implementation (which is why i
  11. ;wrote it. It displays all the information that the CP/M bdos
  12. ;uses and thus you can determine that 'DPH' for that drive is
  13. ;functioning correctly.
  14. ;
  15. ;Command structure.....
  16. ;
  17. ;inf    for the logged drive or....
  18. ;inf d: to look at the info for drive 'd'
  19. ;
  20. ;
  21. ;    Copyright (c) 1982,83 by Steven Engel
  22. ;
  23. ;
  24. ;Version list, most recent first
  25. ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  26. ;
  27. ;version 1.3, fixed the printout of the translate table so it
  28. ;          uses the bios call 'sectran' to find the physical
  29. ;          sectors. This should make it more universal.
  30. ;
  31. ;version 1.2 & earlier, initial releases.
  32. ;
  33. ;
  34. ;if your cp/m system is non-standard in any of the start
  35. ;address offsets from the bios or if your ccp is
  36. ;a non-standard length change the ccplen, ccpo, bdoso equates.
  37. ;
  38. bdos    equ    5        ;bdos call location
  39. bios    equ    1        ;bios warm boot jump location
  40. ccplen    equ    0800h        ;STANDARD ccp length
  41. ccpo    equ    01600h        ;STANDARD ccp offset from bios
  42. bdoso    equ    0e00h        ;STANDARD bdos offset from bios
  43. tpa    equ    0100h        ;tpa (standard one)
  44. cr    equ    0dh
  45. lf    equ    0ah
  46. base    equ    0
  47. defstf    equ    base+4        ;user level+default drive
  48. fcb    equ    base+05ch    ;file control block
  49. line    equ    30        ;number of chars on one line
  50.                 ;for the allocation map display
  51.  
  52.     aseg            ;absolutely
  53.     .z80            ;the only way to go
  54.     org    tpa
  55.  
  56.     jp    start
  57.  
  58. signon: defm    cr,lf,'CP/M 2.2 disk informer'
  59.     defm    ' version 1.3 for drive '
  60. drvnum: defm    'A:, user level '
  61. usrlev: defm    '00',cr,lf
  62.     defm    'CCP is at  $'
  63. bdos@:    defm    cr,lf,'BDOS is at $'
  64. bios@:    defm    cr,lf,'BIOS is at $'
  65. space:    defm    cr,lf,'TPA space with ccp intact is $'
  66. space2: defm    cr,lf,'Space with ccp overlayed is $'
  67. sorry:    defm    cr,lf,lf,'Sorry this program requires'
  68.     defm    ' CP/M 2.0 or later to run',cr,lf,'$'
  69. ntabl:    defm    cr,lf,'This drive uses 1:1 physical to'
  70.     defm    ' sector translation',cr,lf,'$'
  71. ttabl:    defm    cr,lf,'Translate table for this drive is:'
  72.     defm    cr,lf,'$'
  73. csv@:    defm    cr,lf,'Software check vector (csv) is at $'
  74. alv@:    defm    cr,lf,'Allocation storage scratchpad (alv)'
  75.     defm    ' is at $'
  76. dchar:    defm    ' sectors per track and a max. of $'
  77. dent:    defm    ' directory entries'
  78. pnta:    defm    cr,lf,'Directory block allocation:-',cr,lf
  79.     defm    9,'   AL0     AL1   ',cr,lf,9,'$'
  80. dirblk: defm    ' dir block(s) on a $'
  81. tdisk:    defm    'k disk with $'
  82. kused:    defm    'k used and $'
  83. sfree:    defm    'k free$'
  84.  
  85. nres:    defm    ' system tracks '
  86. bksiz:    defm    'with $'
  87. kpblk:    defm    'k per block and skew factor of $'
  88.  
  89. baddpb: defm    cr,lf,lf,'This dpb is stuffed, check your'
  90.     defm    ' bios',cr,lf,lf,'$'
  91.  
  92. dmap:    defm    cr,lf,'Disk storage allocation map:-'
  93.     defm    cr,lf,9,9,'$'
  94. tblk:    defm    cr,lf,9,'Total blocks: $'
  95. used:    defm    '  blocks used: $'
  96. left:    defm    '  blocks free: $'
  97.  
  98.     defs    40        ;our stack
  99. ccpsp:    defs    2        ;ccp stack pointer
  100. block:    defs    2        ;# of blocks used
  101. free:    defs    2        ;# of blocks free
  102. bsize:    defs    1        ;our k/block
  103. ddisk:    defs    1        ;default disk
  104.  
  105. ;dph & dpb storage area
  106.  
  107. xltadr: defs    2        ;disk trans table address
  108.     defs    2        ;bdos scratch area
  109.     defs    2        ; "      "     "
  110.     defs    2        ; "      "     "
  111.     defs    2        ;address of dir buffer
  112. dpb:    defs    2        ;dpb for logged drive
  113. csv:    defs    2        ;csv for this drive
  114. alv:    defs    2        ;alv for this drive
  115.  
  116. spt:    defs    2        ;sectors per track
  117. bsh:    defs    1        ;block shift factor
  118. blm:    defs    1
  119. exm:    defs    1        ;extent mask
  120. dsm:    defs    2        ;total # of blocks
  121. drm:    defs    2        ;total # of dir entries
  122. al0:    defs    1        ;alloc0
  123. al1:    defs    1        ;alloc1
  124. cks:    defs    2        ;size of the dir check vector
  125. off:    defs    2        ;# of reserved tracks
  126.  
  127. bls:    defb    10,19,36,69,134 ;bsh+blm
  128.  
  129. start:    ld    hl,0
  130.     add    hl,sp
  131.     ld    (ccpsp),hl
  132.     ld    sp,ccpsp    ;make our stack here
  133.     ld    hl,0        ;init
  134.     ld    (block),hl    ;init block
  135.     ld    (free),hl    ; and block free
  136.     call    verify        ;ensure cpm 2.0 or later
  137.     ld    hl,(bios)    ;install address for seldsk
  138.     ld    l,01bh        ;l=lsb of bios jmp table seldsk
  139.     ld    (disk+1),hl    ;save in our jump
  140.     ld    l,030h        ;l=lsb of jmp table sectran
  141.     ld    (sectran+1),hl    ;save in our space
  142.  
  143. ;get the drive # and xfer some info
  144. ;note: the user level display stuff assumes a 0-15 user level
  145. ;ccp, so if you are running a non-standard ccp it won't work.
  146.  
  147.     ld    a,(fcb)        ;get currently logged disk
  148.     or    a        ;0 ?
  149.     jr    nz,gotdrv
  150.     ld    a,(defstf)    ;get default drive
  151.     push    af        ;save it
  152.     and    0f0h        ;mask off drive stuff
  153.     rrca            ;get user level
  154.     rrca            ;into first 4 bits
  155.     rrca
  156.     rrca
  157.     cp    10        ;is it > 9 ?
  158.     jr    c,notgrt
  159.     push    af        ;save the number
  160.     ld    a,'1'        ;Ok, save the 1 then
  161.     ld    (usrlev),a
  162.     pop    af        ;restore original
  163.     sub    10        ;make it now 0-5
  164. notgrt: add    a,'0'        ;make it ascii 0-15
  165.     ld    (usrlev+1),a    ;save for the message
  166.     pop    af        ;restore user+drive stuff
  167.     and    0fh        ;mask off user stuff
  168.     jr    drv
  169.  
  170. gotdrv: dec    a        ;make it 0-15
  171. drv:    ld    c,a        ;put it in c
  172.     add    a,'A'        ;make it ascii 'A'-'P'
  173.     ld    (drvnum),a    ;save it for the message
  174.     push    bc        ;save it
  175.     call    seldsk        ;for the bdos
  176.     pop    bc
  177.     call    disk        ;go and select it, hl will=dph
  178.                 ;address filled in above
  179.     ld    de,xltadr    ;address pointer
  180.     ld    bc,16        ;number to move
  181.     ldir            ;move 'em
  182.  
  183.     ld    de,signon
  184.     call    msgout
  185.     ld    hl,(bios)    ;get bios location
  186.     ld    l,0        ;make it cold boot address
  187.     push    hl        ;save for later
  188.     ld    de,-ccpo    ;ccp offset
  189.     add    hl,de        ;hl now points to the ccp
  190.     pop    de        ;get bios pointer in de
  191.     push    hl        ;save ccp pointer
  192.     push    de        ;save bios pointer
  193.     call    hexout        ;print hex out of hl
  194.     ld    de,bdos@    ;print bdos message
  195.     call    msgout
  196.     pop    hl        ;get bios pointer back
  197.     push    hl        ;save it again
  198.     ld    de,-bdoso    ;bdos offset
  199.     add    hl,de
  200.     call    hexout        ;print it in hex
  201.     ld    de,bios@    ;print bios message
  202.     call    msgout
  203.     pop    hl        ;get bios pointer back
  204.     call    hexout
  205.     ld    de,space    ;print tpa space
  206.     call    msgout
  207.     pop    hl        ;get ccp pointer
  208.     ld    de,-tpa        ;tpa
  209.     add    hl,de
  210.     push    hl        ;save this address pointer
  211.     call    decout        ;print it in decimal
  212.     ld    de,space2    ;print space w/out tpa
  213.     call    msgout
  214.     pop    hl
  215.     ld    de,ccplen    ;STANDARD ccp length
  216.     add    hl,de        ;add it on to last count
  217.     call    decout        ;and print it decimally
  218.     call    crlf
  219.  
  220. ;Now determine some information about the disk system
  221.  
  222.     ld    de,csv@        ;tell user where csv is
  223.     call    msgout
  224.     ld    hl,(csv)
  225.     call    hexout
  226.     ld    de,alv@        ;and where the alv is too
  227.     call    msgout
  228.     ld    hl,(alv)
  229.     call    hexout
  230.  
  231.     ld    a,(xltadr)    ;get lsb of xlt address
  232.     or    a        ;is it 0
  233.     jr    nz,okxlt
  234.     ld    a,(xltadr+1)    ;get msb
  235.     or    a
  236.     jr    nz,okxlt
  237.     ld    de,ntabl    ;tell user no sector trans
  238.     call    msgout
  239.     jr    tdpb
  240.  
  241. okxlt:    call    crlf
  242.     ld    hl,(dpb)    ;first we have to get # of secs
  243.     ld    de,spt        ;save in our internal one
  244.     ld    bc,15
  245.     ldir            ;move 'em
  246.  
  247.     ld    de,ttabl    ;trans table message
  248.     call    msgout
  249.     ld    hl,(spt)    ;get # of sects/track
  250.     ld    bc,0        ;the sector counter
  251.  
  252. pntsec: push    bc
  253.     push    de        ;save these
  254.     push    hl
  255.     ld    de,(xltadr)    ;point to the trans table
  256.     call    sectran        ;get the first sector
  257.     call    decout        ;hl has #, print it decimally
  258.     ld    a,','        ;a delimiter
  259.     call    chrout
  260.     pop    hl
  261.     pop    de        ;restore these
  262.     pop    bc
  263.     inc    bc        ;inc for next sector
  264.     dec    hl
  265.     ld    a,h        ;get sector count
  266.     or    l        ;check for 0
  267.     jr    nz,pntsec    ;loop until so
  268.  
  269. tdpb:    ld    hl,(alv)    ;point to allocation info
  270.     ld    de,(dsm)    ;get total block count-1
  271.     inc    de        ;make it total block count
  272.     call    pntmap        ;go and print a disk map
  273.  
  274.     ld    hl,(spt)    ;get sectors count
  275.     call    decout        ;print it
  276.     ld    de,dchar    ;point to message
  277.     call    msgout
  278.     ld    hl,(drm)    ;total # of dir entries
  279.     inc    hl
  280.     call    decout
  281.     ld    de,dent
  282.     call    msgout
  283.     ld    a,(al0)        ;get al0
  284.     call    binout        ;print it in binary
  285.     ld    a,' '        ;and a space
  286.     call    chrout
  287.     ld    a,(al1)        ;get al1
  288.     call    binout        ;print it in binary
  289.     call    crlf
  290.     call    crlf
  291.     ld    hl,(off)    ;get reserved track count
  292.     call    decout
  293.     ld    de,nres
  294.     call    msgout
  295.  
  296.     ld    a,(bsh)        ;get bsh
  297.     ld    b,a
  298.     ld    a,(blm)
  299.     add    a,b        ;get this value
  300.     ld    hl,bls        ;point to bls table (blm+bsh)
  301.     ld    c,a        ;put bsh+blm here for compare
  302.     ld    d,1        ;k block count
  303.     ld    b,5        ;# to check
  304. check:    ld    a,(hl)        ;get first one
  305.     cp    c        ;OK ?
  306.     jr    z,blok        ;yes-it's ok
  307.     ld    a,d
  308.     add    a,a        ;*2
  309.     ld    d,a
  310.     inc    hl
  311.     djnz    check        ;loop for all
  312.     ld    de,baddpb
  313.     call    msgout
  314.     jp    exit
  315.  
  316. blok:    ld    a,d
  317.     ld    (bsize),a    ;save block k size
  318.     ld    h,0
  319.     ld    l,a
  320.     call    decout        ;print it decimally
  321.  
  322.     ld    de,kpblk    ;print k/block
  323.     call    msgout
  324.  
  325.     ld    a,(bsh)        ;get the block shift factor
  326.     ld    l,a
  327.     ld    h,0
  328.     call    decout
  329.     call    crlf
  330.  
  331.     call    fndblk        ;check allocated dir blocks
  332.     push    de
  333.     ex    de,hl
  334.     call    decout
  335.     ld    de,dirblk    ;directory blocks
  336.     call    msgout
  337.  
  338.     pop    de        ;get dir blocks back
  339.     ld    hl,(dsm)    ;get total # of blocks-1
  340.     inc    hl        ;make it proper
  341.     or    a
  342.     sbc    hl,de        ;sub # of allocated dir blocks
  343.     ld    a,(bsize)    ;get # of k/block
  344.     dec    a        ;make it -1
  345.     ld    b,a
  346.     push    bc        ;save this
  347.     push    hl        ;save block count
  348.     call    add        ;add 'em up
  349.     ld    de,tdisk    ;disk size message
  350.     call    msgout
  351.  
  352.     pop    hl        ;restore total block count
  353.     ld    de,(free)    ;get free blocks
  354.     or    a
  355.     sbc    hl,de        ;get # blocks used
  356.     pop    bc
  357.     push    bc
  358.     push    de        ;total block count
  359.     call    add        ;add 'em up and print it
  360.     ld    de,kused
  361.     call    msgout
  362.  
  363.     pop    hl        ;get free # of blocks (pntmap)
  364.     pop    bc        ;get block size back
  365.     call    add        ;add 'em up
  366.     ld    de,sfree
  367.     call    msgout
  368.  
  369. exit:    ld    a,(ddisk)    ;get disk drive back
  370.     ld    c,a
  371.     push    bc
  372.     call    disk        ;install it as before
  373.     pop    bc
  374.     call    seldsk        ;for the bdos
  375.     ld    hl,(ccpsp)    ;get ccp stack pointer back
  376.     ld    sp,hl        ;remake it
  377.     ret            ;and return
  378.  
  379. pntmap: push    de        ;save bit count
  380.     push    hl        ;save byte pointer
  381.     ld    de,dmap        ;tell user what's happening
  382.     call    msgout
  383.     pop    hl
  384.     pop    de
  385.     ld    c,line        ;# on one line
  386. map:    ld    a,(hl)        ;get a byte
  387.     push    hl        ;save this
  388.     ld    b,8        ;8 bits/byte
  389. bpnt1:    rla            ;rotate bit into carry
  390.     push    af        ;save this
  391.     jr    c,one        ;was it a one ?
  392.     ld    hl,(free)    ;get free block count
  393.     inc    hl        ;inc it
  394.     ld    (free),hl    ;save it again
  395.     ld    a,'0'        ;make a 0
  396.     jr    pnt
  397.  
  398. one:    ld    hl,(block)    ;get used block count
  399.     inc    hl        ;inc it
  400.     ld    (block),hl    ;save it again
  401.     ld    a,'1'        ;make a one
  402. pnt:    call    chrout        ;print it
  403.     dec    c        ;dec line count
  404.     call    z,newl
  405.     dec    de        ;dec bit counter
  406.     ld    a,d        ;check for end of bits
  407.     or    e
  408.     jr    z,leave        ;end ?? yes-finished
  409.     pop    af        ;restore char
  410.     djnz    bpnt1        ;loop for 8 bits of the byte
  411.     pop    hl        ;restore byte pointer
  412.     inc    hl        ;inc to next byte
  413.     jr    map        ;loop for next byte fetch
  414.  
  415. leave:    pop    hl        ;relieve stack
  416.     pop    af
  417.  
  418.     ld    de,tblk
  419.     call    msgout
  420.     ld    hl,(dsm)    ;get total block count-1
  421.     inc    hl        ;make it correct
  422.     call    decout
  423.  
  424.     ld    de,used
  425.     call    msgout
  426.     ld    hl,(block)    ;get used block count
  427.     call    decout
  428.  
  429.     ld    de,left
  430.     call    msgout
  431.     ld    hl,(free)    ;get # of free blocks
  432.     call    decout
  433.  
  434. crlf:    ld    a,0dh
  435.     call    chrout
  436.     ld    a,0ah
  437.     call    chrout
  438.  
  439. chrout: push    hl
  440.     push    bc
  441.     push    de
  442.     ld    e,a
  443.     ld    c,2        ;send char to console
  444.     call    bdos
  445.     pop    de
  446.     pop    bc
  447.     pop    hl
  448.     ret
  449.  
  450. ;check al0 & al1 for directory block allocation and return # of
  451. ;allocated blocks in de
  452.  
  453. fndblk: ld    de,0        ;init counter
  454.     ld    b,8        ;bit counter
  455.     ld    a,(al0)        ;first this one
  456.     call    incblk        ;count some bits
  457.     ld    b,8        ;bit counter
  458.     ld    a,(al1)        ;and next this one
  459.  
  460. incblk: rla            ;rotate thru cy, set if block
  461.     jr    nc,inc        ;no-don't inc bit counter
  462.     inc    de        ;inc block counter
  463. inc:    djnz    incblk        ;loop for all bits
  464.     ret
  465.  
  466. ;add up (*2) the number in HL, B times and print it decimally
  467.  
  468. add:    add    hl,hl
  469.     djnz    add        ;add 'em all up
  470.     push    hl
  471.     call    decout
  472.     pop    hl
  473.     ret
  474.  
  475. newl:    call    crlf
  476.     ld    a,9
  477.     call    chrout
  478.     ld    a,9
  479.     call    chrout
  480.     ld    c,line
  481.     ret
  482.  
  483. msgout: ld    c,9        ;print $ terminated string
  484. bcall:    jp    bdos
  485.  
  486. seldsk: ld    e,c        ;select disk in 'C'
  487.     ld    c,14
  488.     jr    bcall
  489.  
  490. disk:    jp    0000        ;jump to select disk
  491.                 ;filled in at init time
  492. sectran:jp    0000        ;jump to sectran
  493.                 ;filled in at init time
  494.  
  495. ;print 16 bit value in HL in decimal
  496.  
  497. decout: push    hl
  498.     call    bdc
  499.     call    prtx
  500.     pop    hl
  501.     ret
  502.  
  503. bdc:    push    de
  504.     push    bc
  505.     ld    de,string
  506. loop:    call    div10
  507.     add    a,'0'
  508.     dec    de
  509.     ld    (de),a
  510.     ld    a,h
  511.     or    l
  512.     jr    nz,loop
  513.     ex    de,hl
  514.     pop    bc
  515.     pop    de
  516.     ret
  517.  
  518. div10:    ld    c,16
  519.     xor    a
  520. loop1:    adc    hl,hl
  521.     rla
  522.     dec    c
  523.     jr    z,term
  524.     cp    10
  525.     ccf
  526.     jr    nc,loop1
  527.     sub    10
  528.     scf
  529.     jr    loop1
  530.  
  531. term:    cp    10
  532.     ccf
  533.     jr    nc,bot
  534.     sub    10
  535.     scf
  536. bot:    adc    hl,hl
  537.     ret
  538.  
  539. prtx:    ld    a,(hl)
  540.     cp    '$'
  541.     ret    z
  542.     push    hl
  543.     call    chrout
  544.     pop    hl
  545.     inc    hl
  546.     jr    prtx
  547.  
  548.     defs    5
  549. string: defm    '$'
  550.  
  551. hexout: push    hl        ;save hex value
  552.     ld    a,'0'        ;a 0 first
  553.     call    chrout        ;print it
  554.     pop    hl        ;restore it
  555.     ld    a,h        ;get msb
  556.     call    hexout2        ;print it
  557.     ld    a,l        ;get lsb
  558.     call    hexout2        ;print it
  559.     ld    a,'h'        ;tack a 'h' on the end
  560.     jp    chrout        ;print it
  561.  
  562. hexout2:push    af
  563.     and    0f0h        ;mask right off
  564.     rrca            ;move
  565.     rrca            ;  it
  566.     rrca            ;   to
  567.     rrca            ;     the right
  568.     call    hexout3        ;print it
  569.     pop    af        ;get char back
  570.     and    0fh        ;mask left half off
  571. hexout3:cp    10        ;need letter
  572.     jr    c,hexout4    ;no
  573.     add    a,7        ;adjust for a-f
  574. hexout4:add    a,'0'        ;make it ascii
  575.     push    hl
  576.     call    chrout        ;print it and return
  577.     pop    hl
  578.     ret
  579.  
  580. ;output in binary the value in A
  581.  
  582. binout: ld    b,8        ;number to move
  583. bino1:    rla            ;move it left
  584.     push    af        ;save rotated value
  585.     jr    c,p1
  586.     ld    a,'0'
  587.     jr    pnt1
  588.  
  589. p1:    ld    a,'1'
  590. pnt1:    call    chrout
  591.     pop    af
  592.     djnz    bino1
  593.     ret
  594.  
  595. ;verify that we are running on a CP/M 2.0 or later
  596.  
  597. verify: ld    c,12
  598.     call    bdos
  599.     cp    20h        ;cp/m 2.0 or later
  600.     ret    nc        ;yes !!!!
  601.     ld    de,sorry    ;tell user
  602.     call    msgout
  603.     jp    exit        ;and exit
  604.  
  605.     end
  606.