Subversion Repositories Krakow BASIC

Rev

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

Rev 28 Rev 29
Line 1... Line 1...
1
/* $Id: basic.c 28 2024-09-05 00:13:42Z nishi $ */
1
/* $Id: basic.c 29 2024-09-05 04:27:28Z 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_MSX)
-
 
18
 
-
 
19
#define PLATFORM "MSX"
-
 
20
#define NEWLINE "\r\n"
-
 
21
#define BREAKKEY
-
 
22
 
-
 
23
#define mull(x, y) ((x) * (y))
-
 
24
#define divl(x, y) ((x) / (y))
-
 
25
 
-
 
26
#include <ctype.h>
-
 
27
#include <string.h>
-
 
28
#include <stdlib.h>
-
 
29
 
-
 
30
#define agetch(x) oggetch(0)
-
 
31
 
-
 
32
void basic(void);
-
 
33
 
-
 
34
void main(void){
-
 
35
	basic();
-
 
36
}
-
 
37
 
-
 
38
char _wgetch(char wait) __naked {
-
 
39
	__asm
-
 
40
		ld hl, #2
-
 
41
		add hl, sp
-
 
42
 
-
 
43
		ld a, (hl)
-
 
44
 
-
 
45
		cp #1
-
 
46
		jp z, wait
-
 
47
 
-
 
48
		call 0x9c
-
 
49
		jp nz, wait
-
 
50
		ld l, a
-
 
51
		ld h, #0
-
 
52
		ret
-
 
53
 
-
 
54
wait:
-
 
55
		call 0x9f
-
 
56
		ld l, a
-
 
57
		ld h, #0
-
 
58
		ret
-
 
59
	__endasm;
-
 
60
}
-
 
61
 
-
 
62
char oggetch(char wait){
-
 
63
	char c = _wgetch(wait);
-
 
64
	if(c == '\r') return '\n';
-
 
65
	if(c == 3) return 1;
-
 
66
	return c;
-
 
67
}
-
 
68
 
-
 
69
void putchar(char c) __naked {
-
 
70
	__asm
-
 
71
		ld hl, #2
-
 
72
		add hl, sp
-
 
73
		ld a, (hl)
-
 
74
		call 0xa2
-
 
75
		ret
-
 
76
	__endasm;
-
 
77
}
-
 
78
 
-
 
79
void putstr(const char* str){
-
 
80
	int i;
-
 
81
	for(i = 0; str[i] != 0; i++) putchar(str[i]);
-
 
82
}
-
 
83
 
-
 
84
void putnum(int a){
-
 
85
	char numbuf[64];
-
 
86
	int incr = 63;
-
 
87
	numbuf[incr--] = 0;
-
 
88
	int i;
-
 
89
	while(1){
-
 
90
		numbuf[incr--] = (a % 10) + '0';
-
 
91
		a /= 10;
-
 
92
		if(a == 0) break;
-
 
93
	}
-
 
94
	putstr(numbuf + incr + 1);
-
 
95
}
-
 
96
 
-
 
97
char strcaseequ(const char* a, const char* b){
-
 
98
	int i;
-
 
99
	if(strlen(a) != strlen(b)) return 0;
-
 
100
	for(i = 0; a[i] != 0; i++){
-
 
101
		if(toupper(a[i]) != toupper(b[i])) return 0;
-
 
102
	}
-
 
103
	return 1;
-
 
104
}
-
 
105
 
-
 
106
void change_color(unsigned char c) __naked {
-
 
107
	__asm
-
 
108
		ld hl, #2
-
 
109
		add hl, sp
-
 
110
 
-
 
111
		ld a, (hl)
-
 
112
		and a, #0xf
-
 
113
		ld (0xf3ea), a
-
 
114
 
-
 
115
		ld a, (hl)
-
 
116
		and a, #0xf0
-
 
117
		sra a
-
 
118
		sra a
-
 
119
		sra a
-
 
120
		sra a
-
 
121
		ld (0xf3e9), a
-
 
122
 
-
 
123
		ld a, #1
-
 
124
		call 0x62
-
 
125
 
-
 
126
		ret
-
 
127
	__endasm;
-
 
128
}
-
 
129
 
-
 
130
#define strnum atoi
-
 
131
 
-
 
132
void clear(void) __naked {
-
 
133
	__asm
-
 
134
		call 0x6f
-
 
135
		ld a, #15
-
 
136
		ld (0xf3e9), a
-
 
137
		ld a, #1
-
 
138
		ld (0xf3ea), a
-
 
139
		ld a, #1
-
 
140
		call 0x62
-
 
141
		ret
-
 
142
	__endasm;
-
 
143
}
-
 
144
 
-
 
145
#define killcursor(x)
-
 
146
#define cursor(x)
-
 
147
 
17
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
148
#elif defined(PLATFORM_UNIX) || defined(PLATFORM_WINDOWS) || defined(PLATFORM_ARDUINO) || defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
18
 
149
 
19
#if defined(PLATFORM_WINDOWS)
150
#if defined(PLATFORM_WINDOWS)
20
#define PLATFORM "Windows"
151
#define PLATFORM "Windows"
21
#define NO_PEEKPOKE
152
#define NO_PEEKPOKE
Line 831... Line 962...
831
	cursor();
962
	cursor();
832
	linebuf[0] = 0;
963
	linebuf[0] = 0;
833
	lineind = 0;
964
	lineind = 0;
834
	while(1) {
965
	while(1) {
835
		char c;
966
		char c;
836
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET)
967
#if defined(PLATFORM_C64) || defined(PLATFORM_A800XL) || defined(PLATFORM_APPLE2) || defined(PLATFORM_PET) || defined(PLATFORM_MSX)
837
		c = oggetch(1);
968
		c = oggetch(1);
838
#else
969
#else
839
		c = agetch();
970
		c = agetch();
840
#endif
971
#endif
841
		if(c != 0) {
972
		if(c != 0) {