home *** CD-ROM | disk | FTP | other *** search
-
- {* -------------------------------------------------------------------------
- * C P / M F I L E M A N A G E R U T I L I T I E S
- * ------------------------------------------------------------------------- *}
-
- procedure DeleteCpmFile ;
- {*
- * Delete the CP/M file associated with the current filelist entry.
- *}
- var
- CpmFib: CpmFibs absolute ACpmFile ; { Type casting file -> FIB }
- begin
- SplitFileName ( ACpmFileName, GetFileEntryName ) ;
- ACpmFileName.Drive:= CpmDriveName.Drive ;
- ACpmFileName.User := CpmDriveName.User ;
- {*
- * Build the FCB for the CP/M file by the invokation of procedure Assign.
- * The file attribute ReadOnly is reset, together with any other attribute,
- * in order to avoid BDOS errors when deleting the file. Note that BDOS
- * errors cause a premature termination of the program: the error handler
- * of TP does not gain control in such a case.
- *}
- RegisterFile ( ACpmFileName, ACpmFile ) ;
- Assign ( ACpmFile, ExpandFileName(ACpmFileName,DNE_Format) ) ;
- Bdos( SetFileAttributes, Addr(CpmFib.Fcb) ) ;
- Erase ( ACpmFile ) ;
- UnRegisterFile( ACpmFile ) ;
- end ; { of DeleteCpmFile }
-
- function GetCpmFreeSpace : Integer ;
- {*
- * Return the amount of free space, in KByte, on the current CP/M disk.
- *}
- var
- CpmDpb : ^DPBs ; { Address of drive's DPB (XLT) }
- BitMap : Integer ; { Address in memory of allocation bitmap }
- FreeBlocks: Integer ; { Number of free blocks on disk }
- BitNumber : Integer ; { Ordinal of next bit to test }
- I : Integer ; { Loop control variable }
- begin
- CpmCurrentDrive:= BdosHL( GetCurrentDrive ) ;
-
- Bdos( SetCurrentDrive, CpmDrive ) ; { Login CP/M disk, build bitmap }
- CpmDpb := DriveAttribute[ExtractDisk(CpmDriveName)].DpbAddress ;
- BitMap := BdosHL( GetAllocationMap ) ;
- FreeBlocks:= 0 ;
- for I:= 0 to CpmDpb^.DSM do
- begin
- BitNumber:= I and $0007 ;
- if ((Mem[BitMap] shr BitNumber) and $01)=$00 then
- FreeBlocks:= Succ( FreeBlocks ) ;
- if BitNumber=7 then
- BitMap := Succ( BitMap ) ;
- end ; { of for }
- GetCpmFreeSpace:= FreeBlocks shl (CpmDpb^.BSH-3) ;
-
- Bdos( SetCurrentDrive, CpmCurrentDrive ) ;
- end ; { of GetCpmFreeSpace }
-
- function LocateCpmFile : Boolean ;
- {*
- * Determine if an CP/M file, with the name given in the current filelist
- * entry, exists or not. If it exists, the function result is True and
- * the FIB ACpmFile is prepared for CP/M file operations.
- *}
- begin
- SplitFileName( ACpmFileName, GetFileEntryName ) ;
- ACpmFileName.Drive:= CpmDriveName.Drive ;
- ACpmFileName.User := CpmDriveName.User ;
- {*
- * Open this file for read access. If this is possible without any
- * error being detected, the file exists.
- *}
- RegisterFile( ACpmFileName, ACpmFile ) ;
- Assign( ACpmFile, ExpandFileName(ACpmFileName,DNE_Format) ) ;
- {$I-} Reset( ACpmFile ) ; {$I+}
- if IoResult=0 then
- begin
- Close( ACpmFile ) ;
- LocateCpmFile:= True ;
- end
- else
- LocateCpmFile:= False ;
- end ; { of LocateCpmFile }
-
- procedure ReadCpmDirectory ;
- {*
- * Build a filelist containing the files on the selected CP/M drive in the
- * selected user area.
- *}
- var
- {*
- * Define the layout of the directory entries as read from the disk. Note
- * that this definition inhibits the use of the CpmFCB for actual I/O, as
- * the last field(s) of the FCB are not stored on disk!
- *}
- Directory: array[0..3] of CpmFCBs absolute ClusterBuffer ;
-
- CpmUserNumber: Integer ; { Selected user number }
- CpmDpb : ^DPBs ; { DPB of selected CP/M drive }
- I, J, K : Integer ; { Loop control variables }
- begin
- PresetFileList ; { Cleanup the filelist }
-
- CpmUserNumber:= ExtractUser( CpmDriveName ) ;
- CpmDpb := DriveAttribute[ExtractDisk(CpmDriveName)].DpbAddress ;
- {*
- * Read the directory entries from disk. It is assumed that all the records
- * of the directory are located in the first data track of the disk.
- *
- * BDOS is NOT used to retrieve the file names for two reasons:
- * -1- reading the directory through BIOS is faster and
- * -2- it delivers at the same time the size of the individual files.
- *}
- Bios( SelectDrive , CpmDrive ) ; { Select CP/M disk drive }
- Bios( SelectTrack , CpmDpb^.OFF ) ; { Select track with directory }
- Bios( SelectBuffer, Addr(Directory) ) ; { Select buffer area }
- for I:= 0 to (CpmDpb^.DRM div 4) do
- begin
- Bios( SelectRecord, I ) ; { Select next record to read }
- Bios( ReadRecord ) ; { Read next directory record }
-
- for J:= 0 to 3 do
- with Directory[J] do
- if Drive=CpmUserNumber then
- begin
- New( FileEntry ) ;
- FileEntry^.Next:= Nil ;
- FileEntry^.Prev:= Nil ;
- FileEntry^.Attr:= [] ;
- FileEntry^.Mark:= False ;
- for K:= 1 to 11 do
- FileEntry^.Name[K]:= Chr( Ord(FileName[K]) and $7F ) ;
- if Ord(FileName[09])>$7F then
- FileEntry^.Attr:= [ReadOnly] ;
- if Ord(FileName[10])>$7F then
- FileEntry^.Attr:= FileEntry^.Attr + [System] ;
- FileEntry^.Size:= Extent*16 + (RecCnt+7) div 8 ;
-
- EnterFileInList ;
- end ; { of if/with/for }
- end ; { of for }
-
- FileEntry:= HeadFileList ; { Preset 'current' file }
- FileIndex:= 1 ;
- Bios( SelectDrive, CpmCurrentDrive ) ; { Reselect default drive }
- end ; { of ReadCpmDirectory }
-
- procedure SetCpmDrive ;
- {*
- * Select the drive and the user area as the default CP/M file area. It
- * must meet the following criteria:
- * 1- the user area is in the range [0,15],
- * 2- the drive is an existing CP/M drive,
- * 3- the drive is not the MS-DOS drive and
- * 4- the device address of the CP/M drive differs from the device
- * address of the MS-DOS drive.
- *}
- var
- DriveUserName : FullFileNames ; { New CP/M default drive & user }
- NewCpmDefault : FileDescriptors ; { New CP/M default drive & user }
- NewCpmDriveName: Char ; { New CP/M default drive name }
- Success : Boolean ; { SetCpmDrive succeeded }
- begin
- Write('Enter drive/user : ' ) ;
- ReadLn( DriveUserName ) ;
- DriveUserName:= DriveUserName + ':' ;
- SplitFileName( NewCpmDefault, DriveUserName ) ; { Crack string }
-
- Success:= False ; { Assume some error }
- if ExtractUser(NewCpmDefault) in [0..15] then
- begin
- NewCpmDriveName:= ExtractDisk( NewCpmDefault ) ;
- if NewCpmDriveName in (ConfiguredDrives-[MsdosDriveName]) then
- with DriveAttribute[NewCpmDriveName] do
- if DevAddress<>MsdosDriveAddress then
- begin
- CpmDrive := Ord(NewCpmDriveName) - Ord('A') ;
- CpmDriveName := NewCpmDefault ;
- CpmDriveAddress:= DevAddress ;
- Success := True ;
- end ; { of if/with/if }
- end ; { of if }
-
- if not Success then
- FlagError( 'SetCD: Illegal specification : ' +
- ExpandFileName(NewCpmDefault,DU_Format) ) ;
- end ; { of SetCpmDrive }
-