Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/video/ly_counter.h
2 views
1
/***************************************************************************
2
* Copyright (C) 2007 by Sindre Aamås *
3
* [email protected] *
4
* *
5
* This program is free software; you can redistribute it and/or modify *
6
* it under the terms of the GNU General Public License version 2 as *
7
* published by the Free Software Foundation. *
8
* *
9
* This program is distributed in the hope that it will be useful, *
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12
* GNU General Public License version 2 for more details. *
13
* *
14
* You should have received a copy of the GNU General Public License *
15
* version 2 along with this program; if not, write to the *
16
* Free Software Foundation, Inc., *
17
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18
***************************************************************************/
19
#ifndef LY_COUNTER_H
20
#define LY_COUNTER_H
21
22
#include "newstate.h"
23
24
namespace gambatte {
25
26
struct SaveState;
27
28
class LyCounter {
29
unsigned long time_;
30
unsigned short lineTime_;
31
unsigned char ly_;
32
bool ds;
33
34
public:
35
LyCounter();
36
void doEvent();
37
bool isDoubleSpeed() const { return ds; }
38
39
unsigned long frameCycles(const unsigned long cc) const {
40
return ly_ * 456ul + lineCycles(cc);
41
}
42
43
unsigned lineCycles(const unsigned long cc) const {
44
return 456u - ((time_ - cc) >> isDoubleSpeed());
45
}
46
47
unsigned lineTime() const { return lineTime_; }
48
unsigned ly() const { return ly_; }
49
unsigned long nextLineCycle(unsigned lineCycle, unsigned long cycleCounter) const;
50
unsigned long nextFrameCycle(unsigned long frameCycle, unsigned long cycleCounter) const;
51
void reset(unsigned long videoCycles, unsigned long lastUpdate);
52
void setDoubleSpeed(bool ds_in);
53
unsigned long time() const { return time_; }
54
55
template<bool isReader>void SyncState(NewState *ns);
56
};
57
58
}
59
60
#endif
61
62