SETUP.C 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // SETUP PROGRAM
  3. // (C) 1994 id Software, inc.
  4. // by John Romero
  5. // October 1-?
  6. //
  7. #include <stdio.h>
  8. #include <dos.h>
  9. #include <conio.h>
  10. #include <mem.h>
  11. #include <stdlib.h>
  12. #include "main.h" // #includes setup.h
  13. //
  14. // Fatal error
  15. //
  16. char errorstring[80];
  17. void Error(char *string)
  18. {
  19. textbackground(0);
  20. textcolor(7);
  21. clrscr();
  22. printf("%s\n",string);
  23. exit(1);
  24. }
  25. void DrawRadios(radiogroup_t *rg)
  26. {
  27. int i;
  28. int value;
  29. radio_t *r;
  30. char far *screen;
  31. byte color;
  32. value = *(rg->master);
  33. color = (rg->bgcolor << 4)+rg->fgcolor;
  34. r = rg->radios;
  35. for (i = 0; i < rg->amount; i++)
  36. {
  37. screen = MK_FP(0xb800,(r->y*160)+(r->x*2));
  38. *(screen+1) = color;
  39. if (value == r->value)
  40. *screen = 7;
  41. else
  42. *screen = ' ';
  43. r++;
  44. }
  45. }
  46. //
  47. // Save screens
  48. //
  49. static int layer = 0; // which screen layer we're at
  50. char far screens[MAXLAYERS][4000];
  51. void SaveScreen(void)
  52. {
  53. movedata(0xb800,0,FP_SEG(&screens[layer]),FP_OFF(&screens[layer]),4000);
  54. layer++;
  55. if (layer > MAXLAYERS)
  56. {
  57. sprintf(errorstring,"More than %d layers!",layer);
  58. Error(errorstring);
  59. }
  60. }
  61. //
  62. // Restore screens
  63. //
  64. void RestoreScreen(void)
  65. {
  66. layer--;
  67. if (layer < 0)
  68. Error("Restored one layer too many!");
  69. movedata(FP_SEG(&screens[layer]),FP_OFF(&screens[layer]),0xb800,0,4000);
  70. }
  71. //
  72. // Draw the dim 3-D edge of a window
  73. //
  74. void DrawDimEdge(pup_t far *pup)
  75. {
  76. char far *screen;
  77. int i;
  78. if ((pup->x + pup->width + 1 > 79) ||
  79. (pup->y + pup->height > 24))
  80. return;
  81. for (i = pup->y + 1; i < pup->y + pup->height + 1; i++)
  82. {
  83. screen = MK_FP(0xb800,i*160 + (pup->x + pup->width)*2);
  84. *(screen+1) = 8;
  85. *(screen+3) = 8;
  86. }
  87. screen = MK_FP(0xb800,(pup->y + pup->height)*160 + (pup->x+2)*2);
  88. for (i = 0; i < pup->width; i++)
  89. {
  90. *(screen+1) = 8;
  91. screen += 2;
  92. }
  93. }
  94. //
  95. // Draw LaughingDog .PUP files!
  96. //
  97. void DrawPup(pup_t far *pup)
  98. {
  99. int width;
  100. int w;
  101. int height;
  102. int x;
  103. int y;
  104. char far *data;
  105. byte code;
  106. char far *screen;
  107. char c;
  108. char a;
  109. short times;
  110. int i;
  111. int string;
  112. w = width = pup->width;
  113. height = pup->height;
  114. x = pup->x;
  115. y = pup->y;
  116. DrawDimEdge(pup);
  117. data = (char far *)(pup + 1);
  118. screen = MK_FP(0xb800,y*160 + x*2);
  119. string = normal;
  120. while(1)
  121. {
  122. code = *data++;
  123. switch(code)
  124. {
  125. case 0: // String of chars w/same attribute
  126. if (string == stringdraw)
  127. {
  128. string = normal;
  129. break;
  130. }
  131. string = stringdraw;
  132. c = *data++; // char
  133. a = *data++; // attribute
  134. *screen++ = c;
  135. *screen++ = a;
  136. if (!--w)
  137. {
  138. if (!--height)
  139. return; // finished!
  140. w = width;
  141. y++;
  142. screen = MK_FP(0xb800,y*160 + x*2);
  143. }
  144. break;
  145. case 0xff: // Repeated byte
  146. c = *data++;
  147. a = *data++;
  148. times = (*data * 256) + *(data+1);
  149. data+=2;
  150. for (i = 0;i < times; i++)
  151. {
  152. *screen++ = c;
  153. *screen++ = a;
  154. if (!--w)
  155. {
  156. if (!--height)
  157. return; // finished!
  158. w = width;
  159. y++;
  160. screen = MK_FP(0xb800,y*160 + x*2);
  161. }
  162. }
  163. break;
  164. default: // char/attibute combo
  165. if (string != stringdraw)
  166. a = *data++;
  167. c = code;
  168. *screen++ = c;
  169. *screen++ = a;
  170. if (!--w)
  171. {
  172. if (!--height)
  173. return; // finished!
  174. w = width;
  175. y++;
  176. screen = MK_FP(0xb800,y*160 + x*2);
  177. }
  178. break;
  179. }
  180. }
  181. }
  182. char **myargv;
  183. int myargc;
  184. void main(int argc, char *argv[])
  185. {
  186. myargv = argv;
  187. myargc = argc;
  188. #ifdef DEBUG
  189. ShowAllPups();
  190. #endif
  191. StartUp();
  192. }