Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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