Esempio n. 1
0
void
DemoLoop_New (void)
{
	//id0_char_t		*s;
	//id0_word_t		move;
	//id0_longword_t	lasttime;
	// REFKEEN - Add FakeCGA shape for 2015 port
	const id0_char_t *FileName0;
	struct Shape FileShape0;
	const id0_char_t *FileName1;
	struct Shape FileShape1;
	// REFKEEN - CREDITS is now a variable, set based on version
//#if CREDITS
	const id0_char_t *FileName2;
	struct Shape FileShape2;
	// REFKEEN - Add second credits shape for 2015 port
	const id0_char_t *FileName3;
	struct Shape FileShape3;
//#endif
	//struct ffblk ffblk;
	//WindowRec	mywin;
	id0_int_t bufsave	= bufferofs;
	id0_int_t dissave	= displayofs;


#if FRILLS
//
// check for launch from ted
//
	if (tedlevel)
	{
		NewGame();
		gamestate.mapon = tedlevelnum;
		GameLoop();
		TEDDeath();
	}
#endif

//
// demo loop
//
	// REFKEEN - Alternative controllers support
	BE_ST_AltControlScheme_Push();
	BE_ST_AltControlScheme_PrepareControllerMapping(&g_ingame_altcontrol_mapping_demoloop);

	US_SetLoadSaveHooks(LoadGame,SaveGame,ResetGame);
	restartgame = gd_Continue;

	BE_FILE_T handle = BE_Cross_open_readonly_for_reading("KDREAMS.CMP");
	//int handle = open("KDREAMS.CMP" ,O_BINARY | O_RDONLY);
	if (!BE_Cross_IsFileValid(handle))
	//if (handle == -1)
		Quit("Couldn't find KDREAMS.CMP");
	BE_Cross_close(handle);
#if 0
	if (findfirst("KDREAMS.CMP", &ffblk, 0) == -1)
		Quit("Couldn't find KDREAMS.CMP");
#endif

	while (true)
	{

		loadedgame = false;

		if (refkeen_current_gamever == BE_GAMEVER_KDREAMS2015)
		{
			FileName0 = "TITLECGA.LBM";
			if (LoadLIBShape("KDREAMS.CMP", FileName0, &FileShape0))
				Quit("Can't load TITLE SCREEN");
		}
		FileName1 = "TITLESCR.LBM";
		if (LoadLIBShape("KDREAMS.CMP", FileName1, &FileShape1))
			Quit("Can't load TITLE SCREEN");
		if (CREDITS)
		{
			// REFKEEN - Instead of loading just "CREDITS.LBM"
			// (which never happened with the original EXEs in practice),
			// load "CREDITS1.LBM" and "CREDITS2.LBM", as available
			// in the 2015 release
			FileName2 = "CREDITS1.LBM";
			if (LoadLIBShape("KDREAMS.CMP", FileName2, &FileShape2))
				Quit("Can't load CREDITS SCREEN 1");
			if (refkeen_current_gamever == BE_GAMEVER_KDREAMS2015)
			FileName3 = "CREDITS2.LBM";
			if (LoadLIBShape("KDREAMS.CMP", FileName3, &FileShape3))
				Quit("Can't load CREDITS SCREEN 3");
		}

		while (!restartgame && !loadedgame)
		{

			VW_InitDoubleBuffer();
			IN_ClearKeysDown();

			while (true)
			{

				// REFKEEN - We're in an EGA-only function anyway,
				// so use EGA versions of VW functions...
				VW_SetScreen_EGA(0, 0);
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(fakecgamode ? &FileShape0 : &FileShape1, 0, 0);
				VW_ScreenToScreen_EGA (64*200,0,40,200);

				if (IN_UserInput(CREDITS ? (TickBase * 8) : (TickBase * 4), false))
					break;

		// REFKEEN - Patch for 2015 port
		if (!fakecgamode)
		{
			if (CREDITS)
			{
				// REFKEEN - Show two credits screens
				// as present in the 2015 release
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape2, 0, 0);
				VW_ScreenToScreen_EGA (64*200,0,40,200);

				if (IN_UserInput(TickBase * 7, false))
					break;

				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape3, 0, 0);
				VW_ScreenToScreen_EGA (64*200,0,40,200);

				if (IN_UserInput(TickBase * 7, false))
					break;
			}
			else
			{
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape1, 0, 0);
				VW_ScreenToScreen_EGA (64*200,0,40,200);

				if (IN_UserInput(TickBase * 3, false))
					break;
			}
		}

				displayofs = 0;
				VWB_Bar(0,0,320,200,FIRSTCOLOR);
				US_DisplayHighScores(-1);

				if (IN_UserInput(TickBase * 6, false))
					break;

			}

			bufferofs = bufsave;
			displayofs = dissave;

			VW_FixRefreshBuffer();
			US_ControlPanel ();
		}

		if (!loadedgame)
			NewGame();

		if (refkeen_current_gamever == BE_GAMEVER_KDREAMS2015)
			FreeShape(&FileShape0);
		FreeShape(&FileShape1);
		if (CREDITS)
		{
			// REFKEEN - Free two credits screens as present in the 2015 release
			FreeShape(&FileShape2);
			FreeShape(&FileShape3);
		}
		GameLoop();
	}
	// REFKEEN - Alternative controllers support
	BE_ST_AltControlScheme_Pop();
}
Esempio n. 2
0
//--------------------------------------------------------------------------
// BLoad()			-- THIS HAS NOT BEEN FULLY TESTED!
//
// NOTICE : This version of BLOAD is compatable with JAMPak V3.0 and the
//				new fileformat...
//--------------------------------------------------------------------------
id0_unsigned_long_t BLoad(const id0_char_t *SourceFile, memptr *DstPtr)
{
	BE_FILE_T handle;

	memptr SrcPtr;
	//id0_unsigned_long_t i, j, k, r, c;
	//id0_word_t flags;
	id0_byte_t Buffer[8];
	id0_unsigned_long_t SrcLen,DstLen;
	struct CMP1Header CompHeader;
	id0_boolean_t Compressed = false;


	memset((void *)&CompHeader,0,sizeof(struct CMP1Header));

	//
	// Open file to load....
	//

	if (!BE_Cross_IsFileValid(handle = BE_Cross_open_for_reading(SourceFile)))
	//if ((handle = open(SourceFile, O_RDONLY|O_BINARY)) == -1)
		return(0);

	//
	// Look for JAMPAK headers
	//

	BE_Cross_readInt8LEBuffer(handle,Buffer,4);
	//read(handle,Buffer,4);

	if (!strncmp((char *)Buffer,COMP,4))
	{
		//
		// Compressed under OLD file format
		//

		Compressed = true;
		SrcLen = Verify(SourceFile);

		BE_Cross_readInt32LE(handle, &CompHeader.OrginalLen);
		//read(handle,(void *)&CompHeader.OrginalLen,4);
		CompHeader.CompType = ct_LZW;
		MM_GetPtr(DstPtr,CompHeader.OrginalLen);
		if (!*DstPtr)
			return(0);
	}
	else
	if (!strncmp((char *)Buffer,CMP1,4))
	{
		//
		// Compressed under new file format...
		//

		Compressed = true;
		SrcLen = Verify(SourceFile);

		BE_Cross_readInt8LEBuffer(handle,(void *)&CompHeader,sizeof(struct CMP1Header));
		//read(handle,(void *)&CompHeader,sizeof(struct CMP1Header));
		// REFKEEN - Big Endian support
#ifdef REFKEEN_ARCH_BIG_ENDIAN
		CompHeader.CompType = BE_Cross_Swap16LE(CompHeader.CompType);
		CompHeader.OrginalLen = BE_Cross_Swap32LE(CompHeader.OrginalLen);
		CompHeader.CompressLen = BE_Cross_Swap32LE(CompHeader.CompressLen);
#endif
		MM_GetPtr(DstPtr,CompHeader.OrginalLen);
		if (!*DstPtr)
			return(0);
	}
	else
		DstLen = Verify(SourceFile);


	//
	// Load the file in memory...
	//

	if (Compressed)
	{
		DstLen = CompHeader.OrginalLen;

		// REFKEEN - Looks like this is an unsigned comparison in original EXE
		if (((id0_unsigned_long_t)MM_TotalFree() < SrcLen) && (CompHeader.CompType))
		{
			if (!InitBufferedIO(handle,&lzwBIO))
				Quit("No memory for buffered I/O.");

			switch (CompHeader.CompType)
			{
				#if LZW_SUPPORT
				case ct_LZW:
					//lzwDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM));
					lzwDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,(SRC_BFILE|DEST_MEM));
				break;
				#endif

				#if LZH_SUPPORT
				case ct_LZH:
					//lzhDecompress(&lzwBIO,MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM));
					lzhDecompress(&lzwBIO,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_BFILE|DEST_MEM));
				break;
				#endif

				default:
					Quit("BLoad() - Unrecognized/Supported compression");
				break;
			}

			FreeBufferedIO(&lzwBIO);
		}
		else
		{
			// REFKEEN - Better close the current file handle before re-opening here
			BE_Cross_close(handle);
			//
			CA_LoadFile(SourceFile,&SrcPtr);
			switch (CompHeader.CompType)
			{
				#if LZW_SUPPORT
				case ct_LZW:
					//lzwDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,(SRC_MEM|DEST_MEM));
					lzwDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,(SRC_MEM|DEST_MEM));
				break;
				#endif

				#if LZH_SUPPORT
				case ct_LZH:
					//lzhDecompress(MK_FP(SrcPtr,8),MK_FP(*DstPtr,0),CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM));
					lzhDecompress((id0_byte_t *)SrcPtr + 8,*DstPtr,CompHeader.OrginalLen,CompHeader.CompressLen,(SRC_MEM|DEST_MEM));
				break;
				#endif

				default:
					Quit("BLoad() - Unrecognized/Supported compression");
				break;
			}
			MM_FreePtr(&SrcPtr);
			// REFKEEN - File handle already closed
			return(DstLen);
		}
	}
	else
	{
		// REFKEEN - Again we close the current file handle first, then load and finally return DstLen without re-closing file handle
		BE_Cross_close(handle);
		CA_LoadFile(SourceFile,DstPtr);
		return(DstLen);
	}

	BE_Cross_close(handle);
	return(DstLen);
}
Esempio n. 3
0
void
DemoLoop (void)
{
	//id0_char_t		*s;
	//id0_word_t		move;
	//id0_longword_t	lasttime;
	const id0_char_t *FileName1;
	struct Shape FileShape1;
#if CREDITS
	const id0_char_t *FileName2;
	struct Shape FileShape2;
#endif
	//struct ffblk ffblk;
	//WindowRec	mywin;
	id0_int_t bufsave	= bufferofs;
	id0_int_t dissave	= displayofs;


#if FRILLS
//
// check for launch from ted
//
	if (tedlevel)
	{
		NewGame();
		gamestate.mapon = tedlevelnum;
		GameLoop();
		TEDDeath();
	}
#endif

//
// demo loop
//
	US_SetLoadSaveHooks(LoadGame,SaveGame,ResetGame);
	restartgame = gd_Continue;

	BE_FILE_T handle = BE_Cross_open_for_reading("KDREAMS.CMP");
	//int handle = open("KDREAMS.CMP" ,O_BINARY | O_RDONLY);
	if (!BE_Cross_IsFileValid(handle))
	//if (handle == -1)
		Quit("Couldn't find KDREAMS.CMP");
	BE_Cross_close(handle);
#if 0
	if (findfirst("KDREAMS.CMP", &ffblk, 0) == -1)
		Quit("Couldn't find KDREAMS.CMP");
#endif

	while (true)
	{

		loadedgame = false;

		FileName1 = "TITLESCR.LBM";
		if (LoadLIBShape("KDREAMS.CMP", FileName1, &FileShape1))
			Quit("Can't load TITLE SCREEN");
#if CREDITS
		FileName2 = "CREDITS.LBM";
		if (LoadLIBShape("KDREAMS.CMP", FileName2, &FileShape2))
			Quit("Can't load CREDITS SCREEN");
#endif

		while (!restartgame && !loadedgame)
		{

			VW_InitDoubleBuffer();
			IN_ClearKeysDown();

			while (true)
			{

				VW_SetScreen(0, 0);
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape1, 0, 0);
				VW_ScreenToScreen (64*200,0,40,200);

#if CREDITS
				if (IN_UserInput(TickBase * 8, false))
					break;
#else
				if (IN_UserInput(TickBase * 4, false))
					break;
#endif

#if CREDITS
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape2, 0, 0);
				VW_ScreenToScreen (64*200,0,40,200);

				if (IN_UserInput(TickBase * 7, false))
					break;
#else
				MoveGfxDst(0, 200);
				UnpackEGAShapeToScreen(&FileShape1, 0, 0);
				VW_ScreenToScreen (64*200,0,40,200);

				if (IN_UserInput(TickBase * 3, false))
					break;
#endif

				displayofs = 0;
				VWB_Bar(0,0,320,200,FIRSTCOLOR);
				US_DisplayHighScores(-1);

				if (IN_UserInput(TickBase * 6, false))
					break;

			}

			bufferofs = bufsave;
			displayofs = dissave;

			VW_FixRefreshBuffer();
			US_ControlPanel ();
		}

		if (!loadedgame)
			NewGame();

		FreeShape(&FileShape1);
#if CREDITS
		FreeShape(&FileShape2);
#endif
		GameLoop();
	}
}
Esempio n. 4
0
//----------------------------------------------------------------------------
// LoadLIBFile() -- Copies a file from an existing archive to dos.
//
// PARAMETERS :
//
//			LibName 	- Name of lib file created with SoftLib V1.0
//
//			FileName - Name of file to load from lib file.
//
//			MemPtr   - (IF !NULL) - Pointer to memory to load into ..
//						  (IF NULL)  - Routine allocates necessary memory and
//											returns a MEM(SEG) pointer to memory allocated.
//
// RETURN :
//
//   		(IF !NULL) - A pointer to the loaded data.
//			(IF NULL)  - Error!
//
//----------------------------------------------------------------------------
memptr LoadLIBFile(const id0_char_t *LibName,const id0_char_t *FileName,memptr *MemPtr)
{
	BE_FILE_T handle;
	id0_unsigned_long_t header;
	struct ChunkHeader Header;
	id0_unsigned_long_t ChunkLen;
	id0_short_t x;
	struct FileEntryHdr FileEntry;     			// Storage for file once found
	struct FileEntryHdr FileEntryHeader;		// Header used durring searching
	struct SoftLibHdr LibraryHeader;				// Library header - Version Checking
	id0_boolean_t FileFound = false;
	id0_unsigned_long_t id_slib = ID_SLIB;
	id0_unsigned_long_t id_chunk = ID_CHUNK;


	//
	// OPEN SOFTLIB FILE
	//

	if (!BE_Cross_IsFileValid(handle = BE_Cross_open_for_reading(LibName)))
	//if ((handle = open(LibName,O_RDONLY|O_BINARY, S_IREAD)) == -1)
		return(NULL);


	//
	//	VERIFY it is a SOFTLIB (SLIB) file
	//

	if (BE_Cross_readInt8LEBuffer(handle,&header,4) < 4)
	//if (read(handle,&header,4) == -1)
	{
		BE_Cross_close(handle);
		return(NULL);
	}

	if (header != id_slib)
	{
		BE_Cross_close(handle);
		return(NULL);
	}


	//
	// CHECK LIBRARY HEADER VERSION NUMBER
	//

	if (BE_Cross_readInt8LEBuffer(handle, &LibraryHeader,sizeof(struct SoftLibHdr)) < sizeof(struct SoftLibHdr))
	//if (read(handle, &LibraryHeader,sizeof(struct SoftLibHdr)) == -1)
		Quit("read error in LoadSLIBFile()\n");
	// REFKEEN - Big Endian support
#ifdef REFKEEN_ARCH_BIG_ENDIAN
	LibraryHeader.Version = BE_Cross_Swap16LE(LibraryHeader.Version);
	LibraryHeader.FileCount = BE_Cross_Swap16LE(LibraryHeader.FileCount);
#endif

	if (LibraryHeader.Version > SOFTLIB_VER)
		Quit("Unsupported file ver ");


	//
	// MANAGE FILE ENTRY HEADERS...
	//

	for (x = 1;x<=LibraryHeader.FileCount;x++)
	{
		if (BE_Cross_readInt8LEBuffer(handle, &FileEntryHeader,sizeof(struct FileEntryHdr)) < sizeof(struct FileEntryHdr))
		//if (read(handle, &FileEntryHeader,sizeof(struct FileEntryHdr)) == -1)
		{
			BE_Cross_close(handle);
			return(NULL);
		}
		// REFKEEN - Big Endian support
#ifdef REFKEEN_ARCH_BIG_ENDIAN
		FileEntryHeader.Offset = BE_Cross_Swap32LE(FileEntryHeader.Offset);
		FileEntryHeader.ChunkLen = BE_Cross_Swap32LE(FileEntryHeader.ChunkLen);
		FileEntryHeader.OrginalLength = BE_Cross_Swap32LE(FileEntryHeader.OrginalLength);
		FileEntryHeader.Compression = BE_Cross_Swap16LE(FileEntryHeader.Compression);
#endif

		//if (!stricmp(FileEntryHeader.FileName,FileName))
		if (!BE_Cross_strcasecmp(FileEntryHeader.FileName,FileName))
		{
			FileEntry = FileEntryHeader;
			FileFound = true;
		}
	}

	//
	// IF FILE HAS BEEN FOUND THEN SEEK TO POSITION AND EXTRACT
	//	ELSE RETURN WITH ERROR CODE...
	//

	if (FileFound)
	{
		if (BE_Cross_seek(handle,FileEntry.Offset,SEEK_CUR) == -1)
		{
			BE_Cross_close(handle);
			return(NULL);
		}

		//
		// READ CHUNK HEADER - Verify we are at the beginning of a chunk..
		//

		if (BE_Cross_readInt8LEBuffer(handle,(id0_char_t *)&Header,sizeof(struct ChunkHeader)) < sizeof(struct ChunkHeader))
		//if (read(handle,(id0_char_t *)&Header,sizeof(struct ChunkHeader)) == -1)
			Quit("LIB File - Unable to read Header!");
		// REFKEEN - Big Endian support
#ifdef REFKEEN_ARCH_BIG_ENDIAN
		// No need to swap Header.HeaderID, id_chunk (ID_CHUNK) should be adjusted
		Header.OrginalLength = BE_Cross_Swap32LE(Header.OrginalLength);
		Header.Compression = BE_Cross_Swap16LE(Header.Compression);
#endif

		if (Header.HeaderID != id_chunk)
			Quit("LIB File - BAD HeaderID!");

		//
		// Allocate memory if Necessary...
		//


		if (!*MemPtr)
			MM_GetPtr(MemPtr,FileEntry.OrginalLength);

		//
		//	Calculate the length of the data (without the chunk header).
		//

		ChunkLen = FileEntry.ChunkLen - sizeof(struct ChunkHeader);


		//
		// Extract Data from file
		//

		switch (Header.Compression)
		{

			#if LZW_SUPPORT
			case ct_LZW:
				if (!InitBufferedIO(handle,&lzwBIO))
					Quit("No memory for buffered I/O.");
				//lzwDecompress(&lzwBIO,MK_FP(*MemPtr,0),FileEntry.OrginalLength,(SRC_BFILE|DEST_MEM));
				lzwDecompress(&lzwBIO,*MemPtr,FileEntry.OrginalLength,(SRC_BFILE|DEST_MEM));
				FreeBufferedIO(&lzwBIO);
				break;
			#endif

			#if LZH_SUPPORT
			case ct_LZH:
				if (!InitBufferedIO(handle,&lzwBIO))
					Quit("No memory for buffered I/O.");
				//lzhDecompress(&lzwBIO, MK_FP(*MemPtr,0), FileEntry.OrginalLength, ChunkLen, (SRC_BFILE|DEST_MEM));
				lzhDecompress(&lzwBIO, *MemPtr, FileEntry.OrginalLength, ChunkLen, (SRC_BFILE|DEST_MEM));
				FreeBufferedIO(&lzwBIO);
				break;
			#endif

			case ct_NONE:
				//if (!CA_FarRead(handle,MK_FP(*MemPtr,0),ChunkLen))
				if (!CA_FarRead(handle,(id0_byte_t *)(*MemPtr),ChunkLen))
				{
//					BE_Cross_close(handle);
					*MemPtr = NULL;
				}
				break;

			default:
				BE_Cross_close(handle);
				Quit("Unknown Chunk.Compression Type!");
				break;
		}
	}
	else
		*MemPtr = NULL;

	BE_Cross_close(handle);
	return(*MemPtr);
}