Ejemplo n.º 1
0
musicp music_load (const char *file, const char *name_alias)
{
    if (name_alias) {
        musicp m = music_find(name_alias);
        if (m) {
            return (m);
        }
    }

    if (!file) {
        if (!name_alias) {
            ERR("no file for music");
        } else {
            ERR("no file for music loading %s", name_alias);
        }
    }

    if (!all_music) {
        all_music = tree_alloc(TREE_KEY_STRING, "TREE ROOT: music");
    }

    musicp m = (typeof(m)) myzalloc(sizeof(*m), "TREE NODE: music");
    m->tree.key = dupstr(name_alias, "TREE KEY: music");

    if (!tree_insert(all_music, &m->tree.node)) {
        ERR("music insert name_alias [%s] failed", name_alias);
    }

    m->data = ramdisk_load(file, &m->len);
    if (!m->data) {
        ERR("cannot load music %s", file);
    }

    SDL_RWops *rw;

    rw = SDL_RWFromMem(m->data, m->len);
    if (!rw) {
        ERR("cannot make RW music %s", file);
    }

#if SDL_MAJOR_VERSION == 1 && SDL_MINOR_VERSION == 2 /* { */
    m->music = Mix_LoadMUS_RW(rw);
#else
    m->music = Mix_LoadMUS_RW(rw, false);
#endif /* } */
    if (!m->music) {
        MSG_BOX("Mix_LoadMUS_RW fail %s: %s %s", file, Mix_GetError(),
            SDL_GetError());
        SDL_ClearError();
    }

    DBG("Load %s", file);

    return (m);
}
Ejemplo n.º 2
0
font *
ttf_read_tga (fontp f, const char *name, int32_t pointsize)
{
    char filename[MAXSTR];
    uint32_t c;
    texp tex;

    if (pointsize < 0) {
        ERR("nutso font size %d", pointsize);
    }

    if (pointsize > 100) {
        ERR("nutso font size %d", pointsize);
    }

    /*
     * Read the glyph data.
     */
    snprintf(filename, sizeof(filename), "%s_pointsize%d.data",
             name, pointsize);

    const unsigned char *glyph_data = ramdisk_load(filename, 0);
    if (!glyph_data) {
        ERR("could not load font %s data", filename);
    }

    memcpy(f->glyphs, glyph_data, sizeof(f->glyphs));

    snprintf(filename, sizeof(filename), "%s_pointsize%u.tga",
             name, pointsize);

    tex = tex_load(filename,
                   filename /* to make unique for same point size */);
    if (!tex) {
        ERR("could not load font %s tex", filename);
    }

    for (c = TTF_GLYPH_MIN; c < TTF_GLYPH_MAX; c++) {
        f->tex[c].tex = tex_get_gl_binding(tex);
        f->tex[c].image = tex_get_surface(tex);
    }

    return (f);
}
Ejemplo n.º 3
0
/* This may be used only once, enforced by 'static int callable' */
int sys_setup(void * BIOS)
{
    static int callable = 1;
    int i, drive;
    unsigned char cmos_disks;
    struct partition *p;
    struct buffer_head *bh;

    /* enforce this func execute only once */
    if (!callable)
        return -1;
    callable = 0;

#ifndef HD_TYPE	/* currenty not define HD_TYPE */
    printk("HD_TYPE no defined, get drive info from BIOS\n");
    for (drive = 0; drive < 2; drive++) {
        hd_info[drive].cyl = *(unsigned short *)BIOS;
        hd_info[drive].head = *(unsigned char *)(2 + BIOS);
        hd_info[drive].wpcom = *(unsigned short *)(5 + BIOS);
        hd_info[drive].ctl = *(unsigned char *)(8 + BIOS);
        hd_info[drive].lzone = *(unsigned short *)(12 + BIOS);
        hd_info[drive].sect = *(unsigned char *)(14 + BIOS);
        BIOS += 16; /* each drive param table is 16 byte long */
    }

    if (hd_info[1].cyl)
        NR_HD = 2;
    else
        NR_HD = 1;
#endif
    /* calculate hard disk total sectors */
    for (i = 0; i < NR_HD; i++) {
        hd[i * 5].start_sect = 0;
        hd[i * 5].nr_sects =
            hd_info[i].head * hd_info[i].sect * hd_info[i].cyl;
    }

    /*
     * We querry CMOS about hard disks : it could be that we have a
     * SCSI/ESDI/etc controller that is BIOS compatable with ST-506, and
     * thus showing up in our BIOS table, but not register compatable, and
     * therefore not present in CMOS.
     *
     * Furthurmore, we will assume that our ST-506 drives <if any> are the
     * primary drives in the system, and the ones reflected as drive 1 or 2.
     *
     * The first drive is stored in the high nibble of CMOS byte 0x12, the
     * second in the low nibble.  This will be either a 4 bit drive type or
     * 0xf indicating use byte 0x19 for an 8 bit type, drive 1, 0x1a for
     * drive 2 in CMOS.
     *
     * Needless to say, a non-zero value means we have an AT controller hard
     * disk for that drive.
     */
    if ((cmos_disks = CMOS_READ(0x12)) & 0xf0) {
        if (cmos_disks & 0x0f)
            NR_HD = 2;
        else
            NR_HD = 1;
    } else {
        NR_HD = 0;
    }

    printk("There are %d hard disk in system\n", NR_HD);

    /* reset un-exist hd[] structure */
    for (i = NR_HD; i < 2; i++) {
        hd[i * 5].start_sect = 0;
        hd[i * 5].nr_sects = 0;
    }

    /* fetch partiton info */
    for (drive = 0; drive < NR_HD; drive++) {
        /* read 1st block (Minix fs: 1 block = 2 sectors = 1KB) */
        if (!(bh = bread(0x300 + drive * 5, 0))) {
            printk("Unable to read partition table of drive %d\n",
                   drive);
            panic("");
        }

        /* validate if it is the boot sector */
        if (bh->b_data[510] != 0x55 ||
                ((unsigned char)bh->b_data[511]) != 0xaa) {
            printk("Bad partition table on drive %d\n", drive);
            panic("");
        }

        /* partition table is at 0x1be of first block */
        p = (void *)bh->b_data + 0x01be;

        /* save each partition's start/total sectors information */
        for (i = 1; i < 5; i++, p++) {
            hd[drive * 5 + i].start_sect = p->start_sect;
            hd[drive * 5 + i].nr_sects = p->nr_sects;
            printk("partition %d of HD %d start sector: %ld, nr_sects: %ld\n",
                   i, drive + 1, p->start_sect, p->nr_sects);
        }

        brelse(bh);
    }

    if (NR_HD)
        printk("Read partition table%s ok.\n", (NR_HD > 1) ? "s" : "");

    /* currently we don't use ramdisk. Nail 2016/02/22 */
    ramdisk_load();

    printk("ROOT_DEV: 0x%x\n", ROOT_DEV);
    printk("Mounting root filesystem...\n");
    mount_root();

    return 0;
}
Ejemplo n.º 4
0
tree_demarshal *demarshal (const char *filename)
{
    demarshal_parse_state state;
    int8_t depth;
#ifdef FASTER_LOADING
    static tree_demarshal *ctx;
#else
    tree_demarshal *ctx;
#endif
    uint8_t newline;
    char *next;
    char *buf;
    int32_t size;
    char *at;
    float tmp_float;
    char *tmp_at = 0;
    int64_t tmp_int = 0;
    uint64_t tmp_hex = 0;
    int64_t tmp_mul = 0;
    uint8_t compress;

    strncpy(demarshal_parse_filename, 
            filename,
            sizeof(demarshal_parse_filename) - 1);

    demarshal_parse_line = 1;

    if (!filename) {
        ERR("no filename");
    }

    buf = (char*)ramdisk_load(filename, &size);
    if (!buf) {
        return (0);
    }

#ifdef FASTER_LOADING
    if (!ctx) {
        ctx = (typeof(ctx)) myzalloc(sizeof(*ctx), "demarshal ctx");
    }
#else
    ctx = (typeof(ctx)) myzalloc(sizeof(*ctx), "demarshal ctx");
#endif

    demarshal_buf_end = buf + size;

    next = buf;
    at = buf;
    depth = 0;
    state = MARSHAL_PARSE_STATE_NONE;
    newline = 1;

    while (at < demarshal_buf_end) {
        at = next;

        if (newline) {
            while (at < demarshal_buf_end) {
                if (*at == '#') {
                    while ((at < demarshal_buf_end) && (*at != '\n')) { at++; }
                    at++;
                } else {
                    while ((at < demarshal_buf_end) && isspace(*at)) { at++; }
                    break;
                }
            }

            newline = 0;
        }

        if (at >= demarshal_buf_end) {
            break;
        }

        char c = *at;

        next = at + 1;

        if (at >= demarshal_buf_end) {
            ERR("Unexpected end in \"%s\"", filename);
        }

        switch (state) {
        case MARSHAL_PARSE_STATE_NONE:
            switch (c) {
            case ' ':
            case '\t':
                continue;

            case '#':
                while ((at < demarshal_buf_end) && (*at != '\n')) { at++; }
                next = at;
                continue;

            default:
                state = MARSHAL_PARSE_STATE_NAME;
                tmp_at = at;
                continue;

            case '0':
                if (*next == 'x') {
                    next++;
                    state = MARSHAL_PARSE_STATE_HEX;
                    tmp_at = at;
                    continue;
                }

            case '1': case '2': case '3': case '4': case '5':
            case '6': case '7': case '8': case '9':
                state = MARSHAL_PARSE_STATE_INT;
                tmp_int = c - '0';
                tmp_mul = 1;
                tmp_at = at;
                continue;

            case '\"':
                state = MARSHAL_PARSE_STATE_STRING;
                tmp_at = at + 1;
                continue;

            case '[':
            case '{':
                demarshal_push_node(ctx, depth, MARSHAL_BRA);
                depth++;
                continue;

            case ']':
            case '}':
                depth--;
                demarshal_push_node(ctx, depth, MARSHAL_KET);
                continue;

            case 13:
                demarshal_parse_line++;
                newline = 1;
                continue;

            case '\n':
                demarshal_parse_line++;
                newline = 1;
                continue;

            case '-':
                state = MARSHAL_PARSE_STATE_INT;
                tmp_int = 0;
                tmp_at = at;
                tmp_mul = -1;
                continue;

            case '.':
            case '+':
                state = MARSHAL_PARSE_STATE_INT;
                tmp_int = 0;
                tmp_at = at;
                tmp_mul = 1;
                continue;
            }

        case MARSHAL_PARSE_STATE_INT:
            while (isdigit(c)) {
                tmp_int *= 10;
                tmp_int += c - '0';
                c = *++at;

                if (at >= demarshal_buf_end) {
                    ERR("Unexpected end in \"%s\" when parsing int", filename);
                }
            }

            if (c == '.') {

                uint8_t need_lex = 0;

                tmp_float = (float)tmp_int;

                float mul = 10.0f;

                c = *++at;

                while (!isspace(c)) {
                    if (at >= demarshal_buf_end) {
                        ERR("Unexpected end in \"%s\" when parsing float",
                            filename);
                    }

                    if (need_lex) {
                        c = *++at;
                        continue;
                    }

                    if (c == 'e') {
                        c = *++at;
                        while (!isspace(c)) {
                            c = *++at;
                        }
                        break;
                    }

                    tmp_float += (float)(c - '0') / mul;
                    mul *= 10.0f;
                    c = *++at;
                }

                if (need_lex) {
                    *at++ = '\0';
                    tmp_float = strtof(tmp_at, 0);
                } else {
                    tmp_float *= (float)tmp_mul;
                }

                demarshal_push_float(ctx, depth, tmp_float);
            } else {
                tmp_int *= tmp_mul;

                demarshal_push_int64(ctx, depth, tmp_int);
            }

            state = MARSHAL_PARSE_STATE_NONE;
            next = at;
            continue;

        case MARSHAL_PARSE_STATE_HEX:
            tmp_hex = 0;

            c = *at;

            while (isdigit(c) ||
                   ((c >= 'a') && (c <='f')) ||
                   ((c >= 'A') && (c <='F'))) {

                tmp_hex *= 16;

                if ((c >= 'a') && (c <='z')) {
                    tmp_hex += c - 'a' + 10;
                } else if ((c >= 'A') && (c <='Z')) {
                    tmp_hex += c - 'A' + 10;
                } else {
                    tmp_hex += c - '0';
                }

                c = *++at;

                if (at >= demarshal_buf_end) {
                    ERR("Unexpected end in \"%s\" when parsing int", filename);
                }
            }

            demarshal_push_int64(ctx, depth, (int64_t)tmp_hex);

            state = MARSHAL_PARSE_STATE_NONE;
            next = at;
            continue;

        case MARSHAL_PARSE_STATE_NAME:
            while ((c != '=') && (c != ' ') && (c != '\t') && (c != '\n')) {
                c = *++at;

                if (at >= demarshal_buf_end) {
                    ERR("Unexpected end in \"%s\" when parsing name",
                        filename);
                }
            }

            if (c == '\n') {
                newline = 1;
            }

            state = MARSHAL_PARSE_STATE_NONE;
            *at = '\0';
            next = at + 1;
            demarshal_push_name(ctx, depth, tmp_at);
            continue;

        case MARSHAL_PARSE_STATE_STRING:
            compress = 0;

            while (c != '\"') {
                c = *++at;

                if (c == '\\') {
                    at++;
                    compress = 1;
                }

                if (at >= demarshal_buf_end) {
                    ERR("Unexpected end in \"%s\" when parsing string",
                        filename);
                }
            }

            state = MARSHAL_PARSE_STATE_NONE;
            *at = '\0';
            next = at + 1;

            if (compress) {
                strnoescape(tmp_at);
            }

            demarshal_push_string(ctx, depth, tmp_at);
            continue;
        }
    }

    if (state != MARSHAL_PARSE_STATE_NONE) {
        ERR("Error in \"%s\" line %u",
            demarshal_parse_filename,
            demarshal_parse_line);
    }

    ctx->nodeat = 0;

    myfree(buf);

#ifdef ENABLE_DEMARSHAL_DEBUG
    demarshal_print(ctx);
#endif

    return (ctx);
}