Example #1
0
void fs_emu_initialize_textures() {
    if (g_fs_emu_theme.width == 0) {
        fs_emu_fatal("theme is not initialized yet");
    }

    //g_atlas = fs_emu_texture_new_from_file("atlas");
    fs_image *image = fs_image_new();
    image->width = 1024;
    image->height = 1024;
    image->format = FS_IMAGE_FORMAT_RGBA;
    image->data = fs_malloc0(1024 * 1024 * 4);
    initialize_atlas(image);

    g_atlas = fs_new(fs_emu_texture, 1);
    g_atlas->width = image->width;
    g_atlas->height = image->height;
    g_atlas->image = image;
    load_texture(g_atlas);
    fs_emu_set_texture(g_atlas);
    fs_gl_add_context_notification(context_notification_handler, g_atlas);

    if (g_fs_emu_theme.overlay_image[0]) {
        char *path = fs_emu_theme_get_resource(g_fs_emu_theme.overlay_image);
        fs_log("g_fs_emu_theme.overlay_image %s => %s\n",
                g_fs_emu_theme.overlay_image, path);
        if (path) {
            g_fs_emu_overlay_texture = fs_emu_texture_new_from_file(path);
        }
    }

    for (int i = 0; i < FS_EMU_MAX_OVERLAYS; i++) {
        for (int j = 0; j < FS_EMU_MAX_OVERLAY_STATES; j++) {
            fs_emu_texture *tex = NULL;
            char *name = fs_strdup_printf("custom_%d_%d.png",
                    i - FS_EMU_FIRST_CUSTOM_OVERLAY, j);
            char *path = fs_emu_theme_get_resource(name);
            if (!path && g_fs_emu_theme.overlays[i].name) {
                free(name);
                name = fs_strdup_printf("%s_%d.png",
                        g_fs_emu_theme.overlays[i].name, j);
                path = fs_emu_theme_get_resource(name);
            }
            if (path) {
                tex = fs_emu_texture_new_from_file(path);
                g_fs_emu_theme.overlays[i].textures[j] = tex;
                free(path);
            }
            else if (j == 1) {
                char *base_name = fs_strdup_printf("custom_%d.png",
                        i - FS_EMU_FIRST_CUSTOM_OVERLAY);
                path = fs_emu_theme_get_resource(base_name);
                if (!path && g_fs_emu_theme.overlays[i].name) {
                    free(name);
                    name = fs_strdup_printf("%s.png",
                            g_fs_emu_theme.overlays[i].name);
                    path = fs_emu_theme_get_resource(name);
                }
                if (path) {
                    tex = fs_emu_texture_new_from_file(path);
                    g_fs_emu_theme.overlays[i].textures[j] = tex;
                    free(path);
                }
                free(base_name);
            }
            else if (j >= 2) {
                g_fs_emu_theme.overlays[i].textures[j] = \
                        g_fs_emu_theme.overlays[i].textures[j - 1];
            }
            free(name);

            // size will be determined from the last loaded texture/state
            // for the overlay
            if (tex) {
                g_fs_emu_theme.overlays[i].w =
                        (double) tex->width / g_fs_emu_theme.width;
                g_fs_emu_theme.overlays[i].h =
                        (double) tex->height / g_fs_emu_theme.height;
            }
        }
    }
}
Example #2
0
static void load_theme() {
    fs_log("loading theme \"%s\"\n", g_fs_emu_theme.path);
    char *p = fs_path_join(g_fs_emu_theme.path, "theme.conf", NULL);
    if (fs_path_exists(p)) {
        fs_config_read_file(p, 1);
    }
    free(p);

    char *cv;
    int iv;

    iv = fs_config_get_int("theme_width");
    if (iv != FS_CONFIG_NONE && iv > 0) {
        g_fs_emu_theme.width = iv;
    }
    iv = fs_config_get_int("theme_height");
    if (iv != FS_CONFIG_NONE && iv > 0) {
        g_fs_emu_theme.height = iv;
    }

    set_color_from_string(g_fs_emu_theme.floor_color_1,
            fs_config_get_const_string("theme_floor_color_1"));
    set_color_from_string(g_fs_emu_theme.floor_color_2,
            fs_config_get_const_string("theme_floor_color_2"));
    set_color_from_string(g_fs_emu_theme.wall_color_1,
            fs_config_get_const_string("theme_wall_color_1"));
    set_color_from_string(g_fs_emu_theme.wall_color_2,
            fs_config_get_const_string("theme_wall_color_2"));

    iv = fs_config_get_int("theme_floor_height");
    if (iv != FS_CONFIG_NONE) {
        g_fs_emu_theme.floor_height = iv;
    }
    cv = fs_config_get_string("theme_overlay_image");
    if (cv) {
        free(g_fs_emu_theme.overlay_image);
        g_fs_emu_theme.overlay_image = cv;
    }
    set_color_from_string(g_fs_emu_theme.fade_color,
            fs_config_get_const_string("theme_fade_color"));
    set_color_from_string(g_fs_emu_theme.heading_color,
            fs_config_get_const_string("theme_heading_color"));
    set_color_from_string(g_fs_emu_theme.item_color,
            fs_config_get_const_string("theme_item_color"));

    for (int i = 0; i < FS_EMU_MAX_OVERLAYS; i++) {
        char *name;
        int val;

        // the first options read here are old compatibility options

        name = fs_strdup_printf("theme_custom_%d_x",
                i - FS_EMU_FIRST_CUSTOM_OVERLAY);
        val = fs_config_get_int(name);
        free(name);
        if (val != FS_CONFIG_NONE) {
            //printf("x is %d\n", val);
            g_fs_emu_theme.overlays[i].x = (double) val /
                    g_fs_emu_theme.width;
        }
        name = fs_strdup_printf("theme_custom_%d_y",
                i - FS_EMU_FIRST_CUSTOM_OVERLAY);
        val = fs_config_get_int(name);
        free(name);
        if (val != FS_CONFIG_NONE) {
            g_fs_emu_theme.overlays[i].y = (double) val /
                    g_fs_emu_theme.height;
        }

        if (!g_fs_emu_theme.overlays[i].name) {
            continue;
        }

        // these are new theme / overlay options

        name = fs_strdup_printf("theme_%s_pos",
                g_fs_emu_theme.overlays[i].name);
        const char *csval = fs_config_get_const_string(name);
        free(name);
        if (csval) {
            int x, y;
            if (sscanf(csval, "%d,%d", &x, &y) == 2) {
                g_fs_emu_theme.overlays[i].x = (double) x /
                        g_fs_emu_theme.width;
                g_fs_emu_theme.overlays[i].y = (double) y /
                        g_fs_emu_theme.height;
            }
        }
    }

#ifdef WITH_LUA
    fs_emu_theme_init_lua();
#endif
}
Example #3
0
static void save_screenshot_of_opengl_framebuffer(const char *path) {
#if 0
    static int count = 0;
    count += 1;

    time_t t = time(NULL);
#ifdef WINDOWS
    struct tm *tm_p = localtime(&t);
#else
    struct tm tm_struct;
    struct tm *tm_p = &tm_struct;
    localtime_r(&t, tm_p);
#endif
    char strbuf[20];
    strftime(strbuf, 20, "%Y-%m-%d-%H-%M", tm_p);
    char *name = fs_strdup_printf("%s-%s-%03d.png",
            g_fs_ml_video_screenshots_prefix,
            strbuf, g_fs_ml_video_screenshot);
    char *path = fs_path_join(g_fs_ml_video_screenshots_dir, name, NULL);
#endif
    fs_log("writing screenshot to %s\n", path);

    int w = fs_ml_video_width();
    int h = fs_ml_video_height();
    fs_log("reading opengl frame buffer (%d x %d)\n", w, h);
    void *out_data = malloc(w * h * 4);

    // when using GL_RGB, remeber to temporarily set GL_UNPACK_ALIGNMENT so
    // all rows will be contiguous (the OpenGL default is to align rows on
    // 4-byte boundaries
    //GLint unpack_alignment;
    //glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment);
    //glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, out_data);
    //glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment);

    // flip image vertically
    int stride = w * 4;
    void *tmp = malloc(stride);
    void *line1 = out_data;
    void *line2 = out_data + stride * (h - 1);
    for (int i = 0; i < h / 2; i++) {
        memcpy(tmp, line1, stride);
        memcpy(line1, line2, stride);
        memcpy(line2, tmp, stride);
        line1 += stride;
        line2 -= stride;
    }
    free(tmp);

    int result = fs_image_save_data(path, out_data, w, h, 4);
    if (result) {
        fs_log("saved screenshot\n");
    }
    else {
        fs_log("error saving screenshot\n");
    }
    free(out_data);
#if 0
    free(name);
    free(path);
#endif
}
Example #4
0
void fs_uae_configure_hard_drives() {
	static const char *ro_string = "ro";
	static const char *rw_string = "rw";
    const char *read_write = rw_string;
    fs_emu_log("fs_uae_configure_hard_drives\n");
    for(int i = 0; i < 10; i++) {
        char *fs_uae_option = fs_strdup_printf("hard_drive_%d", i);
        char *path = fs_config_get_string(fs_uae_option);
        free(fs_uae_option);
        if (path == NULL) {
            continue;
        }
        if (path[0] == '\0') {
        	continue;
        }
        path = fs_uae_expand_path_and_free(path);
        path = fs_uae_resolve_path_and_free(path, FS_UAE_HD_PATHS);
        if (!fs_path_exists(path)) {
            char *msg = fs_strdup_printf("HD path \"%s\" does not exist",
                    path);
            fs_emu_warning(msg);
            free(msg);
            continue;
        }
        int boot_priority = -i;
        read_write = rw_string;
        char *device = fs_strdup_printf("DH%d", i);

        int virtual = 0;
        if (fs_path_is_dir(path)) {
            virtual = 1;
        }
        else if (fs_str_has_suffix(path, ".zip")) {
            virtual = 1;
            read_write = ro_string;
        }

        fs_uae_option = fs_strdup_printf("hard_drive_%d_read_only", i);
        if (fs_config_get_boolean(fs_uae_option) == 1) {
        	read_write = ro_string;
        }
        free(fs_uae_option);

        if (virtual) {
            char *type = fs_strdup("dir");
            int surfaces = 1;
            int reserved = 2;
            //char *hd_controller = g_strdup("ide0");
            int sectors = 32;
            int block_size = 512;

            char *mount_name;
            char *label_option_name = fs_strdup_printf(
                    "hard_drive_%d_label", i);
            char *label_option = fs_config_get_string(label_option_name);
            if (label_option) {
                mount_name = label_option;
            }
            else {
                mount_name = fs_path_get_basename(path);
            }

            fs_emu_log("hard drive mount: %s\n", path);
            fs_emu_log("device: %s\n", device);
            fs_emu_log("mount name: %s\n", mount_name);
            fs_emu_log("read/write: %s\n", read_write);
            fs_emu_log("boot priority: %d\n", boot_priority);
            /*
            char *option = fs_strdup_printf("uaehf%d", i);
            char *value = fs_strdup_printf("%s,%s,%s:%s:%s,%d",
                    type, read_write, device, mount_name, path,
                    boot_priority);
            amiga_set_option(option, value);
            */

            char *option2 = fs_strdup("filesystem2");
            char *value2 = fs_strdup_printf("%s,%s:%s:%s,%d",
                    read_write, device, mount_name, path,
                    boot_priority);
            amiga_set_option(option2, value2);
            free(option2);
            free(value2);

            // uaehf0=hdf,rw,DH0:path.hdf,32,1,2,512,0,,uae;

            //free(option);
            //free(value);
            free(device);
            free(type);
            free(mount_name);
            continue;
        }
        else if (fs_path_exists(path)) {