From b3cbf07f27bd59c1988ff5055f82dd1f092d6f19 Mon Sep 17 00:00:00 2001
From: Karoly Balogh <karoly@freepascal.org>
Date: Tue, 25 Jan 2022 23:14:34 +0100
Subject: [PATCH] + m68k-atari: fixed bogus TOS program flags passed to VLink.
 added -WF argument to allow the user to specify their own flags if needed

---
 compiler/globals.pas         |  3 +++
 compiler/msg/errore.msg      |  1 +
 compiler/options.pas         | 14 ++++++++++++++
 compiler/systems/t_atari.pas |  2 +-
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/compiler/globals.pas b/compiler/globals.pas
index 159ed186c0..890e667c3e 100644
--- a/compiler/globals.pas
+++ b/compiler/globals.pas
@@ -416,6 +416,9 @@ interface
        palmos_applicationid : string[4] = 'FPCA';
 {$endif defined(m68k) or defined(arm)}
 {$if defined(m68k)}
+       { Atari Specific }
+       ataritos_exe_flags: dword = 7;
+
        { Sinclair QL specific }
        sinclairql_metadata_format: string[4] = 'QHDR';
        sinclairql_vlink_experimental: boolean = true; { temporary }
diff --git a/compiler/msg/errore.msg b/compiler/msg/errore.msg
index cff81b2197..c9c1dcdda6 100644
--- a/compiler/msg/errore.msg
+++ b/compiler/msg/errore.msg
@@ -4327,6 +4327,7 @@ A*2We_Use external resources (Darwin)
 P*2We_Use external resources (Darwin)
 p*2We_Use external resources (Darwin)
 3*2WF_Specify full-screen type application (EMX, OS/2)
+6*2WF<x>_Set TOS program flags to <x> (Atari)
 3*2WG_Specify graphic type application (EMX, OS/2, Windows)
 4*2WG_Specify graphic type application (Windows)
 A*2WG_Specify graphic type application (Windows)
diff --git a/compiler/options.pas b/compiler/options.pas
index 4deacbc5b3..97e9bf1d8b 100644
--- a/compiler/options.pas
+++ b/compiler/options.pas
@@ -2810,6 +2810,20 @@ begin
                       end;
                     'F':
                       begin
+{$if defined(m68k)}
+                        if target_info.system in [system_m68k_atari] then
+                          begin
+                            if (length(More)>j) then
+                              begin
+                                val(Copy(More,j+1,255),ataritos_exe_flags,code);
+                                if code<>0 then
+                                  IllegalPara(opt);
+                              end
+                            else
+                              IllegalPara(opt);
+                            break;
+                          end;
+{$endif defined(m68k)}
                         if target_info.system in systems_os2 then
                           begin
                             if UnsetBool(More, j, opt, false) then
diff --git a/compiler/systems/t_atari.pas b/compiler/systems/t_atari.pas
index bc0f95011b..aaa333fa80 100644
--- a/compiler/systems/t_atari.pas
+++ b/compiler/systems/t_atari.pas
@@ -224,7 +224,7 @@ begin
   GCSectionsStr:='';
   DynLinkStr:='';
   MapStr:='';
-  FlagsStr:='-tos-flags fastload,fastram';
+  FlagsStr:='-tos-flags '+tostr(ataritos_exe_flags);
 
   if UseVlink and (cs_link_map in current_settings.globalswitches) then
     MapStr:='-M'+maybequoted(ScriptFixFileName(current_module.mapfilename));