Previous 15994 Revisions Next

r4328 Sunday 22nd February, 2009 at 13:12:29 UTC by Nathan Woods
Fixed Mac 0.129u4 regression
[src/mess/audio]mac.c
[src/mess/includes]mac.h
[src/mess/machine]mac.c

src/mess/audio/mac.c
r4327r4328
1111#include "streams.h"
1212
1313
14static sound_stream *mac_stream;
15static int sample_enable = 0;
16static UINT16 *mac_snd_buf_ptr;
14/***************************************************************************
15    MACROS / CONSTANTS
16***************************************************************************/
1717
18
1918#define MAC_MAIN_SND_BUF_OFFSET   0x0300
2019#define MAC_ALT_SND_BUF_OFFSET   0x5F00
2120#define MAC_SND_BUF_SIZE      370         /* total number of scan lines */
r4327r4328
2524/* intermediate buffer */
2625#define SND_CACHE_SIZE 128
2726
28static UINT8 *snd_cache;
29static int snd_cache_len;
30static int snd_cache_head;
31static int snd_cache_tail;
3227
28/***************************************************************************
29    TYPE DEFINITIONS
30***************************************************************************/
3331
32typedef struct _mac_sound mac_sound;
33struct _mac_sound
34{
35   sound_stream *mac_stream;
36   int sample_enable;
37   UINT16 *mac_snd_buf_ptr;
38   UINT8 *snd_cache;
39   int snd_cache_len;
40   int snd_cache_head;
41   int snd_cache_tail;
42   int indexx;
43};
44
45
46/***************************************************************************
47    INLINE FUNCTIONS
48***************************************************************************/
49
50INLINE mac_sound *get_token(const device_config *device)
51{
52   assert(device != NULL);
53   assert(sound_get_type(device) == SOUND_MAC_SOUND);
54   return (mac_sound *) device->token;
55}
56
57
58/***************************************************************************
59    IMPLEMENTATION
60***************************************************************************/
61
3462/************************************/
3563/* Stream updater                   */
3664/************************************/
r4327r4328
3967{
4068   INT16 last_val = 0;
4169   stream_sample_t *buffer = outputs[0];
70   mac_sound *token = get_token(device);
4271
4372   /* if we're not enabled, just fill with 0 */
4473   if (device->machine->sample_rate == 0)
r4327r4328
4877   }
4978
5079   /* fill in the sample */
51   while (samples && snd_cache_len)
80   while (samples && token->snd_cache_len)
5281   {
53      *buffer++ = last_val = ((snd_cache[snd_cache_head] << 8) ^ 0x8000) & 0xff00;
54      snd_cache_head++;
55      snd_cache_head %= SND_CACHE_SIZE;
56      snd_cache_len--;
82      *buffer++ = last_val = ((token->snd_cache[token->snd_cache_head] << 8) ^ 0x8000) & 0xff00;
83      token->snd_cache_head++;
84      token->snd_cache_head %= SND_CACHE_SIZE;
85      token->snd_cache_len--;
5786      samples--;
5887   }
5988
6089   while (samples--)
61   {   /* should never happen */
90   {
91      /* should never happen */
6292      *buffer++ = last_val;
6393   }
6494}
r4327r4328
71101
72102static DEVICE_START(mac_sound)
73103{
74   snd_cache = auto_malloc(SND_CACHE_SIZE * sizeof(*snd_cache));
75   mac_stream = stream_create(device, 0, 1, MAC_SAMPLE_RATE, 0, mac_sound_update);
76   snd_cache_head = snd_cache_len = snd_cache_tail = 0;
104   mac_sound *token = get_token(device);
105
106   memset(token, 0, sizeof(*token));
107   token->snd_cache = auto_malloc(SND_CACHE_SIZE * sizeof(*token->snd_cache));
108   token->mac_stream = stream_create(device, 0, 1, MAC_SAMPLE_RATE, 0, mac_sound_update);
77109}
78110
79111
r4327r4328
81113/*
82114   Set the sound enable flag (VIA port line)
83115*/
84void mac_enable_sound(running_machine *machine, int on)
116void mac_enable_sound(const device_config *device, int on)
85117{
86   sample_enable = on;
118   mac_sound *token = get_token(device);
119   token->sample_enable = on;
87120}
88121
89122
r4327r4328
91124/*
92125   Set the current sound buffer (one VIA port line)
93126*/
94void mac_set_sound_buffer(running_machine *machine, int buffer)
127void mac_set_sound_buffer(const device_config *device, int buffer)
95128{
129   mac_sound *token = get_token(device);
130
96131   if (buffer)
97      mac_snd_buf_ptr = (UINT16 *) (mess_ram + mess_ram_size - MAC_MAIN_SND_BUF_OFFSET);
132      token->mac_snd_buf_ptr = (UINT16 *) (mess_ram + mess_ram_size - MAC_MAIN_SND_BUF_OFFSET);
98133   else
99      mac_snd_buf_ptr = (UINT16 *) (mess_ram + mess_ram_size - MAC_ALT_SND_BUF_OFFSET);
134      token->mac_snd_buf_ptr = (UINT16 *) (mess_ram + mess_ram_size - MAC_ALT_SND_BUF_OFFSET);
100135}
101136
102137
r4327r4328
104139/*
105140   Set the current sound volume (3 VIA port line)
106141*/
107void mac_set_volume(running_machine *machine, int volume)
142void mac_set_volume(const device_config *device, int volume)
108143{
109   const device_config *device = devtag_get_device(machine, DEVICE_GET_INFO_NAME(mac_sound), "custom");
144   mac_sound *token = get_token(device);
110145
111   stream_update(mac_stream);
112
146   stream_update(token->mac_stream);
113147   volume = (100 / 7) * volume;
114
115148   sound_set_output_gain(device, 0, volume / 100.0);
116149}
117150
r4327r4328
120153/*
121154   Fetch one byte from sound buffer and put it to sound output (called every scanline)
122155*/
123void mac_sh_updatebuffer(running_machine *machine)
156void mac_sh_updatebuffer(const device_config *device)
124157{
125   static int indexx;
126   UINT16 *base = mac_snd_buf_ptr;
158   mac_sound *token = get_token(device);
159   UINT16 *base = token->mac_snd_buf_ptr;
127160
128   indexx++;
129   indexx %= 370;
161   token->indexx++;
162   token->indexx %= 370;
130163
131   if (snd_cache_len >= SND_CACHE_SIZE)
164   if (token->snd_cache_len >= SND_CACHE_SIZE)
132165   {
133166      /* clear buffer */
134      stream_update(mac_stream);
167      stream_update(token->mac_stream);
135168   }
136169
137   if (snd_cache_len >= SND_CACHE_SIZE)
170   if (token->snd_cache_len >= SND_CACHE_SIZE)
138171      /* should never happen */
139172      return;
140173
141   snd_cache[snd_cache_tail] = sample_enable ? (base[indexx] >> 8) & 0xff : 0;
142   snd_cache_tail++;
143   snd_cache_tail %= SND_CACHE_SIZE;
144   snd_cache_len++;
174   token->snd_cache[token->snd_cache_tail] = token->sample_enable ? (base[token->indexx] >> 8) & 0xff : 0;
175   token->snd_cache_tail++;
176   token->snd_cache_tail %= SND_CACHE_SIZE;
177   token->snd_cache_len++;
145178}
146179
147180
r4327r4328
149182{
150183   switch (state)
151184   {
185      /* --- the following bits of info are returned as 64-bit signed integers --- */
186      case DEVINFO_INT_TOKEN_BYTES:      info->i = sizeof(mac_sound);         break;
187
152188      /* --- the following bits of info are returned as pointers to data or functions --- */
153      case DEVINFO_FCT_START:                     info->start = DEVICE_START_NAME(mac_sound);   break;
189      case DEVINFO_FCT_START:            info->start = DEVICE_START_NAME(mac_sound);   break;
154190
155191      /* --- the following bits of info are returned as NULL-terminated strings --- */
156      case DEVINFO_STR_NAME:                     strcpy(info->s, "Mac Sound Custom");            break;
157      case DEVINFO_STR_SOURCE_FILE:               strcpy(info->s, __FILE__);                  break;
192      case DEVINFO_STR_NAME:            strcpy(info->s, "Mac Sound");               break;
193      case DEVINFO_STR_SOURCE_FILE:      strcpy(info->s, __FILE__);                  break;
158194   }
159195}
src/mess/includes/mac.h
r4327r4328
7070
7171DEVICE_GET_INFO( mac_sound );
7272
73void mac_enable_sound( running_machine *machine, int on );
74void mac_set_sound_buffer( running_machine *machine, int buffer );
75void mac_set_volume( running_machine *machine, int volume );
73void mac_enable_sound( const device_config *device, int on );
74void mac_set_sound_buffer( const device_config *device, int buffer );
75void mac_set_volume( const device_config *device, int volume );
7676
77void mac_sh_updatebuffer(running_machine *machine);
77void mac_sh_updatebuffer(const device_config *device);
7878
7979
8080#endif /* MAC_H_ */
src/mess/machine/mac.c
r4327r4328
17221722
17231723static WRITE8_DEVICE_HANDLER(mac_via_out_a)
17241724{
1725   const device_config *sound = devtag_get_device(device->machine, SOUND, "custom");
1726   const device_config *fdc = devtag_get_device(device->machine, APPLEFDC, "fdc");
1727
17251728   set_scc_waitrequest((data & 0x80) >> 7);
17261729   mac_set_screen_buffer((data & 0x40) >> 6);
1727   sony_set_sel_line((device_config*)devtag_get_device(device->machine, APPLEFDC, "fdc"),(data & 0x20) >> 5);
1730   sony_set_sel_line(fdc,(data & 0x20) >> 5);
17281731   if (mac_model == MODEL_MAC_SE)   // on SE this selects which floppy drive (0 = upper, 1 = lower)
17291732   {
17301733      mac_drive_select = ((data & 0x10) >> 4);
r4327r4328
17321735
17331736   if (mac_model < MODEL_MAC_SE)   // SE no longer has dual buffers
17341737   {
1735      mac_set_sound_buffer(device->machine, (data & 0x08) >> 3);
1738      mac_set_sound_buffer(sound, (data & 0x08) >> 3);
17361739   }
1737   mac_set_volume(device->machine, data & 0x07);
1740   mac_set_volume(sound, data & 0x07);
17381741
17391742   /* Early Mac models had VIA A4 control overlaying.  In the Mac SE (and
17401743    * possibly later models), overlay was set on reset, but cleared on the
r4327r4328
17451748
17461749static WRITE8_DEVICE_HANDLER(mac_via_out_b)
17471750{
1751   const device_config *sound = devtag_get_device(device->machine, SOUND, "custom");
17481752   int new_rtc_rTCClk;
17491753
1750   mac_enable_sound(device->machine, (data & 0x80) == 0);
1754   mac_enable_sound(sound, (data & 0x80) == 0);
17511755
17521756   // SE and Classic have SCSI enable/disable here
17531757   if (mac_model >= MODEL_MAC_SE)
r4327r4328
18831887   mac_set_screen_buffer(1);
18841888
18851889   /* setup sound */
1886   mac_set_sound_buffer(machine, 0);
1890   mac_set_sound_buffer(devtag_get_device(machine, SOUND, "custom"), 0);
18871891
18881892   if (has_adb())
18891893   {
r4327r4328
18951899
18961900   if ((mac_model == MODEL_MAC_SE) || (mac_model == MODEL_MAC_CLASSIC))
18971901   {
1898      mac_set_sound_buffer(machine, 1);
1902      mac_set_sound_buffer(devtag_get_device(machine, SOUND, "custom"), 1);
18991903
19001904      // classic will fail RAM test and try to boot appletalk if RAM is not all zero
19011905      memset(mess_ram, 0, mess_ram_size);
r4327r4328
20842088{
20852089   int scanline;
20862090
2087   mac_sh_updatebuffer(machine);
2091   mac_sh_updatebuffer(devtag_get_device(machine, SOUND, "custom"));
20882092
20892093   scanline = video_screen_get_vpos(machine->primary_screen);
20902094   if (scanline == MAC_V_VIS)

Previous 15994 Revisions Next


© 1998-2018 The MESS Team