Advertisement
Guest User

modified pacbox.c

a guest
Nov 26th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.85 KB | None | 0 0
  1. /***************************************************************************
  2. * __________ __ ___.
  3. * Open \______ \ ____ ____ | | _\_ |__ _______ ___
  4. * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
  5. * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
  6. * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
  7. * \/ \/ \/ \/ \/
  8. * $Id$
  9. *
  10. * Pacbox - a Pacman Emulator for Rockbox
  11. *
  12. * Based on PIE - Pacman Instructional Emulator
  13. *
  14. * Copyright (c) 1997-2003,2004 Alessandro Scotti
  15. * http://www.ascotti.org/
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License
  19. * as published by the Free Software Foundation; either version 2
  20. * of the License, or (at your option) any later version.
  21. *
  22. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  23. * KIND, either express or implied.
  24. *
  25. ****************************************************************************/
  26.  
  27. #include "plugin.h"
  28. #include "arcade.h"
  29. #include "pacbox.h"
  30. #include "pacbox_lcd.h"
  31. #include "wsg3.h"
  32. #include "lib/configfile.h"
  33. #include "lib/playback_control.h"
  34.  
  35. struct pacman_settings {
  36. int difficulty;
  37. int numlives;
  38. int bonus;
  39. int ghostnames;
  40. int showfps;
  41. int sound;
  42. int ai;
  43. };
  44.  
  45. static struct pacman_settings settings;
  46. static struct pacman_settings old_settings;
  47. static bool sound_playing = false;
  48.  
  49. #define SETTINGS_VERSION 2
  50. #define SETTINGS_MIN_VERSION 2
  51. #define SETTINGS_FILENAME "pacbox.cfg"
  52.  
  53. static char* difficulty_options[] = { "Normal", "Hard" };
  54. static char* numlives_options[] = { "1", "2", "3", "5" };
  55. static char* bonus_options[] = {"10000", "15000", "20000", "No Bonus"};
  56. static char* ghostnames_options[] = {"Normal", "Alternate"};
  57. static char* yesno_options[] = {"No", "Yes"};
  58. static unsigned char ai_direction[19][150] = /* level turn directions */
  59. {
  60. {2,1,3,1,2,0,3,0,3,1,3,1,3,0,3,0,3,0,2,0,2,0,2,1,3,1,2,0,2,1,3,1,3,0,1,3,0,3,1,2,1,3,1,3,0,3,0,2,1} /* (first half of) first level */
  61. };
  62. static unsigned char ai_location[19][150] = /* level turn locations */
  63. {
  64. {0,52,58,57,61,34,60,37,57,41,58,43,61,46,61,49,57,52,54,51,51,42,48,38,52,43,55,39,54,34,55,34,58,37,47,52,41,51,49,52,48,55,52,58,55,57,57,54,54}
  65. };
  66.  
  67. static struct configdata config[] =
  68. {
  69. {TYPE_ENUM, 0, 2, { .int_p = &settings.difficulty }, "Difficulty",
  70. difficulty_options},
  71. {TYPE_ENUM, 0, 4, { .int_p = &settings.numlives }, "Pacmen Per Game",
  72. numlives_options},
  73. {TYPE_ENUM, 0, 4, { .int_p = &settings.bonus }, "Bonus", bonus_options},
  74. {TYPE_ENUM, 0, 2, { .int_p = &settings.ghostnames }, "Ghost Names",
  75. ghostnames_options},
  76. {TYPE_ENUM, 0, 2, { .int_p = &settings.showfps }, "Show FPS",
  77. yesno_options},
  78. {TYPE_ENUM, 0, 2, { .int_p = &settings.sound }, "Sound",
  79. yesno_options},
  80. {TYPE_ENUM, 0, 2, { .int_p = &settings.ai }, "AI",
  81. yesno_options},
  82. };
  83.  
  84. static bool loadFile( const char * name, unsigned char * buf, int len )
  85. {
  86. char filename[MAX_PATH];
  87.  
  88. rb->snprintf(filename,sizeof(filename), ROCKBOX_DIR "/pacman/%s",name);
  89.  
  90. int fd = rb->open( filename, O_RDONLY);
  91.  
  92. if( fd < 0 ) {
  93. return false;
  94. }
  95.  
  96. int n = rb->read( fd, buf, len);
  97.  
  98. rb->close( fd );
  99.  
  100. if( n != len ) {
  101. return false;
  102. }
  103.  
  104. return true;
  105. }
  106.  
  107. static bool loadROMS( void )
  108. {
  109. bool romsLoaded = false;
  110.  
  111. romsLoaded = loadFile( "pacman.6e", ram_, 0x1000) &&
  112. loadFile( "pacman.6f", ram_+0x1000, 0x1000) &&
  113. loadFile( "pacman.6h", ram_+0x2000, 0x1000) &&
  114. loadFile( "pacman.6j", ram_+0x3000, 0x1000) &&
  115. loadFile( "pacman.5e", charset_rom_, 0x1000) &&
  116. loadFile( "pacman.5f", spriteset_rom_, 0x1000);
  117.  
  118. if( romsLoaded ) {
  119. decodeROMs();
  120. reset_PacmanMachine();
  121. }
  122.  
  123. return romsLoaded;
  124. }
  125.  
  126. /* A buffer to render Pacman's 244x288 screen into */
  127. static unsigned char video_buffer[ScreenWidth*ScreenHeight] __attribute__ ((aligned (16)));
  128.  
  129. static long start_time;
  130. static long video_frames = 0;
  131.  
  132. static int dipDifficulty[] = { DipDifficulty_Normal, DipDifficulty_Hard };
  133. static int dipLives[] = { DipLives_1, DipLives_2, DipLives_3, DipLives_5 };
  134. static int dipBonus[] = { DipBonus_10000, DipBonus_15000, DipBonus_20000,
  135. DipBonus_None };
  136. static int dipGhostNames[] = { DipGhostNames_Normal, DipGhostNames_Alternate };
  137.  
  138. static int settings_to_dip(struct pacman_settings settings)
  139. {
  140. return ( DipPlay_OneCoinOneGame |
  141. DipCabinet_Upright |
  142. DipMode_Play |
  143. DipRackAdvance_Off |
  144.  
  145. dipDifficulty[settings.difficulty] |
  146. dipLives[settings.numlives] |
  147. dipBonus[settings.bonus] |
  148. dipGhostNames[settings.ghostnames]
  149. );
  150. }
  151.  
  152. static bool pacbox_menu(void)
  153. {
  154. int selected=0;
  155. int result;
  156. int menu_quit=0;
  157. int new_setting;
  158. bool need_restart = false;
  159.  
  160. static const struct opt_items noyes[2] = {
  161. { "No", -1 },
  162. { "Yes", -1 },
  163. };
  164.  
  165. static const struct opt_items difficulty_options[2] = {
  166. { "Normal", -1 },
  167. { "Harder", -1 },
  168. };
  169.  
  170. static const struct opt_items numlives_options[4] = {
  171. { "1", -1 },
  172. { "2", -1 },
  173. { "3", -1 },
  174. { "5", -1 },
  175. };
  176.  
  177. static const struct opt_items bonus_options[4] = {
  178. { "10000 points", -1 },
  179. { "15000 points", -1 },
  180. { "20000 points", -1 },
  181. { "No bonus", -1 },
  182. };
  183.  
  184. static const struct opt_items ghostname_options[2] = {
  185. { "Normal", -1 },
  186. { "Alternate", -1 },
  187. };
  188.  
  189. enum
  190. {
  191. PBMI_DIFFICULTY = 0,
  192. PBMI_PACMEN_PER_GAME,
  193. PBMI_BONUS_LIFE,
  194. PBMI_GHOST_NAMES,
  195. PBMI_DISPLAY_FPS,
  196. PBMI_SOUND,
  197. PBMI_AI,
  198. PBMI_RESTART,
  199. PBMI_QUIT,
  200. };
  201.  
  202. MENUITEM_STRINGLIST(menu, "Pacbox Menu", NULL,
  203. "Difficulty", "Pacmen Per Game", "Bonus Life",
  204. "Ghost Names", "Display FPS", "Sound", "AI",
  205. "Restart", "Quit");
  206.  
  207. rb->button_clear_queue();
  208.  
  209. #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
  210. rb->lcd_set_mode(LCD_MODE_RGB565);
  211. #endif
  212.  
  213. while (!menu_quit) {
  214. result=rb->do_menu(&menu, &selected, NULL, false);
  215.  
  216. switch(result)
  217. {
  218. case PBMI_DIFFICULTY:
  219. new_setting=settings.difficulty;
  220. rb->set_option("Difficulty", &new_setting, INT,
  221. difficulty_options , 2, NULL);
  222. if (new_setting != settings.difficulty) {
  223. settings.difficulty=new_setting;
  224. need_restart=true;
  225. }
  226. break;
  227. case PBMI_PACMEN_PER_GAME:
  228. new_setting=settings.numlives;
  229. rb->set_option("Pacmen Per Game", &new_setting, INT,
  230. numlives_options , 4, NULL);
  231. if (new_setting != settings.numlives) {
  232. settings.numlives=new_setting;
  233. need_restart=true;
  234. }
  235. break;
  236. case PBMI_BONUS_LIFE:
  237. new_setting=settings.bonus;
  238. rb->set_option("Bonus Life", &new_setting, INT,
  239. bonus_options , 4, NULL);
  240. if (new_setting != settings.bonus) {
  241. settings.bonus=new_setting;
  242. need_restart=true;
  243. }
  244. break;
  245. case PBMI_GHOST_NAMES:
  246. new_setting=settings.ghostnames;
  247. rb->set_option("Ghost Names", &new_setting, INT,
  248. ghostname_options , 2, NULL);
  249. if (new_setting != settings.ghostnames) {
  250. settings.ghostnames=new_setting;
  251. need_restart=true;
  252. }
  253. break;
  254. case PBMI_DISPLAY_FPS:
  255. rb->set_option("Display FPS",&settings.showfps,INT,
  256. noyes, 2, NULL);
  257. break;
  258. case PBMI_SOUND:
  259. rb->set_option("Sound",&settings.sound, INT,
  260. noyes, 2, NULL);
  261. break;
  262. case PBMI_AI:
  263. rb->set_option("AI",&settings.ai, INT,
  264. noyes, 2, NULL);
  265. break;
  266. case PBMI_RESTART:
  267. need_restart=true;
  268. menu_quit=1;
  269. break;
  270. default:
  271. menu_quit=1;
  272. break;
  273. }
  274. }
  275.  
  276. #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
  277. rb->lcd_set_mode(LCD_MODE_PAL256);
  278. #endif
  279.  
  280. if (need_restart) {
  281. init_PacmanMachine(settings_to_dip(settings));
  282. }
  283.  
  284. /* Possible results:
  285. exit game
  286. restart game
  287. usb connected
  288. */
  289. return (result==PBMI_QUIT);
  290. }
  291.  
  292. /* Sound is emulated in ISR context, so not much is done per sound frame */
  293. #define NBSAMPLES 128
  294. static uint32_t sound_buf[NBSAMPLES];
  295. #if CONFIG_CPU == MCF5249
  296. /* Not enough to put this in IRAM */
  297. static int16_t raw_buf[NBSAMPLES];
  298. #else
  299. static int16_t raw_buf[NBSAMPLES] IBSS_ATTR;
  300. #endif
  301.  
  302. /*
  303. Audio callback
  304. */
  305. static void get_more(const void **start, size_t *size)
  306. {
  307. int32_t *out, *outend;
  308. int16_t *raw;
  309.  
  310. /* Emulate the audio for the current register settings */
  311. playSound(raw_buf, NBSAMPLES);
  312.  
  313. out = sound_buf;
  314. outend = out + NBSAMPLES;
  315. raw = raw_buf;
  316.  
  317. /* Convert to stereo */
  318. do
  319. {
  320. uint32_t sample = (uint16_t)*raw++;
  321. *out++ = sample | (sample << 16);
  322. }
  323. while (out < outend);
  324.  
  325. *start = sound_buf;
  326. *size = NBSAMPLES*sizeof(sound_buf[0]);
  327. }
  328.  
  329. /*
  330. Start the sound emulation
  331. */
  332. static void start_sound(void)
  333. {
  334. int sr_index;
  335.  
  336. if (sound_playing)
  337. return;
  338.  
  339. #ifndef PLUGIN_USE_IRAM
  340. /* Ensure control of PCM - stopping music isn't obligatory */
  341. rb->plugin_get_audio_buffer(NULL);
  342. #endif
  343.  
  344. /* Get the closest rate >= to what is preferred */
  345. sr_index = rb->round_value_to_list32(PREFERRED_SAMPLING_RATE,
  346. rb->hw_freq_sampr, HW_NUM_FREQ, false);
  347.  
  348. if (rb->hw_freq_sampr[sr_index] < PREFERRED_SAMPLING_RATE
  349. && sr_index > 0)
  350. {
  351. /* Round up */
  352. sr_index--;
  353. }
  354.  
  355. wsg3_set_sampling_rate(rb->hw_freq_sampr[sr_index]);
  356.  
  357. rb->pcm_set_frequency(rb->hw_freq_sampr[sr_index]);
  358. rb->pcm_play_data(get_more, NULL, NULL, 0);
  359.  
  360. sound_playing = true;
  361. }
  362.  
  363. /*
  364. Stop the sound emulation
  365. */
  366. static void stop_sound(void)
  367. {
  368. if (!sound_playing)
  369. return;
  370.  
  371. rb->pcm_play_stop();
  372. rb->pcm_set_frequency(HW_SAMPR_DEFAULT);
  373.  
  374. sound_playing = false;
  375. }
  376.  
  377. /* invincibility */
  378. void hack(void)
  379. {
  380. ram_[0x1774] = 0x32;
  381. ram_[0x1775] = 0x3C;
  382. ram_[0x1776] = 0xE0;
  383. ram_[0x1777] = 0xC3;
  384. ram_[0x3CDF] = 0x04;
  385. ram_[0x3CEA] = 0x20;
  386. ram_[0x3CE1] = 0xA7;
  387. ram_[0x3CE2] = 0x00;
  388. ram_[0x3CE3] = 0x17;
  389. ram_[0x3CE4] = 0x64;
  390. ram_[0x3CE5] = 0xC3;
  391. ram_[0x3CE6] = 0xAF;
  392. ram_[0x3CE7] = 0x17;
  393. ram_[0x3CE8] = 0x77;
  394. ram_[0x3CE9] = 0xC3;
  395. ram_[0x3CEA] = 0xAF;
  396. }
  397.  
  398. /* blank controls */
  399. void clear_joystick(void)
  400. {
  401. setDeviceMode( Joy1_Left, DeviceOff);
  402. setDeviceMode( Joy1_Right, DeviceOff);
  403. setDeviceMode( Joy1_Up, DeviceOff);
  404. setDeviceMode( Joy1_Down, DeviceOff);
  405.  
  406. }
  407.  
  408. /*
  409. Make turns automatically
  410. */
  411. unsigned char ai( unsigned char turn )
  412. {
  413. int status;
  414. unsigned char position; /* pac-mans current position */
  415. unsigned char levels[255] = {0,1,2, }; /* table of level to map correspondences */
  416. unsigned char level = levels[ram_[0x4E13]-1]; /* current game level */
  417.  
  418.  
  419. /* AI cannot start in middle of a level */
  420. if( turn > 200)
  421. {
  422. rb->splash(HZ/2, "AI will engage at next level start");
  423. return 0;
  424. }
  425. if( turn == 0)
  426. {
  427. if( ram_[0x4E0E] == 0)
  428. {
  429. turn++;
  430. }
  431. }
  432.  
  433.  
  434. if(turn != 0)
  435. {
  436. /* set which axis to look for pac-man along */
  437. position = ram_[0x4D3A];
  438. if( ai_direction[level][turn-1] < 2)
  439. {
  440. position = ram_[0x4D39];
  441. }
  442.  
  443.  
  444.  
  445. /*move joystick if necessary */
  446. if( position == ai_location[level][turn] )
  447. {
  448. switch(ai_direction[level][turn])
  449. {
  450. case 0:
  451. clear_joystick();
  452. setDeviceMode( Joy1_Up, DeviceOn);
  453. break;
  454. case 1:
  455. clear_joystick();
  456. setDeviceMode( Joy1_Down, DeviceOn);
  457. break;
  458. case 2:
  459. clear_joystick();
  460. setDeviceMode( Joy1_Right, DeviceOn);
  461. break;
  462. case 3:
  463. clear_joystick();
  464. setDeviceMode( Joy1_Left, DeviceOn);
  465. break;
  466. }
  467. turn++;
  468. }
  469. }
  470.  
  471. /* reset turn counter on level end */
  472. if(ram_[0x4E0E] == 254)
  473. {
  474. return 1;
  475. }
  476.  
  477.  
  478. /* Check the button status */
  479. status = rb->button_status();
  480. /*handle buttons if AI is off */
  481. if(!turn || (turn == 1))
  482. {
  483. #ifdef PACMAN_HAS_REMOTE
  484. setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
  485. setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
  486. setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
  487. setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
  488. setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
  489. setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
  490. setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
  491. #else
  492. setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
  493. setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
  494. setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
  495. setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
  496. setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
  497. setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
  498. #ifdef PACMAN_2UP
  499. setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
  500. #endif
  501. #endif
  502. }//else
  503. //hack();
  504.  
  505. //rb->debugf("x = %d \n",ram_[0x4D3A]);
  506. //rb->debugf("y = %d \n",ram_[0x4D39]);
  507. return turn;
  508. }
  509.  
  510. /*
  511. Runs the game engine for one frame.
  512. */
  513. static int gameProc( void )
  514. {
  515. int fps;
  516. int status;
  517. long end_time;
  518. int frame_counter = 0;
  519. int yield_counter = 0;
  520. unsigned char turn = 250;
  521.  
  522. if (settings.sound)
  523. start_sound();
  524.  
  525. while (1)
  526. {
  527. /* Run the machine for one frame (1/60th second) */
  528. run();
  529.  
  530.  
  531.  
  532. frame_counter++;
  533.  
  534. /* Check the button status */
  535. status = rb->button_status();
  536.  
  537. #ifdef HAS_BUTTON_HOLD
  538. if (rb->button_hold())
  539. status = PACMAN_MENU;
  540. #endif
  541.  
  542. if ((status & PACMAN_MENU) == PACMAN_MENU
  543. #ifdef PACMAN_RC_MENU
  544. || status == PACMAN_RC_MENU
  545. #endif
  546. ) {
  547. bool menu_res;
  548.  
  549. end_time = *rb->current_tick;
  550.  
  551. stop_sound();
  552.  
  553. menu_res = pacbox_menu();
  554.  
  555. rb->lcd_clear_display();
  556. #ifdef HAVE_REMOTE_LCD
  557. rb->lcd_remote_clear_display();
  558. rb->lcd_remote_update();
  559. #endif
  560. if (menu_res)
  561. return 1;
  562.  
  563. if (settings.sound)
  564. start_sound();
  565.  
  566. start_time += *rb->current_tick-end_time;
  567. }
  568.  
  569. if(!settings.ai)
  570. {
  571. #ifdef PACMAN_HAS_REMOTE
  572. setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
  573. setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
  574. setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
  575. setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
  576. setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
  577. setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
  578. setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
  579. #else
  580. setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
  581. setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
  582. setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
  583. setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
  584. setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
  585. setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
  586. #ifdef PACMAN_2UP
  587. setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
  588. #endif
  589. #endif
  590. }
  591. /* run ai */
  592. if (settings.ai)
  593. turn = ai(turn);
  594. /* We only update the screen every third frame - Pacman's native
  595. framerate is 60fps, so we are attempting to display 20fps */
  596. if (frame_counter == 60 / FPS) {
  597.  
  598. frame_counter = 0;
  599. video_frames++;
  600.  
  601. yield_counter ++;
  602.  
  603. if (yield_counter == FPS) {
  604. yield_counter = 0;
  605. rb->yield ();
  606. }
  607.  
  608. /* The following functions render the Pacman screen from the
  609. contents of the video and color ram. We first update the
  610. background, and then draw the Sprites on top.
  611. */
  612.  
  613. renderBackground( video_buffer );
  614. renderSprites( video_buffer );
  615.  
  616. #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
  617. rb->lcd_blit_pal256( video_buffer, 0, 0, XOFS, YOFS,
  618. ScreenWidth, ScreenHeight);
  619. #else
  620. blit_display(rb->lcd_framebuffer,video_buffer);
  621. #endif
  622.  
  623. if (settings.showfps) {
  624. fps = (video_frames*HZ*100) / (*rb->current_tick-start_time);
  625. rb->lcd_putsxyf(0,0,"%d.%02d / %d fps ",fps/100,fps%100,FPS);
  626. }
  627.  
  628. #if !defined(HAVE_LCD_MODES) || \
  629. defined(HAVE_LCD_MODES) && !(HAVE_LCD_MODES & LCD_MODE_PAL256)
  630. rb->lcd_update();
  631. #endif
  632.  
  633. /* Keep the framerate at Pacman's 60fps */
  634. end_time = start_time + (video_frames*HZ)/FPS;
  635. while (TIME_BEFORE(*rb->current_tick,end_time)) {
  636. rb->sleep(1);
  637. }
  638. }
  639. }
  640.  
  641. stop_sound();
  642.  
  643. return 0;
  644. }
  645.  
  646. enum plugin_status plugin_start(const void* parameter)
  647. {
  648. (void)parameter;
  649.  
  650. #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  651. rb->cpu_boost(true);
  652. #endif
  653. rb->lcd_set_backdrop(NULL);
  654. rb->lcd_set_foreground(LCD_WHITE);
  655. rb->lcd_set_background(LCD_BLACK);
  656. rb->lcd_clear_display();
  657. rb->lcd_update();
  658.  
  659. /* Set the default settings */
  660. settings.difficulty = 0; /* Normal */
  661. settings.numlives = 2; /* 3 lives */
  662. settings.bonus = 0; /* 10000 points */
  663. settings.ghostnames = 0; /* Normal names */
  664. settings.showfps = 0; /* Do not show FPS */
  665. settings.sound = 0; /* Sound off by default */
  666. settings.ai = 0; /* AI off by default */
  667.  
  668. if (configfile_load(SETTINGS_FILENAME, config,
  669. sizeof(config)/sizeof(*config),
  670. SETTINGS_MIN_VERSION
  671. ) < 0)
  672. {
  673. /* If the loading failed, save a new config file (as the disk is
  674. already spinning) */
  675. configfile_save(SETTINGS_FILENAME, config,
  676. sizeof(config)/sizeof(*config),
  677. SETTINGS_VERSION);
  678. }
  679.  
  680. /* Keep a copy of the saved version of the settings - so we can check if
  681. the settings have changed when we quit */
  682. old_settings = settings;
  683.  
  684. /* Initialise the hardware */
  685. init_PacmanMachine(settings_to_dip(settings));
  686.  
  687. #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
  688. rb->lcd_set_mode(LCD_MODE_PAL256);
  689. #endif
  690.  
  691. /* Load the romset */
  692. if (loadROMS()) {
  693. start_time = *rb->current_tick-1;
  694.  
  695. gameProc();
  696.  
  697. /* Save the user settings if they have changed */
  698. if (rb->memcmp(&settings,&old_settings,sizeof(settings))!=0) {
  699. rb->splash(0, "Saving settings...");
  700. configfile_save(SETTINGS_FILENAME, config,
  701. sizeof(config)/sizeof(*config),
  702. SETTINGS_VERSION);
  703. }
  704. } else {
  705. rb->splashf(HZ*2, "No ROMs in %s/pacman/", ROCKBOX_DIR);
  706. }
  707.  
  708. #if defined(HAVE_LCD_MODES) && (HAVE_LCD_MODES & LCD_MODE_PAL256)
  709. rb->lcd_set_mode(LCD_MODE_RGB565);
  710. #endif
  711.  
  712. #ifdef HAVE_ADJUSTABLE_CPU_FREQ
  713. rb->cpu_boost(false);
  714. #endif
  715.  
  716. return PLUGIN_OK;
  717. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement