2019-10-06 19:55:12 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
Copyright (c) 2019, Anton Krotov
|
|
|
|
All rights reserved.
|
2016-10-24 01:30:27 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE HOST;
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
IMPORT SYSTEM, API, RTL;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
CONST
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
slash* = "/";
|
|
|
|
OS* = "LINUX";
|
|
|
|
|
|
|
|
bit_depth* = RTL.bit_depth;
|
|
|
|
maxint* = RTL.maxint;
|
|
|
|
minint* = RTL.minint;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
VAR
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
argc: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
eol*: ARRAY 2 OF CHAR;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE ExitProcess* (code: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
API.exit(code)
|
|
|
|
END ExitProcess;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetArg* (n: INTEGER; VAR s: ARRAY OF CHAR);
|
|
|
|
VAR
|
|
|
|
i, len, ptr: INTEGER;
|
|
|
|
c: CHAR;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
i := 0;
|
|
|
|
len := LEN(s) - 1;
|
|
|
|
IF (n < argc) & (len > 0) THEN
|
|
|
|
SYSTEM.GET(API.MainParam + (n + 1) * SYSTEM.SIZE(INTEGER), ptr);
|
|
|
|
REPEAT
|
|
|
|
SYSTEM.GET(ptr, c);
|
|
|
|
s[i] := c;
|
|
|
|
INC(i);
|
|
|
|
INC(ptr)
|
|
|
|
UNTIL (c = 0X) OR (i = len)
|
|
|
|
END;
|
|
|
|
s[i] := 0X
|
|
|
|
END GetArg;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetCurrentDirectory* (VAR path: ARRAY OF CHAR);
|
|
|
|
VAR
|
|
|
|
n: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
GetArg(0, path);
|
|
|
|
n := LENGTH(path) - 1;
|
|
|
|
WHILE path[n] # slash DO
|
|
|
|
DEC(n)
|
|
|
|
END;
|
|
|
|
path[n + 1] := 0X
|
|
|
|
END GetCurrentDirectory;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
PROCEDURE FileRead* (F: INTEGER; VAR Buffer: ARRAY OF CHAR; bytes: INTEGER): INTEGER;
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-10-06 19:55:12 +02:00
|
|
|
res := API.fread(SYSTEM.ADR(Buffer[0]), 1, bytes, F);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF res <= 0 THEN
|
|
|
|
res := -1
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END FileRead;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE FileWrite* (F: INTEGER; Buffer: ARRAY OF BYTE; bytes: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-10-06 19:55:12 +02:00
|
|
|
res := API.fwrite(SYSTEM.ADR(Buffer[0]), 1, bytes, F);
|
2019-03-11 09:59:55 +01:00
|
|
|
IF res <= 0 THEN
|
|
|
|
res := -1
|
|
|
|
END
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
RETURN res
|
|
|
|
END FileWrite;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE FileCreate* (FName: ARRAY OF CHAR): INTEGER;
|
|
|
|
RETURN API.fopen(SYSTEM.ADR(FName[0]), SYSTEM.SADR("wb"))
|
|
|
|
END FileCreate;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE FileClose* (File: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
File := API.fclose(File)
|
|
|
|
END FileClose;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE FileOpen* (FName: ARRAY OF CHAR): INTEGER;
|
|
|
|
RETURN API.fopen(SYSTEM.ADR(FName[0]), SYSTEM.SADR("rb"))
|
|
|
|
END FileOpen;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE OutChar* (c: CHAR);
|
|
|
|
BEGIN
|
|
|
|
API.putc(c)
|
|
|
|
END OutChar;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE GetTickCount* (): INTEGER;
|
|
|
|
VAR
|
|
|
|
tp: API.TP;
|
|
|
|
res: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
IF API.clock_gettime(0, tp) = 0 THEN
|
|
|
|
res := tp[0] * 100 + tp[1] DIV 10000000
|
|
|
|
ELSE
|
|
|
|
res := 0
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN res
|
|
|
|
END GetTickCount;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE isRelative* (path: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
RETURN path[0] # slash
|
|
|
|
END isRelative;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE now* (VAR year, month, day, hour, min, sec: INTEGER);
|
|
|
|
END now;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE UnixTime* (): INTEGER;
|
|
|
|
RETURN API.time(0)
|
|
|
|
END UnixTime;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE splitf* (x: REAL; VAR a, b: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
res: INTEGER;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
a := 0;
|
|
|
|
b := 0;
|
|
|
|
SYSTEM.MOVE(SYSTEM.ADR(x), SYSTEM.ADR(a), 4);
|
|
|
|
SYSTEM.MOVE(SYSTEM.ADR(x) + 4, SYSTEM.ADR(b), 4);
|
|
|
|
SYSTEM.GET(SYSTEM.ADR(x), res)
|
|
|
|
RETURN res
|
|
|
|
END splitf;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
BEGIN
|
|
|
|
eol := 0AX;
|
|
|
|
SYSTEM.GET(API.MainParam, argc)
|
2019-10-06 19:55:12 +02:00
|
|
|
END HOST.
|