1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
9 * Copyright (C) 2005 Karl Kurbjun
11 * 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.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
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,
24 * and of course Original Doom by ID Software
25 * See: http://prboom.sourceforge.net/about.html for the history
28 ****************************************************************************/
37 #include "rockmacros.h"
42 #include "lib/helper.h"
44 extern boolean timingdemo
, singledemo
, demoplayback
, fastdemo
; // killough
47 int fpoint
=1; // save 0 for closing
49 int fileexists(const char * fname
)
52 fd
= open(fname
,O_RDONLY
);
62 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
63 int my_open(const char *file
, int flags
, ...)
72 filearray
[fpoint
]=rb
->open(file
, flags
, va_arg(ap
, unsigned int));
76 filearray
[fpoint
]=rb
->open(file
, flags
);
77 if(filearray
[fpoint
]<0)
78 return filearray
[fpoint
];
81 return filearray
[fpoint
-1];
89 while(filearray
[i
]!=id
&& i
<8)
94 printf("A requested FID did not exist!!!!");
100 for(; i
<fpoint
-1; i
++)
101 filearray
[i
]=filearray
[i
+1];
109 bool noprintf
=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates
111 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
112 // Here is a hacked up printf command to get the output from the game.
113 int printf(const char *fmt
, ...)
121 vsnprintf(p_buf
,sizeof(p_buf
), fmt
, ap
);
124 rb
->lcd_putsxy(1,p_xtpt
, (unsigned char *)p_buf
);
129 if(p_xtpt
>LCD_HEIGHT
-8)
133 rb
->lcd_clear_display();
139 char *my_strtok( char * s
, const char * delim
)
141 register char *spanp
;
147 if (s
== NULL
&& (s
= lasts
) == NULL
)
151 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
155 for (spanp
= (char *)delim
; (sc
= *spanp
++) != 0;) {
160 if (c
== 0) { /* no non-delimiter characters */
167 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
168 * Note that delim must have one NUL; we stop if we see that, too.
172 spanp
= (char *)delim
;
174 if ((sc
= *spanp
++) == c
) {
189 int timedemo
; // 1 says there's a timedemo
194 const unsigned char versions_builtin
[7][20] =
205 const unsigned char wads_builtin
[7][30] =
212 GAMEBASE
"plutonia.wad",
217 static char **addons
;
218 static char **demolmp
;
220 // This sets up the base game and builds up myargv/c
221 bool Dhandle_ver (int dver
)
224 case 0: /* Doom Shareware */
225 gamemode
= shareware
;
227 D_AddFile(wads_builtin
[0],source_iwad
);
229 case 1: /* Doom registered */
230 gamemode
= registered
;
232 D_AddFile(wads_builtin
[1],source_iwad
);
234 case 2: /* Ultimate Doom */
237 D_AddFile(wads_builtin
[2],source_iwad
);
240 gamemode
= commercial
;
242 D_AddFile(wads_builtin
[3],source_iwad
);
245 gamemode
= commercial
;
247 D_AddFile(wads_builtin
[4],source_iwad
);
249 case 5: /* Plutonia */
250 gamemode
= commercial
;
251 gamemission
= pack_plut
;
252 D_AddFile(wads_builtin
[5],source_iwad
);
255 gamemode
= commercial
;
256 gamemission
= pack_tnt
;
257 D_AddFile(wads_builtin
[6],source_iwad
);
263 // Start adding to myargv
264 if(argvlist
.timedemo
&& (gamemode
== shareware
))
267 timingdemo
= true; // show stats after quit
268 G_DeferedPlayDemo("demo3");
269 singledemo
= true; // quit after one demo
272 if(argvlist
.addonnum
)
274 snprintf(addon
,sizeof(addon
),"%s%s", GAMEBASE
"addons/", addons
[argvlist
.addonnum
]);
275 D_AddFile(addon
,source_pwad
);
281 snprintf(addon
, sizeof(addon
),"%s%s", GAMEBASE
"demos/", demolmp
[argvlist
.demonum
]);
282 D_AddFile(addon
, source_lmp
);
283 G_DeferedPlayDemo(addon
);
284 singledemo
= true; // quit after one demo
289 // This function builds up the basegame list for use in the options selection
290 // it also sets the defaults for the argvlist
291 // Now checking for rcokdoom.wad based on prboom.wad
292 int Dbuild_base (struct opt_items
*names
)
294 if ( fileexists(GAMEBASE
"rockdoom.wad") )
297 D_AddFile (GAMEBASE
"rockdoom.wad", source_pwad
);
301 /* Doom registered */
308 if ( !fileexists (wads_builtin
[j
]) )
310 names
[i
].string
=versions_builtin
[j
];
311 names
[i
].voice_id
=-1;
315 // Set argvlist defaults
321 // This is a general function that takes in a menu_item structure and makes a list
322 // of files within it based on matching the string stringmatch to the files.
323 int Dbuild_filelistm(char ***names
, char *firstentry
, char *directory
, char *stringmatch
)
331 filedir
=rb
->opendir(directory
);
335 temp
=malloc(sizeof(char *));
341 // Get the total number of entries
342 while((dptr
=rb
->readdir(filedir
)))
345 // Reset the directory
346 rb
->closedir(filedir
);
347 filedir
=rb
->opendir(directory
);
350 temp
=malloc(i
*sizeof(char *));
354 while((dptr
=rb
->readdir(filedir
)))
356 if(rb
->strcasestr(dptr
->d_name
, stringmatch
))
358 startpt
=malloc(strlen(dptr
->d_name
)*sizeof(char));
359 strcpy(startpt
,dptr
->d_name
);
364 rb
->closedir(filedir
);
369 static int translatekey(int key
) __attribute__ ((noinline
));
371 // This key configuration code is not the cleanest or the most efficient, but it works
372 static int translatekey(int key
)
381 return KEY_RIGHTARROW
;
383 return KEY_LEFTARROW
;
387 return KEY_DOWNARROW
;
436 // I havn't added configurable keys for enter or escape because this requires some modification to
437 // m_menu.c which hasn't been done yet.
441 int selected
=0, result
;
445 static const struct opt_items doomkeys
[] = {
451 { "Key Select", -1 },
452 #if defined(TOSHIBA_GIGABEAT_F)
456 { "Key Volume Down", -1 },
457 { "Key Volume Up", -1 },
459 { "Key Record", -1 },
478 int numdoomkeys
=sizeof(doomkeys
) / sizeof(*doomkeys
);
480 MENUITEM_STRINGLIST(menu
, "Set Keys", NULL
,
481 "Game Right", "Game Left", "Game Up", "Game Down",
482 "Game Shoot", "Game Open", "Game Strafe",
483 "Game Weapon", "Game Automap");
487 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
492 *keys
[result
]=translatekey(*keys
[result
]);
493 rb
->set_option(menu_
[result
], keys
[result
], INT
, doomkeys
, numdoomkeys
, NULL
);
494 *keys
[result
]=translatekey(*keys
[result
]);
501 extern int fake_contrast
;
503 static bool Doptions()
505 static const struct opt_items onoff
[2] = {
510 int selected
=0, result
;
513 MENUITEM_STRINGLIST(menu
, "Options", NULL
,
514 "Set Keys", "Sound", "Timedemo", "Player Bobbing",
515 "Weapon Recoil", "Translucency", "Fake Contrast",
516 "Always Run", "Headsup Display", "Statusbar Always Red",
517 #if(LCD_HEIGHT>LCD_WIDTH)
518 "Rotate Screen 90 deg",
525 &default_player_bobbing
,
526 &default_weapon_recoil
,
527 &default_translucency
,
532 #if(LCD_HEIGHT>LCD_WIDTH)
539 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
543 rb
->set_option(menu_
[result
], options
[result
-1], INT
, onoff
, 2, NULL
);
551 static const char* choice_get_name(int selected_item
, void * data
,
552 char * buffer
, size_t buffer_len
)
554 const char **names
= (const char **) data
;
557 return names
[selected_item
];
560 int list_action_callback(int action
, struct gui_synclist
*lists
)
563 if (action
== ACTION_STD_OK
)
564 return ACTION_STD_CANCEL
;
568 bool menuchoice(char **names
, int count
, int *selected
)
570 struct simplelist_info info
;
571 rb
->simplelist_info_init(&info
, NULL
, count
, (void*)names
);
572 info
.selection
= *selected
;
573 info
.get_name
= choice_get_name
;
574 info
.action_callback
= list_action_callback
;
575 if(rb
->simplelist_show_list(&info
))
578 if(info
.selection
<count
&& info
.selection
>=0)
579 *selected
= info
.selection
;
588 int selected
=0, result
;
593 static struct opt_items names
[7];
595 MENUITEM_STRINGLIST(menu
, "Doom Menu", NULL
,
596 "Game", "Addons", "Demos",
597 "Options", "Play Game", "Quit");
599 if( (status
=Dbuild_base(names
)) == 0 ) // Build up the base wad files (select last added file)
601 rb
->splash(HZ
*2, "Missing Base WAD!");
605 int numadd
=Dbuild_filelistm(&addons
, "No Addon", GAMEBASE
"addons/", ".WAD" );
607 int numdemos
=Dbuild_filelistm(&demolmp
, "No Demo", GAMEBASE
"demos/", ".LMP" );
614 /* Clean out the button Queue */
615 while (rb
->button_get(false) != BUTTON_NONE
)
620 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
622 case 0: /* Game picker */
623 rb
->set_option("Game WAD", &gamever
, INT
, names
, status
, NULL
);
626 case 1: /* Addon picker */
627 menuchoice(addons
,numadd
,&argvlist
.addonnum
);
631 menuchoice(demolmp
,numdemos
,&argvlist
.demonum
);
634 case 3: /* Options */
638 case 4: /* Play Game */
655 extern int systemvol
;
656 /* this is the plugin entry point */
657 enum plugin_status
plugin_start(const void* parameter
)
659 /* Disable all talking before initializing IRAM */
660 rb
->talk_disable(true);
666 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
670 rb
->lcd_setfont(FONT_SYSFIXED
);
672 // We're using doom's memory management since it implements a proper free (and re-uses the memory)
673 // and now with prboom's code: realloc and calloc
674 printf ("Z_Init: Init zone memory allocation daemon.\n");
677 printf ("M_LoadDefaults: Load system defaults.\n");
678 M_LoadDefaults (); // load before initing other systems
680 rb
->splash(HZ
*2, "Welcome to RockDoom");
685 rb
->lcd_clear_display();
687 int result
= doom_menu();
690 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
691 rb
->cpu_boost(false);
693 rb
->talk_disable(false);
695 return PLUGIN_OK
; // Quit was selected
697 return PLUGIN_ERROR
; // Missing base wads
700 #if(LCD_HEIGHT>LCD_WIDTH)
703 SCREENHEIGHT
=LCD_WIDTH
;
704 SCREENWIDTH
=LCD_HEIGHT
;
708 SCREENHEIGHT
=LCD_HEIGHT
;
709 SCREENWIDTH
=LCD_WIDTH
;
713 Dhandle_ver( namemap
[ result
] );
715 rb
->lcd_setfont(FONT_SYSFIXED
);
717 rb
->lcd_clear_display();
719 int mod
= (rb
->sound_max(SOUND_VOLUME
)-rb
->sound_min(SOUND_VOLUME
))/15;
721 mod
= rb
->global_settings
->volume
;
722 systemvol
= rb
->global_settings
->volume
-rb
->global_settings
->volume
%mod
;
723 general_translucency
= default_translucency
; // phares
725 backlight_ignore_timeout();
727 rb
->profile_thread();
731 rb
->lcd_set_backdrop(NULL
);
739 backlight_use_settings();
743 I_Quit(); // Make SURE everything was closed out right
745 printf("There were still: %d files open\n", fpoint
);
748 #if (CONFIG_PLATFORM & PLATFORM_HOSTED)
749 close(filearray
[fpoint
]);
751 rb
->close(filearray
[fpoint
]);
756 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
757 rb
->cpu_boost(false);
760 rb
->talk_disable(false);