Previous 199869 Revisions Next

r24775 Tuesday 6th August, 2013 at 15:24:10 UTC by Osso
Modernized s2636 sound device. (nw)
[src/emu/sound]s2636.c s2636.h
[src/emu/video]s2636.c
[src/mame/drivers]zac2650.c
[src/mame/includes]zac2650.h
[src/mame/video]zac2650.c

trunk/src/mame/video/zac2650.c
r24774r24775
55/*************************************************************/
66
77#include "emu.h"
8#include "sound/s2636.h"
98#include "includes/zac2650.h"
109
1110
r24774r24775
3534   machine().gfx[2]->mark_dirty(offset/8);
3635   if (offset == 0xc7)
3736   {
38      s2636_soundport_w(machine().device("s2636snd"), 0, data);
37      m_s2636_sound->soundport_w(0, data);
3938   }
4039}
4140
trunk/src/mame/includes/zac2650.h
r24774r24775
1#include "sound/s2636.h"
2
13class zac2650_state : public driver_device
24{
35public:
r24774r24775
57      : driver_device(mconfig, type, tag),
68      m_videoram(*this, "videoram"),
79      m_s2636_0_ram(*this, "s2636_0_ram"),
8      m_maincpu(*this, "maincpu") { }
10      m_maincpu(*this, "maincpu"),
11      m_s2636_sound(*this, "s2636snd") { }
912
1013   required_shared_ptr<UINT8> m_videoram;
1114   required_shared_ptr<UINT8> m_s2636_0_ram;
15   
16   required_device<cpu_device> m_maincpu;
17   required_device<s2636_sound_device> m_s2636_sound;
18   
1219   bitmap_ind16 m_bitmap;
1320   bitmap_ind16 m_spritebitmap;
1421   int m_CollisionBackground;
r24774r24775
2532   UINT32 screen_update_tinvader(screen_device &screen, bitmap_ind16 &bitmap, const rectangle &cliprect);
2633   int SpriteCollision(int first,int second);
2734   void draw_sprites(bitmap_ind16 &bitmap, const rectangle &cliprect);
28   required_device<cpu_device> m_maincpu;
2935};
trunk/src/mame/drivers/zac2650.c
r24774r24775
1010
1111#include "emu.h"
1212#include "cpu/s2650/s2650.h"
13#include "sound/s2636.h"
1413
1514#include "tinv2650.lh"
1615#include "includes/zac2650.h"
trunk/src/emu/video/s2636.c
r24774r24775
319319      const s2636_interface *intf = get_interface(device);
320320      if ( intf->sound && *intf->sound )
321321      {
322         s2636_soundport_w(device->machine().device(intf->sound), 0, data);
322         device->machine().device<s2636_sound_device>(intf->sound)->soundport_w(0, data);
323323      }
324324   }
325325
trunk/src/emu/sound/s2636.c
r24774r24775
66
77#include "emu.h"
88#include "sound/s2636.h"
9#include "devlegcy.h"
109
10const device_type S2636_SOUND = &device_creator<s2636_sound_device>;
1111
12struct s2636_sound
12s2636_sound_device::s2636_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
13   : device_t(mconfig, S2636_SOUND, "S2636", tag, owner, clock, "s2636", __FILE__),
14      device_sound_interface(mconfig, *this),
15      m_channel(NULL),
16      m_size(0),
17      m_pos(0),
18      m_level(0)
1319{
14   sound_stream *channel;
15   UINT8 reg[1];
16   int size, pos;
17   unsigned level;
18};
20   for (int i = 0; i < 1; i++)
21   m_reg[i] = 0;
22}
1923
24//-------------------------------------------------
25//  device_config_complete - perform any
26//  operations now that the configuration is
27//  complete
28//-------------------------------------------------
2029
21static s2636_sound *get_token(device_t *device)
30void s2636_sound_device::device_config_complete()
2231{
23   assert(device != NULL);
24   assert(device->type() == S2636_SOUND);
25   return (s2636_sound *) downcast<s2636_sound_device *>(device)->token();
2632}
2733
34//-------------------------------------------------
35//  device_start - device-specific startup
36//-------------------------------------------------
2837
29void s2636_soundport_w (device_t *device, int offset, int data)
38void s2636_sound_device::device_start()
3039{
31   s2636_sound *token = get_token(device);
40   m_channel = machine().sound().stream_alloc(*this, 0, 1, machine().sample_rate(), this);
41   save_item(NAME(m_size));
42   save_item(NAME(m_pos));
43   save_item(NAME(m_level));
44   
45   for (int i = 0; i < 1; i++)
46   save_item(NAME(m_reg[i]), i);
47}
3248
33   token->channel->update();
34   token->reg[offset] = data;
49
50void s2636_sound_device::soundport_w (int offset, int data)
51{
52   m_channel->update();
53   m_reg[offset] = data;
3554   switch (offset)
3655   {
3756      case 0:
38         token->pos = 0;
39         token->level = TRUE;
57         m_pos = 0;
58         m_level = TRUE;
4059         // frequency 7874/(data+1)
41         token->size = device->machine().sample_rate() * (data + 1) /7874;
60         m_size = machine().sample_rate() * (data + 1) /7874;
4261         break;
4362   }
4463}
4564
4665
66//-------------------------------------------------
67//  sound_stream_update - handle a stream update
68//-------------------------------------------------
4769
48/************************************/
49/* Sound handler update             */
50/************************************/
51
52static STREAM_UPDATE( s2636_update )
70void s2636_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
5371{
5472   int i;
55   s2636_sound *token = get_token(device);
5673   stream_sample_t *buffer = outputs[0];
5774
5875   for (i = 0; i < samples; i++, buffer++)
5976   {
6077      *buffer = 0;
61      if (token->reg[0] && token->pos <= token->size / 2)
78      if (m_reg[0] && m_pos <= m_size / 2)
6279      {
6380         *buffer = 0x7fff;
6481      }
65      if (token->pos <= token->size)
66         token->pos++;
67      if (token->pos > token->size)
68         token->pos = 0;
82      if (m_pos <= m_size)
83         m_pos++;
84      if (m_pos > m_size)
85         m_pos = 0;
6986   }
7087}
71
72
73
74/************************************/
75/* Sound handler start              */
76/************************************/
77
78static DEVICE_START(s2636_sound)
79{
80   s2636_sound *token = get_token(device);
81   memset(token, 0, sizeof(*token));
82   token->channel = device->machine().sound().stream_alloc(*device, 0, 1, device->machine().sample_rate(), 0, s2636_update);
83}
84
85const device_type S2636_SOUND = &device_creator<s2636_sound_device>;
86
87s2636_sound_device::s2636_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock)
88   : device_t(mconfig, S2636_SOUND, "S2636", tag, owner, clock, "s2636", __FILE__),
89      device_sound_interface(mconfig, *this)
90{
91   m_token = global_alloc_clear(s2636_sound);
92}
93
94//-------------------------------------------------
95//  device_config_complete - perform any
96//  operations now that the configuration is
97//  complete
98//-------------------------------------------------
99
100void s2636_sound_device::device_config_complete()
101{
102}
103
104//-------------------------------------------------
105//  device_start - device-specific startup
106//-------------------------------------------------
107
108void s2636_sound_device::device_start()
109{
110   DEVICE_START_NAME( s2636_sound )(this);
111}
112
113//-------------------------------------------------
114//  sound_stream_update - handle a stream update
115//-------------------------------------------------
116
117void s2636_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples)
118{
119   // should never get here
120   fatalerror("sound_stream_update called; not applicable to legacy sound devices\n");
121}
trunk/src/emu/sound/s2636.h
r24774r24775
1414{
1515public:
1616   s2636_sound_device(const machine_config &mconfig, const char *tag, device_t *owner, UINT32 clock);
17   ~s2636_sound_device() { global_free(m_token); }
17   ~s2636_sound_device() {}
1818
19   // access to legacy token
20   void *token() const { assert(m_token != NULL); return m_token; }
19   void soundport_w (int mode, int data);
20   
2121protected:
2222   // device-level overrides
2323   virtual void device_config_complete();
r24774r24775
2525
2626   // sound stream update overrides
2727   virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples);
28
2829private:
2930   // internal state
30   void *m_token;
31   sound_stream *m_channel;
32   UINT8 m_reg[1];
33   int m_size;
34   int m_pos;
35   unsigned m_level;
3136};
3237
3338extern const device_type S2636_SOUND;
3439
35void s2636_soundport_w (device_t *device, int mode, int data);
3640
37
38#endif /* VC4000_H_ */
41#endif /* S2636_SOUND_H_ */

Previous 199869 Revisions Next


© 1997-2024 The MAME Team