mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
FAMEC idle loops, PSP port sync, minor adjustments
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@525 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
b06778874d
commit
c060a9ab9c
23 changed files with 408 additions and 155 deletions
|
@ -20,8 +20,8 @@ patch_desc_table:
|
|||
.word (0x71f2<<16) | 0x66f2, idle_detector_bcc8, idle_bne, Op6601 @ bne.s
|
||||
.word (0x75fa<<16) | 0x67fa, idle_detector_bcc8, idle_beq, Op6701 @ beq.s
|
||||
.word (0x75f8<<16) | 0x67f8, idle_detector_bcc8, idle_beq, Op6701 @ beq.s
|
||||
.word (0x75f6<<16) | 0x67f6, idle_detector_bcc8, idle_beq, Op6701 @ bne.s
|
||||
.word (0x75f2<<16) | 0x67f2, idle_detector_bcc8, idle_beq, Op6701 @ bne.s
|
||||
.word (0x75f6<<16) | 0x67f6, idle_detector_bcc8, idle_beq, Op6701 @ beq.s
|
||||
.word (0x75f2<<16) | 0x67f2, idle_detector_bcc8, idle_beq, Op6701 @ beq.s
|
||||
.word (0x7dfe<<16) | 0x60fe, idle_detector_dead, idle_bra, Op6001 @ bra.s
|
||||
.word (0x7dfc<<16) | 0x60fc, idle_detector_dead, idle_bra, Op6001 @ bra.s
|
||||
|
||||
|
@ -132,6 +132,7 @@ idle_detector_bcc8:
|
|||
sub r1, r1, r8, lsl #24
|
||||
mov r1, r1, lsr #24
|
||||
sub r1, r1, #2
|
||||
bic r1, r1, #1
|
||||
|
||||
bl SekIsIdleCode
|
||||
tst r0, r0
|
||||
|
|
|
@ -134,7 +134,7 @@ extern M68K_CONTEXT *g_m68kcontext;
|
|||
/* General purpose functions */
|
||||
void fm68k_init(void);
|
||||
int fm68k_reset(void);
|
||||
int fm68k_emulate(int n, int dualcore);
|
||||
int fm68k_emulate(int n, int dualcore, int idle_mode);
|
||||
int fm68k_would_interrupt(void); // to be called from fm68k_emulate()
|
||||
|
||||
unsigned fm68k_get_pc(M68K_CONTEXT *context);
|
||||
|
|
|
@ -503,8 +503,6 @@ typedef signed int s32;
|
|||
#endif
|
||||
|
||||
|
||||
static int init_jump_table(void);
|
||||
|
||||
// global variable
|
||||
///////////////////
|
||||
|
||||
|
@ -634,7 +632,7 @@ void fm68k_init(void)
|
|||
#endif
|
||||
|
||||
if (!initialised)
|
||||
fm68k_emulate(0, 0);
|
||||
fm68k_emulate(0, 0, 0);
|
||||
|
||||
#ifdef FAMEC_DEBUG
|
||||
puts("FAME initialized.");
|
||||
|
@ -653,7 +651,7 @@ void fm68k_init(void)
|
|||
int fm68k_reset(void)
|
||||
{
|
||||
if (!initialised)
|
||||
fm68k_emulate(0, 0);
|
||||
fm68k_emulate(0, 0, 0);
|
||||
|
||||
// Si la CPU esta en ejecucion, salir con M68K_RUNNING
|
||||
if (m68kcontext.execinfo & M68K_RUNNING)
|
||||
|
@ -783,7 +781,7 @@ static void setup_jumptable(void);
|
|||
// main exec function
|
||||
//////////////////////
|
||||
|
||||
int fm68k_emulate(s32 cycles, int dualcore)
|
||||
int fm68k_emulate(s32 cycles, int dualcore, int idle_mode)
|
||||
{
|
||||
#ifndef FAMEC_NO_GOTOS
|
||||
u32 Opcode;
|
||||
|
@ -799,16 +797,13 @@ int fm68k_emulate(s32 cycles, int dualcore)
|
|||
|
||||
if (!initialised)
|
||||
{
|
||||
#ifdef FAMEC_NO_GOTOS
|
||||
init_jump_table();
|
||||
return 0;
|
||||
#else
|
||||
goto init_jump_table;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef PICODRIVE_HACK
|
||||
if (dualcore) goto dualcore_mode;
|
||||
if (idle_mode == 1) goto idle_install;
|
||||
else if (idle_mode == 2) goto idle_remove;
|
||||
famec_restart:
|
||||
#endif
|
||||
|
||||
|
@ -1006,17 +1001,8 @@ dualcore_mode:
|
|||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef FAMEC_NO_GOTOS
|
||||
}
|
||||
|
||||
static int init_jump_table(void)
|
||||
{{
|
||||
#else
|
||||
init_jump_table:
|
||||
{
|
||||
#endif
|
||||
u32 i, j;
|
||||
|
||||
for(i = 0x0000; i <= 0xFFFF; i += 0x0001)
|
||||
|
@ -5032,6 +5018,49 @@ init_jump_table:
|
|||
|
||||
initialised = 1;
|
||||
return 0;
|
||||
}}
|
||||
}
|
||||
|
||||
#ifdef PICODRIVE_HACK
|
||||
|
||||
#define INSTALL_IDLE(fake_op_base,real_op,detector,idle_handler,normal_handler) \
|
||||
JumpTable[fake_op_base] = CAST_OP(idle_handler); \
|
||||
JumpTable[fake_op_base|0x0200] = CAST_OP(normal_handler); \
|
||||
JumpTable[real_op] = CAST_OP(detector)
|
||||
|
||||
#define UNDO_IDLE(fake_op_base,real_op,normal_handler) \
|
||||
JumpTable[fake_op_base] = JumpTable[fake_op_base|0x0200] = CAST_OP(0x4AFC); \
|
||||
JumpTable[real_op] = CAST_OP(normal_handler)
|
||||
|
||||
idle_install:
|
||||
printf("install..\n");
|
||||
INSTALL_IDLE(0x71fa, 0x66fa, idle_detector_bcc8, 0x6601_idle, 0x6601);
|
||||
INSTALL_IDLE(0x71f8, 0x66f8, idle_detector_bcc8, 0x6601_idle, 0x6601);
|
||||
INSTALL_IDLE(0x71f6, 0x66f6, idle_detector_bcc8, 0x6601_idle, 0x6601);
|
||||
INSTALL_IDLE(0x71f2, 0x66f2, idle_detector_bcc8, 0x6601_idle, 0x6601);
|
||||
INSTALL_IDLE(0x75fa, 0x67fa, idle_detector_bcc8, 0x6701_idle, 0x6701);
|
||||
INSTALL_IDLE(0x75f8, 0x67f8, idle_detector_bcc8, 0x6701_idle, 0x6701);
|
||||
INSTALL_IDLE(0x75f6, 0x67f6, idle_detector_bcc8, 0x6701_idle, 0x6701);
|
||||
INSTALL_IDLE(0x75f2, 0x67f2, idle_detector_bcc8, 0x6701_idle, 0x6701);
|
||||
INSTALL_IDLE(0x7dfe, 0x60fe, idle_detector_dead, 0x6001_idle, 0x6001);
|
||||
INSTALL_IDLE(0x7dfc, 0x60fc, idle_detector_dead, 0x6001_idle, 0x6001);
|
||||
return 0;
|
||||
|
||||
idle_remove:
|
||||
printf("remove..\n");
|
||||
UNDO_IDLE(0x71fa, 0x66fa, 0x6601);
|
||||
UNDO_IDLE(0x71f8, 0x66f8, 0x6601);
|
||||
UNDO_IDLE(0x71f6, 0x66f6, 0x6601);
|
||||
UNDO_IDLE(0x71f2, 0x66f2, 0x6601);
|
||||
UNDO_IDLE(0x75fa, 0x67fa, 0x6701);
|
||||
UNDO_IDLE(0x75f8, 0x67f8, 0x6701);
|
||||
UNDO_IDLE(0x75f6, 0x67f6, 0x6701);
|
||||
UNDO_IDLE(0x75f2, 0x67f2, 0x6701);
|
||||
UNDO_IDLE(0x7dfe, 0x60fe, 0x6001);
|
||||
UNDO_IDLE(0x7dfc, 0x60fc, 0x6001);
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void *get_jumptab(void) { return JumpTable; }
|
||||
|
||||
|
|
|
@ -39961,3 +39961,101 @@ OPCODE(0xE7E7)
|
|||
RET(14)
|
||||
}
|
||||
|
||||
#ifdef PICODRIVE_HACK
|
||||
// BRA
|
||||
OPCODE(0x6001_idle)
|
||||
{
|
||||
#ifdef FAMEC_CHECK_BRANCHES
|
||||
u32 newPC = (u32)(PC) - BasePC;
|
||||
s8 offs=Opcode;
|
||||
newPC += offs;
|
||||
SET_PC(newPC);
|
||||
CHECK_BRANCH_EXCEPTION(offs)
|
||||
#else
|
||||
PC += ((s8)(Opcode & 0xFE)) >> 1;
|
||||
#endif
|
||||
{
|
||||
extern int idle_hit_counter;
|
||||
idle_hit_counter++;
|
||||
}
|
||||
m68kcontext.io_cycle_counter = 10;
|
||||
RET(10)
|
||||
}
|
||||
|
||||
// BCC
|
||||
OPCODE(0x6601_idle)
|
||||
{
|
||||
if (flag_NotZ)
|
||||
{
|
||||
extern int idle_hit_counter;
|
||||
idle_hit_counter++;
|
||||
PC += ((s8)(Opcode & 0xFE)) >> 1;
|
||||
m68kcontext.io_cycle_counter = 8;
|
||||
}
|
||||
RET(8)
|
||||
}
|
||||
|
||||
OPCODE(0x6701_idle)
|
||||
{
|
||||
if (!flag_NotZ)
|
||||
{
|
||||
extern int idle_hit_counter;
|
||||
idle_hit_counter++;
|
||||
PC += ((s8)(Opcode & 0xFE)) >> 1;
|
||||
m68kcontext.io_cycle_counter = 8;
|
||||
}
|
||||
RET(8)
|
||||
}
|
||||
|
||||
|
||||
extern int SekIsIdleCode(unsigned short *dst, int bytes);
|
||||
extern int SekRegisterIdlePatch(unsigned int pc, int oldop, int newop);
|
||||
|
||||
OPCODE(idle_detector_bcc8)
|
||||
{
|
||||
extern int idledet_start_frame;
|
||||
extern char Pico[];
|
||||
int frame_count, cond_true, bytes, ret, newop;
|
||||
u16 *dest_pc;
|
||||
|
||||
dest_pc = PC + (((s8)(Opcode & 0xFE)) >> 1);
|
||||
|
||||
frame_count = *(int *)(Pico+0x22208+0x1c); // Pico.m.frame_count
|
||||
if (frame_count < idledet_start_frame)
|
||||
goto end;
|
||||
|
||||
bytes = 0 - (s8)(Opcode & 0xFE) - 2;
|
||||
ret = SekIsIdleCode(dest_pc, bytes);
|
||||
newop = (Opcode & 0xfe) | 0x7100;
|
||||
if (!ret) newop |= 0x200;
|
||||
if (Opcode & 0x0100) newop |= 0x400; // beq
|
||||
|
||||
ret = SekRegisterIdlePatch(GET_PC - 2, Opcode, newop);
|
||||
switch (ret)
|
||||
{
|
||||
case 0: PC[-1] = newop; break;
|
||||
case 1: break;
|
||||
case 2: JumpTable[Opcode] = (Opcode & 0x0100) ? CAST_OP(0x6701) : CAST_OP(0x6601); break;
|
||||
}
|
||||
|
||||
end:
|
||||
cond_true = (Opcode & 0x0100) ? !flag_NotZ : flag_NotZ; // beq?
|
||||
if (cond_true)
|
||||
{
|
||||
PC = dest_pc;
|
||||
m68kcontext.io_cycle_counter -= 2;
|
||||
}
|
||||
RET(8)
|
||||
}
|
||||
|
||||
OPCODE(idle_detector_dead)
|
||||
{
|
||||
// patch without further questions
|
||||
int newop = 0x7d00 | (Opcode & 0xff);
|
||||
PC[-1] = newop;
|
||||
SekRegisterIdlePatch(GET_PC - 2, Opcode, newop);
|
||||
|
||||
PC += ((s8)(Opcode & 0xFE)) >> 1;
|
||||
RET(10)
|
||||
}
|
||||
#endif // PICODRIVE_HACK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue