static struct shortcut* get_shortcut(int index)
{
    int handle_count, handle_index;
    int current_handle = first_handle;
    struct shortcut_handle *h = NULL;
    
    if (first_handle == 0)
    {
        first_handle = core_alloc("shortcuts_head", sizeof(struct shortcut_handle));
        if (first_handle <= 0)
            return NULL;
        h = core_get_data(first_handle);
        h->next_handle = 0;
        current_handle = first_handle;
    }

    handle_count = index/SHORTCUTS_PER_HANDLE + 1;
    handle_index = index%SHORTCUTS_PER_HANDLE;
    do {
        h = core_get_data(current_handle);
        current_handle = h->next_handle;
        handle_count--;
    } while (handle_count > 0 && current_handle > 0);
    if (handle_count > 0 && handle_index == 0)
    {
        char buf[32];
        snprintf(buf, sizeof buf, "shortcuts_%d", index/SHORTCUTS_PER_HANDLE);
        h->next_handle = core_alloc(buf, sizeof(struct shortcut_handle));
        if (h->next_handle <= 0)
            return NULL;
        h = core_get_data(h->next_handle);
        h->next_handle = 0;
    }
    return &h->shortcuts[handle_index];
}
Пример #2
0
static void pbe_buffer_alloc(void)
{
    if (handle > 0)
        return; /* already-allocated */

    unsigned int total_len = (B0_SIZE + B2_SIZE + B3_SIZE) * 2;
    handle = core_alloc("dsp_pbe_buffer",sizeof(int32_t) * total_len);

    if (handle < 0)
    {
        pbe_strength = 0;
        return;
    }
    memset(core_get_data(handle),0,sizeof(int32_t) * total_len);
}
Пример #3
0
static void surround_buffer_alloc(void)
{
    if (handle > 0)
        return; /* already-allocated */

    unsigned int total_len = B0_DLY + B2_DLY + BB_DLY + HH_DLY + CL_DLY;
    handle = core_alloc("dsp_surround_buffer",sizeof(int32_t) * total_len);

    if (handle < 0)
    {
        surround_enabled = false;
        return;
    }
    memset(core_get_data(handle),0,sizeof(int32_t) * total_len);
}
void shortcuts_init(void)
{
    int fd;
    char buf[512];
    struct shortcut *param = NULL;
    struct shortcut_handle *h;
    shortcut_count = 0;
    fd = open_utf8(SHORTCUTS_FILENAME, O_RDONLY);
    if (fd < 0)
        return;
    first_handle = core_alloc("shortcuts_head", sizeof(struct shortcut_handle));
    if (first_handle <= 0)
        return;
    h = core_get_data(first_handle);
    h->next_handle = 0;
    fast_readline(fd, buf, sizeof buf, &param, readline_cb);
    close(fd);
    if (param && verify_shortcut(param))
        shortcut_count++;
}
Пример #5
0
static void cfs_init(void)
{
    struct main_header *hdr;
    struct cfs_header *cfs;
    struct cfs_inode *root_inode, *vfat_inode, *inode;
    struct cfs_direntry *root_direntry, *vfat_direntry;
    struct cfs_direntry_item *root_direntry_items, *vfat_direntry_items;
    unsigned int i, j, k, vfat_inode_nr=0, vfat_inodes_nr[10], vfat_sector_count;
    unsigned char sector[512];
    static unsigned int vfat_data[2][0x8000];
    static unsigned char sector2[0x8000];

    if(cfs_inited)
        return;

    /* Read MBLK */
    _ata_read_sectors(0, 1, &sector);
    hdr = (struct main_header*)&sector;

    logf("CFS is at 0x%x [0x%x]", CFS_START, CFS_START/512);

    /* Read CFS header */
    _ata_read_sectors(CFS_START/512, 64, &sector2);
    cfs = (struct cfs_header*)&sector2;

    logf("First inode = 0x%x", cfs->first_inode);

    /* Read root inode */
    _ata_read_sectors(CFS_CLUSTER2CLUSTER(cfs->first_inode), 64, &sector2);
    root_inode = (struct cfs_inode*)&sector2;
    
    logf("Root inode = 0x%x", root_inode);
    
    logf("0x%x 0x%x", CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), root_inode->first_class_chain[0]);

    /* Read root inode's first sector */
    _ata_read_sectors(CFS_CLUSTER2CLUSTER(root_inode->first_class_chain[0]), 64, &sector2);
    root_direntry = (struct cfs_direntry*)&sector2;
    root_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry));

    logf("0x%x", root_direntry->identifier);

    logf("%d", root_direntry->items);

    /* Search VFAT inode */
    for(i=0; i < root_direntry->items; i++)
    {
        if(root_direntry_items[i].inode_number != 0)
        {
            //logf(" * [%s] at 0x%x", ucs2letostring(&root_direntry_items[i].string[0]), root_direntry_items[i].inode_number);
            if(strcmp(ucs2letostring(&root_direntry_items[i].string[0]), "VFAT") == 0)
                vfat_inode_nr = root_direntry_items[i].inode_number;
        }
    }
    
    logf("VFAT inode = 0x%x", vfat_inode_nr);
    
    if(vfat_inode_nr != 0)
    {
        /* Read VFAT inode */
        _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode_nr), 64, &sector2);
        vfat_inode = (struct cfs_inode*)&sector2;

        /* Read VFAT inode's first sector */
        _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inode->first_class_chain[0]), 64, &sector2);
        vfat_direntry = (struct cfs_direntry*)&sector2;
        vfat_direntry_items = (struct cfs_direntry_item*)(&sector2+sizeof(struct cfs_direntry));

        /* Search for VFAT's subinodes */
        for(i=0; i < vfat_direntry->items; i++)
        {
            logf(" * [%s] at 0x%x\n", ucs2letostring(&vfat_direntry_items[i].string[0]), vfat_direntry_items[i].inode_number);
            if(i > 0)
                vfat_inodes_nr[i-1] = vfat_direntry_items[i].inode_number;
        }

        /* Determine size of VFAT file */
        _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[1]), 1, &sector);
        inode = (struct cfs_inode*)&sector;
#ifndef BOOTLOADER
        sectors_handle = core_alloc("ata sectors", VFAT_SECTOR_SIZE(inode->filesize));
        unsigned long *sectors = core_get_data(sectors_handle);
#else
        static unsigned long _sector[VFAT_SECTOR_SIZE(1024*1024*1024)]; /* 1GB guess */
        sectors = _sector;
#endif

        logf("VFAT file size: 0x%x", inode->filesize);

        /* Clear data sectors */
        memset(&sectors, 0, VFAT_SECTOR_SIZE(inode->filesize)*sizeof(unsigned long));

        /* Read all data sectors' addresses in memory */
        vfat_sector_count = 0;
        for(i=0; vfat_inodes_nr[i] != 0; i++)
        {
            _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_inodes_nr[i]), 1, &sector);
            inode = (struct cfs_inode*)&sector;

            /* Read second & third class chain */
            _ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_first_cluster), 64, &vfat_data[0]);
            _ata_read_sectors(CFS_CLUSTER2CLUSTER(inode->second_class_chain_second_cluster), 64, &vfat_data[1]);

            /* First class chain */
#ifndef BOOTLOADER
            sectors = core_get_data(sectors_handle);
#endif
            for(j=0; j<12; j++)
            {
                if( (inode->first_class_chain[j] & 0xFFFF) != 0xFFFF &&
                     inode->first_class_chain[j] != 0
                  )
                    sectors[vfat_sector_count++] = inode->first_class_chain[j];
            }

            /* Second class chain */
#ifndef BOOTLOADER
            sectors = core_get_data(sectors_handle);
#endif
            for(j=0; j<0x8000/4; j++)
            {
                if( (vfat_data[0][j] & 0xFFFF) != 0xFFFF &&
                    vfat_data[0][j] != 0
                  )
                    sectors[vfat_sector_count++] = vfat_data[0][j];
            }

            /* Third class chain */
            for(j=0; j<0x8000/4; j++)
            {
                if( (vfat_data[1][j] & 0xFFFF) != 0xFFFF &&
                    vfat_data[1][j] != 0
                  )
                {
                    memset(&vfat_data[0], 0, 0x8000*sizeof(unsigned int));

                    /* Read third class subchain(s) */
                    _ata_read_sectors(CFS_CLUSTER2CLUSTER(vfat_data[1][j]), 64, &vfat_data[0]);

#ifndef BOOTLOADER
                    sectors = core_get_data(sectors_handle);
#endif
                    for(k=0; k<0x8000/4; k++)
                    {
                        if( (vfat_data[0][k] & 0xFFFF) != 0xFFFF &&
                            vfat_data[0][k] != 0
                          )
                            sectors[vfat_sector_count++] = vfat_data[0][k];
                    }
                }
            }
        }

        logf("Sector count: %d 0x%x", vfat_sector_count, vfat_sector_count);
    }
    else
        panicf("Cannot find virtual FAT filesystem!");

    cfs_inited = true;
}