mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
clean up dac code a bit
This commit is contained in:
parent
e23f4494fb
commit
4f2cdbf551
7 changed files with 62 additions and 81 deletions
26
pico/debug.c
26
pico/debug.c
|
@ -366,31 +366,31 @@ void PDebugZ80Frame(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
z80_resetCycles();
|
z80_resetCycles();
|
||||||
emustatus &= ~1;
|
PsndStartFrame();
|
||||||
|
|
||||||
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
||||||
PicoSyncZ80(line_sample*488);
|
PicoSyncZ80(SekCycleCnt + line_sample * 488);
|
||||||
if (ym2612.dacen && PsndDacLine <= line_sample)
|
|
||||||
PsndDoDAC(line_sample);
|
|
||||||
if (PsndOut)
|
if (PsndOut)
|
||||||
PsndGetSamples(line_sample);
|
PsndGetSamples(line_sample);
|
||||||
|
|
||||||
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
|
if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
|
||||||
PicoSyncZ80(224*488);
|
PicoSyncZ80(SekCycleCnt + 224 * 488);
|
||||||
z80_int();
|
z80_int();
|
||||||
}
|
}
|
||||||
if (ym2612.dacen && PsndDacLine <= 224)
|
|
||||||
PsndDoDAC(224);
|
|
||||||
if (PsndOut)
|
if (PsndOut)
|
||||||
PsndGetSamples(224);
|
PsndGetSamples(224);
|
||||||
|
|
||||||
// sync z80
|
// sync z80
|
||||||
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
if (/*Pico.m.z80Run &&*/ !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80)) {
|
||||||
PicoSyncZ80(Pico.m.pal ? 151809 : 127671); // cycles adjusted for converter
|
SekCycleCnt += Pico.m.pal ? 151809 : 127671; // cycles adjusted for converter
|
||||||
if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)
|
PicoSyncZ80(SekCycleCnt);
|
||||||
PsndDoDAC(lines-1);
|
}
|
||||||
|
if (PsndOut && ym2612.dacen && PsndDacLine < lines)
|
||||||
|
PsndDoDAC(lines - 1);
|
||||||
|
PsndDoPSG(lines - 1);
|
||||||
|
|
||||||
timers_cycle();
|
timers_cycle();
|
||||||
|
SekCycleAim = SekCycleCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PDebugCPUStep(void)
|
void PDebugCPUStep(void)
|
||||||
|
|
|
@ -932,7 +932,7 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
|
||||||
int scanline = get_scanline(is_from_z80);
|
int scanline = get_scanline(is_from_z80);
|
||||||
//elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", PsndDacLine, scanline, d, is_from_z80);
|
//elprintf(EL_STATUS, "%03i -> %03i dac w %08x z80 %i", PsndDacLine, scanline, d, is_from_z80);
|
||||||
ym2612.dacout = ((int)d - 0x80) << 6;
|
ym2612.dacout = ((int)d - 0x80) << 6;
|
||||||
if (PsndOut && ym2612.dacen && scanline >= PsndDacLine)
|
if (ym2612.dacen)
|
||||||
PsndDoDAC(scanline);
|
PsndDoDAC(scanline);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1016,8 +1016,10 @@ static int ym2612_write_local(u32 a, u32 d, int is_from_z80)
|
||||||
}
|
}
|
||||||
case 0x2b: { /* DAC Sel (YM2612) */
|
case 0x2b: { /* DAC Sel (YM2612) */
|
||||||
int scanline = get_scanline(is_from_z80);
|
int scanline = get_scanline(is_from_z80);
|
||||||
ym2612.dacen = d & 0x80;
|
if (ym2612.dacen != (d & 0x80)) {
|
||||||
if (d & 0x80) PsndDacLine = scanline;
|
ym2612.dacen = d & 0x80;
|
||||||
|
PsndDacLine = scanline;
|
||||||
|
}
|
||||||
#ifdef __GP2X__
|
#ifdef __GP2X__
|
||||||
if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, scanline);
|
if (PicoOpt & POPT_EXT_FM) YM2612Write_940(a, d, scanline);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -85,8 +85,7 @@ static int PicoFrameHints(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
z80_resetCycles();
|
z80_resetCycles();
|
||||||
PsndDacLine = 0;
|
PsndStartFrame();
|
||||||
emustatus &= ~1;
|
|
||||||
|
|
||||||
pv->status&=~0x88; // clear V-Int, come out of vblank
|
pv->status&=~0x88; // clear V-Int, come out of vblank
|
||||||
|
|
||||||
|
@ -145,8 +144,6 @@ static int PicoFrameHints(void)
|
||||||
|
|
||||||
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
||||||
PicoSyncZ80(cycles);
|
PicoSyncZ80(cycles);
|
||||||
if (ym2612.dacen && PsndDacLine <= y)
|
|
||||||
PsndDoDAC(y);
|
|
||||||
#ifdef PICO_CD
|
#ifdef PICO_CD
|
||||||
if (PicoAHW & PAHW_MCD)
|
if (PicoAHW & PAHW_MCD)
|
||||||
pcd_sync_s68k(cycles, 0);
|
pcd_sync_s68k(cycles, 0);
|
||||||
|
@ -230,11 +227,7 @@ static int PicoFrameHints(void)
|
||||||
|
|
||||||
// get samples from sound chips
|
// get samples from sound chips
|
||||||
if (y == 224 && PsndOut)
|
if (y == 224 && PsndOut)
|
||||||
{
|
|
||||||
if (ym2612.dacen && PsndDacLine <= y)
|
|
||||||
PsndDoDAC(y);
|
|
||||||
PsndGetSamples(y);
|
PsndGetSamples(y);
|
||||||
}
|
|
||||||
|
|
||||||
// Run scanline:
|
// Run scanline:
|
||||||
CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
|
CPUS_RUN(CYCLES_M68K_LINE - CYCLES_M68K_VINT_LAG - CYCLES_M68K_ASD);
|
||||||
|
@ -269,8 +262,8 @@ static int PicoFrameHints(void)
|
||||||
cycles = SekCyclesDone();
|
cycles = SekCyclesDone();
|
||||||
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
if (Pico.m.z80Run && !Pico.m.z80_reset && (PicoOpt&POPT_EN_Z80))
|
||||||
PicoSyncZ80(cycles);
|
PicoSyncZ80(cycles);
|
||||||
if (PsndOut && ym2612.dacen && PsndDacLine <= lines-1)
|
if (PsndOut && ym2612.dacen && PsndDacLine < lines)
|
||||||
PsndDoDAC(lines-1);
|
PsndDoDAC(lines - 1);
|
||||||
|
|
||||||
#ifdef PICO_CD
|
#ifdef PICO_CD
|
||||||
if (PicoAHW & PAHW_MCD)
|
if (PicoAHW & PAHW_MCD)
|
||||||
|
|
|
@ -820,6 +820,7 @@ PICO_INTERNAL_ASM void wram_1M_to_2M(unsigned char *m);
|
||||||
|
|
||||||
// sound/sound.c
|
// sound/sound.c
|
||||||
PICO_INTERNAL void PsndReset(void);
|
PICO_INTERNAL void PsndReset(void);
|
||||||
|
PICO_INTERNAL void PsndStartFrame(void);
|
||||||
PICO_INTERNAL void PsndDoDAC(int line_to);
|
PICO_INTERNAL void PsndDoDAC(int line_to);
|
||||||
PICO_INTERNAL void PsndClear(void);
|
PICO_INTERNAL void PsndClear(void);
|
||||||
PICO_INTERNAL void PsndGetSamples(int y);
|
PICO_INTERNAL void PsndGetSamples(int y);
|
||||||
|
|
|
@ -258,6 +258,8 @@ void PicoFrameMS(void)
|
||||||
int nmi;
|
int nmi;
|
||||||
int y;
|
int y;
|
||||||
|
|
||||||
|
PsndStartFrame();
|
||||||
|
|
||||||
nmi = (PicoPad[0] >> 7) & 1;
|
nmi = (PicoPad[0] >> 7) & 1;
|
||||||
if (!Pico.ms.nmi_state && nmi)
|
if (!Pico.ms.nmi_state && nmi)
|
||||||
z80_nmi();
|
z80_nmi();
|
||||||
|
|
|
@ -14,15 +14,13 @@
|
||||||
#include "../cd/cue.h"
|
#include "../cd/cue.h"
|
||||||
#include "mix.h"
|
#include "mix.h"
|
||||||
|
|
||||||
#define SIMPLE_WRITE_SOUND 0
|
|
||||||
|
|
||||||
void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo;
|
void (*PsndMix_32_to_16l)(short *dest, int *src, int count) = mix_32_to_16l_stereo;
|
||||||
|
|
||||||
// master int buffer to mix to
|
// master int buffer to mix to
|
||||||
static int PsndBuffer[2*(44100+100)/50];
|
static int PsndBuffer[2*(44100+100)/50];
|
||||||
|
|
||||||
// dac
|
// dac
|
||||||
static unsigned short dac_info[312+4]; // pppppppp ppppllll, p - pos in buff, l - length to write for this sample
|
static unsigned short dac_info[312+4]; // pos in sample buffer
|
||||||
|
|
||||||
// cdda output buffer
|
// cdda output buffer
|
||||||
short cdda_out_buffer[2*1152];
|
short cdda_out_buffer[2*1152];
|
||||||
|
@ -34,6 +32,7 @@ int PsndLen_exc_add=0; // this is for non-integer sample counts per line, eg. 22
|
||||||
int PsndLen_exc_cnt=0;
|
int PsndLen_exc_cnt=0;
|
||||||
int PsndDacLine=0;
|
int PsndDacLine=0;
|
||||||
short *PsndOut=NULL; // PCM data buffer
|
short *PsndOut=NULL; // PCM data buffer
|
||||||
|
static int PsndLen_use;
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
int timer_a_next_oflow, timer_a_step; // in z80 cycles
|
int timer_a_next_oflow, timer_a_step; // in z80 cycles
|
||||||
|
@ -57,14 +56,12 @@ static void dac_recalculate(void)
|
||||||
for(i=226; i != 225; i++)
|
for(i=226; i != 225; i++)
|
||||||
{
|
{
|
||||||
if (i >= lines) i = 0;
|
if (i >= lines) i = 0;
|
||||||
len = 0;
|
|
||||||
if(dac_cnt < 0) {
|
if(dac_cnt < 0) {
|
||||||
len=1;
|
|
||||||
pos++;
|
pos++;
|
||||||
dac_cnt += lines;
|
dac_cnt += lines;
|
||||||
}
|
}
|
||||||
dac_cnt -= PsndLen;
|
dac_cnt -= PsndLen;
|
||||||
dac_info[i] = (pos<<4)|len;
|
dac_info[i] = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -86,24 +83,12 @@ static void dac_recalculate(void)
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
dac_cnt += PsndLen;
|
dac_cnt += PsndLen;
|
||||||
dac_info[i] = (pos<<4)|len;
|
pos += len;
|
||||||
pos+=len;
|
dac_info[i] = pos;
|
||||||
}
|
}
|
||||||
// last sample
|
|
||||||
for(len = 0, i = pos; i < PsndLen; i++) len++;
|
|
||||||
if (PsndLen_exc_add) len++;
|
|
||||||
dac_info[224] = (pos<<4)|len;
|
|
||||||
}
|
}
|
||||||
mid = (dac_info[lines-1] & 0xfff0) + ((dac_info[lines-1] & 0xf) << 4);
|
|
||||||
for (i = lines; i < sizeof(dac_info) / sizeof(dac_info[0]); i++)
|
for (i = lines; i < sizeof(dac_info) / sizeof(dac_info[0]); i++)
|
||||||
dac_info[i] = mid;
|
dac_info[i] = dac_info[0];
|
||||||
//for(i=len=0; i < lines; i++) {
|
|
||||||
// printf("%03i : %03i : %i\n", i, dac_info[i]>>4, dac_info[i]&0xf);
|
|
||||||
// len+=dac_info[i]&0xf;
|
|
||||||
//}
|
|
||||||
//printf("rate is %i, len %f\n", PsndRate, (double)PsndRate/(Pico.m.pal ? 50.0 : 60.0));
|
|
||||||
//printf("len total: %i, last pos: %i\n", len, pos);
|
|
||||||
//exit(8);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,6 +148,21 @@ void PsndRerate(int preserve_state)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
PICO_INTERNAL void PsndStartFrame(void)
|
||||||
|
{
|
||||||
|
// compensate for float part of PsndLen
|
||||||
|
PsndLen_use = PsndLen;
|
||||||
|
PsndLen_exc_cnt += PsndLen_exc_add;
|
||||||
|
if (PsndLen_exc_cnt >= 0x10000) {
|
||||||
|
PsndLen_exc_cnt -= 0x10000;
|
||||||
|
PsndLen_use++;
|
||||||
|
}
|
||||||
|
|
||||||
|
PsndDacLine = 0;
|
||||||
|
emustatus &= ~1;
|
||||||
|
dac_info[224] = PsndLen_use;
|
||||||
|
}
|
||||||
|
|
||||||
PICO_INTERNAL void PsndDoDAC(int line_to)
|
PICO_INTERNAL void PsndDoDAC(int line_to)
|
||||||
{
|
{
|
||||||
int pos, pos1, len;
|
int pos, pos1, len;
|
||||||
|
@ -172,12 +172,16 @@ PICO_INTERNAL void PsndDoDAC(int line_to)
|
||||||
if (line_to >= 312)
|
if (line_to >= 312)
|
||||||
line_to = 311;
|
line_to = 311;
|
||||||
|
|
||||||
|
pos = dac_info[line_from];
|
||||||
|
pos1 = dac_info[line_to + 1];
|
||||||
|
len = pos1 - pos;
|
||||||
|
if (len <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
PsndDacLine = line_to + 1;
|
PsndDacLine = line_to + 1;
|
||||||
|
|
||||||
pos =dac_info[line_from]>>4;
|
if (!PsndOut)
|
||||||
pos1=dac_info[line_to];
|
return;
|
||||||
len = ((pos1>>4)-pos) + (pos1&0xf);
|
|
||||||
if (!len) return;
|
|
||||||
|
|
||||||
if (PicoOpt & POPT_EN_STEREO) {
|
if (PicoOpt & POPT_EN_STEREO) {
|
||||||
short *d = PsndOut + pos*2;
|
short *d = PsndOut + pos*2;
|
||||||
|
@ -260,17 +264,6 @@ static int PsndRender(int offset, int length)
|
||||||
|
|
||||||
pprof_start(sound);
|
pprof_start(sound);
|
||||||
|
|
||||||
#if !SIMPLE_WRITE_SOUND
|
|
||||||
if (offset == 0) { // should happen once per frame
|
|
||||||
// compensate for float part of PsndLen
|
|
||||||
PsndLen_exc_cnt += PsndLen_exc_add;
|
|
||||||
if (PsndLen_exc_cnt >= 0x10000) {
|
|
||||||
PsndLen_exc_cnt -= 0x10000;
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// PSG
|
// PSG
|
||||||
if (PicoOpt & POPT_EN_PSG)
|
if (PicoOpt & POPT_EN_PSG)
|
||||||
SN76496Update(PsndOut+offset, length, stereo);
|
SN76496Update(PsndOut+offset, length, stereo);
|
||||||
|
@ -322,20 +315,16 @@ static int PsndRender(int offset, int length)
|
||||||
// to be called on 224 or line_sample scanlines only
|
// to be called on 224 or line_sample scanlines only
|
||||||
PICO_INTERNAL void PsndGetSamples(int y)
|
PICO_INTERNAL void PsndGetSamples(int y)
|
||||||
{
|
{
|
||||||
#if SIMPLE_WRITE_SOUND
|
|
||||||
if (y != 224) return;
|
|
||||||
PsndRender(0, PsndLen);
|
|
||||||
if (PicoWriteSound)
|
|
||||||
PicoWriteSound(PsndLen * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2));
|
|
||||||
PsndClear();
|
|
||||||
#else
|
|
||||||
static int curr_pos = 0;
|
static int curr_pos = 0;
|
||||||
|
|
||||||
|
if (ym2612.dacen && PsndDacLine < y)
|
||||||
|
PsndDoDAC(y - 1);
|
||||||
|
|
||||||
if (y == 224)
|
if (y == 224)
|
||||||
{
|
{
|
||||||
if (emustatus & 2)
|
if (emustatus & 2)
|
||||||
curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2);
|
curr_pos += PsndRender(curr_pos, PsndLen-PsndLen/2);
|
||||||
else curr_pos = PsndRender(0, PsndLen);
|
else curr_pos = PsndRender(0, PsndLen_use);
|
||||||
if (emustatus & 1)
|
if (emustatus & 1)
|
||||||
emustatus |= 2;
|
emustatus |= 2;
|
||||||
else emustatus &= ~2;
|
else emustatus &= ~2;
|
||||||
|
@ -343,28 +332,20 @@ PICO_INTERNAL void PsndGetSamples(int y)
|
||||||
PicoWriteSound(curr_pos * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2));
|
PicoWriteSound(curr_pos * ((PicoOpt & POPT_EN_STEREO) ? 4 : 2));
|
||||||
// clear sound buffer
|
// clear sound buffer
|
||||||
PsndClear();
|
PsndClear();
|
||||||
|
PsndDacLine = 224;
|
||||||
|
dac_info[224] = 0;
|
||||||
}
|
}
|
||||||
else if (emustatus & 3) {
|
else if (emustatus & 3) {
|
||||||
emustatus|= 2;
|
emustatus|= 2;
|
||||||
emustatus&=~1;
|
emustatus&=~1;
|
||||||
curr_pos = PsndRender(0, PsndLen/2);
|
curr_pos = PsndRender(0, PsndLen/2);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PICO_INTERNAL void PsndGetSamplesMS(void)
|
PICO_INTERNAL void PsndGetSamplesMS(void)
|
||||||
{
|
{
|
||||||
int stereo = (PicoOpt & 8) >> 3;
|
int stereo = (PicoOpt & 8) >> 3;
|
||||||
int length = PsndLen;
|
int length = PsndLen_use;
|
||||||
|
|
||||||
#if !SIMPLE_WRITE_SOUND
|
|
||||||
// compensate for float part of PsndLen
|
|
||||||
PsndLen_exc_cnt += PsndLen_exc_add;
|
|
||||||
if (PsndLen_exc_cnt >= 0x10000) {
|
|
||||||
PsndLen_exc_cnt -= 0x10000;
|
|
||||||
length++;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// PSG
|
// PSG
|
||||||
if (PicoOpt & POPT_EN_PSG)
|
if (PicoOpt & POPT_EN_PSG)
|
||||||
|
@ -382,3 +363,4 @@ PICO_INTERNAL void PsndGetSamplesMS(void)
|
||||||
PsndClear();
|
PsndClear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vim:shiftwidth=2:ts=2:expandtab
|
||||||
|
|
|
@ -1679,6 +1679,7 @@ void YM2612ResetChip_(void)
|
||||||
for(i = 0x26 ; i >= 0x20 ; i-- ) OPNWriteReg(i,0);
|
for(i = 0x26 ; i >= 0x20 ; i-- ) OPNWriteReg(i,0);
|
||||||
/* DAC mode clear */
|
/* DAC mode clear */
|
||||||
ym2612.dacen = 0;
|
ym2612.dacen = 0;
|
||||||
|
ym2612.dacout = 0;
|
||||||
ym2612.addr_A1 = 0;
|
ym2612.addr_A1 = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue