Archive-ByteBoozer

 view release on metacpan or  search on metacpan

cruncher.c  view on Meta::CPAN

#endif

  while(get >= 0) {
    if(scan(&theMatchLen, &theMatchOffset)) {
      flush();
      copy(theMatchLen, theMatchOffset);
    }
    else {
      ++plainLen;
      --get;
    }
  };
  flush();

  if(errorFlag == _true) {
    return _false;
  }

  //Copy obuf into aTarget!!
  packLen = memSize - put - 1;

#ifdef DEBUG
  printf("\nsize = %i\n", packLen);
#endif

  aTarget->size = packLen + decrLen + 5;
  aTarget->data = (byte *)malloc(aTarget->size);
  if(aTarget->data == NULL) {
    printf("Error (C-3): Out of memory.\n");
    return _false;
  }

  target = aTarget->data + decrLen + 2;

  target[0] = (curByte | (1 << (curCnt - 1)));
  target[1] = aSource->data[0];
  target[2] = aSource->data[1];

  for(i = 0; i < packLen; ++i) {
    target[i + 3] = obuf[put + i + 1];
  }

  switch(theDecrType) {
  case noDecr: {
    uint packStart;
    if(isRelocated)
      packStart = startAdress;
    else
      packStart = 0xfffa;
    packStart -= (packLen + 3);
    aTarget->data[0] = packStart & 0xff;
    aTarget->data[1] = packStart >> 8;
    break;
  }
  case cleanDecr: {
    uint packStart = 0xfffd - packLen;
    uint trnsStart = 0x0814 + packLen;
    cleanDecrCode[0x1e] = packStart & 0xff;
    cleanDecrCode[0x1f] = packStart >> 8;
    cleanDecrCode[0x23] = trnsStart & 0xff;
    cleanDecrCode[0x24] = trnsStart >> 8;
    cleanDecrCode[0xde] = startAdress & 0xff;
    cleanDecrCode[0xdf] = startAdress >> 8;

    target = aTarget->data + 2;
    for(i = 0; i < decrLen; ++i) {
      target[i] = cleanDecrCode[i];
    }

    aTarget->data[0] = 0x01;
    aTarget->data[1] = 0x08;
    break;
  }
  case normalDecr: {
    uint packStart = 0xfffd - packLen;
    uint trnsStart = 0x081e + packLen;
    normalDecrCode[0x1e] = packStart & 0xff;
    normalDecrCode[0x1f] = packStart >> 8;
    normalDecrCode[0x23] = trnsStart & 0xff;
    normalDecrCode[0x24] = trnsStart >> 8;
    normalDecrCode[0xdc] = startAdress & 0xff;
    normalDecrCode[0xdd] = startAdress >> 8;

    target = aTarget->data + 2;
    for(i = 0; i < decrLen; ++i) {
      target[i] = normalDecrCode[i];
    }

    aTarget->data[0] = 0x01;
    aTarget->data[1] = 0x08;
    break;
  }
  case loadInitDecr: {
    uint packStart = 0xfffd - packLen;
    uint trnsStart = 0x086c + packLen;
    loadInitDecrCode[0x55] = packStart & 0xff;
    loadInitDecrCode[0x56] = packStart >> 8;
    loadInitDecrCode[0x5a] = trnsStart & 0xff;
    loadInitDecrCode[0x5b] = trnsStart >> 8;
    loadInitDecrCode[0x110] = startAdress & 0xff;
    loadInitDecrCode[0x111] = startAdress >> 8;

    target = aTarget->data + 2;
    for(i = 0; i < decrLen; ++i) {
      target[i] = loadInitDecrCode[i];
    }

    aTarget->data[0] = 0x01;
    aTarget->data[1] = 0x08;
    break;
  }
  }

  free(ibuf);

  return _true;
}



( run in 1.484 second using v1.01-cache-2.11-cpan-39bf76dae61 )