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
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB1.LBR
/
SDIR03.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
83 lines
;
; SYSLIB Module Name: SDIR03
; Author: Richard Conn
; Part of SYSLIB3 SDIR Series
; SYSLIB Version Number: 3.6
; Module Version Number: 1.5
public dfree
MACLIB SDIRHDR.LIB
;*
;* COMPUTE AMOUNT OF FREE SPACE LEFT ON DISK
;* ON EXIT, DE=AMOUNT OF FREE SPACE ON DISK IN K
;* THE DPARAMS ROUTINE MUST BE CALLED BEFORE THIS ROUTINE IS USED
;*
DFREE:
PUSH BC ; SAVE REGS
PUSH HL
PUSH AF
LD C,27 ; GET ADDRESS OF ALLOCATION VECTOR
CALL BDOS
EX DE,HL
LD HL,(BLKMAX) ; GET LENGTH OF ALLOCATION VECTOR
LD BC,0 ; INIT BLOCK COUNT TO 0
;*
;* BC IS ACCUMULATOR FOR SPACE
;*
FREE1:
PUSH DE ; SAVE ALLOC ADDRESS
LD A,(DE) ; GET BIT PATTERN OF ALLOCATION BYTE
LD E,8 ; SET TO PROCESS 8 BLOCKS
FREE2:
RLA ; ROTATE ALLOCATED BLOCK BIT INTO CARRY FLAG
JP C,FREE3 ; IF SET (BIT=1), BLOCK IS ALLOCATED
INC BC ; IF NOT SET, BLOCK IS NOT ALLOCATED, SO INCREMENT
; FREE BLOCK COUNT
FREE3:
LD D,A ; SAVE REMAINING ALLOCATION BITS IN D
DEC HL ; COUNT DOWN NUMBER OF BLOCKS ON DISK
LD A,L
OR H
JP Z,FREE4 ; DONE IF NO MORE BLOCKS LEFT
LD A,D ; A=CURRENT ALLOCATION BIT PATTERN
DEC E ; HAVE ALL 8 BITS BEEN EXAMINED?
JP NZ,FREE2 ; CONTINUE IF NOT
POP DE ; GET POINTER TO ALLOCATION VECTOR
INC DE ; POINT TO NEXT ALLOCATION BYTE
JP FREE1 ; CONTINUE BY PROCESSING NEXT ALLOCATION BYTE
;*
;* BC = TOTAL AMOUNT OF FREE SPACE IN TERMS OF BLOCKS
;*
FREE4:
POP DE ; CLEAR DE FROM STACK
LD L,C ; HL=BC=NUMBER OF FREE BLOCKS
LD H,B
LD A,(BLKSHF) ; GET BLOCK SHIFT FACTOR
SUB 3 ; CONVERT NUMBER OF BLOCKS TO K
JP Z,FREE6 ; DONE IF SINGLE DENSITY (1K PER BLOCK)
;*
;* WE ARE AT A MORE ADVANCED DENSITY LEVEL; MULTIPLY THE NUMBER OF BLOCKS
;* BY THE SIZE OF A BLOCK IN K
;*
FREE5:
ADD HL,HL ; 2, 4, 8, 16, ETC K/BLK, SO BLOCK SHIFT FACTOR
DEC A ; IS A POWER-OF-TWO MULTIPLE
JP NZ,FREE5
;*
;* AT THIS POINT, HL=AMOUNT OF FREE SPACE ON DISK IN K
;*
FREE6:
EX DE,HL ; DE=ANSWER
POP AF ; RESTORE REGS
POP HL
POP BC
RET
END