2004-06-16 21:54:53 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Daniel Stenberg
|
|
|
|
*
|
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.
|
2004-06-16 21:54:53 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "plugin.h"
|
2011-01-20 13:37:20 +00:00
|
|
|
#include "lib/helper.h"
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define PAD_HEIGHT LCD_HEIGHT / 6 /* Recorder: 10 iRiver: 21 */
|
|
|
|
#define PAD_WIDTH LCD_WIDTH / 50 /* Recorder: 2 iRiver: 2 */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#define BALL_HEIGHT LCD_HEIGHT / 32 /* Recorder: 2 iRiver: 4 */
|
2005-02-16 01:18:14 +00:00
|
|
|
#define BALL_WIDTH LCD_HEIGHT / 32 /* We want a square ball */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define SPEEDX ( LCD_WIDTH * 3 ) / 2 /* Recorder: 168 iRiver: 240 */
|
|
|
|
#define SPEEDY LCD_HEIGHT * 2 /* Recorder: 128 iRiver: 256 */
|
2011-01-20 13:37:20 +00:00
|
|
|
/* This is the width of the dead spot where the
|
|
|
|
* cpu player doesnt care about the ball -- 3/8 of the screen */
|
|
|
|
#define CPU_PLAYER_RIGHT_DIST ( (LCD_WIDTH/8 ) * 5 )
|
|
|
|
#define CPU_PLAYER_LEFT_DIST ( (LCD_WIDTH/8 ) * 3 )
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
#define RES 100
|
|
|
|
|
2005-02-16 01:18:14 +00:00
|
|
|
#define MOVE_STEP LCD_HEIGHT / 32 /* move pad this many steps up/down each move */
|
2004-06-23 06:59:16 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
2006-08-07 17:08:48 +00:00
|
|
|
#define PONG_PAUSE BUTTON_ON
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_F1
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_F3
|
2007-01-14 13:48:09 +00:00
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
|
|
|
#define PONG_PAUSE BUTTON_ON
|
|
|
|
#define PONG_LEFT_UP BUTTON_F1
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_F3
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
2006-08-07 17:08:48 +00:00
|
|
|
#define PONG_PAUSE BUTTON_RIGHT
|
2004-10-18 21:45:00 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_LEFT
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_MENU
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_DOWN
|
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H100_PAD
|
2005-02-04 12:41:09 +00:00
|
|
|
#define PONG_QUIT BUTTON_OFF
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_ON
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_MODE
|
2006-06-30 16:43:47 +00:00
|
|
|
#define PONG_RC_QUIT BUTTON_RC_STOP
|
2005-02-04 12:41:09 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H300_PAD
|
|
|
|
#define PONG_QUIT BUTTON_OFF
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REC
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_MODE
|
|
|
|
#define PONG_RC_QUIT BUTTON_RC_STOP
|
|
|
|
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
2007-07-27 09:57:27 +00:00
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define PONG_QUIT BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_MENU
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_PLAY
|
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD)
|
2006-01-18 11:09:06 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REC
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_PLAY
|
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
|
2007-05-19 23:38:09 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
2006-02-24 15:42:52 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
2007-03-13 02:55:40 +00:00
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
2006-02-24 15:42:52 +00:00
|
|
|
|
2008-12-12 19:50:49 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
|
2009-01-04 23:33:15 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
|
2011-11-16 14:08:01 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_M200_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_CONNECT_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_LEFT
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
2009-04-10 17:28:26 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
|
2009-05-20 11:15:08 +00:00
|
|
|
#define PONG_QUIT BUTTON_HOME
|
2009-04-10 17:28:26 +00:00
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_LEFT
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
2007-10-16 19:57:30 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_C200_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_VOL_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_DOWN
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_LEFT_UP BUTTON_SCROLL_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_SCROLL_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REW
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_FF
|
|
|
|
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_BACK
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == MROBE100_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_MENU
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_LEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_PLAY
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_RIGHT
|
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define PONG_QUIT BUTTON_RC_REC
|
|
|
|
#define PONG_PAUSE BUTTON_RC_PLAY
|
|
|
|
#define PONG_LEFT_UP BUTTON_RC_VOL_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_RC_VOL_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2009-12-15 20:51:41 +00:00
|
|
|
#elif (CONFIG_KEYPAD == COWON_D2_PAD)
|
2008-03-22 22:03:34 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
|
2008-10-07 16:38:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_MENU
|
|
|
|
#define PONG_LEFT_UP BUTTON_VOLUP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_VOLDOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_LEFT
|
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define PONG_QUIT BUTTON_BACK
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
2008-12-08 09:51:42 +00:00
|
|
|
#define PONG_RIGHT_UP BUTTON_PLAY
|
2008-12-04 21:28:56 +00:00
|
|
|
#define PONG_RIGHT_DOWN BUTTON_MENU
|
|
|
|
|
2014-03-21 21:16:02 +00:00
|
|
|
#elif (CONFIG_KEYPAD == CREATIVE_ZENXFI3_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_PLAY
|
|
|
|
#define PONG_LEFT_UP BUTTON_BACK
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_MENU
|
|
|
|
#define PONG_RIGHT_UP BUTTON_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_DOWN
|
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_MENU
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2010-11-02 14:36:08 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD6330_PAD
|
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_MENU
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2009-12-04 03:31:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
|
2009-12-03 23:13:45 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_MENU
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2009-08-31 21:11:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD || \
|
|
|
|
CONFIG_KEYPAD == ONDAVX777_PAD || \
|
|
|
|
CONFIG_KEYPAD == MROBE500_PAD
|
2009-04-07 23:41:44 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
|
2016-01-23 14:54:08 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH92X_PAD
|
2015-07-19 23:50:26 +00:00
|
|
|
#define PONG_QUIT (BUTTON_PLAY|BUTTON_REPEAT)
|
|
|
|
#define PONG_PAUSE (BUTTON_PLAY|BUTTON_REL)
|
2009-08-04 03:08:32 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_FFWD
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_REW
|
|
|
|
|
2015-07-19 23:50:26 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH820_PAD
|
|
|
|
#define PONG_QUIT BUTTON_REW
|
|
|
|
#define PONG_PAUSE BUTTON_PLAY
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_REC
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_FFWD
|
|
|
|
|
2010-02-13 15:46:34 +00:00
|
|
|
#elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
|
|
|
|
#define PONG_QUIT BUTTON_REC
|
|
|
|
#define PONG_PAUSE BUTTON_OK
|
|
|
|
#define PONG_LEFT_UP BUTTON_MENU
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_PREV
|
|
|
|
#define PONG_RIGHT_UP BUTTON_PLAY
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_NEXT
|
|
|
|
|
2010-04-26 21:40:00 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD200_PAD
|
|
|
|
#define PONG_QUIT (BUTTON_REC|BUTTON_PLAY)
|
2010-11-02 10:44:34 +00:00
|
|
|
#define PONG_LEFT_UP BUTTON_REW
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_FF
|
2010-04-26 21:40:00 +00:00
|
|
|
#define PONG_RIGHT_UP BUTTON_VOL_UP
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_VOL_DOWN
|
|
|
|
|
2010-11-30 10:52:14 +00:00
|
|
|
#elif CONFIG_KEYPAD == MPIO_HD300_PAD
|
2012-02-02 13:42:42 +00:00
|
|
|
#define PONG_QUIT (BUTTON_MENU|BUTTON_REPEAT)
|
|
|
|
#define PONG_LEFT_UP BUTTON_REW
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_REC
|
|
|
|
#define PONG_RIGHT_UP BUTTON_FF
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_PLAY
|
2010-11-30 10:52:14 +00:00
|
|
|
|
2011-10-02 16:20:57 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_FUZEPLUS_PAD
|
2012-03-01 22:23:29 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_LEFT_UP BUTTON_BACK
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_BOTTOMLEFT
|
|
|
|
#define PONG_RIGHT_UP BUTTON_PLAYPAUSE
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_BOTTOMRIGHT
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
2011-10-02 16:20:57 +00:00
|
|
|
|
Initial commit of the Samsung YP-R0 port.
This port is a hybrid native/RaaA port. It runs on a embedded linux system,
but is the only application. It therefore can implement lots of stuff that
native targets also implement, while leveraging the underlying linux kernel.
The port is quite advanced. User interface, audio playback, plugins work
mostly fine. Missing is e.g. power mangement and USB (see SamsungYPR0 wiki page).
Included in utils/ypr0tools are scripts and programs required to generate
a patched firmware. The patched firmware has the rootfs modified to load
Rockbox. It includes a early/safe USB mode.
This port needs a new toolchain, one that includes glibc headers and libraries.
rockboxdev.sh can generate it, but e.g. codesourcey and distro packages may
also work.
Most of the initial effort is done by Lorenzo Miori and others (on ABI),
including reverse engineering and patching of the original firmware,
initial drivers, and more. Big thanks to you.
Flyspray: FS#12348
Author: Lorenzo Miori, myself
Merry christmas to ypr0 owners! :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31415 a1c6a512-1295-4272-9138-f99709370657
2011-12-24 11:56:46 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SAMSUNG_YPR0_PAD)
|
|
|
|
#define PONG_QUIT BUTTON_BACK
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_MENU
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_POWER
|
|
|
|
|
2012-04-06 16:17:27 +00:00
|
|
|
#elif (CONFIG_KEYPAD == HM60X_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == HM801_PAD)
|
2012-03-23 18:32:50 +00:00
|
|
|
#define PONG_QUIT BUTTON_POWER
|
|
|
|
#define PONG_PAUSE BUTTON_SELECT
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_LEFT
|
|
|
|
|
2014-06-30 18:24:15 +00:00
|
|
|
#elif CONFIG_KEYPAD == SONY_NWZ_PAD
|
|
|
|
#define PONG_QUIT BUTTON_BACK
|
|
|
|
#define PONG_PAUSE BUTTON_PLAY
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_LEFT
|
|
|
|
|
2014-07-17 08:40:17 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVE_ZEN_PAD
|
|
|
|
#define PONG_QUIT BUTTON_BACK
|
|
|
|
#define PONG_PAUSE BUTTON_PLAYPAUSE
|
|
|
|
#define PONG_LEFT_UP BUTTON_UP
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_DOWN
|
|
|
|
#define PONG_RIGHT_UP BUTTON_RIGHT
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_LEFT
|
|
|
|
|
2014-08-30 11:15:53 +00:00
|
|
|
#elif (CONFIG_KEYPAD == DX50_PAD)
|
|
|
|
#define PONG_QUIT (BUTTON_POWER|BUTTON_REL)
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2004-10-18 21:45:00 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef PONG_QUIT
|
|
|
|
#define PONG_QUIT BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef PONG_LEFT_UP
|
|
|
|
#define PONG_LEFT_UP BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef PONG_LEFT_DOWN
|
|
|
|
#define PONG_LEFT_DOWN BUTTON_BOTTOMLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef PONG_RIGHT_UP
|
|
|
|
#define PONG_RIGHT_UP BUTTON_TOPRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef PONG_RIGHT_DOWN
|
|
|
|
#define PONG_RIGHT_DOWN BUTTON_BOTTOMRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef PONG_PAUSE
|
|
|
|
#define PONG_PAUSE BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
struct player {
|
|
|
|
int xpos; /* X position of pad */
|
|
|
|
int w_pad; /* wanted current Y position of pad */
|
|
|
|
int e_pad; /* existing current Y position of pad */
|
|
|
|
int score;
|
|
|
|
bool iscpu; /* Status of AI player */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ball {
|
|
|
|
int x; /* current X*RES position of the ball */
|
|
|
|
int y; /* current Y*RES position of the ball */
|
|
|
|
int speedx; /* */
|
|
|
|
int speedy; /* */
|
|
|
|
};
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
struct pong {
|
2011-01-20 13:37:20 +00:00
|
|
|
struct ball ball;
|
|
|
|
struct player player[2];
|
2004-06-16 21:54:53 +00:00
|
|
|
};
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void singlepad(int x, int y, int set)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2005-06-24 22:33:21 +00:00
|
|
|
if(set) {
|
2004-06-16 21:54:53 +00:00
|
|
|
rb->lcd_fillrect(x, y, PAD_WIDTH, PAD_HEIGHT);
|
2005-06-24 22:33:21 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
|
|
|
rb->lcd_fillrect(x, y, PAD_WIDTH, PAD_HEIGHT);
|
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
|
|
|
}
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void pad(struct pong *p, int pad)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2011-01-20 13:37:20 +00:00
|
|
|
struct player *player = &p->player[pad];
|
2004-06-16 21:54:53 +00:00
|
|
|
/* clear existing pad */
|
2011-01-20 13:37:20 +00:00
|
|
|
singlepad(player->xpos, player->e_pad, 0);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* draw wanted pad */
|
2011-01-20 13:37:20 +00:00
|
|
|
singlepad(player->xpos, player->w_pad, 1);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* existing is now the wanted */
|
2011-01-20 13:37:20 +00:00
|
|
|
player->e_pad = player->w_pad;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static bool wallcollide(struct pong *p, int pad)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
/* we have already checked for pad-collision, just check if this hits
|
|
|
|
the wall */
|
|
|
|
if(pad) {
|
|
|
|
/* right-side */
|
2011-01-20 13:37:20 +00:00
|
|
|
if(p->ball.x > ( LCD_WIDTH*RES ) - PAD_WIDTH )
|
2004-06-16 21:54:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
2011-01-20 13:37:20 +00:00
|
|
|
if(p->ball.x + ( BALL_WIDTH*RES ) < PAD_WIDTH )
|
2004-06-16 21:54:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns true if the ball has hit a pad, and then the info variable
|
|
|
|
will have extra angle info */
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static bool padcollide(struct pong *p, int pad, int *info)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2011-01-20 13:37:20 +00:00
|
|
|
struct player *player = &p->player[pad];
|
|
|
|
int x = p->ball.x/RES;
|
|
|
|
int y = p->ball.y/RES;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
if((y < (player->e_pad+PAD_HEIGHT)) &&
|
|
|
|
(y + BALL_HEIGHT > player->e_pad)) {
|
2004-06-16 21:54:53 +00:00
|
|
|
/* Y seems likely right */
|
|
|
|
|
|
|
|
/* store the delta between ball-middle MINUS pad-middle, so
|
|
|
|
it returns:
|
|
|
|
0 when the ball hits exactly the middle of the pad
|
|
|
|
positive numbers when the ball is below the middle of the pad
|
|
|
|
negative numbers when the ball is above the middle of the pad
|
|
|
|
|
|
|
|
max number is +- PAD_HEIGHT/2
|
|
|
|
*/
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
*info = (y+BALL_HEIGHT/2) - (player->e_pad + PAD_HEIGHT/2);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
if(pad) {
|
|
|
|
/* right-side */
|
2006-08-07 17:08:48 +00:00
|
|
|
if((x + BALL_WIDTH) >= (LCD_WIDTH - PAD_WIDTH))
|
2004-06-16 21:54:53 +00:00
|
|
|
return true; /* phump */
|
|
|
|
}
|
|
|
|
else {
|
2006-08-07 17:08:48 +00:00
|
|
|
if(x <= PAD_WIDTH)
|
2004-06-16 21:54:53 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false; /* nah */
|
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void bounce(struct pong *p, int pad, int info)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedx = -p->ball.speedx;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
/* Give ball a little push to keep it from getting stuck between wall and pad */
|
|
|
|
if(pad) {
|
|
|
|
/* right side */
|
|
|
|
p->ball.x -= PAD_WIDTH*RES/4;
|
2011-01-08 16:32:56 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.x += PAD_WIDTH*RES/4;
|
2011-01-08 16:32:56 +00:00
|
|
|
}
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* info is the hit-angle into the pad */
|
2011-01-20 13:37:20 +00:00
|
|
|
if(p->ball.speedy > 0) {
|
2004-06-16 21:54:53 +00:00
|
|
|
/* downwards */
|
|
|
|
if(info > 0) {
|
|
|
|
/* below the middle of the pad */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy += info * RES/3;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
else if(info < 0) {
|
|
|
|
/* above the middle */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy = info * RES/2;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* upwards */
|
|
|
|
if(info > 0) {
|
|
|
|
/* below the middle of the pad */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy = info * RES/2;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
else if(info < 0) {
|
|
|
|
/* above the middle */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy += info * RES/3;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy += rb->rand()%21-10;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
#if 0
|
2011-01-20 13:37:20 +00:00
|
|
|
fprintf(stderr, "INFO: %d YSPEED: %d\n", info, p->ball.speedy);
|
2004-06-16 21:54:53 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void score(struct pong *p, int pad)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2007-08-01 23:42:41 +00:00
|
|
|
if(pad)
|
|
|
|
rb->splash(HZ/4, "right scores!");
|
|
|
|
else
|
|
|
|
rb->splash(HZ/4, "left scores!");
|
2004-06-16 21:54:53 +00:00
|
|
|
rb->lcd_clear_display();
|
2011-01-20 13:37:20 +00:00
|
|
|
p->player[pad].score++;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* then move the X-speed of the ball and give it a random Y position */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedx = -p->ball.speedx;
|
|
|
|
p->ball.y = rb->rand()%((LCD_HEIGHT-BALL_HEIGHT)*RES);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
/* avoid hitting the pad with the new ball */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.x = (p->ball.x < 0) ?
|
2006-08-07 17:08:48 +00:00
|
|
|
(RES * PAD_WIDTH) : (RES * (LCD_WIDTH - PAD_WIDTH - BALL_WIDTH));
|
2009-12-04 11:41:31 +00:00
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* restore Y-speed to default */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy = (p->ball.speedy > 0) ? SPEEDY : -SPEEDY;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* set the existing pad positions to something weird to force pad
|
|
|
|
updates */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->player[0].e_pad = -1;
|
|
|
|
p->player[1].e_pad = -1;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void ball(struct pong *p)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
2011-01-20 13:37:20 +00:00
|
|
|
int oldx = p->ball.x/RES;
|
|
|
|
int oldy = p->ball.y/RES;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
int newx;
|
|
|
|
int newy;
|
|
|
|
|
|
|
|
int info;
|
|
|
|
|
|
|
|
/* movement */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.x += p->ball.speedx;
|
|
|
|
p->ball.y += p->ball.speedy;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
newx = p->ball.x/RES;
|
|
|
|
newy = p->ball.y/RES;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* detect if ball hits a wall */
|
2006-08-07 17:08:48 +00:00
|
|
|
if(newy + BALL_HEIGHT > LCD_HEIGHT) {
|
2004-06-16 21:54:53 +00:00
|
|
|
/* hit floor, bounce */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy = -p->ball.speedy;
|
|
|
|
p->ball.y = (LCD_HEIGHT - BALL_HEIGHT) * RES;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
else if(newy < 0) {
|
|
|
|
/* hit ceiling, bounce */
|
2011-01-20 13:37:20 +00:00
|
|
|
p->ball.speedy = -p->ball.speedy;
|
|
|
|
p->ball.y = 0;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* detect if ball hit pads */
|
|
|
|
if(padcollide(p, 0, &info))
|
|
|
|
bounce(p, 0, info);
|
|
|
|
else if(padcollide(p, 1, &info))
|
|
|
|
bounce(p, 1, info);
|
|
|
|
else if(wallcollide(p, 0))
|
|
|
|
score(p, 1);
|
|
|
|
else if(wallcollide(p, 1))
|
|
|
|
score(p, 0);
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
newx = p->ball.x/RES;
|
|
|
|
newy = p->ball.y/RES;
|
2006-08-07 17:08:48 +00:00
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* clear old position */
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
|
2011-01-20 13:37:20 +00:00
|
|
|
rb->lcd_fillrect(oldx, oldy, BALL_WIDTH, BALL_HEIGHT);
|
2005-06-24 22:33:21 +00:00
|
|
|
rb->lcd_set_drawmode(DRMODE_SOLID);
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* draw the new ball position */
|
2006-08-07 17:08:48 +00:00
|
|
|
rb->lcd_fillrect(newx, newy, BALL_WIDTH, BALL_HEIGHT);
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void padmove(int *pos, int dir)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
*pos += dir;
|
2004-06-23 06:59:16 +00:00
|
|
|
if(*pos > (LCD_HEIGHT-PAD_HEIGHT))
|
|
|
|
*pos = (LCD_HEIGHT-PAD_HEIGHT);
|
2004-06-16 21:54:53 +00:00
|
|
|
else if(*pos < 0)
|
|
|
|
*pos = 0;
|
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void key_pad(struct pong *p, int pad, int up, int down)
|
2011-01-20 13:37:20 +00:00
|
|
|
{
|
|
|
|
struct player *player = &p->player[pad];
|
|
|
|
if(player->iscpu) {
|
|
|
|
if((pad && (p->ball.x/RES > CPU_PLAYER_RIGHT_DIST)) /* cpu right */
|
|
|
|
|| (!pad && (p->ball.x/RES < CPU_PLAYER_LEFT_DIST)) /* cpu left */)
|
|
|
|
{
|
|
|
|
if(p->ball.y/RES > player->w_pad) /* player goes down */
|
|
|
|
padmove(&player->w_pad, MOVE_STEP);
|
|
|
|
|
|
|
|
if(p->ball.y/RES < player->w_pad) /* player goes up */
|
|
|
|
padmove(&player->w_pad, -MOVE_STEP);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(down || up) {
|
|
|
|
/* if player presses control keys stop cpu player */
|
|
|
|
player->iscpu = false;
|
|
|
|
p->player[0].score = p->player[1].score = 0; /* reset the score */
|
|
|
|
rb->lcd_clear_display(); /* get rid of the text */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(down) /* player goes down */
|
|
|
|
padmove(&player->w_pad, MOVE_STEP);
|
|
|
|
|
|
|
|
if(up) /* player goes up */
|
|
|
|
padmove(&player->w_pad, -MOVE_STEP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static int keys(struct pong *p)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
int key;
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef PONG_PAUSE
|
|
|
|
static bool pause = false;
|
|
|
|
#endif
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2008-06-09 20:59:55 +00:00
|
|
|
/* number of ticks this function will loop reading keys */
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifndef HAVE_TOUCHSCREEN
|
2008-06-09 20:59:55 +00:00
|
|
|
int time = 4;
|
|
|
|
#else
|
|
|
|
int time = 1;
|
|
|
|
#endif
|
2004-06-16 21:54:53 +00:00
|
|
|
int start = *rb->current_tick;
|
|
|
|
int end = start + time;
|
|
|
|
|
2009-10-18 15:50:30 +00:00
|
|
|
while(TIME_BEFORE(*rb->current_tick, end)) {
|
2004-06-16 21:54:53 +00:00
|
|
|
key = rb->button_get_w_tmo(end - *rb->current_tick);
|
2009-12-04 11:41:31 +00:00
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2009-10-18 15:50:30 +00:00
|
|
|
short touch_x, touch_y;
|
|
|
|
if(key & BUTTON_TOUCHSCREEN)
|
|
|
|
{
|
2011-01-20 13:37:20 +00:00
|
|
|
struct player *player;
|
2009-10-18 15:50:30 +00:00
|
|
|
touch_x = rb->button_get_data() >> 16;
|
|
|
|
touch_y = rb->button_get_data() & 0xFFFF;
|
2009-12-04 11:41:31 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
player = &p->player[0];
|
|
|
|
if(touch_x >= player->xpos && touch_x <= player->xpos+(PAD_WIDTH*4))
|
|
|
|
{
|
|
|
|
padmove(&player->w_pad, touch_y-(player->e_pad*2+PAD_HEIGHT)/2);
|
|
|
|
if (player->iscpu) {
|
|
|
|
/* if left player presses control keys stop cpu player */
|
|
|
|
player->iscpu = false;
|
|
|
|
p->player[0].score = p->player[1].score = 0; /* reset the score */
|
|
|
|
rb->lcd_clear_display(); /* get rid of the text */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
player = &p->player[1];
|
|
|
|
if(touch_x >= player->xpos-(PAD_WIDTH*4) && touch_x <= player->xpos)
|
|
|
|
{
|
|
|
|
padmove(&player->w_pad, touch_y-(player->e_pad*2+PAD_HEIGHT)/2);
|
|
|
|
if (player->iscpu) {
|
|
|
|
/* if right player presses control keys stop cpu player */
|
|
|
|
player->iscpu = false;
|
|
|
|
p->player[0].score = p->player[1].score = 0; /* reset the score */
|
|
|
|
rb->lcd_clear_display(); /* get rid of the text */
|
|
|
|
}
|
|
|
|
}
|
2009-10-18 15:50:30 +00:00
|
|
|
}
|
2008-06-09 20:59:55 +00:00
|
|
|
#endif
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef HAS_BUTTON_HOLD
|
|
|
|
if (rb->button_hold())
|
2011-01-20 13:37:20 +00:00
|
|
|
return 2; /* Pause game */
|
2006-08-07 17:08:48 +00:00
|
|
|
#endif
|
|
|
|
|
2015-07-12 22:30:14 +00:00
|
|
|
if(key == PONG_QUIT
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef PONG_RC_QUIT
|
2015-07-12 22:30:14 +00:00
|
|
|
|| key == PONG_RC_QUIT
|
2006-06-30 16:43:47 +00:00
|
|
|
#endif
|
|
|
|
)
|
2004-10-18 21:45:00 +00:00
|
|
|
return 0; /* exit game NOW */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2006-08-07 17:08:48 +00:00
|
|
|
#ifdef PONG_PAUSE
|
|
|
|
if(key == PONG_PAUSE)
|
|
|
|
pause = !pause;
|
|
|
|
if(pause)
|
|
|
|
return 2; /* Pause game */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
key = rb->button_status(); /* ignore BUTTON_REPEAT */
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
key_pad(p, 0, (key & PONG_LEFT_UP), (key & PONG_LEFT_DOWN));
|
|
|
|
key_pad(p, 1, (key & PONG_RIGHT_UP), (key & PONG_RIGHT_DOWN));
|
2009-12-04 11:41:31 +00:00
|
|
|
|
2004-10-18 21:45:00 +00:00
|
|
|
if(rb->default_event_handler(key) == SYS_USB_CONNECTED)
|
|
|
|
return -1; /* exit game because of USB */
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
2004-10-18 21:45:00 +00:00
|
|
|
return 1; /* return 0 to exit game */
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void showscore(struct pong *p)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
static char buffer[20];
|
2005-02-16 01:18:14 +00:00
|
|
|
int w;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
rb->snprintf(buffer, sizeof(buffer), "%d - %d",
|
|
|
|
p->player[0].score, p->player[1].score);
|
2005-12-02 08:08:54 +00:00
|
|
|
w = rb->lcd_getstringsize((unsigned char *)buffer, NULL, NULL);
|
|
|
|
rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), 0, (unsigned char *)buffer);
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-10-15 20:38:08 +00:00
|
|
|
static void blink_demo(void)
|
2011-01-08 16:32:56 +00:00
|
|
|
{
|
|
|
|
static char buffer[30];
|
|
|
|
int w;
|
|
|
|
|
|
|
|
rb->snprintf(buffer, sizeof(buffer), "Press Key To Play");
|
|
|
|
w = rb->lcd_getstringsize((unsigned char *)buffer, NULL, NULL);
|
|
|
|
if(LCD_WIDTH > ( (w/8)*7 ) ) /* make sure text isn't too long for screen */
|
|
|
|
rb->lcd_putsxy( (LCD_WIDTH / 2) - (w / 2), (LCD_HEIGHT / 2),
|
|
|
|
(unsigned char *)buffer);
|
|
|
|
}
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* this is the plugin entry point */
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2004-06-16 21:54:53 +00:00
|
|
|
{
|
|
|
|
struct pong pong;
|
2004-10-18 21:45:00 +00:00
|
|
|
int game = 1;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-08 16:32:56 +00:00
|
|
|
int blink_timer = 0;
|
|
|
|
int blink_rate = 20;
|
|
|
|
bool blink = true;
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
/* init the struct with some silly values to start with */
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
pong.ball.x = 20*RES;
|
|
|
|
pong.ball.y = 20*RES;
|
|
|
|
pong.ball.speedx = SPEEDX;
|
|
|
|
pong.ball.speedy = SPEEDY;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
pong.player[0].xpos = 0;
|
|
|
|
pong.player[0].e_pad = 0;
|
|
|
|
pong.player[0].w_pad = 7;
|
|
|
|
pong.player[1].xpos = LCD_WIDTH-PAD_WIDTH;
|
|
|
|
pong.player[1].e_pad = 0;
|
|
|
|
pong.player[1].w_pad = 40;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
/* start every game in demo mode */
|
|
|
|
pong.player[0].iscpu = pong.player[1].iscpu = true;
|
2004-06-16 21:54:53 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
pong.player[0].score = pong.player[1].score = 0; /* lets start at 0 - 0 ;-) */
|
2004-06-16 21:54:53 +00:00
|
|
|
|
|
|
|
/* if you don't use the parameter, you can do like
|
|
|
|
this to avoid the compiler warning about it */
|
|
|
|
(void)parameter;
|
2009-12-04 11:41:31 +00:00
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
/* Turn off backlight timeout */
|
2011-01-24 12:29:16 +00:00
|
|
|
backlight_ignore_timeout();
|
2004-06-16 21:54:53 +00:00
|
|
|
/* Clear screen */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
/* go go go */
|
2004-10-18 21:45:00 +00:00
|
|
|
while(game > 0) {
|
2011-01-20 13:37:20 +00:00
|
|
|
if( pong.player[0].iscpu && pong.player[1].iscpu ) {
|
2011-01-08 16:32:56 +00:00
|
|
|
if(blink_timer<blink_rate) {
|
|
|
|
++blink_timer;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
blink_timer=0;
|
|
|
|
blink = !blink;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(blink==true) {
|
|
|
|
blink_demo();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-16 21:54:53 +00:00
|
|
|
showscore(&pong);
|
|
|
|
pad(&pong, 0); /* draw left pad */
|
|
|
|
pad(&pong, 1); /* draw right pad */
|
|
|
|
ball(&pong); /* move and draw ball */
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
|
|
|
|
game = keys(&pong); /* deal with keys */
|
2015-07-12 22:30:14 +00:00
|
|
|
|
|
|
|
if (game == 2) { /* Game Paused */
|
|
|
|
rb->splash(0, "PAUSED");
|
|
|
|
while(game == 2)
|
|
|
|
game = keys(&pong); /* short circuit */
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
}
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|
|
|
|
|
2011-01-20 13:37:20 +00:00
|
|
|
/* Turn on backlight timeout (revert to settings) */
|
|
|
|
backlight_use_settings();
|
2004-10-18 21:45:00 +00:00
|
|
|
return (game == 0) ? PLUGIN_OK : PLUGIN_USB_CONNECTED;
|
2004-06-16 21:54:53 +00:00
|
|
|
}
|