src/mess/audio/wswan.c
| r13406 | r13407 | |
| 57 | 57 | |
| 58 | 58 | static void wswan_ch_set_freq( running_machine &machine, struct CHAN *ch, UINT16 freq ) |
| 59 | 59 | { |
| 60 | freq &= 0x7ff; // docs say freq is 11bits and a few games (Morita Shougi, World Stadium + others) write 0x800 causing a divide by 0 crash |
| 60 | 61 | ch->freq = freq; |
| 61 | | ch->period = machine.sample_rate() / ( 3072000 / ( ( 2048 - freq ) << 5 ) ); |
| 62 | ch->period = machine.sample_rate() / (3072000 / ((2048 - freq) << 5)); |
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | WRITE8_DEVICE_HANDLER( wswan_sound_port_w ) |
| r13406 | r13407 | |
| 69 | 70 | |
| 70 | 71 | switch( offset ) { |
| 71 | 72 | case 0x80: /* Audio 1 freq (lo) */ |
| 72 | | wswan_ch_set_freq( device->machine(), &state->audio1, ( state->audio1.freq & 0xFF00 ) | data ); |
| 73 | wswan_ch_set_freq(device->machine(), &state->audio1, (state->audio1.freq & 0xff00) | data); |
| 73 | 74 | break; |
| 74 | 75 | case 0x81: /* Audio 1 freq (hi) */ |
| 75 | | wswan_ch_set_freq( device->machine(), &state->audio1, ( data << 8 ) | ( state->audio1.freq & 0x00FF ) ); |
| 76 | wswan_ch_set_freq(device->machine(), &state->audio1, (data << 8 ) | (state->audio1.freq & 0x00ff)); |
| 76 | 77 | break; |
| 77 | 78 | case 0x82: /* Audio 2 freq (lo) */ |
| 78 | | wswan_ch_set_freq( device->machine(), &state->audio2, ( state->audio2.freq & 0xFF00 ) | data ); |
| 79 | wswan_ch_set_freq(device->machine(), &state->audio2, (state->audio2.freq & 0xff00) | data); |
| 79 | 80 | break; |
| 80 | 81 | case 0x83: /* Audio 2 freq (hi) */ |
| 81 | | wswan_ch_set_freq( device->machine(), &state->audio2, ( data << 8 ) | ( state->audio2.freq & 0x00FF ) ); |
| 82 | wswan_ch_set_freq(device->machine(), &state->audio2, (data << 8 ) | (state->audio2.freq & 0x00ff)); |
| 82 | 83 | break; |
| 83 | 84 | case 0x84: /* Audio 3 freq (lo) */ |
| 84 | | wswan_ch_set_freq( device->machine(), &state->audio3, ( state->audio3.freq & 0xFF00 ) | data ); |
| 85 | wswan_ch_set_freq(device->machine(), &state->audio3, (state->audio3.freq & 0xff00) | data); |
| 85 | 86 | break; |
| 86 | 87 | case 0x85: /* Audio 3 freq (hi) */ |
| 87 | | wswan_ch_set_freq( device->machine(), &state->audio3, ( data << 8 ) | ( state->audio3.freq & 0x00FF ) ); |
| 88 | wswan_ch_set_freq(device->machine(), &state->audio3, (data << 8) | (state->audio3.freq & 0x00ff)); |
| 88 | 89 | break; |
| 89 | 90 | case 0x86: /* Audio 4 freq (lo) */ |
| 90 | | wswan_ch_set_freq( device->machine(), &state->audio4, ( state->audio4.freq & 0xFF00 ) | data ); |
| 91 | wswan_ch_set_freq(device->machine(), &state->audio4, (state->audio4.freq & 0xff00) | data); |
| 91 | 92 | break; |
| 92 | 93 | case 0x87: /* Audio 4 freq (hi) */ |
| 93 | | wswan_ch_set_freq( device->machine(), &state->audio4, ( data << 8 ) | ( state->audio4.freq & 0x00FF ) ); |
| 94 | wswan_ch_set_freq(device->machine(), &state->audio4, (data << 8) | (state->audio4.freq & 0x00ff)); |
| 94 | 95 | break; |
| 95 | 96 | case 0x88: /* Audio 1 volume */ |
| 96 | 97 | state->audio1.vol_left = ( data & 0xF0 ) >> 4; |
| r13406 | r13407 | |
| 199 | 200 | if ( state->sweep_count >= state->sweep_time ) { |
| 200 | 201 | state->sweep_count = 0; |
| 201 | 202 | state->audio3.freq += state->sweep_step; |
| 202 | | state->audio3.period = device->machine().sample_rate() / ( 3072000 / ( ( 2048 - state->audio3.freq ) << 5 ) ); |
| 203 | state->audio3.period = device->machine().sample_rate() / (3072000 / ((2048 - (state->audio3.freq & 0x7ff)) << 5)); |
| 203 | 204 | } |
| 204 | 205 | } |
| 205 | 206 | left += state->audio3.vol_left * sample; |