Example #1
0
int gfx_loadsprites(int num, char *name)
{
    int handle, size, c;
    int datastart;

    if (!gfx_spriteheaders)
    {
        gfx_setmaxspritefiles(DEFAULT_MAX_SPRFILES);
    }

    bme_error = BME_OPEN_ERROR;
    if (num >= gfx_maxspritefiles) return BME_ERROR;

    gfx_freesprites(num);

    handle = io_open(name);
    if (handle == -1) return BME_ERROR;

    size = io_lseek(handle, 0, SEEK_END);
    io_lseek(handle, 0, SEEK_SET);

    gfx_spriteamount[num] = io_readle32(handle);

    gfx_spriteheaders[num] = malloc(gfx_spriteamount[num] * sizeof(SPRITEHEADER));

    if (!gfx_spriteheaders[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }

    for (c = 0; c < gfx_spriteamount[num]; c++)
    {
        SPRITEHEADER *hptr = gfx_spriteheaders[num] + c;

        hptr->xsize = io_readle16(handle);
        hptr->ysize = io_readle16(handle);
        hptr->xhot = io_readle16(handle);
        hptr->yhot = io_readle16(handle);
        hptr->offset = io_readle32(handle);
    }

    datastart = io_lseek(handle, 0, SEEK_CUR);
    gfx_spritedata[num] = malloc(size - datastart);
    if (!gfx_spritedata[num])
    {
        bme_error = BME_OUT_OF_MEMORY;    
        io_close(handle);
        return BME_ERROR;
    }
    io_read(handle, gfx_spritedata[num], size - datastart);
    io_close(handle);
    bme_error = BME_OK;
    return BME_OK;
}
Example #2
0
SAMPLE *snd_loadrawsample(char *name, int repeat, int end, unsigned char voicemode)
{
    int length;
    int handle;
    SAMPLE *smp;

    bme_error = BME_OPEN_ERROR;
    handle = io_open(name);
    if (handle == -1) return NULL;
    length = io_lseek(handle, 0, SEEK_END);
    if (length == -1)
    {
        io_close(handle);
        return NULL;
    }
    io_lseek(handle, 0, SEEK_SET);
    smp = snd_allocsample(length);
    if (!smp)
    {
        io_close(handle);
        return NULL;
    }
    if (end == 0) end = length;
    if (end > length) end = length;
    if (repeat > length - 1) repeat = length - 1;
    bme_error = BME_READ_ERROR;
    if (io_read(handle, smp->start, length) != length)
    {
        snd_freesample(smp);
        io_close(handle);
        return NULL;
    }
    io_close(handle);
    smp->repeat = smp->start + repeat;
    smp->end = smp->start + end;
    smp->voicemode = voicemode | VM_ON;
    snd_ipcorrect(smp);
    bme_error = BME_OK;
    return smp;
}
Example #3
0
dylan_value Kunix_lseekYio_internalsVioI (dylan_value fd_, dylan_value position_, dylan_value mode_) {
  long T3;
  DWORD T4;
  DWORD T5;
  DWORD T6;
  DWORD T7;
  DWORD T8;
  DWORD T9;
  DWORD T10;
  DWORD T11;
  dylan_value T12;
  dylan_value T13_0;

  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:78
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T5 = primitive_cast_integer_as_raw(fd_);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T4 = primitive_machine_word_shift_right(T5,2);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T7 = primitive_cast_integer_as_raw(position_);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T6 = primitive_machine_word_shift_right(T7,2);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T9 = primitive_cast_integer_as_raw(mode_);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:85
  T8 = primitive_machine_word_shift_right(T9,2);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:81
  T3 = io_lseek(T4, T6, T8);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:80
  T10 = primitive_machine_word_shift_left_signal_overflow(T3,2);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:80
  T11 = primitive_machine_word_logior(T10,1);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:80
  T12 = primitive_cast_raw_as_integer(T11);
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:80
  T13_0 = T12;
  // /opt/opendylan-2014.1/sources/io/unix-interface.dylan:78
  MV_SET_COUNT(1);
  return(T13_0);
}
Example #4
0
int gfx_loadblocks(char *name)
{
    int handle, size, datastart, c;
    BLOCKHEADER *hptr;

    handle = io_open(name);
    if (handle == -1)
    {
        bme_error = BME_OPEN_ERROR;
        return 0;
    }

    if (gfx_blocks)
    {
        free(gfx_blocks);
        gfx_blocks = NULL;
    }
    if (gfx_blockheaders)
    {
        free(gfx_blockheaders);
        gfx_blockheaders = NULL;
    }
    gfx_nblocks = 0;
    
    size = io_lseek(handle, 0, SEEK_END);
    io_lseek(handle, 0, SEEK_SET);

    gfx_nblocks = io_readle32(handle);
    gfx_blockxsize = io_readle32(handle);
    gfx_blockysize = io_readle32(handle);

    gfx_blockheaders = malloc(sizeof(BLOCKHEADER) * gfx_nblocks);
    if (!gfx_blockheaders)
    {
        bme_error = BME_OUT_OF_MEMORY;
        gfx_nblocks = 0;
        io_close(handle);
        return BME_ERROR;
    }

    for (c = 0; c < gfx_nblocks; c++)
    {
        hptr = gfx_blockheaders + c;
        hptr->type = io_readle32(handle);
        hptr->offset = io_readle32(handle);
    }

    datastart = io_lseek(handle, 0, SEEK_CUR);
    gfx_blocks = malloc(size - datastart);
    if (!gfx_blocks)
    { 
        free(gfx_blockheaders);
        gfx_blockheaders = NULL;
        bme_error = BME_OUT_OF_MEMORY;
        gfx_nblocks = 0;
        io_close(handle);
        return BME_ERROR;
    }
    io_read(handle, gfx_blocks, size - datastart);
    io_close(handle);
    bme_error = BME_OK;
    return BME_OK;
}
Example #5
0
int main(int argc, char * argv[])
{
        int i;
        int read_write_error;
        int input_stat[2] = {0};
        int output_stat[2] = {0};

        int flags = 0;
        int count = -1;
        int skip = 0, seek = 0;
        int bs = -1, ibs = 4096, obs = 4096;
        int buffer_size = 0;
        int count_read, count_write;
        time_t time_start, time_finish, time_use;

        const char * input_path = "-";
        const char * output_path = "-";
        const char * input_device = NULL;
        const char * output_device = NULL;

        struct io_base *input_handle, *output_handle;
        char * buffer_read, * buffer_write, * buffer_alloc;

        for (i = 1; i < argc; i++) {
                char * argline = argv[i];
                char * optvalue = getoptvalue(argv[i]);

                ARG_INT(&ibs, 1, "ibs=");
                ARG_INT(&obs, 2, "obs=");
                ARG_INT(&bs, (1 | 2), "bs=");
                ARG_INT(&seek, 4, "seek=");
                ARG_INT(&skip, 8, "skip=");
                ARG_INT(&count, 16, "count=");
                ARG_STRING(&input_path, 32, "if=");
                ARG_STRING(&output_path, 64, "of=");
                ARG_STRING(&input_device, 128, "kin=");
                ARG_STRING(&output_device, 256, "kout=");

                fprintf(stderr, "unkown operand %s", argline);
                exit(-1);
        }

        if (bs != -1) {
                ibs = bs;
                obs = bs;
        }

        valid_size("invalid input block size", ibs);
        valid_size("invalid output block size", obs);

        input_handle = open_file(input_path, GENERIC_READ);
        valid_handle("invalid input handle", input_handle);

        output_handle = open_file(output_path, GENERIC_WRITE);
        valid_handle("invalid output handle", output_handle);

        buffer_size = (ibs < obs? obs: ibs) * 2;
        buffer_alloc = (char *)malloc(buffer_size);
        valid_buffer("alloc buffer fail", buffer_alloc);

        if (seek > 0) {
				off_t posnew = seek * (off_t)(obs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("seek output file fail", posnew == poscur);
        }

        if (skip > 0) {
				off_t posnew = skip * (off_t)(ibs);
				off_t poscur = io_lseek(output_handle, posnew, SEEK_CUR);
                valid_size("skip input file fail", posnew == poscur);
        }

        read_write_error = 0;
        count_read = count_write = 0;
        buffer_read = buffer_write = buffer_alloc;

        time_start = time(NULL);
        while (read_write_error == 0) {
                size_t transfer = 0;

                while (buffer_read < buffer_alloc + obs) {
                        if (!io_read(input_handle, buffer_read, ibs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 1;
                                break;
                        }

                        buffer_read += transfer;
                        count_read += transfer;

                        input_stat[transfer == ibs]++;
                        if (input_stat[0] + input_stat[1] == count) {
                                read_write_error = 1;
                                break;
                        }
                }

                while (buffer_write + obs <= buffer_read) {
                        if (!io_write(output_handle, buffer_write, obs, &transfer)) {
                                read_write_error = 2;
                                break;
                        }

                        if (transfer == 0) {
                                read_write_error = 2;
                                break;
                        }

                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                }

                memmove(buffer_alloc, buffer_write, count_read - count_write);
                buffer_read = buffer_alloc + (count_read - count_write);
                buffer_write = buffer_alloc;
        }

        while (read_write_error == 1 &&
                        count_write < count_read) {
                size_t transfer = (count_read - count_write);

                valid_size("internal error", transfer < obs);
                if (io_write(output_handle, buffer_write, transfer, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }

                if (io_write(output_handle, buffer_write, obs, &transfer)) {
                        output_stat[transfer == obs]++;
                        buffer_write += transfer;
                        count_write += transfer;
                        continue;
                }
           
                read_write_error = 3;
                break;
        }
        time_finish = time(NULL);

        io_close(output_handle);
        io_close(input_handle);
        free(buffer_alloc);

        time_use = time_finish > time_start? time_finish - time_start: 1;
        fprintf(stderr, "%d+%d records in\n", input_stat[1], input_stat[0]);
        fprintf(stderr, "%d+%d records out\n", output_stat[1], output_stat[0]);
        fprintf(stderr, "%d bytes transferred in %ld secs (%ld bytes/sec)\n",
                        count_read, time_use, count_read / time_use);
        return 0;
}