Patch SynchIdleTime() to implement new "idlewait" prefs item.

This commit is contained in:
gbeauche 2006-04-30 21:16:48 +00:00
parent 52ff4b209b
commit 4f07113555
8 changed files with 54 additions and 0 deletions

View File

@ -1433,6 +1433,12 @@ static void create_serial_pane(GtkWidget *top)
static GtkWidget *w_ramsize;
static GtkWidget *w_rom_file;
// Don't use CPU when idle?
static void tb_idlewait(GtkWidget *widget)
{
PrefsReplaceBool("idlewait", GTK_TOGGLE_BUTTON(widget)->active);
}
// "Ignore SEGV" button toggled
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
static void tb_ignoresegv(GtkWidget *widget)
@ -1525,6 +1531,7 @@ static void create_memory_pane(GtkWidget *top)
w_rom_file = table_make_file_entry(table, 4, STR_ROM_FILE_CTRL, "rom");
make_checkbox(box, STR_IDLEWAIT_CTRL, "idlewait", GTK_SIGNAL_FUNC(tb_idlewait));
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
make_checkbox(box, STR_IGNORESEGV_CTRL, "ignoresegv", GTK_SIGNAL_FUNC(tb_ignoresegv));
#endif

View File

@ -41,6 +41,7 @@ prefs_desc platform_prefs_items[] = {
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
{"ignoresegv", TYPE_BOOLEAN, false, "ignore illegal memory accesses"},
#endif
{"idlewait", TYPE_BOOLEAN, false, "sleep when idle"},
{NULL, TYPE_END, false, NULL} // End of list
};
@ -125,4 +126,5 @@ void AddPlatformPrefsDefaults(void)
#ifdef HAVE_SIGSEGV_SKIP_INSTRUCTION
PrefsAddBool("ignoresegv", false);
#endif
PrefsAddBool("idlewait", true);
}

View File

@ -557,6 +557,13 @@ void EmulOp(uint16 opcode, M68kRegisters *r)
r->d[0] = DebugUtil(r->d[0]);
break;
case M68K_EMUL_OP_IDLE_TIME: // SynchIdleTime() patch
// Sleep if no events pending
if (ReadMacInt32(0x14c) == 0)
idle_wait();
r->a[0] = ReadMacInt32(0x2b6);
break;
default:
printf("FATAL: EMUL_OP called with bogus opcode %08x\n", opcode);
printf("d0 %08x d1 %08x d2 %08x d3 %08x\n"

View File

@ -89,6 +89,7 @@ enum {
M68K_EMUL_OP_SOUNDIN_STATUS,
M68K_EMUL_OP_SOUNDIN_CLOSE,
M68K_EMUL_OP_DEBUGUTIL,
M68K_EMUL_OP_IDLE_TIME,
M68K_EMUL_OP_MAX // highest number
};

View File

@ -196,6 +196,7 @@ enum {
STR_CPU_68030_FPU_LAB,
STR_CPU_68040_LAB,
STR_ROM_FILE_CTRL,
STR_IDLEWAIT_CTRL,
STR_JIT_PANE_TITLE = 3700, // JIT Compiler pane
STR_JIT_CTRL,

View File

@ -24,6 +24,7 @@
#include "cpu_emulation.h"
#include "macos_util.h"
#include "main.h"
#include "prefs.h"
#include "emul_op.h"
#include "audio.h"
#include "audio_defs.h"
@ -52,6 +53,32 @@ static uint32 find_rsrc_data(const uint8 *rsrc, uint32 max, const uint8 *search,
}
/*
* Install SynchIdleTime() patch
*/
static void patch_idle_time(uint8 *p, uint32 size, int n = 1)
{
if (!PrefsFindBool("idlewait"))
return;
static const uint8 dat[] = {0x70, 0x03, 0xa0, 0x9f};
uint32 base = find_rsrc_data(p, size, dat, sizeof(dat));
if (base) {
uint8 *pbase = p + base - 0x80;
static const uint8 dat2[] = {0x20, 0x78, 0x02, 0xb6, 0x41, 0xe8, 0x00, 0x80};
base = find_rsrc_data(pbase, 0x80, dat2, sizeof(dat2));
if (base) {
uint16 *p16 = (uint16 *)(pbase + base);
*p16++ = htons(M68K_EMUL_OP_IDLE_TIME);
*p16 = htons(M68K_NOP);
FlushCodeCache(pbase + base, 4);
D(bug(" patch %d applied\n", n));
}
}
}
/*
* Resource patches via vCheckLoad
*/
@ -204,6 +231,9 @@ void CheckLoad(uint32 type, int16 id, uint8 *p, uint32 size)
D(bug(" patch 1 applied\n"));
}
// Patch SynchIdleTime()
patch_idle_time(p, size, 2);
} else if (type == FOURCC('l','p','c','h') && id == 24) {
D(bug(" lpch 24 found\n"));
@ -246,6 +276,9 @@ void CheckLoad(uint32 type, int16 id, uint8 *p, uint32 size)
D(bug(" patch 2 applied\n"));
}
// Patch SynchIdleTime()
patch_idle_time(p, size, 3);
} else if (type == FOURCC('t','h','n','g') && id == -16563) {
D(bug(" thng -16563 found\n"));

View File

@ -25,6 +25,7 @@
#include "prefs.h"
#include "emul_op.h"
#include "rom_patches.h"
#include "timer.h"
#include "m68k.h"
#include "memory.h"
#include "readcpu.h"
@ -152,6 +153,7 @@ void Start680x0(void)
void TriggerInterrupt(void)
{
idle_resume();
SPCFLAGS_SET( SPCFLAG_INT );
}

View File

@ -211,6 +211,7 @@ user_string_def common_strings[] = {
{STR_CPU_68030_FPU_LAB, "68030 with FPU"},
{STR_CPU_68040_LAB, "68040"},
{STR_ROM_FILE_CTRL, "ROM File"},
{STR_IDLEWAIT_CTRL, "Don't Use CPU When Idle"},
{STR_JIT_PANE_TITLE, "JIT Compiler"},
{STR_JIT_CTRL, "Enable JIT Compiler"},