1//============================================================================
2//
3// SSSS tt lll lll
4// SS SS tt ll ll
5// SS tttttt eeee ll ll aaaa
6// SSSS tt ee ee ll ll aa
7// SS tt eeeeee ll ll aaaaa -- "An Atari 2600 VCS Emulator"
8// SS SS tt ee ll ll aa aa
9// SSSS ttt eeeee llll llll aaaaa
10//
11// Copyright (c) 1995-2019 by Bradford W. Mott, Stephen Anthony
12// and the Stella Team
13//
14// See the file "License.txt" for information on usage and redistribution of
15// this file, and for a DISCLAIMER OF ALL WARRANTIES.
16//============================================================================
17
18#include "AbstractFrameManager.hxx"
19
20// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
21AbstractFrameManager::AbstractFrameManager() :
22 myIsRendering(false),
23 myVsync(false),
24 myVblank(false),
25 myLayout(FrameLayout::pal),
26 myOnFrameStart(nullptr),
27 myOnFrameComplete(nullptr)
28{
29 layout(FrameLayout::ntsc);
30}
31
32// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
33void AbstractFrameManager::reset()
34{
35 myIsRendering = false;
36 myVsync = false;
37 myVblank = false;
38 myCurrentFrameTotalLines = 0;
39 myCurrentFrameFinalLines = 0;
40 myPreviousFrameFinalLines = 0;
41 myTotalFrames = 0;
42
43 onReset();
44}
45
46// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47void AbstractFrameManager::nextLine()
48{
49 ++myCurrentFrameTotalLines;
50
51 onNextLine();
52}
53
54// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55void AbstractFrameManager::setHandlers(
56 callback frameStartCallback,
57 callback frameCompletionCallback
58) {
59 myOnFrameStart = frameStartCallback;
60 myOnFrameComplete = frameCompletionCallback;
61}
62
63// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
64void AbstractFrameManager::clearHandlers()
65{
66 myOnFrameStart = myOnFrameComplete = nullptr;
67}
68
69// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
70void AbstractFrameManager::setVblank(bool vblank)
71{
72 if (vblank == myVblank) return;
73
74 myVblank = vblank;
75
76 onSetVblank();
77}
78
79// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
80void AbstractFrameManager::setVsync(bool vsync)
81{
82 if (vsync == myVsync) return;
83
84 myVsync = vsync;
85
86 onSetVsync();
87}
88
89// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
90void AbstractFrameManager::notifyFrameStart()
91{
92 if (myOnFrameStart) myOnFrameStart();
93}
94
95// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
96void AbstractFrameManager::notifyFrameComplete()
97{
98 myPreviousFrameFinalLines = myCurrentFrameFinalLines;
99 myCurrentFrameFinalLines = myCurrentFrameTotalLines;
100 myCurrentFrameTotalLines = 0;
101 ++myTotalFrames;
102
103 if (myOnFrameComplete) myOnFrameComplete();
104}
105
106// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
107void AbstractFrameManager::layout(FrameLayout layout)
108{
109 if (layout == myLayout) return;
110
111 myLayout = layout;
112
113 onLayoutChange();
114}
115
116// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
117bool AbstractFrameManager::save(Serializer& out) const
118{
119 try
120 {
121 out.putBool(myIsRendering);
122 out.putBool(myVsync);
123 out.putBool(myVblank);
124 out.putInt(myCurrentFrameTotalLines);
125 out.putInt(myCurrentFrameFinalLines);
126 out.putInt(myPreviousFrameFinalLines);
127 out.putInt(myTotalFrames);
128 out.putInt(uInt32(myLayout));
129
130 return onSave(out);
131 }
132 catch(...)
133 {
134 cerr << "ERROR: AbstractFrameManager::save" << endl;
135 return false;
136 }
137}
138
139// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
140bool AbstractFrameManager::load(Serializer& in)
141{
142 try
143 {
144 myIsRendering = in.getBool();
145 myVsync = in.getBool();
146 myVblank = in.getBool();
147 myCurrentFrameTotalLines = in.getInt();
148 myCurrentFrameFinalLines = in.getInt();
149 myPreviousFrameFinalLines = in.getInt();
150 myTotalFrames = in.getInt();
151 myLayout = FrameLayout(in.getInt());
152
153 return onLoad(in);
154 }
155 catch(...)
156 {
157 cerr << "ERROR: AbstractFrameManager::load" << endl;
158 return false;
159 }
160}
161