BASIC compiler/interpreter for PIC32MX/MZ-80K
Revision | aeac15e5789baa88885c81631ead80c1d20b0893 (tree) |
---|---|
Time | 2019-04-01 09:53:54 |
Author | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
Interface directory in Zoea source file
@@ -32,7 +32,7 @@ | ||
32 | 32 | // Used for asm("wait") |
33 | 33 | #define WAIT "wait" |
34 | 34 | |
35 | -#include "videoout.h" | |
36 | -#include "SDFSIO.h" | |
37 | -#include "ps2keyboard.h" | |
35 | +#include "interface/videoout.h" | |
36 | +#include "interface/SDFSIO.h" | |
37 | +#include "interface/ps2keyboard.h" | |
38 | 38 | #include "debug.h" |
@@ -170,37 +170,37 @@ file_004=file.c | ||
170 | 170 | file_005=float.c |
171 | 171 | file_006=function.c |
172 | 172 | file_007=globalvars.c |
173 | -file_008=keyinput.c | |
174 | -file_009=library.c | |
175 | -file_010=linker.c | |
176 | -file_011=main.c | |
177 | -file_012=memory.c | |
178 | -file_013=music.c | |
179 | -file_014=operator.c | |
180 | -file_015=run.c | |
181 | -file_016=statement.c | |
182 | -file_017=string.c | |
183 | -file_018=value.c | |
184 | -file_019=debug.c | |
185 | -file_020=cmpdata.c | |
186 | -file_021=varname.c | |
187 | -file_022=envspecific.c | |
188 | -file_023=class.c | |
189 | -file_024=args.c | |
190 | -file_025=timer.c | |
173 | +file_008=library.c | |
174 | +file_009=linker.c | |
175 | +file_010=main.c | |
176 | +file_011=memory.c | |
177 | +file_012=music.c | |
178 | +file_013=operator.c | |
179 | +file_014=run.c | |
180 | +file_015=statement.c | |
181 | +file_016=string.c | |
182 | +file_017=value.c | |
183 | +file_018=debug.c | |
184 | +file_019=cmpdata.c | |
185 | +file_020=varname.c | |
186 | +file_021=envspecific.c | |
187 | +file_022=class.c | |
188 | +file_023=args.c | |
189 | +file_024=timer.c | |
190 | +file_025=interface\keyinput.c | |
191 | 191 | file_026=api.h |
192 | 192 | file_027=compiler.h |
193 | 193 | file_028=editor.h |
194 | -file_029=keyinput.h | |
195 | -file_030=main.h | |
196 | -file_031=ps2keyboard.h | |
197 | -file_032=SDFSIO.h | |
198 | -file_033=videoout.h | |
199 | -file_034=debug.h | |
200 | -file_035=envspecific.h | |
201 | -file_036=lib_videoout_machikania.X.a | |
202 | -file_037=libsdfsio.a | |
203 | -file_038=ps2keyboard.X.a | |
194 | +file_029=main.h | |
195 | +file_030=debug.h | |
196 | +file_031=envspecific.h | |
197 | +file_032=interface\keyinput.h | |
198 | +file_033=interface\ps2keyboard.h | |
199 | +file_034=interface\SDFSIO.h | |
200 | +file_035=interface\videoout.h | |
201 | +file_036=interface\lib_videoout_machikania.X.a | |
202 | +file_037=interface\libsdfsio.a | |
203 | +file_038=interface\ps2keyboard.X.a | |
204 | 204 | file_039=App_32MX170F256B.ld |
205 | 205 | file_040=help.txt |
206 | 206 | file_041=MACHIKAN.INI |
@@ -157,7 +157,8 @@ char* resolve_unresolved(int class){ | ||
157 | 157 | break; |
158 | 158 | default: |
159 | 159 | return ERR_UNKNOWN; |
160 | - } } | |
160 | + } | |
161 | + } | |
161 | 162 | return 0; |
162 | 163 | } |
163 | 164 |
@@ -194,6 +195,15 @@ char* update_class_info(int class){ | ||
194 | 195 | cstruct[z+1]: public method pointer |
195 | 196 | */ |
196 | 197 | |
198 | +/* | |
199 | + Object structure: | |
200 | + object[0]: pointer to class structure | |
201 | + object[1]: field value | |
202 | + ... | |
203 | + object[n]: field value | |
204 | + (according to class structure; public field(s) first, then private field(s)) | |
205 | +*/ | |
206 | + | |
197 | 207 | char* construct_class_structure(int class){ |
198 | 208 | int* record; |
199 | 209 | int i; |
@@ -482,6 +482,19 @@ char* interrupt_statement(); | ||
482 | 482 | #define ASM_LW_A0_XXXX_S8 0x8FC40000 |
483 | 483 | #define ASM_LW_A0_XXXX_S5 0x8EA40000 |
484 | 484 | |
485 | +// Interrupt macros | |
486 | +// 16 different type interruptions are possible | |
487 | +#define NUM_INTERRUPT_TYPES 1 | |
488 | +#define INTERRUPT_TIMER 0 | |
489 | +extern short g_interrupt_flags; | |
490 | +extern int g_int_vector[NUM_INTERRUPT_TYPES]; | |
491 | +#define raise_interrupt_flag(x) do {\ | |
492 | + if (g_int_vector[x]) {\ | |
493 | + IFS0bits.CS1IF=1;\ | |
494 | + g_interrupt_flags|=(1<<(x));\ | |
495 | + }\ | |
496 | +} while(0) | |
497 | + | |
485 | 498 | // Division macro for unsigned long |
486 | 499 | // Valid for 31 bits for all cases and 32 bits for some cases |
487 | 500 | #define div32(x,y,z) ((((unsigned long long)((unsigned long)(x)))*((unsigned long long)((unsigned long)(y))))>>(z)) |
@@ -228,12 +228,14 @@ static const char initext[]= | ||
228 | 228 | "#PRINT\n"; |
229 | 229 | |
230 | 230 | static const char bastext[]= |
231 | -"USETIMER 600\n" | |
232 | -"INTERRUPT TIMER,LABEL1\n" | |
233 | -"END\n" | |
234 | -"LABEL LABEL1\n" | |
235 | -"RETURN\n" | |
231 | +"I=1:WHILE I<=10\n" | |
232 | +"I=I+1:WEND\n" | |
236 | 233 | "\n" |
234 | +"I=1:DO\n" | |
235 | +"I=I+1:LOOP UNTIL I=11\n" | |
236 | +"\n" | |
237 | +"FOR I=1 TO 10\n" | |
238 | +"NEXT\n" | |
237 | 239 | "\n" |
238 | 240 | "\n" |
239 | 241 | "\n"; |
@@ -269,6 +271,8 @@ static const void* debugjumptable[]={ | ||
269 | 271 | FSfopen, |
270 | 272 | }; |
271 | 273 | |
274 | +#define for2(x,y,z) for(x=y;x<=z;x++) | |
275 | + | |
272 | 276 | int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){ |
273 | 277 | asm volatile(".set noreorder"); |
274 | 278 | asm volatile("b label1"); |
@@ -279,6 +283,10 @@ int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){ | ||
279 | 283 | asm volatile("nop"); |
280 | 284 | asm volatile("nop"); |
281 | 285 | asm volatile("nop"); |
286 | + int i; | |
287 | + for2(i,1,10){ | |
288 | + asm volatile("nop"); | |
289 | + } | |
282 | 290 | return a2+a3; |
283 | 291 | } |
284 | 292 |
@@ -4,14 +4,10 @@ | ||
4 | 4 | http://www.ze.em-net.ne.jp/~kenken/index.html |
5 | 5 | */ |
6 | 6 | |
7 | -/* | |
8 | - This file is shared by Megalopa and Zoea | |
9 | -*/ | |
10 | - | |
11 | 7 | #include <xc.h> |
12 | 8 | #include "api.h" |
13 | 9 | #include "editor.h" |
14 | -#include "keyinput.h" | |
10 | +#include "interface/keyinput.h" | |
15 | 11 | #include "compiler.h" |
16 | 12 | #include "main.h" |
17 | 13 |
@@ -8,8 +8,7 @@ | ||
8 | 8 | #include <xc.h> |
9 | 9 | #include "main.h" |
10 | 10 | #include "compiler.h" |
11 | -#include "videoout.h" | |
12 | -#include "ps2keyboard.h" | |
11 | +#include "api.h" | |
13 | 12 | |
14 | 13 | /* |
15 | 14 | int readbuttons(); |
@@ -5,7 +5,7 @@ | ||
5 | 5 | kmorimatsu@users.sourceforge.jp |
6 | 6 | */ |
7 | 7 | |
8 | -#define CPU_CLOCK_HZ 57272720 | |
8 | +#define CPU_CLOCK_HZ (g_use_graphic ? 53693175 : 57272720) | |
9 | 9 | #define PERSISTENT_RAM_SIZE (1024*52) |
10 | 10 | |
11 | 11 | int readbuttons(); |
@@ -157,7 +157,6 @@ char* rnd_function(){ | ||
157 | 157 | return 0; |
158 | 158 | } |
159 | 159 | |
160 | - | |
161 | 160 | char* chr_function(void){ |
162 | 161 | char* err; |
163 | 162 | err=get_value(); |
@@ -241,6 +241,23 @@ SETDIR x$ | ||
241 | 241 | エラーが有れば0以外を返す。 |
242 | 242 | (FEOF(), FGETC(), FINPUT$(), FLEN(), FSEEK(), GETDIR$()関数も参照のこと) |
243 | 243 | |
244 | +<タイマー及び割り込み関連命令と関数> | |
245 | +USETIMER x | |
246 | + タイマーを開始する。xはタイマーの速度を、Hzで指定(4以上の値)。 | |
247 | + | |
248 | +TIMER x | |
249 | + 現在のタイマー値を32ビット整数(x)で設定する。 | |
250 | + | |
251 | +TIMER() | |
252 | + タイマーの現在値を、32ビット整数値として返す。 | |
253 | + | |
254 | +INTERRUPT xxx,yyy[,z1[,z2 ... ]] | |
255 | + 割り込みを設定する。xxxは割り込みの種類、yyyは割り込み時のサブルーチンをラベ | |
256 | + ルで指定。z1, z2等を指定すると、割り込み用サブルーチンの引数となる。現在使用 | |
257 | + 可能な割り込みの種類は以下の通り。 | |
258 | + TIMER | |
259 | + タイマー割り込み。タイマー値が1増えるごとに割り込みがかかる。 | |
260 | + | |
244 | 261 | <整数型関数> |
245 | 262 | 以下、x, y, zは整数値を、x$, y$, z$は文字列を指します。[ ]は省略可能である事 |
246 | 263 | を示します。 |
@@ -13,7 +13,7 @@ | ||
13 | 13 | #include "main.h" |
14 | 14 | #include "compiler.h" |
15 | 15 | #include "api.h" |
16 | -#include "keyinput.h" | |
16 | +#include "interface/keyinput.h" | |
17 | 17 | #include "stdlib.h" |
18 | 18 | #include "math.h" |
19 | 19 |
@@ -84,7 +84,7 @@ | ||
84 | 84 | #include "api.h" |
85 | 85 | #include "compiler.h" |
86 | 86 | #include "editor.h" |
87 | -#include "keyinput.h" | |
87 | +#include "interface/keyinput.h" | |
88 | 88 | #include "main.h" |
89 | 89 | |
90 | 90 | //外付けクリスタル with PLL (16倍) |
@@ -12,17 +12,30 @@ | ||
12 | 12 | #include <xc.h> |
13 | 13 | #include "compiler.h" |
14 | 14 | |
15 | -#define INTERRUPT_TIMER 1 | |
15 | +/* | |
16 | + 16 different type interruptions are possible. | |
17 | + See definition in compiler.h like: | |
18 | + #define NUM_INTERRUPT_TYPES 1 | |
19 | + #define INTERRUPT_TIMER 0 | |
20 | + extern short g_interrupt_flags; | |
21 | + extern int g_int_vector[NUM_INTERRUPT_TYPES]; | |
22 | + #define raise_interrupt_flag(x) do {\ | |
23 | +*/ | |
16 | 24 | |
17 | 25 | // Timer value that increments every timer event |
18 | 26 | static int g_timer; |
19 | 27 | |
20 | -// Enable or disable interrupt | |
21 | -static char g_interrupt_enabled; | |
28 | +// Flags for interrupt | |
29 | +short g_interrupt_flags; | |
22 | 30 | // Jump address when interrupt |
23 | -static int g_int_vector; | |
31 | +int g_int_vector[NUM_INTERRUPT_TYPES]; | |
32 | + | |
33 | +/* | |
34 | + Initialize and termination | |
35 | +*/ | |
24 | 36 | |
25 | 37 | void init_timer(){ |
38 | + int i; | |
26 | 39 | // Stop timer, first |
27 | 40 | T1CON=0x0000; |
28 | 41 | IEC0bits.T1IE=0; |
@@ -31,7 +44,7 @@ void init_timer(){ | ||
31 | 44 | g_timer=0; |
32 | 45 | // Disable interrupt |
33 | 46 | IEC0bits.CS1IE=0; |
34 | - g_interrupt_enabled=0; | |
47 | + for(i=0;i<NUM_INTERRUPT_TYPES;i++) g_int_vector[i]=0; | |
35 | 48 | } |
36 | 49 | |
37 | 50 | void stop_timer(){ |
@@ -40,9 +53,12 @@ void stop_timer(){ | ||
40 | 53 | IEC0bits.T1IE=0; |
41 | 54 | // Disable interrupt |
42 | 55 | IEC0bits.CS1IE=0; |
43 | - g_interrupt_enabled=0; | |
44 | 56 | } |
45 | 57 | |
58 | +/* | |
59 | + Timer interprtation | |
60 | +*/ | |
61 | + | |
46 | 62 | // Interrupt handler |
47 | 63 | #ifndef __DEBUG |
48 | 64 | // Timer1 is also used for debug mode |
@@ -52,8 +68,8 @@ void T1Handler(void){ | ||
52 | 68 | g_timer++; |
53 | 69 | // Clear Timer1 interrupt flag |
54 | 70 | IFS0bits.T1IF=0; |
55 | - // Raise CS1 interrupt flag if required | |
56 | - IFS0bits.CS1IF=g_interrupt_enabled; | |
71 | + // Raise TIMER interrupt flag | |
72 | + raise_interrupt_flag(INTERRUPT_TIMER); | |
57 | 73 | } |
58 | 74 | |
59 | 75 | void lib_usetimer(int hz){ |
@@ -108,6 +124,7 @@ char* timer_statement(){ | ||
108 | 124 | char* err; |
109 | 125 | err=get_value(); |
110 | 126 | if (err) return err; |
127 | + i=(int)(&g_timer); | |
111 | 128 | check_obj_space(3); |
112 | 129 | g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,xxxx |
113 | 130 | g_object[g_objpos++]=0x34630000|(i&0x0000FFFF); // ori v1,v1,xxxx |
@@ -125,9 +142,15 @@ char* timer_function(){ | ||
125 | 142 | return 0; |
126 | 143 | } |
127 | 144 | |
128 | -//CS1 ? Core Software Interrupt 1 2 2 IFS0<2> IEC0<2> IPC0<20:18> IPC0<17:16> | |
145 | +/* | |
146 | + Interrupt interprtation | |
147 | + To cause interruption, use raise_interrupt_flag() macro | |
148 | + For example, | |
149 | + raise_interrupt_flag(INTERRUPT_TIMER); | |
150 | + | |
151 | +*/ | |
152 | + | |
129 | 153 | void BasicInt(int addr){ |
130 | -//TODO: here | |
131 | 154 | // $a0 is the address in BASIC code |
132 | 155 | asm volatile(".set noreorder"); |
133 | 156 | asm volatile("jr $a0"); |
@@ -135,14 +158,21 @@ void BasicInt(int addr){ | ||
135 | 158 | } |
136 | 159 | #pragma interrupt CS1Handler IPL1SOFT vector 2 |
137 | 160 | void CS1Handler(void){ |
161 | + int i; | |
162 | + while(g_interrupt_flags){ | |
163 | + for(i=0;i<NUM_INTERRUPT_TYPES;i++){ | |
164 | + if (g_interrupt_flags & (1<<i)) { | |
165 | + if (g_int_vector[i]) BasicInt(g_int_vector[i]); | |
166 | + g_interrupt_flags &= (1<<i)^0xffff; | |
167 | + } | |
168 | + } | |
169 | + } | |
138 | 170 | IFS0bits.CS1IF=0; |
139 | - BasicInt(g_int_vector); | |
140 | 171 | } |
141 | 172 | |
142 | -void _lib_interrupt(int itype, int address){ | |
143 | - // Ignore itype in the first imprementation | |
144 | - g_int_vector=address; | |
145 | - g_interrupt_enabled=1; | |
173 | +void lib_interrupt_main(int itype, int address){ | |
174 | + // Set address | |
175 | + g_int_vector[itype]=address; | |
146 | 176 | // CS1 interrupt: priority 1 |
147 | 177 | IPC0bits.CS1IP=1; |
148 | 178 | IPC0bits.CS1IS=0; |
@@ -150,9 +180,10 @@ void _lib_interrupt(int itype, int address){ | ||
150 | 180 | } |
151 | 181 | |
152 | 182 | void lib_interrupt(int itype){ |
183 | + // $ra contains the address for interrupt | |
153 | 184 | // $ra is 2 word before the interrupt address |
154 | 185 | asm volatile("addiu $a1,$ra,8"); |
155 | - asm volatile("j _lib_interrupt"); | |
186 | + asm volatile("j lib_interrupt_main"); | |
156 | 187 | } |
157 | 188 | |
158 | 189 | char* interrupt_statement(){ |
@@ -160,21 +191,24 @@ char* interrupt_statement(){ | ||
160 | 191 | int i,opos; |
161 | 192 | char* err; |
162 | 193 | next_position(); |
163 | - if (nextCodeIs("TIMER")) { itype=INTERRUPT_TIMER; | |
194 | + if (nextCodeIs("TIMER")) { | |
195 | + itype=INTERRUPT_TIMER; | |
164 | 196 | } else { |
165 | 197 | return ERR_SYNTAX; |
166 | 198 | } |
167 | 199 | // Detect ',' |
168 | 200 | next_position(); |
169 | - if (g_source[g_srcpos]!=',') return ERR_SYNTAX; g_srcpos++; | |
201 | + if (g_source[g_srcpos]!=',') return ERR_SYNTAX; | |
202 | + g_srcpos++; | |
170 | 203 | // Store address to call |
171 | 204 | call_quicklib_code(lib_interrupt,ASM_ORI_A0_ZERO_|itype); |
172 | - check_obj_space(2); | |
173 | - opos=g_objpos; | |
205 | + check_obj_space(4); | |
206 | + // Skip the region used for interrupt-calling | |
207 | + opos=g_objpos; | |
174 | 208 | g_object[g_objpos++]=0x10000000; // b xxxxx |
175 | 209 | g_object[g_objpos++]=0x00000000; // nop |
210 | + // Begin interrupt-calling region | |
176 | 211 | // Store $ra |
177 | - check_obj_space(2); | |
178 | 212 | g_object[g_objpos++]=0x27BDFFFC; // addiu sp,sp,-4 |
179 | 213 | g_object[g_objpos++]=0xAFBF0004; // sw ra,4(sp) |
180 | 214 | // Compile as GOSUB statement |
@@ -185,7 +219,9 @@ char* interrupt_statement(){ | ||
185 | 219 | g_object[g_objpos++]=0x8FBF0004; // lw ra,4(sp) |
186 | 220 | g_object[g_objpos++]=0x03E00008; // jr ra |
187 | 221 | g_object[g_objpos++]=0x08320004; // addiu sp,sp,4 |
222 | + // End interrupt-calling region | |
188 | 223 | // Complete B assembly |
189 | 224 | g_object[opos]|=g_objpos-opos-1; |
190 | 225 | return 0; |
191 | -} | |
\ No newline at end of file | ||
226 | +} | |
227 | + |