bugfixes in cd/Memory.s, poll loop detection

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@77 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-03-24 18:25:17 +00:00
parent 00bd648e63
commit 7a1f6e45c9
6 changed files with 134 additions and 35 deletions

View file

@ -27,12 +27,16 @@ extern struct Cyclone PicoCpu, PicoCpuS68k;
#define SekCyclesLeftNoMCD PicoCpu.cycles // cycles left for this run #define SekCyclesLeftNoMCD PicoCpu.cycles // cycles left for this run
#define SekCyclesLeft \ #define SekCyclesLeft \
(((PicoMCD&1) && (PicoOpt & 0x2000)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD) (((PicoMCD&1) && (PicoOpt & 0x2000)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
#define SekCyclesLeftS68k \
((PicoOpt & 0x2000) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoCpuS68k.cycles)
#define SekSetCyclesLeftNoMCD(c) PicoCpu.cycles=c #define SekSetCyclesLeftNoMCD(c) PicoCpu.cycles=c
#define SekSetCyclesLeft(c) { \ #define SekSetCyclesLeft(c) { \
if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCycleCnt=SekCycleAim-(c); else SekSetCyclesLeftNoMCD(c); \ if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCycleCnt=SekCycleAim-(c); else SekSetCyclesLeftNoMCD(c); \
} }
#define SekPc (PicoCpu.pc-PicoCpu.membase) #define SekPc (PicoCpu.pc-PicoCpu.membase)
#define SekPcS68k (PicoCpuS68k.pc-PicoCpuS68k.membase) #define SekPcS68k (PicoCpuS68k.pc-PicoCpuS68k.membase)
#define SekSetStop(x) { PicoCpu.stopped=x; if (x) PicoCpu.cycles=0; }
#define SekSetStopS68k(x) { PicoCpuS68k.stopped=x; if (x) PicoCpuS68k.cycles=0; }
#endif #endif
#ifdef EMU_A68K #ifdef EMU_A68K
@ -60,15 +64,25 @@ extern int m68k_ICount;
extern m68ki_cpu_core PicoM68kCPU; // MD's CPU extern m68ki_cpu_core PicoM68kCPU; // MD's CPU
extern m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU extern m68ki_cpu_core PicoS68kCPU; // Mega CD's CPU
#ifndef SekCyclesLeft #ifndef SekCyclesLeft
#define SekCyclesLeftNoMCD m68k_cycles_remaining() #define SekCyclesLeftNoMCD PicoM68kCPU.cyc_remaining_cycles
#define SekCyclesLeft \ #define SekCyclesLeft \
(((PicoMCD&1) && (PicoOpt & 0x2000)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD) (((PicoMCD&1) && (PicoOpt & 0x2000)) ? (SekCycleAim-SekCycleCnt) : SekCyclesLeftNoMCD)
#define SekCyclesLeftS68k \
((PicoOpt & 0x2000) ? (SekCycleAimS68k-SekCycleCntS68k) : PicoS68kCPU.cyc_remaining_cycles)
#define SekSetCyclesLeftNoMCD(c) SET_CYCLES(c) #define SekSetCyclesLeftNoMCD(c) SET_CYCLES(c)
#define SekSetCyclesLeft(c) { \ #define SekSetCyclesLeft(c) { \
if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCycleCnt=SekCycleAim-(c); else SET_CYCLES(c); \ if ((PicoMCD&1) && (PicoOpt & 0x2000)) SekCycleCnt=SekCycleAim-(c); else SET_CYCLES(c); \
} }
#define SekPc m68k_get_reg(&PicoM68kCPU, M68K_REG_PC) #define SekPc m68k_get_reg(&PicoM68kCPU, M68K_REG_PC)
#define SekPcS68k m68k_get_reg(&PicoS68kCPU, M68K_REG_PC) #define SekPcS68k m68k_get_reg(&PicoS68kCPU, M68K_REG_PC)
#define SekSetStop(x) { \
if(x) { SET_CYCLES(0); PicoM68kCPU.stopped=STOP_LEVEL_STOP; } \
else PicoM68kCPU.stopped=0; \
}
#define SekSetStopS68k(x) { \
if(x) { SET_CYCLES(0); PicoS68kCPU.stopped=STOP_LEVEL_STOP; } \
else PicoS68kCPU.stopped=0; \
}
#endif #endif
#endif #endif
@ -91,6 +105,7 @@ extern int SekCycleCntS68k;
extern int SekCycleAimS68k; extern int SekCycleAimS68k;
#define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;} #define SekCyclesResetS68k() {SekCycleCntS68k=SekCycleAimS68k=0;}
#define SekCyclesDoneS68k() (SekCycleAimS68k-SekCyclesLeftS68k)
// does not work as expected // does not work as expected
//extern int z80ExtraCycles; // extra z80 cycles, used when z80 is [en|dis]abled //extern int z80ExtraCycles; // extra z80 cycles, used when z80 is [en|dis]abled

View file

@ -33,6 +33,12 @@ typedef unsigned int u32;
// ----------------------------------------------------------------- // -----------------------------------------------------------------
// poller detection
#define USE_POLL_DETECT
#define POLL_LIMIT 16
#define POLL_CYCLES 124
// int m68k_poll_addr, m68k_poll_cnt;
unsigned int s68k_poll_adclk, s68k_poll_cnt;
#ifndef _ASM_CD_MEMORY_C #ifndef _ASM_CD_MEMORY_C
static u32 m68k_reg_read16(u32 a) static u32 m68k_reg_read16(u32 a)
@ -126,12 +132,12 @@ void m68k_reg_write8(u32 a, u32 d)
if (d & 2) dold &= ~1; // return word RAM to s68k in 2M mode if (d & 2) dold &= ~1; // return word RAM to s68k in 2M mode
} }
Pico_mcd->s68k_regs[3] = d | dold; // really use s68k side register Pico_mcd->s68k_regs[3] = d | dold; // really use s68k side register
#ifdef USE_POLL_DETECT
/* if ((s68k_poll_adclk&0xfe) == 2 && s68k_poll_cnt > POLL_LIMIT) {
d |= Pico_mcd->s68k_regs[3]&0x1d; SekSetStopS68k(0); s68k_poll_adclk = 0;
if (!(d & 4) && (d & 2)) d &= ~1; // return word RAM to s68k in 2M mode //printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);
Pico_mcd->s68k_regs[3] = d; // really use s68k side register }
*/ #endif
return; return;
} }
case 6: case 6:
@ -141,14 +147,28 @@ void m68k_reg_write8(u32 a, u32 d)
Pico_mcd->bios[0x72] = d; Pico_mcd->bios[0x72] = d;
dprintf("hint vector set to %08x", PicoRead32(0x70)); dprintf("hint vector set to %08x", PicoRead32(0x70));
return; return;
case 0xf:
d = (d << 1) | ((d >> 7) & 1); // rol8 1 (special case)
case 0xe: case 0xe:
//dprintf("m68k: comm flag: %02x", d); //dprintf("m68k: comm flag: %02x", d);
Pico_mcd->s68k_regs[0xe] = d; Pico_mcd->s68k_regs[0xe] = d;
#ifdef USE_POLL_DETECT
if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {
SekSetStopS68k(0); s68k_poll_adclk = 0;
//printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);
}
#endif
return; return;
} }
if ((a&0xf0) == 0x10) { if ((a&0xf0) == 0x10) {
Pico_mcd->s68k_regs[a] = d; Pico_mcd->s68k_regs[a] = d;
#ifdef USE_POLL_DETECT
if ((a&0xfe) == (s68k_poll_adclk&0xfe) && s68k_poll_cnt > POLL_LIMIT) {
SekSetStopS68k(0); s68k_poll_adclk = 0;
//printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);
}
#endif
return; return;
} }
@ -178,48 +198,64 @@ u32 s68k_reg_read16(u32 a)
switch (a) { switch (a) {
case 0: case 0:
d = ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state return ((Pico_mcd->s68k_regs[0]&3)<<8) | 1; // ver = 0, not in reset state
goto end;
case 2: case 2:
d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f); d = (Pico_mcd->s68k_regs[a]<<8) | (Pico_mcd->s68k_regs[a+1]&0x1f);
dprintf("s68k_regs r3: %02x @%06x", (u8)d, SekPcS68k); dprintf("s68k_regs r3: %02x @%06x", (u8)d, SekPcS68k);
goto end; goto poll_detect;
case 6: case 6:
d = CDC_Read_Reg(); return CDC_Read_Reg();
goto end;
case 8: case 8:
d = Read_CDC_Host(1); // Gens returns 0 here on byte reads return Read_CDC_Host(1); // Gens returns 0 here on byte reads
goto end;
case 0xC: case 0xC:
d = Pico_mcd->m.timer_stopwatch >> 16; d = Pico_mcd->m.timer_stopwatch >> 16;
dprintf("s68k stopwatch timer read (%04x)", d); dprintf("s68k stopwatch timer read (%04x)", d);
goto end; return d;
case 0x30: case 0x30:
dprintf("s68k int3 timer read (%02x%02x)", Pico_mcd->s68k_regs[30], Pico_mcd->s68k_regs[31]); dprintf("s68k int3 timer read (%02x)", Pico_mcd->s68k_regs[31]);
break; return Pico_mcd->s68k_regs[31];
case 0x34: // fader case 0x34: // fader
d = 0; // no busy bit return 0; // no busy bit
goto end;
case 0x50: // font data (check: Lunar 2, Silpheed) case 0x50: // font data (check: Lunar 2, Silpheed)
READ_FONT_DATA(0x00100000); READ_FONT_DATA(0x00100000);
goto end; return d;
case 0x52: case 0x52:
READ_FONT_DATA(0x00010000); READ_FONT_DATA(0x00010000);
goto end; return d;
case 0x54: case 0x54:
READ_FONT_DATA(0x10000000); READ_FONT_DATA(0x10000000);
goto end; return d;
case 0x56: case 0x56:
READ_FONT_DATA(0x01000000); READ_FONT_DATA(0x01000000);
goto end; return d;
} }
d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1]; d = (Pico_mcd->s68k_regs[a]<<8) | Pico_mcd->s68k_regs[a+1];
end: if (a >= 0x0e && a < 0x30) goto poll_detect;
// dprintf("ret = %04x", d); return d;
poll_detect:
#ifdef USE_POLL_DETECT
// polling detection
if (a == (s68k_poll_adclk&0xfe)) {
unsigned int clkdiff = SekCyclesDoneS68k() - (s68k_poll_adclk>>8);
if (clkdiff <= POLL_CYCLES) {
s68k_poll_cnt++;
//printf("-- diff: %u, cnt = %i\n", clkdiff, s68k_poll_cnt);
if (s68k_poll_cnt > POLL_LIMIT) {
SekSetStopS68k(1);
//printf("%05i:%03i: s68k poll detected @ %06x, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, SekPcS68k, a);
}
s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;
return d;
}
}
s68k_poll_adclk = (SekCyclesDoneS68k() << 8) | a;
s68k_poll_cnt = 0;
#endif
return d; return d;
} }
@ -292,8 +328,7 @@ void s68k_reg_write8(u32 a, u32 d)
Pico_mcd->m.timer_stopwatch = 0; Pico_mcd->m.timer_stopwatch = 0;
return; return;
case 0xe: case 0xe:
Pico_mcd->s68k_regs[0Xf] = (d>>1) | (d<<7); // ror8, Gens note: Dragons lair Pico_mcd->s68k_regs[0xf] = (d>>1) | (d<<7); // ror8 1, Gens note: Dragons lair
Pico_mcd->m.timer_stopwatch = 0;
return; return;
case 0x31: case 0x31:
dprintf("s68k set int3 timer: %02x", d); dprintf("s68k set int3 timer: %02x", d);
@ -634,8 +669,23 @@ static void PicoWriteM68k16(u32 a,u16 d)
return; return;
} }
if ((a&0xffffc0)==0xa12000) // regs
if ((a&0xffffc0)==0xa12000) {
rdprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc); rdprintf("m68k_regs w16: [%02x] %04x @%06x", a&0x3f, d, SekPc);
if (a == 0xe) { // special case, 2 byte writes would be handled differently
Pico_mcd->s68k_regs[0xe] = d >> 8;
#ifdef USE_POLL_DETECT
if ((s68k_poll_adclk&0xfe) == 0xe && s68k_poll_cnt > POLL_LIMIT) {
SekSetStopS68k(0); s68k_poll_adclk = -1;
//printf("%05i:%03i: s68k poll release, a=%02x\n", Pico.m.frame_count, Pico.m.scanline, a);
}
#endif
return;
}
m68k_reg_write8(a, d>>8);
m68k_reg_write8(a+1,d&0xff);
return;
}
OtherWrite16(a,d); OtherWrite16(a,d);
} }
@ -1408,6 +1458,8 @@ void PicoMemSetupCD()
PicoCpuS68k.write16=PicoWriteS68k16; PicoCpuS68k.write16=PicoWriteS68k16;
PicoCpuS68k.write32=PicoWriteS68k32; PicoCpuS68k.write32=PicoWriteS68k32;
#endif #endif
// m68k_poll_addr = m68k_poll_cnt = 0;
s68k_poll_adclk = s68k_poll_cnt = 0;
} }

View file

@ -7,6 +7,7 @@
.equiv PCM_STEP_SHIFT, 11 .equiv PCM_STEP_SHIFT, 11
.equiv POLL_LIMIT, 16
@ jump tables @ jump tables
.data .data
@ -132,6 +133,8 @@ m_s68k_decode_write_table:
.extern SRam .extern SRam
.extern gfx_cd_write16 .extern gfx_cd_write16
.extern s68k_reg_write8 .extern s68k_reg_write8
.extern s68k_poll_adclk
.extern PicoCpuS68k
@ r0=reg3, r1-r3=temp @ r0=reg3, r1-r3=temp
@ -665,7 +668,7 @@ m_m68k_read16_m68k_regs:
.long m_m68k_read16_r0c .long m_m68k_read16_r0c
m_m68k_read16_r00: m_m68k_read16_r00:
add r1, r1, #0x110000 add r1, r1, #0x110000
ldr r0, [r1, #30] ldr r0, [r1, #0x30]
add r1, r1, #0x002200 add r1, r1, #0x002200
ldrb r1, [r1, #2] @ Pico_mcd->m.busreq ldrb r1, [r1, #2] @ Pico_mcd->m.busreq
and r0, r0, #0x04000000 @ we need irq2 mask state and r0, r0, #0x04000000 @ we need irq2 mask state
@ -1073,6 +1076,9 @@ m_m68k_write16_system_io:
bne OtherWrite16 bne OtherWrite16
m_m68k_write16_m68k_regs: m_m68k_write16_m68k_regs:
and r0, r0, #0x3e
cmp r0, #0x0e
beq m_m68k_write16_regs_spec
and r3, r1, #0xff and r3, r1, #0xff
add r2, r0, #1 add r2, r0, #1
stmfd sp!,{r2,r3,lr} stmfd sp!,{r2,r3,lr}
@ -1081,6 +1087,24 @@ m_m68k_write16_m68k_regs:
ldmfd sp!,{r0,r1,lr} ldmfd sp!,{r0,r1,lr}
b m68k_reg_write8 b m68k_reg_write8
m_m68k_write16_regs_spec: @ special case
ldr r2, =(Pico+0x22200)
ldr r3, =s68k_poll_adclk
mov r0, #0x110000
ldr r2, [r2]
add r0, r0, #0x00000e
mov r1, r1, lsr #8
strb r1, [r2, r0] @ if (a == 0xe) s68k_regs[0x0e] = d >> 8;
ldr r2, [r3]
mov r1, #0
and r2, r2, #0xfe
cmp r2, #0x0e
bxne lr
ldr r0, =PicoCpuS68k
str r1, [r0, #0x58] @ push s68k out of stopped state
str r1, [r3]
bx lr
m_m68k_write16_vdp: m_m68k_write16_vdp:
tst r0, #0x70000 tst r0, #0x70000
@ -1454,7 +1478,10 @@ m_s68k_read16_regs:
sub r2, r0, #0x58 sub r2, r0, #0x58
cmp r2, #0x10 cmp r2, #0x10
blo gfx_cd_read blo gfx_cd_read
b s68k_reg_read16 cmp r0, #8
bne s68k_reg_read16
mov r0, #1
b Read_CDC_Host
@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ -1664,7 +1691,7 @@ m_s68k_write8_backup: @ 0xfe0000 - 0xfe3fff (repeated?)
strb r1, [r2, r0] strb r1, [r2, r0]
ldr r1, =SRam ldr r1, =SRam
mov r0, #1 mov r0, #1
str r0, [r1, #0x0e] @ SRam.changed = 1 strb r0, [r1, #0x0e] @ SRam.changed = 1
bx lr bx lr

View file

@ -790,6 +790,9 @@ static void emu_msg_cb(const char *msg)
} }
gettimeofday(&noticeMsgTime, 0); gettimeofday(&noticeMsgTime, 0);
noticeMsgTime.tv_sec -= 2; noticeMsgTime.tv_sec -= 2;
/* assumption: emu_msg_cb gets called only when something slow is about to happen */
reset_timing = 1;
} }
static void emu_state_cb(const char *str) static void emu_state_cb(const char *str)
@ -1168,7 +1171,9 @@ void emu_Loop(void)
if (frames_shown > frames_done) frames_shown = frames_done; if (frames_shown > frames_done) frames_shown = frames_done;
} }
} }
#if 0
sprintf(fpsbuff, "%05i", Pico.m.frame_count);
#endif
lim_time = (frames_done+1) * target_frametime; lim_time = (frames_done+1) * target_frametime;
if(currentConfig.Frameskip >= 0) { // frameskip enabled if(currentConfig.Frameskip >= 0) { // frameskip enabled
for(i = 0; i < currentConfig.Frameskip; i++) { for(i = 0; i < currentConfig.Frameskip; i++) {

View file

@ -1,2 +1,2 @@
#define VERSION "1.201" #define VERSION "1.30"

View file

@ -12,8 +12,8 @@
// pico.c // pico.c
#define CAN_HANDLE_240_LINES 1 #define CAN_HANDLE_240_LINES 1
#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__) //#define dprintf(f,...) printf("%05i:%03i: " f "\n",Pico.m.frame_count,Pico.m.scanline,##__VA_ARGS__)
//#define dprintf(x...) #define dprintf(x...)
#endif //PORT_CONFIG_H #endif //PORT_CONFIG_H