Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI713.ASC

 
Output of file : TI713.ASC contained in archive : C-ALL.ZIP







PRODUCT : Borland C++ NUMBER : 713
VERSION : 2.0
OS : DOS
DATE : September 18, 1991 PAGE : 1/3

TITLE : Switching a Device Driver Between Cooked and Raw Mode




/**************************************************************************
FUNCTION: setdevmode

PURPOSE:
This function will swap a device driver
associated with the given stream into either a
raw (binary) or a cooked (ASCII) mode. This is
useful for outputting to the screen or printer in
a binary mode. Note that once this bit is set
all output to the device is received from the
device driver in the mode indicated by bit 5.
This is true even if you do not use a binary read
or write command.

METHOD:
This function will call, via the ioctl()
function, int 21h / function 44h / subfunction 0
to get the current device status word. The high
order byte of the word is then cleared and then
bit 5 is set to the selected mode. The ioctl() is
then again called this time using subfunction 1
to set a new status.

PARAMETERS:
This function takes two arguments, both are type
integer. The first is the number of the handle
associated with the targeted device driver. The
second is the mode the device driver is to be put
into:

1 = raw (binary) mode
2 = cooked (ASCII) mode

All other values for parameters are invalid and
will generate an error.

RETURN VALUE:
This function will return a 0 on error, 1 if
the new mode is raw and 2 if the new mode is
cooked.
















PRODUCT : Borland C++ NUMBER : 713
VERSION : 2.0
OS : DOS
DATE : September 18, 1991 PAGE : 2/3

TITLE : Switching a Device Driver Between Cooked and Raw Mode




IMPLEMENTATION:
This function can be implemented by including the
prototype: " int setdevmode( int, int); " within
file scope of your calling program. Within file
scope implies external to all functions. You
would then need to compile this file and link it
into the executable. Once this is done you can
simply make function calls to setdevmode() like
any other function.

***********************************************************************/

#include

int setdevmode(int handle, int mode)
{
int ret, /* Function return value */
word, /* Device driver status */
mask = 0x0020, /* Mask to set bit 5 */
mask2 = 0x00ff, /* Mask to clear high order bits */
mask3 = 0x00df; /* Mask to clear bit 5 */

if( mode < 1 || mode >2 ) /* Check for a valid mode */
return (0);

word = ioctl( handle, 0, 0, 0 ); /* Get current driver status*/
if( word == -1 ) /* Check for an error */
return (0);

word &= mask2; /* Clear high order bits */
if( word & mask ) /* Check if bit 5 is set (raw) */
{
if( mode == 2 ) /* Check if ASCII is requested */
word &= mask3; /* Clear bit 5 setting cooked */
}
else
if( mode == 1 ) /* Check if binary is requested */
word |= mask; /* Set bit 5 setting raw */

ret = ioctl( handle, 1, word, 0); /* Change the device driver
status */















PRODUCT : Borland C++ NUMBER : 713
VERSION : 2.0
OS : DOS
DATE : September 18, 1991 PAGE : 3/3

TITLE : Switching a Device Driver Between Cooked and Raw Mode




if( ret == -1 ) /* Check for an error */
return (0);
else
return (mode); /* Return new device driver mode */
}














































  3 Responses to “Category : C Source Code
Archive   : C-ALL.ZIP
Filename : TI713.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/