Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libgambatte/src/video/ly_counter.cpp
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
#include "ly_counter.h"
20
#include "../savestate.h"
21
22
namespace gambatte {
23
24
LyCounter::LyCounter()
25
: time_(0), lineTime_(0), ly_(0), ds(false)
26
{
27
setDoubleSpeed(false);
28
reset(0, 0);
29
}
30
31
void LyCounter::doEvent() {
32
++ly_;
33
34
if (ly_ == 154)
35
ly_ = 0;
36
37
time_ = time_ + lineTime_;
38
}
39
40
unsigned long LyCounter::nextLineCycle(const unsigned lineCycle, const unsigned long cycleCounter) const {
41
unsigned long tmp = time_ + (lineCycle << ds);
42
43
if (tmp - cycleCounter > lineTime_)
44
tmp -= lineTime_;
45
46
return tmp;
47
}
48
49
unsigned long LyCounter::nextFrameCycle(const unsigned long frameCycle, const unsigned long cycleCounter) const {
50
unsigned long tmp = time_ + (((153U - ly()) * 456U + frameCycle) << ds);
51
52
if (tmp - cycleCounter > 70224U << ds)
53
tmp -= 70224U << ds;
54
55
return tmp;
56
}
57
58
void LyCounter::reset(const unsigned long videoCycles, const unsigned long lastUpdate) {
59
ly_ = videoCycles / 456;
60
time_ = lastUpdate + ((456 - (videoCycles - ly_ * 456ul)) << isDoubleSpeed());
61
}
62
63
void LyCounter::setDoubleSpeed(const bool ds_in) {
64
ds = ds_in;
65
lineTime_ = 456U << ds_in;
66
}
67
68
SYNCFUNC(LyCounter)
69
{
70
NSS(time_);
71
NSS(lineTime_);
72
NSS(ly_);
73
NSS(ds);
74
}
75
76
}
77
78