36
36
#include "maincpu.h"
38
39
#include "sid-resources.h"
41
42
#include "vic20sound.h"
45
/* ---------------------------------------------------------------------*/
47
/* Some prototypes are needed */
48
static int vic_sound_machine_init(sound_t *psid, int speed, int cycles_per_sec);
49
static int vic_sound_machine_calculate_samples(sound_t **psid, SWORD *pbuf, int nr, int sound_output_channels, int sound_chip_channels, int *delta_t);
50
static void vic_sound_machine_store(sound_t *psid, WORD addr, BYTE value);
51
static BYTE vic_sound_machine_read(sound_t *psid, WORD addr);
53
static int vic_sound_machine_cycle_based(void)
58
static int vic_sound_machine_channels(void)
63
static sound_chip_t vic_sound_chip = {
65
vic_sound_machine_init,
67
vic_sound_machine_calculate_samples,
68
vic_sound_machine_store,
69
vic_sound_machine_read,
71
vic_sound_machine_cycle_based,
72
vic_sound_machine_channels,
76
static WORD vic_sound_chip_offset = 0;
78
void vic_sound_chip_init(void)
80
vic_sound_chip_offset = sound_chip_register(&vic_sound_chip);
83
/* ---------------------------------------------------------------------*/
44
85
static BYTE noisepattern[1024] = {
45
86
7, 30, 30, 28, 28, 62, 60, 56,120,248,124, 30, 31,143, 7, 7,193,192,224,
46
87
241,224,240,227,225,192,224,120,126, 60, 56,224,225,195,195,135,199, 7, 30,
194
241
void vic_sound_clock(int cycles);
196
static int vic_sound_machine_calculate_samples(sound_t *psid, SWORD *pbuf, int nr,
197
int interleave, int *delta_t)
243
static int vic_sound_machine_calculate_samples(sound_t **psid, SWORD *pbuf, int nr, int soc, int scc, int *delta_t)
201
251
while (s < nr && *delta_t >= snd.cycles_per_sample - snd.leftover_cycles) {
204
int samples_to_do = snd.cycles_per_sample;
206
if (snd.leftover_cycles) {
207
samples_to_do -= snd.leftover_cycles;
208
snd.leftover_cycles = 0;
252
samples_to_do = (int)(snd.cycles_per_sample - snd.leftover_cycles);
253
snd.leftover_cycles += samples_to_do - snd.cycles_per_sample;
210
254
vic_sound_clock(samples_to_do);
212
o = voltagefunction[(((snd.accum*7)/snd.accum_cycles) + 1) * snd.volume];
213
o = snd.lowpassbuf*snd.lowpassbeta + o*(1.0f-snd.lowpassbeta); /* 0.75f + o*0.25f; */
256
o = voltagefunction[(((snd.accum * 7) / snd.accum_cycles) + 1) * snd.volume];
257
o = snd.lowpassbuf * snd.lowpassbeta + o * (1.0f - snd.lowpassbeta); /* 0.75f + o*0.25f; */
215
259
o -= snd.highpassbuf;
216
260
snd.highpassbuf += o * snd.highpassbeta;
365
sound_t *sound_machine_open(int chipno)
367
return sid_sound_machine_open(chipno);
370
int sound_machine_init(sound_t *psid, int speed, int cycles_per_sec)
372
vic_sound_machine_init(psid, speed, cycles_per_sec);
374
if (!sidcart_clock && cycles_per_sec == VIC20_PAL_CYCLES_PER_SEC) {
375
return sid_sound_machine_init(psid, (int)(speed*1.125), cycles_per_sec);
377
return sid_sound_machine_init(psid, speed, cycles_per_sec);
381
void sound_machine_close(sound_t *psid)
383
sid_sound_machine_close(psid);
386
/* for read/store 0x00 <= addr <= 0x1f is the sid
387
* 0x20 <= addr <= 0x3f is the vic
389
* future sound devices will be able to use 0x40 and up
392
BYTE sound_machine_read(sound_t *psid, WORD addr)
394
if (addr >= 0x20 && addr <= 0x3f) {
395
return vic_sound_machine_read(psid, (WORD)(addr-0x20));
397
return sid_sound_machine_read(psid, addr);
401
void sound_machine_store(sound_t *psid, WORD addr, BYTE byte)
403
if (addr >= 0x20 && addr <= 0x3f) {
404
vic_sound_machine_store(psid, (WORD)(addr-0x20), byte);
406
sid_sound_machine_store(psid, addr, byte);
410
void sound_machine_reset(sound_t *psid, CLOCK cpu_clk)
412
sid_sound_machine_reset(psid, cpu_clk);
415
int sound_machine_calculate_samples(sound_t *psid, SWORD *pbuf, int nr,
416
int interleave, int *delta_t)
420
temp = vic_sound_machine_calculate_samples(psid, pbuf, nr, interleave, delta_t);
421
return fastsid_calculate_samples_mix(psid, pbuf, temp, interleave, delta_t);
424
412
void sound_machine_prevent_clk_overflow(sound_t *psid, CLOCK sub)
426
414
sid_sound_machine_prevent_clk_overflow(psid, sub);
431
419
return sid_sound_machine_dump_state(psid);
434
int sound_machine_cycle_based(void)
439
int sound_machine_channels(void)
441
return sid_sound_machine_channels();
444
422
void sound_machine_enable(int enable)
446
424
sid_sound_machine_enable(enable);