Subversion Repositories Krakow BASIC

Rev

Rev 6 | Rev 8 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 6 Rev 7
Line 1... Line 1...
1
/* $Id: basic.c 6 2024-09-03 22:57:45Z nishi $ */
1
/* $Id: basic.c 7 2024-09-04 00:18:36Z nishi $ */
2
 
2
 
3
/* Krakow BASIC - Multi-platform simple BASIC */
3
/* Krakow BASIC - Multi-platform simple BASIC */
4
 
4
 
5
#if defined(PLATFORM_SHIROI)
5
#if defined(PLATFORM_SHIROI)
6
 
6
 
Line 12... Line 12...
12
#include "char.h"
12
#include "char.h"
13
#define PLATFORM "Shiroi"
13
#define PLATFORM "Shiroi"
14
#define NEWLINE "\r\n"
14
#define NEWLINE "\r\n"
15
#define BREAKKEY
15
#define BREAKKEY
16
 
16
 
17
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
17
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
18
 
18
 
19
#if defined(PLATFORM_WINDOWS)
19
#if defined(PLATFORM_WINDOWS)
20
#define PLATFORM "Windows"
20
#define PLATFORM "Windows"
21
#elif defined(PLATFORM_UNIX)
21
#elif defined(PLATFORM_UNIX)
22
#define PLATFORM "Unix"
22
#define PLATFORM "Unix"
Line 32... Line 32...
32
#elif defined(PLATFORM_A800XL)
32
#elif defined(PLATFORM_A800XL)
33
#define PLATFORM "Atari-800XL"
33
#define PLATFORM "Atari-800XL"
34
#define NEWLINE "\n"
34
#define NEWLINE "\n"
35
#define BREAKKEY
35
#define BREAKKEY
36
#include <conio.h>
36
#include <conio.h>
-
 
37
#elif defined(PLATFORM_APPLE2)
-
 
38
#define PLATFORM "Apple2"
-
 
39
#define NEWLINE "\n"
-
 
40
#define BREAKKEY
-
 
41
#include <conio.h>
37
#endif
42
#endif
38
 
43
 
39
#define mull(x, y) ((x) * (y))
44
#define mull(x, y) ((x) * (y))
40
#define divl(x, y) ((x) / (y))
45
#define divl(x, y) ((x) / (y))
41
#define killcursor(x)
46
#define killcursor(x)
Line 77... Line 82...
77
#define BUFFER_SIZE (16 * 1024)
82
#define BUFFER_SIZE (16 * 1024)
78
#undef killcursor
83
#undef killcursor
79
#undef cursor
84
#undef cursor
80
#define killcursor(x) cursor(0)
85
#define killcursor(x) cursor(0)
81
#define cursor(x) cursor(1)
86
#define cursor(x) cursor(1)
-
 
87
#elif defined(PLATFORM_APPLE2)
-
 
88
#define BUFFER_SIZE (8 * 1024)
-
 
89
#undef killcursor
-
 
90
#undef cursor
-
 
91
#define killcursor(x) cursor(0)
-
 
92
#define cursor(x) cursor(1)
82
#endif
93
#endif
83
 
94
 
84
#if defined(PLATFORM_ARDUINO)
95
#if defined(PLATFORM_ARDUINO)
85
int uart_putchar(char c) {
96
int uart_putchar(char c) {
86
	while(!(UCSR0A & _BV(UDRE0)))
97
	while(!(UCSR0A & _BV(UDRE0)))
Line 111... Line 122...
111
	c = getchar();
122
	c = getchar();
112
	if(c == EOF) return -1;
123
	if(c == EOF) return -1;
113
	if(c == '\r') return '\n';
124
	if(c == '\r') return '\n';
114
#elif defined(PLATFORM_ARDUINO)
125
#elif defined(PLATFORM_ARDUINO)
115
rescan:
126
rescan:
116
	if(wait){
127
	if(wait) {
117
		if(!(UCSR0A & _BV(RXC0))) return 0;
128
		if(!(UCSR0A & _BV(RXC0))) return 0;
118
	}else{
129
	} else {
119
		while(!(UCSR0A & _BV(RXC0)));
130
		while(!(UCSR0A & _BV(RXC0)))
-
 
131
			;
120
	}
132
	}
121
	c = UDR0;
133
	c = UDR0;
122
	if(c == '\r') return '\n';
134
	if(c == '\r') return '\n';
123
	if(c == '\n') goto rescan;
135
	if(c == '\n') goto rescan;
124
	if(c == 3) return 1;
136
	if(c == 3) return 1;
125
#elif defined(PLATFORM_C64)
137
#elif defined(PLATFORM_C64)
126
	if(!wait){
138
	if(!wait) {
127
		if(!kbhit()) return 0;
139
		if(!kbhit()) return 0;
128
	}
140
	}
129
	c = cgetc();
141
	c = cgetc();
130
	if(c == EOF) return -1;
142
	if(c == EOF) return -1;
131
	if(c == '\r') return '\n';
143
	if(c == '\r') return '\n';
132
	if(c == 20) return 8;
144
	if(c == 20) return 8;
133
	if(c == 3) return 1;
145
	if(c == 3) return 1;
134
#elif defined(PLATFORM_A800XL)
146
#elif defined(PLATFORM_A800XL)
135
	if(!wait){
147
	if(!wait) {
136
		if(!kbhit()) return 0;
148
		if(!kbhit()) return 0;
137
	}
149
	}
138
	c = cgetc();
150
	c = cgetc();
139
	if(c == EOF) return -1;
151
	if(c == EOF) return -1;
140
	if(c == '\r') return '\n';
152
	if(c == '\r') return '\n';
141
	if(c == 126) return 8;
153
	if(c == 126) return 8;
142
	if(c == 3) return 1;
154
	if(c == 3) return 1;
-
 
155
#elif defined(PLATFORM_APPLE2)
-
 
156
	if(!wait) {
-
 
157
		if(!kbhit()) return 0;
-
 
158
	}
-
 
159
	c = cgetc();
-
 
160
	if(c == EOF) return -1;
-
 
161
	if(c == '\r') return '\n';
-
 
162
	if(c == 3) return 1;
143
#endif
163
#endif
144
	return c;
164
	return c;
145
}
165
}
146
 
166
 
147
bool strcaseequ(const char* a, const char* b) { return strcasecmp(a, b) == 0; }
167
bool strcaseequ(const char* a, const char* b) { return strcasecmp(a, b) == 0; }
Line 202... Line 222...
202
		putstr("\x1b[9");
222
		putstr("\x1b[9");
203
	}
223
	}
204
	putstr(color);
224
	putstr(color);
205
	putstr("m");
225
	putstr("m");
206
	putstr("\x1b[2J\x1b[1;1H");
226
	putstr("\x1b[2J\x1b[1;1H");
207
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
227
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
208
	int fg = (a >> 4) & 0xf;
228
	int fg = (a >> 4) & 0xf;
209
	int bg = (a & 0xf);
229
	int bg = (a & 0xf);
210
	bgcolor(bg);
230
	bgcolor(bg);
211
	textcolor(fg);
231
	textcolor(fg);
212
#endif
232
#endif
Line 215... Line 235...
215
void clear(void) {
235
void clear(void) {
216
#if defined(PLATFORM_WINDOWS)
236
#if defined(PLATFORM_WINDOWS)
217
	system("cls");
237
	system("cls");
218
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_ARDUINO)
238
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_ARDUINO)
219
	putstr("\x1b[0m\x1b[2J\x1b[1;1H");
239
	putstr("\x1b[0m\x1b[2J\x1b[1;1H");
220
#elif defined(PLATFORM_C64)
240
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
221
	clrscr();
241
	clrscr();
222
#endif
242
#endif
223
}
243
}
224
 
244
 
225
void basic(void);
245
void basic(void);
Line 241... Line 261...
241
#elif defined(PLATFORM_ARDUINO)
261
#elif defined(PLATFORM_ARDUINO)
242
	uart_init();
262
	uart_init();
243
	DDRB |= _BV(DDB5);
263
	DDRB |= _BV(DDB5);
244
	PORTB |= _BV(PORT5);
264
	PORTB |= _BV(PORT5);
245
#endif
265
#endif
246
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
266
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
247
	change_color((1 << 4) | 0);
267
	change_color((1 << 4) | 0);
248
#endif
268
#endif
249
	basic();
269
	basic();
250
#if defined(PLATFORM_WINDOWS)
270
#if defined(PLATFORM_WINDOWS)
251
	SetConsoleMode(winstdout, origmode);
271
	SetConsoleMode(winstdout, origmode);