IMPLEMENTATION MODULE VarCallArgs;

FROM SYSTEM IMPORT ADR, ADDRESS;

(* This module allows you to create C-style argument lists *)


(*********************************************************************)
(* Various routines used for variable-length argument lists          *)

VAR
  ArgList : ARRAY [0..4] OF LONGCARD;


PROCEDURE ArgIs(Arg : LONGCARD) : ADDRESS;
(* Pass argument to a C-style routine *)
BEGIN
  ArgList[0] := Arg;
  ArgList[1] := 0;
  RETURN ADR(ArgList);
END ArgIs;


PROCEDURE ArgIs2(Arg1, Arg2 : LONGCARD) : ADDRESS;
(* Pass 2 arguments *)
BEGIN
  ArgList[0] := Arg1;
  ArgList[1] := Arg2;
  ArgList[2] := 0;
  RETURN ADR(ArgList);
END ArgIs2;


PROCEDURE ArgIs3(Arg1, Arg2, Arg3 : LONGCARD) : ADDRESS;
(* Pass up to 3 arguments *)
BEGIN
  ArgList[0] := Arg1;
  ArgList[1] := Arg2;
  ArgList[2] := Arg3;
  ArgList[3] := 0;
  RETURN ADR(ArgList);
END ArgIs3;


PROCEDURE ArgIs4(Arg1, Arg2, Arg3, Arg4 : LONGCARD) : ADDRESS;
(* Pass up to 4 arguments *)
BEGIN
  ArgList[0] := Arg1;
  ArgList[1] := Arg2;
  ArgList[2] := Arg3;
  ArgList[3] := Arg4;
  ArgList[4] := 0;
  RETURN ADR(ArgList);
END ArgIs4;


END VarCallArgs.