OSDN Git Service

Merge branch 'master' of git.sourceforge.jp:/gitroot/heavyosecpu/HeavyOSECPU
[heavyosecpu/HeavyOSECPU.git] / osecpu.h
index 9b24e04..abcfd5f 100644 (file)
--- a/osecpu.h
+++ b/osecpu.h
@@ -1,4 +1,4 @@
-#ifndef _HDLOAD_OSECPU
+#ifndef _HDLOAD_OSECPU
 #define _HDLOAD_OSECPU 1
 
 /* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/
 // 1 : Windows 32bit
 // 2 : Mac OSX 32bit
 // 3 : blike for Linux
-#define DRV_OSNUM 0x0001
+#ifdef _WIN32
+#define DRV_OSNUM                      0x0001
+#endif
+#ifdef __APPLE__
+#define DRV_OSNUM                      0x0002
+#endif
+#ifdef __linux__
+#define DRV_OSNUM                      0x0003
+#endif
+//#define DRV_OSNUM 0x0002
 
 // Decoder (syslib.ose) setting
 // syslib.ose is necessary to work OSECPU
 #define SYSLIB_OSE     "syslib.ose"
+
+//
+// Define constant values
+//
+
+// SIGN1: The 2nd signature of OSECPU Format(05 e1)
+// It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers)
 #define SIGN1          0xe1
 
 #define USE_DEBUGGER   1
-#define USE_TEK5               0       //元々は1
+#define USE_TEK5               1
+
+/* JITC mode flags */
+#define        JITC_LV_SLOWEST         0       /* デバッグ支援は何でもやる */
+#define        JITC_LV_SLOWER          1       /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
+#define        JITC_LV_SAFE            2       /* とにかく止まる、場所は不明、テストは必要最小限 */
+#define        JITC_LV_FASTER          4       /* 情報は生成するがチェックをしない */
+#define        JITC_LV_FASTEST         5       /* 情報すら生成しない */
+#define JITC_PHASE1                    0x0001
+#define JITC_SKIPCHECK         0x0002  /* セキュリティチェックを省略する(高速危険モード) */
+#define JITC_NOSTARTUP         0x0004
+#define JITC_MAXLABELS         4096
+#define PTRCTRLSIZ                     4096
 
 #define        APPSIZ1         1 * 1024 * 1024 /* 1MB for now */
-#define        JITSIZ1         1 * 1024 * 1024 /* 1MB for now */
-#define        SJITSIZ1        1 * 1024 * 1024 /* 1MB for now */
+#define APPJITSIZE  1 * 1024 * 1024 /* 1MB for now */
+#define        SYSJITSIZ1      2 * 1024 * 1024 /* 1MB for now */
 #define        SYSLIBSIZ1      1 * 1024 * 1024 /* 1MB for now */
 #define SYSTMP0SIZ     1 * 1024 * 1024 /* 1MB for now */
 #define SYSTMP1SIZ     2 * 1024 * 1024 /* 1MB for now */
 
 #define KEYBUFSIZ              4096
 
+#define KEY_ENTER              '\n'
+#define KEY_ESC                        27
+#define KEY_BACKSPACE  8
+#define KEY_TAB                        9
+#define KEY_PAGEUP             0x1020
+#define KEY_PAGEDWN            0x1021
+#define        KEY_END                 0x1022
+#define        KEY_HOME                0x1023
+#define KEY_LEFT               0x1024
+#define KEY_UP                 0x1025
+#define KEY_RIGHT              0x1026
+#define KEY_DOWN               0x1027
+#define KEY_INS                        0x1028
+#define KEY_DEL                        0x1029
+
 //
 // HOSECPU structures
 //
+typedef struct PtrCtrl HOSECPU_PointerControlTag;
 struct PtrCtrl {
        int liveSign;
        int size, typ;
        unsigned char *p0;
 };
-typedef struct PtrCtrl HOSECPU_PointerControlTag;
 
-struct Ptr {   /* 32バイト(=256bit!) */
+typedef struct Ptr HOSECPU_PointerRegisterEntry;
+struct Ptr {
+       // 32バイト(=256bit!)
        unsigned char *p;
+       
+       /* static char *typName[] = {
+               "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8",
+               "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32",
+               "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2",
+               "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12",
+               "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24",
+               "T_SINT28", "T_UINT28"
+       } ; */
        int typ;
        unsigned char *p0, *p1;
        int liveSign;
-       struct PtrCtrl *pls;
+       HOSECPU_PointerControlTag *pls;
        int flags, dummy;       /* read/writeなど */
 };
-typedef struct Ptr HOSECPU_PointerRegisterEntry;
 
+typedef struct LabelTable HOSECPU_LabelListTag;
 struct LabelTable {
        unsigned char *p, *p1;
        int opt;
-       
        /*
         * default = -1
         * TYP_CODE = 0
         * T_UINT8 = 3
+        *
+        * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053
         */
        int typ;
 };
 
-typedef struct LabelTable HOSECPU_LabelListTag;
+typedef struct Device_Window HOSECPU_Device_Window;
+struct Device_Window {
+    int *vram;
+    int xsize, ysize;
+};
 
+typedef struct Regs HOSECPU_RuntimeEnvironment;
 struct Regs {
-       int ireg[64];           /* 32bit整数レジスタ */
-       struct Ptr preg[64];    /* ポインタレジスタ */
-
-       int debugInfo0, debugInfo1, dmy[2]; /* 2304 */
-       struct PtrCtrl *ptrCtrl;            /* 2320 */
+       int ireg[64];                                                           // 整数レジスタ (4 * 64) = 256
+       HOSECPU_PointerRegisterEntry preg[64];          // ポインタレジスタ (32 * 64) = 2048
+    //
+       int debugInfo0;                                                         // 2304
+       int debugInfo1;                                                         // 2308
+    int dbg_currentCode;                        // 2312
+       int dmy;                                                                        // 2316
+       //
+       HOSECPU_PointerControlTag *ptrCtrl;         // 2320
        char winClosed, autoSleep;
-       jmp_buf *setjmpEnv;
-
+       jmp_buf setjmpEnv;
+    int appReturnCode;      // アプリ自体の終了コード
+    
+    /* Main environment */
+    int mainArgc;           // HOSECPU起動引数の個数
+    const char **mainArgv;  // HOSECPU起動引数リスト
+    unsigned char *appBin;  // 実行するアプリのバイナリ
+    int appSize0;
+    int appSize1;
+    int executionLevel;
+    
        /* for-junkApi */
-       int argc;
-       const char **argv;
        unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
-
-       struct LabelTable *label;
+    
+       HOSECPU_LabelListTag *label;
        int maxLabels;
        unsigned char *jitbuf, *jitbuf1;
-       void(*errHndl)(struct Regs *);
+       void(*errHndl)(HOSECPU_RuntimeEnvironment *);
        char dbgr;
        int mapDi1s[16][16];
 };
 
 //
-// Define constant values
-//
-
-#define KEY_ENTER              '\n'
-#define KEY_ESC                        27
-#define KEY_BACKSPACE  8
-#define KEY_TAB                        9
-#define KEY_PAGEUP             0x1020
-#define KEY_PAGEDWN            0x1021
-#define        KEY_END                 0x1022
-#define        KEY_HOME                0x1023
-#define KEY_LEFT               0x1024
-#define KEY_UP                 0x1025
-#define KEY_RIGHT              0x1026
-#define KEY_DOWN               0x1027
-#define KEY_INS                        0x1028
-#define KEY_DEL                        0x1029
-
-//
-// Grobal static values
+// Grobal values
 //
 
-static int *keybuf, keybuf_r, keybuf_w, keybuf_c;
-static int *vram = NULL, v_xsiz, v_ysiz;
-
-//デバッグ用。プログラム中の随所で加算される変数
-static int di1_serial = 0;
+extern int *keybuf, keybuf_r, keybuf_w, keybuf_c;
+extern HOSECPU_Device_Window mainWindow;
+// di1_serial: デバッグ用。プログラム中の随所で加算される変数
+extern int di1_serial;
 
 //
 // Functions
@@ -138,6 +189,7 @@ static int di1_serial = 0;
 
 // @main.c
 void putKeybuf(int i);
+int HeavyOSECPUMain(int argc, char **argv);
 
 // @comlib.c
 unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
@@ -149,152 +201,42 @@ void drv_flshWin(int sx, int sy, int x0, int y0);
 void drv_sleep(int msec);
 
 // @function.c
-void dbgrMain(struct Regs *r);
+void dbgrMain(HOSECPU_RuntimeEnvironment *r);
 const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理.
-void randStatInit(unsigned int seed);
-void randStatNext();
-void devFunc(struct Regs *r); // junkApiを処理する関数
+void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数
 
 // @jitc.c
-/* JITCのフラグ群 */
-#define        JITC_LV_SLOWEST         0       /* デバッグ支援は何でもやる */
-#define        JITC_LV_SLOWER          1       /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
-#define        JITC_LV_SAFE            2       /* とにかく止まる、場所は不明、テストは必要最小限 */
-#define        JITC_LV_FASTER          4       /* 情報は生成するがチェックをしない */
-#define        JITC_LV_FASTEST         5       /* 情報すら生成しない */
-#define JITC_PHASE1                    0x0001
-#define JITC_SKIPCHECK         0x0002  /* セキュリティチェックを省略する(高速危険モード) */
-#define JITC_NOSTARTUP         0x0004
-#define JITC_MAXLABELS         4096
-#define PTRCTRLSIZ                     4096
-
-
-int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, struct LabelTable *label);
-int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, struct LabelTable *label, int maxLabels, int level, int debugInfo1, int flags);
+void errorHandler(HOSECPU_RuntimeEnvironment *r);
+void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src);
+// @jitcx86.c
+int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);
+int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, HOSECPU_LabelListTag *label, int maxLabels, int level, int debugInfo1, int flags);
 unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
 unsigned char *jitCompInit(unsigned char *dst);
-void errorHandler(struct Regs *r);
+void jitcRunBinary(void (*bin)(char *), HOSECPU_RuntimeEnvironment *env);
 
-// @screen.c
-static unsigned char fontdata[] = {
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
-       0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x00, 0x00,
-       0x10, 0x3a, 0x56, 0x92, 0x92, 0x90, 0x50, 0x38, 0x14, 0x12, 0x92, 0x92, 0xd4, 0xb8, 0x10, 0x10,
-       0x62, 0x92, 0x94, 0x94, 0x68, 0x08, 0x10, 0x10, 0x20, 0x2c, 0x52, 0x52, 0x92, 0x8c, 0x00, 0x00,
-       0x00, 0x70, 0x88, 0x88, 0x88, 0x90, 0x60, 0x47, 0xa2, 0x92, 0x8a, 0x84, 0x46, 0x39, 0x00, 0x00,
-       0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x00,
-       0x80, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, 0x80, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x92, 0x54, 0x38, 0x54, 0x92, 0x10, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0xfe, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x80, 0x80,
-       0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x02, 0x02, 0x04, 0x18, 0x04, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x0c, 0x0c, 0x0c, 0x14, 0x14, 0x14, 0x24, 0x24, 0x44, 0x7e, 0x04, 0x04, 0x1e, 0x00, 0x00,
-       0x00, 0x7c, 0x40, 0x40, 0x40, 0x58, 0x64, 0x02, 0x02, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x7e, 0x42, 0x42, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1a, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
-       0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x04, 0x08, 0x10, 0x10, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x9a, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x9c, 0x80, 0x46, 0x38, 0x00, 0x00,
-       0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xf0, 0x48, 0x44, 0x44, 0x44, 0x48, 0x78, 0x44, 0x42, 0x42, 0x42, 0x44, 0xf8, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x82, 0x42, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0xf8, 0x44, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x44, 0xf8, 0x00, 0x00,
-       0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
-       0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x44, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x9e, 0x82, 0x82, 0x82, 0x42, 0x46, 0x38, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x84, 0x48, 0x30, 0x00,
-       0x00, 0xe7, 0x42, 0x44, 0x48, 0x50, 0x50, 0x60, 0x50, 0x50, 0x48, 0x44, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xf0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
-       0x00, 0xc3, 0x42, 0x66, 0x66, 0x66, 0x5a, 0x5a, 0x5a, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xc7, 0x42, 0x62, 0x62, 0x52, 0x52, 0x52, 0x4a, 0x4a, 0x4a, 0x46, 0x46, 0xe2, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0xf8, 0x44, 0x42, 0x42, 0x42, 0x44, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x92, 0x8a, 0x44, 0x3a, 0x00, 0x00,
-       0x00, 0xfc, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x82, 0x82, 0x80, 0x40, 0x38, 0x04, 0x02, 0x82, 0x82, 0xc4, 0xb8, 0x00, 0x00,
-       0x00, 0xfe, 0x92, 0x92, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x3c, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x24, 0x24, 0x24, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xee, 0x44, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0xfe, 0x84, 0x84, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x42, 0x82, 0xfe, 0x00, 0x00,
-       0x00, 0x3e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3e, 0x00,
-       0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02,
-       0x00, 0x7c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x7c, 0x00,
-       0x00, 0x10, 0x28, 0x44, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
-       0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x04, 0x3c, 0x44, 0x84, 0x84, 0x8c, 0x76, 0x00, 0x00,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x4c, 0x84, 0x84, 0x80, 0x80, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x0c, 0x04, 0x04, 0x04, 0x04, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x36, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0xfc, 0x80, 0x82, 0x42, 0x3c, 0x00, 0x00,
-       0x0e, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x04, 0x78,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
-       0x00, 0x10, 0x10, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x04, 0x04, 0x00, 0x00, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x30,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x4e, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0xe6, 0x00, 0x00,
-       0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0xdb, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x40, 0xe0,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x0e,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x86, 0x82, 0xc0, 0x38, 0x06, 0x82, 0xc2, 0xbc, 0x00, 0x00,
-       0x00, 0x00, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0e, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3b, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x44, 0x28, 0x28, 0x10, 0x28, 0x28, 0x44, 0xc6, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x10, 0x10, 0x60,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x82, 0x84, 0x08, 0x10, 0x20, 0x42, 0x82, 0xfe, 0x00, 0x00,
-       0x00, 0x06, 0x08, 0x10, 0x10, 0x10, 0x10, 0x60, 0x10, 0x10, 0x10, 0x10, 0x08, 0x06, 0x00, 0x00,
-       0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
-       0x00, 0x60, 0x10, 0x08, 0x08, 0x08, 0x08, 0x06, 0x08, 0x08, 0x08, 0x08, 0x10, 0x60, 0x00, 0x00,
-       0x00, 0x72, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x10, 0x28, 0x44, 0x82, 0xfe, 0x82, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
-};/* tinyMTの32bit版のアルゴリズムを使っています : http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/index-jp.html */
+// @randmt.c
+void randStatInit(unsigned int seed);
+void randStatNext();
+unsigned int randGetNextUInt32(void);
 
+// @screen.c
 static int iColor1[] = {
        0x000000, 0xff0000, 0x00ff00, 0xffff00,
        0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
 };
+void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r);
+void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx);
+void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx);
+int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx);
 
-void putOsaskChar(int c, struct Regs *r);
-
-void checkString(struct Regs *r, int rxx, int pxx);
-
-void checkRect(struct Regs *r, int rxx);
-
-int loadColor(struct Regs *r, int rxx);
-
+// @usetek.c
 #if (USE_TEK5 != 0)
-/* tek.cを移植するのは大変だと思ったので、断念 */
-#error "tek is not supported. edit switch.h and set USE_TEK5=0"
-//     #include "tek.c"
-//     int tek5Decomp(unsigned char *buf, unsigned char *buf1, unsigned char *tmp);
+#include "tek.h"
+int appackSub2(const UCHAR **pp, char *pif);
+int appackSub3u(const UCHAR **pp, char *pif);
+int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp);
 #endif
 
 
 #endif
-