Ejemplo n.º 1
0
TbBool setup_heap_manager(void)
{
    SYNCDBG(8,"Starting");
    const char *fname;
    long i;
    //_DK_setup_heap_manager();
    if (heap == NULL)
    {
        ERRORLOG("Graphics Heap not allocated");
        return false;
    }
    i = heap_size / 512;
    if (i >= KEEPSPRITE_LENGTH)
      i = KEEPSPRITE_LENGTH-1;
    graphics_heap = heapmgr_init(heap, heap_size, i);
    if (graphics_heap == NULL)
    {
        ERRORLOG("Not enough memory to initialize heap.");
        return false;
    }
    wait_for_cd_to_be_available();
    fname = prepare_file_path(FGrp_StdData,"creature.jty");
    //TODO CREATURE_SPRITE Use rewritten file handling when reading is rewritten
    file_handle = _DK_LbFileOpen(fname, Lb_FILE_MODE_READ_ONLY);
    if (file_handle == -1) {
        ERRORLOG("Can not open 'creature.jty'");
        return false;
    }
    for (i=0; i < KEEPSPRITE_LENGTH; i++)
        keepsprite[i] = NULL;
    for (i=0; i < KEEPSPRITE_LENGTH; i++)
        heap_handle[i] = NULL;
    return true;
}
Ejemplo n.º 2
0
TbBool init_sound_heap_two_banks(unsigned char *heap_mem, long heap_size, char *snd_fname, char *spc_fname, long a5)
{
    long i;
    long buf_len;
    unsigned char *buf;
    SYNCDBG(8,"Starting");
    LbMemorySet(heap_mem, 0, heap_size);
    using_two_banks = 0;
    // Open first sound bank and prepare sample table
    if (sound_file != -1)
        close_sound_bank(0);
    samples_in_bank = 0;
    sound_file = _DK_LbFileOpen(snd_fname,Lb_FILE_MODE_READ_ONLY);
    if (sound_file == -1)
    {
        ERRORLOG("Couldn't open primary sound bank file \"%s\"",snd_fname);
        return false;
    }
    buf = heap_mem;
    buf_len = heap_size;
    i = parse_sound_file(sound_file, buf, &samples_in_bank, buf_len, a5);
    if (i == 0)
    {
        ERRORLOG("Couldn't parse sound bank file \"%s\"",snd_fname);
        close_sound_heap();
        return false;
    }
    sample_table = (struct SampleTable *)buf;
    buf_len -= i;
    buf += i;
    if (buf_len <= 0)
    {
        ERRORLOG("Sound bank buffer too short");
        close_sound_heap();
        return false;
    }
    // Open second sound bank and prepare sample table
    if (sound_file2 != -1)
        close_sound_bank(1);
    samples_in_bank2 = 0;
    sound_file2 = _DK_LbFileOpen(spc_fname,Lb_FILE_MODE_READ_ONLY);
    if (sound_file2 == -1)
    {
        ERRORLOG("Couldn't open secondary sound bank file \"%s\"",spc_fname);
        return false;
    }
    i = parse_sound_file(sound_file2, buf, &samples_in_bank2, buf_len, a5);
    if (i == 0)
    {
        ERRORLOG("Couldn't parse sound bank file \"%s\"",spc_fname);
        close_sound_heap();
        return false;
    }
    sample_table2 = (struct SampleTable *)buf;
    buf_len -= i;
    buf += i;
    if (buf_len <= 0)
    {
        ERRORLOG("Sound bank buffer too short");
        close_sound_heap();
        return false;
    }
    SYNCLOG("Got sound buffer of %ld bytes, samples in banks: %d,%d",buf_len,(int)samples_in_bank,(int)samples_in_bank2);
    sndheap = heapmgr_init(buf, buf_len, samples_in_bank2 + samples_in_bank);
    if (sndheap == NULL)
    {
        ERRORLOG("Sound heap manager init error");
        close_sound_heap();
        return false;
    }
    using_two_banks = 1;
    return true;
}