Subversion Repositories Krakow BASIC

Rev

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

Rev 4 Rev 6
Line 1... Line 1...
1
/* $Id: basic.c 4 2024-09-03 22:40:08Z nishi $ */
1
/* $Id: basic.c 6 2024-09-03 22:57:45Z 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)
17
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
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_A800XL)
-
 
33
#define PLATFORM "Atari-800XL"
-
 
34
#define NEWLINE "\n"
-
 
35
#define BREAKKEY
-
 
36
#include <conio.h>
32
#endif
37
#endif
33
 
38
 
34
#define mull(x, y) ((x) * (y))
39
#define mull(x, y) ((x) * (y))
35
#define divl(x, y) ((x) / (y))
40
#define divl(x, y) ((x) / (y))
36
#define killcursor(x)
41
#define killcursor(x)
Line 66... Line 71...
66
#define BUFFER_SIZE (16 * 1024)
71
#define BUFFER_SIZE (16 * 1024)
67
#undef killcursor
72
#undef killcursor
68
#undef cursor
73
#undef cursor
69
#define killcursor(x) cursor(0)
74
#define killcursor(x) cursor(0)
70
#define cursor(x) cursor(1)
75
#define cursor(x) cursor(1)
-
 
76
#elif defined(PLATFORM_A800XL)
-
 
77
#define BUFFER_SIZE (16 * 1024)
-
 
78
#undef killcursor
-
 
79
#undef cursor
-
 
80
#define killcursor(x) cursor(0)
-
 
81
#define cursor(x) cursor(1)
71
#endif
82
#endif
72
 
83
 
73
#if defined(PLATFORM_ARDUINO)
84
#if defined(PLATFORM_ARDUINO)
74
int uart_putchar(char c) {
85
int uart_putchar(char c) {
75
	while(!(UCSR0A & _BV(UDRE0)))
86
	while(!(UCSR0A & _BV(UDRE0)))
Line 118... Line 129...
118
	c = cgetc();
129
	c = cgetc();
119
	if(c == EOF) return -1;
130
	if(c == EOF) return -1;
120
	if(c == '\r') return '\n';
131
	if(c == '\r') return '\n';
121
	if(c == 20) return 8;
132
	if(c == 20) return 8;
122
	if(c == 3) return 1;
133
	if(c == 3) return 1;
-
 
134
#elif defined(PLATFORM_A800XL)
-
 
135
	if(!wait){
-
 
136
		if(!kbhit()) return 0;
-
 
137
	}
-
 
138
	c = cgetc();
-
 
139
	if(c == EOF) return -1;
-
 
140
	if(c == '\r') return '\n';
-
 
141
	if(c == 126) return 8;
-
 
142
	if(c == 3) return 1;
123
#endif
143
#endif
124
	return c;
144
	return c;
125
}
145
}
126
 
146
 
127
bool strcaseequ(const char* a, const char* b) { return strcasecmp(a, b) == 0; }
147
bool strcaseequ(const char* a, const char* b) { return strcasecmp(a, b) == 0; }
Line 182... Line 202...
182
		putstr("\x1b[9");
202
		putstr("\x1b[9");
183
	}
203
	}
184
	putstr(color);
204
	putstr(color);
185
	putstr("m");
205
	putstr("m");
186
	putstr("\x1b[2J\x1b[1;1H");
206
	putstr("\x1b[2J\x1b[1;1H");
187
#elif defined(PLATFORM_C64)
207
#elif defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
188
	int fg = (a >> 4) & 0xf;
208
	int fg = (a >> 4) & 0xf;
189
	int bg = (a & 0xf);
209
	int bg = (a & 0xf);
190
	bgcolor(bg);
210
	bgcolor(bg);
191
	textcolor(fg);
211
	textcolor(fg);
192
#endif
212
#endif
Line 221... Line 241...
221
#elif defined(PLATFORM_ARDUINO)
241
#elif defined(PLATFORM_ARDUINO)
222
	uart_init();
242
	uart_init();
223
	DDRB |= _BV(DDB5);
243
	DDRB |= _BV(DDB5);
224
	PORTB |= _BV(PORT5);
244
	PORTB |= _BV(PORT5);
225
#endif
245
#endif
226
#if defined(PLATFORM_C64)
246
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
227
	change_color((1 << 4) | 0);
247
	change_color((1 << 4) | 0);
228
#endif
248
#endif
229
	basic();
249
	basic();
230
#if defined(PLATFORM_WINDOWS)
250
#if defined(PLATFORM_WINDOWS)
231
	SetConsoleMode(winstdout, origmode);
251
	SetConsoleMode(winstdout, origmode);
Line 540... Line 560...
540
		}
560
		}
541
	}
561
	}
542
	line[incr] = 0;
562
	line[incr] = 0;
543
	if(num == 0) {
563
	if(num == 0) {
544
		int ret = run(line, -1, 0, 0);
564
		int ret = run(line, -1, 0, 0);
545
		putstr("Ready\r\n");
565
		putstr("Ready");
-
 
566
		putstr(NEWLINE);
546
		return ret;
567
		return ret;
547
	} else {
568
	} else {
548
		int addr = BUFFER_SIZE - 1;
569
		int addr = BUFFER_SIZE - 1;
549
		int i;
570
		int i;
550
		int shf = 0;
571
		int shf = 0;
Line 638... Line 659...
638
	putstr(NEWLINE);
659
	putstr(NEWLINE);
639
#else
660
#else
640
	putstr(PLATFORM);
661
	putstr(PLATFORM);
641
	putstr("   Krakow BASIC V");
662
	putstr("   Krakow BASIC V");
642
	putstr(VERSION);
663
	putstr(VERSION);
643
	putstr("\r\n");
664
	putstr(NEWLINE);
644
	putstr("Copyright 2024 by: Nishi.\r\n");
665
	putstr("Copyright 2024 by: Nishi.");
-
 
666
	putstr(NEWLINE);
645
	putstr("                   penguin2233.");
667
	putstr("                   penguin2233.");
646
	putstr(NEWLINE);
668
	putstr(NEWLINE);
647
	putstr(NEWLINE);
669
	putstr(NEWLINE);
648
	putstr(" Max ");
670
	putstr(" Max ");
649
	putnum(LINE_BUFFER_SIZE);
671
	putnum(LINE_BUFFER_SIZE);
Line 669... Line 691...
669
	cursor();
691
	cursor();
670
	linebuf[0] = 0;
692
	linebuf[0] = 0;
671
	lineind = 0;
693
	lineind = 0;
672
	while(1) {
694
	while(1) {
673
		char c;
695
		char c;
674
#if defined(PLATFORM_C64)
696
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL)
675
		c = oggetch(1);
697
		c = oggetch(1);
676
#else
698
#else
677
		c = agetch();
699
		c = agetch();
678
#endif
700
#endif
679
		if(c != 0) killcursor();
701
		if(c != 0) killcursor();
Line 714... Line 736...
714
 
736
 
715
		skip:
737
		skip:
716
			lineind = 0;
738
			lineind = 0;
717
		} else if(c == 0x8 || c == 0x7f) {
739
		} else if(c == 0x8 || c == 0x7f) {
718
			if(lineind > 0) {
740
			if(lineind > 0) {
-
 
741
#if defined(PLATFORM_A800XL)
-
 
742
				putstr("\x7e \x7e");
-
 
743
#else
719
				putstr("\x08 \x08");
744
				putstr("\x08 \x08");
-
 
745
#endif
720
				linebuf[--lineind] = 0;
746
				linebuf[--lineind] = 0;
721
			}
747
			}
722
		} else if(c == -1) {
748
		} else if(c == -1) {
723
			break;
749
			break;
724
		} else if(c != 0) {
750
		} else if(c != 0) {