OSDN Git Service

MacOSX対応を本家からマージ。
authorhikarupsp <hikarupsp@users.sourceforge.jp>
Mon, 10 Mar 2014 13:37:11 +0000 (22:37 +0900)
committerhikarupsp <hikarupsp@users.sourceforge.jp>
Mon, 10 Mar 2014 13:37:11 +0000 (22:37 +0900)
バックエンドコードは正しく動作する模様
フロントエンドコードの実行は行えない

dpndenv.c
main.c
osecpu.h

index 4b958c1..2d317b9 100644 (file)
--- a/dpndenv.c
+++ b/dpndenv.c
@@ -6,6 +6,157 @@
 // for Mac OSX 32-bit
 //
 
+// by Liva, 2013.05.29-
+
+#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);
+}
+
+@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)
 
@@ -72,6 +223,12 @@ 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);
diff --git a/main.c b/main.c
index 342f8cc..cd631c4 100644 (file)
--- a/main.c
+++ b/main.c
@@ -13,7 +13,7 @@ void putKeybuf(int i)
        return;
 }
 
-int osecpuMain(int argc, char **argv)
+int HeavyOSECPUMain(int argc, char **argv)
 {
     FILE *fp;
     
@@ -330,14 +330,3 @@ void LoadAppBin(HOSECPU_RuntimeEnvironment *env)
                exit(EXIT_FAILURE);
        }
 }
-
-void ConvertFCode2BCode(HOSECPU_RuntimeEnvironment *env)
-{
-
-}
-
-int main(int argc, char **argv)
-{
-       // Program entry point
-       return osecpuMain(argc, argv);
-}
\ No newline at end of file
index 1ce7101..2c92d25 100644 (file)
--- a/osecpu.h
+++ b/osecpu.h
@@ -27,7 +27,7 @@
 // 1 : Windows 32bit
 // 2 : Mac OSX 32bit
 // 3 : blike for Linux
-#define DRV_OSNUM 0x0001
+#define DRV_OSNUM 0x0002
 
 // Decoder (syslib.ose) setting
 // syslib.ose is necessary to work OSECPU
@@ -145,6 +145,7 @@ static int di1_serial = 0;
 
 // @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);