From: Toni Wilen Date: Tue, 15 May 2018 17:14:36 +0000 (+0300) Subject: Action Replay statefile support improved. X-Git-Tag: 4000~62 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=ebc42accb829ab707b10c2385c6ac8ec94b6ba3b;p=francis%2Fwinuae.git Action Replay statefile support improved. --- diff --git a/ar.cpp b/ar.cpp index 7cb6f42e..f9c8693d 100644 --- a/ar.cpp +++ b/ar.cpp @@ -504,6 +504,7 @@ static void copytoamiga (uaecptr dst, uae_u8 *src, int len) } int action_replay_flag = ACTION_REPLAY_INACTIVE; +static int ar_state1 = -1, ar_state2 = -1, ar_hide; static int ar_rom_file_size; /* Use this for relocating AR? */ @@ -917,6 +918,7 @@ static void action_replay_unmap_banks (void) static void hide_cart (int hide) { + ar_hide = hide; #ifdef ACTION_REPLAY_HIDE_CARTRIDGE if(hide) { action_replay_unmap_banks (); @@ -1092,17 +1094,8 @@ void action_replay_reset (bool hardreset, bool keyboardreset) } else { if (action_replay_flag == ACTION_REPLAY_INACTIVE) return; - - if (isrestore ()) { - if (m68k_getpc () >= arrom_start && m68k_getpc () <= arrom_start + arrom_size) { - action_replay_flag = ACTION_REPLAY_ACTIVE; - hide_cart (0); - } else { - action_replay_flag = ACTION_REPLAY_IDLE; - hide_cart (1); - } + if (isrestore ()) return; - } if (armodel == 1) { /* We need to mark it as active here, because the kickstart rom jumps directly into it. */ action_replay_flag = ACTION_REPLAY_ACTIVE; @@ -1512,22 +1505,6 @@ int action_replay_unload (int in_memory_reset) write_log_debug (_T("Action Replay State:(%s)\nHrtmon State:(%s)\n"), state[action_replay_flag + 3], state[hrtmon_flag + 3]); - if (armemory_rom && armodel == 1) { - if (is_ar_pc_in_ram() || is_ar_pc_in_rom() || action_replay_flag == ACTION_REPLAY_WAIT_PC) { - write_log (_T("Can't Unload Action Replay 1. It is Active.\n")); - return 0; - } - } else { - if (action_replay_flag != ACTION_REPLAY_IDLE && action_replay_flag != ACTION_REPLAY_INACTIVE) { - write_log (_T("Can't Unload Action Replay. It is Active.\n")); - return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ - } - if (hrtmon_flag != ACTION_REPLAY_IDLE && hrtmon_flag != ACTION_REPLAY_INACTIVE) { - write_log (_T("Can't Unload Hrtmon. It is Active.\n")); - return 0; /* Don't unload it whilst it's active, or it will crash the amiga if not the emulator */ - } - } - unset_special (SPCFLAG_ACTION_REPLAY); /* This shouldn't be necessary here, but just in case. */ action_replay_flag = ACTION_REPLAY_INACTIVE; hrtmon_flag = ACTION_REPLAY_INACTIVE; @@ -2120,7 +2097,7 @@ uae_u8 *save_action_replay (int *len, uae_u8 *dstptr) dstbak = dst = dstptr; else dstbak = dst = xmalloc (uae_u8, arram_size + sizeof ar_custom + sizeof ar_ciaa + sizeof ar_ciab + 1024); - save_u8 (0); + save_u8 (1 | ((regs.spcflags & SPCFLAG_ACTION_REPLAY) ? 2 : 0) | (ar_hide ? 4 : 0)); save_u8 (armodel); save_u32 (get_crc32 (armemory_rom + 4, arrom_size - 4)); save_string (currprefs.cartfile); @@ -2137,6 +2114,9 @@ uae_u8 *save_action_replay (int *len, uae_u8 *dstptr) save_u32 (sizeof ar_ciab); memcpy (dst, ar_ciab, sizeof ar_ciab); dst += sizeof ar_ciab; + save_u8(action_replay_flag); + save_u8(armode_read); + save_u8(armode_write); *len = dst - dstbak; return dstbak; } @@ -2144,9 +2124,10 @@ uae_u8 *save_action_replay (int *len, uae_u8 *dstptr) uae_u8 *restore_action_replay (uae_u8 *src) { TCHAR *s; + uae_u32 flags; action_replay_unload (1); - restore_u8 (); + flags = restore_u8 (); armodel = restore_u8 (); if (!armodel) return src; @@ -2170,12 +2151,43 @@ uae_u8 *restore_action_replay (uae_u8 *src) src += sizeof ar_ciaa; restore_u32 (); src += sizeof ar_ciab; - action_replay_flag = ACTION_REPLAY_IDLE; - if (is_ar_pc_in_rom ()) - action_replay_flag = ACTION_REPLAY_ACTIVE; + armode_read = armode_write = 0; + ar_state1 = -1; + ar_state2 = -1; + if (flags & 1) { + ar_state1 = restore_u8(); + ar_state2 = 0; + armode_read = restore_u8(); + armode_write = restore_u8(); + if (flags & 2) + ar_state2 |= 1; + if (flags & 4) + ar_state2 |= 2; + } else { + action_replay_flag = ACTION_REPLAY_IDLE; + if (is_ar_pc_in_rom ()) + action_replay_flag = ACTION_REPLAY_ACTIVE; + } return src; } +void restore_ar_finish(void) +{ + if (ar_state2 < 0) { + if (m68k_getpc () >= arrom_start && m68k_getpc () <= arrom_start + arrom_size) { + action_replay_flag = ACTION_REPLAY_ACTIVE; + hide_cart (0); + } else { + action_replay_flag = ACTION_REPLAY_IDLE; + hide_cart (1); + } + } else { + action_replay_flag = ar_state1; + if (ar_state2 & 1) + set_special (SPCFLAG_ACTION_REPLAY); + hide_cart((ar_state2 & 2) ? 1 : 0); + } +} #define NPSIZE 65536 diff --git a/include/savestate.h b/include/savestate.h index 4c713e69..d06085fb 100644 --- a/include/savestate.h +++ b/include/savestate.h @@ -216,6 +216,7 @@ extern uae_u8 *restore_action_replay (uae_u8 *); extern uae_u8 *save_action_replay (int *, uae_u8 *); extern uae_u8 *restore_hrtmon (uae_u8 *); extern uae_u8 *save_hrtmon (int *, uae_u8 *); +extern void restore_ar_finish (void); extern void savestate_initsave (const TCHAR *filename, int docompress, int nodialogs, bool save); extern int save_state (const TCHAR *filename, const TCHAR *description); diff --git a/savestate.cpp b/savestate.cpp index 94aec00b..be34fb56 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -771,6 +771,9 @@ void savestate_restore_finish (void) restore_a2065_finish (); #endif restore_cia_finish (); +#ifdef ACTION_REPLAY + restore_ar_finish(); +#endif restore_debug_memwatch_finish (); savestate_state = 0; init_hz_normal();