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"
47 extern boolean timingdemo
, singledemo
, demoplayback
, fastdemo
; // killough
50 int fpoint
=1; // save 0 for closing
52 int fileexists(const char * fname
)
55 fd
= open(fname
,O_RDONLY
);
66 int my_open(const char *file
, int flags
, ...)
75 filearray
[fpoint
]=rb
->open(file
, flags
, va_arg(ap
, unsigned int));
79 filearray
[fpoint
]=rb
->open(file
, flags
);
80 if(filearray
[fpoint
]<0)
81 return filearray
[fpoint
];
84 return filearray
[fpoint
-1];
92 while(filearray
[i
]!=id
&& i
<8)
97 printf("A requested FID did not exist!!!!");
103 for(; i
<fpoint
-1; i
++)
104 filearray
[i
]=filearray
[i
+1];
112 bool noprintf
=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates
115 // Here is a hacked up printf command to get the output from the game.
116 int printf(const char *fmt
, ...)
125 ok
= vsnprintf(p_buf
,sizeof(p_buf
), fmt
, ap
);
128 rb
->lcd_putsxy(1,p_xtpt
, (unsigned char *)p_buf
);
133 if(p_xtpt
>LCD_HEIGHT
-8)
137 rb
->lcd_clear_display();
143 char *my_strtok( char * s
, const char * delim
)
145 register char *spanp
;
151 if (s
== NULL
&& (s
= lasts
) == NULL
)
155 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
159 for (spanp
= (char *)delim
; (sc
= *spanp
++) != 0;) {
164 if (c
== 0) { /* no non-delimiter characters */
171 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
172 * Note that delim must have one NUL; we stop if we see that, too.
176 spanp
= (char *)delim
;
178 if ((sc
= *spanp
++) == c
) {
193 int timedemo
; // 1 says there's a timedemo
198 const unsigned char versions_builtin
[7][20] =
209 const unsigned char wads_builtin
[7][30] =
216 GAMEBASE
"plutonia.wad",
221 static char **addons
;
222 static char **demolmp
;
224 // This sets up the base game and builds up myargv/c
225 bool Dhandle_ver (int dver
)
228 case 0: /* Doom Shareware */
229 gamemode
= shareware
;
231 D_AddFile(wads_builtin
[0],source_iwad
);
233 case 1: /* Doom registered */
234 gamemode
= registered
;
236 D_AddFile(wads_builtin
[1],source_iwad
);
238 case 2: /* Ultimate Doom */
241 D_AddFile(wads_builtin
[2],source_iwad
);
244 gamemode
= commercial
;
246 D_AddFile(wads_builtin
[3],source_iwad
);
249 gamemode
= commercial
;
251 D_AddFile(wads_builtin
[4],source_iwad
);
253 case 5: /* Plutonia */
254 gamemode
= commercial
;
255 gamemission
= pack_plut
;
256 D_AddFile(wads_builtin
[5],source_iwad
);
259 gamemode
= commercial
;
260 gamemission
= pack_tnt
;
261 D_AddFile(wads_builtin
[6],source_iwad
);
267 // Start adding to myargv
268 if(argvlist
.timedemo
&& (gamemode
== shareware
))
271 timingdemo
= true; // show stats after quit
272 G_DeferedPlayDemo("demo3");
273 singledemo
= true; // quit after one demo
276 if(argvlist
.addonnum
)
278 snprintf(addon
,sizeof(addon
),"%s%s", GAMEBASE
"addons/", addons
[argvlist
.addonnum
]);
279 D_AddFile(addon
,source_pwad
);
285 snprintf(addon
, sizeof(addon
),"%s%s", GAMEBASE
"demos/", demolmp
[argvlist
.demonum
]);
286 D_AddFile(addon
, source_lmp
);
287 G_DeferedPlayDemo(addon
);
288 singledemo
= true; // quit after one demo
293 // This function builds up the basegame list for use in the options selection
294 // it also sets the defaults for the argvlist
295 // Now checking for rcokdoom.wad based on prboom.wad
296 int Dbuild_base (struct opt_items
*names
)
298 if ( fileexists(GAMEBASE
"rockdoom.wad") )
301 D_AddFile (GAMEBASE
"rockdoom.wad", source_pwad
);
305 /* Doom registered */
312 if ( !fileexists (wads_builtin
[j
]) )
314 names
[i
].string
=versions_builtin
[j
];
315 names
[i
].voice_id
=-1;
319 // Set argvlist defaults
325 // This is a general function that takes in a menu_item structure and makes a list
326 // of files within it based on matching the string stringmatch to the files.
327 int Dbuild_filelistm(char ***names
, char *firstentry
, char *directory
, char *stringmatch
)
335 filedir
=rb
->opendir(directory
);
339 temp
=malloc(sizeof(char *));
345 // Get the total number of entries
346 while((dptr
=rb
->readdir(filedir
)))
349 // Reset the directory
350 rb
->closedir(filedir
);
351 filedir
=rb
->opendir(directory
);
354 temp
=malloc(i
*sizeof(char *));
358 while((dptr
=rb
->readdir(filedir
)))
360 if(rb
->strcasestr(dptr
->d_name
, stringmatch
))
362 startpt
=malloc(strlen(dptr
->d_name
)*sizeof(char));
363 strcpy(startpt
,dptr
->d_name
);
368 rb
->closedir(filedir
);
373 static int translatekey(int key
) __attribute__ ((noinline
));
375 // This key configuration code is not the cleanest or the most efficient, but it works
376 static int translatekey(int key
)
385 return KEY_RIGHTARROW
;
387 return KEY_LEFTARROW
;
391 return KEY_DOWNARROW
;
440 // I havn't added configurable keys for enter or escape because this requires some modification to
441 // m_menu.c which hasn't been done yet.
445 int selected
=0, result
;
449 static const struct opt_items doomkeys
[] = {
455 { "Key Select", -1 },
456 #if defined(TOSHIBA_GIGABEAT_F)
460 { "Key Volume Down", -1 },
461 { "Key Volume Up", -1 },
463 { "Key Record", -1 },
482 int numdoomkeys
=sizeof(doomkeys
) / sizeof(*doomkeys
);
484 MENUITEM_STRINGLIST(menu
, "Set Keys", NULL
,
485 "Game Right", "Game Left", "Game Up", "Game Down",
486 "Game Shoot", "Game Open", "Game Strafe",
487 "Game Weapon", "Game Automap");
491 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
496 *keys
[result
]=translatekey(*keys
[result
]);
497 rb
->set_option(menu_
[result
], keys
[result
], INT
, doomkeys
, numdoomkeys
, NULL
);
498 *keys
[result
]=translatekey(*keys
[result
]);
505 extern int fake_contrast
;
507 static bool Doptions()
509 static const struct opt_items onoff
[2] = {
514 int selected
=0, result
;
517 MENUITEM_STRINGLIST(menu
, "Options", NULL
,
518 "Set Keys", "Sound", "Timedemo", "Player Bobbing",
519 "Weapon Recoil", "Translucency", "Fake Contrast",
520 "Always Run", "Headsup Display", "Statusbar Always Red",
521 #if(LCD_HEIGHT>LCD_WIDTH)
522 "Rotate Screen 90 deg",
529 &default_player_bobbing
,
530 &default_weapon_recoil
,
531 &default_translucency
,
536 #if(LCD_HEIGHT>LCD_WIDTH)
543 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
547 rb
->set_option(menu_
[result
], options
[result
-1], INT
, onoff
, 2, NULL
);
555 static const char* choice_get_name(int selected_item
, void * data
,
556 char * buffer
, size_t buffer_len
)
558 const char **names
= (const char **) data
;
561 return names
[selected_item
];
564 int list_action_callback(int action
, struct gui_synclist
*lists
)
567 if (action
== ACTION_STD_OK
)
568 return ACTION_STD_CANCEL
;
572 bool menuchoice(char **names
, int count
, int *selected
)
574 struct simplelist_info info
;
575 rb
->simplelist_info_init(&info
, NULL
, count
, (void*)names
);
576 info
.selection
= *selected
;
577 info
.get_name
= choice_get_name
;
578 info
.action_callback
= list_action_callback
;
579 if(rb
->simplelist_show_list(&info
))
582 if(info
.selection
<count
&& info
.selection
>=0)
583 *selected
= info
.selection
;
592 int selected
=0, result
;
597 static struct opt_items names
[7];
599 MENUITEM_STRINGLIST(menu
, "Doom Menu", NULL
,
600 "Game", "Addons", "Demos",
601 "Options", "Play Game", "Quit");
603 if( (status
=Dbuild_base(names
)) == 0 ) // Build up the base wad files (select last added file)
605 rb
->splash(HZ
*2, "Missing Base WAD!");
609 int numadd
=Dbuild_filelistm(&addons
, "No Addon", GAMEBASE
"addons/", ".WAD" );
611 int numdemos
=Dbuild_filelistm(&demolmp
, "No Demo", GAMEBASE
"demos/", ".LMP" );
618 /* Clean out the button Queue */
619 while (rb
->button_get(false) != BUTTON_NONE
)
624 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
626 case 0: /* Game picker */
627 rb
->set_option("Game WAD", &gamever
, INT
, names
, status
, NULL
);
630 case 1: /* Addon picker */
631 menuchoice(addons
,numadd
,&argvlist
.addonnum
);
635 menuchoice(demolmp
,numdemos
,&argvlist
.demonum
);
638 case 3: /* Options */
642 case 4: /* Play Game */
659 extern int systemvol
;
660 /* this is the plugin entry point */
661 enum plugin_status
plugin_start(const void* parameter
)
663 /* Disable all talking before initializing IRAM */
664 rb
->talk_disable(true);
672 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
678 // We're using doom's memory management since it implements a proper free (and re-uses the memory)
679 // and now with prboom's code: realloc and calloc
680 printf ("Z_Init: Init zone memory allocation daemon.\n");
683 printf ("M_LoadDefaults: Load system defaults.\n");
684 M_LoadDefaults (); // load before initing other systems
686 rb
->splash(HZ
*2, "Welcome to RockDoom");
691 rb
->lcd_clear_display();
693 int result
= doom_menu();
696 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
697 rb
->cpu_boost(false);
699 rb
->talk_disable(false);
701 return PLUGIN_OK
; // Quit was selected
703 return PLUGIN_ERROR
; // Missing base wads
706 #if(LCD_HEIGHT>LCD_WIDTH)
709 SCREENHEIGHT
=LCD_WIDTH
;
710 SCREENWIDTH
=LCD_HEIGHT
;
714 SCREENHEIGHT
=LCD_HEIGHT
;
715 SCREENWIDTH
=LCD_WIDTH
;
719 Dhandle_ver( namemap
[ result
] );
723 rb
->lcd_clear_display();
725 int mod
= (rb
->sound_max(SOUND_VOLUME
)-rb
->sound_min(SOUND_VOLUME
))/15;
727 mod
= rb
->global_settings
->volume
;
728 systemvol
= rb
->global_settings
->volume
-rb
->global_settings
->volume
%mod
;
729 general_translucency
= default_translucency
; // phares
731 backlight_force_on();
733 rb
->profile_thread();
737 rb
->lcd_set_backdrop(NULL
);
745 backlight_use_settings();
749 I_Quit(); // Make SURE everything was closed out right
751 printf("There were still: %d files open\n", fpoint
);
755 close(filearray
[fpoint
]);
757 rb
->close(filearray
[fpoint
]);
762 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
763 rb
->cpu_boost(false);
766 rb
->talk_disable(false);