Path: blob/main/misc/emulator/xnes/snes9x/jma/inbyte.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 "inbyte.h"2021namespace NStream{2223CInByte::CInByte(UINT32 aBufferSize):24m_BufferBase(0),25m_BufferSize(aBufferSize)26{27m_BufferBase = new BYTE[m_BufferSize];28}2930CInByte::~CInByte()31{32delete []m_BufferBase;33}3435void CInByte::Init(ISequentialInStream *aStream)36{37m_Stream = aStream;38m_ProcessedSize = 0;39m_Buffer = m_BufferBase;40m_BufferLimit = m_Buffer;41m_StreamWasExhausted = false;42}4344bool CInByte::ReadBlock()45{46if (m_StreamWasExhausted)47return false;48m_ProcessedSize += (m_Buffer - m_BufferBase);49UINT32 aNumProcessedBytes;50HRESULT aResult = m_Stream->Read(m_BufferBase, m_BufferSize, &aNumProcessedBytes);51if (aResult != S_OK)52throw aResult;53m_Buffer = m_BufferBase;54m_BufferLimit = m_Buffer + aNumProcessedBytes;55m_StreamWasExhausted = (aNumProcessedBytes == 0);56return (!m_StreamWasExhausted);57}5859}606162