1
//============================================================================
5
// SS tttttt eeee ll ll aaaa
6
// SSSS tt ee ee ll ll aa
7
// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8
// SS SS tt ee ll ll aa aa
9
// SSSS ttt eeeee llll llll aaaaa
11
// Copyright (c) 1995-1998 by Bradford W. Mott
13
// See the file "license" for information on usage and redistribution of
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
// $Id: SndUnix.cxx,v 1.1 1998/07/15 20:58:10 bwmott Exp $
17
//============================================================================
19
#include <sys/types.h>
24
#include "SndUnix.hxx"
26
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
27
SoundUnix::SoundUnix()
31
// Initialize to impossible values so they will be reset
32
// on the first call to the set method
33
myAUDC0 = myAUDC1 = myAUDF0 = myAUDF1 = myAUDV0 = myAUDV1 = 255;
37
// Create pipe for interprocess communication
40
// Oops. We were not able to create pipe so disable myself and return
45
// Create new process, setup pipe, and start stella-sound
50
// Close STDIN and put the read end of the pipe in its place
53
// Close unused file descriptors in child process
57
// Execute the stella-sound server
58
if(execlp("stella-sound", "stella-sound", (char*)0))
63
else if(myProcessId > 0)
65
// Close unused file descriptors in parent process
68
// Save the pipe's write file descriptor
73
// Couldn't fork so cleanup and disabled myself
81
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
82
SoundUnix::~SoundUnix()
86
// Send quit command to the sound server
87
unsigned char command = 0xC0;
88
write(myFd, &command, 1);
90
// Kill the sound server
91
kill(myProcessId, SIGHUP);
98
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
99
void SoundUnix::set(Sound::Register reg, uInt8 value)
101
// Return if I'm currently disabled or if the stella-sound process has died
102
if(myDisabled || (waitpid(myProcessId, 0, WNOHANG) == myProcessId))
114
if(myAUDC0 != (value & 0x0f))
116
myAUDC0 = (value & 0x0f);
117
command = myAUDC0 | 0x00;
128
if(myAUDC1 != (value & 0x0f))
130
myAUDC1 = (value & 0x0f);
131
command = myAUDC1 | 0x20;
142
if(myAUDF0 != (value & 0x1f))
144
myAUDF0 = (value & 0x1f);
145
command = myAUDF0 | 0x40;
156
if(myAUDF1 != (value & 0x1f))
158
myAUDF1 = (value & 0x1f);
159
command = myAUDF1 | 0x60;
170
if(myAUDV0 != (value & 0x0f))
172
myAUDV0 = (value & 0x0f);
173
command = myAUDV0 | 0x80;
184
if(myAUDV1 != (value & 0x0f))
186
myAUDV1 = (value & 0x0f);
187
command = myAUDV1 | 0xA0;
203
// Send sound command to the stella-sound process
204
write(myFd, &command, 1);
207
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
208
void SoundUnix::mute(bool state)
210
// Return if I'm currently disabled or if the stella-sound process has died
211
if(myDisabled || (waitpid(myProcessId, 0, WNOHANG) == myProcessId))
222
// Setup the mute enable command
223
command = 0x01 | 0xE0;
227
// Setup the mute disable command
228
command = 0x00 | 0xE0;
231
// Send sound command to the stella-sound process
232
write(myFd, &command, 1);