mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
32x: improve pwm a bit more
This commit is contained in:
parent
1ac97cbbf2
commit
8ad1d2adf2
1 changed files with 32 additions and 22 deletions
|
@ -11,6 +11,7 @@ static int pwm_cycles;
|
||||||
static int pwm_mult;
|
static int pwm_mult;
|
||||||
static int pwm_ptr;
|
static int pwm_ptr;
|
||||||
static int pwm_irq_reload;
|
static int pwm_irq_reload;
|
||||||
|
static int pwm_doing_fifo;
|
||||||
|
|
||||||
void p32x_pwm_ctl_changed(void)
|
void p32x_pwm_ctl_changed(void)
|
||||||
{
|
{
|
||||||
|
@ -49,21 +50,15 @@ static void do_pwm_irq(SH2 *sh2, unsigned int m68k_cycles)
|
||||||
static void consume_fifo_do(SH2 *sh2, unsigned int m68k_cycles,
|
static void consume_fifo_do(SH2 *sh2, unsigned int m68k_cycles,
|
||||||
int sh2_cycles_diff)
|
int sh2_cycles_diff)
|
||||||
{
|
{
|
||||||
int do_irq = 0;
|
if (pwm_cycles == 0 || pwm_doing_fifo)
|
||||||
|
|
||||||
if (pwm_cycles == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
elprintf(EL_PWM, "pwm: %u: consume %d/%d, %d,%d ptr %d",
|
elprintf(EL_PWM, "pwm: %u: consume %d/%d, %d,%d ptr %d",
|
||||||
m68k_cycles, sh2_cycles_diff, sh2_cycles_diff / pwm_cycles,
|
m68k_cycles, sh2_cycles_diff, sh2_cycles_diff / pwm_cycles,
|
||||||
Pico32x.pwm_p[0], Pico32x.pwm_p[1], pwm_ptr);
|
Pico32x.pwm_p[0], Pico32x.pwm_p[1], pwm_ptr);
|
||||||
|
|
||||||
if (sh2_cycles_diff >= pwm_cycles * 17) {
|
// this is for recursion from dreq1 writes
|
||||||
// silence/skip
|
pwm_doing_fifo = 1;
|
||||||
Pico32x.pwm_cycle_p = m68k_cycles * 3;
|
|
||||||
Pico32x.pwm_p[0] = Pico32x.pwm_p[1] = 0;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (sh2_cycles_diff >= pwm_cycles) {
|
while (sh2_cycles_diff >= pwm_cycles) {
|
||||||
struct Pico32xMem *mem = Pico32xMem;
|
struct Pico32xMem *mem = Pico32xMem;
|
||||||
|
@ -91,15 +86,11 @@ static void consume_fifo_do(SH2 *sh2, unsigned int m68k_cycles,
|
||||||
|
|
||||||
if (--Pico32x.pwm_irq_cnt == 0) {
|
if (--Pico32x.pwm_irq_cnt == 0) {
|
||||||
Pico32x.pwm_irq_cnt = pwm_irq_reload;
|
Pico32x.pwm_irq_cnt = pwm_irq_reload;
|
||||||
// irq also does dreq1, so call it after cycle update
|
do_pwm_irq(sh2, m68k_cycles);
|
||||||
do_irq = 1;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Pico32x.pwm_cycle_p = m68k_cycles * 3 - sh2_cycles_diff;
|
Pico32x.pwm_cycle_p = m68k_cycles * 3 - sh2_cycles_diff;
|
||||||
|
pwm_doing_fifo = 0;
|
||||||
if (do_irq)
|
|
||||||
do_pwm_irq(sh2, m68k_cycles);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int p32x_pwm_schedule_(SH2 *sh2, unsigned int m68k_now)
|
static int p32x_pwm_schedule_(SH2 *sh2, unsigned int m68k_now)
|
||||||
|
@ -234,16 +225,29 @@ void p32x_pwm_update(int *buf32, int length, int stereo)
|
||||||
int p = 0;
|
int p = 0;
|
||||||
int xmd;
|
int xmd;
|
||||||
|
|
||||||
xmd = Pico32x.regs[0x30 / 2] & 0x0f;
|
consume_fifo(NULL, SekCyclesDoneT2());
|
||||||
if ((xmd != 0x05 && xmd != 0x0a) || pwm_ptr <= 16)
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
step = (pwm_ptr << 16) / length; // FIXME: division..
|
xmd = Pico32x.regs[0x30 / 2] & 0x0f;
|
||||||
|
if (xmd == 0 || xmd == 0x06 || xmd == 0x09 || xmd == 0x0f)
|
||||||
|
goto out; // invalid?
|
||||||
|
|
||||||
|
step = (pwm_ptr << 16) / length;
|
||||||
pwmb = Pico32xMem->pwm;
|
pwmb = Pico32xMem->pwm;
|
||||||
|
|
||||||
if (stereo)
|
if (stereo)
|
||||||
{
|
{
|
||||||
if (xmd == 0x0a) {
|
if (xmd == 0x05) {
|
||||||
|
// normal
|
||||||
|
while (length-- > 0) {
|
||||||
|
*buf32++ += pwmb[0];
|
||||||
|
*buf32++ += pwmb[1];
|
||||||
|
|
||||||
|
p += step;
|
||||||
|
pwmb += (p >> 16) * 2;
|
||||||
|
p &= 0xffff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (xmd == 0x0a) {
|
||||||
// channel swap
|
// channel swap
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
*buf32++ += pwmb[1];
|
*buf32++ += pwmb[1];
|
||||||
|
@ -255,18 +259,24 @@ void p32x_pwm_update(int *buf32, int length, int stereo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
// mono - LMD, RMD specify dst
|
||||||
|
if (xmd & 0x06) // src is R
|
||||||
|
pwmb++;
|
||||||
|
if (xmd & 0x0c) // dst is R
|
||||||
|
buf32++;
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
*buf32++ += pwmb[0];
|
*buf32 += *pwmb;
|
||||||
*buf32++ += pwmb[1];
|
|
||||||
|
|
||||||
p += step;
|
p += step;
|
||||||
pwmb += (p >> 16) * 2;
|
pwmb += (p >> 16) * 2;
|
||||||
p &= 0xffff;
|
p &= 0xffff;
|
||||||
|
buf32 += 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// mostly unused
|
||||||
while (length-- > 0) {
|
while (length-- > 0) {
|
||||||
*buf32++ += pwmb[0];
|
*buf32++ += pwmb[0];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue