コミットメタ情報

リビジョン988a9d6e99170bd0742231e7c954c10b95b6f6d0 (tree)
日時2014-03-29 15:48:49
作者hikarupsp <hikarupsp@user...>
コミッターhikarupsp

ログメッセージ

キーボード関連の構造体化

変更サマリ

差分

--- a/function.c
+++ b/function.c
@@ -386,12 +386,11 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
386386 r->label[i].opt = 0;
387387 }
388388 puc = r->preg[0x31].p;
389- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
389+ i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], 0, JITC_NOSTARTUP + 0);
390390 if (i == 0) {
391- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + JITC_PHASE1 + 0);
391+ i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], 0, JITC_NOSTARTUP + JITC_PHASE1 + 0);
392392 if (i >= 0) {
393- r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
394- di1_serial++;
393+ r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = 0;
395394 r->ireg[0x30] = 0;
396395 r->preg[0x31].p = r->jitbuf;
397396 r->preg[0x31].typ = 0; // TYP_CODE
@@ -474,7 +473,7 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
474473 longjmp(r->setjmpEnv, 1);
475474 }
476475 drv_sleep(r->ireg[0x32]);
477- if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0){
476+ if ((r->ireg[0x31] & 2) != 0 && mainKeyboard.c <= 0){
478477 // opt2:キー入力があったので戻る
479478 continue;
480479 }
@@ -501,9 +500,9 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
501500 break;
502501 }
503502 r->ireg[0x30] |= -1;
504- if (keybuf_c > 0) {
503+ if (mainKeyboard.c > 0) {
505504 // 入力された文字がある
506- r->ireg[0x30] = keybuf[keybuf_r];
505+ r->ireg[0x30] = mainKeyboard.buf[mainKeyboard.r];
507506 if ((r->ireg[0x31] & 16) == 0){
508507 // shift, lockキー([C]マークのあるキー)の無効化
509508 r->ireg[0x30] &= 0x3e3effff;
@@ -514,8 +513,8 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
514513 }
515514 if ((r->ireg[0x31] & 1) != 0) {
516515 // peekでないならバッファを進める
517- keybuf_c--;
518- keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
516+ mainKeyboard.c--;
517+ mainKeyboard.r = (mainKeyboard.r + 1) & (KEYBUFSIZ - 1);
519518 }
520519 }
521520 r->ireg[0x32] = r->ireg[0x33] = 0;
--- a/jitcx86.c
+++ b/jitcx86.c
@@ -1667,11 +1667,11 @@ int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const
16671667 }
16681668
16691669 // ラベルのチェック
1670- i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, 0);
1670+ i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, 0, 0);
16711671 if (i != 0){
16721672 return 2;
16731673 }
1674- i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, JITC_PHASE1 + 0);
1674+ i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, 0, JITC_PHASE1 + 0);
16751675 if (i < 0){
16761676 return 2;
16771677 }
--- a/main.c
+++ b/main.c
@@ -1,27 +1,12 @@
11 #include "osecpu.h"
22
3-int *keybuf, keybuf_r, keybuf_w, keybuf_c;
43 HOSECPU_Device_Window mainWindow;
5-//デバッグ用。プログラム中の随所で加算される変数
6-int di1_serial;
4+HOSECPU_Device_Keyboard mainKeyboard;
75 HOSECPU_RuntimeEnvironment *dbg_env;
86
9-
10-
117 unsigned char *Init_LoadSysLib(char argv0[]);
128 void LoadAppBin(HOSECPU_RuntimeEnvironment *env);
139
14-void putKeybuf(int i)
15-{
16- // TODO : あふれた場合のことを考慮すべき
17- if (keybuf_c < KEYBUFSIZ) {
18- keybuf[keybuf_w] = i;
19- keybuf_c++;
20- keybuf_w = (keybuf_w + 1) & (KEYBUFSIZ - 1);
21- }
22- return;
23-}
24-
2510 int HeavyOSECPUMain(int argc, char **argv)
2611 {
2712 HOSECPU_RuntimeEnvironment env;
@@ -61,8 +46,10 @@ int HeavyOSECPUMain(int argc, char **argv)
6146 mainWindow.xsize = 0;
6247 mainWindow.ysize = 0;
6348 // Initialize keyInputting
64- keybuf = malloc(KEYBUFSIZ * sizeof(int));
65- keybuf_r = keybuf_w = keybuf_c = 0;
49+ mainKeyboard.buf = malloc(KEYBUFSIZ * sizeof(int));
50+ mainKeyboard.r = 0;
51+ mainKeyboard.w = 0;
52+ mainKeyboard.c = 0;
6653 // Initialize HOSECPU_RuntimeEnvironment
6754 env.mainArgc = argc;
6855 env.mainArgv = (const char **)argv;
@@ -71,9 +58,7 @@ int HeavyOSECPUMain(int argc, char **argv)
7158 env.appOSECPUBackendBin = malloc(APPBINSIZE);
7259 //
7360 env.appJITBin = mallocRWE(APPJITSIZE);
74- fprintf(stderr, "appJITBin: %p\n", env.appJITBin);
7561 pAppJITBin = env.appJITBin;
76- fprintf(stderr, "pAppJITBin: %p\n", pAppJITBin);
7762 env.syslibJITBin = mallocRWE(SYSLIBJITSIZE);
7863 pSyslibJITBin = env.syslibJITBin;
7964 // syslibJITBin image:
@@ -115,6 +100,10 @@ int HeavyOSECPUMain(int argc, char **argv)
115100 return 1;
116101 }
117102
103+ //
104+ // Load app
105+ //
106+
118107 LoadAppBin(&env);
119108
120109 tm0 = clock() / (double)CLOCKS_PER_SEC;
@@ -123,13 +112,13 @@ int HeavyOSECPUMain(int argc, char **argv)
123112 // tek5圧縮がかかっている
124113 #if (USE_TEK5 != 0)
125114 tekDecompTemp = malloc(TEKDECOMPTMPSIZE);
126- env.appSize1 = tek5Decomp(env.appOSECPUBin + 2, env.appOSECPUBin + env.appSize0, tekDecompTemp);
115+ env.appOSECPUBinSize = tek5Decomp(env.appOSECPUBin + 2, env.appOSECPUBin + APPBINSIZE, tekDecompTemp);
127116 free(tekDecompTemp);
128- env.appSize1 += 2;
117+ env.appOSECPUBinSize += 2;
129118 #else
130- env.appSize1 = -9;
119+ env.appOSECPUBinSize = -9;
131120 #endif
132- if (env.appSize1 < 0) {
121+ if (env.appOSECPUBinSize < 0) {
133122 fputs("unsupported-format(tek5)\n", stderr);
134123 return 1;
135124 }
@@ -152,7 +141,7 @@ int HeavyOSECPUMain(int argc, char **argv)
152141 env.preg[2].p = &env.appOSECPUBackendBin[2];
153142 env.preg[3].p = &env.appOSECPUBackendBin[APPBINSIZE];
154143 env.preg[4].p = &env.appOSECPUBin[2];
155- env.preg[5].p = &env.appOSECPUBin[env.appSize1];
144+ env.preg[5].p = &env.appOSECPUBin[env.appOSECPUBinSize];
156145 env.preg[6].p = bufP06;
157146 env.preg[7].p = bufP06 + DECODER_BUF06_SIZE;
158147 env.preg[0x0A].p = (unsigned char *)bufP0A;
@@ -172,8 +161,8 @@ int HeavyOSECPUMain(int argc, char **argv)
172161 }
173162 env.appOSECPUBackendBinSize = env.preg[2].p - env.appOSECPUBackendBin;
174163 } else{
175- memcpy(env.appOSECPUBackendBin, env.appOSECPUBin, env.appSize1);
176- env.appOSECPUBackendBinSize = env.appSize1;
164+ memcpy(env.appOSECPUBackendBin, env.appOSECPUBin, env.appOSECPUBinSize);
165+ env.appOSECPUBackendBinSize = env.appOSECPUBinSize;
177166 }
178167
179168 if ((argDebugMode & 2) != 0) {
@@ -184,9 +173,7 @@ int HeavyOSECPUMain(int argc, char **argv)
184173 }
185174
186175 //JITコンパイル
187- fprintf(stderr, "pAppJITBin: %p\n", pAppJITBin);
188176 i = jitc0(&pAppJITBin, env.appJITBin + APPJITSIZE, env.appOSECPUBackendBin, env.appOSECPUBackendBin + APPBINSIZE, env.executionLevel, label);
189- fprintf(stderr, "pAppJITBin: %p\n", pAppJITBin);
190177 if (i == 1){
191178 fputs("app-file header error.\n", stderr);
192179 return 1;
@@ -194,9 +181,8 @@ int HeavyOSECPUMain(int argc, char **argv)
194181 if (i != 0){
195182 return 1;
196183 }
197- di1_serial++;
198184
199- env.appJITBinSize = pAppJITBin - env.appOSECPUBackendBin;
185+ env.appJITBinSize = pAppJITBin - env.appJITBin;
200186
201187 // 末尾にAPI関数呼び出しコードを追加
202188 appBinDevFuncBase = pAppJITBin;
@@ -269,7 +255,7 @@ int HeavyOSECPUMain(int argc, char **argv)
269255 /* 実行結果確認のためのレジスタダンプ */
270256 if (searchArg(argc, (const char **)argv, "verbose:1", 0) != NULL) {
271257 printf("time: JITC=%.3f[sec], exec=%.3f[sec]\n", tm1 - tm0, tm2 - tm1);
272- printf("size: OSECPU=%d, decomp=%d, tmp=%d, native=%d\n", env.appSize0, env.appSize1, env.appOSECPUBackendBinSize, env.appJITBinSize);
258+ printf("size: OSECPU=%d, decomp=%d, native=%d\n", env.appOSECPUBinSize, env.appOSECPUBackendBinSize, env.appJITBinSize);
273259 printf("result:\n");
274260 printf("R00:0x%08X R01:0x%08X R02:0x%08X R03:0x%08X\n", env.ireg[0], env.ireg[1], env.ireg[2], env.ireg[3]);
275261 }
@@ -357,16 +343,27 @@ void LoadAppBin(HOSECPU_RuntimeEnvironment *env)
357343 fputs("app-file load error.\n", stderr);
358344 exit(EXIT_FAILURE);
359345 }
360- env->appSize0 = fread(env->appOSECPUBin, 1, APPBINSIZE - 4, fp);
361- env->appSize1 = env->appSize0;
346+ env->appOSECPUBinSize = fread(env->appOSECPUBin, 1, APPBINSIZE - 4, fp);
362347 fclose(fp);
363348
364- if (env->appSize0 >= APPBINSIZE - 4) {
349+ if (env->appOSECPUBinSize >= APPBINSIZE - 4) {
365350 fputs("app-file too large.\n", stderr);
366351 exit(EXIT_FAILURE);
367352 }
368- if (env->appSize0 < 3) {
353+ if (env->appOSECPUBinSize < 3) {
369354 fputs("app-file header error.\n", stderr);
370355 exit(EXIT_FAILURE);
371356 }
372357 }
358+
359+void putKeybuf(int i)
360+{
361+ // TODO : あふれた場合のことを考慮すべき
362+ if (mainKeyboard.c < KEYBUFSIZ) {
363+ mainKeyboard.buf[mainKeyboard.w] = i;
364+ mainKeyboard.c++;
365+ mainKeyboard.w = (mainKeyboard.w + 1) & (KEYBUFSIZ - 1);
366+ }
367+ return;
368+}
369+
--- a/osecpu.h
+++ b/osecpu.h
@@ -52,8 +52,8 @@
5252 #define SIGN1 0xe1
5353
5454 #define USE_DEBUGGER 1 // デバッグ機能を実行バイナリに含むか設定。デバッガ利用には dbgr:1 引数が実行時に必要。
55-#define ENABLE_DEBUG_CODE 1 // env.dbg_currentCodeに実行するコードを保存するデバッグコードを挿入する
56-#define ENABLE_DEBUG_CODE_ADDR 1
55+#define ENABLE_DEBUG_CODE 0 // env.dbg_currentCodeに実行するコードを保存するデバッグコードを挿入する
56+#define ENABLE_DEBUG_CODE_ADDR 0
5757 #define USE_TEK5 1
5858
5959
@@ -160,6 +160,14 @@ struct Device_Window {
160160 int xsize, ysize;
161161 };
162162
163+typedef struct Device_Keyboard HOSECPU_Device_Keyboard;
164+struct Device_Keyboard {
165+ int *buf;
166+ int r;
167+ int w;
168+ int c;
169+};
170+
163171 typedef struct Regs HOSECPU_RuntimeEnvironment;
164172 struct Regs {
165173 int ireg[64]; // 整数レジスタ (4 * 64) = 256
@@ -178,16 +186,17 @@ struct Regs {
178186 /* Main environment */
179187 int mainArgc; // HOSECPU起動引数の個数
180188 const char **mainArgv; // HOSECPU起動引数リスト
181- //unsigned char *appBin; // 実行するアプリの元バイナリ(渡されたファイルの内容そのもの)
189+ //
182190 unsigned char *appOSECPUBin; // 実行するアプリの元バイナリ(渡されたファイルの内容そのもの)
191+ int appOSECPUBinSize;
183192 unsigned char *appOSECPUBackendBin; // 実行するアプリの元バイナリ(渡されたファイルの内容そのもの)
184193 int appOSECPUBackendBinSize;
185194 unsigned char *appJITBin; // 実行するアプリのJITコンパイルされたバイナリ(実行可能)
186195 int appJITBinSize;
196+ //
187197 unsigned char *syslibOSECPUBin; // syslibの元バイナリ
188198 unsigned char *syslibJITBin; // syslibのJITコンパイルされたバイナリ(実行可能)
189- int appSize0;
190- int appSize1;
199+ //
191200 int executionLevel;
192201
193202 /* for-junkApi */
@@ -205,18 +214,16 @@ struct Regs {
205214 // Grobal values
206215 //
207216
208-extern int *keybuf, keybuf_r, keybuf_w, keybuf_c;
217+extern HOSECPU_Device_Keyboard mainKeyboard;
209218 extern HOSECPU_Device_Window mainWindow;
210-// di1_serial: デバッグ用。プログラム中の随所で加算される変数
211-extern int di1_serial;
212219
213220 //
214221 // Functions
215222 //
216223
217224 // @main.c
218-void putKeybuf(int i);
219225 int HeavyOSECPUMain(int argc, char **argv);
226+void putKeybuf(int i);
220227
221228 // @comlib.c
222229 unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
旧リポジトリブラウザで表示