diff --git a/anotherplan.c b/anotherplan.c index 839cddd..c4b1ead 100644 --- a/anotherplan.c +++ b/anotherplan.c @@ -6,6 +6,7 @@ enum { framerate = 60, + framems = 20, Kdel = 0x7f }; @@ -39,7 +40,6 @@ void main(void) int child = rfork(RFPROC|RFMEM); if (child) { - vlong framems = 1000LL / framerate; vlong startms = nsec()/1000000LL; for(;;) { changeState(); diff --git a/anotherplan_tests.c b/anotherplan_tests.c index 2f4e78a..eef81e1 100644 --- a/anotherplan_tests.c +++ b/anotherplan_tests.c @@ -4,6 +4,20 @@ void main(void) { + /* setup */ + allocmemblock(); + print("alloc'd mem buffer:\n"); + printmemptrs(); + print("loading mem list:\n"); loadmemlist("assets/MEMLIST.BIN"); + + /* run */ + print("\nrunning!\n\n"); + + /* teardown */ + freememblock(); + print("freed mem buffer:\n"); + printmemptrs(); + exits(nil); } \ No newline at end of file diff --git a/memlist.c b/memlist.c index eb5ce42..8644a64 100644 --- a/memlist.c +++ b/memlist.c @@ -64,4 +64,36 @@ loadmemlist(char *filename) close(fd); } free(bankmap); -} \ No newline at end of file +} + +void +allocmemblock(void) +{ + _memPtrStart = malloc(MEM_BLOCK_SIZE); + _scriptBakPtr = _scriptCurPtr = _memPtrStart; + _vidBakPtr = _vidCurPtr = _memPtrStart + MEM_BLOCK_SIZE - 0x800 * 16; + if ( _memPtrStart == nil ) { + exits("could not alloc mem block."); + } +} + +void +freememblock(void) +{ + if ( _memPtrStart != nil ) { + free(_memPtrStart); + } + _memPtrStart = nil; + _scriptBakPtr = _scriptCurPtr = nil; + _vidBakPtr = _vidCurPtr = nil; +} + +void +printmemptrs(void) +{ + print("_memPtrStart: 0x%08p\n", _memPtrStart); + print("_scriptBakPtr: 0x%08p\n", _scriptBakPtr); + print("_scriptCurPtr: 0x%08p\n", _scriptCurPtr); + print("_vidBakPtr: 0x%08p\n", _vidBakPtr); + print("_vidCurPtr: 0x%08p\n", _vidCurPtr); +} diff --git a/memlist.h b/memlist.h index d4f1c11..866b1de 100644 --- a/memlist.h +++ b/memlist.h @@ -1,6 +1,10 @@ #ifndef MEMLIST_H #define MEMLIST_H +enum { + MEM_BLOCK_SIZE = 600 * 1024, /* 600 kB */ +}; + typedef enum AssetState_t { ASSET_NOT_NEEDED = 0, ASSET_LOADED = 1, @@ -28,5 +32,11 @@ typedef struct Asset_t { ushort length; } Asset; +uchar *_memPtrStart, *_scriptBakPtr, *_scriptCurPtr, *_vidBakPtr, *_vidCurPtr = nil; + void loadmemlist(char *filename); +void allocmemblock(void); +void freememblock(void); +void printmemptrs(void); + #endif /* MEMLIST_H */ \ No newline at end of file