-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBbcScreenC.cpp
More file actions
191 lines (176 loc) · 3.58 KB
/
BbcScreenC.cpp
File metadata and controls
191 lines (176 loc) · 3.58 KB
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
/*
* Copyright © 2016-2024 Matt Robinson
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
#include <iostream>
#include "BbcScreen.h"
void PrintException()
{
try
{
// Re-throw the exception so we can handle it here
throw;
}
catch(const std::exception& exp)
{
std::cerr << exp.what() << std::endl;
}
catch(...)
{
std::cerr << "A non-standard exception was thrown" << std::endl;
}
}
BbcScreenP BbcScreen_create(int screenMemSize)
{
try
{
return reinterpret_cast<BbcScreenP>(new BbcScreen(screenMemSize));
}
catch(...)
{
PrintException();
std::terminate();
}
}
BbcScreenP BbcScreen_create2(int screenMemSize, const uint8_t *screenData)
{
try
{
return reinterpret_cast<BbcScreenP>(new BbcScreen(screenMemSize, screenData));
}
catch(...)
{
PrintException();
std::terminate();
}
}
void BbcScreen_delete(BbcScreenP screen)
{
try
{
delete reinterpret_cast<BbcScreen*>(screen);
}
catch(...)
{
PrintException();
std::terminate();
}
}
void BbcScreen_setMode(BbcScreenP screen, uint8_t mode)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
screenPtr->setMode(mode);
}
catch(...)
{
PrintException();
std::terminate();
}
}
uint8_t BbcScreen_getMode(BbcScreenP screen)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->getMode();
}
catch(...)
{
PrintException();
std::terminate();
}
}
void BbcScreen_setScreenByte(BbcScreenP screen, int address, uint8_t byte)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
screenPtr->setScreenByte(address, byte);
}
catch(...)
{
PrintException();
std::terminate();
}
}
uint8_t BbcScreen_getScreenByte(BbcScreenP screen, int address)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->getScreenByte(address);
}
catch(...)
{
PrintException();
std::terminate();
}
}
int BbcScreen_getScreenWidth(BbcScreenP screen)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->getScreenWidth();
}
catch(...)
{
PrintException();
std::terminate();
}
}
int BbcScreen_getScreenHeight(BbcScreenP screen)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->getScreenHeight();
}
catch(...)
{
PrintException();
std::terminate();
}
}
void BbcScreen_setColour(BbcScreenP screen, uint8_t colour, uint8_t value)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->setColour(colour, value);
}
catch(...)
{
PrintException();
std::terminate();
}
}
uint8_t BbcScreen_getColour(BbcScreenP screen, uint8_t colour)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->getColour(colour);
}
catch(...)
{
PrintException();
std::terminate();
}
}
void BbcScreen_draw(BbcScreenP screen, DrawPixelP callback)
{
try
{
BbcScreen *screenPtr = reinterpret_cast<BbcScreen*>(screen);
return screenPtr->draw(static_cast<BbcScreen::DrawPixel>(callback));
}
catch(...)
{
PrintException();
std::terminate();
}
}