April 11, 1999
This page provides hints for accomplishing tasks that might be required by a quiz program operating on an IBM-PC in an MS-DOS environment. Don't worry, we won't give away all the answers!
Don't be surprised by the blank spaces. This page is under construction.
The MS-DOS environment is command-line oriented. Typical programs provide command-line arguiments in a UNIX-like syntax, but the conventions are less definite. Any "UNIX-like" syntax is probably appropriate here -- why change what you already have?
The C main function under Turbo/Borland C/C++ will deliver the argc and argv parameters in the same form as in UNIX. There is no further parsing support provided.
The ANSI clear sequences should work here, if you have ANSI.SYS defined as a driver in your CONFIG.SYS file.
ANSI standard functions should be usable here. Remember to seed the generator with a "random" value such as the current time or the content of a memory location from the video area, etc.
Remember that PC memory is not always vast, and segments (and therefore data structures) are limited to 64K bytes each. You aren't insisting on reading the whole question file into memory at once, are you?
MS-DOS has no concept of user identity, logins, or file protection in the Unix/VMS sense. There is a small set of attributes which may be assigned to files in very special cases, such as SYSTEM or HIDDEN. These are best avoided by portable programs.
The MS-DOS filesystem is hierarchical (since Version 2.0). The full name of a file is a pathname which may include directory components separated by backslashes. If the pathname begins with a backslash it is absolute; otherwise it is relative to the current directory.
A full MS-DOS pathname should provide for a "drive name" prefix which is usually a letter, e.g., C:. To avoid confusion pathnames with a drive name included should be absolute.
MS-DOS filenames may be up to 8 characters which are pretty much limited to letters and numbers. Names are not case sensitive. The OS converts everything to upper case. Names are extended by a dot and 0-3 letters representing a file type. Types have little meaning to MS-DOS but are interpreted by applications.
Remember that filenames are probably system dependent and full pathnames are positively non-portable. Avoid explicit pathnames in your code where possible.
There is no standard convention for program-specific data file names. The standard ANSI C functions tmpfile and tmpnam can be used to create temporary files and to generate file names which are guaranteed unique.
ANSI functions can be used, or time can be measured as discussed in the next section.
PC-compatible architectures running MS-DOS provide the ability to initiate timed events at the system-call (interrupt) level. All models can do this using the system clock tick interrupt, but a cleaner solution is available using the real-time clock chip present in most models.
Two subfunctions of interrupt 1AH can be used to determine the current time, and to set an alarm for a future (absolute) time. When the alarm time is reached, interrupt 4AH (not 1AH!) is triggered. The alarm handler must be attached to this vector.
The Borland/Turbo C functions getvect and setvect may be used to save the previous handler for 4AH and replace it with your own handler. The handler itself is a Turbo C interrupt function. Details are in the Turbo C Reference Manual and User's Guide or the online documentation.
The function int86 can then be used to obtain the time and set the desired alarm time. These subfunctions are selected by setting AH to 02H or 06H, respectively, before calling the interrupt. Get Time returns the current hour, minute and second in CH, CL, and DH, respectively, all in BCD format. Set Alarm accepts time values in the same format in these same three registers. A soft register block must be setup as a struct union REGS as specified in the manual. Significant input register values are placed in this block before an int86 call, and results are found in the same block after the return.
For all of this it is necessary to include the header file <dos.h>, and to set the compiler source option to Turbo C (or C++) keywords rather than ANSI keywords.
TO BE ADDED: