Skip to content

Commit

Permalink
MEGA65+CORE: reorg. window title dynamic update
Browse files Browse the repository at this point in the history
  • Loading branch information
lgblgblgb committed Jun 18, 2024
1 parent 6558f72 commit fbd314f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion targets/mega65/matrix_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ static void dump_regs ( const char rot_fig )
in_hypervisor ? 'H' : 'U',
rot_fig,
videostd_id ? "NTSC" : "PAL ",
cpu_clock_speed_string,
cpu_clock_speed_string_p,
(D6XX_registers[0x7D] & 16) ? '!' : ' '
);
}
Expand Down
38 changes: 20 additions & 18 deletions targets/mega65/mega65.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ static int trace_step_trigger = 0;
#ifdef HAS_UARTMON_SUPPORT
static void (*m65mon_callback)(void) = NULL;
#endif
static const char emulator_paused_title[] = "TRACE/PAUSE";
static char emulator_speed_title[64] = "";
static char fast_mhz_in_string[16] = "";
static const char *cpu_clock_speed_strs[4] = { "1MHz", "2MHz", "3.5MHz", fast_mhz_in_string };
const char *cpu_clock_speed_string = "";
static unsigned int cpu_clock_speed_str_index = 0;
static char fast_mhz_as_string[16] = "";
const char *cpu_clock_speed_string_p = "";
static unsigned int cpu_cycles_per_scanline;
int cpu_cycles_per_step = 100; // some init value, will be overriden, but it must be greater initially than "only a few" anyway
static Uint8 i2c_regs_original[sizeof i2c_regs];
Expand Down Expand Up @@ -122,36 +119,46 @@ void machine_set_speed ( int verbose )
case 4: // 100 - 1MHz
case 5: // 101 - 1MHz
cpu_cycles_per_scanline = (unsigned int)(videostd_1mhz_cycles_per_scanline * (float)(C64_MHZ_CLOCK));
cpu_clock_speed_str_index = 0;
cpu_clock_speed_string_p = "1MHz";
cpu65_set_timing(0);
break;
case 0: // 000 - 2MHz
cpu_cycles_per_scanline = (unsigned int)(videostd_1mhz_cycles_per_scanline * (float)(C128_MHZ_CLOCK));
cpu_clock_speed_str_index = 1;
cpu_clock_speed_string_p = "2MHz";
cpu65_set_timing(0);
break;
case 2: // 010 - 3.5MHz
case 6: // 110 - 3.5MHz
cpu_cycles_per_scanline = (unsigned int)(videostd_1mhz_cycles_per_scanline * (float)(C65_MHZ_CLOCK));
cpu_clock_speed_str_index = 2;
cpu_clock_speed_string_p = "3.5MHz";
cpu65_set_timing(1);
break;
case 1: // 001 - 40MHz (or Xemu specified custom speed)
case 3: // 011 - -- "" --
case 7: // 111 - -- "" --
cpu_cycles_per_scanline = (unsigned int)(videostd_1mhz_cycles_per_scanline * (float)(configdb.fast_mhz));
cpu_clock_speed_str_index = 3;
cpu_clock_speed_string_p = fast_mhz_as_string;
cpu65_set_timing(2);
break;
}
cpu_clock_speed_string = cpu_clock_speed_strs[cpu_clock_speed_str_index];
DEBUG("SPEED: CPU speed is set to %s, cycles per scanline: %d in %s (1MHz cycles per scanline: %f)" NL, cpu_clock_speed_string, cpu_cycles_per_scanline, videostd_name, videostd_1mhz_cycles_per_scanline);
DEBUG("SPEED: CPU speed is set to %s, cycles per scanline: %d in %s (1MHz cycles per scanline: %f)" NL, cpu_clock_speed_string_p, cpu_cycles_per_scanline, videostd_name, videostd_1mhz_cycles_per_scanline);
if (cpu_cycles_per_step > 1 && !hypervisor_is_debugged && !configdb.cpusinglestep)
cpu_cycles_per_step = cpu_cycles_per_scanline; // if in trace mode (or hyper-debug ...), do not set this! So set only if non-trace and non-hyper-debug
}
}


void window_title_pre_update_callback ( void )
{
static const char iomode_names[] = {'2', '3', 'E', '4'};
snprintf(emulator_speed_title, sizeof emulator_speed_title, "%s %s (%c)",
cpu_clock_speed_string_p, videostd_name,
in_hypervisor ? 'H' : iomode_names[io_mode]
);
window_title_custom_addon = paused ? "TRACE/PAUSE" : NULL;
}


int mega65_set_model ( const Uint8 id )
{
static int first_call = 1;
Expand Down Expand Up @@ -418,7 +425,7 @@ static void mega65_init ( void )
#ifdef HAS_UARTMON_SUPPORT
uartmon_init(configdb.uartmon);
#endif
sprintf(fast_mhz_in_string, "%.2fMHz", configdb.fast_mhz);
sprintf(fast_mhz_as_string, "%.2fMHz", configdb.fast_mhz);
DEBUGPRINT("SPEED: fast clock is set to %.2fMHz." NL, configdb.fast_mhz);
cpu65_init_mega_specific();
cpu65_reset(); // reset CPU (though it fetches its reset vector, we don't use that on M65, but the KS hypervisor trap)
Expand Down Expand Up @@ -685,9 +692,6 @@ static void update_emulator ( void )
// XXX: some things has been moved here from the main loop, however update_emulator is called from other places as well, FIXME check if it causes problems or not!
inject_ready_check_do();
audio65_sid_inc_framecount();
strcpy(emulator_speed_title, cpu_clock_speed_strs[cpu_clock_speed_str_index]);
strcat(emulator_speed_title, " ");
strcat(emulator_speed_title, videostd_name);
hid_handle_all_sdl_events();
xemugui_iteration();
nmi_set(IS_RESTORE_PRESSED(), 2); // Custom handling of the restore key ...
Expand Down Expand Up @@ -747,15 +751,13 @@ static void emulation_loop ( void )
// XXX it's maybe a problem to call this!!! update_emulator() is called here which closes frame but no no reopen then ... FIXME: handle this somehow!
update_emulator();
if (trace_step_trigger) {
// if monitor trigges a step, break the pause loop, however we will get back the control on the next
// if monitor triggers a step, break the pause loop, however we will get back the control on the next
// iteration of the infinite "for" loop, as "paused" is not altered
trace_step_trigger = 0;
break; // break the pause loop now
}
// Decorate window title about the mode.
// If "paused" mode is switched off ie by a monitor command (called from update_emulator() above!)
// then it will resets back the the original state, etc
window_title_custom_addon = paused ? (char*)emulator_paused_title : NULL;
if (paused != paused_old) {
paused_old = paused;
if (paused) {
Expand Down
2 changes: 1 addition & 1 deletion targets/mega65/mega65.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ extern int dump_screen ( const char *fn );
extern Uint8 last_dd00_bits;
extern const char *last_reset_type;
extern int cpu_cycles_per_step;
extern const char *cpu_clock_speed_string;
extern const char *cpu_clock_speed_string_p;

#endif
5 changes: 5 additions & 0 deletions targets/mega65/xemu-target.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#define CPU65 cpu65
//#define CPU65_DISCRETE_PF_NZ

// Forces xemu/emutools.c to have a callback on window title update: used in MEGA65 emu
// to set the status of the emulator (ie: paused, running, ...)
// FIXME: define this conditionally when umon/uartmon (?) is enabled
#define WINDOW_TITLE_PRE_UPDATE_CALLBACK window_title_pre_update_callback

// #define DO_NOT_FORCE_UNREACHABLE

#define HAVE_XEMU_EXEC_API
Expand Down
3 changes: 3 additions & 0 deletions xemu/emutools.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,9 @@ void xemu_timekeeping_delay ( int td_em )
td = get_elapsed_time(et_new, &et_old, &unix_time_tv);
seconds_timer_trigger = (unix_time_tv.tv_sec != old_unix_time);
if (seconds_timer_trigger) {
#ifdef WINDOW_TITLE_PRE_UPDATE_CALLBACK
WINDOW_TITLE_PRE_UPDATE_CALLBACK();
#endif
snprintf(window_title_buffer_end, 64, " [%d%% %d%%] %s %s",
((td_em_ALL < td_pc_ALL) && td_pc_ALL) ? td_em_ALL * 100 / td_pc_ALL : 100,
td_em_ALL ? (td_pc_ALL * 100 / td_em_ALL) : -1,
Expand Down
4 changes: 4 additions & 0 deletions xemu/emutools.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ extern void *xemu_realloc ( void *p, size_t size );

extern int xemu_is_first_time_user ( void );

#ifdef WINDOW_TITLE_PRE_UPDATE_CALLBACK
extern void WINDOW_TITLE_PRE_UPDATE_CALLBACK ( void );
#endif

#if !defined(XEMU_ARCH_HTML) && !defined(XEMU_CPU_ARM)
#define HAVE_MM_MALLOC
#endif
Expand Down

0 comments on commit fbd314f

Please sign in to comment.