Subversion Repositories Krakow BASIC

Rev

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

Rev 38 Rev 39
Line 1... Line 1...
1
/* $Id: basic.c 38 2024-09-05 16:02:53Z nishi $ */
1
/* $Id: basic.c 39 2024-09-06 12:56:29Z nishi $ */
2
 
2
 
3
/* Krakow BASIC - Multi-platform simple BASIC */
3
/* Krakow BASIC - Multi-platform simple BASIC */
4
 
4
 
-
 
5
#if defined(PLATFORM_X11)
-
 
6
#define PLATFORM_UNIX
-
 
7
#endif
-
 
8
 
5
#if defined(PLATFORM_SHIROI)
9
#if defined(PLATFORM_SHIROI)
6
 
10
 
7
#include "dri/text.h"
11
#include "dri/text.h"
8
#include "dri/video.h"
12
#include "dri/video.h"
9
#include "dri/math.h"
13
#include "dri/math.h"
Line 208... Line 212...
208
#define LINE_BUFFER_SIZE (128)
212
#define LINE_BUFFER_SIZE (128)
209
#define LINES (32)
213
#define LINES (32)
210
#undef putchar
214
#undef putchar
211
#define putchar uart_putchar
215
#define putchar uart_putchar
212
#elif defined(PLATFORM_UNIX)
216
#elif defined(PLATFORM_UNIX)
-
 
217
#if defined(PLATFORM_X11)
-
 
218
#include <X11/Xlib.h>
-
 
219
#include <pthread.h>
-
 
220
 
-
 
221
void* x11_thread(void* arg);
-
 
222
#else
213
#include <termios.h>
223
#include <termios.h>
214
#include <sys/ioctl.h>
224
#include <sys/ioctl.h>
-
 
225
#endif
215
#elif defined(PLATFORM_PET)
226
#elif defined(PLATFORM_PET)
216
#define BUFFER_SIZE (4 * 1024)
227
#define BUFFER_SIZE (4 * 1024)
217
#undef killcursor
228
#undef killcursor
218
#undef cursor
229
#undef cursor
219
#define killcursor(x) cursor(0)
230
#define killcursor(x) cursor(0)
Line 266... Line 277...
266
	}
277
	}
267
	c = _getch();
278
	c = _getch();
268
	if(c == '\r') return '\n';
279
	if(c == '\r') return '\n';
269
	if(c == '\n') goto rescan;
280
	if(c == '\n') goto rescan;
270
#elif defined(PLATFORM_UNIX)
281
#elif defined(PLATFORM_UNIX)
-
 
282
#if defined(PLATFORM_X11)
-
 
283
#else
271
	if(!wait){
284
	if(!wait){
272
		int b;
285
		int b;
273
		ioctl(0, FIONREAD, &b);
286
		ioctl(0, FIONREAD, &b);
274
		if(b == 0) return 0;
287
		if(b == 0) return 0;
275
	}
288
	}
276
	c = getchar();
289
	c = getchar();
277
	if(c == EOF) return -1;
290
	if(c == EOF) return -1;
278
	if(c == '\r') return '\n';
291
	if(c == '\r') return '\n';
-
 
292
#endif
279
#elif defined(PLATFORM_ARDUINO)
293
#elif defined(PLATFORM_ARDUINO)
280
rescan:
294
rescan:
281
	if(!wait) {
295
	if(!wait) {
282
		if(!(UCSR0A & _BV(RXC0))) return 0;
296
		if(!(UCSR0A & _BV(RXC0))) return 0;
283
	} else {
297
	} else {
Line 410... Line 424...
410
	GetConsoleMode(winstdout, &mode);
424
	GetConsoleMode(winstdout, &mode);
411
	const DWORD origmode = mode;
425
	const DWORD origmode = mode;
412
	mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
426
	mode |= ENABLE_VIRTUAL_TERMINAL_PROCESSING;
413
	SetConsoleMode(winstdout, mode);
427
	SetConsoleMode(winstdout, mode);
414
#elif defined(PLATFORM_UNIX)
428
#elif defined(PLATFORM_UNIX)
-
 
429
#if defined(PLATFORM_X11)
-
 
430
	pthread_t thread;
-
 
431
	pthread_create(&thread, NULL, x11_thread, NULL);
-
 
432
#else
415
	struct termios old, new;
433
	struct termios old, new;
416
	tcgetattr(0, &old);
434
	tcgetattr(0, &old);
417
	new = old;
435
	new = old;
418
	new.c_lflag &= ~(ECHO | ICANON);
436
	new.c_lflag &= ~(ECHO | ICANON);
419
	tcsetattr(0, TCSANOW, &new);
437
	tcsetattr(0, TCSANOW, &new);
-
 
438
#endif
420
#elif defined(PLATFORM_ARDUINO)
439
#elif defined(PLATFORM_ARDUINO)
421
	uart_init();
440
	uart_init();
422
	DDRB |= _BV(DDB5);
441
	DDRB |= _BV(DDB5);
423
	PORTB |= _BV(PORT5);
442
	PORTB |= _BV(PORT5);
424
#endif
443
#endif
Line 428... Line 447...
428
#endif
447
#endif
429
	basic();
448
	basic();
430
#if defined(PLATFORM_WINDOWS)
449
#if defined(PLATFORM_WINDOWS)
431
	SetConsoleMode(winstdout, origmode);
450
	SetConsoleMode(winstdout, origmode);
432
#elif defined(PLATFORM_UNIX)
451
#elif defined(PLATFORM_UNIX)
-
 
452
#if defined(PLATFORM_X11)
-
 
453
	pthread_join(thread, NULL);
-
 
454
#else
433
	tcsetattr(0, TCSANOW, &old);
455
	tcsetattr(0, TCSANOW, &old);
434
#endif
456
#endif
-
 
457
#endif
435
}
458
}
436
 
459
 
437
#else
460
#else
438
#error "Define PLATFORM_*"
461
#error "Define PLATFORM_*"
439
#endif
462
#endif