Subversion Repositories Kolibri OS

Rev

Rev 333 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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