/* End of frame update, return the number of samples run so far. */ int sound_update(unsigned int cycles) { int size, avail; /* run PSG & FM chips until end of frame */ cycles <<= 11; psg_update(cycles); fm_update(cycles); /* check number of available FM samples */ if (config.hq_fm) { size = Fir_Resampler_avail(); } else { size = (snd.fm.pos - snd.fm.buffer) >> 1; } #ifdef LOGSOUND error("%d FM samples available\n",size); #endif /* check number of available PSG samples */ avail = snd.psg.pos - snd.psg.buffer; #ifdef LOGSOUND error("%d PSG samples available\n", avail); #endif /* resynchronize FM & PSG chips */ if (size > avail) { /* FM chip is ahead */ fm_cycles_count += SN76489_Clocks(size - avail) * psg_cycles_ratio; /* return number of available samples */ size = avail; } else { /* PSG chip is ahead */ psg_cycles_count += SN76489_Clocks(avail - size) * psg_cycles_ratio; } #ifdef LOGSOUND error("%lu PSG cycles run\n",psg_cycles_count); error("%lu FM cycles run \n",fm_cycles_count); #endif /* adjust PSG & FM cycle counts for next frame */ psg_cycles_count -= cycles; fm_cycles_count -= cycles; #ifdef LOGSOUND error("%lu PSG cycles left\n",psg_cycles_count); error("%lu FM cycles left\n",fm_cycles_count); #endif return size; }
void psg_write(unsigned int clocks, unsigned int data) { int index; /* PSG chip synchronization */ if (clocks > psg.clocks) { /* run PSG chip until current timestamp */ psg_update(clocks); /* update internal M-cycles clock counter */ psg.clocks += ((clocks - psg.clocks + PSG_MCYCLES_RATIO - 1) / PSG_MCYCLES_RATIO) * PSG_MCYCLES_RATIO; } if (data & 0x80) { /* latch register index (1xxx----) */ psg.latch = index = (data >> 4) & 0x07; }
/* Write PSG chip */ void psg_write(unsigned int cycles, unsigned int data) { psg_update(cycles << 11); SN76489_Write(data); }