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 "Background.hxx"
19#include "TIA.hxx"
20
21// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
22Background::Background()
23 : myTIA(nullptr)
24{
25 reset();
26}
27
28// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
29void Background::reset()
30{
31 myColor = myObjectColor = myDebugColor = 0;
32 myDebugEnabled = false;
33}
34
35// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
36void Background::setColor(uInt8 color)
37{
38 if (color != myObjectColor) myTIA->flushLineCache();
39
40 myObjectColor = color;
41 applyColors();
42}
43
44// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45void Background::setDebugColor(uInt8 color)
46{
47 myTIA->flushLineCache();
48 myDebugColor = color;
49 applyColors();
50}
51
52// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
53void Background::enableDebugColors(bool enabled)
54{
55 myTIA->flushLineCache();
56 myDebugEnabled = enabled;
57 applyColors();
58}
59
60// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
61void Background::applyColorLoss()
62{
63 myTIA->flushLineCache();
64 applyColors();
65}
66
67// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
68void Background::applyColors()
69{
70 if (!myDebugEnabled)
71 {
72 if (myTIA->colorLossActive()) myObjectColor |= 0x01;
73 else myObjectColor &= 0xfe;
74 myColor = myObjectColor;
75 }
76 else
77 myColor = myDebugColor;
78}
79
80// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
81bool Background::save(Serializer& out) const
82{
83 try
84 {
85 out.putByte(myColor);
86 out.putByte(myObjectColor);
87 out.putByte(myDebugColor);
88 out.putBool(myDebugEnabled);
89 }
90 catch(...)
91 {
92 cerr << "ERROR: TIA_BK::save" << endl;
93 return false;
94 }
95
96 return true;
97}
98
99// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
100bool Background::load(Serializer& in)
101{
102 try
103 {
104 myColor = in.getByte();
105 myObjectColor = in.getByte();
106 myDebugColor = in.getByte();
107 myDebugEnabled = in.getBool();
108
109 applyColors();
110 }
111 catch(...)
112 {
113 cerr << "ERROR: TIA_BK::load" << endl;
114 return false;
115 }
116
117 return true;
118}
119