• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

BASIC compiler/interpreter for PIC32MX/MZ-80K (suspended)


コミットメタ情報

リビジョン236 (tree)
日時2018-06-18 08:58:12
作者kmorimatsu

ログメッセージ

Introduce common codes for Megalopa.

変更サマリ

差分

--- mips/branches/megalopa/compiler.h (revision 235)
+++ mips/branches/megalopa/compiler.h (revision 236)
@@ -5,6 +5,9 @@
55 kmorimatsu@users.sourceforge.jp
66 */
77
8+// Include envilonment specific configurations
9+#include "envspecific.h"
10+
811 /* Definitions */
912 // Number of variables (including temporary ones)
1013 #define ALLOC_VAR_NUM 36
@@ -12,17 +15,22 @@
1215 #define ALLOC_PCG_BLOCK 36
1316 // Block # dedicated for GRAPHIC
1417 #define ALLOC_GRAPHIC_BLOCK 37
18+// Block # dedicated for PLAYWAVE
19+#define ALLOC_WAVE_BLOCK 38
1520 // Start # for long name variables
16-#define ALLOC_LNV_BLOCK 38
21+#define ALLOC_LNV_BLOCK 39
1722 // Number of long name variables
1823 #define ALLOC_LNV_NUM 190
1924 // Start # of permanent blocks
20-#define ALLOC_PERM_BLOCK 228
25+#define ALLOC_PERM_BLOCK 229
2126 // Number of blocks that can be assigned for memory allocation (including all above)
22-#define ALLOC_BLOCK_NUM 238
27+#define ALLOC_BLOCK_NUM 239
2328
2429 // Persistent RAM bytes used for object, heap and exception data
25-#define PERSISTENT_RAM_SIZE (1024*100)
30+#ifndef PERSISTENT_RAM_SIZE
31+ // This must be defined in envspecific.h
32+ #define PERSISTENT_RAM_SIZE (1024*53)
33+#endif
2634 // Exception data area bytes
2735 #define EXCEPTION_DATA_SIZE (64)
2836 // RAM size used for object and heap
@@ -108,6 +116,7 @@
108116 LIB_GRAPHIC =LIB_STEP*46,
109117 LIB_WIDTH =LIB_STEP*47,
110118 LIB_FILE =LIB_STEP*48,
119+ LIB_PLAYWAVE =LIB_STEP*49,
111120 LIB_DEBUG =LIB_STEP*127,
112121 };
113122
@@ -200,7 +209,7 @@
200209 extern char g_disable_break;
201210 extern unsigned char* g_pcg_font;
202211 extern char g_use_graphic;
203-extern unsigned char* g_graphic_area;
212+extern unsigned short* g_graphic_area;
204213 extern int* g_libparams;
205214 extern int g_long_name_var_num;
206215 extern int g_temp;
@@ -230,17 +239,21 @@
230239 void err_unexp_next(void);
231240 void err_no_block(void);
232241 void err_invalid_param(void);
242+void err_file(void);
243+void err_wave(void);
233244 char* resolve_label(int s6);
234245
235246 void set_sound(unsigned long* data, int flagsLR);
236247 int musicRemaining(int flagsLR);
237248 void set_music(char* str, int flagsLR);
249+void stop_music(void);
238250 void init_music(void);
251+void play_wave(char* filename);
239252
240253 char* statement(void);
241254 char* gosub_statement();
242255 char* graphic_statement(enum functions func);
243-char* fopen_statement(enum functions func);
256+char* fopen_statement_main(enum functions func);
244257 char* fget_statement();
245258 char* fput_statement();
246259 char* fputc_statement();
@@ -318,6 +331,7 @@
318331 #define ERR_INVALID_PARAM (char*)(g_err_str[18])
319332 #define ERR_FILE (char*)(g_err_str[19])
320333 #define ERR_INVALID_VAR_NAME (char*)(g_err_str[20])
334+#define ERR_WAVE (char*)(g_err_str[21])
321335
322336 /* comple data type numbers */
323337 #define CMPDATA_RESERVED 0
@@ -357,12 +371,3 @@
357371 // Divide by 36 (valid for 32 bits)
358372 #define div36_32(x) div32(x,0xe38e38e4,37)
359373 #define rem36_32(x) (x-36*div36_32(x))
360-
361-// Check break key or buttons when executing BASIC code.
362-// In PS/2 mode, detect ctrl-break.
363-// In button mode, detect pushing four buttons are pushed simultaneously.
364-#define check_break() \
365- if (g_disable_break==0) {\
366- if (ps2keystatus[0x03] || KEYPORT&(KEYSTART | KEYFIRE | KEYUP | KEYDOWN | KEYLEFT | KEYRIGHT)==0) \
367- err_break();\
368- }
--- mips/branches/megalopa/debug.c (revision 235)
+++ mips/branches/megalopa/debug.c (revision 236)
@@ -223,8 +223,10 @@
223223
224224
225225 static const char bastext[]=
226-"PRINT 1,2,3\n"
227-"PRINT 4,5,6;789\n"
226+"CLS\n"
227+"DIM S(512)\n"
228+"EXEC 0x8fdd0012, 0x27bd07fc\n"
229+"print s\n"
228230 "\n";
229231
230232 /*
@@ -233,8 +235,8 @@
233235
234236 int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){
235237 // if (a0<0xa0008192) return 0xa0000000;
236- asm volatile("lw $v0,4($sp)");
237- asm volatile("addu $a0,$v0,$zero");
238+ asm volatile("lw $sp,18($fp)");
239+ asm volatile("addiu $sp,$sp,2044");
238240 return a2+a3;
239241 }
240242
--- mips/branches/megalopa/envspecific.c (nonexistent)
+++ mips/branches/megalopa/envspecific.c (revision 236)
@@ -0,0 +1,79 @@
1+/*
2+ This file is provided under the LGPL license ver 2.1.
3+ Written by Katsumi.
4+ http://hp.vector.co.jp/authors/VA016157/
5+ kmorimatsu@users.sourceforge.jp
6+*/
7+
8+#include <xc.h>
9+#include "compiler.h"
10+#include "lib_video_megalopa.h"
11+#include "ps2keyboard.h"
12+
13+/*
14+ int readbuttons();
15+ Read the tact switches.
16+ For Zoea, disable PS/2 keyboard and enable tact switches, then read.
17+*/
18+
19+int readbuttons(){
20+ return KEYPORT;
21+}
22+
23+/*
24+ void scroll(int x, int y);
25+ Scroll
26+*/
27+
28+void scroll(int x, int y){
29+
30+}
31+
32+void allocate_graphic_area(){
33+ if (!g_graphic_area) {
34+ // Use this pointer like unsigned short GVRAM[G_H_WORD*G_Y_RES] __attribute__ ((aligned (4)));
35+ g_graphic_area=alloc_memory(G_H_WORD*G_Y_RES/2,ALLOC_GRAPHIC_BLOCK);
36+ // Start graphic and clear screen
37+ init_graphic(g_graphic_area);
38+ }
39+}
40+
41+void usegraphic(int mode){
42+ // Modes; 0: stop GRAPHIC, 1: use GRAPHIC, 2: reset GRAPHIC and use it
43+ switch(mode){
44+ case 0:
45+ if (g_use_graphic){
46+ // Stop music before changing CPU speed
47+ stop_music();
48+ // Stop GRAPHIC if used
49+ set_graphmode(0);
50+ g_use_graphic=0;
51+ } else {
52+ // Prepare GRAPHIC area if not used and not allcated.
53+ allocate_graphic_area();
54+ }
55+ break;
56+ case 2:
57+ // Reset GRAPHIC and use it
58+ g_graphic_area=0;
59+ // Continue to case 1:
60+ case 1:
61+ case 3:
62+ default:
63+ // Use GRAPHIC
64+ allocate_graphic_area();
65+ // Start showing GRAPHIC with mode 1, but not with mode 3
66+ if (mode !=3 && !g_use_graphic){
67+ // Stop music before changing CPU speed
68+ stop_music();
69+ // Change to graphic mode.
70+ set_graphmode(1);
71+ g_use_graphic=1;
72+ }
73+ break;
74+ }
75+}
76+
77+void videowidth(int width){
78+
79+}
\ No newline at end of file
--- mips/branches/megalopa/envspecific.h (nonexistent)
+++ mips/branches/megalopa/envspecific.h (revision 236)
@@ -0,0 +1,30 @@
1+/*
2+ This file is provided under the LGPL license ver 2.1.
3+ Written by Katsumi.
4+ http://hp.vector.co.jp/authors/VA016157/
5+ kmorimatsu@users.sourceforge.jp
6+*/
7+
8+#define PERSISTENT_RAM_SIZE (1024*100)
9+
10+int readbuttons();
11+void scroll(int x, int y);
12+void usegraphic(int mode);
13+void videowidth(int width);
14+
15+
16+// 30 or 40 characters per line for Zoea
17+#define printcomma() printstr(" "+rem10_32((unsigned int)(cursor-TVRAM)))
18+
19+// Check break key or buttons when executing BASIC code.
20+// In PS/2 mode, detect ctrl-break.
21+// In button mode, detect pushing four buttons are pushed simultaneously.
22+#define check_break() \
23+ if (g_disable_break==0) {\
24+ if (ps2keystatus[0x03]) err_break();\
25+ }
26+
27+// Megalopa specific lists of statements and functions
28+#define ADDITIONAL_STATEMENTS
29+#define ADDITIONAL_INT_FUNCTIONS
30+#define ADDITIONAL_STR_FUNCTIONS
--- mips/branches/megalopa/error.c (revision 235)
+++ mips/branches/megalopa/error.c (revision 236)
@@ -29,6 +29,7 @@
2929 "Invalid parameter(s)",
3030 "File error",
3131 "Invalid variable name",
32+ "WAVE format error",
3233 };
3334
3435 char* resolve_label(int s6){
@@ -158,3 +159,8 @@
158159 end_exec();
159160 }
160161
162+void err_wave(void){
163+ printstr(ERR_WAVE);
164+ end_exec();
165+}
166+
--- mips/branches/megalopa/exception.c (revision 235)
+++ mips/branches/megalopa/exception.c (revision 236)
@@ -71,9 +71,8 @@
7171 #ifdef __DEBUG
7272 asm volatile("j 0xBFC00000");
7373 #else
74- buttonmode();
7574 for(i=0;i<100000;i++){
76- if((KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE))
75+ if((readbuttons()&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE))
7776 !=(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE)) i=0;
7877 }
7978 asm volatile("j SoftReset");
--- mips/branches/megalopa/function.c (revision 235)
+++ mips/branches/megalopa/function.c (revision 236)
@@ -5,12 +5,10 @@
55 kmorimatsu@users.sourceforge.jp
66 */
77
8-#include "main.h"
98 #include "compiler.h"
109 #include "api.h"
1110
1211 char* music_function(){
13-#ifdef MEGALOPA
1412 char* err;
1513 next_position();
1614 if (g_source[g_srcpos]==')') {
@@ -20,7 +18,6 @@
2018 err=get_value();
2119 if (err) return err;
2220 }
23-#endif
2421 call_lib_code(LIB_MUSICFUNC);
2522 return 0;
2623 }
@@ -470,30 +467,34 @@
470467 return 0;
471468 }
472469
470+static const void* str_func_list[]={
471+ "CHR$(",chr_function,
472+ "HEX$(",hex_function,
473+ "DEC$(",dec_function,
474+ "INPUT$(",input_function,
475+ "GOSUB$(",gosub_function,
476+ "ARGS$(",args_function,
477+ "READ$(",read_function,
478+ "SPRINTF$(",sprintf_function,
479+ "FLOAT$(",floatstr_function,
480+ "SYSTEM$(",system_function,
481+ "FINPUT$(",finput_function,
482+ // Additional functions follow
483+ ADDITIONAL_STR_FUNCTIONS
484+};
485+
473486 char* str_function(void){
474487 char* err;
475- if (nextCodeIs("CHR$(")) {
476- err=chr_function();
477- } else if (nextCodeIs("HEX$(")) {
478- err=hex_function();
479- } else if (nextCodeIs("DEC$(")) {
480- err=dec_function();
481- } else if (nextCodeIs("INPUT$(")) {
482- err=input_function();
483- } else if (nextCodeIs("GOSUB$(")) {
484- err=gosub_function();
485- } else if (nextCodeIs("ARGS$(")) {
486- err=args_function();
487- } else if (nextCodeIs("READ$(")) {
488- err=read_function();
489- } else if (nextCodeIs("SPRINTF$(")) {
490- err=sprintf_function();
491- } else if (nextCodeIs("FLOAT$(")) {
492- err=floatstr_function();
493- } else if (nextCodeIs("SYSTEM$(")) {
494- err=system_function();
495- } else if (nextCodeIs("FINPUT$(")) {
496- err=finput_function();
488+ int i;
489+ char* (*f)();
490+ // Seek the function
491+ for (i=0;i<sizeof(str_func_list)/sizeof(str_func_list[0]);i+=2){
492+ if (nextCodeIs((char*)str_func_list[i])) break;
493+ }
494+ if (i<sizeof(str_func_list)/sizeof(str_func_list[0])) {
495+ // Function found. Call it.
496+ f=str_func_list[i+1];
497+ err=f();
497498 } else {
498499 return ERR_SYNTAX;
499500 }
@@ -503,68 +504,63 @@
503504 return 0;
504505 }
505506
507+// Aliases follow
508+
509+char* gcolor_function(){
510+ return graphic_statement(FUNC_GCOLOR);
511+}
512+
513+char* fopen_function(){
514+ return fopen_statement_main(FUNC_FOPEN);
515+}
516+
517+static const void* int_func_list[]={
518+ "NOT(",not_function,
519+ "DRAWCOUNT(",drawcount_function,
520+ "MUSIC(",music_function,
521+ "TVRAM(",tvram_function,
522+ "KEYS(",keys_function,
523+ "READ(",read_function,
524+ "CREAD(",cread_function,
525+ "GOSUB(",gosub_function,
526+ "STRNCMP(",strncmp_function,
527+ "PEEK(",peek_function,
528+ "LEN(",len_function,
529+ "ASC(",asc_function,
530+ "SGN(",sgn_function,
531+ "ABS(",abs_function,
532+ "RND(",rnd_function,
533+ "VAL(",val_function,
534+ "INKEY(",inkey_function,
535+ "ARGS(",args_function,
536+ "SYSTEM(",system_function,
537+ "INT(",int_function,
538+ "GCOLOR(",gcolor_function,
539+ "FOPEN(",fopen_function,
540+ "FSEEK(",fseek_function,
541+ "FLEN(",flen_function,
542+ "FGET(",fget_statement,
543+ "FPUT(",fput_statement,
544+ "FGETC(",fgetc_function,
545+ "FPUTC(",fputc_statement,
546+ "FREMOVE(",fremove_statement,
547+ "FEOF(",feof_function,
548+ // Additional functions follow
549+ ADDITIONAL_INT_FUNCTIONS
550+};
551+
506552 char* function(void){
507553 char* err;
508- if (nextCodeIs("NOT(")) {
509- err=not_function();
510- } else if (nextCodeIs("DRAWCOUNT(")) {
511- err=drawcount_function();
512- } else if (nextCodeIs("MUSIC(")) {
513- err=music_function();
514- } else if (nextCodeIs("TVRAM(")) {
515- err=tvram_function();
516- } else if (nextCodeIs("KEYS(")) {
517- err=keys_function();
518- } else if (nextCodeIs("READ(")) {
519- err=read_function();
520- } else if (nextCodeIs("CREAD(")) {
521- err=cread_function();
522- } else if (nextCodeIs("GOSUB(")) {
523- err=gosub_function();
524- } else if (nextCodeIs("STRNCMP(")) {
525- err=strncmp_function();
526- } else if (nextCodeIs("PEEK(")) {
527- err=peek_function();
528- } else if (nextCodeIs("LEN(")) {
529- err=len_function();
530- } else if (nextCodeIs("ASC(")) {
531- err=asc_function();
532- } else if (nextCodeIs("SGN(")) {
533- err=sgn_function();
534- } else if (nextCodeIs("ABS(")) {
535- err=abs_function();
536- } else if (nextCodeIs("RND(")) {
537- err=rnd_function();
538- } else if (nextCodeIs("VAL(")) {
539- err=val_function();
540- } else if (nextCodeIs("INKEY(")) {
541- err=inkey_function();
542- } else if (nextCodeIs("ARGS(")) {
543- err=args_function();
544- } else if (nextCodeIs("SYSTEM(")) {
545- err=system_function();
546- } else if (nextCodeIs("INT(")) {
547- err=int_function();
548- } else if (nextCodeIs("GCOLOR(")) {
549- err=graphic_statement(FUNC_GCOLOR);
550- } else if (nextCodeIs("FOPEN(")) {
551- err=fopen_statement(FUNC_FOPEN);
552- } else if (nextCodeIs("FSEEK(")) {
553- err=fseek_function();
554- } else if (nextCodeIs("FLEN(")) {
555- err=flen_function();
556- } else if (nextCodeIs("FGET(")) {
557- err=fget_statement();
558- } else if (nextCodeIs("FPUT(")) {
559- err=fput_statement();
560- } else if (nextCodeIs("FGETC(")) {
561- err=fgetc_function();
562- } else if (nextCodeIs("FPUTC(")) {
563- err=fputc_statement();
564- } else if (nextCodeIs("FREMOVE(")) {
565- err=fremove_statement();
566- } else if (nextCodeIs("FEOF(")) {
567- err=feof_function();
554+ int i;
555+ char* (*f)();
556+ // Seek the function
557+ for (i=0;i<sizeof(int_func_list)/sizeof(int_func_list[0]);i+=2){
558+ if (nextCodeIs((char*)int_func_list[i])) break;
559+ }
560+ if (i<sizeof(int_func_list)/sizeof(int_func_list[0])) {
561+ // Function found. Call it.
562+ f=int_func_list[i+1];
563+ err=f();
568564 } else {
569565 return ERR_SYNTAX;
570566 }
@@ -571,5 +567,5 @@
571567 if (err) return err;
572568 if (g_source[g_srcpos]!=')') return ERR_SYNTAX;
573569 g_srcpos++;
574- return err;
570+ return 0;
575571 }
--- mips/branches/megalopa/globalvars.c (revision 235)
+++ mips/branches/megalopa/globalvars.c (revision 236)
@@ -67,7 +67,7 @@
6767 char g_use_graphic;
6868
6969 // Pointer to graphic RAM
70-unsigned char* g_graphic_area;
70+unsigned short* g_graphic_area;
7171
7272 // Parameter-containing block used for library
7373 int* g_libparams;
--- mips/branches/megalopa/library.c (revision 235)
+++ mips/branches/megalopa/library.c (revision 236)
@@ -150,8 +150,8 @@
150150 stopPCG();
151151 g_pcg_font=0;
152152 // Stop using graphic
153- set_graphmode(0);
154- g_use_graphic=0;
153+ g_use_graphic=1; // Force set_graphmode(0) (see usegraphic() function)
154+ usegraphic(0);
155155 }
156156
157157 void lib_let_str(char* str, int var_num){
@@ -275,13 +275,7 @@
275275 return;
276276 case 1:
277277 // ,
278-#ifdef MEGALOPA
279- i=rem9_32((unsigned int)(cursor-TVRAM));
280- printstr(" "+i);
281-#else
282- i=rem10_32((unsigned int)(cursor-TVRAM));
283- printstr(" "+i);
284-#endif
278+ printcomma();
285279 return;
286280 default:
287281 return;
@@ -308,12 +302,7 @@
308302
309303 int lib_keys(int mask){
310304 int keys;
311- // Enable tact switches
312- if (inPS2MODE()) {
313- buttonmode();
314- }
315-
316- keys=KEYPORT;
305+ keys=readbuttons();
317306 keys=
318307 ((keys&KEYUP)? 0:1)|
319308 ((keys&KEYDOWN)? 0:2)|
@@ -446,106 +435,11 @@
446435 pcg[ascii+1]=(fontdata2>>24)|((fontdata2&0xff0000)>>8)|((fontdata2&0xff00)<<8)|(fontdata2<<24);
447436 }
448437
449-void lib_scroll(int x,int y){
450- int i,j;
451- int vector=y*WIDTH_X1+x;
452- if (vector<0) {
453- // Copy data from upper address to lower address
454- for(i=0-vector;i<WIDTH_X1*WIDTH_Y;i++){
455- TVRAM[i+vector]=TVRAM[i];
456- TVRAM[WIDTH_X1*WIDTH_Y+i+vector]=TVRAM[WIDTH_X1*WIDTH_Y+i];
457- }
458- } else if (0<vector) {
459- // Copy data from lower address to upper address
460- for(i=WIDTH_X1*WIDTH_Y-vector-1;0<=i;i--){
461- TVRAM[i+vector]=TVRAM[i];
462- TVRAM[WIDTH_X1*WIDTH_Y+i+vector]=TVRAM[WIDTH_X1*WIDTH_Y+i];
463- }
464- } else {
465- return;
466- }
467- if (x<0) {
468- // Fill blanc at right
469- for(i=x;i<0;i++){
470- for(j=WIDTH_X1+i;j<WIDTH_X1*WIDTH_Y;j+=WIDTH_X1){
471- TVRAM[j]=0x00;
472- TVRAM[WIDTH_X1*WIDTH_Y+j]=cursorcolor;
473- }
474- }
475- } else if (0<x) {
476- // Fill blanc at left
477- for(i=0;i<x;i++){
478- for(j=i;j<WIDTH_X1*WIDTH_Y;j+=WIDTH_X1){
479- TVRAM[j]=0x00;
480- TVRAM[WIDTH_X1*WIDTH_Y+j]=cursorcolor;
481- }
482- }
483- }
484- if (y<0) {
485- // Fill blanc at bottom
486- for(i=WIDTH_X1*(WIDTH_Y+y);i<WIDTH_X1*WIDTH_Y;i++){
487- TVRAM[i]=0x00;
488- TVRAM[WIDTH_X1*WIDTH_Y+i]=cursorcolor;
489- }
490- } else if (0<y) {
491- // Fill blanc at top
492- for(i=0;i<WIDTH_X1*y;i++){
493- TVRAM[i]=0x00;
494- TVRAM[WIDTH_X1*WIDTH_Y+i]=cursorcolor;
495- }
496- }
438+void lib_usegraphic(int mode){
439+ usegraphic(mode);
440+ // Move current point to (0,0)
441+ g_prev_x=g_prev_y=0;
497442 }
498-
499-void lib_scroll40(int x,int y){
500- int i,j;
501- int vector=y*WIDTH_X2+x;
502- if (vector<0) {
503- // Copy data from upper address to lower address
504- for(i=0-vector;i<WIDTH_X2*WIDTH_Y;i++){
505- TVRAM[i+vector]=TVRAM[i];
506- TVRAM[WIDTH_X2*WIDTH_Y+i+vector]=TVRAM[WIDTH_X2*WIDTH_Y+i];
507- }
508- } else if (0<vector) {
509- // Copy data from lower address to upper address
510- for(i=WIDTH_X2*WIDTH_Y-vector-1;0<=i;i--){
511- TVRAM[i+vector]=TVRAM[i];
512- TVRAM[WIDTH_X2*WIDTH_Y+i+vector]=TVRAM[WIDTH_X2*WIDTH_Y+i];
513- }
514- } else {
515- return;
516- }
517- if (x<0) {
518- // Fill blanc at right
519- for(i=x;i<0;i++){
520- for(j=WIDTH_X2+i;j<WIDTH_X2*WIDTH_Y;j+=WIDTH_X2){
521- TVRAM[j]=0x00;
522- TVRAM[WIDTH_X2*WIDTH_Y+j]=cursorcolor;
523- }
524- }
525- } else if (0<x) {
526- // Fill blanc at left
527- for(i=0;i<x;i++){
528- for(j=i;j<WIDTH_X2*WIDTH_Y;j+=WIDTH_X2){
529- TVRAM[j]=0x00;
530- TVRAM[WIDTH_X2*WIDTH_Y+j]=cursorcolor;
531- }
532- }
533- }
534- if (y<0) {
535- // Fill blanc at bottom
536- for(i=WIDTH_X2*(WIDTH_Y+y);i<WIDTH_X2*WIDTH_Y;i++){
537- TVRAM[i]=0x00;
538- TVRAM[WIDTH_X2*WIDTH_Y+i]=cursorcolor;
539- }
540- } else if (0<y) {
541- // Fill blanc at top
542- for(i=0;i<WIDTH_X2*y;i++){
543- TVRAM[i]=0x00;
544- TVRAM[WIDTH_X2*WIDTH_Y+i]=cursorcolor;
545- }
546- }
547-}
548-
549443 void lib_wait(int period){
550444 int i;
551445 unsigned short dcount;
@@ -558,52 +452,6 @@
558452 }
559453 }
560454
561-void allocate_graphic_area(){
562- if (!g_graphic_area) {
563- // Use this pointer like unsigned short GVRAM[G_H_WORD*G_Y_RES] __attribute__ ((aligned (4)));
564- g_graphic_area=alloc_memory(G_H_WORD*G_Y_RES/2,ALLOC_GRAPHIC_BLOCK);
565- // Start graphic and clear screen
566- init_graphic(g_graphic_area);
567- // Move current point to (0,0)
568- g_prev_x=g_prev_y=0;
569- }
570-}
571-
572-void lib_usegraphic(int mode){
573- // Modes; 0: stop GRAPHIC, 1: use GRAPHIC, 2: reset GRAPHIC and use it
574- switch(mode){
575- case 0:
576- if (g_use_graphic){
577- // Stop GRAPHIC if used
578- set_graphmode(0);
579- g_use_graphic=0;
580- // Set timer4 for tempo
581- PR4=59473; // 3632*262/16-1
582- } else {
583- // Prepare GRAPHIC area if not used and not allcated.
584- allocate_graphic_area();
585- }
586- break;
587- case 2:
588- // Reset GRAPHIC and use it
589- g_graphic_area=0;
590- // Continue to case 1:
591- case 1:
592- case 3:
593- default:
594- // Use GRAPHIC
595- allocate_graphic_area();
596- // Start showing GRAPHIC with mode 1, but not with mode 3
597- if (mode !=3 && !g_use_graphic){
598- set_graphmode(1);
599- g_use_graphic=1;
600- // Set timer4 for tempo
601- PR4=55756; // ~=3405*262/16-1(55755.875)
602- }
603- break;
604- }
605-}
606-
607455 int lib_graphic(int v0,enum functions func){
608456 unsigned char b;
609457 int x1=g_libparams[1];
@@ -921,21 +769,6 @@
921769 return heap;
922770 };
923771
924-void lib_width(int width){
925-#ifdef ZOEA
926- switch(width){
927- case 30:
928- if (twidth!=30) set_width(0);
929- break;
930- case 40:
931- if (twidth!=40) set_width(1);
932- break;
933- default:
934- break;
935- }
936-#endif // ZOEA
937-}
938-
939772 int lib_file_textlen(FSFILE* fhandle){
940773 char buff[128];
941774 int i,textlen,len,seek;
@@ -1197,8 +1030,7 @@
11971030 lib_var_pop(a0,a1,g_libparams);
11981031 return v0;
11991032 case LIB_SCROLL:
1200- if (twidth==40) lib_scroll40(g_libparams[1],v0);
1201- else lib_scroll(g_libparams[1],v0);
1033+ scroll(g_libparams[1],v0);
12021034 return v0;
12031035 case LIB_FILE:
12041036 return lib_file((enum functions)(a3 & FUNC_MASK),g_libparams[1],g_libparams[2],v0);
@@ -1217,6 +1049,9 @@
12171049 case LIB_MUSIC:
12181050 set_music((char*)v0,a0);
12191051 return v0;
1052+ case LIB_PLAYWAVE:
1053+ play_wave((char*)v0);
1054+ return v0;
12201055 case LIB_SETDRAWCOUNT:
12211056 drawcount=(v0&0x0000FFFF);
12221057 return v0;
@@ -1262,7 +1097,7 @@
12621097 g_prev_x=g_prev_y=0;
12631098 return v0;
12641099 case LIB_WIDTH:
1265- lib_width(v0);
1100+ videowidth(v0);
12661101 return v0;
12671102 case LIB_COLOR:
12681103 setcursorcolor(v0);
--- mips/branches/megalopa/music.c (revision 235)
+++ mips/branches/megalopa/music.c (revision 236)
@@ -596,4 +596,11 @@
596596 // Go to next character
597597 while(0<g_mstr[g_mspos] && g_mstr[g_mspos]<=0x20 || g_mstr[g_mspos]=='|') g_mspos++;
598598 }
599+}
600+
601+void play_wave(char* filename){
602+
603+}
604+void stop_music(){
605+
599606 }
\ No newline at end of file
--- mips/branches/megalopa/run.c (revision 235)
+++ mips/branches/megalopa/run.c (revision 236)
@@ -75,7 +75,7 @@
7575
7676 printstr("BASIC "BASVER"\n");
7777 wait60thsec(15);
78- // Initialize music
78+ // Initialize music system
7979 init_music();
8080
8181 printstr("Compiling...");
--- mips/branches/megalopa/statement.c (revision 235)
+++ mips/branches/megalopa/statement.c (revision 236)
@@ -5,7 +5,6 @@
55 kmorimatsu@users.sourceforge.jp
66 */
77
8-#include "main.h"
98 #include "api.h"
109 #include "compiler.h"
1110
@@ -38,8 +37,8 @@
3837 if (err) return err;
3938 call_lib_code(LIB_LABEL);
4039 }
41-#ifdef MEGALOPA
4240 // 2nd param is optional
41+ next_position();
4342 if (g_source[g_srcpos]==',') {
4443 g_srcpos++;
4544 check_obj_space(2);
@@ -56,7 +55,6 @@
5655 check_obj_space(1);
5756 g_object[g_objpos++]=0x24040003; // addiu a0,zero,xx
5857 }
59-#endif
6058 call_lib_code(LIB_SOUND);
6159 return 0;
6260 }
@@ -64,8 +62,8 @@
6462 char *err;
6563 err=get_string();
6664 if (err) return err;
67-#ifdef MEGALOPA
6865 // 2nd param is optional
66+ next_position();
6967 if (g_source[g_srcpos]==',') {
7068 g_srcpos++;
7169 check_obj_space(2);
@@ -82,7 +80,6 @@
8280 check_obj_space(1);
8381 g_object[g_objpos++]=0x24040003; // addiu a0,zero,xx
8482 }
85-#endif
8683 call_lib_code(LIB_MUSIC);
8784 return 0;
8885 }
@@ -696,7 +693,7 @@
696693 return 0;
697694 }
698695
699-char* print_statement(enum libs lib_printstr, enum libs lib_string){
696+char* print_statement_main(enum libs lib_printstr, enum libs lib_string){
700697 char* err;
701698 char b1;
702699 int i;
@@ -1342,7 +1339,7 @@
13421339 return 0;
13431340 }
13441341
1345-char* fopen_statement(enum functions func){
1342+char* fopen_statement_main(enum functions func){
13461343 // func is either FUNC_FOPENST or FUNC_FOPEN
13471344 char* err;
13481345 // Get 1st
@@ -1397,10 +1394,6 @@
13971394 return 0;
13981395 }
13991396
1400-char* fprint_statement(){
1401- return print_statement(LIB_FILE | FUNC_FPRINTSTR,LIB_FILE | FUNC_FSTRING);
1402-}
1403-
14041397 char* fget_statement(){
14051398 return param2_statement(LIB_FILE | FUNC_FGET);
14061399 }
@@ -1453,6 +1446,14 @@
14531446 return 0;
14541447 }
14551448
1449+char* playwave_statement(){
1450+ char* err;
1451+ err=get_string();
1452+ if (err) return err;
1453+ call_lib_code(LIB_PLAYWAVE);
1454+ return 0;
1455+}
1456+
14561457 #ifdef __DEBUG
14571458 char* debug_statement(){
14581459 call_lib_code(LIB_DEBUG);
@@ -1460,142 +1461,147 @@
14601461 }
14611462 #endif
14621463
1464+// Aliases follow
14631465
1466+char* palette_statement(){
1467+ return param4_statement(LIB_PALETTE);
1468+}
1469+
1470+char* gpalette_statement(){
1471+ return param4_statement(LIB_GPALETTE);
1472+}
1473+
1474+char* print_statement(){
1475+ return print_statement_main(LIB_PRINTSTR,LIB_STRING);
1476+}
1477+
1478+char* pset_statement(){
1479+ return graphic_statement(FUNC_PSET);
1480+}
1481+
1482+char* line_statement(){
1483+ return graphic_statement(FUNC_LINE);
1484+}
1485+
1486+char* boxfill_statement(){
1487+ return graphic_statement(FUNC_BOXFILL);
1488+}
1489+
1490+char* circle_statement(){
1491+ return graphic_statement(FUNC_CIRCLE);
1492+}
1493+
1494+char* circlefill_statement(){
1495+ return graphic_statement(FUNC_CIRCLEFILL);
1496+}
1497+
1498+char* gprint_statement(){
1499+ return graphic_statement(FUNC_GPRINT);
1500+}
1501+
1502+char* putbmp_statement(){
1503+ return graphic_statement(FUNC_PUTBMP);
1504+}
1505+
1506+char* point_statement(){
1507+ return graphic_statement(FUNC_POINT);
1508+}
1509+
1510+char* fopen_statement(){
1511+ return fopen_statement_main(FUNC_FOPENST);
1512+}
1513+
1514+char* fprint_statement(){
1515+ return print_statement_main(LIB_FILE | FUNC_FPRINTSTR,LIB_FILE | FUNC_FSTRING);
1516+}
1517+
1518+static const void* statement_list[]={
1519+ "REM",rem_statement,
1520+ "SOUND ",sound_statement,
1521+ "MUSIC ",music_statement,
1522+ "DRAWCOUNT ",drawcount_statement,
1523+ "CURSOR ",cursor_statement,
1524+ "PALETTE ",palette_statement,
1525+ "GPALETTE ",gpalette_statement,
1526+ "BGCOLOR ",bgcolor_statement,
1527+ "CLS",cls_statement,
1528+ "GCLS",gcls_statement,
1529+ "COLOR ",color_statement,
1530+ "GCOLOR ",gcolor_statement,
1531+ "RESTORE ",restore_statement,
1532+ "DATA ",data_statement,
1533+ "CDATA ",cdata_statement,
1534+ "LABEL ",label_statement,
1535+ "DIM ",dim_statement,
1536+ "CLEAR",clear_statement,
1537+ "PRINT",print_statement,
1538+ "IF ",if_statement,
1539+ "ELSEIF ",elseif_statement,
1540+ "ELSE",else_statement,
1541+ "ENDIF",endif_statement,
1542+ "END",end_statement,
1543+ "EXEC ",exec_statement,
1544+ "GOTO ",goto_statement,
1545+ "GOSUB ",gosub_statement,
1546+ "RETURN",return_statement,
1547+ "POKE ",poke_statement,
1548+ "FOR ",for_statement,
1549+ "NEXT",next_statement,
1550+ "LET ",let_statement,
1551+ "PCG ",pcg_statement,
1552+ "USEPCG",usepcg_statement,
1553+ "SCROLL ",scroll_statement,
1554+ "WAIT ",wait_statement,
1555+ "USEGRAPHIC",usegraphic_statement,
1556+ "PSET ",pset_statement,
1557+ "LINE ",line_statement,
1558+ "BOXFILL ",boxfill_statement,
1559+ "CIRCLE ",circle_statement,
1560+ "CIRCLEFILL ",circlefill_statement,
1561+ "GPRINT ",gprint_statement,
1562+ "PUTBMP ",putbmp_statement,
1563+ "POINT ",point_statement,
1564+ "VAR ",var_statement,
1565+ "DO",do_statement,
1566+ "LOOP",loop_statement,
1567+ "WHILE ",while_statement,
1568+ "WEND",wend_statement,
1569+ "BREAK",break_statement,
1570+ "CONTINUE",continue_statement,
1571+ "SYSTEM",system_statement,
1572+ "WIDTH ",width_statement,
1573+ "FOPEN ",fopen_statement,
1574+ "FILE ",file_statement,
1575+ "FCLOSE",fclose_statement,
1576+ "FPRINT ",fprint_statement,
1577+ "FGET ",fget_statement,
1578+ "FPUT ",fput_statement,
1579+ "FPUTC ",fputc_statement,
1580+ "FSEEK ",fseek_statement,
1581+ "FREMOVE ",fremove_statement,
1582+ "USEVAR ",usevar_statement,
1583+ "PLAYWAVE ",playwave_statement,
1584+ // List of additional statements follows
1585+ ADDITIONAL_STATEMENTS
1586+};
1587+
14641588 char* statement(void){
14651589 char* err;
14661590 int prevpos;
1591+ int i;
1592+ char* (*f)();
14671593 // Clear flag for temp area usage.
14681594 g_temp_area_used=0;
14691595 // Initialize stack handler used for value
14701596 g_sdepth=g_maxsdepth=0;
1471- if (nextCodeIs("REM")) {
1472- err=rem_statement();
1473- } else if (nextCodeIs("SOUND ")) {
1474- err=sound_statement();
1475- } else if (nextCodeIs("MUSIC ")) {
1476- err=music_statement();
1477- } else if (nextCodeIs("DRAWCOUNT ")) {
1478- err=drawcount_statement();
1479- } else if (nextCodeIs("CURSOR ")) {
1480- err=cursor_statement();
1481- } else if (nextCodeIs("PALETTE ")) {
1482- err=param4_statement(LIB_PALETTE);
1483- } else if (nextCodeIs("GPALETTE ")) {
1484- err=param4_statement(LIB_GPALETTE);
1485- } else if (nextCodeIs("BGCOLOR ")) {
1486- err=bgcolor_statement();
1487- } else if (nextCodeIs("CLS")) {
1488- err=cls_statement();
1489- } else if (nextCodeIs("GCLS")) {
1490- err=gcls_statement();
1491- } else if (nextCodeIs("COLOR ")) {
1492- err=color_statement();
1493- } else if (nextCodeIs("GCOLOR ")) {
1494- err=gcolor_statement();
1495- } else if (nextCodeIs("RESTORE ")) {
1496- err=restore_statement();
1497- } else if (nextCodeIs("DATA ")) {
1498- err=data_statement();
1499- } else if (nextCodeIs("CDATA ")) {
1500- err=cdata_statement();
1501- } else if (nextCodeIs("LABEL ")) {
1502- err=label_statement();
1503- } else if (nextCodeIs("DIM ")) {
1504- err=dim_statement();
1505- } else if (nextCodeIs("CLEAR")) {
1506- err=clear_statement();
1507- } else if (nextCodeIs("PRINT")) {
1508- err=print_statement(LIB_PRINTSTR,LIB_STRING);
1509- } else if (nextCodeIs("IF ")) {
1510- err=if_statement();
1511- } else if (nextCodeIs("ELSEIF ")) {
1512- err=elseif_statement();
1513- } else if (nextCodeIs("ELSE")) {
1514- err=else_statement();
1515- } else if (nextCodeIs("ENDIF")) {
1516- err=endif_statement();
1517- } else if (nextCodeIs("END")) {
1518- err=end_statement();
1519- } else if (nextCodeIs("EXEC ")) {
1520- err=exec_statement();
1521- } else if (nextCodeIs("GOTO ")) {
1522- err=goto_statement();
1523- } else if (nextCodeIs("GOSUB ")) {
1524- err=gosub_statement();
1525- } else if (nextCodeIs("RETURN")) {
1526- err=return_statement();
1527- } else if (nextCodeIs("POKE ")) {
1528- err=poke_statement();
1529- } else if (nextCodeIs("FOR ")) {
1530- err=for_statement();
1531- } else if (nextCodeIs("NEXT")) {
1532- err=next_statement();
1533- } else if (nextCodeIs("LET ")) {
1534- err=let_statement();
1535- } else if (nextCodeIs("PCG ")) {
1536- err=pcg_statement();
1537- } else if (nextCodeIs("USEPCG")) {
1538- err=usepcg_statement();
1539- } else if (nextCodeIs("SCROLL ")) {
1540- err=scroll_statement();
1541- } else if (nextCodeIs("WAIT ")) {
1542- err=wait_statement();
1543- } else if (nextCodeIs("USEGRAPHIC")) {
1544- err=usegraphic_statement();
1545- } else if (nextCodeIs("PSET ")) {
1546- err=graphic_statement(FUNC_PSET);
1547- } else if (nextCodeIs("LINE ")) {
1548- err=graphic_statement(FUNC_LINE);
1549- } else if (nextCodeIs("BOXFILL ")) {
1550- err=graphic_statement(FUNC_BOXFILL);
1551- } else if (nextCodeIs("CIRCLE ")) {
1552- err=graphic_statement(FUNC_CIRCLE);
1553- } else if (nextCodeIs("CIRCLEFILL ")) {
1554- err=graphic_statement(FUNC_CIRCLEFILL);
1555- } else if (nextCodeIs("GPRINT ")) {
1556- err=graphic_statement(FUNC_GPRINT);
1557- } else if (nextCodeIs("PUTBMP ")) {
1558- err=graphic_statement(FUNC_PUTBMP);
1559- } else if (nextCodeIs("POINT ")) {
1560- err=graphic_statement(FUNC_POINT);
1561- } else if (nextCodeIs("VAR ")) {
1562- err=var_statement();
1563- } else if (nextCodeIs("DO")) {
1564- err=do_statement();
1565- } else if (nextCodeIs("LOOP")) {
1566- err=loop_statement();
1567- } else if (nextCodeIs("WHILE ")) {
1568- err=while_statement();
1569- } else if (nextCodeIs("WEND")) {
1570- err=wend_statement();
1571- } else if (nextCodeIs("BREAK")) {
1572- err=break_statement();
1573- } else if (nextCodeIs("CONTINUE")) {
1574- err=continue_statement();
1575- } else if (nextCodeIs("SYSTEM")) {
1576- err=system_statement();
1577- } else if (nextCodeIs("WIDTH ")) {
1578- err=width_statement();
1579- } else if (nextCodeIs("FOPEN ")) {
1580- err=fopen_statement(FUNC_FOPENST);
1581- } else if (nextCodeIs("FILE ")) {
1582- err=file_statement();
1583- } else if (nextCodeIs("FCLOSE")) {
1584- err=fclose_statement();
1585- } else if (nextCodeIs("FPRINT ")) {
1586- err=fprint_statement();
1587- } else if (nextCodeIs("FGET ")) {
1588- err=fget_statement();
1589- } else if (nextCodeIs("FPUT ")) {
1590- err=fput_statement();
1591- } else if (nextCodeIs("FPUTC ")) {
1592- err=fputc_statement();
1593- } else if (nextCodeIs("FSEEK ")) {
1594- err=fseek_statement();
1595- } else if (nextCodeIs("FREMOVE ")) {
1596- err=fremove_statement();
1597- } else if (nextCodeIs("USEVAR ")) {
1598- err=usevar_statement();
1597+ // Seek the statement
1598+ for (i=0;i<sizeof(statement_list)/sizeof(statement_list[0]);i+=2){
1599+ if (nextCodeIs((char*)statement_list[i])) break;
1600+ }
1601+ if (i<sizeof(statement_list)/sizeof(statement_list[0])) {
1602+ // Statement found. Call it.
1603+ f=statement_list[i+1];
1604+ err=f();
15991605 #ifdef __DEBUG
16001606 } else if (nextCodeIs("DEBUG")) {
16011607 err=debug_statement();