Unit pr_built;

Interface

Uses pr_defs, progdefs, math, strings, console, pr_bdef, mathfunc;

Implementation

Procedure pf_write;
Var s : PChar;
    os: String;
    o : LongInt;
Begin
  s := G_STRING(OFS_PARM0);
  os := ''; o := OFS_PARM0;
  While s^ <> #0 Do Begin
    Case s^ Of
      '%': Case (s+1)^ Of
             'f': Begin
                    o := o + 3;
                    os := os + tofloat(G_FLOAT(o));
                    Inc(s,2);
                  End;
             'v': Begin
                    o := o + 3;
                    os := os + tovec(G_VECTOR(o));
                    Inc(s,2);
                  End;
             'i': Begin
                    o := o + 3;
                    os := os + itos(G_INT(o));
                    Inc(s,2);
                  End;
             '%': Begin os := os + '%'; Inc(s,2); End;
             else PR_RunError('Illegal % format for Write()');
           End;
      else Begin os := os + s^; Inc(s); End;
    End;
  End;
  Con_Write(os);
End;

Procedure pf_writeln;
Var s : PChar;
    os: String;
    o : LongInt;
Begin
  s := G_STRING(OFS_PARM0);
  os := ''; o := OFS_PARM0;
  While s^ <> #0 Do Begin
    Case s^ Of
      '%': Case (s+1)^ Of
             'f': Begin
                    o := o + 3;
                    os := os + tofloat(G_FLOAT(o));
                    Inc(s,2);
                  End;
             'v': Begin
                    o := o + 3;
                    os := os + tovec(G_VECTOR(o));
                    Inc(s,2);
                  End;
             'i': Begin
                    o := o + 3;
                    os := os + itos(G_INT(o));
                    Inc(s,2);
                  End;
             '%': Begin os := os + '%'; Inc(s,2); End;
             else PR_RunError('Illegal % format for Write()');
           End;
      else Begin os := os + s^; Inc(s); End;
    End;
  End;
  Con_WriteLn(os);
End;

Procedure pf_findradius;
Begin
  pr_globals^[OFS_RETURN] := 0;
End;

Procedure pf_set_precision;
Begin
  _D := Trunc(G_FLOAT(OFS_PARM0));
  _N := Trunc(G_FLOAT(OFS_PARM1));
End;

Procedure pf_spawn;
Begin
  pr_globals^[OFS_RETURN] := intfloat(Spawn);
End;

Procedure pf_remove;
Begin
  Remove(G_INT(OFS_PARM0));
End;

Var pt : Array[0..127] Of Char;

Var i : Byte;
Begin
  _D := 6; _N := 3;
  pr_numbuiltins := PR_BUILTS;
  { All built-in functions default to an empty procedure }
  For i := 1 To PR_BUILTS Do pr_builtins[i] := SUB_Null;
  { These should match EXACTLY with the DEFS.BP file's definitions.}
  pr_builtins[1] := pf_write;
  pr_builtins[2] := pf_spawn;
  pr_builtins[3] := pf_remove;
  pr_builtins[4] := pf_sqrt;
  pr_builtins[5] := pf_sin;
  pr_builtins[6] := pf_cos;
  pr_builtins[7] := pf_tan;
  pr_builtins[8] := pf_csc;
  pr_builtins[9] := pf_sec;
  pr_builtins[10] := pf_cot;
  pr_builtins[11] := pf_arcsin;
  pr_builtins[12] := pf_arccos;
  pr_builtins[13] := pf_arctan;
  pr_builtins[14] := pf_normalize;
  pr_builtins[15] := pf_vlen;
  pr_builtins[16] := pf_findradius;

  pr_builtins[254] := pf_writeln;
  pr_builtins[255] := pf_set_precision;
End.
