Write to a DOS File

From CometWiki

Jump to: navigation, search

Write to a DOS File

Syntax:

 DOSRW(AX-value, file-handle, number-of-bytes, format-statement-label) EXCP=statement-label  

Entry:

 AX-value = "@4000@"
                                                                                                                      .
 file-handle = file handle established when the file was opened
                                                                                                                       .
 number-of-bytes = number of characters to be written
                                                                                                                        .
 format-statement-label = format statement containing the data variables to be written to the DOS file


Return:
If the write function is successful, the data variable(s) contained in the format statement will be written to the DOS file, and the AX register will contain the number of bytes tha were actually written (in byte-reversed hex).

If an exception occurs, byte 2 of the AX field will contain the DOS error code (in hex).

Discussion:
The DOSRW function can be used to write data to a DOS file. The data to be written is listed in an Internet Basic format statement.
This function requires that the AX-value be set to "@4000@". The file's handle (established when the file was opened) must also be included in the function call.

Likewise, you must specify the number of bytes to be written to the DOS file and the label of the format statement containing the data to be written to the file.

After the function is executed, the DOS file will contain the data values from the format statement. Also, the AX register will contain the number of bytes that were actually written to the file. This value is in hex, so it will have to be converted to decimal to serve any meaningful purpose.

One application of this AX value is to test for a "disk full" condition. For example, if the number of bytes actually written to a DOS file is less than the number specified to be written, it means that there is no more room to write the data on the disk (i.e., the disk is full).

Example:

 ! S SFWRITE,DSK
 ! O FWRITE,DSK
 ! L T00,E
 ! R QMONITOR
 !
 !==========  WRITE TO A DOS FILE  ==============================
 !
 LENGTH 2 & LOCAL AX$,BX$,CX$,DX$        ! Define registers
            LOCAL FILEHANDLE$            ! Define file handle
 LENGTH 64 & LOCAL FILENAME$             ! Define file name
 !
 LENGTH 100 & LOCAL DATASTRING$          ! Define data string
 !
 LENGTH 3 & LOCAL DOSCODE$               ! Define DOS error code
 LENGTH 37 & LOCAL DOSMESSAGE$           ! Define DOS message
 !
 1000 FORMAT DOSMESSAGE$                 ! File input format
 !
 100 FORMAT (ET)                         ! Screen format
 !
 9999 FORMAT DATASTRING$                 ! File output format
 !
 CLEAR                                   ! Initialize variables
 PRINT (0,100)                           ! Set typewriter mode
 !
 PRINT (0) "NAME OF DOS FILE TO OPEN:"   ! Display prompt
 INPUT (0) FILENAME$                     ! Input file name
 IF FILENAME$ = "" THEN RUN "QMONITOR"   ! If null, then stop
 !
 AX$ = "@3D42@"                          ! Set AX to "OPEN FILE"
 CX$ = "@0000@"                          ! Set CX to null
 !
 DOSFC(AX$,CX$,FILENAME$) EXCP=EXCEPTION ! Open the file
 !
 FILEHANDLE$ = AX$                       ! Store file handle
 !
 WRITE: PRINT (0) "ENTER STRING TO WRITE TO DOS FILE:"
        INPUT (0) DATASTRING$
        IF DATASTRING$ = "" THEN GOTO BOTTOM
 !
        AX$ = "@4000@"                   ! Set AX to "WRITE"
        CX$ = "@0000@"                   ! Set CX to null
 !
        DOSRW(AX$,FILEHANDLE$,100,9999) EXCP=EXCEPTION
 !
 GOTO WRITE                              ! Loop back for more
 !
 BOTTOM: AX$ = "@3E00@"                  ! Set AX to "CLOSE FILE"
         BX$ = FILEHANDLE$               ! Set BX to file handle
         CX$ = "@0000@"                  ! Set CX to null
         DX$ = "@0000@"                  ! Set DX to null
         DOSMS(AX$,BX$,CX$,DX$)          ! Close the file
         RUN "QMONITOR"
 !
 EXCEPTION:                              ! Exception routine
 PRINT (0) "WRITE EXCEPTION"             ! Display message
 OPEN (1) "QERCOMET"                     ! Open error file
 DOSCODE$ = "D" + HEXASC(SUB(AX$,2,1))   ! Construct key to file
 READ (1,1000) KEY=DOSCODE$              ! Read error record
 PRINT (0) "DOS error code: ";DOSCODE$   ! Display DOS error code
 PRINT (0) DOSMESSAGE$                   ! Display error message
 INPUT (0) ""                            ! Hold
 CLOSE (1)                               ! Close error file
 RUN "QMONITOR"                          ! Exit
 END
Personal tools