home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ST-Computer Leser-CD 2000 January
/
LCD_01_2000.iso
/
games
/
doom
/
pmdoom
/
src
/
i_system.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-12-17
|
16KB
|
709 lines
/* 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: */
/* */
/* ----------------------------------------------------------------------------- */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <stdarg.h>
#include <sys/time.h>
#include <unistd.h>
#ifdef ATARI
#include <osbind.h>
#endif
#include "doomdef.h"
#include "m_misc.h"
#include "i_video.h"
#include "i_sound.h"
#include "d_net.h"
#include "g_game.h"
#include "m_argv.h"
#include "sound/sndserv.h"
#ifdef LINUX
#include "video/svgalib.h"
#include "video/x11.h"
#include "sound/devaudio.h"
#endif
#ifdef ATARI
#include "i_cookies.h"
#include "control/ikbd.h"
#include "control/joypad.h"
#include "control/time.h"
#include "control/bios.h"
#include "video/xbios.h"
#include "video/vdi.h"
#include "sound/ataridma.h"
#endif
#ifdef __GNUG__
#pragma implementation "i_system.h"
#endif
#include "i_system.h"
int mb_used = 8; /* 8 Mo par dΘfaut */
void I_NullSysFunc(void);
void
I_Tactile
( int on,
int off,
int total )
{
/* UNUSED. */
on = off = total = 0;
}
ticcmd_t emptycmd;
ticcmd_t* I_BaseTiccmd(void)
{
return &emptycmd;
}
#ifdef ATARI
int atari_HeapSize=8<<20; /* 8 Mo par defaut */
#endif
int I_GetHeapSize (void)
{
return mb_used*1024*1024;
}
byte* I_ZoneBase (int* size)
{
#ifdef ATARI
*size=Mxalloc(-1,3)-131072;
if (*size>atari_HeapSize)
*size=atari_HeapSize;
#else
*size = mb_used*1024*1024;
#endif
printf(" %d Kbytes allocated for zone\n",(*size)>>10);
return (byte *) malloc (*size);
}
/* */
/* I_GetTime */
/* returns time in 1/70th second tics */
/* */
int I_GetTime (void)
{
static int basetime=0;
#ifndef ATARI
int newtics;
struct timeval tp;
struct timezone tzp;
gettimeofday(&tp, &tzp);
if (!basetime)
basetime = tp.tv_sec;
newtics = (tp.tv_sec-basetime)*TICRATE + tp.tv_usec*TICRATE/1000000;
return newtics;
#else
Supexec(I_Asm_UpdateTime);
if (!basetime)
basetime = atari_curtime;
return ((atari_curtime-basetime)*TICRATE)/200; /* Return 35hz value */
#endif
}
/* */
/* I_Init */
/* */
void I_Init (void)
{
I_InitSound();
/* I_InitGraphics(); */
I_InitControl();
signal(SIGINT, (void (*)(int)) I_Quit);
}
/* */
/* I_Quit */
/* */
void I_Quit (void)
{
D_QuitNetGame ();
I_ShutdownControl();
I_ShutdownSound();
I_ShutdownMusic();
M_SaveDefaults ();
I_ShutdownGraphics();
exit(0);
}
void I_WaitVBL(int count)
{
#ifdef SGI
sginap(1);
#else
#ifdef SUN
sleep(0);
#else
#ifdef ATARI
int i;
for (i=0;i<count;i++)
Vsync();
#else
usleep (count * (1000000/70) );
#endif
#endif
#endif
}
byte* I_AllocLow(int length)
{
byte* mem;
mem = (byte *)malloc (length);
memset (mem,0,length);
return mem;
}
/* */
/* 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_ShutdownControl();
I_ShutdownSound();
I_ShutdownMusic();
I_ShutdownGraphics();
exit(-1);
}
void I_StartTic(void)
{
I_UpdateKeyboard();
I_UpdateMouse();
I_UpdateJoystick();
#ifdef ATARI
I_UpdateJoypad();
#endif
}
/* ----------------------------------------------------------------- */
/* Dynamic system dependent functions */
/* ----------------------------------------------------------------- */
typedef struct {
char *name; /* Routine name */
char *param; /* Parameter to force the use of this routine */
int number; /* Number of the routine */
} routlist_t;
enum {
KEYBOARD_OFF =0,
KEYBOARD_SVGALIB,
KEYBOARD_X11,
KEYBOARD_6301,
KEYBOARD_BIOS
};
routlist_t keyboard_rout[]={
{"Off", "off", KEYBOARD_OFF},
{"Svgalib", "svgalib", KEYBOARD_SVGALIB},
{"X11", "x11", KEYBOARD_X11},
{"Ikbd 6301", "ikbd", KEYBOARD_6301},
{"Bios", "bios", KEYBOARD_BIOS}
};
enum {
MOUSE_OFF =0,
MOUSE_SVGALIB,
MOUSE_X11,
MOUSE_6301
};
routlist_t mouse_rout[]={
{"Off", "off", MOUSE_OFF},
{"Svgalib", "svgalib", MOUSE_SVGALIB},
{"X11", "x11", MOUSE_X11},
{"Ikbd 6301", "ikbd", MOUSE_6301}
};
enum {
JOYSTICK_OFF =0,
JOYSTICK_SVGALIB,
JOYSTICK_X11,
JOYSTICK_6301
};
routlist_t joystick_rout[]={
{"Off", "off", JOYSTICK_OFF},
{"Svgalib", "svgalib", JOYSTICK_SVGALIB},
{"X11", "x11", JOYSTICK_X11},
{"Ikbd 6301", "ikbd", JOYSTICK_6301}
};
enum {
JOYPAD_OFF =0,
JOYPAD_ON
};
routlist_t joypad_rout[]={
{"Off", "off", JOYPAD_OFF},
{"On", "on", JOYPAD_ON}
};
enum {
SOUND_OFF =0,
SOUND_SERVER,
SOUND_DEVAUDIO,
SOUND_DMA8
};
routlist_t sound_rout[]={
{"Off", "off", SOUND_OFF},
{"Sound server", "sndserver", SOUND_SERVER},
{"Linux /dev/audio", "devaudio", SOUND_DEVAUDIO},
{"8 bits Dma", "dma8", SOUND_DMA8}
};
/*
enum {
MUSIC_OFF =0
};
routlist_t music_rout[]={
{"Off", "off", MUSIC_OFF}
};
*/
enum {
VIDEO_OFF=0,
VIDEO_SVGALIB,
VIDEO_X11,
VIDEO_XBIOS,
VIDEO_VDI
};
routlist_t video_rout[]={
{"Off", "off", VIDEO_OFF},
{"Svgalib", "svgalib", VIDEO_SVGALIB},
{"X11", "x11", VIDEO_X11},
{"Xbios", "xbios", VIDEO_XBIOS},
{"Vdi", "vdi", VIDEO_VDI}
};
void I_SysInit(void)
{
int p;
int numkbd,nummouse,numjoystick;
#ifdef ATARI
int numjoypad;
#endif
int numsound,/*nummusic,*/numvideo;
/* --- Initialise default system functions --- */
/* controllers */
I_InitControl = I_NullSysFunc; /* Init controller functions */
I_ShutdownControl = I_NullSysFunc; /* Shutdown controller functions */
I_UpdateKeyboard = I_NullSysFunc;
numkbd = KEYBOARD_OFF;
I_UpdateMouse = I_NullSysFunc;
nummouse = MOUSE_OFF;
I_UpdateJoystick = I_NullSysFunc;
numjoystick = JOYSTICK_OFF;
#ifdef ATARI
I_UpdateJoypad = I_NullSysFunc;
numjoypad = JOYPAD_OFF;
#endif
/* sound */
I_SndInit = I_NullSysFunc;
I_SndUpdate = I_NullSysFunc;
I_InitSound = I_NullSysFunc;
I_ShutdownSound = I_NullSysFunc;
I_StartSound = I_NullSysFunc;
numsound = SOUND_OFF;
/* music */
/* nummusic = MUSIC_OFF;*/
/* video */
I_VidInit = I_NullSysFunc;
I_VidUpdate = I_NullSysFunc;
I_SetPalette256 = I_NullSysFunc;
I_InitGraphics = I_InitGraphics_null;
I_ShutdownGraphics = I_NullSysFunc;
I_SetMainScreen = I_NullSysFunc;
numvideo = VIDEO_OFF;
#ifdef ATARI
/* --- Initialise default ATARI functions --- */
I_ScanCookies();
/* controllers */
if ((cookie_mch == MCH_TT) || (cookie_mch == MCH_F30))
{
I_InitControl = I_InitControl_6301;
I_ShutdownControl = I_ShutdownControl_6301;
I_UpdateKeyboard = I_UpdateKeyboard_6301;
numkbd=KEYBOARD_6301;
I_UpdateMouse = I_UpdateMouse_6301;
nummouse=MOUSE_6301;
I_UpdateJoystick = I_UpdateJoystick_6301;
numjoystick=JOYSTICK_6301;
}
else
{
I_InitControl = I_InitControl_bios;
I_UpdateKeyboard = I_UpdateKeyboard_bios;
numkbd=KEYBOARD_BIOS;
}
if (cookie_mch == MCH_F30)
{
I_UpdateJoypad = I_UpdateJoypad_hardware;
numjoypad=JOYPAD_ON;
}
/* video */
switch (cookie_vdo) {
case VDO_TT:
case VDO_F30:
/* Xbios display */
I_VidInit = I_VidInit_xbios;
I_VidUpdate = I_VidUpdate_xbios;
I_SetPalette256 = I_SetPalette256_xbios;
I_InitGraphics = I_InitGraphics_xbios;
I_ShutdownGraphics = I_ShutdownGraphics_xbios;
/* I_SetMainScreen = I_SetMainScreen_xbios;*/
numvideo=VIDEO_XBIOS;
break;
default:
/* Vdi display */
I_VidInit = I_VidInit_vdi;
I_VidUpdate = I_VidUpdate_vdi;
I_SetPalette256 = I_SetPalette256_vdi;
I_InitGraphics = I_InitGraphics_vdi;
I_ShutdownGraphics = I_ShutdownGraphics_vdi;
I_SetMainScreen = I_SetMainScreen_vdi;
numvideo=VIDEO_VDI;
break;
}
/* sound */
if (cookie_snd & (1<<SND_DMA8)) {
I_SndInit = I_SndInit_atari;
I_SndUpdate = I_NullSysFunc;
I_InitSound = I_InitSound_atari;
I_ShutdownSound = I_ShutdownSound_atari;
I_StartSound = I_StartSound_atari;
numsound=SOUND_DMA8;
}
#endif
#ifdef LINUX
/* --- Initialise default LINUX functions --- */
if (getenv("DISPLAY"))
{
/* X11 controllers */
I_UpdateKeyboard = I_UpdateKeyboard_x11;
numkbd = KEYBOARD_X11;
I_UpdateMouse = I_UpdateMouse_x11;
nummouse = MOUSE_X11;
/* X11 display */
I_VidUpdate = I_VidUpdate_x11;
I_SetPalette256 = I_SetPalette256_x11;
I_InitGraphics = I_InitGraphics_x11;
I_ShutdownGraphics = I_ShutdownGraphics_x11;
numvideo=VIDEO_X11;
} else {
/* Svgalib controllers */
I_UpdateKeyboard = I_UpdateKeyboard_svgalib;
numkbd = KEYBOARD_SVGALIB;
/* Svgalib display */
I_VidInit = I_VidInit_svgalib;
I_VidUpdate = I_VidUpdate_svgalib;
I_SetPalette256 = I_SetPalette256_svgalib;
I_InitGraphics = I_InitGraphics_svgalib;
I_ShutdownGraphics = I_ShutdownGraphics_svgalib;
numvideo = VIDEO_SVGALIB;
}
I_SndInit = I_NullSysFunc;
I_SndUpdate = I_NullSysFunc;
I_InitSound = I_InitSound_sndserver;
I_ShutdownSound = I_ShutdownSound_sndserver;
I_StartSound = I_StartSound_sndserver;
numsound=SOUND_SERVER;
#endif
/* --- Initialise forced functions --- */
p=M_CheckParm("-keyboard");
if (p && p < myargc-1 )
{
if (!strcmp("off",myargv[p+1])) {
#ifdef LINUX
/* Keep keyboard routine under X11 */
if ( I_UpdateKeyboard != I_UpdateKeyboard_x11)
#endif
{
I_UpdateKeyboard = I_NullSysFunc;
numkbd=KEYBOARD_OFF;
}
}
#ifdef ATARI
if (!strcmp(keyboard_rout[KEYBOARD_BIOS].param,myargv[p+1]))
{
/* Set bios routines */
I_InitControl=I_InitControl_bios;
I_ShutdownControl=I_NullSysFunc;
I_UpdateKeyboard=I_UpdateKeyboard_bios;
numkbd=KEYBOARD_BIOS;
I_UpdateMouse=I_NullSysFunc;
nummouse=MOUSE_OFF;
I_UpdateJoystick=I_NullSysFunc;
numjoystick=JOYSTICK_OFF;
}
#endif
}
p=M_CheckParm("-mouse");
if (p && p < myargc-1 )
{
if (!strcmp(mouse_rout[MOUSE_OFF].param,myargv[p+1])) {
I_UpdateMouse = I_NullSysFunc;
nummouse=MOUSE_OFF;
}
}
p=M_CheckParm("-joystick");
if (p && p < myargc-1 )
{
if (!strcmp(joystick_rout[JOYSTICK_OFF].param,myargv[p+1])) {
I_UpdateJoystick = I_NullSysFunc;
numjoystick=JOYSTICK_OFF;
}
}
#ifdef ATARI
/* disable IKBD routines if keyboard disabled */
if ((numkbd == KEYBOARD_OFF) && (I_InitControl == I_InitControl_6301))
{
I_InitControl = I_NullSysFunc;
I_ShutdownControl = I_NullSysFunc;
I_UpdateKeyboard = I_NullSysFunc;
numkbd =KEYBOARD_OFF;
I_UpdateMouse = I_NullSysFunc;
nummouse=MOUSE_OFF;
I_UpdateJoystick = I_NullSysFunc;
numjoystick=JOYSTICK_OFF;
}
#endif
#ifdef ATARI
p=M_CheckParm("-joypad");
if (p && p < myargc-1 )
{
if (!strcmp(joypad_rout[JOYPAD_OFF].param,myargv[p+1])) {
I_UpdateJoypad = I_NullSysFunc;
numjoypad=JOYPAD_OFF;
}
}
#endif
p=M_CheckParm("-sound");
if (p && p < myargc-1 )
{
if (!strcmp(sound_rout[SOUND_OFF].param,myargv[p+1])) {
I_SndInit = I_NullSysFunc;
I_SndUpdate = I_NullSysFunc;
I_InitSound = I_NullSysFunc;
I_ShutdownSound = I_NullSysFunc;
numsound=SOUND_OFF;
}
#ifdef LINUX
if (!strcmp(sound_rout[SOUND_DEVAUDIO].param,myargv[p+1])) {
I_SndInit = I_NullSysFunc;
I_SndUpdate = I_SndUpdate_linux;
I_InitSound = I_InitSound_linux;
I_ShutdownSound = I_ShutdownSound_linux;
I_StartSound = I_StartSound_linux;
numsound = SOUND_DEVAUDIO;
}
#endif
if (!strcmp(sound_rout[SOUND_SERVER].param,myargv[p+1])) {
I_SndInit = I_NullSysFunc;
I_SndUpdate = I_NullSysFunc;
I_InitSound = I_InitSound_sndserver;
I_ShutdownSound = I_ShutdownSound_sndserver;
I_StartSound = I_StartSound_sndserver;
numsound=SOUND_SERVER;
}
}
/*
p=M_CheckParm("-music");
if (p && p < myargc-1 )
{
if (!strcmp("off",myargv[p+1])) {
nummusic=MUSIC_OFF;
}
}
*/
p=M_CheckParm("-video");
if (p && p < myargc-1 )
{
if (!strcmp(video_rout[VIDEO_OFF].param,myargv[p+1])) {
#ifdef LINUX
/* Disable keyboard,mouse if no appropriate video */
if (( I_VidUpdate == I_VidUpdate_x11) ||
(I_VidUpdate == I_VidUpdate_svgalib))
{
I_UpdateKeyboard = I_NullSysFunc;
numkbd=KEYBOARD_OFF;
I_UpdateMouse = I_NullSysFunc;
nummouse=MOUSE_OFF;
}
#endif
I_VidInit = I_NullSysFunc;
I_VidUpdate = I_NullSysFunc;
I_SetPalette256 = I_NullSysFunc;
I_InitGraphics = I_InitGraphics_null;
I_ShutdownGraphics = I_NullSysFunc;
I_SetMainScreen = I_NullSysFunc;
numvideo=VIDEO_OFF;
}
#ifdef ATARI
if (!strcmp(video_rout[VIDEO_VDI].param,myargv[p+1])) {
I_VidInit = I_VidInit_vdi;
I_VidUpdate = I_VidUpdate_vdi;
I_SetPalette256 = I_SetPalette256_vdi;
I_InitGraphics = I_InitGraphics_vdi;
I_ShutdownGraphics = I_ShutdownGraphics_vdi;
I_SetMainScreen = I_SetMainScreen_vdi;
numvideo=VIDEO_VDI;
}
#endif
}
/* Display routines names */
printf("Keyboard.: %s\n",keyboard_rout[numkbd].name);
printf("Mouse....: %s\n",mouse_rout[nummouse].name);
printf("Joystick.: %s\n",joystick_rout[numjoystick].name);
#ifdef ATARI
printf("Joypad...: %s\n",joypad_rout[numjoypad].name);
#endif
printf("Sound....: %s\n",sound_rout[numsound].name);
/* printf("Music....: %s\n",music_rout[nummusic].name);*/
printf("Video....: %s\n\n",video_rout[numvideo].name);
/* First initializations */
I_VidInit();
I_SndInit();
}
/* --- Default system dynamic function = Null */
void I_NullSysFunc(void)
{
}
/* --- Controllers : update (keyboard,mouse,joystick,joypads,etc... */
/* void (*I_StartTic)(void); */
void (*I_InitControl) (void);
void (*I_ShutdownControl) (void);
void (*I_UpdateKeyboard) (void);
void (*I_UpdateMouse) (void);
void (*I_UpdateJoystick) (void);
#ifdef ATARI
void (*I_UpdateJoypad) (void);
#endif
/* --- Sound */
void (*I_SndInit)(void); /* Initializations required for sound */
void (*I_SndUpdate)(void); /* Update sound */
void (*I_InitSound)(void); /* Initialize sound */
void (*I_ShutdownSound)(void); /* Shutdown sound */
/* --- Music */
/* --- Video */
void (*I_VidInit)(void); /* Initializations required for video */
void (*I_VidUpdate)(void); /* Render the final screen */
void (*I_SetPalette256)(byte *palette); /* set a 256 colours palette */
void (*I_InitGraphics)(void); /* Init video */
void (*I_ShutdownGraphics)(void); /* Shutdown video */
void (*I_SetMainScreen)(void); /* Set final screen pointer */