mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-06 15:48:05 -04:00
idle loop detection (Cyclone only, with debug stuff)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@502 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
d95259bdaa
commit
053fd9b42f
17 changed files with 372 additions and 37 deletions
|
@ -548,6 +548,7 @@ int PicoCartInsert(unsigned char *rom,unsigned int romsize)
|
|||
int PicoCartUnload(void)
|
||||
{
|
||||
if (Pico.rom != NULL) {
|
||||
SekFinishIdleDet();
|
||||
free(Pico.rom);
|
||||
Pico.rom=NULL;
|
||||
}
|
||||
|
|
33
Pico/Pico.c
33
Pico/Pico.c
|
@ -58,6 +58,8 @@ void PicoPower(void)
|
|||
{
|
||||
unsigned char sram_reg=Pico.m.sram_reg; // must be preserved
|
||||
|
||||
Pico.m.frame_count = 0;
|
||||
|
||||
// clear all memory of the emulated machine
|
||||
memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);
|
||||
|
||||
|
@ -172,6 +174,12 @@ int PicoReset(void)
|
|||
PicoResetMCD();
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
// reinit, so that checksum checks pass
|
||||
SekFinishIdleDet();
|
||||
if (!(PicoOpt & POPT_DIS_IDLE_DET))
|
||||
SekInitIdleDet();
|
||||
}
|
||||
|
||||
// reset sram state; enable sram access by default if it doesn't overlap with ROM
|
||||
Pico.m.sram_reg=sram_reg&0x14;
|
||||
|
@ -188,17 +196,17 @@ int PicoReset(void)
|
|||
// same for Outrunners (92-121, when active is set to 24)
|
||||
// 96 is VR hack
|
||||
static const int dma_timings[] = {
|
||||
96, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy
|
||||
102, 205, 204, 102, // vblank: 40cell:
|
||||
16, 16, 15, 8, // active: 32cell:
|
||||
24, 18, 17, 9 // ...
|
||||
96, 167, 166, 83, // vblank: 32cell: dma2vram dma2[vs|c]ram vram_fill vram_copy
|
||||
102, 205, 204, 102, // vblank: 40cell:
|
||||
16, 16, 15, 8, // active: 32cell:
|
||||
24, 18, 17, 9 // ...
|
||||
};
|
||||
|
||||
static const int dma_bsycles[] = {
|
||||
(488<<8)/96, (488<<8)/167, (488<<8)/166, (488<<8)/83,
|
||||
(488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102,
|
||||
(488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,
|
||||
(488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9
|
||||
(488<<8)/96, (488<<8)/167, (488<<8)/166, (488<<8)/83,
|
||||
(488<<8)/102, (488<<8)/205, (488<<8)/204, (488<<8)/102,
|
||||
(488<<8)/16, (488<<8)/16, (488<<8)/15, (488<<8)/8,
|
||||
(488<<8)/24, (488<<8)/18, (488<<8)/17, (488<<8)/9
|
||||
};
|
||||
|
||||
PICO_INTERNAL int CheckDMA(void)
|
||||
|
@ -232,7 +240,7 @@ static __inline void SekRunM68k(int cyc)
|
|||
{
|
||||
int cyc_do;
|
||||
SekCycleAim+=cyc;
|
||||
if((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
|
||||
if ((cyc_do=SekCycleAim-SekCycleCnt) <= 0) return;
|
||||
#if defined(EMU_CORE_DEBUG)
|
||||
// this means we do run-compare
|
||||
SekCycleCnt+=CM_compareRun(cyc_do, 0);
|
||||
|
@ -498,10 +506,17 @@ static int PicoFrameSimple(void)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int idle_hit_counter = 0;
|
||||
|
||||
int PicoFrame(void)
|
||||
{
|
||||
int acc;
|
||||
|
||||
if ((Pico.m.frame_count&0x3f) == 0) {
|
||||
elprintf(EL_STATUS, "ihits: %i", idle_hit_counter);
|
||||
idle_hit_counter = 0;
|
||||
}
|
||||
|
||||
Pico.m.frame_count++;
|
||||
|
||||
if (PicoAHW & PAHW_MCD) {
|
||||
|
|
|
@ -47,6 +47,7 @@ void mp3_update(int *buffer, int length, int stereo);
|
|||
#define POPT_DIS_VDP_FIFO (1<<16) // 0x 0000
|
||||
#define POPT_EN_SVP_DRC (1<<17)
|
||||
#define POPT_DIS_SPRITE_LIM (1<<18)
|
||||
#define POPT_DIS_IDLE_DET (1<<19)
|
||||
extern int PicoOpt; // bitfield
|
||||
#define PAHW_MCD (1<<0)
|
||||
#define PAHW_32X (1<<1)
|
||||
|
|
|
@ -259,9 +259,9 @@ struct PicoMisc
|
|||
unsigned char eeprom_cycle; // EEPROM SRAM cycle number
|
||||
unsigned char eeprom_slave; // EEPROM slave word for X24C02 and better SRAMs
|
||||
unsigned char prot_bytes[2]; // simple protection faking
|
||||
unsigned short dma_xfers;
|
||||
unsigned short dma_xfers; // 18
|
||||
unsigned char pad[2];
|
||||
unsigned int frame_count; // mainly for movies
|
||||
unsigned int frame_count; // 1c for movies and idle det
|
||||
};
|
||||
|
||||
// some assembly stuff depend on these, do not touch!
|
||||
|
@ -461,6 +461,8 @@ PICO_INTERNAL int SekInit(void);
|
|||
PICO_INTERNAL int SekReset(void);
|
||||
PICO_INTERNAL void SekState(int *data);
|
||||
PICO_INTERNAL void SekSetRealTAS(int use_real);
|
||||
void SekInitIdleDet(void);
|
||||
void SekFinishIdleDet(void);
|
||||
|
||||
// cd/Sek.c
|
||||
PICO_INTERNAL int SekInitS68k(void);
|
||||
|
@ -557,6 +559,7 @@ extern int PsndDacLine;
|
|||
#define EL_CDPOLL 0x00002000 /* MCD: log poll detection */
|
||||
#define EL_SVP 0x00004000 /* SVP stuff */
|
||||
#define EL_PICOHW 0x00008000 /* Pico stuff */
|
||||
#define EL_IDLE 0x00010000 /* idle loop det. */
|
||||
|
||||
#define EL_STATUS 0x40000000 /* status messages */
|
||||
#define EL_ANOMALY 0x80000000 /* some unexpected conditions (during emulation) */
|
||||
|
|
125
Pico/Sek.c
125
Pico/Sek.c
|
@ -193,6 +193,131 @@ PICO_INTERNAL void SekSetRealTAS(int use_real)
|
|||
#endif
|
||||
}
|
||||
|
||||
/* idle loop detection, not to be used in CD mode */
|
||||
#ifdef EMU_C68K
|
||||
#include "cpu/Cyclone/tools/idle.h"
|
||||
#endif
|
||||
|
||||
static int *idledet_addrs = NULL;
|
||||
static int idledet_count = 0, idledet_bads = 0;
|
||||
int idledet_start_frame = 0;
|
||||
|
||||
static int jump_verify[0x10000];
|
||||
extern int CycloneJumpTab[];
|
||||
static unsigned char *rom_verify = NULL;
|
||||
|
||||
void SekInitIdleDet(void)
|
||||
{
|
||||
void *tmp = realloc(idledet_addrs, 0x200*4);
|
||||
if (tmp == NULL) {
|
||||
free(idledet_addrs);
|
||||
idledet_addrs = NULL;
|
||||
}
|
||||
else
|
||||
idledet_addrs = tmp;
|
||||
idledet_count = idledet_bads = 0;
|
||||
idledet_start_frame = Pico.m.frame_count + 360;
|
||||
|
||||
memcpy(jump_verify, CycloneJumpTab, 0x10000*4);
|
||||
rom_verify = realloc(rom_verify, Pico.romsize);
|
||||
memcpy(rom_verify, Pico.rom, Pico.romsize);
|
||||
#ifdef EMU_C68K
|
||||
CycloneInitIdle();
|
||||
#endif
|
||||
}
|
||||
|
||||
int SekIsIdleCode(unsigned short *dst, int bytes)
|
||||
{
|
||||
printf("SekIsIdleCode %04x %i\n", *dst, bytes);
|
||||
switch (bytes)
|
||||
{
|
||||
case 4:
|
||||
if ( (*dst & 0xfff8) == 0x4a10 || // tst.b ($aX) // where should be no need to wait
|
||||
(*dst & 0xfff8) == 0x4a28 || // tst.b ($xxxx,a0) // for byte change anywhere
|
||||
(*dst & 0xff3f) == 0x4a38 || // tst.x ($xxxx.w), tas ($xxxx.w)
|
||||
(*dst & 0xc1ff) == 0x0038 || // move.x ($xxxx.w), dX
|
||||
(*dst & 0xf13f) == 0xb038) // cmp.x ($xxxx.w), dX
|
||||
return 1;
|
||||
break;
|
||||
case 6:
|
||||
if ( ((dst[1] & 0xe0) == 0xe0 && ( // RAM
|
||||
*dst == 0x4a39 || // tst.b ($xxxxxxxx)
|
||||
*dst == 0x4a79 || // tst.w ($xxxxxxxx)
|
||||
*dst == 0x4ab9)) || // tst.l ($xxxxxxxx)
|
||||
*dst == 0x0838) // btst $X, ($xxxx.w) [6 byte op]
|
||||
return 1;
|
||||
break;
|
||||
case 8:
|
||||
if ( (dst[2] & 0xe0) == 0xe0 && ( // RAM
|
||||
*dst == 0x0839 || // btst $X, ($xxxxxxxx.w) [8 byte op]
|
||||
(*dst & 0xffbf) == 0x0c39)) // cmpi.{b,w} $X, ($xxxxxxxx)
|
||||
return 1;
|
||||
break;
|
||||
case 12:
|
||||
if ((*dst & 0xf1f8) == 0x3010 && // move.w (aX), dX
|
||||
(dst[1]&0xf100) == 0x0000 && // arithmetic
|
||||
(dst[3]&0xf100) == 0x0000) // arithmetic
|
||||
return 1;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop)
|
||||
{
|
||||
#ifdef EMU_C68K
|
||||
pc -= PicoCpuCM68k.membase;
|
||||
#endif
|
||||
pc &= ~0xff000000;
|
||||
elprintf(EL_IDLE, "idle: patch %06x %04x %04x #%i", pc, oldop, newop, idledet_count);
|
||||
if (pc > Pico.romsize) {
|
||||
if (++idledet_bads > 128) return 2; // remove detector
|
||||
return 1; // don't patch
|
||||
}
|
||||
|
||||
if (idledet_count >= 0x200 && (idledet_count & 0x1ff) == 0) {
|
||||
void *tmp = realloc(idledet_addrs, (idledet_count+0x200)*4);
|
||||
if (tmp == NULL) return 1;
|
||||
idledet_addrs = tmp;
|
||||
}
|
||||
|
||||
idledet_addrs[idledet_count++] = pc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SekFinishIdleDet(void)
|
||||
{
|
||||
int done_something = idledet_count > 0;
|
||||
#ifdef EMU_C68K
|
||||
CycloneFinishIdle();
|
||||
#endif
|
||||
while (idledet_count > 0)
|
||||
{
|
||||
unsigned short *op = (unsigned short *)&Pico.rom[idledet_addrs[--idledet_count]];
|
||||
if ((*op & 0xfd00) == 0x7100)
|
||||
*op &= 0xff, *op |= 0x6600;
|
||||
else if ((*op & 0xfd00) == 0x7500)
|
||||
*op &= 0xff, *op |= 0x6700;
|
||||
else if ((*op & 0xfd00) == 0x7d00)
|
||||
*op &= 0xff, *op |= 0x6000;
|
||||
else
|
||||
elprintf(EL_STATUS|EL_IDLE, "idle: don't know how to restore %04x", *op);
|
||||
}
|
||||
|
||||
if (done_something)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < 0x10000; i++)
|
||||
if (jump_verify[i] != CycloneJumpTab[i])
|
||||
printf("jumptab corruption @ %04x!\n", i), exit(1);
|
||||
for (i = 0; i < Pico.romsize; i++)
|
||||
if (rom_verify[i] != Pico.rom[i])
|
||||
printf("ROM corruption @ %06x!\n", i), exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(EMU_M68K) && M68K_INSTRUCTION_HOOK == OPT_SPECIFY_HANDLER
|
||||
static unsigned char op_flags[0x400000/2] = { 0, };
|
||||
static int atexit_set = 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue