From c7fbdf64e053179a13205f7c607ae113a83648eb Mon Sep 17 00:00:00 2001 From: ttwilb Date: Tue, 18 Mar 2014 00:09:03 +0900 Subject: [PATCH] =?utf8?q?yao=E3=81=95=E3=82=93=E3=81=AE=E6=8F=90=E6=A1=88?= =?utf8?q?=E3=82=92=E5=8F=82=E8=80=83=E3=81=AB=E3=80=81core.autocrlf=3Dfal?= =?utf8?q?se=E3=81=A8=E3=81=97=E3=81=A6=E3=82=B3=E3=83=9F=E3=83=83?= =?utf8?q?=E3=83=88=E3=81=97=E3=81=A6=E3=81=BF=E3=82=8B=E3=80=82=20?= =?utf8?q?=E3=81=93=E3=82=8C=E3=81=A7=E8=A1=8C=E6=9C=AB=E3=81=AFCrLf?= =?utf8?q?=E3=81=A7(LF=E3=81=AB=E5=A4=89=E6=8F=9B=E3=81=95=E3=82=8C?= =?utf8?q?=E3=81=9A=E3=81=AB)=E3=82=B3=E3=83=9F=E3=83=83=E3=83=88=E3=81=95?= =?utf8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=82=8B=E3=81=AF=E3=81=9A=E3=80=82?= =?utf8?q?=20VS=E3=81=A7=E3=82=B3=E3=83=B3=E3=83=91=E3=82=A4=E3=83=AB?= =?utf8?q?=E3=81=8C=E9=80=9A=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- dpndenv.c | 876 ++++++++++++++++++++++++++++++------------------------------- jitc.c | 164 ++++++------ jitc.h | 2 +- jitcx86.c | 2 +- jitcx86a.c | 2 +- main.c | 2 +- osecpu.h | 484 +++++++++++++++++----------------- tek.c | 2 +- tek.h | 2 +- usetek.c | 176 ++++++------- 10 files changed, 856 insertions(+), 856 deletions(-) diff --git a/dpndenv.c b/dpndenv.c index fd6d4e7..855795d 100644 --- a/dpndenv.c +++ b/dpndenv.c @@ -1,439 +1,439 @@ -#include "osecpu.h" - - -#if (DRV_OSNUM == 0x0002) -// -// for Mac OSX 32-bit -// -#include -#include - -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); -} - -- (void)keyDown:(NSEvent *)theEvent -{ - -} - -- (void)keyUp:(NSEvent *)theEvent -{ - -} - -@end - -@interface Main : NSObject -{ - 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]; - int retv; - retv = HeavyOSECPUMain(argc, (char **)argv); - [NSApp terminate:self]; - [pool release]; - exit(retv); -} - -- (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 setNeedsDisplayInRect: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 - -#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" - +#include "osecpu.h" + + +#if (DRV_OSNUM == 0x0002) +// +// for Mac OSX 32-bit +// +#include +#include + +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); +} + +- (void)keyDown:(NSEvent *)theEvent +{ + +} + +- (void)keyUp:(NSEvent *)theEvent +{ + +} + +@end + +@interface Main : NSObject +{ + 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]; + int retv; + retv = HeavyOSECPUMain(argc, (char **)argv); + [NSApp terminate:self]; + [pool release]; + exit(retv); +} + +- (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 setNeedsDisplayInRect: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 + +#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 diff --git a/jitc.c b/jitc.c index cd66376..abefdcb 100644 --- a/jitc.c +++ b/jitc.c @@ -1,82 +1,82 @@ -#include "osecpu.h" -#include "jitc.h" - -// -// JITC common functions (architecture not dependent) -// - -void errorHandler(HOSECPU_RuntimeEnvironment *r) -{ - puts("security error! abort..."); - printf("debugInfo0=%d, debugInfo1=%d\n", r->debugInfo0, r->debugInfo1); -#if (USE_DEBUGGER != 0) - dbgrMain(r); -#endif - exit(1); -} - -int jitCompCmdLen(const unsigned char *src) -{ - //BCode命令長を取得する - int i = 1; - - if (0x01 <= *src && *src < 0x04){ - // LB, LIMM, PLIMM - i = 6; - } else if (*src == 0x04){ - // CND - i = 2; - } else if (0x08 <= *src && *src < 0x0d){ - // LMEM, SMEM, ??, ??, ?? - i = 8 + src[7] * 4; - } else if (0x0e <= *src && *src < 0x10){ - // PADD, PDIF - i = 8; - } else if (0x10 <= *src && *src < 0x1c){ - // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD, - i = 4; - } else if (0x1c <= *src && *src < 0x1f){ - // ??, ??, PCP - i = 3; - } else if (*src == 0x1f){ - // ?? - i = 11; - } else if(0x20 <= *src && *src < 0x2e){ - // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ, - // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG, - i = 4; - } else if (*src == 0x2f){ - // ?? - i = 4 + src[1]; - } else if (0x30 <= *src && *src < 0x34){ - // ??, ??, MALLOC, ?? - i = 4; - } else if (0x3c <= *src && *src < 0x3e){ - // ??, ?? - i = 7; - } else if (*src == 0xfe){ - // REMARK - i = 2 + src[1]; - } - - return i; -} - -void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src) -{ - // なんか直接代入するとMacではアライメントエラーで落ちるのです... - // *dst = *src; - - dst->p = src->p; - dst->typ = src->typ; - dst->p0 = src->p0; - dst->p1 = src->p1; - dst->liveSign = src->liveSign; - dst->pls = src->pls; - dst->flags = src->flags; - dst->dummy = src->dummy; -} - - - - +#include "osecpu.h" +#include "jitc.h" + +// +// JITC common functions (architecture not dependent) +// + +void errorHandler(HOSECPU_RuntimeEnvironment *r) +{ + puts("security error! abort..."); + printf("debugInfo0=%d, debugInfo1=%d\n", r->debugInfo0, r->debugInfo1); +#if (USE_DEBUGGER != 0) + dbgrMain(r); +#endif + exit(1); +} + +int jitCompCmdLen(const unsigned char *src) +{ + //BCode命令長を取得する + int i = 1; + + if (0x01 <= *src && *src < 0x04){ + // LB, LIMM, PLIMM + i = 6; + } else if (*src == 0x04){ + // CND + i = 2; + } else if (0x08 <= *src && *src < 0x0d){ + // LMEM, SMEM, ??, ??, ?? + i = 8 + src[7] * 4; + } else if (0x0e <= *src && *src < 0x10){ + // PADD, PDIF + i = 8; + } else if (0x10 <= *src && *src < 0x1c){ + // CP/OR, XOR, AND, ADD, SUB, MUL, SHL, SAR, DIV, MOD, + i = 4; + } else if (0x1c <= *src && *src < 0x1f){ + // ??, ??, PCP + i = 3; + } else if (*src == 0x1f){ + // ?? + i = 11; + } else if(0x20 <= *src && *src < 0x2e){ + // CMPE, CMPNE, CMPL, CMPGE, CMPLE, CMPG, TSTZ, TSTNZ, + // PCMPE, PCMPNE, PCMPL, PCMPGE, PCMPLE, PCMPG, + i = 4; + } else if (*src == 0x2f){ + // ?? + i = 4 + src[1]; + } else if (0x30 <= *src && *src < 0x34){ + // ??, ??, MALLOC, ?? + i = 4; + } else if (0x3c <= *src && *src < 0x3e){ + // ??, ?? + i = 7; + } else if (*src == 0xfe){ + // REMARK + i = 2 + src[1]; + } + + return i; +} + +void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src) +{ + // なんか直接代入するとMacではアライメントエラーで落ちるのです... + // *dst = *src; + + dst->p = src->p; + dst->typ = src->typ; + dst->p0 = src->p0; + dst->p1 = src->p1; + dst->liveSign = src->liveSign; + dst->pls = src->pls; + dst->flags = src->flags; + dst->dummy = src->dummy; +} + + + + diff --git a/jitc.h b/jitc.h index 85c88c3..82ef48d 100644 --- a/jitc.h +++ b/jitc.h @@ -1,4 +1,4 @@ - + #ifndef HeavyOSECPU_jitc_h #define HeavyOSECPU_jitc_h diff --git a/jitcx86.c b/jitcx86.c index 57d568a..d4f8e4a 100644 --- a/jitcx86.c +++ b/jitcx86.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" #include "jitc.h" #if (JITC_ARCNUM == 0x0001) diff --git a/jitcx86a.c b/jitcx86a.c index 6804ec8..f77f3b0 100644 --- a/jitcx86a.c +++ b/jitcx86a.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" #include "jitc.h" #if (JITC_ARCNUM == 0x0001) diff --git a/main.c b/main.c index cf2418e..9cc56e6 100644 --- a/main.c +++ b/main.c @@ -1,4 +1,4 @@ -#include "osecpu.h" +#include "osecpu.h" int *keybuf, keybuf_r, keybuf_w, keybuf_c; HOSECPU_Device_Window mainWindow; diff --git a/osecpu.h b/osecpu.h index aebe28c..abcfd5f 100644 --- a/osecpu.h +++ b/osecpu.h @@ -1,242 +1,242 @@ -#ifndef _HDLOAD_OSECPU -#define _HDLOAD_OSECPU 1 - -/* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/ -#define _CRT_SECURE_NO_WARNINGS 1 - -// -// Including stdc headers -// - -#include -#include -#include -#include -#include -#include - - -// -// Compile options -// - -// Target architecture -// 1 : i386 -#define JITC_ARCNUM 0x0001 - -// Target operating system -// 1 : Windows 32bit -// 2 : Mac OSX 32bit -// 3 : blike for Linux -#ifdef _WIN32 -#define DRV_OSNUM 0x0001 -#endif -#ifdef __APPLE__ -#define DRV_OSNUM 0x0002 -#endif -#ifdef __linux__ -#define DRV_OSNUM 0x0003 -#endif -//#define DRV_OSNUM 0x0002 - -// Decoder (syslib.ose) setting -// syslib.ose is necessary to work OSECPU -#define SYSLIB_OSE "syslib.ose" - -// -// Define constant values -// - -// SIGN1: The 2nd signature of OSECPU Format(05 e1) -// It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers) -#define SIGN1 0xe1 - -#define USE_DEBUGGER 1 -#define USE_TEK5 1 - -/* JITC mode flags */ -#define JITC_LV_SLOWEST 0 /* デバッグ支援は何でもやる */ -#define JITC_LV_SLOWER 1 /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */ -#define JITC_LV_SAFE 2 /* とにかく止まる、場所は不明、テストは必要最小限 */ -#define JITC_LV_FASTER 4 /* 情報は生成するがチェックをしない */ -#define JITC_LV_FASTEST 5 /* 情報すら生成しない */ -#define JITC_PHASE1 0x0001 -#define JITC_SKIPCHECK 0x0002 /* セキュリティチェックを省略する(高速危険モード) */ -#define JITC_NOSTARTUP 0x0004 -#define JITC_MAXLABELS 4096 -#define PTRCTRLSIZ 4096 - -#define APPSIZ1 1 * 1024 * 1024 /* 1MB for now */ -#define APPJITSIZE 1 * 1024 * 1024 /* 1MB for now */ -#define SYSJITSIZ1 2 * 1024 * 1024 /* 1MB for now */ -#define SYSLIBSIZ1 1 * 1024 * 1024 /* 1MB for now */ -#define SYSTMP0SIZ 1 * 1024 * 1024 /* 1MB for now */ -#define SYSTMP1SIZ 2 * 1024 * 1024 /* 1MB for now */ - -#define KEYBUFSIZ 4096 - -#define KEY_ENTER '\n' -#define KEY_ESC 27 -#define KEY_BACKSPACE 8 -#define KEY_TAB 9 -#define KEY_PAGEUP 0x1020 -#define KEY_PAGEDWN 0x1021 -#define KEY_END 0x1022 -#define KEY_HOME 0x1023 -#define KEY_LEFT 0x1024 -#define KEY_UP 0x1025 -#define KEY_RIGHT 0x1026 -#define KEY_DOWN 0x1027 -#define KEY_INS 0x1028 -#define KEY_DEL 0x1029 - -// -// HOSECPU structures -// -typedef struct PtrCtrl HOSECPU_PointerControlTag; -struct PtrCtrl { - int liveSign; - int size, typ; - unsigned char *p0; -}; - -typedef struct Ptr HOSECPU_PointerRegisterEntry; -struct Ptr { - // 32バイト(=256bit!) - unsigned char *p; - - /* static char *typName[] = { - "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8", - "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32", - "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2", - "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12", - "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24", - "T_SINT28", "T_UINT28" - } ; */ - int typ; - unsigned char *p0, *p1; - int liveSign; - HOSECPU_PointerControlTag *pls; - int flags, dummy; /* read/writeなど */ -}; - -typedef struct LabelTable HOSECPU_LabelListTag; -struct LabelTable { - unsigned char *p, *p1; - int opt; - /* - * default = -1 - * TYP_CODE = 0 - * T_UINT8 = 3 - * - * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053 - */ - int typ; -}; - -typedef struct Device_Window HOSECPU_Device_Window; -struct Device_Window { - int *vram; - int xsize, ysize; -}; - -typedef struct Regs HOSECPU_RuntimeEnvironment; -struct Regs { - int ireg[64]; // 整数レジスタ (4 * 64) = 256 - HOSECPU_PointerRegisterEntry preg[64]; // ポインタレジスタ (32 * 64) = 2048 - // - int debugInfo0; // 2304 - int debugInfo1; // 2308 - int dbg_currentCode; // 2312 - int dmy; // 2316 - // - HOSECPU_PointerControlTag *ptrCtrl; // 2320 - char winClosed, autoSleep; - jmp_buf setjmpEnv; - int appReturnCode; // アプリ自体の終了コード - - /* Main environment */ - int mainArgc; // HOSECPU起動引数の個数 - const char **mainArgv; // HOSECPU起動引数リスト - unsigned char *appBin; // 実行するアプリのバイナリ - int appSize0; - int appSize1; - int executionLevel; - - /* for-junkApi */ - unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1; - - HOSECPU_LabelListTag *label; - int maxLabels; - unsigned char *jitbuf, *jitbuf1; - void(*errHndl)(HOSECPU_RuntimeEnvironment *); - char dbgr; - int mapDi1s[16][16]; -}; - -// -// Grobal values -// - -extern int *keybuf, keybuf_r, keybuf_w, keybuf_c; -extern HOSECPU_Device_Window mainWindow; -// di1_serial: デバッグ用。プログラム中の随所で加算される変数 -extern int di1_serial; - -// -// Functions -// - -// @main.c -void putKeybuf(int i); -int HeavyOSECPUMain(int argc, char **argv); - -// @comlib.c -unsigned char *ComLib_main(const unsigned char *p, unsigned char *q); -// @dpndenv.c -// OSに依存する関数群を定義する。 -void *mallocRWE(int bytes); // 実行権付きメモリのmalloc. -void drv_openWin(int x, int y, unsigned char *buf, char *winClosed); -void drv_flshWin(int sx, int sy, int x0, int y0); -void drv_sleep(int msec); - -// @function.c -void dbgrMain(HOSECPU_RuntimeEnvironment *r); -const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理. -void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数 - -// @jitc.c -void errorHandler(HOSECPU_RuntimeEnvironment *r); -void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src); -// @jitcx86.c -int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label); -int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, HOSECPU_LabelListTag *label, int maxLabels, int level, int debugInfo1, int flags); -unsigned char *jitCompCallFunc(unsigned char *dst, void *func); -unsigned char *jitCompInit(unsigned char *dst); -void jitcRunBinary(void (*bin)(char *), HOSECPU_RuntimeEnvironment *env); - -// @randmt.c -void randStatInit(unsigned int seed); -void randStatNext(); -unsigned int randGetNextUInt32(void); - -// @screen.c -static int iColor1[] = { - 0x000000, 0xff0000, 0x00ff00, 0xffff00, - 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff -}; -void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r); -void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx); -void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx); -int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx); - -// @usetek.c -#if (USE_TEK5 != 0) -#include "tek.h" -int appackSub2(const UCHAR **pp, char *pif); -int appackSub3u(const UCHAR **pp, char *pif); -int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp); -#endif - - -#endif +#ifndef _HDLOAD_OSECPU +#define _HDLOAD_OSECPU 1 + +/* Visual Studio で fopen()やsprintf() などの古い関数を使用する時に出る警告を抑止する*/ +#define _CRT_SECURE_NO_WARNINGS 1 + +// +// Including stdc headers +// + +#include +#include +#include +#include +#include +#include + + +// +// Compile options +// + +// Target architecture +// 1 : i386 +#define JITC_ARCNUM 0x0001 + +// Target operating system +// 1 : Windows 32bit +// 2 : Mac OSX 32bit +// 3 : blike for Linux +#ifdef _WIN32 +#define DRV_OSNUM 0x0001 +#endif +#ifdef __APPLE__ +#define DRV_OSNUM 0x0002 +#endif +#ifdef __linux__ +#define DRV_OSNUM 0x0003 +#endif +//#define DRV_OSNUM 0x0002 + +// Decoder (syslib.ose) setting +// syslib.ose is necessary to work OSECPU +#define SYSLIB_OSE "syslib.ose" + +// +// Define constant values +// + +// SIGN1: The 2nd signature of OSECPU Format(05 e1) +// It will be changed in OSECPU Rev.2 to "e2" (no adaptation in their binary layers) +#define SIGN1 0xe1 + +#define USE_DEBUGGER 1 +#define USE_TEK5 1 + +/* JITC mode flags */ +#define JITC_LV_SLOWEST 0 /* デバッグ支援は何でもやる */ +#define JITC_LV_SLOWER 1 /* エラーモジュールはレポートできるが、行番号は分からない、テストは過剰 */ +#define JITC_LV_SAFE 2 /* とにかく止まる、場所は不明、テストは必要最小限 */ +#define JITC_LV_FASTER 4 /* 情報は生成するがチェックをしない */ +#define JITC_LV_FASTEST 5 /* 情報すら生成しない */ +#define JITC_PHASE1 0x0001 +#define JITC_SKIPCHECK 0x0002 /* セキュリティチェックを省略する(高速危険モード) */ +#define JITC_NOSTARTUP 0x0004 +#define JITC_MAXLABELS 4096 +#define PTRCTRLSIZ 4096 + +#define APPSIZ1 1 * 1024 * 1024 /* 1MB for now */ +#define APPJITSIZE 1 * 1024 * 1024 /* 1MB for now */ +#define SYSJITSIZ1 2 * 1024 * 1024 /* 1MB for now */ +#define SYSLIBSIZ1 1 * 1024 * 1024 /* 1MB for now */ +#define SYSTMP0SIZ 1 * 1024 * 1024 /* 1MB for now */ +#define SYSTMP1SIZ 2 * 1024 * 1024 /* 1MB for now */ + +#define KEYBUFSIZ 4096 + +#define KEY_ENTER '\n' +#define KEY_ESC 27 +#define KEY_BACKSPACE 8 +#define KEY_TAB 9 +#define KEY_PAGEUP 0x1020 +#define KEY_PAGEDWN 0x1021 +#define KEY_END 0x1022 +#define KEY_HOME 0x1023 +#define KEY_LEFT 0x1024 +#define KEY_UP 0x1025 +#define KEY_RIGHT 0x1026 +#define KEY_DOWN 0x1027 +#define KEY_INS 0x1028 +#define KEY_DEL 0x1029 + +// +// HOSECPU structures +// +typedef struct PtrCtrl HOSECPU_PointerControlTag; +struct PtrCtrl { + int liveSign; + int size, typ; + unsigned char *p0; +}; + +typedef struct Ptr HOSECPU_PointerRegisterEntry; +struct Ptr { + // 32バイト(=256bit!) + unsigned char *p; + + /* static char *typName[] = { + "T_CODE", "T_VPTR", "T_SINT8", "T_UINT8", + "T_SINT16", "T_UINT16", "T_SINT32", "T_UINT32", + "T_SINT4", "T_UINT4", "T_SINT2", "T_UINT2", + "T_SINT1", "T_UINT1", "T_SINT12", "T_UINT12", + "T_SINT20", "T_UINT20", "T_SINT24", "T_UINT24", + "T_SINT28", "T_UINT28" + } ; */ + int typ; + unsigned char *p0, *p1; + int liveSign; + HOSECPU_PointerControlTag *pls; + int flags, dummy; /* read/writeなど */ +}; + +typedef struct LabelTable HOSECPU_LabelListTag; +struct LabelTable { + unsigned char *p, *p1; + int opt; + /* + * default = -1 + * TYP_CODE = 0 + * T_UINT8 = 3 + * + * 将来的には UInt8, SInt32, Flt64, UInt8, VPtr が使えるようになる http://osecpu.osask.jp/wiki/?page0053 + */ + int typ; +}; + +typedef struct Device_Window HOSECPU_Device_Window; +struct Device_Window { + int *vram; + int xsize, ysize; +}; + +typedef struct Regs HOSECPU_RuntimeEnvironment; +struct Regs { + int ireg[64]; // 整数レジスタ (4 * 64) = 256 + HOSECPU_PointerRegisterEntry preg[64]; // ポインタレジスタ (32 * 64) = 2048 + // + int debugInfo0; // 2304 + int debugInfo1; // 2308 + int dbg_currentCode; // 2312 + int dmy; // 2316 + // + HOSECPU_PointerControlTag *ptrCtrl; // 2320 + char winClosed, autoSleep; + jmp_buf setjmpEnv; + int appReturnCode; // アプリ自体の終了コード + + /* Main environment */ + int mainArgc; // HOSECPU起動引数の個数 + const char **mainArgv; // HOSECPU起動引数リスト + unsigned char *appBin; // 実行するアプリのバイナリ + int appSize0; + int appSize1; + int executionLevel; + + /* for-junkApi */ + unsigned char *buf0, *buf1, *junkStack, lastConsoleChar, *junkStack1; + + HOSECPU_LabelListTag *label; + int maxLabels; + unsigned char *jitbuf, *jitbuf1; + void(*errHndl)(HOSECPU_RuntimeEnvironment *); + char dbgr; + int mapDi1s[16][16]; +}; + +// +// Grobal values +// + +extern int *keybuf, keybuf_r, keybuf_w, keybuf_c; +extern HOSECPU_Device_Window mainWindow; +// di1_serial: デバッグ用。プログラム中の随所で加算される変数 +extern int di1_serial; + +// +// Functions +// + +// @main.c +void putKeybuf(int i); +int HeavyOSECPUMain(int argc, char **argv); + +// @comlib.c +unsigned char *ComLib_main(const unsigned char *p, unsigned char *q); +// @dpndenv.c +// OSに依存する関数群を定義する。 +void *mallocRWE(int bytes); // 実行権付きメモリのmalloc. +void drv_openWin(int x, int y, unsigned char *buf, char *winClosed); +void drv_flshWin(int sx, int sy, int x0, int y0); +void drv_sleep(int msec); + +// @function.c +void dbgrMain(HOSECPU_RuntimeEnvironment *r); +const char *searchArg(int argc, const char **argv, const char *tag, int i); // コマンドライン引数処理. +void devFunc(HOSECPU_RuntimeEnvironment *r); // junkApiを処理する関数 + +// @jitc.c +void errorHandler(HOSECPU_RuntimeEnvironment *r); +void PRegCopy(HOSECPU_PointerRegisterEntry *dst, HOSECPU_PointerRegisterEntry *src); +// @jitcx86.c +int jitc0(unsigned char **qq, unsigned char *q1, const unsigned char *p0, const unsigned char *p1, int level, HOSECPU_LabelListTag *label); +int jitCompiler(unsigned char *dst, unsigned char *dst1, const unsigned char *src, const unsigned char *src1, const unsigned char *src0, HOSECPU_LabelListTag *label, int maxLabels, int level, int debugInfo1, int flags); +unsigned char *jitCompCallFunc(unsigned char *dst, void *func); +unsigned char *jitCompInit(unsigned char *dst); +void jitcRunBinary(void (*bin)(char *), HOSECPU_RuntimeEnvironment *env); + +// @randmt.c +void randStatInit(unsigned int seed); +void randStatNext(); +unsigned int randGetNextUInt32(void); + +// @screen.c +static int iColor1[] = { + 0x000000, 0xff0000, 0x00ff00, 0xffff00, + 0x0000ff, 0xff00ff, 0x00ffff, 0xffffff +}; +void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r); +void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx); +void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx); +int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx); + +// @usetek.c +#if (USE_TEK5 != 0) +#include "tek.h" +int appackSub2(const UCHAR **pp, char *pif); +int appackSub3u(const UCHAR **pp, char *pif); +int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp); +#endif + + +#endif diff --git a/tek.c b/tek.c index c465e8b..3fecdc2 100644 --- a/tek.c +++ b/tek.c @@ -1,4 +1,4 @@ -#include +#include #include #include diff --git a/tek.h b/tek.h index 16ef0b5..346b03a 100644 --- a/tek.h +++ b/tek.h @@ -1,4 +1,4 @@ -// +// // tek.h // HeavyOSECPU // diff --git a/usetek.c b/usetek.c index 7e4a517..e3ef62d 100644 --- a/usetek.c +++ b/usetek.c @@ -1,88 +1,88 @@ - -#include "osecpu.h" -#if (USE_TEK5 != 0) -/*----For using tek Begin----*/ -#include "tek.h" - -int appackSub2(const UCHAR **pp, char *pif) -{ - int r = 0; - const UCHAR *p = *pp; - if (*pif == 0) { - r = *p >> 4; - } else { - r = *p & 0x0f; - p++; - *pp = p; - } - *pif ^= 1; - - return r; -} - -int appackSub3u(const UCHAR **pp, char *pif) -{ - int r = 0, i; - - r = appackSub2(pp, pif); - if (0x8 <= r && r <= 0xb) { - r = r << 4 | appackSub2(pp, pif); - r &= 0x3f; - } else if (0xc <= r && r <= 0xd) { - r = r << 4 | appackSub2(pp, pif); - r = r << 4 | appackSub2(pp, pif); - r &= 0x1ff; - } else if (r == 0xe) { - r = appackSub2(pp, pif); - r = r << 4 | appackSub2(pp, pif); - r = r << 4 | appackSub2(pp, pif); - } else if (r == 0x7) { - i = appackSub3u(pp, pif); - r = 0; - while (i > 0) { - r = r << 4 | appackSub2(pp, pif); - i--; - } - } - - return r; -} - -int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp) -{ - static char tek5head[16] = { - 0x89, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, - 0x4f, 0x53, 0x41, 0x53, 0x4b, 0x43, 0x4d, 0x50 - }; - memcpy(tmp, tek5head, 16); - UCHAR *q = tmp + 16; - char iif = 0; - int i, tmpsiz; - const UCHAR *p = &buf[1]; - i = appackSub3u(&p, &iif); - tmpsiz = appackSub3u(&p, &iif); - tmpsiz = tmpsiz << 8 | *p++; - *q++ = (tmpsiz >> 27) & 0xfe; - *q++ = (tmpsiz >> 20) & 0xfe; - *q++ = (tmpsiz >> 13) & 0xfe; - *q++ = (tmpsiz >> 6) & 0xfe; - *q++ = (tmpsiz << 1 | 1) & 0xff; - if (i == 1) *q++ = 0x15; - if (i == 2) *q++ = 0x19; - if (i == 3) *q++ = 0x21; - if (i >= 4) return -9; - while (p < buf1){ - *q++ = *p++; - } - if(tek_decomp(tmp, buf, tmpsiz) != 0){; - // failed - fputs("tek decomp error.\n", stderr); - exit(1); - } - //success - return tmpsiz; -} - -/*----For using tek End----*/ -#endif - + +#include "osecpu.h" +#if (USE_TEK5 != 0) +/*----For using tek Begin----*/ +#include "tek.h" + +int appackSub2(const UCHAR **pp, char *pif) +{ + int r = 0; + const UCHAR *p = *pp; + if (*pif == 0) { + r = *p >> 4; + } else { + r = *p & 0x0f; + p++; + *pp = p; + } + *pif ^= 1; + + return r; +} + +int appackSub3u(const UCHAR **pp, char *pif) +{ + int r = 0, i; + + r = appackSub2(pp, pif); + if (0x8 <= r && r <= 0xb) { + r = r << 4 | appackSub2(pp, pif); + r &= 0x3f; + } else if (0xc <= r && r <= 0xd) { + r = r << 4 | appackSub2(pp, pif); + r = r << 4 | appackSub2(pp, pif); + r &= 0x1ff; + } else if (r == 0xe) { + r = appackSub2(pp, pif); + r = r << 4 | appackSub2(pp, pif); + r = r << 4 | appackSub2(pp, pif); + } else if (r == 0x7) { + i = appackSub3u(pp, pif); + r = 0; + while (i > 0) { + r = r << 4 | appackSub2(pp, pif); + i--; + } + } + + return r; +} + +int tek5Decomp(UCHAR *buf, UCHAR *buf1, UCHAR *tmp) +{ + static char tek5head[16] = { + 0x89, 0xff, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00, + 0x4f, 0x53, 0x41, 0x53, 0x4b, 0x43, 0x4d, 0x50 + }; + memcpy(tmp, tek5head, 16); + UCHAR *q = tmp + 16; + char iif = 0; + int i, tmpsiz; + const UCHAR *p = &buf[1]; + i = appackSub3u(&p, &iif); + tmpsiz = appackSub3u(&p, &iif); + tmpsiz = tmpsiz << 8 | *p++; + *q++ = (tmpsiz >> 27) & 0xfe; + *q++ = (tmpsiz >> 20) & 0xfe; + *q++ = (tmpsiz >> 13) & 0xfe; + *q++ = (tmpsiz >> 6) & 0xfe; + *q++ = (tmpsiz << 1 | 1) & 0xff; + if (i == 1) *q++ = 0x15; + if (i == 2) *q++ = 0x19; + if (i == 3) *q++ = 0x21; + if (i >= 4) return -9; + while (p < buf1){ + *q++ = *p++; + } + if(tek_decomp(tmp, buf, tmpsiz) != 0){; + // failed + fputs("tek decomp error.\n", stderr); + exit(1); + } + //success + return tmpsiz; +} + +/*----For using tek End----*/ +#endif + -- 2.11.0