A C implementation of the Another World VM written for Plan 9.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
anotherplan/memlist.c

99 lines
2.5 KiB

#include <u.h>
#include <libc.h>
#include <bio.h>
#include <mach.h>
#include "memlist.h"
enum {
_memlistsize = 150,
};
static Asset _memlist[_memlistsize] = {0};
void
loadmemlist(char *filename)
{
int fd = open(filename, OREAD);
if ( !fd ) {
exits("couldn't open the file!");
}
Dir *filestats = dirfstat(fd);
if ( filestats == nil ) {
exits("couldn't fstat the file!");
}
vlong filesize = filestats->length;
print("\"%s\" has size %lld.\n", filename, filesize);
free(filestats);
if ( !machbyname("68020") ) {
exits("libmach doesn't support \"68020\" architecture.");
}
Map *bankmap = newmap(nil, 1);
if (bankmap == nil) {
exits("couldn't allocate a new map.");
}
setmap(bankmap, fd, 0, filesize, 0, "memlist");
uvlong offset = 0;
uvlong totalbanksize = 0;
uvlong compressedbanksize = 0;
uint assetno;
for ( assetno = 0; assetno < _memlistsize; assetno++ ) {
Asset *readasset = &_memlist[assetno];
if ( offset + 20 > filesize ) {
break;
}
get1(bankmap, offset, (uchar*) &readasset->state, 1); offset += 1;
get1(bankmap, offset, (uchar*) &readasset->type, 1); offset += 1; offset += 4;
get1(bankmap, offset, (uchar*) &readasset->rank, 1); offset += 1;
get1(bankmap, offset, (uchar*) &readasset->bank, 1); offset += 1;
get4(bankmap, offset, (ulong*) &readasset->bankoffset ); offset += 4; offset += 2;
get2(bankmap, offset, (ushort*) &readasset->packedlength); offset += 2; offset += 2;
get2(bankmap, offset, (ushort*) &readasset->length ); offset += 2;
totalbanksize += readasset->length;
compressedbanksize += readasset->packedlength;
if ( readasset->state == ASSET_END ) {
break;
}
}
print("Read %d assets!\n", assetno);
print("Total size: %lld. Compressed size: %lld.\n", totalbanksize, compressedbanksize);
if (fd) {
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);
}