Rev 2 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | pmbaty | 1 | /* |
2 | * src/system.c |
||
3 | * |
||
4 | * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved. |
||
5 | * |
||
6 | * The use and distribution terms for this software are contained in the file |
||
7 | * named README, which can be found in the root of this distribution. By |
||
8 | * using this software in any fashion, you are agreeing to be bound by the |
||
9 | * terms of this license. |
||
10 | * |
||
11 | * You must not remove this notice, or any other, from this software. |
||
12 | */ |
||
13 | |||
14 | #include <SDL.h> |
||
15 | |||
16 | #include <signal.h> |
||
17 | |||
18 | #include "system.h" |
||
19 | #include "windows.h" |
||
20 | |||
21 | |||
22 | /* |
||
23 | * Panic |
||
24 | */ |
||
25 | void sys_panic (char *err, ...) |
||
26 | { |
||
27 | va_list argptr; |
||
28 | char s[1024]; |
||
29 | |||
30 | /* prepare message */ |
||
31 | va_start (argptr, err); |
||
32 | vsprintf_s (s, sizeof (s), err, argptr); |
||
33 | va_end (argptr); |
||
34 | |||
35 | /* print message and die */ |
||
36 | MessageBox (NULL, s, NULL, MB_OK); |
||
37 | exit (1); |
||
38 | } |
||
39 | |||
40 | |||
41 | /* |
||
42 | * Print a message |
||
43 | */ |
||
44 | void sys_printf (char *msg, ...) |
||
45 | { |
||
46 | va_list argptr; |
||
47 | char s[2048]; |
||
48 | |||
49 | /* prepare message */ |
||
50 | va_start (argptr, msg); |
||
51 | vsprintf_s (s, sizeof (s), msg, argptr); |
||
52 | va_end (argptr); |
||
53 | |||
54 | MessageBox (NULL, s, NULL, MB_OK); |
||
55 | } |
||
56 | |||
57 | |||
58 | /* |
||
59 | * Return number of microseconds elapsed since first call |
||
60 | */ |
||
61 | U32 sys_gettime (void) |
||
62 | { |
||
63 | static U32 ticks_base = 0; |
||
64 | U32 ticks; |
||
65 | |||
66 | ticks = SDL_GetTicks (); |
||
67 | |||
68 | if (!ticks_base) |
||
69 | ticks_base = ticks; |
||
70 | |||
71 | return ticks - ticks_base; |
||
72 | } |
||
73 | |||
74 | |||
75 | /* |
||
76 | * Sleep a number of microseconds |
||
77 | */ |
||
78 | void sys_sleep (int s) |
||
79 | { |
||
80 | SDL_Delay (s); |
||
81 | } |
||
82 | |||
83 | |||
84 | /* |
||
85 | * Initialize system |
||
86 | */ |
||
87 | void sys_init (int argc, char **argv) |
||
88 | { |
||
89 | sysarg_init (argc, argv); |
||
90 | sysvid_init (); |
||
91 | sysjoy_init (); |
||
92 | |||
93 | if (sysarg_args_nosound == 0) |
||
94 | syssnd_init (); |
||
95 | |||
96 | atexit (sys_shutdown); |
||
97 | signal (SIGINT, exit); |
||
98 | signal (SIGTERM, exit); |
||
99 | } |
||
100 | |||
101 | |||
102 | /* |
||
103 | * Shutdown system |
||
104 | */ |
||
105 | void sys_shutdown (void) |
||
106 | { |
||
107 | syssnd_shutdown (); |
||
108 | sysjoy_shutdown (); |
||
109 | sysvid_shutdown (); |
||
110 | } |