initheap.c 1.45 KB
/*
=============================================================================
        Copyright (C) 1997-1999 NINTENDO Co.,Ltd.
        
        $RCSfile: initheap.c,v $
        $Revision: 1.1.1.1 $
        $Date: 2002/10/30 02:07:09 $
=============================================================================
関数名:InitHeap
-----------------------------------------------------------------------------
書式:  #include <malloc.h>
        int InitHeap(void *head, unsigned int  size);
引数:  head 領域確保の先頭ポインタ
        size 領域のサイズ
戻り値:正常に確保出来れば0を、確保に失敗すれば−1を返す。
説明:  メモリ割り当て領域確保と初期化を行う。
-----------------------------------------------------------------------------
*/
#include    <ultra64.h>
#include    "string.h"
#include    "malloc.h"
#include    "_malloc.h"

char    *malloc_ptr = (char *)-1;

void *_InitHeap(void *ptr, unsigned int size)
{
    unsigned int    p;
    struct mallocST *malloc_st_ptr;

    if (size < 0x20)    return  (void *)-1;

    p = (unsigned int)ptr;
    p += 15;
    p &= (~15);
    size -= p - (unsigned int)(ptr);
    malloc_st_ptr = (struct mallocST *)p;
    malloc_st_ptr->next = 0;
    malloc_st_ptr->size = size - MALLOC_HEADSIZE;
    malloc_st_ptr->flag = 0;
    malloc_st_ptr->allsize = size;
    return  malloc_st_ptr;
}

int InitHeap(void *head, unsigned int  size)
{
    malloc_ptr = _InitHeap(head, size);
    if ((int)malloc_ptr == -1)  return  -1;
    return  0;
}