home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / portio.zip / test.c < prev    next >
C/C++ Source or Header  |  1993-05-03  |  2KB  |  65 lines

  1. /* Example program to send a string directly to the printer through I/O port */
  2.  
  3. #include <stdio.h>
  4. #include "portio.h"
  5.  
  6. /*---------------------------------------------------------------------------    
  7. -- Outputs one character directly to LPT1 handling necessary handshaking
  8. --
  9. -- Syntax:  void SendChar(char chr)
  10. --
  11. -- Inputs:  chr - character (byte) to output to printer port
  12. --
  13. -- Output:  none
  14. --
  15. -- Returns: none
  16. --
  17. -- Action: Direct output via INP/OUTP to printer
  18. ----------------------------------------------------------------------------*/
  19. #define OUTPUTPORT            0x378
  20. #define STATUSPORT            OUTPUTPORT+1
  21. #define CONTROLPORT            OUTPUTPORT+2
  22. #define READY_BIT                0x80                /* Ready flag of StatusPort    */
  23. #define STROBE_OUT            0x0D                /* Bit set to strobe data out */
  24. #define STROBE_OFF            0x0C                /* Reset of strobe bit            */
  25. #define LOOPCRITICALCOUNT    10000                /* Times before printing        */
  26.  
  27. void SendChar(char chr) {
  28.         
  29.     int LoopCnt=0;                                    /* Waiting loop counter */
  30.            
  31.     while ( (inp(STATUSPORT) & READY_BIT) == 0) {
  32.         if (LoopCnt++ > LOOPCRITICALCOUNT) {
  33.             printf("I've apparently been busy for a while\n");
  34.             LoopCnt = 0;
  35.         }
  36.     }
  37.  
  38.     outp(OUTPUTPORT, chr);                        /* Send the character */
  39.     outp(CONTROLPORT, STROBE_OUT);            /* Strobe it out */
  40.     outp(CONTROLPORT, STROBE_OFF);            /* And unstrobe  */
  41.  
  42.     return;
  43. }
  44.  
  45. /* ---------------------------------------------------------------------------
  46. -- Routine to send a command string (including potentially nulls) to printer
  47. --
  48. -- Usage:  void SendCommand(char *str)
  49. --
  50. -- Inputs: str - command string
  51. ---------------------------------------------------------------------------- */
  52. void SendCommand(char *str) {
  53.     while (*str) SendChar(*(str++));
  54.     return;
  55. }
  56.  
  57. /* ---------------------------------------------------------------------------
  58. -- Main routine.  Calls SendCommand for single page.
  59. ---------------------------------------------------------------------------- */
  60. int main(int argc, char *argv[]) {
  61.  
  62.     SendCommand("Hi there, I'm a print output\n\r\f");
  63.     return(0);
  64. }
  65.