[Scummvm-cvs-logs] SF.net SVN: scummvm:[51437] tools/branches/gsoc2010-decompiler/decompiler/ kyra

pidgeot at users.sourceforge.net pidgeot at users.sourceforge.net
Wed Jul 28 23:51:57 CEST 2010


Revision: 51437
          http://scummvm.svn.sourceforge.net/scummvm/?rev=51437&view=rev
Author:   pidgeot
Date:     2010-07-28 21:51:57 +0000 (Wed, 28 Jul 2010)

Log Message:
-----------
Read IFF data from KYRA script files

Note: this currently segfaults in the destructor.
Committing to run this through valgrind on other machine.

Modified Paths:
--------------
    tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
    tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h

Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-07-28 21:50:46 UTC (rev 51436)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.cpp	2010-07-28 21:51:57 UTC (rev 51437)
@@ -21,7 +21,63 @@
  */
 
 #include "disassembler.h"
+#include <iostream>
+#include <boost/format.hpp>
 
+IFFChunk::IFFChunk() {
+	_data = NULL;
+}
+
+Kyra::Disassembler::~Disassembler() {
+	if (_textChunk._data)
+		delete [] _textChunk._data;
+	if (_ordrChunk._data)
+		delete [] _ordrChunk._data;
+	if (_dataChunk._data)
+		delete [] _dataChunk._data;
+}
+
 void Kyra::Disassembler::doDisassemble() throw(UnknownOpcodeException) {
+	// Load data
+	IFF_ID id;
+	id = _f.readUint32BE();
+	if (id != MKID_BE('FORM')) {
+		std::cerr << boost::format("ERROR: Unexpected IFF magic number 0x%08X (expected 0x%08X)!\n") % id % MKID_BE('FORM');
+		return;
+	}
+	_f.readUint32BE(); // Skip file length
+	_formType = _f.readUint32BE();
+	if (_formType != MKID_BE('EMC2')) {
+		std::cerr << boost::format("ERROR: Unexpected file type 0x%08X (expected 0x%08X)!\n") % _formType % MKID_BE('EMC2');
+		return;
+	}
+
+	// Read chunks
+	do {
+		IFFChunk temp;
+		temp._chunkType = _f.readUint32BE();
+		temp._size = _f.readUint32BE();
+		temp._data = new uint8[temp._size];
+		_f.read_throwsOnError(&temp._data, temp._size);
+		switch (temp._chunkType) {
+		case MKID_BE('TEXT'):
+			_textChunk = temp;
+			break;
+		case MKID_BE('ORDR'):
+			_ordrChunk = temp;
+			break;
+		case MKID_BE('DATA'):
+			_dataChunk = temp;
+			break;
+		default:
+			std::cerr << boost::format("ERROR: Unexpected chunk type 0x%08X!\n") % temp._chunkType;
+			delete [] temp._data;
+			return;
+		}
+		if (temp._size % 2 != 0) // skip padding byte
+			_f.readByte();
+	} while (_f.pos() != (int)_f.size());
+
+	// Disassemble
 	// TODO
 }

Modified: tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h
===================================================================
--- tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h	2010-07-28 21:50:46 UTC (rev 51436)
+++ tools/branches/gsoc2010-decompiler/decompiler/kyra/disassembler.h	2010-07-28 21:51:57 UTC (rev 51437)
@@ -24,19 +24,35 @@
 #define DEC_KYRA_DISASM_H
 
 #include "decompiler/disassembler.h"
+#include "common/endian.h"
 
+typedef uint32 IFF_ID;
+
+struct IFFChunk {
+public:
+	IFF_ID _chunkType;
+	uint32 _size;
+	uint8 *_data;
+
+	IFFChunk();
+};
+
 namespace Kyra {
 
 /**
  * Disassembler for KYRA.
  */
 class Disassembler : public ::Disassembler {
+private:
+	IFF_ID _formType;    ///< File type as listed in the IFF formatted file.
+	IFFChunk _textChunk; ///< Contents of the TEXT chunk.
+	IFFChunk _ordrChunk; ///< Contents of the ORDR chunk.
+  IFFChunk _dataChunk; ///< Contents of the DATA chunk.
 public:
+	~Disassembler();
 	void doDisassemble() throw(UnknownOpcodeException);
 };
 
 } // End of namespace Kyra
 
 #endif
-
-


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list