⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cocoa.m

📁 qemu虚拟机代码
💻 M
📖 第 1 页 / 共 3 页
字号:
}/* ------------------------------------------------------    cocoa_display_init ------------------------------------------------------*/void cocoa_display_init(DisplayState *ds, int full_screen){    ds->dpy_update = cocoa_update;    ds->dpy_resize = cocoa_resize;    ds->dpy_refresh = cocoa_refresh;        cocoa_resize(ds, 640, 400);        atexit(cocoa_cleanup);}/* ------------------------------------------------------    Interface with Cocoa ------------------------------------------------------*//* ------------------------------------------------------    QemuWindow    Some trick from SDL to use miniwindow ------------------------------------------------------*/static void QZ_SetPortAlphaOpaque (){        /* Assume 32 bit if( bpp == 32 )*/    if ( 1 ) {            uint32_t    *pixels = (uint32_t*) current_ds.data;        uint32_t    rowPixels = current_ds.linesize / 4;        uint32_t    i, j;                for (i = 0; i < current_ds.height; i++)            for (j = 0; j < current_ds.width; j++) {                        pixels[ (i * rowPixels) + j ] |= 0xFF000000;            }    }}@implementation QemuWindow- (void)miniaturize:(id)sender{            /* make the alpha channel opaque so anim won't have holes in it */    QZ_SetPortAlphaOpaque ();        [ super miniaturize:sender ];    }- (void)display{        /*         This method fires just before the window deminaturizes from the Dock.                We'll save the current visible surface, let the window manager redraw any        UI elements, and restore the SDL surface. This way, no expose event         is required, and the deminiaturize works perfectly.    */        /* make sure pixels are fully opaque */    QZ_SetPortAlphaOpaque ();        /* save current visible SDL surface */    [ self cacheImageInRect:[ qd_view frame ] ];        /* let the window manager redraw controls, border, etc */    [ super display ];        /* restore visible SDL surface */    [ self restoreCachedImage ];}@end/* ------------------------------------------------------    QemuCocoaGUIController    NSApp's delegate - indeed main object ------------------------------------------------------*/@interface QemuCocoaGUIController : NSObject{}- (void)applicationDidFinishLaunching: (NSNotification *) note;- (void)applicationWillTerminate:(NSNotification *)aNotification;- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo;- (void)startEmulationWithArgc:(int)argc argv:(char**)argv;@end@implementation QemuCocoaGUIController/* Called when the internal event loop has just started running */- (void)applicationDidFinishLaunching: (NSNotification *) note{    /* Display an open dialog box if no argument were passed or       if qemu was launched from the finder ( the Finder passes "-psn" ) */    if( gArgc <= 1 || strncmp (gArgv[1], "-psn", 4) == 0)    {        NSOpenPanel *op = [[NSOpenPanel alloc] init];                cocoa_resize(&current_ds, 640, 400);                [op setPrompt:@"Boot image"];                [op setMessage:@"Select the disk image you want to boot.\n\nHit the \"Cancel\" button to quit"];                [op beginSheetForDirectory:nil file:nil types:[NSArray arrayWithObjects:@"img",@"iso",@"dmg",@"qcow",@"cow",@"cloop",@"vmdk",nil]              modalForWindow:window modalDelegate:self              didEndSelector:@selector(openPanelDidEnd:returnCode:contextInfo:) contextInfo:NULL];    }    else    {        /* or Launch Qemu, with the global args */        [self startEmulationWithArgc:gArgc argv:gArgv];    }}- (void)applicationWillTerminate:(NSNotification *)aNotification{    printf("Application will terminate\n");    qemu_system_shutdown_request();    /* In order to avoid a crash */    exit(0);}- (void)openPanelDidEnd:(NSOpenPanel *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo{    if(returnCode == NSCancelButton)    {        exit(0);    }        if(returnCode == NSOKButton)    {        char *bin = "qemu";        char *img = (char*)[ [ sheet filename ] cString];                char **argv = (char**)malloc( sizeof(char*)*3 );                asprintf(&argv[0], "%s", bin);        asprintf(&argv[1], "-hda");        asprintf(&argv[2], "%s", img);                printf("Using argc %d argv %s -hda %s\n", 3, bin, img);                [self startEmulationWithArgc:3 argv:(char**)argv];    }}- (void)startEmulationWithArgc:(int)argc argv:(char**)argv{    int status;    /* Launch Qemu */    printf("starting qemu...\n");    status = qemu_main (argc, argv);    exit(status);}@end/* ------------------------------------------------------    Application Creation ------------------------------------------------------*//* Dock Connection */typedef struct CPSProcessSerNum{        UInt32                lo;        UInt32                hi;} CPSProcessSerNum;extern OSErr    CPSGetCurrentProcess( CPSProcessSerNum *psn);extern OSErr    CPSEnableForegroundOperation( CPSProcessSerNum *psn, UInt32 _arg2, UInt32 _arg3, UInt32 _arg4, UInt32 _arg5);extern OSErr    CPSSetFrontProcess( CPSProcessSerNum *psn);/* Menu Creation */static void setApplicationMenu(void){    /* warning: this code is very odd */    NSMenu *appleMenu;    NSMenuItem *menuItem;    NSString *title;    NSString *appName;        appName = @"Qemu";    appleMenu = [[NSMenu alloc] initWithTitle:@""];        /* Add menu items */    title = [@"About " stringByAppendingString:appName];    [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""];    [appleMenu addItem:[NSMenuItem separatorItem]];    title = [@"Hide " stringByAppendingString:appName];    [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@"h"];    menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@"h"];    [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)];    [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""];    [appleMenu addItem:[NSMenuItem separatorItem]];    title = [@"Quit " stringByAppendingString:appName];    [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@"q"];        /* Put menu into the menubar */    menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""];    [menuItem setSubmenu:appleMenu];    [[NSApp mainMenu] addItem:menuItem];    /* Tell the application object that this is now the application menu */    [NSApp setAppleMenu:appleMenu];    /* Finally give up our references to the objects */    [appleMenu release];    [menuItem release];}/* Create a window menu */static void setupWindowMenu(void){    NSMenu      *windowMenu;    NSMenuItem  *windowMenuItem;    NSMenuItem  *menuItem;    windowMenu = [[NSMenu alloc] initWithTitle:@"Window"];        /* "Minimize" item */    menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"];    [windowMenu addItem:menuItem];    [menuItem release];        /* Put menu into the menubar */    windowMenuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""];    [windowMenuItem setSubmenu:windowMenu];    [[NSApp mainMenu] addItem:windowMenuItem];        /* Tell the application object that this is now the window menu */    [NSApp setWindowsMenu:windowMenu];    /* Finally give up our references to the objects */    [windowMenu release];    [windowMenuItem release]; }static void CustomApplicationMain (argc, argv){    NSAutoreleasePool   *pool = [[NSAutoreleasePool alloc] init];    QemuCocoaGUIController *gui_controller;    CPSProcessSerNum PSN;        [NSApplication sharedApplication];        if (!CPSGetCurrentProcess(&PSN))        if (!CPSEnableForegroundOperation(&PSN,0x03,0x3C,0x2C,0x1103))            if (!CPSSetFrontProcess(&PSN))                [NSApplication sharedApplication];                    /* Set up the menubar */    [NSApp setMainMenu:[[NSMenu alloc] init]];    setApplicationMenu();    setupWindowMenu();    /* Create SDLMain and make it the app delegate */    gui_controller = [[QemuCocoaGUIController alloc] init];    [NSApp setDelegate:gui_controller];        /* Start the main event loop */    [NSApp run];        [gui_controller release];    [pool release];}/* Real main of qemu-cocoa */int main(int argc, char **argv){    gArgc = argc;    gArgv = argv;        CustomApplicationMain (argc, argv);        return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -