ST_START.C 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //**************************************************************************
  2. //**
  3. //** st_start.c : Heretic 2 : Raven Software, Corp.
  4. //**
  5. //** $RCSfile: st_start.c,v $
  6. //** $Revision: 1.21 $
  7. //** $Date: 95/12/21 15:03:51 $
  8. //** $Author: bgokey $
  9. //**
  10. //**************************************************************************
  11. // HEADER FILES ------------------------------------------------------------
  12. #ifdef __WATCOMC__
  13. #include <sys\stat.h>
  14. #include <sys\types.h>
  15. #include <io.h>
  16. #else
  17. #include <libc.h>
  18. #include <ctype.h>
  19. #define O_BINARY 0
  20. #endif
  21. #include "h2def.h"
  22. #include <fcntl.h>
  23. #include <stdarg.h> // Needed for next as well as dos
  24. #include "st_start.h"
  25. // MACROS ------------------------------------------------------------------
  26. #define ST_MAX_NOTCHES 32
  27. #define ST_NOTCH_WIDTH 16
  28. #define ST_NOTCH_HEIGHT 23
  29. #define ST_PROGRESS_X 64 // Start of notches x screen pos.
  30. #define ST_PROGRESS_Y 441 // Start of notches y screen pos.
  31. #define ST_NETPROGRESS_X 288
  32. #define ST_NETPROGRESS_Y 32
  33. #define ST_NETNOTCH_WIDTH 8
  34. #define ST_NETNOTCH_HEIGHT 16
  35. #define ST_MAX_NETNOTCHES 8
  36. // TYPES -------------------------------------------------------------------
  37. // EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
  38. extern void SetVideoModeHR(void);
  39. extern void ClearScreenHR(void);
  40. extern void SlamHR(char *buffer);
  41. extern void SlamBlockHR(int x, int y, int w, int h, char *src);
  42. extern void InitPaletteHR(void);
  43. extern void SetPaletteHR(byte *palette);
  44. extern void GetPaletteHR(byte *palette);
  45. extern void FadeToPaletteHR(byte *palette);
  46. extern void FadeToBlackHR(void);
  47. extern void BlackPaletteHR(void);
  48. extern void I_StartupReadKeys(void);
  49. // PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
  50. // PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
  51. char *ST_LoadScreen(void);
  52. void ST_UpdateNotches(int notchPosition);
  53. void ST_UpdateNetNotches(int notchPosition);
  54. // EXTERNAL DATA DECLARATIONS ----------------------------------------------
  55. // PUBLIC DATA DEFINITIONS -------------------------------------------------
  56. // PRIVATE DATA DEFINITIONS ------------------------------------------------
  57. char *bitmap = NULL;
  58. char notchTable[]=
  59. {
  60. // plane 0
  61. 0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40,
  62. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xC0,
  63. 0x0F, 0x90, 0x1B, 0x68, 0x3D, 0xBC, 0x3F, 0xFC, 0x20, 0x08, 0x20, 0x08,
  64. 0x2F, 0xD8, 0x37, 0xD8, 0x37, 0xF8, 0x1F, 0xF8, 0x1C, 0x50,
  65. // plane 1
  66. 0x00, 0x80, 0x01, 0x80, 0x00, 0x00, 0x00, 0x00, 0x02, 0x40, 0x02, 0x40,
  67. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x01, 0xA0,
  68. 0x30, 0x6C, 0x24, 0x94, 0x42, 0x4A, 0x60, 0x0E, 0x60, 0x06, 0x7F, 0xF6,
  69. 0x7F, 0xF6, 0x7F, 0xF6, 0x5E, 0xF6, 0x38, 0x16, 0x23, 0xAC,
  70. // plane 2
  71. 0x00, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, 0x02, 0x40, 0x02, 0x40,
  72. 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x03, 0xE0,
  73. 0x30, 0x6C, 0x24, 0x94, 0x52, 0x6A, 0x7F, 0xFE, 0x60, 0x0E, 0x60, 0x0E,
  74. 0x6F, 0xD6, 0x77, 0xD6, 0x56, 0xF6, 0x38, 0x36, 0x23, 0xAC,
  75. // plane 3
  76. 0x00, 0x00, 0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
  77. 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0x80, 0x02, 0x40,
  78. 0x0F, 0x90, 0x1B, 0x68, 0x3D, 0xB4, 0x1F, 0xF0, 0x1F, 0xF8, 0x1F, 0xF8,
  79. 0x10, 0x28, 0x08, 0x28, 0x29, 0x08, 0x07, 0xE8, 0x1C, 0x50
  80. };
  81. // Red Network Progress notches
  82. char netnotchTable[]=
  83. {
  84. // plane 0
  85. 0x80, 0x50, 0xD0, 0xf0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xD0, 0xF0, 0xC0,
  86. 0x70, 0x50, 0x80, 0x60,
  87. // plane 1
  88. 0x60, 0xE0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0xA0, 0xA0, 0xA0, 0xE0, 0xA0,
  89. 0xA0, 0xE0, 0x60, 0x00,
  90. // plane 2
  91. 0x80, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00,
  92. 0x10, 0x10, 0x80, 0x60,
  93. // plane 3
  94. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  95. 0x00, 0x00, 0x00, 0x00
  96. };
  97. // CODE --------------------------------------------------------------------
  98. //--------------------------------------------------------------------------
  99. //
  100. // Startup Screen Functions
  101. //
  102. //--------------------------------------------------------------------------
  103. //==========================================================================
  104. //
  105. // ST_Init - Do the startup screen
  106. //
  107. //==========================================================================
  108. void ST_Init(void)
  109. {
  110. #ifdef __WATCOMC__
  111. char *pal;
  112. char *buffer;
  113. if (!debugmode)
  114. {
  115. // Set 640x480x16 mode
  116. SetVideoModeHR();
  117. ClearScreenHR();
  118. InitPaletteHR();
  119. BlackPaletteHR();
  120. // Load graphic
  121. buffer = ST_LoadScreen();
  122. pal = buffer;
  123. bitmap = buffer + 16*3;
  124. SlamHR(bitmap);
  125. FadeToPaletteHR(pal);
  126. Z_Free(buffer);
  127. }
  128. #endif
  129. }
  130. void ST_Done(void)
  131. {
  132. #ifdef __WATCOMC__
  133. ClearScreenHR();
  134. #endif
  135. }
  136. //==========================================================================
  137. //
  138. // ST_UpdateNotches
  139. //
  140. //==========================================================================
  141. void ST_UpdateNotches(int notchPosition)
  142. {
  143. #ifdef __WATCOMC__
  144. int x = ST_PROGRESS_X + notchPosition*ST_NOTCH_WIDTH;
  145. int y = ST_PROGRESS_Y;
  146. SlamBlockHR(x,y, ST_NOTCH_WIDTH,ST_NOTCH_HEIGHT, notchTable);
  147. #endif
  148. }
  149. //==========================================================================
  150. //
  151. // ST_UpdateNetNotches - indicates network progress
  152. //
  153. //==========================================================================
  154. void ST_UpdateNetNotches(int notchPosition)
  155. {
  156. #ifdef __WATCOMC__
  157. int x = ST_NETPROGRESS_X + notchPosition*ST_NETNOTCH_WIDTH;
  158. int y = ST_NETPROGRESS_Y;
  159. SlamBlockHR(x,y, ST_NETNOTCH_WIDTH, ST_NETNOTCH_HEIGHT, netnotchTable);
  160. #endif
  161. }
  162. //==========================================================================
  163. //
  164. // ST_Progress - increments progress indicator
  165. //
  166. //==========================================================================
  167. void ST_Progress(void)
  168. {
  169. #ifdef __WATCOMC__
  170. static int notchPosition=0;
  171. // Check for ESC press -- during startup all events eaten here
  172. I_StartupReadKeys();
  173. if (debugmode)
  174. {
  175. printf(".");
  176. }
  177. else
  178. {
  179. if(notchPosition<ST_MAX_NOTCHES)
  180. {
  181. ST_UpdateNotches(notchPosition);
  182. S_StartSound(NULL, SFX_STARTUP_TICK);
  183. notchPosition++;
  184. }
  185. }
  186. #else
  187. printf(".");
  188. #endif
  189. }
  190. //==========================================================================
  191. //
  192. // ST_NetProgress - indicates network progress
  193. //
  194. //==========================================================================
  195. void ST_NetProgress(void)
  196. {
  197. #ifdef __WATCOMC__
  198. static int netnotchPosition=0;
  199. if (debugmode)
  200. {
  201. printf("*");
  202. }
  203. else
  204. {
  205. if(netnotchPosition<ST_MAX_NETNOTCHES)
  206. {
  207. ST_UpdateNetNotches(netnotchPosition);
  208. S_StartSound(NULL, SFX_DRIP);
  209. netnotchPosition++;
  210. }
  211. }
  212. #endif
  213. }
  214. //==========================================================================
  215. //
  216. // ST_NetDone - net progress complete
  217. //
  218. //==========================================================================
  219. void ST_NetDone(void)
  220. {
  221. S_StartSound(NULL, SFX_PICKUP_WEAPON);
  222. }
  223. //==========================================================================
  224. //
  225. // ST_Message - gives debug message
  226. //
  227. //==========================================================================
  228. void ST_Message(char *message, ...)
  229. {
  230. va_list argptr;
  231. char buffer[80];
  232. va_start(argptr, message);
  233. vsprintf(buffer, message, argptr);
  234. va_end(argptr);
  235. if ( strlen(buffer) >= 80 )
  236. {
  237. I_Error("Long debug message has overwritten memory");
  238. }
  239. #ifdef __WATCOMC__
  240. if (debugmode)
  241. {
  242. printf(buffer);
  243. }
  244. #else
  245. printf(buffer);
  246. #endif
  247. }
  248. //==========================================================================
  249. //
  250. // ST_RealMessage - gives user message
  251. //
  252. //==========================================================================
  253. void ST_RealMessage(char *message, ...)
  254. {
  255. va_list argptr;
  256. char buffer[80];
  257. va_start(argptr, message);
  258. vsprintf(buffer, message, argptr);
  259. va_end(argptr);
  260. if ( strlen(buffer) >= 80 )
  261. {
  262. I_Error("Long debug message has overwritten memory\n");
  263. }
  264. printf(buffer); // Always print these messages
  265. }
  266. //==========================================================================
  267. //
  268. // ST_LoadScreen - loads startup graphic
  269. //
  270. //==========================================================================
  271. char *ST_LoadScreen(void)
  272. {
  273. int length,lump;
  274. char *buffer;
  275. lump = W_GetNumForName("STARTUP");
  276. length = W_LumpLength(lump);
  277. buffer = (char *)Z_Malloc(length, PU_STATIC, NULL);
  278. W_ReadLump(lump, buffer);
  279. return(buffer);
  280. }