Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
folium-app
GitHub Repository: folium-app/Folium
Path: blob/a-new-beginning/Cherry/Core/include/Video.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 VIDEO_H
21
#define VIDEO_H
22
23
#include "definitions.h"
24
25
class CVMemory;
26
class Processor;
27
28
class Video
29
{
30
public:
31
enum Overscan
32
{
33
OverscanDisabled,
34
OverscanTopBottom,
35
OverscanFull284,
36
OverscanFull320
37
};
38
39
public:
40
Video(CVMemory* pMemory, Processor* pProcessor);
41
~Video();
42
void Init();
43
void Reset(bool bPAL);
44
bool Tick(unsigned int clockCycles);
45
u8 GetDataPort();
46
u8 GetStatusFlags();
47
void WriteData(u8 data);
48
void WriteControl(u8 control);
49
void SaveState(std::ostream& stream);
50
void LoadState(std::istream& stream);
51
u8* GetVRAM();
52
u8* GetRegisters();
53
u16* GetFrameBuffer();
54
int GetMode();
55
void Render24bit(u16* srcFrameBuffer, u8* dstFrameBuffer, GC_Color_Format pixelFormat, int size, bool overscan = false);
56
void Render16bit(u16* srcFrameBuffer, u8* dstFrameBuffer, GC_Color_Format pixelFormat, int size, bool overscan = false);
57
void SetOverscan(Overscan overscan);
58
Overscan GetOverscan();
59
void SetCustomPalette(GC_Color* palette);
60
void SetPredefinedPalette(int palette);
61
void SetNoSpriteLimit(bool noSpriteLimit);
62
bool IsPAL();
63
u8 GetBufferReg();
64
u16 GetAddressReg();
65
u8 GetStatusReg();
66
int GetRenderLine();
67
int GetCycleCounter();
68
bool GetLatch();
69
70
private:
71
void ScanLine(int line);
72
void LatchSpriteAttributes();
73
void RenderBackground(int line);
74
void RenderSprites(int line);
75
void InitPalettes();
76
77
private:
78
CVMemory* m_pMemory;
79
Processor* m_pProcessor;
80
u8* m_pInfoBuffer;
81
u16* m_pFrameBuffer;
82
u8* m_pVdpVRAM;
83
bool m_bFirstByteInSequence;
84
u8 m_VdpRegister[8];
85
u8 m_VdpBuffer;
86
u16 m_VdpAddress;
87
int m_iCycleCounter;
88
u8 m_VdpStatus;
89
int m_iLinesPerFrame;
90
bool m_bPAL;
91
int m_iMode;
92
int m_iRenderLine;
93
u8 m_SpriteAttribLatch[128];
94
Overscan m_Overscan;
95
96
struct LineEvents
97
{
98
bool vint;
99
bool render;
100
bool display;
101
};
102
103
LineEvents m_LineEvents;
104
105
enum Timing
106
{
107
TIMING_VINT = 0,
108
TIMING_RENDER = 1,
109
TIMING_DISPLAY = 2
110
};
111
112
int m_Timing[3];
113
bool m_bDisplayEnabled;
114
bool m_bSpriteOvrRequest;
115
bool m_bNoSpriteLimit;
116
117
u16 m_palette_565_rgb[16];
118
u16 m_palette_555_rgb[16];
119
u16 m_palette_565_bgr[16];
120
u16 m_palette_555_bgr[16];
121
122
u8 m_CustomPalette[48];
123
u8* m_pCurrentPalette;
124
};
125
126
inline u8* Video::GetVRAM()
127
{
128
return m_pVdpVRAM;
129
}
130
131
inline u8* Video::GetRegisters()
132
{
133
return m_VdpRegister;
134
}
135
136
inline int Video::GetMode()
137
{
138
return m_iMode;
139
}
140
141
inline u16* Video::GetFrameBuffer()
142
{
143
return m_pFrameBuffer;
144
}
145
146
const u8 kPalette_888_coleco[48] = {0,0,0, 0,0,0, 33,200,66, 94,220,120, 84,85,237, 125,118,252, 212,82,77, 66,235,245, 252,85,84, 255,121,120, 212,193,84, 230,206,128, 33,176,59, 201,91,186, 204,204,204, 255,255,255};
147
const u8 kPalette_888_tms9918[48] = {0,0,0, 0,8,0, 0,241,1, 50,251,65, 67,76,255, 112,110,255, 238,75,28, 9,255,255, 255,78,31, 255,112,65, 211,213,0, 228,221,52, 0,209,0, 219,79,211, 193,212,190, 244,255,241};
148
149
const u8 k2bitTo8bit[4] = {0,85,170,255};
150
const u8 k2bitTo5bit[4] = {0,10,21,31};
151
const u8 k2bitTo6bit[4] = {0,21,42,63};
152
const u8 k4bitTo8bit[16] = {0,17,34,51,68,86,102,119,136,153,170,187,204,221,238,255};
153
const u8 k4bitTo5bit[16] = {0,2,4,6,8,10,12,14,17,19,21,23,25,27,29,31};
154
const u8 k4bitTo6bit[16] = {0,4,8,13,17,21,25,29,34,38,42,46,50,55,59,63};
155
156
#endif /* VIDEO_H */
157
158