Path: blob/main/misc/emulator/xnes/snes9x/jma/iiostrm.cpp
28798 views
/*1Copyright (C) 2005-2006 NSRT Team ( http://nsrt.edgeemu.com )2Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )3Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )45This library is free software; you can redistribute it and/or6modify it under the terms of the GNU Lesser General Public7License version 2.1 as published by the Free Software Foundation.89This library is distributed in the hope that it will be useful,10but WITHOUT ANY WARRANTY; without even the implied warranty of11MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12Lesser General Public License for more details.1314You should have received a copy of the GNU Lesser General Public15License along with this library; if not, write to the Free Software16Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA17*/1819#include "portable.h"20#include "iiostrm.h"21#include "crc32.h"2223HRESULT ISequentialInStream_Array::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)24{25if (aSize > size)26{27aSize = size;28}2930*aProcessedSize = aSize;31memcpy(aData, data, aSize);32size -= aSize;33data += aSize;34return(S_OK);35}3637HRESULT ISequentialOutStream_Array::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)38{39if (aSize > size)40{41overflow = true;42aSize = size;43}4445*aProcessedSize = aSize;46memcpy(data, aData, aSize);47size -= aSize;48data += aSize;49total += aSize;50return(S_OK);51}5253HRESULT ISequentialInStream_String::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)54{55if (aSize > data.size())56{57aSize = data.size();58}5960*aProcessedSize = aSize;61memcpy(aData, data.c_str(), aSize);62data.erase(0, aSize);63return(S_OK);64}6566HRESULT ISequentialOutStream_String::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)67{68*aProcessedSize = aSize;69data.append((const char *)aData, aSize);70total += aSize;71return(S_OK);72}7374HRESULT ISequentialInStream_Istream::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)75{76data.read((char *)aData, aSize);77*aProcessedSize = data.gcount();78return(S_OK);79}8081HRESULT ISequentialOutStream_Ostream::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)82{83*aProcessedSize = aSize;84data.write((char *)aData, aSize);85total += aSize;86return(S_OK);87}88899091HRESULT ISequentialInStreamCRC32_Array::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)92{93ISequentialInStream_Array::Read(aData, aSize, aProcessedSize);94crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);95return(S_OK);96}9798HRESULT ISequentialOutStreamCRC32_Array::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)99{100ISequentialOutStream_Array::Write(aData, aSize, aProcessedSize);101crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);102return(S_OK);103}104105HRESULT ISequentialInStreamCRC32_String::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)106{107ISequentialInStream_String::Read(aData, aSize, aProcessedSize);108crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);109return(S_OK);110}111112HRESULT ISequentialOutStreamCRC32_String::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)113{114ISequentialOutStream_String::Write(aData, aSize, aProcessedSize);115crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);116return(S_OK);117}118119HRESULT ISequentialInStreamCRC32_Istream::Read(void *aData, UINT32 aSize, UINT32 *aProcessedSize)120{121ISequentialInStream_Istream::Read(aData, aSize, aProcessedSize);122crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);123return(S_OK);124}125126HRESULT ISequentialOutStreamCRC32_Ostream::Write(const void *aData, UINT32 aSize, UINT32 *aProcessedSize)127{128ISequentialOutStream_Ostream::Write(aData, aSize, aProcessedSize);129crc32 = CRC32lib::CRC32((const unsigned char *)aData, *aProcessedSize, ~crc32);130return(S_OK);131}132133134