int allocate(int size) {

    if(size + 1 > 512) {
        return -1;
    }

    int temp,ceil_size, req_free_list,req_free_list_size,start_addr;

    ceil_size = ceil2(size + 1);
    req_free_list = get_free_list(ceil_size);
    req_free_list_size = find_free_list_size(ceil_size);

    if(heap[req_free_list] == -1) {
        temp = split_rec(req_free_list, req_free_list_size, ceil_size, ceil_size);
        if(temp == 0) {
            return -1;
        }
    }

    temp = req_free_list;
    while(temp < req_free_list + req_free_list_size && heap[temp] != -1) {
        temp = temp + 1;
    }

    temp--;
    start_addr = heap[temp];
    heap[temp] = -1;
    heap[start_addr] = size;
    return start_addr;
}
int deallocate(int start_addr) {
    int size = heap[start_addr];
    int ceil_size,current;

    ceil_size = ceil2(size + 1);

    free_block(start_addr,ceil_size);

    merge_buddies(start_addr, ceil_size);
}
Ejemplo n.º 3
0
    UPVISIBLE
    int sparseset_multi_reserve(sparseset<R, N, H, E>& set, allocator* bucket_alloc, size_t num_buckets) {
        num_buckets = (num_buckets && (num_buckets < 8)) ? 8 : ceil2(num_buckets);
        if ((num_buckets < set.size) || (num_buckets == set.num_buckets())) {
            return sparse_success;
        }

        sparseset<R, N, H, E> temp;
        int retval = ::up::sparseset_construct(temp, bucket_alloc, num_buckets, set.hasher(), set.equals());
        if (retval != sparse_success) {
            return retval;
        }

        ::up::sparseset_multi_move(temp, set);
        ::up::sparseset_swap(temp, set);
        return ::up::sparseset_destruct(temp, bucket_alloc, bucket_alloc);
    }
Ejemplo n.º 4
0
// 6B8172:
static void large_scenery_paint_supports(
    paint_session* session, uint8_t direction, uint16_t height, const TileElement* tileElement, uint32_t dword_F4387C,
    rct_large_scenery_tile* tile)
{
    if (tile->flags & LARGE_SCENERY_TILE_FLAG_NO_SUPPORTS)
    {
        return;
    }

    int32_t ax = 0;
    int32_t supportHeight = height;

    if (supportHeight & 0xF)
    {
        supportHeight &= 0xFFFFFFF0;
        ax = 49;
    }

    int32_t supportImageColourFlags = IMAGE_TYPE_REMAP;

    if (dword_F4387C)
    {
        supportImageColourFlags = dword_F4387C;
    }

    wooden_b_supports_paint_setup(session, (direction & 1), ax, supportHeight, supportImageColourFlags, nullptr);

    int32_t clearanceHeight = ceil2(tileElement->clearance_height * 8 + 15, 16);

    if (tile->flags & LARGE_SCENERY_TILE_FLAG_ALLOW_SUPPORTS_ABOVE)
    {
        paint_util_set_segment_support_height(session, SEGMENTS_ALL, clearanceHeight, 0x20);
    }
    else
    {
        paint_util_set_segment_support_height(session, SEGMENTS_ALL, 0xFFFF, 0);
    }

    paint_util_set_general_support_height(session, clearanceHeight, 0x20);
}
Ejemplo n.º 5
0
void processing_init(Processing* p, double fd, double fMin, size_t sampleCount, size_t pointCount) {
    p->fd = fd;
    p->fMin = fMin;
    
    p->targetFrequency = 440;
    p->filter = false;
    
    p->peakFrequency = 440;
    p->peakPhase = 0;
    
    p->signalLength = ceil2((double)sampleCount);
    p->step = 1;
    
    p->subcounter = 0;
    p->subLength = 32;
    p->subSignalReal = malloc(p->subLength * sizeof(*p->subSignalReal));
    p->subSignalImag = malloc(p->subLength * sizeof(*p->subSignalImag));
    p->subSpectrumReal = malloc(p->subLength * sizeof(*p->subSpectrumReal));
    p->subSpectrumImag = malloc(p->subLength * sizeof(*p->subSpectrumImag));
    p->subSpectrum = malloc(p->subLength * sizeof(*p->subSpectrum));
    
    p->pointCount = pointCount;
    p->points = malloc(p->pointCount * sizeof(*p->points));
    
    p->signal = malloc(p->signalLength * sizeof(*p->signal));
    
    p->previewLength = PREVIEW_LENGTH;
    p->preview = malloc(p->previewLength * sizeof(*p->preview));

    memset(p->signal, 0, p->signalLength * sizeof(*p->signal));

    p->real = malloc(p->signalLength * sizeof(*p->real));
    p->imag = malloc(p->signalLength * sizeof(*p->imag));
    
    p->spectrum = malloc(p->signalLength * sizeof(*p->spectrum));
    
    p->fs = vDSP_create_fftsetupD(log2(p->signalLength), kFFTRadix2);
    p->sfs = vDSP_create_fftsetupD(log2(p->subLength), kFFTRadix2);
}
Ejemplo n.º 6
0
/**
 *  rct2: 0x006A2ECC
 *
 * @param supportType (edi)
 * @param special (ax)
 * @param height (dx)
 * @param imageColourFlags (ebp)
 * @param pathEntry (0x00F3EF6C)
 * @param[out] underground (Carry Flag)
 *
 * @return Whether supports were drawn
 */
bool path_a_supports_paint_setup(paint_session * session, sint32 supportType, sint32 special, sint32 height, uint32 imageColourFlags,
                                 rct_footpath_entry * pathEntry, bool * underground)
{
    if (underground != nullptr) {
        *underground = false; // AND
    }

    if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) {
        return false;
    }

    if (!(session->Unk141E9DB & G141E9DB_FLAG_1)) {
        return false;
    }

    uint16 baseHeight = ceil2(session->Support.height, 16);
    sint32 supportLength = height - baseHeight;
    if (supportLength < 0) {
        if (underground != nullptr) *underground = true; // STC
        return false;
    }

    bool hasSupports = false;

    sint16 heightSteps = supportLength / 16;

    if (session->Support.slope & 0x20) {
        //save dx2
        sub_98196C(session, (pathEntry->bridge_image + 48) | imageColourFlags, 0, 0, 32, 32, 0, baseHeight - 2);
        hasSupports = true;
    } else if (session->Support.slope & 0x10) {
        heightSteps -= 2;
        if (heightSteps < 0) {
            if (underground != nullptr) *underground = true; // STC
            return false;
        }

        uint32 imageId = (supportType * 24) + word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + pathEntry->bridge_image;

        sub_98197C(session, imageId | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
        baseHeight += 16;

        sub_98197C(session, (imageId + 4) | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
        baseHeight += 16;

        hasSupports = true;

    } else if (session->Support.slope & 0x0F) {
        heightSteps -= 1;
        if (heightSteps < 0) {
            if (underground != nullptr) *underground = true; // STC
            return false;
        }

        uint32 ebx = (supportType * 24) + word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK] + pathEntry->bridge_image;

        sub_98197C(session, ebx | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);

        hasSupports = true;
        baseHeight += 16;
    }

    while (heightSteps > 0) {
        if (baseHeight & 0x10 || heightSteps == 1 || baseHeight + 16 == session->WaterHeight) {

            uint32 imageId = (supportType * 24) + pathEntry->bridge_image + 23;

            sub_98196C(session, imageId | imageColourFlags, 0, 0, 32, 32, ((heightSteps == 1) ? 7 : 12), baseHeight);
            heightSteps -= 1;
            baseHeight += 16;
            hasSupports = true;
        } else {
            uint32 imageId = (supportType * 24) + pathEntry->bridge_image + 22;

            sub_98196C(session, imageId | imageColourFlags, 0, 0, 32, 32, ((heightSteps == 2) ? 23 : 28), baseHeight);
            heightSteps -= 2;
            baseHeight += 32;
            hasSupports = true;
        }
    }

    if (special != 0) {
        uint16 specialIndex = (special - 1) & 0xFFFF;

        uint32 imageId = pathEntry->bridge_image + 55 + specialIndex;

        unk_supports_desc supportsDesc = byte_98D8D4[specialIndex];
        unk_supports_desc_bound_box boundBox = supportsDesc.bounding_box;

        if (supportsDesc.var_6 == 0 || session->WoodenSupportsPrependTo == nullptr) {
            sub_98197C(
                session, imageId | imageColourFlags, 0, 0, boundBox.length.y, boundBox.length.x, boundBox.length.z, baseHeight,
                boundBox.offset.x, boundBox.offset.y, baseHeight + boundBox.offset.z);
            hasSupports = true;
        } else {
            paint_struct * paintStruct = sub_98198C(
                session, imageId | imageColourFlags, 0, 0, boundBox.length.y, boundBox.length.x, boundBox.length.z, baseHeight,
                boundBox.offset.x, boundBox.offset.y, baseHeight + boundBox.offset.z);
            hasSupports = true;
            if (paintStruct != nullptr) {
                session->WoodenSupportsPrependTo->var_20 = paintStruct;
            }
        }
    }

    if (underground != nullptr) *underground = false; // AND

    return hasSupports;
}
Ejemplo n.º 7
0
/**
 * Wooden supports
 *  rct2: 0x00662D5C
 *
 * @param supportType (edi)
 * @param special (ax)
 * @param height (dx)
 * @param imageColourFlags (ebp)
 * @param[out] underground (Carry Flag)
 *
 * @return (al) whether supports have been drawn
 */
bool wooden_b_supports_paint_setup(paint_session * session, sint32 supportType, sint32 special, sint32 height, uint32 imageColourFlags, bool * underground)
{
    bool _9E32B1 = false;

    if (gCurrentViewportFlags & VIEWPORT_FLAG_INVISIBLE_SUPPORTS) {
        if (underground != nullptr) *underground = false; // AND
        return false;
    }

    if (!(session->Unk141E9DB & G141E9DB_FLAG_1)) {
        if (underground != nullptr) *underground = false; // AND
        return false;
    }

    uint16 baseHeight = ceil2(session->Support.height, 16);
    sint16 supportLength = height - baseHeight;

    if (supportLength < 0) {
        if (underground != nullptr) *underground = true; // STC
        return false;
    }

    sint16 heightSteps = supportLength / 16;

    bool goTo662E8B = false;

    if (session->Support.slope & 0x20) {
        goTo662E8B = true;
    } else if (session->Support.slope & 0x10) {
        heightSteps -= 2;
        if (heightSteps < 0) {
            if (underground != nullptr) *underground = true; // STC
            return false;
        }

        uint32 imageId = WoodenSupportImageIds[supportType].slope;
        if (imageId == 0) {
            baseHeight += 32;
            goTo662E8B = true;
        } else {
            imageId += word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];

            sub_98197C(session, imageId | imageColourFlags, 0, 0, 32, 32, 11, baseHeight, 0, 0, baseHeight + 2);
            baseHeight += 16;

            sub_98197C(session, (imageId + 4) | imageColourFlags, 0, 0, 32, 32, 3, baseHeight, 0, 0, baseHeight + 2);
            baseHeight += 16;

            _9E32B1 = true;
        }
    } else if ((session->Support.slope & 0x0F) != 0) {
        heightSteps -= 1;
        if (heightSteps < 0) {
            if (underground != nullptr) *underground = true; // STC
            return false;
        }

        uint32 imageId = WoodenSupportImageIds[supportType].slope;
        if (imageId == 0) {
            baseHeight += 16;
            goTo662E8B = true;
        } else {
            imageId += word_97B3C4[session->Support.slope & TILE_ELEMENT_SURFACE_SLOPE_MASK];

            sub_98197C(session, imageId | imageColourFlags, 0, 0, 32, 32, 3, baseHeight, 0, 0, baseHeight + 2);
            baseHeight += 16;

            _9E32B1 = true;
        }
    }

    bool skipTo663004 = false;
    if (goTo662E8B) {
        if (heightSteps == 0) {
            skipTo663004 = true;
        } else {
            sub_98196C(session, WoodenSupportImageIds[supportType].flat | imageColourFlags, 0, 0, 32, 32, 0, baseHeight - 2);
            _9E32B1 = true;
        }
    }

    if (!skipTo663004) {
        while (heightSteps > 0) {
            if (baseHeight & 0x10 || heightSteps == 1 || baseHeight + 16 == session->WaterHeight) {
                sub_98196C(
                    session, WoodenSupportImageIds[supportType].half | imageColourFlags, 0, 0, 32, 32,
                    ((heightSteps == 1) ? 7 : 12), baseHeight);
                heightSteps -= 1;
                baseHeight += 16;
                _9E32B1 = true;
            } else {
                sub_98196C(
                    session, WoodenSupportImageIds[supportType].full | imageColourFlags, 0, 0, 32, 32,
                    ((heightSteps == 2) ? 23 : 28), baseHeight);
                heightSteps -= 2;
                baseHeight += 32;
                _9E32B1 = true;
            }
        }
    }

    if (special != 0) {
        uint16 specialIndex = (special - 1) & 0xFFFF;

        uint32 imageId = WoodenCurveSupportImageIds[supportType];
        unk_supports_desc supportsDesc = byte_97B23C[specialIndex];

        if (imageId != 0 && supportsDesc.var_7 != 0) { // byte_97B23C[special].var_7 is never 0
            imageId = (imageId + specialIndex) | imageColourFlags;

            unk_supports_desc_bound_box boundBox = supportsDesc.bounding_box;

            if (supportsDesc.var_6 == 0 || session->WoodenSupportsPrependTo == nullptr) {
                sub_98197C(
                    session, imageId | imageColourFlags, 0, 0, boundBox.length.x, boundBox.length.y, boundBox.length.z,
                    baseHeight, boundBox.offset.x, boundBox.offset.y, boundBox.offset.z + baseHeight);
                _9E32B1 = true;
            } else {
                paint_struct * paintStruct = sub_98198C(
                    session, imageId | imageColourFlags, 0, 0, boundBox.length.x, boundBox.length.y, boundBox.length.z,
                    baseHeight, boundBox.offset.x, boundBox.offset.y, boundBox.offset.z + baseHeight);
                _9E32B1 = true;
                if (paintStruct != nullptr) {
                    session->WoodenSupportsPrependTo->var_20 = paintStruct;
                }
            }
        }
    }

    if (underground != nullptr) *underground = false; // AND
    return _9E32B1;
}
Ejemplo n.º 8
0
void * EFIAPI LoadFile(CHAR16 * name, UINTN memtype, int32_t* filesize)
{
  // ask for the protocol to handle the filesystem
  EFI_GUID EfiSimpleFileSystemGuid = SIMPLE_FILE_SYSTEM_PROTOCOL;
  EFI_FILE_IO_INTERFACE * FSInterface = NULL;
  struct _EFI_FILE_HANDLE * fsroot = NULL;

  EFI_STATUS localteprotocolstat = uefi_call_wrapper(BS->LocateProtocol, 3, &EfiSimpleFileSystemGuid, NULL, &FSInterface);

  if(localteprotocolstat != EFI_SUCCESS)
  {
    Print(L"Failed to locate protocol\n");
  }

  EFI_STATUS openvolumestat = uefi_call_wrapper(FSInterface->OpenVolume, 2, FSInterface, &fsroot);

  if(openvolumestat != EFI_SUCCESS)
  {
    Print(L"FAiled to open the volume\n");
  }

  struct _EFI_FILE_HANDLE * fp = NULL;

  EFI_STATUS openstat = uefi_call_wrapper(fsroot->Open, 5, fsroot, &fp, name, (UINT64)1, (UINT64)1);



  if(openstat != EFI_SUCCESS)
  {
    Print(L"Failed opening the file\n");
  }


  // even if the specification says that asking to open the file with insuficient memory
  // reports the full file size, qemu and virtualbox implementations don't do that
  // as such we need to get manually the file info
  UINTN infosize = 1024;
  EFI_FILE_INFO * info = AllocatePool(infosize);
  EFI_GUID infoguid = EFI_FILE_INFO_ID;

  EFI_STATUS infostatus = uefi_call_wrapper(fp->GetInfo, 4, fp, &infoguid, &infosize, info);

  if(infostatus != EFI_SUCCESS)
  {
    Print(L"Failed to get FileInfo\n");
  } else
  {
    Print(L"FileSize: %d\n", info->FileSize);
  }

  *filesize = info->FileSize;

  UINTN size = info->FileSize;
  void * data = NULL;

  //data = AllocatePool(size);
  //EFI_STATUS allocstatus = uefi_call_wrapper(BS->AllocatePool, 3, EfiLoaderData, size, (void**)&data);
  float pages = (size/1024)/4;

  UINTN ipages = ceil2(pages);
  EFI_PHYSICAL_ADDRESS tmp;

  EFI_STATUS allocstatus = uefi_call_wrapper(BS->AllocatePages, 4, AllocateAnyPages, memtype, ipages, &tmp);

  data = (void*)tmp;

  //data = AllocatePages2(size);

  //if(data == NULL)
  if(allocstatus != EFI_SUCCESS)
  {
    Print(L"Failed to get Kernel memory\n");
  }

  // phoenix lies, must specify the size myself
  uefi_call_wrapper(fp->Read, 3, fp, &size, data);

  Print(L"Read Size: %d\n", size);

  uefi_call_wrapper(fp->Close, 1, fp);

  return data;
}