• 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

修訂ede891a3c45c56aaec7b1652ea1506d40d6c9446 (tree)
時間2019-05-03 09:12:02
作者Katsumi <kmorimatsu@sour...>
CommiterKatsumi

Log Message

Zoea/Protozoea: Revise KEYS/INKEY interruptions. Add READKEY() function. Revise help.txt

Change Summary

差異

--- a/mips/protozoea/compiler.h
+++ b/mips/protozoea/compiler.h
@@ -125,6 +125,7 @@ enum libs{
125125 LIB_SETDIR =LIB_STEP*51,
126126 LIB_SETDIRFUNC =LIB_STEP*52,
127127 LIB_GETDIR =LIB_STEP*53,
128+ LIB_READKEY =LIB_STEP*54,
128129 LIB_DEBUG =LIB_STEP*127,
129130 };
130131
@@ -516,6 +517,10 @@ extern int g_int_vector[];
516517 // Valid for 31 bits for all cases and 32 bits for some cases
517518 #define div32(x,y,z) ((((unsigned long long)((unsigned long)(x)))*((unsigned long long)((unsigned long)(y))))>>(z))
518519
520+// Divide by 8 (valid for 32 bits)
521+#define div8_32(x) (((unsigned long)(x))>>3)
522+#define rem8_32(x) ((x)&0x07)
523+
519524 // Divide by 9 (valid for 32 bits)
520525 #define div9_32(x) div32(x,0xe38e38e4,35)
521526 #define rem9_32(x) ((x)-9*div9_32(x))
--- a/mips/protozoea/function.c
+++ b/mips/protozoea/function.c
@@ -395,6 +395,11 @@ char* exec_function(){
395395 return exec_statement();
396396 }
397397
398+char* readkey_function(){
399+ call_lib_code(LIB_READKEY);
400+ return 0;
401+}
402+
398403 char* float_constant(float val){
399404 volatile int i;
400405 ((float*)(&i))[0]=val;
@@ -603,6 +608,7 @@ static const void* int_func_list[]={
603608 "TIMER(",timer_function,
604609 "EXEC(",exec_function,
605610 "CORETIMER(",coretimer_function,
611+ "READKEY(",readkey_function,
606612 // Additional functions follow
607613 ADDITIONAL_INT_FUNCTIONS
608614 };
--- a/mips/protozoea/help.txt
+++ b/mips/protozoea/help.txt
@@ -227,6 +227,13 @@ PLAYWAVE([x])
227227 READ()
228228 DATA文の後から、一つずつデーター(32ビット整数値)を読み出す。「CREAD()」
229229 関数も参照。
230+READKEY()
231+ キーボードバッファーから一文字読み込み、返す。バッファーが空の時は0を返す。
232+ 戻り値は24ビット整数で、内容は以下の通り。
233+ bits 0-7 : ASCII コード
234+ bits 8-15 : 仮想キーコード
235+ bits 16-23 : シフトキー押下状態。
236+ 上位から<0><CAPSLK><NUMLK><SCRLK><Win><ALT><CTRL><SHIFT>。
230237 RND()
231238 0から32767までの擬似乱数を返す。
232239 SGN(x)
@@ -561,7 +568,7 @@ INTERRUPT xxx,yyy[,z1[,z2 ... ]]
561568 KEYS
562569 ボタンの押下状態が変化した時。
563570 INKEY
564- キーボード押下時。
571+ キーボード押下時。READKEY()関数と組み合わせて使う。
565572 MUSIC
566573 音楽再生の時、最後の音の再生時に割り込み。
567574 WAVE
--- a/mips/protozoea/interface/ps2keyboard.h
+++ b/mips/protozoea/interface/ps2keyboard.h
@@ -176,3 +176,5 @@ unsigned char ps2readkey();
176176 #define buttonmode() (0)
177177 //#define inPS2MODE() ((LATA&2)>>1) // モード確認用マクロ。PS/2モードの場合1、ボタンモードの場合0を返す
178178 #define inPS2MODE() (0)
179+//#define keycodeExists() (keycodebufp1!=keycodebufp2)
180+#define keycodeExists() (0)
--- a/mips/protozoea/library.c
+++ b/mips/protozoea/library.c
@@ -943,6 +943,11 @@ int lib_file(enum functions func, int a0, int a1, int v0){
943943 return v0;
944944 }
945945
946+int lib_readkey(){
947+ int ret=ps2readkey();
948+ return ret|(vkey<<8);
949+}
950+
946951 int _call_library(int a0,int a1,int a2,enum libs a3);
947952
948953 void call_library(void){
@@ -1011,6 +1016,8 @@ int _call_library(int a0,int a1,int v0,enum libs a3){
10111016 return lib_keys(v0);
10121017 case LIB_INKEY:
10131018 return (int)lib_inkey(v0);
1019+ case LIB_READKEY:
1020+ return lib_readkey();
10141021 case LIB_CURSOR:
10151022 setcursor(g_libparams[1],v0,cursorcolor);
10161023 return v0;
--- a/mips/protozoea/timer.c
+++ b/mips/protozoea/timer.c
@@ -42,6 +42,9 @@ int g_interrupt_flags;
4242 // Jump address when interrupt
4343 int g_int_vector[NUM_INTERRUPT_TYPES];
4444
45+// Current button status
46+static int g_keys_interrupt;
47+
4548 /*
4649 Initialize and termination
4750 */
@@ -56,6 +59,7 @@ void init_timer(){
5659 g_timer=0;
5760 // Disable interrupt
5861 IEC0bits.CS1IE=0;
62+ IFS0bits.CS1IF=0;
5963 for(i=0;i<NUM_INTERRUPT_TYPES;i++) g_int_vector[i]=0;
6064 // CS0 interrupt every 1/60 sec (triggered by Timer2)
6165 IPC0bits.CS0IP=3;
@@ -69,6 +73,8 @@ void init_timer(){
6973 asm volatile("ins $t0,$zero,1,15");
7074 asm volatile("mtc0 $t0,$12,0");
7175 asm volatile("ei");
76+ // The other initialization(s)
77+ g_keys_interrupt=-1;
7278 }
7379
7480 void stop_timer(){
@@ -330,9 +336,7 @@ const int* g_keystatus=(int*)&ps2keystatus[0];
330336
331337 #pragma interrupt CS0Handler IPL3SOFT vector 1
332338 void CS0Handler(void){
333- static int s_keys=-1;
334- static char s_inkey=0;
335- int i;
339+ int keys;
336340 IFS0bits.CS0IF=0;
337341 // Call music function
338342 if (g_music_active) musicint();
@@ -341,21 +345,21 @@ void CS0Handler(void){
341345 // Raise DRAWCOUNT interrupt flag
342346 raise_interrupt_flag(INTERRUPT_DRAWCOUNT);
343347 // Check buttons
344- if (0<=s_keys && s_keys!=(KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE))) {
348+ if (inPS2MODE()) {
349+ keys=readbuttons();
350+ ps2mode();
351+ } else {
352+ keys=readbuttons();
353+ }
354+ keys=keys & (KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE);
355+ if (0<=g_keys_interrupt && g_keys_interrupt!=keys) {
345356 // Raise KEYS interrupt flag
346357 raise_interrupt_flag(INTERRUPT_KEYS);
347358 }
348- s_keys=KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE);
349- // Check PS/2 keyboard down
359+ g_keys_interrupt=keys;
360+ // Check PS/2 keyboard input
350361 if (g_int_vector[INTERRUPT_INKEY]) {
351- for(i=0;i<64;i++){
352- if (g_keystatus[i]) {
353- // Raise INKEY interrupt flag
354- if (!s_inkey) raise_interrupt_flag(INTERRUPT_INKEY);
355- break;
356- }
357- }
358- s_inkey=(i==64) ? 0:1;
362+ if (keycodeExists()) raise_interrupt_flag(INTERRUPT_INKEY);
359363 }
360364 }
361365 }
--- a/mips/zoea/compiler.h
+++ b/mips/zoea/compiler.h
@@ -125,6 +125,7 @@ enum libs{
125125 LIB_SETDIR =LIB_STEP*51,
126126 LIB_SETDIRFUNC =LIB_STEP*52,
127127 LIB_GETDIR =LIB_STEP*53,
128+ LIB_READKEY =LIB_STEP*54,
128129 LIB_DEBUG =LIB_STEP*127,
129130 };
130131
@@ -516,6 +517,10 @@ extern int g_int_vector[];
516517 // Valid for 31 bits for all cases and 32 bits for some cases
517518 #define div32(x,y,z) ((((unsigned long long)((unsigned long)(x)))*((unsigned long long)((unsigned long)(y))))>>(z))
518519
520+// Divide by 8 (valid for 32 bits)
521+#define div8_32(x) (((unsigned long)(x))>>3)
522+#define rem8_32(x) ((x)&0x07)
523+
519524 // Divide by 9 (valid for 32 bits)
520525 #define div9_32(x) div32(x,0xe38e38e4,35)
521526 #define rem9_32(x) ((x)-9*div9_32(x))
--- a/mips/zoea/function.c
+++ b/mips/zoea/function.c
@@ -395,6 +395,11 @@ char* exec_function(){
395395 return exec_statement();
396396 }
397397
398+char* readkey_function(){
399+ call_lib_code(LIB_READKEY);
400+ return 0;
401+}
402+
398403 char* float_constant(float val){
399404 volatile int i;
400405 ((float*)(&i))[0]=val;
@@ -603,6 +608,7 @@ static const void* int_func_list[]={
603608 "TIMER(",timer_function,
604609 "EXEC(",exec_function,
605610 "CORETIMER(",coretimer_function,
611+ "READKEY(",readkey_function,
606612 // Additional functions follow
607613 ADDITIONAL_INT_FUNCTIONS
608614 };
--- a/mips/zoea/help.txt
+++ b/mips/zoea/help.txt
@@ -227,6 +227,13 @@ PLAYWAVE([x])
227227 READ()
228228 DATA文の後から、一つずつデーター(32ビット整数値)を読み出す。「CREAD()」
229229 関数も参照。
230+READKEY()
231+ キーボードバッファーから一文字読み込み、返す。バッファーが空の時は0を返す。
232+ 戻り値は24ビット整数で、内容は以下の通り。
233+ bits 0-7 : ASCII コード
234+ bits 8-15 : 仮想キーコード
235+ bits 16-23 : シフトキー押下状態。
236+ 上位から<0><CAPSLK><NUMLK><SCRLK><Win><ALT><CTRL><SHIFT>。
230237 RND()
231238 0から32767までの擬似乱数を返す。
232239 SGN(x)
@@ -561,7 +568,7 @@ INTERRUPT xxx,yyy[,z1[,z2 ... ]]
561568 KEYS
562569 ボタンの押下状態が変化した時。
563570 INKEY
564- キーボード押下時。
571+ キーボード押下時。READKEY()関数と組み合わせて使う。
565572 MUSIC
566573 音楽再生の時、最後の音の再生時に割り込み。
567574 WAVE
@@ -858,6 +865,8 @@ ON GOTO分やON GOSUB文はサポートしていません。ただし、例え
858865  ・割り込み機能(INTERRUPTステートメント)を追加。
859866  ・オプション機能(OPTIONステートメント)を追加。
860867  ・アイドル機能(IDLEステートメント)を追加。
868+ ・READKEY()関数を追加。
869+ ・EXEC()関数を追加。
861870 ・KM-1207 2019年3月公開。
862871  ・PUTBMPの第5引数に長い名前の変数が使えなかったバグの修正
863872  ・オブジェクト指向プログラミングに対応
Binary files a/mips/zoea/interface/lib_videoout_machikania.X.a and b/mips/zoea/interface/lib_videoout_machikania.X.a differ
--- a/mips/zoea/interface/ps2keyboard.h
+++ b/mips/zoea/interface/ps2keyboard.h
@@ -172,3 +172,8 @@ unsigned char ps2readkey();
172172 void ps2mode(); // PS/2を有効にする
173173 void buttonmode(); // ボタンを有効にする
174174 #define inPS2MODE() ((LATA&2)>>1) // モード確認用マクロ。PS/2モードの場合1、ボタンモードの場合0を返す
175+
176+// Macro(s) follows(s)
177+extern unsigned short * volatile keycodebufp1; //キーコード書き込み先頭ポインタ
178+extern unsigned short * volatile keycodebufp2; //キーコード読み出し先頭ポインタ
179+#define keycodeExists() (keycodebufp1!=keycodebufp2)
--- a/mips/zoea/library.c
+++ b/mips/zoea/library.c
@@ -943,6 +943,11 @@ int lib_file(enum functions func, int a0, int a1, int v0){
943943 return v0;
944944 }
945945
946+int lib_readkey(){
947+ int ret=ps2readkey();
948+ return ret|(vkey<<8);
949+}
950+
946951 int _call_library(int a0,int a1,int a2,enum libs a3);
947952
948953 void call_library(void){
@@ -1011,6 +1016,8 @@ int _call_library(int a0,int a1,int v0,enum libs a3){
10111016 return lib_keys(v0);
10121017 case LIB_INKEY:
10131018 return (int)lib_inkey(v0);
1019+ case LIB_READKEY:
1020+ return lib_readkey();
10141021 case LIB_CURSOR:
10151022 setcursor(g_libparams[1],v0,cursorcolor);
10161023 return v0;
--- a/mips/zoea/timer.c
+++ b/mips/zoea/timer.c
@@ -42,6 +42,9 @@ int g_interrupt_flags;
4242 // Jump address when interrupt
4343 int g_int_vector[NUM_INTERRUPT_TYPES];
4444
45+// Current button status
46+static int g_keys_interrupt;
47+
4548 /*
4649 Initialize and termination
4750 */
@@ -56,6 +59,7 @@ void init_timer(){
5659 g_timer=0;
5760 // Disable interrupt
5861 IEC0bits.CS1IE=0;
62+ IFS0bits.CS1IF=0;
5963 for(i=0;i<NUM_INTERRUPT_TYPES;i++) g_int_vector[i]=0;
6064 // CS0 interrupt every 1/60 sec (triggered by Timer2)
6165 IPC0bits.CS0IP=3;
@@ -69,6 +73,8 @@ void init_timer(){
6973 asm volatile("ins $t0,$zero,1,15");
7074 asm volatile("mtc0 $t0,$12,0");
7175 asm volatile("ei");
76+ // The other initialization(s)
77+ g_keys_interrupt=-1;
7278 }
7379
7480 void stop_timer(){
@@ -330,9 +336,7 @@ const int* g_keystatus=(int*)&ps2keystatus[0];
330336
331337 #pragma interrupt CS0Handler IPL3SOFT vector 1
332338 void CS0Handler(void){
333- static int s_keys=-1;
334- static char s_inkey=0;
335- int i;
339+ int keys;
336340 IFS0bits.CS0IF=0;
337341 // Call music function
338342 if (g_music_active) musicint();
@@ -341,21 +345,21 @@ void CS0Handler(void){
341345 // Raise DRAWCOUNT interrupt flag
342346 raise_interrupt_flag(INTERRUPT_DRAWCOUNT);
343347 // Check buttons
344- if (0<=s_keys && s_keys!=(KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE))) {
348+ if (inPS2MODE()) {
349+ keys=readbuttons();
350+ ps2mode();
351+ } else {
352+ keys=readbuttons();
353+ }
354+ keys=keys & (KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE);
355+ if (0<=g_keys_interrupt && g_keys_interrupt!=keys) {
345356 // Raise KEYS interrupt flag
346357 raise_interrupt_flag(INTERRUPT_KEYS);
347358 }
348- s_keys=KEYPORT&(KEYUP|KEYDOWN|KEYLEFT|KEYRIGHT|KEYSTART|KEYFIRE);
349- // Check PS/2 keyboard down
359+ g_keys_interrupt=keys;
360+ // Check PS/2 keyboard input
350361 if (g_int_vector[INTERRUPT_INKEY]) {
351- for(i=0;i<64;i++){
352- if (g_keystatus[i]) {
353- // Raise INKEY interrupt flag
354- if (!s_inkey) raise_interrupt_flag(INTERRUPT_INKEY);
355- break;
356- }
357- }
358- s_inkey=(i==64) ? 0:1;
362+ if (keycodeExists()) raise_interrupt_flag(INTERRUPT_INKEY);
359363 }
360364 }
361365 }