Subversion Repositories Kolibri OS

Rev

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