Subversion Repositories Krakow BASIC

Rev

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

Rev 29 Rev 36
Line 1... Line 1...
1
/* $Id: basic.c 29 2024-09-05 04:27:28Z nishi $ */
1
/* $Id: basic.c 36 2024-09-05 15:37:50Z 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 253... Line 253...
253
 
253
 
254
	UCSR0C |= _BV(UCSZ00) | _BV(UCSZ01);
254
	UCSR0C |= _BV(UCSZ00) | _BV(UCSZ01);
255
}
255
}
256
#endif
256
#endif
257
 
257
 
258
#define agetch(x) oggetch(0)
258
#define agetch() oggetch(0)
259
char oggetch(char wait) {
259
char oggetch(char wait) {
260
	int c;
260
	int c;
261
#if defined(PLATFORM_WINDOWS)
261
#if defined(PLATFORM_WINDOWS)
262
rescan:
262
rescan:
263
	c = _getch();
263
	c = _getch();
Line 267... Line 267...
267
	c = getchar();
267
	c = getchar();
268
	if(c == EOF) return -1;
268
	if(c == EOF) return -1;
269
	if(c == '\r') return '\n';
269
	if(c == '\r') return '\n';
270
#elif defined(PLATFORM_ARDUINO)
270
#elif defined(PLATFORM_ARDUINO)
271
rescan:
271
rescan:
272
	if(wait) {
272
	if(!wait) {
273
		if(!(UCSR0A & _BV(RXC0))) return 0;
273
		if(!(UCSR0A & _BV(RXC0))) return 0;
274
	} else {
274
	} else {
275
		while(!(UCSR0A & _BV(RXC0)))
275
		while(!(UCSR0A & _BV(RXC0)))
276
			;
276
			;
277
	}
277
	}
Line 465... Line 465...
465
	int result = 0;
465
	int result = 0;
466
	int stack[32];
466
	int stack[32];
467
	int sp = 0;
467
	int sp = 0;
468
	char put = 0;
468
	char put = 0;
469
	char hex = 0;
469
	char hex = 0;
-
 
470
	if(expr[0] == '"' && expr[strlen(expr) - 1] == '"'){
-
 
471
		for(i = 1; expr[i + 1] != 0; i++){
-
 
472
			buffer[i - 1] = expr[i];
-
 
473
		}
-
 
474
		buffer[i - 1] = 0;
-
 
475
		return 0;
-
 
476
	}
470
	for(i = 0; expr[i] != 0; i++) ownbuf[i] = expr[i];
477
	for(i = 0; expr[i] != 0; i++) ownbuf[i] = expr[i];
471
	ownbuf[i] = 0;
478
	ownbuf[i] = 0;
472
	for(i = 0; i < 32; i++) stack[i] = 0;
479
	for(i = 0; i < 32; i++) stack[i] = 0;
473
	for(i = 0;; i++) {
480
	for(i = 0;; i++) {
474
		if(ownbuf[i] == 0) {
481
		if(ownbuf[i] == 0) {
Line 641... Line 648...
641
				putnum(linenum);
648
				putnum(linenum);
642
			}
649
			}
643
			putstr(NEWLINE);
650
			putstr(NEWLINE);
644
			return 1;
651
			return 1;
645
		}
652
		}
-
 
653
	} else if(strcaseequ(rcmd, "PRINT")){
-
 
654
		if(arg[0] != 0){
-
 
655
			char sc = 0;
-
 
656
			int incr = 0;
-
 
657
			for(i = 0;; i++) {
-
 
658
				if(arg[i] != 0) sc = 0;
-
 
659
				if(arg[i] == ';' || arg[i] == 0) {
-
 
660
					char oldc = arg[i];
-
 
661
					arg[i] = 0;
-
 
662
 
-
 
663
					if(strlen(arg + incr) > 0){	
-
 
664
						char buffer[128];
-
 
665
	
-
 
666
						int number;
-
 
667
						int ret = pexpr(arg + incr, buffer, &number);
-
 
668
	
-
 
669
						if(ret == 0){
-
 
670
							putstr(buffer);
-
 
671
						}else if(ret == 1){
-
 
672
							putstr(" ");
-
 
673
							putnum(number);
-
 
674
						}else if(ret == -1){
-
 
675
							putstr("! Syntax error");
-
 
676
							if(linenum != -1) {
-
 
677
								putstr(" in line ");
-
 
678
								putnum(linenum);
-
 
679
							}
-
 
680
							putstr(NEWLINE);
-
 
681
							return 1;
-
 
682
						}
-
 
683
					}
-
 
684
					
-
 
685
					incr = i + 1;
-
 
686
					if(oldc == ';') sc = 1;
-
 
687
					if(oldc == 0) break;
-
 
688
				}
-
 
689
			}
-
 
690
			if(!sc) putstr(NEWLINE);
-
 
691
		}else{
-
 
692
			putstr(NEWLINE);
-
 
693
		}
646
#ifndef NO_PEEKPOKE
694
#ifndef NO_PEEKPOKE
647
	} else if(strcaseequ(rcmd, "POKE")) {
695
	} else if(strcaseequ(rcmd, "POKE")) {
648
		int argc = 0;
696
		int argc = 0;
649
		char* farg = 0;
697
		char* farg = 0;
650
		char* sarg = 0;
698
		char* sarg = 0;