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
) {
184 inline void* memcpy(void* dst
, const void* src
, size_t size
)
186 return rb
->memcpy(dst
, src
, size
);
191 int timedemo
; // 1 says there's a timedemo
196 const unsigned char versions_builtin
[7][20] =
207 const unsigned char wads_builtin
[7][30] =
214 GAMEBASE
"plutonia.wad",
219 static char **addons
;
220 static char **demolmp
;
222 // This sets up the base game and builds up myargv/c
223 bool Dhandle_ver (int dver
)
226 case 0: /* Doom Shareware */
227 gamemode
= shareware
;
229 D_AddFile(wads_builtin
[0],source_iwad
);
231 case 1: /* Doom registered */
232 gamemode
= registered
;
234 D_AddFile(wads_builtin
[1],source_iwad
);
236 case 2: /* Ultimate Doom */
239 D_AddFile(wads_builtin
[2],source_iwad
);
242 gamemode
= commercial
;
244 D_AddFile(wads_builtin
[3],source_iwad
);
247 gamemode
= commercial
;
249 D_AddFile(wads_builtin
[4],source_iwad
);
251 case 5: /* Plutonia */
252 gamemode
= commercial
;
253 gamemission
= pack_plut
;
254 D_AddFile(wads_builtin
[5],source_iwad
);
257 gamemode
= commercial
;
258 gamemission
= pack_tnt
;
259 D_AddFile(wads_builtin
[6],source_iwad
);
265 // Start adding to myargv
266 if(argvlist
.timedemo
&& (gamemode
== shareware
))
269 timingdemo
= true; // show stats after quit
270 G_DeferedPlayDemo("demo3");
271 singledemo
= true; // quit after one demo
274 if(argvlist
.addonnum
)
276 snprintf(addon
,sizeof(addon
),"%s%s", GAMEBASE
"addons/", addons
[argvlist
.addonnum
]);
277 D_AddFile(addon
,source_pwad
);
283 snprintf(addon
, sizeof(addon
),"%s%s", GAMEBASE
"demos/", demolmp
[argvlist
.demonum
]);
284 D_AddFile(addon
, source_lmp
);
285 G_DeferedPlayDemo(addon
);
286 singledemo
= true; // quit after one demo
291 // This function builds up the basegame list for use in the options selection
292 // it also sets the defaults for the argvlist
293 // Now checking for rcokdoom.wad based on prboom.wad
294 int Dbuild_base (struct opt_items
*names
)
296 if ( fileexists(GAMEBASE
"rockdoom.wad") )
299 D_AddFile (GAMEBASE
"rockdoom.wad", source_pwad
);
303 /* Doom registered */
310 if ( !fileexists (wads_builtin
[j
]) )
312 names
[i
].string
=versions_builtin
[j
];
313 names
[i
].voice_id
=-1;
317 // Set argvlist defaults
323 // This is a general function that takes in a menu_item structure and makes a list
324 // of files within it based on matching the string stringmatch to the files.
325 int Dbuild_filelistm(char ***names
, char *firstentry
, char *directory
, char *stringmatch
)
333 filedir
=rb
->opendir(directory
);
337 temp
=malloc(sizeof(char *));
343 // Get the total number of entries
344 while((dptr
=rb
->readdir(filedir
)))
347 // Reset the directory
348 rb
->closedir(filedir
);
349 filedir
=rb
->opendir(directory
);
352 temp
=malloc(i
*sizeof(char *));
356 while((dptr
=rb
->readdir(filedir
)))
358 if(rb
->strcasestr(dptr
->d_name
, stringmatch
))
360 startpt
=malloc(strlen(dptr
->d_name
)*sizeof(char));
361 strcpy(startpt
,dptr
->d_name
);
366 rb
->closedir(filedir
);
371 static int translatekey(int key
) __attribute__ ((noinline
));
373 // This key configuration code is not the cleanest or the most efficient, but it works
374 static int translatekey(int key
)
383 return KEY_RIGHTARROW
;
385 return KEY_LEFTARROW
;
389 return KEY_DOWNARROW
;
438 // I havn't added configurable keys for enter or escape because this requires some modification to
439 // m_menu.c which hasn't been done yet.
443 int selected
=0, result
;
447 static const struct opt_items doomkeys
[] = {
453 { "Key Select", -1 },
454 #if defined(TOSHIBA_GIGABEAT_F)
458 { "Key Volume Down", -1 },
459 { "Key Volume Up", -1 },
461 { "Key Record", -1 },
480 int numdoomkeys
=sizeof(doomkeys
) / sizeof(*doomkeys
);
482 MENUITEM_STRINGLIST(menu
, "Set Keys", NULL
,
483 "Game Right", "Game Left", "Game Up", "Game Down",
484 "Game Shoot", "Game Open", "Game Strafe",
485 "Game Weapon", "Game Automap");
489 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
494 *keys
[result
]=translatekey(*keys
[result
]);
495 rb
->set_option(menu_
[result
], keys
[result
], INT
, doomkeys
, numdoomkeys
, NULL
);
496 *keys
[result
]=translatekey(*keys
[result
]);
503 extern int fake_contrast
;
505 static bool Doptions()
507 static const struct opt_items onoff
[2] = {
512 int selected
=0, result
;
515 MENUITEM_STRINGLIST(menu
, "Options", NULL
,
516 "Set Keys", "Sound", "Timedemo", "Player Bobbing",
517 "Weapon Recoil", "Translucency", "Fake Contrast",
518 "Always Run", "Headsup Display", "Statusbar Always Red",
519 #if(LCD_HEIGHT>LCD_WIDTH)
520 "Rotate Screen 90 deg",
527 &default_player_bobbing
,
528 &default_weapon_recoil
,
529 &default_translucency
,
534 #if(LCD_HEIGHT>LCD_WIDTH)
541 result
= rb
->do_menu(&menu
, &selected
, NULL
, false);
545 rb
->set_option(menu_
[result
], options
[result
-1], INT
, onoff
, 2, NULL
);
553 char* choice_get_name(int selected_item
, void * data
,
554 char * buffer
, size_t buffer_len
)
556 char **names
= (char **) data
;
559 return names
[selected_item
];
561 int list_action_callback(int action
, struct gui_synclist
*lists
)
564 if (action
== ACTION_STD_OK
)
565 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
)
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);
693 return PLUGIN_OK
; // Quit was selected
695 return PLUGIN_ERROR
; // Missing base wads
698 #if(LCD_HEIGHT>LCD_WIDTH)
701 SCREENHEIGHT
=LCD_WIDTH
;
702 SCREENWIDTH
=LCD_HEIGHT
;
706 SCREENHEIGHT
=LCD_HEIGHT
;
707 SCREENWIDTH
=LCD_WIDTH
;
711 Dhandle_ver( namemap
[ result
] );
715 rb
->lcd_clear_display();
717 int mod
= (rb
->sound_max(SOUND_VOLUME
)-rb
->sound_min(SOUND_VOLUME
))/15;
719 mod
= rb
->global_settings
->volume
;
720 systemvol
= rb
->global_settings
->volume
-rb
->global_settings
->volume
%mod
;
721 general_translucency
= default_translucency
; // phares
723 backlight_force_on();
725 rb
->profile_thread();
729 rb
->lcd_set_backdrop(NULL
);
737 backlight_use_settings();
741 I_Quit(); // Make SURE everything was closed out right
743 printf("There were still: %d files open\n", fpoint
);
747 close(filearray
[fpoint
]);
749 rb
->close(filearray
[fpoint
]);
754 #ifdef HAVE_ADJUSTABLE_CPU_FREQ
755 rb
->cpu_boost(false);