// 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 __TIMER_H__17#define __TIMER_H__1819#include "clock.hpp"2021#include <stdint.h>22#include <istream>23#include <ostream>2425namespace AMeteor26{27class Timer28{29public :30Timer (int8_t num, Timer* next) :31m_num(num),32m_reload(0),33m_count(0),34m_control(0),35m_next(next)36{37}3839void Reset ();4041void SetReload (uint16_t rel)42{43m_reload = rel;44}45void Reload ();4647uint16_t GetCount () const;4849bool SaveState (std::ostream& stream);50bool LoadState (std::istream& stream);5152private :53union Control54{55Control(uint16_t v) :56w(v)57{ }5859uint16_t w;60struct61{62unsigned int prescaler : 2;63unsigned int countup : 1;64unsigned int unused1 : 3;65unsigned int irq : 1;66unsigned int start : 1;67unsigned int unused2 : 8;68} b;69};7071const int8_t m_num;72uint16_t m_reload;73uint32_t m_count;74Control m_control;7576Timer* m_next;7778void TimeEvent ();79void Countup ();8081friend void Clock::Commit();82};83}8485#endif868788