Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ukma!husc6!cmcl2!rna!marc From: marc@rna.UUCP (Marc Johnson) Newsgroups: comp.sys.ibm.pc Subject: Re: using files in C on the IBM PC Keywords: raw cooked binary Message-ID: <698@rna.UUCP> Date: 4 Jul 89 00:15:17 GMT References: <114@rm1.UUCP> Reply-To: marc@rna.UUCP (Marc Johnson) Organization: Rockefeller University Neurobiology Lines: 92 In article <114@rm1.UUCP> davis@rm1.UUCP (Gary A. Davis) writes: > >This is in response to an article about ascii/binary and raw/cooked >I/O from Tom Almy. > >At then end, Tom >mentioned that he always issued the DOS calls directly to set raw >mode (for the printer). What commands are these? I am sort of new to >the IBM PC world. I have a graphics file to print generated by a >filter and it happens to contain bit codes that happen to look like >CR/LFs and ^Zs. I can print the file ok by COPY/B FILE PRN (I think >this is the command I used). It fails due to a ^Z byte using the PRINT >FILE command. I would like to use the spooler via the PRINT but is >there a binary option? The filter creates the file but I think there >are problems redirecting it to the printer. The filter does open the >output (stdout) as binary (via setmode()) and is getting created ok >when it is a disk file, but not when redirected as in: > > filter < input.fil > PRN > >Any ideas on this? Thanks... > >Gary >-- > Gary A. Davis > Racal-Milgo, P.O. Box 407044, Fort Lauderdale, Fl 33340, (305) 476-4393 > > {{mailrus,gatech}!uflorida,ucf-cs}!novavax!rm1!davis I don't have any ideas on how to get around the ^Z problem, but I can help you with the DOS calls aprt of your question. DOS provides some low-level system calls to perform basic system tasks. You can access these by using interrupt 21 (INT 21). You'll need some kind of DOS reference to learn what all the DOS calls are (Microsoft Press publishes an excellent DOS Programmer's Reference, and IBM of course has a manual on this, though I forget just which one it is). I do believe there is a call to twiddle the printer to the proper mode for raw I/O, but you'll need the reference work to do it. You'll need to include a header file (Microsoft C calls it "dos.h", I think Lattice calls it "dosregs.h") which defines a struct for the registers. You have to load the registers with the proper values for the DOS call, including the ID of the call you want, then call C's intdos() or int86() or equivalent in your C to get the INT 21. It's not tough once you've seen it done once or twice. Here's an example, in Microsoft C 4.0 to get the current date and time from INT 21 and convert them to DOS directory format: /* * dir_date - Get current date and time from DOS and convert to directory form */ #include dir_date(date, time) unsigned *date, *time; { union REGS iregs, oregs; /* get current date */ iregs.h.ah = 0x2A; /* DOS call 2A in high-byte of register A */ intdos(&iregs, &oregs); /* do INT 21 */ /* * The union oregs contains the results: * register C (word) contains year, * high-byte of register D has month, * low-byte of register D has day */ *date = ((oregs.x.cx - 1980) << 9) | (oregs.h.dh << 5) | oregs.h.dl; /* get current time */ iregs.h.ah = 0x2C; /* DOS call 2C in high-byte of register A */ intdos(&iregs, &oregs); /* do INT 21 */ /* * The union oregs contains the results in registers C and D */ *time = (oregs.h.ch << 11) | (oregs.h.cl) << 5) | ((oregs.h.dh >> 1) & 0x1f); } For calls that could have errors you should check the error as indicated in the DOS call description (usually, the carry is set, and you need to check one of the registers). Good luck. marc =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= = Marc Johnson BITNET: rna!marc@rockvax.bitnet = = Rockefeller Univ. Neurobiology UUCP: ...cmcl2!rna!marc = = New York City INTERNET: marc%rna@rocky2.rockefeller.edu = = (129.85.2.1) = = = = "Gimme the beat boys and free my soul, I wanna get lost in your rock & roll = = ...and drift away" = =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=