/***************************************************************************
*             __________               __   ___.
*   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
*   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
*   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
*   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
*                     \/            \/     \/    \/            \/
* $Id$
*
* Copyright (C) 2005 Adam Boot
*
* Color graphics from Gweled (http://sebdelestaing.free.fr/gweled/)
*
* All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/

#include "plugin.h"

#ifdef HAVE_LCD_BITMAP

PLUGIN_HEADER

/* save files */
#define SCORE_FILE PLUGIN_DIR "/bejeweled.score"
#define SAVE_FILE  PLUGIN_DIR "/bejeweled.save"

/* final game return status */
#define BJ_END  3
#define BJ_USB  2
#define BJ_QUIT 1
#define BJ_LOSE 0

/* button definitions */
#if CONFIG_KEYPAD == RECORDER_PAD
#define BEJEWELED_UP     BUTTON_UP
#define BEJEWELED_DOWN   BUTTON_DOWN
#define BEJEWELED_LEFT   BUTTON_LEFT
#define BEJEWELED_RIGHT  BUTTON_RIGHT
#define BEJEWELED_QUIT   BUTTON_OFF
#define BEJEWELED_START  BUTTON_ON
#define BEJEWELED_SELECT BUTTON_PLAY
#define BEJEWELED_RESUME BUTTON_F1

#elif CONFIG_KEYPAD == ONDIO_PAD
#define BEJEWELED_UP         BUTTON_UP
#define BEJEWELED_DOWN       BUTTON_DOWN
#define BEJEWELED_LEFT       BUTTON_LEFT
#define BEJEWELED_RIGHT      BUTTON_RIGHT
#define BEJEWELED_QUIT       BUTTON_OFF
#define BEJEWELED_START      BUTTON_RIGHT
#define BEJEWELED_SELECT     (BUTTON_MENU|BUTTON_REL)
#define BEJEWELED_SELECT_PRE BUTTON_MENU
#define BEJEWELED_RESUME     (BUTTON_MENU|BUTTON_OFF)

#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
#define BEJEWELED_UP     BUTTON_UP
#define BEJEWELED_DOWN   BUTTON_DOWN
#define BEJEWELED_LEFT   BUTTON_LEFT
#define BEJEWELED_RIGHT  BUTTON_RIGHT
#define BEJEWELED_QUIT   BUTTON_OFF
#define BEJEWELED_START  BUTTON_ON
#define BEJEWELED_SELECT BUTTON_SELECT
#define BEJEWELED_RESUME BUTTON_MODE

#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
#define BEJEWELED_SCROLLWHEEL
#define BEJEWELED_UP         BUTTON_MENU
#define BEJEWELED_DOWN       BUTTON_PLAY
#define BEJEWELED_LEFT       BUTTON_LEFT
#define BEJEWELED_RIGHT      BUTTON_RIGHT
#define BEJEWELED_PREV       BUTTON_SCROLL_BACK
#define BEJEWELED_NEXT       BUTTON_SCROLL_FWD
#define BEJEWELED_QUIT       (BUTTON_SELECT|BUTTON_MENU)
#define BEJEWELED_START      BUTTON_PLAY
#define BEJEWELED_SELECT     (BUTTON_SELECT|BUTTON_REL)
#define BEJEWELED_SELECT_PRE BUTTON_SELECT
#define BEJEWELED_RESUME     (BUTTON_SELECT|BUTTON_PLAY)

#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
#define BEJEWELED_QUIT       BUTTON_PLAY
#define BEJEWELED_START      BUTTON_MODE
#define BEJEWELED_SELECT     BUTTON_SELECT
#define BEJEWELED_RESUME     BUTTON_EQ

#elif CONFIG_KEYPAD == IAUDIO_X5_PAD
#define BEJEWELED_UP         BUTTON_UP
#define BEJEWELED_DOWN       BUTTON_DOWN
#define BEJEWELED_LEFT       BUTTON_LEFT
#define BEJEWELED_RIGHT      BUTTON_RIGHT
#define BEJEWELED_QUIT       BUTTON_POWER
#define BEJEWELED_START      BUTTON_PLAY
#define BEJEWELED_SELECT     BUTTON_MENU
#define BEJEWELED_RESUME     BUTTON_REC

#else
    #error BEJEWELED: Unsupported keypad
#endif

/* swap directions */
#define SWAP_UP    0
#define SWAP_RIGHT 1
#define SWAP_DOWN  2
#define SWAP_LEFT  3

/* play board dimension */
#define BJ_HEIGHT 9
#define BJ_WIDTH  8

/* next level threshold */
#define LEVEL_PTS 100

/* sleep time for animations (1/x seconds) */
#define FALL_TIMER 50
#define SWAP_TIMER 30

/* use 22x22 tiles */
#if (LCD_HEIGHT >= 176) && (LCD_WIDTH >= 220) && \
    (LCD_PIXELFORMAT == RGB565SWAPPED)
/* size of a tile */
#define TILE_WIDTH  22
#define TILE_HEIGHT 22

/* playboard offset from top */
#define YOFS 0

/* number of high scores to save */
#define NUM_SCORES 10

/* bitmaps for the jewels */
static unsigned short jewel[8][484] = {
    /* empty */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* white jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf7bd, 0xe739, 0xe739, 0xf7bd, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xd7bd, 0xc739, 0x4108, 0x1084,
     0x2c63, 0x4108, 0xc739, 0xf7bd, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xd7bd, 0xa631, 0x6108, 0x1084, 0x59ce, 0x79ce, 0x718c, 0x9294,
     0x4d6b, 0x4108, 0xa631, 0xd7bd, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xbef7, 0xa631, 0x6108, 0x1084,
     0x59ce, 0x79ce, 0x79ce, 0x79ce, 0x718c, 0x718c, 0x718c, 0x9294,
     0x6d6b, 0x6108, 0xe739, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xf39c, 0x6529, 0x59ce, 0xbad6, 0xbad6, 0xbad6,
     0xbad6, 0xbad6, 0xb294, 0xd39c, 0x14a5, 0x55ad, 0x96b5, 0x55ad,
     0x6108, 0x96b5, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x4529, 0xd39c, 0x1ce7, 0x1ce7, 0x1ce7, 0x1ce7, 0x1ce7, 0x1ce7,
     0x14a5, 0xd39c, 0xd39c, 0x34a5, 0x96b5, 0xf7bd, 0xcb5a, 0xe739,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6, 0x6108, 0xfbde,
     0x3ce7, 0x5def, 0x5def, 0x5def, 0x3ce7, 0x3ce7, 0x75ad, 0x34a5,
     0xf39c, 0xf39c, 0x55ad, 0xb6b5, 0x75ad, 0x2000, 0x79ce, 0xffff,
     0xffff, 0xffff, 0xffff, 0x8a52, 0xcf7b, 0x5def, 0x3ce7, 0x3ce7,
     0x3ce7, 0x3ce7, 0x3ce7, 0x5def, 0xd7bd, 0x96b5, 0x34a5, 0xd39c,
     0xf39c, 0x75ad, 0xd7bd, 0xcb5a, 0xeb5a, 0xffff, 0xffff, 0xffff,
     0x1ce7, 0x2000, 0x9ad6, 0x3ce7, 0x1ce7, 0x1ce7, 0xfbde, 0x1ce7,
     0x1ce7, 0x3ce7, 0xf7bd, 0xd7bd, 0x75ad, 0x14a5, 0xd39c, 0x34a5,
     0xb6b5, 0x95b5, 0x2000, 0x5def, 0xffff, 0xffff, 0xcf7b, 0x8a52,
     0x3ce7, 0x1ce7, 0xfbde, 0xfbde, 0xdbde, 0xdbde, 0xfbde, 0x1ce7,
     0xb6b5, 0x18c6, 0xb6b5, 0x55ad, 0xf7bd, 0x34a5, 0xb6b5, 0xb6b5,
     0x694a, 0xef7b, 0xffff, 0xffff, 0xc318, 0xb294, 0x9ad6, 0x59ce,
     0x18c6, 0x38c6, 0x38c6, 0x38c6, 0x18c6, 0x38c6, 0x18c6, 0x59ce,
     0x79ce, 0x18c6, 0xdbde, 0x38c6, 0x95b5, 0xd6b5, 0x518c, 0xc318,
     0xffff, 0xffff, 0x2c63, 0x0842, 0x75ad, 0xf39c, 0xf39c, 0x55ad,
     0x96b5, 0x75ad, 0x14a5, 0xd39c, 0xfbde, 0x3ce7, 0x5def, 0x1ce7,
     0x9def, 0xdbde, 0x96b5, 0xd7bd, 0x2842, 0x0c63, 0xffff, 0xffff,
     0xdbde, 0x2000, 0x9294, 0xd39c, 0x14a5, 0x96b5, 0xf7bd, 0xb6b5,
     0x34a5, 0xb294, 0xfbde, 0x3ce7, 0x5def, 0x3ce7, 0x5def, 0xdad6,
     0x58c6, 0x34a5, 0x2000, 0x9ad6, 0xffff, 0xffff, 0xffff, 0x8a52,
     0x2842, 0xf39c, 0xf39c, 0x75ad, 0xb6b5, 0x96b5, 0x34a5, 0xb294,
     0xfbde, 0x3ce7, 0x5def, 0x5def, 0xfbde, 0xdad6, 0xdad6, 0xae73,
     0x0842, 0xffff, 0xffff, 0xffff, 0xffff, 0x38c6, 0x2000, 0xb294,
     0xd39c, 0x14a5, 0x55ad, 0x34a5, 0xf39c, 0xf39c, 0xfbde, 0x3ce7,
     0x3ce7, 0x3ce7, 0xdad6, 0xdad6, 0xbad6, 0xc318, 0xb6b5, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xc739, 0x8a52, 0xf39c, 0xb294,
     0xd39c, 0xd39c, 0xf39c, 0x34a5, 0xfbde, 0x5def, 0x3ce7, 0xfbde,
     0xdad6, 0xdad6, 0x34a5, 0x2421, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x96b5, 0x6108, 0xb294, 0x34a5, 0x14a5, 0x14a5,
     0x55ad, 0x96b5, 0xbad6, 0xdbde, 0xbad6, 0xdad6, 0xdad6, 0x99ce,
     0xa631, 0xb294, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x694a, 0x2000, 0x2842, 0xb294, 0x96b5, 0xb6b5, 0xf7bd,
     0xf7bd, 0x18c6, 0xbad6, 0x99ce, 0x718c, 0x8210, 0xa631, 0xbef7,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x59ce, 0x494a, 0x0000, 0x2842, 0x14a5, 0xd7bd, 0xb6b5, 0x99ce,
     0x718c, 0x8210, 0x8631, 0xb6b5, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x59ce, 0x494a, 0x0000, 0xc739, 0x694a, 0x6108, 0x8631, 0x96b5,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x79ce, 0x694a, 0x6529, 0x96b5, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* blue jewel */
    {0xffff, 0xffff, 0xffff, 0xdfff, 0x8a4a, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0xa629, 0x9ef7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xdfff, 0x6a4a, 0xa801, 0x5e3e, 0xbf66, 0xdf6e, 0xdf76, 0xff7e,
     0xff86, 0x1f8f, 0x1f97, 0x3f9f, 0x3f9f, 0x1f97, 0x2f1b, 0xc731,
     0xbef7, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfff, 0x694a, 0xc901,
     0xdf66, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xfff7, 0xdfe7, 0xbfd7, 0x9fc7, 0x1f97, 0x8c0a, 0x083a, 0xbef7,
     0xffff, 0xffff, 0xdfff, 0x4942, 0xe901, 0xff7e, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdfef, 0xbfdf, 0x9fcf,
     0x7fbf, 0x5faf, 0x5f9f, 0xbf5e, 0x0a02, 0x4942, 0xdfff, 0xffff,
     0x694a, 0xc901, 0x3f26, 0x1f87, 0x1f8f, 0x1f8f, 0x3f97, 0x3f9f,
     0x3f9f, 0x3f9f, 0x3f97, 0x1f97, 0x1f8f, 0xff86, 0xff7e, 0xff76,
     0xdf66, 0xbf5e, 0x3f1e, 0xc909, 0x8a52, 0xffff, 0x3084, 0x4701,
     0xde05, 0x1f06, 0x1f06, 0x1f06, 0x1f06, 0x1f06, 0x1f06, 0x1f06,
     0xbe05, 0x7603, 0x7603, 0x7603, 0x3814, 0x5e66, 0xbe7e, 0x1f9f,
     0x5fb7, 0x4b22, 0xaf73, 0xffff, 0xffff, 0xe731, 0x7103, 0xde05,
     0xff05, 0x3f0e, 0x1f87, 0x1f06, 0x1f06, 0x1f06, 0xbe05, 0x7603,
     0x7603, 0x7603, 0x5c2d, 0xdf66, 0xff7e, 0x3f97, 0xf74c, 0x6521,
     0xdfff, 0xffff, 0xffff, 0xfbde, 0x6208, 0xfa04, 0xbe05, 0xff86,
     0x9fc7, 0x5f1e, 0x1f06, 0x1f06, 0xbe05, 0x7603, 0x7603, 0x7603,
     0x3f2e, 0xbf4e, 0xdf66, 0x3d5e, 0x2100, 0x79ce, 0xffff, 0xffff,
     0xffff, 0xffff, 0x14a5, 0xa300, 0x3d56, 0x9fcf, 0x9fbf, 0x9f5e,
     0x1f06, 0x1f06, 0xbe05, 0x7603, 0x7603, 0x1904, 0x5f1e, 0x7f36,
     0x7f46, 0xe911, 0x107c, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x8a4a, 0x502b, 0x7fc7, 0x7fbf, 0x1f97, 0xbe05, 0xff05,
     0xbe05, 0x7603, 0x7603, 0xfb04, 0x3f06, 0x5f1e, 0x5614, 0x8629,
     0xdfff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x7def,
     0xc310, 0xba5d, 0x7fb7, 0x5fa7, 0xbd1d, 0x9d05, 0x9d05, 0x7603,
     0x7603, 0xde05, 0x1f06, 0x7d05, 0x4100, 0xbad6, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd7bd, 0x4100,
     0xde86, 0x5fa7, 0x3e4e, 0x5c05, 0x5d05, 0x7603, 0x1804, 0x1f06,
     0xff05, 0x8801, 0x518c, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6d6b, 0x4b1a, 0x1f97,
     0xdf7e, 0x1b05, 0x3c05, 0x7603, 0xfb04, 0x1f06, 0xf503, 0xc731,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xbef7, 0x4521, 0xd73c, 0x1f8f, 0x3b15,
     0x1b05, 0x7603, 0xde05, 0x5c05, 0x4100, 0xdbde, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x79ce, 0x2100, 0x3d5e, 0xdc3d, 0xdb04, 0xf803,
     0xff05, 0x4701, 0xb294, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x518c, 0x6709, 0x5e5e, 0x9a04, 0xdb04, 0xb403, 0x083a,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xe839, 0xd323, 0xfa14, 0xda04, 0x6208, 0x1ce7, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x1ce7, 0x6208,
     0xf50b, 0x0501, 0xf39c, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x14a5, 0x0000, 0x4942,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x4d6b, 0x3ce7, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* orange jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xbef7, 0x718c, 0xe320, 0x2c63, 0x1ce7, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0x518c, 0x8210, 0xe120,
     0x0493, 0x0041, 0x2000, 0x2c63, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x9ef7, 0x3084, 0x8110, 0x0229, 0xeabc, 0x32ef, 0x67cc, 0xe0a9,
     0x20a2, 0x0041, 0x2000, 0x0c63, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x7def, 0xef7b, 0x6110, 0x2231,
     0x0abd, 0x52ef, 0x73ef, 0x73ef, 0x46cc, 0xe0a9, 0xe0a9, 0xe0a9,
     0x20a2, 0x0041, 0x2000, 0x0c63, 0xfbde, 0xffff, 0xffff, 0xffff,
     0x7def, 0xcf7b, 0x6108, 0x4231, 0x2ac5, 0x52ef, 0x73ef, 0x73ef,
     0x73ef, 0x73ef, 0x26cc, 0xe0a9, 0xe0a9, 0xe0a9, 0x40b2, 0xc0a9,
     0xc0b2, 0xa059, 0x2000, 0x0b63, 0xfbde, 0xffff, 0xa218, 0x6339,
     0x4bc5, 0x53ef, 0x73ef, 0x73ef, 0x73ef, 0x73ef, 0x11ef, 0xe7dc,
     0x20cb, 0xc0c2, 0x40b2, 0xe0a9, 0xe0b1, 0xe0b1, 0xc0d3, 0xc0ec,
     0x20d4, 0xc059, 0x2000, 0xffff, 0x6108, 0x42a3, 0x4de6, 0x73ef,
     0x73ef, 0x73ef, 0x11ef, 0x06e5, 0x60d3, 0xc0c2, 0x60ba, 0x00b2,
     0x20b2, 0xa0c2, 0x60ba, 0xe0c2, 0xc0ec, 0xc0ec, 0xc0ec, 0x20d4,
     0x0000, 0xffff, 0x4108, 0xa09a, 0xc0db, 0xa4dc, 0x6eee, 0x06e5,
     0xa0d3, 0x40cb, 0xe0c2, 0x60ba, 0x00b2, 0xe0a9, 0xe0a9, 0xe0a9,
     0x00b2, 0xc0c2, 0xe0db, 0xa0d3, 0x80cb, 0x20bb, 0x2000, 0xffff,
     0x4108, 0xa09a, 0xc0db, 0xc0db, 0xc0db, 0xa0db, 0x40cb, 0xe0c2,
     0x80ba, 0x00b2, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9,
     0x60b2, 0xa099, 0xa099, 0x009a, 0x2000, 0xffff, 0x4008, 0xc09a,
     0xc0db, 0xc0db, 0xc0db, 0x40cb, 0xe0c2, 0x80ba, 0x20b2, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0x60b2, 0xa099,
     0xa099, 0xe099, 0x2000, 0xffff, 0x2008, 0xc09a, 0xc0db, 0xc0db,
     0xc0db, 0xe0c2, 0x80ba, 0x20b2, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0x60b2, 0xa099, 0xa099, 0xe099,
     0x4008, 0xffff, 0x2000, 0xc09a, 0xc0db, 0xc0db, 0xa0db, 0x80ba,
     0x20b2, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0x60b2, 0xa099, 0xa099, 0xe099, 0x4008, 0xffff,
     0x2000, 0xc0a2, 0xc0db, 0xc0db, 0xa0d3, 0x20b2, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9,
     0x60b2, 0xa099, 0xa099, 0xe099, 0x4108, 0xffff, 0x2000, 0xc0a2,
     0xc0db, 0xa0d3, 0xc0c2, 0xa0ba, 0x00b2, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9, 0x00b2, 0xc0c2, 0x60ba, 0x20b2,
     0x80ba, 0x80aa, 0x4108, 0xffff, 0x0000, 0xa0a2, 0x80ba, 0xe0a9,
     0xc0a9, 0xc0a9, 0x40b2, 0xa0ba, 0x00b2, 0xe0a9, 0xe0a9, 0xe0a9,
     0x00b2, 0xe0c2, 0x40cb, 0xe0c2, 0x60ba, 0x00b2, 0x00b2, 0x60aa,
     0x6108, 0xffff, 0x8110, 0xc028, 0x009a, 0xe0a9, 0xc0a9, 0xc0a9,
     0xc0a9, 0xc0a9, 0x60b2, 0xa0ba, 0x00b2, 0xe0c2, 0x20dc, 0x20dc,
     0xa0d3, 0x40cb, 0xc0c2, 0x60ba, 0x20a2, 0xe030, 0xa218, 0xffff,
     0x9ef7, 0x1084, 0x6110, 0xc028, 0x009a, 0xe0a9, 0xc0a9, 0xc0a9,
     0xc0a9, 0xc0a9, 0x20cb, 0x20e4, 0xa0ec, 0x60e4, 0x00dc, 0x80d3,
     0xe0b2, 0xe030, 0x4108, 0xcf7b, 0x5def, 0xffff, 0xffff, 0xffff,
     0x9ef7, 0x1084, 0x8110, 0xa028, 0x009a, 0xe0a9, 0xc0a9, 0xc0a9,
     0x60cb, 0xe0db, 0x40e4, 0xa0ec, 0x80bb, 0x0031, 0x4108, 0xcf7b,
     0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x9ef7, 0x3084, 0x8110, 0xa028, 0x009a, 0x00aa, 0xc0db, 0x80d3,
     0x40bb, 0x0031, 0x4108, 0xcf7b, 0x5def, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x9ef7, 0x3084, 0x8110, 0x8020, 0xe069, 0xc028, 0x4108, 0xcf7b,
     0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x9ef7, 0x518c, 0xe320, 0xcf7b, 0x5def, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* purple jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x1084, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6,
     0x0000, 0x18c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe739, 0x0000, 0xe739,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x18c6, 0x0000, 0xb4a0, 0x0000, 0x18c6, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xe739, 0xee70, 0xb9c8, 0x0b58, 0xe739, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6, 0x0000, 0x5ce2,
     0xb8c0, 0x14a0, 0x0000, 0x18c6, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xe739, 0x0e71, 0xdef2, 0xb8c0, 0x14a0,
     0x0a50, 0xe739, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x18c6, 0x0000, 0x5ce2, 0xdef2, 0xb8b8, 0x1398, 0x1288, 0x0000,
     0x18c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe739, 0x0e71,
     0xdef2, 0x9ef2, 0x56b0, 0x1390, 0x1188, 0x0948, 0xe739, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0x18c6, 0x0000, 0x5ce2, 0xdef2, 0x5ad1,
     0x36b0, 0x14a0, 0x1080, 0x0f78, 0x0000, 0x18c6, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xe739, 0x0e71, 0xdef2, 0x7dea, 0x36b0, 0x36b0, 0x36b0,
     0x1080, 0x0e68, 0x0948, 0xe739, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6, 0x0000,
     0x5ce2, 0xdef2, 0x39c9, 0x36b0, 0x36b0, 0x36b0, 0x1398, 0x0f70,
     0x1080, 0x0000, 0x18c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xe739, 0x0e71, 0xdef2, 0x5dea,
     0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x1080, 0x1188, 0x0a50,
     0xe739, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x18c6, 0x0000, 0x5ce2, 0xdef2, 0xf9c0, 0x36b0, 0x36b0,
     0x36b0, 0x36b0, 0x36b0, 0x14a0, 0x1288, 0x1390, 0x0000, 0x18c6,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe739,
     0x0e71, 0xdef2, 0x3ce2, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0,
     0x36b0, 0x36b0, 0x1398, 0x15a0, 0x0a50, 0xe739, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x18c6, 0x0000, 0x5ce2, 0xdef2,
     0xd8c0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0,
     0x16b0, 0x16a8, 0x15a8, 0x0000, 0x18c6, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xe739, 0x0e71, 0xdef2, 0x1ce2, 0x36b0, 0x36b0,
     0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x36b0, 0x16b0,
     0x18b8, 0x0c60, 0xe739, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6,
     0x0000, 0x5ce2, 0xdef2, 0x97b8, 0x35a8, 0x35a8, 0x36a8, 0x36b0,
     0x36b0, 0x36b0, 0x37b8, 0x37b8, 0x37b8, 0x17b8, 0x19c8, 0x19c8,
     0x0000, 0x18c6, 0xffff, 0xffff, 0xffff, 0xe739, 0x0e71, 0xdad1,
     0x3078, 0x0e68, 0x0e68, 0x0e68, 0x1078, 0x1290, 0x14a0, 0x17b8,
     0x19c8, 0x1ad0, 0x1ad0, 0x1ad0, 0x19c8, 0x1ad0, 0x0c60, 0xe739,
     0xffff, 0xffff, 0x18c6, 0x0000, 0x8f78, 0x0f70, 0x0f70, 0x0f70,
     0x0f70, 0x0f70, 0x0f70, 0x1080, 0x1290, 0x1398, 0x15a8, 0x17b8,
     0x17b8, 0x17b8, 0x17b8, 0x17b8, 0x1290, 0x0000, 0x18c6, 0xffff,
     0x0842, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0842, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
     /* red jewel */
    {0xffff, 0xffff, 0x59ce, 0x6110, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x4108, 0x18c6, 0xffff, 0xffff, 0xffff, 0xffff, 0x59ce,
     0x6108, 0x2010, 0x00a0, 0x0098, 0x0090, 0x2090, 0x2088, 0x2080,
     0x2078, 0x2078, 0x2070, 0x2070, 0x4068, 0x4068, 0x4060, 0x0018,
     0x4108, 0x18c6, 0xffff, 0xffff, 0x38c6, 0x4108, 0x2010, 0x2090,
     0x00f8, 0x00f0, 0x00d8, 0x20c8, 0x20b0, 0x40a0, 0x4090, 0x6078,
     0x6078, 0x6078, 0x6078, 0x6078, 0x6078, 0x4078, 0x2018, 0x4108,
     0x18c6, 0xffff, 0x4108, 0x0018, 0x2098, 0x20b8, 0x00f8, 0x00f8,
     0x00f0, 0x00e0, 0x20c8, 0x20b8, 0x40a8, 0x4090, 0x6080, 0x6080,
     0x6080, 0x6078, 0x6078, 0x4098, 0x20a0, 0x0020, 0x4108, 0xffff,
     0x0000, 0x2098, 0x40e0, 0x40e0, 0xa8e1, 0x4bea, 0x4bf2, 0x4bf2,
     0x4bea, 0x6be2, 0x66c9, 0x40b0, 0x81c0, 0x81b8, 0x81b0, 0x81b0,
     0x81b8, 0x00e8, 0x00e8, 0x00a8, 0x0000, 0xffff, 0x0000, 0x20a0,
     0x40e0, 0x40e0, 0x09ea, 0xeef2, 0xeeea, 0xeeea, 0xeee2, 0xeeda,
     0xc8c1, 0x40a0, 0xa2c0, 0xa2c0, 0xa2c0, 0x82c8, 0x82d0, 0x00d8,
     0x00d8, 0x00a0, 0x0000, 0xffff, 0x0000, 0x20a0, 0x40e0, 0x40e0,
     0x09f2, 0xeeea, 0xeeea, 0xeee2, 0xeeda, 0xeeda, 0xc8b9, 0x6098,
     0xa2c0, 0xa2c0, 0x82c8, 0x82d0, 0x82d8, 0x20d0, 0x20d0, 0x00a0,
     0x0000, 0xffff, 0x0000, 0x20a8, 0x40e0, 0x40e0, 0x09f2, 0xeeea,
     0xeee2, 0xeeda, 0xeeda, 0x0ed3, 0xc8b1, 0x6088, 0xa2c0, 0x82c8,
     0x82d0, 0x82d8, 0x82d8, 0x20c0, 0x20c0, 0x00a0, 0x0000, 0xffff,
     0x0000, 0x20a8, 0x40e0, 0x40e0, 0x09e2, 0xeee2, 0xeeda, 0xeeda,
     0x0ed3, 0x0ecb, 0xc8a1, 0x6090, 0x82c8, 0x82d0, 0x82d8, 0x82d8,
     0x82e0, 0x20b8, 0x20b0, 0x2090, 0x0000, 0xffff, 0x0000, 0x20b0,
     0x40e0, 0x40e0, 0x09da, 0xeeda, 0xeed2, 0x0ed3, 0x0ecb, 0x0ec3,
     0xc8b1, 0x40a0, 0x82d0, 0x82d8, 0x82d8, 0x82e0, 0x82e8, 0x20a8,
     0x40a8, 0x2088, 0x0000, 0xffff, 0x0000, 0x20a8, 0x40e0, 0x40e0,
     0x45c9, 0xc8c1, 0xc8b9, 0xc8b1, 0xc8a1, 0xc8b1, 0xc7b9, 0xc8c1,
     0x66d9, 0x66d9, 0x66e1, 0x66e9, 0x66f1, 0x4098, 0x4098, 0x2078,
     0x0000, 0xffff, 0x0000, 0x20a8, 0x40e0, 0x40e0, 0x40a8, 0x40a0,
     0x6090, 0x6080, 0x6090, 0x40a0, 0xe9c9, 0xd3e3, 0xd3eb, 0xd3eb,
     0xd3eb, 0xd3eb, 0xd3eb, 0x4090, 0x4088, 0x2070, 0x0000, 0xffff,
     0x0000, 0x20a0, 0x40e0, 0x40e0, 0x61b0, 0x82b8, 0x82b8, 0x82c0,
     0x82c8, 0x82d0, 0xa8d9, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb,
     0xd3eb, 0x6080, 0x6078, 0x4068, 0x0000, 0xffff, 0x0000, 0x20a0,
     0x40e0, 0x40e0, 0x81a8, 0x82b8, 0x82c0, 0x82c8, 0x82d0, 0x82d8,
     0xa8e1, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0x4088,
     0x4088, 0x2068, 0x0000, 0xffff, 0x0000, 0x2098, 0x40e0, 0x40e0,
     0x81a0, 0x82c0, 0x82c8, 0x82d0, 0x82d8, 0x62e0, 0xa8e9, 0xd3eb,
     0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3e3, 0x4098, 0x4098, 0x2068,
     0x0000, 0xffff, 0x0000, 0x2098, 0x40e0, 0x40e0, 0x61a8, 0x82c8,
     0x82d0, 0x82d8, 0x62e0, 0x62e8, 0xa8f1, 0xd3eb, 0xd3eb, 0xd3eb,
     0xd3eb, 0xd3e3, 0xd3e3, 0x40a0, 0x40a8, 0x2070, 0x0000, 0xffff,
     0x0000, 0x2090, 0x40e0, 0x40e0, 0x61b8, 0x82d0, 0x82d8, 0x62e0,
     0x62e8, 0x62f0, 0xa8f1, 0xd3eb, 0xd3eb, 0xd3eb, 0xd3e3, 0xd3e3,
     0xd3e3, 0x40b0, 0x20b0, 0x2078, 0x0000, 0xffff, 0x8210, 0x2010,
     0x4080, 0x40a0, 0x00f8, 0x00f8, 0x00f8, 0x20d0, 0x40a8, 0x6080,
     0x6078, 0x6078, 0x6078, 0x6078, 0x6078, 0x6078, 0x6078, 0x6080,
     0x4080, 0x0010, 0x6110, 0xffff, 0x79ce, 0x6110, 0x2010, 0x2098,
     0x00f8, 0x00f8, 0x00f8, 0x00e8, 0x20c0, 0x4090, 0x6078, 0x6078,
     0x6078, 0x6078, 0x6078, 0x6078, 0x6078, 0x4080, 0x0018, 0x6108,
     0x59ce, 0xffff, 0xffff, 0x79ce, 0x6110, 0x0018, 0x00b0, 0x00b8,
     0x00b8, 0x00b8, 0x00a0, 0x2088, 0x2070, 0x4068, 0x4068, 0x4060,
     0x4060, 0x4060, 0x4060, 0x0018, 0x4108, 0x59ce, 0xffff, 0xffff,
     0xffff, 0xffff, 0x79ce, 0x8210, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x4108, 0x38c6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
     /* yellow jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xfbde, 0xe739, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xe318,
     0xe018, 0xe318, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xfbde, 0xe318, 0x2463, 0x46ad, 0xc039,
     0xe318, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xfbde, 0xe318, 0x8573, 0xedde, 0x87b5, 0xe083, 0xc039, 0xe318,
     0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xe318, 0x8573,
     0x4de7, 0x2de7, 0xe7bd, 0x408c, 0xe07b, 0xc039, 0xe318, 0xfbde,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xfbde, 0xc318, 0x456b, 0x0ddf, 0x2de7, 0x4de7,
     0x47c6, 0xc09c, 0x408c, 0xe07b, 0xc039, 0xe318, 0xfbde, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde,
     0xe318, 0x456b, 0x4ee7, 0x6eef, 0x6eef, 0x6eef, 0x28df, 0xa1d6,
     0x20a5, 0x408c, 0xe07b, 0xc039, 0xe318, 0xfbde, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xe318, 0xa573, 0x0ddf,
     0x6eef, 0x8eef, 0x8eef, 0x8eef, 0x48e7, 0x20c6, 0x40ad, 0xc09c,
     0x408c, 0x8094, 0x2063, 0xe318, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xfbde, 0xe318, 0xa573, 0x4de7, 0x2de7, 0x6eef, 0x8eef,
     0x8eef, 0x8eef, 0xc4b5, 0x60ad, 0xe0bd, 0x40ad, 0x40ad, 0x80d6,
     0x80d6, 0x406b, 0xe318, 0xfbde, 0xffff, 0xffff, 0xfbde, 0xe318,
     0x656b, 0x0ddf, 0x2de7, 0x4de7, 0x6eef, 0x8eef, 0x8eef, 0xc4b5,
     0x8094, 0x8094, 0x60ad, 0x20c6, 0xe0de, 0xe0de, 0xa0d6, 0xa0d6,
     0x406b, 0xe318, 0xfbde, 0xffff, 0xc739, 0x0121, 0x47ad, 0xa7b5,
     0xe7bd, 0x47ce, 0x28e7, 0x48e7, 0xe4bd, 0x8094, 0x8094, 0x8094,
     0x20a5, 0xc0d6, 0xe0de, 0xc0de, 0xc0d6, 0xa0d6, 0x80ce, 0x8031,
     0xe739, 0xffff, 0xbad6, 0xa210, 0xc039, 0xc07b, 0x408c, 0xc09c,
     0xc1d6, 0x20c6, 0x60ad, 0x8094, 0x8094, 0xe09c, 0xa0d6, 0xe0de,
     0x00df, 0x00e7, 0x00df, 0xc0de, 0x406b, 0xe318, 0xfbde, 0xffff,
     0xffff, 0xdbde, 0xa210, 0xc039, 0xc07b, 0x408c, 0x40ad, 0x60ad,
     0xe0bd, 0x60ad, 0x00a5, 0xa0d6, 0xa0d6, 0xc0d6, 0xe0de, 0x00df,
     0x20e7, 0x8073, 0xe318, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xdbde, 0xa210, 0xc039, 0xc07b, 0x408c, 0xc09c, 0x40ad, 0xe0bd,
     0xe0bd, 0x60ce, 0xc0d6, 0xa0d6, 0xc0d6, 0xc0de, 0x8073, 0xe318,
     0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdbde,
     0xc218, 0xc039, 0xc07b, 0x408c, 0x00a5, 0xc0bd, 0xe0bd, 0xe0bd,
     0x60ce, 0xc0d6, 0x80d6, 0x406b, 0xe318, 0xfbde, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdbde, 0xc218,
     0xc039, 0x208c, 0x60ad, 0xa0b5, 0xc0bd, 0xe0bd, 0xe0bd, 0x60ce,
     0x2063, 0xc318, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xc218, 0xc05a,
     0x60ad, 0x80b5, 0xa0b5, 0xc0bd, 0xe0bd, 0x0063, 0xe318, 0xfbde,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xc218, 0xc05a, 0x60ad,
     0x80b5, 0xa0b5, 0x0063, 0xe318, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xfbde, 0xc218, 0xe05a, 0x60ad, 0xe05a,
     0xe318, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xfbde, 0xe218, 0x2021, 0xe318, 0xfbde, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xfbde, 0xe739, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* green jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0xc631, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2421,
     0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x9ef7, 0xc631, 0xa63a, 0x6756, 0x4546, 0x4546, 0x4546,
     0x4546, 0x4546, 0x4546, 0x4546, 0x4546, 0x0533, 0x4421, 0x5def,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0xc631,
     0xa63a, 0xb9d7, 0x4967, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f,
     0x254f, 0x254f, 0x254f, 0x4c77, 0x063b, 0x4421, 0x5def, 0xffff,
     0xffff, 0xffff, 0xffff, 0x9ef7, 0xc631, 0xa63a, 0xb9d7, 0xdadf,
     0x485f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f,
     0x254f, 0x485f, 0x4d87, 0x063b, 0x6421, 0x7def, 0xffff, 0xffff,
     0x9ef7, 0xc631, 0xa63a, 0xb9d7, 0xdadf, 0xb5bf, 0x4757, 0x254f,
     0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f,
     0x4a67, 0x6f8f, 0x063b, 0x6529, 0x7def, 0xffff, 0xc631, 0xa63a,
     0xb9d7, 0xdadf, 0xb6bf, 0x9097, 0x2657, 0x254f, 0x254f, 0x254f,
     0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x254f, 0x6b77,
     0x7197, 0x073b, 0x8529, 0xffff, 0x0000, 0x4756, 0x4967, 0x485f,
     0x475f, 0x2657, 0x0116, 0xc00d, 0xc00d, 0xa00d, 0x800d, 0x600d,
     0x400d, 0x000d, 0x010d, 0x0116, 0xc00d, 0xa00d, 0x6115, 0x4225,
     0x0000, 0xffff, 0x0000, 0x4446, 0x254f, 0x254f, 0x254f, 0x254f,
     0xc00d, 0xa005, 0x6005, 0x4005, 0x2005, 0x0005, 0xc004, 0xa004,
     0xa004, 0xc00d, 0xa005, 0x4005, 0xe004, 0xe00c, 0x0000, 0xffff,
     0x0000, 0x243e, 0x254f, 0x254f, 0x254f, 0x254f, 0xc00d, 0x8005,
     0x4005, 0x2005, 0x0005, 0xc004, 0xa004, 0x8004, 0x8004, 0xc00d,
     0x6005, 0x0005, 0xc004, 0xc00c, 0x0000, 0xffff, 0x2000, 0x243e,
     0x254f, 0x254f, 0x254f, 0x254f, 0xa00d, 0x4005, 0x2005, 0x0005,
     0xc004, 0xa004, 0x8004, 0x6004, 0x6004, 0xc00d, 0x4005, 0xe004,
     0x8004, 0x800c, 0x0000, 0xffff, 0x2000, 0x043e, 0x254f, 0x254f,
     0x254f, 0x254f, 0x800d, 0x2005, 0x0005, 0xe004, 0xa004, 0x8004,
     0x6004, 0x2004, 0x4004, 0x800d, 0x0005, 0xa004, 0x4004, 0x600c,
     0x0000, 0xffff, 0x4000, 0x043e, 0x254f, 0x254f, 0x254f, 0x254f,
     0x600d, 0x0005, 0xe004, 0xa004, 0x8004, 0x6004, 0x2004, 0x0004,
     0x0004, 0x600d, 0xe004, 0x8004, 0x2004, 0x400c, 0x0000, 0xffff,
     0x4000, 0x043e, 0x254f, 0x254f, 0x254f, 0x254f, 0x400d, 0xe004,
     0xa004, 0x8004, 0x6004, 0x4004, 0x0004, 0xe003, 0xe003, 0x400d,
     0xa004, 0x4004, 0xe003, 0x200c, 0x0000, 0xffff, 0x4108, 0xe43d,
     0x254f, 0x254f, 0x254f, 0x254f, 0x200d, 0xa004, 0x8004, 0x6004,
     0x4004, 0x0004, 0xe003, 0xc003, 0xc003, 0x000d, 0x6004, 0x2004,
     0xc003, 0xe00b, 0x0000, 0xffff, 0x6108, 0xc545, 0x264f, 0x254f,
     0x254f, 0x254f, 0x611d, 0x010d, 0xe10c, 0xc10c, 0xa10c, 0x810c,
     0x610c, 0x410c, 0x4114, 0x6115, 0xc10c, 0x8114, 0x621c, 0x8324,
     0x0000, 0xffff, 0x4842, 0x252a, 0x2e87, 0x4a6f, 0x254f, 0x254f,
     0xe115, 0xc00d, 0xc00d, 0xc00d, 0x600d, 0x400d, 0x000d, 0xc004,
     0xa00c, 0x254f, 0x4657, 0x6b77, 0x4f8f, 0x6532, 0xc631, 0xffff,
     0xbef7, 0x073a, 0x6532, 0x4f8f, 0x4a6f, 0x254f, 0xc00d, 0xa005,
     0xa005, 0x6005, 0x2005, 0xe004, 0xa004, 0x6004, 0x4004, 0x254f,
     0x4a6f, 0x4e87, 0x8532, 0xa631, 0x9ef7, 0xffff, 0xffff, 0xbef7,
     0xe639, 0x8632, 0x5097, 0x6b77, 0xc00d, 0xa005, 0x6005, 0x2005,
     0xe004, 0xa004, 0x4004, 0x0004, 0x0004, 0x4967, 0x4d7f, 0xa532,
     0x8529, 0x9ef7, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0xc631,
     0xa63a, 0x7197, 0xc115, 0x6005, 0x2005, 0xe004, 0xa004, 0x4004,
     0x0004, 0xc003, 0xc003, 0x4c7f, 0xc532, 0x6529, 0x7def, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0xa531, 0xe73a,
     0xa225, 0x4015, 0x200d, 0xe00c, 0xa00c, 0x800c, 0x400c, 0x000c,
     0x2114, 0xe532, 0x4421, 0x5def, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x7def, 0x8529, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4421,
     0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff}
};

/* use 22x22 tiles */
#elif (LCD_HEIGHT >= 176) && (LCD_WIDTH >= 220) && \
      (LCD_PIXELFORMAT == RGB565)
/* size of a tile */
#define TILE_WIDTH  22
#define TILE_HEIGHT 22

/* playboard offset from top */
#define YOFS 0

/* number of high scores to save */
#define NUM_SCORES 10

/* bitmaps for the jewels */
static unsigned short jewel[8][506] = {
    /* empty */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* white jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xbdf7, 0x39e7, 0x39e7, 0xbdf7, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xbdd7, 0x39c7, 0x0841, 0x8410,
     0x632c, 0x0841, 0x39c7, 0xbdf7, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xbdd7, 0x31a6, 0x0861, 0x8410, 0xce59, 0xce79, 0x8c71, 0x9492,
     0x6b4d, 0x0841, 0x31a6, 0xbdd7, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xf7be, 0x31a6, 0x0861, 0x8410,
     0xce59, 0xce79, 0xce79, 0xce79, 0x8c71, 0x8c71, 0x8c71, 0x9492,
     0x6b6d, 0x0861, 0x39e7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x9cf3, 0x2965, 0xce59, 0xd6ba, 0xd6ba, 0xd6ba,
     0xd6ba, 0xd6ba, 0x94b2, 0x9cd3, 0xa514, 0xad55, 0xb596, 0xad55,
     0x0861, 0xb596, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x2945, 0x9cd3, 0xe71c, 0xe71c, 0xe71c, 0xe71c, 0xe71c, 0xe71c,
     0xa514, 0x9cd3, 0x9cd3, 0xa534, 0xb596, 0xbdf7, 0x5acb, 0x39e7,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc618, 0x0861, 0xdefb,
     0xe73c, 0xef5d, 0xef5d, 0xef5d, 0xe73c, 0xe73c, 0xad75, 0xa534,
     0x9cf3, 0x9cf3, 0xad55, 0xb5b6, 0xad75, 0x0020, 0xce79, 0xffff,
     0xffff, 0xffff, 0xffff, 0x528a, 0x7bcf, 0xef5d, 0xe73c, 0xe73c,
     0xe73c, 0xe73c, 0xe73c, 0xef5d, 0xbdd7, 0xb596, 0xa534, 0x9cd3,
     0x9cf3, 0xad75, 0xbdd7, 0x5acb, 0x5aeb, 0xffff, 0xffff, 0xffff,
     0xe71c, 0x0020, 0xd69a, 0xe73c, 0xe71c, 0xe71c, 0xdefb, 0xe71c,
     0xe71c, 0xe73c, 0xbdf7, 0xbdd7, 0xad75, 0xa514, 0x9cd3, 0xa534,
     0xb5b6, 0xb595, 0x0020, 0xef5d, 0xffff, 0xffff, 0x7bcf, 0x528a,
     0xe73c, 0xe71c, 0xdefb, 0xdefb, 0xdedb, 0xdedb, 0xdefb, 0xe71c,
     0xb5b6, 0xc618, 0xb5b6, 0xad55, 0xbdf7, 0xa534, 0xb5b6, 0xb5b6,
     0x4a69, 0x7bef, 0xffff, 0xffff, 0x18c3, 0x94b2, 0xd69a, 0xce59,
     0xc618, 0xc638, 0xc638, 0xc638, 0xc618, 0xc638, 0xc618, 0xce59,
     0xce79, 0xc618, 0xdedb, 0xc638, 0xb595, 0xb5d6, 0x8c51, 0x18c3,
     0xffff, 0xffff, 0x632c, 0x4208, 0xad75, 0x9cf3, 0x9cf3, 0xad55,
     0xb596, 0xad75, 0xa514, 0x9cd3, 0xdefb, 0xe73c, 0xef5d, 0xe71c,
     0xef9d, 0xdedb, 0xb596, 0xbdd7, 0x4228, 0x630c, 0xffff, 0xffff,
     0xdedb, 0x0020, 0x9492, 0x9cd3, 0xa514, 0xb596, 0xbdf7, 0xb5b6,
     0xa534, 0x94b2, 0xdefb, 0xe73c, 0xef5d, 0xe73c, 0xef5d, 0xd6da,
     0xc658, 0xa534, 0x0020, 0xd69a, 0xffff, 0xffff, 0xffff, 0x528a,
     0x4228, 0x9cf3, 0x9cf3, 0xad75, 0xb5b6, 0xb596, 0xa534, 0x94b2,
     0xdefb, 0xe73c, 0xef5d, 0xef5d, 0xdefb, 0xd6da, 0xd6da, 0x73ae,
     0x4208, 0xffff, 0xffff, 0xffff, 0xffff, 0xc638, 0x0020, 0x94b2,
     0x9cd3, 0xa514, 0xad55, 0xa534, 0x9cf3, 0x9cf3, 0xdefb, 0xe73c,
     0xe73c, 0xe73c, 0xd6da, 0xd6da, 0xd6ba, 0x18c3, 0xb5b6, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x39c7, 0x528a, 0x9cf3, 0x94b2,
     0x9cd3, 0x9cd3, 0x9cf3, 0xa534, 0xdefb, 0xef5d, 0xe73c, 0xdefb,
     0xd6da, 0xd6da, 0xa534, 0x2124, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xb596, 0x0861, 0x94b2, 0xa534, 0xa514, 0xa514,
     0xad55, 0xb596, 0xd6ba, 0xdedb, 0xd6ba, 0xd6da, 0xd6da, 0xce99,
     0x31a6, 0x94b2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x4a69, 0x0020, 0x4228, 0x94b2, 0xb596, 0xb5b6, 0xbdf7,
     0xbdf7, 0xc618, 0xd6ba, 0xce99, 0x8c71, 0x1082, 0x31a6, 0xf7be,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xce59, 0x4a49, 0x0000, 0x4228, 0xa514, 0xbdd7, 0xb5b6, 0xce99,
     0x8c71, 0x1082, 0x3186, 0xb5b6, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xce59, 0x4a49, 0x0000, 0x39c7, 0x4a69, 0x0861, 0x3186, 0xb596,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xce79, 0x4a69, 0x2965, 0xb596, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* blue jewel */
    {0xffff, 0xffff, 0xffff, 0xffdf, 0x4a8a, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x29a6, 0xf79e, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffdf, 0x4a6a, 0x01a8, 0x3e5e, 0x66bf, 0x6edf, 0x76df, 0x7eff,
     0x86ff, 0x8f1f, 0x971f, 0x9f3f, 0x9f3f, 0x971f, 0x1b2f, 0x31c7,
     0xf7be, 0xffff, 0xffff, 0xffff, 0xffff, 0xffdf, 0x4a69, 0x01c9,
     0x66df, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf7ff, 0xe7df, 0xd7bf, 0xc79f, 0x971f, 0x0a8c, 0x3a08, 0xf7be,
     0xffff, 0xffff, 0xffdf, 0x4249, 0x01e9, 0x7eff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xefdf, 0xdfbf, 0xcf9f,
     0xbf7f, 0xaf5f, 0x9f5f, 0x5ebf, 0x020a, 0x4249, 0xffdf, 0xffff,
     0x4a69, 0x01c9, 0x263f, 0x871f, 0x8f1f, 0x8f1f, 0x973f, 0x9f3f,
     0x9f3f, 0x9f3f, 0x973f, 0x971f, 0x8f1f, 0x86ff, 0x7eff, 0x76ff,
     0x66df, 0x5ebf, 0x1e3f, 0x09c9, 0x528a, 0xffff, 0x8430, 0x0147,
     0x05de, 0x061f, 0x061f, 0x061f, 0x061f, 0x061f, 0x061f, 0x061f,
     0x05be, 0x0376, 0x0376, 0x0376, 0x1438, 0x665e, 0x7ebe, 0x9f1f,
     0xb75f, 0x224b, 0x73af, 0xffff, 0xffff, 0x31e7, 0x0371, 0x05de,
     0x05ff, 0x0e3f, 0x871f, 0x061f, 0x061f, 0x061f, 0x05be, 0x0376,
     0x0376, 0x0376, 0x2d5c, 0x66df, 0x7eff, 0x973f, 0x4cf7, 0x2165,
     0xffdf, 0xffff, 0xffff, 0xdefb, 0x0862, 0x04fa, 0x05be, 0x86ff,
     0xc79f, 0x1e5f, 0x061f, 0x061f, 0x05be, 0x0376, 0x0376, 0x0376,
     0x2e3f, 0x4ebf, 0x66df, 0x5e3d, 0x0021, 0xce79, 0xffff, 0xffff,
     0xffff, 0xffff, 0xa514, 0x00a3, 0x563d, 0xcf9f, 0xbf9f, 0x5e9f,
     0x061f, 0x061f, 0x05be, 0x0376, 0x0376, 0x0419, 0x1e5f, 0x367f,
     0x467f, 0x11e9, 0x7c10, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x4a8a, 0x2b50, 0xc77f, 0xbf7f, 0x971f, 0x05be, 0x05ff,
     0x05be, 0x0376, 0x0376, 0x04fb, 0x063f, 0x1e5f, 0x1456, 0x2986,
     0xffdf, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xef7d,
     0x10c3, 0x5dba, 0xb77f, 0xa75f, 0x1dbd, 0x059d, 0x059d, 0x0376,
     0x0376, 0x05de, 0x061f, 0x057d, 0x0041, 0xd6ba, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbdd7, 0x0041,
     0x86de, 0xa75f, 0x4e3e, 0x055c, 0x055d, 0x0376, 0x0418, 0x061f,
     0x05ff, 0x0188, 0x8c51, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6b6d, 0x1a4b, 0x971f,
     0x7edf, 0x051b, 0x053c, 0x0376, 0x04fb, 0x061f, 0x03f5, 0x31c7,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xf7be, 0x2145, 0x3cd7, 0x8f1f, 0x153b,
     0x051b, 0x0376, 0x05de, 0x055c, 0x0041, 0xdedb, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xce79, 0x0021, 0x5e3d, 0x3ddc, 0x04db, 0x03f8,
     0x05ff, 0x0147, 0x94b2, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x8c51, 0x0967, 0x5e5e, 0x049a, 0x04db, 0x03b4, 0x3a08,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x39e8, 0x23d3, 0x14fa, 0x04da, 0x0862, 0xe71c, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xe71c, 0x0862,
     0x0bf5, 0x0105, 0x9cf3, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xa514, 0x0000, 0x4249,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x6b4d, 0xe73c, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* orange jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf7be, 0x8c71, 0x20e3, 0x632c, 0xe71c, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xf79e, 0x8c51, 0x1082, 0x20e1,
     0x9304, 0x4100, 0x0020, 0x632c, 0xdefb, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf79e, 0x8430, 0x1081, 0x2902, 0xbcea, 0xef32, 0xcc67, 0xa9e0,
     0xa220, 0x4100, 0x0020, 0x630c, 0xdefb, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xef7d, 0x7bef, 0x1061, 0x3122,
     0xbd0a, 0xef52, 0xef73, 0xef73, 0xcc46, 0xa9e0, 0xa9e0, 0xa9e0,
     0xa220, 0x4100, 0x0020, 0x630c, 0xdefb, 0xffff, 0xffff, 0xffff,
     0xef7d, 0x7bcf, 0x0861, 0x3142, 0xc52a, 0xef52, 0xef73, 0xef73,
     0xef73, 0xef73, 0xcc26, 0xa9e0, 0xa9e0, 0xa9e0, 0xb240, 0xa9c0,
     0xb2c0, 0x59a0, 0x0020, 0x630b, 0xdefb, 0xffff, 0x18a2, 0x3963,
     0xc54b, 0xef53, 0xef73, 0xef73, 0xef73, 0xef73, 0xef11, 0xdce7,
     0xcb20, 0xc2c0, 0xb240, 0xa9e0, 0xb1e0, 0xb1e0, 0xd3c0, 0xecc0,
     0xd420, 0x59c0, 0x0020, 0xffff, 0x0861, 0xa342, 0xe64d, 0xef73,
     0xef73, 0xef73, 0xef11, 0xe506, 0xd360, 0xc2c0, 0xba60, 0xb200,
     0xb220, 0xc2a0, 0xba60, 0xc2e0, 0xecc0, 0xecc0, 0xecc0, 0xd420,
     0x0000, 0xffff, 0x0841, 0x9aa0, 0xdbc0, 0xdca4, 0xee6e, 0xe506,
     0xd3a0, 0xcb40, 0xc2e0, 0xba60, 0xb200, 0xa9e0, 0xa9e0, 0xa9e0,
     0xb200, 0xc2c0, 0xdbe0, 0xd3a0, 0xcb80, 0xbb20, 0x0020, 0xffff,
     0x0841, 0x9aa0, 0xdbc0, 0xdbc0, 0xdbc0, 0xdba0, 0xcb40, 0xc2e0,
     0xba80, 0xb200, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0,
     0xb260, 0x99a0, 0x99a0, 0x9a00, 0x0020, 0xffff, 0x0840, 0x9ac0,
     0xdbc0, 0xdbc0, 0xdbc0, 0xcb40, 0xc2e0, 0xba80, 0xb220, 0xa9e0,
     0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xb260, 0x99a0,
     0x99a0, 0x99e0, 0x0020, 0xffff, 0x0820, 0x9ac0, 0xdbc0, 0xdbc0,
     0xdbc0, 0xc2e0, 0xba80, 0xb220, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0,
     0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xb260, 0x99a0, 0x99a0, 0x99e0,
     0x0840, 0xffff, 0x0020, 0x9ac0, 0xdbc0, 0xdbc0, 0xdba0, 0xba80,
     0xb220, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0,
     0xa9e0, 0xa9e0, 0xb260, 0x99a0, 0x99a0, 0x99e0, 0x0840, 0xffff,
     0x0020, 0xa2c0, 0xdbc0, 0xdbc0, 0xd3a0, 0xb220, 0xa9e0, 0xa9e0,
     0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0,
     0xb260, 0x99a0, 0x99a0, 0x99e0, 0x0841, 0xffff, 0x0020, 0xa2c0,
     0xdbc0, 0xd3a0, 0xc2c0, 0xbaa0, 0xb200, 0xa9e0, 0xa9e0, 0xa9e0,
     0xa9e0, 0xa9e0, 0xa9e0, 0xa9e0, 0xb200, 0xc2c0, 0xba60, 0xb220,
     0xba80, 0xaa80, 0x0841, 0xffff, 0x0000, 0xa2a0, 0xba80, 0xa9e0,
     0xa9c0, 0xa9c0, 0xb240, 0xbaa0, 0xb200, 0xa9e0, 0xa9e0, 0xa9e0,
     0xb200, 0xc2e0, 0xcb40, 0xc2e0, 0xba60, 0xb200, 0xb200, 0xaa60,
     0x0861, 0xffff, 0x1081, 0x28c0, 0x9a00, 0xa9e0, 0xa9c0, 0xa9c0,
     0xa9c0, 0xa9c0, 0xb260, 0xbaa0, 0xb200, 0xc2e0, 0xdc20, 0xdc20,
     0xd3a0, 0xcb40, 0xc2c0, 0xba60, 0xa220, 0x30e0, 0x18a2, 0xffff,
     0xf79e, 0x8410, 0x1061, 0x28c0, 0x9a00, 0xa9e0, 0xa9c0, 0xa9c0,
     0xa9c0, 0xa9c0, 0xcb20, 0xe420, 0xeca0, 0xe460, 0xdc00, 0xd380,
     0xb2e0, 0x30e0, 0x0841, 0x7bcf, 0xef5d, 0xffff, 0xffff, 0xffff,
     0xf79e, 0x8410, 0x1081, 0x28a0, 0x9a00, 0xa9e0, 0xa9c0, 0xa9c0,
     0xcb60, 0xdbe0, 0xe440, 0xeca0, 0xbb80, 0x3100, 0x0841, 0x7bcf,
     0xef5d, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf79e, 0x8430, 0x1081, 0x28a0, 0x9a00, 0xaa00, 0xdbc0, 0xd380,
     0xbb40, 0x3100, 0x0841, 0x7bcf, 0xef5d, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf79e, 0x8430, 0x1081, 0x2080, 0x69e0, 0x28c0, 0x0841, 0x7bcf,
     0xef5d, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xf79e, 0x8c51, 0x20e3, 0x7bcf, 0xef5d, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* purple jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x8410, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc618,
     0x0000, 0xc618, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x39e7, 0x0000, 0x39e7,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xc618, 0x0000, 0xa0b4, 0x0000, 0xc618, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0x39e7, 0x70ee, 0xc8b9, 0x580b, 0x39e7, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc618, 0x0000, 0xe25c,
     0xc0b8, 0xa014, 0x0000, 0xc618, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0x39e7, 0x710e, 0xf2de, 0xc0b8, 0xa014,
     0x500a, 0x39e7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xc618, 0x0000, 0xe25c, 0xf2de, 0xb8b8, 0x9813, 0x8812, 0x0000,
     0xc618, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x39e7, 0x710e,
     0xf2de, 0xf29e, 0xb056, 0x9013, 0x8811, 0x4809, 0x39e7, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xc618, 0x0000, 0xe25c, 0xf2de, 0xd15a,
     0xb036, 0xa014, 0x8010, 0x780f, 0x0000, 0xc618, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x39e7, 0x710e, 0xf2de, 0xea7d, 0xb036, 0xb036, 0xb036,
     0x8010, 0x680e, 0x4809, 0x39e7, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xc618, 0x0000,
     0xe25c, 0xf2de, 0xc939, 0xb036, 0xb036, 0xb036, 0x9813, 0x700f,
     0x8010, 0x0000, 0xc618, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x39e7, 0x710e, 0xf2de, 0xea5d,
     0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0x8010, 0x8811, 0x500a,
     0x39e7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xc618, 0x0000, 0xe25c, 0xf2de, 0xc0f9, 0xb036, 0xb036,
     0xb036, 0xb036, 0xb036, 0xa014, 0x8812, 0x9013, 0x0000, 0xc618,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x39e7,
     0x710e, 0xf2de, 0xe23c, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036,
     0xb036, 0xb036, 0x9813, 0xa015, 0x500a, 0x39e7, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xc618, 0x0000, 0xe25c, 0xf2de,
     0xc0d8, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036,
     0xb016, 0xa816, 0xa815, 0x0000, 0xc618, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x39e7, 0x710e, 0xf2de, 0xe21c, 0xb036, 0xb036,
     0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0xb036, 0xb016,
     0xb818, 0x600c, 0x39e7, 0xffff, 0xffff, 0xffff, 0xffff, 0xc618,
     0x0000, 0xe25c, 0xf2de, 0xb897, 0xa835, 0xa835, 0xa836, 0xb036,
     0xb036, 0xb036, 0xb837, 0xb837, 0xb837, 0xb817, 0xc819, 0xc819,
     0x0000, 0xc618, 0xffff, 0xffff, 0xffff, 0x39e7, 0x710e, 0xd1da,
     0x7830, 0x680e, 0x680e, 0x680e, 0x7810, 0x9012, 0xa014, 0xb817,
     0xc819, 0xd01a, 0xd01a, 0xd01a, 0xc819, 0xd01a, 0x600c, 0x39e7,
     0xffff, 0xffff, 0xc618, 0x0000, 0x788f, 0x700f, 0x700f, 0x700f,
     0x700f, 0x700f, 0x700f, 0x8010, 0x9012, 0x9813, 0xa815, 0xb817,
     0xb817, 0xb817, 0xb817, 0xb817, 0x9012, 0x0000, 0xc618, 0xffff,
     0x4208, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x4208, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* red jewel */
    {0xffff, 0xffff, 0xce59, 0x1061, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0841, 0xc618, 0xffff, 0xffff, 0xffff, 0xffff, 0xce59,
     0x0861, 0x1020, 0xa000, 0x9800, 0x9000, 0x9020, 0x8820, 0x8020,
     0x7820, 0x7820, 0x7020, 0x7020, 0x6840, 0x6840, 0x6040, 0x1800,
     0x0841, 0xc618, 0xffff, 0xffff, 0xc638, 0x0841, 0x1020, 0x9020,
     0xf800, 0xf000, 0xd800, 0xc820, 0xb020, 0xa040, 0x9040, 0x7860,
     0x7860, 0x7860, 0x7860, 0x7860, 0x7860, 0x7840, 0x1820, 0x0841,
     0xc618, 0xffff, 0x0841, 0x1800, 0x9820, 0xb820, 0xf800, 0xf800,
     0xf000, 0xe000, 0xc820, 0xb820, 0xa840, 0x9040, 0x8060, 0x8060,
     0x8060, 0x7860, 0x7860, 0x9840, 0xa020, 0x2000, 0x0841, 0xffff,
     0x0000, 0x9820, 0xe040, 0xe040, 0xe1a8, 0xea4b, 0xf24b, 0xf24b,
     0xea4b, 0xe26b, 0xc966, 0xb040, 0xc081, 0xb881, 0xb081, 0xb081,
     0xb881, 0xe800, 0xe800, 0xa800, 0x0000, 0xffff, 0x0000, 0xa020,
     0xe040, 0xe040, 0xea09, 0xf2ee, 0xeaee, 0xeaee, 0xe2ee, 0xdaee,
     0xc1c8, 0xa040, 0xc0a2, 0xc0a2, 0xc0a2, 0xc882, 0xd082, 0xd800,
     0xd800, 0xa000, 0x0000, 0xffff, 0x0000, 0xa020, 0xe040, 0xe040,
     0xf209, 0xeaee, 0xeaee, 0xe2ee, 0xdaee, 0xdaee, 0xb9c8, 0x9860,
     0xc0a2, 0xc0a2, 0xc882, 0xd082, 0xd882, 0xd020, 0xd020, 0xa000,
     0x0000, 0xffff, 0x0000, 0xa820, 0xe040, 0xe040, 0xf209, 0xeaee,
     0xe2ee, 0xdaee, 0xdaee, 0xd30e, 0xb1c8, 0x8860, 0xc0a2, 0xc882,
     0xd082, 0xd882, 0xd882, 0xc020, 0xc020, 0xa000, 0x0000, 0xffff,
     0x0000, 0xa820, 0xe040, 0xe040, 0xe209, 0xe2ee, 0xdaee, 0xdaee,
     0xd30e, 0xcb0e, 0xa1c8, 0x9060, 0xc882, 0xd082, 0xd882, 0xd882,
     0xe082, 0xb820, 0xb020, 0x9020, 0x0000, 0xffff, 0x0000, 0xb020,
     0xe040, 0xe040, 0xda09, 0xdaee, 0xd2ee, 0xd30e, 0xcb0e, 0xc30e,
     0xb1c8, 0xa040, 0xd082, 0xd882, 0xd882, 0xe082, 0xe882, 0xa820,
     0xa840, 0x8820, 0x0000, 0xffff, 0x0000, 0xa820, 0xe040, 0xe040,
     0xc945, 0xc1c8, 0xb9c8, 0xb1c8, 0xa1c8, 0xb1c8, 0xb9c7, 0xc1c8,
     0xd966, 0xd966, 0xe166, 0xe966, 0xf166, 0x9840, 0x9840, 0x7820,
     0x0000, 0xffff, 0x0000, 0xa820, 0xe040, 0xe040, 0xa840, 0xa040,
     0x9060, 0x8060, 0x9060, 0xa040, 0xc9e9, 0xe3d3, 0xebd3, 0xebd3,
     0xebd3, 0xebd3, 0xebd3, 0x9040, 0x8840, 0x7020, 0x0000, 0xffff,
     0x0000, 0xa020, 0xe040, 0xe040, 0xb061, 0xb882, 0xb882, 0xc082,
     0xc882, 0xd082, 0xd9a8, 0xebd3, 0xebd3, 0xebd3, 0xebd3, 0xebd3,
     0xebd3, 0x8060, 0x7860, 0x6840, 0x0000, 0xffff, 0x0000, 0xa020,
     0xe040, 0xe040, 0xa881, 0xb882, 0xc082, 0xc882, 0xd082, 0xd882,
     0xe1a8, 0xebd3, 0xebd3, 0xebd3, 0xebd3, 0xebd3, 0xebd3, 0x8840,
     0x8840, 0x6820, 0x0000, 0xffff, 0x0000, 0x9820, 0xe040, 0xe040,
     0xa081, 0xc082, 0xc882, 0xd082, 0xd882, 0xe062, 0xe9a8, 0xebd3,
     0xebd3, 0xebd3, 0xebd3, 0xebd3, 0xe3d3, 0x9840, 0x9840, 0x6820,
     0x0000, 0xffff, 0x0000, 0x9820, 0xe040, 0xe040, 0xa861, 0xc882,
     0xd082, 0xd882, 0xe062, 0xe862, 0xf1a8, 0xebd3, 0xebd3, 0xebd3,
     0xebd3, 0xe3d3, 0xe3d3, 0xa040, 0xa840, 0x7020, 0x0000, 0xffff,
     0x0000, 0x9020, 0xe040, 0xe040, 0xb861, 0xd082, 0xd882, 0xe062,
     0xe862, 0xf062, 0xf1a8, 0xebd3, 0xebd3, 0xebd3, 0xe3d3, 0xe3d3,
     0xe3d3, 0xb040, 0xb020, 0x7820, 0x0000, 0xffff, 0x1082, 0x1020,
     0x8040, 0xa040, 0xf800, 0xf800, 0xf800, 0xd020, 0xa840, 0x8060,
     0x7860, 0x7860, 0x7860, 0x7860, 0x7860, 0x7860, 0x7860, 0x8060,
     0x8040, 0x1000, 0x1061, 0xffff, 0xce79, 0x1061, 0x1020, 0x9820,
     0xf800, 0xf800, 0xf800, 0xe800, 0xc020, 0x9040, 0x7860, 0x7860,
     0x7860, 0x7860, 0x7860, 0x7860, 0x7860, 0x8040, 0x1800, 0x0861,
     0xce59, 0xffff, 0xffff, 0xce79, 0x1061, 0x1800, 0xb000, 0xb800,
     0xb800, 0xb800, 0xa000, 0x8820, 0x7020, 0x6840, 0x6840, 0x6040,
     0x6040, 0x6040, 0x6040, 0x1800, 0x0841, 0xce59, 0xffff, 0xffff,
     0xffff, 0xffff, 0xce79, 0x1082, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0841, 0xc638, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* yellow jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xdefb, 0x39e7, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdefb, 0x18e3,
     0x18e0, 0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xdefb, 0x18e3, 0x6324, 0xad46, 0x39c0,
     0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xdefb, 0x18e3, 0x7385, 0xdeed, 0xb587, 0x83e0, 0x39c0, 0x18e3,
     0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdefb, 0x18e3, 0x7385,
     0xe74d, 0xe72d, 0xbde7, 0x8c40, 0x7be0, 0x39c0, 0x18e3, 0xdefb,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xdefb, 0x18c3, 0x6b45, 0xdf0d, 0xe72d, 0xe74d,
     0xc647, 0x9cc0, 0x8c40, 0x7be0, 0x39c0, 0x18e3, 0xdefb, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdefb,
     0x18e3, 0x6b45, 0xe74e, 0xef6e, 0xef6e, 0xef6e, 0xdf28, 0xd6a1,
     0xa520, 0x8c40, 0x7be0, 0x39c0, 0x18e3, 0xdefb, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xdefb, 0x18e3, 0x73a5, 0xdf0d,
     0xef6e, 0xef8e, 0xef8e, 0xef8e, 0xe748, 0xc620, 0xad40, 0x9cc0,
     0x8c40, 0x9480, 0x6320, 0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff,
     0xffff, 0xdefb, 0x18e3, 0x73a5, 0xe74d, 0xe72d, 0xef6e, 0xef8e,
     0xef8e, 0xef8e, 0xb5c4, 0xad60, 0xbde0, 0xad40, 0xad40, 0xd680,
     0xd680, 0x6b40, 0x18e3, 0xdefb, 0xffff, 0xffff, 0xdefb, 0x18e3,
     0x6b65, 0xdf0d, 0xe72d, 0xe74d, 0xef6e, 0xef8e, 0xef8e, 0xb5c4,
     0x9480, 0x9480, 0xad60, 0xc620, 0xdee0, 0xdee0, 0xd6a0, 0xd6a0,
     0x6b40, 0x18e3, 0xdefb, 0xffff, 0x39c7, 0x2101, 0xad47, 0xb5a7,
     0xbde7, 0xce47, 0xe728, 0xe748, 0xbde4, 0x9480, 0x9480, 0x9480,
     0xa520, 0xd6c0, 0xdee0, 0xdec0, 0xd6c0, 0xd6a0, 0xce80, 0x3180,
     0x39e7, 0xffff, 0xd6ba, 0x10a2, 0x39c0, 0x7bc0, 0x8c40, 0x9cc0,
     0xd6c1, 0xc620, 0xad60, 0x9480, 0x9480, 0x9ce0, 0xd6a0, 0xdee0,
     0xdf00, 0xe700, 0xdf00, 0xdec0, 0x6b40, 0x18e3, 0xdefb, 0xffff,
     0xffff, 0xdedb, 0x10a2, 0x39c0, 0x7bc0, 0x8c40, 0xad40, 0xad60,
     0xbde0, 0xad60, 0xa500, 0xd6a0, 0xd6a0, 0xd6c0, 0xdee0, 0xdf00,
     0xe720, 0x7380, 0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff,
     0xdedb, 0x10a2, 0x39c0, 0x7bc0, 0x8c40, 0x9cc0, 0xad40, 0xbde0,
     0xbde0, 0xce60, 0xd6c0, 0xd6a0, 0xd6c0, 0xdec0, 0x7380, 0x18e3,
     0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdedb,
     0x18c2, 0x39c0, 0x7bc0, 0x8c40, 0xa500, 0xbdc0, 0xbde0, 0xbde0,
     0xce60, 0xd6c0, 0xd680, 0x6b40, 0x18e3, 0xdefb, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdedb, 0x18c2,
     0x39c0, 0x8c20, 0xad60, 0xb5a0, 0xbdc0, 0xbde0, 0xbde0, 0xce60,
     0x6320, 0x18c3, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xdefb, 0x18c2, 0x5ac0,
     0xad60, 0xb580, 0xb5a0, 0xbdc0, 0xbde0, 0x6300, 0x18e3, 0xdefb,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xdefb, 0x18c2, 0x5ac0, 0xad60,
     0xb580, 0xb5a0, 0x6300, 0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xdefb, 0x18c2, 0x5ae0, 0xad60, 0x5ae0,
     0x18e3, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xdefb, 0x18e2, 0x2120, 0x18e3, 0xdefb, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xdefb, 0x39e7, 0xdefb, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff},
    /* green jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xf79e, 0x31c6, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2124,
     0xef5d, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xf79e, 0x31c6, 0x3aa6, 0x5667, 0x4645, 0x4645, 0x4645,
     0x4645, 0x4645, 0x4645, 0x4645, 0x4645, 0x3305, 0x2144, 0xef5d,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf79e, 0x31c6,
     0x3aa6, 0xd7b9, 0x6749, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25,
     0x4f25, 0x4f25, 0x4f25, 0x774c, 0x3b06, 0x2144, 0xef5d, 0xffff,
     0xffff, 0xffff, 0xffff, 0xf79e, 0x31c6, 0x3aa6, 0xd7b9, 0xdfda,
     0x5f48, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25,
     0x4f25, 0x5f48, 0x874d, 0x3b06, 0x2164, 0xef7d, 0xffff, 0xffff,
     0xf79e, 0x31c6, 0x3aa6, 0xd7b9, 0xdfda, 0xbfb5, 0x5747, 0x4f25,
     0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25,
     0x674a, 0x8f6f, 0x3b06, 0x2965, 0xef7d, 0xffff, 0x31c6, 0x3aa6,
     0xd7b9, 0xdfda, 0xbfb6, 0x9790, 0x5726, 0x4f25, 0x4f25, 0x4f25,
     0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x776b,
     0x9771, 0x3b07, 0x2985, 0xffff, 0x0000, 0x5647, 0x6749, 0x5f48,
     0x5f47, 0x5726, 0x1601, 0x0dc0, 0x0dc0, 0x0da0, 0x0d80, 0x0d60,
     0x0d40, 0x0d00, 0x0d01, 0x1601, 0x0dc0, 0x0da0, 0x1561, 0x2542,
     0x0000, 0xffff, 0x0000, 0x4644, 0x4f25, 0x4f25, 0x4f25, 0x4f25,
     0x0dc0, 0x05a0, 0x0560, 0x0540, 0x0520, 0x0500, 0x04c0, 0x04a0,
     0x04a0, 0x0dc0, 0x05a0, 0x0540, 0x04e0, 0x0ce0, 0x0000, 0xffff,
     0x0000, 0x3e24, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x0dc0, 0x0580,
     0x0540, 0x0520, 0x0500, 0x04c0, 0x04a0, 0x0480, 0x0480, 0x0dc0,
     0x0560, 0x0500, 0x04c0, 0x0cc0, 0x0000, 0xffff, 0x0020, 0x3e24,
     0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x0da0, 0x0540, 0x0520, 0x0500,
     0x04c0, 0x04a0, 0x0480, 0x0460, 0x0460, 0x0dc0, 0x0540, 0x04e0,
     0x0480, 0x0c80, 0x0000, 0xffff, 0x0020, 0x3e04, 0x4f25, 0x4f25,
     0x4f25, 0x4f25, 0x0d80, 0x0520, 0x0500, 0x04e0, 0x04a0, 0x0480,
     0x0460, 0x0420, 0x0440, 0x0d80, 0x0500, 0x04a0, 0x0440, 0x0c60,
     0x0000, 0xffff, 0x0040, 0x3e04, 0x4f25, 0x4f25, 0x4f25, 0x4f25,
     0x0d60, 0x0500, 0x04e0, 0x04a0, 0x0480, 0x0460, 0x0420, 0x0400,
     0x0400, 0x0d60, 0x04e0, 0x0480, 0x0420, 0x0c40, 0x0000, 0xffff,
     0x0040, 0x3e04, 0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x0d40, 0x04e0,
     0x04a0, 0x0480, 0x0460, 0x0440, 0x0400, 0x03e0, 0x03e0, 0x0d40,
     0x04a0, 0x0440, 0x03e0, 0x0c20, 0x0000, 0xffff, 0x0841, 0x3de4,
     0x4f25, 0x4f25, 0x4f25, 0x4f25, 0x0d20, 0x04a0, 0x0480, 0x0460,
     0x0440, 0x0400, 0x03e0, 0x03c0, 0x03c0, 0x0d00, 0x0460, 0x0420,
     0x03c0, 0x0be0, 0x0000, 0xffff, 0x0861, 0x45c5, 0x4f26, 0x4f25,
     0x4f25, 0x4f25, 0x1d61, 0x0d01, 0x0ce1, 0x0cc1, 0x0ca1, 0x0c81,
     0x0c61, 0x0c41, 0x1441, 0x1561, 0x0cc1, 0x1481, 0x1c62, 0x2483,
     0x0000, 0xffff, 0x4248, 0x2a25, 0x872e, 0x6f4a, 0x4f25, 0x4f25,
     0x15e1, 0x0dc0, 0x0dc0, 0x0dc0, 0x0d60, 0x0d40, 0x0d00, 0x04c0,
     0x0ca0, 0x4f25, 0x5746, 0x776b, 0x8f4f, 0x3265, 0x31c6, 0xffff,
     0xf7be, 0x3a07, 0x3265, 0x8f4f, 0x6f4a, 0x4f25, 0x0dc0, 0x05a0,
     0x05a0, 0x0560, 0x0520, 0x04e0, 0x04a0, 0x0460, 0x0440, 0x4f25,
     0x6f4a, 0x874e, 0x3285, 0x31a6, 0xf79e, 0xffff, 0xffff, 0xf7be,
     0x39e6, 0x3286, 0x9750, 0x776b, 0x0dc0, 0x05a0, 0x0560, 0x0520,
     0x04e0, 0x04a0, 0x0440, 0x0400, 0x0400, 0x6749, 0x7f4d, 0x32a5,
     0x2985, 0xf79e, 0xffff, 0xffff, 0xffff, 0xffff, 0xf79e, 0x31c6,
     0x3aa6, 0x9771, 0x15c1, 0x0560, 0x0520, 0x04e0, 0x04a0, 0x0440,
     0x0400, 0x03c0, 0x03c0, 0x7f4c, 0x32c5, 0x2965, 0xef7d, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xf79e, 0x31a5, 0x3ae7,
     0x25a2, 0x1540, 0x0d20, 0x0ce0, 0x0ca0, 0x0c80, 0x0c40, 0x0c00,
     0x1421, 0x32e5, 0x2144, 0xef5d, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xef7d, 0x2985, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2144,
     0xef5d, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff}
};

/* use 16x16 tiles */
#elif (LCD_HEIGHT == 132) && (LCD_WIDTH == 176) && \
      (LCD_PIXELFORMAT == RGB565SWAPPED)
/* size of a tile */
#define TILE_WIDTH  16
#define TILE_HEIGHT 16

/* playboard offset from top */
#define YOFS 4

/* number of high scores to save */
#define NUM_SCORES 10

/* bitmaps for the jewels */
static unsigned short jewel[8][256] = {
    /* empty */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* white jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x5def, 0xae73, 0xe318,
     0xef7b, 0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xfbde, 0x0c63, 0xa631, 0x14a5, 0x14a5,
     0xef7b, 0x8631, 0x2c63, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x4d6b, 0x2842, 0x55ad, 0x79ce, 0x79ce, 0x34a5,
     0x9294, 0x9294, 0x518c, 0xe739, 0xae73, 0xffff, 0xffff, 0xffff,
     0xffff, 0xbad6, 0x494a, 0xdbde, 0xfbde, 0xfbde, 0xfbde, 0xf7bd,
     0xd39c, 0x34a5, 0x96b5, 0xf7bd, 0x2421, 0x1ce7, 0xffff, 0xffff,
     0xffff, 0xcb5a, 0x75ad, 0x3ce7, 0x3ce7, 0x3ce7, 0x3ce7, 0x59ce,
     0x34a5, 0xd39c, 0x14a5, 0x96b5, 0xae73, 0x6d6b, 0xffff, 0xffff,
     0x3ce7, 0x8631, 0x3ce7, 0x3ce7, 0x3ce7, 0x3ce7, 0x3ce7, 0xbad6,
     0xb6b5, 0x34a5, 0xb294, 0x55ad, 0x96b5, 0x4529, 0x7def, 0xffff,
     0xae73, 0xf39c, 0x3ce7, 0x1ce7, 0xfbde, 0xfbde, 0x1ce7, 0x59ce,
     0x18c6, 0x96b5, 0x34a5, 0x34a5, 0xb6b5, 0x918c, 0xef7b, 0xffff,
     0xc318, 0x38c6, 0x59ce, 0xf7bd, 0x18c6, 0x18c6, 0xf7bd, 0xf7bd,
     0x59ce, 0x79ce, 0x79ce, 0x79ce, 0x95b5, 0x95ad, 0xc318, 0xffff,
     0x8e73, 0x2c63, 0x14a5, 0xf39c, 0x75ad, 0x96b5, 0x14a5, 0xd7bd,
     0x1ce7, 0x5def, 0x5def, 0xfbde, 0xd6b5, 0x6d6b, 0x4d6b, 0xffff,
     0x5def, 0xe318, 0xf39c, 0x14a5, 0xb6b5, 0xd7bd, 0x34a5, 0xd7bd,
     0x1ce7, 0x5def, 0x5ce7, 0xdad6, 0x99ce, 0x0421, 0x1ce7, 0xffff,
     0xffff, 0x4d6b, 0x2c63, 0xd39c, 0x34a5, 0x34a5, 0xf39c, 0xf7bd,
     0x3ce7, 0x5def, 0xfbde, 0xdad6, 0xf7bd, 0xaa52, 0xffff, 0xffff,
     0xffff, 0x3ce7, 0x2421, 0x14a5, 0xd39c, 0xd39c, 0x14a5, 0x18c6,
     0x1ce7, 0xfbde, 0xdad6, 0xdad6, 0xeb5a, 0x9ad6, 0xffff, 0xffff,
     0xffff, 0xffff, 0x3084, 0x2421, 0x2c63, 0x34a5, 0x96b5, 0xf7bd,
     0x38c6, 0xbad6, 0x96b5, 0x694a, 0x4d6b, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0x5def, 0xae73, 0xe318, 0xeb5a, 0x14a5,
     0xf39c, 0xe739, 0xeb5a, 0xdbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0x3084, 0xc318,
     0x2c63, 0x1ce7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* blue jewel */
    {0xffff, 0xffff, 0x9ef7, 0xc729, 0x6709, 0x8709, 0x8709, 0x8709,
     0x8709, 0x8709, 0x8709, 0x8709, 0x6619, 0x3ce7, 0xffff, 0xffff,
     0xffff, 0x7def, 0xa729, 0x7b2d, 0x7fbf, 0x9fcf, 0x9fd7, 0xbfdf,
     0xbfe7, 0xdfef, 0xfff7, 0xffff, 0x9e76, 0x6619, 0x3ce7, 0xffff,
     0x5def, 0x8621, 0xdc3d, 0xdfef, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xfff7, 0xbfdf, 0x9fcf, 0x1d3e, 0x6619, 0x3ce7,
     0xc731, 0xb804, 0xbf5e, 0xdf6e, 0xdf6e, 0xff76, 0xff76, 0xff7e,
     0xff86, 0xdf7e, 0xdf76, 0xbf6e, 0xbf66, 0x9f5e, 0x1a25, 0xa729,
     0x55a5, 0xce0a, 0xbe05, 0xde05, 0x3f1e, 0x3f16, 0x1f06, 0x1f06,
     0xf803, 0x7603, 0x7603, 0xbf66, 0x3f8f, 0x5faf, 0x1344, 0x34a5,
     0xffff, 0xec52, 0x7704, 0x9d05, 0x5faf, 0x9f5e, 0x1f06, 0x1f06,
     0xf803, 0x7603, 0x390c, 0xbf4e, 0xff6e, 0xdc55, 0x8a42, 0xffff,
     0xffff, 0x9ef7, 0x4619, 0x7d76, 0xbfd7, 0x1f97, 0xbe05, 0xff05,
     0xf803, 0x7603, 0x1c0d, 0x7f2e, 0x5e46, 0x8711, 0x7def, 0xffff,
     0xffff, 0xffff, 0x38c6, 0x8c2a, 0x7fc7, 0x7fbf, 0x9d15, 0x9d05,
     0xf803, 0x7603, 0xdf05, 0x3f16, 0x3013, 0xb6b5, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xf07b, 0xf74c, 0x7fb7, 0x1d4e, 0x3c05,
     0xf803, 0x1904, 0x1f06, 0xfa04, 0x0c5b, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xc729, 0x5d76, 0xbe7e, 0xda04,
     0xd803, 0xfc04, 0xbe05, 0x6619, 0x9ef7, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xa719, 0xdf86, 0xda14,
     0xd803, 0xde05, 0x8e0a, 0x38c6, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x14a5, 0x912b, 0x7b3d,
     0x5904, 0x9904, 0xaf6b, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xab4a, 0xd82c,
     0x9a04, 0x8621, 0xdfff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0x4619,
     0x8809, 0x9ad6, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x18c6,
     0x5184, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* orange jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x9ef7, 0x0f84, 0xc218,
     0x4c6b, 0x3ce7, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0x7def, 0xef83, 0x0321, 0x89a4, 0xe5c3,
     0x0092, 0xc120, 0x2c6b, 0x1ce7, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0x7def, 0xce7b, 0x0321, 0xaaac, 0x32ef, 0x73ef, 0x06cc,
     0xe0a9, 0xe0a9, 0xe091, 0xc128, 0x0b63, 0xfbde, 0xffff, 0xffff,
     0xce7b, 0x2329, 0xcaac, 0x32ef, 0x73ef, 0x73ef, 0x53ef, 0x04cc,
     0x00b2, 0xe0a9, 0x20b2, 0x60cb, 0xa0bb, 0x2131, 0xea62, 0xffff,
     0xa118, 0x8add, 0x53ef, 0x73ef, 0x52ef, 0x48e5, 0x20cb, 0x20b2,
     0x20b2, 0x80ba, 0x80ba, 0xc0ec, 0xc0ec, 0xc0ec, 0xc120, 0xffff,
     0xc218, 0xc0db, 0x63dc, 0x27e5, 0x80d3, 0xc0c2, 0x40b2, 0xe0a9,
     0xe0a9, 0xe0a9, 0x20b2, 0x20cb, 0xe0c2, 0xc0ba, 0xe128, 0xffff,
     0xc118, 0xc0db, 0xc0db, 0x80d3, 0xc0c2, 0x40b2, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0x60ba, 0xa099, 0xa099, 0xc120, 0xffff,
     0xa118, 0xc0db, 0xc0db, 0x40cb, 0x40b2, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0x60ba, 0xa099, 0xa099, 0xc120, 0xffff,
     0xc118, 0xc0db, 0xc0db, 0x00cb, 0xe0a9, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0xe0a9, 0x60ba, 0xa099, 0xa099, 0xc120, 0xffff,
     0xc118, 0xc0db, 0xa0d3, 0xc0c2, 0x20b2, 0xe0a9, 0xe0a9, 0xe0a9,
     0xe0a9, 0xe0a9, 0x20b2, 0xa0ba, 0x60ba, 0xa0ba, 0xc120, 0xffff,
     0x8110, 0xa0ba, 0xe0a9, 0xc0a9, 0x00aa, 0x80ba, 0x20b2, 0xe0a9,
     0x20b2, 0x00c3, 0x40cb, 0xa0c2, 0x00b2, 0x20b2, 0xa120, 0xffff,
     0x718c, 0xe228, 0xe089, 0xe0a9, 0xc0a9, 0xc0a9, 0x20b2, 0xc0c2,
     0x60e4, 0x40e4, 0xc0d3, 0x20cb, 0x4092, 0xa120, 0xce7b, 0xffff,
     0xffff, 0xbef7, 0x508c, 0xe228, 0xe081, 0x00aa, 0xc0a9, 0x20cb,
     0x20dc, 0xa0ec, 0x20ab, 0xc120, 0xae73, 0x5def, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xbef7, 0x508c, 0xe220, 0xe081, 0x20bb,
     0xc0a2, 0xe128, 0xae73, 0x5def, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xbef7, 0x308c, 0xc220,
     0xad73, 0x5def, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* purple jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x8e73,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd7bd, 0x0000,
     0xd7bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6631, 0x9080,
     0x6631, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xd7bd, 0xeb50, 0xd9c8,
     0x4948, 0xd7bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0x6631, 0x1ad2, 0xb8c0,
     0x1398, 0x6631, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xd7bd, 0xea50, 0xdef2, 0xd8c0,
     0x1398, 0x4838, 0xd7bd, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0x6739, 0x1ad2, 0x7dea, 0x36b0,
     0x1390, 0x1080, 0x6739, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xf7bd, 0xea50, 0xdef2, 0x19c9, 0x36b0,
     0x14a0, 0x0f70, 0x4738, 0xf7bd, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0x6739, 0x1ad2, 0x5dea, 0x36b0, 0x36b0,
     0x36b0, 0x1078, 0x1078, 0x6739, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xf7bd, 0xea50, 0xdef2, 0xf8c0, 0x36b0, 0x36b0,
     0x36b0, 0x34a0, 0x1188, 0x4840, 0xf7bd, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x8739, 0x1ad2, 0x3ce2, 0x36b0, 0x36b0, 0x36b0,
     0x36b0, 0x36b0, 0x1498, 0x1398, 0x8739, 0xffff, 0xffff, 0xffff,
     0xffff, 0xf7bd, 0xea50, 0xdef2, 0xb8c0, 0x36b0, 0x36b0, 0x36b0,
     0x36b0, 0x36b0, 0x36b0, 0x18c0, 0x4948, 0xf7bd, 0xffff, 0xffff,
     0xffff, 0x8739, 0x1ad2, 0xbad1, 0x34a0, 0x35a0, 0x35a8, 0x36b0,
     0x37b8, 0x37b8, 0x37b8, 0x19c8, 0x17b8, 0x8739, 0xffff, 0xffff,
     0x18c6, 0xc948, 0x9398, 0x0e70, 0x0e68, 0x0e68, 0x1180, 0x1498,
     0x17b8, 0x1ad0, 0x1ad0, 0x1ad0, 0x19c8, 0x4948, 0x18c6, 0xffff,
     0xe739, 0x2210, 0x6420, 0x6420, 0x6420, 0x6420, 0x6420, 0x6420,
     0x6420, 0x6420, 0x6420, 0x6420, 0x6420, 0x2210, 0xe739, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* red jewel */
    {0xffff, 0x79ce, 0x8210, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x8210, 0x79ce, 0xffff, 0xffff,
     0x18c6, 0x4108, 0x2070, 0x00e0, 0x20c8, 0x20b0, 0x4098, 0x6080,
     0x6080, 0x6080, 0x6078, 0x6078, 0x2050, 0x4108, 0x18c6, 0xffff,
     0x2000, 0x2078, 0x20c8, 0x00f0, 0x00e8, 0x00d0, 0x20b8, 0x40a0,
     0x6088, 0x6080, 0x6078, 0x6080, 0x20a8, 0x0088, 0x2000, 0xffff,
     0x0000, 0x40e0, 0x40e0, 0x8cf2, 0xeeea, 0xeee2, 0xeeda, 0xa7c1,
     0x61b0, 0xa2c0, 0xa2c0, 0x82c8, 0x20d8, 0x00d8, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40e0, 0x8cea, 0xeee2, 0xeeda, 0xeed2, 0xa7b1,
     0x81a0, 0x82c0, 0x82d0, 0x82d8, 0x20c8, 0x20c8, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40e0, 0x8ce2, 0xeeda, 0xeed2, 0x0ecb, 0xa7a1,
     0x61b0, 0x82d0, 0x82d8, 0x82e0, 0x20c0, 0x20b8, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40e0, 0x8cda, 0xeed2, 0x0ecb, 0x0ec3, 0xa7b1,
     0x61c0, 0x82d8, 0x82e0, 0x82e8, 0x40b0, 0x40a8, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40e0, 0x87b9, 0xc8b1, 0xc8a1, 0xc8b1, 0xa7c1,
     0x87d1, 0x66e1, 0x66e9, 0x66e9, 0x40a0, 0x4090, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40d8, 0x60a0, 0x6198, 0x61a8, 0x61b8, 0xc8d9,
     0xd3eb, 0xd3eb, 0xd3eb, 0xd3eb, 0x8088, 0x6080, 0x0000, 0xffff,
     0x0000, 0x40e0, 0x40d8, 0x81b0, 0x82c0, 0x82c8, 0x82d8, 0xa8e1,
     0xd3eb, 0xd3eb, 0xd3eb, 0xd3e3, 0x6098, 0x4090, 0x0000, 0xffff,
     0x0000, 0x40d8, 0x40d8, 0x81b8, 0x82c8, 0x82d8, 0x62e0, 0xa8f1,
     0xd3eb, 0xd3eb, 0xd3e3, 0xd3e3, 0x60a0, 0x40a0, 0x0000, 0xffff,
     0x0000, 0x40d8, 0x40d8, 0x61c8, 0x82d8, 0x62e0, 0x62f0, 0xa8e9,
     0xd3eb, 0xd3e3, 0xd3e3, 0xd3e3, 0x60b0, 0x20b0, 0x0000, 0xffff,
     0x4108, 0x2068, 0x20c0, 0x00f0, 0x00f8, 0x00d8, 0x20a8, 0x6090,
     0x6088, 0x6088, 0x6080, 0x6080, 0x4098, 0x2068, 0x4108, 0xffff,
     0x59ce, 0x4110, 0x0078, 0x00f8, 0x00f8, 0x00f0, 0x20b8, 0x6080,
     0x6080, 0x6078, 0x6078, 0x6078, 0x2060, 0x4110, 0x59ce, 0xffff,
     0xffff, 0x9ad6, 0x8210, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
     0x0000, 0x0000, 0x0000, 0x0000, 0x8210, 0x9ad6, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* yellow jewel */
    {0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xc639,
     0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0x6429, 0xa373,
     0x4329, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0x8431, 0x2ac6, 0x87b5,
     0x406b, 0x4329, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xfbde, 0x6429, 0x4ac6, 0x4de7, 0x07c6,
     0x408c, 0x406b, 0x4329, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xfbde, 0x6429, 0x4ace, 0x4ee7, 0x6eef, 0xe7de,
     0xc0bd, 0x408c, 0x406b, 0x4329, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xfbde, 0x8431, 0x4ac6, 0x4ee7, 0x8eef, 0x8eef, 0x07df,
     0xe0bd, 0x00a5, 0x408c, 0x00a5, 0x8331, 0xfbde, 0xffff, 0xffff,
     0xfbde, 0x6429, 0x2ac6, 0x4de7, 0x6eef, 0x8eef, 0x2be7, 0xc19c,
     0x20a5, 0xc0bd, 0x80ce, 0xa0d6, 0xa0b5, 0x8331, 0xfbde, 0xffff,
     0xa531, 0xa373, 0x87b5, 0x07c6, 0x07df, 0x07df, 0xc19c, 0x8094,
     0xa094, 0x80ce, 0xe0de, 0xc0d6, 0xa0d6, 0xc09c, 0xc639, 0xffff,
     0xdbde, 0x0321, 0x406b, 0x408c, 0xe1bd, 0xe0bd, 0x20a5, 0xa094,
     0x00c6, 0xc0d6, 0xe0de, 0x00df, 0x00c6, 0x6329, 0xfbde, 0xffff,
     0xffff, 0xdbde, 0x2321, 0x406b, 0x408c, 0x00a5, 0xc0bd, 0xc0bd,
     0xa0d6, 0xa0d6, 0xc0d6, 0x20c6, 0x8331, 0xfbde, 0xffff, 0xffff,
     0xffff, 0xffff, 0xdbde, 0x2321, 0x406b, 0x408c, 0x80b5, 0xe0bd,
     0x00be, 0xa0d6, 0xa0b5, 0x6329, 0xfbde, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xdbde, 0x2321, 0x608c, 0x80b5, 0xc0b5,
     0xe0bd, 0x40ad, 0x6329, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0x4329, 0xc09c, 0x80b5,
     0x20a5, 0x8331, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0x4329, 0xe083,
     0x6329, 0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xfbde, 0xc639,
     0xfbde, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff},
    /* green jewel */
    {0xffff, 0xffff, 0xffff, 0x718c, 0xa108, 0xe210, 0xe210, 0xe210,
     0xe210, 0xe210, 0xa108, 0x8d6b, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0x718c, 0x4a53, 0x2d7f, 0x254f, 0x254f, 0x254f,
     0x254f, 0x254f, 0x264f, 0x4843, 0xad6b, 0xffff, 0xffff, 0xffff,
     0xffff, 0x718c, 0x4953, 0xbadf, 0x6d87, 0x254f, 0x254f, 0x254f,
     0x254f, 0x254f, 0x254f, 0x4b77, 0x484b, 0xce73, 0xffff, 0xffff,
     0x718c, 0x2953, 0xbad7, 0xdadf, 0x6b77, 0x254f, 0x254f, 0x254f,
     0x254f, 0x254f, 0x254f, 0x254f, 0x4d87, 0x6953, 0xee73, 0xffff,
     0xa108, 0x2e87, 0x6e8f, 0x6c7f, 0xa43e, 0x221e, 0x221e, 0x021e,
     0xe21d, 0xc21d, 0x0226, 0x221e, 0x0326, 0x063e, 0x2109, 0xffff,
     0xe210, 0x254f, 0x254f, 0x254f, 0x221e, 0xa005, 0x6005, 0x2005,
     0xe004, 0xc004, 0x6115, 0xa005, 0x2005, 0xa004, 0x8109, 0xffff,
     0xe210, 0x254f, 0x254f, 0x254f, 0x221e, 0x6005, 0x2005, 0xe004,
     0xc004, 0x8004, 0x4115, 0x6005, 0xe004, 0x6004, 0x8109, 0xffff,
     0xe210, 0x254f, 0x254f, 0x254f, 0x021e, 0x2005, 0x0005, 0xc004,
     0x8004, 0x4004, 0x2115, 0x0005, 0x8004, 0x2004, 0x6109, 0xffff,
     0xe210, 0x254f, 0x254f, 0x254f, 0xe21d, 0x0005, 0xc004, 0x8004,
     0x4004, 0x0004, 0xe114, 0xc004, 0x4004, 0xc003, 0x6109, 0xffff,
     0xe210, 0x254f, 0x254f, 0x254f, 0xc21d, 0xc004, 0x8004, 0x4004,
     0x2004, 0xe003, 0xc114, 0x8004, 0x0004, 0x8003, 0x6109, 0xffff,
     0x8108, 0xe756, 0x254f, 0x254f, 0x2226, 0x8115, 0x6115, 0x4115,
     0x2115, 0x0115, 0x421d, 0x421d, 0x0225, 0x0535, 0xe108, 0xffff,
     0x5084, 0x863a, 0x2b77, 0x254f, 0x221e, 0xa005, 0xa005, 0xa005,
     0x4005, 0xe004, 0x611d, 0x254f, 0x2c77, 0xc73a, 0x5084, 0xffff,
     0xffff, 0x3084, 0xc742, 0x2c7f, 0x221e, 0xa005, 0xa005, 0x4005,
     0xe004, 0x8004, 0x211d, 0x2a6f, 0xc73a, 0x3084, 0xffff, 0xffff,
     0xffff, 0xffff, 0x0f7c, 0x0843, 0x4536, 0xa005, 0x4005, 0xe004,
     0x8004, 0x2004, 0xe224, 0xc63a, 0x0f7c, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xef7b, 0x2109, 0xc111, 0xa111, 0x8111,
     0x8109, 0x6109, 0xe108, 0xef7b, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff,
     0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff}
};

/* use 16x16 tiles */
#elif (LCD_HEIGHT == 128) && (LCD_WIDTH == 160)
/* size of a tile */
#define TILE_WIDTH  16
#define TILE_HEIGHT 16

/* playboard offset from top */
#define YOFS 0

/* number of high scores to save */
#define NUM_SCORES 10

/* bitmaps for the jewels */
static unsigned char jewel[8][32] = {
    /* empty */
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    /* square */
    {0x00, 0x00, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
     0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0x00, 0x00,
     0x00, 0x00, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f,
     0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x3f, 0x00, 0x00},
    /* plus */
    {0x00, 0xe0, 0xe0, 0x60, 0x60, 0x7e, 0x7e, 0x06,
     0x7e, 0x7e, 0x60, 0x60, 0xe0, 0xe0, 0x00, 0x00,
     0x00, 0x03, 0x03, 0x03, 0x03, 0x3f, 0x3f, 0x30,
     0x3f, 0x3f, 0x03, 0x03, 0x03, 0x03, 0x00, 0x00},
    /* triangle */
    {0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0x7c, 0x1e,
     0x7c, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00,
     0x00, 0x30, 0x3c, 0x3f, 0x37, 0x31, 0x30, 0x30,
     0x30, 0x31, 0x37, 0x3f, 0x3c, 0x30, 0x00, 0x00},
    /* diamond */
    {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe,
     0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00, 0x00,
     0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f,
     0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00},
    /* star */
    {0x00, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0xf8, 0xfe,
     0xf8, 0xc0, 0xc0, 0xc0, 0xc0, 0x40, 0x00, 0x00,
     0x00, 0x00, 0x00, 0x30, 0x1f, 0x1f, 0x0f, 0x07,
     0x0f, 0x1f, 0x1f, 0x30, 0x00, 0x00, 0x00, 0x00},
    /* circle */
    {0x00, 0xe0, 0xf8, 0xfc, 0x3c, 0x1e, 0x0e, 0x0e,
     0x0e, 0x1e, 0x3c, 0xfc, 0xf8, 0xe0, 0x00, 0x00,
     0x00, 0x03, 0x0f, 0x1f, 0x1e, 0x3c, 0x38, 0x38,
     0x38, 0x3c, 0x1e, 0x1f, 0x0f, 0x03, 0x00, 0x00},
    /* heart */
    {0x00, 0x78, 0xfc, 0xfe, 0xfe, 0xfc, 0xf8, 0xf0,
     0xf8, 0xfc, 0xfe, 0xfe, 0xfc, 0x78, 0x00, 0x00,
     0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f,
     0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00}
};

/* use 10x8 tiles */
#elif (LCD_HEIGHT == 64) && (LCD_WIDTH == 112)
/* size of a tile */
#define TILE_WIDTH 10
#define TILE_HEIGHT 8

/* playboard offset from top */
#define YOFS 0

/* number of high scores to save */
#define NUM_SCORES 8

/* bitmaps for the jewels */
static unsigned char jewel[8][10] = {
    /* empty */
    {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
    /* square */
    {0x00, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x7e, 0x00, 0x00},
    /* plus */
    {0x00, 0x1c, 0x14, 0x77, 0x41, 0x41, 0x77, 0x14, 0x1c, 0x00},
    /* triangle */
    {0x60, 0x70, 0x5c, 0x46, 0x43, 0x46, 0x5c, 0x70, 0x60, 0x00},
    /* diamond */
    {0x00, 0x08, 0x1c, 0x3e, 0x7f, 0x7f, 0x3e, 0x1c, 0x08, 0x00},
    /* star */
    {0x00, 0x04, 0x6c, 0x3c, 0x1c, 0x1f, 0x3c, 0x6c, 0x04, 0x00},
    /* circle */
    {0x00, 0x1c, 0x3e, 0x63, 0x63, 0x63, 0x63, 0x3e, 0x1c, 0x00},
    /* heart */
    {0x06, 0x0f, 0x1f, 0x3e, 0x7c, 0x3e, 0x1f, 0x0f, 0x06, 0x00}
};

#else
  #error BEJEWELED: Unsupported LCD type
#endif

/* global rockbox api */
static struct plugin_api* rb;

/* the tile struct
 * type is the jewel number 0-7
 * falling if the jewel is falling
 * delete marks the jewel for deletion
 */
struct tile {
    int type;
    bool falling;
    bool delete;
};

/* the game context struct
 * score is the current level score
 * segments is the number of cleared segments in the current run
 * level is the current level
 * highscores is the list of high scores
 * resume denotes whether to resume the currently loaded game
 * dirty denotes whether the high scores are out of sync with the saved file
 * playboard is the game playing board (first row is hidden)
 */
struct game_context {
    unsigned int score;
    unsigned int segments;
    unsigned int level;
    unsigned short highscores[NUM_SCORES];
    bool resume;
    bool dirty;
    struct tile playboard[BJ_WIDTH][BJ_HEIGHT];
};

/*****************************************************************************
* bejeweled_init() initializes bejeweled data structures.
******************************************************************************/
static void bejeweled_init(struct game_context* bj) {
    /* seed the rand generator */
    rb->srand(*rb->current_tick);

    /* check for resumed game */
    if(bj->resume) {
        bj->resume = false;
        return;
    }

    /* reset scoring */
    bj->level = 1;
    bj->score = 0;
    bj->segments = 0;

    /* clear playing board */
    rb->memset(bj->playboard, 0, sizeof(bj->playboard));
}

/*****************************************************************************
* bejeweled_drawboard() redraws the entire game board.
******************************************************************************/
static void bejeweled_drawboard(struct game_context* bj) {
    int i, j;
    int w, h;
    unsigned int tempscore;
    char *title = "Level";
    char str[6];

    tempscore = (bj->score>LEVEL_PTS ? LEVEL_PTS : bj->score);

    /* clear screen */
    rb->lcd_clear_display();

    /* draw separator lines */
    rb->lcd_vline(BJ_WIDTH*TILE_WIDTH, 0, LCD_HEIGHT);
    rb->lcd_hline(BJ_WIDTH*TILE_WIDTH, LCD_WIDTH, 18);
    rb->lcd_hline(BJ_WIDTH*TILE_WIDTH, LCD_WIDTH, LCD_HEIGHT-10);

    /* draw progress bar */
#ifdef HAVE_LCD_COLOR
    rb->lcd_set_foreground(LCD_RGBPACK(64, 64, 255));
#endif
    rb->lcd_fillrect(BJ_WIDTH*TILE_WIDTH+(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/4,
                     (LCD_HEIGHT-10)-(((LCD_HEIGHT-10)-18)*
                         tempscore/LEVEL_PTS),
                     (LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2,
                     ((LCD_HEIGHT-10)-18)*tempscore/LEVEL_PTS);
#ifdef HAVE_LCD_COLOR
    rb->lcd_set_foreground(LCD_RGBPACK(0, 128, 255));
    rb->lcd_drawrect(BJ_WIDTH*TILE_WIDTH+(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/4+1,
                     (LCD_HEIGHT-10)-(((LCD_HEIGHT-10)-18)*
                         tempscore/LEVEL_PTS)+1,
                     (LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-2,
                     ((LCD_HEIGHT-10)-18)*tempscore/LEVEL_PTS-1);
    rb->lcd_set_foreground(LCD_BLACK);
    rb->lcd_drawrect(BJ_WIDTH*TILE_WIDTH+(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/4,
                     (LCD_HEIGHT-10)-(((LCD_HEIGHT-10)-18)*
                         tempscore/LEVEL_PTS),
                     (LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2,
                     ((LCD_HEIGHT-10)-18)*tempscore/LEVEL_PTS+1);
#endif

    /* dispay playing board */
    for(i=0; i<BJ_HEIGHT-1; i++){
        for(j=0; j<BJ_WIDTH; j++){
#ifdef HAVE_LCD_COLOR
            rb->lcd_bitmap(jewel[bj->playboard[j][i+1].type],
                           j*TILE_WIDTH, i*TILE_HEIGHT+YOFS,
                           TILE_WIDTH, TILE_HEIGHT);
#else
            rb->lcd_mono_bitmap(jewel[bj->playboard[j][i+1].type],
                                j*TILE_WIDTH, i*TILE_HEIGHT+YOFS,
                                TILE_WIDTH, TILE_HEIGHT);
#endif
        }
    }

    /* print text */
    rb->lcd_getstringsize(title, &w, &h);
    rb->lcd_putsxy(LCD_WIDTH-(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-w/2, 1, title);

    rb->snprintf(str, 4, "%d", bj->level);
    rb->lcd_getstringsize(str, &w, &h);
    rb->lcd_putsxy(LCD_WIDTH-(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-w/2, 10, str);

    rb->snprintf(str, 6, "%d", (bj->level-1)*LEVEL_PTS+bj->score);
    rb->lcd_getstringsize(str, &w, &h);
    rb->lcd_putsxy(LCD_WIDTH-(LCD_WIDTH-BJ_WIDTH*TILE_WIDTH)/2-w/2,
                   LCD_HEIGHT-8,
                   str);

    rb->lcd_update();
}

/*****************************************************************************
* bejeweled_putjewels() makes the jewels fall to fill empty spots and adds
* new random jewels at the empty spots at the top of each row.
******************************************************************************/
static void bejeweled_putjewels(struct game_context* bj){
    int i, j, k;
    bool mark, done;

    /* loop to make all the jewels fall */
    while(true) {
        /* mark falling jewels and add new jewels to hidden top row*/
        mark = false;
        done = true;
        for(j=0; j<BJ_WIDTH; j++) {
            if(bj->playboard[j][1].type == 0) {
                bj->playboard[j][0].type = rb->rand()%7+1;
            }
            for(i=BJ_HEIGHT-2; i>=0; i--) {
                if(!mark && bj->playboard[j][i+1].type == 0) {
                    mark = true;
                    done = false;
                }
                if(mark) bj->playboard[j][i].falling = true;
            }
            /*if(bj->playboard[1][j].falling) {
                bj->playboard[0][j].type = rb->rand()%7+1;
                bj->playboard[0][j].falling = true;
            }*/
            mark = false;
        }

        /* break if there are no falling jewels */
        if(done) break;

        /* animate falling jewels */
        for(k=TILE_HEIGHT/8; k<=TILE_HEIGHT; k+=TILE_HEIGHT/8) {
            rb->sleep(HZ/FALL_TIMER);
            for(i=0; i<BJ_HEIGHT-1; i++) {
                for(j=0; j<BJ_WIDTH; j++) {
                    if(bj->playboard[j][i].falling &&
                       bj->playboard[j][i].type != 0) {
                        /* clear old position */
#ifdef HAVE_LCD_COLOR
                        rb->lcd_bitmap(jewel[0],
                                   j*TILE_WIDTH,
                                   (i-1)*TILE_HEIGHT+k-TILE_HEIGHT/8+YOFS,
                                   TILE_WIDTH, TILE_HEIGHT);
#else
                        rb->lcd_mono_bitmap(jewel[0],
                                        j*TILE_WIDTH,
                                        (i-1)*TILE_HEIGHT+k-TILE_HEIGHT/8+YOFS,
                                        TILE_WIDTH, TILE_HEIGHT);
#endif
                        /* draw new position */
#ifdef HAVE_LCD_COLOR
                        rb->lcd_bitmap(jewel[bj->playboard[j][i].type],
                                       j*TILE_WIDTH,
                                       (i-1)*TILE_HEIGHT+k+YOFS,
                                       TILE_WIDTH, TILE_HEIGHT);
#else
                        rb->lcd_mono_bitmap(jewel[bj->playboard[j][i].type],
                                            j*TILE_WIDTH,
                                            (i-1)*TILE_HEIGHT+k+YOFS,
                                            TILE_WIDTH, TILE_HEIGHT);
#endif
                    }
                }
            }
            rb->lcd_update();
        }

        /* shift jewels down */
        for(j=0; j<BJ_WIDTH; j++) {
            for(i=BJ_HEIGHT-1; i>=1; i--) {
                if(bj->playboard[j][i-1].falling) {
                    bj->playboard[j][i].type = bj->playboard[j][i-1].type;
                }
            }
        }

        /* clear out top row */
        for(j=0; j<BJ_WIDTH; j++) {
            bj->playboard[j][0].type = 0;
        }

        /* mark everything not falling */
        for(i=0; i<BJ_HEIGHT; i++) {
            for(j=0; j<BJ_WIDTH; j++) {
                bj->playboard[j][i].falling = false;
            }
        }
    }
}

/*****************************************************************************
* bejeweled_clearjewels() finds all the connected rows and columns and
*     calculates and returns the points earned.
******************************************************************************/
static unsigned int bejeweled_clearjewels(struct game_context* bj) {
    int i, j;
    int last, run;
    unsigned int points = 0;

    /* check for connected rows */
    for(i=1; i<BJ_HEIGHT; i++) {
        last = 0;
        run = 1;
        for(j=0; j<BJ_WIDTH; j++) {
            if(bj->playboard[j][i].type == last &&
               bj->playboard[j][i].type != 0) {
                run++;

                if(run == 3) {
                    bj->segments++;
                    points += bj->segments;
                    bj->playboard[j][i].delete = true;
                    bj->playboard[j-1][i].delete = true;
                    bj->playboard[j-2][i].delete = true;
                } else if(run > 3) {
                    points++;
                    bj->playboard[j][i].delete = true;
                }
            } else {
                run = 1;
                last = bj->playboard[j][i].type;
            }
        }
    }

    /* check for connected columns */
    for(j=0; j<BJ_WIDTH; j++) {
        last = 0;
        run = 1;
        for(i=1; i<BJ_HEIGHT; i++) {
            if(bj->playboard[j][i].type != 0 &&
               bj->playboard[j][i].type == last) {
                run++;

                if(run == 3) {
                    bj->segments++;
                    points += bj->segments;
                    bj->playboard[j][i].delete = true;
                    bj->playboard[j][i-1].delete = true;
                    bj->playboard[j][i-2].delete = true;
                } else if(run > 3) {
                    points++;
                    bj->playboard[j][i].delete = true;
                }
            } else {
                run = 1;
                last = bj->playboard[j][i].type;
            }
        }
    }

    /* clear deleted jewels */
    for(i=1; i<BJ_HEIGHT; i++) {
        for(j=0; j<BJ_WIDTH; j++) {
            if(bj->playboard[j][i].delete) {
                bj->playboard[j][i].delete = false;
                bj->playboard[j][i].type = 0;
            }
        }
    }

    return points;
}

/*****************************************************************************
* bejeweled_runboard() runs the board until it settles in a fixed state and
*     returns points earned.
******************************************************************************/
static unsigned int bejeweled_runboard(struct game_context* bj) {
    unsigned int points = 0;
    unsigned int ret;

    bj->segments = 0;

    while((ret = bejeweled_clearjewels(bj)) > 0) {
        points += ret;
        bejeweled_drawboard(bj);
        bejeweled_putjewels(bj);
    }

    return points;
}

/*****************************************************************************
* bejeweled_swapjewels() swaps two jewels as long as it results in points and
*     returns points earned.
******************************************************************************/
static unsigned int bejeweled_swapjewels(struct game_context* bj,
                                         int x, int y, int direc) {
    int k;
    int horzmod, vertmod;
    int movelen = 0;
    bool undo = false;
    unsigned int points = 0;

    /* check for invalid parameters */
    if(x < 0 || x >= BJ_WIDTH || y < 0 || y >= BJ_HEIGHT-1 ||
       direc < SWAP_UP || direc > SWAP_LEFT) return 0;

    /* check for invalid directions */
    if((x == 0 && direc == SWAP_LEFT) ||
       (x == BJ_WIDTH-1 && direc == SWAP_RIGHT) ||
       (y == 0 && direc == SWAP_UP) ||
       (y == BJ_HEIGHT-2 && direc == SWAP_DOWN)) {
        return 0;
    }

    /* set direction variables */
    horzmod = 0;
    vertmod = 0;
    switch(direc) {
        case SWAP_UP:
            vertmod = -1;
            movelen = TILE_HEIGHT;
            break;
        case SWAP_RIGHT:
            horzmod = 1;
            movelen = TILE_WIDTH;
            break;
        case SWAP_DOWN:
            vertmod = 1;
            movelen = TILE_HEIGHT;
            break;
        case SWAP_LEFT:
            horzmod = -1;
            movelen = TILE_WIDTH;
            break;
    }

    while(true) {
        /* animate swapping jewels */
        for(k=TILE_HEIGHT/8; k<=movelen;k+=TILE_HEIGHT/8) {
            rb->sleep(HZ/SWAP_TIMER);
            /* clear old position */
#ifdef HAVE_LCD_COLOR
            rb->lcd_bitmap(jewel[0],
                       x*TILE_WIDTH+horzmod*(k-TILE_WIDTH/8),
                       y*TILE_HEIGHT+vertmod*(k-TILE_HEIGHT/8)+YOFS,
                       TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_bitmap(jewel[0],
                       (x+horzmod)*TILE_WIDTH-horzmod*(k-TILE_WIDTH/8),
                       (y+vertmod)*TILE_HEIGHT-vertmod*(k-TILE_HEIGHT/8)+YOFS,
                       TILE_WIDTH, TILE_HEIGHT);
#else
            rb->lcd_mono_bitmap(jewel[0],
                        x*TILE_WIDTH+horzmod*(k-TILE_WIDTH/8),
                        y*TILE_HEIGHT+vertmod*(k-TILE_HEIGHT/8)+YOFS,
                            TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_mono_bitmap(jewel[0],
                        (x+horzmod)*TILE_WIDTH-horzmod*(k-TILE_WIDTH/8),
                        (y+vertmod)*TILE_HEIGHT-vertmod*(k-TILE_HEIGHT/8)+YOFS,
                        TILE_WIDTH, TILE_HEIGHT);
#endif
            /* draw new position */
#ifdef HAVE_LCD_COLOR
            rb->lcd_bitmap(jewel[bj->playboard[x][y+1].type],
                           x*TILE_WIDTH+horzmod*k,
                           y*TILE_HEIGHT+vertmod*k+YOFS,
                           TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_bitmap(jewel[bj->playboard
                           [x+horzmod][y+1+vertmod].type],
                           (x+horzmod)*TILE_WIDTH-horzmod*k,
                           (y+vertmod)*TILE_HEIGHT-vertmod*k+YOFS,
                           TILE_WIDTH, TILE_HEIGHT);
#else
            rb->lcd_mono_bitmap(jewel[bj->playboard[x][y+1].type],
                                x*TILE_WIDTH+horzmod*k,
                                y*TILE_HEIGHT+vertmod*k+YOFS,
                                TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_set_drawmode(DRMODE_FG);
            rb->lcd_mono_bitmap(jewel[bj->playboard
                                [x+horzmod][y+1+vertmod].type],
                                (x+horzmod)*TILE_WIDTH-horzmod*k,
                                (y+vertmod)*TILE_HEIGHT-vertmod*k+YOFS,
                                TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_set_drawmode(DRMODE_SOLID);
#endif

            rb->lcd_update();
        }

        /* swap jewels */
        int temp = bj->playboard[x][y+1].type;
        bj->playboard[x][y+1].type =
            bj->playboard[x+horzmod][y+1+vertmod].type;
        bj->playboard[x+horzmod][y+1+vertmod].type = temp;

        if(undo) break;

        points = bejeweled_runboard(bj);
        if(points == 0) {undo = true;} else {break;}
    }

    return points;
}

/*****************************************************************************
* bejeweled_movesavail() uses pattern matching to see if there are any
*     available move left.
******************************************************************************/
static bool bejeweled_movesavail(struct game_context* bj) {
    int i, j;
    bool moves = false;
    int mytype;

    for(i=1; i<BJ_HEIGHT; i++) {
        for(j=0; j<BJ_WIDTH; j++) {
            mytype = bj->playboard[j][i].type;

            /* check horizontal patterns */
            if(j <= BJ_WIDTH-3) {
                if(i > 1) {
                    if(bj->playboard[j+1][i-1].type == mytype) {
                        if(bj->playboard[j+2][i-1].type == mytype)
                            {moves = true; break;}
                        if(bj->playboard[j+2][i].type == mytype)
                            {moves = true; break;}
                    }
                    if(bj->playboard[j+1][i].type == mytype) {
                        if(bj->playboard[j+2][i-1].type == mytype)
                            {moves = true; break;}
                    }
                }

                if(j <= BJ_WIDTH-4) {
                    if(bj->playboard[j+3][i].type == mytype) {
                        if(bj->playboard[j+1][i].type == mytype)
                            {moves = true; break;}
                        if(bj->playboard[j+2][i].type == mytype)
                            {moves = true; break;}
                    }
                }

                if(i < BJ_HEIGHT-1) {
                    if(bj->playboard[j+1][i].type == mytype) {
                        if(bj->playboard[j+2][i+1].type == mytype)
                            {moves = true; break;}
                    }
                    if(bj->playboard[j+1][i+1].type == mytype) {
                        if(bj->playboard[j+2][i].type == mytype)
                            {moves = true; break;}
                        if(bj->playboard[j+2][i+1].type == mytype)
                            {moves = true; break;}
                    }
                }
            }

            /* check vertical patterns */
            if(i <= BJ_HEIGHT-3) {
                if(j > 0) {
                    if(bj->playboard[j-1][i+1].type == mytype) {
                        if(bj->playboard[j-1][i+2].type == mytype)
                            {moves = true; break;}
                        if(bj->playboard[j][i+2].type == mytype)
                            {moves = true; break;}
                    }
                    if(bj->playboard[j][i+1].type == mytype) {
                        if(bj->playboard[j-1][i+2].type == mytype)
                            {moves = true; break;}
                    }
                }

                if(i <= BJ_HEIGHT-4) {
                    if(bj->playboard[j][i+3].type == mytype) {
                        if(bj->playboard[j][i+1].type == mytype)
                            {moves = true; break;}
                        if(bj->playboard[j][i+2].type == mytype)
                            {moves = true; break;}
                    }
                }

                if(j < BJ_WIDTH-1) {
                    if(bj->playboard[j][i+1].type == mytype) {
                        if(bj->playboard[j+1][i+2].type == mytype)
                            {moves = true; break;}
                    }
                    if(bj->playboard[j+1][i+1].type == mytype) {
                        if(bj->playboard[j][i+2].type == mytype)
                            {moves = true; break;}
                        if (bj->playboard[j+1][i+2].type == mytype)
                            {moves = true; break;}
                    }
                }
            }
        }

        if(moves) break;
    }

    return moves;
}

/*****************************************************************************
* bejeweled_nextlevel() advances the game to the next level and returns
*     points earned.
******************************************************************************/
static unsigned int bejeweled_nextlevel(struct game_context* bj) {
    int i, x, y;
    unsigned int points = 0;

    /* roll over score, change and display level */
    while(bj->score >= LEVEL_PTS) {
        bj->score -= LEVEL_PTS;
        bj->level++;
        rb->splash(HZ*2, true, "Level %d", bj->level);
        bejeweled_drawboard(bj);
    }

    /* randomly clear some jewels */
    for(i=0; i<16; i++) {
        x = rb->rand()%8;
        y = rb->rand()%8;

        if(bj->playboard[x][y].type != 0) {
            points++;
            bj->playboard[x][y].type = 0;
        }
    }
    bejeweled_drawboard(bj);

    /* run the play board */
    bejeweled_putjewels(bj);
    points += bejeweled_runboard(bj);
    return points;
}

/*****************************************************************************
* bejeweld_recordscore() inserts a high score into the high scores list and
*     returns the high score position.
******************************************************************************/
static int bejeweled_recordscore(struct game_context* bj) {
    int i;
    int position = 0;
    unsigned short current, temp;

    /* calculate total score */
    current = (bj->level-1)*LEVEL_PTS+bj->score;
    if(current <= 0) return 0;

    /* insert the current score into the high scores */
    for(i=0; i<NUM_SCORES; i++) {
        if(current >= bj->highscores[i]) {
            if(!position) {
                position = i+1;
                bj->dirty = true;
            }
            temp = bj->highscores[i];
            bj->highscores[i] = current;
            current = temp;
        }
    }

    return position;
 }

/*****************************************************************************
* bejeweled_loadscores() loads the high scores saved file.
******************************************************************************/
static void bejeweled_loadscores(struct game_context* bj) {
    int fd;

    bj->dirty = false;

    /* clear high scores */
    rb->memset(bj->highscores, 0, sizeof(bj->highscores));

    /* open scores file */
    fd = rb->open(SCORE_FILE, O_RDONLY);
    if(fd < 0) return;

    /* read in high scores */
    if(rb->read(fd, bj->highscores, sizeof(bj->highscores)) <= 0) {
        /* scores are bad, reset */
        rb->memset(bj->highscores, 0, sizeof(bj->highscores));
    }

    rb->close(fd);
}

/*****************************************************************************
* bejeweled_savescores() saves the high scores saved file.
******************************************************************************/
static void bejeweled_savescores(struct game_context* bj) {
    int fd;

    /* write out the high scores to the save file */
    fd = rb->open(SCORE_FILE, O_WRONLY|O_CREAT);
    rb->write(fd, bj->highscores, sizeof(bj->highscores));
    rb->close(fd);
    bj->dirty = false;
}

/*****************************************************************************
* bejeweled_loadgame() loads the saved game and returns load success.
******************************************************************************/
static bool bejeweled_loadgame(struct game_context* bj) {
    int fd;
    bool loaded = false;

    /* open game file */
    fd = rb->open(SAVE_FILE, O_RDONLY);
    if(fd < 0) return loaded;

    /* read in saved game */
    while(true) {
        if(rb->read(fd, &bj->score, sizeof(bj->score)) <= 0) break;
        if(rb->read(fd, &bj->level, sizeof(bj->level)) <= 0) break;
        if(rb->read(fd, bj->playboard, sizeof(bj->playboard)) <= 0) break;
        bj->resume = true;
        loaded = true;
        break;
    }

    rb->close(fd);

    /* delete saved file */
    rb->remove(SAVE_FILE);
    return loaded;
}

/*****************************************************************************
* bejeweled_savegame() saves the current game state.
******************************************************************************/
static void bejeweled_savegame(struct game_context* bj) {
    int fd;

    /* write out the game state to the save file */
    fd = rb->open(SAVE_FILE, O_WRONLY|O_CREAT);
    rb->write(fd, &bj->score, sizeof(bj->score));
    rb->write(fd, &bj->level, sizeof(bj->level));
    rb->write(fd, bj->playboard, sizeof(bj->playboard));
    rb->close(fd);

    bj->resume = true;
}

/*****************************************************************************
* bejeweled_callback() is the default event handler callback which is called
*     on usb connect and shutdown.
******************************************************************************/
static void bejeweled_callback(void* param) {
    struct game_context* bj = (struct game_context*) param;
    if(bj->dirty) {
        rb->splash(HZ, true, "Saving high scores...");
        bejeweled_savescores(bj);
    }
}

/*****************************************************************************
* bejeweled() is the main game subroutine, it returns the final game status.
******************************************************************************/
static int bejeweled(struct game_context* bj) {
    int i, j;
    int w, h;
    int button;
    int lastbutton = BUTTON_NONE;
    char str[18];
    char *title = "Bejeweled";
    bool breakout = false;
    bool showscores = false;
    bool selected = false;

    /* the cursor coordinates */
    int x=0, y=0;

    /* don't resume by default */
    bj->resume = false;

    /********************
    *       menu        *
    ********************/
    while(true){
        rb->lcd_clear_display();

        if(!showscores) {
             /* welcome screen to display key bindings */
            rb->lcd_getstringsize(title, &w, &h);
            rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, title);
#if CONFIG_KEYPAD == RECORDER_PAD
            rb->lcd_puts(0, 1, "ON to start");
            rb->lcd_puts(0, 2, "F1 to save/resume");
            rb->lcd_puts(0, 3, "OFF to exit");
            rb->lcd_puts(0, 4, "PLAY to select");
            rb->lcd_puts(0, 5, "& show high scores");
            rb->lcd_puts(0, 6, "Directions to move");
            rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
            rb->lcd_puts(0, 7, str);
#elif CONFIG_KEYPAD == ONDIO_PAD
            rb->lcd_puts(0, 1, "RIGHT to start");
            rb->lcd_puts(0, 2, "MENU+OFF to sv/res");
            rb->lcd_puts(0, 3, "OFF to exit");
            rb->lcd_puts(0, 4, "MENU to select");
            rb->lcd_puts(0, 5, "& show high scores");
            rb->lcd_puts(0, 6, "Directions to move");
            rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
            rb->lcd_puts(0, 7, str);
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
            rb->lcd_puts(0, 2, "ON to start");
            rb->lcd_puts(0, 3, "MODE to save/resume");
            rb->lcd_puts(0, 4, "OFF to exit");
            rb->lcd_puts(0, 5, "SELECT to select");
            rb->lcd_puts(0, 6, " and show high scores");
            rb->lcd_puts(0, 7, "Directions to move");
            rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
            rb->lcd_puts(0, 9, str);
#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
            rb->lcd_puts(0, 2, "PLAY to start");
            rb->lcd_puts(0, 3, "SELECT+PLAY to save/resume");
            rb->lcd_puts(0, 4, "SELECT+MENU to exit");
            rb->lcd_puts(0, 5, "SELECT to select");
            rb->lcd_puts(0, 6, " and show high scores");
            rb->lcd_puts(0, 7, "Scroll to move");
            rb->lcd_puts(0, 8, "Directions to swap");
            rb->snprintf(str, 18, "High Score: %d", bj->highscores[0]);
            rb->lcd_puts(0, 10, str);
#endif
        } else {
            /* room for a title? */
            j = 0;
            if(LCD_HEIGHT-NUM_SCORES*8 >= 8) {
                rb->snprintf(str, 12, "%s", "High Scores");
                rb->lcd_getstringsize(str, &w, &h);
                rb->lcd_putsxy((LCD_WIDTH-w)/2, 0, str);
                j = 1;
            }

            /* print high scores */
            for(i=0; i<NUM_SCORES; i++) {
                rb->snprintf(str, 11, "#%02d: %d", i+1, bj->highscores[i]);
                rb->lcd_puts(0, i+j, str);
            }
        }

        rb->lcd_update();

        /* handle menu button presses */
        button = rb->button_get(true);
        switch(button){
            case BEJEWELED_START: /* start playing */
                breakout = true;
                break;

            case BEJEWELED_QUIT:  /* quit program */
                if(showscores) {
                    showscores = 0;
                    break;
                }
                return BJ_QUIT;

            case BEJEWELED_RESUME:/* resume game */
                if(!bejeweled_loadgame(bj)) {
                    rb->splash(HZ*2, true, "Nothing to resume");
                } else {
                    breakout = true;
                }
                break;

            case BEJEWELED_SELECT:/* toggle high scores */
#ifdef BEJEWELED_SELECT_PRE
                if(lastbutton != BEJEWELED_SELECT_PRE) break;
#endif
                showscores = !showscores;
                break;

            default:
                if(rb->default_event_handler_ex(button, bejeweled_callback,
                   (void*) bj) == SYS_USB_CONNECTED)
                    return BJ_USB;
                break;
        }

        if(breakout) break;
        if(button != BUTTON_NONE) lastbutton = button;
    }

    lastbutton = BUTTON_NONE;

    /********************
    *       init        *
    ********************/
    bejeweled_init(bj);

    /********************
    *  setup the board  *
    ********************/
    bejeweled_drawboard(bj);
    bejeweled_putjewels(bj);
    bj->score += bejeweled_runboard(bj);
    if (!bejeweled_movesavail(bj)) return BJ_LOSE;

    /**********************
    *        play         *
    **********************/
    while(true) {
        /* refresh the board */
        bejeweled_drawboard(bj);

        /* display the cursor */
        if(selected) {
            rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
            rb->lcd_fillrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
                             TILE_WIDTH, TILE_HEIGHT);
            rb->lcd_set_drawmode(DRMODE_SOLID);
        } else {
            rb->lcd_drawrect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
                             TILE_WIDTH, TILE_HEIGHT);
        }
        rb->lcd_update_rect(x*TILE_WIDTH, y*TILE_HEIGHT+YOFS,
                            TILE_WIDTH, TILE_HEIGHT);

        /* handle game button presses */
        button = rb->button_get(true);
        switch(button){
            case BEJEWELED_RESUME:           /* save and end game */
                rb->splash(HZ, true, "Saving game...");
                bejeweled_savegame(bj);
                /* fall through to BEJEWELED_QUIT */

            case BEJEWELED_QUIT:             /* end game */
                return BJ_END;

            case BEJEWELED_LEFT:             /* move cursor left */
            case (BEJEWELED_LEFT|BUTTON_REPEAT):
                if(selected) {
                    bj->score += bejeweled_swapjewels(bj, x, y, SWAP_LEFT);
                    selected = false;
                    if (!bejeweled_movesavail(bj)) return BJ_LOSE;
#ifndef BEJEWELED_SCROLLWHEEL
                } else {
                    x = (x+BJ_WIDTH-1)%BJ_WIDTH;
#endif
                }
                break;

            case BEJEWELED_RIGHT:            /* move cursor right */
            case (BEJEWELED_RIGHT|BUTTON_REPEAT):
                if(selected) {
                    bj->score += bejeweled_swapjewels(bj, x, y, SWAP_RIGHT);
                    selected = false;
                    if (!bejeweled_movesavail(bj)) return BJ_LOSE;
#ifndef BEJEWELED_SCROLLWHEEL
                } else {
                    x = (x+1)%BJ_WIDTH;
#endif
                }
                break;

            case BEJEWELED_DOWN:             /* move cursor down */
            case (BEJEWELED_DOWN|BUTTON_REPEAT):
                if(selected) {
                    bj->score += bejeweled_swapjewels(bj, x, y, SWAP_DOWN);
                    selected = false;
                    if (!bejeweled_movesavail(bj)) return BJ_LOSE;
#ifndef BEJEWELED_SCROLLWHEEL
                } else {
                    y = (y+1)%(BJ_HEIGHT-1);
#endif
                }
                break;

            case BEJEWELED_UP:               /* move cursor up */
            case (BEJEWELED_UP|BUTTON_REPEAT):
                if(selected) {
                    bj->score += bejeweled_swapjewels(bj, x, y, SWAP_UP);
                    selected = false;
                    if (!bejeweled_movesavail(bj)) return BJ_LOSE;
#ifndef BEJEWELED_SCROLLWHEEL
                } else {
                    y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
#endif
                }
                break;

#ifdef BEJEWELED_SCROLLWHEEL
            case BEJEWELED_PREV:             /* scroll backwards */
            case (BEJEWELED_PREV|BUTTON_REPEAT):
                if(!selected) {
                    if(x == 0) {
                        y = (y+(BJ_HEIGHT-1)-1)%(BJ_HEIGHT-1);
                    }
                    x = (x+BJ_WIDTH-1)%BJ_WIDTH;
                }
                break;

            case BEJEWELED_NEXT:             /* scroll forwards */
            case (BEJEWELED_NEXT|BUTTON_REPEAT):
                if(!selected) {
                    if(x == BJ_WIDTH-1) {
                        y = (y+1)%(BJ_HEIGHT-1);
                    }
                    x = (x+1)%BJ_WIDTH;
                }
                break;
#endif

            case BEJEWELED_SELECT:           /* toggle selected */
#ifdef BEJEWELED_SELECT_PRE
                if(lastbutton != BEJEWELED_SELECT_PRE) break;
#endif
                selected = !selected;
                break;

            default:
                if(rb->default_event_handler_ex(button, bejeweled_callback,
                   (void*) bj) == SYS_USB_CONNECTED)
                    return BJ_USB;
                break;
        }

        if(button != BUTTON_NONE) lastbutton = button;
        if(bj->score >= LEVEL_PTS) bj->score = bejeweled_nextlevel(bj);
    }
}

/*****************************************************************************
* plugin entry point.
******************************************************************************/
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) {
    struct game_context bj;
    bool exit = false;
    int position;
    char str[19];

    /* plugin init */
    (void)parameter;
    rb = api;
    /* end of plugin init */

    /* load high scores */
    bejeweled_loadscores(&bj);

    rb->lcd_setfont(FONT_SYSFIXED);

    while(!exit) {
        switch(bejeweled(&bj)){
            case BJ_LOSE:
                rb->splash(HZ*2, true, "No more moves!");
                /* fall through to BJ_END */

            case BJ_END:
                if(!bj.resume) {
                    if((position = bejeweled_recordscore(&bj))) {
                        rb->snprintf(str, 19, "New high score #%d!", position);
                        rb->splash(HZ*2, true, str);
                    }
                }
                break;

            case BJ_USB:
                rb->lcd_setfont(FONT_UI);
                return PLUGIN_USB_CONNECTED;

            case BJ_QUIT:
                if(bj.dirty) {
                    rb->splash(HZ, true, "Saving high scores...");
                    bejeweled_savescores(&bj);
                }
                exit = true;
                break;

            default:
                break;
        }
    }

    rb->lcd_setfont(FONT_UI);
    return PLUGIN_OK;
}

#endif
