home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.sys.ibm.pc.hardware
- Path: sparky!uunet!gatech!cc.gatech.edu!news
- From: byron@cc.gatech.edu (Byron A Jeff)
- Subject: Re: Reading the Parallel Port
- Message-ID: <1992Dec21.231215.5931@cc.gatech.edu>
- Sender: news@cc.gatech.edu
- Reply-To: byron@cc.gatech.edu (Byron A Jeff)
- Organization: Georgia Institute of Technology
- References: <HINKER.92Dec21101541@booboo.acl.lanl.gov>
- Date: Mon, 21 Dec 1992 23:12:15 GMT
- Lines: 90
-
- In article <HINKER.92Dec21101541@booboo.acl.lanl.gov> Paul J. Hinker <hinker@acl.lanl.gov> writes:
- > I've recently aquired a video digitizer that connects to the
- >parallel port. What I need is a code fragment or pointer to
- >literature describing how one would go about reading the parallel port
- >on a PC type machine.
- >
- > I realize that most PC's don't have bi-directional parallel ports
- >but I've purchased one for my wife's machine [386DX/25] so that's not
- >the problem.
- >
- > The following piece of code [with different addresses, of course]
- >works fine on my Amiga but gets me nowhere on the PC. Note : This is
- >not a 'My machine is better than your machine' post. I'm simply not
- >familiar with the PC way of doing things and am trying to learn.
-
- Now hold on here dude. You're not in AmigaLand anymore (and I think
- AmigaLand is a great place to be personally). Unlike the 68XXX products
- that Commodore uses, PC's I/O space is not (I repeat NOT!) memory mapped.
- Like the Z80, 8080, 8088 and all that has come before, the 80386 has
- a SEPARATE I/O SPACE called ports!
-
- Fortunately the fix is simple. Just use the port based IO instructions
- appropriatly named "in" and "out". You didn't specify a compiler so I'll
- assume TurboC. We must change your code:
-
- >
- >void main()
- >{
- > unsigned char *Parallel_Port = 0x378; /* 0xbfd200 on the Amiga */
- > int i;
- >
- > for (i = 0 ; i < 320 * 200 ; i++)
- > printf("%d\n", *Parallel_Port);
- >
- >}
- >
-
- To the following. (This is from memory folks, please don't nitpick).
-
- #include <dos.h>
-
- void main()
- {
- int Parallel_Port = 0x378; /* 0xbfd200 on the Amiga */
- int i;
-
- for (i = 0 ; i < 320 * 200 ; i++) {
- printf("%d\n", inportb(Parallel_Port));
-
- }
-
- In turboC the inportb macro translates directly to an "in" instruction.
- It's defined in the header file "dos.h". The function "inportb" says to
- read one byte from the specified port.
-
-
- >
- > From what I can tell, the 0x378 port number is missing a base
- >address and the above code fragment is simply reading the value from
- >somewhere in my program's current data segment.
-
- Bingo!
-
- >
- > Could some kind soul tell me where to find the base address [so I
- >can construct the correct FAR pointer with a MK_FP call] for the
- >parallel port?
-
- Ah Ah! We're in the land of I/O ports now.
-
- >
- > Alternately, can anyone recommend a good reference for doing
- >this kind of thing?
-
- Most any lower level PC book will give a listing of the PORTS. Many
- advanced C books will show how to do port programming.
-
- Hope this helps. And please take all my commentary with a grain of ;-) because
- I know this is a new environment to you.
-
- >
- > Any and all help is greatly appreciated.
-
- No problem.
-
- BAJ
- ---
- Another random extraction from the mental bit stream of...
- Byron A. Jeff - PhD student operating in parallel!
- Georgia Tech, Atlanta GA 30332 Internet: byron@cc.gatech.edu
-