forked from VCCE/VCC
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefines.h
More file actions
255 lines (211 loc) · 6.6 KB
/
defines.h
File metadata and controls
255 lines (211 loc) · 6.6 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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
#ifndef __DEFINES_H__
#define __DEFINES_H__
/*
Copyright 2015 by Joseph Forgione
This file is part of VCC (Virtual Color Computer).
VCC (Virtual Color Computer) is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VCC (Virtual Color Computer) is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VCC (Virtual Color Computer). If not, see <http://www.gnu.org/licenses/>.
*/
#include "MachineDefs.h"
#include "Debugger.h"
#include <cstdint>
#include <atomic>
#include <Windows.h>
#include <assert.h>
//Speed throttling
constexpr auto FRAMEINTERVAL = 120u; //Number of frames to sum the framecounter over
constexpr auto TARGETFRAMERATE = 60u; //Number of throttled Frames per second to render
constexpr auto SAMPLESPERFRAME = 262u;
#pragma warning(disable: 4100)
//CPU
constexpr auto FRAMESPERSECORD = 59.923; //The coco really runs at about 59.923 Frames per second
constexpr auto LINESPERSCREEN = 262.0;
constexpr auto NANOSECOND = 1000000000.0;
constexpr auto COLORBURST = 3579545.0;
constexpr auto AUDIOBUFFERS = 12u;
//Misc
constexpr auto QUERY = 255u;
struct SystemState;
namespace VCC
{
const int DefaultWidth = 640;
const int DefaultHeight = 480;
union Pixel;
struct Point
{
int x{}, y{};
Point() = default;
Point(int x, int y) :x(x), y(y) {}
};
struct Size
{
int w{}, h{};
Size() = default;
Size(int w, int h) :w(w), h(h) {}
};
struct Rect : Point, Size
{
Rect() = default;
Rect(int x, int y, int w, int h) : Point(x, y), Size(w, h) {}
bool IsDefaultX() const { return x == CW_USEDEFAULT; }
bool IsDefaultY() const { return y == CW_USEDEFAULT; }
int Top() const { return IsDefaultY() ? 0 : y; }
int Left() const { return IsDefaultX() ? 0 : x; }
int Right() const { return Left() + w; }
int Bottom() const { return Top() + h; }
RECT GetRect() const
{
return { Left(), Top(), Right(), Bottom() };
}
};
// FIXME: Remove this and use std::array
//
// bounds checking array type
//
template <class T, size_t Size>
struct Array
{
void MemCpyFrom(const void* buffer, size_t bytes)
{
assert(bytes <= sizeof(data));
memcpy(&data[0], buffer, bytes);
}
void MemCpyTo(void* outBuffer, size_t bytes)
{
MemCpyTo(0, outBuffer, bytes);
}
void MemCpyTo(size_t startElement, void* outBuffer, size_t bytes)
{
assert(startElement*sizeof(T) + bytes <= sizeof(data));
memcpy(outBuffer, &data[startElement], bytes);
}
void MemSet(uint8_t fill, size_t bytes)
{
assert(bytes <= sizeof(data));
memset(data, fill, bytes);
}
T& operator[](size_t index) { return data[index]; }
const T& operator[](size_t index) const { return data[index]; }
private:
std::array<T, Size> data;
};
//
// bounds checking on existing array
// NOTE: only for video surface, out-of-bounds wraps
//
template <class T, size_t Size>
struct VideoArray
{
explicit VideoArray(T* p) : data(p) {}
T& operator[](size_t index)
{
assert(index < Size);
return data[index % Size];
}
const T& operator[](size_t index) const
{
assert(index < Size);
return data[index % Size];
}
private:
T* data;
};
// delayed flip flop
struct DFF
{
uint8_t D{}; // d input
uint8_t Q{}; // q output
void Reset()
{
D = Q = 0;
}
void Clock(uint8_t d)
{
Q = D;
D = d;
}
};
//
// abstract interface for system state
//
struct ISystemState
{
enum { OK };
virtual ~ISystemState() = default;
virtual int GetWindowHandle(void** handle) = 0;
virtual int GetRect(int rectOption, Rect* rect) = 0;
virtual void SetSurface(void* ptr, uint8_t bitDepth, long stride) = 0;
};
}
struct SystemState
{
HWND WindowHandle = nullptr;
HWND ConfigDialog = nullptr;
HINSTANCE WindowInstance = nullptr;
unsigned char *RamBuffer = nullptr;
unsigned short *WRamBuffer = nullptr;
std::atomic<unsigned char> RamSize = 0;
double CPUCurrentSpeed = 0.0;
unsigned char DoubleSpeedMultiplyer = 0;
unsigned char DoubleSpeedFlag = 0;
unsigned char TurboSpeedFlag = 0;
unsigned char CpuType = 0;
unsigned char FrameSkip = 0;
unsigned char BitDepth = 0;
unsigned char Throttle = 0;
unsigned char *PTRsurface8 = nullptr;
unsigned short *PTRsurface16 = nullptr;
unsigned int *PTRsurface32 = nullptr;
long SurfacePitch = 0;
unsigned short LineCounter = 0;
unsigned char ScanLines = 0;
unsigned char EmulationRunning = 0;
unsigned char ResetPending = 0;
VCC::Size WindowSize;
unsigned char FullScreen = 0;
bool Exiting = false;
unsigned char MousePointer = 0;
unsigned char OverclockFlag = 0;
char StatusLine[256] = { 0 };
// Debugger Package
VCC::Debugger::Debugger Debugger;
};
//
// Abstract interface over SystemState that the display classes use
//
struct SystemStatePtr : VCC::ISystemState
{
explicit SystemStatePtr(SystemState* state) : state(state) {}
int GetWindowHandle(void** handle) override
{
*handle = state->WindowHandle;
return OK;
}
int GetRect(int rectOption, VCC::Rect* rect) override
{
rect->x = 0; rect->y = 0; rect->w = state->WindowSize.w; rect->h = state->WindowSize.h;
return OK;
}
void SetSurface(void* ptr, uint8_t bitDepth, long stride) override
{
state->PTRsurface8 = (unsigned char*)ptr;
state->PTRsurface16 = (unsigned short*)ptr;
state->PTRsurface32 = (unsigned int*)ptr;
state->BitDepth = bitDepth;
state->SurfacePitch = stride;
}
private:
SystemState* state;
};
extern SystemState EmuState;
static char RateList[4][7]={"Mute","11025","22050","44100"};
static unsigned int iRateList[4]={0,11025,22050,44100};
#endif