1 // Emacs style mode select -*- C++ -*-
2 //-----------------------------------------------------------------------------
6 // Copyright (C) 1993-1996 by id Software, Inc.
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.
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
21 // Main loop menu stuff.
22 // Default Config File.
25 //-----------------------------------------------------------------------------
28 rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
56 // Returns the final X coordinate
57 // HU_Init must have been called to init the font
59 extern patch_t* hu_font[HU_FONTSIZE];
73 c = toupper(*string) - HU_FONTSTART;
75 if (c < 0 || c> HU_FONTSIZE)
81 w = SHORT (hu_font[c]->width);
82 if (x+w > SCREENWIDTH)
85 V_DrawPatchDirect(x, y, 0, hu_font[c]);
87 V_DrawPatch(x, y, 0, hu_font[c]);
108 if((fd = create(name, OWRITE, 0644)) < 0)
110 n = write(fd, source, length);
128 if((fd = open(name, OREAD)) < 0)
129 I_Error ("Couldn't open file %s", name);
130 if((d = dirfstat(fd)) == nil)
131 I_Error ("Couldn't stat file %s", name);
135 buf = Z_Malloc(length, PU_STATIC, NULL);
136 if(readn(fd, buf, length) != length)
137 I_Error ("Couldn't read file %s", name);
150 extern int key_right;
155 extern int key_strafeleft;
156 extern int key_straferight;
160 extern int key_strafe;
161 extern int key_speed;
163 extern int mousebfire;
164 extern int mousebstrafe;
165 extern int mousebforward;
168 extern int joybstrafe;
170 extern int joybspeed;
172 extern int viewwidth;
173 extern int viewheight;
175 extern int mouseSensitivity;
176 extern int showMessages;
178 extern int detailLevel;
180 extern int screenblocks;
182 extern int showMessages;
184 // machine-independent sound params
185 extern int numChannels;
187 extern char* chat_macros[];
197 default_t defaults[] =
199 {"mouse_sensitivity",&mouseSensitivity, 5},
200 {"sfx_volume",&snd_SfxVolume, 8},
201 {"music_volume",&snd_MusicVolume, 8},
202 {"show_messages",&showMessages, 1},
205 {"key_right",&key_right, KEY_RIGHTARROW},
206 {"key_left",&key_left, KEY_LEFTARROW},
207 {"key_up",&key_up, KEY_UPARROW},
208 {"key_down",&key_down, KEY_DOWNARROW},
209 {"key_strafeleft",&key_strafeleft, ','},
210 {"key_straferight",&key_straferight, '.'},
212 {"key_fire",&key_fire, KEY_RCTRL},
213 {"key_use",&key_use, ' '},
214 {"key_strafe",&key_strafe, KEY_RALT},
215 {"key_speed",&key_speed, KEY_RSHIFT},
217 {"use_mouse",&usemouse, 1},
218 {"mouseb_fire",&mousebfire,0},
219 {"mouseb_strafe",&mousebstrafe,1},
220 {"mouseb_forward",&mousebforward,2},
222 {"use_joystick",&usejoystick, 0},
223 {"joyb_fire",&joybfire,0},
224 {"joyb_strafe",&joybstrafe,1},
225 {"joyb_use",&joybuse,3},
226 {"joyb_speed",&joybspeed,2},
228 {"screenblocks",&screenblocks, 9},
229 {"detaillevel",&detailLevel, 0},
231 {"snd_channels",&numChannels, 3},
233 {"usegamma",&usegamma, 0},
235 {"chatmacro0",&chat_macros[0], 0, HUSTR_CHATMACRO0 },
236 {"chatmacro1",&chat_macros[1], 0, HUSTR_CHATMACRO1 },
237 {"chatmacro2",&chat_macros[2], 0, HUSTR_CHATMACRO2 },
238 {"chatmacro3",&chat_macros[3], 0, HUSTR_CHATMACRO3 },
239 {"chatmacro4",&chat_macros[4], 0, HUSTR_CHATMACRO4 },
240 {"chatmacro5",&chat_macros[5], 0, HUSTR_CHATMACRO5 },
241 {"chatmacro6",&chat_macros[6], 0, HUSTR_CHATMACRO6 },
242 {"chatmacro7",&chat_macros[7], 0, HUSTR_CHATMACRO7 },
243 {"chatmacro8",&chat_macros[8], 0, HUSTR_CHATMACRO8 },
244 {"chatmacro9",&chat_macros[9], 0, HUSTR_CHATMACRO9 }
254 void M_SaveDefaults (void)
259 f = fopen (defaultfile, "w");
261 return; // can't write the file, but don't complain
263 for (i=0 ; i<numdefaults ; i++)
265 if (defaults[i].defaultstring == 0)
267 fprintf (f,"%s\t\t%i\n",defaults[i].name,
268 *((int*)defaults[i].location));
270 fprintf (f,"%s\t\t\"%s\"\n",defaults[i].name,
271 *((char**)defaults[i].location));
282 void M_LoadDefaults (void)
292 // set everything to base values
293 numdefaults = sizeof(defaults)/sizeof(defaults[0]);
294 for (i=0 ; i<numdefaults ; i++)
295 if(defaults[i].defaultstring == 0)
296 *((int*)defaults[i].location) = defaults[i].defaultvalue;
298 *((char**)defaults[i].location) = defaults[i].defaultstring;
300 // check for a custom default file
301 i = M_CheckParm ("-config");
303 defaultfile = myargv[i+1];
305 defaultfile = basedefault;
306 printf (" default file: %s\n",defaultfile);
308 // read the file in, overriding any set defaults
309 f = fopen (defaultfile, "r");
314 if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
318 if (strparm[0] == '"')
320 // get a string default
321 len = strlen(strparm);
322 newstring = (char *) malloc(len);
324 strcpy(newstring, strparm+1);
326 else if (strparm[0] == '0' && strparm[1] == 'x')
327 sscanf(strparm+2, "%x", &parm);
329 sscanf(strparm, "%i", &parm);
330 for (i=0 ; i<numdefaults ; i++)
331 if (!strcmp(def, defaults[i].name))
333 if (defaults[i].defaultstring == 0)
334 *((int*)defaults[i].location) = parm;
336 *((char**)defaults[i].location) = newstring;
367 unsigned char palette[48];
371 unsigned short bytes_per_line;
372 unsigned short palette_type;
375 unsigned char data; // unbounded
395 pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL);
397 pcx->manufacturer = 0x0a; // PCX id
398 pcx->version = 5; // 256 color
399 pcx->encoding = 1; // uncompressed
400 pcx->bits_per_pixel = 8; // 256 color
403 pcx->xmax = SHORT(width-1);
404 pcx->ymax = SHORT(height-1);
405 pcx->hres = SHORT(width);
406 pcx->vres = SHORT(height);
407 memset (pcx->palette,0,sizeof(pcx->palette));
408 pcx->color_planes = 1; // chunky image
409 pcx->bytes_per_line = SHORT(width);
410 pcx->palette_type = SHORT(2); // not a grey scale
411 memset (pcx->filler,0,sizeof(pcx->filler));
417 for (i=0 ; i<width*height ; i++)
419 if ( (*data & 0xc0) != 0xc0)
429 *pack++ = 0x0c; // palette ID byte
430 for (i=0 ; i<768 ; i++)
431 *pack++ = *palette++;
434 length = pack - (byte *)pcx;
435 M_WriteFile (filename, pcx, length);
444 void M_ScreenShot (void)
450 // munge planar buffer to linear
452 I_ReadScreen (linear);
454 // find a file name to save it to
455 strcpy(lbmname,"DOOM00.pcx");
457 for (i=0 ; i<=99 ; i++)
459 lbmname[4] = i/10 + '0';
460 lbmname[5] = i%10 + '0';
461 if (!I_FileExists (lbmname))
465 I_Error ("M_ScreenShot: Couldn't create a PCX");
468 WritePCXfile (lbmname, linear,
469 SCREENWIDTH, SCREENHEIGHT,
470 W_CacheLumpName ("PLAYPAL",PU_CACHE));
472 players[consoleplayer].message = "screen shot";