summaryrefslogtreecommitdiffstats
path: root/games/xgalaga/files/patch-xgal.sndsrv.freebsd.c
blob: 49e7dcdf1cef0f4533a138f6d80314e1e7ffa670 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
--- xgal.sndsrv.freebsd.c.orig	Sun Apr 12 08:03:21 1998
+++ xgal.sndsrv.freebsd.c	Sun Jul 21 19:10:18 2002
@@ -12,20 +12,24 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
-#include <machine/soundcard.h>
+#include <sys/soundcard.h>
 #include <sys/time.h>
 #include <signal.h>
 #include <string.h>
 
 
 
-char *FILENAME[] = {
+static const char *FILENAME[] = {
                      "/explode.raw",
                      "/firetorp.raw",
                      "/shield.raw",
                      "/torphit.raw",
                      "/explode_big.raw",
 		     "/ddloo.raw",
+/* Two more files are now expected by the xgalaga!
+\* The order is given in the sound.h   -mi */
+                    "/warp.raw",
+                    "/smart.raw"
                    };
 
 #define NUM_SOUNDS	(sizeof(FILENAME)/sizeof(char*))
@@ -36,17 +40,15 @@
 
 
 /* Terminate: Signal Handler */
-void quit ()
+static void quit ()
 {
   exit (0);
 }
 
-
-
-void init (int argc, char **argv)
+static void init (int argc, char **argv)
 {
   int i;
-  char s[1024];
+  char s[FILENAME_MAX];
 
   if (argc != 3)
   {
@@ -61,7 +63,7 @@
     if (s[(int)strlen(s) - 1] == '/') FILENAME[i]++;
     strcat (s, FILENAME[i]);
     FILENAME[i] = malloc ((int)strlen (s));
-    strcpy (FILENAME[i],s);
+    strcpy ((char *)FILENAME[i],s);
     sound_buffer[i]=NULL;
     sound_size[i]=0;
   }
@@ -77,12 +79,12 @@
               Should set mono mode
               Error checking                
 */
-int setup_dsp (char *dspdev,int *is_pcsp)
+static int setup_dsp (char *dspdev,int *is_pcsp)
 {
   int dsp, frag, value;
   int mixer;
 
-  dsp = open(dspdev, O_RDWR);
+  dsp = open(dspdev, O_WRONLY);
   if (dsp < 1)
   {
     fprintf (stderr, "xgal.sndsrv: Couldn't open DSP %s\n",dspdev);
@@ -133,13 +135,13 @@
    Eventually I'll look at the xgal signal handlers and
    just trap this.
 */
-int do_nothing(void)
+static int do_nothing(void)
 {
     fprintf(stderr,"xgal.sndsrv: doing nothing, something is broken\n");
     while(1)  sleep (5);
 }
 
-int read_sound(int k)
+static int read_sound(int k)
 {
   int i,fd,size;
 
@@ -173,7 +175,7 @@
 }
 
 
-void do_everything (int dsp, int is_pcsp)
+static void do_everything (int dsp, int is_pcsp)
 {
   char k;
   int i, j ;
@@ -200,8 +202,14 @@
             /*fprintf(stderr,"terminating sound\n");*/ /*DEBUG*/
             terminate = 0;
         } else {
-            if(sound_size[k]==0) read_sound(k);
-            if(sound_size[k]>0 && playnum<16)  {
+ 	     if(k>=NUM_SOUNDS) {
+ 		fprintf(stderr,
+ 		"Not that many sounds known (%d >= %d)\n",
+ 		(int)k, NUM_SOUNDS);
+ 		continue;
+ 	     };
+ 	     if(sound_size[(int)k]==0) read_sound((int)k);
+ 	     if(sound_size[(int)k]>0 && playnum<16)  {
 	        position[playnum]=0;
                 playing[playnum++]=k;
                 /*fprintf(stderr,"sound %d added to play queue\n",playnum-1);*/ /*DEBUG*/
@@ -251,20 +259,18 @@
   }
 }
 
-
-
-void main (argc, argv)
+int main (argc, argv)
 int argc;
 char **argv;
 {
-  int dsp, is_pcsp, ppid;
-  char filename[512];
+  int dsp, is_pcsp;
 
   fcntl(STDIN_FILENO,F_SETFL,O_NONBLOCK);
   init (argc, argv);
   dsp = setup_dsp (argv[2],&is_pcsp);
 
-  if (!dsp) do_nothing();
+  if (dsp<0) do_nothing();
 
   do_everything (dsp, is_pcsp);
+  return 0;
 }
OpenPOWER on IntegriCloud