/***************************************************************************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 LY_COUNTER_H19#define LY_COUNTER_H2021#include "newstate.h"2223namespace gambatte {2425struct SaveState;2627class LyCounter {28unsigned long time_;29unsigned short lineTime_;30unsigned char ly_;31bool ds;3233public:34LyCounter();35void doEvent();36bool isDoubleSpeed() const { return ds; }3738unsigned long frameCycles(const unsigned long cc) const {39return ly_ * 456ul + lineCycles(cc);40}4142unsigned lineCycles(const unsigned long cc) const {43return 456u - ((time_ - cc) >> isDoubleSpeed());44}4546unsigned lineTime() const { return lineTime_; }47unsigned ly() const { return ly_; }48unsigned long nextLineCycle(unsigned lineCycle, unsigned long cycleCounter) const;49unsigned long nextFrameCycle(unsigned long frameCycle, unsigned long cycleCounter) const;50void reset(unsigned long videoCycles, unsigned long lastUpdate);51void setDoubleSpeed(bool ds_in);52unsigned long time() const { return time_; }5354template<bool isReader>void SyncState(NewState *ns);55};5657}5859#endif606162