9bba42f7bef7ea0cd0edabd931b0df97b627cc3b
[gbajam22] / src / util.c
1 #include "util.h"
2 #include "debug.h"
3
4 extern char __iheap_start;
5 static char *top = &__iheap_start;
6
7 int iwram_brk(void *addr)
8 {
9         if((char*)addr < &__iheap_start) {
10                 addr = &__iheap_start;
11         }
12         if(addr > get_sp()) {
13                 /*return -1;*/
14                 panic(get_pc(), "iwram_brk (%p) >= sp", addr);
15         }
16         top = addr;
17         return 0;
18 }
19
20 void *iwram_sbrk(intptr_t delta)
21 {
22         void *prev = top;
23         iwram_brk(top + delta);
24         return prev;
25 }