Previous 15994 Revisions Next

r14373 Tuesday 7th February, 2012 at 09:59:46 UTC by Miodrag Milanović
Arcadia custom sound moved to c++ (nw)
[src/mess/audio]arcadia.c arcadia.h*
[src/mess/drivers]arcadia.c
[src/mess/includes]arcadia.h
[src/mess/video]arcadia.c

src/mess/audio/arcadia.c
r14372r14373
3838//0x01bc
3939
4040
41typedef struct _arcadia_sound arcadia_sound;
42struct _arcadia_sound
43{
44    sound_stream *channel;
45    UINT8 reg[3];
46    int size, pos,tval,nval;
47   unsigned mode, omode;
48   unsigned volume;
49   unsigned lfsr;
50};
41// device type definition
42const device_type ARCADIA_SOUND = &device_creator<arcadia_sound_device>;
5143
44//-------------------------------------------------
45//  arcadia_sound_device - constructor
46//-------------------------------------------------
5247
53
54INLINE arcadia_sound *get_token(device_t *device)
48arcadia_sound_device::arcadia_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
49   : device_t(mconfig, ARCADIA_SOUND, "Arcadia Custom Sound", tag, owner, clock),
50     device_sound_interface(mconfig, *this)
5551{
56   assert(device != NULL);
57   assert(device->type() == ARCADIA);
58   return (arcadia_sound *) downcast<legacy_device_base *>(device)->token();
5952}
6053
61
62
63void arcadia_soundport_w (device_t *device, int offset, int data)
54//-------------------------------------------------
55//  device_start - device-specific startup
56//-------------------------------------------------
57void arcadia_sound_device::device_start()
6458{
65   arcadia_sound *token = get_token(device);
66
67   token->channel->update();
68   token->reg[offset] = data;
69
70   //logerror("arcadia_sound write:%x=%x\n",offset,data);
71
72   switch (offset)
73   {
74      case 1:
75         //as per Gobbler samples:
76         //the freq counter is only applied on the next change in the flip flop
77         token->size = (data & 0x7f)*OSAMP;
78         //logerror("arcadia_sound write: frq:%d\n",data);
79
80         //reset LFSR
81         if(!token->size)
82            token->lfsr = LFSR_INIT;
83      break;
84
85      case 2:
86         token->volume = (data & 0x07) * 0x800;
87         token->mode   = (data & 0x18) >> 3;
88
89         //logerror("arcadia_sound write: vol:%d mode:%d\n",token->volume,token->mode );
90
91         if (token->mode != token->omode){
92            //not 100% sure about this, maybe we should not reset anything
93            //token->pos  = 0;
94            token->tval = 0;
95         }
96         token->omode = token->mode;
97      break;
98   }
59    m_channel = machine().sound().stream_alloc(*this, 0, 1, UVI_PAL*OSAMP, this);
60    m_lfsr    = LFSR_INIT;
61    m_tval    = 1;
62   logerror("arcadia_sound start\n");
9963}
10064
65//-------------------------------------------------
66//  sound_stream_update - handle update requests for
67//  our sound stream
68//-------------------------------------------------
10169
102
103/************************************/
104/* Sound handler update             */
105/************************************/
106
107static STREAM_UPDATE( arcadia_update )
70void arcadia_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
10871{
10972   int i;
110   arcadia_sound *token = get_token(device);
11173   stream_sample_t *buffer = outputs[0];
11274
11375   for (i = 0; i < samples; i++, buffer++)
r14372r14373
11577      *buffer = 0;
11678
11779      //if minimal pitch ?
118      if (token->reg[1]){
119         switch (token->mode){
80      if (m_reg[1]){
81         switch (m_mode){
12082            //dont play anything
12183            case 0:break;
12284
12385            //tone only
12486            case 1:
125               *buffer = token->volume * token->tval;
87               *buffer = m_volume * m_tval;
12688            break;
12789
12890            //noise only
12991            case 2:
130               *buffer = token->volume * token->nval;
92               *buffer = m_volume * m_nval;
13193            break;
13294
13395            //tone AND noise (bitwise and)
13496            case 3:
135               *buffer = token->volume * (token->tval & token->nval);
97               *buffer = m_volume * (m_tval & m_nval);
13698            break;
13799         }
138100
139101         //counter
140         token->pos++;
102         m_pos++;
141103
142         if (token->pos >= token->size){
104         if (m_pos >= m_size){
143105
144106            //calculate new noise bit ( taps: 0000T000T)
145            unsigned char newBit = token->lfsr & 1;         //first tap
146            newBit = (newBit ^ ((token->lfsr & 0x10)?1:0) );//xor with second tap
107            unsigned char newBit = m_lfsr & 1;         //first tap
108            newBit = (newBit ^ ((m_lfsr & 0x10)?1:0) );//xor with second tap
147109
148            token->nval = token->lfsr & 1; //taking new output from LSB
149            token->lfsr = token->lfsr >> 1;//shifting
110            m_nval = m_lfsr & 1; //taking new output from LSB
111            m_lfsr = m_lfsr >> 1;//shifting
150112
151113            //insert new bit at end position (size-1) (only if non null)
152114            if (newBit)
153               token->lfsr |= LFSR_MASK;
115               m_lfsr |= LFSR_MASK;
154116
155117            //invert tone
156            token->tval = !token->tval;
118            m_tval = !m_tval;
157119
158            token->pos = 0;
120            m_pos = 0;
159121         }
160122      }
161123   }
r14372r14373
163125
164126
165127
166/************************************/
167/* Sound handler start              */
168/************************************/
128//-------------------------------------------------
129//  soundport_w
130//-------------------------------------------------
169131
170static DEVICE_START(arcadia_sound)
132WRITE8_MEMBER(arcadia_sound_device::write)
171133{
172   arcadia_sound *token = get_token(device);
173    token->channel = device->machine().sound().stream_alloc(*device, 0, 1, UVI_PAL*OSAMP, 0, arcadia_update);
174    token->lfsr    = LFSR_INIT;
175    token->tval    = 1;
176   logerror("arcadia_sound start\n");
177}
134   m_channel->update();
135   m_reg[offset] = data;
178136
137   //logerror("arcadia_sound write:%x=%x\n",offset,data);
179138
180
181DEVICE_GET_INFO(arcadia_sound)
182{
183   switch (state)
139   switch (offset)
184140   {
185      /* --- the following bits of info are returned as 64-bit signed integers --- */
186      case DEVINFO_INT_TOKEN_BYTES:               info->i = sizeof(arcadia_sound);         break;
141      case 1:
142         //as per Gobbler samples:
143         //the freq counter is only applied on the next change in the flip flop
144         m_size = (data & 0x7f)*OSAMP;
145         //logerror("arcadia_sound write: frq:%d\n",data);
187146
188      /* --- the following bits of info are returned as pointers to data or functions --- */
189      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(arcadia_sound);      break;
147         //reset LFSR
148         if(!m_size)
149            m_lfsr = LFSR_INIT;
150      break;
190151
191      /* --- the following bits of info are returned as NULL-terminated strings --- */
192      case DEVINFO_STR_NAME:                     strcpy(info->s, "Arcadia Custom");               break;
193      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
152      case 2:
153         m_volume = (data & 0x07) * 0x800;
154         m_mode   = (data & 0x18) >> 3;
155
156         //logerror("arcadia_sound write: vol:%d mode:%d\n",m_volume,m_mode );
157
158         if (m_mode != m_omode){
159            //not 100% sure about this, maybe we should not reset anything
160            //m_pos  = 0;
161            m_tval = 0;
162         }
163         m_omode = m_mode;
164      break;
194165   }
195166}
196
197DEFINE_LEGACY_SOUND_DEVICE(ARCADIA, arcadia_sound);
src/mess/audio/arcadia.h
r0r14373
1#ifndef ARCADIA_SOUND_H_
2#define ARCADIA_SOUND_H_
3
4//**************************************************************************
5//  INTERFACE CONFIGURATION MACROS
6//**************************************************************************
7
8#define MCFG_ARCADIA_SOUND_ADD(_tag) \
9   MCFG_SOUND_ADD(_tag, ARCADIA_SOUND, 0)
10
11//**************************************************************************
12//  TYPE DEFINITIONS
13//**************************************************************************
14
15// ======================> arcadia_sound_device
16
17class arcadia_sound_device : public device_t,
18                      public device_sound_interface
19{
20public:
21   // construction/destruction
22   arcadia_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
23
24   DECLARE_WRITE8_MEMBER(write);
25protected:
26   // device-level overrides
27   virtual void device_start();
28   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
29   
30   sound_stream *m_channel;
31    UINT8 m_reg[3];
32    int m_size, m_pos,m_tval,m_nval;
33   unsigned m_mode, m_omode;
34   unsigned m_volume;
35   unsigned m_lfsr;
36};
37
38// device type definition
39extern const device_type ARCADIA_SOUND;
40
41#endif /* ARCADIA_SOUND_H_ */
src/mess/video/arcadia.c
r14372r14373
374374
375375WRITE8_MEMBER( arcadia_state::arcadia_video_w )
376376{
377   arcadia_sound_device *sound = machine().device<arcadia_sound_device>("custom");
377378   m_reg.data[offset]=data;
378379   switch (offset)
379380   {
r14372r14373
381382         m_ypos=255-data+YPOS;
382383         break;
383384      case 0xfd:
384         arcadia_soundport_w(machine().device("custom"), offset&3, data);
385         sound->write(space, offset&3, data);
385386         m_multicolor = data & 0x80;
386387         break;
387388      case 0xfe:
388         arcadia_soundport_w(machine().device("custom"), offset&3, data);
389         sound->write(space, offset&3, data);
389390         m_shift = (data>>5);
390391         break;
391392      case 0xf0:
src/mess/includes/arcadia.h
r14372r14373
1010#include "emu.h"
1111#include "cpu/s2650/s2650.h"
1212#include "imagedev/cartslot.h"
13#include "audio/arcadia.h"
1314
1415
1516// space vultures sprites above
r14372r14373
8586extern VIDEO_START( arcadia );
8687extern SCREEN_UPDATE_IND16( arcadia );
8788
88
89/*----------- defined in audio/arcadia.c -----------*/
90
91DECLARE_LEGACY_SOUND_DEVICE(ARCADIA, arcadia_sound);
92
93void arcadia_soundport_w (device_t *device, int mode, int data);
94
95
9689#endif /* ARCADIA_H_ */
src/mess/drivers/arcadia.c
r14372r14373
550550
551551   /* sound hardware */
552552   MCFG_SPEAKER_STANDARD_MONO("mono")
553   MCFG_SOUND_ADD("custom", ARCADIA, 0)
553   MCFG_ARCADIA_SOUND_ADD("custom")
554554   MCFG_SOUND_ROUTE(ALL_OUTPUTS, "mono", 1.00)
555555
556556   /* cartridge */

Previous 15994 Revisions Next


© 1998-2018 The MESS Team