- // search an unused chunk that is big enough until the end of the heap
- while ((dsize > csize || cstat==0) && chunk < heap_end ) {
- chunk = (u32*)((uptr)chunk + csize + 4);
-
- // catch out of memory
- if(chunk >= heap_end) {
- printf("malloc %x,%x: Out of memory error!\n",
- v0, a0);
- v0 = 0; pc0 = ra;
- return;
- }
-
- csize = ((u32)*chunk) & 0xfffffffc;
- cstat = ((u32)*chunk) & 1;
- }
-
- // allocate memory
- if(dsize == csize) {
- // chunk has same size
- *chunk &= 0xfffffffc;
- } else if (dsize > csize) {
- v0 = 0; pc0 = ra;
- return;
- } else {
- // split free chunk
- *chunk = SWAP32(dsize);
- newchunk = (u32*)((uptr)chunk + dsize + 4);
- *newchunk = SWAP32(((csize - dsize - 4) & 0xfffffffc) | 1);
- }
-
- // return pointer to allocated memory
- v0 = ((uptr)chunk - (uptr)psxM) + 4;
- v0|= 0x80000000;
- //printf ("malloc %x,%x\n", v0, a0);
- pc0 = ra;
+ PSXBIOS_LOG(" -> %08x\n", ret);
+ mips_return_c(ret, 40);