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

  1. // doomnet.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.  
  24. #include <io.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <process.h>
  29. #include <dos.h>
  30. #include "doomnet.h"
  31.  
  32. doomcom_t    doomcom;
  33. int            vectorishooked;
  34. void interrupt (*olddoomvect) (void);
  35.  
  36.  
  37.  
  38. /*
  39. =================
  40. =
  41. = CheckParm
  42. =
  43. = Checks for the given parameter in the program's command line arguments
  44. =
  45. = Returns the argument number (1 to argc-1) or 0 if not present
  46. =
  47. =================
  48. */
  49.  
  50. int CheckParm (char *check)
  51. {
  52.     int             i;
  53.  
  54.     for (i = 1;i<_argc;i++)
  55.         if ( !stricmp(check,_argv[i]) )
  56.             return i;
  57.  
  58.     return 0;
  59. }
  60.  
  61.  
  62. /*
  63. =============
  64. =
  65. = LaunchDOOM
  66. =
  67. These fields in doomcom should be filled in before calling:
  68.  
  69.     short    numnodes;        // console is allways node 0
  70.     short    ticdup;            // 1 = no duplication, 2-5 = dup for slow nets
  71.     short    extratics;        // 1 = send a backup tic in every packet
  72.  
  73.     short    consoleplayer;    // 0-3 = player number
  74.     short    numplayers;        // 1-4
  75.     short    angleoffset;    // 1 = left, 0 = center, -1 = right
  76.     short    drone;            // 1 = drone
  77. =============
  78. */
  79.  
  80. void LaunchDOOM (void)
  81. {
  82.     char    *newargs[99];
  83.     char    adrstring[10];
  84.     long      flatadr;
  85.     int        p;
  86.     unsigned char    far    *vector;
  87.  
  88. // prepare for DOOM
  89.     doomcom.id = DOOMCOM_ID;
  90.  
  91. // hook an interrupt vector
  92.     p= CheckParm ("-vector");
  93.  
  94.     if (p)
  95.     {
  96.         doomcom.intnum = sscanf ("0x%x",_argv[p+1]);
  97.     }
  98.     else
  99.     {
  100.         for (doomcom.intnum = 0x60 ; doomcom.intnum <= 0x66 ; doomcom.intnum++)
  101.         {
  102.             vector = *(char far * far *)(doomcom.intnum*4);
  103.             if ( !vector || *vector == 0xcf )
  104.                 break;
  105.         }
  106.         if (doomcom.intnum == 0x67)
  107.         {
  108.             printf ("Warning: no NULL or iret interrupt vectors were found in the 0x60 to 0x66\n"
  109.                     "range.  You can specify a vector with the -vector 0x<num> parameter.\n");
  110.             doomcom.intnum = 0x66;
  111.         }
  112.     }
  113.     printf ("Communicating with interupt vector 0x%x\n",doomcom.intnum);
  114.  
  115.     olddoomvect = getvect (doomcom.intnum);
  116.     setvect (doomcom.intnum,NetISR);
  117.     vectorishooked = 1;
  118.  
  119. // build the argument list for DOOM, adding a -net &doomcom
  120.     memcpy (newargs, _argv, (_argc+1)*2);
  121.     newargs[_argc] = "-net";
  122.     flatadr = (long)_DS*16 + (unsigned)&doomcom;
  123.     sprintf (adrstring,"%lu",flatadr);
  124.     newargs[_argc+1] = adrstring;
  125.     newargs[_argc+2] = NULL;
  126.  
  127.         if (!access("DOOM.EXE", 0)) {
  128.                 spawnv  (P_WAIT, "doom", newargs);
  129.                 printf ("Returned from DOOM\n");
  130.                 }
  131.         else if (!access("DOOM2.EXE", 0)) {
  132.                 spawnv  (P_WAIT, "doom2", newargs);
  133.                 printf ("Returned from DOOM II\n");
  134.                 }
  135.         else
  136.                 printf("Error - could not find DOOM(2).EXE!\n");
  137. }
  138.