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]);
112 if((fd = create(name, OWRITE | OTRUNC, 0666)) < 0)
114 n = write(fd, source, length);
132 if((fd = open(name, OREAD)) < 0)
133 I_Error ("Couldn't open file %s", name);
134 if((d = dirfstat(fd)) == nil)
135 I_Error ("Couldn't stat file %s", name);
139 buf = Z_Malloc(length, PU_STATIC, NULL);
140 if(readn(fd, buf, length) != length)
141 I_Error ("Couldn't read file %s", name);
154 extern int key_right;
159 extern int key_strafeleft;
160 extern int key_straferight;
164 extern int key_strafe;
165 extern int key_speed;
167 extern int mousebfire;
168 extern int mousebstrafe;
169 extern int mousebforward;
172 extern int joybstrafe;
174 extern int joybspeed;
176 extern int viewwidth;
177 extern int viewheight;
179 extern int mouseSensitivity;
180 extern int showMessages;
182 extern int detailLevel;
184 extern int screenblocks;
186 extern int showMessages;
188 // machine-independent sound params
189 extern int numChannels;
192 // UNIX hack, to be removed.
194 extern char* sndserver_filename;
203 extern char* chat_macros[];
212 int scantranslate; // PC scan code hack
213 int untranslated; // lousy hack
216 default_t defaults[] =
218 {"mouse_sensitivity",&mouseSensitivity, 5},
219 {"sfx_volume",&snd_SfxVolume, 8},
220 {"music_volume",&snd_MusicVolume, 8},
221 {"show_messages",&showMessages, 1},
224 {"key_right",&key_right, KEY_RIGHTARROW},
225 {"key_left",&key_left, KEY_LEFTARROW},
226 {"key_up",&key_up, KEY_UPARROW},
227 {"key_down",&key_down, KEY_DOWNARROW},
228 {"key_strafeleft",&key_strafeleft, ','},
229 {"key_straferight",&key_straferight, '.'},
231 {"key_fire",&key_fire, KEY_RCTRL},
232 {"key_use",&key_use, ' '},
233 {"key_strafe",&key_strafe, KEY_RALT},
234 {"key_speed",&key_speed, KEY_RSHIFT},
236 // UNIX hack, to be removed.
238 {"sndserver", (int *) &sndserver_filename, (int) "sndserver"},
239 {"mb_used", &mb_used, 2},
243 {"mousedev", (int*)&mousedev, (int)"/dev/ttyS0"},
244 {"mousetype", (int*)&mousetype, (int)"microsoft"},
247 {"use_mouse",&usemouse, 1},
248 {"mouseb_fire",&mousebfire,0},
249 {"mouseb_strafe",&mousebstrafe,1},
250 {"mouseb_forward",&mousebforward,2},
252 {"use_joystick",&usejoystick, 0},
253 {"joyb_fire",&joybfire,0},
254 {"joyb_strafe",&joybstrafe,1},
255 {"joyb_use",&joybuse,3},
256 {"joyb_speed",&joybspeed,2},
258 {"screenblocks",&screenblocks, 9},
259 {"detaillevel",&detailLevel, 0},
261 {"snd_channels",&numChannels, 3},
265 {"usegamma",&usegamma, 0},
267 {"chatmacro0", (int *) &chat_macros[0], (int) HUSTR_CHATMACRO0 },
268 {"chatmacro1", (int *) &chat_macros[1], (int) HUSTR_CHATMACRO1 },
269 {"chatmacro2", (int *) &chat_macros[2], (int) HUSTR_CHATMACRO2 },
270 {"chatmacro3", (int *) &chat_macros[3], (int) HUSTR_CHATMACRO3 },
271 {"chatmacro4", (int *) &chat_macros[4], (int) HUSTR_CHATMACRO4 },
272 {"chatmacro5", (int *) &chat_macros[5], (int) HUSTR_CHATMACRO5 },
273 {"chatmacro6", (int *) &chat_macros[6], (int) HUSTR_CHATMACRO6 },
274 {"chatmacro7", (int *) &chat_macros[7], (int) HUSTR_CHATMACRO7 },
275 {"chatmacro8", (int *) &chat_macros[8], (int) HUSTR_CHATMACRO8 },
276 {"chatmacro9", (int *) &chat_macros[9], (int) HUSTR_CHATMACRO9 }
287 void M_SaveDefaults (void)
293 f = fopen (defaultfile, "w");
295 return; // can't write the file, but don't complain
297 for (i=0 ; i<numdefaults ; i++)
299 if (defaults[i].defaultvalue > -0xfff
300 && defaults[i].defaultvalue < 0xfff)
302 v = *defaults[i].location;
303 fprintf (f,"%s\t\t%i\n",defaults[i].name,v);
305 fprintf (f,"%s\t\t\"%s\"\n",defaults[i].name,
306 * (char **) (defaults[i].location));
317 extern byte scantokey[128];
319 void M_LoadDefaults (void)
326 char* newstring = (char *)0;
330 // set everything to base values
331 numdefaults = sizeof(defaults)/sizeof(defaults[0]);
332 for (i=0 ; i<numdefaults ; i++)
333 *defaults[i].location = defaults[i].defaultvalue;
335 // check for a custom default file
336 i = M_CheckParm ("-config");
339 defaultfile = myargv[i+1];
340 printf (" default file: %s\n",defaultfile);
343 defaultfile = basedefault;
345 // read the file in, overriding any set defaults
346 f = fopen (defaultfile, "r");
352 if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
354 if (strparm[0] == '"')
356 // get a string default
358 len = strlen(strparm);
359 newstring = (char *) malloc(len);
361 strcpy(newstring, strparm+1);
363 else if (strparm[0] == '0' && strparm[1] == 'x')
364 sscanf(strparm+2, "%x", &parm);
366 sscanf(strparm, "%i", &parm);
367 for (i=0 ; i<numdefaults ; i++)
368 if (!strcmp(def, defaults[i].name))
371 *defaults[i].location = parm;
373 *defaults[i].location =
405 unsigned char palette[48];
409 unsigned short bytes_per_line;
410 unsigned short palette_type;
413 unsigned char data; // unbounded
433 pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL);
435 pcx->manufacturer = 0x0a; // PCX id
436 pcx->version = 5; // 256 color
437 pcx->encoding = 1; // uncompressed
438 pcx->bits_per_pixel = 8; // 256 color
441 pcx->xmax = SHORT(width-1);
442 pcx->ymax = SHORT(height-1);
443 pcx->hres = SHORT(width);
444 pcx->vres = SHORT(height);
445 memset (pcx->palette,0,sizeof(pcx->palette));
446 pcx->color_planes = 1; // chunky image
447 pcx->bytes_per_line = SHORT(width);
448 pcx->palette_type = SHORT(2); // not a grey scale
449 memset (pcx->filler,0,sizeof(pcx->filler));
455 for (i=0 ; i<width*height ; i++)
457 if ( (*data & 0xc0) != 0xc0)
467 *pack++ = 0x0c; // palette ID byte
468 for (i=0 ; i<768 ; i++)
469 *pack++ = *palette++;
472 length = pack - (byte *)pcx;
473 M_WriteFile (filename, pcx, length);
482 void M_ScreenShot (void)
488 // munge planar buffer to linear
490 I_ReadScreen (linear);
492 // find a file name to save it to
493 strcpy(lbmname,"DOOM00.pcx");
495 for (i=0 ; i<=99 ; i++)
497 lbmname[4] = i/10 + '0';
498 lbmname[5] = i%10 + '0';
499 if (access(lbmname,0) == -1)
500 break; // file doesn't exist
503 I_Error ("M_ScreenShot: Couldn't create a PCX");
506 WritePCXfile (lbmname, linear,
507 SCREENWIDTH, SCREENHEIGHT,
508 W_CacheLumpName ("PLAYPAL",PU_CACHE));
510 players[consoleplayer].message = "screen shot";