home *** CD-ROM | disk | FTP | other *** search
/ Crazy Collection 12 / CC-12_1.iso / update / doompack / data.a00 / PSETUP11.ZIP / PSSRC.ZIP / PORT.C < prev   
Encoding:
C/C++ Source or Header  |  1994-12-04  |  2.9 KB  |  162 lines

  1. // port.c
  2.  
  3. //  Copyright 1994 Scott Coleman, American Society of Reverse Engineers
  4.  
  5. //   This program is free software; you can redistribute it and/or modify
  6. //   it under the terms of the GNU General Public License as published by
  7. //   the Free Software Foundation, version 1.
  8. //
  9. //   This program is distributed in the hope that it will be useful,
  10. //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. //   GNU General Public License for more details.
  13. //
  14. //   You should have received a copy of the GNU General Public License
  15. //   along with this program; if not, write to the Free Software
  16. //   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  
  18. // NOTE: Portions of this program were adapted from other freely available
  19. // software, including SERSETUP and the Crynwr PLIP parallel port Internet
  20. // Protocol driver.
  21.  
  22.  
  23. #include <dos.h>
  24. #include <conio.h>
  25. #include <string.h>
  26. #include <stdio.h>
  27. #include "doomnet.h"
  28. #include "parsetup.h"
  29.  
  30. typedef unsigned char byte;
  31.  
  32. unsigned portbase=0x378;
  33. unsigned irq=7;
  34.  
  35. #define BUFSIZE 512
  36. void interrupt (*oldisr)();
  37. byte oldmask;
  38. unsigned errcnt=0;
  39. unsigned icnt=0;
  40.  
  41. byte pktbuf[BUFSIZE];
  42.  
  43. unsigned bufseg=0;
  44. unsigned bufofs=0;
  45. unsigned recv_count=0;
  46.  
  47.  
  48.  
  49. void count_in_err(void)
  50. {
  51.  
  52.     errcnt++;
  53. }
  54.  
  55. extern void recv(void);
  56.  
  57.  
  58. void interrupt recvisr(void)
  59. {
  60.  
  61.     icnt++;
  62.         recv();
  63.  
  64.         outportb(0x20, 0x20);
  65.  
  66. }
  67.  
  68.  
  69. void initisr(void)
  70. {
  71. byte mask;
  72.  
  73.     // install new interrupt hander for the printer port
  74.     oldisr = getvect(irq+8);
  75.     setvect(irq+8, recvisr);
  76.  
  77.     // enable interrupts from the printer port
  78.     outportb(portbase+2, inportb(portbase+2)|0x10);
  79.     oldmask = inportb(0x21);
  80.     mask = oldmask & ~(1<<irq);        // enable IRQ in ICR
  81.     outportb(0x21, mask);
  82.  
  83.     outportb(0x20, 0x20);
  84.  
  85. }
  86.  
  87.  
  88. /*
  89. ==============
  90. =
  91. = GetPort
  92. =
  93. ==============
  94. */
  95.  
  96. void GetPort (void)
  97. {
  98. int p;
  99.  
  100.     if (CheckParm ("-lpt2"))
  101.         portbase = 0x278;
  102.     else if (CheckParm ("-lpt3"))
  103.         portbase = 0x3bc;
  104.  
  105.     p = CheckParm ("-port");
  106.     if (p)
  107.         sscanf (_argv[p+1],"0x%x",&portbase);
  108.  
  109.     p = CheckParm("-irq");
  110.     if (p)
  111.         sscanf(_argv[p+1], "%u", &irq);
  112.  
  113.     printf ("Using parallel printer port with base address 0x%x and IRQ %u\n",
  114.         portbase, irq);
  115. }
  116.  
  117.  
  118. /*
  119. ===============
  120. =
  121. = InitPort
  122. =
  123. ===============
  124. */
  125.  
  126. void InitPort (void)
  127. {
  128.  
  129. //
  130. // find the irq and io address of the port
  131. //
  132.     GetPort();
  133.  
  134.     bufseg = FP_SEG(pktbuf);
  135.     bufofs = FP_OFF(pktbuf);
  136.  
  137.     initisr();
  138.  
  139. }
  140.  
  141.  
  142. /*
  143. =============
  144. =
  145. = ShutdownPort
  146. =
  147. =============
  148. */
  149.  
  150. void ShutdownPort ( void )
  151. {
  152.  
  153.     outportb(0x21, oldmask);    // disable IRQs
  154.     setvect(irq+8, oldisr);       // restore vector
  155.  
  156. }
  157.  
  158.  
  159. //==========================================================================
  160.  
  161.  
  162.