Subversion Repositories Krakow BASIC

Rev

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

Rev 8 Rev 9
Line 1... Line 1...
1
/* $Id: basic.c 8 2024-09-04 11:49:13Z nishi $ */
1
/* $Id: basic.c 9 2024-09-04 15:25:47Z 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) || defined(PLATFORM_APPLE2)
17
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
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 27... Line 27...
27
#elif defined(PLATFORM_C64)
27
#elif defined(PLATFORM_C64)
28
#define PLATFORM "Commodore-64"
28
#define PLATFORM "Commodore-64"
29
#define NEWLINE "\r\n"
29
#define NEWLINE "\r\n"
30
#define BREAKKEY
30
#define BREAKKEY
31
#include <conio.h>
31
#include <conio.h>
-
 
32
#elif defined(PLATFORM_PET)
-
 
33
#define PLATFORM "Commodore-PET"
-
 
34
#define NEWLINE "\r\n"
-
 
35
#define BREAKKEY
-
 
36
#include <conio.h>
-
 
37
#include <peekpoke.h>
32
#elif defined(PLATFORM_A800XL)
38
#elif defined(PLATFORM_A800XL)
33
#define PLATFORM "Atari-800XL"
39
#define PLATFORM "Atari-800XL"
34
#define NEWLINE "\n"
40
#define NEWLINE "\n"
35
#define BREAKKEY
41
#define BREAKKEY
36
#include <conio.h>
42
#include <conio.h>
Line 70... Line 76...
70
#define LINES (32)
76
#define LINES (32)
71
#undef putchar
77
#undef putchar
72
#define putchar uart_putchar
78
#define putchar uart_putchar
73
#elif defined(PLATFORM_UNIX)
79
#elif defined(PLATFORM_UNIX)
74
#include <termios.h>
80
#include <termios.h>
-
 
81
#elif defined(PLATFORM_PET)
-
 
82
#define BUFFER_SIZE (4 * 1024)
-
 
83
#undef killcursor
-
 
84
#undef cursor
-
 
85
#define killcursor(x) cursor(0)
-
 
86
#define cursor(x) cursor(1)
75
#elif defined(PLATFORM_C64)
87
#elif defined(PLATFORM_C64)
76
#define BUFFER_SIZE (16 * 1024)
88
#define BUFFER_SIZE (16 * 1024)
77
#undef killcursor
89
#undef killcursor
78
#undef cursor
90
#undef cursor
79
#define killcursor(x) cursor(0)
91
#define killcursor(x) cursor(0)
Line 132... Line 144...
132
	}
144
	}
133
	c = UDR0;
145
	c = UDR0;
134
	if(c == '\r') return '\n';
146
	if(c == '\r') return '\n';
135
	if(c == '\n') goto rescan;
147
	if(c == '\n') goto rescan;
136
	if(c == 3) return 1;
148
	if(c == 3) return 1;
137
#elif defined(PLATFORM_C64)
149
#elif defined(PLATFORM_C64) || defined(PLATFORM_PET)
138
	if(!wait) {
150
	if(!wait) {
139
		if(!kbhit()) return 0;
151
		if(!kbhit()) return 0;
140
	}
152
	}
141
	c = cgetc();
153
	c = cgetc();
142
	if(c == EOF) return -1;
154
	if(c == EOF) return -1;
Line 222... Line 234...
222
		putstr("\x1b[9");
234
		putstr("\x1b[9");
223
	}
235
	}
224
	putstr(color);
236
	putstr(color);
225
	putstr("m");
237
	putstr("m");
226
	putstr("\x1b[2J\x1b[1;1H");
238
	putstr("\x1b[2J\x1b[1;1H");
227
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
239
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
228
	int fg = (a >> 4) & 0xf;
240
	int fg = (a >> 4) & 0xf;
229
	int bg = (a & 0xf);
241
	int bg = (a & 0xf);
230
	bgcolor(bg);
242
	bgcolor(bg);
231
	textcolor(fg);
243
	textcolor(fg);
232
#endif
244
#endif
Line 235... Line 247...
235
void clear(void) {
247
void clear(void) {
236
#if defined(PLATFORM_WINDOWS)
248
#if defined(PLATFORM_WINDOWS)
237
	system("cls");
249
	system("cls");
238
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_ARDUINO)
250
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_ARDUINO)
239
	putstr("\x1b[0m\x1b[2J\x1b[1;1H");
251
	putstr("\x1b[0m\x1b[2J\x1b[1;1H");
240
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
252
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
241
	clrscr();
253
	clrscr();
242
#endif
254
#endif
243
}
255
}
244
 
256
 
245
void basic(void);
257
void basic(void);
246
 
258
 
247
int main() {
259
int main() {
-
 
260
#if defined(PLATFORM_PET)
-
 
261
	if(PEEK(0x9000) == POKE(0x9000, PEEK(0x9000) + 1)) {
-
 
262
		_heapadd((void*)0x9000, 0x2000);
-
 
263
	}
-
 
264
#endif
248
#if defined(PLATFORM_WINDOWS)
265
#if defined(PLATFORM_WINDOWS)
249
	HANDLE winstdout = GetStdHandle(STD_OUTPUT_HANDLE);
266
	HANDLE winstdout = GetStdHandle(STD_OUTPUT_HANDLE);
250
	DWORD mode = 0;
267
	DWORD mode = 0;
251
	GetConsoleMode(winstdout, &mode);
268
	GetConsoleMode(winstdout, &mode);
252
	const DWORD origmode = mode;
269
	const DWORD origmode = mode;
Line 261... Line 278...
261
#elif defined(PLATFORM_ARDUINO)
278
#elif defined(PLATFORM_ARDUINO)
262
	uart_init();
279
	uart_init();
263
	DDRB |= _BV(DDB5);
280
	DDRB |= _BV(DDB5);
264
	PORTB |= _BV(PORT5);
281
	PORTB |= _BV(PORT5);
265
#endif
282
#endif
266
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
283
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
267
	change_color((1 << 4) | 0);
284
	change_color((1 << 4) | 0);
-
 
285
	bordercolor(0);
268
#endif
286
#endif
269
	basic();
287
	basic();
270
#if defined(PLATFORM_WINDOWS)
288
#if defined(PLATFORM_WINDOWS)
271
	SetConsoleMode(winstdout, origmode);
289
	SetConsoleMode(winstdout, origmode);
272
#elif defined(PLATFORM_UNIX)
290
#elif defined(PLATFORM_UNIX)
Line 807... Line 825...
807
	cursor();
825
	cursor();
808
	linebuf[0] = 0;
826
	linebuf[0] = 0;
809
	lineind = 0;
827
	lineind = 0;
810
	while(1) {
828
	while(1) {
811
		char c;
829
		char c;
812
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2)
830
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
813
		c = oggetch(1);
831
		c = oggetch(1);
814
#else
832
#else
815
		c = agetch();
833
		c = agetch();
816
#endif
834
#endif
817
		if(c != 0) {
835
		if(c != 0) {