• R/O
  • SSH
  • HTTPS

コミット

タグ
未設定

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

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

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


コミットメタ情報

リビジョン223 (tree)
日時2018-02-05 08:47:33
作者kmorimatsu

ログメッセージ

Megalopa with MUSIC (monaural) enabled

変更サマリ

差分

--- mips/branches/megalopa/exception.c (revision 222)
+++ mips/branches/megalopa/exception.c (revision 223)
@@ -71,7 +71,7 @@
7171 #ifdef __DEBUG
7272 asm volatile("j 0xBFC00000");
7373 #else
74-// buttonmode();
74+ buttonmode();
7575 for(i=0;i<100000;i++){
7676 if((KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE))
7777 !=(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE)) i=0;
--- mips/branches/megalopa/library.c (revision 222)
+++ mips/branches/megalopa/library.c (revision 223)
@@ -625,28 +625,28 @@
625625 g_prev_y=y1;
626626 break;
627627 case FUNC_PSET:// X1,Y1[,C]
628- g_pset(x1,y1,v0&0xFF);
628+ g_pset(x1,y1,v0);
629629 g_prev_x=x1;
630630 g_prev_y=y1;
631631 break;
632632 case FUNC_LINE:// X1,Y1,X2,Y2[,C]
633- if (y1==y2) g_hline(x1,x2,y1,v0&0xFF);
634- else g_gline(x1,y1,x2,y2,v0&0xFF);
633+ if (y1==y2) g_hline(x1,x2,y1,v0);
634+ else g_gline(x1,y1,x2,y2,v0);
635635 g_prev_x=x2;
636636 g_prev_y=y2;
637637 break;
638638 case FUNC_BOXFILL:// X1,Y1,X2,Y2[,C]
639- g_boxfill(x1,y1,x2,y2,v0&0xFF);
639+ g_boxfill(x1,y1,x2,y2,v0);
640640 g_prev_x=x2;
641641 g_prev_y=y2;
642642 break;
643643 case FUNC_CIRCLE:// X1,Y1,R[,C]
644- g_circle(x1,y1,x2,v0&0xFF);
644+ g_circle(x1,y1,x2,v0);
645645 g_prev_x=x1;
646646 g_prev_y=y1;
647647 break;
648648 case FUNC_CIRCLEFILL:// X1,Y1,R[,C]
649- g_circlefill(x1,y1,x2,v0&0xFF);
649+ g_circlefill(x1,y1,x2,v0);
650650 g_prev_x=x1;
651651 g_prev_y=y1;
652652 break;
--- mips/branches/megalopa/main.c (revision 222)
+++ mips/branches/megalopa/main.c (revision 223)
@@ -206,6 +206,25 @@
206206 // Show blue screen if exception before soft reset.
207207 blue_screen();
208208
209+ // Prepare Timer1 for 60 Hz interrupt
210+ // This will be replaced by video-library-triggered interruption
211+ // TCKPS=0b10 for 1/64 prescaller
212+ //
213+ PR1=262*6080/64-1; // = 24889
214+ TMR1=0;
215+ T1CON=0x0020;
216+ IPC1bits.T1IP=3;
217+ IPC1bits.T1IS=0;
218+ IFS0bits.T1IF=0;
219+ IEC0bits.T1IE=1;
220+/* // Software interrupt every 1/60 sec (triggered by Timer1)
221+ // This is a test routine.
222+ IPC0bits.CS0IP=3;
223+ IPC0bits.CS0IS=0;
224+ IFS0bits.CS0IF=0;
225+ IEC0bits.CS0IE=1; */
226+ T1CONbits.ON=1; // Start timer1
227+
209228 printstr("MachiKania BASIC System\n");
210229 printstr(" Ver "SYSVER1" "SYSVER2" by KENKEN\n");
211230 printstr("BASIC Compiler "BASVER"\n");
@@ -252,3 +271,20 @@
252271 runbasic(tempfile,0);
253272 while(1) asm(WAIT);
254273 }
274+
275+#pragma interrupt timer1int IPL3SOFT vector 4
276+void timer1int(){
277+ // Trigger software interrupt 0
278+ IFS0bits.T1IF=0;
279+ IFS0bits.CS0IF=1;
280+}
281+
282+/*
283+unsigned char test_c;
284+#pragma interrupt musicint IPL3SOFT vector 1
285+void musicint(){
286+ IFS0bits.CS0IF=0;
287+ test_c++;
288+ TVRAM[20]=0x40+(test_c/16);
289+}
290+*/
\ No newline at end of file
--- mips/branches/megalopa/music.c (revision 222)
+++ mips/branches/megalopa/music.c (revision 223)
@@ -66,30 +66,51 @@
6666 static int g_mpoint;
6767 static char* g_mstr;
6868 static int g_mspos;
69-static unsigned short g_music[32];
70-static unsigned short g_sound[32];
71-static unsigned short g_musiclen[32];
72-static unsigned char g_soundlen[32];
73-static int g_musicstart;
74-static int g_musicend;
75-static int g_musicwait;
76-static int g_soundstart;
77-static int g_soundend;
78-static int g_soundwait;
79-static int g_soundrepeat;
69+static unsigned short g_musicL[32];
70+static unsigned short g_soundL[32];
71+static unsigned short g_musiclenL[32];
72+static unsigned char g_soundlenL[32];
73+static int g_musicstartL;
74+static int g_musicendL;
75+static int g_musicwaitL;
76+static int g_soundstartL;
77+static int g_soundendL;
78+static int g_soundwaitL;
79+static int g_soundrepeatL;
80+static unsigned short g_musicR[32];
81+static unsigned short g_soundR[32];
82+static unsigned short g_musiclenR[32];
83+static unsigned char g_soundlenR[32];
84+static int g_musicstartR;
85+static int g_musicendR;
86+static int g_musicwaitR;
87+static int g_soundstartR;
88+static int g_soundendR;
89+static int g_soundwaitR;
90+static int g_soundrepeatR;
8091
81-int musicRemaining(){
82- return (g_musicend-g_musicstart)&31;
92+#define MFLAG_L 2
93+#define MFLAG_R 1
94+
95+//int musicRemaining(int flagsLR){
96+int musicRemaining(){int flagsLR=3;
97+ int l, r;
98+ l=(g_musicendL-g_musicstartL)&31;
99+ r=(g_musicendL-g_musicstartL)&31;
100+ if (flagsLR & MFLAG_L) return l;
101+ if (flagsLR & MFLAG_R) return r;
102+ return (l>r) ? l:r;
83103 }
84104
85-#pragma interrupt timer4int IPL3SOFT vector 16
86-void timer4int(){
105+#pragma interrupt musicint IPL3SOFT vector 1
106+void musicint(){
87107 unsigned int i;
88108 // This function is called every 1/60 sec.
89- IFS0CLR=_IFS0_T4IF_MASK; //IFS0bits.T4IF=0;
90- if (g_soundstart!=g_soundend){
91- // Start timer & OC4
92- i=g_sound[g_soundstart];
109+ IFS0bits.CS0IF=0;
110+ // Left sound/music uses Timer3
111+ if (g_soundstartL!=g_soundendL){
112+ // Start timer
113+ i=g_soundL[g_soundstartL];
93114 if (i<0xffff) {
94115 T3CONSET=0x8000;
95116 PR3=i;
@@ -97,31 +118,31 @@
97118 } else {
98119 T3CONCLR=0x8000;
99120 }
100- if ((--g_soundwait)<=0) {
101- g_soundstart++;
102- if (g_soundstart==g_soundend || 31<g_soundstart) {
103- g_soundstart=0;
104- g_soundrepeat--;
105- if (0<g_soundrepeat) {
106- g_soundwait=g_soundlen[g_soundstart];
121+ if ((--g_soundwaitL)<=0) {
122+ g_soundstartL++;
123+ if (g_soundstartL==g_soundendL || 31<g_soundstartL) {
124+ g_soundstartL=0;
125+ g_soundrepeatL--;
126+ if (0<g_soundrepeatL) {
127+ g_soundwaitL=g_soundlenL[g_soundstartL];
107128 } else {
108- g_soundend=g_soundrepeat=g_soundwait=0;
129+ g_soundendL=g_soundrepeatL=g_soundwaitL=0;
109130 }
110131 } else {
111- g_soundwait=g_soundlen[g_soundstart];
132+ g_soundwaitL=g_soundlenL[g_soundstartL];
112133 }
113134 }
114135 // Shift music data even though without output.
115- if (g_musicstart!=g_musicend) {
116- if ((--g_musicwait)<=0) {
117- g_musicstart++;
118- g_musicstart&=31;
119- g_musicwait=g_musiclen[g_musicstart];
136+ if (g_musicstartL!=g_musicendL) {
137+ if ((--g_musicwaitL)<=0) {
138+ g_musicstartL++;
139+ g_musicstartL&=31;
140+ g_musicwaitL=g_musiclenL[g_musicstartL];
120141 }
121142 }
122- } else if (g_musicstart!=g_musicend) {
123- // Start timer & OC4
124- i=g_music[g_musicstart];
143+ } else if (g_musicstartL!=g_musicendL) {
144+ // Start timer
145+ i=g_musicL[g_musicstartL];
125146 if (i<0xffff) {
126147 T3CONSET=0x8000;
127148 PR3=i;
@@ -129,15 +150,67 @@
129150 } else {
130151 T3CONCLR=0x8000;
131152 }
132- if ((--g_musicwait)<=0) {
133- g_musicstart++;
134- g_musicstart&=31;
135- g_musicwait=g_musiclen[g_musicstart];
153+ if ((--g_musicwaitL)<=0) {
154+ g_musicstartL++;
155+ g_musicstartL&=31;
156+ g_musicwaitL=g_musiclenL[g_musicstartL];
136157 }
137158 } else {
138159 // Stop timer
139160 T3CONCLR=0x8000;
140161 }
162+ // Right sound/music uses Timer4
163+ if (g_soundstartR!=g_soundendR){
164+ // Start timer
165+ i=g_soundR[g_soundstartR];
166+ if (i<0xffff) {
167+ T4CONSET=0x8000;
168+ PR4=i;
169+ if (i<TMR4) TMR4=0;
170+ } else {
171+ T4CONCLR=0x8000;
172+ }
173+ if ((--g_soundwaitR)<=0) {
174+ g_soundstartR++;
175+ if (g_soundstartR==g_soundendR || 31<g_soundstartR) {
176+ g_soundstartR=0;
177+ g_soundrepeatR--;
178+ if (0<g_soundrepeatR) {
179+ g_soundwaitR=g_soundlenR[g_soundstartR];
180+ } else {
181+ g_soundendR=g_soundrepeatR=g_soundwaitR=0;
182+ }
183+ } else {
184+ g_soundwaitR=g_soundlenR[g_soundstartR];
185+ }
186+ }
187+ // Shift music data even though without output.
188+ if (g_musicstartR!=g_musicendR) {
189+ if ((--g_musicwaitR)<=0) {
190+ g_musicstartR++;
191+ g_musicstartR&=31;
192+ g_musicwaitR=g_musiclenR[g_musicstartR];
193+ }
194+ }
195+ } else if (g_musicstartR!=g_musicendR) {
196+ // Start timer
197+ i=g_musicR[g_musicstartR];
198+ if (i<0xffff) {
199+ T4CONSET=0x8000;
200+ PR4=i;
201+ if (i<TMR4) TMR4=0;
202+ } else {
203+ T4CONCLR=0x8000;
204+ }
205+ if ((--g_musicwaitR)<=0) {
206+ g_musicstartR++;
207+ g_musicstartR&=31;
208+ g_musicwaitR=g_musiclenR[g_musicstartR];
209+ }
210+ } else {
211+ // Stop timer
212+ T4CONCLR=0x8000;
213+ }
141214 }
142215
143216 int musicGetNum(){
@@ -157,36 +230,57 @@
157230 return ret;
158231 }
159232
233+static const unsigned int inv_rf4[1]={0x00000010};
234+static const unsigned int inv_rf5[1]={0x00000020};
235+
160236 void init_music(){
161- // Use Timer3, OC3, and OC4 for sound.
162- RPF4R = 0x0b; //Use RPF4 for OC3
163- OC3R=0;
164- OC3CON=0x000b; // Timer3, toggle mode
165- OC3CONSET=0x8000;// Start OC4
166- RPF5R = 0x0b; //Use RPF5 for OC4
167- OC4R=0;
168- OC4CON=0x000b; // Timer3, toggle mode
169- OC4CONSET=0x8000;// Start OC4
237+ // Use Timer3 and DMA2 for left (RF5)
238+ // Use Timer4 and DMA1 for right (RF4)
239+
240+ // Timer3/Timer4 initialization
241+ TMR3=0;
170242 T3CON=0x0050; // Prescaller: 1:32 (1.8 MHz), not yet started
243+ TMR4=0;
244+ T4CON=0x0050; // Prescaller: 1:32 (1.8 MHz), not yet started
171245
172- // Timer4 is used to intterupt every 1/60 sec, just after NTSC view.
173- T4CON=0x0050; // Prescaller: 1:32
174- PR4=49779; // 6080*262/32-1
175- // Timer 4 interruption, IPL3
176- IPC4bits.T4IP=3;
177- IPC4bits.T4IS=0;
178- IFS0bits.T4IF=0;
179- IEC0bits.T4IE=1;
180- // Wait until end of NTSC view.
181- while(!drawing);
182- while(drawing);
183- T4CONSET=0x8000; // Start timer 4.
246+ //DMA2 settings; used for toggling RF5
247+ DMACONSET=0x8000;
248+ DCH2CON=0x00000012; // CHBUSY=0, CHCHNS=0, CHEN=0, CHAED=0, CHCHN=0, CHAEN=1, CHEDET=0, CHPRI=b10
249+ DCH2ECON=0x0e10; // CHAIRQ=0, CHSIRQ=19, CFORCE=0, CABRT=0, PATEN=0, SIRQEN=1, AIRQEN=0
250+ // CHSIRQ=14: Timer3 interrupt
251+ DCH2SSA=((unsigned int)&(inv_rf4[0]))&0x1fffffff;
252+ DCH2DSA=0x1F88653C; // LATFINV
253+ DCH2SSIZ=1;
254+ DCH2DSIZ=1;
255+ DCH2CSIZ=1;
256+ DCH2INTCLR=0x00FF00FF;
257+ DCH2CONSET=0x00000080;
258+
259+ //DMA1 settings; used for toggling RF4
260+ DMACONSET=0x8000;
261+ DCH1CON=0x00000012; // CHBUSY=0, CHCHNS=0, CHEN=0, CHAED=0, CHCHN=0, CHAEN=1, CHEDET=0, CHPRI=b10
262+ DCH1ECON=0x1310; // CHAIRQ=0, CHSIRQ=19, CFORCE=0, CABRT=0, PATEN=0, SIRQEN=1, AIRQEN=0
263+ // CHSIRQ=19: Timer4 interrupt
264+ DCH1SSA=((unsigned int)&(inv_rf5[0]))&0x1fffffff;
265+ DCH1DSA=0x1F88653C; // LATFINV
266+ DCH1SSIZ=1;
267+ DCH1DSIZ=1;
268+ DCH1CSIZ=1;
269+ DCH1INTCLR=0x00FF00FF;
270+ DCH1CONSET=0x00000080;
271+
272+ // Software interrupt every 1/60 sec (triggered by Timer5)
273+ IPC0bits.CS0IP=3;
274+ IPC0bits.CS0IS=0;
275+ IFS0bits.CS0IF=0;
276+ IEC0bits.CS0IE=1;
184277
185278 // Initializations for music/sound.
186279 g_qvalue=160; // Q: 1/4=90
187280 g_lvalue=20; // L: 1/8
188281 g_tones=(int*)&(g_keys[49]); // C major
189- g_musicstart=g_musicend=g_musicwait=g_soundstart=g_soundend=g_soundwait=g_soundrepeat=0;
282+ g_musicstartL=g_musicendL=g_musicwaitL=g_soundstartL=g_soundendL=g_soundwaitL=g_soundrepeatL=0;
283+ g_musicstartR=g_musicendR=g_musicwaitR=g_soundstartR=g_soundendR=g_soundwaitR=g_soundrepeatR=0;
190284 }
191285
192286 void musicSetL(){
@@ -332,7 +426,7 @@
332426 g_tones=(int*)&(g_keys[56]);
333427 return;
334428 default:
335- err_music(g_mstr);
429+// err_music(g_mstr);
336430 break;
337431 }
338432 }
@@ -342,14 +436,16 @@
342436 musicGetNum();
343437 }
344438
345-void set_sound(unsigned long* data){
439+//void set_sound(unsigned long* data, int flagsLR){
440+void set_sound(unsigned long* data){int flagsLR=3;
346441 int sound;
347442 int len;
348443 int pos;
349444 int datalen;
350- IEC0bits.T4IE=0; // Stop interruption, first.
445+ IEC0bits.CS0IE=0; // Stop interruption, first.
351446 // Initialize
352- g_soundrepeat=g_soundstart=g_soundend=0;
447+ if (flagsLR & MFLAG_L) g_soundrepeatL=g_soundstartL=g_soundendL=0;
448+ if (flagsLR & MFLAG_R) g_soundrepeatR=g_soundstartR=g_soundendR=0;
353449 pos=0;
354450 do {
355451 while(data[1]!=0x00000020) data++; // Seek DATA statement
@@ -362,30 +458,36 @@
362458 data++;
363459 if (len) {
364460 // Shift tone if graphic is used
365- if (g_use_graphic) {
461+ if (/*g_use_graphic*/ 0) {
366462 // MUL_15 instead of MUL_16 for CPU clock.
367463 // sound=sound*15/16
368464 sound-=(sound+7)>>4;
369465 }
370- g_sound[pos]=sound-1;
371- g_soundlen[pos]=len;
466+ if (flagsLR & MFLAG_L) g_soundL[pos]=sound-1;
467+ if (flagsLR & MFLAG_R) g_soundR[pos]=sound-1;
468+ if (flagsLR & MFLAG_L) g_soundlenL[pos]=len;
469+ if (flagsLR & MFLAG_R) g_soundlenR[pos]=len;
372470 pos++;
373471 if (32<pos) {
374- err_music("Sound data too long.");
472+// err_music("Sound data too long.");
375473 return;
376474 }
377475 } else {
378- g_soundrepeat=sound;
476+ if (flagsLR & MFLAG_L) g_soundrepeatL=sound;
477+ if (flagsLR & MFLAG_R) g_soundrepeatR=sound;
379478 break;
380479 }
381480 }
382481 } while(len);
383- g_soundend=pos;
384- g_soundwait=g_soundlen[0];
385- IEC0bits.T4IE=1; // Restart interrupt.
482+ if (flagsLR & MFLAG_L) g_soundendL=pos;
483+ if (flagsLR & MFLAG_R) g_soundendR=pos;
484+ if (flagsLR & MFLAG_L) g_soundwaitL=g_soundlenL[0];
485+ if (flagsLR & MFLAG_R) g_soundwaitR=g_soundlenR[0];
486+ IEC0bits.CS0IE=1; // Restart interrupt.
386487 }
387488
388-void set_music(char* str){
489+//void set_music(char* str, int flagsLR){
490+void set_music(char* str){int flagsLR=3;
389491 char b;
390492 unsigned long tone,tonenatural;
391493 int len;
@@ -409,7 +511,7 @@
409511 musicSetM();
410512 break;
411513 default:
412- err_music(str);
514+// err_music(str);
413515 break;
414516 }
415517 } else if ('A'<=b && b<='G' || 'a'<=b && b<='g' || b=='z') {
@@ -463,23 +565,36 @@
463565 len=len/musicGetNum();
464566 }
465567 // Shift tone if graphic is used
466- if (g_use_graphic) {
568+ if (/*g_use_graphic*/ 0) {
467569 // MUL_15 instead of MUL_16 for CPU clock.
468570 // tone=tone*15/16
469571 tone-=(tone+7)>>4;
470572 }
471573 // Update music value array
472- IEC0bits.T4IE=0; // Stop interruption, first.
473- if (g_musicstart==g_musicend) {
474- g_musicwait=len;
574+ IEC0bits.CS0IE=0; // Stop interruption, first.
575+ // Update left music
576+ if (flagsLR & MFLAG_L) {
577+ if (g_musicstartL==g_musicendL) {
578+ g_musicwaitL=len;
579+ }
580+ g_musicL[g_musicendL]=(tone-1)&0x0000FFFF;
581+ g_musiclenL[g_musicendL]=len;
582+ g_musicendL++;
583+ g_musicendL&=31;
475584 }
476- g_music[g_musicend]=(tone-1)&0x0000FFFF;
477- g_musiclen[g_musicend]=len;
478- g_musicend++;
479- g_musicend&=31;
480- IEC0bits.T4IE=1; // Restart interruption.
585+ // Update right music
586+ if (flagsLR & MFLAG_R) {
587+ if (g_musicstartR==g_musicendR) {
588+ g_musicwaitR=len;
589+ }
590+ g_musicR[g_musicendR]=(tone-1)&0x0000FFFF;
591+ g_musiclenR[g_musicendR]=len;
592+ g_musicendR++;
593+ g_musicendR&=31;
594+ }
595+ IEC0bits.CS0IE=1; // Restart interruption.
481596 } else {
482- err_music(str);
597+// err_music(str);
483598 }
484599 // Go to next character
485600 while(0<g_mstr[g_mspos] && g_mstr[g_mspos]<=0x20 || g_mstr[g_mspos]=='|') g_mspos++;
--- mips/branches/megalopa/ps2keyboard.h (revision 222)
+++ mips/branches/megalopa/ps2keyboard.h (revision 223)
@@ -168,16 +168,7 @@
168168 // 上位8ビット:シフト状態(押下:1)、上位から<0><CAPSLK><NUMLK><SCRLK><Win><ALT><CTRL><SHIFT>
169169 // 英数・記号文字の場合、戻り値としてASCIIコード(それ以外は0を返す)
170170
171-#ifdef ZOEA
172-// PIC32MX1xx/2xx版のキーボードとボタンの排他利用システムで使用する関数、マクロ
173-void ps2mode(); // PS/2を有効にする
174-void buttonmode(); // ボタンを有効にする
175-#define inPS2MODE() ((LATA&2)>>1) // モード確認用マクロ。PS/2モードの場合1、ボタンモードの場合0を返す
176-#endif
177-
178-#ifdef MEGALOPA
179171 // Macros for dummy functions
180172 #define ps2mode() (0)
181173 #define buttonmode() (0)
182174 #define inPS2MODE() (1)
183-#endif
\ No newline at end of file