-
Notifications
You must be signed in to change notification settings - Fork 7
/
paslib.h
159 lines (110 loc) · 3.76 KB
/
paslib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#ifndef __PASLIB_H__
#define __PASLIB_H__
#define maxint ((int)(1 << (sizeof(integer)*8-1)) - 1)
#ifdef __cplusplus
extern "C" {
#endif
double sin(double);
double cos(double);
double tan(double);
double atan(double);
double exp(double);
double log(double);
double sqrt(double);
#ifdef __cplusplus
}
#endif
/*
* Macros for some Pascal standard functions
*/
#define trunc(x) ((integer)(x))
#define pred(type,x) ((type)((x) - 1))
#define succ(type,x) ((type)((x) + 1))
#define pack(a_l,a_h,a,i,z) memcpy(z, &(a)[(i)-(a_l)], sizeof(z))
#define unpack(z,a_l,a_h,a,i) memcpy(&(a)[(i)-(a_l)], (z), sizeof(z))
#define bitsize(x) (sizeof(x)*8)
#define odd(x) ((x) & 1)
#define chr(n) ((char)(n))
#define ord(c) ((int)(unsigned char)(c))
#ifdef __cplusplus
#ifndef abs
#if 0 // abs for integers is defined in stdlib
inline signed char abs(signed char x) { return x < 0 ? -x : x; }
inline short abs(short x) { return x < 0 ? -x : x; }
inline int abs(int x) { return x < 0 ? -x : x; }
inline long abs(long x) { return x < 0 ? -x : x; }
#endif
inline float abs(float x) { return x < 0 ? -x : x; }
inline double abs(double x) { return x < 0 ? -x : x; }
#endif
inline int sqr(signed char x) { return x*x; }
inline unsigned sqr(unsigned char x) { return x*x; }
inline int sqr(short x) { return x*x; }
inline unsigned sqr(unsigned short x) { return x*x; }
inline int sqr(int x) { return x*x; }
inline unsigned sqr(unsigned x) { return x*x; }
inline long sqr(long x) { return x*x; }
inline unsigned long sqr(unsigned long x) { return x*x; }
inline float sqr(float x) { return x*x; }
inline double sqr(double x) { return x*x; }
extern "C" void timestamp(integer* day, integer* month, integer* year,
integer* hour, integer* min, integer* sec);
extern "C" real get_realtime();
extern "C" integer round(real);
inline void timestamp(integer& day, integer& month, integer& year,
integer& hour, integer& min, integer& sec)
{
timestamp(&day, &month, &year, &hour, &min, &sec);
}
#else
#ifndef abs
#define abs(x) ((x) < 0 ? -(x) : (x))
#endif
#define sqr(x) ((x)*(x))
void timestamp(integer* day, integer* month, integer* year,
integer* hour, integer* min, integer* sec);
real get_realtime();
integer round(real);
#endif
#ifdef TURBO_PASCAL
#ifdef USE_CONIO
#include <conio.h>
#define readkey() _getche()
#define keypressed() _kbhit()
#endif
#define lo(x) ((x) & 0xFF)
#define hi(x) (((x) >> 8) & 0xFF)
#define ptr(seg, ofs) (void*)(((seg) << 16) | (ofs))
char* get_date();
char* get_time();
#define EXTERN extern
const double pi = 3.14159265359;
#include <ctype.h>
#define ParamCount paramcount
#define ExitProc exitproc
#define RandSeed randseed
#define DirectVideo directvideo
#define ParamStr(i) paramstr(i)
#define GetMem(p, size) getmem(p, size)
#define FreeMem(p, size) freemem(p, size)
#define upcase(c) ((char)toupper(c))
#define lowcase(c) ((char)tolower(c))
extern "C" int paramcount;
extern "C" char const* const* param_array;
extern "C" boolean directvideo;
extern "C" pointer exitproc;
extern "C" unsigned randseed;
inline string paramstr(int index) {
assert(index <= paramcount);
return string(param_array[index]);
}
inline void halt(int code = EXIT_FAILURE) { exit(code); }
#define getmem(ptr,size) ptr = malloc(size)
#define freemem(ptr,size) free(ptr)
extern "C" void Randomize();
extern "C" unsigned randint(unsigned range);
extern "C" double randreal();
inline unsigned Random(unsigned range) { return randint(range); }
inline double Random() { return randreal(); }
#endif
#endif