Path: blob/main/misc/emulator/xnes/snes9x/jma/inbyte.h
28798 views
/*1Copyright (C) 2002 Andrea Mazzoleni ( http://advancemame.sf.net )2Copyright (C) 2001-4 Igor Pavlov ( http://www.7-zip.org )34This library is free software; you can redistribute it and/or5modify it under the terms of the GNU Lesser General Public6License version 2.1 as published by the Free Software Foundation.78This library is distributed in the hope that it will be useful,9but WITHOUT ANY WARRANTY; without even the implied warranty of10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11Lesser General Public License for more details.1213You should have received a copy of the GNU Lesser General Public14License along with this library; if not, write to the Free Software15Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA16*/1718#ifndef __STREAM_INBYTE_H19#define __STREAM_INBYTE_H2021#include "iiostrm.h"2223namespace NStream {2425class CInByte26{27UINT64 m_ProcessedSize;28BYTE *m_BufferBase;29UINT32 m_BufferSize;30BYTE *m_Buffer;31BYTE *m_BufferLimit;32ISequentialInStream* m_Stream;33bool m_StreamWasExhausted;3435bool ReadBlock();3637public:38CInByte(UINT32 aBufferSize = 0x100000);39~CInByte();4041void Init(ISequentialInStream *aStream);4243bool ReadByte(BYTE &aByte)44{45if(m_Buffer >= m_BufferLimit)46if(!ReadBlock())47return false;48aByte = *m_Buffer++;49return true;50}51BYTE ReadByte()52{53if(m_Buffer >= m_BufferLimit)54if(!ReadBlock())55return 0x0;56return *m_Buffer++;57}58void ReadBytes(void *aData, UINT32 aSize, UINT32 &aProcessedSize)59{60for(aProcessedSize = 0; aProcessedSize < aSize; aProcessedSize++)61if (!ReadByte(((BYTE *)aData)[aProcessedSize]))62return;63}64bool ReadBytes(void *aData, UINT32 aSize)65{66UINT32 aProcessedSize;67ReadBytes(aData, aSize, aProcessedSize);68return (aProcessedSize == aSize);69}70UINT64 GetProcessedSize() const { return m_ProcessedSize + (m_Buffer - m_BufferBase); }71};7273}7475#endif767778