Ejemplo n.º 1
0
static void PML_ClosePageFile()
{
	if (PageFile != -1)
		CloseRead(PageFile);
		
	if (PMPages) {
		int i;
		
		for (i = 0; i < ChunksInFile; i++) {
			PageListStruct *page;
			
			page = &PMPages[i];
			if (page->addr != NULL) {
				MM_FreePtr((memptr)&page->addr);
			}
		}
		
		MM_SetLock((memptr)&PMPages,false);
		MM_FreePtr((memptr)&PMPages);
	}
}
Ejemplo n.º 2
0
 void Close()
 {
   CloseRead();
   CloseWrite();
 }
Ejemplo n.º 3
0
myint SaveTheGame(const char *fn, const char *tag, myint dx, myint dy)
{
	objtype *ob;
	myint fd, i, x, y;
	int32_t cs;
	
	fd = OpenWrite(fn);
	
	if (fd != -1) {
		WriteBytes(fd, (byte *)GAMEHDR, 8);
		WriteBytes(fd, (byte *)SAVTYPE, 4);
		WriteInt32(fd, 0x00000000); /* write version */
		WriteBytes(fd, (byte *)GAMETYPE, 4);
	
		WriteInt32(fd, time(NULL));
		WriteInt32(fd, 0x00000000);
	
		WriteInt32(fd, 0x00000000); /* write checksum (placeholder) */
	
		WriteBytes(fd, (byte *)tag, 32); /* write savegame name */
	
		DiskFlopAnim(dx, dy);
	
		WriteInt32(fd, gamestate_difficulty);
		WriteInt32(fd, gamestate.mapon);
		WriteInt32(fd, gamestate.oldscore);
		WriteInt32(fd, gamestate.score);
		WriteInt32(fd, gamestate.nextextra);
		WriteInt32(fd, gamestate.lives);
		WriteInt32(fd, gamestate.health);
		WriteInt32(fd, gamestate.ammo);
		WriteInt32(fd, gamestate.keys);
		WriteInt32(fd, gamestate.bestweapon);
		WriteInt32(fd, gamestate.weapon);
		WriteInt32(fd, gamestate.chosenweapon);
		WriteInt32(fd, gamestate.faceframe);
		WriteInt32(fd, gamestate.attackframe);
		WriteInt32(fd, gamestate.attackcount);
		WriteInt32(fd, gamestate.weaponframe);
		WriteInt32(fd, gamestate_episode);
		WriteInt32(fd, gamestate.secretcount);
		WriteInt32(fd, gamestate.treasurecount);
		WriteInt32(fd, gamestate.killcount);
		WriteInt32(fd, gamestate.secrettotal);
		WriteInt32(fd, gamestate.treasuretotal);
		WriteInt32(fd, gamestate.killtotal);
		WriteInt32(fd, gamestate.TimeCount);
		WriteInt32(fd, gamestate.killx);
		WriteInt32(fd, gamestate.killy);
		WriteInt8(fd, gamestate.victoryflag);
	
		DiskFlopAnim(dx, dy);
	
#ifdef SPEAR
		for (i = 0; i < 20; i++) {
#else
		for (i = 0; i < 8; i++) {
#endif
			WriteInt32(fd, LevelRatios[i].kill);
			WriteInt32(fd, LevelRatios[i].secret);
			WriteInt32(fd, LevelRatios[i].treasure);
			WriteInt32(fd, LevelRatios[i].time);
		}
	
		DiskFlopAnim(dx, dy);
	
		WriteBytes(fd, (byte *)tilemap, 64*64); /* MAPSIZE * MAPSIZE */
	
		DiskFlopAnim(dx, dy);
	
		for (x = 0; x < 64; x++)
			for (y = 0; y < 64; y++)
				WriteInt32(fd, actorat[x][y]);
	
		DiskFlopAnim(dx, dy);
			
		WriteBytes(fd, (byte *)&areabyplayer, 8);
	
		for (ob = player; ob; ob = obj_next(ob)) {
			DiskFlopAnim(dx, dy);
			
			WriteInt32(fd, obj_id(ob));
			WriteInt32(fd, ob->active);
			WriteInt32(fd, ob->ticcount);
			WriteInt32(fd, ob->obclass);
			WriteInt32(fd, ob->state);
			WriteInt8(fd,  ob->flags);
			WriteInt32(fd, ob->distance);
			WriteInt32(fd, ob->dir);
			WriteInt32(fd, ob->x);
			WriteInt32(fd, ob->y);
			WriteInt32(fd, ob->tilex);
			WriteInt32(fd, ob->tiley);
			WriteInt8(fd,  ob->areanumber);
			WriteInt32(fd, ob->viewx);
			WriteInt32(fd, ob->viewheight);
			WriteInt32(fd, ob->transx);
			WriteInt32(fd, ob->transy);
			WriteInt32(fd, ob->angle);
			WriteInt32(fd, ob->hitpoints);
			WriteInt32(fd, ob->speed);
			WriteInt32(fd, ob->temp1);
			WriteInt32(fd, ob->temp2);
			//WriteInt32(fd, ob->temp3);
		}	
		
		WriteInt32(fd, 0xFFFFFFFF); /* end of actor list */
		
		DiskFlopAnim(dx, dy);
		
		WriteInt32(fd, laststatobj - statobjlist); /* ptr offset */

		for (i = 0; i < 400; i++) { /* MAXSTATS */
			WriteInt8(fd,  statobjlist[i].tilex);
			WriteInt8(fd,  statobjlist[i].tiley);
			WriteInt32(fd, statobjlist[i].shapenum);
			WriteInt8(fd,  statobjlist[i].is_bonus);
			WriteInt8(fd,  statobjlist[i].itemnumber);
		}
	
		DiskFlopAnim(dx, dy);
	
		for (i = 0; i < 64; i++) { /* MAXDOORS */
			WriteInt32(fd, doorposition[i]);
		}
	
		DiskFlopAnim(dx, dy);
	
		for (i = 0; i < 64; i++) { /* MAXDOORS */
			WriteInt8(fd,  doorobjlist[i].tilex);
			WriteInt8(fd,  doorobjlist[i].tiley);
			WriteInt8(fd,  doorobjlist[i].vertical);
			WriteInt8(fd,  doorobjlist[i].lock);
			WriteInt8(fd,  doorobjlist[i].action);
			WriteInt32(fd, doorobjlist[i].ticcount);
		}
	
		DiskFlopAnim(dx, dy);
	
		WriteInt32(fd, pwallstate);
		WriteInt32(fd, pwallx);
		WriteInt32(fd, pwally);
		WriteInt32(fd, pwalldir);
		WriteInt32(fd, pwallpos);

		DiskFlopAnim(dx, dy);

		CloseWrite(fd);

		fd = OpenRead(fn);
		ReadSeek(fd, 64, SEEK_SET);
		cs = CalcFileChecksum(fd, ReadLength(fd) - 64);
		CloseRead(fd);
		
		fd = OpenWriteAppend(fn);
		WriteSeek(fd, 28, SEEK_SET);
		WriteInt32(fd, cs);
		
		CloseWrite(fd);
	} else {
Ejemplo n.º 4
0
myint ReadConfig()
{
#ifndef EMBEDDED
	myint fd, configokay;
	char buf[8];
	int32_t version, v;
#ifdef ENABLE_CONTROLS
	myint i;
#endif
	
	configokay = 0;
	
	fd = OpenRead(configname);
	
	if (fd != -1) {
		SetDefaults();
		
		ReadBytes(fd, (byte *)buf, 8);
		if (strncmp(buf, GAMEHDR, 8))
			goto configend;
		
		ReadBytes(fd, (byte *)buf, 4);
		if (strncmp(buf, CFGTYPE, 4))
			goto configend;
		
		version = ReadInt32(fd);
		if (version != 0xFFFFFFFF && version != 0x00000000)
			goto configend;
		
		ReadBytes(fd, (byte *)buf, 4);
		if (strncmp(buf, GAMETYPE, 4))
			goto configend;
		
		ReadInt32(fd);	/* skip over time */
		ReadInt32(fd);	/* skip over padding */
		
		v = ReadInt32(fd);	/* get checksum */
		if (v != CalcFileChecksum(fd, ReadLength(fd) - 32))
			goto configend;
		
		ReadSeek(fd, 32, SEEK_SET);
		
#ifdef ENABLE_HIGHSCORES
		for (i = 0; i < 7; i++) { /* MaxScores = 7 */
			ReadBytes(fd, (byte *)Scores[i].name, 58);
			Scores[i].score = ReadInt32(fd);
			Scores[i].completed = ReadInt32(fd);
			Scores[i].episode = ReadInt32(fd);
		}
#endif
		
		viewsize = ReadInt32(fd);
		
		/* load the new data */
		if (version == 0x00000000) {
			/* sound config, etc. */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			
#ifdef ENABLE_CONTROLS
			/* direction keys */	
			for (i = 0; i < 4; i++) {
				dirscan[i] = ReadInt32(fd);
			}
			
			/* other game keys */
			for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */
				buttonscan[i] = ReadInt32(fd);
			}
			
			/* mouse enabled */
			mouseenabled = ReadInt8(fd);
			
			/* mouse buttons */
			for (i = 0; i < 4; i++) {
				buttonmouse[i] = ReadInt32(fd);
			}
#endif
			
			/* mouse adjustment */
			mouseadjustment = ReadInt32(fd);
			
			/* unimplemented joystick */
			v = ReadInt32(fd);
			if (v != 0xFFFFFFFF) {
			}
		}
#ifndef EMBEDDED
#ifdef UPLOAD		
		MainMenu[readthis].active = 1;
		MainItems.curpos = 0;
#endif
#endif

		configokay = 1;
	} 
	
configend:	
	
	if (fd != -1)
		CloseRead(fd);
	
	if (!configokay) {
		SetDefaults();
	}
#else
	SetDefaults();
#endif
	
	return 0;
}
Ejemplo n.º 5
0
myint WriteConfig()
{
#ifndef EMBEDDED
#ifdef ENABLE_CONTROLS
	myint i;
#endif
	myint fd;
	int32_t cs;
	
	fd = OpenWrite(configname);
	
	if (fd != -1) {
		WriteBytes(fd, (byte *)GAMEHDR, 8);	/* WOLF3D, 0, 0 */
		WriteBytes(fd, (byte *)CFGTYPE, 4);	/* CFG, 0 */
		WriteInt32(fd, 0x00000000);		/* Version (integer) */
		WriteBytes(fd, (byte *)GAMETYPE, 4);	/* XXX, 0 */
		WriteInt32(fd, time(NULL));		/* Time */
		WriteInt32(fd, 0x00000000);		/* Padding */
		WriteInt32(fd, 0x00000000);		/* Checksum (placeholder) */
	
#ifdef ENABLE_HIGHSCORES
		for (i = 0; i < 7; i++) { /* MaxScores = 7 */
			WriteBytes(fd, (byte *)Scores[i].name, 58);
			WriteInt32(fd, Scores[i].score);
			WriteInt32(fd, Scores[i].completed);
			WriteInt32(fd, Scores[i].episode);
		}
#endif
		
		WriteInt32(fd, viewsize);

		/* sound config, etc. (to be done) */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
		WriteInt32(fd, 0); /* padding */
			
#ifdef ENABLE_CONTROLS
		/* direction keys */	
		for (i = 0; i < 4; i++) {
			WriteInt32(fd, dirscan[i]);
		}
			
		/* other game keys */
		for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */
			WriteInt32(fd, buttonscan[i]);
		}
			
		/* mouse enabled */
		WriteInt8(fd, mouseenabled);
			
		/* mouse buttons */
		for (i = 0; i < 4; i++) {
			WriteInt32(fd, buttonmouse[i]);
		}
#endif
			
		/* mouse adjustment */
		WriteInt32(fd, mouseadjustment);
			
		/* joystick (to be done) */
		WriteInt32(fd, -1);

		CloseWrite(fd);
		
		fd = OpenRead(configname);
		ReadSeek(fd, 32, SEEK_SET);
		cs = CalcFileChecksum(fd, ReadLength(fd) - 32);
		CloseRead(fd);
		
		fd = OpenWriteAppend(configname);
		WriteSeek(fd, 28, SEEK_SET);
		WriteInt32(fd, cs);
		
		CloseWrite(fd);
	}
	
#endif
	return 0;
}
Ejemplo n.º 6
0
void CA_Shutdown()
{
	CloseRead(maphandle);
	CloseRead(grhandle);
	CloseRead(audiohandle);
}
Ejemplo n.º 7
0
static void CAL_SetupMapFile()
{
	int i;
	int handle;
	long pos;
	char fname[13];
	
	strcpy(fname, mheadname);
	if (w0 == true || w1 == true || s0 == true || s1 == true){
		strcat(fname, extension);
	}else{
		strcat(fname, extension2);
	}

	handle = OpenRead(fname);
	if (handle == -1)
		CA_CannotOpen(fname);

	RLEWtag = ReadInt16(handle);

/* open the data file */
	strcpy(fname, gmapsname);
	if (w0 == true || w1 == true || s0 == true || s1 == true){
		strcat(fname, extension);
	}else{
		strcat(fname, extension2);
	}

	maphandle = OpenRead(fname);
	if (maphandle == -1)
		CA_CannotOpen(fname);

/* load all map header */
	for (i = 0; i < NUMMAPS; i++)
	{
		pos = ReadInt32(handle);
		if (pos == 0) {
			mapheaderseg[i] = NULL;
			continue;
		}
			
		MM_GetPtr((memptr)&mapheaderseg[i], sizeof(maptype));
		MM_SetLock((memptr)&mapheaderseg[i], true);

		ReadSeek(maphandle, pos, SEEK_SET);
		
		mapheaderseg[i]->planestart[0] = ReadInt32(maphandle);
		mapheaderseg[i]->planestart[1] = ReadInt32(maphandle);
		mapheaderseg[i]->planestart[2] = ReadInt32(maphandle);
		
		mapheaderseg[i]->planelength[0] = ReadInt16(maphandle);
		mapheaderseg[i]->planelength[1] = ReadInt16(maphandle);
		mapheaderseg[i]->planelength[2] = ReadInt16(maphandle);
		mapheaderseg[i]->width = ReadInt16(maphandle);
		mapheaderseg[i]->height = ReadInt16(maphandle);
		ReadBytes(maphandle, (byte *)mapheaderseg[i]->name, 16);		
	}

	CloseRead(handle);
	
/* allocate space for 2 64*64 planes */
	for (i = 0;i < MAPPLANES; i++) {
		MM_GetPtr((memptr)&mapsegs[i], 64*64*2);
		MM_SetLock((memptr)&mapsegs[i], true);
	}
}
Ejemplo n.º 8
0
static void CAL_SetupGrFile()
{
	char fname[13];
	int handle;
	byte *grtemp;
	int i;

/* load vgadict.ext (huffman dictionary for graphics files) */
	strcpy(fname, gdictname);
	strcat(fname, extension);

	handle = OpenRead(fname);
	if (handle == -1)
		CA_CannotOpen(fname);

	for (i = 0; i < 256; i++) {
		grhuffman[i].bit0 = ReadInt16(handle);
		grhuffman[i].bit1 = ReadInt16(handle);
	}
	
	CloseRead(handle);
	
/* load the data offsets from vgahead.ext */
	if (w0 == true){
		MM_GetPtr((memptr)&grstarts, (NUMCHUNKSWL1+1)*4);
		MM_GetPtr((memptr)&grtemp, (NUMCHUNKSWL1+1)*3);
	}else if (w1 == true){
		MM_GetPtr((memptr)&grstarts, (NUMCHUNKSWL6+1)*4);
		MM_GetPtr((memptr)&grtemp, (NUMCHUNKSWL6+1)*3);
	}else if (s0 == true){
		MM_GetPtr((memptr)&grstarts, (NUMCHUNKSSDM+1)*4);
		MM_GetPtr((memptr)&grtemp, (NUMCHUNKSSDM+1)*3);
	}else{
		MM_GetPtr((memptr)&grstarts, (NUMCHUNKSSOD+1)*4);
		MM_GetPtr((memptr)&grtemp, (NUMCHUNKSSOD+1)*3);
	}
	
	strcpy(fname, gheadname);
	strcat(fname, extension);

	handle = OpenRead(fname);
	if (handle == -1)
		CA_CannotOpen(fname);
	if (w0 == true){
		ReadBytes(handle, grtemp, (NUMCHUNKSWL1+1)*3);
	
		for (i = 0; i < NUMCHUNKSWL1+1; i++)
			grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16);
	}else if (w1 == true){
		ReadBytes(handle, grtemp, (NUMCHUNKSWL6+1)*3);
	
		for (i = 0; i < NUMCHUNKSWL6+1; i++)
			grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16);
	}else if (s0 == true){
		ReadBytes(handle, grtemp, (NUMCHUNKSSDM+1)*3);
	
		for (i = 0; i < NUMCHUNKSSDM+1; i++)
			grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16);
	}else{
		ReadBytes(handle, grtemp, (NUMCHUNKSSOD+1)*3);
	
		for (i = 0; i < NUMCHUNKSSOD+1; i++)
			grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16);
	}

	MM_FreePtr((memptr)&grtemp);
	
	CloseRead(handle);
	
/* Open the graphics file, leaving it open until the game is finished */
	strcpy(fname, gfilename);
	strcat(fname, extension);

	grhandle = OpenRead(fname);
	if (grhandle == -1)
		CA_CannotOpen(fname);

/* load the pic headers into pictable */
	CA_CacheGrChunk(STRUCTPIC);

	if (w0 == true){
		grtemp = grsegsWL1[STRUCTPIC];
		for (i = 0; i < NUMPICSWL1; i++) {
			pictableWL1[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8);
			pictableWL1[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8);
		}
	}else if (w1 == true){
		grtemp = grsegsWL6[STRUCTPIC];
		for (i = 0; i < NUMPICSWL6; i++) {
			pictableWL6[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8);
			pictableWL6[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8);
		}
	}else if (s0 == true){
		grtemp = grsegsSDM[STRUCTPIC];
		for (i = 0; i < NUMPICSSDM; i++) {
			pictableSDM[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8);
			pictableSDM[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8);
		}
	}else{
		grtemp = grsegsSOD[STRUCTPIC];
		for (i = 0; i < NUMPICSSOD; i++) {
			pictableSOD[i].width = grtemp[i*4+0] | (grtemp[i*4+1] << 8);
			pictableSOD[i].height = grtemp[i*4+2] | (grtemp[i*4+3] << 8);
		}
	}

	CA_UnCacheGrChunk(STRUCTPIC);
}