2020-05-25 22:48:33 +02:00
|
|
|
(*
|
2019-03-11 09:59:55 +01:00
|
|
|
BSD 2-Clause License
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2021-06-15 19:33:16 +02:00
|
|
|
Copyright (c) 2018-2021, Anton Krotov
|
2019-03-11 09:59:55 +01:00
|
|
|
All rights reserved.
|
2016-10-24 01:30:27 +02:00
|
|
|
*)
|
|
|
|
|
|
|
|
MODULE UTILS;
|
|
|
|
|
2019-10-06 19:55:12 +02:00
|
|
|
IMPORT HOST;
|
2019-03-11 09:59:55 +01:00
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
CONST
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
slash* = HOST.slash;
|
2020-10-13 09:58:51 +02:00
|
|
|
eol* = HOST.eol;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
bit_depth* = HOST.bit_depth;
|
|
|
|
maxint* = HOST.maxint;
|
|
|
|
minint* = HOST.minint;
|
2019-09-26 22:23:06 +02:00
|
|
|
|
|
|
|
min32* = -2147483647-1;
|
|
|
|
max32* = 2147483647;
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
vMajor* = 1;
|
2021-06-15 19:33:16 +02:00
|
|
|
vMinor* = 52;
|
|
|
|
Date* = "07-may-2021";
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
FILE_EXT* = ".ob07";
|
|
|
|
RTL_NAME* = "RTL";
|
|
|
|
|
|
|
|
MAX_GLOBAL_SIZE* = 1600000000;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
VAR
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
time*: INTEGER;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
maxreal*: REAL;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-09-26 22:23:06 +02:00
|
|
|
target*:
|
|
|
|
|
|
|
|
RECORD
|
|
|
|
|
|
|
|
bit_depth*,
|
|
|
|
maxInt*,
|
|
|
|
minInt*,
|
|
|
|
maxSet*,
|
|
|
|
maxHex*: INTEGER;
|
|
|
|
|
|
|
|
maxReal*: REAL
|
|
|
|
|
|
|
|
END;
|
|
|
|
|
|
|
|
bit_diff*: INTEGER;
|
|
|
|
|
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
|
|
|
RETURN HOST.FileRead(F, Buffer, bytes)
|
|
|
|
END FileRead;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE FileWrite* (F: INTEGER; Buffer: ARRAY OF BYTE; bytes: INTEGER): INTEGER;
|
|
|
|
RETURN HOST.FileWrite(F, Buffer, bytes)
|
|
|
|
END FileWrite;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE FileCreate* (FName: ARRAY OF CHAR): INTEGER;
|
|
|
|
RETURN HOST.FileCreate(FName)
|
|
|
|
END FileCreate;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE FileClose* (F: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
HOST.FileClose(F)
|
|
|
|
END FileClose;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE FileOpen* (FName: ARRAY OF CHAR): INTEGER;
|
|
|
|
RETURN HOST.FileOpen(FName)
|
|
|
|
END FileOpen;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE chmod* (FName: ARRAY OF CHAR);
|
|
|
|
BEGIN
|
|
|
|
HOST.chmod(FName)
|
|
|
|
END chmod;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE GetArg* (i: INTEGER; VAR str: ARRAY OF CHAR);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
HOST.GetArg(i, str)
|
|
|
|
END GetArg;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE Exit* (code: INTEGER);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
HOST.ExitProcess(code)
|
|
|
|
END Exit;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE GetTickCount* (): INTEGER;
|
|
|
|
RETURN HOST.GetTickCount()
|
|
|
|
END GetTickCount;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
|
|
|
|
PROCEDURE OutChar* (c: CHAR);
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2019-03-11 09:59:55 +01:00
|
|
|
HOST.OutChar(c)
|
|
|
|
END OutChar;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE splitf* (x: REAL; VAR a, b: INTEGER): INTEGER;
|
|
|
|
RETURN HOST.splitf(x, a, b)
|
|
|
|
END splitf;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE d2s* (x: REAL): INTEGER;
|
|
|
|
RETURN HOST.d2s(x)
|
|
|
|
END d2s;
|
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE isRelative* (path: ARRAY OF CHAR): BOOLEAN;
|
|
|
|
RETURN HOST.isRelative(path)
|
|
|
|
END isRelative;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE GetCurrentDirectory* (VAR path: ARRAY OF CHAR);
|
|
|
|
BEGIN
|
|
|
|
HOST.GetCurrentDirectory(path)
|
|
|
|
END GetCurrentDirectory;
|
2016-10-24 01:30:27 +02:00
|
|
|
|
|
|
|
|
2019-03-11 09:59:55 +01:00
|
|
|
PROCEDURE UnixTime* (): INTEGER;
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN HOST.UnixTime()
|
2019-03-11 09:59:55 +01:00
|
|
|
END UnixTime;
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
|
2020-05-25 22:48:33 +02:00
|
|
|
PROCEDURE SetBitDepth* (BitDepth: INTEGER; Double: BOOLEAN);
|
2019-09-26 22:23:06 +02:00
|
|
|
BEGIN
|
|
|
|
ASSERT((BitDepth = 16) OR (BitDepth = 32) OR (BitDepth = 64));
|
|
|
|
bit_diff := bit_depth - BitDepth;
|
|
|
|
ASSERT(bit_diff >= 0);
|
|
|
|
|
|
|
|
target.bit_depth := BitDepth;
|
|
|
|
target.maxSet := BitDepth - 1;
|
|
|
|
target.maxHex := BitDepth DIV 4;
|
|
|
|
target.minInt := ASR(minint, bit_diff);
|
|
|
|
target.maxInt := ASR(maxint, bit_diff);
|
2020-05-25 22:48:33 +02:00
|
|
|
|
|
|
|
IF Double THEN
|
|
|
|
target.maxReal := maxreal
|
|
|
|
ELSE
|
|
|
|
target.maxReal := 1.9;
|
|
|
|
PACK(target.maxReal, 127)
|
|
|
|
END
|
2019-09-26 22:23:06 +02:00
|
|
|
END SetBitDepth;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Byte* (n: INTEGER; idx: INTEGER): BYTE;
|
|
|
|
RETURN ASR(n, 8 * idx) MOD 256
|
|
|
|
END Byte;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Align* (VAR bytes: INTEGER; align: INTEGER): BOOLEAN;
|
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
INC(bytes, (-bytes) MOD align)
|
|
|
|
RETURN bytes >= 0
|
2019-09-26 22:23:06 +02:00
|
|
|
END Align;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Long* (value: INTEGER): INTEGER;
|
|
|
|
RETURN ASR(LSL(value, bit_diff), bit_diff)
|
|
|
|
END Long;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Short* (value: INTEGER): INTEGER;
|
|
|
|
RETURN LSR(LSL(value, bit_diff), bit_diff)
|
|
|
|
END Short;
|
|
|
|
|
|
|
|
|
|
|
|
PROCEDURE Log2* (x: INTEGER): INTEGER;
|
|
|
|
VAR
|
|
|
|
n: INTEGER;
|
|
|
|
|
|
|
|
BEGIN
|
|
|
|
n := 0;
|
|
|
|
WHILE ~ODD(x) DO
|
|
|
|
x := x DIV 2;
|
|
|
|
INC(n)
|
|
|
|
END;
|
|
|
|
|
|
|
|
IF x # 1 THEN
|
|
|
|
n := -1
|
|
|
|
END
|
|
|
|
|
|
|
|
RETURN n
|
|
|
|
END Log2;
|
|
|
|
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
PROCEDURE hexdgt* (n: BYTE): BYTE;
|
2019-10-06 19:55:12 +02:00
|
|
|
BEGIN
|
2020-10-13 09:58:51 +02:00
|
|
|
IF n < 10 THEN
|
|
|
|
INC(n, ORD("0"))
|
|
|
|
ELSE
|
|
|
|
INC(n, ORD("A") - 10)
|
2019-10-06 19:55:12 +02:00
|
|
|
END
|
|
|
|
|
2020-10-13 09:58:51 +02:00
|
|
|
RETURN n
|
|
|
|
END hexdgt;
|
2019-10-06 19:55:12 +02:00
|
|
|
|
|
|
|
|
2016-10-24 01:30:27 +02:00
|
|
|
BEGIN
|
2021-06-15 19:33:16 +02:00
|
|
|
time := HOST.GetTickCount();
|
2020-10-13 09:58:51 +02:00
|
|
|
maxreal := HOST.maxreal
|
2020-05-25 22:48:33 +02:00
|
|
|
END UTILS.
|