changeset 1195:b8e919aa6350 trunk

[svn] - Jma_File_Reader class
author nenolod
date Tue, 13 Jun 2006 21:23:52 -0700
parents 0c0a5ff7b20b
children ec7998847818
files ChangeLog Plugins/Input/console/Jma_File.cpp Plugins/Input/console/Jma_File.h Plugins/Input/console/Makefile.in
diffstat 4 files changed, 203 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Jun 13 20:37:25 2006 -0700
+++ b/ChangeLog	Tue Jun 13 21:23:52 2006 -0700
@@ -1,3 +1,39 @@
+2006-06-14 03:37:25 +0000  William Pitcock <nenolod@nenolod.net>
+  revision [1298]
+  - add libjma (a hopefully portable snapshot of the ZSNES JMA implementation)
+  
+
+  Changes:        Modified:
+  +3 -1           trunk/Plugins/Input/console/Makefile.in  
+  +28 -0          trunk/Plugins/Input/console/libjma/7z.h  
+  +50 -0          trunk/Plugins/Input/console/libjma/7zlzma.cpp  
+  +19 -0          trunk/Plugins/Input/console/libjma/Makefile  
+  +6 -0           trunk/Plugins/Input/console/libjma/README  
+  +73 -0          trunk/Plugins/Input/console/libjma/aribitcd.h  
+  +29 -0          trunk/Plugins/Input/console/libjma/ariconst.h  
+  +12 -0          trunk/Plugins/Input/console/libjma/ariprice.h  
+  +126 -0         trunk/Plugins/Input/console/libjma/btreecd.h  
+  +80 -0          trunk/Plugins/Input/console/libjma/crc32.cpp  
+  +26 -0          trunk/Plugins/Input/console/libjma/crc32.h  
+  +132 -0         trunk/Plugins/Input/console/libjma/iiostrm.cpp  
+  +210 -0         trunk/Plugins/Input/console/libjma/iiostrm.h  
+  +60 -0          trunk/Plugins/Input/console/libjma/inbyte.cpp  
+  +76 -0          trunk/Plugins/Input/console/libjma/inbyte.h  
+  +550 -0         trunk/Plugins/Input/console/libjma/jma.cpp  
+  +88 -0          trunk/Plugins/Input/console/libjma/jma.h  
+  +93 -0          trunk/Plugins/Input/console/libjma/lencoder.h  
+  +122 -0         trunk/Plugins/Input/console/libjma/litcoder.h  
+  +41 -0          trunk/Plugins/Input/console/libjma/lzma.cpp  
+  +124 -0         trunk/Plugins/Input/console/libjma/lzma.h  
+  +298 -0         trunk/Plugins/Input/console/libjma/lzmadec.cpp  
+  +82 -0          trunk/Plugins/Input/console/libjma/lzmadec.h  
+  +83 -0          trunk/Plugins/Input/console/libjma/portable.h  
+  +60 -0          trunk/Plugins/Input/console/libjma/rcdefs.h  
+  +143 -0         trunk/Plugins/Input/console/libjma/rngcoder.h  
+  +89 -0          trunk/Plugins/Input/console/libjma/winout.cpp  
+  +89 -0          trunk/Plugins/Input/console/libjma/winout.h  
+
+
 2006-06-13 15:36:56 +0000  Yoshiki Yazawa <yaz@cc.rim.or.jp>
   revision [1296]
   filesize must be cached, otherwise lookup loop will crash.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/console/Jma_File.cpp	Tue Jun 13 21:23:52 2006 -0700
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2006 William Pitcock, et al.
+ * All rights reserved.
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software module and associated documentation files
+ * (the "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
+ * persons to whom the Software is furnished to do so, subject to the following
+ * conditions: 
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include "libjma/jma.h"
+#include "Jma_File.h"
+
+#include <vector>
+
+// Jma_File_Reader
+
+Jma_File_Reader::Jma_File_Reader()
+{
+}
+
+Jma_File_Reader::~Jma_File_Reader()
+{
+	close();
+}
+
+Jma_File_Reader::error_t Jma_File_Reader::open( const char *jmaspec, const char* file )
+{
+	jma_ = new JMA::jma_open(jmaspec);
+	std::vector<JMA::jma_public_file_info> file_info = jma_->get_files_info();
+	bool found = false;
+	int size_;
+	std::string m = file;
+
+	for (std::vector<JMA::jma_public_file_info>::iterator i = file_info.begin();
+		i != file_info.end(); i++)
+	{
+		if (m == i->name)
+		{
+			found = true;
+			size_ = i->size;
+			break;
+		}
+	}
+
+	if (found == false)
+		return "JMA container entry not found";
+
+	buf_ = new unsigned char[size_];
+
+	jma_->extract_file(m, buf_);
+
+	bufptr_ = buf_;
+
+	return NULL;
+}
+
+long Jma_File_Reader::size() const
+{
+	return size_;
+}
+
+long Jma_File_Reader::read_avail( unsigned char* p, long s )
+{
+	p = new unsigned char[s];
+
+	for (long i = 0; i < s; i++)
+		p[i] = *bufptr_++;
+
+	return s;
+}
+
+long Jma_File_Reader::tell() const
+{
+	long i = (char *) bufptr_ - (char *) buf_;
+
+	return i;
+}
+
+Jma_File_Reader::error_t Jma_File_Reader::seek( long n )
+{
+	if (n > size_)
+		return "Error seeking in file";
+
+	/* move the iter to this position */
+	bufptr_ = buf_ + n;
+
+	return NULL;
+}
+
+void Jma_File_Reader::close()
+{
+	delete buf_;
+	delete jma_;
+
+	size_ = 0;
+	bufptr_ = NULL;
+	buf_ = NULL;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Plugins/Input/console/Jma_File.h	Tue Jun 13 21:23:52 2006 -0700
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2006 William Pitcock, et al.
+ * All rights reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software module and associated documentation files
+ * (the "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to permit
+ * persons to whom the Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ *     The above copyright notice and this permission notice shall be
+ *     included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
+ * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
+ * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+ * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+ * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+// JMA file access
+
+#ifndef JMA_FILE_H
+#define JMA_FILE_H
+
+#include "abstract_file.h"
+
+class Jma_File_Reader : public File_Reader {
+private:
+	unsigned char *buf_;
+	unsigned char *bufptr_;
+	long size_;
+	JMA::jma_open *jma_;
+public:
+	Jma_File_Reader();
+	~Jma_File_Reader();
+	
+	// JMA::jma_open is the container class, oh how fucked up
+	error_t open( const char *, const char* );
+	
+	long size() const;
+	long read_avail( unsigned char*, long );
+	
+	long tell() const;
+	error_t seek( long );
+	
+	void close();
+};
+
+#endif
+
--- a/Plugins/Input/console/Makefile.in	Tue Jun 13 20:37:25 2006 -0700
+++ b/Plugins/Input/console/Makefile.in	Tue Jun 13 21:23:52 2006 -0700
@@ -17,6 +17,7 @@
 	Gb_Oscs.cpp     \
 	Gbs_Emu.cpp     \
 	Gym_Emu.cpp     \
+	Jma_File.cpp	\
 	Multi_Buffer.cpp    \
 	Music_Emu.cpp       \
 	Nes_Apu.cpp     \