diff options
| author | Eugene Sandulenko | 2014-10-06 14:50:05 +0200 | 
|---|---|---|
| committer | Eugene Sandulenko | 2015-12-15 00:05:02 +0100 | 
| commit | 8ca14d1d642fce2617513fdc0c3223af2ab4e7e7 (patch) | |
| tree | 191bf0157fbb79df4721e6094141db206dc41ffa /engines/lab/savegame.cpp | |
| parent | 64f9c902ddf0c8294fd9e5f66cf96661eb12040b (diff) | |
| download | scummvm-rg350-8ca14d1d642fce2617513fdc0c3223af2ab4e7e7.tar.gz scummvm-rg350-8ca14d1d642fce2617513fdc0c3223af2ab4e7e7.tar.bz2 scummvm-rg350-8ca14d1d642fce2617513fdc0c3223af2ab4e7e7.zip | |
LAB: Initial code
Diffstat (limited to 'engines/lab/savegame.cpp')
| -rw-r--r-- | engines/lab/savegame.cpp | 323 | 
1 files changed, 323 insertions, 0 deletions
| diff --git a/engines/lab/savegame.cpp b/engines/lab/savegame.cpp new file mode 100644 index 0000000000..ed25c38ef2 --- /dev/null +++ b/engines/lab/savegame.cpp @@ -0,0 +1,323 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +/* + * This code is based on Labyrinth of Time code with assistance of + * + * Copyright (c) 1993 Terra Nova Development + * Copyright (c) 2004 The Wyrmkeep Entertainment Co. + * + */ + +#include "lab/stddefines.h" +#include "lab/labfun.h" +#include "lab/modernsavegame.h" + +namespace Lab { + +/* The version string */ +#if defined(DOSCODE) +#define SAVEVERSION         "LBS2" +#else +#define SAVEVERSION         "LBS3" +#define SAVEVERSION_COMPAT  "LBS2" +#endif + +#define BOOKMARK  0 +#define CARDMARK  1 +#define FLOPPY    2 + +typedef void *LABFH; +#define INVALID_LABFH   NULL + +uint16 FileType, FileNum; + + + +/*----- The Amiga specific area of saveGame.c -----*/ + + +/*****************************************************************************/ +/* Opens a file to write to from disk.                                       */ +/*****************************************************************************/ +static LABFH saveGameOpen(char *filename, bool iswrite) { +	warning("STUB: saveGameOpen"); +	return 0; + +#if 0 +	if (iswrite) { +		unlink(filename); +		return fopen(filename, "wb"); +	} else +		return fopen(filename, "rb"); +#endif +} + + + + +/*****************************************************************************/ +/* Closes a file.                                                            */ +/*****************************************************************************/ +static void saveGameClose(LABFH file, bool iswrite) { +	warning("STUB: saveGameClose"); +	return; + +#if 0 +	if (file != INVALID_LABFH) +		fclose(file); +#endif +} + + + + +/*****************************************************************************/ +/* Writes a block of memory to whatever it is that we're writing to.         */ +/*****************************************************************************/ +static void saveGameWriteBlock(LABFH file, void *data, uint32 size) { +	warning("STUB: saveGameWriteBlock"); +	return; + +	//fwrite(data, 1, size, file); +} + + + +/*****************************************************************************/ +/* Writes a block of memory to whatever it is that we're writing to.         */ +/*****************************************************************************/ +static void saveGameReadBlock(LABFH file, void *data, uint32 size) { +	warning("STUB: saveGameReadBlock"); +	return; + +	//fread(data, 1, size, file); +} + + + + +/*----- The machine independent section of saveGame.c -----*/ + + +/* Lab: Labyrinth specific */ +extern uint16 combination[6]; +extern uint16 CurTile[4] [4]; + +#if !defined(DOSCODE) +extern CrumbData BreadCrumbs[MAX_CRUMBS]; +extern uint16 NumCrumbs; +extern bool DroppingCrumbs; +extern bool FollowingCrumbs; +#endif + +/*****************************************************************************/ +/* Writes the game out to disk.                                              */ +/* Assumes that the file has already been openned and is there.              */ +/*****************************************************************************/ +static bool saveGame(uint16 RoomNum, uint16 Direction, uint16 Quarters, LargeSet set1, LargeSet set2, LABFH file) { +#if !defined(DOSCODE) +	uint16 temp; +	CrumbData crumbs[sizeof(BreadCrumbs) / sizeof(CrumbData)]; +#endif +	uint16 last, counter, counter1; +	char c; + +	saveGameWriteBlock(file, (void *)SAVEVERSION, 4L); +#if defined(DOSCODE) +	saveGameWriteBlock(file, &RoomNum, 2L); +	saveGameWriteBlock(file, &Direction, 2L); +	saveGameWriteBlock(file, &Quarters, 2L); +#else +	temp = swapUShort(RoomNum); +	saveGameWriteBlock(file, &temp, 2L); +	temp = swapUShort(Direction); +	saveGameWriteBlock(file, &temp, 2L); +	temp = swapUShort(Quarters); +	saveGameWriteBlock(file, &temp, 2L); +#endif + +	last = set1->lastElement / 8; +	saveGameWriteBlock(file, &(set1->array[0]), (uint32) last); + +	last = set2->lastElement / 8; +	saveGameWriteBlock(file, &(set2->array[0]), (uint32) last); + +	/* LAB: the combination lock and tile stuff */ +	for (counter = 0; counter < 6; counter++) { +		c = (char)combination[counter]; +		saveGameWriteBlock(file, &c, 1L); +	} + +	for (counter = 0; counter < 4; counter++) +		for (counter1 = 0; counter1 < 4; counter1++) +#if defined(DOSCODE) +			saveGameWriteBlock(file, &(CurTile[counter] [counter1]), 2L); + +#else +		{ +			temp = swapUShort(CurTile[counter] [counter1]); +			saveGameWriteBlock(file, &temp, 2L); +		} +#endif + +#if !defined(DOSCODE) +	saveGameWriteBlock(file, g_SaveGameImage, SAVED_IMAGE_SIZE); +	memcpy(crumbs, BreadCrumbs, sizeof BreadCrumbs); +	swapUShortPtr(&crumbs[0].RoomNum, sizeof(BreadCrumbs) / sizeof(uint16)); +	saveGameWriteBlock(file, crumbs, sizeof BreadCrumbs); +#endif + +	saveGameClose(file, true); + +	return true; +} + + + +/*****************************************************************************/ +/* Reads the game from disk.                                                 */ +/* Assumes that the file has already been openned and is there.              */ +/*****************************************************************************/ +static bool loadGame(uint16 *RoomNum, uint16 *Direction, uint16 *Quarters, LargeSet set1, LargeSet set2, LABFH file) { +#if !defined(DOSCODE) +	uint16 t; +	CrumbData crumbs[sizeof(BreadCrumbs) / sizeof(CrumbData)]; +#endif +	char temp[5], c; +	uint16 last, counter, counter1; + +	saveGameReadBlock(file, temp, 4L); +	temp[4] = 0; + +	/* +	   if (strcmp(temp, SAVEVERSION) != 0) +	   { +	    saveGameClose(file, false); +	    return false; +	   } +	 */ + +#if defined(DOSCODE) +	saveGameReadBlock(file, RoomNum, 2L); +	saveGameReadBlock(file, Direction, 2L); +	saveGameReadBlock(file, Quarters, 2L); +#else +	saveGameReadBlock(file, &t, 2L); +	*RoomNum = swapUShort(t); +	saveGameReadBlock(file, &t, 2L); +	*Direction = swapUShort(t); +	saveGameReadBlock(file, &t, 2L); +	*Quarters = swapUShort(t); +#endif + +	last = set1->lastElement / 8; +	saveGameReadBlock(file, &(set1->array[0]), (uint32) last); + +	last = set2->lastElement / 8; +	saveGameReadBlock(file, &(set2->array[0]), (uint32) last); + +	/* LAB: the combination lock and tile stuff */ +	for (counter = 0; counter < 6; counter++) { +		saveGameReadBlock(file, &c, 1L); +		combination[counter] = c; +	} + +	for (counter = 0; counter < 4; counter++) +		for (counter1 = 0; counter1 < 4; counter1++) +#if defined(DOSCODE) +			saveGameReadBlock(file, &(CurTile[counter] [counter1]), 2L); + +#else +		{ +			saveGameReadBlock(file, &t, 2L); +			CurTile[counter] [counter1] = swapUShort(t); +		} +#endif + +	if (strcmp(temp, SAVEVERSION) == 0) { +		saveGameReadBlock(file, g_SaveGameImage, SAVED_IMAGE_SIZE); + +		memset(crumbs, 0, sizeof BreadCrumbs); +		saveGameReadBlock(file, crumbs, sizeof BreadCrumbs); +		swapUShortPtr(&crumbs[0].RoomNum, sizeof(BreadCrumbs) / sizeof(uint16)); +		memcpy(BreadCrumbs, crumbs, sizeof BreadCrumbs); +		DroppingCrumbs = (BreadCrumbs[0].RoomNum != 0); +		FollowingCrumbs = false; + +		for (counter = 0; counter < MAX_CRUMBS; counter++) +			if (BreadCrumbs[counter].RoomNum == 0) break; + +		NumCrumbs = counter; +	} + +	saveGameClose(file, false); + +	return true; +} + + + + +/*****************************************************************************/ +/* Saves the game to the floppy disk.                                        */ +/*****************************************************************************/ +bool saveFloppy(char *path, uint16 RoomNum, uint16 Direction, uint16 NumQuarters, LargeSet Conditions, LargeSet Rooms, uint16 filenum, uint16 type) { +	LABFH FPtr; + +	g_music->checkMusic(); + +	FileType = type; +	FileNum  = filenum; + +	if ((FPtr = saveGameOpen(path, true)) != INVALID_LABFH) +		saveGame(RoomNum, Direction, NumQuarters, Conditions, Rooms, FPtr); +	else +		return false; + +	return true; +} + + + + +/*****************************************************************************/ +/* Reads the game from the floppy disk.                                      */ +/*****************************************************************************/ +bool readFloppy(char *path, uint16 *RoomNum, uint16 *Direction, uint16 *NumQuarters, LargeSet Conditions, LargeSet Rooms, uint16 filenum, uint16 type) { +	LABFH FPtr; + +	g_music->checkMusic(); + +	FileType = type; +	FileNum  = filenum; + +	if ((FPtr = saveGameOpen(path, false)) != INVALID_LABFH) { +		if (!loadGame(RoomNum, Direction, NumQuarters, Conditions, Rooms, FPtr)) +			return false; +	} else +		return false; + +	return true; +} + +} // End of namespace Lab | 
