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
)
71 filearray
[fpoint
]=rb
->open(file
, flags
);
73 if(filearray
[fpoint
]<0)
74 return filearray
[fpoint
];
77 return filearray
[fpoint
-1];
85 while(filearray
[i
]!=id
&& i
<8)
90 printf("A requested FID did not exist!!!!");
96 for(; i
<fpoint
-1; i
++)
97 filearray
[i
]=filearray
[i
+1];
105 bool noprintf
=0; // Variable disables printf lcd updates to protect grayscale lib/direct lcd updates
108 // Here is a hacked up printf command to get the output from the game.
109 int printf(const char *fmt
, ...)
118 ok
= vsnprintf(p_buf
,sizeof(p_buf
), fmt
, ap
);
121 rb
->lcd_putsxy(1,p_xtpt
, (unsigned char *)p_buf
);
126 if(p_xtpt
>LCD_HEIGHT
-8)
130 rb
->lcd_clear_display();
136 char *my_strtok( char * s
, const char * delim
)
138 register char *spanp
;
144 if (s
== NULL
&& (s
= lasts
) == NULL
)
148 * Skip (span) leading delimiters (s += strspn(s, delim), sort of).
152 for (spanp
= (char *)delim
; (sc
= *spanp
++) != 0;) {
157 if (c
== 0) { /* no non-delimiter characters */
164 * Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
165 * Note that delim must have one NUL; we stop if we see that, too.
169 spanp
= (char *)delim
;
171 if ((sc
= *spanp
++) == c
) {
186 int timedemo
; // 1 says there's a timedemo
191 const unsigned char versions_builtin
[7][20] =
202 const unsigned char wads_builtin
[7][30] =
209 GAMEBASE
"plutonia.wad",
214 static char **addons
;
215 static char **demolmp
;
217 // This sets up the base game and builds up myargv/c
218 bool Dhandle_ver (int dver
)
221 case 0: /* Doom Shareware */
222 gamemode
= shareware
;
224 D_AddFile(wads_builtin
[0],source_iwad
);
226 case 1: /* Doom registered */
227 gamemode
= registered
;
229 D_AddFile(wads_builtin
[1],source_iwad
);
231 case 2: /* Ultimate Doom */
234 D_AddFile(wads_builtin
[2],source_iwad
);
237 gamemode
= commercial
;
239 D_AddFile(wads_builtin
[3],source_iwad
);
242 gamemode
= commercial
;
244 D_AddFile(wads_builtin
[4],source_iwad
);
246 case 5: /* Plutonia */
247 gamemode
= commercial
;
248 gamemission
= pack_plut
;
249 D_AddFile(wads_builtin
[5],source_iwad
);
252 gamemode
= commercial
;
253 gamemission
= pack_tnt
;
254 D_AddFile(wads_builtin
[6],source_iwad
);
260 // Start adding to myargv
261 if(argvlist
.timedemo
&& (gamemode
== shareware
))
264 timingdemo
= true; // show stats after quit
265 G_DeferedPlayDemo("demo3");
266 singledemo
= true; // quit after one demo
269 if(argvlist
.addonnum
)
271 snprintf(addon
,sizeof(addon
),"%s%s", GAMEBASE
"addons/", addons
[argvlist
.addonnum
]);
272 D_AddFile(addon
,source_pwad
);
278 snprintf(addon
, sizeof(addon
),"%s%s", GAMEBASE
"demos/", demolmp
[argvlist
.demonum
]);
279 D_AddFile(addon
, source_lmp
);
280 G_DeferedPlayDemo(addon
);
281 singledemo
= true; // quit after one demo
286 // This function builds up the basegame list for use in the options selection
287 // it also sets the defaults for the argvlist
288 // Now checking for rcokdoom.wad based on prboom.wad
289 int Dbuild_base (struct opt_items
*names
)
291 if ( fileexists(GAMEBASE
"rockdoom.wad") )
294 D_AddFile (GAMEBASE
"rockdoom.wad", source_pwad
);
298 /* Doom registered */
305 if ( !fileexists (wads_builtin
[j
]) )
307 names
[i
].string
=versions_builtin
[j
];
308 names
[i
].voice_id
=-1;
312 // Set argvlist defaults
318 // This is a general function that takes in a menu_item structure and makes a list
319 // of files within it based on matching the string stringmatch to the files.
320 int Dbuild_filelistm(char ***names
, char *firstentry
, char *directory
, char *stringmatch
)
328 filedir
=rb
->opendir(directory
);
332 temp
=malloc(sizeof(char *));
338 // Get the total number of entries
339 while((dptr
=rb
->readdir(filedir
)))
342 // Reset the directory
343 rb
->closedir(filedir
);
344 filedir
=rb
->opendir(directory
);
347 temp
=malloc(i
*sizeof(char *));
351 while((dptr
=rb
->readdir(filedir
)))
353 if(rb
->strcasestr(dptr
->d_name
, stringmatch
))
355 startpt
=malloc(strlen(dptr
->d_name
)*sizeof(char));
356 strcpy(startpt
,dptr
->d_name
);
361 rb
->closedir(filedir
);
366 static int translatekey(int key
) __attribute__ ((noinline
));
368 // This key configuration code is not the cleanest or the most efficient, but it works
369 static int translatekey(int key
)
378 return KEY_RIGHTARROW
;
380 return KEY_LEFTARROW
;
384 return KEY_DOWNARROW
;
433 // I havn't added configurable keys for enter or escape because this requires some modification to
434 // m_menu.c which hasn't been done yet.
438 int selected
=0, result
;
442 static const struct opt_items doomkeys
[] = {
448 { "Key Select", -1 },
449 #if defined(TOSHIBA_GIGABEAT_F)
453 { "Key Volume Down", -1 },
454 { "Key Volume Up", -1 },
456 { "Key Record", -1 },
475 int numdoomkeys
=sizeof(doomkeys
) / sizeof(*doomkeys
);
477 MENUITEM_STRINGLIST(menu
, "Set Keys", NULL
,
478 "Game Right", "Game Left", "Game Up", "Game Down",
479 "Game Shoot", "Game Open", "Game Strafe",
480 "Game Weapon", "Game Automap");
484 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
489 *keys
[result
]=translatekey(*keys
[result
]);
490 rb
->set_option(menu_
[result
], keys
[result
], INT
, doomkeys
, numdoomkeys
, NULL
);
491 *keys
[result
]=translatekey(*keys
[result
]);
498 extern int fake_contrast
;
500 static bool Doptions()
502 static const struct opt_items onoff
[2] = {
507 int selected
=0, result
;
510 MENUITEM_STRINGLIST(menu
, "Options", NULL
,
511 "Set Keys", "Sound", "Timedemo", "Player Bobbing",
512 "Weapon Recoil", "Translucency", "Fake Contrast",
513 "Always Run", "Headsup Display", "Statusbar Always Red",
514 #if(LCD_HEIGHT>LCD_WIDTH)
515 "Rotate Screen 90 deg",
522 &default_player_bobbing
,
523 &default_weapon_recoil
,
524 &default_translucency
,
529 #if(LCD_HEIGHT>LCD_WIDTH)
536 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
540 rb
->set_option(menu_
[result
], options
[result
-1], INT
, onoff
, 2, NULL
);
548 static const char* choice_get_name(int selected_item
, void * data
,
549 char * buffer
, size_t buffer_len
)
551 const char **names
= (const char **) data
;
554 return names
[selected_item
];
557 int list_action_callback(int action
, struct gui_synclist
*lists
)
560 if (action
== ACTION_STD_OK
)
561 return ACTION_STD_CANCEL
;
565 bool menuchoice(char **names
, int count
, int *selected
)
567 struct simplelist_info info
;
568 rb
->simplelist_info_init(&info
, NULL
, count
, (void*)names
);
569 info
.selection
= *selected
;
570 info
.get_name
= choice_get_name
;
571 info
.action_callback
= list_action_callback
;
572 if(rb
->simplelist_show_list(&info
))
575 if(info
.selection
<count
&& info
.selection
>=0)
576 *selected
= info
.selection
;
585 int selected
=0, result
;
590 static struct opt_items names
[7];
592 MENUITEM_STRINGLIST(menu
, "Doom Menu", NULL
,
593 "Game", "Addons", "Demos",
594 "Options", "Play Game", "Quit");
596 if( (status
=Dbuild_base(names
)) == 0 ) // Build up the base wad files (select last added file)
598 rb
->splash(HZ
*2, "Missing Base WAD!");
602 int numadd
=Dbuild_filelistm(&addons
, "No Addon", GAMEBASE
"addons/", ".WAD" );
604 int numdemos
=Dbuild_filelistm(&demolmp
, "No Demo", GAMEBASE
"demos/", ".LMP" );
611 /* Clean out the button Queue */
612 while (rb
->button_get(false) != BUTTON_NONE
)
617 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
619 case 0: /* Game picker */
620 rb
->set_option("Game WAD", &gamever
, INT
, names
, status
, NULL
);
623 case 1: /* Addon picker */
624 menuchoice(addons
,numadd
,&argvlist
.addonnum
);
628 menuchoice(demolmp
,numdemos
,&argvlist
.demonum
);
631 case 3: /* Options */
635 case 4: /* Play Game */
652 extern int systemvol
;
653 /* this is the plugin entry point */
654 enum plugin_status
plugin_start(const void* parameter
)
656 /* Disable all talking before initializing IRAM */
657 rb
->talk_disable(true);
665 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
671 // We're using doom's memory management since it implements a proper free (and re-uses the memory)
672 // and now with prboom's code: realloc and calloc
673 printf ("Z_Init: Init zone memory allocation daemon.\n");
676 printf ("M_LoadDefaults: Load system defaults.\n");
677 M_LoadDefaults (); // load before initing other systems
679 rb
->splash(HZ
*2, "Welcome to RockDoom");
684 rb
->lcd_clear_display();
686 int result
= doom_menu();
689 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
690 rb
->cpu_boost(false);
692 rb
->talk_disable(false);
694 return PLUGIN_OK
; // Quit was selected
696 return PLUGIN_ERROR
; // Missing base wads
699 #if(LCD_HEIGHT>LCD_WIDTH)
702 SCREENHEIGHT
=LCD_WIDTH
;
703 SCREENWIDTH
=LCD_HEIGHT
;
707 SCREENHEIGHT
=LCD_HEIGHT
;
708 SCREENWIDTH
=LCD_WIDTH
;
712 Dhandle_ver( namemap
[ result
] );
716 rb
->lcd_clear_display();
718 int mod
= (rb
->sound_max(SOUND_VOLUME
)-rb
->sound_min(SOUND_VOLUME
))/15;
720 mod
= rb
->global_settings
->volume
;
721 systemvol
= rb
->global_settings
->volume
-rb
->global_settings
->volume
%mod
;
722 general_translucency
= default_translucency
; // phares
724 backlight_force_on();
726 rb
->profile_thread();
730 rb
->lcd_set_backdrop(NULL
);
738 backlight_use_settings();
742 I_Quit(); // Make SURE everything was closed out right
744 printf("There were still: %d files open\n", fpoint
);
748 close(filearray
[fpoint
]);
750 rb
->close(filearray
[fpoint
]);
755 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
756 rb
->cpu_boost(false);
759 rb
->talk_disable(false);