home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / lambda / soundpot / p / z33rcp02.lbr / RCPSP.LZB / RCPSP.LIB
Encoding:
Text File  |  1993-10-25  |  3.8 KB  |  134 lines

  1.     page
  2.  
  3. ; RCP-SP.Z80    'SP' Command
  4.  
  5. ;=============================================================================
  6. ;
  7. ;    D I S K    S P A C E    C O M M A N D
  8. ;
  9. ;=============================================================================
  10.  
  11. ; Command:    SP
  12. ; Function:    Shows space remaining on designated drive
  13. ; Syntax:    SP [DIR:|DU:]
  14. ; Comments:    This code can be called by several other RCP commands so that
  15. ;        they can show the space remaining on the disk after their
  16. ;        operation.
  17.  
  18.      if    [erasp or cpsp or dirsp]
  19. crspace:            ; Used to call space after other subroutines
  20.     call    crlf        ; Start new line
  21.      endif    ;[erasp or cpsp or dirsp]
  22.  
  23. space:
  24.     ld    a,(fcb1)    ; Determine requested drive
  25.     or    a        ; If drive explicitly selected
  26.     jr    nz,space1    ; ..then skip
  27.  
  28.     ld    c,25        ; BDOS get current drive function
  29.     call    bdos
  30.     inc    a        ; Shift to range 1..16
  31.  
  32. space1:
  33.     dec    a        ; Shift to range 0..15
  34.     ld    e,a        ; Save in E for selecting disk below
  35.     add    'A'        ; Convert to letter and
  36.     ld    (seldrv),a    ;   save in message string below
  37.     ld    c,14        ; BDOS select disk function
  38.     call    bdos        ; Not needed if no drive selected, but smallest
  39.                 ; ..possible code size this way.
  40.  
  41. ; Here we extract the following disk parameter information from the disk
  42. ; parameter block (DPB):
  43. ;    BLKSHF: block shift factor (1 byte)
  44. ;    BLKMAX:    max number of blocks on disk (2 bytes)
  45.  
  46. dparams:
  47.     ld    c,31        ; BDOS get disk parameters function
  48.     call    bdos
  49.     inc    hl        ; Advance to block shift factor byte
  50.     inc    hl
  51.     ld    a,(hl)        ; Get value and
  52.     ld    (blkshf),a    ; ..save it in code below
  53.     inc    hl        ; Advance to max block number word
  54.     inc    hl
  55.     inc    hl
  56.     ld    e,(hl)        ; Get value into HL
  57.     inc    hl
  58.     ld    d,(hl)
  59.     inc    de        ; Add 1 for max number of blocks
  60.  
  61. ; Compute amount of free space left on disk
  62.  
  63. dfree:
  64.     ld    c,27        ; BDOS get allocation vector function
  65.     push    de        ; Save BLKMAX value
  66.     call    bdos        ; Get allocation vector into HL
  67.     ld    b,h        ; Copy allocation vector to BC
  68.     ld    c,l
  69.     pop    hl        ; Restore MAXBLK value to HL
  70.     ld    de,0        ; Inititialize count of free blocks
  71.  
  72. ; At this point we have
  73. ;    BC = allocation vector address
  74. ;    DE = free block count
  75. ;    HL = number of blocks on disk
  76.  
  77. free1:
  78.     push    bc        ; Save allocation address
  79.     ld    a,(bc)        ; Get bit pattern of allocation byte
  80.     ld    b,8        ; Set to process 8 blocks
  81. free2:
  82.     rla            ; Rotate allocated block bit into carry flag
  83.     jr    c,free3        ; If set (bit=1), block is allocated
  84.     inc    de        ; If not set, block is not allocated, so
  85.                 ; ..increment free block count
  86. free3:
  87.     ld    c,a        ; Save remaining allocation bits in C
  88.     dec    hl        ; Count down number of blocks on disk
  89.     ld    a,l        ; See if we are down to zero
  90.     or    h
  91.     jr    z,free4        ; Branch if no more blocks to check
  92.     ld    a,c        ; Get back current allocation bit pattern
  93.     djnz    free2        ; Loop through 8 bits
  94.     pop    bc        ; Get pointer to allocation vector
  95.     inc    bc        ; Point to next allocation byte
  96.     jr    free1        ; Continue by processing next allocation byte
  97.  
  98. free4:
  99.     pop    bc        ; Clean up stack
  100.     ex    de,hl        ; Free block count to HL
  101. blkshf    equ    $+1        ; Pointer for in-the-code modification
  102.     ld    a,0        ; Get block shift factor
  103.     sub    3        ; Convert to log base 2 of K per block
  104.     jr    z,free6        ; Done if single density (1k per block)
  105.  
  106. ; Convert for blocks of more than 1K each
  107.  
  108. free5:
  109.     add    hl,hl
  110.     dec    a
  111.     jr    nz,free5
  112.  
  113. ; At this point HL = amount of free space on disk in K
  114.  
  115. free6:
  116.     call    print
  117.     db    ' Space on '
  118. seldrv:    db    0        ; Modified above to contain drive letter
  119.     db    ':',[' '+80h]
  120.  
  121. ; Display decimal value of HL
  122.  
  123.     ld    b,0        ; Initialize count of digits already printed
  124.     ld    de,10000    ; Divisor in DE
  125.     call    decdsp        ; Print digit (or space if leading '0')
  126.     ld    de,1000
  127.     call    decdsp
  128.     call    decdsp3        ; Display hundreds, tens, and units
  129.     ld    a,'K'
  130.     jp    conout        ; Final return from space routine
  131.  
  132. ; End RCP-SP.Z80
  133.  
  134.