コミットメタ情報

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

ログメッセージ

yaoさんの提案を参考に、core.autocrlf=falseとしてコミットしてみる。
これで行末はCrLfで(LFに変換されずに)コミットされているはず。
VSでコンパイルが通る

変更サマリ

差分

--- a/dpndenv.c
+++ b/dpndenv.c
@@ -1,439 +1,439 @@
1-#include "osecpu.h"
2-
3-
4-#if (DRV_OSNUM == 0x0002)
5-//
6-// for Mac OSX 32-bit
7-//
8-#include <mach/mach.h>
9-#include <Cocoa/Cocoa.h>
10-
11-void *mallocRWE(int bytes)
12-{
13- void *p = malloc(bytes);
14- vm_protect(mach_task_self(), (vm_address_t) p, bytes, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
15- return p;
16-}
17-
18-NSApplication* app;
19-
20-@interface OSECPUView : NSView
21-{
22- unsigned char *_buf;
23- int _sx;
24- int _sy;
25- CGContextRef _context;
26-}
27-
28-- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy;
29-- (void)drawRect:(NSRect)rect;
30-@end
31-
32-@implementation OSECPUView
33-- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy
34-{
35- self = [super initWithFrame:frameRect];
36- if (self) {
37- _buf = buf;
38- _sx = sx;
39- _sy = sy;
40- }
41- return self;
42-}
43-
44-- (void)drawRect:(NSRect)rect {
45- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
46- _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));
47- CGImageRef image = CGBitmapContextCreateImage(_context);
48- CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
49- CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);
50- CFRelease(colorSpace);
51- CFRelease(image);
52-}
53-
54-- (void)keyDown:(NSEvent *)theEvent
55-{
56-
57-}
58-
59-- (void)keyUp:(NSEvent *)theEvent
60-{
61-
62-}
63-
64-@end
65-
66-@interface Main : NSObject<NSWindowDelegate>
67-{
68- int argc;
69- const unsigned char **argv;
70- char *winClosed;
71- OSECPUView *_view;
72-}
73-
74-- (void)runApp;
75-- (void)createThread:(int)_argc args:(const unsigned char **)_argv;
76-- (BOOL)windowShouldClose:(id)sender;
77-- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int)sy winClosed:(char *)_winClosed;
78-- (void)flushWin:(NSRect)rect;
79-@end
80-
81-@implementation Main
82-- (void)runApp
83-{
84- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
85- int retv;
86- retv = HeavyOSECPUMain(argc, (char **)argv);
87- [NSApp terminate:self];
88- [pool release];
89- exit(retv);
90-}
91-
92-- (void)createThread : (int)_argc args:(const unsigned char **)_argv
93-{
94- argc = _argc;
95- argv = _argv;
96- NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];
97- [thread start];
98-}
99-
100-- (BOOL)windowShouldClose:(id)sender
101-{
102- *winClosed = 1;
103- return YES;
104-}
105-
106-- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed
107-{
108-
109- NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO];
110- [window setTitle: @"osecpu"];
111- [window center];
112- [window makeKeyAndOrderFront:nil];
113- [window setReleasedWhenClosed:YES];
114- window.delegate = self;
115- winClosed = _winClosed;
116-
117- _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy];
118- [window.contentView addSubview:_view];
119-}
120-
121-- (void)flushWin : (NSRect)rect
122-{
123- [_view setNeedsDisplayInRect:rect];
124-}
125-
126-@end
127-
128-id objc_main;
129-
130-int main(int argc, char **argv)
131-{
132- objc_main = [[Main alloc] init];
133-
134- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
135- app = [[NSApplication alloc] init];
136- [objc_main createThread:argc args:(const unsigned char **)argv];
137- [app run];
138- [pool release];
139- return 0;
140-}
141-
142-void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)
143-{
144- [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];
145-}
146-
147-void drv_flshWin(int sx, int sy, int x0, int y0)
148-{
149- [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
150-}
151-
152-void drv_sleep(int msec)
153-{
154- [NSThread sleepForTimeInterval:0.001*msec];
155- return;
156-}
157-
158-
159-#elif (DRV_OSNUM == 0x0003)
160-
161-#error "Your OS is not supported."
162-
163-#elif (DRV_OSNUM == 0x0001)
164-//
165-// for Windows 32-bit
166-//
167-#include <windows.h>
168-
169-#define TIMER_ID 1
170-#define TIMER_INTERVAL 10
171-
172-struct BLD_WORK {
173- HINSTANCE hi;
174- HWND hw;
175- BITMAPINFO bmi;
176- int tmcount1, tmcount2, flags, smp; /* bit0: 終了 */
177- HANDLE mtx;
178- char *winClosed;
179-};
180-
181-struct BLD_WORK bld_work;
182-
183-struct BL_WIN {
184- int xsiz, ysiz, *buf;
185-};
186-
187-struct BL_WORK {
188- struct BL_WIN win;
189- jmp_buf jb;
190- int csiz_x, csiz_y, cx, cy, col0, col1, tabsiz, slctwin;
191- int tmcount, tmcount0, mod, rand_seed;
192- int *cbuf;
193- unsigned char *ftyp;
194- unsigned char **fptn;
195- int *ccol, *cbak;
196- int *kbuf, kbuf_rp, kbuf_wp, kbuf_c;
197-};
198-
199-struct BL_WORK bl_work;
200-
201-#define BL_SIZ_KBUF 8192
202-
203-#define BL_WAITKEYF 0x00000001
204-#define BL_WAITKEYNF 0x00000002
205-#define BL_WAITKEY 0x00000003
206-#define BL_GETKEY 0x00000004
207-#define BL_CLEARREP 0x00000008
208-#define BL_DELFFF 0x00000010
209-
210-#define BL_KEYMODE 0x00000000 // 作りかけ, make/remake/breakが見えるかどうか
211-
212-#define w bl_work
213-#define dw bld_work
214-
215-void bld_openWin(int x, int y, char *winClosed);
216-void bld_flshWin(int sx, int sy, int x0, int y0);
217-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp);
218-void bl_cls();
219-int bl_iCol(int i);
220-void bl_readyWin(int n);
221-
222-static HANDLE threadhandle;
223-
224-int main(int argc, char **argv)
225-{
226- // Program entry point
227- return HeavyOSECPUMain(argc, argv);
228-}
229-
230-void *mallocRWE(int bytes)
231-{
232- void *p = malloc(bytes);
233- DWORD dmy;
234- VirtualProtect(p, bytes, PAGE_EXECUTE_READWRITE, &dmy);
235- return p;
236-}
237-
238-static int winthread(void *dmy)
239-{
240- WNDCLASSEX wc;
241- RECT r;
242- int i, x, y;
243- MSG msg;
244-
245- x = dw.bmi.bmiHeader.biWidth;
246- y = -dw.bmi.bmiHeader.biHeight;
247-
248- wc.cbSize = sizeof (WNDCLASSEX);
249- wc.style = CS_HREDRAW | CS_VREDRAW;
250- wc.lpfnWndProc = WndProc;
251- wc.cbClsExtra = 0;
252- wc.cbWndExtra = 0;
253- wc.hInstance = dw.hi;
254- wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
255- IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
256- wc.hIconSm = wc.hIcon;
257- wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
258- IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
259- wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
260- wc.lpszMenuName = NULL;
261- wc.lpszClassName = "WinClass";
262- if (RegisterClassEx(&wc) == 0)
263- return 1;
264- r.left = 0;
265- r.top = 0;
266- r.right = x;
267- r.bottom = y;
268- AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
269- x = r.right - r.left;
270- y = r.bottom - r.top;
271-
272- char *t = "osecpu";
273-
274- dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,
275- CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
276- if (dw.hw == NULL)
277- return 1;
278- ShowWindow(dw.hw, SW_SHOW);
279- UpdateWindow(dw.hw);
280- SetTimer(dw.hw, TIMER_ID, TIMER_INTERVAL, NULL);
281- SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);
282- SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);
283- dw.flags |= 2 | 4;
284-
285- for (;;) {
286- i = GetMessage(&msg, NULL, 0, 0);
287- if (i == 0 || i == -1) /* エラーもしくは終了メッセージ */
288- break;
289- /* そのほかはとりあえずデフォルト処理で */
290- TranslateMessage(&msg);
291- DispatchMessage(&msg);
292- }
293- // PostQuitMessage(0);
294- dw.flags |= 1; /* 終了, bld_waitNF()が見つける */
295- if (dw.winClosed != NULL)
296- *dw.winClosed = 1;
297- return 0;
298-}
299-
300-void bld_openWin(int sx, int sy, char *winClosed)
301-{
302- static int i;
303-
304- dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
305- dw.bmi.bmiHeader.biWidth = sx;
306- dw.bmi.bmiHeader.biHeight = -sy;
307- dw.bmi.bmiHeader.biPlanes = 1;
308- dw.bmi.bmiHeader.biBitCount = 32;
309- dw.bmi.bmiHeader.biCompression = BI_RGB;
310- dw.winClosed = winClosed;
311-
312- threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
313-
314- return;
315-}
316-
317-void drv_flshWin(int sx, int sy, int x0, int y0)
318-{
319- InvalidateRect(dw.hw, NULL, FALSE);
320- UpdateWindow(dw.hw);
321- return;
322-}
323-
324-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
325-{
326- int i, j;
327- if (msg == WM_PAINT) {
328- PAINTSTRUCT ps;
329- HDC hdc = BeginPaint(dw.hw, &ps);
330- SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,
331- 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
332- EndPaint(dw.hw, &ps);
333- }
334- if (msg == WM_DESTROY) {
335- PostQuitMessage(0);
336- return 0;
337- }
338- if (msg == WM_TIMER && wp == TIMER_ID) {
339- w.tmcount += TIMER_INTERVAL;
340- return 0;
341- }
342- if (msg == WM_TIMER && wp == TIMER_ID + 1) {
343- dw.tmcount1 += TIMER_INTERVAL * 10;
344- w.tmcount = dw.tmcount1;
345- return 0;
346- }
347- if (msg == WM_TIMER && wp == TIMER_ID + 2) {
348- dw.tmcount2 += TIMER_INTERVAL * 100;
349- w.tmcount = dw.tmcount1 = dw.tmcount2;
350- return 0;
351- }
352- if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
353- i = -1;
354-
355- if (wp == VK_RETURN) i = KEY_ENTER;
356- if (wp == VK_ESCAPE) i = KEY_ESC;
357- if (wp == VK_BACK) i = KEY_BACKSPACE;
358- if (wp == VK_TAB) i = KEY_TAB;
359- if (wp == VK_PRIOR) i = KEY_PAGEUP;
360- if (wp == VK_NEXT) i = KEY_PAGEDWN;
361- if (wp == VK_END) i = KEY_END;
362- if (wp == VK_HOME) i = KEY_HOME;
363- if (wp == VK_LEFT) i = KEY_LEFT;
364- if (wp == VK_RIGHT) i = KEY_RIGHT;
365- if (wp == VK_UP) i = KEY_UP;
366- if (wp == VK_DOWN) i = KEY_DOWN;
367- if (wp == VK_INSERT) i = KEY_INS;
368- if (wp == VK_DELETE) i = KEY_DEL;
369- j &= 0;
370- if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
371- if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
372- if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
373- if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
374- if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
375- if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
376- if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
377- if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
378- if (j != 0) {
379- if ('A' <= wp && wp <= 'Z') i = wp;
380- }
381- if (i != -1) {
382- putKeybuf(i | j);
383- // bl_putKeyB(1, &i);
384- return 0;
385- }
386- }
387- if (msg == WM_KEYUP) {
388- i = 0xfff;
389- // bl_putKeyB(1, &i);
390- }
391- if (msg == WM_CHAR) {
392- i = 0;
393- if (' ' <= wp && wp <= 0x7e) {
394- i = wp;
395- j &= 0;
396- if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
397- if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
398- if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
399- if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
400- if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
401- if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
402- if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
403- if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
404- if (('A' <= wp && wp <= 'Z') || ('a' <= wp && wp <= 'z')) {
405- if (j != 0) {
406- i |= j;
407- i &= ~0x20;
408- }
409- }
410- putKeybuf(i);
411- // bl_putKeyB(1, &i);
412- return 0;
413- }
414- }
415- return DefWindowProc(hw, msg, wp, lp);
416-}
417-
418-void drv_openWin(int sx, int sy, UCHAR *buf, char *winClosed)
419-{
420- w.win.buf = (int *)buf;
421- w.win.xsiz = sx;
422- w.win.ysiz = sy;
423- bld_openWin(sx, sy, winClosed);
424- return;
425-}
426-
427-void drv_sleep(int msec)
428-{
429- Sleep(msec);
430- // MsgWaitForMultipleObjects(1, &threadhandle, FALSE, msec, QS_ALLINPUT);
431- /* 勉強不足でまだ書き方が分かりません! */
432- return;
433-}
434-
435-#else
436-
437-#error "Illegal OS type. Edit osecpu.h and look at DRV_OSNUM"
438-
1+#include "osecpu.h"
2+
3+
4+#if (DRV_OSNUM == 0x0002)
5+//
6+// for Mac OSX 32-bit
7+//
8+#include <mach/mach.h>
9+#include <Cocoa/Cocoa.h>
10+
11+void *mallocRWE(int bytes)
12+{
13+ void *p = malloc(bytes);
14+ vm_protect(mach_task_self(), (vm_address_t) p, bytes, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
15+ return p;
16+}
17+
18+NSApplication* app;
19+
20+@interface OSECPUView : NSView
21+{
22+ unsigned char *_buf;
23+ int _sx;
24+ int _sy;
25+ CGContextRef _context;
26+}
27+
28+- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy;
29+- (void)drawRect:(NSRect)rect;
30+@end
31+
32+@implementation OSECPUView
33+- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy
34+{
35+ self = [super initWithFrame:frameRect];
36+ if (self) {
37+ _buf = buf;
38+ _sx = sx;
39+ _sy = sy;
40+ }
41+ return self;
42+}
43+
44+- (void)drawRect:(NSRect)rect {
45+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
46+ _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));
47+ CGImageRef image = CGBitmapContextCreateImage(_context);
48+ CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
49+ CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);
50+ CFRelease(colorSpace);
51+ CFRelease(image);
52+}
53+
54+- (void)keyDown:(NSEvent *)theEvent
55+{
56+
57+}
58+
59+- (void)keyUp:(NSEvent *)theEvent
60+{
61+
62+}
63+
64+@end
65+
66+@interface Main : NSObject<NSWindowDelegate>
67+{
68+ int argc;
69+ const unsigned char **argv;
70+ char *winClosed;
71+ OSECPUView *_view;
72+}
73+
74+- (void)runApp;
75+- (void)createThread:(int)_argc args:(const unsigned char **)_argv;
76+- (BOOL)windowShouldClose:(id)sender;
77+- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int)sy winClosed:(char *)_winClosed;
78+- (void)flushWin:(NSRect)rect;
79+@end
80+
81+@implementation Main
82+- (void)runApp
83+{
84+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
85+ int retv;
86+ retv = HeavyOSECPUMain(argc, (char **)argv);
87+ [NSApp terminate:self];
88+ [pool release];
89+ exit(retv);
90+}
91+
92+- (void)createThread : (int)_argc args:(const unsigned char **)_argv
93+{
94+ argc = _argc;
95+ argv = _argv;
96+ NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];
97+ [thread start];
98+}
99+
100+- (BOOL)windowShouldClose:(id)sender
101+{
102+ *winClosed = 1;
103+ return YES;
104+}
105+
106+- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed
107+{
108+
109+ NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO];
110+ [window setTitle: @"osecpu"];
111+ [window center];
112+ [window makeKeyAndOrderFront:nil];
113+ [window setReleasedWhenClosed:YES];
114+ window.delegate = self;
115+ winClosed = _winClosed;
116+
117+ _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy];
118+ [window.contentView addSubview:_view];
119+}
120+
121+- (void)flushWin : (NSRect)rect
122+{
123+ [_view setNeedsDisplayInRect:rect];
124+}
125+
126+@end
127+
128+id objc_main;
129+
130+int main(int argc, char **argv)
131+{
132+ objc_main = [[Main alloc] init];
133+
134+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
135+ app = [[NSApplication alloc] init];
136+ [objc_main createThread:argc args:(const unsigned char **)argv];
137+ [app run];
138+ [pool release];
139+ return 0;
140+}
141+
142+void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)
143+{
144+ [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];
145+}
146+
147+void drv_flshWin(int sx, int sy, int x0, int y0)
148+{
149+ [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
150+}
151+
152+void drv_sleep(int msec)
153+{
154+ [NSThread sleepForTimeInterval:0.001*msec];
155+ return;
156+}
157+
158+
159+#elif (DRV_OSNUM == 0x0003)
160+
161+#error "Your OS is not supported."
162+
163+#elif (DRV_OSNUM == 0x0001)
164+//
165+// for Windows 32-bit
166+//
167+#include <windows.h>
168+
169+#define TIMER_ID 1
170+#define TIMER_INTERVAL 10
171+
172+struct BLD_WORK {
173+ HINSTANCE hi;
174+ HWND hw;
175+ BITMAPINFO bmi;
176+ int tmcount1, tmcount2, flags, smp; /* bit0: 終了 */
177+ HANDLE mtx;
178+ char *winClosed;
179+};
180+
181+struct BLD_WORK bld_work;
182+
183+struct BL_WIN {
184+ int xsiz, ysiz, *buf;
185+};
186+
187+struct BL_WORK {
188+ struct BL_WIN win;
189+ jmp_buf jb;
190+ int csiz_x, csiz_y, cx, cy, col0, col1, tabsiz, slctwin;
191+ int tmcount, tmcount0, mod, rand_seed;
192+ int *cbuf;
193+ unsigned char *ftyp;
194+ unsigned char **fptn;
195+ int *ccol, *cbak;
196+ int *kbuf, kbuf_rp, kbuf_wp, kbuf_c;
197+};
198+
199+struct BL_WORK bl_work;
200+
201+#define BL_SIZ_KBUF 8192
202+
203+#define BL_WAITKEYF 0x00000001
204+#define BL_WAITKEYNF 0x00000002
205+#define BL_WAITKEY 0x00000003
206+#define BL_GETKEY 0x00000004
207+#define BL_CLEARREP 0x00000008
208+#define BL_DELFFF 0x00000010
209+
210+#define BL_KEYMODE 0x00000000 // 作りかけ, make/remake/breakが見えるかどうか
211+
212+#define w bl_work
213+#define dw bld_work
214+
215+void bld_openWin(int x, int y, char *winClosed);
216+void bld_flshWin(int sx, int sy, int x0, int y0);
217+LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp);
218+void bl_cls();
219+int bl_iCol(int i);
220+void bl_readyWin(int n);
221+
222+static HANDLE threadhandle;
223+
224+int main(int argc, char **argv)
225+{
226+ // Program entry point
227+ return HeavyOSECPUMain(argc, argv);
228+}
229+
230+void *mallocRWE(int bytes)
231+{
232+ void *p = malloc(bytes);
233+ DWORD dmy;
234+ VirtualProtect(p, bytes, PAGE_EXECUTE_READWRITE, &dmy);
235+ return p;
236+}
237+
238+static int winthread(void *dmy)
239+{
240+ WNDCLASSEX wc;
241+ RECT r;
242+ int i, x, y;
243+ MSG msg;
244+
245+ x = dw.bmi.bmiHeader.biWidth;
246+ y = -dw.bmi.bmiHeader.biHeight;
247+
248+ wc.cbSize = sizeof (WNDCLASSEX);
249+ wc.style = CS_HREDRAW | CS_VREDRAW;
250+ wc.lpfnWndProc = WndProc;
251+ wc.cbClsExtra = 0;
252+ wc.cbWndExtra = 0;
253+ wc.hInstance = dw.hi;
254+ wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
255+ IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
256+ wc.hIconSm = wc.hIcon;
257+ wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
258+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
259+ wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
260+ wc.lpszMenuName = NULL;
261+ wc.lpszClassName = "WinClass";
262+ if (RegisterClassEx(&wc) == 0)
263+ return 1;
264+ r.left = 0;
265+ r.top = 0;
266+ r.right = x;
267+ r.bottom = y;
268+ AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
269+ x = r.right - r.left;
270+ y = r.bottom - r.top;
271+
272+ char *t = "osecpu";
273+
274+ dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,
275+ CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
276+ if (dw.hw == NULL)
277+ return 1;
278+ ShowWindow(dw.hw, SW_SHOW);
279+ UpdateWindow(dw.hw);
280+ SetTimer(dw.hw, TIMER_ID, TIMER_INTERVAL, NULL);
281+ SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);
282+ SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);
283+ dw.flags |= 2 | 4;
284+
285+ for (;;) {
286+ i = GetMessage(&msg, NULL, 0, 0);
287+ if (i == 0 || i == -1) /* エラーもしくは終了メッセージ */
288+ break;
289+ /* そのほかはとりあえずデフォルト処理で */
290+ TranslateMessage(&msg);
291+ DispatchMessage(&msg);
292+ }
293+ // PostQuitMessage(0);
294+ dw.flags |= 1; /* 終了, bld_waitNF()が見つける */
295+ if (dw.winClosed != NULL)
296+ *dw.winClosed = 1;
297+ return 0;
298+}
299+
300+void bld_openWin(int sx, int sy, char *winClosed)
301+{
302+ static int i;
303+
304+ dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
305+ dw.bmi.bmiHeader.biWidth = sx;
306+ dw.bmi.bmiHeader.biHeight = -sy;
307+ dw.bmi.bmiHeader.biPlanes = 1;
308+ dw.bmi.bmiHeader.biBitCount = 32;
309+ dw.bmi.bmiHeader.biCompression = BI_RGB;
310+ dw.winClosed = winClosed;
311+
312+ threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
313+
314+ return;
315+}
316+
317+void drv_flshWin(int sx, int sy, int x0, int y0)
318+{
319+ InvalidateRect(dw.hw, NULL, FALSE);
320+ UpdateWindow(dw.hw);
321+ return;
322+}
323+
324+LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
325+{
326+ int i, j;
327+ if (msg == WM_PAINT) {
328+ PAINTSTRUCT ps;
329+ HDC hdc = BeginPaint(dw.hw, &ps);
330+ SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,
331+ 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
332+ EndPaint(dw.hw, &ps);
333+ }
334+ if (msg == WM_DESTROY) {
335+ PostQuitMessage(0);
336+ return 0;
337+ }
338+ if (msg == WM_TIMER && wp == TIMER_ID) {
339+ w.tmcount += TIMER_INTERVAL;
340+ return 0;
341+ }
342+ if (msg == WM_TIMER && wp == TIMER_ID + 1) {
343+ dw.tmcount1 += TIMER_INTERVAL * 10;
344+ w.tmcount = dw.tmcount1;
345+ return 0;
346+ }
347+ if (msg == WM_TIMER && wp == TIMER_ID + 2) {
348+ dw.tmcount2 += TIMER_INTERVAL * 100;
349+ w.tmcount = dw.tmcount1 = dw.tmcount2;
350+ return 0;
351+ }
352+ if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
353+ i = -1;
354+
355+ if (wp == VK_RETURN) i = KEY_ENTER;
356+ if (wp == VK_ESCAPE) i = KEY_ESC;
357+ if (wp == VK_BACK) i = KEY_BACKSPACE;
358+ if (wp == VK_TAB) i = KEY_TAB;
359+ if (wp == VK_PRIOR) i = KEY_PAGEUP;
360+ if (wp == VK_NEXT) i = KEY_PAGEDWN;
361+ if (wp == VK_END) i = KEY_END;
362+ if (wp == VK_HOME) i = KEY_HOME;
363+ if (wp == VK_LEFT) i = KEY_LEFT;
364+ if (wp == VK_RIGHT) i = KEY_RIGHT;
365+ if (wp == VK_UP) i = KEY_UP;
366+ if (wp == VK_DOWN) i = KEY_DOWN;
367+ if (wp == VK_INSERT) i = KEY_INS;
368+ if (wp == VK_DELETE) i = KEY_DEL;
369+ j &= 0;
370+ if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
371+ if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
372+ if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
373+ if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
374+ if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
375+ if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
376+ if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
377+ if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
378+ if (j != 0) {
379+ if ('A' <= wp && wp <= 'Z') i = wp;
380+ }
381+ if (i != -1) {
382+ putKeybuf(i | j);
383+ // bl_putKeyB(1, &i);
384+ return 0;
385+ }
386+ }
387+ if (msg == WM_KEYUP) {
388+ i = 0xfff;
389+ // bl_putKeyB(1, &i);
390+ }
391+ if (msg == WM_CHAR) {
392+ i = 0;
393+ if (' ' <= wp && wp <= 0x7e) {
394+ i = wp;
395+ j &= 0;
396+ if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
397+ if ((GetKeyState(VK_LMENU) & (1 << 15)) != 0) j |= 1 << 18;
398+ if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
399+ if ((GetKeyState(VK_RMENU) & (1 << 15)) != 0) j |= 1 << 26;
400+ if ((GetKeyState(VK_RSHIFT) & (1 << 15)) != 0) i |= 1 << 24;
401+ if ((GetKeyState(VK_LSHIFT) & (1 << 15)) != 0) i |= 1 << 16;
402+ if ((GetKeyState(VK_NUMLOCK) & (1 << 0)) != 0) i |= 1 << 22;
403+ if ((GetKeyState(VK_CAPITAL) & (1 << 0)) != 0) i |= 1 << 23;
404+ if (('A' <= wp && wp <= 'Z') || ('a' <= wp && wp <= 'z')) {
405+ if (j != 0) {
406+ i |= j;
407+ i &= ~0x20;
408+ }
409+ }
410+ putKeybuf(i);
411+ // bl_putKeyB(1, &i);
412+ return 0;
413+ }
414+ }
415+ return DefWindowProc(hw, msg, wp, lp);
416+}
417+
418+void drv_openWin(int sx, int sy, UCHAR *buf, char *winClosed)
419+{
420+ w.win.buf = (int *)buf;
421+ w.win.xsiz = sx;
422+ w.win.ysiz = sy;
423+ bld_openWin(sx, sy, winClosed);
424+ return;
425+}
426+
427+void drv_sleep(int msec)
428+{
429+ Sleep(msec);
430+ // MsgWaitForMultipleObjects(1, &threadhandle, FALSE, msec, QS_ALLINPUT);
431+ /* 勉強不足でまだ書き方が分かりません! */
432+ return;
433+}
434+
435+#else
436+
437+#error "Illegal OS type. Edit osecpu.h and look at DRV_OSNUM"
438+
439439 #endif
\ No newline at end of file
--- a/jitc.c
+++ b/jitc.c
@@ -1,82 +1,82 @@
1-#include "osecpu.h"
2-#include "jitc.h"
3-
4-//
5-// JITC common functions (architecture not dependent)
6-//
7-
8-void errorHandler(HOSECPU_RuntimeEnvironment *r)
9-{
10- puts("security error! abort...");
11- printf("debugInfo0=%d, debugInfo1=%d\n", r->debugInfo0, r->debugInfo1);
12-#if (USE_DEBUGGER != 0)
13- dbgrMain(r);
14-#endif
15- exit(1);
16-}
17-
18-int jitCompCmdLen(const unsigned char *src)
19-{
20- //BCode命令長を取得する
21- int i = 1;
22-
23- if (0x01 <= *src && *src < 0x04){
24- // LB, LIMM, PLIMM
25- i = 6;
26- } else if (*src == 0x04){
27- // CND
28- i = 2;
29- } else if (0x08 <= *src && *src < 0x0d){
30- // LMEM, SMEM, ??, ??, ??
31- i = 8 + src[7] * 4;
32- } else if (0x0e <= *src && *src < 0x10){
33- // PADD, PDIF
34- i = 8;
35- } else if (0x10 <= *src && *src < 0x1c){
36- // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD,
37- i = 4;
38- } else if (0x1c <= *src && *src < 0x1f){
39- // ??, ??, PCP
40- i = 3;
41- } else if (*src == 0x1f){
42- // ??
43- i = 11;
44- } else if(0x20 <= *src && *src < 0x2e){
45- // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ,
46- // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG,
47- i = 4;
48- } else if (*src == 0x2f){
49- // ??
50- i = 4 + src[1];
51- } else if (0x30 <= *src && *src < 0x34){
52- // ??, ??, MALLOC, ??
53- i = 4;
54- } else if (0x3c <= *src && *src < 0x3e){
55- // ??, ??
56- i = 7;
57- } else if (*src == 0xfe){
58- // REMARK
59- i = 2 + src[1];
60- }
61-
62- return i;
63-}
64-
65-void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src)
66-{
67- // なんか直接代入するとMacではアライメントエラーで落ちるのです...
68- // *dst = *src;
69-
70- dst->p = src->p;
71- dst->typ = src->typ;
72- dst->p0 = src->p0;
73- dst->p1 = src->p1;
74- dst->liveSign = src->liveSign;
75- dst->pls = src->pls;
76- dst->flags = src->flags;
77- dst->dummy = src->dummy;
78-}
79-
80-
81-
82-
1+#include "osecpu.h"
2+#include "jitc.h"
3+
4+//
5+// JITC common functions (architecture not dependent)
6+//
7+
8+void errorHandler(HOSECPU_RuntimeEnvironment *r)
9+{
10+ puts("security error! abort...");
11+ printf("debugInfo0=%d, debugInfo1=%d\n", r->debugInfo0, r->debugInfo1);
12+#if (USE_DEBUGGER != 0)
13+ dbgrMain(r);
14+#endif
15+ exit(1);
16+}
17+
18+int jitCompCmdLen(const unsigned char *src)
19+{
20+ //BCode命令長を取得する
21+ int i = 1;
22+
23+ if (0x01 <= *src && *src < 0x04){
24+ // LB, LIMM, PLIMM
25+ i = 6;
26+ } else if (*src == 0x04){
27+ // CND
28+ i = 2;
29+ } else if (0x08 <= *src && *src < 0x0d){
30+ // LMEM, SMEM, ??, ??, ??
31+ i = 8 + src[7] * 4;
32+ } else if (0x0e <= *src && *src < 0x10){
33+ // PADD, PDIF
34+ i = 8;
35+ } else if (0x10 <= *src && *src < 0x1c){
36+ // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD,
37+ i = 4;
38+ } else if (0x1c <= *src && *src < 0x1f){
39+ // ??, ??, PCP
40+ i = 3;
41+ } else if (*src == 0x1f){
42+ // ??
43+ i = 11;
44+ } else if(0x20 <= *src && *src < 0x2e){
45+ // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ,
46+ // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG,
47+ i = 4;
48+ } else if (*src == 0x2f){
49+ // ??
50+ i = 4 + src[1];
51+ } else if (0x30 <= *src && *src < 0x34){
52+ // ??, ??, MALLOC, ??
53+ i = 4;
54+ } else if (0x3c <= *src && *src < 0x3e){
55+ // ??, ??
56+ i = 7;
57+ } else if (*src == 0xfe){
58+ // REMARK
59+ i = 2 + src[1];
60+ }
61+
62+ return i;
63+}
64+
65+void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src)
66+{
67+ // なんか直接代入するとMacではアライメントエラーで落ちるのです...
68+ // *dst = *src;
69+
70+ dst->p = src->p;
71+ dst->typ = src->typ;
72+ dst->p0 = src->p0;
73+ dst->p1 = src->p1;
74+ dst->liveSign = src->liveSign;
75+ dst->pls = src->pls;
76+ dst->flags = src->flags;
77+ dst->dummy = src->dummy;
78+}
79+
80+
81+
82+
--- a/jitc.h
+++ b/jitc.h
@@ -1,4 +1,4 @@
1-
1+
22 #ifndef HeavyOSECPU_jitc_h
33 #define HeavyOSECPU_jitc_h
44
--- a/jitcx86.c
+++ b/jitcx86.c
@@ -1,4 +1,4 @@
1-#include "osecpu.h"
1+#include "osecpu.h"
22 #include "jitc.h"
33
44 #if (JITC_ARCNUM == 0x0001)
--- a/jitcx86a.c
+++ b/jitcx86a.c
@@ -1,4 +1,4 @@
1-#include "osecpu.h"
1+#include "osecpu.h"
22 #include "jitc.h"
33
44 #if (JITC_ARCNUM == 0x0001)
--- a/main.c
+++ b/main.c
@@ -1,4 +1,4 @@
1-#include "osecpu.h"
1+#include "osecpu.h"
22
33 int *keybuf, keybuf_r, keybuf_w, keybuf_c;
44 HOSECPU_Device_Window mainWindow;
--- a/osecpu.h
+++ b/osecpu.h
@@ -1,242 +1,242 @@
1-#ifndef _HDLOAD_OSECPU
2-#define _HDLOAD_OSECPU 1
3-
4-/* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/
5-#define _CRT_SECURE_NO_WARNINGS 1
6-
7-//
8-// Including stdc headers
9-//
10-
11-#include <stdio.h>
12-#include <string.h>
13-#include <limits.h>
14-#include <time.h>
15-#include <setjmp.h>
16-#include <stdlib.h>
17-
18-
19-//
20-// Compile options
21-//
22-
23-// Target architecture
24-// 1 : i386
25-#define JITC_ARCNUM 0x0001
26-
27-// Target operating system
28-// 1 : Windows 32bit
29-// 2 : Mac OSX 32bit
30-// 3 : blike for Linux
31-#ifdef _WIN32
32-#define DRV_OSNUM 0x0001
33-#endif
34-#ifdef __APPLE__
35-#define DRV_OSNUM 0x0002
36-#endif
37-#ifdef __linux__
38-#define DRV_OSNUM 0x0003
39-#endif
40-//#define DRV_OSNUM 0x0002
41-
42-// Decoder (syslib.ose) setting
43-// syslib.ose is necessary to work OSECPU
44-#define SYSLIB_OSE "syslib.ose"
45-
46-//
47-// Define constant values
48-//
49-
50-// SIGN1: The 2nd signature of OSECPU Format(05 e1)
51-// It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers)
52-#define SIGN1 0xe1
53-
54-#define USE_DEBUGGER 1
55-#define USE_TEK5 1
56-
57-/* JITC mode flags */
58-#define JITC_LV_SLOWEST 0 /* デバッグ支援は何でもやる */
59-#define JITC_LV_SLOWER 1 /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
60-#define JITC_LV_SAFE 2 /* とにかく止まる、場所は不明、テストは必要最小限 */
61-#define JITC_LV_FASTER 4 /* 情報は生成するがチェックをしない */
62-#define JITC_LV_FASTEST 5 /* 情報すら生成しない */
63-#define JITC_PHASE1 0x0001
64-#define JITC_SKIPCHECK 0x0002 /* セキュリティチェックを省略する(高速危険モード) */
65-#define JITC_NOSTARTUP 0x0004
66-#define JITC_MAXLABELS 4096
67-#define PTRCTRLSIZ 4096
68-
69-#define APPSIZ1 1 * 1024 * 1024 /* 1MB for now */
70-#define APPJITSIZE 1 * 1024 * 1024 /* 1MB for now */
71-#define SYSJITSIZ1 2 * 1024 * 1024 /* 1MB for now */
72-#define SYSLIBSIZ1 1 * 1024 * 1024 /* 1MB for now */
73-#define SYSTMP0SIZ 1 * 1024 * 1024 /* 1MB for now */
74-#define SYSTMP1SIZ 2 * 1024 * 1024 /* 1MB for now */
75-
76-#define KEYBUFSIZ 4096
77-
78-#define KEY_ENTER '\n'
79-#define KEY_ESC 27
80-#define KEY_BACKSPACE 8
81-#define KEY_TAB 9
82-#define KEY_PAGEUP 0x1020
83-#define KEY_PAGEDWN 0x1021
84-#define KEY_END 0x1022
85-#define KEY_HOME 0x1023
86-#define KEY_LEFT 0x1024
87-#define KEY_UP 0x1025
88-#define KEY_RIGHT 0x1026
89-#define KEY_DOWN 0x1027
90-#define KEY_INS 0x1028
91-#define KEY_DEL 0x1029
92-
93-//
94-// HOSECPU structures
95-//
96-typedef struct PtrCtrl HOSECPU_PointerControlTag;
97-struct PtrCtrl {
98- int liveSign;
99- int size, typ;
100- unsigned char *p0;
101-};
102-
103-typedef struct Ptr HOSECPU_PointerRegisterEntry;
104-struct Ptr {
105- // 32バイト(=256bit!)
106- unsigned char *p;
107-
108- /* static char *typName[] = {
109- "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8",
110- "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32",
111- "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2",
112- "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12",
113- "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24",
114- "T_SINT28", "T_UINT28"
115- } ; */
116- int typ;
117- unsigned char *p0, *p1;
118- int liveSign;
119- HOSECPU_PointerControlTag *pls;
120- int flags, dummy; /* read/writeなど */
121-};
122-
123-typedef struct LabelTable HOSECPU_LabelListTag;
124-struct LabelTable {
125- unsigned char *p, *p1;
126- int opt;
127- /*
128- * default = -1
129- * TYP_CODE = 0
130- * T_UINT8 = 3
131- *
132- * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053
133- */
134- int typ;
135-};
136-
137-typedef struct Device_Window HOSECPU_Device_Window;
138-struct Device_Window {
139- int *vram;
140- int xsize, ysize;
141-};
142-
143-typedef struct Regs HOSECPU_RuntimeEnvironment;
144-struct Regs {
145- int ireg[64]; // 整数レジスタ (4 * 64) = 256
146- HOSECPU_PointerRegisterEntry preg[64]; // ポインタレジスタ (32 * 64) = 2048
147- //
148- int debugInfo0; // 2304
149- int debugInfo1; // 2308
150- int dbg_currentCode; // 2312
151- int dmy; // 2316
152- //
153- HOSECPU_PointerControlTag *ptrCtrl; // 2320
154- char winClosed, autoSleep;
155- jmp_buf setjmpEnv;
156- int appReturnCode; // アプリ自体の終了コード
157-
158- /* Main environment */
159- int mainArgc; // HOSECPU起動引数の個数
160- const char **mainArgv; // HOSECPU起動引数リスト
161- unsigned char *appBin; // 実行するアプリのバイナリ
162- int appSize0;
163- int appSize1;
164- int executionLevel;
165-
166- /* for-junkApi */
167- unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
168-
169- HOSECPU_LabelListTag *label;
170- int maxLabels;
171- unsigned char *jitbuf, *jitbuf1;
172- void(*errHndl)(HOSECPU_RuntimeEnvironment *);
173- char dbgr;
174- int mapDi1s[16][16];
175-};
176-
177-//
178-// Grobal values
179-//
180-
181-extern int *keybuf, keybuf_r, keybuf_w, keybuf_c;
182-extern HOSECPU_Device_Window mainWindow;
183-// di1_serial: デバッグ用。プログラム中の随所で加算される変数
184-extern int di1_serial;
185-
186-//
187-// Functions
188-//
189-
190-// @main.c
191-void putKeybuf(int i);
192-int HeavyOSECPUMain(int argc, char **argv);
193-
194-// @comlib.c
195-unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
196-// @dpndenv.c
197-// OSに依存する関数群を定義する。
198-void *mallocRWE(int bytes); // 実行権付きメモリのmalloc.
199-void drv_openWin(int x, int y, unsigned char *buf, char *winClosed);
200-void drv_flshWin(int sx, int sy, int x0, int y0);
201-void drv_sleep(int msec);
202-
203-// @function.c
204-void dbgrMain(HOSECPU_RuntimeEnvironment *r);
205-const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理.
206-void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数
207-
208-// @jitc.c
209-void errorHandler(HOSECPU_RuntimeEnvironment *r);
210-void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src);
211-// @jitcx86.c
212-int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);
213-int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, HOSECPU_LabelListTag *label, int maxLabels, int level, int debugInfo1, int flags);
214-unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
215-unsigned char *jitCompInit(unsigned char *dst);
216-void jitcRunBinary(void (*bin)(char *), HOSECPU_RuntimeEnvironment *env);
217-
218-// @randmt.c
219-void randStatInit(unsigned int seed);
220-void randStatNext();
221-unsigned int randGetNextUInt32(void);
222-
223-// @screen.c
224-static int iColor1[] = {
225- 0x000000, 0xff0000, 0x00ff00, 0xffff00,
226- 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
227-};
228-void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r);
229-void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx);
230-void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx);
231-int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx);
232-
233-// @usetek.c
234-#if (USE_TEK5 != 0)
235-#include "tek.h"
236-int appackSub2(const UCHAR **pp, char *pif);
237-int appackSub3u(const UCHAR **pp, char *pif);
238-int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp);
239-#endif
240-
241-
242-#endif
1+#ifndef _HDLOAD_OSECPU
2+#define _HDLOAD_OSECPU 1
3+
4+/* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/
5+#define _CRT_SECURE_NO_WARNINGS 1
6+
7+//
8+// Including stdc headers
9+//
10+
11+#include <stdio.h>
12+#include <string.h>
13+#include <limits.h>
14+#include <time.h>
15+#include <setjmp.h>
16+#include <stdlib.h>
17+
18+
19+//
20+// Compile options
21+//
22+
23+// Target architecture
24+// 1 : i386
25+#define JITC_ARCNUM 0x0001
26+
27+// Target operating system
28+// 1 : Windows 32bit
29+// 2 : Mac OSX 32bit
30+// 3 : blike for Linux
31+#ifdef _WIN32
32+#define DRV_OSNUM 0x0001
33+#endif
34+#ifdef __APPLE__
35+#define DRV_OSNUM 0x0002
36+#endif
37+#ifdef __linux__
38+#define DRV_OSNUM 0x0003
39+#endif
40+//#define DRV_OSNUM 0x0002
41+
42+// Decoder (syslib.ose) setting
43+// syslib.ose is necessary to work OSECPU
44+#define SYSLIB_OSE "syslib.ose"
45+
46+//
47+// Define constant values
48+//
49+
50+// SIGN1: The 2nd signature of OSECPU Format(05 e1)
51+// It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers)
52+#define SIGN1 0xe1
53+
54+#define USE_DEBUGGER 1
55+#define USE_TEK5 1
56+
57+/* JITC mode flags */
58+#define JITC_LV_SLOWEST 0 /* デバッグ支援は何でもやる */
59+#define JITC_LV_SLOWER 1 /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */
60+#define JITC_LV_SAFE 2 /* とにかく止まる、場所は不明、テストは必要最小限 */
61+#define JITC_LV_FASTER 4 /* 情報は生成するがチェックをしない */
62+#define JITC_LV_FASTEST 5 /* 情報すら生成しない */
63+#define JITC_PHASE1 0x0001
64+#define JITC_SKIPCHECK 0x0002 /* セキュリティチェックを省略する(高速危険モード) */
65+#define JITC_NOSTARTUP 0x0004
66+#define JITC_MAXLABELS 4096
67+#define PTRCTRLSIZ 4096
68+
69+#define APPSIZ1 1 * 1024 * 1024 /* 1MB for now */
70+#define APPJITSIZE 1 * 1024 * 1024 /* 1MB for now */
71+#define SYSJITSIZ1 2 * 1024 * 1024 /* 1MB for now */
72+#define SYSLIBSIZ1 1 * 1024 * 1024 /* 1MB for now */
73+#define SYSTMP0SIZ 1 * 1024 * 1024 /* 1MB for now */
74+#define SYSTMP1SIZ 2 * 1024 * 1024 /* 1MB for now */
75+
76+#define KEYBUFSIZ 4096
77+
78+#define KEY_ENTER '\n'
79+#define KEY_ESC 27
80+#define KEY_BACKSPACE 8
81+#define KEY_TAB 9
82+#define KEY_PAGEUP 0x1020
83+#define KEY_PAGEDWN 0x1021
84+#define KEY_END 0x1022
85+#define KEY_HOME 0x1023
86+#define KEY_LEFT 0x1024
87+#define KEY_UP 0x1025
88+#define KEY_RIGHT 0x1026
89+#define KEY_DOWN 0x1027
90+#define KEY_INS 0x1028
91+#define KEY_DEL 0x1029
92+
93+//
94+// HOSECPU structures
95+//
96+typedef struct PtrCtrl HOSECPU_PointerControlTag;
97+struct PtrCtrl {
98+ int liveSign;
99+ int size, typ;
100+ unsigned char *p0;
101+};
102+
103+typedef struct Ptr HOSECPU_PointerRegisterEntry;
104+struct Ptr {
105+ // 32バイト(=256bit!)
106+ unsigned char *p;
107+
108+ /* static char *typName[] = {
109+ "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8",
110+ "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32",
111+ "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2",
112+ "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12",
113+ "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24",
114+ "T_SINT28", "T_UINT28"
115+ } ; */
116+ int typ;
117+ unsigned char *p0, *p1;
118+ int liveSign;
119+ HOSECPU_PointerControlTag *pls;
120+ int flags, dummy; /* read/writeなど */
121+};
122+
123+typedef struct LabelTable HOSECPU_LabelListTag;
124+struct LabelTable {
125+ unsigned char *p, *p1;
126+ int opt;
127+ /*
128+ * default = -1
129+ * TYP_CODE = 0
130+ * T_UINT8 = 3
131+ *
132+ * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053
133+ */
134+ int typ;
135+};
136+
137+typedef struct Device_Window HOSECPU_Device_Window;
138+struct Device_Window {
139+ int *vram;
140+ int xsize, ysize;
141+};
142+
143+typedef struct Regs HOSECPU_RuntimeEnvironment;
144+struct Regs {
145+ int ireg[64]; // 整数レジスタ (4 * 64) = 256
146+ HOSECPU_PointerRegisterEntry preg[64]; // ポインタレジスタ (32 * 64) = 2048
147+ //
148+ int debugInfo0; // 2304
149+ int debugInfo1; // 2308
150+ int dbg_currentCode; // 2312
151+ int dmy; // 2316
152+ //
153+ HOSECPU_PointerControlTag *ptrCtrl; // 2320
154+ char winClosed, autoSleep;
155+ jmp_buf setjmpEnv;
156+ int appReturnCode; // アプリ自体の終了コード
157+
158+ /* Main environment */
159+ int mainArgc; // HOSECPU起動引数の個数
160+ const char **mainArgv; // HOSECPU起動引数リスト
161+ unsigned char *appBin; // 実行するアプリのバイナリ
162+ int appSize0;
163+ int appSize1;
164+ int executionLevel;
165+
166+ /* for-junkApi */
167+ unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1;
168+
169+ HOSECPU_LabelListTag *label;
170+ int maxLabels;
171+ unsigned char *jitbuf, *jitbuf1;
172+ void(*errHndl)(HOSECPU_RuntimeEnvironment *);
173+ char dbgr;
174+ int mapDi1s[16][16];
175+};
176+
177+//
178+// Grobal values
179+//
180+
181+extern int *keybuf, keybuf_r, keybuf_w, keybuf_c;
182+extern HOSECPU_Device_Window mainWindow;
183+// di1_serial: デバッグ用。プログラム中の随所で加算される変数
184+extern int di1_serial;
185+
186+//
187+// Functions
188+//
189+
190+// @main.c
191+void putKeybuf(int i);
192+int HeavyOSECPUMain(int argc, char **argv);
193+
194+// @comlib.c
195+unsigned char *ComLib_main(const unsigned char *p, unsigned char *q);
196+// @dpndenv.c
197+// OSに依存する関数群を定義する。
198+void *mallocRWE(int bytes); // 実行権付きメモリのmalloc.
199+void drv_openWin(int x, int y, unsigned char *buf, char *winClosed);
200+void drv_flshWin(int sx, int sy, int x0, int y0);
201+void drv_sleep(int msec);
202+
203+// @function.c
204+void dbgrMain(HOSECPU_RuntimeEnvironment *r);
205+const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理.
206+void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数
207+
208+// @jitc.c
209+void errorHandler(HOSECPU_RuntimeEnvironment *r);
210+void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src);
211+// @jitcx86.c
212+int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label);
213+int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, HOSECPU_LabelListTag *label, int maxLabels, int level, int debugInfo1, int flags);
214+unsigned char *jitCompCallFunc(unsigned char *dst, void *func);
215+unsigned char *jitCompInit(unsigned char *dst);
216+void jitcRunBinary(void (*bin)(char *), HOSECPU_RuntimeEnvironment *env);
217+
218+// @randmt.c
219+void randStatInit(unsigned int seed);
220+void randStatNext();
221+unsigned int randGetNextUInt32(void);
222+
223+// @screen.c
224+static int iColor1[] = {
225+ 0x000000, 0xff0000, 0x00ff00, 0xffff00,
226+ 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff
227+};
228+void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r);
229+void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx);
230+void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx);
231+int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx);
232+
233+// @usetek.c
234+#if (USE_TEK5 != 0)
235+#include "tek.h"
236+int appackSub2(const UCHAR **pp, char *pif);
237+int appackSub3u(const UCHAR **pp, char *pif);
238+int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp);
239+#endif
240+
241+
242+#endif
--- a/tek.c
+++ b/tek.c
@@ -1,4 +1,4 @@
1-#include <setjmp.h>
1+#include <setjmp.h>
22 #include <string.h>
33 #include <stdlib.h>
44
--- a/tek.h
+++ b/tek.h
@@ -1,4 +1,4 @@
1-//
1+//
22 // tek.h
33 // HeavyOSECPU
44 //
--- a/usetek.c
+++ b/usetek.c
@@ -1,88 +1,88 @@
1-
2-#include "osecpu.h"
3-#if (USE_TEK5 != 0)
4-/*----For using tek Begin----*/
5-#include "tek.h"
6-
7-int appackSub2(const UCHAR **pp, char *pif)
8-{
9- int r = 0;
10- const UCHAR *p = *pp;
11- if (*pif == 0) {
12- r = *p >> 4;
13- } else {
14- r = *p & 0x0f;
15- p++;
16- *pp = p;
17- }
18- *pif ^= 1;
19-
20- return r;
21-}
22-
23-int appackSub3u(const UCHAR **pp, char *pif)
24-{
25- int r = 0, i;
26-
27- r = appackSub2(pp, pif);
28- if (0x8 <= r && r <= 0xb) {
29- r = r << 4 | appackSub2(pp, pif);
30- r &= 0x3f;
31- } else if (0xc <= r && r <= 0xd) {
32- r = r << 4 | appackSub2(pp, pif);
33- r = r << 4 | appackSub2(pp, pif);
34- r &= 0x1ff;
35- } else if (r == 0xe) {
36- r = appackSub2(pp, pif);
37- r = r << 4 | appackSub2(pp, pif);
38- r = r << 4 | appackSub2(pp, pif);
39- } else if (r == 0x7) {
40- i = appackSub3u(pp, pif);
41- r = 0;
42- while (i > 0) {
43- r = r << 4 | appackSub2(pp, pif);
44- i--;
45- }
46- }
47-
48- return r;
49-}
50-
51-int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp)
52-{
53- static char tek5head[16] = {
54- 0x89, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
55- 0x4f, 0x53, 0x41, 0x53, 0x4b, 0x43, 0x4d, 0x50
56- };
57- memcpy(tmp, tek5head, 16);
58- UCHAR *q = tmp + 16;
59- char iif = 0;
60- int i, tmpsiz;
61- const UCHAR *p = &buf[1];
62- i = appackSub3u(&p, &iif);
63- tmpsiz = appackSub3u(&p, &iif);
64- tmpsiz = tmpsiz << 8 | *p++;
65- *q++ = (tmpsiz >> 27) & 0xfe;
66- *q++ = (tmpsiz >> 20) & 0xfe;
67- *q++ = (tmpsiz >> 13) & 0xfe;
68- *q++ = (tmpsiz >> 6) & 0xfe;
69- *q++ = (tmpsiz << 1 | 1) & 0xff;
70- if (i == 1) *q++ = 0x15;
71- if (i == 2) *q++ = 0x19;
72- if (i == 3) *q++ = 0x21;
73- if (i >= 4) return -9;
74- while (p < buf1){
75- *q++ = *p++;
76- }
77- if(tek_decomp(tmp, buf, tmpsiz) != 0){;
78- // failed
79- fputs("tek decomp error.\n", stderr);
80- exit(1);
81- }
82- //success
83- return tmpsiz;
84-}
85-
86-/*----For using tek End----*/
87-#endif
88-
1+
2+#include "osecpu.h"
3+#if (USE_TEK5 != 0)
4+/*----For using tek Begin----*/
5+#include "tek.h"
6+
7+int appackSub2(const UCHAR **pp, char *pif)
8+{
9+ int r = 0;
10+ const UCHAR *p = *pp;
11+ if (*pif == 0) {
12+ r = *p >> 4;
13+ } else {
14+ r = *p & 0x0f;
15+ p++;
16+ *pp = p;
17+ }
18+ *pif ^= 1;
19+
20+ return r;
21+}
22+
23+int appackSub3u(const UCHAR **pp, char *pif)
24+{
25+ int r = 0, i;
26+
27+ r = appackSub2(pp, pif);
28+ if (0x8 <= r && r <= 0xb) {
29+ r = r << 4 | appackSub2(pp, pif);
30+ r &= 0x3f;
31+ } else if (0xc <= r && r <= 0xd) {
32+ r = r << 4 | appackSub2(pp, pif);
33+ r = r << 4 | appackSub2(pp, pif);
34+ r &= 0x1ff;
35+ } else if (r == 0xe) {
36+ r = appackSub2(pp, pif);
37+ r = r << 4 | appackSub2(pp, pif);
38+ r = r << 4 | appackSub2(pp, pif);
39+ } else if (r == 0x7) {
40+ i = appackSub3u(pp, pif);
41+ r = 0;
42+ while (i > 0) {
43+ r = r << 4 | appackSub2(pp, pif);
44+ i--;
45+ }
46+ }
47+
48+ return r;
49+}
50+
51+int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp)
52+{
53+ static char tek5head[16] = {
54+ 0x89, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00,
55+ 0x4f, 0x53, 0x41, 0x53, 0x4b, 0x43, 0x4d, 0x50
56+ };
57+ memcpy(tmp, tek5head, 16);
58+ UCHAR *q = tmp + 16;
59+ char iif = 0;
60+ int i, tmpsiz;
61+ const UCHAR *p = &buf[1];
62+ i = appackSub3u(&p, &iif);
63+ tmpsiz = appackSub3u(&p, &iif);
64+ tmpsiz = tmpsiz << 8 | *p++;
65+ *q++ = (tmpsiz >> 27) & 0xfe;
66+ *q++ = (tmpsiz >> 20) & 0xfe;
67+ *q++ = (tmpsiz >> 13) & 0xfe;
68+ *q++ = (tmpsiz >> 6) & 0xfe;
69+ *q++ = (tmpsiz << 1 | 1) & 0xff;
70+ if (i == 1) *q++ = 0x15;
71+ if (i == 2) *q++ = 0x19;
72+ if (i == 3) *q++ = 0x21;
73+ if (i >= 4) return -9;
74+ while (p < buf1){
75+ *q++ = *p++;
76+ }
77+ if(tek_decomp(tmp, buf, tmpsiz) != 0){;
78+ // failed
79+ fputs("tek decomp error.\n", stderr);
80+ exit(1);
81+ }
82+ //success
83+ return tmpsiz;
84+}
85+
86+/*----For using tek End----*/
87+#endif
88+
旧リポジトリブラウザで表示