OSDN Git Service

表示画面が更新されないバグを修正。
[heavyosecpu/HeavyOSECPU.git] / osecpu.h
1 #ifndef _HDLOAD_OSECPU
2 #define _HDLOAD_OSECPU 1
3
4 /* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/
5 #define _CRT_SECURE_NO_WARNINGS 1
6
7 //
8 // Including stdc headers
9 //
10
11 #include <stdio.h>
12 #include <string.h>
13 #include <limits.h>
14 #include <time.h>
15 #include <setjmp.h>
16 #include <stdlib.h>
17
18
19 //
20 // Compile options
21 //
22
23 // Target architecture
24 // 1 : i386
25 #define JITC_ARCNUM 0x0001
26
27 // Target operating system
28 // 1 : Windows 32bit
29 // 2 : Mac OSX 32bit
30 // 3 : blike for Linux
31
32 #ifdef _WIN32
33 #define DRV_OSNUM                       0x0001
34 #endif
35 #ifdef __APPLE__
36 #define DRV_OSNUM                       0x0002
37 #endif
38 #ifdef __linux__
39 #define DRV_OSNUM                       0x0003
40 #endif
41 //#define DRV_OSNUM 0x0002
42
43 // Decoder (syslib.ose) setting
44 // syslib.ose is necessary to work OSECPU
45 #define SYSLIB_OSE      "syslib.ose"
46
47
48 /*
49  * The 2nd signature of OSECPU Format(05 e1)
50  * It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers)
51  */
52 #define SIGN1           0xe1
53
54 #define USE_DEBUGGER    1
55 #define USE_TEK5                0       //元々は1
56
57 #define APPSIZ1         1 * 1024 * 1024 /* 1MB for now */
58 #define JITSIZ1         1 * 1024 * 1024 /* 1MB for now */
59 #define SJITSIZ1        1 * 1024 * 1024 /* 1MB for now */
60 #define SYSLIBSIZ1      1 * 1024 * 1024 /* 1MB for now */
61 #define SYSTMP0SIZ      1 * 1024 * 1024 /* 1MB for now */
62 #define SYSTMP1SIZ      2 * 1024 * 1024 /* 1MB for now */
63
64 #define KEYBUFSIZ               4096
65
66 //
67 // HOSECPU structures
68 //
69 typedef struct PtrCtrl HOSECPU_PointerControlTag;
70 struct PtrCtrl {
71         int liveSign;
72         int size, typ;
73         unsigned char *p0;
74 };
75
76 typedef struct Ptr HOSECPU_PointerRegisterEntry;
77 struct Ptr {    /* 32バイト(=256bit!) */
78         unsigned char *p;
79         int typ;
80         unsigned char *p0, *p1;
81         int liveSign;
82         HOSECPU_PointerControlTag *pls;
83         int flags, dummy;       /* read/writeなど */
84 };
85
86 typedef struct LabelTable HOSECPU_LabelListTag;
87 struct LabelTable {
88         unsigned char *p, *p1;
89         int opt;
90         /*
91          * default = -1
92          * TYP_CODE = 0
93          * T_UINT8 = 3
94          *
95          * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053
96          */
97         int typ;
98 };
99
100 typedef struct Regs HOSECPU_RuntimeEnvironment;
101 struct Regs {
102         int ireg[64];           /* 32bit整数レジスタ */
103         HOSECPU_PointerRegisterEntry preg[64];    /* ポインタレジスタ */
104     //
105         int debugInfo0, debugInfo1, dmy[2]; /* 2304 */
106         HOSECPU_PointerControlTag *ptrCtrl;            /* 2320 */
107         char winClosed, autoSleep;
108         jmp_buf *setjmpEnv;
109     
110     /* Main environment */
111     int mainArgc;           // HOSECPU起動引数の個数
112     const char **mainArgv;  // HOSECPU起動引数リスト
113     unsigned char *appBin;  // 実行するアプリのバイナリ
114     int appSize0;
115     int appSize1;
116     int executionLevel;
117     
118         /* for-junkApi */
119         //int argc;
120         //const char **argv;
121         unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
122
123         HOSECPU_LabelListTag *label;
124         int maxLabels;
125         unsigned char *jitbuf, *jitbuf1;
126         void(*errHndl)(HOSECPU_RuntimeEnvironment *);
127         char dbgr;
128         int mapDi1s[16][16];
129 };
130
131
132 //
133 // Define constant values
134 //
135
136 #define KEY_ENTER               '\n'
137 #define KEY_ESC                 27
138 #define KEY_BACKSPACE   8
139 #define KEY_TAB                 9
140 #define KEY_PAGEUP              0x1020
141 #define KEY_PAGEDWN             0x1021
142 #define KEY_END                 0x1022
143 #define KEY_HOME                0x1023
144 #define KEY_LEFT                0x1024
145 #define KEY_UP                  0x1025
146 #define KEY_RIGHT               0x1026
147 #define KEY_DOWN                0x1027
148 #define KEY_INS                 0x1028
149 #define KEY_DEL                 0x1029
150
151 //
152 // Grobal values
153 //
154
155 extern int *keybuf, keybuf_r, keybuf_w, keybuf_c;
156 extern int *vram, v_xsiz, v_ysiz;
157 //デバッグ用。プログラム中の随所で加算される変数
158 extern int di1_serial;
159
160 //
161 // Functions
162 //
163
164 // @main.c
165 void putKeybuf(int i);
166 int HeavyOSECPUMain(int argc, char **argv);
167
168 // @comlib.c
169 unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
170 // @dpndenv.c
171 // OSに依存する関数群を定義する。
172 void *mallocRWE(int bytes); // 実行権付きメモリのmalloc.
173 void drv_openWin(int x, int y, unsigned char *buf, char *winClosed);
174 void drv_flshWin(int sx, int sy, int x0, int y0);
175 void drv_sleep(int msec);
176
177 // @function.c
178 void dbgrMain(HOSECPU_RuntimeEnvironment *r);
179 const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理.
180 void randStatInit(unsigned int seed);
181 void randStatNext();
182 void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数
183
184 // @jitc.c
185 /* JITCのフラグ群 */
186 #define JITC_LV_SLOWEST         0       /* デバッグ支援は何でもやる */
187 #define JITC_LV_SLOWER          1       /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
188 #define JITC_LV_SAFE            2       /* とにかく止まる、場所は不明、テストは必要最小限 */
189 #define JITC_LV_FASTER          4       /* 情報は生成するがチェックをしない */
190 #define JITC_LV_FASTEST         5       /* 情報すら生成しない */
191 #define JITC_PHASE1                     0x0001
192 #define JITC_SKIPCHECK          0x0002  /* セキュリティチェックを省略する(高速危険モード) */
193 #define JITC_NOSTARTUP          0x0004
194 #define JITC_MAXLABELS          4096
195 #define PTRCTRLSIZ                      4096
196 int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);
197 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);
198 unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
199 unsigned char *jitCompInit(unsigned char *dst);
200 void errorHandler(HOSECPU_RuntimeEnvironment *r);
201
202 // @screen.c
203 static int iColor1[] = {
204         0x000000, 0xff0000, 0x00ff00, 0xffff00,
205         0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
206 };
207 void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r);
208 void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx);
209 void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx);
210 int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx);
211
212 #if (USE_TEK5 != 0)
213 /* tek.cを移植するのは大変だと思ったので、断念 */
214 #error "tek is not supported. edit switch.h and set USE_TEK5=0"
215 //      #include "tek.c"
216 //      int tek5Decomp(unsigned char *buf, unsigned char *buf1, unsigned char *tmp);
217 #endif
218
219
220 #endif
221