mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-06 23:58:04 -04:00
Merge branch 'dev'
This commit is contained in:
commit
9a1f192a14
89 changed files with 3226 additions and 4002 deletions
149
pico/32x/32x.c
149
pico/32x/32x.c
|
@ -17,12 +17,12 @@ SH2 sh2s[2];
|
|||
static int REGPARM(2) sh2_irq_cb(SH2 *sh2, int level)
|
||||
{
|
||||
if (sh2->pending_irl > sh2->pending_int_irq) {
|
||||
elprintf(EL_32X, "%csh2 ack/irl %d @ %08x",
|
||||
sh2->is_slave ? 's' : 'm', level, sh2->pc);
|
||||
elprintf_sh2(sh2, EL_32X, "ack/irl %d @ %08x",
|
||||
level, sh2_pc(sh2));
|
||||
return 64 + sh2->pending_irl / 2;
|
||||
} else {
|
||||
elprintf(EL_32X, "%csh2 ack/int %d/%d @ %08x",
|
||||
sh2->is_slave ? 's' : 'm', level, sh2->pending_int_vector, sh2->pc);
|
||||
elprintf_sh2(sh2, EL_32X, "ack/int %d/%d @ %08x",
|
||||
level, sh2->pending_int_vector, sh2_pc(sh2));
|
||||
sh2->pending_int_irq = 0; // auto-clear
|
||||
sh2->pending_level = sh2->pending_irl;
|
||||
return sh2->pending_int_vector;
|
||||
|
@ -39,13 +39,13 @@ void p32x_update_irls(SH2 *active_sh2, int m68k_cycles)
|
|||
m68k_cycles = sh2_cycles_done_m68k(active_sh2);
|
||||
|
||||
// msh2
|
||||
irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[0]) & ((Pico32x.sh2irq_mask[0] << 3) | P32XI_VRES);
|
||||
irqs = Pico32x.sh2irqs | Pico32x.sh2irqi[0];
|
||||
while ((irqs >>= 1))
|
||||
mlvl++;
|
||||
mlvl *= 2;
|
||||
|
||||
// ssh2
|
||||
irqs = (Pico32x.sh2irqs | Pico32x.sh2irqi[1]) & ((Pico32x.sh2irq_mask[1] << 3) | P32XI_VRES);
|
||||
irqs = Pico32x.sh2irqs | Pico32x.sh2irqi[1];
|
||||
while ((irqs >>= 1))
|
||||
slvl++;
|
||||
slvl *= 2;
|
||||
|
@ -67,6 +67,33 @@ void p32x_update_irls(SH2 *active_sh2, int m68k_cycles)
|
|||
elprintf(EL_32X, "update_irls: m %d/%d, s %d/%d", mlvl, mrun, slvl, srun);
|
||||
}
|
||||
|
||||
// the mask register is inconsistent, CMD is supposed to be a mask,
|
||||
// while others are actually irq trigger enables?
|
||||
// TODO: test on hw..
|
||||
void p32x_trigger_irq(SH2 *sh2, int m68k_cycles, unsigned int mask)
|
||||
{
|
||||
Pico32x.sh2irqs |= mask & P32XI_VRES;
|
||||
Pico32x.sh2irqi[0] |= mask & (Pico32x.sh2irq_mask[0] << 3);
|
||||
Pico32x.sh2irqi[1] |= mask & (Pico32x.sh2irq_mask[1] << 3);
|
||||
|
||||
p32x_update_irls(sh2, m68k_cycles);
|
||||
}
|
||||
|
||||
void p32x_update_cmd_irq(SH2 *sh2, int m68k_cycles)
|
||||
{
|
||||
if ((Pico32x.sh2irq_mask[0] & 2) && (Pico32x.regs[2 / 2] & 1))
|
||||
Pico32x.sh2irqi[0] |= P32XI_CMD;
|
||||
else
|
||||
Pico32x.sh2irqi[0] &= ~P32XI_CMD;
|
||||
|
||||
if ((Pico32x.sh2irq_mask[1] & 2) && (Pico32x.regs[2 / 2] & 2))
|
||||
Pico32x.sh2irqi[1] |= P32XI_CMD;
|
||||
else
|
||||
Pico32x.sh2irqi[1] &= ~P32XI_CMD;
|
||||
|
||||
p32x_update_irls(sh2, m68k_cycles);
|
||||
}
|
||||
|
||||
void Pico32xStartup(void)
|
||||
{
|
||||
elprintf(EL_STATUS|EL_32X, "32X startup");
|
||||
|
@ -85,9 +112,6 @@ void Pico32xStartup(void)
|
|||
if (!Pico.m.pal)
|
||||
Pico32x.vdp_regs[0] |= P32XV_nPAL;
|
||||
|
||||
PREG8(msh2.peri_regs, 4) =
|
||||
PREG8(ssh2.peri_regs, 4) = 0x84; // SCI SSR
|
||||
|
||||
rendstatus_old = -1;
|
||||
|
||||
emu_32x_startup();
|
||||
|
@ -100,6 +124,8 @@ void p32x_reset_sh2s(void)
|
|||
|
||||
sh2_reset(&msh2);
|
||||
sh2_reset(&ssh2);
|
||||
sh2_peripheral_reset(&msh2);
|
||||
sh2_peripheral_reset(&ssh2);
|
||||
|
||||
// if we don't have BIOS set, perform it's work here.
|
||||
// MSH2
|
||||
|
@ -140,7 +166,7 @@ void p32x_reset_sh2s(void)
|
|||
// program will set S_OK
|
||||
}
|
||||
|
||||
msh2.m68krcycles_done = ssh2.m68krcycles_done = SekCyclesDoneT();
|
||||
msh2.m68krcycles_done = ssh2.m68krcycles_done = SekCyclesDone();
|
||||
}
|
||||
|
||||
void Pico32xInit(void)
|
||||
|
@ -156,7 +182,7 @@ void PicoPower32x(void)
|
|||
memset(&Pico32x, 0, sizeof(Pico32x));
|
||||
|
||||
Pico32x.regs[0] = P32XS_REN|P32XS_nRES; // verified
|
||||
Pico32x.vdp_regs[0x0a/2] = P32XV_VBLK|P32XV_HBLK|P32XV_PEN;
|
||||
Pico32x.vdp_regs[0x0a/2] = P32XV_VBLK|P32XV_PEN;
|
||||
Pico32x.sh2_regs[0] = P32XS2_ADEN;
|
||||
}
|
||||
|
||||
|
@ -174,8 +200,8 @@ void PicoUnload32x(void)
|
|||
void PicoReset32x(void)
|
||||
{
|
||||
if (PicoAHW & PAHW_32X) {
|
||||
Pico32x.sh2irqs |= P32XI_VRES;
|
||||
p32x_update_irls(NULL, SekCyclesDoneT2());
|
||||
msh2.m68krcycles_done = ssh2.m68krcycles_done = SekCyclesDone();
|
||||
p32x_trigger_irq(NULL, SekCyclesDone(), P32XI_VRES);
|
||||
p32x_sh2_poll_event(&msh2, SH2_IDLE_STATES, 0);
|
||||
p32x_sh2_poll_event(&ssh2, SH2_IDLE_STATES, 0);
|
||||
p32x_pwm_ctl_changed();
|
||||
|
@ -222,19 +248,29 @@ static void p32x_start_blank(void)
|
|||
Pico32xSwapDRAM(Pico32x.pending_fb ^ 1);
|
||||
}
|
||||
|
||||
Pico32x.sh2irqs |= P32XI_VINT;
|
||||
p32x_update_irls(NULL, SekCyclesDoneT2());
|
||||
p32x_trigger_irq(NULL, SekCyclesDone(), P32XI_VINT);
|
||||
p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, 0);
|
||||
p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, 0);
|
||||
}
|
||||
|
||||
// compare cycles, handling overflows
|
||||
// check if a > b
|
||||
#define CYCLES_GT(a, b) \
|
||||
((int)((a) - (b)) > 0)
|
||||
// check if a >= b
|
||||
#define CYCLES_GE(a, b) \
|
||||
((int)((a) - (b)) >= 0)
|
||||
void p32x_schedule_hint(SH2 *sh2, int m68k_cycles)
|
||||
{
|
||||
// rather rough, 32x hint is useless in practice
|
||||
int after;
|
||||
|
||||
if (!((Pico32x.sh2irq_mask[0] | Pico32x.sh2irq_mask[1]) & 4))
|
||||
return; // nobody cares
|
||||
// note: when Pico.m.scanline is 224, SH2s might
|
||||
// still be at scanline 93 (or so)
|
||||
if (!(Pico32x.sh2_regs[0] & 0x80) && Pico.m.scanline > 224)
|
||||
return;
|
||||
|
||||
after = (Pico32x.sh2_regs[4 / 2] + 1) * 488;
|
||||
if (sh2 != NULL)
|
||||
p32x_event_schedule_sh2(sh2, P32X_EVENT_HINT, after);
|
||||
else
|
||||
p32x_event_schedule(m68k_cycles, P32X_EVENT_HINT, after);
|
||||
}
|
||||
|
||||
/* events */
|
||||
static void fillend_event(unsigned int now)
|
||||
|
@ -244,13 +280,21 @@ static void fillend_event(unsigned int now)
|
|||
p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, now);
|
||||
}
|
||||
|
||||
static void hint_event(unsigned int now)
|
||||
{
|
||||
p32x_trigger_irq(NULL, now, P32XI_HINT);
|
||||
p32x_schedule_hint(NULL, now);
|
||||
}
|
||||
|
||||
typedef void (event_cb)(unsigned int now);
|
||||
|
||||
unsigned int event_times[P32X_EVENT_COUNT];
|
||||
/* times are in m68k (7.6MHz) cycles */
|
||||
unsigned int p32x_event_times[P32X_EVENT_COUNT];
|
||||
static unsigned int event_time_next;
|
||||
static event_cb *event_cbs[] = {
|
||||
static event_cb *p32x_event_cbs[P32X_EVENT_COUNT] = {
|
||||
[P32X_EVENT_PWM] = p32x_pwm_irq_event,
|
||||
[P32X_EVENT_FILLEND] = fillend_event,
|
||||
[P32X_EVENT_HINT] = hint_event,
|
||||
};
|
||||
|
||||
// schedule event at some time 'after', in m68k clocks
|
||||
|
@ -260,8 +304,8 @@ void p32x_event_schedule(unsigned int now, enum p32x_event event, int after)
|
|||
|
||||
when = (now + after) | 1;
|
||||
|
||||
elprintf(EL_32X, "new event #%u %u->%u", event, now, when);
|
||||
event_times[event] = when;
|
||||
elprintf(EL_32X, "32x: new event #%u %u->%u", event, now, when);
|
||||
p32x_event_times[event] = when;
|
||||
|
||||
if (event_time_next == 0 || CYCLES_GT(event_time_next, when))
|
||||
event_time_next = when;
|
||||
|
@ -278,7 +322,7 @@ void p32x_event_schedule_sh2(SH2 *sh2, enum p32x_event event, int after)
|
|||
sh2_end_run(sh2, left_to_next);
|
||||
}
|
||||
|
||||
static void run_events(unsigned int until)
|
||||
static void p32x_run_events(unsigned int until)
|
||||
{
|
||||
int oldest, oldest_diff, time;
|
||||
int i, diff;
|
||||
|
@ -287,8 +331,8 @@ static void run_events(unsigned int until)
|
|||
oldest = -1, oldest_diff = 0x7fffffff;
|
||||
|
||||
for (i = 0; i < P32X_EVENT_COUNT; i++) {
|
||||
if (event_times[i]) {
|
||||
diff = event_times[i] - until;
|
||||
if (p32x_event_times[i]) {
|
||||
diff = p32x_event_times[i] - until;
|
||||
if (diff < oldest_diff) {
|
||||
oldest_diff = diff;
|
||||
oldest = i;
|
||||
|
@ -297,13 +341,13 @@ static void run_events(unsigned int until)
|
|||
}
|
||||
|
||||
if (oldest_diff <= 0) {
|
||||
time = event_times[oldest];
|
||||
event_times[oldest] = 0;
|
||||
elprintf(EL_32X, "run event #%d %u", oldest, time);
|
||||
event_cbs[oldest](time);
|
||||
time = p32x_event_times[oldest];
|
||||
p32x_event_times[oldest] = 0;
|
||||
elprintf(EL_32X, "32x: run event #%d %u", oldest, time);
|
||||
p32x_event_cbs[oldest](time);
|
||||
}
|
||||
else if (oldest_diff < 0x7fffffff) {
|
||||
event_time_next = event_times[oldest];
|
||||
event_time_next = p32x_event_times[oldest];
|
||||
break;
|
||||
}
|
||||
else {
|
||||
|
@ -313,7 +357,8 @@ static void run_events(unsigned int until)
|
|||
}
|
||||
|
||||
if (oldest != -1)
|
||||
elprintf(EL_32X, "next event #%d at %u", oldest, event_time_next);
|
||||
elprintf(EL_32X, "32x: next event #%d at %u",
|
||||
oldest, event_time_next);
|
||||
}
|
||||
|
||||
static inline void run_sh2(SH2 *sh2, int m68k_cycles)
|
||||
|
@ -323,16 +368,16 @@ static inline void run_sh2(SH2 *sh2, int m68k_cycles)
|
|||
pevt_log_sh2_o(sh2, EVT_RUN_START);
|
||||
sh2->state |= SH2_STATE_RUN;
|
||||
cycles = C_M68K_TO_SH2(*sh2, m68k_cycles);
|
||||
elprintf(EL_32X, "%csh2 +run %u %d",
|
||||
sh2->is_slave?'s':'m', sh2->m68krcycles_done, cycles);
|
||||
elprintf_sh2(sh2, EL_32X, "+run %u %d @%08x",
|
||||
sh2->m68krcycles_done, cycles, sh2->pc);
|
||||
|
||||
done = sh2_execute(sh2, cycles);
|
||||
done = sh2_execute(sh2, cycles, PicoOpt & POPT_EN_DRC);
|
||||
|
||||
sh2->m68krcycles_done += C_SH2_TO_M68K(*sh2, done);
|
||||
sh2->state &= ~SH2_STATE_RUN;
|
||||
pevt_log_sh2_o(sh2, EVT_RUN_END);
|
||||
elprintf(EL_32X, "%csh2 -run %u %d",
|
||||
sh2->is_slave?'s':'m', sh2->m68krcycles_done, done);
|
||||
elprintf_sh2(sh2, EL_32X, "-run %u %d",
|
||||
sh2->m68krcycles_done, done);
|
||||
}
|
||||
|
||||
// sync other sh2 to this one
|
||||
|
@ -355,8 +400,8 @@ void p32x_sync_other_sh2(SH2 *sh2, unsigned int m68k_target)
|
|||
return;
|
||||
}
|
||||
|
||||
elprintf(EL_32X, "%csh2 sync to %u %d",
|
||||
osh2->is_slave?'s':'m', m68k_target, m68k_cycles);
|
||||
elprintf_sh2(osh2, EL_32X, "sync to %u %d",
|
||||
m68k_target, m68k_cycles);
|
||||
|
||||
run_sh2(osh2, m68k_cycles);
|
||||
|
||||
|
@ -396,7 +441,7 @@ void sync_sh2s_normal(unsigned int m68k_target)
|
|||
while (CYCLES_GT(m68k_target, now))
|
||||
{
|
||||
if (event_time_next && CYCLES_GE(now, event_time_next))
|
||||
run_events(now);
|
||||
p32x_run_events(now);
|
||||
|
||||
target = m68k_target;
|
||||
if (event_time_next && CYCLES_GT(target, event_time_next))
|
||||
|
@ -470,10 +515,13 @@ void sync_sh2s_lockstep(unsigned int m68k_target)
|
|||
}
|
||||
}
|
||||
|
||||
#define CPUS_RUN(m68k_cycles,s68k_cycles) do { \
|
||||
#define CPUS_RUN(m68k_cycles) do { \
|
||||
SekRunM68k(m68k_cycles); \
|
||||
if ((Pico32x.emu_flags & P32XF_Z80_32X_IO) && Pico.m.z80Run \
|
||||
&& !Pico.m.z80_reset && (PicoOpt & POPT_EN_Z80)) \
|
||||
PicoSyncZ80(SekCyclesDone()); \
|
||||
if (Pico32x.emu_flags & (P32XF_68KCPOLL|P32XF_68KVPOLL)) \
|
||||
p32x_sync_sh2s(SekCyclesDoneT2()); \
|
||||
p32x_sync_sh2s(SekCyclesDone()); \
|
||||
} while (0)
|
||||
|
||||
#define PICO_32X
|
||||
|
@ -481,10 +529,14 @@ void sync_sh2s_lockstep(unsigned int m68k_target)
|
|||
|
||||
void PicoFrame32x(void)
|
||||
{
|
||||
Pico.m.scanline = 0;
|
||||
|
||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_VBLK; // get out of vblank
|
||||
if ((Pico32x.vdp_regs[0] & P32XV_Mx) != 0) // no forced blanking
|
||||
Pico32x.vdp_regs[0x0a/2] &= ~P32XV_PEN; // no palette access
|
||||
|
||||
if (!(Pico32x.sh2_regs[0] & 0x80))
|
||||
p32x_schedule_hint(NULL, SekCyclesDone());
|
||||
p32x_sh2_poll_event(&msh2, SH2_STATE_VPOLL, 0);
|
||||
p32x_sh2_poll_event(&ssh2, SH2_STATE_VPOLL, 0);
|
||||
|
||||
|
@ -519,11 +571,10 @@ void Pico32xStateLoaded(int is_early)
|
|||
return;
|
||||
}
|
||||
|
||||
SekCycleCnt = 0;
|
||||
sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCycleCntT;
|
||||
p32x_update_irls(NULL, SekCycleCntT);
|
||||
sh2s[0].m68krcycles_done = sh2s[1].m68krcycles_done = SekCyclesDone();
|
||||
p32x_update_irls(NULL, SekCyclesDone());
|
||||
p32x_pwm_state_loaded();
|
||||
run_events(SekCycleCntT);
|
||||
p32x_run_events(SekCyclesDone());
|
||||
}
|
||||
|
||||
// vim:shiftwidth=2:ts=2:expandtab
|
||||
|
|
|
@ -43,7 +43,7 @@ static void convert_pal555(int invert_prio)
|
|||
\
|
||||
for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
|
||||
unsigned short t = *p32x; \
|
||||
if (*pmd != mdbg && !((t ^ inv) & 0x8000)) { \
|
||||
if ((*pmd & 0x3f) != mdbg && !((t ^ inv) & 0x8000)) { \
|
||||
pmd_draw_code; \
|
||||
continue; \
|
||||
} \
|
||||
|
@ -59,7 +59,7 @@ static void convert_pal555(int invert_prio)
|
|||
int i; \
|
||||
for (i = 320; i > 0; i--, pd++, p32x++, pmd++) { \
|
||||
t = pal[*(unsigned char *)((long)p32x ^ 1)]; \
|
||||
if ((t & 0x20) || *pmd == mdbg) \
|
||||
if ((t & 0x20) || (*pmd & 0x3f) == mdbg) \
|
||||
*pd = t; \
|
||||
else \
|
||||
pmd_draw_code; \
|
||||
|
@ -74,7 +74,7 @@ static void convert_pal555(int invert_prio)
|
|||
for (i = 320; i > 0; p32x++) { \
|
||||
t = pal[*p32x & 0xff]; \
|
||||
for (len = (*p32x >> 8) + 1; len > 0 && i > 0; len--, i--, pd++, pmd++) { \
|
||||
if (*pmd == mdbg || (t & 0x20)) \
|
||||
if ((*pmd & 0x3f) == mdbg || (t & 0x20)) \
|
||||
*pd = t; \
|
||||
else \
|
||||
pmd_draw_code; \
|
||||
|
|
|
@ -77,6 +77,7 @@ Pico32xNativePal:
|
|||
ldr r9, =HighPal @ palmd
|
||||
and r4, r2, #0xff
|
||||
mov r5, #328
|
||||
lsl r3, #26 @ mdbg << 26
|
||||
mla r11,r4,r5,r11 @ r11 = pmd = PicoDraw2FB + offs*328: md data
|
||||
tst r10,#P32XV_PRI
|
||||
moveq r10,#0
|
||||
|
@ -107,7 +108,7 @@ Pico32xNativePal:
|
|||
subs r6, r6, #1
|
||||
blt 0b @ loop_outer
|
||||
ldrh r8, [r5], #2 @ 32x pixel
|
||||
cmp r7, r3 @ MD has bg pixel?
|
||||
cmp r3, r7, lsl #26 @ MD has bg pixel?
|
||||
beq 3f @ draw32x
|
||||
eor r12,r8, r10
|
||||
ands r12,r12,#0x8000 @ !((t ^ inv) & 0x8000)
|
||||
|
@ -145,6 +146,7 @@ Pico32xNativePal:
|
|||
ldr r9, =HighPal @ palmd
|
||||
and r4, r2, #0xff
|
||||
mov r5, #328
|
||||
lsl r3, #26 @ mdbg << 26
|
||||
mla r11,r4,r5,r11 @ r11 = pmd = PicoDraw2FB + offs*328: md data
|
||||
call_scan_prep \call_scan
|
||||
|
||||
|
@ -191,14 +193,14 @@ Pico32xNativePal:
|
|||
tst r12,#0x20
|
||||
ldrneb r12,[r11,#-2] @ MD pixel 0
|
||||
eor lr, r8, #0x20
|
||||
cmpne r12,r3 @ MD has bg pixel?
|
||||
cmpne r3, r12, lsl #26 @ MD has bg pixel?
|
||||
.if \do_md
|
||||
mov r12,r12,lsl #1
|
||||
ldrneh r7, [r9, r12] @ t = palmd[pmd[0]]
|
||||
tst lr, #0x20
|
||||
ldrneb lr, [r11,#-1] @ MD pixel 1
|
||||
strh r7, [r0], #2
|
||||
cmpne lr, r3 @ MD has bg pixel?
|
||||
cmpne r3, lr, lsl #26 @ MD has bg pixel?
|
||||
mov lr, lr, lsl #1
|
||||
ldrneh r8, [r9, lr] @ t = palmd[pmd[1]]
|
||||
strh r8, [r0], #2
|
||||
|
@ -207,7 +209,7 @@ Pico32xNativePal:
|
|||
tst lr, #0x20
|
||||
ldrneb lr, [r11,#-1] @ MD pixel 1
|
||||
add r0, r0, #4
|
||||
cmpne lr, r3 @ MD has bg pixel?
|
||||
cmpne r3, lr, lsl #26 @ MD has bg pixel?
|
||||
streqh r8, [r0, #-2]
|
||||
.endif
|
||||
b 2b @ loop_inner
|
||||
|
@ -265,12 +267,12 @@ Pico32xNativePal:
|
|||
9: @ bg_mode:
|
||||
ldrb r12,[r11],#1 @ MD pixel
|
||||
ldrb lr, [r11],#1
|
||||
cmp r12,r3 @ MD has bg pixel?
|
||||
cmp r3, lr, lsl #26 @ MD has bg pixel?
|
||||
.if \do_md
|
||||
mov r12,r12,lsl #1
|
||||
ldrneh r12,[r9, r12] @ t = palmd[*pmd]
|
||||
moveq r12,r7
|
||||
cmp lr, r3
|
||||
cmp r3, lr, lsl #26
|
||||
mov lr, lr, lsl #1
|
||||
ldrneh lr, [r9, lr]
|
||||
moveq lr, r7
|
||||
|
@ -278,7 +280,7 @@ Pico32xNativePal:
|
|||
strh lr, [r0], #2
|
||||
.else
|
||||
streqh r7, [r0]
|
||||
cmp lr, r3
|
||||
cmp r3, lr, lsl #26
|
||||
streqh r7, [r0, #2]
|
||||
add r0, r0, #4
|
||||
.endif
|
||||
|
@ -302,6 +304,7 @@ Pico32xNativePal:
|
|||
ldr r9, =HighPal @ palmd
|
||||
and r4, r2, #0xff
|
||||
mov r5, #328
|
||||
lsl r3, #26 @ mdbg << 26
|
||||
mla r11,r4,r5,r11 @ r11 = pmd = PicoDraw2FB + offs*328: md data
|
||||
call_scan_prep \call_scan
|
||||
|
||||
|
@ -335,7 +338,7 @@ Pico32xNativePal:
|
|||
ldrb r7, [r11], #1 @ MD pixel
|
||||
subs r6, r6, #1
|
||||
blt 0b @ loop_outer
|
||||
cmp r7, r3 @ MD has bg pixel?
|
||||
cmp r3, r7, lsl #26 @ MD has bg pixel?
|
||||
mov r7, r7, lsl #1
|
||||
tstne lr, #0x20
|
||||
.if \do_md
|
||||
|
|
File diff suppressed because it is too large
Load diff
126
pico/32x/pwm.c
126
pico/32x/pwm.c
|
@ -11,6 +11,8 @@ static int pwm_cycles;
|
|||
static int pwm_mult;
|
||||
static int pwm_ptr;
|
||||
static int pwm_irq_reload;
|
||||
static int pwm_doing_fifo;
|
||||
static int pwm_silent;
|
||||
|
||||
void p32x_pwm_ctl_changed(void)
|
||||
{
|
||||
|
@ -19,7 +21,12 @@ void p32x_pwm_ctl_changed(void)
|
|||
|
||||
cycles = (cycles - 1) & 0x0fff;
|
||||
pwm_cycles = cycles;
|
||||
pwm_mult = 0x10000 / cycles;
|
||||
|
||||
// supposedly we should stop FIFO when xMd is 0,
|
||||
// but mars test disagrees
|
||||
pwm_mult = 0;
|
||||
if ((control & 0x0f) != 0)
|
||||
pwm_mult = 0x10000 / cycles;
|
||||
|
||||
pwm_irq_reload = (control & 0x0f00) >> 8;
|
||||
pwm_irq_reload = ((pwm_irq_reload - 1) & 0x0f) + 1;
|
||||
|
@ -30,8 +37,7 @@ void p32x_pwm_ctl_changed(void)
|
|||
|
||||
static void do_pwm_irq(SH2 *sh2, unsigned int m68k_cycles)
|
||||
{
|
||||
Pico32x.sh2irqs |= P32XI_PWM;
|
||||
p32x_update_irls(sh2, m68k_cycles);
|
||||
p32x_trigger_irq(sh2, m68k_cycles, P32XI_PWM);
|
||||
|
||||
if (Pico32x.regs[0x30 / 2] & P32XP_RTP) {
|
||||
p32x_event_schedule(m68k_cycles, P32X_EVENT_PWM, pwm_cycles / 3 + 1);
|
||||
|
@ -40,6 +46,15 @@ static void do_pwm_irq(SH2 *sh2, unsigned int m68k_cycles)
|
|||
}
|
||||
}
|
||||
|
||||
static int convert_sample(unsigned int v)
|
||||
{
|
||||
if (v == 0)
|
||||
return 0;
|
||||
if (v > pwm_cycles)
|
||||
v = pwm_cycles;
|
||||
return ((int)v - pwm_cycles / 2) * pwm_mult;
|
||||
}
|
||||
|
||||
#define consume_fifo(sh2, m68k_cycles) { \
|
||||
int cycles_diff = ((m68k_cycles) * 3) - Pico32x.pwm_cycle_p; \
|
||||
if (cycles_diff >= pwm_cycles) \
|
||||
|
@ -49,57 +64,53 @@ static void do_pwm_irq(SH2 *sh2, unsigned int m68k_cycles)
|
|||
static void consume_fifo_do(SH2 *sh2, unsigned int m68k_cycles,
|
||||
int sh2_cycles_diff)
|
||||
{
|
||||
int do_irq = 0;
|
||||
struct Pico32xMem *mem = Pico32xMem;
|
||||
unsigned short *fifo_l = mem->pwm_fifo[0];
|
||||
unsigned short *fifo_r = mem->pwm_fifo[1];
|
||||
int sum = 0;
|
||||
|
||||
if (pwm_cycles == 0)
|
||||
if (pwm_cycles == 0 || pwm_doing_fifo)
|
||||
return;
|
||||
|
||||
elprintf(EL_PWM, "pwm: %u: consume %d/%d, %d,%d ptr %d",
|
||||
m68k_cycles, sh2_cycles_diff, sh2_cycles_diff / pwm_cycles,
|
||||
Pico32x.pwm_p[0], Pico32x.pwm_p[1], pwm_ptr);
|
||||
|
||||
if (sh2_cycles_diff >= pwm_cycles * 17) {
|
||||
// silence/skip
|
||||
Pico32x.pwm_cycle_p = m68k_cycles * 3;
|
||||
Pico32x.pwm_p[0] = Pico32x.pwm_p[1] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
while (sh2_cycles_diff >= pwm_cycles) {
|
||||
struct Pico32xMem *mem = Pico32xMem;
|
||||
short *fifo_l = mem->pwm_fifo[0];
|
||||
short *fifo_r = mem->pwm_fifo[1];
|
||||
// this is for recursion from dreq1 writes
|
||||
pwm_doing_fifo = 1;
|
||||
|
||||
for (; sh2_cycles_diff >= pwm_cycles; sh2_cycles_diff -= pwm_cycles)
|
||||
{
|
||||
if (Pico32x.pwm_p[0] > 0) {
|
||||
fifo_l[0] = fifo_l[1];
|
||||
fifo_l[1] = fifo_l[2];
|
||||
fifo_l[2] = fifo_l[3];
|
||||
Pico32x.pwm_p[0]--;
|
||||
mem->pwm_current[0] = convert_sample(fifo_l[0]);
|
||||
sum += mem->pwm_current[0];
|
||||
}
|
||||
if (Pico32x.pwm_p[1] > 0) {
|
||||
fifo_r[0] = fifo_r[1];
|
||||
fifo_r[1] = fifo_r[2];
|
||||
fifo_r[2] = fifo_r[3];
|
||||
Pico32x.pwm_p[1]--;
|
||||
mem->pwm_current[1] = convert_sample(fifo_r[0]);
|
||||
sum += mem->pwm_current[1];
|
||||
}
|
||||
|
||||
mem->pwm[pwm_ptr * 2 ] = fifo_l[0];
|
||||
mem->pwm[pwm_ptr * 2 + 1] = fifo_r[0];
|
||||
mem->pwm[pwm_ptr * 2 ] = mem->pwm_current[0];
|
||||
mem->pwm[pwm_ptr * 2 + 1] = mem->pwm_current[1];
|
||||
pwm_ptr = (pwm_ptr + 1) & (PWM_BUFF_LEN - 1);
|
||||
|
||||
sh2_cycles_diff -= pwm_cycles;
|
||||
|
||||
if (--Pico32x.pwm_irq_cnt == 0) {
|
||||
Pico32x.pwm_irq_cnt = pwm_irq_reload;
|
||||
// irq also does dreq1, so call it after cycle update
|
||||
do_irq = 1;
|
||||
break;
|
||||
do_pwm_irq(sh2, m68k_cycles);
|
||||
}
|
||||
}
|
||||
Pico32x.pwm_cycle_p = m68k_cycles * 3 - sh2_cycles_diff;
|
||||
|
||||
if (do_irq)
|
||||
do_pwm_irq(sh2, m68k_cycles);
|
||||
pwm_doing_fifo = 0;
|
||||
if (sum != 0)
|
||||
pwm_silent = 0;
|
||||
}
|
||||
|
||||
static int p32x_pwm_schedule_(SH2 *sh2, unsigned int m68k_now)
|
||||
|
@ -114,8 +125,6 @@ static int p32x_pwm_schedule_(SH2 *sh2, unsigned int m68k_now)
|
|||
if (cycles_diff_sh2 >= pwm_cycles)
|
||||
consume_fifo_do(sh2, m68k_now, cycles_diff_sh2);
|
||||
|
||||
if (Pico32x.sh2irqs & P32XI_PWM)
|
||||
return 0; // previous not acked
|
||||
if (!((Pico32x.sh2irq_mask[0] | Pico32x.sh2irq_mask[1]) & 1))
|
||||
return 0; // masked by everyone
|
||||
|
||||
|
@ -138,6 +147,12 @@ void p32x_pwm_schedule_sh2(SH2 *sh2)
|
|||
p32x_event_schedule_sh2(sh2, P32X_EVENT_PWM, after);
|
||||
}
|
||||
|
||||
void p32x_pwm_sync_to_sh2(SH2 *sh2)
|
||||
{
|
||||
int m68k_cycles = sh2_cycles_done_m68k(sh2);
|
||||
consume_fifo(sh2, m68k_cycles);
|
||||
}
|
||||
|
||||
void p32x_pwm_irq_event(unsigned int m68k_now)
|
||||
{
|
||||
p32x_pwm_schedule(m68k_now);
|
||||
|
@ -188,8 +203,9 @@ void p32x_pwm_write16(unsigned int a, unsigned int d,
|
|||
|
||||
a &= 0x0e;
|
||||
if (a == 0) { // control
|
||||
// supposedly we should stop FIFO when xMd is 0,
|
||||
// but mars test disagrees
|
||||
// avoiding pops..
|
||||
if ((Pico32x.regs[0x30 / 2] & 0x0f) == 0)
|
||||
Pico32xMem->pwm_fifo[0][0] = Pico32xMem->pwm_fifo[1][0] = 0;
|
||||
Pico32x.regs[0x30 / 2] = d;
|
||||
p32x_pwm_ctl_changed();
|
||||
Pico32x.pwm_irq_cnt = pwm_irq_reload; // ?
|
||||
|
@ -200,12 +216,9 @@ void p32x_pwm_write16(unsigned int a, unsigned int d,
|
|||
}
|
||||
else if (a <= 8) {
|
||||
d = (d - 1) & 0x0fff;
|
||||
if (d > pwm_cycles)
|
||||
d = pwm_cycles;
|
||||
d = (d - pwm_cycles / 2) * pwm_mult;
|
||||
|
||||
if (a == 4 || a == 8) { // L ch or MONO
|
||||
short *fifo = Pico32xMem->pwm_fifo[0];
|
||||
unsigned short *fifo = Pico32xMem->pwm_fifo[0];
|
||||
if (Pico32x.pwm_p[0] < 3)
|
||||
Pico32x.pwm_p[0]++;
|
||||
else {
|
||||
|
@ -215,7 +228,7 @@ void p32x_pwm_write16(unsigned int a, unsigned int d,
|
|||
fifo[Pico32x.pwm_p[0]] = d;
|
||||
}
|
||||
if (a == 6 || a == 8) { // R ch or MONO
|
||||
short *fifo = Pico32xMem->pwm_fifo[1];
|
||||
unsigned short *fifo = Pico32xMem->pwm_fifo[1];
|
||||
if (Pico32x.pwm_p[1] < 3)
|
||||
Pico32x.pwm_p[1]++;
|
||||
else {
|
||||
|
@ -234,16 +247,31 @@ void p32x_pwm_update(int *buf32, int length, int stereo)
|
|||
int p = 0;
|
||||
int xmd;
|
||||
|
||||
xmd = Pico32x.regs[0x30 / 2] & 0x0f;
|
||||
if ((xmd != 0x05 && xmd != 0x0a) || pwm_ptr <= 16)
|
||||
goto out;
|
||||
consume_fifo(NULL, SekCyclesDone());
|
||||
|
||||
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?
|
||||
if (pwm_silent)
|
||||
return;
|
||||
|
||||
step = (pwm_ptr << 16) / length;
|
||||
pwmb = Pico32xMem->pwm;
|
||||
|
||||
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
|
||||
while (length-- > 0) {
|
||||
*buf32++ += pwmb[1];
|
||||
|
@ -255,18 +283,24 @@ void p32x_pwm_update(int *buf32, int length, int stereo)
|
|||
}
|
||||
}
|
||||
else {
|
||||
// mono - LMD, RMD specify dst
|
||||
if (xmd & 0x06) // src is R
|
||||
pwmb++;
|
||||
if (xmd & 0x0c) // dst is R
|
||||
buf32++;
|
||||
while (length-- > 0) {
|
||||
*buf32++ += pwmb[0];
|
||||
*buf32++ += pwmb[1];
|
||||
*buf32 += *pwmb;
|
||||
|
||||
p += step;
|
||||
pwmb += (p >> 16) * 2;
|
||||
p &= 0xffff;
|
||||
buf32 += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// mostly unused
|
||||
while (length-- > 0) {
|
||||
*buf32++ += pwmb[0];
|
||||
|
||||
|
@ -281,6 +315,8 @@ void p32x_pwm_update(int *buf32, int length, int stereo)
|
|||
|
||||
out:
|
||||
pwm_ptr = 0;
|
||||
pwm_silent = Pico32xMem->pwm_current[0] == 0
|
||||
&& Pico32xMem->pwm_current[1] == 0;
|
||||
}
|
||||
|
||||
void p32x_pwm_state_loaded(void)
|
||||
|
@ -290,11 +326,11 @@ void p32x_pwm_state_loaded(void)
|
|||
p32x_pwm_ctl_changed();
|
||||
|
||||
// for old savestates
|
||||
cycles_diff_sh2 = SekCycleCntT * 3 - Pico32x.pwm_cycle_p;
|
||||
cycles_diff_sh2 = SekCycleCnt * 3 - Pico32x.pwm_cycle_p;
|
||||
if (cycles_diff_sh2 >= pwm_cycles || cycles_diff_sh2 < 0) {
|
||||
Pico32x.pwm_irq_cnt = pwm_irq_reload;
|
||||
Pico32x.pwm_cycle_p = SekCycleCntT * 3;
|
||||
p32x_pwm_schedule(SekCycleCntT);
|
||||
Pico32x.pwm_cycle_p = SekCycleCnt * 3;
|
||||
p32x_pwm_schedule(SekCycleCnt);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ static void dmac_transfer_complete(SH2 *sh2, struct dma_chan *chan)
|
|||
{
|
||||
chan->chcr |= DMA_TE; // DMA has ended normally
|
||||
|
||||
p32x_sh2_poll_event(sh2, SH2_STATE_SLEEP, SekCyclesDoneT());
|
||||
p32x_sh2_poll_event(sh2, SH2_STATE_SLEEP, SekCyclesDone());
|
||||
if (chan->chcr & DMA_IE)
|
||||
dmac_te_irq(sh2, chan);
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ static void dmac_transfer_one(SH2 *sh2, struct dma_chan *chan)
|
|||
// DMA trigger by SH2 register write
|
||||
static void dmac_trigger(SH2 *sh2, struct dma_chan *chan)
|
||||
{
|
||||
elprintf(EL_32XP, "sh2 DMA %08x->%08x, cnt %d, chcr %04x @%06x",
|
||||
elprintf_sh2(sh2, EL_32XP, "DMA %08x->%08x, cnt %d, chcr %04x @%06x",
|
||||
chan->sar, chan->dar, chan->tcr, chan->chcr, sh2->pc);
|
||||
chan->tcr &= 0xffffff;
|
||||
|
||||
|
@ -142,7 +142,7 @@ static void dmac_trigger(SH2 *sh2, struct dma_chan *chan)
|
|||
|
||||
// DREQ0 is only sent after first 4 words are written.
|
||||
// we do multiple of 4 words to avoid messing up alignment
|
||||
if (chan->sar == 0x20004012) {
|
||||
if ((chan->sar & ~0x20000000) == 0x00004012) {
|
||||
if (Pico32x.dmac0_fifo_ptr && (Pico32x.dmac0_fifo_ptr & 3) == 0) {
|
||||
elprintf(EL_32XP, "68k -> sh2 DMA");
|
||||
p32x_dreq0_trigger();
|
||||
|
@ -150,6 +150,10 @@ static void dmac_trigger(SH2 *sh2, struct dma_chan *chan)
|
|||
return;
|
||||
}
|
||||
|
||||
// DREQ1
|
||||
if ((chan->dar & 0xc7fffff0) == 0x00004030)
|
||||
return;
|
||||
|
||||
elprintf(EL_32XP|EL_ANOMALY, "unhandled DMA: "
|
||||
"%08x->%08x, cnt %d, chcr %04x @%06x",
|
||||
chan->sar, chan->dar, chan->tcr, chan->chcr, sh2->pc);
|
||||
|
@ -207,6 +211,16 @@ void p32x_timers_do(unsigned int m68k_slice)
|
|||
}
|
||||
}
|
||||
|
||||
void sh2_peripheral_reset(SH2 *sh2)
|
||||
{
|
||||
memset(sh2->peri_regs, 0, sizeof(sh2->peri_regs)); // ?
|
||||
PREG8(sh2->peri_regs, 0x001) = 0xff; // SCI BRR
|
||||
PREG8(sh2->peri_regs, 0x003) = 0xff; // SCI TDR
|
||||
PREG8(sh2->peri_regs, 0x004) = 0x84; // SCI SSR
|
||||
PREG8(sh2->peri_regs, 0x011) = 0x01; // TIER
|
||||
PREG8(sh2->peri_regs, 0x017) = 0xe0; // TOCR
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// SH2 internal peripheral memhandlers
|
||||
// we keep them in little endian format
|
||||
|
@ -219,8 +233,8 @@ u32 sh2_peripheral_read8(u32 a, SH2 *sh2)
|
|||
a &= 0x1ff;
|
||||
d = PREG8(r, a);
|
||||
|
||||
elprintf(EL_32XP, "%csh2 peri r8 [%08x] %02x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a | ~0x1ff, d, sh2_pc(sh2));
|
||||
elprintf_sh2(sh2, EL_32XP, "peri r8 [%08x] %02x @%06x",
|
||||
a | ~0x1ff, d, sh2_pc(sh2));
|
||||
return d;
|
||||
}
|
||||
|
||||
|
@ -232,8 +246,8 @@ u32 sh2_peripheral_read16(u32 a, SH2 *sh2)
|
|||
a &= 0x1ff;
|
||||
d = r[(a / 2) ^ 1];
|
||||
|
||||
elprintf(EL_32XP, "%csh2 peri r16 [%08x] %04x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a | ~0x1ff, d, sh2_pc(sh2));
|
||||
elprintf_sh2(sh2, EL_32XP, "peri r16 [%08x] %04x @%06x",
|
||||
a | ~0x1ff, d, sh2_pc(sh2));
|
||||
return d;
|
||||
}
|
||||
|
||||
|
@ -243,40 +257,90 @@ u32 sh2_peripheral_read32(u32 a, SH2 *sh2)
|
|||
a &= 0x1fc;
|
||||
d = sh2->peri_regs[a / 4];
|
||||
|
||||
elprintf(EL_32XP, "%csh2 peri r32 [%08x] %08x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a | ~0x1ff, d, sh2_pc(sh2));
|
||||
elprintf_sh2(sh2, EL_32XP, "peri r32 [%08x] %08x @%06x",
|
||||
a | ~0x1ff, d, sh2_pc(sh2));
|
||||
return d;
|
||||
}
|
||||
|
||||
static void sci_trigger(SH2 *sh2, u8 *r)
|
||||
{
|
||||
u8 *oregs;
|
||||
|
||||
if (!(PREG8(r, 2) & 0x20))
|
||||
return; // transmitter not enabled
|
||||
if ((PREG8(r, 4) & 0x80)) // TDRE - TransmitDataR Empty
|
||||
return;
|
||||
|
||||
oregs = (u8 *)sh2->other_sh2->peri_regs;
|
||||
if (!(PREG8(oregs, 2) & 0x10))
|
||||
return; // receiver not enabled
|
||||
|
||||
PREG8(oregs, 5) = PREG8(r, 3); // other.RDR = this.TDR
|
||||
PREG8(r, 4) |= 0x80; // TDRE - TDR empty
|
||||
PREG8(oregs, 4) |= 0x40; // RDRF - RDR Full
|
||||
|
||||
// might need to delay these a bit..
|
||||
if (PREG8(r, 2) & 0x80) { // TIE - tx irq enabled
|
||||
int level = PREG8(oregs, 0x60) >> 4;
|
||||
int vector = PREG8(oregs, 0x64) & 0x7f;
|
||||
elprintf_sh2(sh2, EL_32XP, "SCI tx irq (%d, %d)",
|
||||
level, vector);
|
||||
sh2_internal_irq(sh2, level, vector);
|
||||
}
|
||||
// TODO: TEIE
|
||||
if (PREG8(oregs, 2) & 0x40) { // RIE - rx irq enabled
|
||||
int level = PREG8(oregs, 0x60) >> 4;
|
||||
int vector = PREG8(oregs, 0x63) & 0x7f;
|
||||
elprintf_sh2(sh2->other_sh2, EL_32XP, "SCI rx irq (%d, %d)",
|
||||
level, vector);
|
||||
sh2_internal_irq(sh2->other_sh2, level, vector);
|
||||
}
|
||||
}
|
||||
|
||||
void REGPARM(3) sh2_peripheral_write8(u32 a, u32 d, SH2 *sh2)
|
||||
{
|
||||
u8 *r = (void *)sh2->peri_regs;
|
||||
elprintf(EL_32XP, "%csh2 peri w8 [%08x] %02x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a, d, sh2_pc(sh2));
|
||||
u8 old;
|
||||
|
||||
elprintf_sh2(sh2, EL_32XP, "peri w8 [%08x] %02x @%06x",
|
||||
a, d, sh2_pc(sh2));
|
||||
|
||||
a &= 0x1ff;
|
||||
PREG8(r, a) = d;
|
||||
old = PREG8(r, a);
|
||||
|
||||
// X-men SCI hack
|
||||
if ((a == 2 && (d & 0x20)) || // transmiter enabled
|
||||
(a == 4 && !(d & 0x80))) { // valid data in TDR
|
||||
void *oregs = sh2->other_sh2->peri_regs;
|
||||
if ((PREG8(oregs, 2) & 0x50) == 0x50) { // receiver + irq enabled
|
||||
int level = PREG8(oregs, 0x60) >> 4;
|
||||
int vector = PREG8(oregs, 0x63) & 0x7f;
|
||||
elprintf(EL_32XP, "%csh2 SCI recv irq (%d, %d)",
|
||||
(sh2->is_slave ^ 1) ? 's' : 'm', level, vector);
|
||||
sh2_internal_irq(sh2->other_sh2, level, vector);
|
||||
return;
|
||||
switch (a) {
|
||||
case 0x002: // SCR - serial control
|
||||
if (!(PREG8(r, a) & 0x20) && (d & 0x20)) { // TE being set
|
||||
PREG8(r, a) = d;
|
||||
sci_trigger(sh2, r);
|
||||
}
|
||||
break;
|
||||
case 0x003: // TDR - transmit data
|
||||
break;
|
||||
case 0x004: // SSR - serial status
|
||||
d = (old & (d | 0x06)) | (d & 1);
|
||||
PREG8(r, a) = d;
|
||||
sci_trigger(sh2, r);
|
||||
return;
|
||||
case 0x005: // RDR - receive data
|
||||
break;
|
||||
case 0x010: // TIER
|
||||
if (d & 0x8e)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "TIER: %02x", d);
|
||||
d = (d & 0x8e) | 1;
|
||||
break;
|
||||
case 0x017: // TOCR
|
||||
d |= 0xe0;
|
||||
break;
|
||||
}
|
||||
PREG8(r, a) = d;
|
||||
}
|
||||
|
||||
void REGPARM(3) sh2_peripheral_write16(u32 a, u32 d, SH2 *sh2)
|
||||
{
|
||||
u16 *r = (void *)sh2->peri_regs;
|
||||
elprintf(EL_32XP, "%csh2 peri w16 [%08x] %04x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a, d, sh2_pc(sh2));
|
||||
elprintf_sh2(sh2, EL_32XP, "peri w16 [%08x] %04x @%06x",
|
||||
a, d, sh2_pc(sh2));
|
||||
|
||||
a &= 0x1ff;
|
||||
|
||||
|
@ -297,17 +361,20 @@ void REGPARM(3) sh2_peripheral_write16(u32 a, u32 d, SH2 *sh2)
|
|||
void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2)
|
||||
{
|
||||
u32 *r = sh2->peri_regs;
|
||||
elprintf(EL_32XP, "%csh2 peri w32 [%08x] %08x @%06x",
|
||||
sh2->is_slave ? 's' : 'm', a, d, sh2_pc(sh2));
|
||||
u32 old;
|
||||
|
||||
elprintf_sh2(sh2, EL_32XP, "peri w32 [%08x] %08x @%06x",
|
||||
a, d, sh2_pc(sh2));
|
||||
|
||||
a &= 0x1fc;
|
||||
old = r[a / 4];
|
||||
r[a / 4] = d;
|
||||
|
||||
switch (a) {
|
||||
// division unit (TODO: verify):
|
||||
case 0x104: // DVDNT: divident L, starts divide
|
||||
elprintf(EL_32XP, "%csh2 divide %08x / %08x",
|
||||
sh2->is_slave ? 's' : 'm', d, r[0x100 / 4]);
|
||||
elprintf_sh2(sh2, EL_32XP, "divide %08x / %08x",
|
||||
d, r[0x100 / 4]);
|
||||
if (r[0x100 / 4]) {
|
||||
signed int divisor = r[0x100 / 4];
|
||||
r[0x118 / 4] = r[0x110 / 4] = (signed int)d % divisor;
|
||||
|
@ -317,8 +384,8 @@ void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2)
|
|||
r[0x110 / 4] = r[0x114 / 4] = r[0x118 / 4] = r[0x11c / 4] = 0; // ?
|
||||
break;
|
||||
case 0x114:
|
||||
elprintf(EL_32XP, "%csh2 divide %08x%08x / %08x @%08x",
|
||||
sh2->is_slave ? 's' : 'm', r[0x110 / 4], d, r[0x100 / 4], sh2_pc(sh2));
|
||||
elprintf_sh2(sh2, EL_32XP, "divide %08x%08x / %08x @%08x",
|
||||
r[0x110 / 4], d, r[0x100 / 4], sh2_pc(sh2));
|
||||
if (r[0x100 / 4]) {
|
||||
signed long long divident = (signed long long)r[0x110 / 4] << 32 | d;
|
||||
signed int divisor = r[0x100 / 4];
|
||||
|
@ -328,8 +395,7 @@ void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2)
|
|||
r[0x11c / 4] = r[0x114 / 4] = divident;
|
||||
divident >>= 31;
|
||||
if ((unsigned long long)divident + 1 > 1) {
|
||||
//elprintf(EL_32XP, "%csh2 divide overflow! @%08x",
|
||||
// sh2->is_slave ? 's' : 'm', sh2_pc(sh2));
|
||||
//elprintf_sh2(sh2, EL_32XP, "divide overflow! @%08x", sh2_pc(sh2));
|
||||
r[0x11c / 4] = r[0x114 / 4] = divident > 0 ? 0x7fffffff : 0x80000000; // overflow
|
||||
}
|
||||
}
|
||||
|
@ -341,6 +407,8 @@ void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2)
|
|||
// perhaps starting a DMA?
|
||||
if (a == 0x1b0 || a == 0x18c || a == 0x19c) {
|
||||
struct dmac *dmac = (void *)&sh2->peri_regs[0x180 / 4];
|
||||
if (a == 0x1b0 && !((old ^ d) & d & DMA_DME))
|
||||
return;
|
||||
if (!(dmac->dmaor & DMA_DME))
|
||||
return;
|
||||
|
||||
|
@ -354,29 +422,28 @@ void REGPARM(3) sh2_peripheral_write32(u32 a, u32 d, SH2 *sh2)
|
|||
/* 32X specific */
|
||||
static void dreq0_do(SH2 *sh2, struct dma_chan *chan)
|
||||
{
|
||||
unsigned short *dreqlen = &Pico32x.regs[0x10 / 2];
|
||||
unsigned short dreqlen = Pico32x.regs[0x10 / 2];
|
||||
int i;
|
||||
|
||||
// debug/sanity checks
|
||||
if (chan->tcr != *dreqlen)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq0: tcr0 and len differ: %d != %d",
|
||||
chan->tcr, *dreqlen);
|
||||
if (chan->tcr < dreqlen || chan->tcr > dreqlen + 4)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq0: tcr0/len inconsistent: %d/%d",
|
||||
chan->tcr, dreqlen);
|
||||
// note: DACK is not connected, single addr mode should not be used
|
||||
if ((chan->chcr & 0x3f08) != 0x0400)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq0: bad control: %04x", chan->chcr);
|
||||
if (chan->sar != 0x20004012)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq0: bad sar?: %08x\n", chan->sar);
|
||||
if ((chan->sar & ~0x20000000) != 0x00004012)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq0: bad sar?: %08x", chan->sar);
|
||||
|
||||
// HACK: assume bus is busy and SH2 is halted
|
||||
sh2->state |= SH2_STATE_SLEEP;
|
||||
|
||||
for (i = 0; i < Pico32x.dmac0_fifo_ptr && chan->tcr > 0; i++) {
|
||||
elprintf(EL_32XP, "dmaw [%08x] %04x, left %d",
|
||||
chan->dar, Pico32x.dmac_fifo[i], *dreqlen);
|
||||
elprintf_sh2(sh2, EL_32XP, "dreq0 [%08x] %04x, dreq_len %d",
|
||||
chan->dar, Pico32x.dmac_fifo[i], dreqlen);
|
||||
p32x_sh2_write16(chan->dar, Pico32x.dmac_fifo[i], sh2);
|
||||
chan->dar += 2;
|
||||
chan->tcr--;
|
||||
(*dreqlen)--;
|
||||
}
|
||||
|
||||
if (Pico32x.dmac0_fifo_ptr != i)
|
||||
|
@ -385,8 +452,6 @@ static void dreq0_do(SH2 *sh2, struct dma_chan *chan)
|
|||
Pico32x.dmac0_fifo_ptr -= i;
|
||||
|
||||
Pico32x.regs[6 / 2] &= ~P32XS_FULL;
|
||||
if (*dreqlen == 0)
|
||||
Pico32x.regs[6 / 2] &= ~P32XS_68S; // transfer complete
|
||||
if (chan->tcr == 0)
|
||||
dmac_transfer_complete(sh2, chan);
|
||||
else
|
||||
|
@ -436,8 +501,19 @@ void p32x_dreq1_trigger(void)
|
|||
hit = 1;
|
||||
}
|
||||
|
||||
if (!hit)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq1: nobody cared");
|
||||
// debug
|
||||
#if (EL_LOGMASK & (EL_32XP|EL_ANOMALY))
|
||||
{
|
||||
static int miss_count;
|
||||
if (!hit) {
|
||||
if (++miss_count == 4)
|
||||
elprintf(EL_32XP|EL_ANOMALY, "dreq1: nobody cared");
|
||||
}
|
||||
else
|
||||
miss_count = 0;
|
||||
}
|
||||
#endif
|
||||
(void)hit;
|
||||
}
|
||||
|
||||
// vim:shiftwidth=2:ts=2:expandtab
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue