Revisión | fa336f514b6c229263e38d47cbedf1d234779de5 (tree) |
---|---|
Tiempo | 2014-03-11 20:54:44 |
Autor | ttwilb <ttwilb@user...> |
Commiter | ttwilb |
Merge branch 'master' of git.sourceforge.jp:/gitroot/heavyosecpu/HeavyOSECPU
@@ -8,6 +8,15 @@ struct ComLib_Str { | ||
8 | 8 | |
9 | 9 | int ComLib_getBit(struct ComLib_Str *s) |
10 | 10 | { |
11 | + //ビットを一つずつ取り出す | |
12 | + if (s->bitBufLen == 0) { | |
13 | + s->bitBuf = s->p[0] | s->p[1] << 8; | |
14 | + s->p += 2; | |
15 | + s->bitBufLen = 16; | |
16 | + } | |
17 | + s->bitBufLen--; | |
18 | + return (s->bitBuf >> s->bitBufLen) & 1; | |
19 | + /* | |
11 | 20 | if (s->bitBufLen == 0) { |
12 | 21 | s->bitBuf = s->p[0] | s->p[1] << 8; |
13 | 22 | s->p += 2; |
@@ -15,16 +24,19 @@ int ComLib_getBit(struct ComLib_Str *s) | ||
15 | 24 | } |
16 | 25 | s->bitBufLen--; |
17 | 26 | return (s->bitBuf >> s->bitBufLen) & 1; |
27 | + */ | |
18 | 28 | } |
19 | 29 | |
20 | 30 | int ComLib_getTmpBit(struct ComLib_Str *s) |
21 | 31 | { |
32 | + //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す | |
22 | 33 | s->tmp = (s->tmp << 1 | ComLib_getBit(s)) & 0xffff; |
23 | 34 | return ComLib_getBit(s); |
24 | 35 | } |
25 | 36 | |
26 | 37 | unsigned char *ComLib_main(const unsigned char *p, unsigned char *q) |
27 | 38 | { |
39 | + //hh4デコーダー? | |
28 | 40 | struct ComLib_Str s; |
29 | 41 | int i, dis = 0; |
30 | 42 | dis |= -1; |
@@ -35,14 +47,20 @@ l0: | ||
35 | 47 | *q++ = *s.p++; |
36 | 48 | l1: |
37 | 49 | i = ComLib_getBit(&s); |
38 | - if (i != 0) goto l0; | |
50 | + if (i != 0){ | |
51 | + //4bit | |
52 | + goto l0; | |
53 | + } | |
39 | 54 | s.tmp = 1; |
40 | 55 | do { |
41 | 56 | i = ComLib_getTmpBit(&s); |
42 | - if (s.tmp == 0) goto fin; | |
57 | + if (s.tmp == 0){ | |
58 | + goto fin; | |
59 | + } | |
43 | 60 | } while (i == 0); |
44 | - if (s.tmp >= 3) | |
61 | + if (s.tmp >= 3){ | |
45 | 62 | dis = ~((s.tmp - 3) << 8 | *s.p++); |
63 | + } | |
46 | 64 | s.tmp &= 0; |
47 | 65 | i = ComLib_getTmpBit(&s); |
48 | 66 | s.tmp = s.tmp << 1 | i; |
@@ -54,9 +72,12 @@ l1: | ||
54 | 72 | s.tmp += 2; |
55 | 73 | } |
56 | 74 | s.tmp++; |
57 | - if (dis < -0xd00) s.tmp++; | |
58 | - for (i = 0; i < s.tmp; i++) | |
75 | + if (dis < -0xd00){ | |
76 | + s.tmp++; | |
77 | + } | |
78 | + for (i = 0; i < s.tmp; i++){ | |
59 | 79 | q[i] = q[i + dis]; |
80 | + } | |
60 | 81 | q += s.tmp; |
61 | 82 | goto l1; |
62 | 83 | fin: |
@@ -344,18 +344,18 @@ void devFunc(HOSECPU_RuntimeEnvironment *r) | ||
344 | 344 | /* return: R30, P31 */ |
345 | 345 | if (r->buf0 == NULL) |
346 | 346 | r->buf0 = malloc(1024 * 1024); |
347 | - if (r->argc <= r->ireg[0x31]) { | |
347 | + if (r->mainArgc <= r->ireg[0x31]) { | |
348 | 348 | fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]); |
349 | 349 | exit(1); |
350 | 350 | } |
351 | - fp = fopen(r->argv[r->ireg[0x31]], "rb"); | |
351 | + fp = fopen(r->mainArgv[r->ireg[0x31]], "rb"); | |
352 | 352 | if (fp == NULL) { |
353 | - fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->argv[r->ireg[0x31]]); | |
353 | + fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]); | |
354 | 354 | exit(1); |
355 | 355 | } |
356 | 356 | i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp); |
357 | 357 | if (i >= 1024 * 1024 - 4 || i < 0) { |
358 | - fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->argv[r->ireg[0x31]]); | |
358 | + fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->mainArgv[r->ireg[0x31]]); | |
359 | 359 | exit(1); |
360 | 360 | } |
361 | 361 | fclose(fp); |
@@ -368,13 +368,13 @@ void devFunc(HOSECPU_RuntimeEnvironment *r) | ||
368 | 368 | |
369 | 369 | case 0xff02: |
370 | 370 | /* return: none */ |
371 | - if (r->argc <= r->ireg[0x31]) { | |
371 | + if (r->mainArgc <= r->ireg[0x31]) { | |
372 | 372 | fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]); |
373 | 373 | exit(1); |
374 | 374 | } |
375 | - fp = fopen(r->argv[r->ireg[0x31]], "wb"); | |
375 | + fp = fopen(r->mainArgv[r->ireg[0x31]], "wb"); | |
376 | 376 | if (fp == NULL) { |
377 | - fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->argv[r->ireg[0x31]]); | |
377 | + fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]); | |
378 | 378 | exit(1); |
379 | 379 | } |
380 | 380 | if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){ |
@@ -29,6 +29,7 @@ void errorHandler(HOSECPU_RuntimeEnvironment *r) | ||
29 | 29 | |
30 | 30 | int jitCompCmdLen(const unsigned char *src) |
31 | 31 | { |
32 | + //BCode命令長を取得する | |
32 | 33 | int i = 1; |
33 | 34 | if (0x01 <= *src && *src < 0x04) i = 6; |
34 | 35 | if (*src == 0x04) i = 2; |
@@ -43,7 +44,10 @@ int jitCompCmdLen(const unsigned char *src) | ||
43 | 44 | if (*src == 0xfe) i = 2 + src[1]; |
44 | 45 | return i; |
45 | 46 | } |
46 | -#if (JITC_ARCNUM == 0x0001) /* x86-32bit */ | |
47 | +#if (JITC_ARCNUM == 0x0001) | |
48 | +// | |
49 | +// for x86-32bit | |
50 | +// | |
47 | 51 | |
48 | 52 | /* 他のCPUへ移植する人へ: |
49 | 53 | 以下は最適化のためのものなので、すべて0として簡単に移植しても問題ありません */ |
@@ -41,10 +41,10 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
41 | 41 | //unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0; |
42 | 42 | // syslib.oseのjitc結果を格納する領域を確保。 |
43 | 43 | sysjit00 = mallocRWE(SJITSIZ1); |
44 | + sysjit = sysjit00; | |
44 | 45 | // 現在の、jitc結果を格納するメモリへの書き込み位置のアドレス |
45 | 46 | // sysjit: 現在のjitc書き込み位置 |
46 | 47 | // sysjit00: jitc結果の先頭 |
47 | - sysjit = sysjit00; | |
48 | 48 | //ワークメモリを三つくらいもらう |
49 | 49 | systmp0 = malloc(SYSTMP0SIZ); /* syslibのjitc用 */ |
50 | 50 | systmp1 = malloc(SYSTMP1SIZ); |
@@ -63,18 +63,13 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
63 | 63 | } |
64 | 64 | ptrCtrl[0].size = -2; |
65 | 65 | |
66 | - /* syslibの読み込み */ | |
67 | - syslib = Init_LoadSysLib(argv[0], systmp0); | |
66 | + /* syslibの読み込み */ | |
67 | + syslib = Init_LoadSysLib(argv[0], systmp0); | |
68 | 68 | |
69 | - // jitc.cのerrHndl()をCALLするネィティブコードを挿入。 | |
70 | - // sysjitの値は次の書き込み位置へずらされる。 | |
71 | - // 元々のsysjitはsysjit00へ保存されている。 | |
72 | - sysjit = jitCompInit(sysjit); | |
73 | - | |
74 | - // sysjit (アドレス変数)は下の関数の実行で変更される(だから参照渡し) | |
75 | - // もちろんsysjitの値は次の書き込み位置へずらされる。 | |
69 | + sysjit = jitCompInit(sysjit); | |
70 | + sysjit00 = sysjit; | |
76 | 71 | // labelはjitc0()内で初期化される。 |
77 | - i = jitc0(&sysjit, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_FASTEST, label); | |
72 | + i = jitc0(&sysjit, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_SLOWEST+9, label); | |
78 | 73 | if (i != 0){ |
79 | 74 | fputs("syslib-file JITC error.\n", stderr); |
80 | 75 | return 1; |
@@ -128,7 +123,7 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
128 | 123 | env.preg[0x0b].p = (void *)pxxFlag; |
129 | 124 | env.preg[0x0c].p = (void *)typLabel; |
130 | 125 | env.preg[0x0d].p = opTbl; |
131 | - jitfunc = (void *)sysjit; | |
126 | + jitfunc = (void *)sysjit00; | |
132 | 127 | (*jitfunc)(((char *)&env) + 128); /* サイズを節約するためにEBPを128バイトずらす */ |
133 | 128 | if (env.ireg[0] != 0) { |
134 | 129 | jp = env.preg[2].p - 1; |
@@ -145,13 +140,15 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
145 | 140 | memcpy(systmp0, env.appBin, env.appSize1); |
146 | 141 | tmpsiz = env.appSize1; |
147 | 142 | } |
148 | - | |
143 | + | |
149 | 144 | if ((argDebug & 2) != 0) { |
145 | + /*変換後のバックエンドコードをファイルへ保存*/ | |
150 | 146 | fp = fopen("debug2.bin", "wb"); |
151 | 147 | fwrite(systmp0, 1, tmpsiz, fp); |
152 | 148 | fclose(fp); |
153 | 149 | } |
154 | 150 | |
151 | + //JITコンパイル | |
155 | 152 | i = jitc0(&jp, jitbuf + 1024 * 1024, systmp0, systmp0 + tmpsiz, env.executionLevel, label); |
156 | 153 | if (i == 1){ |
157 | 154 | fputs("app-file header error.\n", stderr); |
@@ -180,8 +177,6 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
180 | 177 | env.preg[i].p1 = NULL; |
181 | 178 | } |
182 | 179 | |
183 | - env.argc = argc; | |
184 | - env.argv = (const char **)argv; | |
185 | 180 | env.buf0 = env.buf1 = NULL; |
186 | 181 | env.preg[0x28].p = p28; |
187 | 182 | env.preg[0x28].typ = 0; // TYP_CODE |
@@ -116,8 +116,8 @@ struct Regs { | ||
116 | 116 | int executionLevel; |
117 | 117 | |
118 | 118 | /* for-junkApi */ |
119 | - int argc; | |
120 | - const char **argv; | |
119 | + //int argc; | |
120 | + //const char **argv; | |
121 | 121 | unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1; |
122 | 122 | |
123 | 123 | HOSECPU_LabelListTag *label; |
@@ -2,36 +2,51 @@ | ||
2 | 2 | |
3 | 3 | void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r) |
4 | 4 | { |
5 | - if (0x10 <= c && c <= 0x1f) | |
5 | + if (0x10 <= c && c <= 0x1f){ | |
6 | 6 | c = "0123456789ABCDEF"[c & 0x0f]; |
7 | - putchar(r->lastConsoleChar = c); | |
7 | + } | |
8 | + putchar(c); | |
9 | + r->lastConsoleChar = c; | |
8 | 10 | return; |
9 | 11 | } |
10 | 12 | |
11 | 13 | void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx) |
12 | 14 | { |
13 | 15 | char c = 0; |
14 | - if (r->preg[pxx].typ != 0x03) c = 1; | |
15 | - if (r->preg[pxx].p < r->preg[pxx].p0) c = 1; | |
16 | - if (r->ireg[rxx] < 0) c = 1; | |
17 | - if (r->preg[pxx].p + r->ireg[rxx] > r->preg[pxx].p1) c = 1; | |
18 | - if (c != 0) | |
16 | + if (r->preg[pxx].typ != 0x03){ | |
17 | + c = 1; | |
18 | + } | |
19 | + if (r->preg[pxx].p < r->preg[pxx].p0){ | |
20 | + c = 1; | |
21 | + } | |
22 | + if (r->ireg[rxx] < 0){ | |
23 | + c = 1; | |
24 | + } | |
25 | + if (r->preg[pxx].p + r->ireg[rxx] > r->preg[pxx].p1){ | |
26 | + c = 1; | |
27 | + } | |
28 | + if (c != 0){ | |
19 | 29 | (*(r->errHndl))(r); |
30 | + } | |
20 | 31 | return; |
21 | 32 | } |
22 | 33 | |
23 | 34 | int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx) |
24 | 35 | { |
25 | - int c = r->ireg[rxx], m = r->ireg[0x31] & 0x0c, rr, gg, bb; | |
36 | + int c, m, rr, gg, bb; | |
37 | + c = r->ireg[rxx]; | |
38 | + m = r->ireg[0x31] & 0x0c; | |
26 | 39 | if (m == 0x04) { |
27 | - if (c < -1 || c > 7) | |
40 | + if (c < -1 || c > 7){ | |
28 | 41 | (*(r->errHndl))(r); |
42 | + } | |
29 | 43 | c = iColor1[c & 0x07]; |
30 | 44 | } |
31 | 45 | if (m == 0x08) { |
32 | 46 | // 00, 24, 48, 6d, 91, b6, da, ff |
33 | - if (c < 0 || c >= (1 << 9)) | |
47 | + if (c < 0 || c >= (1 << 9)){ | |
34 | 48 | (*(r->errHndl))(r); |
49 | + } | |
35 | 50 | rr = (c >> 6) & 0x07; |
36 | 51 | gg = (c >> 3) & 0x07; |
37 | 52 | bb = c & 0x07; |
@@ -45,8 +60,9 @@ int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx) | ||
45 | 60 | // 41, 4a, 52, 5a, 62, 6a, 73, 7b, |
46 | 61 | // 83, 8b, 94, 9c, a4, ac, b4, bd, |
47 | 62 | // c5, cd, d5, de, e6, ee, f6, ff |
48 | - if (c < 0 || c >= (1 << 15)) | |
63 | + if (c < 0 || c >= (1 << 15)){ | |
49 | 64 | (*(r->errHndl))(r); |
65 | + } | |
50 | 66 | rr = (c >> 10) & 0x1f; |
51 | 67 | gg = (c >> 5) & 0x1f; |
52 | 68 | bb = c & 0x1f; |
@@ -62,13 +78,28 @@ void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx) | ||
62 | 78 | { |
63 | 79 | char c = 0; |
64 | 80 | int i; |
65 | - if (r->ireg[rxx + 0] <= 0 || r->ireg[rxx + 0] > v_xsiz) c = 1; | |
66 | - if (r->ireg[rxx + 1] <= 0 || r->ireg[rxx + 1] > v_ysiz) c = 1; | |
67 | - if (r->ireg[rxx + 2] < 0 || r->ireg[rxx + 2] >= v_xsiz) c = 1; | |
68 | - if (r->ireg[rxx + 3] < 0 || r->ireg[rxx + 3] >= v_ysiz) c = 1; | |
69 | - i = r->ireg[rxx + 2] + r->ireg[rxx + 0]; if (i <= 0 || i > v_xsiz) c = 1; | |
70 | - i = r->ireg[rxx + 1] + r->ireg[rxx + 3]; if (i <= 0 || i > v_ysiz) c = 1; | |
71 | - if (c != 0) | |
81 | + if (r->ireg[rxx + 0] <= 0 || r->ireg[rxx + 0] > v_xsiz){ | |
82 | + c = 1; | |
83 | + } | |
84 | + if (r->ireg[rxx + 1] <= 0 || r->ireg[rxx + 1] > v_ysiz){ | |
85 | + c = 1; | |
86 | + } | |
87 | + if (r->ireg[rxx + 2] < 0 || r->ireg[rxx + 2] >= v_xsiz){ | |
88 | + c = 1; | |
89 | + } | |
90 | + if (r->ireg[rxx + 3] < 0 || r->ireg[rxx + 3] >= v_ysiz){ | |
91 | + c = 1; | |
92 | + } | |
93 | + i = r->ireg[rxx + 2] + r->ireg[rxx + 0]; | |
94 | + if (i <= 0 || i > v_xsiz){ | |
95 | + c = 1; | |
96 | + } | |
97 | + i = r->ireg[rxx + 1] + r->ireg[rxx + 3]; | |
98 | + if (i <= 0 || i > v_ysiz){ | |
99 | + c = 1; | |
100 | + } | |
101 | + if (c != 0){ | |
72 | 102 | (*(r->errHndl))(r); |
103 | + } | |
73 | 104 | return; |
74 | 105 | } |
\ No newline at end of file |