• R/O
  • HTTP
  • SSH
  • HTTPS

HeavyOSECPU: Commit


Commit MetaInfo

Revisiónfa336f514b6c229263e38d47cbedf1d234779de5 (tree)
Tiempo2014-03-11 20:54:44
Autorttwilb <ttwilb@user...>
Commiterttwilb

Log Message

Merge branch 'master' of git.sourceforge.jp:/gitroot/heavyosecpu/HeavyOSECPU

Cambiar Resumen

Diferencia incremental

--- a/comlib.c
+++ b/comlib.c
@@ -8,6 +8,15 @@ struct ComLib_Str {
88
99 int ComLib_getBit(struct ComLib_Str *s)
1010 {
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+ /*
1120 if (s->bitBufLen == 0) {
1221 s->bitBuf = s->p[0] | s->p[1] << 8;
1322 s->p += 2;
@@ -15,16 +24,19 @@ int ComLib_getBit(struct ComLib_Str *s)
1524 }
1625 s->bitBufLen--;
1726 return (s->bitBuf >> s->bitBufLen) & 1;
27+ */
1828 }
1929
2030 int ComLib_getTmpBit(struct ComLib_Str *s)
2131 {
32+ //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す
2233 s->tmp = (s->tmp << 1 | ComLib_getBit(s)) & 0xffff;
2334 return ComLib_getBit(s);
2435 }
2536
2637 unsigned char *ComLib_main(const unsigned char *p, unsigned char *q)
2738 {
39+ //hh4デコーダー?
2840 struct ComLib_Str s;
2941 int i, dis = 0;
3042 dis |= -1;
@@ -35,14 +47,20 @@ l0:
3547 *q++ = *s.p++;
3648 l1:
3749 i = ComLib_getBit(&s);
38- if (i != 0) goto l0;
50+ if (i != 0){
51+ //4bit
52+ goto l0;
53+ }
3954 s.tmp = 1;
4055 do {
4156 i = ComLib_getTmpBit(&s);
42- if (s.tmp == 0) goto fin;
57+ if (s.tmp == 0){
58+ goto fin;
59+ }
4360 } while (i == 0);
44- if (s.tmp >= 3)
61+ if (s.tmp >= 3){
4562 dis = ~((s.tmp - 3) << 8 | *s.p++);
63+ }
4664 s.tmp &= 0;
4765 i = ComLib_getTmpBit(&s);
4866 s.tmp = s.tmp << 1 | i;
@@ -54,9 +72,12 @@ l1:
5472 s.tmp += 2;
5573 }
5674 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++){
5979 q[i] = q[i + dis];
80+ }
6081 q += s.tmp;
6182 goto l1;
6283 fin:
--- a/function.c
+++ b/function.c
@@ -344,18 +344,18 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
344344 /* return: R30, P31 */
345345 if (r->buf0 == NULL)
346346 r->buf0 = malloc(1024 * 1024);
347- if (r->argc <= r->ireg[0x31]) {
347+ if (r->mainArgc <= r->ireg[0x31]) {
348348 fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
349349 exit(1);
350350 }
351- fp = fopen(r->argv[r->ireg[0x31]], "rb");
351+ fp = fopen(r->mainArgv[r->ireg[0x31]], "rb");
352352 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]]);
354354 exit(1);
355355 }
356356 i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp);
357357 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]]);
359359 exit(1);
360360 }
361361 fclose(fp);
@@ -368,13 +368,13 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
368368
369369 case 0xff02:
370370 /* return: none */
371- if (r->argc <= r->ireg[0x31]) {
371+ if (r->mainArgc <= r->ireg[0x31]) {
372372 fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
373373 exit(1);
374374 }
375- fp = fopen(r->argv[r->ireg[0x31]], "wb");
375+ fp = fopen(r->mainArgv[r->ireg[0x31]], "wb");
376376 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]]);
378378 exit(1);
379379 }
380380 if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
--- a/jitc.c
+++ b/jitc.c
@@ -29,6 +29,7 @@ void errorHandler(HOSECPU_RuntimeEnvironment *r)
2929
3030 int jitCompCmdLen(const unsigned char *src)
3131 {
32+ //BCode命令長を取得する
3233 int i = 1;
3334 if (0x01 <= *src && *src < 0x04) i = 6;
3435 if (*src == 0x04) i = 2;
@@ -43,7 +44,10 @@ int jitCompCmdLen(const unsigned char *src)
4344 if (*src == 0xfe) i = 2 + src[1];
4445 return i;
4546 }
46-#if (JITC_ARCNUM == 0x0001) /* x86-32bit */
47+#if (JITC_ARCNUM == 0x0001)
48+//
49+// for x86-32bit
50+//
4751
4852 /* 他のCPUへ移植する人へ:
4953 以下は最適化のためのものなので、すべて0として簡単に移植しても問題ありません */
--- a/main.c
+++ b/main.c
@@ -41,10 +41,10 @@ int HeavyOSECPUMain(int argc, char **argv)
4141 //unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0;
4242 // syslib.oseのjitc結果を格納する領域を確保。
4343 sysjit00 = mallocRWE(SJITSIZ1);
44+ sysjit = sysjit00;
4445 // 現在の、jitc結果を格納するメモリへの書き込み位置のアドレス
4546 // sysjit: 現在のjitc書き込み位置
4647 // sysjit00: jitc結果の先頭
47- sysjit = sysjit00;
4848 //ワークメモリを三つくらいもらう
4949 systmp0 = malloc(SYSTMP0SIZ); /* syslibのjitc用 */
5050 systmp1 = malloc(SYSTMP1SIZ);
@@ -63,18 +63,13 @@ int HeavyOSECPUMain(int argc, char **argv)
6363 }
6464 ptrCtrl[0].size = -2;
6565
66- /* syslibの読み込み */
67- syslib = Init_LoadSysLib(argv[0], systmp0);
66+ /* syslibの読み込み */
67+ syslib = Init_LoadSysLib(argv[0], systmp0);
6868
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;
7671 // 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);
7873 if (i != 0){
7974 fputs("syslib-file JITC error.\n", stderr);
8075 return 1;
@@ -128,7 +123,7 @@ int HeavyOSECPUMain(int argc, char **argv)
128123 env.preg[0x0b].p = (void *)pxxFlag;
129124 env.preg[0x0c].p = (void *)typLabel;
130125 env.preg[0x0d].p = opTbl;
131- jitfunc = (void *)sysjit;
126+ jitfunc = (void *)sysjit00;
132127 (*jitfunc)(((char *)&env) + 128); /* サイズを節約するためにEBPを128バイトずらす */
133128 if (env.ireg[0] != 0) {
134129 jp = env.preg[2].p - 1;
@@ -145,13 +140,15 @@ int HeavyOSECPUMain(int argc, char **argv)
145140 memcpy(systmp0, env.appBin, env.appSize1);
146141 tmpsiz = env.appSize1;
147142 }
148-
143+
149144 if ((argDebug & 2) != 0) {
145+ /*変換後のバックエンドコードをファイルへ保存*/
150146 fp = fopen("debug2.bin", "wb");
151147 fwrite(systmp0, 1, tmpsiz, fp);
152148 fclose(fp);
153149 }
154150
151+ //JITコンパイル
155152 i = jitc0(&jp, jitbuf + 1024 * 1024, systmp0, systmp0 + tmpsiz, env.executionLevel, label);
156153 if (i == 1){
157154 fputs("app-file header error.\n", stderr);
@@ -180,8 +177,6 @@ int HeavyOSECPUMain(int argc, char **argv)
180177 env.preg[i].p1 = NULL;
181178 }
182179
183- env.argc = argc;
184- env.argv = (const char **)argv;
185180 env.buf0 = env.buf1 = NULL;
186181 env.preg[0x28].p = p28;
187182 env.preg[0x28].typ = 0; // TYP_CODE
--- a/osecpu.h
+++ b/osecpu.h
@@ -116,8 +116,8 @@ struct Regs {
116116 int executionLevel;
117117
118118 /* for-junkApi */
119- int argc;
120- const char **argv;
119+ //int argc;
120+ //const char **argv;
121121 unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
122122
123123 HOSECPU_LabelListTag *label;
--- a/screen.c
+++ b/screen.c
@@ -2,36 +2,51 @@
22
33 void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r)
44 {
5- if (0x10 <= c && c <= 0x1f)
5+ if (0x10 <= c && c <= 0x1f){
66 c = "0123456789ABCDEF"[c & 0x0f];
7- putchar(r->lastConsoleChar = c);
7+ }
8+ putchar(c);
9+ r->lastConsoleChar = c;
810 return;
911 }
1012
1113 void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx)
1214 {
1315 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){
1929 (*(r->errHndl))(r);
30+ }
2031 return;
2132 }
2233
2334 int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx)
2435 {
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;
2639 if (m == 0x04) {
27- if (c < -1 || c > 7)
40+ if (c < -1 || c > 7){
2841 (*(r->errHndl))(r);
42+ }
2943 c = iColor1[c & 0x07];
3044 }
3145 if (m == 0x08) {
3246 // 00, 24, 48, 6d, 91, b6, da, ff
33- if (c < 0 || c >= (1 << 9))
47+ if (c < 0 || c >= (1 << 9)){
3448 (*(r->errHndl))(r);
49+ }
3550 rr = (c >> 6) & 0x07;
3651 gg = (c >> 3) & 0x07;
3752 bb = c & 0x07;
@@ -45,8 +60,9 @@ int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx)
4560 // 41, 4a, 52, 5a, 62, 6a, 73, 7b,
4661 // 83, 8b, 94, 9c, a4, ac, b4, bd,
4762 // c5, cd, d5, de, e6, ee, f6, ff
48- if (c < 0 || c >= (1 << 15))
63+ if (c < 0 || c >= (1 << 15)){
4964 (*(r->errHndl))(r);
65+ }
5066 rr = (c >> 10) & 0x1f;
5167 gg = (c >> 5) & 0x1f;
5268 bb = c & 0x1f;
@@ -62,13 +78,28 @@ void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx)
6278 {
6379 char c = 0;
6480 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){
72102 (*(r->errHndl))(r);
103+ }
73104 return;
74105 }
\ No newline at end of file
Show on old repository browser