Path: blob/main/misc/emulator/xnes/snes9x/jma/winout.cpp
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#include "winout.h"1920namespace NStream {21namespace NWindow {2223void COut::Create(UINT32 aKeepSizeBefore, UINT32 aKeepSizeAfter, UINT32 aKeepSizeReserv)24{25m_Pos = 0;26m_PosLimit = aKeepSizeReserv + aKeepSizeBefore;27m_KeepSizeBefore = aKeepSizeBefore;28m_KeepSizeAfter = aKeepSizeAfter;29m_KeepSizeReserv = aKeepSizeReserv;30m_StreamPos = 0;31m_MoveFrom = m_KeepSizeReserv;32m_WindowSize = aKeepSizeBefore;33UINT32 aBlockSize = m_KeepSizeBefore + m_KeepSizeAfter + m_KeepSizeReserv;34delete []m_Buffer;35m_Buffer = new BYTE[aBlockSize];36}3738COut::~COut()39{40delete []m_Buffer;41}4243void COut::SetWindowSize(UINT32 aWindowSize)44{45m_WindowSize = aWindowSize;46m_MoveFrom = m_KeepSizeReserv + m_KeepSizeBefore - aWindowSize;47}4849void COut::Init(ISequentialOutStream *aStream, bool aSolid)50{51m_Stream = aStream;5253if(aSolid)54m_StreamPos = m_Pos;55else56{57m_Pos = 0;58m_PosLimit = m_KeepSizeReserv + m_KeepSizeBefore;59m_StreamPos = 0;60}61}6263HRESULT COut::Flush()64{65UINT32 aSize = m_Pos - m_StreamPos;66if(aSize == 0)67return S_OK;68UINT32 aProcessedSize;69HRESULT aResult = m_Stream->Write(m_Buffer + m_StreamPos, aSize, &aProcessedSize);70if (aResult != S_OK)71return aResult;72if (aSize != aProcessedSize)73return E_FAIL;74m_StreamPos = m_Pos;75return S_OK;76}7778void COut::MoveBlockBackward()79{80HRESULT aResult = Flush();81if (aResult != S_OK)82throw aResult;83memmove(m_Buffer, m_Buffer + m_MoveFrom, m_WindowSize + m_KeepSizeAfter);84m_Pos -= m_MoveFrom;85m_StreamPos -= m_MoveFrom;86}8788}}899091