Previous 199869 Revisions Next

r21622 Wednesday 6th March, 2013 at 04:36:55 UTC by Andrew Gardner
Modernized vc4000 device.  [Andrew Gardner]
[src/mess/audio]vc4000.c
[src/mess/includes]vc4000.h
[src/mess/video]vc4000.c

trunk/src/mess/audio/vc4000.c
r21621r21622
88#include "includes/vc4000.h"
99
1010
11struct vc4000_sound
12{
13   sound_stream *channel;
14   UINT8 reg[1];
15   int size, pos;
16   unsigned level;
17};
11const device_type VC4000 = &device_creator<vc4000_sound_device>;
1812
19
20static vc4000_sound *get_token(device_t *device)
13vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
14   : device_t(mconfig, VC4000, "VC 4000 Custom", tag, owner, clock),
15     device_sound_interface(mconfig, *this),
16     m_channel(NULL),
17     m_size(0),
18      m_pos(0),
19     m_level(0)
2120{
22   assert(device != NULL);
23   assert(device->type() == VC4000);
24   return (vc4000_sound *) downcast<vc4000_sound_device *>(device)->token();
21   memset(m_reg, 0, sizeof(UINT8)*1);
2522}
2623
2724
28void vc4000_soundport_w (device_t *device, int offset, int data)
29{
30   vc4000_sound *token = get_token(device);
25//-------------------------------------------------
26//  device_start - device-specific startup
27//-------------------------------------------------
3128
32   token->channel->update();
33   token->reg[offset] = data;
34   switch (offset)
35   {
36      case 0:
37         token->pos = 0;
38         token->level = TRUE;
39         // frequency 7874/(data+1)
40         token->size = device->machine().sample_rate() * (data + 1) /7874;
41         break;
42   }
29void vc4000_sound_device::device_start()
30{
31   m_channel = stream_alloc(0, 1, machine().sample_rate());
4332}
4433
4534
35//-------------------------------------------------
36//  sound_stream_update - handle a stream update
37//-------------------------------------------------
4638
47/************************************/
48/* Sound handler update             */
49/************************************/
50
51static STREAM_UPDATE( vc4000_update )
39void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
5240{
5341   int i;
54   vc4000_sound *token = get_token(device);
5542   stream_sample_t *buffer = outputs[0];
5643
5744   for (i = 0; i < samples; i++, buffer++)
5845   {
5946      *buffer = 0;
60      if (token->reg[0] && token->pos <= token->size / 2)
47      if (m_reg[0] && m_pos <= m_size / 2)
6148      {
6249         *buffer = 0x7fff;
6350      }
64      if (token->pos <= token->size)
65         token->pos++;
66      if (token->pos > token->size)
67         token->pos = 0;
51      if (m_pos <= m_size)
52         m_pos++;
53      if (m_pos > m_size)
54         m_pos = 0;
6855   }
6956}
7057
7158
72
73/************************************/
74/* Sound handler start              */
75/************************************/
76
77static DEVICE_START(vc4000_sound)
59void vc4000_sound_device::soundport_w(int offset, int data)
7860{
79   vc4000_sound *token = get_token(device);
80   memset(token, 0, sizeof(*token));
81   token->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, vc4000_update);
61   m_channel->update();
62   m_reg[offset] = data;
63   switch (offset)
64   {
65      case 0:
66         m_pos = 0;
67         m_level = TRUE;
68         // frequency 7874/(data+1)
69         m_size = machine().sample_rate() * (data + 1) /7874;
70         break;
71   }
8272}
83
84const device_type VC4000 = &device_creator<vc4000_sound_device>;
85
86vc4000_sound_device::vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
87   : device_t(mconfig, VC4000, "VC 4000 Custom", tag, owner, clock),
88      device_sound_interface(mconfig, *this)
89{
90   m_token = global_alloc_clear(vc4000_sound);
91}
92
93//-------------------------------------------------
94//  device_config_complete - perform any
95//  operations now that the configuration is
96//  complete
97//-------------------------------------------------
98
99void vc4000_sound_device::device_config_complete()
100{
101}
102
103//-------------------------------------------------
104//  device_start - device-specific startup
105//-------------------------------------------------
106
107void vc4000_sound_device::device_start()
108{
109   DEVICE_START_NAME( vc4000_sound )(this);
110}
111
112//-------------------------------------------------
113//  sound_stream_update - handle a stream update
114//-------------------------------------------------
115
116void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
117{
118   // should never get here
119   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
120}
trunk/src/mess/includes/vc4000.h
r21621r21622
139139
140140/*----------- defined in audio/vc4000.c -----------*/
141141
142//**************************************************************************
143//  TYPE DEFINITIONS
144//**************************************************************************
145
146// ======================> vc4000_sound_device
147
142148class vc4000_sound_device : public device_t,
143                           public device_sound_interface
149                     public device_sound_interface
144150{
145151public:
146152   vc4000_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
147   ~vc4000_sound_device() { global_free(m_token); }
153   ~vc4000_sound_device() { }
148154
149   // access to legacy token
150   void *token() const { assert(m_token != NULL); return m_token; }
151155protected:
152156   // device-level overrides
153   virtual void device_config_complete();
154157   virtual void device_start();
155158
156159   // sound stream update overrides
157160   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
161
162public:
163    void soundport_w(int mode, int data);
164
158165private:
159   // internal state
160   void *m_token;
166   sound_stream *m_channel;
167   UINT8 m_reg[1];
168   int m_size;
169    int m_pos;
170   unsigned m_level;
161171};
162172
163173extern const device_type VC4000;
164174
165void vc4000_soundport_w (device_t *device, int mode, int data);
166
167
168175#endif /* VC4000_H_ */
trunk/src/mess/video/vc4000.c
r21621r21622
320320
321321   case 0xc7:                      // Soundregister
322322      m_video.reg.data[offset] = data;
323      vc4000_soundport_w(machine().device("custom"), 0, data);
323      machine().device<vc4000_sound_device>("custom")->soundport_w(0, data);
324324      break;
325325
326326   case 0xc8:                      // Digits 1 and 2

Previous 199869 Revisions Next


© 1997-2024 The MAME Team