Beispiel #1
0
void CA_CacheAudioChunk(int chunk)
{
	int pos, length;

	if (w0 == true || w1 == true){
		if (audiosegsWL6[chunk])
			return;	
	} else {
		if (audiosegsSOD[chunk])
			return;	
	}

	pos = audiostarts[chunk];
	length = audiostarts[chunk+1]-pos;

	ReadSeek(audiohandle, pos, SEEK_SET);

	if (w0 == true || w1 == true){
		MM_GetPtr((memptr)&audiosegsWL6[chunk], length);
	} else {
		MM_GetPtr((memptr)&audiosegsSOD[chunk], length);
	}

	if (w0 == true || w1 == true){
		ReadBytes(audiohandle, audiosegsWL6[chunk], length);
	} else {
		ReadBytes(audiohandle, audiosegsSOD[chunk], length);
	}
}
Beispiel #2
0
static void PML_ReadFromFile(byte *buf, long offset, word length)
{
	if (!buf)
		Quit("PML_ReadFromFile: Null pointer");
	if (!offset)
		Quit("PML_ReadFromFile: Zero offset");
	if (ReadSeek(PageFile, offset, SEEK_SET) != offset)
		Quit("PML_ReadFromFile: Seek failed");
	if (ReadBytes(PageFile, buf, length) != length)
		Quit("PML_ReadFromFile: Read failed");
}
Beispiel #3
0
void CA_CacheGrChunk(int chunk)
{
	long pos, compressed;
	byte *source;

	if (grhandle == -1)
		return;
		
	if (w0 == true){
		if (grsegsWL1[chunk]) {
			return;
		}
	}else if (w1 == true){
		if (grsegsWL6[chunk]) {
			return;
		}
	}else if (s0 == true){
		if (grsegsSDM[chunk]) {
			return;
		}
	}else{
		if (grsegsSOD[chunk]) {
			return;
		}
	}

/* load the chunk into a buffer */
	pos = grstarts[chunk];

	compressed = grstarts[chunk+1]-pos;

	ReadSeek(grhandle, pos, SEEK_SET);

	MM_GetPtr((memptr)&source, compressed);
	ReadBytes(grhandle, source, compressed);

	if (w0 == true){
		CAL_ExpandGrChunkWL1(chunk, source);
	} else if (w1 == true){
		CAL_ExpandGrChunkWL6(chunk, source);
	}else if (s0 == true){
		CAL_ExpandGrChunkSDM(chunk, source);
	}else{
		CAL_ExpandGrChunkSOD(chunk, source);
	}
	
	MM_FreePtr((memptr)&source);
}
Beispiel #4
0
void CA_CacheMap(int mapnum)
{
	long pos,compressed;
	int plane;
	byte *source;
	memptr buffer2seg;
	long expanded;

	mapon = mapnum;

/* load the planes into the already allocated buffers */

	for (plane = 0; plane < MAPPLANES; plane++)
	{
		pos = mapheaderseg[mapnum]->planestart[plane];
		compressed = mapheaderseg[mapnum]->planelength[plane];

		ReadSeek(maphandle, pos, SEEK_SET);

		MM_GetPtr((void *)&source, compressed);

		ReadBytes(maphandle, (byte *)source, compressed);

		expanded = source[0] | (source[1] << 8);
		MM_GetPtr(&buffer2seg, expanded);

/* NOTE: CarmackExpand implicitly fixes endianness, a RLEW'd only map
         would (likely) need to be swapped in CA_RLEWexpand
         
         Wolfenstein 3D/Spear of Destiny maps are always Carmack'd so this
         case is OK.  CA_RLEWexpand would need to be adjusted for Blake Stone
         and the like.
*/         		
		CAL_CarmackExpand(source+2, (word *)buffer2seg, expanded);
		MM_FreePtr((void *)&source);

		expanded = 64*64*2;
		CA_RLEWexpand(((word *)buffer2seg)+1, mapsegs[plane], expanded, RLEWtag);
		MM_FreePtr(&buffer2seg);
	}
}
Beispiel #5
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 {
Beispiel #6
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;
}
Beispiel #7
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;
}
Beispiel #8
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);
	}
}