• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
Aucun tag

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

Révisionca87cc9f5488601454618a4fbf7a71d06a2ce98b (tree)
l'heure2019-03-25 07:01:27
AuteurKatsumi <kmorimatsu@sour...>
CommiterKatsumi

Message de Log

USETIMER, TIMER, and TIMER()

Change Summary

Modification

--- a/mips/zoea/basic.mcp
+++ b/mips/zoea/basic.mcp
@@ -68,6 +68,7 @@ file_040=.
6868 file_041=.
6969 file_042=.
7070 file_043=.
71+file_044=.
7172 [GENERATED_FILES]
7273 file_000=no
7374 file_001=no
@@ -113,6 +114,7 @@ file_040=no
113114 file_041=no
114115 file_042=no
115116 file_043=no
117+file_044=no
116118 [OTHER_FILES]
117119 file_000=no
118120 file_001=no
@@ -153,11 +155,12 @@ file_035=no
153155 file_036=no
154156 file_037=no
155157 file_038=no
156-file_039=yes
158+file_039=no
157159 file_040=yes
158160 file_041=yes
159161 file_042=yes
160162 file_043=yes
163+file_044=yes
161164 [FILE_INFO]
162165 file_000=compiler.c
163166 file_001=editor.c
@@ -184,25 +187,26 @@ file_021=varname.c
184187 file_022=envspecific.c
185188 file_023=class.c
186189 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
206210 [SUITE_INFO]
207211 suite_guid={62D235D8-2DB2-49CD-AF24-5489A6015337}
208212 suite_state=
--- a/mips/zoea/compiler.h
+++ b/mips/zoea/compiler.h
@@ -368,6 +368,13 @@ char* static_statement();
368368 char* static_method(char type);
369369 char* resolve_unresolved(int class);
370370
371+void init_timer();
372+void stop_timer();
373+char* usetimer_statement();
374+char* timer_statement();
375+char* timer_function();
376+
377+
371378 /* Error messages */
372379 #define ERR_SYNTAX (char*)(g_err_str[0])
373380 #define ERR_NE_BINARY (char*)(g_err_str[1])
--- a/mips/zoea/debug.c
+++ b/mips/zoea/debug.c
@@ -228,13 +228,13 @@ static const char initext[]=
228228 "#PRINT\n";
229229
230230 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"
234236 "\n"
235-"CLS\n"
236237 "\n"
237-"LABEL TST:PRINT\n"
238238 "\n";
239239
240240 static const char class1text[]=
@@ -270,13 +270,9 @@ static const void* debugjumptable[]={
270270
271271 int _debug_test(int a0, int a1, int a2, int a3, int param4, int param5){
272272 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)");
280276 asm volatile("nop");
281277 asm volatile("nop");
282278 asm volatile("nop");
--- a/mips/zoea/envspecific.h
+++ b/mips/zoea/envspecific.h
@@ -5,6 +5,7 @@
55 kmorimatsu@users.sourceforge.jp
66 */
77
8+#define CPU_CLOCK_HZ 57272720
89 #define PERSISTENT_RAM_SIZE (1024*52)
910
1011 int readbuttons();
--- a/mips/zoea/function.c
+++ b/mips/zoea/function.c
@@ -597,6 +597,7 @@ static const void* int_func_list[]={
597597 "PLAYWAVE(",playwave_function,
598598 "NEW(",new_function,
599599 "SETDIR(",setdir_function,
600+ "TIMER(",timer_function,
600601 // Additional functions follow
601602 ADDITIONAL_INT_FUNCTIONS
602603 };
--- a/mips/zoea/main.c
+++ b/mips/zoea/main.c
@@ -14,6 +14,72 @@
1414 // lib_colortext32.a : カラービデオ信号出力システムライブラリ(30×27テキスト版)
1515 // libsdfsio.a : SDカードアクセス用ライブラリ
1616
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+
1783 #include <xc.h>
1884 #include "api.h"
1985 #include "compiler.h"
--- a/mips/zoea/reservednames.js
+++ b/mips/zoea/reservednames.js
@@ -139,6 +139,7 @@ var namearray=[
139139 'SYSTEM',
140140 'TAN',
141141 'TANH',
142+ 'TIMER',
142143 'TVRAM',
143144 'UNTIL',
144145 'USEPCG',
--- a/mips/zoea/run.c
+++ b/mips/zoea/run.c
@@ -116,6 +116,7 @@ int runbasic(char *appname,int test){
116116
117117 // Warm up environment
118118 pre_run();
119+ init_timer();
119120
120121 // Execute program
121122 // Start program from the beginning of RAM.
@@ -126,6 +127,7 @@ int runbasic(char *appname,int test){
126127 // Cool down environment
127128 post_run();
128129 lib_file(FUNC_FINIT,0,0,0);
130+ stop_timer();
129131
130132 return 0;
131133 }
--- a/mips/zoea/statement.c
+++ b/mips/zoea/statement.c
@@ -1717,6 +1717,8 @@ static const void* statement_list[]={
17171717 "STATIC ",static_statement,
17181718 "SETDIR ",setdir_statement,
17191719 "OPTION ",option_statement,
1720+ "USETIMER ",usetimer_statement,
1721+ "TIMER ",timer_statement,
17201722 // List of additional statements follows
17211723 ADDITIONAL_STATEMENTS
17221724 };
--- /dev/null
+++ b/mips/zoea/timer.c
@@ -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
--- a/mips/zoea/varname.c
+++ b/mips/zoea/varname.c
@@ -120,6 +120,7 @@ static const int reserved_var_names[]={
120120 0x47f711de, /*SYSTEM*/
121121 0x000166bf, /*TAN*/
122122 0x000f72ed, /*TANH*/
123+ 0x020ed5f3, /*TIMER*/
123124 0x02182fee, /*TVRAM*/
124125 0x022c2a2d, /*UNTIL*/
125126 0x4e8887d0, /*USEPCG*/