1 //
2 // Copyright(C) 1993-1996 Id Software, Inc.
3 // Copyright(C) 1993-2008 Raven Software
4 // Copyright(C) 2005-2014 Simon Howard
5 //
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 // GNU General Public License for more details.
15 //
16 
17 
18 
19 // HEADER FILES ------------------------------------------------------------
20 
21 #include <stdarg.h>
22 
23 #include "config.h"
24 
25 #include "h2def.h"
26 #include "i_system.h"
27 #include "i_video.h"
28 #include "i_videohr.h"
29 #include "s_sound.h"
30 #include "st_start.h"
31 
32 
33 // MACROS ------------------------------------------------------------------
34 #define ST_MAX_NOTCHES		32
35 #define ST_NOTCH_WIDTH		16
36 #define ST_NOTCH_HEIGHT		23
37 #define ST_PROGRESS_X		64      // Start of notches x screen pos.
38 #define ST_PROGRESS_Y		441     // Start of notches y screen pos.
39 
40 #define ST_NETPROGRESS_X		288
41 #define ST_NETPROGRESS_Y		32
42 #define ST_NETNOTCH_WIDTH		8
43 #define ST_NETNOTCH_HEIGHT		16
44 #define ST_MAX_NETNOTCHES		8
45 
46 byte *ST_LoadScreen(void);
47 void ST_UpdateNotches(int notchPosition);
48 void ST_UpdateNetNotches(int notchPosition);
49 
50 // PRIVATE DATA DEFINITIONS ------------------------------------------------
51 static const byte *bitmap = NULL;
52 int graphical_startup = 1;
53 static boolean using_graphical_startup;
54 
55 static const byte notchTable[] = {
56     // plane 0
57     0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40,
58     0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xC0,
59     0x0F, 0x90, 0x1B, 0x68, 0x3D, 0xBC, 0x3F, 0xFC, 0x20, 0x08, 0x20, 0x08,
60     0x2F, 0xD8, 0x37, 0xD8, 0x37, 0xF8, 0x1F, 0xF8, 0x1C, 0x50,
61 
62     // plane 1
63     0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x02, 0x40,
64     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xA0,
65     0x30, 0x6C, 0x24, 0x94, 0x42, 0x4A, 0x60, 0x0E, 0x60, 0x06, 0x7F, 0xF6,
66     0x7F, 0xF6, 0x7F, 0xF6, 0x5E, 0xF6, 0x38, 0x16, 0x23, 0xAC,
67 
68     // plane 2
69     0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x02, 0x40, 0x02, 0x40,
70     0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xE0,
71     0x30, 0x6C, 0x24, 0x94, 0x52, 0x6A, 0x7F, 0xFE, 0x60, 0x0E, 0x60, 0x0E,
72     0x6F, 0xD6, 0x77, 0xD6, 0x56, 0xF6, 0x38, 0x36, 0x23, 0xAC,
73 
74     // plane 3
75     0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
76     0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0x80, 0x02, 0x40,
77     0x0F, 0x90, 0x1B, 0x68, 0x3D, 0xB4, 0x1F, 0xF0, 0x1F, 0xF8, 0x1F, 0xF8,
78     0x10, 0x28, 0x08, 0x28, 0x29, 0x08, 0x07, 0xE8, 0x1C, 0x50
79 };
80 
81 
82 // Red Network Progress notches
83 static const byte netnotchTable[] = {
84     // plane 0
85     0x80, 0x50, 0xD0, 0xf0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xD0, 0xF0, 0xC0,
86     0x70, 0x50, 0x80, 0x60,
87 
88     // plane 1
89     0x60, 0xE0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0xA0,
90     0xA0, 0xE0, 0x60, 0x00,
91 
92     // plane 2
93     0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
94     0x10, 0x10, 0x80, 0x60,
95 
96     // plane 3
97     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
98     0x00, 0x00, 0x00, 0x00
99 };
100 
101 // CODE --------------------------------------------------------------------
102 
103 
104 
105 //--------------------------------------------------------------------------
106 //
107 // Startup Screen Functions
108 //
109 //--------------------------------------------------------------------------
110 
111 
112 //==========================================================================
113 //
114 // ST_Init - Do the startup screen
115 //
116 //==========================================================================
117 
ST_Init(void)118 void ST_Init(void)
119 {
120     byte *pal;
121     byte *buffer;
122 
123     using_graphical_startup = false;
124 
125     if (graphical_startup && !debugmode && !testcontrols)
126     {
127         I_SetWindowTitleHR("Hexen startup - " PACKAGE_STRING);
128 
129         // Set 640x480x16 mode
130         if (I_SetVideoModeHR())
131         {
132             using_graphical_startup = true;
133             I_InitWindowIcon();
134 
135             S_StartSongName("orb", true);
136 
137             I_ClearScreenHR();
138             I_InitPaletteHR();
139             I_BlackPaletteHR();
140 
141             // Load graphic
142             buffer = ST_LoadScreen();
143             pal = buffer;
144             bitmap = buffer + 16 * 3;
145 
146             I_SlamHR(bitmap);
147             I_FadeToPaletteHR(pal);
148             Z_Free(buffer);
149         }
150     }
151 }
152 
ST_Done(void)153 void ST_Done(void)
154 {
155     if (using_graphical_startup)
156     {
157         I_ClearScreenHR();
158         I_UnsetVideoModeHR();
159     }
160 }
161 
162 
163 //==========================================================================
164 //
165 // ST_UpdateNotches
166 //
167 //==========================================================================
168 
ST_UpdateNotches(int notchPosition)169 void ST_UpdateNotches(int notchPosition)
170 {
171     int x = ST_PROGRESS_X + notchPosition * ST_NOTCH_WIDTH;
172     int y = ST_PROGRESS_Y;
173     I_SlamBlockHR(x, y, ST_NOTCH_WIDTH, ST_NOTCH_HEIGHT, notchTable);
174 }
175 
176 
177 //==========================================================================
178 //
179 // ST_UpdateNetNotches - indicates network progress
180 //
181 //==========================================================================
182 
ST_UpdateNetNotches(int notchPosition)183 void ST_UpdateNetNotches(int notchPosition)
184 {
185     int x = ST_NETPROGRESS_X + notchPosition * ST_NETNOTCH_WIDTH;
186     int y = ST_NETPROGRESS_Y;
187     I_SlamBlockHR(x, y, ST_NETNOTCH_WIDTH, ST_NETNOTCH_HEIGHT, netnotchTable);
188 }
189 
190 
191 //==========================================================================
192 //
193 // ST_Progress - increments progress indicator
194 //
195 //==========================================================================
196 
ST_Progress(void)197 void ST_Progress(void)
198 {
199     // Check for ESC press -- during startup all events eaten here
200     if (I_CheckAbortHR())
201     {
202         I_Quit();
203     }
204 
205     if (using_graphical_startup)
206     {
207         static int notchPosition = 0;
208 
209         if (notchPosition < ST_MAX_NOTCHES)
210         {
211             ST_UpdateNotches(notchPosition);
212             S_StartSound(NULL, SFX_STARTUP_TICK);
213             //I_Sleep(1000);
214             notchPosition++;
215         }
216     }
217 
218     printf(".");
219 }
220 
221 
222 //==========================================================================
223 //
224 // ST_NetProgress - indicates network progress
225 //
226 //==========================================================================
227 
ST_NetProgress(void)228 void ST_NetProgress(void)
229 {
230     printf("*");
231 
232     if (using_graphical_startup)
233     {
234         static int netnotchPosition = 0;
235 
236         if (netnotchPosition < ST_MAX_NETNOTCHES)
237         {
238             ST_UpdateNetNotches(netnotchPosition);
239             S_StartSound(NULL, SFX_DRIP);
240             netnotchPosition++;
241         }
242     }
243 }
244 
245 
246 //==========================================================================
247 //
248 // ST_NetDone - net progress complete
249 //
250 //==========================================================================
ST_NetDone(void)251 void ST_NetDone(void)
252 {
253     if (using_graphical_startup)
254     {
255         S_StartSound(NULL, SFX_PICKUP_WEAPON);
256     }
257 }
258 
259 
260 //==========================================================================
261 //
262 // ST_Message - gives debug message
263 //
264 //==========================================================================
265 
ST_Message(char * message,...)266 void ST_Message(char *message, ...)
267 {
268     va_list argptr;
269 
270     va_start(argptr, message);
271     vprintf(message, argptr);
272     va_end(argptr);
273 }
274 
275 //==========================================================================
276 //
277 // ST_RealMessage - gives user message
278 //
279 //==========================================================================
280 
ST_RealMessage(char * message,...)281 void ST_RealMessage(char *message, ...)
282 {
283     va_list argptr;
284 
285     va_start(argptr, message);
286     vprintf(message, argptr);
287     va_end(argptr);
288 }
289 
290 
291 
292 //==========================================================================
293 //
294 // ST_LoadScreen - loads startup graphic
295 //
296 //==========================================================================
297 
298 
ST_LoadScreen(void)299 byte *ST_LoadScreen(void)
300 {
301     int length, lump;
302     byte *buffer;
303 
304     lump = W_GetNumForName("STARTUP");
305     length = W_LumpLength(lump);
306     buffer = (byte *) Z_Malloc(length, PU_STATIC, NULL);
307     W_ReadLump(lump, buffer);
308     return (buffer);
309 }
310 
311