src/mess/audio/mac.c
| r4327 | r4328 | |
| 11 | 11 | #include "streams.h" |
| 12 | 12 | |
| 13 | 13 | |
| 14 | | static sound_stream *mac_stream; |
| 15 | | static int sample_enable = 0; |
| 16 | | static UINT16 *mac_snd_buf_ptr; |
| 14 | /*************************************************************************** |
| 15 | MACROS / CONSTANTS |
| 16 | ***************************************************************************/ |
| 17 | 17 | |
| 18 | | |
| 19 | 18 | #define MAC_MAIN_SND_BUF_OFFSET 0x0300 |
| 20 | 19 | #define MAC_ALT_SND_BUF_OFFSET 0x5F00 |
| 21 | 20 | #define MAC_SND_BUF_SIZE 370 /* total number of scan lines */ |
| r4327 | r4328 | |
| 25 | 24 | /* intermediate buffer */ |
| 26 | 25 | #define SND_CACHE_SIZE 128 |
| 27 | 26 | |
| 28 | | static UINT8 *snd_cache; |
| 29 | | static int snd_cache_len; |
| 30 | | static int snd_cache_head; |
| 31 | | static int snd_cache_tail; |
| 32 | 27 | |
| 28 | /*************************************************************************** |
| 29 | TYPE DEFINITIONS |
| 30 | ***************************************************************************/ |
| 33 | 31 | |
| 32 | typedef struct _mac_sound mac_sound; |
| 33 | struct _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 | |
| 50 | INLINE 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 | |
| 34 | 62 | /************************************/ |
| 35 | 63 | /* Stream updater */ |
| 36 | 64 | /************************************/ |
| r4327 | r4328 | |
| 39 | 67 | { |
| 40 | 68 | INT16 last_val = 0; |
| 41 | 69 | stream_sample_t *buffer = outputs[0]; |
| 70 | mac_sound *token = get_token(device); |
| 42 | 71 | |
| 43 | 72 | /* if we're not enabled, just fill with 0 */ |
| 44 | 73 | if (device->machine->sample_rate == 0) |
| r4327 | r4328 | |
| 48 | 77 | } |
| 49 | 78 | |
| 50 | 79 | /* fill in the sample */ |
| 51 | | while (samples && snd_cache_len) |
| 80 | while (samples && token->snd_cache_len) |
| 52 | 81 | { |
| 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--; |
| 57 | 86 | samples--; |
| 58 | 87 | } |
| 59 | 88 | |
| 60 | 89 | while (samples--) |
| 61 | | { /* should never happen */ |
| 90 | { |
| 91 | /* should never happen */ |
| 62 | 92 | *buffer++ = last_val; |
| 63 | 93 | } |
| 64 | 94 | } |
| r4327 | r4328 | |
| 71 | 101 | |
| 72 | 102 | static DEVICE_START(mac_sound) |
| 73 | 103 | { |
| 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); |
| 77 | 109 | } |
| 78 | 110 | |
| 79 | 111 | |
| r4327 | r4328 | |
| 81 | 113 | /* |
| 82 | 114 | Set the sound enable flag (VIA port line) |
| 83 | 115 | */ |
| 84 | | void mac_enable_sound(running_machine *machine, int on) |
| 116 | void mac_enable_sound(const device_config *device, int on) |
| 85 | 117 | { |
| 86 | | sample_enable = on; |
| 118 | mac_sound *token = get_token(device); |
| 119 | token->sample_enable = on; |
| 87 | 120 | } |
| 88 | 121 | |
| 89 | 122 | |
| r4327 | r4328 | |
| 91 | 124 | /* |
| 92 | 125 | Set the current sound buffer (one VIA port line) |
| 93 | 126 | */ |
| 94 | | void mac_set_sound_buffer(running_machine *machine, int buffer) |
| 127 | void mac_set_sound_buffer(const device_config *device, int buffer) |
| 95 | 128 | { |
| 129 | mac_sound *token = get_token(device); |
| 130 | |
| 96 | 131 | 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); |
| 98 | 133 | 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); |
| 100 | 135 | } |
| 101 | 136 | |
| 102 | 137 | |
| r4327 | r4328 | |
| 104 | 139 | /* |
| 105 | 140 | Set the current sound volume (3 VIA port line) |
| 106 | 141 | */ |
| 107 | | void mac_set_volume(running_machine *machine, int volume) |
| 142 | void mac_set_volume(const device_config *device, int volume) |
| 108 | 143 | { |
| 109 | | const device_config *device = devtag_get_device(machine, DEVICE_GET_INFO_NAME(mac_sound), "custom"); |
| 144 | mac_sound *token = get_token(device); |
| 110 | 145 | |
| 111 | | stream_update(mac_stream); |
| 112 | | |
| 146 | stream_update(token->mac_stream); |
| 113 | 147 | volume = (100 / 7) * volume; |
| 114 | | |
| 115 | 148 | sound_set_output_gain(device, 0, volume / 100.0); |
| 116 | 149 | } |
| 117 | 150 | |
| r4327 | r4328 | |
| 120 | 153 | /* |
| 121 | 154 | Fetch one byte from sound buffer and put it to sound output (called every scanline) |
| 122 | 155 | */ |
| 123 | | void mac_sh_updatebuffer(running_machine *machine) |
| 156 | void mac_sh_updatebuffer(const device_config *device) |
| 124 | 157 | { |
| 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; |
| 127 | 160 | |
| 128 | | indexx++; |
| 129 | | indexx %= 370; |
| 161 | token->indexx++; |
| 162 | token->indexx %= 370; |
| 130 | 163 | |
| 131 | | if (snd_cache_len >= SND_CACHE_SIZE) |
| 164 | if (token->snd_cache_len >= SND_CACHE_SIZE) |
| 132 | 165 | { |
| 133 | 166 | /* clear buffer */ |
| 134 | | stream_update(mac_stream); |
| 167 | stream_update(token->mac_stream); |
| 135 | 168 | } |
| 136 | 169 | |
| 137 | | if (snd_cache_len >= SND_CACHE_SIZE) |
| 170 | if (token->snd_cache_len >= SND_CACHE_SIZE) |
| 138 | 171 | /* should never happen */ |
| 139 | 172 | return; |
| 140 | 173 | |
| 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++; |
| 145 | 178 | } |
| 146 | 179 | |
| 147 | 180 | |
| r4327 | r4328 | |
| 149 | 182 | { |
| 150 | 183 | switch (state) |
| 151 | 184 | { |
| 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 | |
| 152 | 188 | /* --- 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; |
| 154 | 190 | |
| 155 | 191 | /* --- 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; |
| 158 | 194 | } |
| 159 | 195 | } |
src/mess/machine/mac.c
| r4327 | r4328 | |
| 1722 | 1722 | |
| 1723 | 1723 | static WRITE8_DEVICE_HANDLER(mac_via_out_a) |
| 1724 | 1724 | { |
| 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 | |
| 1725 | 1728 | set_scc_waitrequest((data & 0x80) >> 7); |
| 1726 | 1729 | 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); |
| 1728 | 1731 | if (mac_model == MODEL_MAC_SE) // on SE this selects which floppy drive (0 = upper, 1 = lower) |
| 1729 | 1732 | { |
| 1730 | 1733 | mac_drive_select = ((data & 0x10) >> 4); |
| r4327 | r4328 | |
| 1732 | 1735 | |
| 1733 | 1736 | if (mac_model < MODEL_MAC_SE) // SE no longer has dual buffers |
| 1734 | 1737 | { |
| 1735 | | mac_set_sound_buffer(device->machine, (data & 0x08) >> 3); |
| 1738 | mac_set_sound_buffer(sound, (data & 0x08) >> 3); |
| 1736 | 1739 | } |
| 1737 | | mac_set_volume(device->machine, data & 0x07); |
| 1740 | mac_set_volume(sound, data & 0x07); |
| 1738 | 1741 | |
| 1739 | 1742 | /* Early Mac models had VIA A4 control overlaying. In the Mac SE (and |
| 1740 | 1743 | * possibly later models), overlay was set on reset, but cleared on the |
| r4327 | r4328 | |
| 1745 | 1748 | |
| 1746 | 1749 | static WRITE8_DEVICE_HANDLER(mac_via_out_b) |
| 1747 | 1750 | { |
| 1751 | const device_config *sound = devtag_get_device(device->machine, SOUND, "custom"); |
| 1748 | 1752 | int new_rtc_rTCClk; |
| 1749 | 1753 | |
| 1750 | | mac_enable_sound(device->machine, (data & 0x80) == 0); |
| 1754 | mac_enable_sound(sound, (data & 0x80) == 0); |
| 1751 | 1755 | |
| 1752 | 1756 | // SE and Classic have SCSI enable/disable here |
| 1753 | 1757 | if (mac_model >= MODEL_MAC_SE) |
| r4327 | r4328 | |
| 1883 | 1887 | mac_set_screen_buffer(1); |
| 1884 | 1888 | |
| 1885 | 1889 | /* setup sound */ |
| 1886 | | mac_set_sound_buffer(machine, 0); |
| 1890 | mac_set_sound_buffer(devtag_get_device(machine, SOUND, "custom"), 0); |
| 1887 | 1891 | |
| 1888 | 1892 | if (has_adb()) |
| 1889 | 1893 | { |
| r4327 | r4328 | |
| 1895 | 1899 | |
| 1896 | 1900 | if ((mac_model == MODEL_MAC_SE) || (mac_model == MODEL_MAC_CLASSIC)) |
| 1897 | 1901 | { |
| 1898 | | mac_set_sound_buffer(machine, 1); |
| 1902 | mac_set_sound_buffer(devtag_get_device(machine, SOUND, "custom"), 1); |
| 1899 | 1903 | |
| 1900 | 1904 | // classic will fail RAM test and try to boot appletalk if RAM is not all zero |
| 1901 | 1905 | memset(mess_ram, 0, mess_ram_size); |
| r4327 | r4328 | |
| 2084 | 2088 | { |
| 2085 | 2089 | int scanline; |
| 2086 | 2090 | |
| 2087 | | mac_sh_updatebuffer(machine); |
| 2091 | mac_sh_updatebuffer(devtag_get_device(machine, SOUND, "custom")); |
| 2088 | 2092 | |
| 2089 | 2093 | scanline = video_screen_get_vpos(machine->primary_screen); |
| 2090 | 2094 | if (scanline == MAC_V_VIS) |