Ejemplo n.º 1
0
static void _cfg_load_midi_part_locked(struct midi_port *q)
{
        struct cfg_section *c;
        /*struct midi_provider *p;*/
        cfg_file_t cfg;
        const char *sn;
        char *ptr, *ss, *sp;
        char buf[256];
        int j;

        ss = q->name;
        if (!ss) return;
        while (isspace(*ss)) ss++;
        if (!*ss) return;

        sp = q->provider ? q->provider->name : NULL;
        if (sp) {
                while (isspace(*sp)) sp++;
                if (!*sp) sp = NULL;
        }

        ptr = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, ptr);

        /* look for MIDI port sections */
        for (c = cfg.sections; c; c = c->next) {
                j = -1;
                sscanf(c->name, "MIDI Port %d", &j);
                if (j < 1) continue;
                sn = cfg_get_string(&cfg, c->name, "name", buf, 255, NULL);
                if (!sn) continue;
                if (strcasecmp(ss, sn) != 0) continue;
                sn = cfg_get_string(&cfg, c->name, "provider", buf, 255, NULL);
                if (sn && sp && strcasecmp(sp, sn) != 0) continue;
                /* okay found port */
                if ((q->iocap & MIDI_INPUT) && cfg_get_number(&cfg, c->name, "input", 0)) {
                        q->io |= MIDI_INPUT;
                }
                if ((q->iocap & MIDI_OUTPUT) && cfg_get_number(&cfg, c->name, "output", 0)) {
                        q->io |= MIDI_OUTPUT;
                }
                if (q->io && q->enable) q->enable(q);
        }

        cfg_free(&cfg);
        free(ptr);
}
Ejemplo n.º 2
0
static void cfg_load_palette(cfg_file_t *cfg)
{
        uint8_t colors[48];
        int n;
        char palette_text[49] = "";
        const char *ptr;

        palette_load_preset(cfg_get_number(cfg, "General", "palette", 2));

        cfg_get_string(cfg, "General", "palette_cur", palette_text, 48, "");
        for (n = 0; n < 48; n++) {
                if (palette_text[n] == '\0' || (ptr = strchr(palette_trans, palette_text[n])) == NULL)
                        return;
                colors[n] = ptr - palette_trans;
        }
        memcpy(current_palette, colors, sizeof(current_palette));
}
Ejemplo n.º 3
0
void cfg_load(void)
{
        char *tmp;
        const char *ptr;
        int i;
        cfg_file_t cfg;

        tmp = dmoz_path_concat(cfg_dir_dotschism, "config");
        cfg_init(&cfg, tmp);
        free(tmp);

        /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

        cfg_get_string(&cfg, "Video", "driver", cfg_video_driver, 64, "");
        cfg_video_fullscreen = !!cfg_get_number(&cfg, "Video", "fullscreen", 0);
        cfg_video_mousecursor = cfg_get_number(&cfg, "Video", "mouse_cursor", MOUSE_EMULATED);
        cfg_video_mousecursor = CLAMP(cfg_video_mousecursor, 0, MOUSE_MAX_STATE);
        ptr = cfg_get_string(&cfg, "Video", "aspect", NULL, 0, NULL);
        if (ptr && *ptr)
                put_env_var("SCHISM_VIDEO_ASPECT", ptr);

        tmp = get_home_directory();
        cfg_get_string(&cfg, "Directories", "modules", cfg_dir_modules, PATH_MAX, tmp);
        cfg_get_string(&cfg, "Directories", "samples", cfg_dir_samples, PATH_MAX, tmp);
        cfg_get_string(&cfg, "Directories", "instruments", cfg_dir_instruments, PATH_MAX, tmp);
        free(tmp);

        ptr = cfg_get_string(&cfg, "Directories", "module_pattern", NULL, 0, NULL);
        if (ptr) {
                strncpy(cfg_module_pattern, ptr, PATH_MAX);
                cfg_module_pattern[PATH_MAX] = 0;
        }

        ptr = cfg_get_string(&cfg, "Directories", "export_pattern", NULL, 0, NULL);
        if (ptr) {
                strncpy(cfg_export_pattern, ptr, PATH_MAX);
                cfg_export_pattern[PATH_MAX] = 0;
        }

        ptr = cfg_get_string(&cfg, "General", "numlock_setting", NULL, 0, NULL);
        if (!ptr)
                status.fix_numlock_setting = NUMLOCK_GUESS;
        else if (strcasecmp(ptr, "on") == 0)
                status.fix_numlock_setting = NUMLOCK_ALWAYS_ON;
        else if (strcasecmp(ptr, "off") == 0)
                status.fix_numlock_setting = NUMLOCK_ALWAYS_OFF;
        else
                status.fix_numlock_setting = NUMLOCK_HONOR;

        set_key_repeat(cfg_get_number(&cfg, "General", "key_repeat_delay", key_repeat_delay()),
                       cfg_get_number(&cfg, "General", "key_repeat_rate", key_repeat_rate()));

        /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

        cfg_load_info(&cfg);
        cfg_load_patedit(&cfg);
        cfg_load_audio(&cfg);
        cfg_load_midi(&cfg);
        cfg_load_disko(&cfg);
        cfg_load_dmoz(&cfg);

        /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

        if (cfg_get_number(&cfg, "General", "classic_mode", 0))
                status.flags |= CLASSIC_MODE;
        else
                status.flags &= ~CLASSIC_MODE;
        if (cfg_get_number(&cfg, "General", "make_backups", 1))
                status.flags |= MAKE_BACKUPS;
        else
                status.flags &= ~MAKE_BACKUPS;
        if (cfg_get_number(&cfg, "General", "numbered_backups", 0))
                status.flags |= NUMBERED_BACKUPS;
        else
                status.flags &= ~NUMBERED_BACKUPS;

        i = cfg_get_number(&cfg, "General", "time_display", TIME_PLAY_ELAPSED);
        /* default to play/elapsed for invalid values */
        if (i < 0 || i >= TIME_PLAYBACK)
                i = TIME_PLAY_ELAPSED;
        status.time_display = i;

        i = cfg_get_number(&cfg, "General", "vis_style", VIS_OSCILLOSCOPE);
        /* default to oscilloscope for invalid values */
        if (i < 0 || i >= VIS_SENTINEL)
                i = VIS_OSCILLOSCOPE;
        status.vis_style = i;

        kbd_sharp_flat_toggle(cfg_get_number(&cfg, "General", "accidentals_as_flats", 0) == 1);

#ifdef MACOSX
# define DEFAULT_META 1
#else
# define DEFAULT_META 0
#endif
        if (cfg_get_number(&cfg, "General", "meta_is_ctrl", DEFAULT_META))
                status.flags |= META_IS_CTRL;
        else
                status.flags &= ~META_IS_CTRL;
        if (cfg_get_number(&cfg, "General", "altgr_is_alt", 1))
                status.flags |= ALTGR_IS_ALT;
        else
                status.flags &= ~ALTGR_IS_ALT;
        if (cfg_get_number(&cfg, "Video", "lazy_redraw", 0))
                status.flags |= LAZY_REDRAW;
        else
                status.flags &= ~LAZY_REDRAW;

        if (cfg_get_number(&cfg, "General", "midi_like_tracker", 0))
                status.flags |= MIDI_LIKE_TRACKER;
        else
                status.flags &= ~MIDI_LIKE_TRACKER;

        cfg_get_string(&cfg, "General", "font", cfg_font, NAME_MAX, "font.cfg");

        cfg_load_palette(&cfg);

        /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

        cfg_free(&cfg);
}
Ejemplo n.º 4
0
static int
pack_image(const char *indn, const char *outfn)
{
    struct imagewty_header *header;
    group_t *head, *filelist;
    uint32_t i, num_files;
    variable_t *var;
    FILE *cfp, *ofp;
    void *p;

    /* try to open image configuration */
    cfp = dir_fopen(indn, "image.cfg", "r");
    if (cfp == NULL) {
        fprintf(stderr, "Error: unable to open %s/%s!\n", indn, "image.cfg");
        return -ENOENT;
    }

    ofp = fopen(outfn, "wb");
    if (ofp == NULL) {
        fprintf(stderr, "Error: could not create image file %s!\n", outfn);
        fclose(cfp);
        return -ENOENT;
    }

    /* file is there, now try to load it */
    head = cfg_load(cfp);
    fclose(cfp);
    if (head == NULL) {
        fprintf(stderr, "Error: failed to parse %s/%s!\n", indn, "image.cfg");
        return -EINVAL;
    }

    /* Got configuration, time to start packing it all up! */
    var = cfg_find_var("filelist", head);
    if (var == NULL || var->type != VT_STRING) {
        fprintf(stderr, "Error: Unable to find filelist string "
                        "variable in configuration!\n");
        cfg_free(head);
        return -EINVAL;
    }

    filelist = cfg_find_group(var->str, head);
    if (filelist == NULL) {
        fprintf(stderr, "Error: unable to find group %s!\n", var->str);
        cfg_free(head);
        return -EINVAL;
    }

    num_files = cfg_count_vars(filelist);
    if (!num_files) {
        fprintf(stderr, "Error: no files to pack found in configuration!\n");
        cfg_free(head);
        return -EINVAL;
    }

    p = malloc(1024 + num_files * 1024);
    if (p == NULL) {
        fprintf(stderr, "Error: failed to allocate memory for image!\n");
        cfg_free(head);
        return -ENOMEM;
    }

    /* Initialize image file header */
    memset(p, 0, 1024 + num_files * 1024);
    header = p;
    memcpy(header->magic, IMAGEWTY_MAGIC, sizeof(header->magic));
    header->header_version = 0x0100;
    header->header_size = 0x50; /* should be 0x60 for version == 0x0300 */
    header->ram_base = 0x04D00000;
    header->version = cfg_get_number("version", head);
    header->image_size = 0; /* this will be filled in later on */
    header->image_header_size = 1024;
    header->v1.pid = cfg_get_number("pid", head);
    header->v1.vid = cfg_get_number("vid", head);
    header->v1.hardware_id = cfg_get_number("hardwareid", head);
    header->v1.firmware_id = cfg_get_number("firmwareid", head);
    header->v1.val1 = 1;
    header->v1.val1024 = 1024;
    header->v1.num_files = num_files;
    header->v1.num_files = cfg_count_vars(filelist);
    header->v1.val1024_2 = 1024;

    /* Setup file headers */
    {
        uint32_t offset = (num_files +1) * 1024;
        struct imagewty_file_header *fheaders;
        variable_t *var;

        fheaders = (struct imagewty_file_header*) (p + 1024);
        for(var=filelist->vars; var; var=var->next) {
            variable_t *v, *fn = NULL, *mt = NULL, *st = NULL;
            uint32_t size;
            FILE *fp;
            for (v=var->items; v; v=v->next) {
                if (v->type != VT_STRING)
                    continue;
                if (strcmp(v->name, "filename") == 0)
                    fn = v;
                else if (strcmp(v->name, "maintype") == 0)
                    mt = v;
                else if (strcmp(v->name, "subtype") == 0)
                    st = v;
            }

            if (!fn || !mt || !st) {
                fprintf(stderr, "Error: incomplete filelist item!\n");
                return -EINVAL;
            }

            fheaders->filename_len = IMAGEWTY_FHDR_FILENAME_LEN;
            fheaders->total_header_size = 1024;
            strcpy((char*)fheaders->v1.filename, fn->str);
            strcpy((char*)fheaders->maintype, mt->str);
            strcpy((char*)fheaders->subtype, st->str);

            fp = dir_fopen(indn, fn->str, "rb");
            if (fp) {
                fseek(fp, 0, SEEK_END);
                size = ftell(fp);
                fclose(fp);
            } else {
                fprintf(stderr, "Error: unable to read file '%s'!\n", fn->str);
                continue;
            }

            fheaders->v1.offset = offset;
            fheaders->v1.stored_length =
            fheaders->v1.original_length = size;
            if (fheaders->v1.stored_length & 0x1FF) {
                fheaders->v1.stored_length &= ~0x1FF;
                fheaders->v1.stored_length += 0x200;
            }
            offset += fheaders->v1.stored_length;
            fheaders = (struct imagewty_file_header*) ((uint8_t*)fheaders + 1024);
        }

        /* We now know the total size of the file; patch it into the main header */
        if (offset & 0xFF)
            offset = (offset & 0xFF) + 0x100;

        header->image_size = offset;
    }

    /* Now we have all headers setup in memory, time to write out the image file */
    fwrite(p, 1024, num_files +1, ofp);

    /* now write the file content too */
    for (i = 1; i <= num_files; i++) {
        struct imagewty_file_header *h =
            (struct imagewty_file_header*)(p + i * 1024);

        FILE *fp = dir_fopen(indn, h->v1.filename, "rb");
        if (fp != NULL) {
            char buf[512];
            size_t size = 0;
            while(!feof(fp)) {
                size_t bytesread = fread(buf, 1, 512, fp);
                if (bytesread) {
                    if (bytesread & 0x1ff)
                        bytesread = (bytesread & ~0x1ff) + 0x200;

                    if (flag_encryption_enabled)
                        rc6_encrypt_inplace(buf, bytesread, &filecontent_ctx);
                    fwrite(buf, 1, bytesread, ofp);
                }
                size += bytesread;
            }
            fclose(fp);
        }
    }

    /* Headers no longer used; encrypt and write if requested */
    if (flag_encryption_enabled) {
        void *curr = rc6_encrypt_inplace(p, 1024, &header_ctx);
        rc6_encrypt_inplace(curr, num_files * 1024, &fileheaders_ctx);
        rewind(ofp);
        fwrite(p, 1024, num_files +1, ofp);
    }

    fclose(ofp);

    /* Done, free configuration, no longer needed */
    cfg_free(head);

    return 0;
}