Skip to content

Instantly share code, notes, and snippets.

@Ferk
Last active October 23, 2019 11:14
Show Gist options
  • Select an option

  • Save Ferk/d3064376cc094278d92be715e0396f06 to your computer and use it in GitHub Desktop.

Select an option

Save Ferk/d3064376cc094278d92be715e0396f06 to your computer and use it in GitHub Desktop.
sdl_doom -> ps2doom diff
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/d_main.c ps2doom-master/d_main.c
--- sdl_doom-master/d_main.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/d_main.c 2011-04-08 20:08:52.000000000 +0200
@@ -31,15 +31,23 @@
#define FGCOLOR 8
-#ifdef NORMALUNIX
#include <stdio.h>
#include <stdlib.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#endif
+//extern int access(char *file, int mode);
+
+#define R_OK 4
+static int access(char *file, int mode)
+{
+ FILE *test_fp;
+
+ test_fp = fopen(file, "r");
+ if ( test_fp != NULL ) {
+ fclose(test_fp);
+ return(0);
+ }
+ return(-1);
+}
#include "doomdef.h"
#include "doomstat.h"
@@ -62,12 +70,7 @@
#include "i_system.h"
#include "i_sound.h"
-
-#ifdef __SDL__
-#include "i_sdl_video.h"
-#else
#include "i_video.h"
-#endif
#include "g_game.h"
@@ -398,16 +401,6 @@
// Update display, next frame, with current state.
D_Display ();
-
-#ifndef SNDSERV
- // Sound mixing for the buffer is snychronous.
- I_UpdateSound();
-#endif
- // Synchronous sound output is explicitly called.
-#ifndef SNDINTR
- // Update sound output.
- I_SubmitSound();
-#endif
}
}
@@ -577,47 +570,50 @@
char* plutoniawad;
char* tntwad;
-#ifdef NORMALUNIX
char *home;
char *doomwaddir;
doomwaddir = getenv("DOOMWADDIR");
+
+ #ifdef _EE
+ doomwaddir = "";
+ #else
if (!doomwaddir)
- doomwaddir = ".";
+ doomwaddir = "./";
+ #endif
// Commercial.
doom2wad = malloc(strlen(doomwaddir)+1+9+1);
- sprintf(doom2wad, "%s/doom2.wad", doomwaddir);
+ sprintf(doom2wad, "%sdoom2.wad", doomwaddir);
// Retail.
- doomuwad = malloc(strlen(doomwaddir)+1+9+1);
- sprintf(doomuwad, "%s/doomu.wad", doomwaddir);
+ doomuwad = malloc(strlen(doomwaddir)+1+8+1);
+ sprintf(doomuwad, "%sdoomu.wad", doomwaddir);
// Registered.
doomwad = malloc(strlen(doomwaddir)+1+8+1);
- sprintf(doomwad, "%s/doom.wad", doomwaddir);
+ sprintf(doomwad, "%sdoom.wad", doomwaddir);
// Shareware.
doom1wad = malloc(strlen(doomwaddir)+1+9+1);
- sprintf(doom1wad, "%s/doom1.wad", doomwaddir);
+ sprintf(doom1wad, "%sdoom1.wad", doomwaddir);
// Bug, dear Shawn.
// Insufficient malloc, caused spurious realloc errors.
plutoniawad = malloc(strlen(doomwaddir)+1+/*9*/12+1);
- sprintf(plutoniawad, "%s/plutonia.wad", doomwaddir);
+ sprintf(plutoniawad, "%splutonia.wad", doomwaddir);
tntwad = malloc(strlen(doomwaddir)+1+9+1);
- sprintf(tntwad, "%s/tnt.wad", doomwaddir);
+ sprintf(tntwad, "%stnt.wad", doomwaddir);
// French stuff.
doom2fwad = malloc(strlen(doomwaddir)+1+10+1);
- sprintf(doom2fwad, "%s/doom2f.wad", doomwaddir);
+ sprintf(doom2fwad, "%sdoom2f.wad", doomwaddir);
home = getenv("HOME");
if (!home)
- I_Error("Please set $HOME to your home directory");
- sprintf(basedefault, "%s/.doomrc", home);
-#endif
+ home = ".";
+ sprintf(basedefault, "%s.doomrc", home);
if (M_CheckParm ("-shdev"))
{
@@ -826,28 +822,28 @@
" "
"The Ultimate DOOM Startup v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
case shareware:
sprintf (title,
" "
"DOOM Shareware Startup v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
case registered:
sprintf (title,
" "
"DOOM Registered Startup v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
case commercial:
sprintf (title,
" "
"DOOM 2: Hell on Earth v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
/*FIXME
case pack_plut:
@@ -855,14 +851,14 @@
" "
"DOOM 2: Plutonia Experiment v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
case pack_tnt:
sprintf (title,
" "
"DOOM 2: TNT - Evilution v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
*/
default:
@@ -870,7 +866,7 @@
" "
"Public DOOM - v%i.%i"
" ",
- VERSION/100,VERSION%100);
+ VERSION_NUM/100,VERSION_NUM%100);
break;
}
@@ -879,13 +875,6 @@
if (devparm)
printf(D_DEVSTR);
- if (M_CheckParm("-cdrom"))
- {
- printf(D_CDROM);
- mkdir("c:\\doomdata",0);
- strcpy (basedefault,"c:/doomdata/default.cfg");
- }
-
// turbo option
if ( (p=M_CheckParm ("-turbo")) )
{
@@ -1016,6 +1005,11 @@
printf ("V_Init: allocate screens.\n");
V_Init ();
+ #ifdef _EE
+ SDL_SYS_TimerInit();
+ #endif
+
+
printf ("M_LoadDefaults: Load system defaults.\n");
M_LoadDefaults (); // load before initing other systems
@@ -1024,6 +1018,7 @@
printf ("W_Init: Init WADfiles.\n");
W_InitMultipleFiles (wadfiles);
+printf("added\n");
// Check for -file in shareware
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/d_net.c ps2doom-master/d_net.c
--- sdl_doom-master/d_net.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/d_net.c 2011-04-08 20:08:52.000000000 +0200
@@ -492,7 +492,7 @@
continue;
if (netbuffer->checksum & NCMD_SETUP)
{
- if (netbuffer->player != VERSION)
+ if (netbuffer->player != VERSION_NUM)
I_Error ("Different DOOM versions cannot play a net game!");
startskill = netbuffer->retransmitfrom & 15;
deathmatch = (netbuffer->retransmitfrom & 0xc0) >> 6;
@@ -521,7 +521,7 @@
if (respawnparm)
netbuffer->retransmitfrom |= 0x10;
netbuffer->starttic = startepisode * 64 + startmap;
- netbuffer->player = VERSION;
+ netbuffer->player = VERSION_NUM;
netbuffer->numtics = 0;
HSendPacket (i, NCMD_SETUP);
}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/doomdef.h ps2doom-master/doomdef.h
--- sdl_doom-master/doomdef.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/doomdef.h 2011-04-08 20:08:52.000000000 +0200
@@ -30,7 +30,7 @@
// Global parameters/defines.
//
// DOOM version
-enum { VERSION = 110 };
+enum { VERSION_NUM = 110 };
// Game mode handling - identify IWAD version
@@ -107,9 +107,6 @@
// Defines suck. C sucks.
// C++ might sucks for OOP, but it sure is a better C.
// So there.
-#define MAX_SCREEN_BLOCKS 11
-#define MAX_SCREEN_SIZE (MAX_SCREEN_BLOCKS - 3)
-
#define SCREENWIDTH 320
//SCREEN_MUL*BASE_WIDTH //320
#define SCREENHEIGHT 200
Only in ps2doom-master/: doomsav0.dsg
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/doomtype.h ps2doom-master/doomtype.h
--- sdl_doom-master/doomtype.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/doomtype.h 2011-04-08 20:08:52.000000000 +0200
@@ -31,6 +31,13 @@
#ifdef __cplusplus
typedef bool boolean;
#else
+#ifdef __BEOS__ /* boolean is a builtin type for MWCC */
+#define boolean D_BOOL
+#undef false
+#define false D_false
+#undef true
+#define true D_true
+#endif
typedef enum {false, true} boolean;
#endif
typedef unsigned char byte;
@@ -41,19 +48,35 @@
#ifdef LINUX
#include <values.h>
#else
+#ifndef MAXCHAR
#define MAXCHAR ((char)0x7f)
+#endif
+#ifndef MAXSHORT
#define MAXSHORT ((short)0x7fff)
+#endif
// Max pos 32-bit int.
+#ifndef MAXINT
#define MAXINT ((int)0x7fffffff)
+#endif
+#ifndef MAXLONG
#define MAXLONG ((long)0x7fffffff)
+#endif
+#ifndef MINCHAR
#define MINCHAR ((char)0x80)
+#endif
+#ifndef MINSHORT
#define MINSHORT ((short)0x8000)
+#endif
// Max negative 32-bit integer.
+#ifndef MININT
#define MININT ((int)0x80000000)
+#endif
+#ifndef MINLONG
#define MINLONG ((long)0x80000000)
#endif
+#endif
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/f_finale.c ps2doom-master/f_finale.c
--- sdl_doom-master/f_finale.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/f_finale.c 2011-04-08 20:08:52.000000000 +0200
@@ -28,8 +28,8 @@
#include <ctype.h>
// Functions.
-#include "i_system.h"
#include "m_swap.h"
+#include "i_system.h"
#include "z_zone.h"
#include "v_video.h"
#include "w_wad.h"
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/g_game.c ps2doom-master/g_game.c
--- sdl_doom-master/g_game.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/g_game.c 2011-04-08 20:08:52.000000000 +0200
@@ -1212,8 +1212,8 @@
// skip the description field
memset (vcheck,0,sizeof(vcheck));
- sprintf (vcheck,"version %i",VERSION);
- if (strcmp (save_p, vcheck))
+ sprintf (vcheck,"version %i",VERSION_NUM);
+ if (strcmp ((char *)save_p, vcheck))
return; // bad version
save_p += VERSIONSIZE;
@@ -1286,7 +1286,7 @@
memcpy (save_p, description, SAVESTRINGSIZE);
save_p += SAVESTRINGSIZE;
memset (name2,0,sizeof(name2));
- sprintf (name2,"version %i",VERSION);
+ sprintf (name2,"version %i",VERSION_NUM);
memcpy (save_p, name2, VERSIONSIZE);
save_p += VERSIONSIZE;
@@ -1552,7 +1552,7 @@
demo_p = demobuffer;
- *demo_p++ = VERSION;
+ *demo_p++ = VERSION_NUM;
*demo_p++ = gameskill;
*demo_p++ = gameepisode;
*demo_p++ = gamemap;
@@ -1586,7 +1586,7 @@
gameaction = ga_nothing;
demobuffer = demo_p = W_CacheLumpName (defdemoname, PU_STATIC);
- if ( *demo_p++ != VERSION)
+ if ( *demo_p++ != VERSION_NUM)
{
fprintf( stderr, "Demo is from a different game version!\n");
gameaction = ga_nothing;
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/hu_lib.c ps2doom-master/hu_lib.c
--- sdl_doom-master/hu_lib.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/hu_lib.c 2011-04-08 20:08:52.000000000 +0200
@@ -25,10 +25,11 @@
#include <ctype.h>
+#include "m_swap.h"
+
#include "doomdef.h"
#include "v_video.h"
-#include "m_swap.h"
#include "hu_lib.h"
#include "r_local.h"
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_main.c ps2doom-master/i_main.c
--- sdl_doom-master/i_main.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_main.c 2011-04-08 20:08:52.000000000 +0200
@@ -25,6 +25,7 @@
rcsid[] = "$Id: i_main.c,v 1.4 1997/02/03 22:45:10 b1 Exp $";
+#include "SDL.h"
#include "doomdef.h"
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_net.c ps2doom-master/i_net.c
--- sdl_doom-master/i_net.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_net.c 2011-04-08 20:08:52.000000000 +0200
@@ -26,14 +26,42 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
+#include <errno.h>
+#if defined(linux) || defined(__SVR4)
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
-#include <errno.h>
#include <unistd.h>
#include <netdb.h>
#include <sys/ioctl.h>
+#else
+#ifdef __BEOS__
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <unistd.h>
+#include <netdb.h>
+#include <sys/ioctl.h>
+#include <byteorder.h>
+#ifndef IPPORT_USERRESERVED
+#define IPPORT_USERRESERVED 5000
+#endif
+#else
+#ifdef __WIN32__
+#define Win32_Winsock
+#include <windows.h>
+#else
+#ifdef _EE // PlayStation 2 Emotion Engine
+#include <tcpip.h>
+#include <ps2ip.h>
+#include "ps2doom.h"
+#define IPPORT_USERRESERVED 1024 // ??
+#else
+#error You should hack this file for your BSD sockets layer
+#endif
+#endif
+#endif
+#endif
#include "i_system.h"
#include "d_event.h"
@@ -52,18 +80,31 @@
// For some odd reason...
+#ifndef B_HOST_IS_LENDIAN
+#define B_HOST_IS_LENDIAN 1
+#endif
+#if !defined(sparc) && B_HOST_IS_LENDIAN
+#ifndef ntohl
#define ntohl(x) \
((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
(((unsigned long int)(x) & 0x0000ff00U) << 8) | \
(((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
(((unsigned long int)(x) & 0xff000000U) >> 24)))
+#endif
+#ifndef ntohs
#define ntohs(x) \
((unsigned short int)((((unsigned short int)(x) & 0x00ff) << 8) | \
- (((unsigned short int)(x) & 0xff00) >> 8))) \
+ (((unsigned short int)(x) & 0xff00) >> 8)))
+#endif
+#ifndef htonl
#define htonl(x) ntohl(x)
+#endif
+#ifndef htons
#define htons(x) ntohs(x)
+#endif
+#endif
void NetSend (void);
boolean NetListen (void);
@@ -92,7 +133,7 @@
int s;
// allocate a socket
- s = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP);
+ s = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s<0)
I_Error ("can't create socket: %s",strerror(errno));
@@ -171,7 +212,9 @@
, (struct sockaddr *)&fromaddress, &fromlen );
if (c == -1 )
{
+#ifdef EWOULDBLOCK
if (errno != EWOULDBLOCK)
+#endif
I_Error ("GetPacket: %s",strerror(errno));
doomcom->remotenode = -1; // no packet
return;
@@ -222,7 +265,7 @@
int GetLocalAddress (void)
{
char hostname[1024];
- struct hostent* hostentry; // host information entry
+ struct hostent* hostentry = 0; // host information entry
int v;
// get local address
@@ -230,7 +273,12 @@
if (v == -1)
I_Error ("GetLocalAddress : gethostname: errno %d",errno);
+ #ifdef _EE
+ // TODO!!
+ #else
hostentry = gethostbyname (hostname);
+ #endif
+
if (!hostentry)
I_Error ("GetLocalAddress : gethostbyname: couldn't get local host");
@@ -246,7 +294,7 @@
boolean trueval = true;
int i;
int p;
- struct hostent* hostentry; // host information entry
+ struct hostent* hostentry = 0; // host information entry
doomcom = malloc (sizeof (*doomcom) );
memset (doomcom, 0, sizeof(*doomcom) );
@@ -311,7 +359,12 @@
}
else
{
+ #ifdef _EE
+ // TODO!!
+ #else
hostentry = gethostbyname (myargv[i]);
+ #endif
+
if (!hostentry)
I_Error ("gethostbyname: couldn't find %s", myargv[i]);
sendaddress[doomcom->numnodes].sin_addr.s_addr
@@ -326,7 +379,9 @@
// build message to receive
insocket = UDPsocket ();
BindToLocalPort (insocket,htons(DOOMPORT));
+#ifdef linux
ioctl (insocket, FIONBIO, &trueval);
+#endif
sendsocket = UDPsocket ();
}
Only in sdl_doom-master/: i_sdl_video.c
Only in sdl_doom-master/: i_sdl_video.h
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_sound.c ps2doom-master/i_sound.c
--- sdl_doom-master/i_sound.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_sound.c 2011-04-08 20:08:52.000000000 +0200
@@ -24,33 +24,16 @@
static const char
rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $";
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-
#include <math.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-#ifndef LINUX
-#include <sys/filio.h>
-#endif
-
-#include <fcntl.h>
-#include <unistd.h>
-#include <sys/ioctl.h>
-
-// Linux voxware output.
-#include <linux/soundcard.h>
-
-// Timer stuff. Experimental.
-#include <time.h>
-#include <signal.h>
+#include "SDL_audio.h"
+#include "SDL_mutex.h"
+#include "SDL_byteorder.h"
+#include "SDL_version.h"
#include "z_zone.h"
+#include "m_swap.h"
#include "i_system.h"
#include "i_sound.h"
#include "m_argv.h"
@@ -59,30 +42,6 @@
#include "doomdef.h"
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-// Separate sound server process.
-FILE* sndserver=0;
-char* sndserver_filename = "./sndserver ";
-#elif SNDINTR
-
-// Update all 30 millisecs, approx. 30fps synchronized.
-// Linux resolution is allegedly 10 millisecs,
-// scale is microseconds.
-#define SOUND_INTERVAL 500
-
-// Get the interrupt. Set duration in millisecs.
-int I_SoundSetTimer( int duration_of_tick );
-void I_SoundDelTimer( void );
-#else
-// None?
-#endif
-
-
-// A quick hack to establish a protocol between
-// synchronous mix buffer updates and asynchronous
-// audio writes. Probably redundant with gametic.
-static int flag = 0;
// The number of internal mixing channels,
// the samples calculated for each mixing step,
@@ -91,14 +50,10 @@
// Needed for calling the actual sound output.
-#define SAMPLECOUNT 512
+static int SAMPLECOUNT= 512;
#define NUM_CHANNELS 8
-// It is 2 for 16bit, and 2 for two channels.
-#define BUFMUL 4
-#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
#define SAMPLERATE 11025 // Hz
-#define SAMPLESIZE 2 // 16bit
// The actual lengths of all sound effects.
int lengths[NUMSFX];
@@ -106,12 +61,6 @@
// The actual output device.
int audio_fd;
-// The global mixing buffer.
-// Basically, samples from all active internal channels
-// are modifed and added, and stored in the buffer
-// that is submitted to the audio device.
-signed short mixbuffer[MIXBUFFERSIZE];
-
// The channel step amount...
unsigned int channelstep[NUM_CHANNELS];
@@ -153,31 +102,6 @@
-
-//
-// Safe ioctl, convenience.
-//
-void
-myioctl
-( int fd,
- int command,
- int* arg )
-{
- int rc;
-
- rc = ioctl(fd, command, arg);
- if (rc < 0)
- {
- fprintf(stderr, "ioctl(dsp,%d,arg) failed\n", command);
- fprintf(stderr, "errno=%d\n", errno);
- exit(-1);
- }
-}
-
-
-
-
-
//
// This function loads the sound data from the WAD lump,
// for single sound.
@@ -354,6 +278,7 @@
// Per left/right channel.
// x^2 seperation,
// adjust volume properly.
+ volume *= 8;
leftvol =
volume - ((volume*seperation*seperation) >> 16); ///(256*256);
seperation = seperation - 257;
@@ -419,8 +344,10 @@
// which also turn the unsigned samples
// into signed samples.
for (i=0 ; i<128 ; i++)
- for (j=0 ; j<256 ; j++)
+ for (j=0 ; j<256 ; j++) {
vol_lookup[i*256+j] = (i*(j-128)*256)/127;
+//fprintf(stderr, "vol_lookup[%d*256+%d] = %d\n", i, j, vol_lookup[i*256+j]);
+ }
}
@@ -479,25 +406,17 @@
// UNUSED
priority = 0;
-#ifdef SNDSERV
- if (sndserver)
- {
- fprintf(sndserver, "p%2.2x%2.2x%2.2x%2.2x\n", id, pitch, vol, sep);
- fflush(sndserver);
- }
- // warning: control reaches end of non-void function.
- return id;
-#else
// Debug.
//fprintf( stderr, "starting sound %d", id );
// Returns a handle (not used).
+ SDL_LockAudio();
id = addsfx( id, vol, steptable[pitch], sep );
+ SDL_UnlockAudio();
// fprintf( stderr, "/handle is %d\n", id );
return id;
-#endif
}
@@ -521,54 +440,44 @@
}
-
-
//
// 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).
+// mixes the per channel samples into the given
+// mixing buffer, and clamping it to the allowed
+// range.
//
// This function currently supports only 16bit.
//
-void I_UpdateSound( void )
+void I_UpdateSound(void *unused, Uint8 *stream, int len)
{
-#ifdef SNDINTR
- // Debug. Count buffer misses with interrupt.
- static int misses = 0;
-#endif
-
-
// Mix current sound data.
// Data, from raw sound, for right and left.
register unsigned int sample;
register int dl;
register int dr;
- // Pointers in global mixbuffer, left, right, end.
+ // Pointers in audio stream, left, right, end.
signed short* leftout;
signed short* rightout;
signed short* leftend;
- // Step in mixbuffer, left and right, thus two.
+ // Step in stream, left and right, thus two.
int step;
// Mixing channel index.
int chan;
// Left and right channel
- // are in global mixbuffer, alternating.
- leftout = mixbuffer;
- rightout = mixbuffer+1;
+ // are in audio stream, alternating.
+ leftout = (signed short *)stream;
+ rightout = ((signed short *)stream)+1;
step = 2;
// Determine end, for left channel only
// (right channel is implicit).
- leftend = mixbuffer + SAMPLECOUNT*step;
+ leftend = leftout + SAMPLECOUNT*step;
// Mix sounds into the mixing buffer.
// Loop over step*SAMPLECOUNT,
@@ -629,48 +538,12 @@
else
*rightout = dr;
- // Increment current pointers in mixbuffer.
+ // Increment current pointers in stream
leftout += step;
rightout += step;
}
-
-#ifdef SNDINTR
- // Debug check.
- if ( flag )
- {
- misses += flag;
- flag = 0;
- }
-
- if ( misses > 10 )
- {
- fprintf( stderr, "I_SoundUpdate: missed 10 buffer writes\n");
- misses = 0;
- }
-
- // Increment flag for update.
- flag++;
-#endif
}
-
-//
-// This would be used to write out the mixbuffer
-// during each game loop update.
-// Updates sound buffer and audio device at runtime.
-// It is called during Timer interrupt with SNDINTR.
-// Mixing now done synchronous, and
-// only output be done asynchronous?
-//
-void
-I_SubmitSound(void)
-{
- // Write it to DSP device.
- write(audio_fd, mixbuffer, SAMPLECOUNT*BUFMUL);
-}
-
-
-
void
I_UpdateSoundParams
( int handle,
@@ -688,109 +561,37 @@
}
-
-
void I_ShutdownSound(void)
{
-#ifdef SNDSERV
- if (sndserver)
- {
- // Send a "quit" command.
- fprintf(sndserver, "q\n");
- fflush(sndserver);
- }
-#else
- // Wait till all pending sounds are finished.
- int done = 0;
- int i;
-
-
- // FIXME (below).
- fprintf( stderr, "I_ShutdownSound: NOT finishing pending sounds\n");
- fflush( stderr );
-
- while ( !done )
- {
- for( i=0 ; i<8 && !channels[i] ; i++);
-
- // FIXME. No proper channel output.
- //if (i==8)
- done=1;
- }
-#ifdef SNDINTR
- I_SoundDelTimer();
-#endif
-
- // Cleaning up -releasing the DSP device.
- close ( audio_fd );
-#endif
-
- // Done.
- return;
+ SDL_CloseAudio();
}
-
-
-
-
void
I_InitSound()
{
-#ifdef SNDSERV
- char buffer[256];
-
- if (getenv("DOOMWADDIR"))
- sprintf(buffer, "%s/%s",
- getenv("DOOMWADDIR"),
- sndserver_filename);
- else
- sprintf(buffer, "%s", sndserver_filename);
-
- // start sound process
- if ( !access(buffer, X_OK) )
- {
- strcat(buffer, " -quiet");
- sndserver = popen(buffer, "w");
- }
- else
- fprintf(stderr, "Could not start sound server [%s]\n", buffer);
-#else
-
+ SDL_AudioSpec wanted;
int i;
-#ifdef SNDINTR
- fprintf( stderr, "I_SoundSetTimer: %d microsecs\n", SOUND_INTERVAL );
- I_SoundSetTimer( SOUND_INTERVAL );
-#endif
-
// Secure and configure sound device first.
fprintf( stderr, "I_InitSound: ");
- audio_fd = open("/dev/dsp", O_WRONLY);
- if (audio_fd<0)
- fprintf(stderr, "Could not open /dev/dsp\n");
-
-
- i = 11 | (2<<16);
- myioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &i);
- myioctl(audio_fd, SNDCTL_DSP_RESET, 0);
-
- i=SAMPLERATE;
-
- myioctl(audio_fd, SNDCTL_DSP_SPEED, &i);
-
- i=1;
- myioctl(audio_fd, SNDCTL_DSP_STEREO, &i);
-
- myioctl(audio_fd, SNDCTL_DSP_GETFMTS, &i);
-
- if (i&=AFMT_S16_LE)
- myioctl(audio_fd, SNDCTL_DSP_SETFMT, &i);
- else
- fprintf(stderr, "Could not play signed 16 data\n");
-
- fprintf(stderr, " configured audio device\n" );
+ // Open the audio device
+ wanted.freq = SAMPLERATE;
+ if ( SDL_BYTEORDER == SDL_BIG_ENDIAN ) {
+ wanted.format = AUDIO_S16MSB;
+ } else {
+ wanted.format = AUDIO_S16LSB;
+ }
+ wanted.channels = 2;
+ wanted.samples = SAMPLECOUNT;
+ wanted.callback = I_UpdateSound;
+ if ( SDL_OpenAudio(&wanted, NULL) < 0 ) {
+ fprintf(stderr, "couldn't open audio with desired format\n");
+ return;
+ }
+ SAMPLECOUNT = wanted.samples;
+ fprintf(stderr, " configured audio device with %d samples/slice\n", SAMPLECOUNT);
// Initialize external data (all sounds) at start, keep static.
@@ -814,14 +615,9 @@
fprintf( stderr, " pre-cached all sound data\n");
- // Now initialize mixbuffer with zero.
- for ( i = 0; i< MIXBUFFERSIZE; i++ )
- mixbuffer[i] = 0;
-
// Finished initialization.
fprintf(stderr, "I_InitSound: sound module ready\n");
-
-#endif
+ SDL_PauseAudio(0);
}
@@ -888,98 +684,3 @@
return looping || musicdies > gametic;
}
-
-
-//
-// Experimental stuff.
-// A Linux timer interrupt, for asynchronous
-// sound output.
-// I ripped this out of the Timer class in
-// our Difference Engine, including a few
-// SUN remains...
-//
-#ifdef sun
- typedef sigset_t tSigSet;
-#else
- typedef int tSigSet;
-#endif
-
-
-// We might use SIGVTALRM and ITIMER_VIRTUAL, if the process
-// time independend timer happens to get lost due to heavy load.
-// SIGALRM and ITIMER_REAL doesn't really work well.
-// There are issues with profiling as well.
-static int /*__itimer_which*/ itimer = ITIMER_REAL;
-
-static int sig = SIGALRM;
-
-// Interrupt handler.
-void I_HandleSoundTimer( int ignore )
-{
- // Debug.
- //fprintf( stderr, "%c", '+' ); fflush( stderr );
-
- // Feed sound device if necesary.
- if ( flag )
- {
- // See I_SubmitSound().
- // Write it to DSP device.
- write(audio_fd, mixbuffer, SAMPLECOUNT*BUFMUL);
-
- // Reset flag counter.
- flag = 0;
- }
- else
- return;
-
- // UNUSED, but required.
- ignore = 0;
- return;
-}
-
-// Get the interrupt. Set duration in millisecs.
-int I_SoundSetTimer( int duration_of_tick )
-{
- // Needed for gametick clockwork.
- struct itimerval value;
- struct itimerval ovalue;
- struct sigaction act;
- struct sigaction oact;
-
- int res;
-
- // This sets to SA_ONESHOT and SA_NOMASK, thus we can not use it.
- // signal( _sig, handle_SIG_TICK );
-
- // Now we have to change this attribute for repeated calls.
- act.sa_handler = I_HandleSoundTimer;
-#ifndef sun
- //ac t.sa_mask = _sig;
-#endif
- act.sa_flags = SA_RESTART;
-
- sigaction( sig, &act, &oact );
-
- value.it_interval.tv_sec = 0;
- value.it_interval.tv_usec = duration_of_tick;
- value.it_value.tv_sec = 0;
- value.it_value.tv_usec = duration_of_tick;
-
- // Error is -1.
- res = setitimer( itimer, &value, &ovalue );
-
- // Debug.
- if ( res == -1 )
- fprintf( stderr, "I_SoundSetTimer: interrupt n.a.\n");
-
- return res;
-}
-
-
-// Remove the interrupt. Set duration to zero.
-void I_SoundDelTimer()
-{
- // Debug.
- if ( I_SoundSetTimer( 0 ) == -1)
- fprintf( stderr, "I_SoundDelTimer: failed to remove interrupt. Doh!\n");
-}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_sound.h ps2doom-master/i_sound.h
--- sdl_doom-master/i_sound.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_sound.h 2011-04-08 20:08:52.000000000 +0200
@@ -25,13 +25,6 @@
#include "doomdef.h"
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-#include <stdio.h>
-extern FILE* sndserver;
-extern char* sndserver_filename;
-#endif
-
#include "doomstat.h"
#include "sounds.h"
@@ -40,10 +33,6 @@
// Init at program start...
void I_InitSound();
-// ... update sound buffer and audio device at runtime...
-void I_UpdateSound(void);
-void I_SubmitSound(void);
-
// ... shut down and relase at program termination.
void I_ShutdownSound(void);
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_system.c ps2doom-master/i_system.c
--- sdl_doom-master/i_system.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_system.c 2011-04-08 20:08:52.000000000 +0200
@@ -25,12 +25,10 @@
#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
#include <stdarg.h>
-#include <sys/time.h>
-#include <unistd.h>
+#include <ctype.h>
+#include "SDL.h"
+#include "SDL_timer.h"
#include "doomdef.h"
#include "m_misc.h"
@@ -51,6 +49,19 @@
int mb_used = 6;
+int I_strncasecmp(char *str1, char *str2, int len)
+{
+ char c1, c2;
+
+ while ( *str1 && *str2 && len-- ) {
+ c1 = *str1++;
+ c2 = *str2++;
+ if ( toupper(c1) != toupper(c2) )
+ return(1);
+ }
+ return(0);
+}
+
void
I_Tactile
( int on,
@@ -83,20 +94,11 @@
//
// I_GetTime
-// returns time in 1/70th second tics
+// returns time in 1/35 second tics
//
int I_GetTime (void)
{
- struct timeval tp;
- struct timezone tzp;
- int newtics;
- static int basetime=0;
-
- gettimeofday(&tp, &tzp);
- if (!basetime)
- basetime = tp.tv_sec;
- newtics = (tp.tv_sec-basetime)*TICRATE + tp.tv_usec*TICRATE/1000000;
- return newtics;
+ return (SDL_GetTicks()*TICRATE)/1000;
}
@@ -106,8 +108,16 @@
//
void I_Init (void)
{
+ if ( SDL_Init(SDL_INIT_AUDIO|SDL_INIT_VIDEO|SDL_INIT_JOYSTICK) < 0 )
+ I_Error("Could not initialize SDL: %s", SDL_GetError());
+
I_InitSound();
// I_InitGraphics();
+
+ SDL_Joystick *joystick;
+
+ joystick = SDL_JoystickOpen(0);
+
}
//
@@ -125,15 +135,7 @@
void I_WaitVBL(int count)
{
-#ifdef SGI
- sginap(1);
-#else
-#ifdef SUN
- sleep(0);
-#else
- usleep (count * (1000000/70) );
-#endif
-#endif
+ SDL_Delay((count*1000)/70);
}
void I_BeginRead(void)
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_system.h ps2doom-master/i_system.h
--- sdl_doom-master/i_system.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_system.h 2011-04-08 20:08:52.000000000 +0200
@@ -88,6 +88,8 @@
void I_Error (char *error, ...);
+// fixes bug under Win32 (mingwin32)
+int I_strncasecmp(char *str1, char *str2, int len);
#endif
//-----------------------------------------------------------------------------
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/i_video.c ps2doom-master/i_video.c
--- sdl_doom-master/i_video.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/i_video.c 2011-04-08 20:08:52.000000000 +0200
@@ -17,7 +17,7 @@
// $Log:$
//
// DESCRIPTION:
-// DOOM graphics stuff for X11, UNIX.
+// DOOM graphics stuff for SDL library
//
//-----------------------------------------------------------------------------
@@ -25,30 +25,10 @@
rcsid[] = "$Id: i_x.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
#include <stdlib.h>
-#include <unistd.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/keysym.h>
-
-#include <X11/extensions/XShm.h>
-// Had to dig up XShm.c for this one.
-// It is in the libXext, but not in the XFree86 headers.
-#ifdef LINUX
-int XShmGetEventBase( Display* dpy ); // problems with g++?
-#endif
-#include <stdarg.h>
-#include <sys/time.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-
-#include <netinet/in.h>
-#include <errno.h>
-#include <signal.h>
+#include "SDL.h"
+#include "m_swap.h"
#include "doomstat.h"
#include "i_system.h"
#include "v_video.h"
@@ -57,103 +37,81 @@
#include "doomdef.h"
-#define POINTER_WARP_COUNTDOWN 1
-
-Display* X_display=0;
-Window X_mainWindow;
-Colormap X_cmap;
-Visual* X_visual;
-GC X_gc;
-XEvent X_event;
-int X_screen;
-XVisualInfo X_visualinfo;
-XImage* image;
-int X_width;
-int X_height;
-
-// MIT SHared Memory extension.
-boolean doShm;
-XShmSegmentInfo X_shminfo;
-int X_shmeventtype;
+SDL_Surface *screen;
// Fake mouse handling.
-// This cannot work properly w/o DGA.
-// Needs an invisible mouse cursor at least.
boolean grabMouse;
-int doPointerWarp = POINTER_WARP_COUNTDOWN;
// Blocky mode,
// replace each 320x200 pixel with multiply*multiply pixels.
// According to Dave Taylor, it still is a bonehead thing
// to use ....
static int multiply=1;
+static int joy_x=0, joy_y=0;
+#define JOYVAL 5000
//
-// Translates the key currently in X_event
+// Translates the key
//
-int xlatekey(void)
+int xlatekey(SDL_keysym *key)
{
int rc;
- switch(rc = XKeycodeToKeysym(X_display, X_event.xkey.keycode, 0))
+ switch(key->sym)
{
- case XK_Left: rc = KEY_LEFTARROW; break;
- case XK_Right: rc = KEY_RIGHTARROW; break;
- case XK_Down: rc = KEY_DOWNARROW; break;
- case XK_Up: rc = KEY_UPARROW; break;
- case XK_Escape: rc = KEY_ESCAPE; break;
- case XK_Return: rc = KEY_ENTER; break;
- case XK_Tab: rc = KEY_TAB; break;
- case XK_F1: rc = KEY_F1; break;
- case XK_F2: rc = KEY_F2; break;
- case XK_F3: rc = KEY_F3; break;
- case XK_F4: rc = KEY_F4; break;
- case XK_F5: rc = KEY_F5; break;
- case XK_F6: rc = KEY_F6; break;
- case XK_F7: rc = KEY_F7; break;
- case XK_F8: rc = KEY_F8; break;
- case XK_F9: rc = KEY_F9; break;
- case XK_F10: rc = KEY_F10; break;
- case XK_F11: rc = KEY_F11; break;
- case XK_F12: rc = KEY_F12; break;
-
- case XK_BackSpace:
- case XK_Delete: rc = KEY_BACKSPACE; break;
-
- case XK_Pause: rc = KEY_PAUSE; break;
+ case SDLK_LEFT: rc = KEY_LEFTARROW; break;
+ case SDLK_RIGHT: rc = KEY_RIGHTARROW; break;
+ case SDLK_DOWN: rc = KEY_DOWNARROW; break;
+ case SDLK_UP: rc = KEY_UPARROW; break;
+ case SDLK_ESCAPE: rc = KEY_ESCAPE; break;
+ case SDLK_RETURN: rc = KEY_ENTER; break;
+ case SDLK_TAB: rc = KEY_TAB; break;
+ case SDLK_F1: rc = KEY_F1; break;
+ case SDLK_F2: rc = KEY_F2; break;
+ case SDLK_F3: rc = KEY_F3; break;
+ case SDLK_F4: rc = KEY_F4; break;
+ case SDLK_F5: rc = KEY_F5; break;
+ case SDLK_F6: rc = KEY_F6; break;
+ case SDLK_F7: rc = KEY_F7; break;
+ case SDLK_F8: rc = KEY_F8; break;
+ case SDLK_F9: rc = KEY_F9; break;
+ case SDLK_F10: rc = KEY_F10; break;
+ case SDLK_F11: rc = KEY_F11; break;
+ case SDLK_F12: rc = KEY_F12; break;
+
+ case SDLK_BACKSPACE:
+ case SDLK_DELETE: rc = KEY_BACKSPACE; break;
+
+ case SDLK_PAUSE: rc = KEY_PAUSE; break;
- case XK_KP_Equal:
- case XK_equal: rc = KEY_EQUALS; break;
+ case SDLK_EQUALS: rc = KEY_EQUALS; break;
- case XK_KP_Subtract:
- case XK_minus: rc = KEY_MINUS; break;
+ case SDLK_KP_MINUS:
+ case SDLK_MINUS: rc = KEY_MINUS; break;
- case XK_Shift_L:
- case XK_Shift_R:
+ case SDLK_LSHIFT:
+ case SDLK_RSHIFT:
rc = KEY_RSHIFT;
break;
- case XK_Control_L:
- case XK_Control_R:
+ case SDLK_LCTRL:
+ case SDLK_RCTRL:
rc = KEY_RCTRL;
break;
- case XK_Alt_L:
- case XK_Meta_L:
- case XK_Alt_R:
- case XK_Meta_R:
+ case SDLK_LALT:
+ case SDLK_LMETA:
+ case SDLK_RALT:
+ case SDLK_RMETA:
rc = KEY_RALT;
break;
default:
- if (rc >= XK_space && rc <= XK_asciitilde)
- rc = rc - XK_space + ' ';
- if (rc >= 'A' && rc <= 'Z')
- rc = rc - 'A' + 'a';
+ rc = key->sym;
break;
}
@@ -163,16 +121,7 @@
void I_ShutdownGraphics(void)
{
- // Detach from X server
- if (!XShmDetach(X_display, &X_shminfo))
- I_Error("XShmDetach() failed in I_ShutdownGraphics()");
-
- // Release shared memory.
- shmdt(X_shminfo.shmaddr);
- shmctl(X_shminfo.shmid, IPC_RMID, 0);
-
- // Paranoia.
- image->data = NULL;
+ SDL_Quit();
}
@@ -186,121 +135,199 @@
}
-static int lastmousex = 0;
-static int lastmousey = 0;
-boolean mousemoved = false;
-boolean shmFinished;
-void I_GetEvent(void)
-{
+
+/* This processes SDL events */
+void I_GetEvent(SDL_Event *Event)
+{
+ Uint8 buttonstate;
event_t event;
- // put event-grabbing stuff in here
- XNextEvent(X_display, &X_event);
- switch (X_event.type)
+ //printf("Event->type: %i\n", Event->type);
+
+ switch (Event->type)
+ {
+ /* PS2 joystick support */
+
+ case SDL_JOYBUTTONDOWN:
{
- case KeyPress:
+ // printf("button: %i\n", Event->jbutton.button);
+
+ switch(Event->jbutton.button)
+ {
+ case 0:
+ event.data1 = KEY_RCTRL;
+ break;
+
+ case 1:
+ event.data1 = KEY_ENTER;
+ break;
+
+ case 2:
+ event.data1 = SDLK_SPACE;
+ break;
+
+ case 3:
+ event.data1 = KEY_ESCAPE;
+ break;
+
+ case 6:
+ event.data1 = SDLK_x;
+ break;
+
+ case 7:
+ event.data1 = KEY_RCTRL;
+ break;
+
+ case 8:
+ event.data1 = SDLK_y;
+ break;
+
+ case 9:
+ event.data1 = SDLK_SPACE;
+ break;
+
+
+ }
event.type = ev_keydown;
- event.data1 = xlatekey();
+
D_PostEvent(&event);
- // fprintf(stderr, "k");
+
+ } break;
+
+ case SDL_JOYBUTTONUP:
+ {
+ switch(Event->jbutton.button)
+ {
+ case 0:
+ event.data1 = KEY_RCTRL;
break;
- case KeyRelease:
- event.type = ev_keyup;
- event.data1 = xlatekey();
- D_PostEvent(&event);
- // fprintf(stderr, "ku");
+
+ case 1:
+ event.data1 = KEY_ENTER;
break;
- case ButtonPress:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xbutton.state & Button1Mask)
- | (X_event.xbutton.state & Button2Mask ? 2 : 0)
- | (X_event.xbutton.state & Button3Mask ? 4 : 0)
- | (X_event.xbutton.button == Button1)
- | (X_event.xbutton.button == Button2 ? 2 : 0)
- | (X_event.xbutton.button == Button3 ? 4 : 0);
- event.data2 = event.data3 = 0;
- D_PostEvent(&event);
- // fprintf(stderr, "b");
+
+ case 2:
+ event.data1 = KEY_RCTRL;
break;
- case ButtonRelease:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xbutton.state & Button1Mask)
- | (X_event.xbutton.state & Button2Mask ? 2 : 0)
- | (X_event.xbutton.state & Button3Mask ? 4 : 0);
- // suggest parentheses around arithmetic in operand of |
- event.data1 =
- event.data1
- ^ (X_event.xbutton.button == Button1 ? 1 : 0)
- ^ (X_event.xbutton.button == Button2 ? 2 : 0)
- ^ (X_event.xbutton.button == Button3 ? 4 : 0);
- event.data2 = event.data3 = 0;
- D_PostEvent(&event);
- // fprintf(stderr, "bu");
+
+ case 3:
+ event.data1 = KEY_ESCAPE;
break;
- case MotionNotify:
- event.type = ev_mouse;
- event.data1 =
- (X_event.xmotion.state & Button1Mask)
- | (X_event.xmotion.state & Button2Mask ? 2 : 0)
- | (X_event.xmotion.state & Button3Mask ? 4 : 0);
- event.data2 = (X_event.xmotion.x - lastmousex) << 2;
- event.data3 = (lastmousey - X_event.xmotion.y) << 2;
-
- if (event.data2 || event.data3)
- {
- lastmousex = X_event.xmotion.x;
- lastmousey = X_event.xmotion.y;
- if (X_event.xmotion.x != X_width/2 &&
- X_event.xmotion.y != X_height/2)
- {
+
+ case 6:
+ event.data1 = SDLK_x;
+ break;
+
+ case 7:
+ event.data1 = KEY_RCTRL;
+ break;
+
+ case 8:
+ event.data1 = SDLK_y;
+ break;
+
+ case 9:
+ event.data1 = SDLK_SPACE;
+ break;
+
+ }
+
+ event.type = ev_keyup;
+
D_PostEvent(&event);
- // fprintf(stderr, "m");
- mousemoved = false;
- } else
+
+ } break;
+
+
+ case SDL_JOYAXISMOTION:
+ {
+ // printf(" event.jaxis.axis : %i value: %i\n", Event->jaxis.axis, Event->jaxis.value);
+
+
+ if( Event->jaxis.axis == 0)
{
- mousemoved = true;
+ joy_x = 0;
+
+ if( (Event->jaxis.value > JOYVAL) )
+ joy_x = 1;
+ else
+ if( ( Event->jaxis.value < -JOYVAL) )
+ joy_x = -1;
}
+
+ if( Event->jaxis.axis == 1)
+ {
+ joy_y = 0;
+
+ if( (Event->jaxis.value > JOYVAL) )
+ joy_y = 1;
+ else
+ if( ( Event->jaxis.value < -JOYVAL) )
+ joy_y = -1;
}
+
+ event.data2 = joy_x;
+ event.data3 = joy_y;
+ event.type = ev_joystick;
+
+ D_PostEvent(&event);
+
+ } break;
+
+
+
+
+ case SDL_KEYDOWN:
+ event.type = ev_keydown;
+ event.data1 = xlatekey(&Event->key.keysym);
+ D_PostEvent(&event);
break;
- case Expose:
- case ConfigureNotify:
+ case SDL_KEYUP:
+ event.type = ev_keyup;
+ event.data1 = xlatekey(&Event->key.keysym);
+ D_PostEvent(&event);
break;
- default:
- if (doShm && X_event.type == X_shmeventtype) shmFinished = true;
+ case SDL_MOUSEBUTTONDOWN:
+ case SDL_MOUSEBUTTONUP:
+ buttonstate = SDL_GetMouseState(NULL, NULL);
+ event.type = ev_mouse;
+ event.data1 = 0
+ | (buttonstate & SDL_BUTTON(1) ? 1 : 0)
+ | (buttonstate & SDL_BUTTON(2) ? 2 : 0)
+ | (buttonstate & SDL_BUTTON(3) ? 4 : 0);
+ event.data2 = event.data3 = 0;
+ D_PostEvent(&event);
break;
+
+#if (SDL_MAJOR_VERSION >= 0) && (SDL_MINOR_VERSION >= 9)
+ case SDL_MOUSEMOTION:
+ /* Ignore mouse warp events */
+ if ((Event->motion.x != screen->w/2)||(Event->motion.y != screen->h/2))
+ {
+ /* Warp the mouse back to the center */
+ if (grabMouse) {
+ SDL_WarpMouse(screen->w/2, screen->h/2);
}
+ event.type = ev_mouse;
+ event.data1 = 0
+ | (Event->motion.state & SDL_BUTTON(1) ? 1 : 0)
+ | (Event->motion.state & SDL_BUTTON(2) ? 2 : 0)
+ | (Event->motion.state & SDL_BUTTON(3) ? 4 : 0);
+ event.data2 = Event->motion.xrel << 2;
+ event.data3 = -Event->motion.yrel << 2;
+ D_PostEvent(&event);
+ }
+ break;
+#endif
+ case SDL_QUIT:
+ I_Quit();
}
-Cursor
-createnullcursor
-( Display* display,
- Window root )
-{
- Pixmap cursormask;
- XGCValues xgc;
- GC gc;
- XColor dummycolour;
- Cursor cursor;
-
- cursormask = XCreatePixmap(display, root, 1, 1, 1/*depth*/);
- xgc.function = GXclear;
- gc = XCreateGC(display, cursormask, GCFunction, &xgc);
- XFillRectangle(display, cursormask, gc, 0, 0, 1, 1);
- dummycolour.pixel = 0;
- dummycolour.red = 0;
- dummycolour.flags = 04;
- cursor = XCreatePixmapCursor(display, cursormask, cursormask,
- &dummycolour,&dummycolour, 0,0);
- XFreePixmap(display,cursormask);
- XFreeGC(display,gc);
- return cursor;
}
//
@@ -308,33 +335,12 @@
//
void I_StartTic (void)
{
+ SDL_Event Event;
- if (!X_display)
- return;
-
- while (XPending(X_display))
- I_GetEvent();
-
- // Warp the pointer back to the middle of the window
- // or it will wander off - that is, the game will
- // loose input focus within X11.
- if (grabMouse)
- {
- if (!--doPointerWarp)
- {
- XWarpPointer( X_display,
- None,
- X_mainWindow,
- 0, 0,
- 0, 0,
- X_width/2, X_height/2);
-
- doPointerWarp = POINTER_WARP_COUNTDOWN;
- }
- }
-
- mousemoved = false;
+ // printf("starttic\n");
+ while ( SDL_PollEvent(&Event) )
+ I_GetEvent(&Event);
}
@@ -355,7 +361,6 @@
static int lasttic;
int tics;
int i;
- // UNUSED static unsigned char *bigscreen=0;
// draws little dots on the bottom of the screen
if (devparm)
@@ -370,11 +375,32 @@
screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0xff;
for ( ; i<20*2 ; i+=2)
screens[0][ (SCREENHEIGHT-1)*SCREENWIDTH + i] = 0x0;
-
}
// scales the screen size before blitting it
- if (multiply == 2)
+ if ( SDL_MUSTLOCK(screen) ) {
+ if ( SDL_LockSurface(screen) < 0 ) {
+ return;
+ }
+ }
+ if ((multiply == 1) && SDL_MUSTLOCK(screen))
+ {
+ unsigned char *olineptr;
+ unsigned char *ilineptr;
+ int y;
+
+ ilineptr = (unsigned char *) screens[0];
+ olineptr = (unsigned char *) screen->pixels;
+
+ y = SCREENHEIGHT;
+ while (y--)
+ {
+ memcpy(olineptr, ilineptr, screen->w);
+ ilineptr += SCREENWIDTH;
+ olineptr += screen->pitch;
+ }
+ }
+ else if (multiply == 2)
{
unsigned int *olineptrs[2];
unsigned int *ilineptr;
@@ -384,8 +410,10 @@
unsigned int fouripixels;
ilineptr = (unsigned int *) (screens[0]);
- for (i=0 ; i<2 ; i++)
- olineptrs[i] = (unsigned int *) &image->data[i*X_width];
+ for (i=0 ; i<2 ; i++) {
+ olineptrs[i] =
+ (unsigned int *)&((Uint8 *)screen->pixels)[i*screen->pitch];
+ }
y = SCREENHEIGHT;
while (y--)
@@ -412,8 +440,8 @@
*olineptrs[1]++ = twoopixels;
#endif
} while (x-=4);
- olineptrs[0] += X_width/4;
- olineptrs[1] += X_width/4;
+ olineptrs[0] += screen->pitch/4;
+ olineptrs[1] += screen->pitch/4;
}
}
@@ -426,8 +454,10 @@
unsigned int fouripixels;
ilineptr = (unsigned int *) (screens[0]);
- for (i=0 ; i<3 ; i++)
- olineptrs[i] = (unsigned int *) &image->data[i*X_width];
+ for (i=0 ; i<3 ; i++) {
+ olineptrs[i] =
+ (unsigned int *)&((Uint8 *)screen->pixels)[i*screen->pitch];
+ }
y = SCREENHEIGHT;
while (y--)
@@ -467,57 +497,18 @@
*olineptrs[2]++ = fouropixels[0];
#endif
} while (x-=4);
- olineptrs[0] += 2*X_width/4;
- olineptrs[1] += 2*X_width/4;
- olineptrs[2] += 2*X_width/4;
+ olineptrs[0] += 2*screen->pitch/4;
+ olineptrs[1] += 2*screen->pitch/4;
+ olineptrs[2] += 2*screen->pitch/4;
}
}
- else if (multiply == 4)
- {
- // Broken. Gotta fix this some day.
- void Expand4(unsigned *, double *);
- Expand4 ((unsigned *)(screens[0]), (double *) (image->data));
- }
-
- if (doShm)
- {
-
- if (!XShmPutImage( X_display,
- X_mainWindow,
- X_gc,
- image,
- 0, 0,
- 0, 0,
- X_width, X_height,
- True ))
- I_Error("XShmPutImage() failed\n");
-
- // wait for it to finish and processes all input events
- shmFinished = false;
- do
- {
- I_GetEvent();
- } while (!shmFinished);
-
- }
- else
- {
-
- // draw the image
- XPutImage( X_display,
- X_mainWindow,
- X_gc,
- image,
- 0, 0,
- 0, 0,
- X_width, X_height );
-
- // sync up with server
- XSync(X_display, False);
-
+ if ( SDL_MUSTLOCK(screen) ) {
+ SDL_UnlockSurface(screen);
}
+ SDL_UpdateRect(screen, 0, 0, 0, 0);
+ SDL_Flip(screen);
}
@@ -531,193 +522,42 @@
//
-// Palette stuff.
-//
-static XColor colors[256];
-
-void UploadNewPalette(Colormap cmap, byte *palette)
-{
-
- register int i;
- register int c;
- static boolean firstcall = true;
-
-#ifdef __cplusplus
- if (X_visualinfo.c_class == PseudoColor && X_visualinfo.depth == 8)
-#else
- if (X_visualinfo.class == PseudoColor && X_visualinfo.depth == 8)
-#endif
- {
- // initialize the colormap
- if (firstcall)
- {
- firstcall = false;
- for (i=0 ; i<256 ; i++)
- {
- colors[i].pixel = i;
- colors[i].flags = DoRed|DoGreen|DoBlue;
- }
- }
-
- // set the X colormap entries
- for (i=0 ; i<256 ; i++)
- {
- c = gammatable[usegamma][*palette++];
- colors[i].red = (c<<8) + c;
- c = gammatable[usegamma][*palette++];
- colors[i].green = (c<<8) + c;
- c = gammatable[usegamma][*palette++];
- colors[i].blue = (c<<8) + c;
- }
-
- // store the colors to the current colormap
- XStoreColors(X_display, cmap, colors, 256);
-
- }
-}
-
-//
// I_SetPalette
//
void I_SetPalette (byte* palette)
{
- UploadNewPalette(X_cmap, palette);
-}
-
-
-//
-// This function is probably redundant,
-// if XShmDetach works properly.
-// ddt never detached the XShm memory,
-// thus there might have been stale
-// handles accumulating.
-//
-void grabsharedmemory(int size)
-{
-
- int key = ('d'<<24) | ('o'<<16) | ('o'<<8) | 'm';
- struct shmid_ds shminfo;
- int minsize = 320*200;
- int id;
- int rc;
- // UNUSED int done=0;
- int pollution=5;
-
- // try to use what was here before
- do
- {
- id = shmget((key_t) key, minsize, 0777); // just get the id
- if (id != -1)
- {
- rc=shmctl(id, IPC_STAT, &shminfo); // get stats on it
- if (!rc)
- {
- if (shminfo.shm_nattch)
- {
- fprintf(stderr, "User %d appears to be running "
- "DOOM. Is that wise?\n", shminfo.shm_cpid);
- key++;
- }
- else
- {
- if (getuid() == shminfo.shm_perm.cuid)
- {
- rc = shmctl(id, IPC_RMID, 0);
- if (!rc)
- fprintf(stderr,
- "Was able to kill my old shared memory\n");
- else
- I_Error("Was NOT able to kill my old shared memory");
-
- id = shmget((key_t)key, size, IPC_CREAT|0777);
- if (id==-1)
- I_Error("Could not get shared memory");
-
- rc=shmctl(id, IPC_STAT, &shminfo);
-
- break;
-
- }
- if (size >= shminfo.shm_segsz)
- {
- fprintf(stderr,
- "will use %d's stale shared memory\n",
- shminfo.shm_cpid);
- break;
- }
- else
- {
- fprintf(stderr,
- "warning: can't use stale "
- "shared memory belonging to id %d, "
- "key=0x%x\n",
- shminfo.shm_cpid, key);
- key++;
- }
- }
- }
- else
- {
- I_Error("could not get stats on key=%d", key);
- }
- }
- else
- {
- id = shmget((key_t)key, size, IPC_CREAT|0777);
- if (id==-1)
- {
- extern int errno;
- fprintf(stderr, "errno=%d\n", errno);
- I_Error("Could not get any shared memory");
- }
- break;
- }
- } while (--pollution);
+ int i;
+ SDL_Color colors[256];
- if (!pollution)
- {
- I_Error("Sorry, system too polluted with stale "
- "shared memory segments.\n");
+ for ( i=0; i<256; ++i ) {
+ colors[i].r = gammatable[usegamma][*palette++];
+ colors[i].g = gammatable[usegamma][*palette++];
+ colors[i].b = gammatable[usegamma][*palette++];
+ colors[i].unused = 0;
}
-
- X_shminfo.shmid = id;
-
- // attach to the shared memory segment
- image->data = X_shminfo.shmaddr = shmat(id, 0, 0);
-
- fprintf(stderr, "shared memory id=%d, addr=0x%x\n", id,
- (int) (image->data));
+ SDL_SetColors(screen, colors, 0, 256);
}
-// TODO: Look more careful on I_InitGraphics()
-
void I_InitGraphics(void)
{
- char* displayname;
- char* d;
- int n;
- int pnum;
- int x=0;
- int y=0;
-
- // warning: char format, different type arg
- char xsign=' ';
- char ysign=' ';
-
- int oktodraw;
- unsigned long attribmask;
- XSetWindowAttributes attribs;
- XGCValues xgcvalues;
- int valuemask;
static int firsttime=1;
+ Uint16 video_w, video_h, w, h;
+ Uint8 video_bpp;
+ Uint32 video_flags;
if (!firsttime)
return;
firsttime = 0;
- signal(SIGINT, (void (*)(int)) I_Quit);
+ video_flags = (SDL_DOUBLEBUF | SDL_HWSURFACE);
+ if (!!M_CheckParm("-fullscreen"))
+ video_flags |= SDL_FULLSCREEN;
+
+ #ifdef _EE
+ video_flags |= SDL_FULLSCREEN;
+ #endif
if (M_CheckParm("-2"))
multiply = 2;
@@ -725,329 +565,53 @@
if (M_CheckParm("-3"))
multiply = 3;
- if (M_CheckParm("-4"))
- multiply = 4;
-
- X_width = SCREENWIDTH * multiply;
- X_height = SCREENHEIGHT * multiply;
-
- // check for command-line display name
- if ( (pnum=M_CheckParm("-disp")) ) // suggest parentheses around assignment
- displayname = myargv[pnum+1];
- else
- displayname = 0;
-
// check if the user wants to grab the mouse (quite unnice)
grabMouse = !!M_CheckParm("-grabmouse");
- // check for command-line geometry
- if ( (pnum=M_CheckParm("-geom")) ) // suggest parentheses around assignment
- {
- // warning: char format, different type arg 3,5
- n = sscanf(myargv[pnum+1], "%c%d%c%d", &xsign, &x, &ysign, &y);
-
- if (n==2)
- x = y = 0;
- else if (n==6)
- {
- if (xsign == '-')
- x = -x;
- if (ysign == '-')
- y = -y;
- }
- else
- I_Error("bad -geom parameter");
- }
-
- // open the display
- X_display = XOpenDisplay(displayname);
- if (!X_display)
- {
- if (displayname)
- I_Error("Could not open display [%s]", displayname);
- else
- I_Error("Could not open display (DISPLAY=[%s])", getenv("DISPLAY"));
- }
-
- // use the default visual
- X_screen = DefaultScreen(X_display);
- if (!XMatchVisualInfo(X_display, X_screen, 8, PseudoColor, &X_visualinfo))
- I_Error("xdoom currently only supports 256-color PseudoColor screens");
- X_visual = X_visualinfo.visual;
-
- // check for the MITSHM extension
- doShm = XShmQueryExtension(X_display);
-
- // even if it's available, make sure it's a local connection
- if (doShm)
- {
- if (!displayname) displayname = (char *) getenv("DISPLAY");
- if (displayname)
- {
- d = displayname;
- while (*d && (*d != ':')) d++;
- if (*d) *d = 0;
- if (!(!strcasecmp(displayname, "unix") || !*displayname)) doShm = false;
- }
- }
-
- fprintf(stderr, "Using MITSHM extension\n");
-
- // create the colormap
- X_cmap = XCreateColormap(X_display, RootWindow(X_display,
- X_screen), X_visual, AllocAll);
-
- // setup attributes for main window
- attribmask = CWEventMask | CWColormap | CWBorderPixel;
- attribs.event_mask =
- KeyPressMask
- | KeyReleaseMask
- // | PointerMotionMask | ButtonPressMask | ButtonReleaseMask
- | ExposureMask;
-
- attribs.colormap = X_cmap;
- attribs.border_pixel = 0;
-
- // create the main window
- X_mainWindow = XCreateWindow( X_display,
- RootWindow(X_display, X_screen),
- x, y,
- X_width, X_height,
- 0, // borderwidth
- 8, // depth
- InputOutput,
- X_visual,
- attribmask,
- &attribs );
-
- XDefineCursor(X_display, X_mainWindow,
- createnullcursor( X_display, X_mainWindow ) );
-
- // create the GC
- valuemask = GCGraphicsExposures;
- xgcvalues.graphics_exposures = False;
- X_gc = XCreateGC( X_display,
- X_mainWindow,
- valuemask,
- &xgcvalues );
-
- // map the window
- XMapWindow(X_display, X_mainWindow);
-
- // wait until it is OK to draw
- oktodraw = 0;
- while (!oktodraw)
- {
- XNextEvent(X_display, &X_event);
- if (X_event.type == Expose
- && !X_event.xexpose.count)
- {
- oktodraw = 1;
- }
- }
-
- // grabs the pointer so it is restricted to this window
- if (grabMouse)
- XGrabPointer(X_display, X_mainWindow, True,
- ButtonPressMask|ButtonReleaseMask|PointerMotionMask,
- GrabModeAsync, GrabModeAsync,
- X_mainWindow, None, CurrentTime);
-
- if (doShm)
- {
-
- X_shmeventtype = XShmGetEventBase(X_display) + ShmCompletion;
-
- // create the image
- image = XShmCreateImage( X_display,
- X_visual,
- 8,
- ZPixmap,
- 0,
- &X_shminfo,
- X_width,
- X_height );
-
- grabsharedmemory(image->bytes_per_line * image->height);
-
-
- // UNUSED
- // create the shared memory segment
- // X_shminfo.shmid = shmget (IPC_PRIVATE,
- // image->bytes_per_line * image->height, IPC_CREAT | 0777);
- // if (X_shminfo.shmid < 0)
- // {
- // perror("");
- // I_Error("shmget() failed in InitGraphics()");
- // }
- // fprintf(stderr, "shared memory id=%d\n", X_shminfo.shmid);
- // attach to the shared memory segment
- // image->data = X_shminfo.shmaddr = shmat(X_shminfo.shmid, 0, 0);
-
-
- if (!image->data)
- {
- perror("");
- I_Error("shmat() failed in InitGraphics()");
- }
-
- // get the X server to attach to it
- if (!XShmAttach(X_display, &X_shminfo))
- I_Error("XShmAttach() failed in InitGraphics()");
-
- }
- else
- {
- image = XCreateImage( X_display,
- X_visual,
- 8,
- ZPixmap,
- 0,
- (char*)malloc(X_width * X_height),
- X_width, X_height,
- 8,
- X_width );
-
+ video_w = w = SCREENWIDTH * multiply;
+ video_h = h = SCREENHEIGHT * multiply;
+ video_bpp = 8;
+
+ /* We need to allocate a software surface because the DOOM! code expects
+ the screen surface to be valid all of the time. Properly done, the
+ rendering code would allocate the video surface in video memory and
+ then call SDL_LockSurface()/SDL_UnlockSurface() around frame rendering.
+ Eventually SDL will support flipping, which would be really nice in
+ a complete-frame rendering application like this.
+ */
+ switch (video_w/w) {
+ case 3:
+ multiply *= 3;
+ break;
+ case 2:
+ multiply *= 2;
+ break;
+ case 1:
+ multiply *= 1;
+ break;
+ default:
+ ;
}
-
- if (multiply == 1)
- screens[0] = (unsigned char *) (image->data);
- else
+ if ( multiply > 3 ) {
+ I_Error("Smallest available mode (%dx%d) is too large!",
+ video_w, video_h);
+ }
+ screen = SDL_SetVideoMode(video_w, video_h, 8, video_flags);
+ if ( screen == NULL ) {
+ I_Error("Could not set %dx%d video mode: %s", video_w, video_h,
+ SDL_GetError());
+ }
+ SDL_ShowCursor(0);
+ SDL_WM_SetCaption("SDL DOOM! v1.10", "doom");
+
+ /* Set up the screen displays */
+ w = SCREENWIDTH * multiply;
+ h = SCREENHEIGHT * multiply;
+ if (multiply == 1 && !SDL_MUSTLOCK(screen) ) {
+ screens[0] = (unsigned char *) screen->pixels;
+ } else {
screens[0] = (unsigned char *) malloc (SCREENWIDTH * SCREENHEIGHT);
-
+ if ( screens[0] == NULL )
+ I_Error("Couldn't allocate screen memory");
}
-
-
-unsigned exptable[256];
-
-void InitExpand (void)
-{
- int i;
-
- for (i=0 ; i<256 ; i++)
- exptable[i] = i | (i<<8) | (i<<16) | (i<<24);
}
-
-double exptable2[256*256];
-
-void InitExpand2 (void)
-{
- int i;
- int j;
- // UNUSED unsigned iexp, jexp;
- double* exp;
- union
- {
- double d;
- unsigned u[2];
- } pixel;
-
- printf ("building exptable2...\n");
- exp = exptable2;
- for (i=0 ; i<256 ; i++)
- {
- pixel.u[0] = i | (i<<8) | (i<<16) | (i<<24);
- for (j=0 ; j<256 ; j++)
- {
- pixel.u[1] = j | (j<<8) | (j<<16) | (j<<24);
- *exp++ = pixel.d;
- }
- }
- printf ("done.\n");
-}
-
-int inited;
-
-void
-Expand4
-( unsigned* lineptr,
- double* xline )
-{
- double dpixel;
- unsigned x;
- unsigned y;
- unsigned fourpixels;
- unsigned step;
- double* exp;
-
- exp = exptable2;
- if (!inited)
- {
- inited = 1;
- InitExpand2 ();
- }
-
-
- step = 3*SCREENWIDTH/2;
-
- y = SCREENHEIGHT-1;
- do
- {
- x = SCREENWIDTH;
-
- do
- {
- fourpixels = lineptr[0];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[0] = dpixel;
- xline[160] = dpixel;
- xline[320] = dpixel;
- xline[480] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[1] = dpixel;
- xline[161] = dpixel;
- xline[321] = dpixel;
- xline[481] = dpixel;
-
- fourpixels = lineptr[1];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[2] = dpixel;
- xline[162] = dpixel;
- xline[322] = dpixel;
- xline[482] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[3] = dpixel;
- xline[163] = dpixel;
- xline[323] = dpixel;
- xline[483] = dpixel;
-
- fourpixels = lineptr[2];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[4] = dpixel;
- xline[164] = dpixel;
- xline[324] = dpixel;
- xline[484] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[5] = dpixel;
- xline[165] = dpixel;
- xline[325] = dpixel;
- xline[485] = dpixel;
-
- fourpixels = lineptr[3];
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff0000)>>13) );
- xline[6] = dpixel;
- xline[166] = dpixel;
- xline[326] = dpixel;
- xline[486] = dpixel;
-
- dpixel = *(double *)( (int)exp + ( (fourpixels&0xffff)<<3 ) );
- xline[7] = dpixel;
- xline[167] = dpixel;
- xline[327] = dpixel;
- xline[487] = dpixel;
-
- lineptr+=4;
- xline+=8;
- } while (x-=16);
- xline += step;
- } while (y--);
-}
-
-
Only in ps2doom-master/: install-sh
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_argv.c ps2doom-master/m_argv.c
--- sdl_doom-master/m_argv.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_argv.c 2011-04-08 20:08:52.000000000 +0200
@@ -26,6 +26,8 @@
#include <string.h>
+#include "i_system.h"
+
int myargc;
char** myargv;
@@ -44,7 +46,7 @@
for (i = 1;i<myargc;i++)
{
- if ( !strcasecmp(check, myargv[i]) )
+ if ( !I_strncasecmp(check, myargv[i], strlen(check)) )
return i;
}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_bbox.h ps2doom-master/m_bbox.h
--- sdl_doom-master/m_bbox.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_bbox.h 2011-04-08 20:08:52.000000000 +0200
@@ -23,7 +23,7 @@
#ifndef __M_BBOX__
#define __M_BBOX__
-#include <values.h>
+#include "doomtype.h"
#include "m_fixed.h"
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_menu.c ps2doom-master/m_menu.c
--- sdl_doom-master/m_menu.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_menu.c 2011-04-08 20:08:52.000000000 +0200
@@ -25,14 +25,10 @@
static const char
rcsid[] = "$Id: m_menu.c,v 1.7 1997/02/03 22:45:10 b1 Exp $";
-#include <unistd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdlib.h>
+#include <stdio.h>
#include <ctype.h>
-
+#include "m_swap.h"
#include "doomdef.h"
#include "dstrings.h"
@@ -52,7 +48,6 @@
#include "g_game.h"
#include "m_argv.h"
-#include "m_swap.h"
#include "s_sound.h"
@@ -510,27 +505,24 @@
//
void M_ReadSaveStrings(void)
{
- int handle;
+ FILE *handle;
int count;
int i;
char name[256];
for (i = 0;i < load_end;i++)
{
- if (M_CheckParm("-cdrom"))
- sprintf(name,"c:\\doomdata\\"SAVEGAMENAME"%d.dsg",i);
- else
sprintf(name,SAVEGAMENAME"%d.dsg",i);
- handle = open (name, O_RDONLY | 0, 0666);
- if (handle == -1)
+ handle = fopen (name, "r");
+ if (handle == NULL)
{
strcpy(&savegamestrings[i][0],EMPTYSTRING);
LoadMenu[i].status = 0;
continue;
}
- count = read (handle, &savegamestrings[i], SAVESTRINGSIZE);
- close (handle);
+ count = fread (&savegamestrings[i], 1, SAVESTRINGSIZE, handle);
+ fclose (handle);
LoadMenu[i].status = 1;
}
}
@@ -1161,7 +1153,7 @@
}
break;
case 1:
- if (screenSize < MAX_SCREEN_SIZE)
+ if (screenSize < 8)
{
screenblocks++;
screenSize++;
@@ -1169,6 +1161,7 @@
break;
}
+
R_SetViewSize (screenblocks, detailLevel);
}
@@ -1742,7 +1735,7 @@
static short y;
short i;
short max;
- char string[128];
+ char string[40];
int start;
inhelpscreens = false;
@@ -1851,6 +1844,12 @@
whichSkull = 0;
skullAnimCounter = 10;
screenSize = screenblocks - 3;
+
+ // Hack - fullsize screen
+ screenSize++;
+ screenblocks++;
+
+
messageToPrint = 0;
messageString = NULL;
messageLastMenuActive = menuactive;
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_misc.c ps2doom-master/m_misc.c
--- sdl_doom-master/m_misc.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_misc.c 2011-04-08 20:08:52.000000000 +0200
@@ -27,14 +27,10 @@
static const char
rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
#include <stdlib.h>
-#include <unistd.h>
-
#include <ctype.h>
+extern int access(char *file, int mode);
#include "doomdef.h"
@@ -115,16 +111,16 @@
void* source,
int length )
{
- int handle;
+ FILE *handle;
int count;
- handle = open ( name, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666);
+ handle = fopen ( name, "wb");
- if (handle == -1)
+ if (handle == NULL)
return false;
- count = write (handle, source, length);
- close (handle);
+ count = fwrite (source, 1, length, handle);
+ fclose (handle);
if (count < length)
return false;
@@ -141,19 +137,19 @@
( char const* name,
byte** buffer )
{
- int handle, count, length;
- struct stat fileinfo;
+ FILE *handle;
+ int count, length;
byte *buf;
- handle = open (name, O_RDONLY | O_BINARY, 0666);
- if (handle == -1)
- I_Error ("Couldn't read file %s", name);
- if (fstat (handle,&fileinfo) == -1)
+ handle = fopen (name, "rb");
+ if (handle == NULL)
I_Error ("Couldn't read file %s", name);
- length = fileinfo.st_size;
+ fseek(handle, 0, SEEK_END);
+ length = ftell(handle);
+ rewind(handle);
buf = Z_Malloc (length, PU_STATIC, NULL);
- count = read (handle, buf, length);
- close (handle);
+ count = fread (buf, 1, length, handle);
+ fclose (handle);
if (count < length)
I_Error ("Couldn't read file %s", name);
@@ -207,17 +203,6 @@
extern int numChannels;
-// UNIX hack, to be removed.
-#ifdef SNDSERV
-extern char* sndserver_filename;
-extern int mb_used;
-#endif
-
-#ifdef LINUX
-char* mousetype;
-char* mousedev;
-#endif
-
extern char* chat_macros[];
@@ -239,7 +224,6 @@
{"show_messages",&showMessages, 1},
-#ifdef NORMALUNIX
{"key_right",&key_right, KEY_RIGHTARROW},
{"key_left",&key_left, KEY_LEFTARROW},
{"key_up",&key_up, KEY_UPARROW},
@@ -252,19 +236,6 @@
{"key_strafe",&key_strafe, KEY_RALT},
{"key_speed",&key_speed, KEY_RSHIFT},
-// UNIX hack, to be removed.
-#ifdef SNDSERV
- {"sndserver", (int *) &sndserver_filename, (int) "sndserver"},
- {"mb_used", &mb_used, 2},
-#endif
-
-#endif
-
-#ifdef LINUX
- {"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"},
- {"mousetype", (int*)&mousetype, (int)"microsoft"},
-#endif
-
{"use_mouse",&usemouse, 1},
{"mouseb_fire",&mousebfire,0},
{"mouseb_strafe",&mousebstrafe,1},
@@ -285,6 +256,7 @@
{"usegamma",&usegamma, 0},
+#ifndef __BEOS__
{"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 },
{"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 },
{"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 },
@@ -295,6 +267,7 @@
{"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 },
{"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 },
{"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 }
+#endif
};
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_swap.c ps2doom-master/m_swap.c
--- sdl_doom-master/m_swap.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_swap.c 2011-04-08 20:08:52.000000000 +0200
@@ -31,9 +31,6 @@
#include "m_swap.h"
-// Not needed with big endian.
-#ifndef __BIG_ENDIAN__
-
// Swap 16bit, that is, MSB and LSB byte.
unsigned short SwapSHORT(unsigned short x)
{
@@ -52,6 +49,3 @@
}
-#endif
-
-
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/m_swap.h ps2doom-master/m_swap.h
--- sdl_doom-master/m_swap.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/m_swap.h 2011-04-08 20:08:52.000000000 +0200
@@ -31,9 +31,16 @@
// Endianess handling.
// WAD files are stored little endian.
+#ifdef sparc
+#define __BIG_ENDIAN__
+#endif
+#ifdef __BEOS__
+#include <byteorder.h>
+#if B_HOST_IS_BENDIAN
+#define __BIG_ENDIAN__
+#endif
+#endif
#ifdef __BIG_ENDIAN__
-short SwapSHORT(short);
-long SwapLONG(long);
#define SHORT(x) ((short)SwapSHORT((unsigned short) (x)))
#define LONG(x) ((long)SwapLONG((unsigned long) (x)))
#else
Only in ps2doom-master/: missing
Only in ps2doom-master/: mkinstalldirs
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/p_doors.c ps2doom-master/p_doors.c
--- sdl_doom-master/p_doors.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/p_doors.c 2011-04-08 20:08:52.000000000 +0200
@@ -134,7 +134,7 @@
break;
case normal:
- case close:
+ case __close:
door->sector->specialdata = NULL;
P_RemoveThinker (&door->thinker); // unlink and free
break;
@@ -153,7 +153,7 @@
switch(door->type)
{
case blazeClose:
- case close: // DO NOT GO BACK UP!
+ case __close: // DO NOT GO BACK UP!
break;
default:
@@ -184,7 +184,7 @@
case close30ThenOpen:
case blazeOpen:
- case open:
+ case __open:
door->sector->specialdata = NULL;
P_RemoveThinker (&door->thinker); // unlink and free
break;
@@ -302,7 +302,7 @@
sfx_bdcls);
break;
- case close:
+ case __close:
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4*FRACUNIT;
door->direction = -1;
@@ -329,7 +329,7 @@
break;
case normal:
- case open:
+ case __open:
door->direction = 1;
door->topheight = P_FindLowestCeilingSurrounding(sec);
door->topheight -= 4*FRACUNIT;
@@ -478,7 +478,7 @@
case 32:
case 33:
case 34:
- door->type = open;
+ door->type = __open;
line->special = 0;
break;
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/p_enemy.c ps2doom-master/p_enemy.c
--- sdl_doom-master/p_enemy.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/p_enemy.c 2011-04-08 20:08:52.000000000 +0200
@@ -589,7 +589,7 @@
}
junk.tag = 666;
- EV_DoDoor(&junk,open);
+ EV_DoDoor(&junk,__open);
}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/p_spec.c ps2doom-master/p_spec.c
--- sdl_doom-master/p_spec.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/p_spec.c 2011-04-08 20:08:52.000000000 +0200
@@ -542,13 +542,13 @@
// All from here to RETRIGGERS.
case 2:
// Open Door
- EV_DoDoor(line,open);
+ EV_DoDoor(line,__open);
line->special = 0;
break;
case 3:
// Close Door
- EV_DoDoor(line,close);
+ EV_DoDoor(line,__close);
line->special = 0;
break;
@@ -801,7 +801,7 @@
case 75:
// Close Door
- EV_DoDoor(line,close);
+ EV_DoDoor(line,__close);
break;
case 76:
@@ -845,8 +845,8 @@
break;
case 86:
- // Open Door
- EV_DoDoor(line,open);
+ // __open Door
+ EV_DoDoor(line,__open);
break;
case 87:
@@ -987,7 +987,7 @@
case 46:
// OPEN DOOR
- EV_DoDoor(line,open);
+ EV_DoDoor(line,__open);
P_ChangeSwitchTexture(line,1);
break;
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/p_spec.h ps2doom-master/p_spec.h
--- sdl_doom-master/p_spec.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/p_spec.h 2011-04-08 20:08:52.000000000 +0200
@@ -329,8 +329,8 @@
{
normal,
close30ThenOpen,
- close,
- open,
+ __close,
+ __open,
raiseIn5Mins,
blazeRaise,
blazeOpen,
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/p_switch.c ps2doom-master/p_switch.c
--- sdl_doom-master/p_switch.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/p_switch.c 2011-04-08 20:08:52.000000000 +0200
@@ -424,7 +424,7 @@
case 50:
// Close Door
- if (EV_DoDoor(line,close))
+ if (EV_DoDoor(line,__close))
P_ChangeSwitchTexture(line,0);
break;
@@ -454,7 +454,7 @@
case 103:
// Open Door
- if (EV_DoDoor(line,open))
+ if (EV_DoDoor(line,__open))
P_ChangeSwitchTexture(line,0);
break;
@@ -513,7 +513,7 @@
// BUTTONS
case 42:
// Close Door
- if (EV_DoDoor(line,close))
+ if (EV_DoDoor(line,__close))
P_ChangeSwitchTexture(line,1);
break;
@@ -537,7 +537,7 @@
case 61:
// Open Door
- if (EV_DoDoor(line,open))
+ if (EV_DoDoor(line,__open))
P_ChangeSwitchTexture(line,1);
break;
Only in ps2doom-master/: ps2doom.c
Only in ps2doom-master/: ps2doom.h
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/r_data.c ps2doom-master/r_data.c
--- sdl_doom-master/r_data.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/r_data.c 2011-04-08 20:08:52.000000000 +0200
@@ -27,11 +27,19 @@
static const char
rcsid[] = "$Id: r_data.c,v 1.4 1997/02/03 16:47:55 b1 Exp $";
-#include "i_system.h"
-#include "z_zone.h"
+#ifdef __BEOS__
+#ifdef __GNUC__
+extern void *alloca(int);
+#else
+#include <alloca.h>
+#endif
+#endif /* __BEOS__ */
#include "m_swap.h"
+#include "i_system.h"
+#include "z_zone.h"
+
#include "w_wad.h"
#include "doomdef.h"
@@ -41,11 +49,6 @@
#include "doomstat.h"
#include "r_sky.h"
-#ifdef LINUX
-#include <alloca.h>
-#endif
-
-
#include "r_data.h"
//
@@ -530,7 +533,17 @@
texture->height = SHORT(mtexture->height);
texture->patchcount = SHORT(mtexture->patchcount);
+ /* memcpy() generates a BUS error on Solaris with optimization on */
+#if 0
memcpy (texture->name, mtexture->name, sizeof(texture->name));
+#else
+ { char *src; char *dst;
+ src = (char *)mtexture->name;
+ dst = (char *)texture->name;
+ for (j=0; j<sizeof(texture->name); ++j )
+ *dst++ = *src++;
+ }
+#endif
mpatch = &mtexture->patches[0];
patch = &texture->patches[0];
@@ -702,7 +715,7 @@
return 0;
for (i=0 ; i<numtextures ; i++)
- if (!strncasecmp (textures[i]->name, name, 8) )
+ if (!I_strncasecmp (textures[i]->name, name, 8) )
return i;
return -1;
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/r_main.c ps2doom-master/r_main.c
--- sdl_doom-master/r_main.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/r_main.c 2011-04-08 20:08:52.000000000 +0200
@@ -660,11 +660,7 @@
int detail )
{
setsizeneeded = true;
- if (blocks > MAX_SCREEN_BLOCKS) {
- setblocks = MAX_SCREEN_BLOCKS;
- } else {
setblocks = blocks;
- }
setdetail = detail;
}
@@ -683,7 +679,7 @@
setsizeneeded = false;
- if (setblocks == MAX_SCREEN_BLOCKS)
+ if (setblocks == 11)
{
scaledviewwidth = SCREENWIDTH;
viewheight = SCREENHEIGHT;
@@ -772,8 +768,6 @@
extern int detailLevel;
extern int screenblocks;
-
-
void R_Init (void)
{
R_InitData ();
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/st_lib.c ps2doom-master/st_lib.c
--- sdl_doom-master/st_lib.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/st_lib.c 2011-04-08 20:08:52.000000000 +0200
@@ -27,13 +27,13 @@
#include <ctype.h>
+#include "m_swap.h"
+
#include "doomdef.h"
#include "z_zone.h"
#include "v_video.h"
-#include "m_swap.h"
-
#include "i_system.h"
#include "w_wad.h"
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/tables.h ps2doom-master/tables.h
--- sdl_doom-master/tables.h 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/tables.h 2011-04-08 20:08:52.000000000 +0200
@@ -38,9 +38,7 @@
-#ifdef LINUX
-#include <math.h>
-#else
+#ifndef PI
#define PI 3.141592657
#endif
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/v_video.c ps2doom-master/v_video.c
--- sdl_doom-master/v_video.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/v_video.c 2011-04-08 20:08:52.000000000 +0200
@@ -28,6 +28,7 @@
rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $";
+#include "m_swap.h"
#include "i_system.h"
#include "r_local.h"
@@ -35,7 +36,6 @@
#include "doomdata.h"
#include "m_bbox.h"
-#include "m_swap.h"
#include "v_video.h"
@@ -482,18 +482,12 @@
void V_Init (void)
{
int i;
- // stick these in low dos memory on PCs
-
-#ifdef SDL
- // screen[0] is allocated by SDL_SetVideoMode()
- // in i_sdl_video.c
- for (i=1 ; i<4 ; i++)
- screens[i] = I_AllocLow(SCREENWIDTH*SCREENHEIGHT);
-#else
byte* base;
+ // stick these in low dos memory on PCs
+
base = I_AllocLow (SCREENWIDTH*SCREENHEIGHT*4);
+
for (i=0 ; i<4 ; i++)
screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
-#endif
}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/w_wad.c ps2doom-master/w_wad.c
--- sdl_doom-master/w_wad.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/w_wad.c 2011-04-08 20:08:52.000000000 +0200
@@ -26,20 +26,13 @@
rcsid[] = "$Id: w_wad.c,v 1.5 1997/02/03 16:47:57 b1 Exp $";
-#ifdef NORMALUNIX
-#include <ctype.h>
-#include <sys/types.h>
+#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
-#include <unistd.h>
-#include <malloc.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <alloca.h>
-#define O_BINARY 0
-#endif
+#include <ctype.h>
-#include "doomtype.h"
#include "m_swap.h"
+#include "doomtype.h"
#include "i_system.h"
#include "z_zone.h"
@@ -64,21 +57,25 @@
void** lumpcache;
-#define strcmpi strcasecmp
-
+#if defined(linux) || defined(__BEOS__) || defined(__SVR4)
void strupr (char* s)
{
while (*s) { *s = toupper(*s); s++; }
}
+#endif
-int filelength (int handle)
+int filelength (FILE *handle)
{
- struct stat fileinfo;
+ unsigned long pos, size;
- if (fstat (handle,&fileinfo) == -1)
- I_Error ("Error fstating");
+ pos = ftell(handle);
+printf("Position was %lu\n", pos);
+ fseek(handle, 0, SEEK_END);
+ size = ftell(handle);
+ fseek(handle, pos, SEEK_SET);
+printf("Size is %lu\n", size);
- return fileinfo.st_size;
+ return (int)size;
}
@@ -134,6 +131,14 @@
// specially to allow map reloads.
// But: the reload feature is a fragile hack...
+#ifdef __BEOS__
+#ifdef __GNUC__
+extern void *alloca(int);
+#else
+#include <alloca.h>
+#endif
+#endif /* __BEOS__ */
+
int reloadlump;
char* reloadname;
@@ -143,7 +148,7 @@
wadinfo_t header;
lumpinfo_t* lump_p;
unsigned i;
- int handle;
+ FILE *handle;
int length;
int startlump;
filelump_t* fileinfo;
@@ -160,7 +165,7 @@
reloadlump = numlumps;
}
- if ( (handle = open (filename,O_RDONLY | O_BINARY)) == -1)
+ if ( (handle = fopen (filename,"rb")) == NULL)
{
printf (" couldn't open %s\n",filename);
return;
@@ -169,7 +174,7 @@
printf (" adding %s\n",filename);
startlump = numlumps;
- if (strcmpi (filename+strlen(filename)-3 , "wad" ) )
+ if (I_strncasecmp (filename+strlen(filename)-3 , "wad", 3 ) )
{
// single lump file
fileinfo = &singleinfo;
@@ -181,7 +186,7 @@
else
{
// WAD file
- read (handle, &header, sizeof(header));
+ fread (&header, 1, sizeof(header), handle);
if (strncmp(header.identification,"IWAD",4))
{
// Homebrew levels?
@@ -197,8 +202,8 @@
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo = alloca (length);
- lseek (handle, header.infotableofs, SEEK_SET);
- read (handle, fileinfo, length);
+ fseek (handle, header.infotableofs, SEEK_SET);
+ fread (fileinfo, 1, length, handle);
numlumps += header.numlumps;
}
@@ -211,7 +216,7 @@
lump_p = &lumpinfo[startlump];
- storehandle = reloadname ? -1 : handle;
+ storehandle = reloadname ? -1 : (int)handle;
for (i=startlump ; i<numlumps ; i++,lump_p++, fileinfo++)
{
@@ -222,7 +227,7 @@
}
if (reloadname)
- close (handle);
+ fclose (handle);
}
@@ -239,23 +244,23 @@
int lumpcount;
lumpinfo_t* lump_p;
unsigned i;
- int handle;
+ FILE *handle;
int length;
filelump_t* fileinfo;
if (!reloadname)
return;
- if ( (handle = open (reloadname,O_RDONLY | O_BINARY)) == -1)
+ if ( (handle = fopen (reloadname,"rb")) == NULL)
I_Error ("W_Reload: couldn't open %s",reloadname);
- read (handle, &header, sizeof(header));
+ fread (&header, 1, sizeof(header), handle);
lumpcount = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = lumpcount*sizeof(filelump_t);
fileinfo = alloca (length);
- lseek (handle, header.infotableofs, SEEK_SET);
- read (handle, fileinfo, length);
+ fseek (handle, header.infotableofs, SEEK_SET);
+ fread (fileinfo, 1, length, handle);
// Fill in lumpinfo
lump_p = &lumpinfo[reloadlump];
@@ -271,7 +276,7 @@
lump_p->size = LONG(fileinfo->size);
}
- close (handle);
+ fclose (handle);
}
@@ -421,6 +426,39 @@
return lumpinfo[lump].size;
}
+int ps2_fread_init = 0;
+char *ps2_buffer;
+int ps2_pos = 0;
+
+int ps2_fread(void *dest, int num, int size, FILE *fd)
+{
+ if(ps2_fread_init == 0)
+ {
+ fseek(fd, 0, SEEK_END);
+
+ int size = ftell(fd);
+
+ // printf("file: %i size: %i\n", fd, size);
+
+ ps2_buffer = (char*)malloc(size);
+
+ fseek(fd, 0, SEEK_SET);
+
+ fread(ps2_buffer, 1, size, fd);
+
+ fclose(fd);
+
+ ps2_fread_init = 1;
+ }
+
+ memcpy(dest, ps2_buffer + ps2_pos, num * size);
+ return num*size;
+}
+
+void ps2_fseek(FILE* fd, int pos, int a)
+{
+ ps2_pos = pos;
+}
//
@@ -435,7 +473,7 @@
{
int c;
lumpinfo_t* l;
- int handle;
+ FILE *handle;
if (lump >= numlumps)
I_Error ("W_ReadLump: %i >= numlumps",lump);
@@ -447,21 +485,27 @@
if (l->handle == -1)
{
// reloadable file, so use open / read / close
- if ( (handle = open (reloadname,O_RDONLY | O_BINARY)) == -1)
+ if ( (handle = fopen (reloadname,"rb")) == NULL)
I_Error ("W_ReadLump: couldn't open %s",reloadname);
}
else
- handle = l->handle;
+ handle = (FILE *)l->handle;
- lseek (handle, l->position, SEEK_SET);
- c = read (handle, dest, l->size);
+ // Hack to make I/O quicker
+ ps2_fseek (handle, l->position, SEEK_SET);
+ c = ps2_fread (dest, 1, l->size, handle);
+
+ /*
+ fseek (handle, l->position, SEEK_SET);
+ c = fread (dest, 1, l->size, handle);
+ */
if (c < l->size)
I_Error ("W_ReadLump: only read %i of %i on lump %i",
c,l->size,lump);
if (l->handle == -1)
- close (handle);
+ fclose (handle);
// ??? I_EndRead ();
}
diff -wur --exclude '*.TXT' --exclude 'READ*' --exclude '*.txt' --exclude CVS --exclude 'Change*' --exclude 'config.*' --exclude 'configure*' --exclude '*.m4' --exclude 'Make*' --exclude 'FILES*' --exclude TODO sdl_doom-master/wi_stuff.c ps2doom-master/wi_stuff.c
--- sdl_doom-master/wi_stuff.c 2012-12-19 12:14:42.000000000 +0100
+++ ps2doom-master/wi_stuff.c 2011-04-08 20:08:52.000000000 +0200
@@ -26,10 +26,11 @@
#include <stdio.h>
+#include "m_swap.h"
+
#include "z_zone.h"
#include "m_random.h"
-#include "m_swap.h"
#include "i_system.h"
@@ -373,7 +374,7 @@
static patch_t* frags;
// Time sucks.
-static patch_t* time;
+static patch_t* d_time;
static patch_t* par;
static patch_t* sucks;
@@ -1456,7 +1457,7 @@
V_DrawPatch(SP_STATSX, SP_STATSY+2*lh, FB, sp_secret);
WI_drawPercent(SCREENWIDTH - SP_STATSX, SP_STATSY+2*lh, cnt_secret[0]);
- V_DrawPatch(SP_TIMEX, SP_TIMEY, FB, time);
+ V_DrawPatch(SP_TIMEX, SP_TIMEY, FB, d_time);
WI_drawTime(SCREENWIDTH/2 - SP_TIMEX, SP_TIMEY, cnt_time);
if (wbs->epsd < 3)
@@ -1669,7 +1670,7 @@
colon = W_CacheLumpName("WICOLON", PU_STATIC);
// "time"
- time = W_CacheLumpName("WITIME", PU_STATIC);
+ d_time = W_CacheLumpName("WITIME", PU_STATIC);
// "sucks"
sucks = W_CacheLumpName("WISUCKS", PU_STATIC);
@@ -1752,7 +1753,7 @@
Z_ChangeTag(sp_secret, PU_CACHE);
Z_ChangeTag(items, PU_CACHE);
Z_ChangeTag(frags, PU_CACHE);
- Z_ChangeTag(time, PU_CACHE);
+ Z_ChangeTag(d_time, PU_CACHE);
Z_ChangeTag(sucks, PU_CACHE);
Z_ChangeTag(par, PU_CACHE);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment