Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/SixteenBitRegister.h
2 views
1
/*
2
* Gearcoleco - ColecoVision Emulator
3
* Copyright (C) 2021 Ignacio Sanchez
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 as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* any later version.
9
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see http://www.gnu.org/licenses/
17
*
18
*/
19
20
#ifndef SIXTEENBITREGISTER_H
21
#define SIXTEENBITREGISTER_H
22
23
#include "definitions.h"
24
25
class SixteenBitRegister
26
{
27
public:
28
SixteenBitRegister() { }
29
void SetLow(u8 low);
30
u8 GetLow() const;
31
void SetHigh(u8 high);
32
u8 GetHigh() const;
33
u8* GetHighRegister();
34
u8* GetLowRegister();
35
void SetValue(u16 value);
36
u16 GetValue() const;
37
void Increment();
38
void Decrement();
39
40
private:
41
union sixteenBit
42
{
43
u16 v;
44
struct
45
{
46
#ifdef IS_LITTLE_ENDIAN
47
uint8_t low;
48
uint8_t high;
49
#else
50
uint8_t high;
51
uint8_t low;
52
#endif
53
};
54
} m_Value;
55
};
56
57
58
inline void SixteenBitRegister::SetLow(u8 low)
59
{
60
m_Value.low = low;
61
}
62
63
inline u8 SixteenBitRegister::GetLow() const
64
{
65
return m_Value.low;
66
}
67
68
inline void SixteenBitRegister::SetHigh(u8 high)
69
{
70
m_Value.high = high;
71
}
72
73
inline u8 SixteenBitRegister::GetHigh() const
74
{
75
return m_Value.high;
76
}
77
78
inline u8* SixteenBitRegister::GetHighRegister()
79
{
80
return &m_Value.high;
81
}
82
83
inline u8* SixteenBitRegister::GetLowRegister()
84
{
85
return &m_Value.low;
86
}
87
88
inline void SixteenBitRegister::SetValue(u16 value)
89
{
90
m_Value.v = value;
91
}
92
93
inline u16 SixteenBitRegister::GetValue() const
94
{
95
return m_Value.v;
96
}
97
98
inline void SixteenBitRegister::Increment()
99
{
100
m_Value.v++;
101
}
102
103
inline void SixteenBitRegister::Decrement()
104
{
105
m_Value.v--;
106
}
107
108
#endif /* SIXTEENBITREGISTER_H */
109
110
111