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

  1. // parsetup.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 <bios.h>
  24. #include <stdarg.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <mem.h>
  28. #include <dos.h>
  29. #include <time.h>
  30. #include <string.h>
  31. #include "parsetup.h"
  32. #include "doomnet.h"
  33.  
  34. unsigned newpkt=0;
  35.  
  36. extern void recv(void);
  37. extern void send_pkt(void);
  38. extern byte pktbuf[];
  39. extern unsigned recv_count;
  40. extern unsigned errcnt;
  41.  
  42.  
  43. /*
  44. =================
  45. =
  46. = Error
  47. =
  48. = For abnormal program terminations
  49. =
  50. =================
  51. */
  52.  
  53. void Error (char *error, ...)
  54. {
  55. va_list argptr;
  56.  
  57.         ShutdownPort();
  58.  
  59.     if (error)
  60.     {
  61.         va_start (argptr,error);
  62.         vprintf (error,argptr);
  63.         va_end (argptr);
  64.         printf ("\n");
  65.         exit (1);
  66.     }
  67.  
  68.         printf ("Clean exit from PARSETUP\n");
  69.     exit (0);
  70. }
  71.  
  72.  
  73. /*
  74. ================
  75. =
  76. = ReadPacket
  77. =
  78. ================
  79. */
  80.  
  81. #define MAXPACKET    512
  82.  
  83. boolean ReadPacket(void)
  84. {
  85.  
  86.         if (newpkt) {
  87.                 newpkt=0;
  88.                 return true;   // true - got a good packet
  89.                 }
  90.  
  91.         return (false);     // false - no packet available
  92.  
  93. }
  94.  
  95.  
  96. /*
  97. =============
  98. =
  99. = WritePacket
  100. =
  101. =============
  102. */
  103.  
  104. int WritePacket(byte *data, unsigned len)
  105. {
  106.  
  107.         _CX = len;
  108.         _DS = FP_SEG(data);
  109.         _SI = FP_OFF(data);
  110.         _ES = _DI = 0;
  111.         send_pkt();
  112.  
  113.         asm jnc sendok;
  114.  
  115.         return (_DH);
  116.  
  117. sendok:
  118.     return (0);
  119.  
  120. }
  121.  
  122.  
  123. /*
  124. =============
  125. =
  126. = NetISR
  127. =
  128. =============
  129. */
  130.  
  131. void interrupt NetISR (void)
  132. {
  133.     if (doomcom.command == CMD_SEND)
  134.     {
  135.                 // I_ColorBlack (0,0,63);
  136.         WritePacket ((char *)&doomcom.data, doomcom.datalength);
  137.     }
  138.     else if (doomcom.command == CMD_GET)
  139.     {
  140.         //I_ColorBlack (63,63,0);
  141.  
  142.         if (ReadPacket () && recv_count <= sizeof(doomcom.data) )
  143.         {
  144.             doomcom.remotenode = 1;
  145.                         doomcom.datalength = recv_count;
  146.                         memcpy (&doomcom.data, &pktbuf, recv_count);
  147.         }
  148.         else
  149.             doomcom.remotenode = -1;
  150.  
  151.     }
  152.         //I_ColorBlack (0,0,0);
  153. }
  154.  
  155.  
  156.  
  157.  
  158. /*
  159. =================
  160. =
  161. = Connect
  162. =
  163. = Figures out who is player 0 and 1
  164. =================
  165. */
  166.  
  167. void Connect (void)
  168. {
  169. struct time     time;
  170. int             oldsec;
  171. int     localstage, remotestage;
  172. char    str[20];
  173.  
  174.  
  175.     printf ("Attempting to connect across parallel link, press escape to abort.\n");
  176.  
  177.  
  178.         //
  179.         // wait for a good packet
  180.         //
  181.  
  182.     oldsec = -1;
  183.     localstage = remotestage = 0;
  184.  
  185.     do
  186.     {
  187.         while ( bioskey(1) )
  188.         {
  189.             if ( (bioskey (0) & 0xff) == 27)
  190.                 Error ("\n\nNetwork game synchronization aborted.");
  191.         }
  192.  
  193.         while (ReadPacket ())
  194.         {
  195.             pktbuf[recv_count] = 0;
  196.             printf ("read: %s\n",pktbuf);
  197.             if (recv_count != 7)
  198.                 goto badpacket;
  199.             if (strncmp(pktbuf,"PLAY",4) )
  200.                 goto badpacket;
  201.             remotestage = pktbuf[6] - '0';
  202.             localstage = remotestage+1;
  203.             if (pktbuf[4] == '0'+doomcom.consoleplayer)
  204.             {
  205.                 doomcom.consoleplayer ^= 1;
  206.                 localstage = remotestage = 0;
  207.             }
  208.             oldsec = -1;
  209.         }
  210. badpacket:
  211.  
  212.         gettime (&time);
  213.         if (time.ti_sec != oldsec)
  214.         {
  215.             oldsec = time.ti_sec;
  216.             sprintf (str,"PLAY%i_%i",doomcom.consoleplayer,localstage);
  217.             WritePacket (str,strlen(str));
  218.                 printf ("wrote: %s\n",str);
  219.         }
  220.  
  221.     } while (remotestage < 1);
  222.  
  223. //
  224. // flush out any extras
  225. //
  226.     while (ReadPacket ())
  227.     ;
  228. }
  229.  
  230.  
  231. /*
  232. =================
  233. =
  234. = main
  235. =
  236. =================
  237. */
  238.  
  239. void main(void)
  240. {
  241. int p;
  242. time_t t;
  243.  
  244.         //
  245.         // set network characteristics
  246.         //
  247.     doomcom.ticdup = 1;
  248.     doomcom.extratics = 0;
  249.     doomcom.numnodes = 2;
  250.     doomcom.numplayers = 2;
  251.     doomcom.drone = 0;
  252.  
  253.     t = time(&t);
  254.  
  255.     printf("\n"
  256.                 "DOOM PRINTER PORT DEVICE DRIVER version 1.1\n"
  257.                 "Brought to you by the American Society of Reverse Engineers\n"
  258.                 "Send comments or (gasp!) bug reports to asre@uiuc.edu\n\n");
  259.  
  260. //
  261. // allow override of automatic player ordering to allow a slower computer
  262. // to be set as player 1 always
  263. //
  264.     if (CheckParm ("-player1"))
  265.         doomcom.consoleplayer = 1;
  266.     else
  267.         doomcom.consoleplayer = 0;
  268.  
  269. //
  270. // establish communications
  271. //
  272.     InitPort ();
  273.  
  274.         Connect ();
  275.  
  276. //
  277. // launch DOOM
  278. //
  279.     LaunchDOOM ();
  280.  
  281.     Error (NULL);
  282.  
  283. }
  284.  
  285.