home *** CD-ROM | disk | FTP | other *** search
- extern struct ExecBase * SysBase;
-
- static __inline void*
- AllocVec (unsigned long byteSize,unsigned long requirements)
- {
- register void *_res __asm("d0");
- register struct ExecBase *a6 __asm("a6") = SysBase;
- register unsigned long d0 __asm("d0") = byteSize;
- register unsigned long d1 __asm("d1") = requirements;
- __asm __volatile ("jsr a6@(-0x2ac)"
- : "=r" (_res)
- : "r" (a6), "r" (d0), "r" (d1)
- : "a0","a1","d0","d1", "memory");
- return _res;
- }
-
- static __inline void
- FreeVec (void *memoryBlock)
- {
- register struct ExecBase *a6 __asm("a6") = SysBase;
- register void *a1 __asm("a1") = memoryBlock;
- __asm __volatile ("jsr a6@(-0x2b2)"
- : /* no output */
- : "r" (a6), "r" (a1)
- : "a0","a1","d0","d1", "memory");
- }
-
- static __inline void
- CopyMem (void *source,void *dest,unsigned long size)
- {
- register struct ExecBase *a6 __asm("a6") = SysBase;
- register void *a0 __asm("a0") = source;
- register void *a1 __asm("a1") = dest;
- register unsigned long d0 __asm("d0") = size;
- __asm __volatile ("jsr a6@(-0x270)"
- : /* no output */
- : "r" (a6), "r" (a0), "r" (a1), "r" (d0)
- : "a0","a1","d0","d1", "memory");
- }
-
- void *malloc(unsigned long Anz);
- void free(unsigned long *p);
-
-
- void *realloc(unsigned long *ptr, unsigned long size)
- {
- /* Free memory */
- if(size==0)
- {
- if(ptr) free(ptr);
- return 0;
- }
- else
- if(ptr)
- {
- /* now we are in trouble. We depend on how the length of the memory-Block
- is stored by AllocVec: in the longword before ptr the length of the
- memory-Block (with the len-long)*/
-
- char *new_ptr=0;
- unsigned long old_len=*(ptr-1)-4;
-
- if((new_ptr=malloc(size)))
- {
- if(size > old_len) size=old_len; /* don't copy more than the old size */
- CopyMem(ptr, new_ptr, size);
- free(ptr);
-
- return new_ptr;
- }
- else
- return 0;
- }
- else
- {
- /* behave like normal malloc */
- return malloc(size);
- }
- }