/***************************************************************************1* Copyright (C) 2007 by Sindre Aamås *2* [email protected] *3* *4* This program is free software; you can redistribute it and/or modify *5* it under the terms of the GNU General Public License version 2 as *6* published by the Free Software Foundation. *7* *8* This program is distributed in the hope that it will be useful, *9* but WITHOUT ANY WARRANTY; without even the implied warranty of *10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *11* GNU General Public License version 2 for more details. *12* *13* You should have received a copy of the GNU General Public License *14* version 2 along with this program; if not, write to the *15* Free Software Foundation, Inc., *16* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *17***************************************************************************/18#ifndef ENVELOPE_UNIT_H19#define ENVELOPE_UNIT_H2021#include "sound_unit.h"22#include "../savestate.h"23#include "newstate.h"2425namespace gambatte {2627class EnvelopeUnit : public SoundUnit {28public:29struct VolOnOffEvent {30virtual ~VolOnOffEvent() {}31virtual void operator()(unsigned long /*cc*/) {}32};3334private:35static VolOnOffEvent nullEvent;36VolOnOffEvent &volOnOffEvent;37unsigned char nr2;38unsigned char volume;3940public:41explicit EnvelopeUnit(VolOnOffEvent &volOnOffEvent = nullEvent);42void event();43bool dacIsOn() const { return nr2 & 0xF8; }44unsigned getVolume() const { return volume; }45bool nr2Change(unsigned newNr2);46bool nr4Init(unsigned long cycleCounter);47void reset();48void loadState(const SaveState::SPU::Env &estate, unsigned nr2, unsigned long cc);4950template<bool isReader>void SyncState(NewState *ns);51};5253}5455#endif565758