rickjr/src/system.c

179 lines
3.1 KiB
C

/*
* xrick/src/system.c
*
* Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
*
* The use and distribution terms for this software are contained in the file
* named README, which can be found in the root of this distribution. By
* using this software in any fashion, you are agreeing to be bound by the
* terms of this license.
*
* You must not remove this notice, or any other, from this software.
*/
#ifdef IIGS
#pragma noroot
#endif
#if !(defined(IIGS) || defined(F256))
#include <SDL.h>
#endif
#ifndef F256
#include <stdarg.h> /* args for sys_panic */
#include <fcntl.h> /* fcntl in sys_panic */
#include <stdio.h> /* printf */
#include <stdlib.h>
#include <signal.h>
#endif
#include "system.h"
#ifdef F256
void puts(char* c_str)
{
}
#endif
/*
* Panic
*/
void
sys_panic(char *err, ...)
{
#ifndef F256
va_list argptr;
char s[1024];
/* change stdin to non blocking */
/*fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);*/
/* NOTE HPUX: use ... is it OK on Linux ? */
/* fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NDELAY); */
/* prepare message */
va_start(argptr, err);
vsprintf(s, err, argptr);
va_end(argptr);
/* print message and die */
printf("%s\npanic!\n", s);
exit(1);
#endif
}
/*
* Print a message
*/
void
sys_printf(char *msg, ...)
{
#ifndef F256
va_list argptr;
char s[1024];
/* change stdin to non blocking */
/*fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~FNDELAY);*/
/* NOTE HPUX: use ... is it OK on Linux ? */
/* fcntl(0, F_SETFL, fcntl (0, F_GETFL, 0) & ~O_NDELAY); */
/* prepare message */
va_start(argptr, msg);
vsprintf(s, msg, argptr);
va_end(argptr);
printf(s);
#endif
}
/*
* Return number of microseconds elapsed since first call
*/
U32
sys_gettime(void)
{
#ifdef IIGS
return tick[0] << 4;
#elif defined(F256)
/*$$TODO -> Hook this to the jiffytime, make similar the the GS */
/* or use general purpose system timer */
static U32 dumb;
dumb+=1;
return dumb;
#else
static U32 ticks_base = 0;
U32 ticks;
ticks = SDL_GetTicks();
if (!ticks_base)
ticks_base = ticks;
return ticks - ticks_base;
#endif
}
/*
* Sleep a number of microseconds
*/
void
sys_sleep(int s)
{
#ifdef IIGS
// on GS we're going to work in ms, also we don't sleep, we just wait
while (s > 8)
{
sysvid_wait_vblank();
s -= 16; // About 1/60th of a second
}
#endif
#if !(defined(IIGS) || defined(F256))
SDL_Delay(s);
#endif
}
/*
* Initialize system
*/
CODE_BLOCK(8) void
sys_init(int argc, char **argv)
{
sysarg_init(argc, argv);
sysvid_init();
#ifdef ENABLE_JOYSTICK
sysjoy_init();
#endif
#ifdef ENABLE_SOUND
if (sysarg_args_nosound == 0)
syssnd_init();
#endif
#ifndef F256
atexit(sys_shutdown);
#endif
#if !(defined(IIGS) || defined(F256))
signal(SIGINT, exit);
signal(SIGTERM, exit);
#endif
}
/*
* Shutdown system
*/
void
sys_shutdown(void)
{
#ifdef ENABLE_SOUND
syssnd_shutdown();
#endif
#ifdef ENABLE_JOYSTICK
sysjoy_shutdown();
#endif
sysvid_shutdown();
}
/* eof */