forked from randyrossi/bmc64
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vicescreen.h
201 lines (173 loc) · 6.1 KB
/
vicescreen.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// vicescreen.h
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _vice_screen_h
#define _vice_screen_h
#include <circle/bcmframebuffer.h>
#include <circle/chargenerator.h>
#include <circle/device.h>
#include <circle/macros.h>
#include <circle/spinlock.h>
#include <circle/types.h>
#define DEPTH 8
// really ((green) & 0x3F) << 5, but to have a 0-31 range for all colors
#define COLOR16(red, green, blue) \
(((red)&0x1F) << 11 | ((green)&0x1F) << 6 | ((blue)&0x1F))
// BGRA (was RGBA with older firmware)
#define COLOR32(red, green, blue, alpha) \
(((blue)&0xFF) | ((green)&0xFF) << 8 | ((red)&0xFF) << 16 | \
((alpha)&0xFF) << 24)
#define BLACK_COLOR 0
#if DEPTH == 8
typedef u8 TScreenColor;
#define NORMAL_COLOR16 COLOR16(31, 31, 31)
#define HIGH_COLOR16 COLOR16(31, 0, 0)
#define HALF_COLOR16 COLOR16(0, 0, 31)
#define NORMAL_COLOR 1
#define HIGH_COLOR 2
#define HALF_COLOR 3
#elif DEPTH == 16
typedef u16 TScreenColor;
#define NORMAL_COLOR COLOR16(31, 31, 31)
#define HIGH_COLOR COLOR16(31, 0, 0)
#define HALF_COLOR COLOR16(0, 0, 31)
#elif DEPTH == 32
typedef u32 TScreenColor;
#define NORMAL_COLOR COLOR32(255, 255, 255, 255)
#define HIGH_COLOR COLOR32(255, 0, 0, 255)
#define HALF_COLOR COLOR32(0, 0, 255, 255)
#else
#error DEPTH must be 8, 16 or 32
#endif
struct TScreenStatus {
TScreenColor *pContent;
unsigned nSize;
unsigned nState;
unsigned nScrollStart;
unsigned nScrollEnd;
unsigned nCursorX;
unsigned nCursorY;
boolean bCursorOn;
TScreenColor Color;
boolean bInsertOn;
unsigned nParam1;
unsigned nParam2;
boolean bUpdated;
};
class CViceScreenDevice : public CDevice /// Writing characters to screen
{
public:
/// \param nWidth Screen width in pixels (0 for default resolution)
/// \param nHeight Screen height in pixels (0 for default resolution)
/// \param bVirtual FALSE for physical screen, TRUE for virtual screen buffer
CViceScreenDevice(unsigned nWidth, unsigned nHeight,
boolean bVirtual = FALSE);
~CViceScreenDevice(void);
/// \return Operation successful?
boolean Initialize(void);
/// \return Screen width in pixels
unsigned GetWidth(void) const;
/// \return Screen height in pixels
unsigned GetHeight(void) const;
/// \return Screen width in characters
unsigned GetColumns(void) const;
/// \return Screen height in characters
unsigned GetRows(void) const;
/// \return Current screen status to be written back with SetStatus()
TScreenStatus GetStatus(void);
/// \param Status Screen status previously returned from GetStatus()
/// \return FALSE on failure (screen is currently updated and cannot be
/// written)
boolean SetStatus(const TScreenStatus &Status);
/// \brief Write characters to screen
/// \note Supports several escape sequences (see: doc/screen.txt).
/// \param pBuffer Pointer to the characters to be written
/// \param nCount Number of characters to be written
/// \return Number of written characters
int Write(const void *pBuffer, unsigned nCount);
/// \brief Set a pixel to a specific color
/// \param nPosX X-Position of the pixel (based on 0)
/// \param nPosY Y-Position of the pixel (based on 0)
/// \param Color The color to be set (value depends on screen DEPTH)
void SetPixel(unsigned nPosX, unsigned nPosY, TScreenColor Color);
/// \brief Get the color value of a pixel
/// \param nPosX X-Position of the pixel (based on 0)
/// \param nPosY Y-Position of the pixel (based on 0)
/// \return The requested color value (depends on screen DEPTH)
TScreenColor GetPixel(unsigned nPosX, unsigned nPosY);
/// \brief Displays rotating symbols in the upper right corner of the screen
/// \param nIndex Index of the rotor to be displayed (0..3)
/// \param nCount Phase (angle) of the current rotor symbol (0..3)
void Rotor(unsigned nIndex, unsigned nCount);
// Added for VICE
TScreenColor *GetBuffer() { return m_pBuffer; }
int GetPitch() { return m_nPitch; }
void SetPalette(u8 index, u16 rgb565);
void UpdatePalette();
void SetVirtualOffset(u32 x, u32 y);
void WaitForVerticalSync();
private:
void Write(char chChar);
void CarriageReturn(void);
void ClearDisplayEnd(void) MAXOPT;
void ClearLineEnd(void);
void CursorDown(void);
void CursorHome(void);
void CursorLeft(void);
void CursorMove(unsigned nRow, unsigned nColumn);
void CursorRight(void);
void CursorUp(void);
void DeleteChars(unsigned nCount);
void DeleteLines(unsigned nCount);
void DisplayChar(char chChar);
void EraseChars(unsigned nCount);
void InsertLines(unsigned nCount);
void InsertMode(boolean bBegin);
void NewLine(void);
void ReverseScroll(void);
void SetCursorMode(boolean bVisible);
void SetScrollRegion(unsigned nStartRow, unsigned nEndRow);
void SetStandoutMode(unsigned nMode);
void Tabulator(void);
void Scroll(void) MAXOPT;
void DisplayChar(char chChar, unsigned nPosX, unsigned nPosY,
TScreenColor Color);
void EraseChar(unsigned nPosX, unsigned nPosY);
void InvertCursor(void);
private:
unsigned m_nInitWidth;
unsigned m_nInitHeight;
boolean m_bVirtual;
CBcmFrameBuffer *m_pFrameBuffer;
CCharGenerator m_CharGen;
TScreenColor *m_pBuffer;
unsigned m_nSize;
unsigned m_nPitch;
unsigned m_nWidth;
unsigned m_nHeight;
unsigned m_nUsedHeight;
unsigned m_nState;
unsigned m_nScrollStart;
unsigned m_nScrollEnd;
unsigned m_nCursorX;
unsigned m_nCursorY;
boolean m_bCursorOn;
TScreenColor m_Color;
boolean m_bInsertOn;
unsigned m_nParam1;
unsigned m_nParam2;
boolean m_bUpdated;
CSpinLock m_SpinLock;
};
#endif