UNIT System;

INTERFACE

CONST KERNEL32='kernel32.dll';

TYPE HRESULT=LONGINT;
     HINST=LONGWORD;
     HMODULE=HINST;
     PLONGWORD=^LONGWORD;
     PWORD=^WORD;
     PBYTE=^BYTE;
     PSHORTSTRING=^SHORTSTRING;
     PANSISTRING=^ANSISTRING;
     PWIDESTRING=^WIDESTRING;
     PSTRING=PANSISTRING;
     PEXTENDED=^EXTENDED;
     PCURRENCY=^CURRENCY;
     PVARIANT=^VARIANT;
     POLEVARIANT= ^OLEVARIANT;
     PINT64=^INT64;
     TDateTime=DOUBLE;
     PDateTime=^TDateTime;

     PGUID=^TGUID;
     TGUID=RECORD
      D1:CARDINAL;
      D2:WORD;
      D3:WORD;
      D4:ARRAY[0..7] OF BYTE;
     END;

VAR HInstance:LONGWORD;
    HKernel32:HMODULE;
    HUser32:HMODULE;
    ExitCode:LONGWORD;
    IsConsole:BOOLEAN;

PROCEDURE ExitProcess(uExitCode:LONGWORD); STDCALL; EXTERNAL kernel32 NAME 'ExitProcess';
PROCEDURE Move(CONST Source;VAR Dest;Count:INTEGER); ASSEMBLER; REGISTER;
PROCEDURE _COS;
PROCEDURE _SIN;
PROCEDURE _EXP;
PROCEDURE _FillChar; REGISTER;
PROCEDURE _InitExe;
PROCEDURE _halt0;
PROCEDURE _HandleFinally;

IMPLEMENTATION

PROCEDURE Move(CONST Source;VAR Dest;Count:INTEGER); ASSEMBLER; REGISTER;
ASM
 PUSH ESI
 PUSH EDI
 MOV ESI,EAX
 MOV EDI,EBX
 REP MOVSB
 POP EDI
 POP ESI
END;

PROCEDURE _COS; ASSEMBLER;
ASM
 FCOS
END;

PROCEDURE _SIN; ASSEMBLER;
ASM
 FSIN
END;

PROCEDURE _EXP; ASSEMBLER;
ASM
 FLDL2E
 FMUL
 FLD ST(0)
 FRNDINT
 FSUB ST(1),ST
 FXCH ST(1)
 F2XM1
 FLD1
 FADD
 FSCALE         
 FSTP ST(1)
END;

PROCEDURE _FillChar; ASSEMBLER; REGISTER;
ASM
 PUSH EDI
 MOV EDI,EAX
 MOV EAX,ECX
 MOV ECX,EDX
 REP STOSB
 POP EDI
END;

PROCEDURE _InitExe;
ASM
END;

PROCEDURE _InitLib;
ASM
END;

PROCEDURE _halt0;
ASM
 PUSH ExitCode
 CALL ExitProcess
END;

PROCEDURE _HandleFinally; ASSEMBLER;
ASM
END;

END.