From 21a3dd03296942d07ca0527f0ad2ad06ee410a31 Mon Sep 17 00:00:00 2001
From: Miro Kropacek <[EMAIL REDACTED]>
Date: Thu, 1 Oct 2026 14:14:54 +1000
Subject: [PATCH] atari: -mfastcall fixes
---
configure | 3 ++
configure.ac | 4 ++
src/video/ataricommon/SDL_atarieddi.S | 5 +-
src/video/ataricommon/SDL_ikbdinterrupt.S | 8 ++++
src/video/ataricommon/SDL_xbiosinterrupt.S | 54 +++++++++++++++++++---
5 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/configure b/configure
index 590092e1e..b44eeca91 100755
--- a/configure
+++ b/configure
@@ -21358,6 +21358,9 @@ else
enable_atari_ldg=yes
fi
+ if $CC $CFLAGS -dM -E - </dev/null | grep -q __FASTCALL__; then
+ enable_atari_ldg=no
+ fi
if test x$video_gem = xyes -a x$enable_atari_ldg = xyes; then
ac_fn_c_check_header_mongrel "$LINENO" "ldg.h" "ac_cv_header_ldg_h" "$ac_includes_default"
if test "x$ac_cv_header_ldg_h" = xyes; then :
diff --git a/configure.ac b/configure.ac
index c21a2f4f4..cca267231 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2188,6 +2188,10 @@ CheckAtariLdg()
AC_ARG_ENABLE(atari-ldg,
[AS_HELP_STRING([--enable-atari-ldg], [use Atari LDG for shared object loading [default=yes]])],
, enable_atari_ldg=yes)
+ dnl LDG modules are built for the default calling convention
+ if $CC $CFLAGS -dM -E - </dev/null | grep -q __FASTCALL__; then
+ enable_atari_ldg=no
+ fi
if test x$video_gem = xyes -a x$enable_atari_ldg = xyes; then
AC_CHECK_HEADER(ldg.h, have_ldg_hdr=yes)
AC_CHECK_LIB(ldg, ldg_open, have_ldg_lib=yes, have_ldg_lib=no, -lgem)
diff --git a/src/video/ataricommon/SDL_atarieddi.S b/src/video/ataricommon/SDL_atarieddi.S
index dbc127dcf..c01008dfa 100644
--- a/src/video/ataricommon/SDL_atarieddi.S
+++ b/src/video/ataricommon/SDL_atarieddi.S
@@ -35,13 +35,14 @@
/*--- Vector installer ---*/
SYM(Atari_get_EdDI_version):
-#if defined(__mcoldfire__)
+#if !defined(__FASTCALL__)
movel sp@(4),a0
+#endif
movel a0,eddi_cookie
+#if defined(__mcoldfire__)
lea sp@(-8),sp
moveml d2/a2,sp@
#else
- movel sp@(4),eddi_cookie
moveml d2/a2,sp@-
#endif
diff --git a/src/video/ataricommon/SDL_ikbdinterrupt.S b/src/video/ataricommon/SDL_ikbdinterrupt.S
index be30a8069..4cfa02f81 100644
--- a/src/video/ataricommon/SDL_ikbdinterrupt.S
+++ b/src/video/ataricommon/SDL_ikbdinterrupt.S
@@ -115,12 +115,20 @@ ikbd_installed:
movew d1,sp@-
+#ifdef __FASTCALL__
+ movel ikbd_kbdvecs,d0
+ addil #32,d0
+ movel #0x4c53444c,d1 /* "LSDL" */
+ lea ikbd,a0
+ jsr SYM(Atari_UnhookXbra)
+#else
pea ikbd
movel #0x4c53444c,sp@- /* "LSDL" */
movel ikbd_kbdvecs,a0
pea a0@(32)
jsr SYM(Atari_UnhookXbra)
lea sp@(12),sp
+#endif
movew sp@+,d1
diff --git a/src/video/ataricommon/SDL_xbiosinterrupt.S b/src/video/ataricommon/SDL_xbiosinterrupt.S
index 9b8f9ea32..fd18f0f58 100644
--- a/src/video/ataricommon/SDL_xbiosinterrupt.S
+++ b/src/video/ataricommon/SDL_xbiosinterrupt.S
@@ -182,11 +182,19 @@ no_ikbd_packet_restore:
#else
moveml d1/a0,sp@-
#endif
+#ifdef __FASTCALL__
+ lea a0@(16),a1
+ movel a1,d0
+ movel #0x4c53444c,d1 /* "LSDL" */
+ lea newmousevector(pc),a0
+ jsr SYM(Atari_UnhookXbra)
+#else
pea newmousevector(pc)
movel #0x4c53444c,sp@- /* "LSDL" */
pea a0@(16)
jsr SYM(Atari_UnhookXbra)
lea sp@(12),sp
+#endif
clrl oldmousevector
#if defined(__mcoldfire__)
@@ -203,16 +211,33 @@ no_restore_mouse:
tstl oldjoystickvector
beqs no_restore_joystick
- movew d1,sp@-
-
+#if defined(__mcoldfire__)
+ lea sp@(-8),sp
+ moveml d1/a0,sp@
+#else
+ moveml d1/a0,sp@-
+#endif
+#ifdef __FASTCALL__
+ lea a0@(24),a1
+ movel a1,d0
+ movel #0x4c53444c,d1 /* "LSDL" */
+ lea newjoystickvector(pc),a0
+ jsr SYM(Atari_UnhookXbra)
+#else
pea newjoystickvector(pc)
movel #0x4c53444c,sp@- /* "LSDL" */
pea a0@(24)
jsr SYM(Atari_UnhookXbra)
lea sp@(12),sp
+#endif
clrl oldjoystickvector
- movew sp@+,d1
+#if defined(__mcoldfire__)
+ moveml sp@,d1/a0
+ lea sp@(8),sp
+#else
+ moveml sp@+,d1/a0
+#endif
no_restore_joystick:
@@ -221,16 +246,33 @@ no_restore_joystick:
tstl oldkeyboardvector
beqs no_restore_keyboard
- movew d1,sp@-
-
+#if defined(__mcoldfire__)
+ lea sp@(-8),sp
+ moveml d1/a0,sp@
+#else
+ moveml d1/a0,sp@-
+#endif
+#ifdef __FASTCALL__
+ lea a0@(-4),a1
+ movel a1,d0
+ movel #0x4c53444c,d1 /* "LSDL" */
+ lea newkeyboardvector(pc),a0
+ jsr SYM(Atari_UnhookXbra)
+#else
pea newkeyboardvector(pc)
movel #0x4c53444c,sp@- /* "LSDL" */
pea a0@(-4)
jsr SYM(Atari_UnhookXbra)
lea sp@(12),sp
+#endif
clrl oldkeyboardvector
- movew sp@+,d1
+#if defined(__mcoldfire__)
+ moveml sp@,d1/a0
+ lea sp@(8),sp
+#else
+ moveml sp@+,d1/a0
+#endif
no_restore_keyboard: