(*    THIS SOURCE CODE CONTAINS SEVERAL USEFUL FUNCTIONS FOR TURBO PASCAL.
      THIS IS A SOURCE CODE AND SHOULD NOT BE COMPILED SEPARATELY.  IN
      ORDER TO USE THESE FUNCTIONS, A PROGRAM USING THESE SHOULD INCLUDE
      THE STATEMENT '{$I FUNCTION.PAS}', AND THIS PROGRAM SHOULD BE ON
      THE SAME DISK AS THE CALLING PROGRAM.     *)

TYPE
   ZZZZZ1 = STRING[1];
   ZZZZZ5 = STRING[11];
   ZZZZZ2 = STRING[80];

FUNCTION TAB(TABSPACE:INTEGER): ZZZZZ1;
   BEGIN
   GOTOXY(TABSPACE, WHEREY);
   TAB:='';
   END;

FUNCTION SPC(SPCE:INTEGER): ZZZZZ2;
   TYPE
      ZZZZZ3=STRING[80];

   VAR
      ZZZZZ4:ZZZZZ3;

   BEGIN
   ZZZZZ4:='';
   WHILE SPCE<>0 DO
      BEGIN
      SPCE:=SPCE-1;
      ZZZZZ4:=ZZZZZ4+' ';
      END;
   SPC:=ZZZZZ4;
   END;

FUNCTION MIN(INT1, INT2:INTEGER):INTEGER;
   BEGIN
   IF INT1>INT2 THEN MIN:=INT2 ELSE MIN:=INT1;
   END;

FUNCTION MAX(INT1, INT2:INTEGER):INTEGER;
   BEGIN
   IF INT1>INT2 THEN MAX:=INT1 ELSE MAX:=INT2;
   END;

FUNCTION MINR(REAL1, REAL2:REAL):REAL;
   BEGIN
   IF REAL1>REAL2 THEN MINR:=REAL2 ELSE MINR:=REAL1;
   END;

FUNCTION MAXR(REAL1, REAL2:REAL):REAL;
   BEGIN
   IF REAL1>REAL2 THEN MAXR:=REAL1 ELSE MAXR:=REAL2;
   END;

PROCEDURE SWITCH(VAR INT1, INT2:INTEGER);
   VAR
      TEMP: INTEGER;


   BEGIN
   TEMP:=INT1;
   INT1:=INT2;
   INT2:=TEMP;
   END;

PROCEDURE SWITCHR(VAR REAL1, REAL2:REAL);
   VAR
      TEMP: REAL;

   BEGIN
   TEMP:=REAL1;
   REAL1:=REAL2;
   REAL2:=TEMP;
   END;

FUNCTION DATE:ZZZZZ5;

   TYPE
      RESULT = RECORD
               AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: INTEGER;
               END;
      STRING11 = STRING[11];

   VAR
      DATERESULT: RESULT;
      PARTDATE, TMPDATE: STRING11;

   BEGIN
      PARTDATE := '           ';
      DATERESULT.AX := $2A00;
      INTR($21,DATERESULT);
      STR(DATERESULT.DX DIV 256, TMPDATE);
      IF LENGTH(TMPDATE) = 1 THEN TMPDATE := ' ' + TMPDATE;
      INSERT(TMPDATE, PARTDATE, 1);
      PARTDATE[3] := '-';
      STR(DATERESULT.DX MOD 256, TMPDATE);
      IF LENGTH(TMPDATE) = 1 THEN TMPDATE := ' ' + TMPDATE;
      INSERT(TMPDATE, PARTDATE, 4);
      PARTDATE[6] := '-';
      STR(DATERESULT.CX, TMPDATE);
      INSERT(TMPDATE, PARTDATE, 7);
      DATE := PARTDATE;
   END;

FUNCTION TIME: ZZZZZ5;

   TYPE
      RESULT = RECORD
               AX,BX,CX,DX,BP,SI,DI,DS,ES,FLAGS: INTEGER;
               END;
      STRING11 = STRING[11];

   VAR
      TIMERESULT: RESULT;
      PARTTIME, TMPTIME: STRING11;

   BEGIN
      PARTTIME := '           ';
      TIMERESULT.AX := $2C00;
      INTR($21,TIMERESULT);
      STR(TIMERESULT.CX DIV 256, TMPTIME);
      IF LENGTH(TMPTIME) = 1 THEN TMPTIME := ' ' + TMPTIME;
      INSERT(TMPTIME, PARTTIME, 1);
      PARTTIME[3] := ':';
      STR(TIMERESULT.CX MOD 256, TMPTIME);
      IF LENGTH(TMPTIME) = 1 THEN TMPTIME := '0' + TMPTIME;
      INSERT(TMPTIME, PARTTIME, 4);
      PARTTIME[6] := ':';
      STR(TIMERESULT.DX DIV 256, TMPTIME);
      IF LENGTH(TMPTIME) = 1 THEN TMPTIME := '0' + TMPTIME;
      INSERT(TMPTIME, PARTTIME, 7);
      PARTTIME[9] := ':';
      STR(TIMERESULT.DX MOD 256, TMPTIME);
      IF LENGTH(TMPTIME) = 1 THEN TMPTIME := '0' + TMPTIME;
      INSERT(TMPTIME, PARTTIME, 10);
      TIME := PARTTIME;
   END;

FUNCTION FLOAT(INT1: INTEGER): REAL;

   BEGIN
      FLOAT:=INT1/1;
   END;
