SDL-1.2: atari: SDL_AtariIkbd_Restore as etv_term

From 6ff63e6fe6b117d5dbd7fb7e1cd56036c542675f Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Sat, 20 Apr 2019 23:15:52 +0200
Subject: [PATCH] atari: SDL_AtariIkbd_Restore as etv_term

---
 src/video/ataricommon/SDL_ikbdevents.c    |  1 +
 src/video/ataricommon/SDL_ikbdinterrupt.S | 17 +++++++++++++++++
 2 files changed, 18 insertions(+)

diff --git a/src/video/ataricommon/SDL_ikbdevents.c b/src/video/ataricommon/SDL_ikbdevents.c
index a9087942..b89f543f 100644
--- a/src/video/ataricommon/SDL_ikbdevents.c
+++ b/src/video/ataricommon/SDL_ikbdevents.c
@@ -52,6 +52,7 @@ void AtariIkbd_InitOSKeymap(_THIS)
 	atari_prevmouseb = 0;
 
 	Supexec(SDL_AtariIkbd_Install);
+	Setexc(VEC_PROCTERM, SDL_AtariIkbd_Restore);
 }
 
 static int atari_GetButton(int button)
diff --git a/src/video/ataricommon/SDL_ikbdinterrupt.S b/src/video/ataricommon/SDL_ikbdinterrupt.S
index 6f42ff6d..a822c89b 100644
--- a/src/video/ataricommon/SDL_ikbdinterrupt.S
+++ b/src/video/ataricommon/SDL_ikbdinterrupt.S
@@ -113,6 +113,16 @@ _SDL_AtariIkbd_Restore:
 	rts
 
 ikbd_installed:
+        /*
+         * even though SDL_AtariXbios_Restore() is called via Supexec(),
+         * it is also a etv_term vector which needs to preserve all registers
+         */
+#if defined(__mcoldfire__)
+        lea	sp@(-8),sp
+        moveml	d1/a0,sp@
+#else
+        moveml	d1/a0,sp@-
+#endif
 	| Disable interrupts
 
 	movew	sr,d1
@@ -158,6 +168,13 @@ ikbd_finbuffer:
 	| Interrupts done
 
 	clrw	_SDL_AtariIkbd_enabled
+
+#if defined(__mcoldfire__)
+        moveml	sp@,d1-/a0
+        lea	sp@(8),sp
+#else
+        moveml	sp@+,d1/a0
+#endif
 	rts
 
 	.bss