[PATCH 1/2] Sync host mouse position to Atari one if line-A base is known

[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]


Do this when resolution is changed (instead of warping host mouse to
middle of screen) and when Hatari window is entered.  Mouse position
sync is based on TOS line-A mouse co-ordinates at negative offsets
from line-A base.

I've tested this to work with TOS versions 1.04 - TOS 4.04 and EmuTOS
(cartridge code which does the line-A call to get the base address is
used only when GEMDOS HD or VDI mode is enabled and that's not
supported for the first TOS versions).
---
 src/includes/vdi.h |  1 +
 src/main.c         |  7 +++++++
 src/screen.c       | 11 +++++++++--
 src/vdi.c          | 20 +++++++++++++++++++-
 4 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/src/includes/vdi.h b/src/includes/vdi.h
index 78afd1ba..cabd8d1a 100644
--- a/src/includes/vdi.h
+++ b/src/includes/vdi.h
@@ -51,6 +51,7 @@ extern void AES_Info(FILE *fp, Uint32 bShowOpcodes);
 extern void VDI_Info(FILE *fp, Uint32 bShowOpcodes);
 extern bool VDI_AES_Entry(void);
 extern void VDI_LineA(Uint32 LineABase, Uint32 FontBase);
+extern bool VDI_GetMousePos(int *x, int *y);
 extern void VDI_Complete(void);
 extern void VDI_Reset(void);
 
diff --git a/src/main.c b/src/main.c
index e1a6f191..52794f41 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,6 +52,7 @@ const char Main_fileid[] = "Hatari main.c : " __DATE__ " " __TIME__;
 #include "stMemory.h"
 #include "str.h"
 #include "tos.h"
+#include "vdi.h"
 #include "video.h"
 #include "avi_record.h"
 #include "debugui.h"
@@ -653,6 +654,12 @@ void Main_EventHandler(void)
 			{
 				SDL_UpdateRect(sdlscrn, 0, 0, 0, 0);
 			}
+			if (event.window.event == SDL_WINDOWEVENT_ENTER)
+			{
+				int x, y;
+				if (VDI_GetMousePos(&x, &y))
+					Main_WarpMouse(x * nScreenZoomX, y * nScreenZoomX, false);
+			}
 			bContinueProcessing = true;
 			break;
 #endif /* WITH_SDL2 */
diff --git a/src/screen.c b/src/screen.c
index 2db89d1b..5e07feff 100644
--- a/src/screen.c
+++ b/src/screen.c
@@ -1369,7 +1369,7 @@ void Screen_SetGenConvSize(int width, int height, int bpp, bool bForceChange)
 {
 	const bool keep = ConfigureParams.Screen.bKeepResolution;
 	int screenwidth, screenheight, maxw, maxh;
-	int scalex, scaley, sbarheight;
+	int scalex, scaley, sbarheight, x, y;
 
 	if (bpp == 24)
 		bpp = 32;
@@ -1499,7 +1499,14 @@ void Screen_SetGenConvSize(int width, int height, int bpp, bool bForceChange)
 			sdlscrn->format->Rshift, sdlscrn->format->Gshift, sdlscrn->format->Bshift,
 			sdlscrn->format->Rloss, sdlscrn->format->Gloss, sdlscrn->format->Bloss));
 
-	Main_WarpMouse(sdlscrn->w/2,sdlscrn->h/2, false);
+	if (VDI_GetMousePos(&x, &y)) {
+		x *= nScreenZoomX;
+		y *= nScreenZoomX;
+	} else {
+		x = sdlscrn->w/2;
+		y = sdlscrn->h/2;
+	}
+	Main_WarpMouse(x, y, false);
 }
 
 void Screen_GenConvUpdate(SDL_Rect *extra, bool forced)
diff --git a/src/vdi.c b/src/vdi.c
index d51232ca..35e5fbf9 100644
--- a/src/vdi.c
+++ b/src/vdi.c
@@ -62,12 +62,14 @@ static Uint16 AESOpCode;
 
 /*-----------------------------------------------------------------------*/
 /**
- * Called to reset VDI variables on reset.
+ * Called to reset VDI & LineA variables on reset.
  */
 void VDI_Reset(void)
 {
 	/* no VDI calls in progress */
 	VDI_OldPC = 0;
+	/* LineA base address is still unknown */
+	LineABase = 0;
 }
 
 /*-----------------------------------------------------------------------*/
@@ -825,6 +827,22 @@ void VDI_LineA(Uint32 linea, Uint32 fontbase)
 	}
 }
 
+/*-----------------------------------------------------------------------*/
+/**
+ * Get mouse x, y position from LineA variables if LineABase is known,
+ * to be used for mouse position synchronization with host.
+ *
+ * Return true for success, false for failure
+ */
+bool VDI_GetMousePos(int *x, int *y)
+{
+	if (!LineABase) {
+		return false;
+	}
+	*x = STMemory_ReadWord(LineABase - 602);  /* GCURX */
+	*y = STMemory_ReadWord(LineABase - 600);  /* GCURY */
+	return true;
+}
 
 /*-----------------------------------------------------------------------*/
 /**
-- 
2.20.1


--------------0629368FBCC8BC04038AF43D--



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/