Ejemplo n.º 1
0
void gfx_init_x11() {
    int f;
    XSetWindowAttributes attr;
    XSizeHints hints;
    Atom WM_DELETE_WINDOW;
    XGCValues gcValues;

    display = XOpenDisplay(NULL);
    screen = DefaultScreen(display);
    visual = DefaultVisual(display, screen);
    depth = DefaultDepth(display, screen);

    create_colormap_lookup_table();

    /* hints.flags=PResizeInc|PMinSize|PMaxSize; */
    hints.flags = PMinSize;
    hints.max_width = 2 * emu_window_width;
    hints.max_height = 2 * emu_window_height;
    hints.min_width = selected_model->pixel_width;
    hints.min_height = selected_model->pixel_height;
    hints.width_inc = 16;
    hints.height_inc = 16;

    attr.background_pixel = cmap24[C_gray]; /* TODO customize */
    win = XCreateWindow(display, DefaultRootWindow(display), 0, 0,
            emu_window_width + WINDOW_FRAME, emu_window_height + WINDOW_FRAME,
            0,
            CopyFromParent,
            CopyFromParent, CopyFromParent, CWBackPixel, &attr);

    WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", False);
    XSetWMProtocols(display, win, &WM_DELETE_WINDOW, 1);
    XSetWMNormalHints(display, win, &hints);

    XSetStandardProperties(display, win, selected_model->title,
            selected_model->title,
            None,
            NULL, 0, NULL);

    XSelectInput(display, win,
            ExposureMask | ButtonPressMask | ButtonReleaseMask
                    | PropertyChangeMask | KeyPressMask | KeyReleaseMask
                    | Button1MotionMask | StructureNotifyMask);
    gc = XCreateGC(display, win, 0, 0);
    gcBackground = XCreateGC(display, win, 0, 0);

    gcValues.function = GXor;
    gcInvers = XCreateGC(display, win, GCFunction, &gcValues);
    XClearWindow(display, win);

    for (f = 0; f < ZOOM_MAX; f++) {
        krtImage[f] = XCreatePixmap(display, win,
                selected_model->pixel_width * (f + 1),
                selected_model->pixel_height * (f + 1), depth);
    }

    generateFonts();
    initialized = 1; /* so jetzt läuft unser Main-Thread weiter */

    XMapRaised(display, win);
    XFlush(display);

    handle_event();
    gfx_exit();
}
Ejemplo n.º 2
0
Archivo: gfx.c Proyecto: harnold/ducks
int gfx_init(int mode)
{
    struct vbe_info info;
    struct vbe_mode_info mode_info;

    if (gfx_check_vbe_info(&info) != 0)
        return -1;

    if (gfx_check_vbe_mode_info(&info, mode, &mode_info) != 0)
        return -1;

    vga_get_mode(&gfx_saved_vga_mode);
    gfx_mode_info.mode = gfx_saved_vga_mode;

    if (vbe_set_mode(mode, VBE_LINEAR_FRAMEBUFFER | VBE_CLEAR_DISPLAY_MEMORY) != 0) {
        error("Setting VBE mode %Xh failed", mode);
        goto failure;
    }

    gfx_mode_info.mode = mode;
    gfx_mode_info.x_resolution = mode_info.x_resolution;
    gfx_mode_info.y_resolution = mode_info.y_resolution;
    gfx_mode_info.page_size = mode_info.bytes_per_scanline * mode_info.y_resolution;

    if (mode_info.phys_base_ptr <= 0xFFFFF) {
        error("Unsupported hardware configuration: Framebuffer in real-mode memory "
              "(physical base address = %Xh)", mode_info.phys_base_ptr);
        goto failure;
    }

    if (dpmi_map_physical_address(mode_info.phys_base_ptr,
                                  2 * gfx_mode_info.page_size,
                                  &gfx_framebuffer_address) != 0) {
        error("Mapping graphics card framebuffer to memory failed");
        goto failure;
    }

    if (vbe_set_display_start(0, 0, VBE_WAIT_FOR_RETRACE) != 0) {
        error("Setting display start failed");
        goto failure;
    }

    init_image(&gfx_buffer_1,
               gfx_mode_info.x_resolution,
               gfx_mode_info.y_resolution,
               (uint8_t *) gfx_framebuffer_address);

    init_image(&gfx_buffer_2,
               gfx_mode_info.x_resolution,
               gfx_mode_info.y_resolution,
               gfx_buffer_1.data + gfx_mode_info.page_size);

    gfx_front_buffer = &gfx_buffer_1;
    gfx_back_buffer = &gfx_buffer_2;

    gfx_check_refresh_rate();
    gfx_reset_clip_rect();

    return 0;

failure:

    gfx_exit();
    return -1;
}