BASIC compiler/interpreter for PIC32MX/MZ-80K
Révision | ca87cc9f5488601454618a4fbf7a71d06a2ce98b (tree) |
---|---|
l'heure | 2019-03-25 07:01:27 |
Auteur | Katsumi <kmorimatsu@sour...> |
Commiter | Katsumi |
USETIMER, TIMER, and TIMER()
@@ -68,6 +68,7 @@ file_040=. | ||
68 | 68 | file_041=. |
69 | 69 | file_042=. |
70 | 70 | file_043=. |
71 | +file_044=. | |
71 | 72 | [GENERATED_FILES] |
72 | 73 | file_000=no |
73 | 74 | file_001=no |
@@ -113,6 +114,7 @@ file_040=no | ||
113 | 114 | file_041=no |
114 | 115 | file_042=no |
115 | 116 | file_043=no |
117 | +file_044=no | |
116 | 118 | [OTHER_FILES] |
117 | 119 | file_000=no |
118 | 120 | file_001=no |
@@ -153,11 +155,12 @@ file_035=no | ||
153 | 155 | file_036=no |
154 | 156 | file_037=no |
155 | 157 | file_038=no |
156 | -file_039=yes | |
158 | +file_039=no | |
157 | 159 | file_040=yes |
158 | 160 | file_041=yes |
159 | 161 | file_042=yes |
160 | 162 | file_043=yes |
163 | +file_044=yes | |
161 | 164 | [FILE_INFO] |
162 | 165 | file_000=compiler.c |
163 | 166 | file_001=editor.c |
@@ -184,25 +187,26 @@ file_021=varname.c | ||
184 | 187 | file_022=envspecific.c |
185 | 188 | file_023=class.c |
186 | 189 | file_024=args.c |
187 | -file_025=api.h | |
188 | -file_026=compiler.h | |
189 | -file_027=editor.h | |
190 | -file_028=keyinput.h | |
191 | -file_029=main.h | |
192 | -file_030=ps2keyboard.h | |
193 | -file_031=SDFSIO.h | |
194 | -file_032=videoout.h | |
195 | -file_033=debug.h | |
196 | -file_034=envspecific.h | |
197 | -file_035=lib_videoout_machikania.X.a | |
198 | -file_036=libsdfsio.a | |
199 | -file_037=ps2keyboard.X.a | |
200 | -file_038=App_32MX170F256B.ld | |
201 | -file_039=help.txt | |
202 | -file_040=MACHIKAN.INI | |
203 | -file_041=reservednames.js | |
204 | -file_042=class.txt | |
205 | -file_043=sharedfiles.js | |
190 | +file_025=timer.c | |
191 | +file_026=api.h | |
192 | +file_027=compiler.h | |
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 | |
204 | +file_039=App_32MX170F256B.ld | |
205 | +file_040=help.txt | |
206 | +file_041=MACHIKAN.INI | |
207 | +file_042=reservednames.js | |
208 | +file_043=class.txt | |
209 | +file_044=sharedfiles.js | |
206 | 210 | [SUITE_INFO] |
207 | 211 | suite_guid={62D235D8-2DB2-49CD-AF24-5489A6015337} |
208 | 212 | suite_state= |
@@ -368,6 +368,13 @@ char* static_statement(); | ||
368 | 368 | char* static_method(char type); |
369 | 369 | char* resolve_unresolved(int class); |
370 | 370 | |
371 | +void init_timer(); | |
372 | +void stop_timer(); | |
373 | +char* usetimer_statement(); | |
374 | +char* timer_statement(); | |
375 | +char* timer_function(); | |
376 | + | |
377 | + | |
371 | 378 | /* Error messages */ |
372 | 379 | #define ERR_SYNTAX (char*)(g_err_str[0]) |
373 | 380 | #define ERR_NE_BINARY (char*)(g_err_str[1]) |
@@ -228,13 +228,13 @@ static const char initext[]= | ||
228 | 228 | "#PRINT\n"; |
229 | 229 | |
230 | 230 | static const char bastext[]= |
231 | -"REM 1\n" | |
232 | -"REM 2\n" | |
233 | -"REM 3\n" | |
231 | +"USETIMER 600\n" | |
232 | +"END\n" | |
233 | +"\n" | |
234 | +"\n" | |
235 | +"\n" | |
234 | 236 | "\n" |
235 | -"CLS\n" | |
236 | 237 | "\n" |
237 | -"LABEL TST:PRINT\n" | |
238 | 238 | "\n"; |
239 | 239 | |
240 | 240 | static const char class1text[]= |
@@ -270,13 +270,9 @@ static const void* debugjumptable[]={ | ||
270 | 270 | |
271 | 271 | int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){ |
272 | 272 | asm volatile(".set noreorder"); |
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"); | |
273 | + asm volatile("lui $v1,0x1234"); | |
274 | + asm volatile("ori $v1,$v1,0x5678"); | |
275 | + asm volatile("sw $v0,0($v1)"); | |
280 | 276 | asm volatile("nop"); |
281 | 277 | asm volatile("nop"); |
282 | 278 | asm volatile("nop"); |
@@ -5,6 +5,7 @@ | ||
5 | 5 | kmorimatsu@users.sourceforge.jp |
6 | 6 | */ |
7 | 7 | |
8 | +#define CPU_CLOCK_HZ 57272720 | |
8 | 9 | #define PERSISTENT_RAM_SIZE (1024*52) |
9 | 10 | |
10 | 11 | int readbuttons(); |
@@ -597,6 +597,7 @@ static const void* int_func_list[]={ | ||
597 | 597 | "PLAYWAVE(",playwave_function, |
598 | 598 | "NEW(",new_function, |
599 | 599 | "SETDIR(",setdir_function, |
600 | + "TIMER(",timer_function, | |
600 | 601 | // Additional functions follow |
601 | 602 | ADDITIONAL_INT_FUNCTIONS |
602 | 603 | }; |
@@ -14,6 +14,72 @@ | ||
14 | 14 | // lib_colortext32.a : カラービデオ信号出力システムライブラリ(30×27テキスト版) |
15 | 15 | // libsdfsio.a : SDカードアクセス用ライブラリ |
16 | 16 | |
17 | +/* | |
18 | + PIC32MX ペリフェラル使用状況 | |
19 | + | |
20 | + 割り込み | |
21 | + NTSC, Timer2, vector 8, priority 5 | |
22 | + NTSC, OC3, vector 14, priority 5 | |
23 | + NTSC, OC2, vector 10, priority 5 | |
24 | + NTSC, OC1, vector 6, priority 5 | |
25 | + PS/2, CNF, vector 33, priority 6 | |
26 | + PS/2, Timer5, vector 20, priority 4 | |
27 | + MUSIC, CS0, vector 1, priority 2 | |
28 | + TIMER, Timer1, vector 4, priority 3 | |
29 | + INT, CS1, vector 2, priority 1 | |
30 | + | |
31 | + タイマー | |
32 | + Timer1 BASIC用タイマー | |
33 | + Timer2 NTSC | |
34 | + Timer3 MUSIC/PWM | |
35 | + Timer4 MUSIC | |
36 | + Timer5 PS/2 | |
37 | + | |
38 | + DMA | |
39 | + DMA0 未使用 | |
40 | + DMA1 未使用 | |
41 | + DMA2 MUSIC | |
42 | + DMA3 PS/2 | |
43 | + | |
44 | + Output compair | |
45 | + OC1 NTSC | |
46 | + OC2 NTSC | |
47 | + OC3 NTSC | |
48 | + OC4 MUSIC/PWM | |
49 | + OC5 | |
50 | + | |
51 | + SPI | |
52 | + SPI1 未使用 | |
53 | + SPI2 マルチメディアカード | |
54 | + | |
55 | + I2C | |
56 | + I2C1 未使用 | |
57 | + I2C2 未使用 | |
58 | + | |
59 | + ポート使用 | |
60 | + A0 MMC | |
61 | + A1 PS2/button 切換え | |
62 | + A2 Crystal | |
63 | + A3 Crystal | |
64 | + A4 MMC | |
65 | + B0 NTSC | |
66 | + B1 NTSC | |
67 | + B2 NTSC | |
68 | + B3 NTSC | |
69 | + B4 NTSC | |
70 | + B5 MMC | |
71 | + B6 未使用 | |
72 | + B7 button | |
73 | + B8 PS2/button | |
74 | + B9 PS2/button | |
75 | + B10 button | |
76 | + B11 button | |
77 | + B12 未使用 | |
78 | + B13 audio out | |
79 | + B14 button | |
80 | + B15 MMC | |
81 | +*/ | |
82 | + | |
17 | 83 | #include <xc.h> |
18 | 84 | #include "api.h" |
19 | 85 | #include "compiler.h" |
@@ -139,6 +139,7 @@ var namearray=[ | ||
139 | 139 | 'SYSTEM', |
140 | 140 | 'TAN', |
141 | 141 | 'TANH', |
142 | + 'TIMER', | |
142 | 143 | 'TVRAM', |
143 | 144 | 'UNTIL', |
144 | 145 | 'USEPCG', |
@@ -116,6 +116,7 @@ int runbasic(char *appname,int test){ | ||
116 | 116 | |
117 | 117 | // Warm up environment |
118 | 118 | pre_run(); |
119 | + init_timer(); | |
119 | 120 | |
120 | 121 | // Execute program |
121 | 122 | // Start program from the beginning of RAM. |
@@ -126,6 +127,7 @@ int runbasic(char *appname,int test){ | ||
126 | 127 | // Cool down environment |
127 | 128 | post_run(); |
128 | 129 | lib_file(FUNC_FINIT,0,0,0); |
130 | + stop_timer(); | |
129 | 131 | |
130 | 132 | return 0; |
131 | 133 | } |
@@ -1717,6 +1717,8 @@ static const void* statement_list[]={ | ||
1717 | 1717 | "STATIC ",static_statement, |
1718 | 1718 | "SETDIR ",setdir_statement, |
1719 | 1719 | "OPTION ",option_statement, |
1720 | + "USETIMER ",usetimer_statement, | |
1721 | + "TIMER ",timer_statement, | |
1720 | 1722 | // List of additional statements follows |
1721 | 1723 | ADDITIONAL_STATEMENTS |
1722 | 1724 | }; |
@@ -0,0 +1,149 @@ | ||
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 | +/* | |
9 | + This file is shared by Megalopa and Zoea | |
10 | +*/ | |
11 | + | |
12 | +#include <xc.h> | |
13 | +#include "compiler.h" | |
14 | + | |
15 | +// Timer value that increments every timer event | |
16 | +static int g_timer; | |
17 | + | |
18 | +// Enable or disable interrupt | |
19 | +static char g_interrupt_enabled; | |
20 | +// Jump address when interrupt | |
21 | +static void* g_int_vector; | |
22 | + | |
23 | +void init_timer(){ | |
24 | + // Stop timer, first | |
25 | + T1CON=0x0000; | |
26 | + IEC0bits.T1IE=0; | |
27 | + TMR1=0; | |
28 | + PR1=0xffff; | |
29 | + g_timer=0; | |
30 | + // Disable interrupt | |
31 | + IEC0bits.CS1IE=0; | |
32 | + g_interrupt_enabled=0; | |
33 | +} | |
34 | + | |
35 | +void stop_timer(){ | |
36 | + // Stop timer | |
37 | + T1CON=0x0000; | |
38 | + IEC0bits.T1IE=0; | |
39 | + // Disable interrupt | |
40 | + IEC0bits.CS1IE=0; | |
41 | + g_interrupt_enabled=0; | |
42 | +} | |
43 | + | |
44 | +// Interrupt handler | |
45 | +#ifndef __DEBUG | |
46 | + // Timer1 is also used for debug mode | |
47 | + #pragma interrupt T1Handler IPL2SOFT vector 4 | |
48 | +#endif | |
49 | +void T1Handler(void){ | |
50 | + g_timer++; | |
51 | + // Clear Timer1 interrupt flag | |
52 | + IFS0bits.T1IF=0; | |
53 | + // Raise CS1 interrupt flag if required | |
54 | + IFS0bits.CS1IF=g_interrupt_enabled; | |
55 | +} | |
56 | + | |
57 | +//CS1 ? Core Software Interrupt 1 2 2 IFS0<2> IEC0<2> IPC0<20:18> IPC0<17:16> | |
58 | +void BasicInt(void){ | |
59 | +//TODO: here | |
60 | + // Do the same thing as gosub statement does: 4($sp) is the return address | |
61 | + asm volatile(".set noreorder"); | |
62 | + asm volatile("la $v0,%0"::"i"(&g_int_vector)); | |
63 | + asm volatile("addiu $sp,$sp,-12"); | |
64 | + asm volatile("sw $ra,8($sp)"); | |
65 | + asm volatile("bgezall $zero,label1"); | |
66 | + asm volatile("lw $v0,0($v0)"); | |
67 | + asm volatile("beq $zero,$zero,label2"); | |
68 | + asm volatile("nop"); | |
69 | + asm volatile("label1:"); | |
70 | + asm volatile("jr $v0"); | |
71 | + asm volatile("sw $ra,4($sp)"); | |
72 | + asm volatile("label2:"); | |
73 | + asm volatile("lw $ra,4($sp)"); | |
74 | + asm volatile("addiu $sp,$sp,8"); // 4 was already added by RETURN statement | |
75 | +} | |
76 | +#pragma interrupt CS1Handler IPL1SOFT vector 2 | |
77 | +void CS1Handler(void){ | |
78 | + IFS0bits.CS1IF=0; | |
79 | + BasicInt(); | |
80 | +} | |
81 | + | |
82 | +void lib_usetimer(int hz){ | |
83 | + int temppr1; | |
84 | + // Stop timer, first | |
85 | + T1CON=0x0000; | |
86 | + IEC0bits.T1IE=0; | |
87 | + TMR1=0; | |
88 | + PR1=0xffff; | |
89 | + if (!hz) { | |
90 | + return; | |
91 | + } | |
92 | + // PR1 setting | |
93 | + temppr1=CPU_CLOCK_HZ/hz; | |
94 | + if (temppr1<=65536) { | |
95 | + // no prescaler | |
96 | + T1CON=0x0000; | |
97 | + PR1=temppr1-1; | |
98 | + } else if ((temppr1>>3)<=65536) { | |
99 | + // 1/8 prescaler | |
100 | + T1CON=0x0010; | |
101 | + PR1=(temppr1>>3)-1; | |
102 | + } else if ((temppr1>>6)<=65536) { | |
103 | + // 1/64 prescaler | |
104 | + T1CON=0x0020; | |
105 | + PR1=(temppr1>>6)-1; | |
106 | + } else if ((temppr1>>8)<=65536) { | |
107 | + // 1/256 prescaler | |
108 | + T1CON=0x0030; | |
109 | + PR1=(temppr1>>8)-1; | |
110 | + } else { | |
111 | + err_invalid_param(); | |
112 | + } | |
113 | + // Timer1 interrupt: priority 2 | |
114 | + IPC1bits.T1IP=2; | |
115 | + IPC1bits.T1IS=0; | |
116 | + IEC0bits.T1IE=1; | |
117 | + // Start timer | |
118 | + T1CONbits.ON=1; | |
119 | +} | |
120 | + | |
121 | +char* usetimer_statement(){ | |
122 | + char* err; | |
123 | + err=get_value(); | |
124 | + if (err) return err; | |
125 | + call_quicklib_code(lib_usetimer,ASM_ADDU_A0_V0_ZERO); | |
126 | + return 0; | |
127 | +} | |
128 | + | |
129 | +char* timer_statement(){ | |
130 | + int i; | |
131 | + char* err; | |
132 | + err=get_value(); | |
133 | + if (err) return err; | |
134 | + check_obj_space(3); | |
135 | + g_object[g_objpos++]=0x3C030000|((i>>16)&0x0000FFFF); // lui v1,xxxx | |
136 | + g_object[g_objpos++]=0x34630000|(i&0x0000FFFF); // ori v1,v1,xxxx | |
137 | + g_object[g_objpos++]=0xAC620000; // sw v0,0(v1) | |
138 | + return 0; | |
139 | +} | |
140 | + | |
141 | +char* timer_function(){ | |
142 | + int i; | |
143 | + i=(int)(&g_timer); | |
144 | + check_obj_space(3); | |
145 | + g_object[g_objpos++]=0x3C020000|((i>>16)&0x0000FFFF); // lui v0,xxxx | |
146 | + g_object[g_objpos++]=0x34420000|(i&0x0000FFFF); // ori v0,v0,xxxx | |
147 | + g_object[g_objpos++]=0x8C420000; // lw v0,0(v0) | |
148 | + return 0; | |
149 | +} | |
\ No newline at end of file |
@@ -120,6 +120,7 @@ static const int reserved_var_names[]={ | ||
120 | 120 | 0x47f711de, /*SYSTEM*/ |
121 | 121 | 0x000166bf, /*TAN*/ |
122 | 122 | 0x000f72ed, /*TANH*/ |
123 | + 0x020ed5f3, /*TIMER*/ | |
123 | 124 | 0x02182fee, /*TVRAM*/ |
124 | 125 | 0x022c2a2d, /*UNTIL*/ |
125 | 126 | 0x4e8887d0, /*USEPCG*/ |