File size: 6,486 Bytes
a2a15a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
255
256
257
/*
 *
 * $Id: hardware.h,v 1.1 2024/02/25 04:43:16 stefan Exp stefan $
 *
 * Stefan's basic interpreter 
 *
 * See the licence file on 
 * https://github.com/slviajero/tinybasic for copyright/left.
 *   (GNU GENERAL PUBLIC LICENSE, Version 3, 29 June 2007)
 *
 * Author: Stefan Lenz, [email protected]
 * 
 *
 * Runtime environment for the BASIC interpreter, the 
 * hardware configuration file. It contains all hardware 
 * related settings and dependencies.
 *
 * This is hardware.h for POSIX systems and the POSIX runtime
 * environment runtime.c. 
 * 
 * Default setting is POSIX for most UNIXes including Mac.
 * RASPPI activates Raspberry PI related features. 
 * MINGW activates windows related features.
 * MSDOS for MSDOS compiles with tc 2.0 (untested in this version, last tested in 1.4)
 *
 */

#undef MINGW
#undef MSDOS
#undef RASPPI
#define POSIX

/*
 *	MEMSIZE sets the BASIC main memory to a fixed value,
 *		if MEMSIZE=0 a heuristic is used based on free heap
 *		size and architecture parameters
 */
#define MEMSIZE 0

/* 
 * Hardware flags of the POSIX systems 
 * POSIXTERMINAL, POSIXVT52TOANSI: ensure compatibility of BASIC programs  
 *  control characters of BASIC are translated to ANSI, bringing the Aruino 
 *  VT52 commands to POSIX
 * POSIXSIGNALS: enables signal handling of ^C interrupting programs
 * POSIXNONBLOCKING: non blocking I/O to handle GET and the BREAKCHAR 
 *  tricky on DOS, not very portable, experimental, use signals instead
 * POSIXFRAMEBUFFER: directly draw to the frame buffer of Raspberry PI
 *  only tested on this platform
 * POSIXWIRE: simple Raspberry PI wire code
 * POSIXMQTT: analogous to ARDUINOMQTT, send and receive MQTT messages (unfinished)
 * POSIXWIRING: use the (deprectated) wiring code for gpio on Raspberry Pi
 * POSIXPIGPIO: use the pigpio library on a Raspberry PI  - currently broken - wire change - don't use
 */

#define POSIXTERMINAL
#define POSIXVT52TOANSI
#define POSIXSIGNALS
#undef POSIXNONBLOCKING
#undef POSIXFRAMEBUFFER
#undef POSIXWIRE
#undef POSIXMQTT
#undef POSIXWIRING
#undef POSIXPIGPIO

/* simulates SPI RAM, only test code, keep undefed if you don't want to do something special */
#undef SPIRAMSIMULATOR

#ifdef SPIRAMSIMULATOR
#define USEMEMINTERFACE
#endif

/* use a serial port as printer interface - unfinished - similar to Arduino */
#define POSIXPRT

/* use TAB in MS mode */
#define HASMSTAB

/* build in BASIC programs on Posix currently without function */
#define HASBUILDIN
/* this is the demo module */
// #define BUILDINMODULE "buildin/buildin.h"
/* a small tutorial */
// #define BUILDINMODULE "buildin/buildin-tutorial.h"
#define BUILDINMODULE "buildin/buildin-arduinotest.h"
// #define BUILDINMODULE "buildin/buildin-games.h"

/* used pins and other parameters */

/*
 * Mechanisms to interrupt the interpreter
 *
 *	BREAKCHAR is the character stopping the program on Ardunios
 *  BREAKPIN can be set, it is a pin that needs to go to low to stop a BASIC program
 *    This should be done in hardware*.h
 *  BREAKSIGNAL can also be set, should be done in hardware*.h
 */

#define BREAKCHAR '#' /* the character to interrupt the interpreter */

/* set this is you want pin 4 on low interrupting the interpreter */
/* #define BREAKPIN 4 */

/* the SIGNAL the interpreters listens to for interrupt */
#define BREAKSIGNAL SIGINT

/* 
 * In case of non blocking IO turn on background tasks, we check BREAKCHAR only 
 * once every second in background and don't poll the keyboard after each statement.
 *
 * This is also needed for slow keyboards on Arduino. 
 */
#ifdef POSIXNONBLOCKING
#define BREAKINBACKGROUND
#define BASICBGTASK
#endif

/* frame buffer health check - currently only supported on Raspberry */ 
#ifndef RASPPI
#undef POSIXFRAMEBUFFER
#endif

/* wire parameters for Raspberry*/
#define POSIXI2CBUS 1

/* the size of the EEPROM dummy */
#define EEPROMSIZE 1024

/* they all have this */
#define FILESYSTEMDRIVER

/* and they have this */
#define HASCLOCK

/* some have this */
#if defined(POSIXWIRE) && defined(POSIXPIGPIO)
#define HASWIRE
#endif

/* we can do graphics and tell language.h that we can */
#ifdef POSIXFRAMEBUFFER
#define DISPLAYHASGRAPH
#endif

/* after run behaviour on POSIX systems, 1 to terminate if started
    on the command line with a file argument, 0 to stay active and 
    show a BASIC prompt*/
#define TERMINATEAFTERRUN 1

/* 
 * all the things the POSIX platforms need to source 
 */

/* define all the types Arduino has for compatibility of the interface */

typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned short uint16_t;
typedef signed short int16_t;
typedef unsigned char byte;
typedef unsigned long long uint64_t;
typedef unsigned int uint32_t;

/*
 * additional prototypes in an non Arduino world 
 */
unsigned long millis();

/* the ususal suspects */
#include <stdio.h>
#include <stdlib.h>

/* floating point maths only needed if HASFLOAT*/
#include <math.h>
#include <float.h>

/* time stuff */
#include <time.h>
#include <sys/types.h>
#include <sys/timeb.h>

/* directories and files */
#ifndef MSDOS
#include <dirent.h>
#include <unistd.h>
#else
#include <dir.h>
#include <dos.h>
#endif

/* windowy things for windows */
#ifdef MINGW
#include <windows.h>
#endif

/* 
 *  Tell BASIC we have a second serial port
 */
#ifdef POSIXPRT
#define HASSERIAL1
#endif

/* 
 *  Tell BASIC we have a radio adapter
 */
#undef HASRF24

/* 
 *  Tell BASIC we have MQTT
 */
#ifdef POSIXMQTT
#define HASMQTT
#endif

/* we definitely don't run on an Arduino */
#undef ARDUINOPROGMEM
#define PROGMEM 
#undef ARDUINO

/* and we use the buffer sizes for real computers */
#if MEMSIZE == 0 || MEMSIZE < 2560000
#define BUFSIZE         256
#define STACKSIZE       256
#define GOSUBDEPTH      64
#define FORDEPTH        64
#define LINECACHESIZE   64
#else
#define BUFSIZE         256
#define STACKSIZE       256
#define GOSUBDEPTH      196
#define FORDEPTH        196
#define LINECACHESIZE   196
#endif

/* the buffer size for simulated serial RAM */
#define SPIRAMSBSIZE 512

/* 
 * This code measures the fast ticker frequency. 
 */
#define FASTTICKERPROFILE

/*
 * Does the platform has command line args and do we want to use them 
 */
#define HASARGS

/*
 * How restrictive are we on function recursive calls to protect the stack
 * On Posix systems we can be more generous.
 */
#define FNLIMIT 128

/* all POSIXish systems can do the full interpreter, only here for compatibility with Arduino */
#define BASICFULL