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 #include "id_heads.h"
26
27
28 void VL_LatchToScreen(
29 int source,
30 int width,
31 int height,
32 int x,
33 int y);
34
35 void IN_StartAck();
36 bool IN_CheckAck();
37 void CalcTics();
38 void ForceUpdateStatusBar();
39
40 pictabletype* pictable;
41 pictabletype* picmtable;
42
43 int16_t px;
44 int16_t py;
45 uint8_t fontcolor;
46 uint8_t backcolor;
47 int16_t fontnumber;
48
49 bool allcaps = false;
50
51 // BBi
52 LatchesCache latches_cache;
53
VW_DrawPropString(const char * string)54 void VW_DrawPropString(
55 const char* string)
56 {
57 fontstruct* font =
58 static_cast<fontstruct*>(grsegs[STARTFONT + fontnumber]);
59
60 int height = font->height;
61
62 int string_length = static_cast<int>(strlen(string));
63
64 for (int c = 0; c < string_length; ++c) {
65 uint8_t ch = string[c];
66 int width = font->width[ch];
67
68 const uint8_t* source =
69 (reinterpret_cast<const uint8_t*>(font)) + font->location[ch];
70
71 for (int w = 0; w < width; ++w) {
72 for (int h = 0; h < height; ++h) {
73 if (source[h * width] != 0) {
74 VL_Plot(px + w, py + h, fontcolor);
75 }
76 }
77
78 ++source;
79 }
80
81 px = static_cast<int16_t>(px + width);
82 }
83 }
84
VWL_MeasureString(const char * string,int * width,int * height,fontstruct * font)85 void VWL_MeasureString(
86 const char* string,
87 int* width,
88 int* height,
89 fontstruct* font)
90 {
91 *height = font->height;
92
93 for (*width = 0; string[0] != '\0'; ++string) {
94 // proportional width
95 *width += font->width[static_cast<uint8_t>(*string)];
96 }
97 }
98
VW_MeasurePropString(const char * string,int * width,int * height)99 void VW_MeasurePropString(
100 const char* string,
101 int* width,
102 int* height)
103 {
104 VWL_MeasureString(
105 string,
106 width,
107 height,
108 static_cast<fontstruct*>(grsegs[STARTFONT + fontnumber]));
109 }
110
111
112 /*
113 =============================================================================
114
115 Double buffer management routines
116
117 =============================================================================
118 */
119
VWB_DrawTile8(int x,int y,int tile)120 void VWB_DrawTile8(
121 int x,
122 int y,
123 int tile)
124 {
125 LatchDrawChar(x, y, tile);
126 }
127
VWB_DrawPic(int x,int y,int chunknum)128 void VWB_DrawPic(
129 int x,
130 int y,
131 int chunknum)
132 {
133 int picnum = chunknum - STARTPICS;
134 int width = pictable[picnum].width;
135 int height = pictable[picnum].height;
136
137 VL_MemToScreen(
138 static_cast<const uint8_t*>(grsegs[chunknum]),
139 width,
140 height,
141 x & (~7),
142 y);
143 }
144
VWB_DrawMPic(int x,int y,int chunknum)145 void VWB_DrawMPic(
146 int x,
147 int y,
148 int chunknum)
149 {
150 int picnum = chunknum - STARTPICS;
151 int width = pictable[picnum].width;
152 int height = pictable[picnum].height;
153
154 VL_MaskMemToScreen(
155 static_cast<const uint8_t*>(grsegs[chunknum]),
156 width,
157 height,
158 x,
159 y,
160 255);
161 }
162
VWB_DrawPropString(const char * string)163 void VWB_DrawPropString(
164 const char* string)
165 {
166 VW_DrawPropString(string);
167 }
168
VWB_Bar(int x,int y,int width,int height,uint8_t color)169 void VWB_Bar(
170 int x,
171 int y,
172 int width,
173 int height,
174 uint8_t color)
175 {
176 VW_Bar(x, y, width, height, color);
177 }
178
VWB_Plot(int x,int y,uint8_t color)179 void VWB_Plot(
180 int x,
181 int y,
182 uint8_t color)
183 {
184 VW_Plot(x, y, color);
185 }
186
VWB_Hlin(int x1,int x2,int y,uint8_t color)187 void VWB_Hlin(
188 int x1,
189 int x2,
190 int y,
191 uint8_t color)
192 {
193 VW_Hlin(x1, x2, y, color);
194 }
195
VWB_Vlin(int y1,int y2,int x,uint8_t color)196 void VWB_Vlin(
197 int y1,
198 int y2,
199 int x,
200 uint8_t color)
201 {
202 VW_Vlin(y1, y2, x, color);
203 }
204
205
206 /*
207 =============================================================================
208
209 WOLFENSTEIN STUFF
210
211 =============================================================================
212 */
213
LatchDrawPic(int x,int y,int picnum)214 void LatchDrawPic(
215 int x,
216 int y,
217 int picnum)
218 {
219 int wide = pictable[picnum - STARTPICS].width;
220 int height = pictable[picnum - STARTPICS].height;
221 int source = latchpics[2 + picnum - LATCHPICS_LUMP_START];
222
223 VL_LatchToScreen(source, wide, height, x * 8, y);
224 }
225
LoadLatchMem()226 void LoadLatchMem()
227 {
228 // Calculate total size of latches cache.
229 //
230 const auto tile8_total_size =
231 ::STARTTILE8 * 8 * 8;
232
233 int pics_total_size = 0;
234
235 for (int i = ::LATCHPICS_LUMP_START; i <= ::LATCHPICS_LUMP_END; ++i)
236 {
237 const auto width = pictable[i - ::STARTPICS].width;
238 const auto height = pictable[i - ::STARTPICS].height;
239
240 pics_total_size += width * height;
241 }
242
243 const auto latches_cache_size = tile8_total_size + pics_total_size;
244
245 ::latches_cache.resize(
246 latches_cache_size);
247
248
249 int destoff = 0;
250 int picnum = 0;
251
252 //
253 // tile 8s
254 //
255 ::latchpics[picnum++] = destoff;
256 ::CA_CacheGrChunk(::STARTTILE8);
257 auto src = static_cast<const uint8_t*>(::grsegs[::STARTTILE8]);
258
259 for (int i = 0; i < ::NUMTILE8; ++i)
260 {
261 ::VL_MemToLatch(src, 8, 8, destoff);
262 src += 64;
263 destoff += 64;
264 }
265
266 ::UNCACHEGRCHUNK(::STARTTILE8);
267
268 //
269 // pics
270 //
271 ++picnum;
272
273 for (int i = ::LATCHPICS_LUMP_START; i <= ::LATCHPICS_LUMP_END; ++i)
274 {
275 const auto width = pictable[i - ::STARTPICS].width;
276 const auto height = pictable[i - ::STARTPICS].height;
277
278 ::CA_CacheGrChunk(i);
279
280 ::VL_MemToLatch(
281 static_cast<const uint8_t*>(::grsegs[i]),
282 width,
283 height,
284 destoff);
285
286 ::UNCACHEGRCHUNK(i);
287
288 ::latchpics[picnum++] = destoff;
289 destoff += width * height;
290 }
291 }
292
293 extern ControlInfo c;
294