}\r
}\r
\r
-static int get_scanline(int is_from_z80);\r
-\r
static void psg_write_68k(u32 d)\r
{\r
// look for volume write and update if needed\r
if ((d & 0x90) == 0x90)\r
- PsndDoPSG(Pico.m.scanline);\r
+ PsndDoPSG(z80_cycles_from_68k());\r
\r
SN76496Write(d);\r
}\r
static void psg_write_z80(u32 d)\r
{\r
if ((d & 0x90) == 0x90) {\r
- int scanline = get_scanline(1);\r
- PsndDoPSG(scanline);\r
+ PsndDoPSG(z80_cyclesDone());\r
}\r
\r
SN76496Write(d);\r
PICO_INTERNAL void PsndReset(void);\r
PICO_INTERNAL void PsndStartFrame(void);\r
PICO_INTERNAL void PsndDoDAC(int cycle_to);\r
-PICO_INTERNAL void PsndDoPSG(int line_to);\r
-PICO_INTERNAL void PsndDoYM2413(int line_to);\r
-PICO_INTERNAL void PsndDoFM(int line_to);\r
+PICO_INTERNAL void PsndDoPSG(int cyc_to);\r
+PICO_INTERNAL void PsndDoYM2413(int cyc_to);\r
+PICO_INTERNAL void PsndDoFM(int cyc_to);\r
PICO_INTERNAL void PsndClear(void);\r
PICO_INTERNAL void PsndGetSamples(int y);\r
PICO_INTERNAL void PsndGetSamplesMS(int y);\r
Pico.snd.dac_val = dout;\r
}\r
\r
-PICO_INTERNAL void PsndDoPSG(int line_to)\r
+PICO_INTERNAL void PsndDoPSG(int cyc_to)\r
{\r
int pos, len;\r
int stereo = 0;\r
\r
- // Q16, number of samples since last call\r
- len = ((line_to+1) * Pico.snd.smpl_mult) - Pico.snd.psg_pos;\r
- if (len <= 0)\r
- return;\r
+ // number of samples to fill in buffer (Q20)\r
+ len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.psg_pos;\r
\r
// update position and calculate buffer offset and length\r
- pos = (Pico.snd.psg_pos+0x8000) >> 16;\r
+ pos = (Pico.snd.psg_pos+0x80000) >> 20;\r
Pico.snd.psg_pos += len;\r
- len = ((Pico.snd.psg_pos+0x8000) >> 16) - pos;\r
+ len = ((Pico.snd.psg_pos+0x80000) >> 20) - pos;\r
+\r
+ // avoid loss of the 1st sample of a new block (Q rounding issues)\r
+ if (pos+len == 0)\r
+ len = 1, Pico.snd.psg_pos += 0x80000;\r
+ if (len <= 0)\r
+ return;\r
\r
if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_PSG))\r
return;\r
}\r
\r
#if 0\r
-PICO_INTERNAL void PsndDoYM2413(int line_to)\r
+PICO_INTERNAL void PsndDoYM2413(int cyc_to)\r
{\r
int pos, len;\r
int stereo = 0;\r
short *buf;\r
\r
- // Q16, number of samples since last call\r
- len = ((line_to+1) * Pico.snd.smpl_mult) - Pico.snd.ym2413_pos;\r
- if (len <= 0)\r
- return;\r
+ // number of samples to fill in buffer (Q20)\r
+ len = (cyc_to * Pico.snd.clkl_mult) - Pico.snd.ym2413_pos;\r
\r
// update position and calculate buffer offset and length\r
- pos = (Pico.snd.ym2413_pos+0x8000) >> 16;\r
+ pos = (Pico.snd.ym2413_pos+0x80000) >> 20;\r
Pico.snd.ym2413_pos += len;\r
- len = ((Pico.snd.ym2413_pos+0x8000) >> 16) - pos;\r
+ len = ((Pico.snd.ym2413_pos+0x80000) >> 20) - pos;\r
+\r
+ // avoid loss of the 1st sample of a new block (Q rounding issues)\r
+ if (pos+len == 0)\r
+ len = 1, Pico.snd.ym2413_pos += 0x80000;\r
+ if (len <= 0)\r
+ return;\r
\r
if (!PicoIn.sndOut || !(PicoIn.opt & POPT_EN_YM2413))\r
return;\r