Skip to content

Commit

Permalink
make an explicit machine_powerup function and call this explicitly fr…
Browse files Browse the repository at this point in the history
…om machine_trigger_reset, instead of doing the related init indirectly in machine_reset. makes machine_reset more worm 'as expected'. should fix #2036

git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@45176 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
mrdudz committed May 31, 2024
1 parent f52a002 commit eb5aa00
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 16 deletions.
2 changes: 1 addition & 1 deletion vice/src/autostart.c
Original file line number Diff line number Diff line change
Expand Up @@ -1519,7 +1519,7 @@ static void reboot_for_autostart(const char *program_name, unsigned int mode,
lib_free(temp_name);
}

mem_powerup();
/* mem_powerup(); */ /* power cycle takes care of this */

autostart_ignore_reset = 1;
deallocate_program_name();
Expand Down
2 changes: 1 addition & 1 deletion vice/src/c64/cart/turbomaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ void turbomaster_mainloop(interrupt_cpu_status_t *cpu_int_status, alarm_context_
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down
6 changes: 5 additions & 1 deletion vice/src/cbm2/cbm2-cmdline-options.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ static int cbm2_set_model(const char *model, void *extra)
if (!cbm2_init_ok) {
return 0;
}

#if 0
mem_powerup();
mem_load();
machine_trigger_reset(MACHINE_RESET_MODE_RESET_CPU);
#else
machine_trigger_reset(MACHINE_RESET_MODE_POWER_CYCLE);
mem_load();
#endif
return 0;
}
return -1;
Expand Down
31 changes: 23 additions & 8 deletions vice/src/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
#endif

static int machine_init_was_called = 0;
static int mem_initialized = 0;
static bool is_jammed = false;
static char *jam_reason = NULL;
static int jam_action = MACHINE_JAM_ACTION_DIALOG;
Expand Down Expand Up @@ -173,6 +172,20 @@ char *machine_jam_reason(void)
return jam_reason;
}

void machine_powerup(void)
{
static CLOCK powerup_clk = CLOCK_MAX;

machine_specific_powerup();

/* some functions we can omit, if the cpu did not run since last call */
if (maincpu_clk != powerup_clk) {
mem_powerup();
}

powerup_clk = maincpu_clk;
}

static void machine_trigger_reset_internal(const unsigned int mode)
{
is_jammed = false;
Expand All @@ -184,8 +197,7 @@ static void machine_trigger_reset_internal(const unsigned int mode)

switch (mode) {
case MACHINE_RESET_MODE_POWER_CYCLE:
mem_initialized = 0; /* force memory initialization */
machine_specific_powerup();
machine_powerup();
/* Fall through. */
case MACHINE_RESET_MODE_RESET_CPU:
maincpu_trigger_reset();
Expand Down Expand Up @@ -214,6 +226,14 @@ void machine_reset_event_playback(CLOCK offset, void *data)
machine_trigger_reset_internal(((unsigned int*)data)[0]);
}

/* called via cpu_reset() */
/* CAUTION: this function is only called when the CPU core is "clocked" (ie the
emulated machine is running). In particular that means that multiple calls
to the machine_trigger_reset() function will not result in multiple calls
to this function (if the cpu core is not running). */
/* NOTE: To make sure things work "as expected", really only deal with "reset"
in the function below - anything related to "powerup" should go into
machine_powerup() instead */
void machine_reset(void)
{
log_message(LOG_DEFAULT, "Main CPU: RESET.");
Expand All @@ -226,11 +246,6 @@ void machine_reset(void)
}

/* Do machine-specific initialization. */
if (!mem_initialized) {
mem_powerup();
mem_initialized = 1;
}

machine_specific_reset();

kbdbuf_abort();
Expand Down
1 change: 1 addition & 0 deletions vice/src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ void machine_specific_reset(void);
void machine_reset_event_playback(CLOCK offset, void *data);

/* Power-up the machine. */
void machine_powerup(void);
void machine_specific_powerup(void);

/* Shutdown the emachine. */
Expand Down
2 changes: 1 addition & 1 deletion vice/src/main65816cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ void maincpu_mainloop(void)
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down
2 changes: 1 addition & 1 deletion vice/src/mainc64cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ void maincpu_mainloop(void)
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down
2 changes: 1 addition & 1 deletion vice/src/maincpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void maincpu_mainloop(void)
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down
2 changes: 1 addition & 1 deletion vice/src/mainviccpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ void maincpu_mainloop(void)
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down
2 changes: 1 addition & 1 deletion vice/src/pet/6809.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ h6809_regs_t h6809_regs;
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_POWER_CYCLE: \
mem_powerup(); \
machine_powerup(); \
DO_INTERRUPT(IK_RESET); \
break; \
case JAM_MONITOR: \
Expand Down

0 comments on commit eb5aa00

Please sign in to comment.