-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphics.h
206 lines (189 loc) · 7.59 KB
/
graphics.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
202
203
204
205
206
#ifndef GRAPHICS_H
#define GRAPHICS_H
#include <stdint.h>
union __attribute__((packed)) gblptn_or_gbdoti {
uint16_t gblptn;
uint8_t gbdoti[8];
};
struct __attribute__((packed)) graphics_ucw {
uint8_t gbon_ptn;
uint8_t gbbcc;
uint8_t gbdotu;
uint8_t gbdsp;
uint8_t gbcpc[4];
uint16_t gbsx1;
uint16_t gbsy1;
uint16_t gblng1;
uint16_t gbwdpa;
uint16_t gbrbuf[3];
uint16_t gbsx2;
uint16_t gbsy2;
uint16_t gbmdot;
uint16_t gbcir;
uint16_t gblng2;
union gblptn_or_gbdoti gblptn_or_gbdoti;
uint8_t gbdtyp;
uint8_t gbfill;
uint16_t gbgwk1;
uint16_t gbgwk2;
uint16_t gbgwk3;
uint16_t gbgwk4;
uint16_t gbgwk5;
uint16_t gbgwk6;
uint16_t gbgwk7;
uint16_t gbgwk8;
uint16_t gbgp12;
uint16_t gbgp34;
uint16_t gbgp56;
uint16_t gbgp78;
uint16_t gbgp910;
uint16_t gbgp1112;
uint16_t gbgp1314;
uint16_t gbgp1516;
};
/**
* graphics_mode The graphics mode to use.
* 0bvvcm0000
* v: The VRAM region to use.
* c: The CRT display mode to use.
* m: The memory bank to use.
*/
typedef uint8_t graphics_mode;
static const graphics_mode GRAPHICS_MODE_VRAM_REGION_UPPER = 0x40;
static const graphics_mode GRAPHICS_MODE_VRAM_REGION_LOWER = 0x80;
static const graphics_mode GRAPHICS_MODE_VRAM_REGION_ALL = 0xc0;
static const graphics_mode GRAPHICS_MODE_CRT_DISPLAY_COLOR = 0x00;
static const graphics_mode GRAPHICS_MODE_CRT_DISPLAY_MONOCHROME = 0x20;
static const graphics_mode GRAPHICS_MODE_DISPLAY_BANK0 = 0x00;
static const graphics_mode GRAPHICS_MODE_DISPLAY_BANK1 = 0x10;
/**
* target_screens The screens that should be drawn to.
* 0brspp0000
* r: The resolution to draw at.
* s: The screen region to draw to.
* p: The planes to draw to.
*/
typedef uint8_t target_screens;
static const target_screens TARGET_SCREENS_STANDARD_RESOLUTION = 0x00;
static const target_screens TARGET_SCREENS_HIGH_RESOLUTION = 0x80;
static const target_screens TARGET_SCREENS_LOWER_ALL = 0x80;
static const target_screens TARGET_SCREENS_UPPER = 0x40;
static const target_screens TARGET_SCREENS_PLANE1 = 0x00;
static const target_screens TARGET_SCREENS_PLANE2 = 0x10;
static const target_screens TARGET_SCREENS_PLANE3 = 0x20;
static const target_screens TARGET_SCREENS_PLANE123 = 0x30;
typedef uint8_t draw_mode;
/**
* draw_mode Whether 0 or 1 should be drawn.
* 0b00000ppp
* p: If the plane should be cleared or set to.
*/
static const draw_mode DRAW_MODE_PLANE1_CLEAR = 0x00;
static const draw_mode DRAW_MODE_PLANE1_SET = 0x01;
static const draw_mode DRAW_MODE_PLANE2_CLEAR = 0x00;
static const draw_mode DRAW_MODE_PLANE2_SET = 0x02;
static const draw_mode DRAW_MODE_PLANE3_CLEAR = 0x00;
static const draw_mode DRAW_MODE_PLANE3_SET = 0x04;
typedef uint8_t draw_operation;
static const draw_operation DRAW_OPERATION_REPLACE = 0x00;
static const draw_operation DRAW_OPERATION_COMPLIMENT = 0x01;
static const draw_operation DRAW_OPERATION_CLEAR = 0x02;
static const draw_operation DRAW_OPERATION_SET = 0x03;
typedef uint8_t draw_direction;
static const draw_direction DRAW_DIRECTION_LINE_DOWN = 0;
static const draw_direction DRAW_DIRECTION_LINE_DOWN_RIGHT = 1;
static const draw_direction DRAW_DIRECTION_LINE_RIGHT = 2;
static const draw_direction DRAW_DIRECTION_LINE_UP_RIGHT = 3;
static const draw_direction DRAW_DIRECTION_LINE_UP = 4;
static const draw_direction DRAW_DIRECTION_LINE_UP_LEFT = 5;
static const draw_direction DRAW_DIRECTION_LINE_LEFT = 6;
static const draw_direction DRAW_DIRECTION_LINE_DOWN_LEFT = 7;
static const draw_direction DRAW_DIRECTION_RECTANGLE_TOP_LEFT_BOTTOM_RIGHT = 0;
static const draw_direction DRAW_DIRECTION_DIAMOND_LEFT_RIGHT = 1;
static const draw_direction DRAW_DIRECTION_RECTANGLE_BOTTOM_LEFT_TOP_RIGHT = 2;
static const draw_direction DRAW_DIRECTION_DIAMOND_BOTTOM_TOP = 3;
static const draw_direction DRAW_DIRECTION_RECTANGLE_BOTTOM_RIGHT_TOP_LEFT = 4;
static const draw_direction DRAW_DIRECTION_DIAMOND_RIGHT_LEFT = 5;
static const draw_direction DRAW_DIRECTION_RECTANGLE_TOP_RIGHT_BOTTOM_LEFT = 6;
static const draw_direction DRAW_DIRECTION_DIAMOND_TOP_BOTTOM = 7;
typedef uint8_t draw_type;
static const draw_type DRAW_TYPE_LINE = 0x01;
static const draw_type DRAW_TYPE_RECTANGLE = 0x02;
/**
* graphics_start() - Starts showing the graphics screen.
*/
void graphics_start();
/**
* graphics_finish() - Finishes showing the graphics screen.
*
* Any graphics that were previously showing will be cleared.
*/
void graphics_finish();
/**
* graphics_set_mode() - Set the display mode settings
* @param mode The VRAM region, CRT display mode, and memory bank
*/
void graphics_set_mode(graphics_mode mode);
/**
* graphics_set_palette() - Sets the palette from the UCW.
* @param The UCW to read the palette data from.
*
* Before calling this function ucw should be initialized by calling
* graphics_ucw_init_palette().
*/
void graphics_set_palette(struct graphics_ucw* ucw);
/**
* graphics_ucw_init_palette - Initializes UCW with a pallete.
* @param color0 Color used when P1=0 P2=0 P3=0 in the format of 0b0grb.
* @param color1 Color used when P1=0 P2=0 P3=1 in the format of 0b0grb.
* @param color2 Color used when P1=0 P2=1 P3=0 in the format of 0b0grb.
* @param color3 Color used when P1=0 P2=1 P3=1 in the format of 0b0grb.
* @param color4 Color used when P1=1 P2=0 P3=0 in the format of 0b0grb.
* @param color5 Color used when P1=1 P2=0 P3=1 in the format of 0b0grb.
* @param color6 Color used when P1=1 P2=1 P3=0 in the format of 0b0grb.
* @param color7 Color used when P1=1 P2=1 P3=1 in the format of 0b0grb.
*/
void graphics_ucw_init_palette(struct graphics_ucw* ucw,
uint8_t color0,
uint8_t color1,
uint8_t color2,
uint8_t color3,
uint8_t color4,
uint8_t color5,
uint8_t color6,
uint8_t color7);
/**
* graphics_draw_line_rectangle - Draws a straight line or rectangle.
* @param target_screens Defines the screens that will be drawn to.
* @param ucw The unit control word containing data about what to draw.
*
* Before calling this function ucw should be initialized by calling
* graphics_ucw_draw_init_line_rectangle().
*/
void graphics_draw_line_rectangle(target_screens target_screens,
struct graphics_ucw* ucw);
/**
* graphics_ucw_init_draw_line_rectangle - Initialize UCW for drawing a line or
* rectangle.
* @param ucw The UCW that should be initialized.
* @param drawing_modes The drawing mode that should be used for each plane.
* @param drawing_operations The operation that should be used for drawing.
* @param direction The direction for drawing betwen (x1, y1) and (x2, y2)
* @param x1 The x coordinate of the first point.
* @param y1 The y coordinate of the first point.
* @param x2 The x coordinate of the second point.
* @param y2 The y coordinate of the second point.
* @param line_pattern The 16 bit long line pattern that should be drawn in.
* @param type Whether a line or a rectangle should be drawn.
*/
void graphics_ucw_init_draw_line_rectangle(struct graphics_ucw* ucw,
draw_mode modes,
draw_operation operations,
draw_direction direction,
uint16_t x1,
uint16_t y1,
uint16_t x2,
uint16_t y2,
uint16_t line_pattern,
draw_type type);
#endif