OSDN Git Service

syslibのエラーは出なくなったがアプリは動かない(pack error)
[heavyosecpu/HeavyOSECPU.git] / dpndenv.c
index 54a520b..e579393 100644 (file)
--- a/dpndenv.c
+++ b/dpndenv.c
-#include "osecpu.h"\r
-\r
-\r
-#if (DRV_OSNUM == 0x0002)\r
-//\r
-// for Mac OSX 32-bit\r
-//\r
-#include <mach/mach.h>\r
-#include <Cocoa/Cocoa.h>\r
-\r
-void *mallocRWE(int bytes)\r
-{\r
-       void *p = malloc(bytes);\r
-       vm_protect(mach_task_self(), (vm_address_t) p, bytes, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);\r
-       return p;\r
-}\r
-\r
-NSApplication* app;\r
-\r
-@interface OSECPUView : NSView\r
-{\r
-       unsigned char *_buf;\r
-       int _sx;\r
-       int _sy;\r
-       CGContextRef _context;\r
-}\r
-\r
-- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy;\r
-- (void)drawRect:(NSRect)rect;\r
-@end\r
-\r
-@implementation OSECPUView\r
-- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy\r
-{\r
-       self = [super initWithFrame:frameRect];\r
-       if (self) {\r
-               _buf = buf;\r
-               _sx = sx;\r
-               _sy = sy;\r
-       }\r
-       return self;\r
-}\r
-\r
-- (void)drawRect:(NSRect)rect {\r
-       CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();\r
-       _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));\r
-       CGImageRef image = CGBitmapContextCreateImage(_context);\r
-       CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];\r
-       CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);\r
-       \r
-       CFRelease(colorSpace);\r
-       CFRelease(image);\r
-}\r
-\r
-@end\r
-\r
-@interface Main : NSObject<NSWindowDelegate>\r
-{\r
-       int argc;\r
-       const unsigned char **argv;\r
-       char *winClosed;\r
-       OSECPUView *_view;\r
-}\r
-\r
-- (void)runApp;\r
-- (void)createThread:(int)_argc args:(const unsigned char **)_argv;\r
-- (BOOL)windowShouldClose:(id)sender;\r
-- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int)sy winClosed:(char *)_winClosed;\r
-- (void)flushWin:(NSRect)rect;\r
-@end\r
-\r
-@implementation Main\r
-- (void)runApp\r
-{\r
-       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];\r
-       HeavyOSECPUMain(argc, (char **)argv);\r
-       [NSApp terminate:self];\r
-       [pool release];\r
-}\r
-\r
-- (void)createThread : (int)_argc args:(const unsigned char **)_argv\r
-{\r
-       argc = _argc;\r
-       argv = _argv;\r
-       NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];\r
-       [thread start];\r
-}\r
-\r
-- (BOOL)windowShouldClose:(id)sender\r
-{\r
-       *winClosed = 1;\r
-       return YES;\r
-}\r
-\r
-- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed\r
-{\r
-       \r
-       NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO];\r
-       [window setTitle: @"osecpu"];\r
-       [window center];\r
-       [window makeKeyAndOrderFront:nil];\r
-       [window setReleasedWhenClosed:YES];\r
-       window.delegate = self;\r
-       winClosed = _winClosed;\r
-       \r
-       _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy];\r
-       [window.contentView addSubview:_view];\r
-}\r
-\r
-- (void)flushWin : (NSRect)rect\r
-{\r
-       [_view drawRect:rect];\r
-}\r
-\r
-@end\r
-\r
-id objc_main;\r
-\r
-int main(int argc, char **argv)\r
-{\r
-       objc_main = [[Main alloc] init];\r
-       \r
-       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];\r
-       app = [[NSApplication alloc] init];\r
-       [objc_main createThread:argc args:(const unsigned char **)argv];\r
-       [app run];\r
-       [pool release];\r
-       return 0;\r
-}\r
-\r
-void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)\r
-{\r
-       [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];\r
-}\r
-\r
-void drv_flshWin(int sx, int sy, int x0, int y0)\r
-{\r
-       [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];\r
-}\r
-\r
-void drv_sleep(int msec)\r
-{\r
-       [NSThread sleepForTimeInterval:0.001*msec];\r
-       return;\r
-}\r
-\r
-\r
-#elif (DRV_OSNUM == 0x0003)\r
-\r
-#error "Your OS is not supported."\r
-\r
-#elif (DRV_OSNUM == 0x0001)\r
-//\r
-// for Windows 32-bit\r
-//\r
-#include <windows.h>\r
-\r
-#define TIMER_ID                        1\r
-#define TIMER_INTERVAL         10\r
-\r
-struct BLD_WORK {\r
-       HINSTANCE hi;\r
-       HWND hw;\r
-       BITMAPINFO bmi;\r
-       int tmcount1, tmcount2, flags, smp; /* bit0: 終了 */\r
-       HANDLE mtx;\r
-       char *winClosed;\r
-};\r
-\r
-struct BLD_WORK bld_work;\r
-\r
-struct BL_WIN {\r
-       int xsiz, ysiz, *buf;\r
-};\r
-\r
-struct BL_WORK {\r
-       struct BL_WIN win;\r
-       jmp_buf jb;\r
-       int csiz_x, csiz_y, cx, cy, col0, col1, tabsiz, slctwin;\r
-       int tmcount, tmcount0, mod, rand_seed;\r
-       int *cbuf;\r
-       unsigned char *ftyp;\r
-       unsigned char **fptn;\r
-       int *ccol, *cbak;\r
-       int *kbuf, kbuf_rp, kbuf_wp, kbuf_c;\r
-};\r
-\r
-struct BL_WORK bl_work;\r
-\r
-#define BL_SIZ_KBUF                    8192\r
-\r
-#define BL_WAITKEYF            0x00000001\r
-#define BL_WAITKEYNF   0x00000002\r
-#define BL_WAITKEY             0x00000003\r
-#define BL_GETKEY              0x00000004\r
-#define BL_CLEARREP            0x00000008\r
-#define BL_DELFFF              0x00000010\r
-\r
-#define        BL_KEYMODE              0x00000000      // 作りかけ, make/remake/breakが見えるかどうか\r
-\r
-#define w      bl_work\r
-#define dw     bld_work\r
-\r
-void bld_openWin(int x, int y, char *winClosed);\r
-void bld_flshWin(int sx, int sy, int x0, int y0);\r
-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp);\r
-void bl_cls();\r
-int bl_iCol(int i);\r
-void bl_readyWin(int n);\r
-\r
-static HANDLE threadhandle;\r
-\r
-int main(int argc, char **argv)\r
-{\r
-       // Program entry point\r
-       return HeavyOSECPUMain(argc, argv);\r
-}\r
-\r
-void *mallocRWE(int bytes)\r
-{\r
-       void *p = malloc(bytes);\r
-       DWORD dmy;\r
-       VirtualProtect(p, bytes, PAGE_EXECUTE_READWRITE, &dmy);\r
-       return p;\r
-}\r
-\r
-static int winthread(void *dmy)\r
-{\r
-       WNDCLASSEX wc;\r
-       RECT r;\r
-       int i, x, y;\r
-       MSG msg;\r
-       \r
-       x = dw.bmi.bmiHeader.biWidth;\r
-       y = -dw.bmi.bmiHeader.biHeight;\r
-       \r
-       wc.cbSize = sizeof (WNDCLASSEX);\r
-       wc.style = CS_HREDRAW | CS_VREDRAW;\r
-       wc.lpfnWndProc = WndProc;\r
-       wc.cbClsExtra = 0;\r
-       wc.cbWndExtra = 0;\r
-       wc.hInstance = dw.hi;\r
-       wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),\r
-                                                               IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
-       wc.hIconSm = wc.hIcon;\r
-       wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),\r
-                                                                       IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);\r
-       wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;\r
-       wc.lpszMenuName = NULL;\r
-       wc.lpszClassName = L"WinClass";\r
-       if (RegisterClassEx(&wc) == 0)\r
-               return 1;\r
-       r.left = 0;\r
-       r.top = 0;\r
-       r.right = x;\r
-       r.bottom = y;\r
-       AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);\r
-       x = r.right - r.left;\r
-       y = r.bottom - r.top;\r
-       \r
-       char *t = "osecpu";\r
-       \r
-       dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,\r
-                                                 CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);\r
-       if (dw.hw == NULL)\r
-               return 1;\r
-       ShowWindow(dw.hw, SW_SHOW);\r
-       UpdateWindow(dw.hw);\r
-       SetTimer(dw.hw, TIMER_ID, TIMER_INTERVAL, NULL);\r
-       SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);\r
-       SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);\r
-       dw.flags |= 2 | 4;\r
-       \r
-       for (;;) {\r
-               i = GetMessage(&msg, NULL, 0, 0);\r
-               if (i == 0 || i == -1)  /* エラーもしくは終了メッセージ */\r
-                       break;\r
-               /* そのほかはとりあえずデフォルト処理で */\r
-               TranslateMessage(&msg);\r
-               DispatchMessage(&msg);\r
-       }\r
-       //      PostQuitMessage(0);\r
-       dw.flags |= 1; /* 終了, bld_waitNF()が見つける */\r
-       if (dw.winClosed != NULL)\r
-               *dw.winClosed = 1;\r
-       return 0;\r
-}\r
-\r
-void bld_openWin(int sx, int sy, char *winClosed)\r
-{\r
-       static int i;\r
-       \r
-       dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);\r
-       dw.bmi.bmiHeader.biWidth = sx;\r
-       dw.bmi.bmiHeader.biHeight = -sy;\r
-       dw.bmi.bmiHeader.biPlanes = 1;\r
-       dw.bmi.bmiHeader.biBitCount = 32;\r
-       dw.bmi.bmiHeader.biCompression = BI_RGB;\r
-       dw.winClosed = winClosed;\r
-       \r
-       threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);\r
-       \r
-       return;\r
-}\r
-\r
-void drv_flshWin(int sx, int sy, int x0, int y0)\r
-{\r
-       InvalidateRect(dw.hw, NULL, FALSE);\r
-       UpdateWindow(dw.hw);\r
-       return;\r
-}\r
-\r
-LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)\r
-{\r
-       int i, j;\r
-       if (msg == WM_PAINT) {\r
-               PAINTSTRUCT ps;\r
-               HDC hdc = BeginPaint(dw.hw, &ps);\r
-               SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,\r
-                                                 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);\r
-               EndPaint(dw.hw, &ps);\r
-       }\r
-       if (msg == WM_DESTROY) {\r
-               PostQuitMessage(0);\r
-               return 0;\r
-       }\r
-       if (msg == WM_TIMER && wp == TIMER_ID) {\r
-               w.tmcount += TIMER_INTERVAL;\r
-               return 0;\r
-       }\r
-       if (msg == WM_TIMER && wp == TIMER_ID + 1) {\r
-               dw.tmcount1 += TIMER_INTERVAL * 10;\r
-               w.tmcount = dw.tmcount1;\r
-               return 0;\r
-       }\r
-       if (msg == WM_TIMER && wp == TIMER_ID + 2) {\r
-               dw.tmcount2 += TIMER_INTERVAL * 100;\r
-               w.tmcount = dw.tmcount1 = dw.tmcount2;\r
-               return 0;\r
-       }\r
-       if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {\r
-               i = -1;\r
-               \r
-               if (wp == VK_RETURN)    i = KEY_ENTER;\r
-               if (wp == VK_ESCAPE)    i = KEY_ESC;\r
-               if (wp == VK_BACK)              i = KEY_BACKSPACE;\r
-               if (wp == VK_TAB)               i = KEY_TAB;\r
-               if (wp == VK_PRIOR)             i = KEY_PAGEUP;\r
-               if (wp == VK_NEXT)              i = KEY_PAGEDWN;\r
-               if (wp == VK_END)               i = KEY_END;\r
-               if (wp == VK_HOME)              i = KEY_HOME;\r
-               if (wp == VK_LEFT)              i = KEY_LEFT;\r
-               if (wp == VK_RIGHT)             i = KEY_RIGHT;\r
-               if (wp == VK_UP)                i = KEY_UP;\r
-               if (wp == VK_DOWN)              i = KEY_DOWN;\r
-               if (wp == VK_INSERT)    i = KEY_INS;\r
-               if (wp == VK_DELETE)    i = KEY_DEL;\r
-               j &= 0;\r
-               if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;\r
-               if ((GetKeyState(VK_LMENU)    & (1 << 15)) != 0) j |= 1 << 18;\r
-               if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;\r
-               if ((GetKeyState(VK_RMENU)    & (1 << 15)) != 0) j |= 1 << 26;\r
-               if ((GetKeyState(VK_RSHIFT)   & (1 << 15)) != 0) i |= 1 << 24;\r
-               if ((GetKeyState(VK_LSHIFT)   & (1 << 15)) != 0) i |= 1 << 16;\r
-               if ((GetKeyState(VK_NUMLOCK)  & (1 << 0)) != 0) i |= 1 << 22;\r
-               if ((GetKeyState(VK_CAPITAL)  & (1 << 0)) != 0) i |= 1 << 23;\r
-               if (j != 0) {\r
-                       if ('A' <= wp && wp <= 'Z') i = wp;\r
-               }\r
-               if (i != -1) {\r
-                       putKeybuf(i | j);\r
-                       //                      bl_putKeyB(1, &i);\r
-                       return 0;\r
-               }\r
-       }\r
-       if (msg == WM_KEYUP) {\r
-               i = 0xfff;\r
-               //              bl_putKeyB(1, &i);\r
-       }\r
-       if (msg == WM_CHAR) {\r
-               i = 0;\r
-               if (' ' <= wp && wp <= 0x7e) {\r
-                       i = wp;\r
-                       j &= 0;\r
-                       if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;\r
-                       if ((GetKeyState(VK_LMENU)    & (1 << 15)) != 0) j |= 1 << 18;\r
-                       if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;\r
-                       if ((GetKeyState(VK_RMENU)    & (1 << 15)) != 0) j |= 1 << 26;\r
-                       if ((GetKeyState(VK_RSHIFT)   & (1 << 15)) != 0) i |= 1 << 24;\r
-                       if ((GetKeyState(VK_LSHIFT)   & (1 << 15)) != 0) i |= 1 << 16;\r
-                       if ((GetKeyState(VK_NUMLOCK)  & (1 << 0)) != 0) i |= 1 << 22;\r
-                       if ((GetKeyState(VK_CAPITAL)  & (1 << 0)) != 0) i |= 1 << 23;\r
-                       if (('A' <= wp && wp <= 'Z') || ('a' <= wp && wp <= 'z')) {\r
-                               if (j != 0) {\r
-                                       i |= j;\r
-                                       i &= ~0x20;\r
-                               }\r
-                       }\r
-                       putKeybuf(i);\r
-                       //                      bl_putKeyB(1, &i);\r
-                       return 0;\r
-               }\r
-       }\r
-       return DefWindowProc(hw, msg, wp, lp);\r
-}\r
-\r
-void drv_openWin(int sx, int sy, UCHAR *buf, char *winClosed)\r
-{\r
-       w.win.buf = (int *)buf;\r
-       w.win.xsiz = sx;\r
-       w.win.ysiz = sy;\r
-       bld_openWin(sx, sy, winClosed);\r
-       return;\r
-}\r
-\r
-void drv_sleep(int msec)\r
-{\r
-       Sleep(msec);\r
-       //      MsgWaitForMultipleObjects(1, &threadhandle, FALSE, msec, QS_ALLINPUT);\r
-       /* 勉強不足でまだ書き方が分かりません! */\r
-       return;\r
-}\r
-\r
-#else\r
-\r
-#error "Illegal OS type. Edit osecpu.h and look at DRV_OSNUM"\r
-\r
+#include "osecpu.h"
+
+
+#if (DRV_OSNUM == 0x0002)
+//
+// for Mac OSX 32-bit
+//
+#include <mach/mach.h>
+#include <Cocoa/Cocoa.h>
+
+void *mallocRWE(int bytes)
+{
+       void *p = malloc(bytes);
+       vm_protect(mach_task_self(), (vm_address_t) p, bytes, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
+       return p;
+}
+
+NSApplication* app;
+
+@interface OSECPUView : NSView
+{
+       unsigned char *_buf;
+       int _sx;
+       int _sy;
+       CGContextRef _context;
+}
+
+- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy;
+- (void)drawRect:(NSRect)rect;
+@end
+
+@implementation OSECPUView
+- (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy
+{
+       self = [super initWithFrame:frameRect];
+       if (self) {
+               _buf = buf;
+               _sx = sx;
+               _sy = sy;
+       }
+       return self;
+}
+
+- (void)drawRect:(NSRect)rect {
+       CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
+       _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));
+       CGImageRef image = CGBitmapContextCreateImage(_context);
+       CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+       CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);
+       
+       CFRelease(colorSpace);
+       CFRelease(image);
+}
+
+@end
+
+@interface Main : NSObject<NSWindowDelegate>
+{
+       int argc;
+       const unsigned char **argv;
+       char *winClosed;
+       OSECPUView *_view;
+}
+
+- (void)runApp;
+- (void)createThread:(int)_argc args:(const unsigned char **)_argv;
+- (BOOL)windowShouldClose:(id)sender;
+- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int)sy winClosed:(char *)_winClosed;
+- (void)flushWin:(NSRect)rect;
+@end
+
+@implementation Main
+- (void)runApp
+{
+       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+       HeavyOSECPUMain(argc, (char **)argv);
+       [NSApp terminate:self];
+       [pool release];
+}
+
+- (void)createThread : (int)_argc args:(const unsigned char **)_argv
+{
+       argc = _argc;
+       argv = _argv;
+       NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];
+       [thread start];
+}
+
+- (BOOL)windowShouldClose:(id)sender
+{
+       *winClosed = 1;
+       return YES;
+}
+
+- (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed
+{
+       
+       NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO];
+       [window setTitle: @"osecpu"];
+       [window center];
+       [window makeKeyAndOrderFront:nil];
+       [window setReleasedWhenClosed:YES];
+       window.delegate = self;
+       winClosed = _winClosed;
+       
+       _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy];
+       [window.contentView addSubview:_view];
+}
+
+- (void)flushWin : (NSRect)rect
+{
+       [_view drawRect:rect];
+}
+
+@end
+
+id objc_main;
+
+int main(int argc, char **argv)
+{
+       objc_main = [[Main alloc] init];
+       
+       NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+       app = [[NSApplication alloc] init];
+       [objc_main createThread:argc args:(const unsigned char **)argv];
+       [app run];
+       [pool release];
+       return 0;
+}
+
+void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)
+{
+       [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];
+}
+
+void drv_flshWin(int sx, int sy, int x0, int y0)
+{
+       [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
+}
+
+void drv_sleep(int msec)
+{
+       [NSThread sleepForTimeInterval:0.001*msec];
+       return;
+}
+
+
+#elif (DRV_OSNUM == 0x0003)
+
+#error "Your OS is not supported."
+
+#elif (DRV_OSNUM == 0x0001)
+//
+// for Windows 32-bit
+//
+#include <windows.h>
+
+#define TIMER_ID                        1
+#define TIMER_INTERVAL         10
+
+struct BLD_WORK {
+       HINSTANCE hi;
+       HWND hw;
+       BITMAPINFO bmi;
+       int tmcount1, tmcount2, flags, smp; /* bit0: 終了 */
+       HANDLE mtx;
+       char *winClosed;
+};
+
+struct BLD_WORK bld_work;
+
+struct BL_WIN {
+       int xsiz, ysiz, *buf;
+};
+
+struct BL_WORK {
+       struct BL_WIN win;
+       jmp_buf jb;
+       int csiz_x, csiz_y, cx, cy, col0, col1, tabsiz, slctwin;
+       int tmcount, tmcount0, mod, rand_seed;
+       int *cbuf;
+       unsigned char *ftyp;
+       unsigned char **fptn;
+       int *ccol, *cbak;
+       int *kbuf, kbuf_rp, kbuf_wp, kbuf_c;
+};
+
+struct BL_WORK bl_work;
+
+#define BL_SIZ_KBUF                    8192
+
+#define BL_WAITKEYF            0x00000001
+#define BL_WAITKEYNF   0x00000002
+#define BL_WAITKEY             0x00000003
+#define BL_GETKEY              0x00000004
+#define BL_CLEARREP            0x00000008
+#define BL_DELFFF              0x00000010
+
+#define        BL_KEYMODE              0x00000000      // 作りかけ, make/remake/breakが見えるかどうか
+
+#define w      bl_work
+#define dw     bld_work
+
+void bld_openWin(int x, int y, char *winClosed);
+void bld_flshWin(int sx, int sy, int x0, int y0);
+LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp);
+void bl_cls();
+int bl_iCol(int i);
+void bl_readyWin(int n);
+
+static HANDLE threadhandle;
+
+int main(int argc, char **argv)
+{
+       // Program entry point
+       return HeavyOSECPUMain(argc, argv);
+}
+
+void *mallocRWE(int bytes)
+{
+       void *p = malloc(bytes);
+       DWORD dmy;
+       VirtualProtect(p, bytes, PAGE_EXECUTE_READWRITE, &dmy);
+       return p;
+}
+
+static int winthread(void *dmy)
+{
+       WNDCLASSEX wc;
+       RECT r;
+       int i, x, y;
+       MSG msg;
+       
+       x = dw.bmi.bmiHeader.biWidth;
+       y = -dw.bmi.bmiHeader.biHeight;
+       
+       wc.cbSize = sizeof (WNDCLASSEX);
+       wc.style = CS_HREDRAW | CS_VREDRAW;
+       wc.lpfnWndProc = WndProc;
+       wc.cbClsExtra = 0;
+       wc.cbWndExtra = 0;
+       wc.hInstance = dw.hi;
+       wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
+                                                               IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
+       wc.hIconSm = wc.hIcon;
+       wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
+                                                                       IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
+       wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
+       wc.lpszMenuName = NULL;
+       wc.lpszClassName = "WinClass";
+       if (RegisterClassEx(&wc) == 0)
+               return 1;
+       r.left = 0;
+       r.top = 0;
+       r.right = x;
+       r.bottom = y;
+       AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
+       x = r.right - r.left;
+       y = r.bottom - r.top;
+       
+       char *t = "osecpu";
+       
+       dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,
+                                                 CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
+       if (dw.hw == NULL)
+               return 1;
+       ShowWindow(dw.hw, SW_SHOW);
+       UpdateWindow(dw.hw);
+       SetTimer(dw.hw, TIMER_ID, TIMER_INTERVAL, NULL);
+       SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);
+       SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);
+       dw.flags |= 2 | 4;
+       
+       for (;;) {
+               i = GetMessage(&msg, NULL, 0, 0);
+               if (i == 0 || i == -1)  /* エラーもしくは終了メッセージ */
+                       break;
+               /* そのほかはとりあえずデフォルト処理で */
+               TranslateMessage(&msg);
+               DispatchMessage(&msg);
+       }
+       //      PostQuitMessage(0);
+       dw.flags |= 1; /* 終了, bld_waitNF()が見つける */
+       if (dw.winClosed != NULL)
+               *dw.winClosed = 1;
+       return 0;
+}
+
+void bld_openWin(int sx, int sy, char *winClosed)
+{
+       static int i;
+       
+       dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
+       dw.bmi.bmiHeader.biWidth = sx;
+       dw.bmi.bmiHeader.biHeight = -sy;
+       dw.bmi.bmiHeader.biPlanes = 1;
+       dw.bmi.bmiHeader.biBitCount = 32;
+       dw.bmi.bmiHeader.biCompression = BI_RGB;
+       dw.winClosed = winClosed;
+       
+       threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
+       
+       return;
+}
+
+void drv_flshWin(int sx, int sy, int x0, int y0)
+{
+       InvalidateRect(dw.hw, NULL, FALSE);
+       UpdateWindow(dw.hw);
+       return;
+}
+
+LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
+{
+       int i, j;
+       if (msg == WM_PAINT) {
+               PAINTSTRUCT ps;
+               HDC hdc = BeginPaint(dw.hw, &ps);
+               SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,
+                                                 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
+               EndPaint(dw.hw, &ps);
+       }
+       if (msg == WM_DESTROY) {
+               PostQuitMessage(0);
+               return 0;
+       }
+       if (msg == WM_TIMER && wp == TIMER_ID) {
+               w.tmcount += TIMER_INTERVAL;
+               return 0;
+       }
+       if (msg == WM_TIMER && wp == TIMER_ID + 1) {
+               dw.tmcount1 += TIMER_INTERVAL * 10;
+               w.tmcount = dw.tmcount1;
+               return 0;
+       }
+       if (msg == WM_TIMER && wp == TIMER_ID + 2) {
+               dw.tmcount2 += TIMER_INTERVAL * 100;
+               w.tmcount = dw.tmcount1 = dw.tmcount2;
+               return 0;
+       }
+       if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
+               i = -1;
+               
+               if (wp == VK_RETURN)    i = KEY_ENTER;
+               if (wp == VK_ESCAPE)    i = KEY_ESC;
+               if (wp == VK_BACK)              i = KEY_BACKSPACE;
+               if (wp == VK_TAB)               i = KEY_TAB;
+               if (wp == VK_PRIOR)             i = KEY_PAGEUP;
+               if (wp == VK_NEXT)              i = KEY_PAGEDWN;
+               if (wp == VK_END)               i = KEY_END;
+               if (wp == VK_HOME)              i = KEY_HOME;
+               if (wp == VK_LEFT)              i = KEY_LEFT;
+               if (wp == VK_RIGHT)             i = KEY_RIGHT;
+               if (wp == VK_UP)                i = KEY_UP;
+               if (wp == VK_DOWN)              i = KEY_DOWN;
+               if (wp == VK_INSERT)    i = KEY_INS;
+               if (wp == VK_DELETE)    i = KEY_DEL;
+               j &= 0;
+               if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
+               if ((GetKeyState(VK_LMENU)    & (1 << 15)) != 0) j |= 1 << 18;
+               if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
+               if ((GetKeyState(VK_RMENU)    & (1 << 15)) != 0) j |= 1 << 26;
+               if ((GetKeyState(VK_RSHIFT)   & (1 << 15)) != 0) i |= 1 << 24;
+               if ((GetKeyState(VK_LSHIFT)   & (1 << 15)) != 0) i |= 1 << 16;
+               if ((GetKeyState(VK_NUMLOCK)  & (1 << 0)) != 0) i |= 1 << 22;
+               if ((GetKeyState(VK_CAPITAL)  & (1 << 0)) != 0) i |= 1 << 23;
+               if (j != 0) {
+                       if ('A' <= wp && wp <= 'Z') i = wp;
+               }
+               if (i != -1) {
+                       putKeybuf(i | j);
+                       //                      bl_putKeyB(1, &i);
+                       return 0;
+               }
+       }
+       if (msg == WM_KEYUP) {
+               i = 0xfff;
+               //              bl_putKeyB(1, &i);
+       }
+       if (msg == WM_CHAR) {
+               i = 0;
+               if (' ' <= wp && wp <= 0x7e) {
+                       i = wp;
+                       j &= 0;
+                       if ((GetKeyState(VK_LCONTROL) & (1 << 15)) != 0) j |= 1 << 17;
+                       if ((GetKeyState(VK_LMENU)    & (1 << 15)) != 0) j |= 1 << 18;
+                       if ((GetKeyState(VK_RCONTROL) & (1 << 15)) != 0) j |= 1 << 25;
+                       if ((GetKeyState(VK_RMENU)    & (1 << 15)) != 0) j |= 1 << 26;
+                       if ((GetKeyState(VK_RSHIFT)   & (1 << 15)) != 0) i |= 1 << 24;
+                       if ((GetKeyState(VK_LSHIFT)   & (1 << 15)) != 0) i |= 1 << 16;
+                       if ((GetKeyState(VK_NUMLOCK)  & (1 << 0)) != 0) i |= 1 << 22;
+                       if ((GetKeyState(VK_CAPITAL)  & (1 << 0)) != 0) i |= 1 << 23;
+                       if (('A' <= wp && wp <= 'Z') || ('a' <= wp && wp <= 'z')) {
+                               if (j != 0) {
+                                       i |= j;
+                                       i &= ~0x20;
+                               }
+                       }
+                       putKeybuf(i);
+                       //                      bl_putKeyB(1, &i);
+                       return 0;
+               }
+       }
+       return DefWindowProc(hw, msg, wp, lp);
+}
+
+void drv_openWin(int sx, int sy, UCHAR *buf, char *winClosed)
+{
+       w.win.buf = (int *)buf;
+       w.win.xsiz = sx;
+       w.win.ysiz = sy;
+       bld_openWin(sx, sy, winClosed);
+       return;
+}
+
+void drv_sleep(int msec)
+{
+       Sleep(msec);
+       //      MsgWaitForMultipleObjects(1, &threadhandle, FALSE, msec, QS_ALLINPUT);
+       /* 勉強不足でまだ書き方が分かりません! */
+       return;
+}
+
+#else
+
+#error "Illegal OS type. Edit osecpu.h and look at DRV_OSNUM"
+
 #endif
\ No newline at end of file