tips:revmedia:v1i6a3

DOS Interfacing (Part II)

Published ByDateVersionKnowledge LevelKeywords
Sprezzatura Ltd01 NOV 19891.15+EXPERTDOS, OSOPEN, OPEN, SETPTR, IMPORT.READ, INP, OUT, FILE.SIZE, DISKSIZE, STATUS

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.

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.

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

         OPEN "PRN" TO PRN.FILE THEN
            WRITE STRING TO PRN.FILE
         END

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.

         FILENAME = "C:\AREV\PRN.DAT"
         FILENAME := CHAR(0)
         FLAG = 1
         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

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

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

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

where

Ais the DOS file var (OSOPENED)
Bis the offset within the file
Cis the record delimiter
Dis the End of File marker
Eis the record length
Fis the record returned
Gis 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

         OSOPEN "TEST.DAT" TO A ELSE STOP
         B = 0 ; * offset, auto-incremented
         C = CHAR(13) : CHAR(10)
         D = CHAR(26)
         E = ""
         F = "" ; G = ""
         LOOP
         UNTIL G = 2 DO
              CALL IMPORT.READ(A,B,C,D,E,F,G)
              PRINT F
         REPEAT

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

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.

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

         DECLARE FUNCTION FILE.SIZE,DISKSIZE
         DECLARE SUBROUTINE MSG
         SPACE.NEEDED = FILE.SIZE("BP")
         AVAILABLE       = disksize("C")<2>
         IF SPACE.NEEDED > AVAILABLE THEN
              MSG("ERROR - No Room","","","")
         END ELSE
              *
              * Transfer logic here
              *
         END

(Volume 1, Issue 6, Pages 4,5)

  • tips/revmedia/v1i6a3.txt
  • Last modified: 2024/06/19 20:20
  • by 127.0.0.1