This repository has been archived by the owner on May 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
/
id_vh.c
302 lines (241 loc) · 7.18 KB
/
id_vh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
#include "wl_def.h"
pictabletype *pictable;
int px,py;
byte fontcolor,backcolor;
int fontnumber;
//==========================================================================
void VWB_DrawPropString(const char* string)
{
fontstruct *font;
int width, step, height;
byte *source, *dest;
byte ch;
int i;
int sx, sy;
dest = VL_LockSurface(screenBuffer);
if(dest == NULL) return;
font = (fontstruct *) grsegs[STARTFONT+fontnumber];
height = font->height;
dest += scaleFactor * (ylookup[py] + px);
while ((ch = (byte)*string++)!=0)
{
width = step = font->width[ch];
source = ((byte *)font)+font->location[ch];
while (width--)
{
for(i=0; i<height; i++)
{
if(source[i*step])
{
for(sy=0; sy<scaleFactor; sy++)
for(sx=0; sx<scaleFactor; sx++)
dest[ylookup[scaleFactor*i+sy]+sx]=fontcolor;
}
}
source++;
px++;
dest+=scaleFactor;
}
}
VL_UnlockSurface(screenBuffer);
}
void VWL_MeasureString (const char *string, word *width, word *height, fontstruct *font)
{
*height = font->height;
for (*width = 0;*string;string++)
*width += font->width[*((byte *)string)]; // proportional width
}
void VW_MeasurePropString (const char *string, word *width, word *height)
{
VWL_MeasureString(string,width,height,(fontstruct *)grsegs[STARTFONT+fontnumber]);
}
/*
=============================================================================
Double buffer management routines
=============================================================================
*/
void VH_UpdateScreen (SDL_Surface *surface)
{
SDL_BlitSurface (surface,NULL,screen,NULL);
SDL_UpdateTexture(texture, NULL, screen->pixels, screenPitch);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
void VWB_DrawTile8 (int x, int y, int tile)
{
VL_MemToScreen (grsegs[STARTTILE8]+tile*64,8,8,x,y);
}
void VWB_DrawPic (int x, int y, int chunknum)
{
int picnum = chunknum - STARTPICS;
unsigned width,height;
x &= ~7;
width = pictable[picnum].width;
height = pictable[picnum].height;
VL_MemToScreen (grsegs[chunknum],width,height,x,y);
}
void VWB_DrawPicScaledCoord (int scx, int scy, int chunknum)
{
int picnum = chunknum - STARTPICS;
unsigned width,height;
width = pictable[picnum].width;
height = pictable[picnum].height;
VL_MemToScreenScaledCoord (grsegs[chunknum],width,height,scx,scy);
}
void VWB_Bar (int x, int y, int width, int height, int color)
{
VW_Bar (x,y,width,height,color);
}
void VWB_Plot (int x, int y, int color)
{
if(scaleFactor == 1)
VW_Plot(x,y,color);
else
VW_Bar(x, y, 1, 1, color);
}
void VWB_Hlin (int x1, int x2, int y, int color)
{
if(scaleFactor == 1)
VW_Hlin(x1,x2,y,color);
else
VW_Bar(x1, y, x2-x1+1, 1, color);
}
void VWB_Vlin (int y1, int y2, int x, int color)
{
if(scaleFactor == 1)
VW_Vlin(y1,y2,x,color);
else
VW_Bar(x, y1, 1, y2-y1+1, color);
}
/*
=============================================================================
WOLFENSTEIN STUFF
=============================================================================
*/
/*
===================
=
= FizzleFade
=
= returns true if aborted
=
= It uses maximum-length Linear Feedback Shift Registers (LFSR) counters.
= You can find a list of them with lengths from 3 to 168 at:
= http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf
= Many thanks to Xilinx for this list!!!
=
===================
*/
// XOR masks for the pseudo-random number sequence starting with n=17 bits
static const uint32_t rndmasks[] = {
// n XNOR from (starting at 1, not 0 as usual)
0x00012000, // 17 17,14
0x00020400, // 18 18,11
0x00040023, // 19 19,6,2,1
0x00090000, // 20 20,17
0x00140000, // 21 21,19
0x00300000, // 22 22,21
0x00420000, // 23 23,18
0x00e10000, // 24 24,23,22,17
0x01200000, // 25 25,22 (this is enough for 8191x4095)
};
static unsigned int rndbits_y;
static unsigned int rndmask;
extern SDL_Color curpal[256];
// Returns the number of bits needed to represent the given value
static int log2_ceil(uint32_t x)
{
int n = 0;
uint32_t v = 1;
while(v < x)
{
n++;
v <<= 1;
}
return n;
}
void VH_Startup()
{
int rndbits_x = log2_ceil(screenWidth);
rndbits_y = log2_ceil(screenHeight);
int rndbits = rndbits_x + rndbits_y;
if(rndbits < 17)
rndbits = 17; // no problem, just a bit slower
else if(rndbits > 25)
rndbits = 25; // fizzle fade will not fill whole screen
rndmask = rndmasks[rndbits - 17];
}
boolean FizzleFade (SDL_Surface *source, int x1, int y1,
unsigned width, unsigned height, unsigned frames, boolean abortable)
{
unsigned x, y, p, frame, pixperframe;
int32_t rndval;
rndval = 1;
pixperframe = width * height / frames;
IN_StartAck ();
frame = GetTimeCount();
byte *srcptr = VL_LockSurface(source);
if(srcptr == NULL) return false;
while (1)
{
IN_ProcessEvents();
if(abortable && IN_CheckAck ())
{
VL_UnlockSurface(source);
VH_UpdateScreen (source);
return true;
}
byte *destptr = VL_LockSurface(screen);
if (!destptr)
Quit ("Unable to lock dest surface: %s\n",SDL_GetError());
for (p = 0; p < pixperframe; p++)
{
//
// seperate random value into x/y pair
//
x = rndval >> rndbits_y;
y = rndval & ((1 << rndbits_y) - 1);
//
// advance to next random element
//
rndval = (rndval >> 1) ^ (rndval & 1 ? 0 : rndmask);
if (x >= width || y >= height)
p--; // not into the view area; get a new pair
else
{
//
// copy one pixel
//
if(screenBits == 8)
{
*(destptr + (y1 + y) * screen->pitch + x1 + x)
= *(srcptr + (y1 + y) * source->pitch + x1 + x);
}
else
{
byte col = *(srcptr + (y1 + y) * source->pitch + x1 + x);
uint32_t fullcol = SDL_MapRGBA(screen->format, curpal[col].r, curpal[col].g, curpal[col].b,SDL_ALPHA_OPAQUE);
memcpy(destptr + (y1 + y) * screen->pitch + (x1 + x) * screen->format->BytesPerPixel,
&fullcol, screen->format->BytesPerPixel);
}
}
if (rndval == 1)
{
//
// entire sequence has been completed
//
VL_UnlockSurface (screenBuffer);
VL_UnlockSurface (screen);
VH_UpdateScreen (screenBuffer);
return false;
}
}
VL_UnlockSurface(screen);
SDL_UpdateTexture(texture, NULL, screen->pixels, screenPitch);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
frame++;
Delay(frame - GetTimeCount()); // don't go too fast
}
return false;
}