-#include "osecpu.h"
+#include "osecpu.h"
#if (DRV_OSNUM == 0x0002)
//
// for Mac OSX 32-bit
//
-
-// by Liva, 2013.05.29-
-
#include <mach/mach.h>
#include <Cocoa/Cocoa.h>
@interface OSECPUView : NSView
{
- unsigned char *_buf;
- int _sx;
- int _sy;
+ unsigned char *_buf;
+ int _sx;
+ int _sy;
CGContextRef _context;
}
@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;
+ 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);
+ 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<NSWindowDelegate>
{
- int argc;
- const unsigned char **argv;
- char *winClosed;
- OSECPUView *_view;
+ int argc;
+ const unsigned char **argv;
+ char *winClosed;
+ OSECPUView *_view;
}
- (void)runApp;
@implementation Main
- (void)runApp
{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- HeavyOSECPUMain(argc, (char **)argv);
- [NSApp terminate:self];
+ 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];
+ 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;
+ *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 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];
+ [_view setNeedsDisplayInRect:rect];
}
@end
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];
+ 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;
+ return 0;
}
void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)
{
- [objc_main openWin:buf sx:sx sy:sy winClosed: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)];
+ [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
}
void drv_sleep(int msec)
{
- [NSThread sleepForTimeInterval:0.001*msec];
- return;
+ [NSThread sleepForTimeInterval:0.001*msec];
+ return;
}
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.cbWndExtra = 0;
wc.hInstance = dw.hi;
wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
- IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
+ 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);
+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
wc.lpszMenuName = NULL;
- wc.lpszClassName = L"WinClass";
+ wc.lpszClassName = "WinClass";
if (RegisterClassEx(&wc) == 0)
return 1;
r.left = 0;
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);
+ CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
if (dw.hw == NULL)
return 1;
ShowWindow(dw.hw, SW_SHOW);
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) /* エラーもしくは終了メッセージ */
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.biBitCount = 32;
dw.bmi.bmiHeader.biCompression = BI_RGB;
dw.winClosed = winClosed;
-
+
threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
-
+
return;
}
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);
+ 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
EndPaint(dw.hw, &ps);
}
if (msg == WM_DESTROY) {
}
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;
#else
-#error "Illegal OS type. Edit switch.h and look at DRV_OSNUM"
+#error "Illegal OS type. Edit osecpu.h and look at DRV_OSNUM"
#endif
\ No newline at end of file