mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
32x: preliminary PWM implementation. 32x opts in menu
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@790 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
5e128c6d27
commit
db1d3564e6
16 changed files with 256 additions and 46 deletions
|
@ -135,12 +135,15 @@ static __inline void SekRunM68k(int cyc)
|
|||
|
||||
void PicoFrame32x(void)
|
||||
{
|
||||
pwm_frame_smp_cnt = 0;
|
||||
|
||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
|
||||
if ((Pico32x.vdp_regs[0] & 3 ) != 0) // no forced blanking
|
||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no pal access
|
||||
if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking
|
||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access
|
||||
|
||||
p32x_poll_event(1);
|
||||
|
||||
PicoFrameStart();
|
||||
PicoFrameHints();
|
||||
}
|
||||
|
||||
|
|
|
@ -123,7 +123,6 @@ static void dma_68k2sh2_do(void)
|
|||
Pico32x.regs[6 / 2] &= ~P32XS_68S; // transfer complete
|
||||
if (dmac0->tcr0 == 0)
|
||||
dmac0->chcr0 |= 2; // DMA has ended normally
|
||||
p32x_poll_undetect(&m68k_poll, 0);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
|
@ -137,7 +136,7 @@ static u32 p32x_reg_read16(u32 a)
|
|||
if ((a & 0x30) == 0x20)
|
||||
return sh2_comm_faker(a);
|
||||
#else
|
||||
if (p32x_poll_detect(&m68k_poll, a, SekPc, 0)) {
|
||||
if ((a & 0x30) == 0x20 && p32x_poll_detect(&m68k_poll, a, SekPc, 0)) {
|
||||
SekEndRun(16);
|
||||
}
|
||||
#endif
|
||||
|
@ -146,6 +145,8 @@ static u32 p32x_reg_read16(u32 a)
|
|||
if (a == 0x24 || a == 0x26)
|
||||
return sh2_comm_faker(a);
|
||||
#endif
|
||||
if ((a & 0x30) == 0x30)
|
||||
return p32x_pwm_read16(a);
|
||||
|
||||
return Pico32x.regs[a / 2];
|
||||
}
|
||||
|
@ -196,9 +197,6 @@ static void p32x_reg_write16(u32 a, u32 d)
|
|||
u16 *r = Pico32x.regs;
|
||||
a &= 0x3e;
|
||||
|
||||
// for write loops with FIFO checks..
|
||||
m68k_poll.cnt = 0;
|
||||
|
||||
switch (a) {
|
||||
case 0x00: // adapter ctl
|
||||
r[0] = (r[0] & 0x83) | (d & P32XS_FM);
|
||||
|
@ -234,6 +232,11 @@ static void p32x_reg_write16(u32 a, u32 d)
|
|||
SekEndRun(16);
|
||||
return;
|
||||
}
|
||||
// PWM
|
||||
else if ((a & 0x30) == 0x30) {
|
||||
p32x_pwm_write16(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
p32x_reg_write8(a + 1, d);
|
||||
}
|
||||
|
@ -296,9 +299,19 @@ static u32 p32x_sh2reg_read16(u32 a, int cpuid)
|
|||
return r[a / 2];
|
||||
}
|
||||
|
||||
// DREQ src, dst; comm port
|
||||
if ((a & 0x38) == 0x08 || (a & 0x30) == 0x20)
|
||||
// DREQ src, dst
|
||||
if ((a & 0x38) == 0x08)
|
||||
return r[a / 2];
|
||||
// comm port
|
||||
if ((a & 0x30) == 0x20) {
|
||||
if (p32x_poll_detect(&sh2_poll[cpuid], a, sh2_pc(cpuid), 0))
|
||||
ash2_end_run(8);
|
||||
return r[a / 2];
|
||||
}
|
||||
if ((a & 0x30) == 0x30) {
|
||||
sh2_poll[cpuid].cnt = 0;
|
||||
return p32x_pwm_read16(a);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -316,12 +329,18 @@ static void p32x_sh2reg_write16(u32 a, u32 d, int cpuid)
|
|||
{
|
||||
a &= 0xfe;
|
||||
|
||||
// comm
|
||||
if ((a & 0x30) == 0x20 && Pico32x.regs[a/2] != d) {
|
||||
Pico32x.regs[a / 2] = d;
|
||||
p32x_poll_undetect(&m68k_poll, 0);
|
||||
p32x_poll_undetect(&sh2_poll[cpuid ^ 1], 0);
|
||||
return;
|
||||
}
|
||||
// PWM
|
||||
else if ((a & 0x30) == 0x30) {
|
||||
p32x_pwm_write16(a, d);
|
||||
return;
|
||||
}
|
||||
|
||||
switch (a) {
|
||||
case 0x14: Pico32x.sh2irqs &= ~P32XI_VRES; goto irls;
|
||||
|
@ -561,7 +580,6 @@ static void bank_switch(int b)
|
|||
|
||||
u32 p32x_sh2_read8(u32 a, int id)
|
||||
{
|
||||
int pd_vdp = 0;
|
||||
u32 d = 0;
|
||||
|
||||
if (id == 0 && a < sizeof(Pico32xMem->sh2_rom_m))
|
||||
|
@ -581,13 +599,14 @@ u32 p32x_sh2_read8(u32 a, int id)
|
|||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
d = p32x_sh2reg_read16(a, id);
|
||||
goto out_pd;
|
||||
goto out_16to8;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
d = p32x_vdp_read16(a);
|
||||
pd_vdp = 1;
|
||||
goto out_pd;
|
||||
if (p32x_poll_detect(&sh2_poll[id], a, sh2_pc(id), 1))
|
||||
ash2_end_run(8);
|
||||
goto out_16to8;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4200) {
|
||||
|
@ -599,10 +618,6 @@ u32 p32x_sh2_read8(u32 a, int id)
|
|||
id ? 's' : 'm', a, d, sh2_pc(id));
|
||||
return d;
|
||||
|
||||
out_pd:
|
||||
if (p32x_poll_detect(&sh2_poll[id], a, sh2_pc(id), pd_vdp))
|
||||
ash2_end_run(8);
|
||||
|
||||
out_16to8:
|
||||
if (a & 1)
|
||||
d &= 0xff;
|
||||
|
@ -616,7 +631,6 @@ out_16to8:
|
|||
|
||||
u32 p32x_sh2_read16(u32 a, int id)
|
||||
{
|
||||
int pd_vdp = 0;
|
||||
u32 d = 0;
|
||||
|
||||
if (id == 0 && a < sizeof(Pico32xMem->sh2_rom_m))
|
||||
|
@ -636,13 +650,14 @@ u32 p32x_sh2_read16(u32 a, int id)
|
|||
|
||||
if ((a & 0x0fffff00) == 0x4000) {
|
||||
d = p32x_sh2reg_read16(a, id);
|
||||
goto out_pd;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4100) {
|
||||
d = p32x_vdp_read16(a);
|
||||
pd_vdp = 1;
|
||||
goto out_pd;
|
||||
if (p32x_poll_detect(&sh2_poll[id], a, sh2_pc(id), 1))
|
||||
ash2_end_run(8);
|
||||
goto out;
|
||||
}
|
||||
|
||||
if ((a & 0x0fffff00) == 0x4200) {
|
||||
|
@ -654,10 +669,6 @@ u32 p32x_sh2_read16(u32 a, int id)
|
|||
id ? 's' : 'm', a, d, sh2_pc(id));
|
||||
return d;
|
||||
|
||||
out_pd:
|
||||
if (p32x_poll_detect(&sh2_poll[id], a, sh2_pc(id), pd_vdp))
|
||||
ash2_end_run(8);
|
||||
|
||||
out:
|
||||
elprintf(EL_32X, "%csh2 r16 [%08x] %04x @%06x",
|
||||
id ? 's' : 'm', a, d, sh2_pc(id));
|
||||
|
|
144
pico/32x/pwm.c
Normal file
144
pico/32x/pwm.c
Normal file
|
@ -0,0 +1,144 @@
|
|||
#include "../pico_int.h"
|
||||
|
||||
static int pwm_line_samples;
|
||||
static int pwm_cycles;
|
||||
static int pwm_mult;
|
||||
static int pwm_ptr;
|
||||
int pwm_frame_smp_cnt;
|
||||
|
||||
|
||||
void p32x_pwm_refresh(void)
|
||||
{
|
||||
int cycles = Pico32x.regs[0x32 / 2];
|
||||
int frame_samples;
|
||||
|
||||
cycles = (cycles - 1) & 0x0fff;
|
||||
if (cycles < 500) {
|
||||
elprintf(EL_32X|EL_ANOMALY, "pwm: low cycle value: %d", cycles + 1);
|
||||
cycles = 500;
|
||||
}
|
||||
pwm_cycles = cycles;
|
||||
pwm_mult = 0x10000 / cycles;
|
||||
if (Pico.m.pal)
|
||||
frame_samples = OSC_PAL / 7 * 3 / 50 / cycles;
|
||||
else
|
||||
frame_samples = OSC_NTSC / 7 * 3 / 60 / cycles;
|
||||
|
||||
pwm_line_samples = (frame_samples << 16) / scanlines_total;
|
||||
}
|
||||
|
||||
// irq for every sample??
|
||||
// FIXME: we need to hit more than once per line :(
|
||||
void p32x_pwm_irq_check(void)
|
||||
{
|
||||
int tm = (Pico32x.regs[0x30 / 2] & 0x0f00) >> 8;
|
||||
if (tm == 0)
|
||||
return; // TODO: verify
|
||||
|
||||
Pico32x.pwm_irq_sample_cnt += pwm_line_samples;
|
||||
if (Pico32x.pwm_irq_sample_cnt >= (tm << 16)) {
|
||||
Pico32x.pwm_irq_sample_cnt -= tm << 16;
|
||||
Pico32x.sh2irqs |= P32XI_PWM;
|
||||
p32x_update_irls();
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int p32x_pwm_read16(unsigned int a)
|
||||
{
|
||||
unsigned int d = 0;
|
||||
int predict;
|
||||
|
||||
a &= 0x0e;
|
||||
switch (a) {
|
||||
case 0: // control
|
||||
case 2: // cycle
|
||||
return Pico32x.regs[(0x30 + a) / 2];
|
||||
|
||||
case 4: // L ch
|
||||
case 6: // R ch
|
||||
case 8: // MONO
|
||||
predict = (pwm_line_samples * Pico.m.scanline) >> 16;
|
||||
elprintf(EL_32X, "pwm: read status: ptr %d/%d, predict %d",
|
||||
pwm_frame_smp_cnt, (pwm_line_samples * scanlines_total) >> 16, predict);
|
||||
if (pwm_frame_smp_cnt > predict + 3)
|
||||
d |= P32XP_FULL;
|
||||
else if (pwm_frame_smp_cnt == 0 || pwm_frame_smp_cnt < predict - 1)
|
||||
d |= P32XP_EMPTY;
|
||||
break;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void p32x_pwm_write16(unsigned int a, unsigned int d)
|
||||
{
|
||||
a &= 0x0e;
|
||||
if (a == 0) // control
|
||||
Pico32x.regs[0x30 / 2] = d;
|
||||
else if (a == 2) { // cycle
|
||||
Pico32x.regs[0x32 / 2] = d & 0x0fff;
|
||||
p32x_pwm_refresh();
|
||||
Pico32x.pwm_irq_sample_cnt = 0; // resets?
|
||||
}
|
||||
else if (a <= 8) {
|
||||
d &= 0x0fff;
|
||||
if (d > pwm_cycles)
|
||||
d = pwm_cycles;
|
||||
d = (d - pwm_cycles / 2) * pwm_mult;
|
||||
|
||||
if (a < 6) // L ch
|
||||
Pico32xMem->pwm[pwm_ptr * 2] = d;
|
||||
else if (a == 6) // R ch
|
||||
Pico32xMem->pwm[pwm_ptr * 2 + 1] = d;
|
||||
else // MONO
|
||||
Pico32xMem->pwm[pwm_ptr * 2] = Pico32xMem->pwm[pwm_ptr * 2 + 1] = d;
|
||||
|
||||
if (a >= 6) { // R or MONO
|
||||
pwm_frame_smp_cnt++;
|
||||
pwm_ptr = (pwm_ptr + 1) & (PWM_BUFF_LEN - 1);
|
||||
elprintf(EL_32X, "pwm: smp_cnt %d, ptr %d, smp %x", pwm_frame_smp_cnt, pwm_ptr, d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void p32x_pwm_update(int *buf32, int length, int stereo)
|
||||
{
|
||||
extern int pwm_ptr;
|
||||
short *pwmb;
|
||||
int step;
|
||||
int p = 0;
|
||||
|
||||
if (pwm_ptr <= 16) // at least some samples..
|
||||
return;
|
||||
|
||||
step = (pwm_ptr << 16) / length; // FIXME: division..
|
||||
pwmb = Pico32xMem->pwm;
|
||||
|
||||
if (stereo)
|
||||
{
|
||||
while (length-- > 0) {
|
||||
*buf32++ += pwmb[0];
|
||||
*buf32++ += pwmb[1];
|
||||
|
||||
p += step;
|
||||
pwmb += (p >> 16) * 2;
|
||||
p &= 0xffff;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (length-- > 0) {
|
||||
*buf32++ += pwmb[0];
|
||||
|
||||
p += step;
|
||||
pwmb += (p >> 16) * 2;
|
||||
p &= 0xffff;
|
||||
}
|
||||
}
|
||||
|
||||
elprintf(EL_STATUS, "pwm_update: pwm_ptr %d, len %d, step %04x, done %d",
|
||||
pwm_ptr, length, step, (pwmb - Pico32xMem->pwm) / 2);
|
||||
|
||||
pwm_ptr = 0;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue