blob: 763e9d5681e73fd801b6f3bc39875c8fd96a5623 [file] [log] [blame]
Dave Chapman47f4a452006-03-28 15:44:01 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2005 Karl Kurbjun
10 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000011 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
Dave Chapman47f4a452006-03-28 15:44:01 +000015 *
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
18 *
19 * H300 Port by Karl Kurbjun
20 * IPod port by Dave Chapman and Paul Louden
21 * Additional code contributed by Thom Johansen
22 * Based off work by: Digita Doom, IDoom, Prboom, lSDLDoom, LxDoom,
23 * MBF, Boom, DosDoom,
24 * and of course Original Doom by ID Software
25 * See: http://prboom.sourceforge.net/about.html for the history
26 *
27 *
28 ****************************************************************************/
29
30#include "d_main.h"
31#include "doomdef.h"
32#include "settings.h"
33#include "m_fixed.h"
34#include "m_argv.h"
35#include "m_misc.h"
36#include "g_game.h"
37#include "rockmacros.h"
38#include "doomstat.h"
39#include "i_system.h"
Karl Kurbjun65c15eb2006-04-22 03:48:15 +000040#include "hu_stuff.h"
41#include "st_stuff.h"
Jonathan Gordon77a458a2007-05-08 11:55:43 +000042#include "lib/oldmenuapi.h"
Jens Arnold2aa0c4c2008-01-06 14:05:55 +000043#include "lib/helper.h"
Dave Chapman47f4a452006-03-28 15:44:01 +000044
45PLUGIN_HEADER
Michael Sevakisacc29d92006-11-18 02:18:29 +000046PLUGIN_IRAM_DECLARE
Dave Chapman47f4a452006-03-28 15:44:01 +000047
48extern boolean timingdemo, singledemo, demoplayback, fastdemo; // killough
49
50int filearray[9];
51int fpoint=1; // save 0 for closing
52
53int fileexists(const char * fname)
54{
55 int fd;
56 fd = open(fname,O_RDONLY);
57
58 if (fd>=0)
59 {
60 close(fd);
61 return 0;
62 }
63 return -1;
64}
65
66#ifndef SIMULATOR
67int my_open(const char *file, int flags)
68{
69 if(fpoint==8)
70 return -1;
71#undef open
72 filearray[fpoint]=rb->open(file, flags);
73
74 if(filearray[fpoint]<0)
75 return filearray[fpoint];
76
77 fpoint++;
78 return filearray[fpoint-1];
79}
80
81int my_close(int id)
82{
83 int i=0;
84 if(id<0)
85 return id;
86 while(filearray[i]!=id && i<8)
87 i++;
88
89 if(i==8)
90 {
91 printf("A requested FID did not exist!!!!");
92 return -9;
93 }
94#undef close
95 rb->close(id);
96
97 for(; i<fpoint-1; i++)
98 filearray[i]=filearray[i+1];
99
100 fpoint--;
101 return 0;
102}
103#endif
Steve Bavin65265772008-05-13 09:57:56 +0000104const struct plugin_api* rb;
Dave Chapman47f4a452006-03-28 15:44:01 +0000105#define MAXARGVS 100
106
Karl Kurbjun6e337112006-04-03 17:11:42 +0000107bool noprintf=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates
108
Karl Kurbjunaec58142007-06-03 22:03:36 +0000109#ifndef SIMULATOR
Dave Chapman47f4a452006-03-28 15:44:01 +0000110// Here is a hacked up printf command to get the output from the game.
111int printf(const char *fmt, ...)
112{
113 static int p_xtpt;
114 char p_buf[50];
115 bool ok;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000116 rb->yield();
Dave Chapman47f4a452006-03-28 15:44:01 +0000117 va_list ap;
118
119 va_start(ap, fmt);
120 ok = vsnprintf(p_buf,sizeof(p_buf), fmt, ap);
121 va_end(ap);
122
123 rb->lcd_putsxy(1,p_xtpt, (unsigned char *)p_buf);
Karl Kurbjun6e337112006-04-03 17:11:42 +0000124 if (!noprintf)
125 rb->lcd_update();
Dave Chapman47f4a452006-03-28 15:44:01 +0000126
127 p_xtpt+=8;
128 if(p_xtpt>LCD_HEIGHT-8)
129 {
130 p_xtpt=0;
Karl Kurbjun6e337112006-04-03 17:11:42 +0000131 if (!noprintf)
132 rb->lcd_clear_display();
Dave Chapman47f4a452006-03-28 15:44:01 +0000133 }
134 return 1;
135}
Karl Kurbjunaec58142007-06-03 22:03:36 +0000136#endif
Dave Chapman47f4a452006-03-28 15:44:01 +0000137
138char *my_strtok( char * s, const char * delim )
139{
140 register char *spanp;
141 register int c, sc;
142 char *tok;
143 static char *lasts;
144
145
146 if (s == NULL && (s = lasts) == NULL)
147 return (NULL);
148
149 /*
150 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
151 */
152cont:
153 c = *s++;
154 for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
155 if (c == sc)
156 goto cont;
157 }
158
159 if (c == 0) { /* no non-delimiter characters */
160 lasts = NULL;
161 return (NULL);
162 }
163 tok = s - 1;
164
165 /*
166 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
167 * Note that delim must have one NUL; we stop if we see that, too.
168 */
169 for (;;) {
170 c = *s++;
171 spanp = (char *)delim;
172 do {
173 if ((sc = *spanp++) == c) {
174 if (c == 0)
175 s = NULL;
176 else
177 s[-1] = 0;
178 lasts = s;
179 return (tok);
180 }
181 } while (sc != 0);
182 }
183 /* NOTREACHED */
184}
Dave Chapman47f4a452006-03-28 15:44:01 +0000185
186inline void* memcpy(void* dst, const void* src, size_t size)
187{
188 return rb->memcpy(dst, src, size);
189}
190
Dave Chapman47f4a452006-03-28 15:44:01 +0000191struct argvlist
192{
193 int timedemo; // 1 says there's a timedemo
194 int demonum;
195 int addonnum;
196} argvlist;
197
198const unsigned char versions_builtin[7][20] =
199{
200 "Doom Shareware",
201 "Doom Registered",
202 "Ultimate Doom",
203 "Doom 2",
Paul Loudend17de722007-02-17 17:51:44 +0000204 "Freedoom",
Dave Chapman47f4a452006-03-28 15:44:01 +0000205 "Plutonia",
206 "TNT"
207};
208
209const unsigned char wads_builtin[7][30] =
210{
211 GAMEBASE"doom1.wad",
212 GAMEBASE"doom.wad",
213 GAMEBASE"doomu.wad",
214 GAMEBASE"doom2.wad",
Paul Loudend17de722007-02-17 17:51:44 +0000215 GAMEBASE"doomf.wad",
Dave Chapman47f4a452006-03-28 15:44:01 +0000216 GAMEBASE"plutonia.wad",
217 GAMEBASE"tnt.wad"
218};
219
220int namemap[7];
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000221static struct menu_item *addons;
222static struct menu_item *demolmp;
Dave Chapman47f4a452006-03-28 15:44:01 +0000223char addon[200];
224// This sets up the base game and builds up myargv/c
225bool Dhandle_ver (int dver)
226{
227 switch (dver) {
228 case 0: /* Doom Shareware */
229 gamemode = shareware;
230 gamemission = doom;
231 D_AddFile(wads_builtin[0],source_iwad);
232 break;
233 case 1: /* Doom registered */
234 gamemode = registered;
235 gamemission = doom;
236 D_AddFile(wads_builtin[1],source_iwad);
237 break;
238 case 2: /* Ultimate Doom */
239 gamemode = retail;
240 gamemission = doom;
241 D_AddFile(wads_builtin[2],source_iwad);
242 break;
243 case 3: /* Doom2 */
244 gamemode = commercial;
245 gamemission = doom2;
246 D_AddFile(wads_builtin[3],source_iwad);
247 break;
248 case 4: /* Doom2f */
249 gamemode = commercial;
250 gamemission = doom2;
251 D_AddFile(wads_builtin[4],source_iwad);
252 break;
253 case 5: /* Plutonia */
254 gamemode = commercial;
255 gamemission = pack_plut;
256 D_AddFile(wads_builtin[5],source_iwad);
257 break;
258 case 6: /* TNT */
259 gamemode = commercial;
260 gamemission = pack_tnt;
261 D_AddFile(wads_builtin[6],source_iwad);
262 break;
263 default:
264 gamemission = none;
265 return 0;
266 }
267 // Start adding to myargv
268 if(argvlist.timedemo && (gamemode == shareware))
269 {
270 singletics = true;
271 timingdemo = true; // show stats after quit
272 G_DeferedPlayDemo("demo3");
273 singledemo = true; // quit after one demo
274 }
275
276 if(argvlist.addonnum)
277 {
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000278 snprintf(addon,sizeof(addon),"%s%s", GAMEBASE"addons/", addons[argvlist.addonnum].desc);
Dave Chapman47f4a452006-03-28 15:44:01 +0000279 D_AddFile(addon,source_pwad);
280 modifiedgame = true;
281 }
282
283 if(argvlist.demonum)
284 {
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000285 snprintf(addon, sizeof(addon),"%s%s", GAMEBASE"demos/", demolmp[argvlist.demonum].desc);
Dave Chapman47f4a452006-03-28 15:44:01 +0000286 D_AddFile(addon, source_lmp);
287 G_DeferedPlayDemo(addon);
288 singledemo = true; // quit after one demo
289 }
290 return 1;
291}
292
293// This function builds up the basegame list for use in the options selection
294// it also sets the defaults for the argvlist
Karl Kurbjun1123ab62006-04-03 20:03:02 +0000295// Now checking for rcokdoom.wad based on prboom.wad
Dave Chapman47f4a452006-03-28 15:44:01 +0000296int Dbuild_base (struct opt_items *names)
297{
Karl Kurbjun1123ab62006-04-03 20:03:02 +0000298 if ( fileexists(GAMEBASE"rockdoom.wad") )
Dave Chapman47f4a452006-03-28 15:44:01 +0000299 return 0;
300
Karl Kurbjun1123ab62006-04-03 20:03:02 +0000301 D_AddFile (GAMEBASE"rockdoom.wad", source_pwad);
Dave Chapman47f4a452006-03-28 15:44:01 +0000302
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000303 int i=0, j;
Dave Chapman47f4a452006-03-28 15:44:01 +0000304 /* Doom Shareware */
Dave Chapman47f4a452006-03-28 15:44:01 +0000305 /* Doom registered */
Dave Chapman47f4a452006-03-28 15:44:01 +0000306 /* Ultimate Doom */
Dave Chapman47f4a452006-03-28 15:44:01 +0000307 /* Doom2 */
Dave Chapman47f4a452006-03-28 15:44:01 +0000308 /* Doom2f */
Dave Chapman47f4a452006-03-28 15:44:01 +0000309 /* Plutonia */
Dave Chapman47f4a452006-03-28 15:44:01 +0000310 /* TNT */
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000311 for(j=0;j<7;j++)
312 if ( !fileexists (wads_builtin[j]) )
313 {
314 names[i].string=versions_builtin[j];
Jens Arnolda4f0de02007-10-02 19:53:35 +0000315 names[i].voice_id=-1;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000316 namemap[i]=j;
317 i++;
318 }
Dave Chapman47f4a452006-03-28 15:44:01 +0000319 // Set argvlist defaults
320 argvlist.timedemo=0;
321
322 return i;
323}
324
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000325// This is a general function that takes in a menu_item structure and makes a list
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000326// of files within it based on matching the string stringmatch to the files.
327int Dbuild_filelistm(struct menu_item **names, char *firstentry, char *directory, char *stringmatch)
328{
329 int i=0;
330 DIR *filedir;
331 struct dirent *dptr;
332 char *startpt;
333 struct menu_item *temp;
334
Kevin Ferrare011a3252007-07-20 17:06:55 +0000335 filedir=rb->opendir(directory);
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000336
337 if(filedir==NULL)
338 {
Jens Arnolda4f0de02007-10-02 19:53:35 +0000339 temp=malloc(sizeof(struct menu_item));
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000340 temp[0].desc=firstentry;
341 temp[0].function=0;
342 *names=temp;
343 return 1;
344 }
345
346 // Get the total number of entries
347 while((dptr=rb->readdir(filedir)))
348 i++;
349
350 // Reset the directory
Kevin Ferrare011a3252007-07-20 17:06:55 +0000351 rb->closedir(filedir);
352 filedir=rb->opendir(directory);
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000353
354 i++;
Jens Arnolda4f0de02007-10-02 19:53:35 +0000355 temp=malloc(i*sizeof(struct menu_item));
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000356 temp[0].desc=firstentry;
357 temp[0].function=0;
358 i=1;
359
360 while((dptr=rb->readdir(filedir)))
361 {
362 if(rb->strcasestr(dptr->d_name, stringmatch))
363 {
364 startpt=malloc(strlen(dptr->d_name)*sizeof(char));
365 strcpy(startpt,dptr->d_name);
366 temp[i].desc=startpt;
367 temp[i].function=0;
368 i++;
369 }
370 }
Kevin Ferrare011a3252007-07-20 17:06:55 +0000371 rb->closedir(filedir);
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000372 *names=temp;
373 return i;
374}
Dave Chapman47f4a452006-03-28 15:44:01 +0000375
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000376static int translatekey(int key) __attribute__ ((noinline));
377
Karl Kurbjun0926f642006-04-04 17:53:29 +0000378// This key configuration code is not the cleanest or the most efficient, but it works
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000379static int translatekey(int key)
Dave Chapman47f4a452006-03-28 15:44:01 +0000380{
Karl Kurbjun0926f642006-04-04 17:53:29 +0000381 if (key<31)
382 {
383 switch(key)
384 {
385 case 0:
386 return 0;
387 case 1:
388 return KEY_RIGHTARROW;
389 case 2:
390 return KEY_LEFTARROW;
391 case 3:
392 return KEY_UPARROW;
393 case 4:
394 return KEY_DOWNARROW;
395 case 5:
Karl Kurbjun0926f642006-04-04 17:53:29 +0000396 return KEY_ENTER;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000397 case 6:
398 return KEY_RCTRL;
399 case 7:
400 return ' ';
401 case 8:
402 return KEY_ESCAPE;
403 case 9:
404 return 'w';
Karl Kurbjun8ae68022006-04-04 23:13:50 +0000405 case 10:
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000406 return KEY_TAB;
Karl Kurbjun0926f642006-04-04 17:53:29 +0000407 default:
408 return 0;
409 }
410 }
411 else
412 {
413 switch(key)
414 {
415 case 0:
416 return 0;
417 case KEY_RIGHTARROW:
418 return 1;
419 case KEY_LEFTARROW:
420 return 2;
421 case KEY_UPARROW:
422 return 3;
423 case KEY_DOWNARROW:
424 return 4;
Karl Kurbjun0926f642006-04-04 17:53:29 +0000425 case KEY_ENTER:
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000426 return 5;
427 case KEY_RCTRL:
428 return 6;
429 case ' ':
430 return 7;
431 case KEY_ESCAPE:
432 return 8;
433 case 'w':
Karl Kurbjun0926f642006-04-04 17:53:29 +0000434 return 9;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000435 case KEY_TAB:
436 return 10;
Karl Kurbjun0926f642006-04-04 17:53:29 +0000437 default:
438 return 0;
439 }
440 }
441}
442
443// I havn't added configurable keys for enter or escape because this requires some modification to
444// m_menu.c which hasn't been done yet.
445
446int Oset_keys()
447{
448 int m, result;
449 int menuquit=0;
450
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000451
Karl Kurbjun0926f642006-04-04 17:53:29 +0000452 static const struct opt_items doomkeys[] = {
Jens Arnolda4f0de02007-10-02 19:53:35 +0000453 { "Unmapped", -1 },
454 { "Key Right", -1 },
455 { "Key Left", -1 },
456 { "Key Up", -1 },
457 { "Key Down", -1 },
458 { "Key Select", -1 },
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000459#if defined(TOSHIBA_GIGABEAT_F)
Jens Arnolda4f0de02007-10-02 19:53:35 +0000460 { "Key A", -1 },
461 { "Key Menu", -1 },
462 { "Key Power", -1 },
463 { "Key Volume Down", -1 },
464 { "Key Volume Up", -1 },
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000465#else
Jens Arnolda4f0de02007-10-02 19:53:35 +0000466 { "Key Record", -1 },
467 { "Key Mode", -1 },
468 { "Key Off", -1 },
469 { "Key On", -1 },
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000470#endif
Karl Kurbjun0926f642006-04-04 17:53:29 +0000471 };
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000472
473 int *keys[]={
474 &key_right,
475 &key_left,
476 &key_up,
477 &key_down,
478 &key_fire,
479 &key_use,
480 &key_strafe,
481 &key_weapon,
482 &key_map
483 };
484
Karl Kurbjun0926f642006-04-04 17:53:29 +0000485 int numdoomkeys=sizeof(doomkeys) / sizeof(*doomkeys);
486
487 static const struct menu_item items[] = {
488 { "Game Right", NULL },
489 { "Game Left", NULL },
490 { "Game Up", NULL },
491 { "Game Down", NULL },
492 { "Game Shoot", NULL },
493 { "Game Open", NULL },
494 { "Game Strafe", NULL },
495 { "Game Weapon", NULL },
Karl Kurbjun8ae68022006-04-04 23:13:50 +0000496 { "Game Automap", NULL },
Karl Kurbjun0926f642006-04-04 17:53:29 +0000497 };
498
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000499 m = menu_init(rb, items, sizeof(items) / sizeof(*items),
Karl Kurbjun26dd5c52006-06-10 18:47:11 +0000500 NULL, NULL, NULL, NULL);
Karl Kurbjun0926f642006-04-04 17:53:29 +0000501
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000502 while(!menuquit)
503 {
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000504 result=menu_show(m);
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000505 if(result<0)
Karl Kurbjun0926f642006-04-04 17:53:29 +0000506 menuquit=1;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000507 else
508 {
509 *keys[result]=translatekey(*keys[result]);
510 rb->set_option(items[result].desc, keys[result], INT, doomkeys, numdoomkeys, NULL );
511 *keys[result]=translatekey(*keys[result]);
512 }
Karl Kurbjun0926f642006-04-04 17:53:29 +0000513 }
514
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000515 menu_exit(m);
Karl Kurbjun0926f642006-04-04 17:53:29 +0000516
517 return (1);
Dave Chapman47f4a452006-03-28 15:44:01 +0000518}
519
Dave Chapman47f4a452006-03-28 15:44:01 +0000520extern int fake_contrast;
521
522static bool Doptions()
523{
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000524 static const struct opt_items onoff[2] = {
Jens Arnolda4f0de02007-10-02 19:53:35 +0000525 { "Off", -1 },
526 { "On", -1 },
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000527 };
528
Dave Chapman47f4a452006-03-28 15:44:01 +0000529 int m, result;
530 int menuquit=0;
531
532 static const struct menu_item items[] = {
Karl Kurbjun0926f642006-04-04 17:53:29 +0000533 { "Set Keys", NULL },
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000534 { "Sound", NULL },
Dave Chapman47f4a452006-03-28 15:44:01 +0000535 { "Timedemo", NULL },
536 { "Player Bobbing", NULL },
537 { "Weapon Recoil", NULL },
538 { "Translucency", NULL },
539 { "Fake Contrast", NULL },
Karl Kurbjun6f8af212006-04-17 00:37:51 +0000540 { "Always Run", NULL },
Karl Kurbjun65c15eb2006-04-22 03:48:15 +0000541 { "Headsup Display", NULL },
542 { "Statusbar Always Red", NULL },
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000543#if(LCD_HEIGHT>LCD_WIDTH)
544 { "Rotate Screen 90 deg", NULL },
545#endif
Dave Chapman47f4a452006-03-28 15:44:01 +0000546 };
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000547
548 void *options[]={
549 &enable_sound,
550 &argvlist.timedemo,
551 &default_player_bobbing,
552 &default_weapon_recoil,
553 &default_translucency,
554 &fake_contrast,
555 &autorun,
556 &hud_displayed,
557 &sts_always_red,
558#if(LCD_HEIGHT>LCD_WIDTH)
559 &rotate_screen,
560#endif
561 };
Dave Chapman47f4a452006-03-28 15:44:01 +0000562
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000563 m = menu_init(rb, items, sizeof(items) / sizeof(*items),
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000564 NULL, NULL, NULL, NULL);
Dave Chapman47f4a452006-03-28 15:44:01 +0000565
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000566 while(!menuquit)
567 {
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000568 result=menu_show(m);
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000569 if(result==0)
Dave Chapman47f4a452006-03-28 15:44:01 +0000570 Oset_keys();
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000571 else if (result > 0)
572 rb->set_option(items[result].desc, options[result-1], INT, onoff, 2, NULL );
573 else
Dave Chapman47f4a452006-03-28 15:44:01 +0000574 menuquit=1;
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000575 }
Dave Chapman47f4a452006-03-28 15:44:01 +0000576
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000577 menu_exit(m);
Dave Chapman47f4a452006-03-28 15:44:01 +0000578
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000579 return (1);
Dave Chapman47f4a452006-03-28 15:44:01 +0000580}
581
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000582int menuchoice(struct menu_item *menu, int items)
583{
584 int m, result;
585
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000586 m = menu_init(rb, menu, items,NULL, NULL, NULL, NULL);
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000587
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000588 result= menu_show(m);
589 menu_exit(m);
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000590 if(result<items && result>=0)
591 return result;
592 return 0;
593}
594
Dave Chapman47f4a452006-03-28 15:44:01 +0000595//
596// Doom Menu
597//
598int doom_menu()
599{
600 int m;
601 int result;
602 int status;
603 int gamever;
604 bool menuquit=0;
605
606 static struct opt_items names[7];
607
608 static const struct menu_item items[] = {
609 { "Game", NULL },
610 { "Addons", NULL },
611 { "Demos", NULL },
612 { "Options", NULL },
613 { "Play Game", NULL },
614 { "Quit", NULL },
615 };
616
617 if( (status=Dbuild_base(names)) == 0 ) // Build up the base wad files (select last added file)
618 {
Jens Arnold4d6374c2007-03-16 21:56:08 +0000619 rb->splash(HZ*2, "Missing Base WAD!");
Karl Kurbjun9f2be9b2006-04-17 05:01:33 +0000620 return -2;
Dave Chapman47f4a452006-03-28 15:44:01 +0000621 }
622
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000623 int numadd=Dbuild_filelistm(&addons, "No Addon", GAMEBASE"addons/", ".WAD" );
Dave Chapman47f4a452006-03-28 15:44:01 +0000624
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000625 int numdemos=Dbuild_filelistm(&demolmp, "No Demo", GAMEBASE"demos/", ".LMP" );
Karl Kurbjunc87f98c2006-04-17 03:09:29 +0000626
Dave Chapman47f4a452006-03-28 15:44:01 +0000627 argvlist.demonum=0;
Dave Chapman47f4a452006-03-28 15:44:01 +0000628 argvlist.addonnum=0;
629
630 gamever=status-1;
631
Karl Kurbjun26dd5c52006-06-10 18:47:11 +0000632 /* Clean out the button Queue */
633 while (rb->button_get(false) != BUTTON_NONE)
634 rb->yield();
635
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000636 m = menu_init(rb, items, sizeof(items) / sizeof(*items),
Karl Kurbjun26dd5c52006-06-10 18:47:11 +0000637 NULL, NULL, NULL, NULL);
Dave Chapman47f4a452006-03-28 15:44:01 +0000638
639 while(!menuquit)
640 {
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000641 result=menu_show(m);
Dave Chapman47f4a452006-03-28 15:44:01 +0000642 switch (result) {
643 case 0: /* Game picker */
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000644 rb->set_option("Game WAD", &gamever, INT, names, status, NULL );
Dave Chapman47f4a452006-03-28 15:44:01 +0000645 break;
646
647 case 1: /* Addon picker */
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000648 argvlist.addonnum=menuchoice(addons,numadd);
Dave Chapman47f4a452006-03-28 15:44:01 +0000649 break;
650
Karl Kurbjun0926f642006-04-04 17:53:29 +0000651 case 2: /* Demos */
Karl Kurbjunb0722d12006-04-17 04:38:26 +0000652 argvlist.demonum=menuchoice(demolmp,numdemos);
Dave Chapman47f4a452006-03-28 15:44:01 +0000653 break;
654
655 case 3: /* Options */
656 Doptions();
657 break;
658
659 case 4: /* Play Game */
660 menuquit=1;
661 break;
662
663 case 5: /* Quit */
664 menuquit=1;
665 gamever=-1;
666 break;
667
668 default:
669 break;
670 }
671 }
672
Jonathan Gordon77a458a2007-05-08 11:55:43 +0000673 menu_exit(m);
Dave Chapman47f4a452006-03-28 15:44:01 +0000674
675 return (gamever);
676}
677
678extern int systemvol;
679/* this is the plugin entry point */
Steve Bavin65265772008-05-13 09:57:56 +0000680enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
Dave Chapman47f4a452006-03-28 15:44:01 +0000681{
Tomasz Malesinski80da8b12006-11-26 18:31:41 +0000682 PLUGIN_IRAM_INIT(api)
683
Dave Chapman47f4a452006-03-28 15:44:01 +0000684 rb = api;
685 (void)parameter;
686
Karl Kurbjun4e2a74c2006-04-15 22:08:36 +0000687 doomexit=0;
688
Christian Gmeinera91b7942006-04-09 15:00:30 +0000689#ifdef HAVE_ADJUSTABLE_CPU_FREQ
Dave Chapman47f4a452006-03-28 15:44:01 +0000690 rb->cpu_boost(true);
691#endif
692
Dave Chapman47f4a452006-03-28 15:44:01 +0000693 rb->lcd_setfont(0);
694
Dave Chapman47f4a452006-03-28 15:44:01 +0000695 // We're using doom's memory management since it implements a proper free (and re-uses the memory)
696 // and now with prboom's code: realloc and calloc
Karl Kurbjunc87f98c2006-04-17 03:09:29 +0000697 printf ("Z_Init: Init zone memory allocation daemon.\n");
Dave Chapman47f4a452006-03-28 15:44:01 +0000698 Z_Init ();
699
700 printf ("M_LoadDefaults: Load system defaults.\n");
701 M_LoadDefaults (); // load before initing other systems
702
Jens Arnold4d6374c2007-03-16 21:56:08 +0000703 rb->splash(HZ*2, "Welcome to RockDoom");
Dave Chapman47f4a452006-03-28 15:44:01 +0000704
Karl Kurbjunc87f98c2006-04-17 03:09:29 +0000705 myargv =0;
706 myargc=0;
Dave Chapman47f4a452006-03-28 15:44:01 +0000707
Karl Kurbjun9f2be9b2006-04-17 05:01:33 +0000708 rb->lcd_clear_display();
Dave Chapman47f4a452006-03-28 15:44:01 +0000709
Karl Kurbjun9f2be9b2006-04-17 05:01:33 +0000710 int result = doom_menu();
Karl Kurbjun4caa6762006-10-01 01:07:45 +0000711 if (result < 0)
712 {
713#ifdef HAVE_ADJUSTABLE_CPU_FREQ
Jens Arnold2aa0c4c2008-01-06 14:05:55 +0000714 rb->cpu_boost(false);
Karl Kurbjun4caa6762006-10-01 01:07:45 +0000715#endif
Jens Arnold2aa0c4c2008-01-06 14:05:55 +0000716 if( result == -1 )
717 return PLUGIN_OK; // Quit was selected
718 else
719 return PLUGIN_ERROR; // Missing base wads
Karl Kurbjun4caa6762006-10-01 01:07:45 +0000720 }
Dave Chapman47f4a452006-03-28 15:44:01 +0000721
Karl Kurbjunb47a43a2007-01-17 18:52:24 +0000722#if(LCD_HEIGHT>LCD_WIDTH)
723 if(rotate_screen)
724 {
725 SCREENHEIGHT=LCD_WIDTH;
726 SCREENWIDTH=LCD_HEIGHT;
727 }
728 else
729 {
730 SCREENHEIGHT=LCD_HEIGHT;
731 SCREENWIDTH=LCD_WIDTH;
732 }
733#endif
734
Dave Chapman47f4a452006-03-28 15:44:01 +0000735 Dhandle_ver( namemap[ result ] );
736
737 rb->lcd_setfont(0);
738
739 rb->lcd_clear_display();
740
Karl Kurbjun546d96c2006-04-02 20:45:24 +0000741 systemvol= rb->global_settings->volume-rb->global_settings->volume%((rb->sound_max(SOUND_VOLUME)-rb->sound_min(SOUND_VOLUME))/15);
Dave Chapman47f4a452006-03-28 15:44:01 +0000742 general_translucency = default_translucency; // phares
Karl Kurbjun993545b2006-04-14 21:07:56 +0000743
Jens Arnold2aa0c4c2008-01-06 14:05:55 +0000744 backlight_force_on(rb);
Karl Kurbjun993545b2006-04-14 21:07:56 +0000745#ifdef RB_PROFILE
746 rb->profile_thread();
747#endif
748
Robert Kukla1317ebb2008-04-07 22:09:14 +0000749#if LCD_DEPTH>1
Karl Kurbjund6b0c972006-11-15 06:14:27 +0000750 rb->lcd_set_backdrop(NULL);
Robert Kukla1317ebb2008-04-07 22:09:14 +0000751#endif
Karl Kurbjund6b0c972006-11-15 06:14:27 +0000752
Dave Chapman47f4a452006-03-28 15:44:01 +0000753 D_DoomMain ();
754
Karl Kurbjun993545b2006-04-14 21:07:56 +0000755#ifdef RB_PROFILE
756 rb->profstop();
757#endif
Jens Arnold2aa0c4c2008-01-06 14:05:55 +0000758 backlight_use_settings(rb);
Karl Kurbjun993545b2006-04-14 21:07:56 +0000759
Dave Chapman47f4a452006-03-28 15:44:01 +0000760 M_SaveDefaults ();
761
762 I_Quit(); // Make SURE everything was closed out right
763
Karl Kurbjun6f8af212006-04-17 00:37:51 +0000764 printf("There were still: %d files open\n", fpoint);
Dave Chapman47f4a452006-03-28 15:44:01 +0000765 while(fpoint>0)
766 {
Nicolas Pennequin9ff40572007-10-09 18:44:07 +0000767#ifdef SIMULATOR
768 close(filearray[fpoint]);
769#else
Dave Chapman47f4a452006-03-28 15:44:01 +0000770 rb->close(filearray[fpoint]);
Nicolas Pennequin9ff40572007-10-09 18:44:07 +0000771#endif
Dave Chapman47f4a452006-03-28 15:44:01 +0000772 fpoint--;
773 }
774
Christian Gmeinera91b7942006-04-09 15:00:30 +0000775#ifdef HAVE_ADJUSTABLE_CPU_FREQ
Dave Chapman47f4a452006-03-28 15:44:01 +0000776 rb->cpu_boost(false);
777#endif
778
779 return PLUGIN_OK;
780}