trunk/src/mess/audio/vc4000.c
| r21621 | r21622 | |
| 8 | 8 | #include "includes/vc4000.h" |
| 9 | 9 | |
| 10 | 10 | |
| 11 | | struct vc4000_sound |
| 12 | | { |
| 13 | | sound_stream *channel; |
| 14 | | UINT8 reg[1]; |
| 15 | | int size, pos; |
| 16 | | unsigned level; |
| 17 | | }; |
| 11 | const device_type VC4000 = &device_creator<vc4000_sound_device>; |
| 18 | 12 | |
| 19 | | |
| 20 | | static vc4000_sound *get_token(device_t *device) |
| 13 | vc4000_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) |
| 21 | 20 | { |
| 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); |
| 25 | 22 | } |
| 26 | 23 | |
| 27 | 24 | |
| 28 | | void 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 | //------------------------------------------------- |
| 31 | 28 | |
| 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 | | } |
| 29 | void vc4000_sound_device::device_start() |
| 30 | { |
| 31 | m_channel = stream_alloc(0, 1, machine().sample_rate()); |
| 43 | 32 | } |
| 44 | 33 | |
| 45 | 34 | |
| 35 | //------------------------------------------------- |
| 36 | // sound_stream_update - handle a stream update |
| 37 | //------------------------------------------------- |
| 46 | 38 | |
| 47 | | /************************************/ |
| 48 | | /* Sound handler update */ |
| 49 | | /************************************/ |
| 50 | | |
| 51 | | static STREAM_UPDATE( vc4000_update ) |
| 39 | void vc4000_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 52 | 40 | { |
| 53 | 41 | int i; |
| 54 | | vc4000_sound *token = get_token(device); |
| 55 | 42 | stream_sample_t *buffer = outputs[0]; |
| 56 | 43 | |
| 57 | 44 | for (i = 0; i < samples; i++, buffer++) |
| 58 | 45 | { |
| 59 | 46 | *buffer = 0; |
| 60 | | if (token->reg[0] && token->pos <= token->size / 2) |
| 47 | if (m_reg[0] && m_pos <= m_size / 2) |
| 61 | 48 | { |
| 62 | 49 | *buffer = 0x7fff; |
| 63 | 50 | } |
| 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; |
| 68 | 55 | } |
| 69 | 56 | } |
| 70 | 57 | |
| 71 | 58 | |
| 72 | | |
| 73 | | /************************************/ |
| 74 | | /* Sound handler start */ |
| 75 | | /************************************/ |
| 76 | | |
| 77 | | static DEVICE_START(vc4000_sound) |
| 59 | void vc4000_sound_device::soundport_w(int offset, int data) |
| 78 | 60 | { |
| 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 | } |
| 82 | 72 | } |
| 83 | | |
| 84 | | const device_type VC4000 = &device_creator<vc4000_sound_device>; |
| 85 | | |
| 86 | | vc4000_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 | | |
| 99 | | void vc4000_sound_device::device_config_complete() |
| 100 | | { |
| 101 | | } |
| 102 | | |
| 103 | | //------------------------------------------------- |
| 104 | | // device_start - device-specific startup |
| 105 | | //------------------------------------------------- |
| 106 | | |
| 107 | | void 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 | | |
| 116 | | void 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
| r21621 | r21622 | |
| 139 | 139 | |
| 140 | 140 | /*----------- defined in audio/vc4000.c -----------*/ |
| 141 | 141 | |
| 142 | //************************************************************************** |
| 143 | // TYPE DEFINITIONS |
| 144 | //************************************************************************** |
| 145 | |
| 146 | // ======================> vc4000_sound_device |
| 147 | |
| 142 | 148 | class vc4000_sound_device : public device_t, |
| 143 | | public device_sound_interface |
| 149 | public device_sound_interface |
| 144 | 150 | { |
| 145 | 151 | public: |
| 146 | 152 | 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() { } |
| 148 | 154 | |
| 149 | | // access to legacy token |
| 150 | | void *token() const { assert(m_token != NULL); return m_token; } |
| 151 | 155 | protected: |
| 152 | 156 | // device-level overrides |
| 153 | | virtual void device_config_complete(); |
| 154 | 157 | virtual void device_start(); |
| 155 | 158 | |
| 156 | 159 | // sound stream update overrides |
| 157 | 160 | virtual void sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples); |
| 161 | |
| 162 | public: |
| 163 | void soundport_w(int mode, int data); |
| 164 | |
| 158 | 165 | private: |
| 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; |
| 161 | 171 | }; |
| 162 | 172 | |
| 163 | 173 | extern const device_type VC4000; |
| 164 | 174 | |
| 165 | | void vc4000_soundport_w (device_t *device, int mode, int data); |
| 166 | | |
| 167 | | |
| 168 | 175 | #endif /* VC4000_H_ */ |