DPRG
DPRG List  



[DPRG] Changing Printer Ports in C++

Subject: [DPRG] Changing Printer Ports in C++
From: Ed Okerson eokerson at texasconnect.net
Date: Sun Aug 31 17:42:01 CDT 2003

Did you look in stdio.h to see how stdprn is set up?  That might give some
clues on how to create another stream that talks to a device.  Or you can
always write to the port with biosprint(int cmd, int abyte, int port)

Where cmd can be:
 0 - prints the character in abyte
 1 - initialize the port
 2 - read printer status

abyte can be any value from 0 to 255

and port = 0 is LPT1 , 1 is LPT2 etc.

This will only write to the port one byte at a time, but you could always
write a wrapper function:

#include <stdio.h>
#inlcude <bios.h>

outlpt(int port, char *st)
{
  int x;

  for(x = 0, x < strlen(st); x++)
  {
    biosprint(0, st[x], port);
  }
}

int main()
{
  printf("Hello, world\n");
  outlpt(0, "\xA0\x28");	/* set display to 4-bit, 2 lines, 5x7 char */
  outlpt(0, "\xA0\x0C");	/* display on, cursor off, blink off       */
  outlpt(0, "\xA0\x06");	/* increment cursor, no display shift     */
  outlpt(0, "\xA0\x01");	/* clear and home display                 */

  outlpt(0, "Row1-11111111111111111111111111111111111");
  outlpt(0, "Row2-22222222222222222222222222222222222");
  outlpt(1, "Row3-33333333333333333333333333333333333");
  outlpt(1, "Row4-44444444444444444444444444444444444");

  return 0;
}


Ed Okerson

On 31 Aug 2003, Bill Boyer wrote:

> Let me re-explain so you guys don't get all wound up with memory maps
> and Visual C++.
>
> This is on a JK Micro Flashlite 386ex single-board computer running XDOS
> 3.3c from an EPROM and Borland C++ 4.52 code compiled on a PC and
> uploaded as a .exe to the 386ex board via a terminal program.
>
> The board has a single 10-pin dual-row header for connecting one or two
> HD44780-compatible LCD displays. A TSR program they furnish redirects
> requests to LPT1 and LPT2 to this connector in a format usable by the
> LCDs.
>
> If you have two LCD's connected, they share all the data lines except
> the E (enable) line. E1 is used if you want to write to the LCD as LPT1,
> and E2 is used to write to the LCD as LPT2.
>
> With a 4x40 LCD (Tanner's special, $10) you physically have one 4x40
> display, but electrically it is two complete separate 2x40 displays /
> chipsets that are written to individually. Hence the need to be able to
> write to LPT1 and LPT2 with the same program.
>
> So far, the LCD powers up, the TSR runs, and the code below will
> initialize a 2x16 or half of a 4x4 LCD and display characters properly.
>
> The problem is writing to LPT2 so I can use the other half of the
> display.
>
> **********************************
>
> #include <stdio.h>
>
> int main()
> {
> 	printf("Hello, world\n");
> 	fprintf(stdprn,"\xA0\x28");		/* set display to 4-bit, 2 lines, 5x7 char
> */
> 	fprintf(stdprn,"\xA0\x0C");	   /* display on, cursor off, blink
> off       */
> 	fprintf(stdprn,"\xA0\x06");		/* increment cursor, no display shift
> */
> 	fprintf(stdprn,"\xA0\x01");		/* clear and home display
> */
>
> 	fprintf(stdprn,"Row1-11111111111111111111111111111111111");
> 	fprintf(stdprn,"Row2-22222222222222222222222222222222222");
>
> 	return 0;
> }
>
> *****************************************************
>
> > You can't write directly to non memory mapped I/O ports in "normal" C or
> > C++. You need a helper routine written in assembler.
> >
> > Most run time libraries provide routines named something like inport()
> > and outport() which do the work for you. Sometimes they'll be called
> > _inport _outport or _inp and _outp.
> >
> > In Visual C++ 6.0 they're called _inp and _outp and they can be found in
> > conio.h
>
>
> > > > You still haven't answered my question though -- how can I directly
> > > > write to LPT2 in C++? One reference book mentioned using a file
> > > > pointer and the FOPEN statement, but it did not seem to
> > > work properly
> > > > for either port, although an FPRINTF to STDPRN worked fine.
> > >
> > > Sorry, I have no idea how you'd do that in C++.  Any
> > > low-level C++ gurus lurking out there?
> > >
> > > The only possible thing I could think of would be to open
> > > another file for LPT2 and then overwrite stdprn with the new
> > > file handle.  I don't even know if that would work.
>
>
> _______________________________________________
> DPRGlist mailing list
> DPRGlist at dprg.org
> http://nimon.ncc.com/mailman/listinfo/dprglist
>


More information about the DPRG mailing list