mov cx, cRecords ;number of records to write
mov dx, seg FileFCB
mov ds, dx
mov dx, offset FileFCB ;ds:dx points to FCB
mov ah, 28h ;Random Block Write
int 21h
cmp al, 0 ;zero means success
jne error_handler
Random Block Write (Function 28h) writes the data at the current disk transfer address (DTA) to one or more records in the file identified by the file control block (FCB).
This function has been superseded by Write File or Device (Function 40h) and Move File Pointer (Function 42h).
cRecords
Specifies the number of records to write.
FileFCB
Points to an FCB structure that identifies an open file. The structure must have been previously filled by using Open File with FCB (Function 0Fh) or Create File with FCB (Function 16h). Also, the fcbRandomRecNo field must specify the first record to write. The FCB structure has the following form:
FCB STRUC
fcbDriveID db ? ;drive no. (0=default, 1=A, etc.)
fcbFileName db '????????' ;filename
fcbExtent db '???' ;file extension
fcbCurBlockNo dw ? ;current block number
fcbRecSize dw ? ;record size
fcbFileSize db 4 dup (?) ;size of file in bytes
fcbFileDate dw ? ;date file last modified
fcbFileTime dw ? ;time file last modified
fcbReserved db 8 dup (?) ;reserved
fcbCurRecNo db ? ;current record number
fcbRandomRecNo db 4 dup (?) ;random record number
FCB ENDS
For a full description of the FCB structure, see Chapter 3, “File System.”
If the function is successful, the AL register contains 00h. Otherwise, the AL register contains 01h if the disk is full or 02h if the DTA overlapped a segment boundary. In either case, the write operation is canceled.
If the function returns 00h or 01h, the CX register contains the number of records actually written.
MS-DOS updates the fcbCurBlockNo and fcbCurRecNo fields in the FCB structure to agree with the fcbRandomRecNo field before it attempts to write the records to the disk. The block and record fields are incremented after a successful write operation; successive calls to this function write sequential groups of records to the file.
This function can be used to write files on a network drive but only if the network has granted write (or similar) access to the given file or drive.
Function 0Fh Open File with FCB
Function 16h Create File with FCB
Function 22h Random Write
Function 27h Random Block Read
Function 40h Write File or Device
Function 42h Move File Pointer