summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpierre <pierre@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-07 15:58:42 +0000
committerpierre <pierre@3ad0048d-3df7-0310-abae-a5850022a9f2>2021-04-07 15:58:42 +0000
commitc53634d4bcd98528c7219a895935ca826c94a613 (patch)
tree63410d24d444a42352e1e78da086c199ae1ba1bb
parent428daa671221a4f15a6d3629c513ba959b0da647 (diff)
downloadfpc-c53634d4bcd98528c7219a895935ca826c94a613.tar.gz
Add basic support for setting argc and argv for sinclairql OS
git-svn-id: https://svn.freepascal.org/svn/fpc/trunk@49134 3ad0048d-3df7-0310-abae-a5850022a9f2
-rw-r--r--rtl/sinclairql/si_prc.pp33
-rw-r--r--rtl/sinclairql/system.pp42
2 files changed, 75 insertions, 0 deletions
diff --git a/rtl/sinclairql/si_prc.pp b/rtl/sinclairql/si_prc.pp
index 90e49c1b2c..1b611c9e73 100644
--- a/rtl/sinclairql/si_prc.pp
+++ b/rtl/sinclairql/si_prc.pp
@@ -26,6 +26,15 @@ var
binend: byte; external name '_etext';
bssstart: byte; external name '_sbss';
bssend: byte; external name '_ebss';
+ a4_at_entry : dword;
+ a5_at_entry : dword;
+ a6_at_entry : dword;
+ a7_at_entry : dword;
+ nb_ChannelIds : word;
+ pChannelIds : pdword;
+ pData : pointer;
+ CmdLine_len : word; public name '__CmdLine_len';
+ pCmdLine : pchar; public name '__pCmdLine';
procedure PascalMain; external name 'PASCALMAIN';
procedure PascalStart; forward;
@@ -41,6 +50,30 @@ asm
dc.l $46504300 { Job name, just FPC for now }
@start:
+ { According to QDOS:SMS reference manual }
+ { Section 3.2 v 4.4 (10/06/2018) }
+ move.l a4,d0
+ move.l d0,a4_at_entry
+ move.l a5,d0
+ move.l d0,a5_at_entry
+ move.l a6,d0
+ move.l d0,a6_at_entry
+ move.l a7,d0
+ move.l d0,a7_at_entry
+
+ move.w (a7),d0
+ move.w d0,nb_ChannelIds
+ add.l #2,d0
+ move.l d0,pChannelIds
+ move.l a6,d0
+ add.l a4,d0
+ move.l d0,pData
+ move.l a6,d0
+ add.l a5,d0
+ move.l d0,a0
+ move.w (a0),CmdLine_Len
+ add.l #2,d0
+ move.l d0,pCmdLine
{ relocation code }
{ get our actual position in RAM }
diff --git a/rtl/sinclairql/system.pp b/rtl/sinclairql/system.pp
index 45d8d82548..97cc15fc51 100644
--- a/rtl/sinclairql/system.pp
+++ b/rtl/sinclairql/system.pp
@@ -109,8 +109,50 @@ begin
GetProcessID := mt_inf(nil, nil);
end;
+var
+ CmdLine_len : word; external name '__CmdLine_len';
+ pCmdLine : pchar; external name '__pCmdLine';
procedure SysInitParamsAndEnv;
+var
+ str_len, i : word;
+ c : char;
+ in_word : boolean;
+const
+ word_separators=[' ',#0];
begin
+ str_len:=CmdLine_len;
+ argc:=0;
+ argv:=nil;
+ args:=pCmdLine;
+ if not assigned(args) then
+ exit;
+ { Parse command line }
+ { Compute argc imply replace spaces by #0 }
+ i:=0;
+ in_word:=false;
+ while (i < str_len) do
+ begin
+ c:=args[i];
+ if (not in_word) then
+ begin
+ if not(c in word_separators) then
+ begin
+ inc(argc);
+ argv[argc]:=@args[i];
+ in_word:=true;
+ end
+ else
+ begin
+ args[i]:=#0;
+ end;
+ end
+ else if (c in word_separators) then
+ begin
+ in_word:=false;
+ args[i]:=#0;
+ end;
+ inc(i);
+ end;
end;
procedure randomize;