2006-03-11 15:44:35 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Pacbox - a Pacman Emulator for Rockbox
|
|
|
|
*
|
|
|
|
* Based on PIE - Pacman Instructional Emulator
|
|
|
|
*
|
|
|
|
* Copyright (c) 1997-2003,2004 Alessandro Scotti
|
|
|
|
* http://www.ascotti.org/
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-03-11 15:44:35 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
#include "arcade.h"
|
2006-03-13 01:42:11 +00:00
|
|
|
#include "pacbox.h"
|
|
|
|
#include "pacbox_lcd.h"
|
2010-07-01 00:26:01 +00:00
|
|
|
#include "wsg3.h"
|
2006-03-15 17:32:18 +00:00
|
|
|
#include "lib/configfile.h"
|
2009-08-05 14:29:29 +00:00
|
|
|
#include "lib/playback_control.h"
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
struct pacman_settings {
|
|
|
|
int difficulty;
|
|
|
|
int numlives;
|
|
|
|
int bonus;
|
|
|
|
int ghostnames;
|
|
|
|
int showfps;
|
2010-07-01 00:26:01 +00:00
|
|
|
int sound;
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static struct pacman_settings settings;
|
|
|
|
static struct pacman_settings old_settings;
|
2010-07-01 00:26:01 +00:00
|
|
|
static bool sound_playing = false;
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
#define SETTINGS_VERSION 1
|
|
|
|
#define SETTINGS_MIN_VERSION 1
|
|
|
|
#define SETTINGS_FILENAME "pacbox.cfg"
|
|
|
|
|
|
|
|
static char* difficulty_options[] = { "Normal", "Hard" };
|
|
|
|
static char* numlives_options[] = { "1", "2", "3", "5" };
|
|
|
|
static char* bonus_options[] = {"10000", "15000", "20000", "No Bonus"};
|
|
|
|
static char* ghostnames_options[] = {"Normal", "Alternate"};
|
2010-07-01 00:26:01 +00:00
|
|
|
static char* yesno_options[] = {"No", "Yes"};
|
2006-03-15 17:32:18 +00:00
|
|
|
|
|
|
|
static struct configdata config[] =
|
|
|
|
{
|
2009-01-17 22:53:12 +00:00
|
|
|
{TYPE_ENUM, 0, 2, { .int_p = &settings.difficulty }, "Difficulty",
|
|
|
|
difficulty_options},
|
|
|
|
{TYPE_ENUM, 0, 4, { .int_p = &settings.numlives }, "Pacmen Per Game",
|
|
|
|
numlives_options},
|
|
|
|
{TYPE_ENUM, 0, 4, { .int_p = &settings.bonus }, "Bonus", bonus_options},
|
|
|
|
{TYPE_ENUM, 0, 2, { .int_p = &settings.ghostnames }, "Ghost Names",
|
|
|
|
ghostnames_options},
|
|
|
|
{TYPE_ENUM, 0, 2, { .int_p = &settings.showfps }, "Show FPS",
|
2010-07-01 00:26:01 +00:00
|
|
|
yesno_options},
|
|
|
|
{TYPE_ENUM, 0, 2, { .int_p = &settings.sound }, "Sound",
|
|
|
|
yesno_options},
|
2006-03-15 17:32:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static bool loadFile( const char * name, unsigned char * buf, int len )
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
|
|
|
char filename[MAX_PATH];
|
|
|
|
|
2007-09-10 09:46:36 +00:00
|
|
|
rb->snprintf(filename,sizeof(filename), ROCKBOX_DIR "/pacman/%s",name);
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
int fd = rb->open( filename, O_RDONLY);
|
|
|
|
|
|
|
|
if( fd < 0 ) {
|
|
|
|
return false;
|
|
|
|
}
|
2009-08-05 14:29:29 +00:00
|
|
|
|
2006-03-11 15:44:35 +00:00
|
|
|
int n = rb->read( fd, buf, len);
|
2009-08-05 14:29:29 +00:00
|
|
|
|
2006-03-11 15:44:35 +00:00
|
|
|
rb->close( fd );
|
|
|
|
|
|
|
|
if( n != len ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static bool loadROMS( void )
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
|
|
|
bool romsLoaded = false;
|
|
|
|
|
|
|
|
romsLoaded = loadFile( "pacman.6e", ram_, 0x1000) &&
|
|
|
|
loadFile( "pacman.6f", ram_+0x1000, 0x1000) &&
|
|
|
|
loadFile( "pacman.6h", ram_+0x2000, 0x1000) &&
|
|
|
|
loadFile( "pacman.6j", ram_+0x3000, 0x1000) &&
|
|
|
|
loadFile( "pacman.5e", charset_rom_, 0x1000) &&
|
|
|
|
loadFile( "pacman.5f", spriteset_rom_, 0x1000);
|
|
|
|
|
|
|
|
if( romsLoaded ) {
|
|
|
|
decodeROMs();
|
|
|
|
reset_PacmanMachine();
|
|
|
|
}
|
|
|
|
|
|
|
|
return romsLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* A buffer to render Pacman's 244x288 screen into */
|
2006-03-18 09:14:10 +00:00
|
|
|
static unsigned char video_buffer[ScreenWidth*ScreenHeight] __attribute__ ((aligned (16)));
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static long start_time;
|
|
|
|
static long video_frames = 0;
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static int dipDifficulty[] = { DipDifficulty_Normal, DipDifficulty_Hard };
|
|
|
|
static int dipLives[] = { DipLives_1, DipLives_2, DipLives_3, DipLives_5 };
|
|
|
|
static int dipBonus[] = { DipBonus_10000, DipBonus_15000, DipBonus_20000,
|
|
|
|
DipBonus_None };
|
|
|
|
static int dipGhostNames[] = { DipGhostNames_Normal, DipGhostNames_Alternate };
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static int settings_to_dip(struct pacman_settings settings)
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
|
|
|
return ( DipPlay_OneCoinOneGame |
|
|
|
|
DipCabinet_Upright |
|
|
|
|
DipMode_Play |
|
|
|
|
DipRackAdvance_Off |
|
|
|
|
|
|
|
|
dipDifficulty[settings.difficulty] |
|
|
|
|
dipLives[settings.numlives] |
|
|
|
|
dipBonus[settings.bonus] |
|
|
|
|
dipGhostNames[settings.ghostnames]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
static bool pacbox_menu(void)
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
2009-06-16 04:25:21 +00:00
|
|
|
int selected=0;
|
2006-03-11 15:44:35 +00:00
|
|
|
int result;
|
|
|
|
int menu_quit=0;
|
|
|
|
int new_setting;
|
|
|
|
bool need_restart = false;
|
|
|
|
|
|
|
|
static const struct opt_items noyes[2] = {
|
2006-08-11 12:48:36 +00:00
|
|
|
{ "No", -1 },
|
|
|
|
{ "Yes", -1 },
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct opt_items difficulty_options[2] = {
|
2006-08-11 12:48:36 +00:00
|
|
|
{ "Normal", -1 },
|
|
|
|
{ "Harder", -1 },
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct opt_items numlives_options[4] = {
|
2006-08-11 12:48:36 +00:00
|
|
|
{ "1", -1 },
|
|
|
|
{ "2", -1 },
|
|
|
|
{ "3", -1 },
|
|
|
|
{ "5", -1 },
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct opt_items bonus_options[4] = {
|
2006-08-11 12:48:36 +00:00
|
|
|
{ "10000 points", -1 },
|
|
|
|
{ "15000 points", -1 },
|
|
|
|
{ "20000 points", -1 },
|
|
|
|
{ "No bonus", -1 },
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct opt_items ghostname_options[2] = {
|
2006-08-11 12:48:36 +00:00
|
|
|
{ "Normal", -1 },
|
|
|
|
{ "Alternate", -1 },
|
2006-03-11 15:44:35 +00:00
|
|
|
};
|
|
|
|
|
2010-07-01 00:26:01 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PBMI_DIFFICULTY = 0,
|
|
|
|
PBMI_PACMEN_PER_GAME,
|
|
|
|
PBMI_BONUS_LIFE,
|
|
|
|
PBMI_GHOST_NAMES,
|
|
|
|
PBMI_DISPLAY_FPS,
|
|
|
|
PBMI_SOUND,
|
|
|
|
PBMI_RESTART,
|
|
|
|
PBMI_QUIT,
|
|
|
|
};
|
|
|
|
|
2009-06-16 04:25:21 +00:00
|
|
|
MENUITEM_STRINGLIST(menu, "Pacbox Menu", NULL,
|
|
|
|
"Difficulty", "Pacmen Per Game", "Bonus Life",
|
2010-07-01 00:26:01 +00:00
|
|
|
"Ghost Names", "Display FPS", "Sound",
|
2010-03-19 23:24:22 +00:00
|
|
|
"Restart", "Quit");
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
rb->button_clear_queue();
|
2009-09-07 21:41:10 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
|
|
|
|
rb->lcd_set_mode(LCD_MODE_RGB565);
|
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
while (!menu_quit) {
|
2009-06-16 04:25:21 +00:00
|
|
|
result=rb->do_menu(&menu, &selected, NULL, false);
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
switch(result)
|
|
|
|
{
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_DIFFICULTY:
|
2006-03-11 15:44:35 +00:00
|
|
|
new_setting=settings.difficulty;
|
|
|
|
rb->set_option("Difficulty", &new_setting, INT,
|
|
|
|
difficulty_options , 2, NULL);
|
|
|
|
if (new_setting != settings.difficulty) {
|
|
|
|
settings.difficulty=new_setting;
|
|
|
|
need_restart=true;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_PACMEN_PER_GAME:
|
2006-03-11 15:44:35 +00:00
|
|
|
new_setting=settings.numlives;
|
|
|
|
rb->set_option("Pacmen Per Game", &new_setting, INT,
|
|
|
|
numlives_options , 4, NULL);
|
|
|
|
if (new_setting != settings.numlives) {
|
|
|
|
settings.numlives=new_setting;
|
|
|
|
need_restart=true;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_BONUS_LIFE:
|
2006-03-11 15:44:35 +00:00
|
|
|
new_setting=settings.bonus;
|
|
|
|
rb->set_option("Bonus Life", &new_setting, INT,
|
|
|
|
bonus_options , 4, NULL);
|
|
|
|
if (new_setting != settings.bonus) {
|
|
|
|
settings.bonus=new_setting;
|
|
|
|
need_restart=true;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_GHOST_NAMES:
|
2006-03-11 15:44:35 +00:00
|
|
|
new_setting=settings.ghostnames;
|
|
|
|
rb->set_option("Ghost Names", &new_setting, INT,
|
|
|
|
ghostname_options , 2, NULL);
|
|
|
|
if (new_setting != settings.ghostnames) {
|
|
|
|
settings.ghostnames=new_setting;
|
|
|
|
need_restart=true;
|
|
|
|
}
|
|
|
|
break;
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_DISPLAY_FPS:
|
2009-08-05 14:29:29 +00:00
|
|
|
rb->set_option("Display FPS",&settings.showfps,INT,
|
2006-03-15 17:32:18 +00:00
|
|
|
noyes, 2, NULL);
|
2006-03-11 15:44:35 +00:00
|
|
|
break;
|
2010-07-01 00:26:01 +00:00
|
|
|
case PBMI_SOUND:
|
|
|
|
rb->set_option("Sound",&settings.sound, INT,
|
|
|
|
noyes, 2, NULL);
|
|
|
|
break;
|
|
|
|
case PBMI_RESTART:
|
2006-03-11 15:44:35 +00:00
|
|
|
need_restart=true;
|
|
|
|
menu_quit=1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
menu_quit=1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-09-07 21:41:10 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
|
|
|
|
rb->lcd_set_mode(LCD_MODE_PAL256);
|
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
if (need_restart) {
|
|
|
|
init_PacmanMachine(settings_to_dip(settings));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Possible results:
|
|
|
|
exit game
|
|
|
|
restart game
|
|
|
|
usb connected
|
|
|
|
*/
|
2010-07-01 00:26:01 +00:00
|
|
|
return (result==PBMI_QUIT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sound is emulated in ISR context, so not much is done per sound frame */
|
|
|
|
#define NBSAMPLES 128
|
|
|
|
static uint32_t sound_buf[NBSAMPLES];
|
2010-07-01 00:46:15 +00:00
|
|
|
#if CONFIG_CPU == MCF5249
|
|
|
|
/* Not enough to put this in IRAM */
|
2010-07-01 03:57:37 +00:00
|
|
|
static int16_t raw_buf[NBSAMPLES];
|
2010-07-01 00:46:15 +00:00
|
|
|
#else
|
2010-07-01 03:57:37 +00:00
|
|
|
static int16_t raw_buf[NBSAMPLES] IBSS_ATTR;
|
2010-07-01 00:46:15 +00:00
|
|
|
#endif
|
2010-07-01 00:26:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Audio callback
|
|
|
|
*/
|
|
|
|
static void get_more(unsigned char **start, size_t *size)
|
|
|
|
{
|
2010-07-01 03:57:37 +00:00
|
|
|
int32_t *out, *outend;
|
|
|
|
int16_t *raw;
|
2010-07-01 00:26:01 +00:00
|
|
|
|
|
|
|
/* Emulate the audio for the current register settings */
|
|
|
|
playSound(raw_buf, NBSAMPLES);
|
|
|
|
|
|
|
|
out = sound_buf;
|
2010-07-01 03:57:37 +00:00
|
|
|
outend = out + NBSAMPLES;
|
2010-07-01 00:26:01 +00:00
|
|
|
raw = raw_buf;
|
|
|
|
|
2010-07-01 03:57:37 +00:00
|
|
|
/* Convert to stereo */
|
|
|
|
do
|
2010-07-01 00:26:01 +00:00
|
|
|
{
|
2010-07-01 03:57:37 +00:00
|
|
|
uint32_t sample = (uint16_t)*raw++;
|
2010-07-01 00:26:01 +00:00
|
|
|
*out++ = sample | (sample << 16);
|
|
|
|
}
|
2010-07-01 03:57:37 +00:00
|
|
|
while (out < outend);
|
2010-07-01 00:26:01 +00:00
|
|
|
|
|
|
|
*start = (unsigned char *)sound_buf;
|
|
|
|
*size = NBSAMPLES*sizeof(sound_buf[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Start the sound emulation
|
|
|
|
*/
|
|
|
|
static void start_sound(void)
|
|
|
|
{
|
|
|
|
int sr_index;
|
|
|
|
|
|
|
|
if (sound_playing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifndef PLUGIN_USE_IRAM
|
|
|
|
/* Ensure control of PCM - stopping music isn't obligatory */
|
|
|
|
rb->plugin_get_audio_buffer(NULL);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Get the closest rate >= to what is preferred */
|
|
|
|
sr_index = rb->round_value_to_list32(PREFERRED_SAMPLING_RATE,
|
|
|
|
rb->hw_freq_sampr, HW_NUM_FREQ, false);
|
|
|
|
|
|
|
|
if (rb->hw_freq_sampr[sr_index] < PREFERRED_SAMPLING_RATE
|
|
|
|
&& sr_index > 0)
|
|
|
|
{
|
|
|
|
/* Round up */
|
|
|
|
sr_index--;
|
|
|
|
}
|
|
|
|
|
|
|
|
wsg3_set_sampling_rate(rb->hw_freq_sampr[sr_index]);
|
|
|
|
|
|
|
|
rb->pcm_set_frequency(rb->hw_freq_sampr[sr_index]);
|
|
|
|
rb->pcm_play_data(get_more, NULL, 0);
|
|
|
|
|
|
|
|
sound_playing = true;
|
2006-03-11 15:44:35 +00:00
|
|
|
}
|
|
|
|
|
2010-07-01 00:26:01 +00:00
|
|
|
/*
|
|
|
|
Stop the sound emulation
|
|
|
|
*/
|
|
|
|
static void stop_sound(void)
|
|
|
|
{
|
|
|
|
if (!sound_playing)
|
|
|
|
return;
|
|
|
|
|
|
|
|
rb->pcm_play_stop();
|
|
|
|
rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
|
|
|
|
|
|
|
|
sound_playing = false;
|
|
|
|
}
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Runs the game engine for one frame.
|
|
|
|
*/
|
2006-03-15 17:32:18 +00:00
|
|
|
static int gameProc( void )
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
|
|
|
int fps;
|
|
|
|
int status;
|
|
|
|
long end_time;
|
2006-03-20 23:01:28 +00:00
|
|
|
int frame_counter = 0;
|
|
|
|
int yield_counter = 0;
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2010-07-01 00:26:01 +00:00
|
|
|
if (settings.sound)
|
|
|
|
start_sound();
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
/* Run the machine for one frame (1/60th second) */
|
|
|
|
run();
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
frame_counter++;
|
2006-03-16 23:21:47 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
/* Check the button status */
|
|
|
|
status = rb->button_status();
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-07-30 03:10:09 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
if (rb->button_hold())
|
|
|
|
status = PACMAN_MENU;
|
|
|
|
#endif
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
if ((status & PACMAN_MENU) == PACMAN_MENU
|
2006-03-18 09:14:10 +00:00
|
|
|
#ifdef PACMAN_RC_MENU
|
2006-03-20 23:01:28 +00:00
|
|
|
|| status == PACMAN_RC_MENU
|
2006-03-18 09:14:10 +00:00
|
|
|
#endif
|
2006-03-20 23:01:28 +00:00
|
|
|
) {
|
2010-07-01 00:26:01 +00:00
|
|
|
bool menu_res;
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
end_time = *rb->current_tick;
|
2010-07-01 00:26:01 +00:00
|
|
|
|
|
|
|
stop_sound();
|
|
|
|
|
|
|
|
menu_res = pacbox_menu();
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
rb->lcd_clear_display();
|
2006-03-11 15:44:35 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2006-03-20 23:01:28 +00:00
|
|
|
rb->lcd_remote_clear_display();
|
|
|
|
rb->lcd_remote_update();
|
2006-03-11 15:44:35 +00:00
|
|
|
#endif
|
2010-07-01 00:26:01 +00:00
|
|
|
if (menu_res)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (settings.sound)
|
|
|
|
start_sound();
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
start_time += *rb->current_tick-end_time;
|
|
|
|
}
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-18 09:14:10 +00:00
|
|
|
#ifdef PACMAN_HAS_REMOTE
|
2006-03-20 23:01:28 +00:00
|
|
|
setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
|
2006-03-18 09:14:10 +00:00
|
|
|
#else
|
2006-03-20 23:01:28 +00:00
|
|
|
setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
|
|
|
|
setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
|
2006-03-11 15:44:35 +00:00
|
|
|
#ifdef PACMAN_2UP
|
2006-03-20 23:01:28 +00:00
|
|
|
setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
|
2006-03-18 09:14:10 +00:00
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
#endif
|
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
/* We only update the screen every third frame - Pacman's native
|
|
|
|
framerate is 60fps, so we are attempting to display 20fps */
|
|
|
|
if (frame_counter == 60 / FPS) {
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
frame_counter = 0;
|
|
|
|
video_frames++;
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
yield_counter ++;
|
2006-03-13 01:42:11 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
if (yield_counter == FPS) {
|
|
|
|
yield_counter = 0;
|
|
|
|
rb->yield ();
|
|
|
|
}
|
2009-08-05 14:29:29 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
/* The following functions render the Pacman screen from the
|
|
|
|
contents of the video and color ram. We first update the
|
|
|
|
background, and then draw the Sprites on top.
|
|
|
|
*/
|
2006-03-13 01:42:11 +00:00
|
|
|
|
2006-03-20 23:01:28 +00:00
|
|
|
renderBackground( video_buffer );
|
|
|
|
renderSprites( video_buffer );
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2009-09-07 21:41:10 +00:00
|
|
|
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
|
|
|
|
rb->lcd_blit_pal256( video_buffer, 0, 0, XOFS, YOFS,
|
|
|
|
ScreenWidth, ScreenHeight);
|
|
|
|
#else
|
2006-03-20 23:01:28 +00:00
|
|
|
blit_display(rb->lcd_framebuffer,video_buffer);
|
2009-09-07 21:41:10 +00:00
|
|
|
#endif
|
2006-03-20 23:01:28 +00:00
|
|
|
|
|
|
|
if (settings.showfps) {
|
|
|
|
fps = (video_frames*HZ*100) / (*rb->current_tick-start_time);
|
2010-08-28 21:46:45 +00:00
|
|
|
rb->lcd_putsxyf(0,0,"%d.%02d / %d fps ",fps/100,fps%100,FPS);
|
2006-03-20 23:01:28 +00:00
|
|
|
}
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2009-09-07 21:41:10 +00:00
|
|
|
#if !defined(HAVE_LCD_MODES) || \
|
|
|
|
defined(HAVE_LCD_MODES) && !(HAVE_LCD_MODES & LCD_MODE_PAL256)
|
2006-03-20 23:01:28 +00:00
|
|
|
rb->lcd_update();
|
2009-09-07 21:41:10 +00:00
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2009-08-05 14:29:29 +00:00
|
|
|
/* Keep the framerate at Pacman's 60fps */
|
2006-03-20 23:01:28 +00:00
|
|
|
end_time = start_time + (video_frames*HZ)/FPS;
|
|
|
|
while (TIME_BEFORE(*rb->current_tick,end_time)) {
|
2009-08-05 14:29:29 +00:00
|
|
|
rb->sleep(1);
|
2006-03-20 23:01:28 +00:00
|
|
|
}
|
2006-03-11 15:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2010-07-01 00:26:01 +00:00
|
|
|
|
|
|
|
stop_sound();
|
|
|
|
|
2006-03-11 15:44:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-03-11 15:44:35 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(true);
|
|
|
|
#endif
|
2006-11-15 06:14:27 +00:00
|
|
|
rb->lcd_set_backdrop(NULL);
|
2006-03-11 15:44:35 +00:00
|
|
|
rb->lcd_set_foreground(LCD_WHITE);
|
|
|
|
rb->lcd_set_background(LCD_BLACK);
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
/* Set the default settings */
|
2006-03-11 15:44:35 +00:00
|
|
|
settings.difficulty = 0; /* Normal */
|
|
|
|
settings.numlives = 2; /* 3 lives */
|
|
|
|
settings.bonus = 0; /* 10000 points */
|
|
|
|
settings.ghostnames = 0; /* Normal names */
|
2006-03-13 01:52:11 +00:00
|
|
|
settings.showfps = 0; /* Do not show FPS */
|
2010-07-01 00:26:01 +00:00
|
|
|
settings.sound = 0; /* Sound off by default */
|
2006-03-11 15:44:35 +00:00
|
|
|
|
2006-03-15 17:32:18 +00:00
|
|
|
if (configfile_load(SETTINGS_FILENAME, config,
|
|
|
|
sizeof(config)/sizeof(*config),
|
|
|
|
SETTINGS_MIN_VERSION
|
|
|
|
) < 0)
|
|
|
|
{
|
|
|
|
/* If the loading failed, save a new config file (as the disk is
|
|
|
|
already spinning) */
|
|
|
|
configfile_save(SETTINGS_FILENAME, config,
|
|
|
|
sizeof(config)/sizeof(*config),
|
|
|
|
SETTINGS_VERSION);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Keep a copy of the saved version of the settings - so we can check if
|
|
|
|
the settings have changed when we quit */
|
|
|
|
old_settings = settings;
|
|
|
|
|
2006-03-11 15:44:35 +00:00
|
|
|
/* Initialise the hardware */
|
|
|
|
init_PacmanMachine(settings_to_dip(settings));
|
2009-09-07 21:41:10 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
|
|
|
|
rb->lcd_set_mode(LCD_MODE_PAL256);
|
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
/* Load the romset */
|
|
|
|
if (loadROMS()) {
|
|
|
|
start_time = *rb->current_tick-1;
|
2006-03-20 23:01:28 +00:00
|
|
|
|
|
|
|
gameProc();
|
2006-03-15 17:32:18 +00:00
|
|
|
|
|
|
|
/* Save the user settings if they have changed */
|
|
|
|
if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) {
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(0, "Saving settings...");
|
2006-03-15 17:32:18 +00:00
|
|
|
configfile_save(SETTINGS_FILENAME, config,
|
|
|
|
sizeof(config)/sizeof(*config),
|
|
|
|
SETTINGS_VERSION);
|
|
|
|
}
|
2006-03-11 15:44:35 +00:00
|
|
|
} else {
|
2008-08-15 08:27:39 +00:00
|
|
|
rb->splashf(HZ*2, "No ROMs in %s/pacman/", ROCKBOX_DIR);
|
2006-03-11 15:44:35 +00:00
|
|
|
}
|
2009-09-07 21:41:10 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
|
|
|
|
rb->lcd_set_mode(LCD_MODE_RGB565);
|
|
|
|
#endif
|
2006-03-11 15:44:35 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
|
|
|
|
rb->cpu_boost(false);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|