コミットメタ情報

リビジョン8ede1653bdaddfceae402f8f86b29e1ef490d205 (tree)
日時2014-03-10 00:18:50
作者ttwilb <ttwilb@user...>
コミッターttwilb

ログメッセージ

Deleted sources

変更サマリ

  • modified: .gitignore (diff)
  • modified: HeavyOSECPU.sln (diff)
  • delete: HeavyOSECPU/HeavyOSECPU.vcxproj
  • delete: HeavyOSECPU/HeavyOSECPU.vcxproj.filters
  • delete: HeavyOSECPU/comlib.c
  • delete: HeavyOSECPU/comlib.h
  • delete: HeavyOSECPU/dependent.c
  • delete: HeavyOSECPU/dependent.h
  • delete: HeavyOSECPU/function.c
  • delete: HeavyOSECPU/function.h
  • delete: HeavyOSECPU/jitc.c
  • delete: HeavyOSECPU/jitc.h
  • delete: HeavyOSECPU/main.c
  • delete: HeavyOSECPU/osecpu.h
  • delete: HeavyOSECPU/screen.c
  • delete: HeavyOSECPU/screen.h
  • delete: HeavyOSECPU/switch.h

差分

--- a/.gitignore
+++ b/.gitignore
@@ -154,3 +154,6 @@ $RECYCLE.BIN/
154154
155155 # Mac desktop service store files
156156 .DS_Store
157+/HeavyOSECPU.vcxproj
158+/HeavyOSECPU.sln
159+/HeavyOSECPU.vcxproj.filters
--- a/HeavyOSECPU.sln
+++ b/HeavyOSECPU.sln
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
33 # Visual Studio 2013
44 VisualStudioVersion = 12.0.30110.0
55 MinimumVisualStudioVersion = 10.0.40219.1
6-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HeavyOSECPU", "HeavyOSECPU\HeavyOSECPU.vcxproj", "{300C89E4-CD40-4017-B8A5-1B01C5B6C3B0}"
6+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HeavyOSECPU", "HeavyOSECPU.vcxproj", "{300C89E4-CD40-4017-B8A5-1B01C5B6C3B0}"
77 EndProject
88 Global
99 GlobalSection(SolutionConfigurationPlatforms) = preSolution
--- a/HeavyOSECPU/HeavyOSECPU.vcxproj
+++ /dev/null
@@ -1,98 +0,0 @@
1-<?xml version="1.0" encoding="utf-8"?>
2-<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3- <ItemGroup Label="ProjectConfigurations">
4- <ProjectConfiguration Include="Debug|Win32">
5- <Configuration>Debug</Configuration>
6- <Platform>Win32</Platform>
7- </ProjectConfiguration>
8- <ProjectConfiguration Include="Release|Win32">
9- <Configuration>Release</Configuration>
10- <Platform>Win32</Platform>
11- </ProjectConfiguration>
12- </ItemGroup>
13- <PropertyGroup Label="Globals">
14- <ProjectGuid>{300C89E4-CD40-4017-B8A5-1B01C5B6C3B0}</ProjectGuid>
15- <Keyword>Win32Proj</Keyword>
16- <RootNamespace>HeavyOSECPU</RootNamespace>
17- </PropertyGroup>
18- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20- <ConfigurationType>Application</ConfigurationType>
21- <UseDebugLibraries>true</UseDebugLibraries>
22- <PlatformToolset>v120</PlatformToolset>
23- <CharacterSet>Unicode</CharacterSet>
24- </PropertyGroup>
25- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26- <ConfigurationType>Application</ConfigurationType>
27- <UseDebugLibraries>false</UseDebugLibraries>
28- <PlatformToolset>v120</PlatformToolset>
29- <WholeProgramOptimization>true</WholeProgramOptimization>
30- <CharacterSet>Unicode</CharacterSet>
31- </PropertyGroup>
32- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33- <ImportGroup Label="ExtensionSettings">
34- </ImportGroup>
35- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37- </ImportGroup>
38- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
39- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
40- </ImportGroup>
41- <PropertyGroup Label="UserMacros" />
42- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
43- <LinkIncremental>true</LinkIncremental>
44- </PropertyGroup>
45- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
46- <LinkIncremental>false</LinkIncremental>
47- </PropertyGroup>
48- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
49- <ClCompile>
50- <PrecompiledHeader>
51- </PrecompiledHeader>
52- <WarningLevel>Level3</WarningLevel>
53- <Optimization>Disabled</Optimization>
54- <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
55- </ClCompile>
56- <Link>
57- <SubSystem>Console</SubSystem>
58- <GenerateDebugInformation>true</GenerateDebugInformation>
59- </Link>
60- </ItemDefinitionGroup>
61- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62- <ClCompile>
63- <WarningLevel>Level3</WarningLevel>
64- <PrecompiledHeader>
65- </PrecompiledHeader>
66- <Optimization>MaxSpeed</Optimization>
67- <FunctionLevelLinking>true</FunctionLevelLinking>
68- <IntrinsicFunctions>true</IntrinsicFunctions>
69- <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
70- </ClCompile>
71- <Link>
72- <SubSystem>Console</SubSystem>
73- <GenerateDebugInformation>true</GenerateDebugInformation>
74- <EnableCOMDATFolding>true</EnableCOMDATFolding>
75- <OptimizeReferences>true</OptimizeReferences>
76- </Link>
77- </ItemDefinitionGroup>
78- <ItemGroup>
79- <ClInclude Include="comlib.h" />
80- <ClInclude Include="dependent.h" />
81- <ClInclude Include="function.h" />
82- <ClInclude Include="jitc.h" />
83- <ClInclude Include="osecpu.h" />
84- <ClInclude Include="screen.h" />
85- <ClInclude Include="switch.h" />
86- </ItemGroup>
87- <ItemGroup>
88- <ClCompile Include="comlib.c" />
89- <ClCompile Include="dependent.c" />
90- <ClCompile Include="function.c" />
91- <ClCompile Include="jitc.c" />
92- <ClCompile Include="main.c" />
93- <ClCompile Include="screen.c" />
94- </ItemGroup>
95- <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
96- <ImportGroup Label="ExtensionTargets">
97- </ImportGroup>
98-</Project>
\ No newline at end of file
--- a/HeavyOSECPU/HeavyOSECPU.vcxproj.filters
+++ /dev/null
@@ -1,60 +0,0 @@
1-<?xml version="1.0" encoding="utf-8"?>
2-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3- <ItemGroup>
4- <Filter Include="ソース ファイル">
5- <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6- <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7- </Filter>
8- <Filter Include="ヘッダー ファイル">
9- <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10- <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11- </Filter>
12- <Filter Include="リソース ファイル">
13- <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14- <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15- </Filter>
16- </ItemGroup>
17- <ItemGroup>
18- <ClInclude Include="osecpu.h">
19- <Filter>ヘッダー ファイル</Filter>
20- </ClInclude>
21- <ClInclude Include="switch.h">
22- <Filter>ヘッダー ファイル</Filter>
23- </ClInclude>
24- <ClInclude Include="dependent.h">
25- <Filter>ヘッダー ファイル</Filter>
26- </ClInclude>
27- <ClInclude Include="function.h">
28- <Filter>ヘッダー ファイル</Filter>
29- </ClInclude>
30- <ClInclude Include="jitc.h">
31- <Filter>ヘッダー ファイル</Filter>
32- </ClInclude>
33- <ClInclude Include="comlib.h">
34- <Filter>ヘッダー ファイル</Filter>
35- </ClInclude>
36- <ClInclude Include="screen.h">
37- <Filter>ヘッダー ファイル</Filter>
38- </ClInclude>
39- </ItemGroup>
40- <ItemGroup>
41- <ClCompile Include="main.c">
42- <Filter>ソース ファイル</Filter>
43- </ClCompile>
44- <ClCompile Include="dependent.c">
45- <Filter>ソース ファイル</Filter>
46- </ClCompile>
47- <ClCompile Include="jitc.c">
48- <Filter>ソース ファイル</Filter>
49- </ClCompile>
50- <ClCompile Include="function.c">
51- <Filter>ソース ファイル</Filter>
52- </ClCompile>
53- <ClCompile Include="screen.c">
54- <Filter>ソース ファイル</Filter>
55- </ClCompile>
56- <ClCompile Include="comlib.c">
57- <Filter>ソース ファイル</Filter>
58- </ClCompile>
59- </ItemGroup>
60-</Project>
\ No newline at end of file
--- a/HeavyOSECPU/comlib.c
+++ /dev/null
@@ -1,64 +0,0 @@
1-#include "osecpu.h"
2-
3-struct ComLib_Str {
4- const unsigned char *p;
5- int bitBuf, bitBufLen;
6- int tmp;
7-};
8-
9-int ComLib_getBit(struct ComLib_Str *s)
10-{
11- if (s->bitBufLen == 0) {
12- s->bitBuf = s->p[0] | s->p[1] << 8;
13- s->p += 2;
14- s->bitBufLen |= 16;
15- }
16- s->bitBufLen--;
17- return (s->bitBuf >> s->bitBufLen) & 1;
18-}
19-
20-int ComLib_getTmpBit(struct ComLib_Str *s)
21-{
22- s->tmp = (s->tmp << 1 | ComLib_getBit(s)) & 0xffff;
23- return ComLib_getBit(s);
24-}
25-
26-unsigned char *ComLib_main(const unsigned char *p, unsigned char *q)
27-{
28- struct ComLib_Str s;
29- int i, dis;
30- dis |= -1;
31- s.p = p;
32- s.bitBufLen &= 0;
33- goto l1;
34-l0:
35- *q++ = *s.p++;
36-l1:
37- i = ComLib_getBit(&s);
38- if (i != 0) goto l0;
39- s.tmp = 1;
40- do {
41- i = ComLib_getTmpBit(&s);
42- if (s.tmp == 0) goto fin;
43- } while (i == 0);
44- if (s.tmp >= 3)
45- dis = ~((s.tmp - 3) << 8 | *s.p++);
46- s.tmp &= 0;
47- i = ComLib_getTmpBit(&s);
48- s.tmp = s.tmp << 1 | i;
49- if (s.tmp == 0) {
50- s.tmp |= 1;
51- do {
52- i = ComLib_getTmpBit(&s);
53- } while (i == 0);
54- s.tmp += 2;
55- }
56- s.tmp++;
57- if (dis < -0xd00) s.tmp++;
58- for (i = 0; i < s.tmp; i++)
59- q[i] = q[i + dis];
60- q += s.tmp;
61- goto l1;
62-fin:
63- return q;
64-}
\ No newline at end of file
--- a/HeavyOSECPU/comlib.h
+++ /dev/null
@@ -1,8 +0,0 @@
1-#ifndef _HDLOAD_COMLIB
2-#define _HDLOAD_COMLIB 1
3-
4-/* ComLib関係 */
5-
6-unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
7-
8-#endif
\ No newline at end of file
--- a/HeavyOSECPU/dependent.c
+++ /dev/null
@@ -1,278 +0,0 @@
1-#include "osecpu.h"
2-#include <windows.h>
3-
4-#if (DRV_OSNUM == 0x0002)
5-
6-#error "Your OS is not supported."
7-
8-#elif (DRV_OSNUM == 0x0003)
9-
10-#error "Your OS is not supported."
11-
12-#elif (DRV_OSNUM == 0x0001)
13-
14-#define TIMER_ID 1
15-#define TIMER_INTERVAL 10
16-
17-struct BLD_WORK {
18- HINSTANCE hi;
19- HWND hw;
20- BITMAPINFO bmi;
21- int tmcount1, tmcount2, flags, smp; /* bit0: 終了 */
22- HANDLE mtx;
23- char *winClosed;
24-};
25-
26-struct BLD_WORK bld_work;
27-
28-struct BL_WIN {
29- int xsiz, ysiz, *buf;
30-};
31-
32-struct BL_WORK {
33- struct BL_WIN win;
34- jmp_buf jb;
35- int csiz_x, csiz_y, cx, cy, col0, col1, tabsiz, slctwin;
36- int tmcount, tmcount0, mod, rand_seed;
37- int *cbuf;
38- unsigned char *ftyp;
39- unsigned char **fptn;
40- int *ccol, *cbak;
41- int *kbuf, kbuf_rp, kbuf_wp, kbuf_c;
42-};
43-
44-struct BL_WORK bl_work;
45-
46-#define BL_SIZ_KBUF 8192
47-
48-#define BL_WAITKEYF 0x00000001
49-#define BL_WAITKEYNF 0x00000002
50-#define BL_WAITKEY 0x00000003
51-#define BL_GETKEY 0x00000004
52-#define BL_CLEARREP 0x00000008
53-#define BL_DELFFF 0x00000010
54-
55-#define BL_KEYMODE 0x00000000 // 作りかけ, make/remake/breakが見えるかどうか
56-
57-#define w bl_work
58-#define dw bld_work
59-
60-void bld_openWin(int x, int y, char *winClosed);
61-void bld_flshWin(int sx, int sy, int x0, int y0);
62-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp);
63-void bl_cls();
64-int bl_iCol(int i);
65-void bl_readyWin(int n);
66-
67-static HANDLE threadhandle;
68-
69-void *mallocRWE(int bytes)
70-{
71- void *p = malloc(bytes);
72- DWORD dmy;
73- VirtualProtect(p, bytes, PAGE_EXECUTE_READWRITE, &dmy);
74- return p;
75-}
76-
77-static int winthread(void *dmy)
78-{
79- WNDCLASSEX wc;
80- RECT r;
81- int i, x, y;
82- MSG msg;
83-
84- x = dw.bmi.bmiHeader.biWidth;
85- y = -dw.bmi.bmiHeader.biHeight;
86-
87- wc.cbSize = sizeof (WNDCLASSEX);
88- wc.style = CS_HREDRAW | CS_VREDRAW;
89- wc.lpfnWndProc = WndProc;
90- wc.cbClsExtra = 0;
91- wc.cbWndExtra = 0;
92- wc.hInstance = dw.hi;
93- wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
94- IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
95- wc.hIconSm = wc.hIcon;
96- wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
97- IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
98- wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
99- wc.lpszMenuName = NULL;
100- wc.lpszClassName = L"WinClass";
101- if (RegisterClassEx(&wc) == 0)
102- return 1;
103- r.left = 0;
104- r.top = 0;
105- r.right = x;
106- r.bottom = y;
107- AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
108- x = r.right - r.left;
109- y = r.bottom - r.top;
110-
111- char *t = "osecpu";
112-
113- dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,
114- CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
115- if (dw.hw == NULL)
116- return 1;
117- ShowWindow(dw.hw, SW_SHOW);
118- UpdateWindow(dw.hw);
119- SetTimer(dw.hw, TIMER_ID, TIMER_INTERVAL, NULL);
120- SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);
121- SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);
122- dw.flags |= 2 | 4;
123-
124- for (;;) {
125- i = GetMessage(&msg, NULL, 0, 0);
126- if (i == 0 || i == -1) /* エラーもしくは終了メッセージ */
127- break;
128- /* そのほかはとりあえずデフォルト処理で */
129- TranslateMessage(&msg);
130- DispatchMessage(&msg);
131- }
132- // PostQuitMessage(0);
133- dw.flags |= 1; /* 終了, bld_waitNF()が見つける */
134- if (dw.winClosed != NULL)
135- *dw.winClosed = 1;
136- return 0;
137-}
138-
139-void bld_openWin(int sx, int sy, char *winClosed)
140-{
141- static int i;
142-
143- dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
144- dw.bmi.bmiHeader.biWidth = sx;
145- dw.bmi.bmiHeader.biHeight = -sy;
146- dw.bmi.bmiHeader.biPlanes = 1;
147- dw.bmi.bmiHeader.biBitCount = 32;
148- dw.bmi.bmiHeader.biCompression = BI_RGB;
149- dw.winClosed = winClosed;
150-
151- threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
152-
153- return;
154-}
155-
156-void drv_flshWin(int sx, int sy, int x0, int y0)
157-{
158- InvalidateRect(dw.hw, NULL, FALSE);
159- UpdateWindow(dw.hw);
160- return;
161-}
162-
163-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
164-{
165- int i, j;
166- if (msg == WM_PAINT) {
167- PAINTSTRUCT ps;
168- HDC hdc = BeginPaint(dw.hw, &ps);
169- SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,
170- 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
171- EndPaint(dw.hw, &ps);
172- }
173- if (msg == WM_DESTROY) {
174- PostQuitMessage(0);
175- return 0;
176- }
177- if (msg == WM_TIMER && wp == TIMER_ID) {
178- w.tmcount += TIMER_INTERVAL;
179- return 0;
180- }
181- if (msg == WM_TIMER && wp == TIMER_ID + 1) {
182- dw.tmcount1 += TIMER_INTERVAL * 10;
183- w.tmcount = dw.tmcount1;
184- return 0;
185- }
186- if (msg == WM_TIMER && wp == TIMER_ID + 2) {
187- dw.tmcount2 += TIMER_INTERVAL * 100;
188- w.tmcount = dw.tmcount1 = dw.tmcount2;
189- return 0;
190- }
191- if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
192- i = -1;
193-
194- if (wp == VK_RETURN) i = KEY_ENTER;
195- if (wp == VK_ESCAPE) i = KEY_ESC;
196- if (wp == VK_BACK) i = KEY_BACKSPACE;
197- if (wp == VK_TAB) i = KEY_TAB;
198- if (wp == VK_PRIOR) i = KEY_PAGEUP;
199- if (wp == VK_NEXT) i = KEY_PAGEDWN;
200- if (wp == VK_END) i = KEY_END;
201- if (wp == VK_HOME) i = KEY_HOME;
202- if (wp == VK_LEFT) i = KEY_LEFT;
203- if (wp == VK_RIGHT) i = KEY_RIGHT;
204- if (wp == VK_UP) i = KEY_UP;
205- if (wp == VK_DOWN) i = KEY_DOWN;
206- if (wp == VK_INSERT) i = KEY_INS;
207- if (wp == VK_DELETE) i = KEY_DEL;
208- j &= 0;
209- if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
210- if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
211- if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
212- if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
213- if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
214- if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
215- if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
216- if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
217- if (j != 0) {
218- if ('A' <= wp && wp <= 'Z') i = wp;
219- }
220- if (i != -1) {
221- putKeybuf(i | j);
222- // bl_putKeyB(1, &i);
223- return 0;
224- }
225- }
226- if (msg == WM_KEYUP) {
227- i = 0xfff;
228- // bl_putKeyB(1, &i);
229- }
230- if (msg == WM_CHAR) {
231- i = 0;
232- if (' ' <= wp && wp <= 0x7e) {
233- i = wp;
234- j &= 0;
235- if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
236- if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
237- if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
238- if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
239- if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
240- if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
241- if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
242- if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
243- if (('A' <= wp && wp <= 'Z') || ('a' <= wp && wp <= 'z')) {
244- if (j != 0) {
245- i |= j;
246- i &= ~0x20;
247- }
248- }
249- putKeybuf(i);
250- // bl_putKeyB(1, &i);
251- return 0;
252- }
253- }
254- return DefWindowProc(hw, msg, wp, lp);
255-}
256-
257-void drv_openWin(int sx, int sy, UCHAR *buf, char *winClosed)
258-{
259- w.win.buf = (int *)buf;
260- w.win.xsiz = sx;
261- w.win.ysiz = sy;
262- bld_openWin(sx, sy, winClosed);
263- return;
264-}
265-
266-void drv_sleep(int msec)
267-{
268- Sleep(msec);
269- // MsgWaitForMultipleObjects(1, &threadhandle, FALSE, msec, QS_ALLINPUT);
270- /* 勉強不足でまだ書き方が分かりません! */
271- return;
272-}
273-
274-#else
275-
276-#error "Illegal OS type. Edit switch.h and look at DRV_OSNUM"
277-
278-#endif
\ No newline at end of file
--- a/HeavyOSECPU/dependent.h
+++ /dev/null
@@ -1,11 +0,0 @@
1-#ifndef _HDLOAD_DEPENDENT
2-#define _HDLOAD_DEPENDENT
3-
4-/* OSに依存する関数群を定義する。 */
5-
6-void *mallocRWE(int bytes); // 実行権付きメモリのmalloc.
7-void drv_openWin(int x, int y, unsigned char *buf, char *winClosed);
8-void drv_flshWin(int sx, int sy, int x0, int y0);
9-void drv_sleep(int msec);
10-
11-#endif
\ No newline at end of file
--- a/HeavyOSECPU/function.c
+++ /dev/null
@@ -1,598 +0,0 @@
1-#include "osecpu.h"
2-
3-static struct {
4- unsigned stat[4], mat1, mat2, tmat;
5-} randStat;
6-
7-void randStatNext()
8-{
9- unsigned x, y;
10- x = (randStat.stat[0] & 0x7fffffff) ^ randStat.stat[1] ^ randStat.stat[2];
11- y = randStat.stat[3];
12- x ^= x << 1;
13- y ^= (y >> 1) ^ x;
14- randStat.stat[1] = randStat.stat[2] ^ (-((int)(y & 1)) & randStat.mat1);
15- randStat.stat[2] = x ^ (y << 10) ^ (-((int)(y & 1)) & randStat.mat2);
16- randStat.stat[3] = y;
17- return;
18-}
19-
20-void randStatInit(unsigned seed)
21-{
22- int i;
23- randStat.stat[0] = seed;
24- randStat.stat[1] = randStat.mat1 = 0x8f7011ee;
25- randStat.stat[2] = randStat.mat2 = 0xfc78ff1f;
26- randStat.stat[3] = randStat.tmat = 0x3793fdff;
27- for (i = 1; i < 8; i++)
28- randStat.stat[i & 3] ^= i + ((unsigned)1812433253) * (randStat.stat[(i - 1) & 3] ^ (randStat.stat[(i - 1) & 3] >> 30));
29- for (i = 0; i < 8; i++)
30- randStatNext();
31- return;
32-}
33-
34-const unsigned char *searchArg(int argc, const unsigned char **argv, const unsigned char *tag, int i)
35-{
36- int j, l;
37- const unsigned char *r = NULL;
38- if (tag != NULL) {
39- l = strlen(tag);
40- for (j = 1; j < argc; j++) {
41- if (strncmp(argv[j], tag, l) == 0) {
42- r = argv[j] + l;
43- if (i == 0) break;
44- i--;
45- }
46- }
47- }
48- else {
49- for (j = 1; j < argc; j++) {
50- if (strchr(argv[j], ':') == NULL) {
51- r = argv[j];
52- if (i == 0) break;
53- i--;
54- }
55- }
56- }
57- if (i != 0) r = NULL;
58- return r;
59-}
60-
61-void devFunc0001(int len, unsigned char *puc, struct Regs *r)
62-{
63- while (len > 0) {
64- putOsaskChar(*puc++, r);
65- len--;
66- }
67- return;
68-}
69-
70-void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned char *puc, struct Regs *r)
71-{
72- if (sy == 0) sy = sx;
73- int xx = x + sx * 8;
74- int yy = y + sy * 16;
75- if (xx <= 0 || xx > v_xsiz || yy <= 0 || yy > v_ysiz)
76- (*(r->errHndl))(r);
77- if (x < 0 || x >= v_xsiz || y < 0 || y >= v_ysiz)
78- (*(r->errHndl))(r);
79- int i, ddx, ddy, j, ch, dx, dy;
80-
81- if ((mod & 3) == 0 && sx == 1 && sy == 1) {
82- // メジャーケースを高速化.
83- for (i = 0; i < len; i++) {
84- ch = puc[i];
85- if (0x10 <= ch && ch <= 0x1f)
86- ch = "0123456789ABCDEF"[ch & 0x0f];
87- for (dy = 0; dy < 16; dy++) {
88- j = fontdata[(ch - ' ') * 16 + dy];
89- for (dx = 0; dx < 8; dx++) {
90- if ((j & (0x80 >> dx)) != 0) vram[(x + dx) + (y + dy) * v_xsiz] = c;
91- }
92- }
93- x += 8;
94- }
95- return;
96- }
97- for (i = 0; i < len; i++) {
98- ch = puc[i];
99- if (0x10 <= ch && ch <= 0x1f)
100- ch = "0123456789ABCDEF"[ch & 0x0f];
101- for (dy = 0; dy < 16; dy++) {
102- j = fontdata[(ch - ' ') * 16 + dy];
103- for (ddy = 0; ddy < sy; ddy++) {
104- for (dx = 0; dx < 8; dx++) {
105- if ((j & (0x80 >> dx)) != 0) {
106- for (ddx = 0; ddx < sx; ddx++) {
107- if ((mod & 3) == 0) vram[x + y * v_xsiz] = c;
108- if ((mod & 3) == 1) vram[x + y * v_xsiz] |= c;
109- if ((mod & 3) == 2) vram[x + y * v_xsiz] ^= c;
110- if ((mod & 3) == 3) vram[x + y * v_xsiz] &= c;
111- x++;
112- }
113- }
114- else
115- x += sx;
116- }
117- x -= sx * 8;
118- y++;
119- }
120- }
121- x += sx * 8;
122- y -= sy * 16;
123- }
124- return;
125-}
126-
127-void devFunc0004(int mod, int x0, int y0, int x1, int y1, int c)
128-{
129- int x, y;
130- if (mod == 0) {
131- for (y = y0; y <= y1; y++) {
132- for (x = x0; x <= x1; x++) {
133- vram[x + y * v_xsiz] = c;
134- }
135- }
136- }
137- else {
138- for (y = y0; y <= y1; y++) {
139- for (x = x0; x <= x1; x++) {
140- if (mod == 1) vram[x + y * v_xsiz] |= c;
141- if (mod == 2) vram[x + y * v_xsiz] ^= c;
142- if (mod == 3) vram[x + y * v_xsiz] &= c;
143- }
144- }
145- }
146- return;
147-}
148-
149-int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int qlen, int *q, struct Regs *r)
150-{
151- int i = 0, base, j, k;
152- char sign;
153- while (plen > 0) {
154- if (i >= buflen)
155- (*(r->errHndl))(r);
156- if (*p != 0x01) {
157- buf[i++] = *p++;
158- plen--;
159- continue;
160- }
161- p++;
162- plen--;
163- if (qlen < 4)
164- (*(r->errHndl))(r);
165- base = q[0];
166- sign = 0;
167- if (base == 0) base = 16;
168-#if (REVISION == 1)
169- if (base == -3) base = 10;
170-#endif
171- if (base == -1) base = 10;
172- if (base < 0 || base > 16)
173- (*(r->errHndl))(r);
174- if (q[1] + i > buflen)
175- (*(r->errHndl))(r);
176- j = q[3];
177- if ((q[2] & 4) == 0) {
178- // jは符号付き整数.
179- if ((q[2] & 8) != 0 && j > 0) sign = '+';
180- if (j < 0) { sign = '-'; j *= -1; }
181- }
182- else {
183- // jは符号無し整数.
184- if ((q[2] & 8) != 0 && j != 0) sign = '+';
185- }
186- for (k = q[1] - 1; k >= 0; k--) {
187- buf[i + k] = (j % base) + 0x10;
188- j = ((unsigned)j) / base;
189- }
190- k = 0;
191- if ((q[2] & 2) == 0 && j == 0) {
192- for (k = 0; k < q[1] - 1; k++) {
193- if (buf[i + k] != 0x10) break;
194- buf[i + k] = ' ';
195- }
196- }
197- if (sign != 0) {
198- if (k > 0) k--;
199- buf[i + k] = sign;
200- }
201- if ((q[2] & 1) != 0 && buf[i] == ' ') {
202- for (j = 0; k < q[1]; k++, j++)
203- buf[i + j] = buf[i + k];
204- i += j;
205- }
206- else
207- i += q[1];
208- qlen -= 4;
209- q += 4;
210- }
211- return i;
212-}
213-
214-void devFunc(struct Regs *r)
215-{
216- FILE *fp;
217- r = (struct Regs *) (((char *)r) - 128); /* サイズを節約するためにEBPを128バイトずらしているのを元に戻す */
218- int i, c;
219- int x, y, len, dx, dy;
220- unsigned char *puc;
221- unsigned char pucbuf[256];
222- if (r->winClosed != 0)
223- longjmp(*(r->setjmpEnv), 1);
224- if (0xff44 <= r->ireg[0x30] && r->ireg[0x30] <= 0xff48) {
225- if (vram == NULL) {
226- v_xsiz = 640;
227- v_ysiz = 480;
228- vram = malloc(640 * 480 * 4);
229- drv_openWin(640, 480, (void *)vram, &r->winClosed);
230- r->autoSleep = 1;
231- for (i = 640 * 480 - 1; i >= 0; i--)
232- vram[i] = 0;
233- }
234- }
235-
236- switch (r->ireg[0x30]) {
237- case 0xff00:
238- printf("R31=%d(dec)\n", r->ireg[0x31]);
239- break;
240-
241- case 0xff01:
242- /* return: R30, P31 */
243- if (r->buf0 == NULL)
244- r->buf0 = malloc(1024 * 1024);
245- if (r->argc <= r->ireg[0x31]) {
246- fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
247- exit(1);
248- }
249- fp = fopen(r->argv[r->ireg[0x31]], "rb");
250- if (fp == NULL) {
251- fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->argv[r->ireg[0x31]]);
252- exit(1);
253- }
254- i = fread(r->buf0, 1, 1024 * 1024 - 4, fp);
255- if (i >= 1024 * 1024 - 4 || i < 0) {
256- fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->argv[r->ireg[0x31]]);
257- exit(1);
258- }
259- fclose(fp);
260- r->preg[0x31].p = r->buf0;
261- r->preg[0x31].p0 = r->buf0;
262- r->preg[0x31].p1 = r->buf0 + i;
263- r->preg[0x31].typ = 3; // T_UINT8
264- r->ireg[0x30] = i;
265- break;
266-
267- case 0xff02:
268- /* return: none */
269- if (r->argc <= r->ireg[0x31]) {
270- fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
271- exit(1);
272- }
273- fp = fopen(r->argv[r->ireg[0x31]], "wb");
274- if (fp == NULL) {
275- fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->argv[r->ireg[0x31]]);
276- exit(1);
277- }
278- if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
279- fprintf(stderr, "devFunc: error: R30=ff02: fwrite error: R02=%08X\n", r->ireg[0x32]);
280- exit(1);
281- }
282- fwrite(r->preg[0x31].p, 1, r->ireg[0x32], fp);
283- fclose(fp);
284- break;
285-
286- case 0xff03:
287- /* return: P31 */
288- if (r->buf1 == NULL)
289- r->buf1 = malloc(1024 * 1024);
290- r->preg[0x31].p = r->buf1;
291- r->preg[0x31].p0 = r->buf1;
292- r->preg[0x31].p1 = r->buf1 + 1024 * 1024;
293- break;
294-
295- case 0xff04:
296- printf("P31.(p-p0)=%d(dec)\n", r->preg[0x31].p - r->preg[0x31].p0);
297- break;
298-
299- case 0xff05:
300- fwrite(r->preg[0x31].p, 1, r->ireg[0x31], stdout);
301- break;
302-
303- case 0xff06:
304- // R31はリターンコード.
305- // これを反映すべきだが、現状は手抜きでいつも正常終了.
306- longjmp(*(r->setjmpEnv), 1);
307- break;
308-
309- case 0xff07:
310- // マシになった文字列表示.OSASK文字列に対応.offにすれば通常の文字列処理もできる.現状はonのみサポート.
311- checkString(r, 0x31, 0x31);
312- devFunc0001(r->ireg[0x31], r->preg[0x31].p, r);
313- break;
314-
315- case 0xff08:
316- // JITC on JITC
317- // R31: 言語(back-end, front-end, ...
318- // R32: level
319- // R33: debugInfo1
320- checkString(r, 0x34, 0x31);
321- if (r->ireg[0x33] < 0 || r->ireg[0x33] > 15 || r->debugInfo1 > 15)
322- (*(r->errHndl))(r);
323- for (i = 0; i < r->maxLabels; i++)
324- r->label[i].opt = 0;
325- puc = r->preg[0x31].p;
326- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
327- if (i == 0) {
328- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + JITC_PHASE1 + 0);
329- if (i >= 0) {
330- r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
331- di1_serial++;
332- r->ireg[0x30] = 0;
333- r->preg[0x31].p = r->jitbuf;
334- r->preg[0x31].typ = 0; // TYP_CODE
335- r->preg[0x31].p0 = r->jitbuf;
336- r->preg[0x31].p1 = r->jitbuf + 1;
337- //int j; for (j = 0; j < i; j++) printf("%02X ", r->jitbuf[j]); putchar('\n');
338- r->jitbuf += i;
339- static unsigned char ff08_ret[3] = { 0x1e, 0x3f, 0x30 };
340- i = jitCompiler(r->jitbuf, r->jitbuf1, ff08_ret, ff08_ret + 3, puc, r->label, r->maxLabels, r->ireg[0x32], -1, JITC_NOSTARTUP + JITC_PHASE1 + 0);
341- r->jitbuf += i;
342- break;
343- }
344- }
345- r->ireg[0x30] = -1;
346- break;
347-
348- case 0xff09:
349- // たぶんbit7を使ったテキストはうまく処理できない(これはもはや仕様にしても問題ないかも).
350- checkString(r, 0x31, 0x31);
351- len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x31], r->preg[0x31].p, r->ireg[0x32], (int *)r->preg[0x32].p, r);
352- devFunc0001(len, pucbuf, r);
353- break;
354-
355- case 0xff40:
356- /* R31とR32でサイズを指定 */
357- v_xsiz = r->ireg[0x31];
358- v_ysiz = r->ireg[0x32];
359- if (v_xsiz <= 0 || v_ysiz <= 0)
360- (*(r->errHndl))(r);
361- r->preg[0x31].p = (void *)(vram = malloc(v_xsiz * v_ysiz * 4));
362- r->preg[0x31].p0 = r->preg[0x31].p;
363- r->preg[0x31].p1 = r->preg[0x31].p + v_xsiz * v_ysiz * 4;
364- drv_openWin(r->ireg[0x31], r->ireg[0x32], r->preg[0x31].p, &r->winClosed);
365- // drv_flshWin(r->ireg[1], r->ireg[2], 0, 0);
366- r->autoSleep = 1;
367- for (i = v_xsiz * v_ysiz - 1; i >= 0; i--)
368- vram[i] = 0;
369- break;
370-
371- case 0xff41:
372- /* R31とR32でサイズを指定、R33とR34でx0,y0指定 */
373- if (r->ireg[0x31] == -1) { r->ireg[0x31] = v_xsiz; r->ireg[0x33] &= 0; }
374- if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_ysiz; r->ireg[0x34] &= 0; }
375- checkRect(r, 0x31);
376- drv_flshWin(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34]);
377- break;
378-
379- case 0xff42:
380- if (r->ireg[0x32] == -1) {
381- r->autoSleep = 1;
382- longjmp(*(r->setjmpEnv), 1);
383- }
384- if (r->ireg[0x32] < 0)
385- (*(r->errHndl))(r);
386- r->autoSleep = 0;
387- if ((r->ireg[0x31] & 1) == 0 && vram != NULL)
388- drv_flshWin(v_xsiz, v_ysiz, 0, 0);
389- for (;;) {
390- if (r->winClosed != 0)
391- longjmp(*(r->setjmpEnv), 1);
392- drv_sleep(r->ireg[0x32]);
393- if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0) continue;
394- break;
395- }
396- break;
397-
398- case 0xff43:
399- // 1:peek
400- // 2:stdin
401- // 4,8: ソース指定.
402- // 16: shift, lock系を有効化.
403- // 32: 左右のshift系を区別する.
404- if (r->ireg[0x31] == 2) { // なぜ3にしなかったのか...
405- r->ireg[0x30] = fgetc(stdin);
406- if (r->ireg[0x30] == EOF)
407- r->ireg[0x30] = -1;
408- break;
409- }
410- r->ireg[0x30] |= -1;
411- if (keybuf_c > 0) {
412- r->ireg[0x30] = keybuf[keybuf_r];
413- if ((r->ireg[0x31] & 16) == 0) r->ireg[0x30] &= 0x3e3effff;
414- if ((r->ireg[0x31] & 32) == 0) r->ireg[0x30] |= (r->ireg[0x30] >> 8) & 0xff0000;
415- if ((r->ireg[0x31] & 1) != 0) {
416- keybuf_c--;
417- keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
418- }
419- }
420- r->ireg[0x32] = r->ireg[0x33] = 0;
421- if (r->ireg[0x30] == 4132) r->ireg[0x32]--;
422- if (r->ireg[0x30] == 4133) r->ireg[0x33]--;
423- if (r->ireg[0x30] == 4134) r->ireg[0x32]++;
424- if (r->ireg[0x30] == 4135) r->ireg[0x33]++;
425- break;
426-
427- case 0xff44:
428- c = loadColor(r, 0x34);
429- if (r->ireg[0x32] < 0 || r->ireg[0x32] >= v_xsiz || r->ireg[0x33] < 0 || r->ireg[0x33] >= v_ysiz)
430- (*(r->errHndl))(r);
431- if ((r->ireg[0x31] & 3) == 0) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] = c;
432- if ((r->ireg[0x31] & 3) == 1) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] |= c;
433- if ((r->ireg[0x31] & 3) == 2) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] ^= c;
434- if ((r->ireg[0x31] & 3) == 3) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] &= c;
435- break;
436-
437- case 0xff45:
438- c = loadColor(r, 0x36);
439- if (r->ireg[0x32] < 0 || r->ireg[0x32] >= v_xsiz || r->ireg[0x33] < 0 || r->ireg[0x33] >= v_ysiz)
440- (*(r->errHndl))(r);
441- if (r->ireg[0x34] < 0 || r->ireg[0x34] >= v_xsiz || r->ireg[0x35] < 0 || r->ireg[0x35] >= v_ysiz)
442- (*(r->errHndl))(r);
443- dx = r->ireg[0x34] - r->ireg[0x32];
444- dy = r->ireg[0x35] - r->ireg[0x33];
445- x = r->ireg[0x32] << 10;
446- y = r->ireg[0x33] << 10;
447- if (dx < 0) dx = -dx;
448- if (dy < 0) dy = -dy;
449- if (dx >= dy) {
450- len = dx + 1; dx = 1024;
451- if (r->ireg[0x32] > r->ireg[0x34]) dx *= -1;
452- if (r->ireg[0x33] > r->ireg[0x35]) dy *= -1;
453- dy = (dy << 10) / len;
454- }
455- else {
456- len = dy + 1; dy = 1024;
457- if (r->ireg[0x33] > r->ireg[0x35]) dy *= -1;
458- if (r->ireg[0x32] > r->ireg[0x34]) dx *= -1;
459- dx = (dx << 10) / len;
460- }
461- if ((r->ireg[0x31] & 3) == 0) {
462- for (i = 0; i < len; i++) {
463- vram[(x >> 10) + (y >> 10) * v_xsiz] = c;
464- x += dx;
465- y += dy;
466- }
467- break;
468- }
469- for (i = 0; i < len; i++) {
470- // if ((r->ireg[0x31] & 3) == 0) vram[(x >> 10) + (y >> 10) * v_xsiz] = c;
471- if ((r->ireg[0x31] & 3) == 1) vram[(x >> 10) + (y >> 10) * v_xsiz] |= c;
472- if ((r->ireg[0x31] & 3) == 2) vram[(x >> 10) + (y >> 10) * v_xsiz] ^= c;
473- if ((r->ireg[0x31] & 3) == 3) vram[(x >> 10) + (y >> 10) * v_xsiz] &= c;
474- x += dx;
475- y += dy;
476- }
477- break;
478-
479- case 0xff46: // fillRect(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
480- c = loadColor(r, 0x36);
481- if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz; r->ireg[0x34] &= 0; }
482- if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz; r->ireg[0x35] &= 0; }
483- checkRect(r, 0x32);
484- int mod3 = r->ireg[0x31] & 3, x0 = r->ireg[0x34], y0 = r->ireg[0x35], x1 = r->ireg[0x34] + r->ireg[0x32] - 1, y1 = r->ireg[0x35] + r->ireg[0x33] - 1;
485- if ((r->ireg[0x31] & 0x20) == 0) {
486- devFunc0004(mod3, x0, y0, x1, y1, c);
487- }
488- else { // drawRect
489- devFunc0004(mod3, x0, y0, x1, y0, c);
490- devFunc0004(mod3, x0, y1, x1, y1, c);
491- devFunc0004(mod3, x0, y0, x0, y1, c);
492- devFunc0004(mod3, x1, y0, x1, y1, c);
493- }
494- break;
495-
496- case 0xff47: // fillOval(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
497- // これの計算精度はアーキテクチャに依存する.
498- c = loadColor(r, 0x36);
499- if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz; r->ireg[0x34] &= 0; }
500- if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz; r->ireg[0x35] &= 0; }
501- checkRect(r, 0x32);
502- double dcx = 0.5 * (r->ireg[0x32] - 1), dcy = 0.5 * (r->ireg[0x33] - 1), dcxy = (dcx + 0.5) * (dcy + 0.5) - 0.1;
503- dcxy *= dcxy;
504- mod3 = r->ireg[0x31] & 3;
505- x1 = r->ireg[0x32];
506- y1 = r->ireg[0x33];
507- if (mod3 == 0 && (r->ireg[0x31] & 0x20) == 0) {
508- for (y = 0; y < y1; y++) {
509- double dty = (y - dcy) * dcx;
510- for (x = 0; x < x1; x++) {
511- double dtx = (x - dcx) * dcy;
512- if (dtx * dtx + dty * dty > dcxy) continue;
513- vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] = c;
514- }
515- }
516- }
517- else {
518-#define DRAWOVALPARAM 1
519- double dcx1 = 0.5 * (r->ireg[0x32] - (1 + DRAWOVALPARAM * 2)), dcy1 = 0.5 * (r->ireg[0x33] - (1 + DRAWOVALPARAM * 2)), dcxy1 = (dcx1 + 0.5) * (dcy1 + 0.5) - 0.1;
520- dcxy1 *= dcxy1;
521- for (y = 0; y < y1; y++) {
522- double dty = (y - dcy) * dcx;
523- double dty1 = (y - dcy) * dcx1;
524- for (x = 0; x < x1; x++) {
525- double dtx = (x - dcx) * dcy;
526- double dtx1 = (x - dcx) * dcy1;
527- if (dtx * dtx + dty * dty > dcxy) continue;
528- if (DRAWOVALPARAM <= x && x < x1 - DRAWOVALPARAM && DRAWOVALPARAM <= y && y < y1 - DRAWOVALPARAM) {
529- if (dtx1 * dtx1 + dty1 * dty1 < dcxy1) continue;
530- }
531- if (mod3 == 0) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] = c;
532- if (mod3 == 1) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] |= c;
533- if (mod3 == 2) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] ^= c;
534- if (mod3 == 3) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] &= c;
535- }
536- }
537- }
538- break;
539-
540- case 0xff48: // drawString(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36, s.len:R37, s.p:P31)
541- checkString(r, 0x37, 0x31);
542- devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), r->ireg[0x37], r->preg[0x31].p, r);
543- break;
544-
545- case 0xff49: /* 適当な乱数を返す */
546- randStatNext();
547- unsigned u32t;
548- u32t = randStat.stat[0] + (randStat.stat[2] >> 8);
549- r->ireg[0x30] = randStat.stat[3] ^ u32t ^ (-((int)(u32t & 1)) & randStat.tmat);
550- if (r->ireg[0x31] > 0)
551- r->ireg[0x30] = (r->ireg[0x30] & 0x7fffffff) % (r->ireg[0x31] + 1);
552- break;
553-
554- case 0xff4a: /* seedの指定 */
555- randStatInit(r->ireg[0x31]);
556- break;
557-
558- case 0xff4b: /* 適当なseedを提供 */
559- r->ireg[0x30] = (int)(time(NULL) ^ (long)0x55555555);
560- break;
561-
562- case 0xff4c:
563- checkString(r, 0x37, 0x31);
564- len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x37], r->preg[0x31].p, r->ireg[0x38], (int *)r->preg[0x32].p, r);
565- devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), len, pucbuf, r);
566- break;
567-
568- case 0xff4d:
569- // bitblt(mod, xsiz, ysiz, xscale, yscale, x0, y0, lineskip, inv, p_buf, typ0, p_table, typ1);
570- // mod: 0x20:use_table, 0x40:inv_is_visible & typ1_is_color
571- puc = r->preg[0x31].p;
572- mod3 = r->ireg[0x31] & 3;
573- dx = r->ireg[0x34];
574- dy = r->ireg[0x35];
575- if (dy == 0) dy = dx;
576- if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz / dx; r->ireg[0x36] &= 0; }
577- if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz / dy; r->ireg[0x37] &= 0; }
578- for (y = 0; y < r->ireg[0x33]; y++) {
579- y0 = y * dy + r->ireg[0x37];
580- for (x = 0; x < r->ireg[0x32]; x++) {
581- x0 = x * dx + r->ireg[0x36];
582- c = iColor1[*puc++];
583- devFunc0004(mod3, x0, y0, x0 + dx, y0 + dy, c);
584- }
585- puc += r->ireg[0x38];
586- }
587- break;
588-
589- default:
590- printf("devFunc: error: R30=%08X\n", r->ireg[0x30]);
591- exit(1);
592-
593- }
594- return;
595-}
596-
597-
598-
--- a/HeavyOSECPU/function.h
+++ /dev/null
@@ -1,16 +0,0 @@
1-#ifndef _HDLOAD_FUNCTION
2-#define _HDLOAD_FUNCTION 1
3-
4-/* プログラムのすべての部分で汎用的に利用できる関数を定義する。 */
5-
6-
7-void dbgrMain(struct Regs *r);
8-const unsigned char *searchArg(int argc, const unsigned char **argv, const unsigned char *tag, int i); // コマンドライン引数処理.
9-void randStatInit(unsigned int seed);
10-void randStatNext();
11-void devFunc(struct Regs *r); // junkApiを処理する関数
12-
13-
14-
15-
16-#endif
\ No newline at end of file
--- a/HeavyOSECPU/jitc.c
+++ /dev/null
@@ -1,1655 +0,0 @@
1-#include "osecpu.h"
2-
3-#define JITC_ERR_MASK 255
4-#define JITC_ERR_PHASE0ONLY 256
5-#define JITC_ERR_REGNUM (1 | JITC_ERR_PHASE0ONLY)
6-#define JITC_ERR_DST1 (2 | JITC_ERR_PHASE0ONLY)
7-#define JITC_ERR_OPECODE (3 | JITC_ERR_PHASE0ONLY)
8-#define JITC_ERR_LABELNUM (4 | JITC_ERR_PHASE0ONLY)
9-#define JITC_ERR_LABELREDEF (5 | JITC_ERR_PHASE0ONLY)
10-#define JITC_ERR_PREFIX (6 | JITC_ERR_PHASE0ONLY)
11-#define JITC_ERR_LABELNODEF 7
12-#define JITC_ERR_LABELTYP 8
13-#define JITC_ERR_IDIOM 9
14-#define JITC_ERR_PREGNUM (10 | JITC_ERR_PHASE0ONLY)
15-#define JITC_ERR_SRC1 (11 | JITC_ERR_PHASE0ONLY)
16-#define JITC_ERR_BADTYPE (12 | JITC_ERR_PHASE0ONLY)
17-#define JITC_ERR_PREFIXFAR (13 | JITC_ERR_PHASE0ONLY)
18-#define JITC_ERR_INTERNAL 99
19-
20-void errorHandler(struct Regs *r)
21-{
22- puts("security error! abort...");
23- printf("debugInfo0=%d, debugInfo1=%d\n", r->debugInfo0, r->debugInfo1);
24-#if (USE_DEBUGGER != 0)
25- dbgrMain(r);
26-#endif
27- exit(1);
28-}
29-
30-int jitCompCmdLen(const unsigned char *src)
31-{
32- int i = 1;
33- if (0x01 <= *src && *src < 0x04) i = 6;
34- if (*src == 0x04) i = 2;
35- if (0x08 <= *src && *src < 0x0d) i = 8 + src[7] * 4;
36- if (0x0e <= *src && *src < 0x10) i = 8;
37- if (0x10 <= *src && *src < 0x2e) i = 4;
38- if (0x1c <= *src && *src < 0x1f) i = 3;
39- if (*src == 0x1f) i = 11;
40- if (*src == 0x2f) i = 4 + src[1];
41- if (0x30 <= *src && *src <= 0x33) i = 4;
42- if (0x3c <= *src && *src <= 0x3d) i = 7;
43- if (*src == 0xfe) i = 2 + src[1];
44- return i;
45-}
46-#if (JITC_ARCNUM == 0x0001) /* x86-32bit */
47-
48-/* 他のCPUへ移植する人へ:
49-以下は最適化のためのものなので、すべて0として簡単に移植しても問題ありません */
50-#define jitCompA0001_USE_R3F_CMPJMP 1*1
51-#define jitCompA0001_USE_R3F_IMM32 1*1
52-#define jitCompA0001_USE_R3F_IMM8 1*1
53-#define jitCompA0001_USE_R3F_INCDEC 1*1
54-#define jitCompA0001_OPTIMIZE_JMP 1*1
55-#define jitCompA0001_OPTIMIZE_MOV 1*1 /* 1にすると速度低下する? */
56-#define jitCompA0001_OPTIMIZE_CMP 1*1
57-#define jitCompA0001_OPTIMIZE_ALIGN 4*1 /* 0-8を想定 */
58-#define jitCompA0001_EBP128 128*1
59-
60-struct JitCompWork {
61- unsigned char *dst, *dst0;
62- int err, maxLabels;
63-#if (jitCompA0001_USE_R3F_IMM32 != 0)
64- int r3f;
65-#endif
66- char prefix;
67-};
68-
69-#define jitCompPutByte1(p, c0) *p++ = c0
70-#define jitCompPutByte2(p, c0, c1) *p++ = c0; *p++ = c1
71-#define jitCompPutByte3(p, c0, c1, c2) *p++ = c0; *p++ = c1; *p++ = c2
72-#define jitCompPutByte4(p, c0, c1, c2, c3) *p++ = c0; *p++ = c1; *p++ = c2; *p++ = c3
73-
74-static void jitCompPutImm32(struct JitCompWork *w, int i)
75-{
76- jitCompPutByte1(w->dst, i & 0xff);
77- jitCompPutByte1(w->dst, (i >> 8) & 0xff);
78- jitCompPutByte1(w->dst, (i >> 16) & 0xff);
79- jitCompPutByte1(w->dst, (i >> 24) & 0xff);
80- return;
81-}
82-
83-int jitCompGetImm32(const unsigned char *src)
84-{
85- return (src[0] << 24) | (src[1] << 16) | (src[2] << 8) | src[3];
86-}
87-
88-int jitCompGetLabelNum(struct JitCompWork *w, const unsigned char *src)
89-{
90- int i = jitCompGetImm32(src);
91- if (i < 0 || i >= w->maxLabels) {
92- w->err = JITC_ERR_LABELNUM;
93- i = 0;
94- }
95- return i;
96-}
97-
98-void jitCompA0001_85DispN(struct JitCompWork *w, int disp, int n)
99-{
100- disp -= jitCompA0001_EBP128;
101- if (-128 <= disp && disp <= 127) {
102- jitCompPutByte2(w->dst, 0x45 | (n << 3), disp & 0xff);
103- }
104- else {
105- jitCompPutByte1(w->dst, 0x85 | (n << 3));
106- jitCompPutImm32(w, disp);
107- }
108- return;
109-}
110-
111-void jitCompA0001_movEbpDispReg32(struct JitCompWork *w, int disp, int reg32)
112-{
113- jitCompPutByte1(w->dst, 0x89); /* MOV(mem, reg32); */
114- jitCompA0001_85DispN(w, disp, reg32);
115- return;
116-}
117-
118-void jitCompA0001_movReg32EbpDisp(struct JitCompWork *w, int reg32, int disp)
119-{
120- jitCompPutByte1(w->dst, 0x8b); /* MOV(reg32, mem); */
121- jitCompA0001_85DispN(w, disp, reg32);
122- return;
123-}
124-
125-void jitCompA0001_movEaxRxx(struct JitCompWork *w, int rxx)
126-{
127-#if (jitCompA0001_USE_R3F_IMM32 != 0)
128- if (rxx == 0x3f) {
129- jitCompPutByte1(w->dst, 0xb8); /* MOV(EAX, ?); */
130- jitCompPutImm32(w, w->r3f);
131- return;
132- }
133-#endif
134- if (rxx >= 0x40 || rxx < 0) w->err = JITC_ERR_REGNUM;
135- jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, rxx * 4); /* MOV(EAX, [EBP+?]); */
136- return;
137-}
138-
139-void jitCompA0001_movRxxEax(struct JitCompWork *w, int rxx)
140-{
141- if (rxx >= 0x40 || rxx < 0) w->err = JITC_ERR_REGNUM;
142- jitCompA0001_movEbpDispReg32(w, rxx * 4, 0 /* EAX */); /* MOV([EBP+?], EAX); */
143- return;
144-}
145-
146-void jitCompA0001_fixPrefix(struct JitCompWork *w)
147-{
148- if (w->prefix != 0) {
149- if (w->dst - w->dst0 > 127) w->err = JITC_ERR_REGNUM;
150- w->dst0[-1] = (unsigned char)((w->dst - w->dst0) & 0xff);
151- }
152- return;
153-}
154-
155-void jitCompA0001_checkCompPtr(struct JitCompWork *w, int p0, int p1)
156-{
157- if (p0 >= 0x3f || p0 < 0) w->err = JITC_ERR_PREGNUM;
158- if (p1 >= 0x3f || p1 < 0) w->err = JITC_ERR_PREGNUM;
159- /* 比較可能可能なのかのチェックのコードを出力 */ /* 未完成 */
160- return;
161-}
162-
163-void jitCompA000_loadRegCacheAll(struct JitCompWork *w)
164-{
165- jitCompA0001_movReg32EbpDisp(w, 3 /* EBX */, 0 * 4); /* EBX = R00; */
166- jitCompA0001_movReg32EbpDisp(w, 1 /* ECX */, 1 * 4); /* ECX = R01; */
167- jitCompA0001_movReg32EbpDisp(w, 2 /* EDX */, 2 * 4); /* EDX = R02; */
168- return;
169-}
170-
171-void jitCompA000_storeRegCacheAll(struct JitCompWork *w)
172-{
173- jitCompA0001_movEbpDispReg32(w, 0 * 4, 3 /* EBX */); /* R00 = EBX; */
174- jitCompA0001_movEbpDispReg32(w, 1 * 4, 1 /* ECX */); /* R01 = ECX; */
175- jitCompA0001_movEbpDispReg32(w, 2 * 4, 2 /* EDX */); /* R02 = EDX; */
176- return;
177-}
178-
179-void jitCompA000_loadRegCacheEcx(struct JitCompWork *w)
180-{
181- jitCompA0001_movReg32EbpDisp(w, 1 /* ECX */, 1 * 4); /* ECX = R01; */
182- return;
183-}
184-
185-void jitCompA000_storeRegCacheEcx(struct JitCompWork *w)
186-{
187- jitCompA0001_movEbpDispReg32(w, 1 * 4, 1 /* ECX */); /* R01 = ECX; */
188- return;
189-}
190-
191-void jitCompA000_loadRegCacheEdx(struct JitCompWork *w)
192-{
193- jitCompA0001_movReg32EbpDisp(w, 2 /* EDX */, 2 * 4); /* EDX = R02; */
194- return;
195-}
196-
197-void jitCompA000_storeRegCacheEdx(struct JitCompWork *w)
198-{
199- jitCompA0001_movEbpDispReg32(w, 2 * 4, 2 /* EDX */); /* R02 = EDX; */
200- return;
201-}
202-
203-int jitCompA000_selectRegCache(int rxx, int reg)
204-{
205- if (rxx == 0) reg = 3; /* EBX */
206- if (rxx == 1) reg = 1; /* ECX */
207- if (rxx == 2) reg = 2; /* EDX */
208- return reg;
209-}
210-
211-void jitCompA000_loadPRegCacheAll(struct JitCompWork *w)
212-{
213- // jitCompA0001_movReg32EbpDisp(w, 5 /* EBP */, 256 + 0 * 32 + 0); /* EBP = P00; */
214- jitCompA0001_movReg32EbpDisp(w, 6 /* ESI */, 256 + 1 * 32 + 0); /* ESI = P01; */
215- jitCompA0001_movReg32EbpDisp(w, 7 /* EDI */, 256 + 2 * 32 + 0); /* EDI = P02; */
216- return;
217-}
218-
219-void jitCompA000_storePRegCacheAll(struct JitCompWork *w)
220-{
221- // jitCompA0001_movEbpDispReg32(w, 256 + 0 * 32 + 0, 5 /* EBP */); /* P00 = EBP; */
222- jitCompA0001_movEbpDispReg32(w, 256 + 1 * 32 + 0, 6 /* ESI */); /* P01 = ESI; */
223- jitCompA0001_movEbpDispReg32(w, 256 + 2 * 32 + 0, 7 /* EDI */); /* P02 = EDI; */
224- return;
225-}
226-
227-int jitCompA000_selectPRegCache(int pxx, int reg)
228-{
229- // if (pxx == 0) reg = 5; /* EBP */
230- if (pxx == 1) reg = 6; /* ESI */
231- if (pxx == 2) reg = 7; /* EDI */
232- return reg;
233-}
234-
235-int jitCompA000_convTyp(int t)
236-{
237- int r = -1;
238- if (1 <= t && t <= 7) r = t;
239- if (8 <= t && t <= 13) r = 2 | (t & 1);
240- if (14 <= t && t <= 15) r = 4 | (t & 1);
241- if (16 <= t && t <= 21) r = 6 | (t & 1);
242- return r;
243-}
244-
245-int jitCompA000_dataWidth(int t)
246-{
247- int r = -1;
248- if (t == 0x0001) r = 256;
249- t >>= 1;
250- if (t == 0x0002 / 2) r = 8;
251- if (t == 0x0004 / 2) r = 16;
252- if (t == 0x0006 / 2) r = 32;
253- if (t == 0x0008 / 2) r = 4;
254- if (t == 0x000a / 2) r = 2;
255- if (t == 0x000c / 2) r = 1;
256- if (t == 0x000e / 2) r = 12;
257- if (t == 0x0010 / 2) r = 20;
258- if (t == 0x0012 / 2) r = 24;
259- if (t == 0x0014 / 2) r = 28;
260- return r;
261-}
262-
263-static unsigned char *errfnc;
264-
265-void jitCompA0001_checkType0(struct JitCompWork *w, int pxx, int typ, int ac)
266-{
267- if (typ <= 0) { w->err = JITC_ERR_BADTYPE; }
268- if (typ > 0x7f) { w->err = JITC_ERR_INTERNAL; }
269- jitCompA0001_movReg32EbpDisp(w, 0 /* EAX */, 256 + pxx * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */
270- jitCompPutByte3(w->dst, 0x83, 0xf8, typ & 0x7f); /* CMP(EAX, ?); */
271- jitCompPutByte2(w->dst, 0x0f, 0x85); /* JNE */
272- jitCompPutImm32(w, errfnc - (w->dst + 4));
273- return;
274-}
275-
276-void jitCompA0001_checkType(struct JitCompWork *w, int pxx, int typ, int ac)
277-// data用.
278-// 将来的にはaliveやアクセス権チェックも入れる
279-{
280- jitCompA0001_checkType0(w, pxx, typ, ac);
281- return;
282-}
283-
284-void jitCompA0001_checkLimit(struct JitCompWork *w, int reg, int pxx)
285-{
286- jitCompPutByte1(w->dst, 0x3b); /* CMP(reg, [EBP+?]); */
287- jitCompA0001_85DispN(w, 256 + pxx * 32 + 8, reg); /* p0 */
288- jitCompPutByte2(w->dst, 0x0f, 0x82); /* JB */
289- jitCompPutImm32(w, errfnc - (w->dst + 4));
290- jitCompPutByte1(w->dst, 0x3b); /* CMP(reg, [EBP+?]); */
291- jitCompA0001_85DispN(w, 256 + pxx * 32 + 12, reg); /* p1 */
292- jitCompPutByte2(w->dst, 0x0f, 0x83); /* JAE */
293- jitCompPutImm32(w, errfnc - (w->dst + 4));
294- return;
295-}
296-
297-void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
298-void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0);
299-void funcf4(char *ebp, int pxx, int typ, int len);
300-void funcf5(char *ebp, int pxx, int typ, int len); // pxxはダミーで参照されない.
301-void funcf6(char *ebp, int pxx, int typ, int len);
302-void funcf7(char *ebp, int pxx, int typ, int len); // typとlenはダミーで参照されない.
303-// F5の場合、decoderが対応するalloc-freeを結びつけるのが簡単で、typやlenを指定必須にしてもフロントエンドコードに影響はない.
304-
305-void errHndl(struct Regs *r);
306-
307-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)
308-/* IA-32用 */
309-/* 本来ならこのレイヤでは文法チェックしない */
310-{
311- struct JitCompWork w;
312- unsigned char *dst00 = dst, *errmsg = "", *enter0 = NULL, *tmp_ucp;
313- const unsigned char *oldsrc;
314- int timecount = 0, i, j = 0, lastlabel = -1, debugInfo0 = -1;
315- int reg0, reg1, reg2, cmp0reg = -1, cmp0lev = 0;
316- w.dst = w.dst0 = dst;
317- w.err = 0;
318- w.maxLabels = maxLabels;
319- if ((flags & JITC_NOSTARTUP) == 0) {
320- jitCompPutByte1(w.dst, 0x60); /* PUSHAD(); */
321- jitCompA000_loadRegCacheAll(&w); /* start-up */
322- jitCompA000_loadPRegCacheAll(&w);
323- }
324- if (level <= JITC_LV_SLOWER) {
325- jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); */
326- jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */
327- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
328- jitCompPutImm32(&w, debugInfo1);
329- jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
330- }
331- while (src < src1) {
332- w.prefix = 0;
333- if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; goto err_w; }
334- timecount++;
335- if (timecount >= 64) {
336- timecount -= 64;
337- /* 未完成(timeoutチェックコードを入れる) */
338- }
339- prefix_continue:
340- switch (*src) {
341-
342- case 0x00: /* NOP */
343- if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
344- break;
345-
346- case 0x01: /* LB */
347- if (enter0 == NULL && (src[6] == 0x3c || (src[6] == 0xfe && src[7] == 0x01 && src[9] == 0x3c))) {
348- jitCompPutByte1(w.dst, 0xe9);
349- enter0 = w.dst;
350- jitCompPutImm32(&w, 0);
351- }
352- if (src[6] == 0x34) {
353- tmp_ucp = w.dst;
354- jitCompPutByte1(w.dst, 0xe9);
355- i = jitCompGetImm32(&src[7]);
356- j = 32;
357- if (i != 1) {
358- i = jitCompA000_convTyp(i);
359- j = 0;
360- if (i == 2 || i == 3) { j = 1; }
361- if (i == 4 || i == 5) { j = 2; }
362- if (i == 6 || i == 7) { j = 4; }
363- }
364- j *= jitCompGetImm32(&src[11]);
365- if (j <= 0) w.err = JITC_ERR_BADTYPE;
366- jitCompPutImm32(&w, j);
367-#if (jitCompA0001_OPTIMIZE_JMP != 0)
368- if (j <= 127 - jitCompA0001_OPTIMIZE_ALIGN) {
369- w.dst -= 5;
370- jitCompPutByte2(w.dst, 0xeb, j);
371- }
372-#endif
373- }
374-#if (jitCompA0001_OPTIMIZE_ALIGN != 0)
375- for (;;) {
376- i = ((int)w.dst) & (jitCompA0001_OPTIMIZE_ALIGN - 1); /* ALIGNで割ったあまりを計算 */
377- if (i == 0) break;
378- i = jitCompA0001_OPTIMIZE_ALIGN - i;
379- if (i == 1) { jitCompPutByte1(w.dst, 0x90); j += i; } /* NOP(); */
380- if (i == 2) { jitCompPutByte2(w.dst, 0x89, 0xc0); j += i; } /* MOV(EAX, EAX); */
381- if (i == 3) { jitCompPutByte3(w.dst, 0x8d, 0x76, 0x00); j += i; } /* LEA(ESI, [ESI+0]); */
382- if (i == 4) { jitCompPutByte4(w.dst, 0x8d, 0x74, 0x26, 0x00); j += i; } /* LEA(ESI, [ESI*1+0]); */
383- if (i == 5) { jitCompPutByte1(w.dst, 0x0d); jitCompPutImm32(&w, 0); j += i; } /* OR(EAX, 0); */
384- if (i == 6) { jitCompPutByte2(w.dst, 0x8d, 0xb6); jitCompPutImm32(&w, 0); j += i; } /* LEA(ESI, [ESI+0]); */
385- if (i >= 7) { jitCompPutByte3(w.dst, 0x8d, 0xb4, 0x26); jitCompPutImm32(&w, 0); j += 7; } /* LEA(ESI, [ESI*1+0]); */
386- }
387-#endif
388- if (src[6] == 0x34) {
389- tmp_ucp[1] = j & 0xff;
390- if (*tmp_ucp == 0xe9) {
391- tmp_ucp[2] = (j >> 8) & 0xff;
392- tmp_ucp[3] = (j >> 16) & 0xff;
393- tmp_ucp[4] = (j >> 24) & 0xff;
394- }
395- }
396- if ((flags & JITC_PHASE1) == 0) {
397- i = jitCompGetLabelNum(&w, src + 2);
398- //printf("i=%06X %06X\n", i, src-src0);
399- if (label[i].opt != 0 && w.err == 0) { w.err = JITC_ERR_LABELREDEF; goto err_w; }
400- if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
401- label[i].opt = src[1] + 1;
402- label[i].typ = 0; /* TYP_CODE */
403- label[i].p = w.dst;
404- label[i].p1 = w.dst + 1;
405- lastlabel = i;
406- }
407- cmp0reg = -1;
408- timecount = 0;
409- /* 未完成(timeoutチェックコードを入れる) */
410- break;
411-
412- case 0x02: /* LIMM */
413- if (src[1] == 0x3f && w.prefix != 0) w.err = JITC_ERR_PREFIX;
414-#if (jitCompA0001_USE_R3F_IMM32 != 0)
415- if (src[1] == 0x3f) {
416- w.r3f = jitCompGetImm32(src + 2);
417- break;
418- }
419-#endif
420- i = jitCompGetImm32(src + 2);
421- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
422-#if (jitCompA0001_OPTIMIZE_MOV != 0)
423- if (i == 0) {
424- jitCompPutByte2(w.dst, 0x31, 0xc0 | reg0 << 3 | reg0); /* XOR(reg0, reg0); */
425- jitCompA0001_movRxxEax(&w, src[1]);
426- break;
427- }
428-#endif
429- jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */
430- jitCompPutImm32(&w, i);
431- if (reg0 == 0)
432- jitCompA0001_movRxxEax(&w, src[1]);
433- break;
434-
435- case 0x03: /* PLIMM */ /* 未完成(plsまで対応) */
436- i = jitCompGetLabelNum(&w, src + 2);
437- if ((flags & JITC_PHASE1) != 0 && w.err == 0) {
438- if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }
439- if (src[1] != 0x3f && label[i].opt != 2) { w.err = JITC_ERR_LABELTYP; goto err_w; }
440- if (src[1] == 0x3f && label[i].typ != 0) { w.err = JITC_ERR_LABELTYP; goto err_w; }
441- }
442- if (src[1] == 0x3f) {
443- if (w.prefix == 0) {
444- jitCompPutByte1(w.dst, 0xe9); /* JMP(?); */
445- }
446- else {
447- w.dst[-1] = w.dst[-2] ^ 0xf1; /* 74->85, 75->84 */
448- w.dst[-2] = 0x0f;
449- w.prefix = 0;
450- }
451- j = 0;
452- if ((flags & JITC_PHASE1) != 0 || ((flags & JITC_PHASE1) == 0) && label[i].opt != 0)
453- j = label[i].p - (w.dst + 4);
454- jitCompPutImm32(&w, j);
455-#if (jitCompA0001_OPTIMIZE_JMP != 0)
456- if (-128 - 3 <= j && j < 0) {
457- if (w.dst[-5] == 0xe9) {
458- j += 3;
459- w.dst -= 5;
460- jitCompPutByte1(w.dst, 0xeb); /* JMP(?); */
461- }
462- else {
463- j += 4;
464- w.dst -= 6;
465- jitCompPutByte1(w.dst, w.dst[1] ^ 0xf0);
466- }
467- jitCompPutByte1(w.dst, j & 0xff);
468- }
469-#endif
470- }
471- else {
472- reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
473- jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */
474- jitCompPutImm32(&w, (int)label[i].p);
475- if (reg0 == 0)
476- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32, 0); /* MOV([EBP+?], EAX); */
477- if (level < JITC_LV_FASTEST) {
478- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 8, reg0); /* MOV([EBP+?], reg0); */ /* p0 */
479- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
480- jitCompPutImm32(&w, label[i].typ);
481- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 4, 0); /* MOV([EBP+?], EAX); */ /* typ */
482- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
483- jitCompPutImm32(&w, (int)label[i].p1);
484- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 12, 0); /* MOV([EBP+?], EAX); */ /* p1 */
485- jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); */
486- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 16, 0); /* MOV([EBP+?], EAX); */ /* liveSign */
487- jitCompA0001_movReg32EbpDisp(&w, 0, 2320); /* MOV(EAX, ptrCtrl); */
488- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 20, 0); /* MOV([EBP+?], EAX); */ /* pls */
489- }
490- }
491- break;
492-
493- case 0x04: /* CND (prefix) */
494- if (src[1] >= 0x40) w.err = JITC_ERR_REGNUM;
495- reg0 = jitCompA000_selectRegCache(src[1], -1 /* mem */);
496- if (reg0 < 0) {
497- jitCompPutByte1(w.dst, 0xf7); /* TEST([EBP+?],1); */
498- jitCompA0001_85DispN(&w, src[1] * 4, 0);
499- }
500- else {
501- jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); /* TEST(reg0,1); */
502- }
503- jitCompPutImm32(&w, 1);
504- jitCompPutByte2(w.dst, 0x74, 0x00); /* JZ($+2) */
505- cmp0reg = -1;
506- if (w.err != 0) goto err_w;
507- src += 2;
508- w.prefix = 1;
509- w.dst0 = w.dst;
510- goto prefix_continue;
511-
512- case 0x08: /* LMEM */ /* 完成 */
513- i = jitCompGetImm32(src + 2);
514- if (i == 0x0001) w.err = JITC_ERR_BADTYPE;
515- if (level < JITC_LV_FASTER) {
516- jitCompA0001_checkType(&w, src[6], i, 0); // read
517- cmp0reg = -1;
518- }
519- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
520- reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
521- if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */)
522- reg1 = 0; /* EAX */
523- if (reg1 == 2 /* EDX */)
524- jitCompA000_storeRegCacheEdx(&w);
525- if (reg1 <= 3 /* EAX, EDX */)
526- jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
527- if (level < JITC_LV_FASTER)
528- jitCompA0001_checkLimit(&w, reg1, src[6]);
529- i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
530- switch (i) {
531- case 0x0002:
532- jitCompPutByte3(w.dst, 0x0f, 0xbe, reg0 << 3 | reg1); /* MOVSX(reg0,BYTE [reg1]); */
533- break;
534- case 0x0003:
535- jitCompPutByte3(w.dst, 0x0f, 0xb6, reg0 << 3 | reg1); /* MOVZX(reg0,BYTE [reg1]); */
536- break;
537- case 0x0004:
538- jitCompPutByte3(w.dst, 0x0f, 0xbf, reg0 << 3 | reg1); /* MOVSX(reg0,WORD [reg1]); */
539- break;
540- case 0x0005:
541- jitCompPutByte3(w.dst, 0x0f, 0xb7, reg0 << 3 | reg1); /* MOVZX(reg0,WORD [reg1]); */
542- break;
543- case 0x0006:
544- case 0x0007:
545- jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */
546- break;
547- default:
548- w.err = JITC_ERR_BADTYPE;
549- }
550- if (reg0 == 0 /* EAX */)
551- jitCompA0001_movRxxEax(&w, src[1]);
552- if (reg1 == 2 /* EDX */)
553- jitCompA000_loadRegCacheEdx(&w);
554- break;
555-
556- case 0x09: /* SMEM */ /* 完成 */
557- i = jitCompGetImm32(src + 2);
558- if (i == 0x0001) w.err = JITC_ERR_BADTYPE;
559- if (level < JITC_LV_FASTER) {
560- jitCompA0001_checkType(&w, src[6], i, 1); // write
561- cmp0reg = -1;
562- }
563- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
564- reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
565- if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */)
566- reg1 = 0; /* EAX */
567- if (reg1 == 2 /* EDX */)
568- jitCompA000_storeRegCacheEdx(&w);
569- if (reg1 <= 3 /* EAX, EDX */)
570- jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
571- if (level < JITC_LV_FASTER)
572- jitCompA0001_checkLimit(&w, reg1, src[6]);
573- if (reg0 == 0 /* EAX */)
574- jitCompA0001_movEaxRxx(&w, src[1]);
575- /* 値の範囲チェック */
576- i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
577- switch (i) {
578- case 0x0002:
579- case 0x0003:
580- jitCompPutByte2(w.dst, 0x88, reg0 << 3 | reg1); /* MOV([reg1], BYTE(reg0)); */
581- break;
582- case 0x0004:
583- case 0x0005:
584- jitCompPutByte3(w.dst, 0x66, 0x89, reg0 << 3 | reg1); /* MOV([reg1], WORD(reg0)); */
585- break;
586- case 0x0006:
587- case 0x0007:
588- jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */
589- break;
590- default:
591- w.err = JITC_ERR_BADTYPE;
592- }
593- if (reg1 == 2 /* EDX */)
594- jitCompA000_loadRegCacheEdx(&w);
595- break;
596-
597- case 0x0a: /* PLMEM */ /* 完成 */
598- i = jitCompGetImm32(src + 2);
599- if (i != 0x0001) w.err = JITC_ERR_BADTYPE;
600- if (level < JITC_LV_FASTER) {
601- jitCompA0001_checkType(&w, src[6], i, 0); // read
602- cmp0reg = -1;
603- }
604- reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
605- reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
606- // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */
607- // reg1 = 0; /* EAX */
608- if (reg0 == reg1 && reg0 != 0) { // bugfix: hinted by yao, 2013.09.14. thanks!
609- jitCompA000_storePRegCacheAll(&w);
610- reg1 = 2; /* EDX */
611- }
612- if (reg1 == 2 /* EDX */)
613- jitCompA000_storeRegCacheEdx(&w);
614- if (reg1 <= 3 /* EAX, EDX */)
615- jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
616- if (level < JITC_LV_FASTER)
617- jitCompA0001_checkLimit(&w, reg1, src[6]);
618- jitCompPutByte2(w.dst, 0x8b, reg0 << 3 | reg1); /* MOV(reg0, [reg1]); */
619- if (reg0 == 0 /* EAX */)
620- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0); /* MOV([EBP+?], EAX); */
621- for (i = 4; i < 32; i += 4) {
622- jitCompPutByte3(w.dst, 0x8b, 0x40 | reg1, i); /* MOV(EAX, [reg1+?]); */
623- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
624- }
625- if (reg1 == 2 /* EDX */)
626- jitCompA000_loadRegCacheEdx(&w);
627- break;
628-
629- case 0x0b: /* PSMEM */ /* 完成 */
630- i = jitCompGetImm32(src + 2);
631- if (i != 0x0001) w.err = JITC_ERR_BADTYPE;
632- if (level < JITC_LV_FASTER) {
633- jitCompA0001_checkType(&w, src[6], i, 1); // write
634- cmp0reg = -1;
635- }
636- reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
637- reg1 = jitCompA000_selectPRegCache(src[6], 2 /* EDX */);
638- // if (reg0 != 0 /* EAX */ && reg1 == 2 /* EDX */) /* これをやってはいけない!(by K, 2013.08.02) */
639- // reg1 = 0; /* EAX */
640- if (reg1 == 2 /* EDX */)
641- jitCompA000_storeRegCacheEdx(&w);
642- if (reg1 <= 3 /* EAX, EDX */)
643- jitCompA0001_movReg32EbpDisp(&w, reg1, 256 + src[6] * 32 + 0); /* MOV(reg1, [EBP+?]); */
644- if (level < JITC_LV_FASTER)
645- jitCompA0001_checkLimit(&w, reg1, src[6]);
646- if (reg0 == 0 /* EAX */)
647- jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[1] * 32 + 0); /* MOV(reg0, [EBP+?]); */
648- jitCompPutByte2(w.dst, 0x89, reg0 << 3 | reg1); /* MOV([reg1], reg0); */
649- for (i = 4; i < 32; i += 4) {
650- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[1] * 32 + i); /* MOV(EAX, [EBP+?]); */
651- jitCompPutByte3(w.dst, 0x89, 0x40 | reg1, i); /* MOV([reg1+?], EAX); */
652- }
653- if (reg1 == 2 /* EDX */)
654- jitCompA000_loadRegCacheEdx(&w);
655- break;
656-
657- case 0x0e: /* PADD */ /* 完成 */
658- if (level < JITC_LV_FASTER) {
659- jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 2), 2); // other, aliveテストはとりあえずしない.
660- cmp0reg = -1;
661- }
662- reg0 = jitCompA000_selectPRegCache(src[1], 0 /* EAX */);
663- reg1 = jitCompA000_selectPRegCache(src[6], -1 /* mem */);
664- if (reg1 < 0 /* mem */)
665- jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */
666- if (reg1 >= 0 && reg0 != reg1) {
667- jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
668- }
669- i = jitCompGetImm32(src + 2);
670- j = -1;
671- if (i == 1)
672- j = 5; /* 32 */
673- else {
674- i = jitCompA000_convTyp(i);
675- if (0x0002 <= i && i <= 0x0007)
676- j = (i - 0x0002) >> 1;
677- }
678- if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; }
679-#if (jitCompA0001_USE_R3F_IMM32 != 0)
680- if (src[7] == 0x3f) {
681- j = w.r3f << j;
682-#if (jitCompA0001_USE_R3F_IMM8 != 0)
683- if (-0x80 <= j && j <= 0x7f) {
684-#if (jitCompA0001_USE_R3F_INCDEC != 0)
685- if (j == 1) { jitCompPutByte1(w.dst, 0x40 | reg0); goto padd1; } /* INC */
686- if (j == -1) { jitCompPutByte1(w.dst, 0x48 | reg0); goto padd1; } /* DEC */
687-#endif
688- jitCompPutByte3(w.dst, 0x83, 0xc0 | reg0, j & 0xff); /* ADD(reg0, im8); */
689- goto padd1;
690- }
691-#endif
692- if (reg0 == 0) {
693- jitCompPutByte1(w.dst, 0x05); /* ADD(reg0, ?); */
694- }
695- else {
696- jitCompPutByte2(w.dst, 0x81, 0xc0 | reg0); /* ADD(reg0, ?); */
697- }
698- jitCompPutImm32(&w, j);
699- goto padd1;
700- }
701-#endif
702- if (src[7] >= 0x40) w.err = JITC_ERR_REGNUM;
703- if (j == 0) {
704- reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */);
705- if (reg1 >= 0) {
706- jitCompPutByte2(w.dst, 0x01, 0xc0 | reg1 << 3 | reg0); /* ADD(reg0, reg1); */
707- }
708- else {
709- jitCompPutByte1(w.dst, 0x03); /* ADD(reg0, [EBP+?]); */
710- jitCompA0001_85DispN(&w, src[7] * 4, reg0);
711- }
712- }
713- else {
714- reg1 = jitCompA000_selectRegCache(src[7], -1 /* mem */);
715- reg2 = 2; /* EDX */
716- jitCompA000_storeRegCacheEdx(&w);
717- if (reg1 < 0)
718- jitCompA0001_movReg32EbpDisp(&w, reg2, src[7] * 4); /* MOV(reg2, [EBP+?]); */
719- if (reg1 >= 0 && reg1 != reg2) {
720- jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg2); /* MOV(reg2, reg1); */
721- }
722- jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg2, j); /* SHL(reg2, ?); */
723- jitCompPutByte2(w.dst, 0x01, 0xc0 | reg2 << 3 | reg0); /* ADD(reg0, reg2); */
724- jitCompA000_loadRegCacheEdx(&w);
725- }
726-#if (jitCompA0001_USE_R3F_IMM32 != 0)
727- padd1:
728-#endif
729- if (reg0 == 0 /* EAX */)
730- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, reg0); /* MOV([EBP+?], reg0); */
731- if (src[1] != src[6]) {
732- for (i = 4; i < 32; i += 4) {
733- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
734- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
735- }
736- }
737- cmp0reg = -1;
738- break;
739-
740- case 0x0f: /* PDIF */ /* 未完成 */
741- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
742- jitCompA000_storePRegCacheAll(&w); // 手抜き.
743- jitCompA0001_checkCompPtr(&w, src[6], src[7]);
744- jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[6] * 32 + 0); /* MOV(reg0, [EBP+?]); */
745- jitCompPutByte1(w.dst, 0x2b); /* SUB(EAX, [EBP+?]); */
746- jitCompA0001_85DispN(&w, 256 + src[7] * 32 + 0, reg0);
747- i = jitCompA000_convTyp(jitCompGetImm32(src + 2));
748- j = -1;
749- if (0x0002 <= i && i <= 0x0007)
750- j = (i - 0x0002) >> 1;
751- if (j < 0) { w.err = JITC_ERR_BADTYPE; goto err_w; }
752- if (j > 0) {
753- jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, j); /* SAR(reg0,?); */
754- }
755- if (reg0 == 0 /* EAX */)
756- jitCompA0001_movRxxEax(&w, src[1]);
757- cmp0reg = src[1]; cmp0lev = 1;
758- break;
759-
760- case 0x10: /* OR */
761- case 0x11: /* XOR */
762- case 0x12: /* AND */
763- case 0x14: /* ADD */
764- case 0x15: /* SUB */
765- case 0x16: /* MUL */
766- if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
767- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
768- reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */);
769-#if (jitCompA0001_USE_R3F_IMM32 != 0)
770- if (src[2] == 0x3f) { // SUBのみ該当.
771- if (*src != 0x15) w.err = JITC_ERR_REGNUM;
772- reg2 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
773- if (reg2 >= 0)
774- jitCompA000_storeRegCacheAll(&w);
775- jitCompPutByte1(w.dst, 0xb8 | reg0); /* MOV(reg0, ?); */
776- jitCompPutImm32(&w, w.r3f);
777- jitCompPutByte1(w.dst, 0x2b);
778- jitCompA0001_85DispN(&w, src[3] * 4, reg0);
779- if (reg0 == 0)
780- jitCompA0001_movRxxEax(&w, src[1]);
781- break;
782- }
783-#endif
784- if (reg1 < 0) {
785- jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg0, [EBP+?]); */
786- }
787- if (reg1 >= 0 && reg0 != reg1) {
788- jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
789- }
790- if (!(src[0] == 0x10 && src[3] == 0xff)) { // bugfix: hinted by Iris, 2013.06.26. thanks!
791- cmp0reg = src[1];
792- cmp0lev = 1;
793- if (src[0] < 0x14)
794- cmp0lev = 2;
795- if (src[0] == 0x16)
796- cmp0reg = -1;
797- }
798- if (!(src[0] == 0x10 && src[3] == 0xff)) {
799-#if (jitCompA0001_USE_R3F_IMM32 != 0)
800- if (src[3] == 0x3f) {
801- if (*src == 0x16 && w.r3f == -1) {
802- jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */
803- if (reg0 == 0)
804- jitCompA0001_movRxxEax(&w, src[1]);
805- break;
806- }
807-#if (jitCompA0001_USE_R3F_INCDEC != 0)
808- if ((*src == 0x14 && w.r3f == 1) || (*src == 0x15 && w.r3f == -1)) {
809- jitCompPutByte1(w.dst, 0x40 | reg0); /* INC(reg0); */
810- if (reg0 == 0)
811- jitCompA0001_movRxxEax(&w, src[1]);
812- break;
813- }
814- if ((*src == 0x15 && w.r3f == 1) || (*src == 0x14 && w.r3f == -1)) {
815- jitCompPutByte1(w.dst, 0x48 | reg0); /* DEC(reg0); */
816- if (reg0 == 0)
817- jitCompA0001_movRxxEax(&w, src[1]);
818- break;
819- }
820-#endif
821-#if (jitCompA0001_USE_R3F_IMM8 != 0)
822- if (-0x80 <= w.r3f && w.r3f <= 0x7f) {
823- if (*src != 0x16) {
824- static unsigned char basic_op_table_im8[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 };
825- jitCompPutByte3(w.dst, 0x83, basic_op_table_im8[*src - 0x10] | reg0, w.r3f & 0xff);
826- }
827- else {
828- jitCompPutByte3(w.dst, 0x6b, 0xc0 | reg0 << 3 | reg0, w.r3f & 0xff);
829- }
830- if (reg0 == 0)
831- jitCompA0001_movRxxEax(&w, src[1]);
832- break;
833- }
834-#endif
835- if (reg0 == 0 /* EAX */) {
836- static unsigned char basic_op_table_im32_eax[] = { 0x0d, 0x35, 0x25, 0, 0x05, 0x2d, 0xc0 };
837- if (*src == 0x16) { jitCompPutByte1(w.dst, 0x69); }
838- jitCompPutByte1(w.dst, basic_op_table_im32_eax[*src - 0x10]);
839- }
840- else {
841- if (*src != 0x16) {
842- static unsigned char basic_op_table_im32_reg[] = { 0xc8, 0xf0, 0xe0, 0, 0xc0, 0xe8 };
843- jitCompPutByte2(w.dst, 0x81, basic_op_table_im32_reg[*src - 0x10] | reg0);
844- }
845- else {
846- jitCompPutByte2(w.dst, 0x69, 0xc0 | reg0 << 3 | reg0);
847- }
848- }
849- jitCompPutImm32(&w, w.r3f);
850- if (reg0 == 0)
851- jitCompA0001_movRxxEax(&w, src[1]);
852- break;
853- }
854-#endif
855- reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
856- if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
857- if (*src != 0x16) {
858- if (reg1 >= 0) {
859- static unsigned char basic_op_table_rr[] = { 0x09, 0x31, 0x21, 0, 0x01, 0x29 }; /* op(reg,reg); */
860- jitCompPutByte2(w.dst, basic_op_table_rr[*src - 0x10], 0xc0 | reg1 << 3 | reg0);
861- }
862- else {
863- static unsigned char basic_op_table_rm[] = { 0x0b, 0x33, 0x23, 0, 0x03, 0x2b, 0xaf }; /* op(reg,mem); */
864- jitCompPutByte1(w.dst, basic_op_table_rm[*src - 0x10]);
865- jitCompA0001_85DispN(&w, src[3] * 4, reg0);
866- }
867- }
868- else {
869- if (reg1 >= 0) {
870- jitCompPutByte3(w.dst, 0x0f, 0xaf, 0xc0 | reg0 << 3 | reg1);
871- }
872- else {
873- jitCompPutByte2(w.dst, 0x0f, 0xaf);
874- jitCompA0001_85DispN(&w, src[3] * 4, reg0);
875- }
876- }
877- }
878- if (reg0 == 0)
879- jitCompA0001_movRxxEax(&w, src[1]);
880- break;
881-
882- case 0x18: /* SHL */
883- case 0x19: /* SAR */
884- if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
885- if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
886-#if (jitCompA0001_USE_R3F_IMM32 != 0)
887- if (src[3] == 0x3f) {
888- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
889- reg1 = jitCompA000_selectRegCache(src[2], -1 /* mem */);
890- if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
891- if (reg1 == -1)
892- jitCompA0001_movReg32EbpDisp(&w, reg0, src[2] * 4); /* MOV(reg1, [EBP+?]); */
893- else {
894- if (reg0 != reg1) {
895- jitCompPutByte2(w.dst, 0x89, 0xc0 | reg1 << 3 | reg0); /* MOV(reg0, reg1); */
896- }
897- }
898- if (*src == 0x18) { jitCompPutByte3(w.dst, 0xc1, 0xe0 | reg0, w.r3f); } /* SHL(reg0, im8); */
899- if (*src == 0x19) { jitCompPutByte3(w.dst, 0xc1, 0xf8 | reg0, w.r3f); } /* SAR(reg0, im8); */
900- if (reg0 == 0 /* EAX */)
901- jitCompA0001_movRxxEax(&w, src[1]);
902- cmp0reg = src[1];
903- cmp0lev = 1;
904- break;
905- }
906-#endif
907- jitCompA000_storeRegCacheAll(&w); // 手抜き.
908- jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
909-#if (jitCompA0001_USE_R3F_IMM32 != 0)
910- if (src[2] == 0x3f) {
911- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
912- jitCompPutImm32(&w, w.r3f);
913- }
914- else {
915- jitCompA0001_movEaxRxx(&w, src[2]);
916- }
917-#else
918- jitCompA0001_movEaxRxx(&w, src[2]);
919-#endif
920- if (*src == 0x18) { jitCompPutByte2(w.dst, 0xd3, 0xe0); } /* SHL(EAX, CL); */
921- if (*src == 0x19) { jitCompPutByte2(w.dst, 0xd3, 0xf8); } /* SAR(EAX, CL); */
922- jitCompA0001_movRxxEax(&w, src[1]);
923- jitCompA000_loadRegCacheAll(&w); // 手抜き.
924- cmp0reg = src[1];
925- cmp0lev = 1;
926- break;
927-
928- case 0x1a: /* DIV */
929- case 0x1b: /* MOD */
930- if (src[1] >= 0x3f) w.err = JITC_ERR_REGNUM;
931- if (src[2] >= 0x40) w.err = JITC_ERR_REGNUM;
932- if (src[3] >= 0x40) w.err = JITC_ERR_REGNUM;
933- jitCompA000_storeRegCacheAll(&w); // 手抜き.
934-#if (jitCompA0001_USE_R3F_IMM32 != 0)
935- if (src[3] == 0x3f) {
936- jitCompPutByte1(w.dst, 0xb8 | 1); /* MOV(ECX, ?); */
937- jitCompPutImm32(&w, w.r3f);
938- }
939- else {
940- jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
941- }
942- if (src[2] == 0x3f) {
943- jitCompPutByte1(w.dst, 0xb8 | 0); /* MOV(EAX, ?); */
944- jitCompPutImm32(&w, w.r3f);
945- }
946- else {
947- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */
948- }
949-#else
950- jitCompA0001_movReg32EbpDisp(&w, 1 /* ECX */, src[3] * 4); /* MOV(ECX, [EBP+?]); */
951- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, src[2] * 4); /* MOV(EAX, [EBP+?]); */
952-#endif
953- jitCompPutByte1(w.dst, 0x99); /* CDQ(); */
954- /* ECXがゼロではないことを確認すべき */
955- jitCompPutByte2(w.dst, 0xf7, 0xf9); /* IDIV(ECX); */
956- if (*src == 0x1a) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 0 /* EAX */); }
957- if (*src == 0x1b) { jitCompA0001_movEbpDispReg32(&w, src[1] * 4, 2 /* EDX */); }
958- jitCompA000_loadRegCacheAll(&w); // 手抜き.
959- cmp0reg = -1;
960- break;
961-
962- case 0x1c: /* PLMT0 */
963- case 0x1d: /* PLMT1 */
964- if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
965- if (level < JITC_LV_FASTEST) {
966- cmp0reg = -1;
967- if (level < JITC_LV_FASTER) {
968- // typ が一致していることを確認.
969- // plsとliveSignが一致していることを確認.
970-
971- // preg1はp0 <= p <= p1 を満たしているか?.
972- // 新しいp0/p1は古いp0〜p1に適合しているか?.
973-
974- }
975- }
976-
977- case 0x1e: /* PCP */ /* 未完成(p1まで完成) */
978- if (src[1] >= 0x40 || src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
979- if (src[2] == 0x3f) w.err = JITC_ERR_PREGNUM;
980- if (src[1] != 0x3f) {
981- /* src[2] == 0xff の場合に対応できてない */
982- jitCompA000_storePRegCacheAll(&w); // 手抜き.
983- for (i = 0; i < 32; i += 4) {
984- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + i); /* MOV(EAX, [EBP+?]); */
985- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
986- }
987- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
988- }
989- else {
990- if (level < JITC_LV_FASTER) {
991- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 4); /* MOV(EAX, [EBP+?]); */ /* typ */
992- jitCompPutByte3(w.dst, 0x83, 0xf8, 0); /* CMP(EAX, 0); */
993- jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */
994- jitCompPutImm32(&w, errfnc - (w.dst + 4));
995- /* セキュリティチェックが足りてない!(aliveとか) */
996- }
997- reg0 = 0; /* EAX */
998- jitCompA000_storePRegCacheAll(&w); // 手抜き.
999- jitCompA0001_movReg32EbpDisp(&w, reg0, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */
1000- if (level < JITC_LV_FASTER) {
1001- jitCompPutByte1(w.dst, 0x3b); /* CMP(reg0, [EBP+?]); */
1002- jitCompA0001_85DispN(&w, 256 + src[2] * 32 + 8, reg0); /* p0 */
1003- jitCompPutByte2(w.dst, 0x0f, 0x85); /* JNE */
1004- jitCompPutImm32(&w, errfnc - (w.dst + 4));
1005- }
1006- jitCompPutByte2(w.dst, 0xff, 0xe0); /* JMP(EAX); */
1007- }
1008- break;
1009-
1010- case 0x1f: /* PCST */
1011- if (jitCompGetImm32(src + 2) == 0) {
1012- if (level < JITC_LV_FASTER)
1013- jitCompA0001_checkType0(&w, src[6], jitCompGetImm32(src + 7), 2);
1014- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1015- for (i = 0; i < 32 - 4; i += 4) {
1016- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
1017- if (i == 4) {
1018- jitCompPutByte1(w.dst, 0x0d); /* OR(EAX, ?); */
1019- jitCompPutImm32(&w, 0x80000000);
1020- }
1021- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1022- }
1023- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
1024- jitCompPutImm32(&w, debugInfo1);
1025- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 28, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1026- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1027- cmp0reg = -1;
1028- break;
1029- }
1030- if (jitCompGetImm32(src + 7) == 0) {
1031- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1032- for (i = 0; i < 32 - 4; i += 4) {
1033- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + i); /* MOV(EAX, [EBP+?]); */
1034- if (i == 4) {
1035- jitCompPutByte1(w.dst, 0x25); /* AND(EAX, ?); */
1036- jitCompPutImm32(&w, 0x7fffffff);
1037- }
1038- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + i, 0 /* EAX */); /* MOV([EBP+?], EAX); */
1039- }
1040- if (level < JITC_LV_FASTER) {
1041- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[6] * 32 + 28); /* MOV(EAX, [EBP+?]); */
1042- jitCompPutByte1(w.dst, 0x3d); /* CMP(EAX, ?); */
1043- jitCompPutImm32(&w, debugInfo1);
1044- jitCompPutByte2(w.dst, 0x74, 8); /* JE */
1045- jitCompPutByte2(w.dst, 0x31, 0xc0); /* XOR(EAX, EAX); (2) */
1046- jitCompA0001_movEbpDispReg32(&w, 256 + src[1] * 32 + 0, 0 /* EAX */); /* MOV([EBP+?], EAX); (1+1+4) */
1047- }
1048- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1049- cmp0reg = -1;
1050- break;
1051- }
1052- w.err = JITC_ERR_OPECODE;
1053- goto err_w;
1054-
1055- case 0x20: /* CMPE */
1056- case 0x21: /* CMPNE */
1057- case 0x22: /* CMPL */
1058- case 0x23: /* CMPGE */
1059- case 0x24: /* CMPLE */
1060- case 0x25: /* CMPG */
1061- case 0x26: /* TSTZ */
1062- case 0x27: /* TSTNZ */
1063- reg0 = jitCompA000_selectRegCache(src[2], 0 /* EAX */);
1064- reg1 = jitCompA000_selectRegCache(src[3], -1 /* mem */);
1065- if (src[1] == 0x3f) {
1066- /* 特殊構文チェック */
1067- if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1068- if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) {
1069- w.err = JITC_ERR_IDIOM; goto err_w;
1070- }
1071- }
1072- if (reg0 == 0)
1073- jitCompA0001_movEaxRxx(&w, src[2]);
1074-#if (jitCompA0001_USE_R3F_IMM32 != 0)
1075- if (src[3] == 0x3f) {
1076-#if (jitCompA0001_OPTIMIZE_CMP != 0)
1077- if ((*src <= 0x25 && w.r3f == 0) || (*src >= 0x26 && w.r3f == -1)) {
1078- i = 0;
1079- if (cmp0reg == src[2]) {
1080- if (cmp0lev >= 1 && (src[0] == 0x20 || src[0] == 0x21 || src[0] == 0x26 || src[0] == 0x27))
1081- i = 1;
1082- if (cmp0lev >= 2 && (src[0] == 0x22 || src[0] == 0x23 || src[0] == 0x24 || src[0] == 0x25))
1083- i = 1;
1084- }
1085- if (i == 0) {
1086- jitCompPutByte2(w.dst, 0x85, 0xc0 | reg0 << 3 | reg0); /* TEST(reg0, reg0); */
1087- }
1088- cmp0reg = src[2];
1089- cmp0lev = 2;
1090- goto cmpcc1;
1091- }
1092-#endif
1093-#if (jitCompA0001_USE_R3F_IMM8 != 0)
1094- if (-0x80 <= w.r3f && w.r3f <= 0x7f && *src <= 0x25) {
1095- jitCompPutByte3(w.dst, 0x83, 0xf8 | reg0, w.r3f);
1096- goto cmpcc1;
1097- }
1098-#endif
1099- if (reg0 == 0) {
1100- if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3d); }
1101- if (*src >= 0x26) { jitCompPutByte1(w.dst, 0xa9); }
1102- }
1103- else {
1104- if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x81, 0xf8 | reg0); }
1105- if (*src >= 0x26) { jitCompPutByte2(w.dst, 0xf7, 0xc0 | reg0); }
1106- }
1107- jitCompPutImm32(&w, w.r3f);
1108- goto cmpcc1;
1109- }
1110-#endif
1111- if (src[3] >= 0x40) w.err = JITC_ERR_PREGNUM;
1112- if (reg1 >= 0) {
1113- if (*src <= 0x25) { jitCompPutByte2(w.dst, 0x39, 0xc0 | reg1 << 3 | reg0); }
1114- if (*src >= 0x26) { jitCompPutByte2(w.dst, 0x85, 0xc0 | reg1 << 3 | reg0); }
1115- }
1116- else {
1117- if (*src <= 0x25) { jitCompPutByte1(w.dst, 0x3b); }
1118- if (*src >= 0x26) { jitCompPutByte1(w.dst, 0x85); }
1119- jitCompA0001_85DispN(&w, src[3] * 4, reg0);
1120- }
1121- cmpcc1:
1122- if (w.err != 0) goto err_w;
1123- static unsigned char cmpcc_table0[] = {
1124- 0x04, 0x05, 0x0c, 0x0d, 0x0e, 0x0f, 0x04, 0x05, /* CMPcc, TSTcc */
1125- 0x04, 0x05, 0x02, 0x03, 0x06, 0x07 /* PCMPcc */
1126- };
1127-#if (jitCompA0001_USE_R3F_CMPJMP != 0)
1128- if (src[1] == 0x3f) {
1129- /* 特殊構文を利用した最適化 */
1130- jitCompPutByte2(w.dst, 0x0f, 0x80 | cmpcc_table0[*src - 0x20]);
1131- src += 6;
1132- i = jitCompGetLabelNum(&w, src + 2);
1133- if ((flags & JITC_PHASE1) != 0 && w.err != 0) {
1134- if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }
1135- // if (label[i].typ != 1) { w.err = JITC_ERR_LABELTYP; goto err_w; }
1136- }
1137- j = 0;
1138- if ((flags & JITC_PHASE1) != 0 || ((flags & JITC_PHASE1) == 0) && label[i].opt != 0)
1139- j = label[i].p - (w.dst + 4);
1140- jitCompPutImm32(&w, j);
1141-#if (jitCompA0001_OPTIMIZE_JMP != 0)
1142- if (-128 - 4 <= j && j < 0) {
1143- j += 4;
1144- w.dst -= 6;
1145- jitCompPutByte2(w.dst, w.dst[1] ^ 0xf0, j & 0xff);
1146- }
1147-#endif
1148- src += 6;
1149- if (w.err != 0) goto err_w;
1150- continue;
1151- }
1152-#endif
1153- /* 一般的なJITC */
1154- reg0 = jitCompA000_selectRegCache(src[1], 0 /* EAX */);
1155- jitCompPutByte3(w.dst, 0x0f, 0x90 | cmpcc_table0[*src - 0x20], 0xc0 | reg0); /* SETcc(BYTE(reg0)); */
1156- jitCompPutByte3(w.dst, 0x0f, 0xb6, 0xc0 | reg0 << 3 | reg0); /* MOVZX(reg0, BYTE(reg0)); */
1157- jitCompPutByte2(w.dst, 0xf7, 0xd8 | reg0); /* NEG(reg0); */
1158- if (reg0 == 0)
1159- jitCompA0001_movRxxEax(&w, src[1]);
1160- cmp0reg = src[2];
1161- cmp0lev = 1;
1162- break;
1163-
1164- case 0x28: /* PCMPE */
1165- case 0x29: /* PCMPNE */
1166- case 0x2a: /* PCMPL */
1167- case 0x2b: /* PCMPGE */
1168- case 0x2c: /* PCMPLE */
1169- case 0x2d: /* PCMPG */
1170- if (src[1] == 0x3f) {
1171- /* 特殊構文チェック */
1172- if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1173- if (src[4] != 0x04 || src[5] != 0x3f || src[6] != 0x03 || src[7] != 0x3f) {
1174- w.err = JITC_ERR_IDIOM; goto err_w;
1175- }
1176- }
1177- if (src[2] >= 0x40) w.err = JITC_ERR_PREGNUM;
1178- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1179- if (src[3] != 0xff)
1180- jitCompA0001_checkCompPtr(&w, src[2], src[3]);
1181- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + src[2] * 32 + 0); /* MOV(EAX, [EBP+?]); */
1182- if (src[3] != 0xff) {
1183- jitCompPutByte1(w.dst, 0x3b); /* CMP(EAX, [EBP+?]); */
1184- jitCompA0001_85DispN(&w, 256 + src[3] * 32 + 0, 0);
1185- }
1186- else {
1187- /* ヌルポインタとの比較はこれでいいのか?たぶんよくない */
1188- jitCompPutByte3(w.dst, 0x83, 0xf8, 0x00); /* CMP(EAX, 0); */
1189- }
1190- cmp0reg = -1;
1191- goto cmpcc1;
1192-
1193- case 0x30: /* talloc(old:F4) */
1194- case 0x31: /* tfree(old:F5) */
1195- case 0x32: /* malloc(old:F6) */
1196- case 0x33: /* mfree(old:F7) */
1197- jitCompA000_storeRegCacheAll(&w); // 手抜き.
1198- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1199- jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */
1200- jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */
1201- jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */
1202- jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */
1203- jitCompPutByte1(w.dst, 0xe8);
1204- if (*src == 0x30) j = ((unsigned char *)&funcf4) - (w.dst + 4);
1205- if (*src == 0x31) j = ((unsigned char *)&funcf5) - (w.dst + 4);
1206- if (*src == 0x32) j = ((unsigned char *)&funcf6) - (w.dst + 4);
1207- if (*src == 0x33) j = ((unsigned char *)&funcf7) - (w.dst + 4);
1208- jitCompPutImm32(&w, j);
1209- jitCompPutByte3(w.dst, 0x83, 0xc4, 0x10); /* ADD(ESP,16); */
1210- jitCompA000_loadRegCacheAll(&w); // 手抜き.
1211- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1212- cmp0reg = -1;
1213- break;
1214-
1215- case 0x34: /* data (暫定) */
1216- cmp0reg = -1;
1217- if (w.prefix != 0) { w.err = JITC_ERR_PREFIX; goto err_w; }
1218- int k = jitCompGetImm32(&src[1]), tmpData, bitCount, dataWidth = jitCompA000_dataWidth(k);
1219- if (lastlabel >= 0 && label[lastlabel].typ == 0)
1220- label[lastlabel].typ = k;
1221- if (k != 1) {
1222- i = jitCompA000_convTyp(k);
1223- if (i < 2 || i > 7) { w.err = JITC_ERR_BADTYPE; goto err_w; }
1224- }
1225- j = jitCompGetImm32(&src[5]);
1226- oldsrc = src;
1227- src += 9;
1228- if (k != 1) {
1229- bitCount = 7;
1230- while (j > 0) {
1231- if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; }
1232- if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; }
1233- tmpData = 0;
1234- for (k = 0; k < dataWidth; k++) {
1235- tmpData = tmpData << 1 | ((*src >> bitCount) & 1);
1236- bitCount--;
1237- if (bitCount < 0) {
1238- bitCount = 7;
1239- src++;
1240- }
1241- }
1242- if ((i & 1) == 0 && dataWidth <= 31 && (tmpData >> (dataWidth - 1)) != 0) {
1243- tmpData -= 1 << dataWidth;
1244- }
1245- if (i == 2 || i == 3) { jitCompPutByte1(w.dst, tmpData & 0xff); }
1246- if (i == 4 || i == 5) { jitCompPutByte2(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff); }
1247- if (i == 6 || i == 7) { jitCompPutByte4(w.dst, tmpData & 0xff, (tmpData >> 8) & 0xff, (tmpData >> 16) & 0xff, (tmpData >> 24) & 0xff); }
1248- j--;
1249- }
1250- }
1251- else {
1252- while (j > 0) {
1253- if (src >= src1) { w.err = JITC_ERR_SRC1; src = oldsrc; goto err_w; }
1254- if (w.dst + 256 > dst1) { w.err = JITC_ERR_DST1; src = oldsrc; goto err_w; }
1255- i = jitCompGetImm32(src);
1256- src += 4;
1257- if ((flags & JITC_PHASE1) != 0 && w.err == 0) {
1258- if (label[i].opt == 0) { w.err = JITC_ERR_LABELNODEF; goto err_w; }
1259- }
1260- jitCompPutImm32(&w, (int)label[i].p);
1261- jitCompPutImm32(&w, label[i].typ);
1262- jitCompPutImm32(&w, (int)label[i].p);
1263- jitCompPutImm32(&w, (int)label[i].p1);
1264- jitCompPutImm32(&w, 0); /* liveSign */
1265- jitCompPutImm32(&w, 2320); /* pls */
1266- jitCompPutImm32(&w, 0);
1267- jitCompPutImm32(&w, 0);
1268- j--;
1269- }
1270- }
1271- if (lastlabel >= 0 && label[lastlabel].p1 < w.dst)
1272- label[lastlabel].p1 = w.dst;
1273- continue;
1274-
1275- case 0x3c: /* ENTER */
1276- jitCompA000_storeRegCacheAll(&w); // 手抜き.
1277- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1278- jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */
1279- jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */
1280- jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */
1281- jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */
1282- jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */
1283- jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */
1284- jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */
1285- jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */
1286- jitCompPutByte1(w.dst, 0xe8);
1287- j = ((unsigned char *)&func3c) - (w.dst + 4);
1288- jitCompPutImm32(&w, j);
1289- jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */
1290- jitCompA000_loadRegCacheAll(&w); // 手抜き.
1291- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1292- cmp0reg = -1;
1293- break;
1294-
1295- case 0x3d: /* LEAVE */
1296- jitCompA000_storeRegCacheAll(&w); // 手抜き.
1297- jitCompA000_storePRegCacheAll(&w); // 手抜き.
1298- jitCompPutByte2(w.dst, 0x6a, src[6]); /* PUSH(?); */
1299- jitCompPutByte2(w.dst, 0x6a, src[5]); /* PUSH(?); */
1300- jitCompPutByte2(w.dst, 0x6a, src[4] & 0x0f); /* PUSH(?); */
1301- jitCompPutByte2(w.dst, 0x6a, (src[4] >> 4) & 0x0f); /* PUSH(?); */
1302- jitCompPutByte2(w.dst, 0x6a, src[3]); /* PUSH(?); */
1303- jitCompPutByte2(w.dst, 0x6a, src[2]); /* PUSH(?); */
1304- jitCompPutByte2(w.dst, 0x6a, src[1]); /* PUSH(?); */
1305- jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */
1306- jitCompPutByte1(w.dst, 0xe8);
1307- j = ((unsigned char *)&func3d) - (w.dst + 4);
1308- jitCompPutImm32(&w, j);
1309- jitCompPutByte3(w.dst, 0x83, 0xc4, 0x20); /* ADD(ESP,32); */
1310- jitCompA000_loadRegCacheAll(&w); // 手抜き.
1311- jitCompA000_loadPRegCacheAll(&w); // 手抜き.
1312- cmp0reg = -1;
1313- break;
1314-
1315- case 0xfe: /* remark */
1316- if (src[1] == 0x01 && src[2] == 0x00) { // DBGINFO1
1317- if (level <= JITC_LV_SLOWER) {
1318- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
1319- jitCompPutImm32(&w, debugInfo1);
1320- jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
1321- }
1322- }
1323- if (src[1] == 0x01 && src[2] == 0x03) { // DBGINFO1CLR
1324- if (level <= JITC_LV_SLOWER) {
1325- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
1326- jitCompPutImm32(&w, -1);
1327- jitCompA0001_movEbpDispReg32(&w, 2304 + 4, 0 /* EAX */); /* MOV(debugInfo1, EAX); */
1328- }
1329- }
1330- if (src[1] == 0x05 && src[2] == 0x00) { // DBGINFO0
1331- if (level <= JITC_LV_SLOWEST) {
1332- debugInfo0 = jitCompGetImm32(src + 3);
1333- // jitCompPutByte1(w.dst, 0xbf); /* MOV(EDI, ?); */
1334- // jitCompPutImm32(&w, debugInfo0);
1335- jitCompPutByte1(w.dst, 0xb8); /* MOV(EAX, ?); */
1336- jitCompPutImm32(&w, debugInfo0);
1337- jitCompA0001_movEbpDispReg32(&w, 2304 + 0, 0 /* EAX */); /* MOV(debugInfo0, EAX); */
1338- }
1339- }
1340- break;
1341-
1342- default:
1343- w.err = JITC_ERR_OPECODE;
1344- goto err_w;
1345- }
1346- if (w.err != 0) goto err_w;
1347- jitCompA0001_fixPrefix(&w);
1348- if (w.err != 0) goto err_w;
1349- src += jitCompCmdLen(src);
1350- }
1351- if (enter0 != NULL) {
1352- j = w.dst - (enter0 + 4);
1353- enter0[0] = j & 0xff;
1354- enter0[1] = (j >> 8) & 0xff;
1355- enter0[2] = (j >> 16) & 0xff;
1356- enter0[3] = (j >> 24) & 0xff;
1357- }
1358- if ((flags & JITC_NOSTARTUP) == 0) {
1359- jitCompA000_storeRegCacheAll(&w);
1360- jitCompA000_storePRegCacheAll(&w);
1361- jitCompPutByte1(w.dst, 0x61); /* POPAD(); */
1362- }
1363- if ((flags & JITC_PHASE1) != 0)
1364- return w.dst - dst00;
1365- return 0;
1366-
1367-err_w:
1368- if ((w.err & JITC_ERR_PHASE0ONLY) != 0) {
1369- if ((flags & JITC_PHASE1) == 0)
1370- w.err &= ~JITC_ERR_PHASE0ONLY;
1371- }
1372- if (w.err == (JITC_ERR_MASK & JITC_ERR_REGNUM)) errmsg = "reg-number error";
1373- if (w.err == (JITC_ERR_MASK & JITC_ERR_DST1)) errmsg = "dst1 error";
1374- if (w.err == (JITC_ERR_MASK & JITC_ERR_OPECODE)) errmsg = "opecode error";
1375- if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELNUM)) errmsg = "label number too large";
1376- if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELREDEF)) errmsg = "label redefine";
1377- if (w.err == (JITC_ERR_MASK & JITC_ERR_PREFIX)) { errmsg = "prefix redefine"; w.dst -= 2; }
1378- if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELNODEF)) errmsg = "label not defined";
1379- if (w.err == (JITC_ERR_MASK & JITC_ERR_LABELTYP)) errmsg = "label type error";
1380- if (w.err == (JITC_ERR_MASK & JITC_ERR_IDIOM)) errmsg = "idiom error";
1381- if (w.err == (JITC_ERR_MASK & JITC_ERR_PREGNUM)) errmsg = "preg-number error";
1382- if (w.err == (JITC_ERR_MASK & JITC_ERR_SRC1)) errmsg = "src1 error";
1383- if (w.err == (JITC_ERR_MASK & JITC_ERR_BADTYPE)) errmsg = "bad type code";
1384- if (w.err == (JITC_ERR_MASK & JITC_ERR_PREFIXFAR)) errmsg = "prefix internal error";
1385- if (w.err == (JITC_ERR_MASK & JITC_ERR_INTERNAL)) errmsg = "general internal error";
1386- if (*errmsg != '\0') {
1387- fprintf(stderr, "JITC: %s at %06X (debugInfo0=%d)\n ", errmsg, src - src0, debugInfo0);
1388- for (i = 0; i < 16; i++)
1389- fprintf(stderr, "%02X ", src[i]);
1390- static char *table[0x30] = {
1391- "NOP", "LB", "LIMM", "PLIMM", "CND", "??", "??", "??",
1392- "LMEM", "SMEM", "PLMEM", "PSMEM", "LEA", "??", "PADD", "PDIF",
1393- "CP/OR", "XOR", "AND", "??", "ADD", "SUB", "MUL", "??",
1394- "SHL", "SAR", "DIV", "MOD", "PLMT0", "PLMT1", "PCP", "PCST",
1395- "CMPE", "CMPNE", "CMPL", "CMPGE", "CMPLE", "CMPG", "TSTZ", "TSTNZ",
1396- "PCMPE", "PCMPNE", "PCMPL", "PCMPGE", "PCMPLE", "PCMPG", "??", "EXT" };
1397- errmsg = "??";
1398- if (*src < 0x30) errmsg = table[*src];
1399- fprintf(stderr, "(%s)\n", errmsg);
1400- }
1401- return -1;
1402-}
1403-
1404-unsigned char *jitCompCallFunc(unsigned char *dst, void *func)
1405-{
1406- struct JitCompWork w;
1407- w.dst = dst;
1408- jitCompA000_storeRegCacheAll(&w);
1409- jitCompA000_storePRegCacheAll(&w);
1410- jitCompPutByte1(w.dst, 0x60); /* PUSHAD(); */
1411- jitCompPutByte1(w.dst, 0x50); /* PUSH(EAX); */ /* for 16byte-align(win32では不要なのだけど、MacOSには必要らしい) */
1412- jitCompPutByte1(w.dst, 0x55); /* PUSH(EBP); */
1413- jitCompPutByte1(w.dst, 0xe8); /* CALL(func); */
1414- int j = ((unsigned char *)func) - (w.dst + 4);
1415- jitCompPutImm32(&w, j);
1416- jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */ /* (win32では不要なのだけど、MacOSには必要らしい) */
1417- jitCompPutByte1(w.dst, 0x58); /* POP(EAX); */
1418- jitCompPutByte1(w.dst, 0x61); /* POPAD(); */
1419- jitCompA000_loadRegCacheAll(&w);
1420- jitCompA000_loadPRegCacheAll(&w);
1421- jitCompA0001_movReg32EbpDisp(&w, 0 /* EAX */, 256 + 0x30 * 32 + 0); /* MOV(EAX, [EBP+?]); */
1422- jitCompPutByte2(w.dst, 0xff, 0xe0); /* JMP(EAX); */
1423- return w.dst;
1424-}
1425-
1426-unsigned char *jitCompInit(unsigned char *dst)
1427-{
1428- errfnc = dst;
1429- return jitCompCallFunc(dst, &errHndl);
1430-}
1431-
1432-void func3c(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0)
1433-{
1434- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1435- int i, *pi;
1436- struct Ptr *pp;
1437- if (r->junkStack + 2048 > r->junkStack1) (*(r->errHndl))(r);
1438- pi = (void *)r->junkStack; r->junkStack += r1 * 4;
1439- for (i = 0; i < r1; i++)
1440- pi[i] = r->ireg[i];
1441- pp = (void *)r->junkStack; r->junkStack += p1 * 32;
1442- for (i = 0; i < p1; i++)
1443- pp[i] = r->preg[i];
1444- pp = (void *)r->junkStack; r->junkStack += 32;
1445- *pp = r->preg[0x30];
1446- pi = (void *)r->junkStack; r->junkStack += 4;
1447- *pi = opt << 16 | r1 << 8 | p1;
1448- for (i = 0; i < lenR; i++)
1449- r->ireg[r0 + i] = r->ireg[0x30 + i];
1450- for (i = 0; i < lenP; i++)
1451- r->preg[p0 + i] = r->preg[0x31 + i];
1452- return;
1453-}
1454-
1455-void func3d(char *ebp, int opt, int r1, int p1, int lenR, int lenP, int r0, int p0)
1456-{
1457- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1458- int i;
1459- r->junkStack -= 4;
1460- r->junkStack -= 32; struct Ptr *pp = (void *)r->junkStack;
1461- r->preg[0x30] = *pp;
1462- r->junkStack -= p1 * 32; pp = (void *)r->junkStack;
1463- for (i = 0; i < p1; i++)
1464- r->preg[i] = pp[i];
1465- r->junkStack -= r1 * 4; int *pi = (void *)r->junkStack;
1466- for (i = 0; i < r1; i++)
1467- r->ireg[i] = pi[i];
1468- return;
1469-}
1470-
1471-void funcf4(char *ebp, int pxx, int typ, int len)
1472-{
1473- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1474- int width = jitCompA000_dataWidth(jitCompA000_convTyp(r->ireg[typ])) >> 3;
1475- if (width < 0 || r->ireg[len] < 0)
1476- (*(r->errHndl))(r);
1477- void *p = r->junkStack;
1478- if (r->junkStack + width * r->ireg[len] + 256 > r->junkStack1) (*(r->errHndl))(r);
1479- r->junkStack += width * r->ireg[len];
1480- r->preg[pxx].p = p;
1481- r->preg[pxx].typ = r->ireg[typ];
1482- r->preg[pxx].p0 = p;
1483- r->preg[pxx].p1 = (void *)r->junkStack;
1484- int *pi = (int *)r->junkStack;
1485- *pi = width * r->ireg[len];
1486- r->junkStack += sizeof (int);
1487- if (r->ireg[typ] == 1) {
1488- int i, i1 = (width * r->ireg[len]) >> 2;
1489- pi = p;
1490- for (i = 0; i < i1; i++)
1491- pi[i] = 0;
1492- }
1493- return;
1494-}
1495-
1496-void funcf5(char *ebp, int pxx, int typ, int len)
1497-{
1498- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1499- r->junkStack -= sizeof (int);
1500- int *pi = (int *)r->junkStack;
1501- r->junkStack -= *pi;
1502-#if 0
1503- int width = jitCompA000_dataWidth(r->ireg[typ]);
1504- void *p = r->junkStack;
1505- r->junkStack -= width * r->ireg[len];
1506-#endif
1507- return;
1508-}
1509-
1510-void funcf6(char *ebp, int pxx, int typ, int len)
1511-{
1512- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1513- int width = jitCompA000_dataWidth(jitCompA000_convTyp(r->ireg[typ])) >> 3;
1514- if (width < 0 || r->ireg[len] < 0)
1515- (*(r->errHndl))(r);
1516- void *p = malloc(width * r->ireg[len]);
1517- r->preg[pxx].p = p;
1518- r->preg[pxx].typ = r->ireg[typ];
1519- r->preg[pxx].p0 = p;
1520- r->preg[pxx].p1 = (unsigned char *)p + width * r->ireg[len];
1521- if (r->ireg[typ] == 1) {
1522- int i, i1 = (width * r->ireg[len]) >> 2, *pi;
1523- pi = p;
1524- for (i = 0; i < i1; i++)
1525- pi[i] = 0;
1526- for (i = 1; i < i1; i += 8)
1527- pi[i] |= -1;
1528- }
1529- return;
1530-}
1531-
1532-void funcf7(char *ebp, int pxx, int typ, int len)
1533-{
1534- struct Regs *r = (struct Regs *) (ebp - jitCompA0001_EBP128);
1535- free(r->preg[pxx].p);
1536- return;
1537-}
1538-
1539-void errHndl(struct Regs *r)
1540-{
1541- r = (struct Regs *) (((char *)r) - jitCompA0001_EBP128);
1542- (*(r->errHndl))(r);
1543- // ここに帰ってきてはいけない.
1544-}
1545-
1546-int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, struct LabelTable *label)
1547-{
1548- unsigned char *q = *qq;
1549- if (p0[0] != 0x05 || p0[1] != SIGN1)
1550- return 1;
1551-
1552- *q++ = 0x55; /* PUSH(EBP); */
1553- *q++ = 0x8b; *q++ = 0x6c; *q++ = 0x24; *q++ = 0x08; /* MOV(EBP,[ESP+8]); */
1554-
1555- int i;
1556- for (i = 0; i < JITC_MAXLABELS; i++)
1557- label[i].opt = 0;
1558-
1559- i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, 0);
1560- if (i != 0) return 2;
1561- i = jitCompiler(q, q1, p0 + 2, p1, p0, label, JITC_MAXLABELS, level, di1_serial, JITC_PHASE1 + 0);
1562- if (i < 0) return 2;
1563- q += i;
1564-
1565- *q++ = 0x5d; /* POP(EBP); */
1566- *q++ = 0xc3; /* RET(); */
1567-
1568- *qq = q;
1569- return 0;
1570-}
1571-
1572-#if (USE_DEBUGGER != 0)
1573-
1574-int dbgrGetRegNum(const unsigned char *p)
1575-{
1576- int i, j, r = -1;
1577- if (p[2] <= ' ') {
1578- i = p[0] - '0';
1579- j = p[1] - '0';
1580- if (i > 9) i -= 'A' - '0' - 10;
1581- if (j > 9) j -= 'A' - '0' - 10;
1582- if (0 <= i && i <= 15 && 0 <= j && j <= 15)
1583- r = i << 4 | j;
1584- }
1585- return r;
1586-}
1587-
1588-void dbgrMain(struct Regs *r)
1589-{
1590- if (r->dbgr == 0) return;
1591- for (;;) {
1592- unsigned char cmd[64], *p;
1593- int i, j, k;
1594- printf("\ndbgr>");
1595- p = fgets(cmd, 64, stdin);
1596- if (p == NULL) break;
1597- if (cmd[0] == '\0') continue;
1598- if (cmd[0] == 'q' && cmd[1] <= ' ') break;
1599- if (cmd[0] == 'p' && cmd[1] <= ' ' && cmd[1] != '\0') {
1600- p = &cmd[2];
1601- while (*p <= ' ' && *p != '\0') p++;
1602- if (*p == 'R') {
1603- i = dbgrGetRegNum(p + 1);
1604- if (0 <= i && i <= 0x3f) {
1605- printf("R%02X = 0x%08X = %d\n", i, r->ireg[i], r->ireg[i]);
1606- }
1607- else
1608- puts("register name error");
1609- continue;
1610- }
1611- if (*p == 'P') {
1612- i = dbgrGetRegNum(p + 1);
1613- if (0 <= i && i <= 0x3f) {
1614- p = "invalid";
1615- if (0 <= r->preg[i].typ && r->preg[i].typ <= 0x15) {
1616- static unsigned char *typName[] = {
1617- "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8",
1618- "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32",
1619- "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2",
1620- "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12",
1621- "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24",
1622- "T_SINT28", "T_UINT28"
1623- };
1624- p = typName[r->preg[i].typ];
1625- }
1626- printf("P%02X:\n type = %s(%04X), (origin-ptr) = 0x%08X\n", i, p, r->preg[i].typ, r->preg[i].p0);
1627- if (r->preg[i].p != NULL && r->preg[i].p0 != NULL) {
1628- j = jitCompA000_dataWidth(jitCompA000_convTyp(r->preg[i].typ)) >> 3;
1629- if (j <= 0) j = 1;
1630- k = (r->preg[i].p1 - r->preg[i].p0) / j;
1631- printf(" size = 0x%08X = %d\n", k, k);
1632- k = (r->preg[i].p - r->preg[i].p0) / j;
1633- printf(" pos = 0x%08X = %d\n", k, k);
1634- }
1635- else {
1636- puts(" null pointer");
1637- }
1638- }
1639- else
1640- puts("register name error");
1641- continue;
1642- }
1643- }
1644- puts("command error");
1645- }
1646- return;
1647-}
1648-
1649-#endif
1650-
1651-
1652-#endif
1653-
1654-
1655-
--- a/HeavyOSECPU/jitc.h
+++ /dev/null
@@ -1,23 +0,0 @@
1-#ifndef _HDLOAD_JITC
2-#define _HDLOAD_JITC 1
3-
4-/* JITCのフラグ群 */
5-#define JITC_LV_SLOWEST 0 /* デバッグ支援は何でもやる */
6-#define JITC_LV_SLOWER 1 /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
7-#define JITC_LV_SAFE 2 /* とにかく止まる、場所は不明、テストは必要最小限 */
8-#define JITC_LV_FASTER 4 /* 情報は生成するがチェックをしない */
9-#define JITC_LV_FASTEST 5 /* 情報すら生成しない */
10-#define JITC_PHASE1 0x0001
11-#define JITC_SKIPCHECK 0x0002 /* セキュリティチェックを省略する(高速危険モード) */
12-#define JITC_NOSTARTUP 0x0004
13-#define JITC_MAXLABELS 4096
14-#define PTRCTRLSIZ 4096
15-
16-
17-int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, struct LabelTable *label);
18-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);
19-unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
20-unsigned char *jitCompInit(unsigned char *dst);
21-void errorHandler(struct Regs *r);
22-
23-#endif
--- a/HeavyOSECPU/main.c
+++ /dev/null
@@ -1,250 +0,0 @@
1-#include "osecpu.h"
2-
3-void putKeybuf(int i)
4-{
5- if (keybuf_c < KEYBUFSIZ) {
6- keybuf[keybuf_w] = i;
7- keybuf_c++;
8- keybuf_w = (keybuf_w + 1) & (KEYBUFSIZ - 1);
9- }
10- return;
11-}
12-
13-int osecpuMain(int argc, char **argv)
14-{
15- unsigned char *appbin = malloc(APPSIZ1), *up;
16- unsigned char *jitbuf = mallocRWE(1024 * 1024); /* とりあえず1MBで */
17- unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0;
18- unsigned char *systmp0 = malloc(SYSTMP0SIZ);
19- unsigned char *systmp1 = malloc(SYSTMP1SIZ);
20- unsigned char *systmp2 = malloc(1024 * 1024), *opTbl = malloc(256);
21- struct LabelTable *label = malloc(JITC_MAXLABELS * sizeof (struct LabelTable));
22- int level = JITC_LV_SLOWEST, tmpsiz, i;
23- keybuf = malloc(KEYBUFSIZ * sizeof (int));
24- keybuf_r = keybuf_w = keybuf_c = 0;
25- jmp_buf setjmpEnv;
26- double tm0, tm1, tm2;
27- struct PtrCtrl *ptrCtrl = malloc(PTRCTRLSIZ * sizeof (struct PtrCtrl));
28-
29- randStatInit((unsigned int)time(NULL));
30- for (i = 0; i < PTRCTRLSIZ; i++) {
31- ptrCtrl[i].liveSign = 0;
32- ptrCtrl[i].size = -1;
33- }
34- ptrCtrl[0].size = -2;
35-
36- /* syslibの読み込み */
37- unsigned char *syslib = malloc(SYSLIBSIZ1);
38- int appsiz0, appsiz1;
39- FILE *fp = fopen(SYSLIB_OSE, "rb");
40- if (fp == NULL) {
41- syslib[0] = '/';
42- strcpy(syslib + 1, argv[0]);
43- up = syslib + 1;
44- while (*up != '\0') up++;
45- while (*up != '/' && *up != 0x5c) up--;
46- up++;
47- strcpy(up, SYSLIB_OSE);
48- fp = fopen(syslib + 1, "rb");
49- }
50- if (fp == NULL) {
51- fputs("syslib-file fopen error.\n", stderr);
52- return 1;
53- }
54- appsiz0 = fread(syslib, 1, SYSLIBSIZ1 - 4, fp);
55- fclose(fp);
56- if (appsiz0 >= SYSLIBSIZ1 - 4) {
57- fputs("syslib-file too large.\n", stderr);
58- return 1;
59- }
60- if (syslib[0] == 0x05 && syslib[1] == 0xc1) {
61- memcpy(systmp0, syslib, appsiz0);
62- ComLib_main(systmp0 + 2, syslib + 2);
63- syslib[0] = 0x05;
64- syslib[1] = 0x1b;
65- }
66-
67- sysjit1 = jitCompInit(sysjit1);
68- sysjit0 = sysjit1;
69- i = jitc0(&sysjit1, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_SLOWEST + 9, label);
70- if (i != 0) {
71- fputs("syslib-file JITC error.\n", stderr);
72- return 1;
73- }
74- di1_serial++;
75-
76- /* アプリバイナリの読み込み */
77- if (argc <= 1) { return 0; }
78- const unsigned char *argv1 = argv[1];
79- if (argv1[0] == ':' && argv1[2] == ':') {
80- level = argv1[1] - '0';
81- if (level < 0 || level > 9)
82- level = JITC_LV_SLOWEST;
83- argv1 += 3;
84- }
85- fp = fopen(argv1, "rb");
86- if (fp == NULL) {
87- fputs("app-file load error.\n", stderr);
88- return 1;
89- }
90- appsiz1 = appsiz0 = fread(appbin, 1, APPSIZ1 - 4, fp);
91- fclose(fp);
92- if (appsiz0 >= APPSIZ1 - 4) {
93- fputs("app-file too large.\n", stderr);
94- return 1;
95- }
96- if (appsiz0 < 3) {
97- header_error:
98- fputs("app-file header error.\n", stderr);
99- return 1;
100- }
101-
102- tm0 = clock() / (double)CLOCKS_PER_SEC;
103-
104- if (appbin[2] == 0xf0) {
105-#if (USE_TEK5 != 0)
106- appsiz1 = tek5Decomp(appbin + 2, appbin + appsiz0, systmp0) + 2;
107-#else
108- appsiz1 = -9;
109-#endif
110- if (appsiz1 < 0) {
111- fputs("unsupported-format(tek5)\n", stderr);
112- return 1;
113- }
114- }
115-
116- int argDebug = 0, stacksiz = 1;
117- const unsigned char *cp = searchArg(argc, argv, "debug:", 0);
118- if (cp != NULL) argDebug = *cp - '0';
119- cp = searchArg(argc, argv, "stack:", 0);
120- if (cp != NULL) stacksiz = strtol(cp, NULL, 0);
121-
122- struct Regs regs;
123- void(*jitfunc)(char *);
124- unsigned char *jp = jitbuf; /* JIT-pointer */
125-
126- /* フロントエンドコードをバックエンドコードに変換する */
127- if ((appbin[2] & 0xf0) != 0) {
128- systmp0[0] = appbin[0];
129- systmp0[1] = appbin[1];
130- regs.preg[2].p = systmp0 + 2;
131- regs.preg[3].p = systmp0 + SYSTMP0SIZ;
132- regs.preg[4].p = appbin + 2;
133- regs.preg[5].p = appbin + appsiz1;
134- regs.preg[6].p = systmp1;
135- regs.preg[7].p = systmp1 + SYSTMP1SIZ;
136- regs.preg[10].p = systmp2;
137- int pxxFlag[64], typLabel[4096];
138- regs.preg[0x0b].p = (void *)pxxFlag;
139- regs.preg[0x0c].p = (void *)typLabel;
140- regs.preg[0x0d].p = opTbl;
141- jitfunc = (void *)sysjit0;
142- (*jitfunc)(((char *)&regs) + 128); /* サイズを節約するためにEBPを128バイトずらす */
143- if (regs.ireg[0] != 0) {
144- jp = regs.preg[2].p - 1;
145- fprintf(stderr, "unpack error: %02X (at %06X) (R00=%d)\n", *jp, jp - systmp0, regs.ireg[0]);
146- if ((argDebug & 2) != 0) {
147- fp = fopen("debug2.bin", "wb");
148- fwrite(systmp0, 1, jp - systmp0 + 16, fp);
149- fclose(fp);
150- }
151- exit(1);
152- }
153- tmpsiz = regs.preg[2].p - systmp0;
154- }
155- else {
156- memcpy(systmp0, appbin, appsiz1);
157- tmpsiz = appsiz1;
158- }
159-
160- if ((argDebug & 2) != 0) {
161- fp = fopen("debug2.bin", "wb");
162- fwrite(systmp0, 1, tmpsiz, fp);
163- fclose(fp);
164- }
165-
166- i = jitc0(&jp, jitbuf + 1024 * 1024, systmp0, systmp0 + tmpsiz, level, label);
167- if (i == 1) goto header_error;
168- if (i != 0) return 1;
169- di1_serial++;
170-
171- int appsiz2 = jp - jitbuf;
172-
173- unsigned char *p28 = jp;
174- jp = jitCompCallFunc(jp, &devFunc);
175-
176- tm1 = clock() / (double)CLOCKS_PER_SEC;
177-
178- /* レジスタ初期化 */
179- for (i = 0; i < 64; i++)
180- regs.ireg[i] = 0;
181- for (i = 0; i < 64; i++) {
182- regs.preg[i].p = NULL;
183- regs.preg[i].typ = -1;
184- regs.preg[i].p0 = NULL;
185- regs.preg[i].p1 = NULL;
186- }
187-
188- regs.argc = argc;
189- regs.argv = argv;
190- regs.buf0 = regs.buf1 = NULL;
191- regs.preg[0x28].p = p28;
192- regs.preg[0x28].typ = 0; // TYP_CODE
193- regs.preg[0x28].p0 = p28;
194- regs.preg[0x28].p1 = p28 + 1;
195- // regs.preg[0x00].p = malloc(1024 * 1024) + (1024 * 1024 - 32);
196- regs.junkStack = malloc(stacksiz << 20);
197- regs.junkStack1 = regs.junkStack + (stacksiz << 20);
198- regs.winClosed = 0;
199- regs.autoSleep = 0;
200- regs.setjmpEnv = &setjmpEnv;
201- regs.lastConsoleChar = '\n';
202-
203- regs.label = label;
204- regs.maxLabels = JITC_MAXLABELS;
205- regs.jitbuf = jp;
206- regs.jitbuf1 = jitbuf + 1024 * 1024;
207- regs.errHndl = &errorHandler;
208- regs.dbgr = 0;
209- if (searchArg(argc, argv, "dbgr:1", 0) != NULL) regs.dbgr = 1;
210-
211- if ((argDebug & 1) != 0) {
212- fp = fopen("debug1.bin", "wb");
213- fwrite(jitbuf, 1, jp - jitbuf, fp);
214- fclose(fp);
215- }
216-
217- /* JITコード実行 */
218- jitfunc = (void *)jitbuf;
219- if (setjmp(setjmpEnv) == 0)
220- (*jitfunc)(((char *)&regs) + 128); /* サイズを節約するためにEBPを128バイトずらす */
221- if (regs.autoSleep != 0) {
222- if (vram != NULL)
223- drv_flshWin(v_xsiz, v_ysiz, 0, 0);
224- while (regs.winClosed == 0)
225- drv_sleep(100);
226- }
227- if (regs.lastConsoleChar != '\n')
228- putchar('\n');
229-
230- tm2 = clock() / (double)CLOCKS_PER_SEC;
231-
232- /* 実行結果確認のためのレジスタダンプ */
233- if (searchArg(argc, argv, "verbose:1", 0) != NULL) {
234- printf("time: JITC=%.3f[sec], exec=%.3f[sec]\n", tm1 - tm0, tm2 - tm1);
235- printf("size: OSECPU=%d, decomp=%d, tmp=%d, native=%d\n", appsiz0, appsiz1, tmpsiz, appsiz2);
236- printf("result:\n");
237- printf("R00:0x%08X R01:0x%08X R02:0x%08X R03:0x%08X\n", regs.ireg[0], regs.ireg[1], regs.ireg[2], regs.ireg[3]);
238- }
239-#if (USE_DEBUGGER != 0)
240- dbgrMain(&regs);
241-#endif
242- return 0;
243-}
244-
245-int main(int argc, char **argv)
246-{
247- // Program entry point
248-
249- return osecpuMain(argc, argv);
250-}
\ No newline at end of file
--- a/HeavyOSECPU/osecpu.h
+++ /dev/null
@@ -1,95 +0,0 @@
1-#ifndef _HDLOAD_OSECPU
2-#define _HDLOAD_OSECPU 1
3-
4-// プロジェクトのすべてのファイルで読み込むヘッダ
5-
6-#include <stdio.h>
7-#include <string.h>
8-#include <limits.h>
9-#include <time.h>
10-#include <setjmp.h>
11-#include <stdlib.h>
12-
13-struct PtrCtrl {
14- int liveSign;
15- int size, typ;
16- unsigned char *p0;
17-};
18-
19-struct Ptr { /* 32バイト(=256bit!) */
20- unsigned char *p;
21- int typ;
22- unsigned char *p0, *p1;
23- int liveSign;
24- struct PtrCtrl *pls;
25- int flags, dummy; /* read/writeなど */
26-};
27-
28-struct LabelTable {
29- unsigned char *p, *p1;
30- int opt, typ;
31-};
32-
33-struct Regs {
34- int ireg[64]; /* 32bit整数レジスタ */
35- struct Ptr preg[64]; /* ポインタレジスタ */
36-
37- int debugInfo0, debugInfo1, dmy[2]; /* 2304 */
38- struct PtrCtrl *ptrCtrl; /* 2320 */
39- char winClosed, autoSleep;
40- jmp_buf *setjmpEnv;
41-
42- /* for-junkApi */
43- int argc;
44- const unsigned char **argv;
45- unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
46-
47- struct LabelTable *label;
48- int maxLabels;
49- unsigned char *jitbuf, *jitbuf1;
50- void(*errHndl)(struct Regs *);
51- char dbgr;
52- int mapDi1s[16][16];
53-};
54-
55-#define KEY_ENTER '\n'
56-#define KEY_ESC 27
57-#define KEY_BACKSPACE 8
58-#define KEY_TAB 9
59-#define KEY_PAGEUP 0x1020
60-#define KEY_PAGEDWN 0x1021
61-#define KEY_END 0x1022
62-#define KEY_HOME 0x1023
63-#define KEY_LEFT 0x1024
64-#define KEY_UP 0x1025
65-#define KEY_RIGHT 0x1026
66-#define KEY_DOWN 0x1027
67-#define KEY_INS 0x1028
68-#define KEY_DEL 0x1029
69-
70-static int *keybuf, keybuf_r, keybuf_w, keybuf_c;
71-static int *vram = NULL, v_xsiz, v_ysiz;
72-static int di1_serial = 0;
73-
74-// main.c
75-void putKeybuf(int i);
76-
77-#include "switch.h"
78-#include "function.h"
79-#include "dependent.h"
80-#include "jitc.h"
81-#include "screen.h"
82-#include "comlib.h"
83-
84-#if (USE_TEK5 != 0)
85-
86-/* tek.cを移植するのは大変だと思ったので、断念 */
87-#error "tek is not supported. edit switch.h and set USE_TEK5=0"
88-
89-// #include "tek.c"
90-// int tek5Decomp(unsigned char *buf, unsigned char *buf1, unsigned char *tmp);
91-#endif
92-
93-
94-#endif
95-
--- a/HeavyOSECPU/screen.c
+++ /dev/null
@@ -1,74 +0,0 @@
1-#include "osecpu.h"
2-
3-void putOsaskChar(int c, struct Regs *r)
4-{
5- if (0x10 <= c && c <= 0x1f)
6- c = "0123456789ABCDEF"[c & 0x0f];
7- putchar(r->lastConsoleChar = c);
8- return;
9-}
10-
11-void checkString(struct Regs *r, int rxx, int pxx)
12-{
13- 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)
19- (*(r->errHndl))(r);
20- return;
21-}
22-
23-int loadColor(struct Regs *r, int rxx)
24-{
25- int c = r->ireg[rxx], m = r->ireg[0x31] & 0x0c, rr, gg, bb;
26- if (m == 0x04) {
27- if (c < -1 || c > 7)
28- (*(r->errHndl))(r);
29- c = iColor1[c & 0x07];
30- }
31- if (m == 0x08) {
32- // 00, 24, 48, 6d, 91, b6, da, ff
33- if (c < 0 || c >= (1 << 9))
34- (*(r->errHndl))(r);
35- rr = (c >> 6) & 0x07;
36- gg = (c >> 3) & 0x07;
37- bb = c & 0x07;
38- rr = (rr * 255) / 7;
39- gg = (gg * 255) / 7;
40- bb = (bb * 255) / 7;
41- c = rr << 16 | gg << 8 | bb;
42- }
43- if (m == 0x0c) {
44- // 00, 08, 10, 18, 20, 29, 31, 39,
45- // 41, 4a, 52, 5a, 62, 6a, 73, 7b,
46- // 83, 8b, 94, 9c, a4, ac, b4, bd,
47- // c5, cd, d5, de, e6, ee, f6, ff
48- if (c < 0 || c >= (1 << 15))
49- (*(r->errHndl))(r);
50- rr = (c >> 10) & 0x1f;
51- gg = (c >> 5) & 0x1f;
52- bb = c & 0x1f;
53- rr = (rr * 255) / 31;
54- gg = (gg * 255) / 31;
55- bb = (bb * 255) / 31;
56- c = rr << 16 | gg << 8 | bb;
57- }
58- return c;
59-}
60-
61-void checkRect(struct Regs *r, int rxx)
62-{
63- char c = 0;
64- 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)
72- (*(r->errHndl))(r);
73- return;
74-}
\ No newline at end of file
--- a/HeavyOSECPU/screen.h
+++ /dev/null
@@ -1,116 +0,0 @@
1-#ifndef _HDLOAD_SCREEN
2-#define _HDLOAD_SCREEN 1
3-
4-static unsigned char fontdata[] = {
5- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
6- 0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
7- 0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
8- 0x00, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x00, 0x00,
9- 0x10, 0x3a, 0x56, 0x92, 0x92, 0x90, 0x50, 0x38, 0x14, 0x12, 0x92, 0x92, 0xd4, 0xb8, 0x10, 0x10,
10- 0x62, 0x92, 0x94, 0x94, 0x68, 0x08, 0x10, 0x10, 0x20, 0x2c, 0x52, 0x52, 0x92, 0x8c, 0x00, 0x00,
11- 0x00, 0x70, 0x88, 0x88, 0x88, 0x90, 0x60, 0x47, 0xa2, 0x92, 0x8a, 0x84, 0x46, 0x39, 0x00, 0x00,
12- 0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
13- 0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x00,
14- 0x80, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, 0x80, 0x00,
15- 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x92, 0x54, 0x38, 0x54, 0x92, 0x10, 0x00, 0x00, 0x00, 0x00,
16- 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0xfe, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
17- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
18- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
19- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
20- 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x80, 0x80,
21- 0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0x00, 0x00,
22- 0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
23- 0x00, 0x18, 0x24, 0x42, 0x42, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
24- 0x00, 0x18, 0x24, 0x42, 0x02, 0x02, 0x04, 0x18, 0x04, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
25- 0x00, 0x0c, 0x0c, 0x0c, 0x14, 0x14, 0x14, 0x24, 0x24, 0x44, 0x7e, 0x04, 0x04, 0x1e, 0x00, 0x00,
26- 0x00, 0x7c, 0x40, 0x40, 0x40, 0x58, 0x64, 0x02, 0x02, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
27- 0x00, 0x18, 0x24, 0x42, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
28- 0x00, 0x7e, 0x42, 0x42, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
29- 0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
30- 0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1a, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
31- 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
32- 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
33- 0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
34- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
35- 0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
36- 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x04, 0x08, 0x10, 0x10, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
37- 0x00, 0x38, 0x44, 0x82, 0x9a, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x9c, 0x80, 0x46, 0x38, 0x00, 0x00,
38- 0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
39- 0x00, 0xf0, 0x48, 0x44, 0x44, 0x44, 0x48, 0x78, 0x44, 0x42, 0x42, 0x42, 0x44, 0xf8, 0x00, 0x00,
40- 0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x82, 0x42, 0x44, 0x38, 0x00, 0x00,
41- 0x00, 0xf8, 0x44, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x44, 0xf8, 0x00, 0x00,
42- 0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
43- 0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x44, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
44- 0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x9e, 0x82, 0x82, 0x82, 0x42, 0x46, 0x38, 0x00, 0x00,
45- 0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
46- 0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
47- 0x00, 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x84, 0x48, 0x30, 0x00,
48- 0x00, 0xe7, 0x42, 0x44, 0x48, 0x50, 0x50, 0x60, 0x50, 0x50, 0x48, 0x44, 0x42, 0xe7, 0x00, 0x00,
49- 0x00, 0xf0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
50- 0x00, 0xc3, 0x42, 0x66, 0x66, 0x66, 0x5a, 0x5a, 0x5a, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
51- 0x00, 0xc7, 0x42, 0x62, 0x62, 0x52, 0x52, 0x52, 0x4a, 0x4a, 0x4a, 0x46, 0x46, 0xe2, 0x00, 0x00,
52- 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
53- 0x00, 0xf8, 0x44, 0x42, 0x42, 0x42, 0x44, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
54- 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x92, 0x8a, 0x44, 0x3a, 0x00, 0x00,
55- 0x00, 0xfc, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
56- 0x00, 0x3a, 0x46, 0x82, 0x82, 0x80, 0x40, 0x38, 0x04, 0x02, 0x82, 0x82, 0xc4, 0xb8, 0x00, 0x00,
57- 0x00, 0xfe, 0x92, 0x92, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
58- 0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x3c, 0x00, 0x00,
59- 0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,
60- 0x00, 0xe7, 0x42, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00,
61- 0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x24, 0x24, 0x24, 0x42, 0x42, 0xe7, 0x00, 0x00,
62- 0x00, 0xee, 0x44, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
63- 0x00, 0xfe, 0x84, 0x84, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x42, 0x82, 0xfe, 0x00, 0x00,
64- 0x00, 0x3e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3e, 0x00,
65- 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02,
66- 0x00, 0x7c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x7c, 0x00,
67- 0x00, 0x10, 0x28, 0x44, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
68- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
69- 0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
70- 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x04, 0x3c, 0x44, 0x84, 0x84, 0x8c, 0x76, 0x00, 0x00,
71- 0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x00, 0x00,
72- 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x4c, 0x84, 0x84, 0x80, 0x80, 0x82, 0x44, 0x38, 0x00, 0x00,
73- 0x0c, 0x04, 0x04, 0x04, 0x04, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x36, 0x00, 0x00,
74- 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0xfc, 0x80, 0x82, 0x42, 0x3c, 0x00, 0x00,
75- 0x0e, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
76- 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x04, 0x78,
77- 0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
78- 0x00, 0x10, 0x10, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
79- 0x00, 0x04, 0x04, 0x00, 0x00, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x30,
80- 0xc0, 0x40, 0x40, 0x40, 0x40, 0x4e, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0xe6, 0x00, 0x00,
81- 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
82- 0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0xdb, 0x00, 0x00,
83- 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
84- 0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
85- 0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x40, 0xe0,
86- 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x0e,
87- 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x00, 0x00,
88- 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x86, 0x82, 0xc0, 0x38, 0x06, 0x82, 0xc2, 0xbc, 0x00, 0x00,
89- 0x00, 0x00, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0e, 0x00, 0x00,
90- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3b, 0x00, 0x00,
91- 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00,
92- 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x00, 0x00,
93- 0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x44, 0x28, 0x28, 0x10, 0x28, 0x28, 0x44, 0xc6, 0x00, 0x00,
94- 0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x10, 0x10, 0x60,
95- 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x82, 0x84, 0x08, 0x10, 0x20, 0x42, 0x82, 0xfe, 0x00, 0x00,
96- 0x00, 0x06, 0x08, 0x10, 0x10, 0x10, 0x10, 0x60, 0x10, 0x10, 0x10, 0x10, 0x08, 0x06, 0x00, 0x00,
97- 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
98- 0x00, 0x60, 0x10, 0x08, 0x08, 0x08, 0x08, 0x06, 0x08, 0x08, 0x08, 0x08, 0x10, 0x60, 0x00, 0x00,
99- 0x00, 0x72, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
100- 0x00, 0x00, 0x00, 0x00, 0x10, 0x28, 0x44, 0x82, 0xfe, 0x82, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
101-};/* tinyMTの32bit版のアルゴリズムを使っています : http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/index-jp.html */
102-
103-static int iColor1[] = {
104- 0x000000, 0xff0000, 0x00ff00, 0xffff00,
105- 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
106-};
107-
108-void putOsaskChar(int c, struct Regs *r);
109-
110-void checkString(struct Regs *r, int rxx, int pxx);
111-
112-void checkRect(struct Regs *r, int rxx);
113-
114-int loadColor(struct Regs *r, int rxx);
115-
116-#endif
\ No newline at end of file
--- a/HeavyOSECPU/switch.h
+++ /dev/null
@@ -1,45 +0,0 @@
1-#ifndef _HDLOAD_SWITCH
2-#define _HDLOAD_SWITCH 1
3-
4-/*
5- * このファイルを編集することでコンパイルの仕方を変更できます
6- */
7-
8-
9-/*
10- * CPUのアーキテクチャ
11- * 1 : i386
12- */
13-#define JITC_ARCNUM 0x0001
14-
15-/*
16- * 実行環境となるOSの種類
17- * 1 : Win32
18- * 2 : Mac OS
19- * 3 : blike for Linux
20- */
21-#define DRV_OSNUM 0x0001
22-
23-/*
24- * フロントエンドコード->バックエンドコード を実行するsyslib(decorder)ファイルを指定する。
25- * OSECPUの動作にはsyslib.oseが必要。
26- */
27-#define SYSLIB_OSE "syslib.ose"
28-#define SIGN1 0xe1
29-
30-
31-
32-#define USE_DEBUGGER 1
33-#define USE_TEK5 0 //元々は1
34-
35-#define APPSIZ1 1 * 1024 * 1024 /* とりあえず1MBで */
36-#define JITSIZ1 1 * 1024 * 1024 /* とりあえず1MBで */
37-#define SJITSIZ1 1 * 1024 * 1024 /* とりあえず1MBで */
38-#define SYSLIBSIZ1 1 * 1024 * 1024 /* とりあえず1MBで */
39-#define SYSTMP0SIZ 1 * 1024 * 1024 /* とりあえず1MBで */
40-#define SYSTMP1SIZ 2 * 1024 * 1024 /* とりあえず2MBで */
41-
42-#define KEYBUFSIZ 4096
43-
44-#endif
45-
旧リポジトリブラウザで表示