In order for this site to work correctly, and for us to improve the site, we need to store a small file (called a cookie) on your computer.
By continuing to use this website, you agree to our cookies and privacy policy.
  
Home page Home page Home page Home page
Pixel
Pixel Header R1 C1 Pixel
Pixel Header R2 C1 Pixel
Pixel Header R3 C1 Pixel
Pixel

DOS Interfacing (Part II)

Issue 4 considered the routines available for querying the DOS environment. This month's investigates the routines available for interfacing to DOS and DOS file structures. Whilst some of these routines are documented we will consider how their use may be extended. It is worth pointing out that this article is NOT exhaustive, there are other routines that can be used to interface to DOS - these will be covered at a later date.

OSOPEN

Internal statement. Used to open a DOS file for direct access. If an attempt is made to open a DOS file that does not exist, an error code of 4 will be returned in STATUS(). If an attempt is made to open a DOS subdirectory, an error code of 2 will be returned in STATUS(). Thus to see if a DOS directory exists, OSOPEN it and check the status. If the status is 2, the directory exists, if 2 a file exists with that name.

OPEN

Internal statement. The normal OPEN command can be used to access the various DOS special devices. Thus the printer could be addressed directly by


0001           OPEN "PRN" TO PRN.FILE THEN
0002              WRITE STRING TO PRN.FILE
0003           END

SETPTR

External subroutine (C or Assembler). Used by PDISK to redirect printer output to file. Passed Filename and Flag, returns Flag indicating status or requested operation. Filename must be appended with a CHAR(0) (this tends to imply a 'C' routine as 'C' uses CHAR(0) as an end of string marker). Flag should be set on entry to 1 for overwrite existing file or 0 for no overwrite.


0001           FILENAME = "C:\AREV\PRN.DAT"
0002           FILENAME := CHAR(0)
0003           FLAG = 1
0004           CALL SETPTR(FILENAME,FLAG)

The exit conditions are, unfortunately not just 0 or 1! They appear not to conform to the standard OSOPEN error conditions, but those of which I am aware are

         2    Invalid Path
         3    No such path
         5    Access denied
         20   File exists
         21   Redirected OK

IMPORT.READ

External subroutine. Used to read records sequentially from a DOS file. With this routine, if the filename and dos delimiters/record length are known, the developer can sequentially access records in a DOS file without access to OSBREAD! The calling syntax is


0001           CALL IMPORT.READ(A,B,C,D,E,F,G)

where

         A    is the DOS file var (OSOPENED)
         B    is the offset within the file
         C    is the record delimiter
         D    is the End of File marker
         E    is the record length
         F    is the record returned
         G    is a flag indicating OK (1) or EOF (2).

Thus to process all records in TEST.DAT which is a CRLF delimited ASCII file with Ctrl-Z as EOF we would


0001           OSOPEN "TEST.DAT" TO A ELSE STOP
0002           B = 0 ; * offset, auto-incremented
0003           C = CHAR(13) : CHAR(10)
0004           D = CHAR(26)
0005           E = ""
0006           F = "" ; G = ""
0007           LOOP
0008           UNTIL G = 2 DO
0009                CALL IMPORT.READ(A,B,C,D,E,F,G)
0010                PRINT F
0011           REPEAT

INP

Used to query a port address directly. As this is so hardware specific it can be dangerous to use as it is not portable.

OUT

Used to output to a port address directly. As this is so hardware specific it can be dangerous to use as it is not specific.

FILE.SIZE

A function passed one parameter, the name of the Revelation file that is being sized. The routine returns the size of the DOS file indicating the overflow frames. Using this in conjunction with the DISKSIZE function allows the programmer to see whether there is enough space on disk for a file before attempting to move it, eg


0001           DECLARE FUNCTION FILE.SIZE,DISKSIZE
0002           DECLARE SUBROUTINE MSG
0003           SPACE.NEEDED = FILE.SIZE("BP")
0004           AVAILABLE       = disksize("C")<2>
0005           IF SPACE.NEEDED > AVAILABLE THEN
0006                MSG("ERROR - No Room","","","")
0007           END ELSE
0008                *
0009                * Transfer logic here
0010                *
0011           END

(Volume 1, Issue 6, Pages 4,5)
Pixel
Pixel Footer R1 C1 Pixel
Pixel
Pixel
Pixel