aboutsummaryrefslogtreecommitdiffstats
path: root/blassic.h
blob: 219d439cfd71016ce25a7588382eb43ba38e42a6 (plain) (blame)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
#ifndef INCLUDE_BLASSIC_H
#define INCLUDE_BLASSIC_H

// blassic.h
// Revision 6-feb-2005

// Now do not use hash_map at all.
//#if ! defined __BORLANDC__ && __GNUC__ < 3
//#if defined __GNUC__
//#define USE_HASH_MAP
//#endif


#if defined _Windows || defined __CYGWIN__ || defined __MINGW32__


#define BLASSIC_USE_WINDOWS

#ifndef __MT__
#define __MT__
#endif


#else


// This is controlled with the configure option --disable-graphics
#ifndef BLASSIC_CONFIG_NO_GRAPHICS

#define BLASSIC_USE_X

#endif


#ifdef __linux__

// Uncomment next #define if you want to use the svgalib option
// or tell it to configure.
// Support for svgalib is currently outdated.
//#define BLASSIC_USE_SVGALIB

#endif

#endif

// Borland define _M_IX86, gcc define __i386__
#if defined (_M_IX86) || defined (__i386__)

#define BLASSIC_INTEL

// In other processor used the endianess is different and / or
// there are restrictions of alignment.

#endif


#ifdef __BORLANDC__
#pragma warn -8027
#endif


#ifdef HAVE_CSTDLIB
#include <cstdlib>
#else
#include <stdlib.h>
#endif

#include <string>
#include <vector>
#include <climits>

// Now defined here instead of in var.h to reduce dependencies.

enum VarType { VarUndef, VarNumber, VarInteger,
	VarString, VarStringSlice };

inline bool is_numeric_type (VarType v)
{ return v == VarNumber || v == VarInteger; }

inline bool is_string_type (VarType v)
{ return v == VarString || v == VarStringSlice; }


typedef unsigned char BlChar;
typedef unsigned short BlCode;
typedef double BlNumber;

#if ULONG_MAX == 4294967295UL

typedef long BlInt32;
const BlInt32 BlInt32Max= LONG_MAX;
const BlInt32 BlInt32Min= LONG_MIN;

typedef unsigned long BlUint32;
const BlUint32 BlUint32Max= ULONG_MAX;

#elif UINT_MAX == 4294967295UL

typedef int BlInt32;
const BlInt32 BlInt32Max= INT_MAX;
const BlInt32 BlInt32Min= INT_MIN;

typedef unsigned int BlUint32;
const BlUint32 BlUint32Max= UINT_MAX;

#elif USHRT_MAX == 4294967295UL

typedef short BlInt32;
const BlInt32 BlInt32Max= SHRT_MAX;
const BlInt32 BlInt32Min= SHRT_MIN;

typedef unsigned short BlUint32;
const BlUint32 BlUint32Max= USHRT_MAX;

#else

#error Unsupported platform

#endif

typedef BlInt32 BlInteger;
typedef BlUint32 BlLineNumber;
typedef BlUint32 BlLineLength;

const BlInteger BlIntegerMax= BlInt32Max;
const BlInteger BlIntegerMin= BlInt32Min;

// We limit the max line number as if it were signed.
const BlLineNumber BlMaxLineNumber= BlIntegerMax;

// Special line number values.

const BlLineNumber LineEndProgram= BlUint32Max;
const BlLineNumber LineBeginProgram= BlUint32Max - 1;
const BlLineNumber LineDirectCommand= BlUint32Max - 2;
const BlLineNumber LineNoDelete= BlUint32Max - 3;

typedef unsigned short BlChunk;
typedef unsigned short BlErrNo;
typedef unsigned short BlChannel;

const BlChannel DefaultChannel= 0;
const BlChannel PrinterChannel= 65535;

class ProgramPos {
public:
	ProgramPos () :
		num (LineEndProgram), chunk (0)
	{ }
	ProgramPos (BlLineNumber num) :
		num (num), chunk (0)
	{ }
	ProgramPos (BlLineNumber num, BlChunk chunk) :
		num (num), chunk (chunk)
	{ }
	void operator= (BlLineNumber num)
	{
		this->num= num;
		chunk= 0;
	}
	void nextchunk () { ++chunk; }
	void nextline () { ++num; chunk= 0; }
	operator bool () { return num != 0 || chunk != 0; }
	BlLineNumber getnum () const { return num; }
	BlChunk getchunk () const { return chunk; }
	void setchunk (BlChunk n) { chunk= n; }
private:
	BlLineNumber num;
	BlChunk chunk;
};

// Global variables:

//extern BlLineNumber blnAuto, blnAutoInc;

extern bool fInterrupted;

extern const std::string strPrompt;

// version.cpp
namespace version {

extern const unsigned short Major, Minor, Release;

} // namespace version

class Exit {
public:
	Exit (int ncode= 0);
	int code () const;
private:
	int exitcode;
};

std::string getprogramarg (size_t n);
void setprogramargs (const std::vector <std::string> & nargs);

inline BlInteger peek16 (const BlChar * p)
{
	#ifdef BLASSIC_INTEL
	return * reinterpret_cast <const unsigned short *> (p);
	#else
	return p [0] | (static_cast <unsigned short> (p [1]) << 8);
	#endif
}

inline void poke16 (BlChar * p, short n)
{
	#ifdef BLASSIC_INTEL
	* reinterpret_cast <short *> (p)= n;
	#else
	p [0]= BlChar (n & 0xFF);
	p [1]= BlChar ( (n >> 8) & 0xFF);
	#endif
}

inline BlInteger peek32 (const BlChar * p)
{
	#ifdef BLASSIC_INTEL
	return * reinterpret_cast <const BlInteger *> (p);
	#else
	return p [0] |
		(BlInteger (p [1]) << 8) |
		(BlInteger (p [2]) << 16) |
		(BlInteger (p [3]) << 24);
	#endif
}

inline void poke32 (BlChar * p, BlUint32 n)
{
	#ifdef BLASSIC_INTEL
	* reinterpret_cast <BlInteger *> (p)= n;
	#else
	p [0]= BlChar (n & 0xFF);
	p [1]= BlChar ( (n >> 8) & 0xFF);
	p [2]= BlChar ( (n >> 16) & 0xFF);
	p [3]= BlChar (n >> 24);
	#endif
}

inline void poke32 (BlChar * p, BlInteger n)
{
	poke32 (p, static_cast <BlUint32> (n) );
}

namespace blassic {

void idle (); // Implemented in graphics.cpp

} // namespace blassic

#endif

// Fin de blassic.h
Un proyecto texto-plano.xyz