home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / sys / ibm / pc / hardware / 33905 < prev    next >
Encoding:
Text File  |  1992-12-22  |  3.2 KB  |  103 lines

  1. Newsgroups: comp.sys.ibm.pc.hardware
  2. Path: sparky!uunet!gatech!cc.gatech.edu!news
  3. From: byron@cc.gatech.edu (Byron A Jeff)
  4. Subject: Re: Reading the Parallel Port
  5. Message-ID: <1992Dec21.231215.5931@cc.gatech.edu>
  6. Sender: news@cc.gatech.edu
  7. Reply-To: byron@cc.gatech.edu (Byron A Jeff)
  8. Organization: Georgia Institute of Technology
  9. References: <HINKER.92Dec21101541@booboo.acl.lanl.gov>
  10. Date: Mon, 21 Dec 1992 23:12:15 GMT
  11. Lines: 90
  12.  
  13. In article <HINKER.92Dec21101541@booboo.acl.lanl.gov> Paul J. Hinker <hinker@acl.lanl.gov> writes:
  14. >     I've recently aquired a video digitizer that connects to the
  15. >parallel port.  What I need is a code fragment or pointer to
  16. >literature describing how one would go about reading the parallel port
  17. >on a PC type machine.
  18. >
  19. >     I realize that most PC's don't have bi-directional parallel ports
  20. >but I've purchased one for my wife's machine [386DX/25] so that's not
  21. >the problem.
  22. >
  23. >     The following piece of code [with different addresses, of course]
  24. >works fine on my Amiga but gets me nowhere on the PC.  Note : This is
  25. >not a 'My machine is better than your machine' post.  I'm simply not
  26. >familiar with the PC way of doing things and am trying to learn.
  27.  
  28. Now hold on here dude. You're not in AmigaLand anymore (and I think
  29. AmigaLand is a great place to be personally). Unlike the 68XXX products
  30. that Commodore uses, PC's I/O space is not (I repeat NOT!) memory mapped.
  31. Like the Z80, 8080, 8088 and all that has come before, the 80386 has
  32. a SEPARATE I/O SPACE called ports!
  33.  
  34. Fortunately the fix is simple. Just use the port based IO instructions
  35. appropriatly named "in" and "out". You didn't specify a compiler so I'll
  36. assume TurboC. We must change your code:
  37.  
  38. >
  39. >void main()
  40. >{
  41. >   unsigned char *Parallel_Port = 0x378; /* 0xbfd200 on the Amiga */
  42. >   int i;
  43. >
  44. >   for (i = 0 ; i < 320 * 200 ; i++)
  45. >      printf("%d\n", *Parallel_Port);
  46. >
  47. >}
  48. >
  49.  
  50. To the following. (This is from memory folks, please don't nitpick).
  51.  
  52. #include <dos.h>
  53.  
  54. void main()
  55. {
  56.    int Parallel_Port = 0x378; /* 0xbfd200 on the Amiga */
  57.    int i;
  58.  
  59.    for (i = 0 ; i < 320 * 200 ; i++) {
  60.       printf("%d\n", inportb(Parallel_Port));
  61.  
  62. }
  63.  
  64. In turboC the inportb macro translates directly to an "in" instruction.
  65. It's defined in the header file "dos.h". The function "inportb" says to
  66. read one byte from the specified port.
  67.  
  68.  
  69. >
  70. >   From what I can tell, the 0x378 port number is missing a base
  71. >address and the above code fragment is simply reading the value from
  72. >somewhere in my program's current data segment.
  73.  
  74. Bingo!
  75.  
  76. >
  77. >   Could some kind soul tell me where to find the base address [so I
  78. >can construct the correct FAR pointer with a MK_FP call] for the
  79. >parallel port?
  80.  
  81. Ah Ah! We're in the land of I/O ports now.
  82.  
  83. >
  84. >   Alternately, can anyone recommend a good reference for doing
  85. >this kind of thing?
  86.  
  87. Most any lower level PC book will give a listing of the PORTS. Many
  88. advanced C books will show how to do port programming.
  89.  
  90. Hope this helps. And please take all my commentary with a grain of ;-) because
  91. I know this is a new environment to you.
  92.  
  93. >
  94. >   Any and all help is greatly appreciated.
  95.  
  96. No problem.
  97.  
  98. BAJ
  99. ---
  100. Another random extraction from the mental bit stream of...
  101. Byron A. Jeff - PhD student operating in parallel!
  102. Georgia Tech, Atlanta GA 30332   Internet: byron@cc.gatech.edu
  103.