Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/libmeteor/include/ameteor/graphics/screen.hpp
2 views
1
// Meteor - A Nintendo Gameboy Advance emulator
2
// Copyright (C) 2009-2011 Philippe Daouadi
3
//
4
// This program is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
#ifndef __GRAPHICS_SCREEN_H__
18
#define __GRAPHICS_SCREEN_H__
19
20
#include "bglayer.hpp"
21
#include "objects.hpp"
22
#include "renderer.hpp"
23
24
#include <stdint.h>
25
#include <istream>
26
#include <ostream>
27
28
namespace AMeteor
29
{
30
namespace Graphics
31
{
32
class Screen
33
{
34
public :
35
static const uint8_t WIDTH = 240;
36
static const uint8_t HEIGHT = 160;
37
38
// we skip x frames every FRMSKIP_TOTAL frames
39
static const uint8_t FRMSKIP_TOTAL = 10;
40
41
Screen (Memory& memory, Io& io);
42
~Screen ();
43
44
Renderer& GetRenderer()
45
{
46
return m_renderer;
47
}
48
const Renderer& GetRenderer() const
49
{
50
return m_renderer;
51
}
52
53
const uint16_t* GetSurface () const
54
{
55
return m_surface;
56
}
57
58
void SetFrameskip (uint8_t skip)
59
{
60
m_frameskip = skip;
61
m_curframe = 0;
62
}
63
64
void DrawLine (uint8_t line);
65
66
void UpdateDispCnt (uint16_t dispcnt)
67
{
68
m_dispcnt = dispcnt;
69
}
70
71
#define UPDATE_BG_CNT(num) \
72
void UpdateBg##num##Cnt (uint16_t cnt) \
73
{ \
74
m_bgLayer##num.UpdateCnt(cnt); \
75
}
76
UPDATE_BG_CNT(0)
77
UPDATE_BG_CNT(1)
78
UPDATE_BG_CNT(2)
79
UPDATE_BG_CNT(3)
80
#undef UPDATE_BG_CNT
81
82
#define UPDATE_BG_OFF(num, coord) \
83
void UpdateBg##num##coord##Off (uint16_t off) \
84
{ \
85
m_bgLayer##num.Update##coord##Off(off); \
86
}
87
UPDATE_BG_OFF(0, X)
88
UPDATE_BG_OFF(0, Y)
89
UPDATE_BG_OFF(1, X)
90
UPDATE_BG_OFF(1, Y)
91
UPDATE_BG_OFF(2, X)
92
UPDATE_BG_OFF(2, Y)
93
UPDATE_BG_OFF(3, X)
94
UPDATE_BG_OFF(3, Y)
95
#undef UPDATE_BG_OFF
96
97
#define UPDATE_BG_REF(num, coord) \
98
void UpdateBg##num##Ref##coord(int32_t x) \
99
{ \
100
m_ref##coord##num = (x & (0x1 << 27)) ? x | 0xF0000000 : x & 0x07FFFFFF; \
101
}
102
UPDATE_BG_REF(2, X)
103
UPDATE_BG_REF(2, Y)
104
UPDATE_BG_REF(3, X)
105
UPDATE_BG_REF(3, Y)
106
#undef UPDATE_BG_REF
107
108
void OamWrite (uint32_t begin, uint32_t end)
109
{
110
m_objs.OamWrite (begin, end);
111
}
112
void OamWrite16 (uint32_t add)
113
{
114
m_objs.OamWrite16 (add);
115
}
116
void OamWrite32 (uint32_t add)
117
{
118
m_objs.OamWrite32 (add);
119
}
120
121
bool SaveState (std::ostream& stream);
122
bool LoadState (std::istream& stream);
123
124
private :
125
Io& m_io;
126
127
uint16_t* m_surface;
128
129
Renderer m_renderer;
130
131
uint8_t m_frameskip, m_curframe;
132
133
uint16_t m_dispcnt;
134
int32_t m_refX2, m_refY2, m_refX3, m_refY3;
135
uint16_t* m_pPalette;
136
137
// FIXME is this REALLY useful ?
138
static BgLayer Screen::* const BgLayers [4];
139
BgLayer m_bgLayer0, m_bgLayer1, m_bgLayer2, m_bgLayer3;
140
Objects m_objs;
141
142
void DrawWindow (uint8_t line, uint8_t* surface,
143
uint16_t win0v, uint16_t win0h, uint8_t mask);
144
};
145
}
146
}
147
148
#endif
149
150