Setup mem pointers in memlist.c/.h.

This commit is contained in:
kvothe. 2020-08-29 11:57:06 -04:00
parent 1df87210a6
commit 4f5f96ebde
4 changed files with 58 additions and 2 deletions

View File

@ -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();

View File

@ -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);
}

View File

@ -64,4 +64,36 @@ loadmemlist(char *filename)
close(fd);
}
free(bankmap);
}
}
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);
}

View File

@ -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 */