Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!husc6!seismo!rochester!ur-tut!ur-cvsvax!srs!dan From: dan@srs.UUCP Newsgroups: comp.sys.ibm.pc Subject: Re: ioctl on msdos device drivers Message-ID: <150@srs.UUCP> Date: Mon, 13-Apr-87 13:36:40 EST Article-I.D.: srs.150 Posted: Mon Apr 13 13:36:40 1987 Date-Received: Sat, 18-Apr-87 02:28:04 EST References: <959@rocksvax.UUCP> <4490002@hpcvck.HP> Organization: S.R.Systems Lines: 136 > I would also be interested in what people have to say about > setting ioctl for devices like printers. I have been trying > to write a graphics dump routine for my MSDOS computer (not IBM > compatible), and was having trouble. I was opening the printer > as a binary device, but MSDOS was *not* treating like a binary > device/file. If I wrote the info to a file first, then did > COPY PRN: /B, it printed the info fine. > I am mainly interested in setting devices to raw/cooked mode from > C. Any help would be appreciated. > > Scott Linn > hplabs!hp-pcd!scott Exactly my experience. (The /b option on copy is also useful for blasting text files to the screen because, in RAW mode, DOS sends the entire write request to the device rather than breaking it up into single bytes as it does in cooked mode.) Here follows Microsoft C code for setting handles to raw mode. It was posted in February, but merits reposting. - Dan Kegel /*--- rawmode.c ------------------------------------------------- Routines to set and reset raw mode for Microsoft C. Stolen from the sources to the mighty game Hack. Thanks to Mark Zbikowski (markz@microsoft.UUCP). Applications should set stdout to raw mode when they start up, and set it back to the old mode when terminating. Programs which rely on cooked mode will appear to hang in raw mode because, in raw mode, keyboard reads don't terminate when the user hits ENTER; they continue until the line buffer is full. ------------------------------------------------------------------*/ #include #include #define DEVICE 0x80 #define RAW 0x20 #define IOCTL 0x44 #define STDIN fileno(stdin) #define STDOUT fileno(stdout) #define GETBITS 0 #define SETBITS 1 static unsigned old_stdin, old_stdout, ioctl(); #define BREAKCHECK 0x33 static unsigned old_breakchk, breakctl(); /*---- SetHandleRaw ----------------------------------------------------- Given any file handle, sets it into raw mode. Useful when opening handles to printers, COM ports, etc., as it lets you output ^Z chars without fear. -------------------------------------------------------------------------*/ void SetHandleRaw(handle) short handle; { int temp; temp = ioctl(handle, GETBITS, 0); if (temp & DEVICE) ioctl(handle, SETBITS, temp | RAW); } /*---- rawgetchar --------------------------------------------------- Read a character from keyboard with neither echo nor ^C-checking. Used by editors, etc., which can't afford to let themselves be killed by the user, or who want to use ^C for a function key. ----------------------------------------------------------------------*/ int rawgetchar() { return (0xff & bdos(7, 0, 0)); } /*--- set_raw --------------------------------------------------------- Call this to set raw mode; call restore_raw() later to restore console to old rawness state. (Don't strand user in RAW mode!) Not only sets raw mode, but also turns off ^C trapping on random DOS calls. All character input from stdin should be done with rawgetchar() to avoid ^C trapping on input. -----------------------------------------------------------------------*/ set_raw() { old_stdin = ioctl(STDIN, GETBITS, 0); old_stdout = ioctl(STDOUT, GETBITS, 0); old_breakchk = breakctl(GETBITS, 0); if (old_stdin & DEVICE) ioctl(STDIN, SETBITS, old_stdin | RAW); if (old_stdout & DEVICE) ioctl(STDOUT, SETBITS, old_stdout | RAW); (void) breakctl(SETBITS, 0); } restore_raw() { if (old_stdin) (void) ioctl(STDIN, SETBITS, old_stdin); if (old_stdout) (void) ioctl(STDOUT, SETBITS, old_stdout); if (old_breakchk) (void) breakctl(SETBITS, old_breakchk); } static unsigned ioctl(handle, mode, setvalue) unsigned setvalue; { union REGS regs; regs.h.ah = IOCTL; regs.h.al = mode; regs.x.bx = handle; regs.h.dl = setvalue; regs.h.dh = 0; /* Zero out dh */ intdos(®s, ®s); return (regs.x.dx); } /* Controls ^C - checking during everything except keyboard reads */ static unsigned breakctl(mode, setvalue) unsigned setvalue; { union REGS regs; regs.h.ah = BREAKCHECK; regs.h.al = mode; regs.h.dl = setvalue; intdos(®s, ®s); return (regs.x.dx & 0xff); } /*------ end of rawmode.c ----------------------------------------------*/