shithub: hexen

Download patch

ref: c095130709566a648844c10b24a8fb8a82917569
parent: 0de63fa5e707d4811a67e3f3e81cd7e9349581f2
author: Jacob Moody <moody@posixcafe.org>
date: Sat Jan 21 22:08:14 EST 2023

merge qwx's doom stuff stub sound for now

--- /dev/null
+++ b/LICENSE
@@ -1,0 +1,339 @@
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
+ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Lesser General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License along
+    with this program; if not, write to the Free Software Foundation, Inc.,
+    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Lesser General
+Public License instead of this License.
--- /dev/null
+++ b/README
@@ -1,0 +1,3 @@
+WIP port of HHexen to plan9.
+
+https://hhexen.sourceforge.net/hhexen.html
--- a/am_map.c
+++ b/am_map.c
@@ -263,7 +263,7 @@
 
 	automapactive = true;
 #ifndef RENDER3D
-	fb = screen;
+	fb = screens;
 #endif
 
 	f_oldloc.x = H2MAXINT;
--- a/h2def.h
+++ b/h2def.h
@@ -301,7 +301,8 @@
 	ev_keydown,
 	ev_keyup,
 	ev_mouse,
-	ev_joystick
+	ev_joystick,
+	ev_char
 } evtype_t;
 
 typedef struct
@@ -963,7 +964,7 @@
 
 extern	boolean		precache;	/* if true, load all graphics at level load */
 
-extern	byte		*screen;	/* off screen work buffer, from V_video.c */
+extern	byte		*screens;	/* off screen work buffer, from V_video.c */
 
 extern	boolean		singledemo;	/* quit after playing a demo from cmdline */
 
--- /dev/null
+++ b/i_cdmus.c
@@ -1,0 +1,186 @@
+
+//**************************************************************************
+//**
+//** i_cdmus.c
+//**
+//** $Revision: 562 $
+//** $Date: 2010-10-20 15:45:52 +0300 (Wed, 20 Oct 2010) $
+//**
+//**************************************************************************
+
+// HEADER FILES ------------------------------------------------------------
+
+#include "h2stdinc.h"
+#include "h2def.h"
+#include "i_cdmus.h"
+
+// MACROS ------------------------------------------------------------------
+
+#define MAX_AUDIO_TRACKS	25
+
+// TYPES -------------------------------------------------------------------
+
+// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
+
+// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
+
+// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
+
+// EXTERNAL DATA DECLARATIONS ----------------------------------------------
+
+// PUBLIC DATA DEFINITIONS -------------------------------------------------
+
+int cdaudio;	/* boolean: enabled or disabled */
+
+boolean i_CDMusic;
+int i_CDTrack;
+int i_CDCurrentTrack;
+int i_CDMusicLength;
+int oldTic;
+
+int cd_Error;
+
+// PRIVATE DATA DEFINITIONS ------------------------------------------------
+
+#if 0 /* nothing is here yet */
+static int cd_FirstTrack;
+static int cd_LastTrack;
+static char cd_dev[64] = "/dev/cdrom";
+#endif
+static int cdfile = -1;
+
+// CODE --------------------------------------------------------------------
+
+static int I_CDGetDiskInfo(void)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusInit
+//
+// Initializes the CD audio system.  Must be called before using any
+// other I_CDMus functions.
+//
+// Returns: 0 (ok) or -1 (error, in cd_Error).
+//
+//==========================================================================
+
+int I_CDMusInit(void)
+{
+	//open CD device
+	I_CDGetDiskInfo ();
+	return -1;	// not implemented yet
+}
+
+//==========================================================================
+//
+// I_CDMusPlay
+//
+// Play an audio CD track.
+//
+// Returns: 0 (ok) or -1 (error, in cd_Error).
+//
+//==========================================================================
+
+int I_CDMusPlay(int track)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusStop
+//
+// Stops the playing of an audio CD.
+//
+// Returns: 0 (ok) or -1 (error, in cd_Error).
+//
+//==========================================================================
+
+int I_CDMusStop(void)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusResume
+//
+// Resumes the playing of an audio CD.
+//
+// Returns: 0 (ok) or -1 (error, in cd_Error).
+//
+//==========================================================================
+
+int I_CDMusResume(void)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusSetVolume
+//
+// Sets the CD audio volume (0 - 255).
+//
+// Returns: 0 (ok) or -1 (error, in cd_Error).
+//
+//==========================================================================
+
+int I_CDMusSetVolume(int volume)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusFirstTrack
+//
+// Returns: the number of the first track.
+//
+//==========================================================================
+
+int I_CDMusFirstTrack(void)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusLastTrack
+//
+// Returns: the number of the last track.
+//
+//==========================================================================
+
+int I_CDMusLastTrack(void)
+{
+	return 0;
+}
+
+//==========================================================================
+//
+// I_CDMusShutDown
+//
+//==========================================================================
+
+void I_CDMusShutdown(void)
+{
+	if (cdfile != -1)
+		close(cdfile);
+	cdfile = -1;
+}
+
+//==========================================================================
+//
+// I_CDMusUpdate
+//
+//==========================================================================
+
+void I_CDMusUpdate(void)
+{
+
+}
+
--- /dev/null
+++ b/i_main.c
@@ -1,0 +1,13 @@
+/* i_main.c */
+
+#include "h2stdinc.h"
+#include "h2def.h"
+#include "soundst.h"
+#include "st_start.h"
+
+void main(int argc, char **argv)
+{
+	myargc = argc; 
+	myargv = argv; 
+	H2_Main ();
+} 
--- /dev/null
+++ b/i_net.c
@@ -1,0 +1,161 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id:$
+//
+// Copyright (C) 1993-1996 by id Software, Inc.
+//
+// This source is available for distribution and/or modification
+// only under the terms of the DOOM Source Code License as
+// published by id Software. All rights reserved.
+//
+// The source is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
+// for more details.
+//
+// $Log:$
+//
+// DESCRIPTION:
+//
+//-----------------------------------------------------------------------------
+
+static const char
+rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
+
+#include "h2stdinc.h"
+#include "h2def.h"
+
+// #include "i_system.h"
+// #include "d_event.h"
+//#include "d_net.h"
+//#include "m_argv.h"
+
+#include "i_net.h"
+
+
+//
+// I_InitNetwork
+//
+void I_InitNetwork (void)
+{
+printf("PORTME i_net.c I_InitNetwork (use 9P)\n");
+
+	doomcom = malloc (sizeof(*doomcom));
+	memset (doomcom, 0, sizeof(*doomcom));
+
+	/* set up for network */
+	doomcom->ticdup = 1;
+	doomcom->extratics = 0;
+
+//	netsend = PacketSend;
+//	netget = PacketGet;
+//	netgame = true;
+
+	/* parse player number and host list */
+//	doomcom->consoleplayer = myargv[i+1][0]-'1';
+
+	doomcom->numnodes = 1;	// this node for sure
+
+	doomcom->id = DOOMCOM_ID;
+	doomcom->numplayers = doomcom->numnodes;
+
+/*
+    boolean		trueval = true;
+    int			i;
+    int			p;
+    struct hostent*	hostentry;	// host information entry
+	
+    doomcom = malloc (sizeof (*doomcom) );
+    memset (doomcom, 0, sizeof(*doomcom) );
+    
+    // set up for network
+    i = M_CheckParm ("-dup");
+    if (i && i< myargc-1)
+    {
+	doomcom->ticdup = myargv[i+1][0]-'0';
+	if (doomcom->ticdup < 1)
+	    doomcom->ticdup = 1;
+	if (doomcom->ticdup > 9)
+	    doomcom->ticdup = 9;
+    }
+    else
+	doomcom-> ticdup = 1;
+	
+    if (M_CheckParm ("-extratic"))
+	doomcom-> extratics = 1;
+    else
+	doomcom-> extratics = 0;
+		
+    p = M_CheckParm ("-port");
+    if (p && p<myargc-1)
+    {
+	DOOMPORT = atoi (myargv[p+1]);
+	printf ("using alternate port %i\n",DOOMPORT);
+    }
+    
+    // parse network game options,
+    //  -net <consoleplayer> <host> <host> ...
+    i = M_CheckParm ("-net");
+    if (!i)
+    {
+	// single player game
+	netgame = false;
+	doomcom->id = DOOMCOM_ID;
+	doomcom->numplayers = doomcom->numnodes = 1;
+	doomcom->deathmatch = false;
+	doomcom->consoleplayer = 0;
+	return;
+    }
+
+    netsend = PacketSend;
+    netget = PacketGet;
+    netgame = true;
+
+    // parse player number and host list
+    doomcom->consoleplayer = myargv[i+1][0]-'1';
+
+    doomcom->numnodes = 1;	// this node for sure
+	
+    i++;
+    while (++i < myargc && myargv[i][0] != '-')
+    {
+	sendaddress[doomcom->numnodes].sin_family = AF_INET;
+	sendaddress[doomcom->numnodes].sin_port = htons(DOOMPORT);
+	if (myargv[i][0] == '.')
+	{
+	    sendaddress[doomcom->numnodes].sin_addr.s_addr 
+		= inet_addr (myargv[i]+1);
+	}
+	else
+	{
+	    hostentry = gethostbyname (myargv[i]);
+	    if (!hostentry)
+		I_Error ("gethostbyname: couldn't find %s", myargv[i]);
+	    sendaddress[doomcom->numnodes].sin_addr.s_addr 
+		= *(int *)hostentry->h_addr_list[0];
+	}
+	doomcom->numnodes++;
+    }
+	
+    doomcom->id = DOOMCOM_ID;
+    doomcom->numplayers = doomcom->numnodes;
+*/
+}
+
+
+void I_NetCmd (void)
+{
+/*
+    if (doomcom->command == CMD_SEND)
+    {
+	netsend ();
+    }
+    else if (doomcom->command == CMD_GET)
+    {
+	netget ();
+    }
+    else
+	I_Error ("Bad net cmd: %i\n",doomcom->command);
+*/
+}
--- /dev/null
+++ b/i_net.h
@@ -1,0 +1,45 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id:$
+//
+// Copyright (C) 1993-1996 by id Software, Inc.
+//
+// This source is available for distribution and/or modification
+// only under the terms of the DOOM Source Code License as
+// published by id Software. All rights reserved.
+//
+// The source is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
+// for more details.
+//
+// DESCRIPTION:
+//	System specific network interface stuff.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __I_NET__
+#define __I_NET__
+
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+
+// Called by D_DoomMain.
+
+
+void I_InitNetwork (void);
+void I_NetCmd (void);
+
+
+#endif
+//-----------------------------------------------------------------------------
+//
+// $Log:$
+//
+//-----------------------------------------------------------------------------
--- /dev/null
+++ b/i_sound.c
@@ -1,0 +1,182 @@
+/* i_sound.c */
+
+#include "i_system.h"
+#include "i_sound.h"
+//#include "w_wad.h"	// W_GetNumForName()
+//#include "z_zone.h"
+//#include "m_argv.h"
+
+/* The number of internal mixing channels,
+**  the samples calculated for each mixing step,
+**  the size of the 16bit, 2 hardware channel (stereo)
+**  mixing buffer, and the samplerate of the raw data.
+*/
+
+/* Needed for calling the actual sound output. */
+#define	AUDFREQ		44100
+#define	SFXFREQ		11025
+#define	SAMPLECOUNT	(AUDFREQ/TICRATE)
+#define	NUM_CHANNELS	8
+
+/* The actual lengths of all sound effects. */
+int	lengths[NUMSFX];
+
+/* The actual output device. */
+static int audio_fd = -1;
+
+/* The global mixing buffer.
+** Basically, samples from all active internal channels
+**  are modified and added, and stored in the buffer
+**  that is submitted to the audio device.
+*/
+uchar mixbuf[SAMPLECOUNT*4];
+
+/* The channel step amount... */
+uint	channelstep[NUM_CHANNELS];
+/* ... and a 0.16 bit remainder of last step. */
+uint	channelstepremainder[NUM_CHANNELS];
+
+/* The channel data pointers, start and end. */
+uchar*	channels[NUM_CHANNELS];
+uchar*	channelsend[NUM_CHANNELS];
+
+/* Time/gametic that the channel started playing,
+**  used to determine oldest, which automatically
+**  has lowest priority.
+** In case number of active sounds exceeds
+**  available channels.
+*/
+int	channelstart[NUM_CHANNELS];
+
+/* The sound in channel handles,
+**  determined on registration,
+**  might be used to unregister/stop/modify,
+**  currently unused.
+*/
+int	channelhandles[NUM_CHANNELS];
+
+/* SFX id of the playing sound effect.
+** Used to catch duplicates (like chainsaw).
+*/
+int	channelids[NUM_CHANNELS];
+
+/* Pitch to stepping lookup, unused. */
+int	steptable[256];
+
+/* Volume lookups. */
+int	vol_lookup[128*256];
+
+/* Hardware left and right channel volume lookup. */
+int*	channelleftvol_lookup[NUM_CHANNELS];
+int*	channelrightvol_lookup[NUM_CHANNELS];
+
+int snd_MaxVolume;
+int UpdateState;
+int snd_Channels;
+int snd_MusicVolume;
+
+void I_StartupSound(void)
+{
+}
+
+void I_InitSound(void)
+{
+}
+
+/* This function loops all active (internal) sound
+**  channels, retrieves a given number of samples
+**  from the raw sound data, modifies it according
+**  to the current (internal) channel parameters,
+**  mixes the per-channel samples into the global
+**  mixbuffer, clamping it to the allowed range,
+**  and sets up everything for transferring the
+**  contents of the mixbuffer to the (two)
+**  hardware channels (left and right, that is).
+**
+** This function currently supports only 16bit.
+*/
+void I_UpdateSound(void)
+{
+}
+
+void I_ShutdownSound(void)
+{
+}
+
+void I_SetChannels(int channels)
+{
+}
+
+int I_GetSfxLumpNum(sfxinfo_t *sfxinfo)
+{
+	return 0;
+}
+
+int I_StartSound(int id, void *data, int vol, int sep, int pitch, int)
+{
+	return 0;
+}
+
+void I_StopSound(int handle)
+{
+	USED(handle);
+//	printf("PORTME i_sound.c I_StopSound\n");
+}
+
+int I_SoundIsPlaying(int handle)
+{
+	return 1;
+}
+
+void I_UpdateSoundParams(int handle, int vol, int sep, int pitch)
+{
+	/* I fail to see that this is used.
+	** Would be using the handle to identify
+	**  on which channel the sound might be active,
+	**  and resetting the channel parameters.
+	*/
+	USED(handle, vol, sep, pitch);
+}
+
+void I_InitMusic(void)
+{
+}
+
+void I_ShutdownMusic(void)
+{
+}
+
+void I_SetMusicVolume(int)
+{
+}
+
+void I_PauseSong(int)
+{
+}
+
+void I_ResumeSong(int)
+{
+}
+
+void I_PlaySong(int handle, int loop)
+{
+}
+
+void I_StopSong(int)
+{
+	I_ShutdownMusic();
+}
+
+int I_RegisterSong(void *data)
+{
+	return 0;
+}
+
+void I_UnRegisterSong(int handle)
+{
+}
+
+int I_RegisterExternalSong(char *name)
+{
+	return 0;
+}
--- a/i_sound.h
+++ b/i_sound.h
@@ -1,54 +1,112 @@
-//**************************************************************************
-//**
-//** i_sound.h : Heretic 2 : Raven Software, Corp.
-//**
-//** $Revision: 421 $
-//** $Date: 2009-05-22 16:08:37 +0300 (Fri, 22 May 2009) $
-//**
-//**************************************************************************
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id:$
+//
+// Copyright (C) 1993-1996 by id Software, Inc.
+//
+// This source is available for distribution and/or modification
+// only under the terms of the DOOM Source Code License as
+// published by id Software. All rights reserved.
+//
+// The source is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
+// for more details.
+//
+//
+// DESCRIPTION:
+//	System interface, sound.
+//
+//-----------------------------------------------------------------------------
 
-#ifndef __SOUND__
-#define __SOUND__
+#ifndef __I_SOUND__
+#define __I_SOUND__
 
-#define SND_TICRATE		140	/* tic rate for updating sound */
-#define SND_MAXSONGS		40	/* max number of songs in game */
-#define SND_SAMPLERATE		11025	/* sample rate of sound effects */
+#include "h2stdinc.h"
+#include "h2def.h"
 
-typedef enum
-{
-	snd_none,
-	snd_PC,
-	snd_Adlib,
-	snd_SB,
-	snd_PAS,
-	snd_GUS,
-	snd_MPU,
-	snd_MPU2,
-	snd_MPU3,
-	snd_AWE,
-	snd_CDMUSIC,
-	NUM_SCARDS
-} cardenum_t;
+//#include "doomstat.h"
+#include "sounds.h"
 
+// Init at program start...
+void I_StartupSound(void);
+
+// ... update sound buffer and audio device at runtime...
+void I_UpdateSound(void);
+
+// ... shut down and relase at program termination.
+void I_ShutdownSound(void);
+
+int	I_RegisterSong(void *data);
+void	I_UnRegisterSong(int handle);
+int	I_RegisterExternalSong(char *name);
+
+
+//
+//  SFX I/O
+//
+
+// Initialize channels?
+void I_SetChannels(int channels);
+
+// Get raw data lump index for sound descriptor.
+int I_GetSfxLumpNum (sfxinfo_t* sfxinfo );
+
+
+// Starts a sound in a particular sound channel.
+int
+I_StartSound
+( int		id,
+  void		*data,
+  int		vol,
+  int		sep,
+  int		pitch,
+  int		priority );
+
+
+// Stops a sound channel.
+void I_StopSound(int handle);
+
+// Called by S_*() functions
+//  to see if a channel is still playing.
+// Returns 0 if no longer playing, 1 if playing.
+int I_SoundIsPlaying(int handle);
+
+// Updates the volume, separation,
+//  and pitch of a sound channel.
+void
+I_UpdateSoundParams
+( int		handle,
+  int		vol,
+  int		sep,
+  int		pitch );
+
+
+//
+//  MUSIC I/O
+//
+void I_InitMusic(void);
+void I_ShutdownMusic(void);
+// Volume.
+void I_SetMusicVolume(int volume);
+// PAUSE game handling.
 void I_PauseSong(int handle);
 void I_ResumeSong(int handle);
-void I_SetMusicVolume(int volume);
-void I_SetSfxVolume(int volume);
-int I_RegisterSong(void *data);
-int I_RegisterExternalSong(const char *name);	/* External music file support */
-void I_UnRegisterSong(int handle);
-int I_QrySongPlaying(int handle);
+// Called by anything that wishes to start music.
+//  plays a song, and when the song is done,
+//  starts playing it again in an endless loop.
+// Horrible thing to do, considering.
+void I_PlaySong(int handle, int looping);
+// Stops a song over 3 seconds.
 void I_StopSong(int handle);
-void I_PlaySong(int handle, boolean looping);
-int I_GetSfxLumpNum(sfxinfo_t *sound);
-int I_StartSound (int id, void *data, int vol, int sep, int pitch, int priority);
-void I_StopSound(int handle);
-int I_SoundIsPlaying(int handle);
-void I_UpdateSoundParams(int handle, int vol, int sep, int pitch);
-void I_sndArbitrateCards(void);
-void I_StartupSound (void);
-void I_ShutdownSound (void);
-void I_SetChannels(int channels);
+// See above (register), then think backwards
 
-#endif	/* __SOUND__ */
 
+
+#endif
+//-----------------------------------------------------------------------------
+//
+// $Log:$
+//
+//-----------------------------------------------------------------------------
--- /dev/null
+++ b/i_system.c
@@ -1,0 +1,147 @@
+/* i_system.c */
+
+#include "h2stdinc.h"
+#include "h2def.h"
+
+#include "i_system.h"
+#include "i_video.h"
+
+//#include "g_game.h"
+//#include "m_misc.h"
+
+int mb_used = 32;	/* 32MB heap */
+
+void I_Init (void)
+{
+	I_InitSound();
+	I_InitGraphics();
+	I_MouseEnable(1);
+}
+
+byte* I_ZoneBase (int *size)
+{
+	*size = mb_used*1024*1024;
+	return (byte *) malloc(*size);
+}
+
+/* returns time in 1/70th second tics */
+int I_GetTime (void)
+{
+	return (int)((nsec()*TICRATE)/1000000000);
+}
+
+static ticcmd_t emptycmd;
+ticcmd_t* I_BaseTiccmd (void)
+{
+	return &emptycmd;
+}
+
+void I_Quit (void)
+{
+	D_QuitNetGame ();
+	I_ShutdownSound();
+	I_ShutdownMusic();
+	M_SaveDefaults ();
+	I_ShutdownGraphics();
+	exits(nil);
+}
+
+byte* I_AllocLow (int length)
+{
+	byte *mem;
+        
+	mem = (byte *)malloc (length);
+	memset (mem,0,length);
+	return mem;
+}
+
+void I_Tactile(int on, int off, int total)
+{
+	USED(on, off, total);
+}
+
+//
+// I_Error
+//
+extern boolean demorecording;
+
+void I_Error (char *error, ...)
+{
+    va_list	argptr;
+
+    // Message first.
+    va_start (argptr,error);
+    fprintf (stderr, "Error: ");
+    vfprintf (stderr,error,argptr);
+    fprintf (stderr, "\n");
+    va_end (argptr);
+
+    fflush( stderr );
+
+    // Shutdown. Here might be other errors.
+    if (demorecording)
+	G_CheckDemoStatus();
+
+    D_QuitNetGame ();
+    I_ShutdownGraphics();
+
+    exits("I_Error");
+}
+
+int I_FileExists (char *filepath)
+{
+	return access(filepath, AEXIST) == 0;
+}
+
+int I_Open (char *filepath)
+{
+	return open(filepath, OREAD);
+}
+
+void I_Close (int handle)
+{
+	close (handle);
+}
+
+int I_Seek (int handle, int n)
+{
+	return seek(handle, n, 0);
+}
+
+int I_Read (int handle, void *buf, int n)
+{
+	return read(handle, buf, n);
+}
+
+void I_CheckExternDriver (void)
+{
+}
+
+
+char* I_IdentifyWAD(char *wadname)
+{
+	static char path[1024];
+	char *home;
+
+	snprint(path, sizeof path, wadname);
+	if (I_FileExists (path))
+		return path;
+
+	if(home = getenv("home")){
+		snprintf(path, sizeof path, "%s/lib/doom/%s", home, wadname);
+		free(home);
+
+		if (I_FileExists (path))
+			return path;
+	}
+
+	snprintf(path, sizeof path, "/sys/lib/doom/%s", wadname);
+	if (I_FileExists (path))
+		return path;
+
+	snprintf(path, sizeof path, "/sys/games/lib/doom/%s", wadname);
+	if (I_FileExists (path))
+		return path;
+
+	return nil;
+}
--- /dev/null
+++ b/i_system.h
@@ -1,0 +1,109 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id:$
+//
+// Copyright (C) 1993-1996 by id Software, Inc.
+//
+// This source is available for distribution and/or modification
+// only under the terms of the DOOM Source Code License as
+// published by id Software. All rights reserved.
+//
+// The source is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
+// for more details.
+//
+// DESCRIPTION:
+//	System specific interface stuff.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __I_SYSTEM__
+#define __I_SYSTEM__
+
+//#include "d_ticcmd.h"
+//#include "d_event.h"
+
+#include "h2stdinc.h"
+#include "h2def.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+// Called by DoomMain.
+void I_Init (void);
+
+// Called by startup code
+// to get the ammount of memory to malloc
+// for the zone management.
+byte*	I_ZoneBase (int *size);
+
+
+// Called by D_DoomLoop,
+// returns current time in tics.
+int I_GetTime (void);
+
+
+//
+// Called by D_DoomLoop,
+// called before processing any tics in a frame
+// (just after displaying a frame).
+// Time consuming syncronous operations
+// are performed here (joystick reading).
+// Can call D_PostEvent.
+//
+void I_StartFrame (void);
+
+
+//
+// Called by D_DoomLoop,
+// called before processing each tic in a frame.
+// Quick syncronous operations are performed here.
+// Can call D_PostEvent.
+void I_StartTic (void);
+
+// Asynchronous interrupt functions should maintain private queues
+// that are read by the synchronous functions
+// to be converted into events.
+
+// Either returns a null ticcmd,
+// or calls a loadable driver to build it.
+// This ticcmd will then be modified by the gameloop
+// for normal input.
+ticcmd_t* I_BaseTiccmd (void);
+
+
+// Called by M_Responder when quit is selected.
+// Clean exit, displays sell blurb.
+void I_Quit (void);
+
+
+// Allocates from low memory under dos,
+// just mallocs under unix
+byte* I_AllocLow (int length);
+
+void I_Tactile (int on, int off, int total);
+
+
+void I_Error (char *error, ...);
+
+int I_FileExists (char *filepath);
+
+int I_Open (char *filepath);
+void I_Close (int handle);
+
+int I_Seek(int handle, int n);
+int I_Read(int handle, void *buf, int n);
+
+char* I_IdentifyWAD(char *wadname);
+
+#endif
+//-----------------------------------------------------------------------------
+//
+// $Log:$
+//
+//-----------------------------------------------------------------------------
--- /dev/null
+++ b/i_video.c
@@ -1,0 +1,414 @@
+/* i_video.c */
+
+#include "h2stdinc.h"
+#include "h2def.h"
+
+#include "i_system.h"
+
+extern byte *screens;
+int DisplayTicker = 0;
+
+#include <draw.h>
+#include <mouse.h>
+#include <keyboard.h>
+
+static int resized;
+static int mouseactive;
+extern int usemouse;
+
+static Rectangle grabout;
+static Point center;
+
+static void kbdproc(void);
+static void mouseproc(void);
+
+static uchar cmap[3*256];
+
+static int kbdpid = -1;
+static int mousepid = -1;
+
+static void
+catch(void *, char *msg)
+{
+	/* in case we crash, disable mouse grab */
+	if(strncmp(msg, "sys:", 4) == 0)
+		mouseactive = 0;
+	noted(NDFLT);
+}
+
+void I_InitGraphics(void)
+{
+	int pid;
+
+	notify(catch);
+
+	if(initdraw(nil, nil, "doom") < 0)
+		I_Error("I_InitGraphics failed");
+
+	draw(screen, screen->r, display->black, nil, ZP);
+
+	center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
+	grabout = insetrect(screen->r, Dx(screen->r)/8);
+
+	if((pid = rfork(RFPROC|RFMEM)) == 0){
+		kbdproc();
+		exits(nil);
+	}
+	kbdpid = pid;
+
+	if((pid = rfork(RFPROC|RFMEM)) == 0){
+		mouseproc();
+		exits(nil);
+	}
+	mousepid = pid;
+}
+
+void I_ShutdownGraphics(void)
+{
+	if(kbdpid != -1){
+		postnote(PNPROC, kbdpid, "shutdown");
+		kbdpid = -1;
+	}
+	if(mousepid != -1){
+		postnote(PNPROC, mousepid, "shutdown");
+		mousepid = -1;
+	}
+}
+
+void I_SetPalette(byte *palette)
+{
+	uchar *c;
+
+	c = cmap;
+	while(c < cmap+3*256)
+		*c++ = gammatable[usegamma][*palette++];
+}
+
+void I_UpdateNoBlit(void)
+{
+	// DELETEME?
+}
+
+void I_StartFrame(void)
+{
+}
+
+void I_Update(void)
+{
+	Image *rowimg;
+	Rectangle r;
+	int y, scale;
+	uchar *s, *e, *d, *m;
+	uchar buf[SCREENWIDTH*3*12];
+
+	if(resized){
+		resized = 0;
+		if(getwindow(display, Refnone) < 0)
+			sysfatal("getwindow: %r");
+
+		/* make black background */
+		draw(screen, screen->r, display->black, nil, ZP);
+
+		center = addpt(screen->r.min, Pt(Dx(screen->r)/2, Dy(screen->r)/2));
+		grabout = insetrect(screen->r, Dx(screen->r)/8);
+	}
+
+	scale = Dx(screen->r)/SCREENWIDTH;
+	if(scale <= 0)
+		scale = 1;
+	else if(scale > 12)
+		scale = 12;
+
+	/* where to draw the scaled row */
+	r = rectsubpt(rectaddpt(Rect(0, 0, scale*SCREENWIDTH, scale), center),
+		Pt(scale*SCREENWIDTH/2, scale*SCREENHEIGHT/2));
+
+	/* the row image, y-axis gets scaled with repl flag */
+	rowimg = allocimage(display, Rect(0, 0, scale*SCREENWIDTH, 1), RGB24, scale > 1, DNofill);
+	if(rowimg == nil)
+		sysfatal("allocimage: %r");
+
+	s = screens;
+	for(y = 0; y < SCREENHEIGHT; y++){
+		d = buf;
+		e = s + SCREENWIDTH;
+		for(; s < e; s++){
+			m = &cmap[*s * 3];
+			switch(scale){
+			case 12:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 11:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 10:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 9:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 8:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 7:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 6:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 5:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 4:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 3:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 2:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			case 1:
+				*d++ = m[2];
+				*d++ = m[1];
+				*d++ = m[0];
+			}
+		}
+		loadimage(rowimg, rowimg->r, buf, d - buf);
+		draw(screen, r, rowimg, nil, ZP);
+		r.min.y += scale;
+		r.max.y += scale;
+	}
+	freeimage(rowimg);
+
+	flushimage(display, 1);
+}
+
+void I_MouseEnable(int on)
+{
+	static char nocurs[2*4+2*2*16];
+	static int fd = -1;
+
+	if(mouseactive == on || !usemouse)
+		return;
+	if(mouseactive = on){
+		if((fd = open("/dev/cursor", ORDWR|OCEXEC)) < 0)
+			return;
+		write(fd, nocurs, sizeof(nocurs));
+	}else if(fd >= 0) {
+		close(fd);
+		fd = -1;
+	}
+}
+
+void I_ReadScreen(byte *scr)
+{
+	memcpy (scr, screens, SCREENWIDTH*SCREENHEIGHT);
+}
+
+void I_BeginRead(void)
+{
+	I_Error("PORTME i_video.c I_BeginRead");
+}
+
+void I_EndRead(void)
+{
+	I_Error("PORTME i_video.c I_EndRead");
+}
+
+void I_StartTic(void)
+{
+}
+
+void I_WaitVBL(int)
+{
+}
+
+
+static int
+runetokey(Rune r)
+{
+	switch(r){
+	case Kleft:
+		return KEY_LEFTARROW;
+	case Kright:
+		return KEY_RIGHTARROW;
+	case Kup:
+		return KEY_UPARROW;
+	case Kdown:
+		return KEY_DOWNARROW;
+
+	case Kshift:
+		return KEY_RSHIFT;
+	case Kctl:
+		return KEY_RCTRL;
+	case Kalt:
+		return KEY_LALT;
+	case Kaltgr:
+		return KEY_RALT;
+
+	case Kbs:
+		return KEY_BACKSPACE;
+	case '\n':
+		return KEY_ENTER;
+	case Kprint:
+		return KEY_PAUSE;
+
+	case KF|1:
+	case KF|2:
+	case KF|3:
+	case KF|4:
+	case KF|5:
+	case KF|6:
+	case KF|7:
+	case KF|8:
+	case KF|9:
+	case KF|10:
+	case KF|11:
+	case KF|12:
+		return KEY_F1+(r-(KF|1));
+
+	default:
+		if(r < 0x80)
+			return r;
+	}
+	return 0;
+}
+
+static void
+kbdproc(void)
+{
+	char buf[128], buf2[128], *s;
+	int kfd, n;
+	Rune r;
+	event_t e;
+
+	if((kfd = open("/dev/kbd", OREAD)) < 0)
+		sysfatal("can't open kbd: %r");
+
+	buf2[0] = 0;
+	buf2[1] = 0;
+	buf[0] = 0;
+	for(;;){
+		if(buf[0] != 0){
+			n = strlen(buf)+1;
+			memmove(buf, buf+n, sizeof(buf)-n);
+		}
+		if(buf[0] == 0){
+			n = read(kfd, buf, sizeof(buf)-1);
+			if(n <= 0)
+				break;
+			buf[n-1] = 0;
+			buf[n] = 0;
+		}
+
+		e.data1 = -1;
+		e.data2 = -1;
+		e.data3 = -1;
+
+		switch(buf[0]){
+		case 'c':
+			chartorune(&r, buf+1);
+			if(r){
+				e.data1 = r;
+				e.type = ev_char;
+				H2_PostEvent(&e);
+			}
+			/* no break */
+		default:
+			continue;
+		case 'k':
+			s = buf+1;
+			while(*s){
+				s += chartorune(&r, s);
+				if(utfrune(buf2+1, r) == nil){
+					if(e.data1 = runetokey(r)){
+						e.type = ev_keydown;
+						H2_PostEvent(&e);
+					}
+				}
+			}
+			break;
+		case 'K':
+			s = buf2+1;
+			while(*s){
+				s += chartorune(&r, s);
+				if(utfrune(buf+1, r) == nil){
+					if(e.data1 = runetokey(r)){
+						e.type = ev_keyup;
+						H2_PostEvent(&e);
+					}
+				}
+			}
+			break;
+		}
+		strcpy(buf2, buf);
+	}
+}
+
+static void
+mouseproc(void)
+{
+	int fd, n, nerr;
+	Mouse m, om;
+	char buf[1+5*12];
+	event_t e;
+
+	if((fd = open("/dev/mouse", ORDWR)) < 0)
+		sysfatal("can't open mouse: %r");
+
+	memset(&m, 0, sizeof m);
+	memset(&om, 0, sizeof om);
+	nerr = 0;
+	for(;;){
+		n = read(fd, buf, sizeof buf);
+		if(n != 1+4*12){
+			fprint(2, "mouse: bad count %d not 49: %r\n", n);
+			if(n<0 || ++nerr>10)
+				break;
+			continue;
+		}
+		nerr = 0;
+		switch(buf[0]){
+		case 'r':
+			resized = 1;
+			/* fall through */
+		case 'm':
+			if(!mouseactive)
+				break;
+
+			m.xy.x = atoi(buf+1+0*12);
+			m.xy.y = atoi(buf+1+1*12);
+			m.buttons = atoi(buf+1+2*12);
+			m.msec = atoi(buf+1+3*12);
+
+			if(!ptinrect(m.xy, grabout)){
+				fprint(fd, "m%d %d", center.x, center.y);
+
+				m.xy = center;
+				om.xy = center;
+			}
+			
+			e.type = ev_mouse;
+			e.data1 = m.buttons;
+			e.data2 = m.xy.x - om.xy.x;
+			e.data3 = om.xy.y - m.xy.y;
+			H2_PostEvent(&e);
+			om = m;
+
+			break;
+		}
+	}
+}
+
--- /dev/null
+++ b/i_video.h
@@ -1,0 +1,63 @@
+// Emacs style mode select   -*- C++ -*- 
+//-----------------------------------------------------------------------------
+//
+// $Id:$
+//
+// Copyright (C) 1993-1996 by id Software, Inc.
+//
+// This source is available for distribution and/or modification
+// only under the terms of the DOOM Source Code License as
+// published by id Software. All rights reserved.
+//
+// The source is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
+// for more details.
+//
+// DESCRIPTION:
+//	System specific interface stuff.
+//
+//-----------------------------------------------------------------------------
+
+
+#ifndef __I_VIDEO__
+#define __I_VIDEO__
+
+
+//#include "doomtype.h"
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+
+// Called by D_DoomMain,
+// determines the hardware configuration
+// and sets up the video mode
+void I_InitGraphics (void);
+
+
+void I_ShutdownGraphics(void);
+
+// Takes full 8 bit values.
+void I_SetPalette (byte* palette);
+
+void I_UpdateNoBlit (void);
+void I_FinishUpdate (void);
+void I_MouseEnable (int);
+
+// Wait for vertical retrace or pause a bit.
+void I_WaitVBL(int count);
+
+void I_ReadScreen (byte* scr);
+
+void I_BeginRead (void);
+void I_EndRead (void);
+
+
+#endif
+//-----------------------------------------------------------------------------
+//
+// $Log:$
+//
+//-----------------------------------------------------------------------------
--- a/m_misc.c
+++ b/m_misc.c
@@ -767,7 +767,7 @@
 //
 // munge planar buffer to linear
 // 
-	linear = screen;
+	linear = screens;
 //
 // find a file name to save it to
 //
--- a/mkfile
+++ b/mkfile
@@ -5,6 +5,12 @@
 CFLAGS=-Fpw
 
 OFILES=\
+	i_system.$O \
+	i_video.$O \
+	i_net.$O \
+	i_sound.$O \
+	i_cdmus.$O \
+	i_main.$O \
 	am_map.$O \
 	a_action.$O \
 	ct_chat.$O \
--- a/p_setup.c
+++ b/p_setup.c
@@ -1432,7 +1432,7 @@
 
 const char *P_GetMapSongLump(int map)
 {
-	if (!strcasecmp(MapInfo[QualifyMap(map)].songLump, DEFAULT_SONG_LUMP))
+	if (!cistrcmp(MapInfo[QualifyMap(map)].songLump, DEFAULT_SONG_LUMP))
 	{
 		return NULL;
 	}
--- a/r_data.c
+++ b/r_data.c
@@ -533,7 +533,7 @@
 
 	for (i = 0; i < numtextures; i++)
 	{
-		if (!strncasecmp(textures[i]->name, name, 8))
+		if (!cistrncmp(textures[i]->name, name, 8))
 			return i;
 	}
 
--- a/r_draw.c
+++ b/r_draw.c
@@ -473,7 +473,7 @@
 	else
 		viewwindowy = (SCREENHEIGHT - SBARHEIGHT - height) >> 1;
 	for (i = 0; i < height; i++)
-		ylookup[i] = screen + (i + viewwindowy)*SCREENWIDTH;
+		ylookup[i] = screens + (i + viewwindowy)*SCREENWIDTH;
 }
 
 
@@ -497,7 +497,7 @@
 		return;
 
 	src = (byte *) W_CacheLumpName("F_022", PU_CACHE);
-	dest = screen;
+	dest = screens;
 
 	for (y = 0 ; y < SCREENHEIGHT - SBARHEIGHT; y++)
 	{
@@ -548,7 +548,7 @@
 		return;
 
 	src = (byte *) W_CacheLumpName("F_022", PU_CACHE);
-	dest = screen;
+	dest = screens;
 
 	for (y = 0; y < 34; y++)
 	{
--- a/s_sound.c
+++ b/s_sound.c
@@ -381,12 +381,12 @@
 	{
 		if (*sc_String == '$')
 		{
-			if (!strcasecmp(sc_String, "$ARCHIVEPATH"))
+			if (!cistrcmp(sc_String, "$ARCHIVEPATH"))
 			{
 				SC_MustGetString();
 				strcpy(ArchivePath, sc_String);
 			}
-			else if (!strcasecmp(sc_String, "$MAP"))
+			else if (!cistrcmp(sc_String, "$MAP"))
 			{
 				SC_MustGetNumber();
 				SC_MustGetString();
--- a/sc_man.c
+++ b/sc_man.c
@@ -444,7 +444,7 @@
 
 boolean SC_Compare(const char *text)
 {
-	if (strcasecmp(text, sc_String) == 0)
+	if (cistrcmp(text, sc_String) == 0)
 	{
 		return true;
 	}
--- a/sn_sonix.c
+++ b/sn_sonix.c
@@ -129,7 +129,7 @@
 
 	for (i = 0; i < NUMSFX; i++)
 	{
-		if (!strcasecmp(name, S_sfx[i].tagName))
+		if (!cistrcmp(name, S_sfx[i].tagName))
 		{
 			return i;
 		}
@@ -182,7 +182,7 @@
 			}
 			for (j = 0; j < SEQ_NUMSEQ; j++)
 			{
-				if (!strcasecmp(SequenceTranslate[j].name, sc_String+1))
+				if (!cistrcmp(SequenceTranslate[j].name, sc_String+1))
 				{
 					SequenceTranslate[j].scriptNum = i;
 					inSequence = j;
--- a/v_video.c
+++ b/v_video.c
@@ -117,7 +117,7 @@
 
 #else	/* RENDER3D */
 
-byte	*screen;
+byte	*screens;
 int	dirtybox[4];
 
 //---------------------------------------------------------------------------
@@ -129,7 +129,7 @@
 void V_Init(void)
 {
 	// I_AllocLow will put screen in low dos memory on PCs.
-	screen = I_AllocLow(SCREENWIDTH*SCREENHEIGHT);
+	screens = I_AllocLow(SCREENWIDTH*SCREENHEIGHT);
 }
 
 //---------------------------------------------------------------------------
@@ -159,7 +159,7 @@
 	}
 
 	col = 0;
-	desttop = screen + y*SCREENWIDTH + x;
+	desttop = screens + y*SCREENWIDTH + x;
 	w = SHORT(patch->width);
 
 	for ( ; col < w; x++, col++, desttop++)
@@ -250,7 +250,7 @@
 	}
 
 	col = 0;
-	desttop = screen + y*SCREENWIDTH + x;
+	desttop = screens + y*SCREENWIDTH + x;
 	w = SHORT(patch->width);
 
 	for ( ; col < w; x++, col++, desttop++)
@@ -302,7 +302,7 @@
 	}
 
 	col = 0;
-	desttop = screen + y*SCREENWIDTH + x;
+	desttop = screens + y*SCREENWIDTH + x;
 	w = SHORT(patch->width);
 
 	for ( ; col < w; x++, col++, desttop++)
@@ -354,8 +354,8 @@
 	}
 
 	col = 0;
-	desttop = screen+y*SCREENWIDTH+x;
-	desttop2 = screen+(y+2)*SCREENWIDTH+x+2;
+	desttop = screens+y*SCREENWIDTH+x;
+	desttop2 = screens+(y+2)*SCREENWIDTH+x+2;
 	w = SHORT(patch->width);
 
 	for ( ; col < w; x++, col++, desttop++, desttop2++)
@@ -388,7 +388,7 @@
 	int	i, j;
 	byte	*dest;
 
-	dest = screen + x + SCREENWIDTH*y;
+	dest = screens + x + SCREENWIDTH*y;
 	for (i = 0; i < height; i++)
 	{
 		for (j = 0; j < width; j++)
@@ -407,7 +407,7 @@
 
 void V_DrawRawScreen(byte *raw)
 {
-	memcpy(screen, raw, SCREENWIDTH*SCREENHEIGHT);
+	memcpy(screens, raw, SCREENWIDTH*SCREENHEIGHT);
 }
 
 #endif	/* ! RENDER3D */
--- a/w_wad.c
+++ b/w_wad.c
@@ -648,7 +648,7 @@
 	}
 	l = lumpinfo+lump;
 	//I_BeginRead();
-	lseek(l->handle, l->position, SEEK_SET);
+	seek(l->handle, l->position, 0);
 	c = read(l->handle, dest, l->size);
 	if (c < l->size)
 	{