From 513d69e89683480e69999362dca1d689da568f4d Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Thu, 12 Jul 2018 21:45:48 +0300 Subject: [PATCH] Prevent clipboard activity immediately after mode changes delaying automatic host to Amiga transfers, it is possible mode change means program switching to native from RTG and taking over the system. --- devices.cpp | 5 ++++ drawing.cpp | 2 ++ filesys.cpp | 7 +++-- include/clipboard.h | 1 + include/devices.h | 1 + od-win32/clipboard_win32.cpp | 51 +++++++++++++++++++++++++----------- od-win32/win32gfx.cpp | 3 +++ 7 files changed, 53 insertions(+), 17 deletions(-) diff --git a/devices.cpp b/devices.cpp index e6760c4e..bc032020 100644 --- a/devices.cpp +++ b/devices.cpp @@ -500,3 +500,8 @@ void devices_unpause(void) pausevideograb(0); ethernet_pause(0); } + +void devices_unsafeperiod(void) +{ + clipboard_unsafeperiod(); +} diff --git a/drawing.cpp b/drawing.cpp index 7c92d3a3..b55f1479 100644 --- a/drawing.cpp +++ b/drawing.cpp @@ -3954,6 +3954,8 @@ void check_prefs_picasso(void) if (ad->picasso_requested_on == ad->picasso_on && !ad->picasso_requested_forced_on) continue; + + devices_unsafeperiod(); if (!ad->picasso_requested_on && monid > 0) { ad->picasso_requested_on = ad->picasso_on; diff --git a/filesys.cpp b/filesys.cpp index 75b16923..3edd22a2 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -1874,12 +1874,12 @@ int filesys_eject(int nr) } static uae_u32 heartbeat; -static int heartbeat_count; +static int heartbeat_count, heartbeat_count_cont; static int heartbeat_task; bool filesys_heartbeat(void) { - return heartbeat_count > 0; + return heartbeat_count_cont > 0; } // This uses filesystem process to reduce resource usage @@ -9044,9 +9044,12 @@ void filesys_vsync (void) if (heartbeat == get_long_host(rtarea_bank.baseaddr + RTAREA_HEARTBEAT)) { if (heartbeat_count > 0) heartbeat_count--; + if (heartbeat_count_cont > 0) + heartbeat_count_cont--; return; } heartbeat = get_long_host(rtarea_bank.baseaddr + RTAREA_HEARTBEAT); + heartbeat_count_cont = 10; cia_heartbeat (); for (u = units; u; u = u->next) { diff --git a/include/clipboard.h b/include/clipboard.h index b5f4ae31..9e6cb467 100644 --- a/include/clipboard.h +++ b/include/clipboard.h @@ -11,5 +11,6 @@ extern uaecptr amiga_clipboard_proc_start(TrapContext *ctx); extern void amiga_clipboard_task_start(TrapContext *ctx, uaecptr); extern void clipboard_disable(bool); extern void clipboard_vsync(void); +extern void clipboard_unsafeperiod(void); #endif /* UAE_CLIPBOARD_H */ diff --git a/include/devices.h b/include/devices.h index bb149b36..14e784df 100644 --- a/include/devices.h +++ b/include/devices.h @@ -17,6 +17,7 @@ void devices_restore_start(void); void device_check_config(void); void devices_pause(void); void devices_unpause(void); +void devices_unsafeperiod(void); #define IRQ_SOURCE_PCI 0 #define IRQ_SOURCE_SOUND 1 diff --git a/od-win32/clipboard_win32.cpp b/od-win32/clipboard_win32.cpp index c6051b9f..6d3aad01 100644 --- a/od-win32/clipboard_win32.cpp +++ b/od-win32/clipboard_win32.cpp @@ -26,9 +26,11 @@ int clipboard_debug; static HWND chwnd; static HDC hdc; static uaecptr clipboard_data; -static int vdelay, signaling, initialized; +static int vdelay, vdelay2; +static int signaling, initialized; static uae_u8 *to_amiga; static uae_u32 to_amiga_size; +static int to_amiga_phase; static int clipopen; static int clipactive; static int clipboard_change; @@ -67,8 +69,6 @@ static void debugwrite (TrapContext *ctx, const TCHAR *name, uaecptr p, int size static uae_u32 to_amiga_start_cb(TrapContext *ctx, void *ud) { - if (!filesys_heartbeat()) - return 0; if (trap_get_long(ctx, clipboard_data) != 0) return 0; if (clipboard_debug) { @@ -79,20 +79,18 @@ static uae_u32 to_amiga_start_cb(TrapContext *ctx, void *ud) #endif trap_put_long(ctx, clipboard_data, to_amiga_size); uae_Signal(trap_get_long(ctx, clipboard_data + 8), 1 << 13); + to_amiga_phase = 2; return 1; } static void to_amiga_start(TrapContext *ctx) { + to_amiga_phase = 0; if (!initialized) return; if (!clipboard_data) return; - if (!ctx) { - trap_callback(to_amiga_start_cb, NULL); - } else { - to_amiga_start_cb(ctx, NULL); - } + to_amiga_phase = 1; } static uae_char *pctoamiga (const uae_char *txt) @@ -988,21 +986,35 @@ static uae_u32 clipboard_vsync_cb(TrapContext *ctx, void *ud) void clipboard_vsync(void) { - if (!signaling || !clipboard_data) - return; if (!filesys_heartbeat()) return; - vdelay--; - if (vdelay > 0) + if (!clipboard_data) return; - trap_callback(clipboard_vsync_cb, NULL); - vdelay = 50; + + if (signaling) { + vdelay--; + if (vdelay > 0) + return; + + trap_callback(clipboard_vsync_cb, NULL); + vdelay = 50; + } + + if (vdelay2 > 0) { + vdelay2--; + //write_log(_T("vdelay2 = %d\n"), vdelay2); + } + + if (to_amiga_phase == 1 && vdelay2 <= 0) { + trap_callback(to_amiga_start_cb, NULL); + } + } void clipboard_reset(void) { write_log (_T("clipboard: reset (%08x)\n"), clipboard_data); - vdelay = 100; + clipboard_unsafeperiod(); clipboard_free_delayed (); clipboard_data = 0; signaling = 0; @@ -1010,6 +1022,7 @@ void clipboard_reset(void) xfree (to_amiga); to_amiga = NULL; to_amiga_size = 0; + to_amiga_phase = 0; clip_disabled = false; ReleaseDC (chwnd, hdc); } @@ -1024,3 +1037,11 @@ void target_paste_to_keyboard(void) { clipboard_read(NULL, chwnd, true); } + +// force 2 second delay before accepting new data +void clipboard_unsafeperiod(void) +{ + vdelay2 = 100; + if (vdelay < 60) + vdelay = 60; +} diff --git a/od-win32/win32gfx.cpp b/od-win32/win32gfx.cpp index dc74ad99..b4e88a28 100644 --- a/od-win32/win32gfx.cpp +++ b/od-win32/win32gfx.cpp @@ -61,6 +61,7 @@ #include "rp.h" #endif #include "statusline.h" +#include "devices.h" #define DM_DX_FULLSCREEN 1 #define DM_W_FULLSCREEN 2 @@ -4287,6 +4288,7 @@ bool toggle_rtg (int monid, int mode) gfxboard_toggle(r->monitor_id, -1, -1); if (mode < -1) return true; + devices_unsafeperiod(); gfxboard_rtg_disable(monid, old_index); // can always switch from RTG to custom if (ad->picasso_requested_on && ad->picasso_on) { @@ -4360,6 +4362,7 @@ void toggle_fullscreen(int monid, int mode) v = GFX_WINDOW; } *p = v; + devices_unsafeperiod(); updatewinfsmode(monid, &changed_prefs); } -- 2.47.3