// Meteor - A Nintendo Gameboy Advance emulator1// Copyright (C) 2009-2011 Philippe Daouadi2//3// This program is free software: you can redistribute it and/or modify4// it under the terms of the GNU General Public License as published by5// the Free Software Foundation, either version 3 of the License, or6// (at your option) any later version.7//8// This program is distributed in the hope that it will be useful,9// but WITHOUT ANY WARRANTY; without even the implied warranty of10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the11// GNU General Public License for more details.12//13// You should have received a copy of the GNU General Public License14// along with this program. If not, see <http://www.gnu.org/licenses/>.1516#ifndef __CLOCK_H__17#define __CLOCK_H__1819#include <stdint.h>20#include <climits>21#include <vector>22#include <istream>23#include <ostream>2425namespace AMeteor26{27class Clock28{29public :30Clock ()31{32Reset();33}3435void Reset ();3637void ResetCounter()38{39m_count = 0;40}41unsigned int GetCounter() const42{43return m_count;44}4546void TimePass (unsigned short cycles)47{48m_cycles += cycles;49}50void Commit ();51void WaitForNext ();5253void AddLcd (uint32_t cycles)54{55// The lcd clock is always enabled56m_lcd += cycles;57SetFirst();58}5960void AddTimer (uint8_t num, uint32_t cycles)61{62if (m_timer[num] == INT_MAX)63m_timer[num] = cycles;64else65m_timer[num] += cycles;66SetFirst();67}68void SetTimer (uint8_t num, uint32_t cycles)69{70m_timer[num] = cycles;71SetFirst();72}73void DisableTimer (uint8_t num)74{75m_timer[num] = INT_MAX;76SetFirst();77}78int GetTimer (uint8_t num)79{80return m_timer[num];81}8283//void SetBattery (uint32_t cycles)84//{85// m_battery = cycles;86//}87//void DisableBattery ()88//{89// m_battery = INT_MAX;90// no need to SetFirst since battery will be disabled only in TimeEvent91//}9293bool SaveState (std::ostream& stream);94bool LoadState (std::istream& stream);9596private :97// XXX freq98static const int SOUND_PERIOD = 380;99100unsigned short m_cycles;101unsigned short m_first;102int m_lcd, m_timer[4], m_sound;//, m_battery;103104unsigned int m_count;105106void SetFirst ();107};108}109110#endif111112113