1 /*
2 BStone: A Source port of
3 Blake Stone: Aliens of Gold and Blake Stone: Planet Strike
4 
5 Copyright (c) 1992-2013 Apogee Entertainment, LLC
6 Copyright (c) 2013-2015 Boris I. Bendovsky (bibendovsky@hotmail.com)
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the
20 Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 */
23 
24 
25 #ifndef BSTONE_ID_VL_INCLUDED
26 #define BSTONE_ID_VL_INCLUDED
27 
28 
29 #include <cstdint>
30 #include <array>
31 #include <vector>
32 #include "bstone_ref_values.h"
33 #include "bstone_sprite_cache.h"
34 
35 
36 using VgaBuffer = std::vector<uint8_t>;
37 using UiMaskBuffer = std::array<bool, ::vga_ref_width * ::vga_ref_height>;
38 
39 
40 // ===========================================================================
41 
42 #define NOFADE_CODE
43 
44 #define SCREENWIDTH (320) // default screen width in bytes
45 
46 #define TILEWIDTH (4)
47 
48 // ===========================================================================
49 
50 extern int bufferofs; // all drawing is reletive to this
51 
52 extern bool screenfaded;
53 
54 // BBi
55 const int vga_ref_size = 256 * 1024;
56 const int vga_plane_count = 4;
57 const int vga_plane_width = vga_ref_width / 4;
58 const int vga_plane_height = vga_ref_height + 8;
59 const int vga_plane_size = vga_plane_width * vga_plane_height;
60 const int vga_page_size = vga_plane_count * vga_plane_size;
61 const int vga_page_count = 3;
62 
63 extern int screen_x;
64 extern int screen_y;
65 
66 extern int screen_width;
67 extern int screen_height;
68 
69 extern int vga_scale;
70 extern int vga_width;
71 extern int vga_height;
72 extern int vga_area;
73 extern int vga_3d_view_top;
74 extern int vga_3d_view_bottom;
75 
76 const bool default_vid_widescreen = true;
77 extern bool vid_widescreen;
78 
79 // Is VSync enabled?
80 extern bool vid_has_vsync;
81 
82 // Are we drawing HUD and a level?
83 extern bool vid_is_hud;
84 
85 // Are we drawing a level?
86 extern bool vid_is_3d;
87 
88 extern bstone::SpriteCache vid_sprite_cache;
89 // BBi
90 
91 // ===========================================================================
92 
93 void VL_Startup();
94 
95 void VL_Shutdown();
96 
97 void VL_SetVGAPlane();
98 
99 void VL_SetTextMode();
100 
101 void VL_DePlaneVGA();
102 
103 void VL_ClearVideo(
104     uint8_t color);
105 
106 void WaitVBL(
107     int16_t vbls);
108 
109 void VL_WaitVBL(
110     uint32_t vbls);
111 
112 void VL_CrtcStart(
113     int16_t crtc);
114 
115 void VL_FillPalette(
116     uint8_t red,
117     uint8_t green,
118     uint8_t blue);
119 
120 void VL_SetColor(
121     int color,
122     int red,
123     int green,
124     int blue);
125 
126 void VL_GetColor(
127     int color,
128     int* red,
129     int* green,
130     int* blue);
131 
132 void VL_SetPalette(
133     int first,
134     int count,
135     const uint8_t* palette);
136 
137 void VL_GetPalette(
138     int first,
139     int count,
140     uint8_t* palette);
141 
142 void VL_SetPaletteIntensity(
143     int start,
144     int end,
145     const uint8_t* palette,
146     int intensity);
147 
148 void VL_FadeOut(
149     int start,
150     int end,
151     int red,
152     int green,
153     int blue,
154     int steps);
155 
156 void VL_FadeIn(
157     int start,
158     int end,
159     const uint8_t* palette,
160     int steps);
161 
162 void VL_ColorBorder(
163     int16_t color);
164 
165 void VL_Plot(
166     int x,
167     int y,
168     uint8_t color,
169     const bool is_transparent = false);
170 
171 void VL_Hlin(
172     int x,
173     int y,
174     int width,
175     uint8_t color);
176 
177 void VL_Vlin(
178     int x,
179     int y,
180     int height,
181     uint8_t color);
182 
183 void VL_Bar(
184     int x,
185     int y,
186     int width,
187     int height,
188     uint8_t color,
189     const bool is_transparent = false);
190 
191 void VL_DrawPicBare(
192     int16_t x,
193     int16_t y,
194     uint8_t* pic,
195     int16_t width,
196     int16_t height);
197 
198 void VL_MemToLatch(
199     const uint8_t* source,
200     int width,
201     int height,
202     int dest);
203 
204 void VL_ScreenToScreen(
205     int source,
206     int dest,
207     int width,
208     int height);
209 
210 void VL_MemToScreen(
211     const uint8_t* source,
212     int width,
213     int height,
214     int x,
215     int y);
216 
217 void VL_MaskMemToScreen(
218     const uint8_t* source,
219     int width,
220     int height,
221     int x,
222     int y,
223     uint8_t mask);
224 
225 void VL_ScreenToMem(
226     uint8_t* dest,
227     int width,
228     int height,
229     int x,
230     int y);
231 
232 void VL_DrawTile8String(
233     char* str,
234     char* tile8ptr,
235     int16_t printx,
236     int16_t printy);
237 
238 void VL_DrawLatch8String(
239     char* str,
240     uint16_t tile8ptr,
241     int16_t printx,
242     int16_t printy);
243 
244 void VL_SizeTile8String(
245     char* str,
246     int16_t* width,
247     int16_t* height);
248 
249 void VL_DrawPropString(
250     char* str,
251     uint16_t tile8ptr,
252     int16_t printx,
253     int16_t printy);
254 
255 void VL_SizePropString(
256     char* str,
257     int16_t* width,
258     int16_t* height,
259     char* font);
260 
261 // BBi
262 void VL_RefreshScreen();
263 
264 int vl_get_offset(
265     int base_offset,
266     int x,
267     int y);
268 
269 uint8_t vl_get_pixel(
270     int base_offset,
271     int x,
272     int y);
273 
274 void vl_update_widescreen();
275 
276 void vid_set_ui_mask(
277     bool value);
278 
279 void vid_set_ui_mask(
280     int x,
281     int y,
282     int width,
283     int height,
284     bool value);
285 
286 void vid_set_ui_mask_3d(
287     bool value);
288 
289 void vid_clear_3d();
290 
291 void vid_export_ui(
292     VgaBuffer& dst_buffer);
293 
294 void vid_import_ui(
295     const VgaBuffer& src_buffer,
296     bool is_transparent = false);
297 
298 void vid_export_ui_mask(
299     UiMaskBuffer& dst_buffer);
300 
301 void vid_import_ui_mask(
302     const UiMaskBuffer& src_buffer);
303 
304 void vid_draw_ui_sprite(
305     const int sprite_id,
306     const int center_x,
307     const int center_y,
308     const int new_side = bstone::Sprite::side);
309 
310 
311 #endif // BSTONE_ID_VL_INCLUDED
312