• R/O
  • HTTP
  • SSH
  • HTTPS

提交

標籤
無標籤

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

BASIC compiler/interpreter for PIC32MX/MZ-80K


Commit MetaInfo

修訂248e3318060e4f3fbda9efd2e276a9f65a03b534 (tree)
時間2019-03-17 09:19:35
作者Katsumi <kmorimatsu@sour...>
CommiterKatsumi

Log Message

Support loading class file from LIB directory.
SETDIR/GETDIR functions and statement.

Change Summary

差異

--- a/mips/classes/CSWTIF/CSWTIF.BAS
+++ b/mips/classes/CSWTIF/CSWTIF.BAS
@@ -1,5 +1,5 @@
11 REM CSWTIF.BAS ver 0.1
2-REM Class CSWPNG for MachiKania Type M
2+REM Class CSWTIF for MachiKania Type M
33 REM for showing TIFF picture file
44
55 REM FNAME: file name
--- a/mips/megalopa/cmpdata.c
+++ b/mips/megalopa/cmpdata.c
@@ -25,10 +25,22 @@
2525 data16: general 16 bit data (short)
2626 */
2727
28+/*
29+ CMPDATA_TEMP structure
30+ type: CMPDATA_TEMP (6)
31+ len: n+1
32+ data16: id
33+ record[1]: any data
34+ record[2]: any data
35+ ...
36+ record[n]: any data
37+*/
38+
2839 #define g_cmpdata g_objmax
2940
3041 static int* g_cmpdata_end;
3142 static int* g_cmpdata_point;
43+static unsigned short g_cmpdata_id;
3244
3345 /*
3446 Initialize routine must be called when starting compiler.
@@ -36,6 +48,15 @@ static int* g_cmpdata_point;
3648 void cmpdata_init(){
3749 g_cmpdata_end=g_objmax;
3850 g_cmpdata_point=g_objmax;
51+ g_cmpdata_id=1;
52+}
53+
54+/*
55+ Returns ID as 16 bit indivisual number
56+*/
57+unsigned short cmpdata_get_id(){
58+ if ((++g_cmpdata_id)==0) printstr("CMPDATA: no more ID!\n");
59+ return g_cmpdata_id;
3960 }
4061
4162 /*
--- a/mips/megalopa/compiler.h
+++ b/mips/megalopa/compiler.h
@@ -122,6 +122,9 @@ enum libs{
122122 LIB_FILE =LIB_STEP*48,
123123 LIB_PLAYWAVE =LIB_STEP*49,
124124 LIB_PLAYWAVEFUNC =LIB_STEP*50,
125+ LIB_SETDIR =LIB_STEP*51,
126+ LIB_SETDIRFUNC =LIB_STEP*52,
127+ LIB_GETDIR =LIB_STEP*53,
125128 LIB_DEBUG =LIB_STEP*127,
126129 };
127130
@@ -321,6 +324,7 @@ void blue_screen(void);
321324 char* get_float();
322325
323326 void cmpdata_init();
327+unsigned short cmpdata_get_id();
324328 char* cmpdata_insert(unsigned char type, short data16, int* data, unsigned char num);
325329 void cmpdata_reset();
326330 int* cmpdata_find(unsigned char type);
@@ -401,6 +405,7 @@ char* resolve_unresolved(int class);
401405 #define CMPDATA_FIELD 3
402406 #define CMPDATA_STATIC 4
403407 #define CMPDATA_UNSOLVED 5
408+#define CMPDATA_TEMP 6
404409 // Sub types follow
405410 #define CMPTYPE_PUBLIC_FIELD 0
406411 #define CMPTYPE_PRIVATE_FIELD 1
--- a/mips/megalopa/debug.c
+++ b/mips/megalopa/debug.c
@@ -227,22 +227,12 @@ static const char initext[]=
227227 "#PRINT\n"
228228 "#PRINT\n";
229229
230-
231230 static const char bastext[]=
232-"USECLASS CLASS1\n"
233-"CLS\n"
234-"dim o(9)\n"
235-"for j=1 to 100\n"
236-" cursor 0,0\n"
237-" for i=1 to 9\n"
238-" o(i)=new(CLASS1)\n"
239-" next\n"
240-" for i=1 to 9\n"
241-" a=o(i)\n"
242-" print hex$(a),\n"
243-" delete a\n"
244-" next\n"
245-"next\n"
231+"print getdir$()\n"
232+"end\n"
233+"\n"
234+"\n"
235+"\n"
246236 "\n"
247237 "\n"
248238 "\n";
@@ -280,7 +270,14 @@ static const void* debugjumptable[]={
280270
281271 int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){
282272 asm volatile(".set noreorder");
283- asm volatile("lw $a0,-8($s5)");
273+ asm volatile("lw $a0,4($s5)");
274+ asm volatile("lw $a1,8($s5)");
275+ asm volatile("lw $a2,12($s5)");
276+ asm volatile("lw $a3,16($s5)");
277+ asm volatile("nop");
278+ asm volatile("nop");
279+ asm volatile("nop");
280+ asm volatile("nop");
284281 asm volatile("nop");
285282 asm volatile("nop");
286283 asm volatile("nop");
--- a/mips/megalopa/file.c
+++ b/mips/megalopa/file.c
@@ -170,11 +170,14 @@ int compile_and_link_file(char* buff,char* appname){
170170 }
171171
172172 int compile_and_link_class(char* buff,int class){
173- int i;
173+ int i,j;
174174 char* err;
175175 char* classname;
176176 char classfile[13];
177+ char classdir[11];
177178 int data[2];
179+ unsigned short cwd_id;
180+ int* record;
178181 while(1){
179182 // Begin compiling class
180183 err=begin_compiling_class(class);
@@ -187,9 +190,41 @@ int compile_and_link_class(char* buff,int class){
187190 classfile[i++]='A';
188191 classfile[i++]='S';
189192 classfile[i]=0;
190- // Compile it
191- i=compile_and_link_file(buff,&classfile[0]);
192- if (i) break;
193+ // Check if file exists in current directory
194+ err=init_file(buff,&classfile[0]);
195+ if (!err) {
196+ // Class file found in current directory
197+ close_file();
198+ // Compile it
199+ i=compile_and_link_file(buff,&classfile[0]);
200+ if (i) break;
201+ } else {
202+ // Class file not found in current directory.
203+ // Try library directory, for example, \LIB\CLASS1\CLASS1.BAS
204+ // Store current directory, first
205+ if (!FSgetcwd(buff,256)) break;
206+ for(i=0;buff[i];i++);
207+ cwd_id=cmpdata_get_id();
208+ if (!cwd_id) break;
209+ err=cmpdata_insert(CMPDATA_TEMP,cwd_id,(int*)(&buff[0]),(i+1+3)>>2);
210+ if (err) break;
211+ // Change current directory to class library directory
212+ for(i=0;classdir[i]="\\LIB\\"[i];i++);
213+ for(j=0;classdir[i++]=classname[j];j++);
214+ classdir[i]=0;
215+ FSchdir(classdir);
216+ // Compile class file
217+ i=compile_and_link_file(buff,&classfile[0]);
218+ // Restore current dirctory
219+ cmpdata_reset();
220+ while(record=cmpdata_find(CMPDATA_TEMP)){
221+ if (cwd_id=(record[0]&0xffff)) break;
222+ }
223+ if (!record) break;
224+ FSchdir((char*)(&record[1]));
225+ cmpdata_delete(record);
226+ if (i) break;
227+ }
193228 // End compiling class
194229 err=end_compiling_class(class);
195230 if (err) break;
--- a/mips/megalopa/function.c
+++ b/mips/megalopa/function.c
@@ -379,6 +379,19 @@ char* playwave_function(){
379379 return 0;
380380 }
381381
382+char* setdir_function(){
383+ char* err;
384+ err=get_string();
385+ if (err) return err;
386+ call_lib_code(LIB_SETDIRFUNC);
387+ return 0;
388+}
389+
390+char* getdir_function(){
391+ call_lib_code(LIB_GETDIR);
392+ return 0;
393+}
394+
382395 char* float_constant(float val){
383396 volatile int i;
384397 ((float*)(&i))[0]=val;
@@ -498,6 +511,7 @@ static const void* str_func_list[]={
498511 "FLOAT$(",floatstr_function,
499512 "SYSTEM$(",system_function,
500513 "FINPUT$(",finput_function,
514+ "GETDIR$(",getdir_function,
501515 // Additional functions follow
502516 ADDITIONAL_STR_FUNCTIONS
503517 };
@@ -582,6 +596,7 @@ static const void* int_func_list[]={
582596 "FEOF(",feof_function,
583597 "PLAYWAVE(",playwave_function,
584598 "NEW(",new_function,
599+ "SETDIR(",setdir_function,
585600 // Additional functions follow
586601 ADDITIONAL_INT_FUNCTIONS
587602 };
--- a/mips/megalopa/library.c
+++ b/mips/megalopa/library.c
@@ -25,6 +25,20 @@ static int g_gcolor=7;
2525 static int g_prev_x=0;
2626 static int g_prev_y=0;
2727
28+int lib_setdir(int mode,char* path){
29+ int ret;
30+ ret=FSchdir(path);
31+ if (mode==LIB_SETDIR && ret) err_file();
32+ return ret;
33+}
34+
35+int lib_getdir(){
36+ char* path;
37+ path=calloc_memory(32,-1);
38+ FSgetcwd (path,128);
39+ return (int)path;
40+}
41+
2842 int lib_read(int mode, unsigned int label){
2943 unsigned int i,code,code2;
3044 static unsigned int pos=0;
@@ -1016,6 +1030,11 @@ int _call_library(int a0,int a1,int v0,enum libs a3){
10161030 case LIB_SETDRAWCOUNT:
10171031 drawcount=(v0&0x0000FFFF);
10181032 return v0;
1033+ case LIB_GETDIR:
1034+ return lib_getdir();
1035+ case LIB_SETDIRFUNC:
1036+ case LIB_SETDIR:
1037+ return lib_setdir(a3,(char*)v0);
10191038 case LIB_DRAWCOUNT:
10201039 return drawcount;
10211040 case LIB_SYSTEM:
--- a/mips/megalopa/reservednames.js
+++ b/mips/megalopa/reservednames.js
@@ -88,6 +88,7 @@ var namearray=[
8888 'FSEEK',
8989 'GCLS',
9090 'GCOLOR',
91+ 'GETDIR',
9192 'GOSUB',
9293 'GOTO',
9394 'GPRINT',
@@ -128,6 +129,7 @@ var namearray=[
128129 'RETURN',
129130 'RND',
130131 'SCROLL',
132+ 'SETDIR',
131133 'SGN',
132134 'SIN',
133135 'SINH',
--- a/mips/megalopa/statement.c
+++ b/mips/megalopa/statement.c
@@ -1542,6 +1542,14 @@ char* useclass_statement(){
15421542 return 0;
15431543 }
15441544
1545+char* setdir_statement(){
1546+ char* err;
1547+ err=get_string();
1548+ if (err) return err;
1549+ call_lib_code(LIB_SETDIR);
1550+ return 0;
1551+}
1552+
15451553 #ifdef __DEBUG
15461554 char* debug_statement(){
15471555 call_lib_code(LIB_DEBUG);
@@ -1689,6 +1697,7 @@ static const void* statement_list[]={
16891697 "DELETE ",delete_statement,
16901698 "CALL ",call_statement,
16911699 "STATIC ",static_statement,
1700+ "SETDIR ",setdir_statement,
16921701 // List of additional statements follows
16931702 ADDITIONAL_STATEMENTS
16941703 };
--- a/mips/megalopa/varname.c
+++ b/mips/megalopa/varname.c
@@ -69,6 +69,7 @@ static const int reserved_var_names[]={
6969 0x00aefdec, /*FSEEK*/
7070 0x00063b90, /*GCLS*/
7171 0x1a808bcb, /*GCOLOR*/
72+ 0x1ab733b3, /*GETDIR*/
7273 0x00c60f03, /*GOSUB*/
7374 0x0006796c, /*GOTO*/
7475 0x1bcfcc39, /*GPRINT*/
@@ -109,6 +110,7 @@ static const int reserved_var_names[]={
109110 0x425c9703, /*RETURN*/
110111 0x00015e69, /*RND*/
111112 0x45c26d49, /*SCROLL*/
113+ 0x45f6e3b3, /*SETDIR*/
112114 0x00016287, /*SGN*/
113115 0x000162cf, /*SIN*/
114116 0x000ee52d, /*SINH*/