コミットメタ情報

リビジョンb96b977b6b31a69547fc8f27b1911e3c25b4100a (tree)
日時2014-03-14 22:28:42
作者hikarupsp <hikarupsp@user...>
コミッターhikarupsp

ログメッセージ

tek対応はできた模様(一部64bit幅の演算を32bitで行っていたのが原因)
展開されたバックエンドコードは正常であると確認した。
しかし、MacOSXでは、アライメントエラーで落ちる。これは64bit環境特有のもののようだ。

変更サマリ

差分

--- a/main.c
+++ b/main.c
@@ -103,7 +103,7 @@ int HeavyOSECPUMain(int argc, char **argv)
103103 fputs("tek decomp error.\n", stderr);
104104 return 1;
105105 }
106- env.appSize1++;
106+ env.appSize1 += 2;
107107 #else
108108 env.appSize1 = -9;
109109 #endif
--- a/tek.c
+++ b/tek.c
@@ -1,21 +1,19 @@
1-#include "tek.h"
1+#include <setjmp.h>
2+#include <string.h>
3+#include <stdlib.h>
24
3-static unsigned int tek_getnum_s7s(UCHAR **pp);
4-/*
5-// not used.
6-static int tek_lzrestore_stk1(int srcsiz, UCHAR *src, int outsiz, UCHAR *q);
5+#if (!defined(NULL))
6+ #define NULL 0
7+#endif
8+
9+typedef unsigned char UCHAR;
10+typedef unsigned int UINT32;
11+typedef UINT32 tek_TPRB;
12+
13+/* not used
714 static int tek_decode1(int siz, UCHAR *p, UCHAR *q);
8-static unsigned int tek_getnum_s7(UCHAR **pp);
9-static int tek_lzrestore_stk2(int srcsiz, UCHAR *src, int outsiz, UCHAR *q);
1015 static int tek_decode2(int siz, UCHAR *p, UCHAR *q);
1116 */
12-static int tek_lzrestore_tek5(int srcsiz, UCHAR *src, int outsiz, UCHAR *outbuf);
13-static void tek_setbm5(struct tek_STR_BITMODEL *bm, int t, int m);
14-static int tek_rdget0(struct tek_STR_RNGDEC *rd, int n, int i);
15-static int tek_rdget1(struct tek_STR_RNGDEC *rd, tek_TPRB *prob0, int n, int j, struct tek_STR_BITMODEL *bm);
16-static UINT32 tek_revbit(UINT32 data, int len);
17-static int tek_getlen5(struct tek_STR_RNGDEC *rd, int m, int s_pos, int stk);
18-static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int pb, int lp, int flags);
1917 static int tek_decode5(int siz, UCHAR *p, UCHAR *q);
2018
2119 static unsigned int tek_getnum_s7s(UCHAR **pp)
@@ -49,7 +47,7 @@ int tek_getsize(unsigned char *p)
4947
5048 #endif
5149
52-int tek_decomp(unsigned char *p, unsigned char *q, int size)
50+int tek_decomp(unsigned char *p, char *q, int size)
5351 {
5452 int err = -1;
5553 #if 0
@@ -61,8 +59,8 @@ int tek_decomp(unsigned char *p, unsigned char *q, int size)
6159 err = tek_decode5(size, p, q);
6260 }
6361 #else
64- if (*p == 0x89) {
65- err = tek_decode5(size, p, q);
62+if (*p == 0x89) {
63+ err = tek_decode5(size, p, (UCHAR *)q);
6664 }
6765 #endif
6866 if (err != 0) {
@@ -185,7 +183,7 @@ static int tek_lzrestore_stk2(int srcsiz, UCHAR *src, int outsiz, UCHAR *q)
185183 } while (--j);
186184 if (q >= q1)
187185 break;
188-
186+
189187 /* lzフェーズ */
190188 j = 0;
191189 do {
@@ -263,10 +261,12 @@ static int tek_decode2(int siz, UCHAR *p, UCHAR *q)
263261
264262 #endif
265263
264+static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int pb, int lp, int flags);
265+
266266 static int tek_lzrestore_tek5(int srcsiz, UCHAR *src, int outsiz, UCHAR *outbuf)
267267 {
268268 int wrksiz, lc, lp, pb, flags = 0, *work, prop0, fl;
269-
269+
270270 if ((fl = (prop0 = *src) & 0x0f) == 0x01) /* 0001 */
271271 flags |= -1;
272272 else if (fl == 0x05)
@@ -311,6 +311,35 @@ static int tek_lzrestore_tek5(int srcsiz, UCHAR *src, int outsiz, UCHAR *outbuf)
311311 return flags;
312312 }
313313
314+struct tek_STR_BITMODEL {
315+ UCHAR t, m, s, dmy;
316+ UINT32 prb0, prb1, tmsk, ntm, lt, lt0, dmy4;
317+};
318+
319+struct tek_STR_PRB {
320+ struct tek_STR_PRB_PB {
321+ struct tek_STR_PRB_PBST {
322+ tek_TPRB mch, rep0l1;
323+ } st[12];
324+ tek_TPRB lenlow[2][8], lenmid[2][8];
325+ } pb[16];
326+ struct tek_STR_PRB_ST {
327+ tek_TPRB rep, repg0, repg1, repg2;
328+ } st[12];
329+ tek_TPRB lensel[2][2], lenhigh[2][256], pslot[4][64], algn[64];
330+ tek_TPRB spdis[2][2+4+8+16+32], lenext[2+4+8+16+32];
331+ tek_TPRB repg3, fchgprm[2 * 32], tbmt[16], tbmm[16], fchglt;
332+ tek_TPRB lit[1];
333+};
334+
335+struct tek_STR_RNGDEC {
336+ UCHAR *p;
337+ UINT32 range, code, rmsk;
338+ jmp_buf errjmp;
339+ struct tek_STR_BITMODEL bm[32], *ptbm[16];
340+ struct tek_STR_PRB probs;
341+};
342+
314343 static void tek_setbm5(struct tek_STR_BITMODEL *bm, int t, int m)
315344 {
316345 bm->t = t;
@@ -354,7 +383,7 @@ static int tek_rdget1(struct tek_STR_RNGDEC *rd, tek_TPRB *prob0, int n, int j,
354383 /* 寿命切れ */
355384 if (tek_rdget1(rd, &rd->probs.fchglt, 0x71, 0, &rd->bm[3]) == 0) {
356385 /* 寿命変更はまだサポートしてない */
357- err:
386+err:
358387 longjmp(rd->errjmp, 1);
359388 }
360389 i = bm - rd->bm;
@@ -376,17 +405,18 @@ static int tek_rdget1(struct tek_STR_RNGDEC *rd, tek_TPRB *prob0, int n, int j,
376405 }
377406 if (p & bm->ntm) {
378407 p &= bm->tmsk;
379- fixprob:
408+ fixprob:
380409 *prob = p;
381410 }
382411 }
383-
412+
384413 while (rd->range < (UINT32) (1 << 24)) {
385414 rd->range <<= 8;
386415 rd->code = rd->code << 8 | *rd->p++;
387416 }
388417 j += j;
389- i = (UINT32)((rd->range & rd->rmsk) * p) >> 16;
418+ // 64ビット幅が必要
419+ i = (unsigned int)(((unsigned long long)(rd->range & rd->rmsk) * p) >> 16);
390420 if (rd->code < i) {
391421 j |= 1;
392422 rd->range = i;
@@ -443,7 +473,7 @@ static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int p
443473 UINT32 *lit1;
444474 struct tek_STR_RNGDEC *rd = (struct tek_STR_RNGDEC *) work;
445475 struct tek_STR_PRB *prb = &rd->probs;
446-
476+
447477 rd->p = &src[4];
448478 rd->range |= -1;
449479 rd->code = src[0] << 24 | src[1] << 16 | src[2] << 8 | src[3];
@@ -469,17 +499,17 @@ static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int p
469499 } else {
470500 UCHAR pt[14];
471501 static UCHAR pt1[14] = {
472- 8, 8, 8, 8, 8, 8, 8, 8,
473- 8, 8, 18, 18, 18, 8
502+ 8, 8, 8, 8, 8, 8, 8, 8,
503+ 8, 8, 18, 18, 18, 8
474504 };
475505 static UCHAR pt2[14] = {
476- 8, 8, 10, 11, 12, 12, 14, 15,
506+ 8, 8, 10, 11, 12, 12, 14, 15,
477507 16, 16, 18, 18, 20, 21
478508 };
479509 /*
480- 0- 7:mch, mch, lit1, lensel, lenlow, lenmid, lenhigh, lenext
481- 8-15:pslot, pslot, sdis, sdis, align, rep-repg2
482- */
510+ 0- 7:mch, mch, lit1, lensel, lenlow, lenmid, lenhigh, lenext
511+ 8-15:pslot, pslot, sdis, sdis, align, rep-repg2
512+ */
483513 rd->rmsk |= -1;
484514 rd->bm[1].t = 5; rd->bm[1].m = 3; /* for fchgprm */
485515 rd->bm[2].t = 9; rd->bm[2].m = 2; /* for tbmt, tbmm */
@@ -507,7 +537,7 @@ static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int p
507537 }
508538 for (i = 0; i < 32; i++)
509539 tek_setbm5(&rd->bm[i], rd->bm[i].t, rd->bm[i].m);
510-
540+
511541 if ((tek_rdget1(rd, &prb->pb[0].st[0].mch, 0x71, 0, rd->ptbm[0]) ^ stk) == 0)
512542 goto err;
513543 *q++ = tek_rdget1(rd, prb->lit, lit0cntmsk, 1, &rd->bm[24]) & 0xff;
@@ -597,7 +627,7 @@ static int tek_decmain5(int *work, UCHAR *src, int osiz, UCHAR *q, int lc, int p
597627 i = tek_getlen5(rd, 1, s_pos, stk);
598628 s = s < 7 ? 8 : 11;
599629 }
600- skip:
630+skip:
601631 i += 2;
602632 if (pos + rep[0] < 0)
603633 goto err;
旧リポジトリブラウザで表示