summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoshe Piekarski <mendelmunkis@protonmail.com>2018-04-01 23:34:15 -0500
committerFranklin Wei <franklin@rockbox.org>2019-07-28 20:25:16 -0400
commitb3295f0ed6de06acad47a580b4edf6ccef8564a7 (patch)
treef5f6144c7ff51ef70665df3f76e8be490661d9cb
parent183e45e8d0b4425bbd41fab37f2a4dc143e1e27c (diff)
downloadrockbox-b3295f0ed6de06acad47a580b4edf6ccef8564a7.tar.gz
rockbox-b3295f0ed6de06acad47a580b4edf6ccef8564a7.zip
Pacbox AI
Pacman can make moves by itself Change-Id: I7a39fed1e2bf5dbfb07e4d801d080a6e097730e9
-rwxr-xr-x[-rw-r--r--]apps/plugins/pacbox/pacbox.c318
-rw-r--r--apps/plugins/pacbox/pacbox.h2
2 files changed, 297 insertions, 23 deletions
diff --git a/apps/plugins/pacbox/pacbox.c b/apps/plugins/pacbox/pacbox.c
index efba47b576..b902103676 100644..100755
--- a/apps/plugins/pacbox/pacbox.c
+++ b/apps/plugins/pacbox/pacbox.c
@@ -13,6 +13,9 @@
13 * 13 *
14 * Copyright (c) 1997-2003,2004 Alessandro Scotti 14 * Copyright (c) 1997-2003,2004 Alessandro Scotti
15 * http://www.ascotti.org/ 15 * http://www.ascotti.org/
16 * AI code (c) 2017 Moshe Piekarski
17 *
18 * ToDo convert all score to pinky location
16 * 19 *
17 * This program is free software; you can redistribute it and/or 20 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License 21 * modify it under the terms of the GNU General Public License
@@ -31,6 +34,10 @@
31#include "wsg3.h" 34#include "wsg3.h"
32#include "lib/configfile.h" 35#include "lib/configfile.h"
33#include "lib/playback_control.h" 36#include "lib/playback_control.h"
37#include "lib/helper.h"
38
39/*Allows split screen jump and makes pacman invincible if you start at 18 credits (for testing purposes)*/
40//#define CHEATS 1
34 41
35struct pacman_settings { 42struct pacman_settings {
36 int difficulty; 43 int difficulty;
@@ -39,14 +46,15 @@ struct pacman_settings {
39 int ghostnames; 46 int ghostnames;
40 int showfps; 47 int showfps;
41 int sound; 48 int sound;
49 int ai;
42}; 50};
43 51
44static struct pacman_settings settings; 52static struct pacman_settings settings;
45static struct pacman_settings old_settings; 53static struct pacman_settings old_settings;
46static bool sound_playing = false; 54static bool sound_playing = false;
47 55
48#define SETTINGS_VERSION 1 56#define SETTINGS_VERSION 2
49#define SETTINGS_MIN_VERSION 1 57#define SETTINGS_MIN_VERSION 2
50#define SETTINGS_FILENAME "pacbox.cfg" 58#define SETTINGS_FILENAME "pacbox.cfg"
51 59
52static char* difficulty_options[] = { "Normal", "Hard" }; 60static char* difficulty_options[] = { "Normal", "Hard" };
@@ -55,6 +63,45 @@ static char* bonus_options[] = {"10000", "15000", "20000", "No Bonus"};
55static char* ghostnames_options[] = {"Normal", "Alternate"}; 63static char* ghostnames_options[] = {"Normal", "Alternate"};
56static char* yesno_options[] = {"No", "Yes"}; 64static char* yesno_options[] = {"No", "Yes"};
57 65
66#ifdef AI
67static unsigned char ai_direction[15][205] = /* level turn directions */
68{
69 {2,1,3,1,2,0,3,0,3,1,2,1,3,1,3,0,3,0,2,0,3,0,2,1,3,1,2,0,2,1,3,1,3,0,3,1,3,1,2,0,3,0,3,0,3,0,2,0,3,1,2,0,2,0,3,1,2,1,2,1,2,0,2,0,2,0,3,1,3,1,2,1,2,1,3,0,2,0,2,0,2,1,2,0,3,0,2,1,3,0,3,2,1,3,0,3,1,2,1,2,0,2,3,1,3,0,3,0,2,4}, /* first level */
70 {2,0,3,1,3,1,2,0,2,0,2,0,3,1,3,1,2,1,2,0,3,0,3,0,3,1,3,1,2,1,2,0,2,0,3,0,2,0,3,1,2,0,3,1,2,0,2,1,2,1,2,0,2,0,3,1,0,3,0,3,2,0,2,0,2,0,3,1,0,3,2,0,2,1,2,1,3,0,3,1,3,1,3,0,3,0,1,2,1,3,1,3,1,2},/* second level*/
71 {2,1,3,1,2,0,2,0,3,0,2,1,3,1,2,1,2,0,3,0,3,0,3,1,3,1,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3,1,3,0,3,0,3,0,2,1,3,1,3,0,3,0,2,0,2,1,2,1,3,1,2,1,2,0,2,0,3,0,2,0,3,0,3,1,2,0,2,1,3,1,3,1,3,0,3,0,2,1,3,1,2,1,2,0,2,0,3,0,3,1,2,1,3,0},
83 {2,1,3,1,2,0,3,0,2,0,3,1,2,0,3,1,2,1,2,0,2,0,2,0,3,0,3,0,2,1,3,0,2,1,3,1,2,1,2,1,2,0,2,1,2,1,2,1,3,0,1,3,0,1,2,1,2,1,2,0,3,1,2}
84};
85static unsigned char ai_location[15][205] = /* level turn locations */
86{
87 {0,52,58,57,61,34,60,37,54,43,55,42,58,43,61,46,60,49,57,48,54,49,51,42,52,43,55,39,54,34,55,34,58,37,107,52,58,57,61,48,60,49,57,52,42,57,39,48,35,57,40,54,39,48,35,52,37,51,40,48,43,45,42,42,39,39,35,43,37,49,40,48,43,42,49,49,45,45,42,42,39,39,40,34,39,43,35,34,40,37,39,223,39,55,52,54,57,55,57,58,54,57,119,52,58,55,57,57,54,53}, /* first level */
88 {0,47,54,52,58,57,61,45,60,42,57,39,54,43,55,49,58,48,61,34,60,37,54,40,51,49,52,57,55,57,58,54,54,51,48,52,39,48,35,57,40,54,39,57,40,54,35,48,37,40,56,37,57,33,54,37,125,54,40,51,170,42,48,39,39,34,35,37,174,39,220,45,35,39,37,34,40,37,39,40,40,43,43,46,42,49,16,40,48,42,48,45,52,55}, /*second level */
89 {0,52,58,57,61,45,60,42,57,43,54,39,55,49,58,48,61,34,60,37,54,40,51,49,52,57,55,57,58,54,54,51,51,139,49,48,52,42,57,39,48,35,57,40,54,39,48,35,52,37,51,40,48,43,49,46,52,55,39,54,34,55,34,58,37,57,43,54,42,51,49,52,48,55,39,35,43,37,49,40,48,43,45,42,42,39,39,35,43,37,39,35,34,37,43,127,37,39,40,34}, /*third level */
90 {0,52,58,57,61,45,60,42,57,43,54,39,55,49,58,48,61,34,60,37,54,40,51,49,52,57,55,57,58,54,54,51,51,71,49,48,52,42,57,39,48,35,57,40,54,39,48,35,52,37,51,40,48,43,49,46,52,55,45,54,39,48,40,49,49,52,48,55,45,54,42,45,43,42,42,39,43,35,39,37,34,40,37,39,43,35,34,151,35,37,37,49,40,48,43,42,52,43,55,46,54,49,51,42,48,39,52,34,55,34,58,37,54,43,55,87,45,54,42,48,39,88}, /*fourth level */
91 {0,14,39,58,34,61,46,60,49,57,45,54,42,45,43,42,42,39,39,35,43,37,42,40,43,43,42,49,49,52,48,55,42,58,43,61,57,60,54,54,57,55,57,58,54,57,48,54,52,39,48,35,52,37,57,35,54,46,51,49,42,48,39,42,34,39,37,35,43,37,49,40,48,43,49,46,52,42,57,39,39,35,34,37,40,105,43,35,39,40,34,39,40,40,43,43,49,52,48,55,45,54,39,58,36,57,34,54,37,55,43,54,39,51}, /*fifth level */
92 {0,184,39,58,34,61,46,60,49,57,45,54,42,45,43,42,42,39,39,35,43,37,42,40,43,43,42,49,49,52,48,55,42,58,43,61,57,60,54,54,57,55,57,58,54,57,48,54,52,39,48,35,52,37,57,35,54,46,51,49,42,45,43,42,42,39,52,40,57,39,51,40,48,43,45,42,42,39,43,35,39,40,34,39,37,35,34,37,37,35,34,200,37,46,40,45,49,49,42,52,39,58,36,57,34,54,37,55,52,119,54,48,37,},/*sixth level*/
93 {0,52,58,57,61,45,60,42,57,43,54,42,51,49,48,52,55,45,54,42,48,39,52,40,45,49,52,52,48,51,49,42,45,49,52,52,55,42,58,43,61,57,60,54,54,57,55,57,58,57,61,48,60,49,57,48,54,52,55,48,54,52,55,51,58,48,61,45,60,42,57,39,48,40,45,49,46,40,49,49,48,52,52,48,55,52,58,57,61,48,60,49,57,42,58,43,61,34,60,37,54,34,55,34,58,118,34,61,43,60,42,57,39,48,54,52,57,55,57,58,57,61,48,60,49,57,39,48,40,52,43,55,39,42,34,39,37,40,34,39,37,35,34,37,37,35,43,37,42,40,43,43,42,46,51,49,42,48,39,55,52,48,51,49,42,52,39,48,54,52,51,51,42,52,39,48,54,42,57,39,54,35,57,37,141,35,48,37,49,40,48,43,49,46,52,39},/*ninth level*/
94 {0,14,39,58,34,61,46,60,49,57,45,54,42,45,43,42,42,39,39,35,43,37,42,40,43,43,42,49,49,52,48,55,42,58,43,61,57,60,54,54,57,55,57,58,54,57,48,54,52,39,48,35,52,37,57,35,54,46,51,49,42,45,43,42,42,39,57,40,54,39,51,40,48,43,42,46,39,42,34,39,37,35,34,40,37,39,43,205,37,42,40,43,43,42,73,45,43,42,42,39,39,58,36,57,34,54,37,55,52,48,51,49,42,52,45,60,},/*tenth level*/
95 {0,52,58,57,61,45,60,42,57,43,54,42,51,49,48,52,55,45,54,42,48,39,52,40,45,49,52,52,48,51,49,42,45,49,52,52,55,42,58,43,61,57,60,54,54,57,55,57,58,57,61,48,60,49,57,48,54,52,55,48,54,52,55,51,58,48,61,45,60,42,57,39,48,40,45,49,46,40,49,49,48,52,52,48,55,52,58,57,61,48,60,49,57,42,58,43,61,34,60,37,54,34,55,34,58,94,34,61,43,60,42,57,39,48,54,52,57,55,57,58,57,61,48,60,49,57,39,48,40,52,43,55,39,42,34,39,37,40,34,39,37,35,34,37,37,191,46,40,45,49,46,52,39,42,40,43,43,49,49,42,52,39,55,52,48,51,49,42,52,39,48,54,39,48,35,57,37,51,40,48,43,45,42,42,39,39,35,43,37,57,40,54,35},/*twelfth level*/
96 {0,14,39,58,34,61,46,60,49,57,45,54,42,45,43,42,42,39,39,35,43,37,42,40,43,43,42,49,49,52,48,55,42,58,43,61,57,60,54,54,57,55,57,58,54,57,48,54,52,39,48,35,52,37,48,35,57,37,54,35,104,52,37,51,40,48,43,49,49,42,48,39,42,34,39,57,40,54,46,51,49,42,48,39,52,34,55,34,58,37,54,40,51,49,48,52,39,42,40,43,43,49,52,52,48,37,42,34,39,37,35,34,37,37,35,43,37,127,39},/*fourteenth level*/
97 {0,52,58,57,61,45,60,42,57,43,54,42,51,49,48,52,55,45,54,42,48,39,52,40,45,45,52,52,48,51,49,42,45,49,52,52,55,42,58,43,61,57,60,54,54,57,55,57,58,57,61,48,60,49,57,48,54,52,55,48,54,52,55,51,58,48,61,45,60,42,57,39,48,40,45,49,46,40,49,49,48,52,52,48,55,52,58,57,61,48,60,49,57,42,58,43,61,34,60,37,54,34,55,34,58,124,34,61,43,60,42,57,39,48,54,52,57,55,57,58,57,61,48,60,49,57,39,48,40,52,43,55,39,54,40,45,49,49,42,52,43,55,52,54,51,48,37,41,34,39,37,35,34,37,37,46,40,45,46,42,49,39,42,40,43,43,42,49,49,48,52,55,39,54,40,48,54,39,48,35,57,159,173,37,54,40,57,39,54,35,48,37,45,35,39,37,40},
98 {0,14,39,58,34,61,46,60,49,57,48,54,52,48,51,45,48,42,49,39,42,40,43,43,42,49,49,52,52,58,57,61,45,60,42,57,39,39,52,55,45,54,39,42,34,39,37,35,43,37,46,35,52,46,51,49,42,48,54,42,57,35,54,37,57,40,54,39,45,35,34,40,37,52,34,55,34,58,34,61,57,60,57,57,57,53},
99 {0,14,39,58,34,61,46,60,49,57,48,54,52,48,51,45,48,42,49,39,42,40,43,43,42,49,49,52,52,58,57,61,45,60,42,57,39,39,52,55,45,54,39,42,34,39,37,35,43,37,49,40,48,43,49,49,42,52,34,55,34,58,37,42,34,35,43,37,57,35,54,37,57,40,54,35,48,37,49,40,48,43,49,46,52,52,57,55,57},
100 {0,52,58,57,61,34,60,37,54,43,55,42,58,43,61,46,60,49,57,52,54,48,55,52,58,55,57,57,54,54,48,51,49,42,52,43,55,39,58,36,57,34,54,37,42,34,39,37,35,43,37,39,35,34,37,37,46,40,49,49,48,52,35,48,37,49,40,48,43,45,42,42,39,52,35,57,37,54,40,57},
101 {0,52,58,57,61,48,60,49,57,48,54,52,55,48,54,57,55,57,58,54,48,51,45,48,42,49,39,52,35,48,37,52,34,48,37,52,46,51,49,45,37,39,33,38,35,35,49,34,60,37,53,60,42,55,60,38,35,58,40,54,35,57,37}
102};
103#endif
104
58static struct configdata config[] = 105static struct configdata config[] =
59{ 106{
60 {TYPE_ENUM, 0, 2, { .int_p = &settings.difficulty }, "Difficulty", 107 {TYPE_ENUM, 0, 2, { .int_p = &settings.difficulty }, "Difficulty",
@@ -68,6 +115,10 @@ static struct configdata config[] =
68 yesno_options}, 115 yesno_options},
69 {TYPE_ENUM, 0, 2, { .int_p = &settings.sound }, "Sound", 116 {TYPE_ENUM, 0, 2, { .int_p = &settings.sound }, "Sound",
70 yesno_options}, 117 yesno_options},
118#ifdef AI
119 {TYPE_ENUM, 0, 2, { .int_p = &settings.ai }, "AI",
120 yesno_options},
121#endif
71}; 122};
72 123
73static bool loadFile( const char * name, unsigned char * buf, int len ) 124static bool loadFile( const char * name, unsigned char * buf, int len )
@@ -183,6 +234,9 @@ static bool pacbox_menu(void)
183 PBMI_GHOST_NAMES, 234 PBMI_GHOST_NAMES,
184 PBMI_DISPLAY_FPS, 235 PBMI_DISPLAY_FPS,
185 PBMI_SOUND, 236 PBMI_SOUND,
237#ifdef AI
238 PBMI_AI,
239#endif
186 PBMI_RESTART, 240 PBMI_RESTART,
187 PBMI_QUIT, 241 PBMI_QUIT,
188 }; 242 };
@@ -190,6 +244,9 @@ static bool pacbox_menu(void)
190 MENUITEM_STRINGLIST(menu, "Pacbox Menu", NULL, 244 MENUITEM_STRINGLIST(menu, "Pacbox Menu", NULL,
191 "Difficulty", "Pacmen Per Game", "Bonus Life", 245 "Difficulty", "Pacmen Per Game", "Bonus Life",
192 "Ghost Names", "Display FPS", "Sound", 246 "Ghost Names", "Display FPS", "Sound",
247#ifdef AI
248 "AI",
249#endif
193 "Restart", "Quit"); 250 "Restart", "Quit");
194 251
195 rb->button_clear_queue(); 252 rb->button_clear_queue();
@@ -247,6 +304,12 @@ static bool pacbox_menu(void)
247 rb->set_option("Sound",&settings.sound, INT, 304 rb->set_option("Sound",&settings.sound, INT,
248 noyes, 2, NULL); 305 noyes, 2, NULL);
249 break; 306 break;
307#ifdef AI
308 case PBMI_AI:
309 rb->set_option("AI",&settings.ai, INT,
310 noyes, 2, NULL);
311 break;
312#endif
250 case PBMI_RESTART: 313 case PBMI_RESTART:
251 need_restart=true; 314 need_restart=true;
252 menu_quit=1; 315 menu_quit=1;
@@ -321,7 +384,7 @@ static void start_sound(void)
321 return; 384 return;
322 385
323#ifndef PLUGIN_USE_IRAM 386#ifndef PLUGIN_USE_IRAM
324 /* Ensure control of PCM - stopping music isn't obligatory */ 387 /* Ensure control of PCM - stopping music itn't obligatory */
325 rb->plugin_get_audio_buffer(NULL); 388 rb->plugin_get_audio_buffer(NULL);
326#endif 389#endif
327 390
@@ -358,6 +421,207 @@ static void stop_sound(void)
358 sound_playing = false; 421 sound_playing = false;
359} 422}
360 423
424/* use buttons for joystick */
425void joystick(void)
426{
427 int status;
428 /* Check the button status */
429 status = rb->button_status();
430 rb->button_clear_queue();
431 /*handle buttons if AI is off */
432#ifdef PACMAN_HAS_REMOTE
433 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff);
434 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff);
435 setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff);
436 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff);
437 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff);
438 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff);
439 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff);
440#else
441 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff);
442 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
443 setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
444 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
445 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
446 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
447#ifdef PACMAN_2UP
448 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
449#endif
450#endif
451#ifdef CHEATS
452// skip level for testing purposes
453 if(status == SKIP_LEVEL)
454 {
455//dots
456 ram_[0x4E0E] = 242;
457//level
458 ram_[0x4E13] = 254;
459 }
460#endif
461}
462#ifdef AI
463/* blank controls */
464void clear_joystick(void)
465{
466 setDeviceMode( Joy1_Left, DeviceOff);
467 setDeviceMode( Joy1_Right, DeviceOff);
468 setDeviceMode( Joy1_Up, DeviceOff);
469 setDeviceMode( Joy1_Down, DeviceOff);
470
471}
472
473/* Make turns */
474void ai_turn( unsigned char level, unsigned char turn)
475{
476 switch(ai_direction[level][turn])
477 {
478 case 0:
479 clear_joystick();
480 setDeviceMode( Joy1_Up, DeviceOn);
481 break;
482 case 1:
483 clear_joystick();
484 setDeviceMode( Joy1_Down, DeviceOn);
485 break;
486 case 2:
487 clear_joystick();
488 setDeviceMode( Joy1_Right, DeviceOn);
489 break;
490 case 3:
491 clear_joystick();
492 setDeviceMode( Joy1_Left, DeviceOn);
493 break;
494 case 4:
495 clear_joystick();
496 break;
497 }
498}
499/*
500 Decide turns automatically
501*/
502unsigned char ai( unsigned char turn )
503{
504 unsigned char position; /* pac-mans current position */
505 unsigned char score = ram_[0x4E81]; /* current score */
506 unsigned char level; /* current game level */
507 unsigned char map[20] = {0,1,2,3,4,5,4,4,6,7,4,8,8,9,10,10,11,10,12,12};
508
509 /*Select level map*/
510 if(ram_[0x4E13] < 20)
511 {
512 level=map[ram_[0x4E13]];
513 }else if(ram_[0x4E13] != 255)
514 level=13;
515 else
516 level=14;
517
518 if((level == 4) || (level == 8) || (level == 10))
519 {
520 switch(ram_[0x4E13])
521 {
522 case 4:
523 ai_location[4][85] = 105;
524 break;
525 case 6:
526 ai_location[4][85] = 143;
527 break;
528 case 7:
529 ai_location[4][85] = 91;
530 break;
531 case 10:
532 ai_location[4][85] = 217;
533 break;
534 case 11:
535 ai_location[8][105] = 94;
536 ai_location[8][145] = 191;
537 break;
538 case 12:
539 ai_location[8][105] = 138;
540 ai_location[8][145] = 75;
541 break;
542 case 14:
543 ai_location[10][105] = 124;
544 ai_location[10][181] = 159;
545 ai_location[10][182] = 173;
546 break;
547 case 15:
548 ai_location[10][105] = 200;
549 ai_location[10][181] = 75;
550 ai_location[10][182] = 89;
551 break;
552 case 17:
553 ai_location[10][105] = 154;
554 ai_location[10][181] = 189;
555 ai_location[10][182] = 203;
556 default:
557 break;
558 }
559 }
560
561 /* AI can't start in middle of a level */
562 if( turn > 200)
563 {
564 rb->splash(HZ/2, "AI will engage at next level start");
565 return 0;
566 }
567 if( turn == 0)
568 {
569 if( (ram_[0x4E0E] == 1) && (ram_[0x4D3A] == 47))
570 {
571 turn++;
572 }
573 joystick();
574 return turn;
575 }
576
577
578 if(turn != 0)
579 {
580 /* set which axis to look for pac-man along */
581 position = ram_[0x4D3A];
582 if( ai_direction[level][turn-1] < 2)
583 {
584 position = ram_[0x4D39];
585 }
586
587
588 /*move joystick if necessary */
589 if(ai_location[level][turn] < 70)
590 {
591 if(ai_location[level][turn] < 30) /* handle turns using pinky's location as basis for turn timing */
592 {
593 if( ram_[0x4D31] == (ai_location[level][turn] + 30))
594 {
595 ai_turn(level,turn);
596 turn++;
597 }
598 }else if( position == ai_location[level][turn] ) /* handle turns using pacman's location as basis for turn timing */
599 {
600 ai_turn(level,turn);
601 turn++;
602 }
603 }else /* handle turns on eating ghost after center of tile using score as basis for turn timing */
604 {
605 if( score == (ai_location[level][turn]-70))
606 {
607 ai_turn(level,turn);
608 turn++;
609 }
610 }
611 }
612
613 /* reset turn counter and joystick direction on level start */
614 if(ram_[0x4E0E] == 0 )
615 {
616 /*levels that start facing right */
617 if((level != 4) && (level != 11) && (level != 7) && (level != 5) && (level != 9) && (level !=12))
618 clear_joystick();
619 return 1;
620 }
621 return turn;
622}
623#endif
624
361/* 625/*
362 Runs the game engine for one frame. 626 Runs the game engine for one frame.
363*/ 627*/
@@ -368,6 +632,7 @@ static int gameProc( void )
368 long end_time; 632 long end_time;
369 int frame_counter = 0; 633 int frame_counter = 0;
370 int yield_counter = 0; 634 int yield_counter = 0;
635 unsigned char turn = 250;
371 636
372 if (settings.sound) 637 if (settings.sound)
373 start_sound(); 638 start_sound();
@@ -377,10 +642,19 @@ static int gameProc( void )
377 /* Run the machine for one frame (1/60th second) */ 642 /* Run the machine for one frame (1/60th second) */
378 run(); 643 run();
379 644
645/*Make Pac-man invincible*/
646#ifdef CHEATS
647 if(ram_[0x4E6E]== 23)
648 ram_[0x4DA5]=00;
649#endif
650
651
652
380 frame_counter++; 653 frame_counter++;
381 654
382 /* Check the button status */ 655 /* Check the button status */
383 status = rb->button_status(); 656 status = rb->button_status();
657 rb->button_clear_queue();
384 658
385#ifdef HAS_BUTTON_HOLD 659#ifdef HAS_BUTTON_HOLD
386 if (rb->button_hold()) 660 if (rb->button_hold())
@@ -413,27 +687,18 @@ static int gameProc( void )
413 687
414 start_time += *rb->current_tick-end_time; 688 start_time += *rb->current_tick-end_time;
415 } 689 }
416 690#ifdef AI
417#ifdef PACMAN_HAS_REMOTE 691 if(!settings.ai)
418 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT || status == PACMAN_RC_LEFT) ? DeviceOn : DeviceOff); 692 {
419 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT || status == PACMAN_RC_RIGHT) ? DeviceOn : DeviceOff); 693 joystick();
420 setDeviceMode( Joy1_Up, (status & PACMAN_UP || status == PACMAN_RC_UP) ? DeviceOn : DeviceOff); 694 turn = 250;
421 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN || status == PACMAN_RC_DOWN) ? DeviceOn : DeviceOff); 695 }
422 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN || status == PACMAN_RC_COIN) ? DeviceOn : DeviceOff); 696 /* run ai */
423 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP || status == PACMAN_RC_1UP) ? DeviceOn : DeviceOff); 697 if (settings.ai)
424 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP || status == PACMAN_RC_2UP) ? DeviceOn : DeviceOff); 698 turn = ai(turn);
425#else 699#else
426 setDeviceMode( Joy1_Left, (status & PACMAN_LEFT) ? DeviceOn : DeviceOff); 700 joystick();
427 setDeviceMode( Joy1_Right, (status & PACMAN_RIGHT) ? DeviceOn : DeviceOff);
428 setDeviceMode( Joy1_Up, (status & PACMAN_UP) ? DeviceOn : DeviceOff);
429 setDeviceMode( Joy1_Down, (status & PACMAN_DOWN) ? DeviceOn : DeviceOff);
430 setDeviceMode( CoinSlot_1, (status & PACMAN_COIN) ? DeviceOn : DeviceOff);
431 setDeviceMode( Key_OnePlayer, (status & PACMAN_1UP) ? DeviceOn : DeviceOff);
432#ifdef PACMAN_2UP
433 setDeviceMode( Key_TwoPlayers, (status & PACMAN_2UP) ? DeviceOn : DeviceOff);
434#endif 701#endif
435#endif
436
437 /* We only update the screen every third frame - Pacman's native 702 /* We only update the screen every third frame - Pacman's native
438 framerate is 60fps, so we are attempting to display 20fps */ 703 framerate is 60fps, so we are attempting to display 20fps */
439 if (frame_counter == 60 / FPS) { 704 if (frame_counter == 60 / FPS) {
@@ -506,6 +771,7 @@ enum plugin_status plugin_start(const void* parameter)
506 settings.ghostnames = 0; /* Normal names */ 771 settings.ghostnames = 0; /* Normal names */
507 settings.showfps = 0; /* Do not show FPS */ 772 settings.showfps = 0; /* Do not show FPS */
508 settings.sound = 0; /* Sound off by default */ 773 settings.sound = 0; /* Sound off by default */
774 settings.ai = 0; /* AI off by default */
509 775
510 if (configfile_load(SETTINGS_FILENAME, config, 776 if (configfile_load(SETTINGS_FILENAME, config,
511 sizeof(config)/sizeof(*config), 777 sizeof(config)/sizeof(*config),
@@ -523,6 +789,10 @@ enum plugin_status plugin_start(const void* parameter)
523 the settings have changed when we quit */ 789 the settings have changed when we quit */
524 old_settings = settings; 790 old_settings = settings;
525 791
792 /*Turn off backlight for ai*/
793 if(settings.ai)
794 backlight_ignore_timeout();
795
526 /* Initialise the hardware */ 796 /* Initialise the hardware */
527 init_PacmanMachine(settings_to_dip(settings)); 797 init_PacmanMachine(settings_to_dip(settings));
528 798
@@ -555,5 +825,7 @@ enum plugin_status plugin_start(const void* parameter)
555 rb->cpu_boost(false); 825 rb->cpu_boost(false);
556#endif 826#endif
557 827
828 backlight_use_settings();
829
558 return PLUGIN_OK; 830 return PLUGIN_OK;
559} 831}//
diff --git a/apps/plugins/pacbox/pacbox.h b/apps/plugins/pacbox/pacbox.h
index 1310e90b93..a93beca67a 100644
--- a/apps/plugins/pacbox/pacbox.h
+++ b/apps/plugins/pacbox/pacbox.h
@@ -285,6 +285,8 @@
285#define PACMAN_2UP BUTTON_BOTTOMRIGHT 285#define PACMAN_2UP BUTTON_BOTTOMRIGHT
286#define PACMAN_COIN BUTTON_PLAYPAUSE 286#define PACMAN_COIN BUTTON_PLAYPAUSE
287#define PACMAN_MENU BUTTON_POWER 287#define PACMAN_MENU BUTTON_POWER
288#define SKIP_LEVEL BUTTON_VOL_DOWN
289#define AI 1
288 290
289#elif CONFIG_KEYPAD == SANSA_CONNECT_PAD 291#elif CONFIG_KEYPAD == SANSA_CONNECT_PAD
290 292