src/mess/audio/arcadia.c
| r14372 | r14373 | |
| 38 | 38 | //0x01bc |
| 39 | 39 | |
| 40 | 40 | |
| 41 | | typedef struct _arcadia_sound arcadia_sound; |
| 42 | | struct _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 |
| 42 | const device_type ARCADIA_SOUND = &device_creator<arcadia_sound_device>; |
| 51 | 43 | |
| 44 | //------------------------------------------------- |
| 45 | // arcadia_sound_device - constructor |
| 46 | //------------------------------------------------- |
| 52 | 47 | |
| 53 | | |
| 54 | | INLINE arcadia_sound *get_token(device_t *device) |
| 48 | arcadia_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) |
| 55 | 51 | { |
| 56 | | assert(device != NULL); |
| 57 | | assert(device->type() == ARCADIA); |
| 58 | | return (arcadia_sound *) downcast<legacy_device_base *>(device)->token(); |
| 59 | 52 | } |
| 60 | 53 | |
| 61 | | |
| 62 | | |
| 63 | | void arcadia_soundport_w (device_t *device, int offset, int data) |
| 54 | //------------------------------------------------- |
| 55 | // device_start - device-specific startup |
| 56 | //------------------------------------------------- |
| 57 | void arcadia_sound_device::device_start() |
| 64 | 58 | { |
| 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"); |
| 99 | 63 | } |
| 100 | 64 | |
| 65 | //------------------------------------------------- |
| 66 | // sound_stream_update - handle update requests for |
| 67 | // our sound stream |
| 68 | //------------------------------------------------- |
| 101 | 69 | |
| 102 | | |
| 103 | | /************************************/ |
| 104 | | /* Sound handler update */ |
| 105 | | /************************************/ |
| 106 | | |
| 107 | | static STREAM_UPDATE( arcadia_update ) |
| 70 | void arcadia_sound_device::sound_stream_update(sound_stream &stream, stream_sample_t **inputs, stream_sample_t **outputs, int samples) |
| 108 | 71 | { |
| 109 | 72 | int i; |
| 110 | | arcadia_sound *token = get_token(device); |
| 111 | 73 | stream_sample_t *buffer = outputs[0]; |
| 112 | 74 | |
| 113 | 75 | for (i = 0; i < samples; i++, buffer++) |
| r14372 | r14373 | |
| 115 | 77 | *buffer = 0; |
| 116 | 78 | |
| 117 | 79 | //if minimal pitch ? |
| 118 | | if (token->reg[1]){ |
| 119 | | switch (token->mode){ |
| 80 | if (m_reg[1]){ |
| 81 | switch (m_mode){ |
| 120 | 82 | //dont play anything |
| 121 | 83 | case 0:break; |
| 122 | 84 | |
| 123 | 85 | //tone only |
| 124 | 86 | case 1: |
| 125 | | *buffer = token->volume * token->tval; |
| 87 | *buffer = m_volume * m_tval; |
| 126 | 88 | break; |
| 127 | 89 | |
| 128 | 90 | //noise only |
| 129 | 91 | case 2: |
| 130 | | *buffer = token->volume * token->nval; |
| 92 | *buffer = m_volume * m_nval; |
| 131 | 93 | break; |
| 132 | 94 | |
| 133 | 95 | //tone AND noise (bitwise and) |
| 134 | 96 | case 3: |
| 135 | | *buffer = token->volume * (token->tval & token->nval); |
| 97 | *buffer = m_volume * (m_tval & m_nval); |
| 136 | 98 | break; |
| 137 | 99 | } |
| 138 | 100 | |
| 139 | 101 | //counter |
| 140 | | token->pos++; |
| 102 | m_pos++; |
| 141 | 103 | |
| 142 | | if (token->pos >= token->size){ |
| 104 | if (m_pos >= m_size){ |
| 143 | 105 | |
| 144 | 106 | //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 |
| 147 | 109 | |
| 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 |
| 150 | 112 | |
| 151 | 113 | //insert new bit at end position (size-1) (only if non null) |
| 152 | 114 | if (newBit) |
| 153 | | token->lfsr |= LFSR_MASK; |
| 115 | m_lfsr |= LFSR_MASK; |
| 154 | 116 | |
| 155 | 117 | //invert tone |
| 156 | | token->tval = !token->tval; |
| 118 | m_tval = !m_tval; |
| 157 | 119 | |
| 158 | | token->pos = 0; |
| 120 | m_pos = 0; |
| 159 | 121 | } |
| 160 | 122 | } |
| 161 | 123 | } |
| r14372 | r14373 | |
| 163 | 125 | |
| 164 | 126 | |
| 165 | 127 | |
| 166 | | /************************************/ |
| 167 | | /* Sound handler start */ |
| 168 | | /************************************/ |
| 128 | //------------------------------------------------- |
| 129 | // soundport_w |
| 130 | //------------------------------------------------- |
| 169 | 131 | |
| 170 | | static DEVICE_START(arcadia_sound) |
| 132 | WRITE8_MEMBER(arcadia_sound_device::write) |
| 171 | 133 | { |
| 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; |
| 178 | 136 | |
| 137 | //logerror("arcadia_sound write:%x=%x\n",offset,data); |
| 179 | 138 | |
| 180 | | |
| 181 | | DEVICE_GET_INFO(arcadia_sound) |
| 182 | | { |
| 183 | | switch (state) |
| 139 | switch (offset) |
| 184 | 140 | { |
| 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); |
| 187 | 146 | |
| 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; |
| 190 | 151 | |
| 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; |
| 194 | 165 | } |
| 195 | 166 | } |
| 196 | | |
| 197 | | DEFINE_LEGACY_SOUND_DEVICE(ARCADIA, arcadia_sound); |
src/mess/audio/arcadia.h
| r0 | r14373 | |
| 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 | |
| 17 | class arcadia_sound_device : public device_t, |
| 18 | public device_sound_interface |
| 19 | { |
| 20 | public: |
| 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); |
| 25 | protected: |
| 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 |
| 39 | extern const device_type ARCADIA_SOUND; |
| 40 | |
| 41 | #endif /* ARCADIA_SOUND_H_ */ |