Subversion Repositories Kolibri OS

Rev

Rev 298 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
298 serge 1
// Emacs style mode select   -*- C++ -*-
2
//-----------------------------------------------------------------------------
3
//
4
// $Id:$
5
//
6
// Copyright (C) 1993-1996 by id Software, Inc.
7
//
8
// This source is available for distribution and/or modification
9
// only under the terms of the DOOM Source Code License as
10
// published by id Software. All rights reserved.
11
//
12
// The source is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// FITNESS FOR A PARTICULAR PURPOSE. See the DOOM Source Code License
15
// for more details.
16
//
17
//
18
// $Log:$
19
//
20
// DESCRIPTION:
21
//	Main loop menu stuff.
22
//	Default Config File.
23
//	PCX Screenshots.
24
//
25
//-----------------------------------------------------------------------------
26
 
27
static const char
28
rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
29
 
30
#include 
31
#include 
32
 
33
extern int access(char *file, int mode);
34
 
35
#include "doomdef.h"
36
 
37
#include "z_zone.h"
38
 
39
#include "m_swap.h"
40
#include "m_argv.h"
41
 
42
#include "w_wad.h"
43
 
44
#include "i_system.h"
45
#include "i_video.h"
46
#include "v_video.h"
47
 
48
#include "hu_stuff.h"
49
 
50
// State.
51
#include "doomstat.h"
52
 
53
// Data.
54
#include "dstrings.h"
55
 
56
#include "m_misc.h"
57
 
58
//
59
// M_DrawText
60
// Returns the final X coordinate
61
// HU_Init must have been called to init the font
62
//
63
extern patch_t*		hu_font[HU_FONTSIZE];
64
 
65
int
66
M_DrawText
67
( int		x,
68
  int		y,
69
  boolean	direct,
70
  char*		string )
71
{
72
    int 	c;
73
    int		w;
74
 
75
    while (*string)
76
    {
77
	c = toupper(*string) - HU_FONTSTART;
78
	string++;
79
	if (c < 0 || c> HU_FONTSIZE)
80
	{
81
	    x += 4;
82
	    continue;
83
	}
84
 
85
	w = SHORT (hu_font[c]->width);
86
	if (x+w > SCREENWIDTH)
87
	    break;
88
	if (direct)
89
	    V_DrawPatchDirect(x, y, 0, hu_font[c]);
90
	else
91
	    V_DrawPatch(x, y, 0, hu_font[c]);
92
	x+=w;
93
    }
94
 
95
    return x;
96
}
97
 
98
 
99
 
100
 
101
//
102
// M_WriteFile
103
//
104
#ifndef O_BINARY
105
#define O_BINARY 0
106
#endif
107
 
108
boolean
109
M_WriteFile
110
( char const*	name,
111
  void*		source,
112
  int		length )
113
{
114
    FILE       *handle;
115
    int		count;
116
 
117
    handle = fopen ( name, "wb");
118
 
119
    if (handle == NULL)
120
	return false;
121
 
122
    count = fwrite (source, 1, length, handle);
123
    fclose (handle);
124
 
125
    if (count < length)
126
	return false;
127
 
128
    return true;
129
}
130
 
131
 
132
//
133
// M_ReadFile
134
//
135
int
136
M_ReadFile
137
( char const*	name,
138
  byte**	buffer )
139
{
140
    FILE *handle;
141
    int count, length;
142
    byte	*buf;
143
 
144
    handle = fopen (name, "rb");
145
    if (handle == NULL)
146
	I_Error ("Couldn't read file %s", name);
147
    fseek(handle, 0, SEEK_END);
148
    length = ftell(handle);
149
    rewind(handle);
150
    buf = Z_Malloc (length, PU_STATIC, NULL);
151
    count = fread (buf, 1, length, handle);
152
    fclose (handle);
153
 
154
    if (count < length)
155
	I_Error ("Couldn't read file %s", name);
156
 
157
    *buffer = buf;
158
    return length;
159
}
160
 
161
 
162
//
163
// DEFAULTS
164
//
165
int		usemouse;
166
int		usejoystick;
167
 
168
extern int	key_right;
169
extern int	key_left;
170
extern int	key_up;
171
extern int	key_down;
172
 
173
extern int	key_strafeleft;
174
extern int	key_straferight;
175
 
176
extern int	key_fire;
177
extern int	key_use;
178
extern int	key_strafe;
179
extern int	key_speed;
180
 
181
extern int	mousebfire;
182
extern int	mousebstrafe;
183
extern int	mousebforward;
184
 
185
extern int	joybfire;
186
extern int	joybstrafe;
187
extern int	joybuse;
188
extern int	joybspeed;
189
 
190
extern int	viewwidth;
191
extern int	viewheight;
192
 
193
extern int	mouseSensitivity;
194
extern int	showMessages;
195
 
196
extern int	detailLevel;
197
 
198
extern int	screenblocks;
199
 
200
extern int	showMessages;
201
 
202
// machine-independent sound params
203
extern	int	numChannels;
204
 
205
 
206
extern char*	chat_macros[];
207
 
208
 
209
 
210
typedef struct
211
{
212
    char*	name;
213
    int*	location;
214
    int		defaultvalue;
215
    int		scantranslate;		// PC scan code hack
216
    int		untranslated;		// lousy hack
217
} default_t;
218
 
219
default_t	defaults[] =
220
{
221
    {"mouse_sensitivity",&mouseSensitivity, 5},
222
    {"sfx_volume",&snd_SfxVolume, 8},
223
    {"music_volume",&snd_MusicVolume, 8},
224
    {"show_messages",&showMessages, 1},
225
 
226
 
227
    {"key_right",&key_right, KEY_RIGHTARROW},
228
    {"key_left",&key_left, KEY_LEFTARROW},
229
    {"key_up",&key_up, KEY_UPARROW},
230
    {"key_down",&key_down, KEY_DOWNARROW},
231
    {"key_strafeleft",&key_strafeleft, ','},
232
    {"key_straferight",&key_straferight, '.'},
233
 
234
    {"key_fire",&key_fire, KEY_RCTRL},
235
    {"key_use",&key_use, ' '},
236
    {"key_strafe",&key_strafe, KEY_RALT},
237
    {"key_speed",&key_speed, KEY_RSHIFT},
238
 
239
    {"use_mouse",&usemouse, 1},
240
    {"mouseb_fire",&mousebfire,0},
241
    {"mouseb_strafe",&mousebstrafe,1},
242
    {"mouseb_forward",&mousebforward,2},
243
 
244
    {"use_joystick",&usejoystick, 0},
245
    {"joyb_fire",&joybfire,0},
246
    {"joyb_strafe",&joybstrafe,1},
247
    {"joyb_use",&joybuse,3},
248
    {"joyb_speed",&joybspeed,2},
249
 
250
    {"screenblocks",&screenblocks, 9},
251
    {"detaillevel",&detailLevel, 0},
252
 
253
    {"snd_channels",&numChannels, 3},
254
 
255
 
256
 
257
    {"usegamma",&usegamma, 0},
258
 
259
#ifndef __BEOS__
260
    {"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 },
261
    {"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 },
262
    {"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 },
263
    {"chatmacro3", (int *) &chat_macros[3], (int) HUSTR_CHATMACRO3 },
264
    {"chatmacro4", (int *) &chat_macros[4], (int) HUSTR_CHATMACRO4 },
265
    {"chatmacro5", (int *) &chat_macros[5], (int) HUSTR_CHATMACRO5 },
266
    {"chatmacro6", (int *) &chat_macros[6], (int) HUSTR_CHATMACRO6 },
267
    {"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 },
268
    {"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 },
269
    {"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 }
270
#endif
271
 
272
};
273
 
274
int	numdefaults;
275
char*	defaultfile;
276
 
277
 
278
//
279
// M_SaveDefaults
280
//
281
void M_SaveDefaults (void)
282
{
283
    int		i;
284
    int		v;
285
    FILE*	f;
286
 
287
    f = fopen (defaultfile, "w");
288
    if (!f)
289
	return; // can't write the file, but don't complain
290
 
291
    for (i=0 ; i
292
    {
293
	if (defaults[i].defaultvalue > -0xfff
294
	    && defaults[i].defaultvalue < 0xfff)
295
	{
296
	    v = *defaults[i].location;
300 serge 297
	    printf ("%s\t\t%i\n",defaults[i].name,v);
298 serge 298
	} else {
300 serge 299
	    printf ("%s\t\t\"%s\"\n",defaults[i].name,
298 serge 300
		     * (char **) (defaults[i].location));
301
	}
302
    }
303
 
304
    fclose (f);
305
}
306
 
307
 
308
//
309
// M_LoadDefaults
310
//
311
extern byte	scantokey[128];
312
 
313
void M_LoadDefaults (void)
314
{
315
    int		i;
316
    int		len;
317
    FILE*	f;
318
    char	def[80];
319
    char	strparm[100];
320
    char*	newstring;
321
    int		parm;
322
    boolean	isstring;
323
 
324
    // set everything to base values
325
    numdefaults = sizeof(defaults)/sizeof(defaults[0]);
326
    for (i=0 ; i
327
	*defaults[i].location = defaults[i].defaultvalue;
328
 
329
    // check for a custom default file
330
    i = M_CheckParm ("-config");
331
    if (i && i
332
    {
333
	defaultfile = myargv[i+1];
334
//	__libclog_printf ("	default file: %s\n",defaultfile);
335
    }
336
    else
337
	defaultfile = basedefault;
300 serge 338
/**********
298 serge 339
    // read the file in, overriding any set defaults
340
    f = fopen (defaultfile, "r");
341
    if (f)
342
    {
343
	while (!feof(f))
344
	{
345
	    isstring = false;
346
	    if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
347
	    {
348
		if (strparm[0] == '"')
349
		{
350
		    // get a string default
351
		    isstring = true;
352
		    len = strlen(strparm);
353
		    newstring = (char *) malloc(len);
354
		    strparm[len-1] = 0;
355
		    strcpy(newstring, strparm+1);
356
		}
357
		else if (strparm[0] == '0' && strparm[1] == 'x')
358
		    sscanf(strparm+2, "%x", &parm);
359
		else
360
		    sscanf(strparm, "%i", &parm);
361
		for (i=0 ; i
362
		    if (!strcmp(def, defaults[i].name))
363
		    {
364
			if (!isstring)
365
			    *defaults[i].location = parm;
366
			else
367
			    *defaults[i].location =
368
				(int) newstring;
369
			break;
370
		    }
371
	    }
372
	}
373
 
374
	fclose (f);
375
    }
300 serge 376
**********/
298 serge 377
}
378
 
379
 
380
//
381
// SCREEN SHOTS
382
//
383
 
384
 
385
typedef struct
386
{
387
    char		manufacturer;
388
    char		version;
389
    char		encoding;
390
    char		bits_per_pixel;
391
 
392
    unsigned short	xmin;
393
    unsigned short	ymin;
394
    unsigned short	xmax;
395
    unsigned short	ymax;
396
 
397
    unsigned short	hres;
398
    unsigned short	vres;
399
 
400
    unsigned char	palette[48];
401
 
402
    char		reserved;
403
    char		color_planes;
404
    unsigned short	bytes_per_line;
405
    unsigned short	palette_type;
406
 
407
    char		filler[58];
408
    unsigned char	data;		// unbounded
409
} pcx_t;
410
 
411
 
412
//
413
// WritePCXfile
414
//
415
void
416
WritePCXfile
417
( char*		filename,
418
  byte*		data,
419
  int		width,
420
  int		height,
421
  byte*		palette )
422
{
423
    int		i;
424
    int		length;
425
    pcx_t*	pcx;
426
    byte*	pack;
427
 
428
    pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL);
429
 
430
    pcx->manufacturer = 0x0a;		// PCX id
431
    pcx->version = 5;			// 256 color
432
    pcx->encoding = 1;			// uncompressed
433
    pcx->bits_per_pixel = 8;		// 256 color
434
    pcx->xmin = 0;
435
    pcx->ymin = 0;
436
    pcx->xmax = SHORT(width-1);
437
    pcx->ymax = SHORT(height-1);
438
    pcx->hres = SHORT(width);
439
    pcx->vres = SHORT(height);
440
    memset (pcx->palette,0,sizeof(pcx->palette));
441
    pcx->color_planes = 1;		// chunky image
442
    pcx->bytes_per_line = SHORT(width);
443
    pcx->palette_type = SHORT(2);	// not a grey scale
444
    memset (pcx->filler,0,sizeof(pcx->filler));
445
 
446
 
447
    // pack the image
448
    pack = &pcx->data;
449
 
450
    for (i=0 ; i
451
    {
452
	if ( (*data & 0xc0) != 0xc0)
453
	    *pack++ = *data++;
454
	else
455
	{
456
	    *pack++ = 0xc1;
457
	    *pack++ = *data++;
458
	}
459
    }
460
 
461
    // write the palette
462
    *pack++ = 0x0c;	// palette ID byte
463
    for (i=0 ; i<768 ; i++)
464
	*pack++ = *palette++;
465
 
466
    // write output file
467
    length = pack - (byte *)pcx;
468
    M_WriteFile (filename, pcx, length);
469
 
470
    Z_Free (pcx);
471
}
472
 
473
 
474
//
475
// M_ScreenShot
476
//
477
void M_ScreenShot (void)
478
{
479
    int		i;
480
    byte*	linear;
481
    char	lbmname[12];
482
 
483
    // munge planar buffer to linear
484
    linear = screens[2];
485
    I_ReadScreen (linear);
486
 
487
    // find a file name to save it to
488
    strcpy(lbmname,"DOOM00.pcx");
489
 
490
    for (i=0 ; i<=99 ; i++)
491
    {
492
	lbmname[4] = i/10 + '0';
493
	lbmname[5] = i%10 + '0';
494
	if (access(lbmname,0) == -1)
495
	    break;	// file doesn't exist
496
    }
497
    if (i==100)
498
	I_Error ("M_ScreenShot: Couldn't create a PCX");
499
 
500
    // save the pcx file
501
    WritePCXfile (lbmname, linear,
502
		  SCREENWIDTH, SCREENHEIGHT,
503
		  W_CacheLumpName ("PLAYPAL",PU_CACHE));
504
 
505
    players[consoleplayer].message = "screen shot";
506
}
507
 
508