Previous 199869 Revisions Next

r21678 Thursday 7th March, 2013 at 04:30:56 UTC by Andrew Gardner
Modernized wswan, special, and svision devices. [Andrew Gardner]
[src/mess/audio]special.c svision.c wswan.c
[src/mess/drivers]svision.c
[src/mess/includes]special.h svision.h wswan.h
[src/mess/machine]special.c wswan.c

trunk/src/mess/machine/special.c
r21677r21678
182182
183183WRITE_LINE_MEMBER( special_state::specimx_pit8253_out0_changed )
184184{
185   specimx_set_input( m_specimx_audio, 0, state );
185   m_specimx_audio->set_input( 0, state );
186186}
187187
188188WRITE_LINE_MEMBER( special_state::specimx_pit8253_out1_changed )
189189{
190   specimx_set_input( m_specimx_audio, 1, state );
190   m_specimx_audio->set_input( 1, state );
191191}
192192
193193WRITE_LINE_MEMBER( special_state::specimx_pit8253_out2_changed )
194194{
195   specimx_set_input( m_specimx_audio, 2, state );
195   m_specimx_audio->set_input( 2, state );
196196}
197197
198198
r21677r21678
220220
221221MACHINE_START_MEMBER(special_state,specimx)
222222{
223   m_specimx_audio = machine().device("custom");
223   m_specimx_audio = machine().device<specimx_sound_device>("custom");
224224   m_drive = 0;
225225   m_fdc->setup_drq_cb(fd1793_t::line_cb(FUNC(special_state::fdc_drq), this));
226226}
trunk/src/mess/machine/wswan.c
r21677r21678
846846                   Bit 0-3 - Master volume
847847                   Bit 4-7 - Unknown
848848                */
849         wswan_sound_port_w( machine().device("custom"), space, offset, data );
849         machine().device<wswan_sound_device>("custom")->wswan_sound_port_w( space, offset, data );
850850         break;
851851      case 0xa0:  /* Hardware type - this is probably read only
852852                   Bit 0   - Enable cartridge slot and/or disable bios
trunk/src/mess/includes/svision.h
r21677r21678
2727   int palette_on;
2828};
2929
30class svision_sound_device; // defined below
3031
3132class svision_state : public driver_device
3233{
r21677r21678
4041      , m_joy2(*this, "JOY2")
4142   { }
4243
43   device_t *m_sound;
44   svision_sound_device *m_sound;
4445   int *m_dma_finished;
4546   svision_t m_svision;
4647   svision_pet_t m_pet;
r21677r21678
8687
8788/*----------- defined in audio/svision.c -----------*/
8889
90
91//**************************************************************************
92//  TYPE DEFINITIONS
93//**************************************************************************
94
95enum SVISION_NOISE_Type
96{
97   SVISION_NOISE_Type7Bit,
98   SVISION_NOISE_Type14Bit
99};
100
101struct SVISION_NOISE
102{
103    SVISION_NOISE() :
104     on(0),
105      right(0),
106      left(0),
107      play(0),
108     type(SVISION_NOISE_Type7Bit),
109     state(0),
110     volume(0),
111     count(0),
112     step(0.0),
113      pos(0.0),
114     value(0)
115    {
116       memset(reg, 0, sizeof(UINT8)*3);
117    }
118
119   UINT8 reg[3];
120   int on, right, left, play;
121   SVISION_NOISE_Type type;
122   int state;
123   int volume;
124   int count;
125   double step, pos;
126   int value; // currently simple random function
127};
128
129struct SVISION_DMA
130{
131    SVISION_DMA() :
132     on(0),
133      right(0),
134      left(0),
135     ca14to16(0),
136     start(0),
137      size(0),
138     pos(0.0),
139      step(0.0),
140     finished(0)
141    {
142       memset(reg, 0, sizeof(UINT8)*5);
143    }
144
145   UINT8 reg[5];
146   int on, right, left;
147   int ca14to16;
148   int start,size;
149   double pos, step;
150   int finished;
151};
152
153struct SVISION_CHANNEL
154{
155    SVISION_CHANNEL() :
156     on(0),
157     waveform(0),
158      volume(0),
159     pos(0),
160     size(0),
161     count(0)
162    {
163       memset(reg, 0, sizeof(UINT8)*4);
164    }
165
166   UINT8 reg[4];
167   int on;
168   int waveform, volume;
169   int pos;
170   int size;
171   int count;
172};
173
174
175// ======================> svision_sound_device
176
89177class svision_sound_device : public device_t,
90                           public device_sound_interface
178                      public device_sound_interface
91179{
92180public:
93181   svision_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
94   ~svision_sound_device() { global_free(m_token); }
182   ~svision_sound_device() { }
95183
96   // access to legacy token
97   void *token() const { assert(m_token != NULL); return m_token; }
98184protected:
99185   // device-level overrides
100   virtual void device_config_complete();
101186   virtual void device_start();
102187
103188   // sound stream update overrides
104189   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
190
191public:
192    DECLARE_WRITE8_MEMBER( svision_sounddma_w );
193    DECLARE_WRITE8_MEMBER( svision_noise_w );
194       
195public:
196    int *dma_finished();
197    void sound_decrement();
198    void soundport_w(int which, int offset, int data);
199
105200private:
106   // internal state
107   void *m_token;
201   sound_stream *m_mixer_channel;
202   SVISION_DMA m_dma;
203   SVISION_NOISE m_noise;
204   SVISION_CHANNEL m_channel[2];
108205};
109206
110207extern const device_type SVISION;
111208
112209
113int *svision_dma_finished(device_t *device);
114void svision_sound_decrement(device_t *device);
115void svision_soundport_w(device_t *device, int which, int offset, int data);
116DECLARE_WRITE8_DEVICE_HANDLER( svision_sounddma_w );
117DECLARE_WRITE8_DEVICE_HANDLER( svision_noise_w );
118
119
120210#endif /* SVISION_H_ */
trunk/src/mess/includes/wswan.h
r21677r21678
185185
186186/*----------- defined in audio/wswan.c -----------*/
187187
188//**************************************************************************
189//  TYPE DEFINITIONS
190//**************************************************************************
191
192struct CHAN
193{
194    CHAN() :
195     freq(0),
196     period(0),
197     pos(0),
198     vol_left(0),
199     vol_right(0),
200     on(0),
201     signal(0) { }
202           
203   UINT16  freq;           /* frequency */
204   UINT32  period;         /* period */
205   UINT32  pos;            /* position */
206   UINT8   vol_left;       /* volume left */
207   UINT8   vol_right;      /* volume right */
208   UINT8   on;         /* on/off */
209   INT8    signal;         /* signal */
210};
211
212
213// ======================> wswan_sound_device
214
188215class wswan_sound_device : public device_t,
189216                           public device_sound_interface
190217{
191218public:
192219   wswan_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
193   ~wswan_sound_device() { global_free(m_token); }
220   ~wswan_sound_device() { }
194221
195   // access to legacy token
196   void *token() const { assert(m_token != NULL); return m_token; }
197222protected:
198223   // device-level overrides
199   virtual void device_config_complete();
200224   virtual void device_start();
201225
202226   // sound stream update overrides
203227   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
228
229public:
230    DECLARE_WRITE8_MEMBER( wswan_sound_port_w );
231
204232private:
205   // internal state
206   void *m_token;
233    void wswan_ch_set_freq( CHAN *ch, UINT16 freq );
234
235private:
236   sound_stream *m_channel;
237   CHAN m_audio1;     /* Audio channel 1 */
238   CHAN m_audio2;     /* Audio channel 2 */
239   CHAN m_audio3;     /* Audio channel 3 */
240   CHAN m_audio4;     /* Audio channel 4 */
241   INT8    m_sweep_step;     /* Sweep step */
242   UINT32  m_sweep_time;     /* Sweep time */
243   UINT32  m_sweep_count;        /* Sweep counter */
244   UINT8   m_noise_type;     /* Noise generator type */
245   UINT8   m_noise_reset;        /* Noise reset */
246   UINT8   m_noise_enable;       /* Noise enable */
247   UINT16  m_sample_address;     /* Sample address */
248   UINT8   m_audio2_voice;       /* Audio 2 voice */
249   UINT8   m_audio3_sweep;       /* Audio 3 sweep */
250   UINT8   m_audio4_noise;       /* Audio 4 noise */
251   UINT8   m_mono;           /* mono */
252   UINT8   m_voice_data;     /* voice data */
253   UINT8   m_output_volume;      /* output volume */
254   UINT8   m_external_stereo;    /* external stereo */
255   UINT8   m_external_speaker;   /* external speaker */
256   UINT16  m_noise_shift;        /* Noise counter shift register */
257   UINT8   m_master_volume;      /* Master volume */
207258};
208259
209260extern const device_type WSWAN;
210261
211262
212DECLARE_WRITE8_DEVICE_HANDLER( wswan_sound_port_w );
213
214263#endif /* WSWAN_H_ */
trunk/src/mess/includes/special.h
r21677r21678
2121#include "machine/ram.h"
2222
2323
24class specimx_sound_device; // defined below
25
2426class special_state : public driver_device
2527{
2628public:
r21677r21678
8385   UINT8 m_erik_color_2;
8486   UINT8 m_erik_background;
8587   UINT8 m_specimx_color;
86   device_t *m_specimx_audio;
88   specimx_sound_device *m_specimx_audio;
8789   int m_specialist_8255_porta;
8890   int m_specialist_8255_portb;
8991   int m_specialist_8255_portc;
r21677r21678
148150extern const i8255_interface specialist_ppi8255_interface;
149151
150152
151
152
153
154
155
156
157153/*----------- defined in video/special.c -----------*/
158154
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173155extern const rgb_t specimx_palette[16];
174156
157
175158/*----------- defined in audio/special.c -----------*/
176159
177160class specimx_sound_device : public device_t,
178                           public device_sound_interface
161                      public device_sound_interface
179162{
180163public:
181164   specimx_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
182   ~specimx_sound_device() { global_free(m_token); }
165   ~specimx_sound_device() { }
183166
184   // access to legacy token
185   void *token() const { assert(m_token != NULL); return m_token; }
186167protected:
187168   // device-level overrides
188   virtual void device_config_complete();
189169   virtual void device_start();
190170
191171   // sound stream update overrides
192172   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
173
174public:
175    void set_input(int index, int state);
176
193177private:
194   // internal state
195   void *m_token;
178      sound_stream *m_mixer_channel;
179   int m_specimx_input[3];
196180};
197181
198182extern const device_type SPECIMX;
199183
200
201void specimx_set_input(device_t *device, int index, int state);
202
203184#endif /* SPECIAL_H_ */
trunk/src/mess/drivers/svision.c
r21677r21678
166166         break;
167167
168168      case 0x10: case 0x11: case 0x12: case 0x13:
169         svision_soundport_w(m_sound, 0, offset & 3, data);
169         m_sound->soundport_w(0, offset & 3, data);
170170         break;
171171
172172      case 0x14: case 0x15: case 0x16: case 0x17:
173         svision_soundport_w(m_sound, 1, offset & 3, data);
173         m_sound->soundport_w(1, offset & 3, data);
174174         break;
175175
176176      case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c:
177         svision_sounddma_w(m_sound, space, offset - 0x18, data);
177         m_sound->svision_sounddma_w(space, offset - 0x18, data);
178178         break;
179179
180180      case 0x28: case 0x29: case 0x2a:
181         svision_noise_w(m_sound, space, offset - 0x28, data);
181         m_sound->svision_noise_w(space, offset - 0x28, data);
182182         break;
183183
184184      default:
r21677r21678
443443   if (BANK&1)
444444      device.execute().set_input_line(INPUT_LINE_NMI, PULSE_LINE);
445445
446   svision_sound_decrement(m_sound);
446   m_sound->sound_decrement();
447447}
448448
449449DRIVER_INIT_MEMBER(svision_state,svision)
450450{
451451   m_svision.timer1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(svision_state::svision_timer),this));
452   m_sound = machine().device("custom");
453   m_dma_finished = svision_dma_finished(m_sound);
452   m_sound = machine().device<svision_sound_device>("custom");
453   m_dma_finished = m_sound->dma_finished();
454454   m_pet.on = FALSE;
455455   m_user1 = memregion("user1");
456456   m_bank1 = membank("bank1");
r21677r21678
461461DRIVER_INIT_MEMBER(svision_state,svisions)
462462{
463463   m_svision.timer1 = machine().scheduler().timer_alloc(timer_expired_delegate(FUNC(svision_state::svision_timer),this));
464   m_sound = machine().device("custom");
465   m_dma_finished = svision_dma_finished(m_sound);
464   m_sound = machine().device<svision_sound_device>("custom");
465   m_dma_finished = m_sound->dma_finished();
466466   m_user1 = memregion("user1");
467467   m_bank1 = membank("bank1");
468468   m_bank2 = membank("bank2");
trunk/src/mess/audio/special.c
r21677r21678
99
1010#include "includes/special.h"
1111
12struct specimx_sound_state
13{
14   sound_stream *mixer_channel;
15   int specimx_input[3];
16};
1712
18static STREAM_UPDATE( specimx_sh_update );
13// device type definition
14const device_type SPECIMX = &device_creator<specimx_sound_device>;
1915
20INLINE specimx_sound_state *get_safe_token(device_t *device)
16
17//**************************************************************************
18//  LIVE DEVICE
19//**************************************************************************
20
21//-------------------------------------------------
22//  specimx_sound_device - constructor
23//-------------------------------------------------
24
25specimx_sound_device::specimx_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
26   : device_t(mconfig, SPECIMX, "Specialist MX Custom", tag, owner, clock),
27     device_sound_interface(mconfig, *this),
28     m_mixer_channel(NULL)
2129{
22   assert(device != NULL);
23   assert(device->type() == SPECIMX);
24   return (specimx_sound_state *)downcast<specimx_sound_device *>(device)->token();
30    memset(m_specimx_input, 0, sizeof(int)*3);
2531}
2632
27static DEVICE_START(specimx_sound)
33
34//-------------------------------------------------
35//  device_start - device-specific startup
36//-------------------------------------------------
37
38void specimx_sound_device::device_start()
2839{
29   specimx_sound_state *state = get_safe_token(device);
30   state->specimx_input[0] = state->specimx_input[1] = state->specimx_input[2] = 0;
31   state->mixer_channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, specimx_sh_update);
40   m_specimx_input[0] = m_specimx_input[1] = m_specimx_input[2] = 0;
41   m_mixer_channel = stream_alloc(0, 1, machine().sample_rate());
3242}
3343
34static STREAM_UPDATE( specimx_sh_update )
44
45//-------------------------------------------------
46//  sound_stream_update - handle a stream update
47//-------------------------------------------------
48
49void specimx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
3550{
36   specimx_sound_state *state = get_safe_token(device);
3751   INT16 channel_0_signal;
3852   INT16 channel_1_signal;
3953   INT16 channel_2_signal;
4054
4155   stream_sample_t *sample_left = outputs[0];
4256
43   channel_0_signal = state->specimx_input[0] ? 3000 : -3000;
44   channel_1_signal = state->specimx_input[1] ? 3000 : -3000;
45   channel_2_signal = state->specimx_input[2] ? 3000 : -3000;
57   channel_0_signal = m_specimx_input[0] ? 3000 : -3000;
58   channel_1_signal = m_specimx_input[1] ? 3000 : -3000;
59   channel_2_signal = m_specimx_input[2] ? 3000 : -3000;
4660
4761   while (samples--)
4862   {
r21677r21678
6175   }
6276}
6377
64void specimx_set_input(device_t *device, int index, int state)
78
79void specimx_sound_device::set_input(int index, int state)
6580{
66   specimx_sound_state *sndstate = get_safe_token(device);
67   if (sndstate->mixer_channel!=NULL) {
68      sndstate->mixer_channel->update();
81   if (m_mixer_channel!=NULL)
82    {
83      m_mixer_channel->update();
6984   }
70   sndstate->specimx_input[index] = state;
85   m_specimx_input[index] = state;
7186}
7287
7388
74const device_type SPECIMX = &device_creator<specimx_sound_device>;
75
76specimx_sound_device::specimx_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
77   : device_t(mconfig, SPECIMX, "Specialist MX Custom", tag, owner, clock),
78      device_sound_interface(mconfig, *this)
79{
80   m_token = global_alloc_clear(specimx_sound_state);
81}
82
83//-------------------------------------------------
84//  device_config_complete - perform any
85//  operations now that the configuration is
86//  complete
87//-------------------------------------------------
88
89void specimx_sound_device::device_config_complete()
90{
91}
92
93//-------------------------------------------------
94//  device_start - device-specific startup
95//-------------------------------------------------
96
97void specimx_sound_device::device_start()
98{
99   DEVICE_START_NAME( specimx_sound )(this);
100}
101
102//-------------------------------------------------
103//  sound_stream_update - handle a stream update
104//-------------------------------------------------
105
106void specimx_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
107{
108   // should never get here
109   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
110}
trunk/src/mess/audio/svision.c
r21677r21678
77#include "emu.h"
88#include "includes/svision.h"
99
10enum SVISION_NOISE_Type
11{
12   SVISION_NOISE_Type7Bit,
13   SVISION_NOISE_Type14Bit
14};
1510
16struct SVISION_NOISE
17{
18   UINT8 reg[3];
19   int on, right, left, play;
20   SVISION_NOISE_Type type;
21   int state;
22   int volume;
23   int count;
24   double step, pos;
25   int value; // currently simple random function
26};
11// device type definition
12const device_type SVISION = &device_creator<svision_sound_device>;
2713
28struct SVISION_DMA
29{
30   UINT8 reg[5];
31   int on, right, left;
32   int ca14to16;
33   int start,size;
34   double pos, step;
35   int finished;
36};
3714
38struct SVISION_CHANNEL
39{
40   UINT8 reg[4];
41   int on;
42   int waveform, volume;
43   int pos;
44   int size;
45   int count;
46};
15//**************************************************************************
16//  LIVE DEVICE
17//**************************************************************************
4718
48struct svision_sound_state
49{
50   sound_stream *mixer_channel;
51   SVISION_DMA dma;
52   SVISION_NOISE noise;
53   SVISION_CHANNEL channel[2];
54};
19//-------------------------------------------------
20//  svision_sound_device - constructor
21//-------------------------------------------------
5522
56
57INLINE svision_sound_state *get_safe_token(device_t *device)
23svision_sound_device::svision_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
24   : device_t(mconfig, SVISION, "Super Vision Custom", tag, owner, clock),
25     device_sound_interface(mconfig, *this),
26     m_mixer_channel(NULL)
5827{
59   assert(device != NULL);
60   assert(device->type() == SVISION);
61   return (svision_sound_state *)downcast<svision_sound_device *>(device)->token();
6228}
6329
64int *svision_dma_finished(device_t *device)
65{
66   svision_sound_state *state = get_safe_token(device);
67   return &state->dma.finished;
68}
6930
70void svision_sound_decrement(device_t *device)
71{
72   svision_sound_state *state = get_safe_token(device);
31//-------------------------------------------------
32//  device_start - device-specific startup
33//-------------------------------------------------
7334
74   if (state->channel[0].count > 0)
75      state->channel[0].count--;
76   if (state->channel[1].count > 0)
77      state->channel[1].count--;
78   if (state->noise.count > 0)
79      state->noise.count--;
80}
81
82WRITE8_DEVICE_HANDLER( svision_sounddma_w )
35void svision_sound_device::device_start()
8336{
84   svision_sound_state *state = get_safe_token(device);
85   logerror("%.6f svision snddma write %04x %02x\n", space.machine().time().as_double(),offset+0x18,data);
86   state->dma.reg[offset] = data;
87   switch (offset)
88   {
89      case 0:
90      case 1:
91         state->dma.start = (state->dma.reg[0] | (state->dma.reg[1] << 8));
92         break;
93      case 2:
94         state->dma.size = (data ? data : 0x100) * 32;
95         break;
96      case 3:
97         state->dma.step = space.machine().device("maincpu")->unscaled_clock() / (256.0 * space.machine().sample_rate() * (1 + (data & 3)));
98         state->dma.right = data & 4;
99         state->dma.left = data & 8;
100         state->dma.ca14to16 = ((data & 0x70) >> 4) << 14;
101         break;
102      case 4:
103         state->dma.on = data & 0x80;
104         if (state->dma.on)
105         {
106            state->dma.pos = 0.0;
107         }
108         break;
109   }
110}
37   memset(&m_dma, 0, sizeof(m_dma));
38   memset(&m_noise, 0, sizeof(m_noise));
39   memset(m_channel, 0, sizeof(m_channel));
11140
112WRITE8_DEVICE_HANDLER( svision_noise_w )
113{
114   svision_sound_state *state = get_safe_token(device);
115   //  logerror("%.6f svision noise write %04x %02x\n",machine.time(),offset+0x28,data);
116   state->noise.reg[offset]=data;
117   switch (offset)
118   {
119      case 0:
120         state->noise.volume=data&0xf;
121         state->noise.step= space.machine().device("maincpu")->unscaled_clock() / (256.0*space.machine().sample_rate()*(1+(data>>4)));
122         break;
123      case 1:
124         state->noise.count = data + 1;
125         break;
126      case 2:
127         state->noise.type = (SVISION_NOISE_Type) (data & 1);
128         state->noise.play = data & 2;
129         state->noise.right = data & 4;
130         state->noise.left = data & 8;
131         state->noise.on = data & 0x10; /* honey bee start */
132         state->noise.state = 1;
133         break;
134   }
135   state->noise.pos=0.0;
41   m_mixer_channel = stream_alloc(0, 2, machine().sample_rate());
13642}
13743
138void svision_soundport_w(device_t *device, int which, int offset, int data)
139{
140   svision_sound_state *state = get_safe_token(device);
141   SVISION_CHANNEL *channel = &state->channel[which];
142   UINT16 size;
14344
144   state->mixer_channel->update();
145   channel->reg[offset] = data;
45//-------------------------------------------------
46//  sound_stream_update - handle a stream update
47//-------------------------------------------------
14648
147   switch (offset)
148   {
149      case 0:
150      case 1:
151         size = channel->reg[0] | ((channel->reg[1] & 7) << 8);
152         if (size)
153         {
154            //  channel->size=(int)(device->machine().sample_rate()*(size<<5)/4e6);
155            channel->size= (int) (device->machine().sample_rate() * (size << 5) / device->machine().device("maincpu")->unscaled_clock());
156         }
157         else
158         {
159            channel->size = 0;
160         }
161         channel->pos = 0;
162         break;
163      case 2:
164         channel->on = data & 0x40;
165         channel->waveform = (data & 0x30) >> 4;
166         channel->volume = data & 0xf;
167         break;
168      case 3:
169         channel->count = data + 1;
170         break;
171   }
172}
173
174/************************************/
175/* Sound handler update             */
176/************************************/
177static STREAM_UPDATE( svision_update )
49void svision_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
17850{
179   svision_sound_state *state = get_safe_token(device);
18051   stream_sample_t *left=outputs[0], *right=outputs[1];
18152   int i, j;
18253   SVISION_CHANNEL *channel;
r21677r21678
18556   {
18657      *left = 0;
18758      *right = 0;
188      for (channel=state->channel, j=0; j<ARRAY_LENGTH(state->channel); j++, channel++)
59      for (channel=m_channel, j=0; j<ARRAY_LENGTH(m_channel); j++, channel++)
18960      {
19061         if (channel->size != 0)
19162         {
r21677r21678
22192               channel->pos = 0;
22293         }
22394      }
224      if (state->noise.on && (state->noise.play || state->noise.count))
95      if (m_noise.on && (m_noise.play || m_noise.count))
22596      {
226         INT16 s = (state->noise.value ? 1 << 8: 0) * state->noise.volume;
97         INT16 s = (m_noise.value ? 1 << 8: 0) * m_noise.volume;
22798         int b1, b2;
228         if (state->noise.left)
99         if (m_noise.left)
229100            *left += s;
230         if (state->noise.right)
101         if (m_noise.right)
231102            *right += s;
232         state->noise.pos += state->noise.step;
233         if (state->noise.pos >= 1.0)
103         m_noise.pos += m_noise.step;
104         if (m_noise.pos >= 1.0)
234105         {
235            switch (state->noise.type)
106            switch (m_noise.type)
236107            {
237108               case SVISION_NOISE_Type7Bit:
238                  state->noise.value = state->noise.state & 0x40 ? 1 : 0;
239                  b1 = (state->noise.state & 0x40) != 0;
240                  b2 = (state->noise.state & 0x20) != 0;
241                  state->noise.state=(state->noise.state<<1)+(b1!=b2?1:0);
109                  m_noise.value = m_noise.state & 0x40 ? 1 : 0;
110                  b1 = (m_noise.state & 0x40) != 0;
111                  b2 = (m_noise.state & 0x20) != 0;
112                  m_noise.state=(m_noise.state<<1)+(b1!=b2?1:0);
242113                  break;
243114               case SVISION_NOISE_Type14Bit:
244115               default:
245                  state->noise.value = state->noise.state & 0x2000 ? 1 : 0;
246                  b1 = (state->noise.state & 0x2000) != 0;
247                  b2 = (state->noise.state & 0x1000) != 0;
248                  state->noise.state = (state->noise.state << 1) + (b1 != b2 ? 1 : 0);
116                  m_noise.value = m_noise.state & 0x2000 ? 1 : 0;
117                  b1 = (m_noise.state & 0x2000) != 0;
118                  b2 = (m_noise.state & 0x1000) != 0;
119                  m_noise.state = (m_noise.state << 1) + (b1 != b2 ? 1 : 0);
249120            }
250            state->noise.pos -= 1;
121            m_noise.pos -= 1;
251122         }
252123      }
253      if (state->dma.on)
124      if (m_dma.on)
254125      {
255126         UINT8 sample;
256127         INT16 s;
257         UINT16 addr = state->dma.start + (unsigned) state->dma.pos / 2;
128         UINT16 addr = m_dma.start + (unsigned) m_dma.pos / 2;
258129         if (addr >= 0x8000 && addr < 0xc000)
259130         {
260            sample = device->machine().root_device().memregion("user1")->base()[(addr & 0x3fff) | state->dma.ca14to16];
131            sample = machine().root_device().memregion("user1")->base()[(addr & 0x3fff) | m_dma.ca14to16];
261132         }
262133         else
263134         {
264            sample = device->machine().device("maincpu")->memory().space(AS_PROGRAM).read_byte(addr);
135            sample = machine().device("maincpu")->memory().space(AS_PROGRAM).read_byte(addr);
265136         }
266         if (((unsigned)state->dma.pos) & 1)
137         if (((unsigned)m_dma.pos) & 1)
267138            s = (sample & 0xf);
268139         else
269140            s = (sample & 0xf0) >> 4;
270141         s <<= 8;
271         if (state->dma.left)
142         if (m_dma.left)
272143            *left += s;
273         if (state->dma.right)
144         if (m_dma.right)
274145            *right += s;
275         state->dma.pos += state->dma.step;
276         if (state->dma.pos >= state->dma.size)
146         m_dma.pos += m_dma.step;
147         if (m_dma.pos >= m_dma.size)
277148         {
278            svision_state *sv_state = device->machine().driver_data<svision_state>();
279            state->dma.finished = TRUE;
280            state->dma.on = FALSE;
149            svision_state *sv_state = machine().driver_data<svision_state>();
150            m_dma.finished = TRUE;
151            m_dma.on = FALSE;
281152            sv_state->svision_irq();
282153         }
283154      }
284155   }
285156}
286157
287/************************************/
288/* Sound handler start              */
289/************************************/
290158
291static DEVICE_START( svision_sound )
159WRITE8_MEMBER( svision_sound_device::svision_sounddma_w )
292160{
293   svision_sound_state *state = get_safe_token(device);
294   memset(&state->dma, 0, sizeof(state->dma));
295   memset(&state->noise, 0, sizeof(state->noise));
296   memset(state->channel, 0, sizeof(state->channel));
297
298   state->mixer_channel = device->machine().sound().stream_alloc(*device, 0, 2, device->machine().sample_rate(), 0, svision_update);
161   logerror("%.6f svision snddma write %04x %02x\n", space.machine().time().as_double(),offset+0x18,data);
162   m_dma.reg[offset] = data;
163   switch (offset)
164   {
165      case 0:
166      case 1:
167         m_dma.start = (m_dma.reg[0] | (m_dma.reg[1] << 8));
168         break;
169      case 2:
170         m_dma.size = (data ? data : 0x100) * 32;
171         break;
172      case 3:
173         m_dma.step = space.machine().device("maincpu")->unscaled_clock() / (256.0 * space.machine().sample_rate() * (1 + (data & 3)));
174         m_dma.right = data & 4;
175         m_dma.left = data & 8;
176         m_dma.ca14to16 = ((data & 0x70) >> 4) << 14;
177         break;
178      case 4:
179         m_dma.on = data & 0x80;
180         if (m_dma.on)
181         {
182            m_dma.pos = 0.0;
183         }
184         break;
185   }
299186}
300187
301const device_type SVISION = &device_creator<svision_sound_device>;
302188
303svision_sound_device::svision_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
304   : device_t(mconfig, SVISION, "Super Vision Custom", tag, owner, clock),
305      device_sound_interface(mconfig, *this)
189WRITE8_MEMBER( svision_sound_device::svision_noise_w )
306190{
307   m_token = global_alloc_clear(svision_sound_state);
191   //  logerror("%.6f svision noise write %04x %02x\n",machine.time(),offset+0x28,data);
192   m_noise.reg[offset]=data;
193   switch (offset)
194   {
195      case 0:
196         m_noise.volume=data&0xf;
197         m_noise.step= space.machine().device("maincpu")->unscaled_clock() / (256.0*space.machine().sample_rate()*(1+(data>>4)));
198         break;
199      case 1:
200         m_noise.count = data + 1;
201         break;
202      case 2:
203         m_noise.type = (SVISION_NOISE_Type) (data & 1);
204         m_noise.play = data & 2;
205         m_noise.right = data & 4;
206         m_noise.left = data & 8;
207         m_noise.on = data & 0x10; /* honey bee start */
208         m_noise.state = 1;
209         break;
210   }
211   m_noise.pos=0.0;
308212}
309213
310//-------------------------------------------------
311//  device_config_complete - perform any
312//  operations now that the configuration is
313//  complete
314//-------------------------------------------------
315214
316void svision_sound_device::device_config_complete()
215int *svision_sound_device::dma_finished()
317216{
217   return &m_dma.finished;
318218}
319219
320//-------------------------------------------------
321//  device_start - device-specific startup
322//-------------------------------------------------
323220
324void svision_sound_device::device_start()
221void svision_sound_device::sound_decrement()
325222{
326   DEVICE_START_NAME( svision_sound )(this);
223   if (m_channel[0].count > 0)
224      m_channel[0].count--;
225   if (m_channel[1].count > 0)
226      m_channel[1].count--;
227   if (m_noise.count > 0)
228      m_noise.count--;
327229}
328230
329//-------------------------------------------------
330//  sound_stream_update - handle a stream update
331//-------------------------------------------------
332231
333void svision_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
232void svision_sound_device::soundport_w(int which, int offset, int data)
334233{
335   // should never get here
336   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
234   SVISION_CHANNEL *channel = &m_channel[which];
235   UINT16 size;
236
237   m_mixer_channel->update();
238   channel->reg[offset] = data;
239
240   switch (offset)
241   {
242      case 0:
243      case 1:
244         size = channel->reg[0] | ((channel->reg[1] & 7) << 8);
245         if (size)
246         {
247            //  channel->size=(int)(device->machine().sample_rate()*(size<<5)/4e6);
248            channel->size= (int) (machine().sample_rate() * (size << 5) / machine().device("maincpu")->unscaled_clock());
249         }
250         else
251         {
252            channel->size = 0;
253         }
254         channel->pos = 0;
255         break;
256      case 2:
257         channel->on = data & 0x40;
258         channel->waveform = (data & 0x30) >> 4;
259         channel->volume = data & 0xf;
260         break;
261      case 3:
262         channel->count = data + 1;
263         break;
264   }
337265}
266
trunk/src/mess/audio/wswan.c
r21677r21678
1111#include "includes/wswan.h"
1212
1313
14struct CHAN {
15   UINT16  freq;           /* frequency */
16   UINT32  period;         /* period */
17   UINT32  pos;            /* position */
18   UINT8   vol_left;       /* volume left */
19   UINT8   vol_right;      /* volume right */
20   UINT8   on;         /* on/off */
21   INT8    signal;         /* signal */
22};
14// device type definition
15const device_type WSWAN = &device_creator<wswan_sound_device>;
2316
24struct wswan_sound_state {
25   sound_stream *channel;
26   struct CHAN audio1;     /* Audio channel 1 */
27   struct CHAN audio2;     /* Audio channel 2 */
28   struct CHAN audio3;     /* Audio channel 3 */
29   struct CHAN audio4;     /* Audio channel 4 */
30   INT8    sweep_step;     /* Sweep step */
31   UINT32  sweep_time;     /* Sweep time */
32   UINT32  sweep_count;        /* Sweep counter */
33   UINT8   noise_type;     /* Noise generator type */
34   UINT8   noise_reset;        /* Noise reset */
35   UINT8   noise_enable;       /* Noise enable */
36   UINT16  sample_address;     /* Sample address */
37   UINT8   audio2_voice;       /* Audio 2 voice */
38   UINT8   audio3_sweep;       /* Audio 3 sweep */
39   UINT8   audio4_noise;       /* Audio 4 noise */
40   UINT8   mono;           /* mono */
41   UINT8   voice_data;     /* voice data */
42   UINT8   output_volume;      /* output volume */
43   UINT8   external_stereo;    /* external stereo */
44   UINT8   external_speaker;   /* external speaker */
45   UINT16  noise_shift;        /* Noise counter shift register */
46   UINT8   master_volume;      /* Master volume */
47};
4817
18//**************************************************************************
19//  LIVE DEVICE
20//**************************************************************************
4921
50INLINE wswan_sound_state *get_safe_token(device_t *device)
22//-------------------------------------------------
23//  wswan_sound_device - constructor
24//-------------------------------------------------
25
26wswan_sound_device::wswan_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
27   : device_t(mconfig, WSWAN, "WonderSwan Custom", tag, owner, clock),
28     device_sound_interface(mconfig, *this),
29     m_channel(NULL),
30     m_sweep_step(0),
31     m_sweep_time(0),
32     m_sweep_count(0),
33     m_noise_type(0),
34     m_noise_reset(0),
35     m_noise_enable(0),
36     m_sample_address(0),
37     m_audio2_voice(0),
38     m_audio3_sweep(0),
39     m_audio4_noise(0),
40     m_mono(0),
41     m_voice_data(0),
42     m_output_volume(0),
43     m_external_stereo(0),
44     m_external_speaker(0),
45     m_noise_shift(0),
46     m_master_volume(0)
5147{
52   assert(device != NULL);
53   assert(device->type() == WSWAN);
54   return (wswan_sound_state *)downcast<wswan_sound_device *>(device)->token();
5548}
5649
57static void wswan_ch_set_freq( running_machine &machine, struct CHAN *ch, UINT16 freq )
50
51//-------------------------------------------------
52//  device_start - device-specific startup
53//-------------------------------------------------
54
55void wswan_sound_device::device_start()
5856{
57   m_channel = stream_alloc(0, 2, machine().sample_rate());
58
59   m_audio1.on = 0;
60   m_audio1.signal = 16;
61   m_audio1.pos = 0;
62   m_audio2.on = 0;
63   m_audio2.signal = 16;
64   m_audio2.pos = 0;
65   m_audio3.on = 0;
66   m_audio3.signal = 16;
67   m_audio3.pos = 0;
68   m_audio4.on = 0;
69   m_audio4.signal = 16;
70   m_audio4.pos = 0;
71}
72
73
74//-------------------------------------------------
75//  sound_stream_update - handle a stream update
76//-------------------------------------------------
77
78void wswan_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
79{
80   stream_sample_t sample, left, right;
81
82   while( samples-- > 0 )
83   {
84      left = right = 0;
85
86      if ( m_audio1.on ) {
87         sample = m_audio1.signal;
88         m_audio1.pos++;
89         if ( m_audio1.pos >= m_audio1.period / 2 ) {
90            m_audio1.pos = 0;
91            m_audio1.signal = -m_audio1.signal;
92         }
93         left += m_audio1.vol_left * sample;
94         right += m_audio1.vol_right * sample;
95      }
96
97      if ( m_audio2.on ) {
98         if ( m_audio2_voice ) {
99            left += (m_voice_data - 128)*(m_master_volume & 0x0f);
100            right += (m_voice_data - 128)*(m_master_volume & 0x0f);
101         } else {
102            sample = m_audio2.signal;
103            m_audio2.pos++;
104            if ( m_audio2.pos >= m_audio2.period / 2 ) {
105               m_audio2.pos = 0;
106               m_audio2.signal = -m_audio2.signal;
107            }
108            left += m_audio2.vol_left * sample;
109            right += m_audio2.vol_right * sample;
110         }
111      }
112
113      if ( m_audio3.on ) {
114         sample = m_audio3.signal;
115         m_audio3.pos++;
116         if ( m_audio3.pos >= m_audio3.period / 2 ) {
117            m_audio3.pos = 0;
118            m_audio3.signal = -m_audio3.signal;
119         }
120         if ( m_audio3_sweep && m_sweep_time ) {
121            m_sweep_count++;
122            if ( m_sweep_count >= m_sweep_time ) {
123               m_sweep_count = 0;
124               m_audio3.freq += m_sweep_step;
125               m_audio3.period = machine().sample_rate() / (3072000  / ((2048 - (m_audio3.freq & 0x7ff)) << 5));
126            }
127         }
128         left += m_audio3.vol_left * sample;
129         right += m_audio3.vol_right * sample;
130      }
131
132      if ( m_audio4.on ) {
133         if ( m_audio4_noise ) {
134            sample = 0;
135         } else {
136            sample = m_audio4.signal;
137            m_audio4.pos++;
138            if ( m_audio4.pos >= m_audio4.period / 2 ) {
139               m_audio4.pos = 0;
140               m_audio4.signal = -m_audio4.signal;
141            }
142         }
143         left += m_audio4.vol_left * sample;
144         right += m_audio4.vol_right * sample;
145      }
146
147      left <<= 5;
148      right <<= 5;
149
150      *(outputs[0]++) = left;
151      *(outputs[1]++) = right;
152   }
153}
154
155
156void wswan_sound_device::wswan_ch_set_freq( CHAN *ch, UINT16 freq )
157{
59158   freq &= 0x7ff;  // docs say freq is 11bits and a few games (Morita Shougi, World Stadium + others) write 0x800 causing a divide by 0 crash
60159   ch->freq = freq;
61   ch->period = machine.sample_rate() / (3072000 / ((2048 - freq) << 5));
160   ch->period = machine().sample_rate() / (3072000 / ((2048 - freq) << 5));
62161}
63162
64WRITE8_DEVICE_HANDLER( wswan_sound_port_w )
163WRITE8_MEMBER( wswan_sound_device::wswan_sound_port_w )
65164{
66   wswan_sound_state *state = get_safe_token(device);
165   m_channel->update();
67166
68   state->channel->update();
69
70167   switch( offset ) {
71168   case 0x80:              /* Audio 1 freq (lo) */
72      wswan_ch_set_freq(space.machine(), &state->audio1, (state->audio1.freq & 0xff00) | data);
169      wswan_ch_set_freq(&m_audio1, (m_audio1.freq & 0xff00) | data);
73170      break;
74171   case 0x81:              /* Audio 1 freq (hi) */
75      wswan_ch_set_freq(space.machine(), &state->audio1, (data << 8 ) | (state->audio1.freq & 0x00ff));
172      wswan_ch_set_freq(&m_audio1, (data << 8 ) | (m_audio1.freq & 0x00ff));
76173      break;
77174   case 0x82:              /* Audio 2 freq (lo) */
78      wswan_ch_set_freq(space.machine(), &state->audio2, (state->audio2.freq & 0xff00) | data);
175      wswan_ch_set_freq(&m_audio2, (m_audio2.freq & 0xff00) | data);
79176      break;
80177   case 0x83:              /* Audio 2 freq (hi) */
81      wswan_ch_set_freq(space.machine(), &state->audio2, (data << 8 ) | (state->audio2.freq & 0x00ff));
178      wswan_ch_set_freq(&m_audio2, (data << 8 ) | (m_audio2.freq & 0x00ff));
82179      break;
83180   case 0x84:              /* Audio 3 freq (lo) */
84      wswan_ch_set_freq(space.machine(), &state->audio3, (state->audio3.freq & 0xff00) | data);
181      wswan_ch_set_freq(&m_audio3, (m_audio3.freq & 0xff00) | data);
85182      break;
86183   case 0x85:              /* Audio 3 freq (hi) */
87      wswan_ch_set_freq(space.machine(), &state->audio3, (data << 8) | (state->audio3.freq & 0x00ff));
184      wswan_ch_set_freq(&m_audio3, (data << 8) | (m_audio3.freq & 0x00ff));
88185      break;
89186   case 0x86:              /* Audio 4 freq (lo) */
90      wswan_ch_set_freq(space.machine(), &state->audio4, (state->audio4.freq & 0xff00) | data);
187      wswan_ch_set_freq(&m_audio4, (m_audio4.freq & 0xff00) | data);
91188      break;
92189   case 0x87:              /* Audio 4 freq (hi) */
93      wswan_ch_set_freq(space.machine(), &state->audio4, (data << 8) | (state->audio4.freq & 0x00ff));
190      wswan_ch_set_freq(&m_audio4, (data << 8) | (m_audio4.freq & 0x00ff));
94191      break;
95192   case 0x88:              /* Audio 1 volume */
96      state->audio1.vol_left = ( data & 0xF0 ) >> 4;
97      state->audio1.vol_right = data & 0x0F;
193      m_audio1.vol_left = ( data & 0xF0 ) >> 4;
194      m_audio1.vol_right = data & 0x0F;
98195      break;
99196   case 0x89:              /* Audio 2 volume */
100      state->voice_data = data;
101      state->audio2.vol_left = ( data & 0xF0 ) >> 4;
102      state->audio2.vol_right = data & 0x0F;
197      m_voice_data = data;
198      m_audio2.vol_left = ( data & 0xF0 ) >> 4;
199      m_audio2.vol_right = data & 0x0F;
103200      break;
104201   case 0x8A:              /* Audio 3 volume */
105      state->audio3.vol_left = ( data & 0xF0 ) >> 4;
106      state->audio3.vol_right = data & 0x0F;
202      m_audio3.vol_left = ( data & 0xF0 ) >> 4;
203      m_audio3.vol_right = data & 0x0F;
107204      break;
108205   case 0x8B:              /* Audio 4 volume */
109      state->audio4.vol_left = ( data & 0xF0 ) >> 4;
110      state->audio4.vol_right = data & 0x0F;
206      m_audio4.vol_left = ( data & 0xF0 ) >> 4;
207      m_audio4.vol_right = data & 0x0F;
111208      break;
112209   case 0x8C:              /* Sweep step */
113      state->sweep_step = (INT8)data;
210      m_sweep_step = (INT8)data;
114211      break;
115212   case 0x8D:              /* Sweep time */
116      state->sweep_time = space.machine().sample_rate() / ( 3072000 / ( 8192 * (data + 1) ) );
213      m_sweep_time = space.machine().sample_rate() / ( 3072000 / ( 8192 * (data + 1) ) );
117214      break;
118215   case 0x8E:              /* Noise control */
119      state->noise_type = data & 0x07;
120      state->noise_reset = ( data & 0x08 ) >> 3;
121      state->noise_enable = ( data & 0x10 ) >> 4;
216      m_noise_type = data & 0x07;
217      m_noise_reset = ( data & 0x08 ) >> 3;
218      m_noise_enable = ( data & 0x10 ) >> 4;
122219      break;
123220   case 0x8F:              /* Sample location */
124      state->sample_address = data << 6;
221      m_sample_address = data << 6;
125222      break;
126223   case 0x90:              /* Audio control */
127      state->audio1.on = data & 0x01;
128      state->audio2.on = ( data & 0x02 ) >> 1;
129      state->audio3.on = ( data & 0x04 ) >> 2;
130      state->audio4.on = ( data & 0x08 ) >> 3;
131      state->audio2_voice = ( data & 0x20 ) >> 5;
132      state->audio3_sweep = ( data & 0x40 ) >> 6;
133      state->audio4_noise = ( data & 0x80 ) >> 7;
224      m_audio1.on = data & 0x01;
225      m_audio2.on = ( data & 0x02 ) >> 1;
226      m_audio3.on = ( data & 0x04 ) >> 2;
227      m_audio4.on = ( data & 0x08 ) >> 3;
228      m_audio2_voice = ( data & 0x20 ) >> 5;
229      m_audio3_sweep = ( data & 0x40 ) >> 6;
230      m_audio4_noise = ( data & 0x80 ) >> 7;
134231      break;
135232   case 0x91:              /* Audio output */
136      state->mono = data & 0x01;
137      state->output_volume = ( data & 0x06 ) >> 1;
138      state->external_stereo = ( data & 0x08 ) >> 3;
139      state->external_speaker = 1;
233      m_mono = data & 0x01;
234      m_output_volume = ( data & 0x06 ) >> 1;
235      m_external_stereo = ( data & 0x08 ) >> 3;
236      m_external_speaker = 1;
140237      break;
141238   case 0x92:              /* Noise counter shift register (lo) */
142      state->noise_shift = ( state->noise_shift & 0xFF00 ) | data;
239      m_noise_shift = ( m_noise_shift & 0xFF00 ) | data;
143240      break;
144241   case 0x93:              /* Noise counter shift register (hi) */
145      state->noise_shift = ( data << 8 ) | ( state->noise_shift & 0x00FF );
242      m_noise_shift = ( data << 8 ) | ( m_noise_shift & 0x00FF );
146243      break;
147244   case 0x94:              /* Master volume */
148      state->master_volume = data;
245      m_master_volume = data;
149246      break;
150247   }
151248}
152249
153static STREAM_UPDATE( wswan_sh_update )
154{
155   wswan_sound_state *state = get_safe_token(device);
156   stream_sample_t sample, left, right;
157250
158   while( samples-- > 0 )
159   {
160      left = right = 0;
161
162      if ( state->audio1.on ) {
163         sample = state->audio1.signal;
164         state->audio1.pos++;
165         if ( state->audio1.pos >= state->audio1.period / 2 ) {
166            state->audio1.pos = 0;
167            state->audio1.signal = -state->audio1.signal;
168         }
169         left += state->audio1.vol_left * sample;
170         right += state->audio1.vol_right * sample;
171      }
172
173      if ( state->audio2.on ) {
174         if ( state->audio2_voice ) {
175            left += (state->voice_data - 128)*(state->master_volume & 0x0f);
176            right += (state->voice_data - 128)*(state->master_volume & 0x0f);
177         } else {
178            sample = state->audio2.signal;
179            state->audio2.pos++;
180            if ( state->audio2.pos >= state->audio2.period / 2 ) {
181               state->audio2.pos = 0;
182               state->audio2.signal = -state->audio2.signal;
183            }
184            left += state->audio2.vol_left * sample;
185            right += state->audio2.vol_right * sample;
186         }
187      }
188
189      if ( state->audio3.on ) {
190         sample = state->audio3.signal;
191         state->audio3.pos++;
192         if ( state->audio3.pos >= state->audio3.period / 2 ) {
193            state->audio3.pos = 0;
194            state->audio3.signal = -state->audio3.signal;
195         }
196         if ( state->audio3_sweep && state->sweep_time ) {
197            state->sweep_count++;
198            if ( state->sweep_count >= state->sweep_time ) {
199               state->sweep_count = 0;
200               state->audio3.freq += state->sweep_step;
201               state->audio3.period = device->machine().sample_rate() / (3072000  / ((2048 - (state->audio3.freq & 0x7ff)) << 5));
202            }
203         }
204         left += state->audio3.vol_left * sample;
205         right += state->audio3.vol_right * sample;
206      }
207
208      if ( state->audio4.on ) {
209         if ( state->audio4_noise ) {
210            sample = 0;
211         } else {
212            sample = state->audio4.signal;
213            state->audio4.pos++;
214            if ( state->audio4.pos >= state->audio4.period / 2 ) {
215               state->audio4.pos = 0;
216               state->audio4.signal = -state->audio4.signal;
217            }
218         }
219         left += state->audio4.vol_left * sample;
220         right += state->audio4.vol_right * sample;
221      }
222
223      left <<= 5;
224      right <<= 5;
225
226      *(outputs[0]++) = left;
227      *(outputs[1]++) = right;
228   }
229}
230
231static DEVICE_START(wswan_sound)
232{
233   wswan_sound_state *state = get_safe_token(device);
234   state->channel = device->machine().sound().stream_alloc(*device, 0, 2, device->machine().sample_rate(), 0, wswan_sh_update);
235
236   state->audio1.on = 0;
237   state->audio1.signal = 16;
238   state->audio1.pos = 0;
239   state->audio2.on = 0;
240   state->audio2.signal = 16;
241   state->audio2.pos = 0;
242   state->audio3.on = 0;
243   state->audio3.signal = 16;
244   state->audio3.pos = 0;
245   state->audio4.on = 0;
246   state->audio4.signal = 16;
247   state->audio4.pos = 0;
248}
249
250
251const device_type WSWAN = &device_creator<wswan_sound_device>;
252
253wswan_sound_device::wswan_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
254   : device_t(mconfig, WSWAN, "WonderSwan Custom", tag, owner, clock),
255      device_sound_interface(mconfig, *this)
256{
257   m_token = global_alloc_clear(wswan_sound_state);
258}
259
260//-------------------------------------------------
261//  device_config_complete - perform any
262//  operations now that the configuration is
263//  complete
264//-------------------------------------------------
265
266void wswan_sound_device::device_config_complete()
267{
268}
269
270//-------------------------------------------------
271//  device_start - device-specific startup
272//-------------------------------------------------
273
274void wswan_sound_device::device_start()
275{
276   DEVICE_START_NAME( wswan_sound )(this);
277}
278
279//-------------------------------------------------
280//  sound_stream_update - handle a stream update
281//-------------------------------------------------
282
283void wswan_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
284{
285   // should never get here
286   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
287}

Previous 199869 Revisions Next


© 1997-2024 The MAME Team