[Scummvm-cvs-logs] CVS: scummvm/simon midi.cpp,1.1.1.1,1.2 midi.h,1.1.1.1,1.2 res.cpp,1.1.1.1,1.2 simon.cpp,1.6,1.7 simon.h,1.2,1.3 sys.cpp,1.1.1.1,NONE

Pawe? Ko?odziejski aquadran at users.sourceforge.net
Mon Sep 16 01:23:04 CEST 2002


Update of /cvsroot/scummvm/scummvm/simon
In directory usw-pr-cvs1:/tmp/cvs-serv17740/simon

Modified Files:
	midi.cpp midi.h res.cpp simon.cpp simon.h 
Removed Files:
	sys.cpp 
Log Message:
simon also use class File

Index: midi.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/midi.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- midi.cpp	21 Aug 2002 16:07:37 -0000	1.1.1.1
+++ midi.cpp	16 Sep 2002 08:22:30 -0000	1.2
@@ -27,34 +27,7 @@
 #include "sound/mixer.h"
 #include "simon/simon.h"
 
-void MidiPlayer::read_from_file(void *dst, uint size)
-{
-	if (fread(dst, size, 1, _input) != 1)
-		error("Midi read error");
-}
-
-byte MidiPlayer::read_byte_from_file()
-{
-	byte num;
-	read_from_file(&num, 1);
-	return num;
-}
-
-uint32 MidiPlayer::read_uint32_from_file()
-{
-	uint32 num;
-	read_from_file(&num, 4);
-	return READ_BE_UINT32(&num);
-}
-
-uint16 MidiPlayer::read_uint16_from_file()
-{
-	uint16 num;
-	read_from_file(&num, 2);
-	return READ_BE_UINT16(&num);
-}
-
-void MidiPlayer::read_all_songs(FILE *in)
+void MidiPlayer::read_all_songs(File *in)
 {
 	uint i, num;
 
@@ -62,14 +35,14 @@
 
 	_midi_cur_song_ptr = _midi_songs;
 
-	num = read_byte_from_file();
+	num = _input->readByte();
 
 	for (i = 0; i != num; i++) {
 		read_one_song(&_midi_songs[i]);
 	}
 }
 
-void MidiPlayer::read_all_songs_old(FILE *in)
+void MidiPlayer::read_all_songs_old(File *in)
 {
 	uint i, num;
 
@@ -89,18 +62,18 @@
 	uint i;
 
 	if (!old) {
-		if (read_uint32_from_file() != 6)
+		if (_input->readDwordBE() != 6)
 			error("Invalid 'MThd' chunk size");
-		s->midi_format = read_uint16_from_file();
-		s->num_tracks = read_uint16_from_file();
-		s->ppqn = read_uint16_from_file();
+		s->midi_format = _input->readWordBE();
+		s->num_tracks = _input->readWordBE();
+		s->ppqn = _input->readWordBE();
 	} else {
 		s->midi_format = 0;
 		s->num_tracks = 1;
 		s->ppqn = 0xc0;
 
-		read_uint16_from_file();
-		read_byte_from_file();
+		_input->readWordBE();
+		_input->readByte();
 	}
 
 	s->tracks = t = (Track *)calloc(s->num_tracks, sizeof(Track));
@@ -109,15 +82,15 @@
 
 	for (i = 0; i != s->num_tracks; i++, t++) {
 		if (!old) {
-			if (read_uint32_from_file() != 'MTrk')
+			if (_input->readDwordBE() != 'MTrk')
 				error("Midi track has no 'MTrk'");
 
-			t->data_size = read_uint32_from_file();
+			t->data_size = _input->readDwordLE();
 		} else {
-			uint32 pos = ftell(_input);
-			fseek(_input, 0, SEEK_END);
-			uint32 end = ftell(_input);
-			fseek(_input, pos, SEEK_SET);
+			uint32 pos = _input->pos();
+			_input->seek(0, SEEK_END);
+			uint32 end = _input->pos();
+			_input->seek(pos, SEEK_SET);
 			t->data_size = end - pos;
 		}
 
@@ -125,7 +98,7 @@
 		if (t->data_ptr == NULL)
 			error("Out of memory when allocating MIDI track data");
 
-		read_from_file(t->data_ptr, t->data_size);
+		_input->read(t->data_ptr, t->data_size);
 
 		t->data_cur_size = t->data_size;
 		t->data_cur_ptr = t->data_ptr;
@@ -152,7 +125,7 @@
 	s->num_tracks = 0;
 	s->tracks = NULL;
 
-	uint32 id = read_uint32_from_file();
+	uint32 id = _input->readDwordBE();
 
 	switch (id) {
 	case 'MThd':

Index: midi.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/midi.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- midi.h	21 Aug 2002 16:07:37 -0000	1.1.1.1
+++ midi.h	16 Sep 2002 08:22:30 -0000	1.2
@@ -23,12 +23,13 @@
 #define SIMON_MIDI_H
 
 class MidiDriver;
+class File;
 struct MidiEvent;
 
 class MidiPlayer {
 public:
-	void read_all_songs(FILE *in);
-	void read_all_songs_old(FILE *in);
+	void read_all_songs(File *in);
+	void read_all_songs_old(File *in);
 	void initialize();
 	void shutdown();
 	void play();
@@ -63,7 +64,7 @@
 
 	MidiDriver *_md;
 
-	FILE *_input;
+	File *_input;
 
 	uint _midi_var10, _midi_5;
 	bool _midi_var9;
@@ -91,9 +92,6 @@
 
 	void read_from_file(void *dst, uint size);
 	void read_one_song(Song *s);
-	byte read_byte_from_file();
-	uint32 read_uint32_from_file();
-	uint16 read_uint16_from_file();
 
 	static uint32 track_read_gamma(Track *t);
 	static byte track_read_byte(Track *t);

Index: res.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/res.cpp,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -u -d -r1.1.1.1 -r1.2
--- res.cpp	21 Aug 2002 16:07:37 -0000	1.1.1.1
+++ res.cpp	16 Sep 2002 08:22:30 -0000	1.2
@@ -93,62 +93,15 @@
 	" ", " ", "BT ", " ", "B "
 };
 
-FILE *SimonState::fopen_maybe_lowercase(const char *filename)
-{
-	FILE *in;
-	char buf[256], dotbuf[256], *e;
-	const char *s = _gameDataPath;
-
-	if (filename == NULL || *filename == '\0')
-		return NULL;
-
-	strcpy(buf, s);
-	strcat(buf, filename);
-	strcpy(dotbuf, buf);
-	strcat(dotbuf, ".");					// '.' appended version
-								// for dumb vfat drivers 
-
-	/* original filename */
-	in = fopen(buf, "rb");
-	if (in)
-		return in;
-
-	/* lowercase original filename */
-	e = buf + strlen(s);
-	do
-		*e = tolower(*e);
-	while (*e++);
-	in = fopen(buf, "rb");
-	if (in)
-		return in;
-
-	if (strchr(buf, '.'))
-		return NULL;
-
-	/* dot appended original filename */
-	in = fopen(dotbuf, "rb");
-	if (in)
-		return in;
-
-	/* lowercase dot appended */
-	e = dotbuf + strlen(s);
-	do
-		*e = tolower(*e);
-	while (*e++);
-	in = fopen(dotbuf, "rb");
-
-	return in;
-}
-
 bool SimonState::loadGamePcFile(const char *filename)
 {
-	FILE *in;
+	File * in = new File();
 	int num_inited_objects;
 	int i, file_size;
 
 	/* read main gamepc file */
-	in = fopen_maybe_lowercase(filename);
-	if (in == NULL)
+	in->open(filename, _gameDataPath);
+	if (in->isOpen() == false)
 		return false;
 
 	num_inited_objects = allocGamePcVars(in);
@@ -163,22 +116,22 @@
 
 	readSubroutineBlock(in);
 
-	fclose(in);
+	in->close();
 
 	/* Read list of TABLE resources */
-	in = fopen_maybe_lowercase("TBLLIST");
-	if (in == NULL)
+	in->open("TBLLIST", _gameDataPath);
+	if (in->isOpen() == false)
 		return false;
 
-	fseek(in, 0, SEEK_END);
-	file_size = ftell(in);
+	in->seek(0, SEEK_END);
+	file_size = in->pos();
 
 	_tbl_list = (byte *)malloc(file_size);
 	if (_tbl_list == NULL)
 		error("Out of memory for strip table list");
-	fseek(in, 0, SEEK_SET);
-	fread(_tbl_list, file_size, 1, in);
-	fclose(in);
+	in->seek(0, SEEK_SET);
+	in->read(_tbl_list, file_size);
+	in->close();
 
 	/* Remember the current state */
 	_subroutine_list_org = _subroutine_list;
@@ -186,64 +139,64 @@
 	_tablesheap_curpos_org = _tablesheap_curpos;
 
 	/* Read list of TEXT resources */
-	in = fopen_maybe_lowercase("STRIPPED.TXT");
-	if (in == NULL)
+	in->open("STRIPPED.TXT", _gameDataPath);
+	if (in->isOpen() == false)
 		return false;
 
-	fseek(in, 0, SEEK_END);
-	file_size = ftell(in);
+	in->seek(0, SEEK_END);
+	file_size = in->pos();
 	_stripped_txt_mem = (byte *)malloc(file_size);
 	if (_stripped_txt_mem == NULL)
 		error("Out of memory for strip text list");
-	fseek(in, 0, SEEK_SET);
-	fread(_stripped_txt_mem, file_size, 1, in);
-	fclose(in);
+	in->seek(0, SEEK_SET);
+	in->read(_stripped_txt_mem, file_size);
+	in->close();
 
 	return true;
 }
 
-void SimonState::readGamePcText(FILE *in)
+void SimonState::readGamePcText(File *in)
 {
 	uint text_size;
 	byte *text_mem;
 
-	_text_size = text_size = fileReadBE32(in);
+	_text_size = text_size = in->readDwordBE();
 	text_mem = (byte *)malloc(text_size);
 	if (text_mem == NULL)
 		error("Out of text memory");
 
-	fread(text_mem, text_size, 1, in);
+	in->read(text_mem, text_size);
 
 	setupStringTable(text_mem, _stringtab_num);
 }
 
-void SimonState::readItemFromGamePc(FILE *in, Item *item)
+void SimonState::readItemFromGamePc(File *in, Item *item)
 {
 	uint32 type;
 
-	item->unk2 = fileReadBE16(in);
-	item->unk1 = fileReadBE16(in);
-	item->unk3 = fileReadBE16(in);
+	item->unk2 = in->readWordBE();
+	item->unk1 = in->readWordBE();
+	item->unk3 = in->readWordBE();
 	item->sibling = (uint16)fileReadItemID(in);
 	item->child = (uint16)fileReadItemID(in);
 	item->parent = (uint16)fileReadItemID(in);
-	fileReadBE16(in);
-	item->unk4 = fileReadBE16(in);
+	in->readWordBE();
+	item->unk4 = in->readWordBE();
 	item->children = NULL;
 
-	type = fileReadBE32(in);
+	type = in->readDwordBE();
 	while (type) {
-		type = fileReadBE16(in);
+		type = in->readWordBE();
 		if (type != 0)
 			readItemChildren(in, item, type);
 	}
 }
 
-void SimonState::readItemChildren(FILE *in, Item *item, uint type)
+void SimonState::readItemChildren(File *in, Item *item, uint type)
 {
 	if (type == 1) {
-		uint fr1 = fileReadBE16(in);
-		uint fr2 = fileReadBE16(in);
+		uint fr1 = in->readWordBE();
+		uint fr2 = in->readWordBE();
 		uint i, size;
 		uint j, k;
 		Child1 *child;
@@ -261,7 +214,7 @@
 			if (j & 3)
 				child->array[k++] = (uint16)fileReadItemID(in);
 	} else if (type == 2) {
-		uint32 fr = fileReadBE32(in);
+		uint32 fr = in->readDwordBE();
 		uint i, k, size;
 		Child2 *child;
 
@@ -275,27 +228,27 @@
 
 		k = 0;
 		if (fr & 1) {
-			child->array[k++] = (uint16)fileReadBE32(in);
+			child->array[k++] = (uint16)in->readDwordBE();
 		}
 		for (i = 1; i != 16; i++)
 			if (fr & (1 << i))
-				child->array[k++] = fileReadBE16(in);
+				child->array[k++] = in->readWordBE();
 
-		child->string_id = (uint16)fileReadBE32(in);
+		child->string_id = (uint16)in->readDwordBE();
 	} else {
 		error("readItemChildren: invalid mode");
 	}
 }
 
-uint fileReadItemID(FILE *in)
+uint fileReadItemID(File *in)
 {
-	uint32 val = fileReadBE32(in);
+	uint32 val = in->readDwordBE();
 	if (val == 0xFFFFFFFF)
 		return 0;
 	return val + 2;
 }
 
-byte *SimonState::readSingleOpcode(FILE *in, byte *ptr)
+byte *SimonState::readSingleOpcode(File *in, byte *ptr)
 {
 	int i, l;
 	const char *string_ptr;
@@ -339,20 +292,20 @@
 		case 'n':
 		case 'p':
 		case 'v':
-			val = fileReadBE16(in);
+			val = in->readWordBE();
 			*ptr++ = val >> 8;
 			*ptr++ = val & 255;
 			break;
 
 		case 'B':
-			*ptr++ = fileReadByte(in);
+			*ptr++ = in->readByte();
 			if (ptr[-1] == 0xFF) {
-				*ptr++ = fileReadByte(in);
+				*ptr++ = in->readByte();
 			}
 			break;
 
 		case 'I':
-			val = fileReadBE16(in);
+			val = in->readWordBE();
 			switch (val) {
 			case 1:
 				val = 0xFFFF;
@@ -377,7 +330,7 @@
 			break;
 
 		case 'T':
-			val = fileReadBE16(in);
+			val = in->readWordBE();
 			switch (val) {
 			case 0:
 				val = 0xFFFF;
@@ -386,7 +339,7 @@
 				val = 0xFFFD;
 				break;
 			default:
-				val = (uint16)fileReadBE32(in);
+				val = (uint16)in->readDwordBE();
 				break;
 			}
 			*ptr++ = val >> 8;

Index: simon.cpp
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/simon.cpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- simon.cpp	25 Aug 2002 11:33:54 -0000	1.6
+++ simon.cpp	16 Sep 2002 08:22:30 -0000	1.7
@@ -208,16 +208,16 @@
 	return org;
 }
 
-int SimonState::allocGamePcVars(FILE *in)
+int SimonState::allocGamePcVars(File *in)
 {
 	uint item_array_size, item_array_inited, stringtable_num;
 	uint32 version;
 	uint i;
 
-	item_array_size = fileReadBE32(in);
-	version = fileReadBE32(in);
-	item_array_inited = fileReadBE32(in);
-	stringtable_num = fileReadBE32(in);
+	item_array_size = in->readDwordBE();
+	version = in->readDwordBE();
+	item_array_inited = in->readDwordBE();
+	stringtable_num = in->readDwordBE();
 
 	item_array_inited += 2;				/* first two items are predefined */
 	item_array_size += 2;
@@ -315,20 +315,20 @@
 	}
 }
 
-void SimonState::readSubroutineLine(FILE *in, SubroutineLine *sl, Subroutine *sub)
+void SimonState::readSubroutineLine(File *in, SubroutineLine *sl, Subroutine *sub)
 {
 	byte line_buffer[1024], *q = line_buffer;
 	int size;
 
 	if (sub->id == 0) {
-		sl->cond_a = fileReadBE16(in);
-		sl->cond_b = fileReadBE16(in);
-		sl->cond_c = fileReadBE16(in);
+		sl->cond_a = in->readWordBE();
+		sl->cond_b = in->readWordBE();
+		sl->cond_c = in->readWordBE();
 	}
 
-	while ((*q = fileReadByte(in)) != 0xFF) {
+	while ((*q = in->readByte()) != 0xFF) {
 		if (*q == 87) {
-			fileReadBE16(in);
+			in->readWordBE();
 		} else {
 			q = readSingleOpcode(in, q);
 		}
@@ -373,9 +373,9 @@
 	return sl;
 }
 
-void SimonState::readSubroutine(FILE *in, Subroutine *sub)
+void SimonState::readSubroutine(File *in, Subroutine *sub)
 {
-	while (fileReadBE16(in) == 0) {
+	while (in->readWordBE() == 0) {
 		readSubroutineLine(in, createSubroutineLine(sub, 0xFFFF), sub);
 	}
 }
@@ -394,10 +394,10 @@
 	return sub;
 }
 
-void SimonState::readSubroutineBlock(FILE *in)
+void SimonState::readSubroutineBlock(File *in)
 {
-	while (fileReadBE16(in) == 0) {
-		readSubroutine(in, createSubroutine(fileReadBE16(in)));
+	while (in->readWordBE() == 0) {
+		readSubroutine(in, createSubroutine(in->readWordBE()));
 	}
 }
 
@@ -780,7 +780,7 @@
 	int i;
 	uint min_num, max_num;
 	char filename[30];
-	FILE *in;
+	File *in;
 
 	p = _tbl_list;
 	if (p == NULL)
@@ -866,7 +866,7 @@
 	return size;
 }
 
-FILE *SimonState::openTablesFile_gme(const char *filename)
+File *SimonState::openTablesFile_gme(const char *filename)
 {
 	uint res;
 	uint32 offs;
@@ -874,11 +874,11 @@
 	res = atoi(filename + 6) + gss->TABLE_INDEX_BASE - 1;
 	offs = _game_offsets_ptr[res];
 
-	fseek(_game_file, offs, SEEK_SET);
+	_game_file->seek(offs, SEEK_SET);
 	return _game_file;
 }
 
-void SimonState::closeTablesFile_gme(FILE *in)
+void SimonState::closeTablesFile_gme(File *in)
 {
 	/* not needed */
 }
@@ -886,35 +886,37 @@
 /* Simon1DOS load tables file */
 uint SimonState::loadTextFile_simon1(const char *filename, byte *dst)
 {
-	FILE *fo = fopen_maybe_lowercase(filename);
+	File fo;
+	fo.open(filename, _gameDataPath);
 	uint32 size;
 
-	if (fo == NULL)
+	if (fo.isOpen() == false)
 		error("loadTextFile: Cannot open '%s'", filename);
 
-	fseek(fo, 0, SEEK_END);
-	size = ftell(fo);
-	fseek(fo, 0, SEEK_SET);
+	fo.seek(0, SEEK_END);
+	size = fo.pos();
+	fo.seek(0, SEEK_SET);
 
-	if (fread(dst, size, 1, fo) != 1)
+	if (fo.read(dst, size) != size)
 		error("loadTextFile: fread failed");
-	fclose(fo);
+	fo.close();
 
 	return size;
 }
 
 
-FILE *SimonState::openTablesFile_simon1(const char *filename)
+File *SimonState::openTablesFile_simon1(const char *filename)
 {
-	FILE *fo = fopen_maybe_lowercase(filename);
-	if (fo == NULL)
+	File *fo = new File();
+	fo->open(filename, _gameDataPath);
+	if (fo->isOpen() == false)
 		error("openTablesFile: Cannot open '%s'", filename);
 	return fo;
 }
 
-void SimonState::closeTablesFile_simon1(FILE *in)
+void SimonState::closeTablesFile_simon1(File *in)
 {
-	fclose(in);
+	in->close();
 }
 
 uint SimonState::loadTextFile(const char *filename, byte *dst)
@@ -925,7 +927,7 @@
 		return loadTextFile_gme(filename, dst);
 }
 
-FILE *SimonState::openTablesFile(const char *filename)
+File *SimonState::openTablesFile(const char *filename)
 {
 	if (_game == GAME_SIMON1DOS)
 		return openTablesFile_simon1(filename);
@@ -933,7 +935,7 @@
 		return openTablesFile_gme(filename);
 }
 
-void SimonState::closeTablesFile(FILE *in)
+void SimonState::closeTablesFile(File *in)
 {
 	if (_game == GAME_SIMON1DOS)
 		closeTablesFile_simon1(in);
@@ -1436,23 +1438,24 @@
 
 void SimonState::loadIconFile()
 {
-	FILE *in = fopen_maybe_lowercase("ICON.DAT");
+	File in;
+	in.open("ICON.DAT", _gameDataPath);
 	uint size;
 
-	if (in == NULL)
+	if (in.isOpen() == false)
 		error("Cannot open icon.dat");
 
-	fseek(in, 0, SEEK_END);
-	size = ftell(in);
+	in.seek(0, SEEK_END);
+	size = in.pos();
 
 	_icon_file_ptr = (byte *)malloc(size);
 	if (_icon_file_ptr == NULL)
 		error("Out of icon memory");
 
-	fseek(in, 0, SEEK_SET);
+	in.seek(0, SEEK_SET);
 
-	fread(_icon_file_ptr, size, 1, in);
-	fclose(in);
+	in.read(_icon_file_ptr, size);
+	in.close();
 }
 
 
@@ -2282,7 +2285,7 @@
 int SimonState::display_savegame_list(int curpos, bool load, char *dst)
 {
 	int slot, last_slot;
-	FILE *in;
+	File in;
 
 	showMessageFormat("\xC");
 
@@ -2291,12 +2294,12 @@
 	slot = curpos;
 
 	while (curpos + 6 > slot) {
-		in = fopen(gen_savename(slot), "rb");
-		if (!in)
+		in.open(gen_savename(slot), getSavePath());
+		if (in.isOpen() == false)
 			break;
 
-		fread(dst, 1, 18, in);
-		fclose(in);
+		in.read(dst, 18);
+		in.close();
 		last_slot = slot;
 		if (slot < 10)
 			showMessageFormat(" ");
@@ -2316,10 +2319,10 @@
 		}
 	} else {
 		if (curpos + 6 == slot) {
-			in = fopen(gen_savename(slot), "rb");
-			if (in != NULL) {
+			in.open(gen_savename(slot), getSavePath());
+			if (in.isOpen() == true) {
 				slot++;
-				fclose(in);
+				in.close();
 			}
 		}
 	}
@@ -3287,20 +3290,20 @@
 void SimonState::readSfxFile(const char *filename)
 {
 	if (!(_game & GAME_SIMON2)) {
-		FILE *in;
+		File in;
 		uint32 size;
 
-		in = fopen_maybe_lowercase(filename);
+		in.open(filename, _gameDataPath);
 
-		if (in == NULL) {
+		if (in.isOpen() == false) {
 			warning("readSfxFile: Cannot load sfx file %s", filename);
 			return;
 		}
 
-		fseek(in, 0, SEEK_END);
-		size = ftell(in);
+		in.seek(0, SEEK_END);
+		size = in.pos();
 
-		fseek(in, 0, SEEK_SET);
+		in.seek(0, SEEK_SET);
 
 		/* stop all sounds */
 		_mixer->stopAll();
@@ -3313,9 +3316,9 @@
 		if (_sfx_heap == NULL)
 			error("readSfxFile: Not enough SFX memory");
 
-		fread(_sfx_heap, size, 1, in);
+		in.read(_sfx_heap, size);
 
-		fclose(in);
+		in.close();
 	} else {
 		int res;
 		uint32 offs;
@@ -4042,7 +4045,7 @@
 void SimonState::read_vga_from_datfile_1(uint vga_id)
 {
 	if (_game == GAME_SIMON1DOS) {
-		FILE *in;
+		File in;
 		char buf[50];
 		uint32 size;
 		// FIXME - weird hack to make the beard show up when wearing it (see bug #590800) 
@@ -4051,20 +4054,20 @@
 		else 
 			sprintf(buf, "%.3d%d.VGA", vga_id >> 1, (vga_id & 1) + 1);
 
-		in = fopen_maybe_lowercase(buf);
-		if (in == NULL) {
+		in.open(buf, _gameDataPath);
+		if (in.isOpen() == false) {
 			warning("read_vga_from_datfile_1: cannot open %s", buf);
 			return;
 		}
 
-		fseek(in, 0, SEEK_END);
-		size = ftell(in);
-		fseek(in, 0, SEEK_SET);
+		in.seek(0, SEEK_END);
+		size = in.pos();
+		in.seek(0, SEEK_SET);
 
-		if (fread(_vga_buffer_pointers[11].vgaFile2, size, 1, in) != 1)
+		if (in.read(_vga_buffer_pointers[11].vgaFile2, size) != size)
 			error("read_vga_from_datfile_1: read failed");
 
-		fclose(in);
+		in.close();
 	} else {
 		uint32 offs_a = _game_offsets_ptr[vga_id];
 		uint32 size = _game_offsets_ptr[vga_id + 1] - offs_a;
@@ -4076,27 +4079,27 @@
 byte *SimonState::read_vga_from_datfile_2(uint id)
 {
 	if (_game == GAME_SIMON1DOS) {
-		FILE *in;
+		File in;
 		char buf[50];
 		uint32 size;
 		byte *dst;
 
 		sprintf(buf, "%.3d%d.VGA", id >> 1, (id & 1) + 1);
 
-		in = fopen_maybe_lowercase(buf);
-		if (in == NULL)
+		in.open(buf, _gameDataPath);
+		if (in.isOpen() == false)
 			error("read_vga_from_datfile_2: cannot open %s", buf);
 
-		fseek(in, 0, SEEK_END);
-		size = ftell(in);
-		fseek(in, 0, SEEK_SET);
+		in.seek(0, SEEK_END);
+		size = in.pos();
+		in.seek(0, SEEK_SET);
 
 		dst = setup_vga_destination(size);
 
-		if (fread(dst, size, 1, in) != 1)
+		if (in.read(dst, size) != size)
 			error("read_vga_from_datfile_2: read failed");
 
-		fclose(in);
+		in.close();
 
 		return dst;
 	} else {
@@ -4113,9 +4116,8 @@
 
 void SimonState::resfile_read(void *dst, uint32 offs, uint32 size)
 {
-	if (fseek(_game_file, offs, SEEK_SET) != 0)
-		error("resfile_read(%d,%d) seek failed", offs, size);
-	if (fread(dst, size, 1, _game_file) != 1)
+	_game_file->seek(offs, SEEK_SET);
+	if (_game_file->read(dst, size) != size)
 		error("resfile_read(%d,%d) read failed", offs, size);
 }
 
@@ -4123,9 +4125,9 @@
 void SimonState::openGameFile()
 {
 	if (_game != GAME_SIMON1DOS) {
-		_game_file = fopen_maybe_lowercase(gss->gme_filename);
+		_game_file->open(gss->gme_filename, _gameDataPath);
 
-		if (_game_file == NULL)
+		if (_game_file->isOpen() == false)
 			error("cannot open game file '%s'", gss->gme_filename);
 
 		_game_offsets_ptr = (uint32 *)malloc(gss->NUM_GAME_OFFSETS * sizeof(uint32));
@@ -4377,7 +4379,7 @@
 void SimonState::shutdown()
 {
 	if (_game_file) {
-		fclose(_game_file);
+		delete _game_file;
 		_game_file = NULL;
 	}
 }
@@ -4451,7 +4453,7 @@
 
 bool SimonState::save_game(uint slot, const char *caption)
 {
-	FILE *f;
+	File f;
 	uint item_index, num_item, i;
 	TimeEvent *te;
 
@@ -4461,42 +4463,42 @@
 	errno = 0;
 #endif
 
-	f = fopen(gen_savename(slot), "wb");
-	if (f == NULL) {
+	f.open(gen_savename(slot), getSavePath(), 2);
+	if (f.isOpen() == false) {
 		_lock_word &= ~0x100;
 		return false;
 	}
 
-	fwrite(caption, 1, 0x12, f);
+	f.write((char*)caption, 0x12);
 
-	fileWriteBE32(f, _itemarray_inited - 1);
-	fileWriteBE32(f, 0xFFFFFFFF);
-	fileWriteBE32(f, 0);
-	fileWriteBE32(f, 0);
+	f.writeDwordBE(_itemarray_inited - 1);
+	f.writeDwordBE(0xFFFFFFFF);
+	f.writeDwordBE(0);
+	f.writeDwordBE(0);
 
 	i = 0;
 	for (te = _first_time_struct; te; te = te->next)
 		i++;
 
-	fileWriteBE32(f, i);
+	f.writeDwordBE(i);
 	for (te = _first_time_struct; te; te = te->next) {
-		fileWriteBE32(f, te->time + _base_time);
-		fileWriteBE16(f, te->subroutine_id);
+		f.writeDwordBE(te->time + _base_time);
+		f.writeWordBE(te->subroutine_id);
 	}
 
 	item_index = 1;
 	for (num_item = _itemarray_inited - 1; num_item; num_item--) {
 		Item *item = _itemarray_ptr[item_index++];
 
-		fileWriteBE16(f, item->parent);
-		fileWriteBE16(f, item->sibling);
-		fileWriteBE16(f, item->unk3);
-		fileWriteBE16(f, item->unk4);
+		f.writeWordBE(item->parent);
+		f.writeWordBE(item->sibling);
+		f.writeWordBE(item->unk3);
+		f.writeWordBE(item->unk4);
 
 		{
 			Child1 *child1 = findChildOfType1(item);
 			if (child1) {
-				fileWriteBE16(f, child1->fr2);
+				f.writeWordBE(child1->fr2);
 			}
 		}
 
@@ -4505,12 +4507,12 @@
 			uint i, j;
 
 			if (child2) {
-				fileWriteBE32(f, child2->avail_props);
+				f.writeDwordBE(child2->avail_props);
 				i = child2->avail_props & 1;
 
 				for (j = 1; j < 16; j++) {
 					if ((1 << j) & child2->avail_props) {
-						fileWriteBE16(f, child2->array[i++]);
+						f.writeWordBE(child2->array[i++]);
 					}
 				}
 			}
@@ -4521,7 +4523,7 @@
 			if (child9) {
 				uint i;
 				for (i = 0; i != 4; i++) {
-					fileWriteBE16(f, child9->array[i]);
+					f.writeWordBE(child9->array[i]);
 				}
 			}
 		}
@@ -4529,19 +4531,19 @@
 
 	/* write the 255 variables */
 	for (i = 0; i != 255; i++) {
-		fileWriteBE16(f, readVariable(i));
+		f.writeWordBE(readVariable(i));
 	}
 
 	/* write the items in array 6 */
 	for (i = 0; i != 10; i++) {
-		fileWriteBE16(f, itemPtrToID(_item_array_6[i]));
+		f.writeWordBE(itemPtrToID(_item_array_6[i]));
 	}
 
 	/* Write the bits in array 1 & 2 */
 	for (i = 0; i != 32; i++)
-		fileWriteBE16(f, _bit_array[i]);
+		f.writeWordBE(_bit_array[i]);
 
-	fclose(f);
+	f.close();
 
 	_lock_word &= ~0x100;
 
@@ -4551,16 +4553,15 @@
 char *SimonState::gen_savename(int slot)
 {
 	static char buf[256];
-	const char *dir = getSavePath();
 
-	sprintf(buf, "%sSAVE.%.3d", dir, slot);
+	sprintf(buf, "SAVE.%.3d", slot);
 	return buf;
 }
 
 bool SimonState::load_game(uint slot)
 {
 	char ident[18];
-	FILE *f;
+	File f;
 	uint num, item_index, i;
 
 	_lock_word |= 0x100;
@@ -4569,33 +4570,32 @@
 	errno = 0;
 #endif
 
-	f = fopen(gen_savename(slot), "rb");
-	if (f == NULL) {
+	f.open(gen_savename(slot), getSavePath(), 1);
+	if (f.isOpen() == false) {
 		_lock_word &= ~0x100;
 		return false;
 	}
 
-	fread(ident, 1, 18, f);
+	f.read(ident, 18);
 
-	num = fileReadBE32(f);
+	num = f.readDwordBE();
 
-	if (fileReadBE32(f) != 0xFFFFFFFF || num != _itemarray_inited - 1) {
-		fclose(f);
+	if (f.readDwordBE() != 0xFFFFFFFF || num != _itemarray_inited - 1) {
+		f.close();
 		_lock_word &= ~0x100;
 		return false;
 	}
 
-	fileReadBE32(f);
-	fileReadBE32(f);
-
+	f.readDwordBE();
+	f.readDwordBE();
 	_no_parent_notify = true;
 
 
 	/* add all timers */
 	killAllTimers();
-	for (num = fileReadBE32(f); num; num--) {
-		uint32 timeout = fileReadBE32(f);
-		uint16 func_to_call = fileReadBE16(f);
+	for (num = f.readDwordBE(); num; num--) {
+		uint32 timeout = f.readDwordBE();
+		uint16 func_to_call = f.readWordBE();
 		addTimeEvent(timeout, func_to_call);
 	}
 
@@ -4603,8 +4603,8 @@
 	for (num = _itemarray_inited - 1; num; num--) {
 		Item *item = _itemarray_ptr[item_index++], *parent_item;
 
-		uint parent = fileReadBE16(f);
-		uint sibling = fileReadBE16(f);
+		uint parent = f.readWordBE();
+		uint sibling = f.readWordBE();
 
 		parent_item = derefItem(parent);
 
@@ -4615,13 +4615,13 @@
 			item->sibling = sibling;
 		}
 
-		item->unk3 = fileReadBE16(f);
-		item->unk4 = fileReadBE16(f);
+		item->unk3 = f.readWordBE();
+		item->unk4 = f.readWordBE();
 
 		{
 			Child1 *child1 = findChildOfType1(item);
 			if (child1 != NULL) {
-				child1->fr2 = fileReadBE16(f);
+				child1->fr2 = f.readWordBE();
 			}
 		}
 
@@ -4629,12 +4629,12 @@
 			Child2 *child2 = findChildOfType2(item);
 			uint i, j;
 			if (child2 != NULL) {
-				child2->avail_props = fileReadBE32(f);
+				child2->avail_props = f.readDwordBE();
 				i = child2->avail_props & 1;
 
 				for (j = 1; j < 16; j++) {
 					if ((1 << j) & child2->avail_props) {
-						child2->array[i++] = fileReadBE16(f);
+						child2->array[i++] = f.readWordBE();
 					}
 				}
 			}
@@ -4645,7 +4645,7 @@
 			if (child9) {
 				uint i;
 				for (i = 0; i != 4; i++) {
-					child9->array[i] = fileReadBE16(f);
+					child9->array[i] = f.readWordBE();
 				}
 			}
 		}
@@ -4654,19 +4654,19 @@
 
 	/* read the 255 variables */
 	for (i = 0; i != 255; i++) {
-		writeVariable(i, fileReadBE16(f));
+		writeVariable(i, f.readWordBE());
 	}
 
 	/* write the items in array 6 */
 	for (i = 0; i != 10; i++) {
-		_item_array_6[i] = derefItem(fileReadBE16(f));
+		_item_array_6[i] = derefItem(f.readWordBE());
 	}
 
 	/* Write the bits in array 1 & 2 */
 	for (i = 0; i != 32; i++)
-		_bit_array[i] = fileReadBE16(f);
+		_bit_array[i] = f.readWordBE();
 
-	fclose(f);
+	f.close();
 
 	_no_parent_notify = false;
 
@@ -4690,12 +4690,13 @@
 
 		_voice_offsets = NULL;
 
-		_voice_file = fopen_maybe_lowercase(s);
-		if (_voice_file == NULL) {
+		_voice_file = new File();
+		_voice_file->open(s, _gameDataPath);
+		if (_voice_file->isOpen() == false) {
 			warning("Cannot open voice file %s, trying %s", s, s2);
 			if (s2) {
-				_voice_file = fopen_maybe_lowercase(s2);
-				if (_voice_file == NULL) {
+				_voice_file->open(s2, _gameDataPath);
+				if (_voice_file->isOpen() == false) {
 					warning("Cannot open voice file %s", s2);
 					return;
 				}
@@ -4707,18 +4708,19 @@
 		if (_voice_offsets == NULL)
 			error("Out of memory for voice offsets");
 
-		if (fread(_voice_offsets, gss->NUM_VOICE_RESOURCES * sizeof(uint32), 1, _voice_file) != 1)
+		if (_voice_file->read(_voice_offsets, gss->NUM_VOICE_RESOURCES * sizeof(uint32)) != gss->NUM_VOICE_RESOURCES * sizeof(uint32))
 			error("Cannot read voice offsets");
 
 		_effects_offsets = NULL;
-		_effects_file = fopen_maybe_lowercase(e);
-		if (_effects_file != NULL)
+		_effects_file = new File();
+		_effects_file->open(e, _gameDataPath);
+		if (_effects_file->isOpen() == true)
 		{
 			_effects_offsets = (uint32 *)malloc(gss->NUM_EFFECTS_RESOURCES * sizeof(uint32));
 			if (_effects_offsets == NULL)
 				error("Out of memory for effects offsets");
 
-			if (fread(_effects_offsets, gss->NUM_EFFECTS_RESOURCES * sizeof(uint32), 1, _effects_file) != 1)
+			if (_effects_file->read(_effects_offsets, gss->NUM_EFFECTS_RESOURCES * sizeof(uint32)) != gss->NUM_EFFECTS_RESOURCES * sizeof(uint32))
 				error("Cannot read effects offsets");
 		}
 
@@ -4777,13 +4779,13 @@
 void SimonState::playVoice(uint voice)
 {
 	_mixer->stop(_voice_sound);
-	fseek(_voice_file, _voice_offsets[voice], SEEK_SET);
+	_voice_file->seek(_voice_offsets[voice], SEEK_SET);
 
 	if (!_effects_offsets) {			/* WAVE audio */
 		WaveHeader wave_hdr;
 		uint32 data[2];
 
-		if (fread(&wave_hdr, sizeof(wave_hdr), 1, _voice_file) != 1 ||
+		if (_voice_file->read(&wave_hdr, sizeof(wave_hdr)) != sizeof(wave_hdr) ||
 				wave_hdr.riff != MKID('RIFF') || wave_hdr.wave != MKID('WAVE')
 				|| wave_hdr.fmt != MKID('fmt ') || READ_LE_UINT16(&wave_hdr.format_tag) != 1
 				|| READ_LE_UINT16(&wave_hdr.channels) != 1
@@ -4792,10 +4794,10 @@
 			return;
 		}
 
-		fseek(_voice_file, READ_LE_UINT32(&wave_hdr.size) - sizeof(wave_hdr) + 20, SEEK_CUR);
+		_voice_file->seek(READ_LE_UINT32(&wave_hdr.size) - sizeof(wave_hdr) + 20, SEEK_CUR);
 
-		data[0] = fileReadLE32(_voice_file);
-		data[1] = fileReadLE32(_voice_file);
+		data[0] = _voice_file->readDwordLE();
+		data[1] = _voice_file->readDwordLE();
 		if (												//fread(data, sizeof(data), 1, _voice_file) != 1 ||
 				 data[0] != 'atad') {
 			warning("playVoice(%d): cannot read data header", voice);
@@ -4803,7 +4805,7 @@
 		}
 
 		byte *buffer = (byte *)malloc(data[1]);
-		fread(buffer, data[1], 1, _voice_file);
+		_voice_file->read(buffer, data[1]);
 
 		_mixer->playRaw(&_voice_sound, buffer, data[1], READ_LE_UINT32(&wave_hdr.samples_per_sec),
 										 SoundMixer::FLAG_UNSIGNED);
@@ -4812,21 +4814,21 @@
 		VocBlockHeader voc_block_hdr;
 		uint32 size;
 
-		if (fread(&voc_hdr, sizeof(voc_hdr), 1, _voice_file) != 1 ||
+		if (_voice_file->read(&voc_hdr, sizeof(voc_hdr)) != sizeof(voc_hdr) ||
 				strncmp((char *)voc_hdr.desc, "Creative Voice File\x1A", 10) != 0) {
 			warning("playVoice(%d): cannot read voc header", voice);
 			return;
 		}
 
-		fread(&size, 4, 1, _voice_file);
+		_voice_file->read(&size, 4);
 		size = size & 0xffffff;
-		fseek(_voice_file, -1, SEEK_CUR);
-		fread(&voc_block_hdr, sizeof(voc_block_hdr), 1, _voice_file);
+		_voice_file->seek(-1, SEEK_CUR);
+		_voice_file->read(&voc_block_hdr, sizeof(voc_block_hdr));
 
 		uint32 samples_per_sec = 1000000L / (256L - (long)voc_block_hdr.tc);
 
 		byte *buffer = (byte *)malloc(size);
-		fread(buffer, size, 1, _voice_file);
+		_voice_file->read(buffer, size);
 
 		_mixer->playRaw(&_voice_sound, buffer, size, samples_per_sec, SoundMixer::FLAG_UNSIGNED);
 	}
@@ -4842,24 +4844,24 @@
 			uint32 size;
 
 			_mixer->stop(_effects_sound);
-			fseek(_effects_file, _effects_offsets[sound], SEEK_SET);
+			_effects_file->seek(_effects_offsets[sound], SEEK_SET);
 
 
-			if (fread(&voc_hdr, sizeof(voc_hdr), 1, _effects_file) != 1 ||
+			if (_effects_file->read(&voc_hdr, sizeof(voc_hdr)) != sizeof(voc_hdr) ||
 					strncmp((char *)voc_hdr.desc, "Creative Voice File\x1A", 10) != 0) {
 				warning("playSound(%d): cannot read voc header", sound);
 				return;
 			}
 
-			fread(&size, 4, 1, _effects_file);
+			_effects_file->read(&size, 4);
 			size = size & 0xffffff;
-			fseek(_effects_file, -1, SEEK_CUR);
-			fread(&voc_block_hdr, sizeof(voc_block_hdr), 1, _effects_file);
+			_effects_file->seek(-1, SEEK_CUR);
+			_effects_file->read(&voc_block_hdr, sizeof(voc_block_hdr));
 
 			uint32 samples_per_sec = 1000000L / (256L - (long)voc_block_hdr.tc);
 
 			byte *buffer = (byte *)malloc(size);
-			fread(buffer, size, 1, _effects_file);
+			_effects_file->read(buffer, size);
 
 			_mixer->playRaw(&_effects_sound, buffer, size, samples_per_sec, SoundMixer::FLAG_UNSIGNED);
 		} else {
@@ -4897,26 +4899,24 @@
 
 void SimonState::playMusic(uint music)
 {
-	FILE *f;
-
 	midi.shutdown();
 
 	/* FIXME: not properly implemented */
 	if (_game & GAME_WIN) {
-		fseek(_game_file, _game_offsets_ptr[gss->MUSIC_INDEX_BASE + music] - 1, SEEK_SET);
-		f = _game_file;
-
+		_game_file->seek(_game_offsets_ptr[gss->MUSIC_INDEX_BASE + music] - 1, SEEK_SET);
+		File *f = _game_file;
 		midi.read_all_songs(f);
 	} else {
 		char buf[50];
+		File *f = new File();
 		sprintf(buf, "MOD%d.MUS", music);
-		f = fopen_maybe_lowercase(buf);
-		if (f == NULL) {
+		f->open(buf, _gameDataPath);
+		if (f->isOpen() == false) {
 			warning("Cannot load music from '%s'", buf);
 			return;
 		}
 		midi.read_all_songs_old(f);
-		fclose(f);
+		f->close();
 	}
 
 	midi.initialize();

Index: simon.h
===================================================================
RCS file: /cvsroot/scummvm/scummvm/simon/simon.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- simon.h	31 Aug 2002 13:29:10 -0000	1.2
+++ simon.h	16 Sep 2002 08:22:30 -0000	1.3
@@ -26,6 +26,7 @@
 #include "engine.h"
 #include "simon/midi.h"
 #include "sound/mixer.h"
+#include "file.h"
 
 /* Various other settings */
 //#define DUMP_CONTINOUS_MAINSCRIPT
@@ -39,14 +40,7 @@
 //#define DUMP_BITMAPS_FILE_NR 8
 //#define DUMP_DRAWN_BITMAPS
 
-uint fileReadByte(FILE *in);
-uint fileReadBE16(FILE *in);
-uint fileReadLE16(FILE *in);
-uint32 fileReadBE32(FILE *in);
-uint32 fileReadLE32(FILE *in);
-void fileWriteBE32(FILE *in, uint32 value);
-void fileWriteBE16(FILE *in, uint16 value);
-uint fileReadItemID(FILE *in);
+uint fileReadItemID(File *in);
 
 #define ARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
 #define CHECK_BOUNDS(x,y) assert((uint)(x)<ARRAYSIZE(y))
@@ -130,10 +124,10 @@
 	};
 
 
-	FILE *_game_file;
-	FILE *_voice_file;
+	File *_game_file;
+	File *_voice_file;
 	uint32 *_voice_offsets;
-	FILE *_effects_file;
+	File *_effects_file;
 	uint32 *_effects_offsets;
 
 	byte *_stripped_txt_mem;
@@ -357,16 +351,16 @@
 	SimonState(GameDetector *detector, OSystem *syst);
 	virtual ~SimonState();
 
-	int allocGamePcVars(FILE *in);
+	int allocGamePcVars(File *in);
 	Item *allocItem1();
 	void loginPlayerHelper(Item *item, int a, int b);
 	void loginPlayer();
 	void allocateStringTable(int num);
 	void setupStringTable(byte *mem, int num);
 	void setupLocalStringTable(byte *mem, int num);
-	void readGamePcText(FILE *in);
-	void readItemChildren(FILE *in, Item *item, uint tmp);
-	void readItemFromGamePc(FILE *in, Item *item);
+	void readGamePcText(File *in);
+	void readItemChildren(File *in, Item *item, uint tmp);
+	void readItemFromGamePc(File *in, Item *item);
 	bool loadGamePcFile(const char *filename);
 
 	byte *allocateItem(uint size);
@@ -380,11 +374,11 @@
 	void allocTablesHeap();
 
 	Subroutine *createSubroutine(uint a);
-	void readSubroutine(FILE *in, Subroutine *sub);
+	void readSubroutine(File *in, Subroutine *sub);
 	SubroutineLine *createSubroutineLine(Subroutine *sub, int a);
-	void readSubroutineLine(FILE *in, SubroutineLine *new_table, Subroutine *sub);
-	byte *readSingleOpcode(FILE *in, byte *ptr);
-	void readSubroutineBlock(FILE *in);
+	void readSubroutineLine(File *in, SubroutineLine *new_table, Subroutine *sub);
+	byte *readSingleOpcode(File *in, byte *ptr);
+	void readSubroutineBlock(File *in);
 
 	Subroutine *getSubroutineByID(uint subroutine_id);
 
@@ -509,16 +503,16 @@
 
 
 	uint loadTextFile(const char *filename, byte *dst);
-	FILE *openTablesFile(const char *filename);
-	void closeTablesFile(FILE *in);
+	File *openTablesFile(const char *filename);
+	void closeTablesFile(File *in);
 
 	uint loadTextFile_simon1(const char *filename, byte *dst);
-	FILE *openTablesFile_simon1(const char *filename);
-	void closeTablesFile_simon1(FILE *in);
+	File *openTablesFile_simon1(const char *filename);
+	void closeTablesFile_simon1(File *in);
 
 	uint loadTextFile_gme(const char *filename, byte *dst);
-	FILE *openTablesFile_gme(const char *filename);
-	void closeTablesFile_gme(FILE *in);
+	File *openTablesFile_gme(const char *filename);
+	void closeTablesFile_gme(File *in);
 
 	void readSfxFile(const char *filename);
 
@@ -796,8 +790,6 @@
 	void set_dummy_cursor();
 
 	void set_volume(byte volume);
-
-	FILE *fopen_maybe_lowercase(const char *filename);
 
 	void save_or_load_dialog(bool load);
 	void o_unk_132_helper_3();

--- sys.cpp DELETED ---





More information about the Scummvm-git-logs mailing list