blob: 48357ee5faad3091f39b21cfee16d581ebff78b9 [file] [log] [blame]
Dave Chapmanbc6c62b2007-08-19 18:24:17 +00001/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2007 Mauricio Peccorini
11*
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012* This program is free software; you can redistribute it and/or
13* modify it under the terms of the GNU General Public License
14* as published by the Free Software Foundation; either version 2
15* of the License, or (at your option) any later version.
Dave Chapmanbc6c62b2007-08-19 18:24:17 +000016*
17* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18* KIND, either express or implied.
19*
20****************************************************************************/
21
22#include "plugin.h"
23#include "gnuchess.h"
24
Jens Arnold106ac752008-03-22 14:20:04 +000025/* button definitions */
26#if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
27 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
28#define CB_SELECT BUTTON_SELECT
29#define CB_UP BUTTON_MENU
30#define CB_DOWN BUTTON_PLAY
31#define CB_LEFT BUTTON_LEFT
32#define CB_RIGHT BUTTON_RIGHT
33#define CB_PLAY (BUTTON_SELECT | BUTTON_PLAY)
34#define CB_LEVEL (BUTTON_SELECT | BUTTON_RIGHT)
35#define CB_RESTART (BUTTON_SELECT | BUTTON_LEFT)
36#define CB_MENU (BUTTON_SELECT | BUTTON_MENU)
37
38#define CB_SCROLL_UP (BUTTON_SCROLL_FWD|BUTTON_REPEAT)
39#define CB_SCROLL_DOWN (BUTTON_SCROLL_BACK|BUTTON_REPEAT)
40#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
41#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
42
43#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
44#define CB_SELECT BUTTON_SELECT
45#define CB_UP BUTTON_UP
46#define CB_DOWN BUTTON_DOWN
47#define CB_LEFT BUTTON_LEFT
48#define CB_RIGHT BUTTON_RIGHT
49#define CB_PLAY BUTTON_PLAY
50#define CB_LEVEL BUTTON_REC
51#define CB_RESTART (BUTTON_SELECT | BUTTON_PLAY)
52#define CB_MENU BUTTON_POWER
53
54#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
55#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
56#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
57#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
58
59#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || (CONFIG_KEYPAD == IRIVER_H300_PAD)
60#define CB_SELECT BUTTON_SELECT
61#define CB_UP BUTTON_UP
62#define CB_DOWN BUTTON_DOWN
63#define CB_LEFT BUTTON_LEFT
64#define CB_RIGHT BUTTON_RIGHT
65#define CB_PLAY BUTTON_ON
66#define CB_LEVEL BUTTON_MODE
67#define CB_RESTART BUTTON_REC
68#define CB_MENU BUTTON_OFF
69
70#define CB_RC_QUIT BUTTON_RC_STOP
71
72#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
73#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
74#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
75#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
76
77#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
78#define CB_SELECT BUTTON_SELECT
79#define CB_UP BUTTON_UP
80#define CB_DOWN BUTTON_DOWN
81#define CB_LEFT BUTTON_LEFT
82#define CB_RIGHT BUTTON_RIGHT
83#define CB_PLAY BUTTON_PLAY
84#define CB_LEVEL BUTTON_EQ
85#define CB_MENU BUTTON_MODE
86
87#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
88#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
89#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
90#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
91
92#elif CONFIG_KEYPAD == RECORDER_PAD
93#define CB_SELECT BUTTON_PLAY
94#define CB_UP BUTTON_UP
95#define CB_DOWN BUTTON_DOWN
96#define CB_LEFT BUTTON_LEFT
97#define CB_RIGHT BUTTON_RIGHT
98#define CB_PLAY BUTTON_ON
99#define CB_LEVEL BUTTON_F1
100#define CB_RESTART BUTTON_F3
101#define CB_MENU BUTTON_OFF
102
103#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
104#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
105#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
106#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
107
108#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
109#define CB_SELECT BUTTON_SELECT
110#define CB_UP BUTTON_UP
111#define CB_DOWN BUTTON_DOWN
112#define CB_LEFT BUTTON_LEFT
113#define CB_RIGHT BUTTON_RIGHT
114#define CB_PLAY BUTTON_ON
115#define CB_LEVEL BUTTON_F1
116#define CB_RESTART BUTTON_F3
117#define CB_MENU BUTTON_OFF
118
119#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
120#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
121#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
122#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
123
124#elif CONFIG_KEYPAD == ONDIO_PAD
125#define CB_SELECT_PRE BUTTON_MENU
126#define CB_SELECT (BUTTON_MENU|BUTTON_REL)
127#define CB_UP BUTTON_UP
128#define CB_DOWN BUTTON_DOWN
129#define CB_LEFT BUTTON_LEFT
130#define CB_RIGHT BUTTON_RIGHT
131#define CB_PLAY_PRE BUTTON_MENU
132#define CB_PLAY (BUTTON_MENU|BUTTON_REPEAT)
133#define CB_LEVEL (BUTTON_MENU|BUTTON_OFF)
134#define CB_RESTART (BUTTON_MENU|BUTTON_LEFT)
135#define CB_MENU BUTTON_OFF
136
137#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
138#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
139#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
140#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
141
142#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
143#define CB_SELECT BUTTON_SELECT
144#define CB_UP BUTTON_UP
145#define CB_DOWN BUTTON_DOWN
146#define CB_LEFT BUTTON_LEFT
147#define CB_RIGHT BUTTON_RIGHT
148#define CB_PLAY BUTTON_A
149#define CB_LEVEL BUTTON_MENU
150#define CB_MENU BUTTON_POWER
151
152#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
153#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
154#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
155#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
156
Michael Sevakisa74d1502008-05-02 00:38:11 +0000157#elif (CONFIG_KEYPAD == GIGABEAT_S_PAD)
158#define CB_SELECT BUTTON_SELECT
159#define CB_UP BUTTON_UP
160#define CB_DOWN BUTTON_DOWN
161#define CB_LEFT BUTTON_LEFT
162#define CB_RIGHT BUTTON_RIGHT
163#define CB_PLAY BUTTON_PLAY
164#define CB_LEVEL BUTTON_MENU
165#define CB_MENU BUTTON_POWER
166
167#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
168#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
169#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
170#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
171
Jens Arnold106ac752008-03-22 14:20:04 +0000172#elif CONFIG_KEYPAD == IRIVER_H10_PAD
173#define CB_SELECT BUTTON_REW
174#define CB_UP BUTTON_SCROLL_UP
175#define CB_DOWN BUTTON_SCROLL_DOWN
176#define CB_LEFT BUTTON_LEFT
177#define CB_RIGHT BUTTON_RIGHT
178#define CB_PLAY BUTTON_PLAY
179#define CB_LEVEL BUTTON_FF
180#define CB_RESTART (BUTTON_REW | BUTTON_PLAY)
181#define CB_MENU BUTTON_POWER
182
183#define CB_SCROLL_UP (BUTTON_SCROLL_BACK|BUTTON_REPEAT)
184#define CB_SCROLL_DOWN (BUTTON_SCROLL_FWD|BUTTON_REPEAT)
185#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
186#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
187
188#elif CONFIG_KEYPAD == SANSA_E200_PAD
189#define CB_SELECT BUTTON_SELECT
190#define CB_UP BUTTON_UP
191#define CB_DOWN BUTTON_DOWN
192#define CB_LEFT BUTTON_LEFT
193#define CB_RIGHT BUTTON_RIGHT
194#define CB_PLAY (BUTTON_SELECT | BUTTON_RIGHT)
195#define CB_LEVEL BUTTON_REC
196#define CB_RESTART (BUTTON_SELECT | BUTTON_REPEAT)
197#define CB_MENU BUTTON_POWER
198
199#define CB_SCROLL_UP (BUTTON_SCROLL_UP|BUTTON_REPEAT)
200#define CB_SCROLL_DOWN (BUTTON_SCROLL_DOWN|BUTTON_REPEAT)
201#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
202#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
203
204#elif CONFIG_KEYPAD == SANSA_C200_PAD
205#define CB_SELECT BUTTON_SELECT
206#define CB_UP BUTTON_UP
207#define CB_DOWN BUTTON_DOWN
208#define CB_LEFT BUTTON_LEFT
209#define CB_RIGHT BUTTON_RIGHT
210#define CB_PLAY BUTTON_VOL_UP
211#define CB_LEVEL BUTTON_REC
212#define CB_MENU BUTTON_POWER
213
214#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
215#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
216#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
217#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
218
219#elif CONFIG_KEYPAD == MROBE500_PAD
220#define CB_SELECT BUTTON_RC_MODE
221#define CB_UP BUTTON_RC_PLAY
222#define CB_DOWN BUTTON_RC_DOWN
223#define CB_LEFT BUTTON_RC_REW
224#define CB_RIGHT BUTTON_RC_FF
225#define CB_PLAY BUTTON_RC_HEART
226#define CB_LEVEL BUTTON_RC_VOL_DOWN
227#define CB_MENU BUTTON_POWER
228
229#define CB_SCROLL_UP (BUTTON_RC_PLAY|BUTTON_REPEAT)
230#define CB_SCROLL_DOWN (BUTTON_RC_DOWN|BUTTON_REPEAT)
231#define CB_SCROLL_LEFT (BUTTON_RC_REW|BUTTON_REPEAT)
232#define CB_SCROLL_RIGHT (BUTTON_RC_FF|BUTTON_REPEAT)
233
234#elif (CONFIG_KEYPAD == MROBE100_PAD)
235#define CB_SELECT BUTTON_SELECT
236#define CB_UP BUTTON_UP
237#define CB_DOWN BUTTON_DOWN
238#define CB_LEFT BUTTON_LEFT
239#define CB_RIGHT BUTTON_RIGHT
240#define CB_PLAY BUTTON_PLAY
241#define CB_LEVEL BUTTON_DISPLAY
242#define CB_MENU BUTTON_POWER
243
244#define CB_SCROLL_UP (BUTTON_UP|BUTTON_REPEAT)
245#define CB_SCROLL_DOWN (BUTTON_DOWN|BUTTON_REPEAT)
246#define CB_SCROLL_LEFT (BUTTON_LEFT|BUTTON_REPEAT)
247#define CB_SCROLL_RIGHT (BUTTON_RIGHT|BUTTON_REPEAT)
248
249#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
250#define CB_SELECT BUTTON_RC_PLAY
251#define CB_UP BUTTON_RC_VOL_UP
252#define CB_DOWN BUTTON_RC_VOL_DOWN
253#define CB_LEFT BUTTON_RC_REW
254#define CB_RIGHT BUTTON_RC_FF
255#define CB_PLAY BUTTON_RC_MODE
256#define CB_LEVEL BUTTON_RC_MENU
257#define CB_RESTART (BUTTON_RC_PLAY|BUTTON_REPEAT)
258#define CB_MENU BUTTON_RC_REC
259
260#define CB_SCROLL_UP (BUTTON_RC_VOL_UP|BUTTON_REPEAT)
261#define CB_SCROLL_DOWN (BUTTON_RC_VOL_DOWN|BUTTON_REPEAT)
262#define CB_SCROLL_LEFT (BUTTON_RC_REW|BUTTON_REPEAT)
263#define CB_SCROLL_RIGHT (BUTTON_RC_FF|BUTTON_REPEAT)
264
265#define CB_RC_QUIT BUTTON_REC
266
Rob Purchase554d7ed2008-03-22 22:03:34 +0000267#elif CONFIG_KEYPAD == COWOND2_PAD
Rob Purchase554d7ed2008-03-22 22:03:34 +0000268#define CB_LEVEL BUTTON_PLUS
Rob Purchase297e0502008-04-27 15:30:19 +0000269#define CB_RESTART BUTTON_MINUS
270#define CB_MENU (BUTTON_MENU|BUTTON_REL)
Rob Purchase554d7ed2008-03-22 22:03:34 +0000271
Rob Purchase554d7ed2008-03-22 22:03:34 +0000272
Jens Arnold106ac752008-03-22 14:20:04 +0000273#else
274#error No keymap defined!
275#endif
276
Rob Purchase297e0502008-04-27 15:30:19 +0000277#ifdef HAVE_TOUCHPAD
278#ifndef CB_LEVEL
279#define CB_LEVEL BUTTON_TOPLEFT
280#endif
281#ifndef CB_RESTART
282#define CB_RESTART BUTTON_TOPRIGHT
283#endif
284#ifndef CB_MENU
285#define CB_MENU (BUTTON_BOTTOMLEFT|BUTTON_REL)
286#endif
287#ifndef CB_PLAY
288#define CB_PLAY (BUTTON_CENTER|BUTTON_REPEAT)
289#endif
290#ifndef CB_SELECT
291#define CB_SELECT BUTTON_CENTER
292#endif
293#ifndef CB_UP
294#define CB_UP BUTTON_TOPMIDDLE
295#endif
296#ifndef CB_DOWN
297#define CB_DOWN BUTTON_BOTTOMMIDDLE
298#endif
299#ifndef CB_LEFT
300#define CB_LEFT BUTTON_MIDLEFT
301#endif
302#ifndef CB_RIGHT
303#define CB_RIGHT BUTTON_MIDRIGHT
304#endif
305#ifndef CB_SCROLL_UP
306#define CB_SCROLL_UP (BUTTON_TOPMIDDLE|BUTTON_REPEAT)
307#endif
308#ifndef CB_SCROLL_DOWN
309#define CB_SCROLL_DOWN (BUTTON_BOTTOMMIDDLE|BUTTON_REPEAT)
310#endif
311#ifndef CB_SCROLL_LEFT
312#define CB_SCROLL_LEFT (BUTTON_MIDLEFT|BUTTON_REPEAT)
313#endif
314#ifndef CB_SCROLL_RIGHT
315#define CB_SCROLL_RIGHT (BUTTON_MIDRIGHT|BUTTON_REPEAT)
316#endif
317#endif
318
Dave Chapmanbc6c62b2007-08-19 18:24:17 +0000319/* structure to represent the plies */
320struct pgn_ply_node {
321 unsigned short player;
322 char pgn_text[9];
323 unsigned short row_from;
324 unsigned short column_from;
325 unsigned short row_to;
326 unsigned short column_to;
327 unsigned short taken_piece;
328 unsigned short promotion_piece;
329 bool enpassant;
330 bool castle;
331 bool promotion;
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000332 bool checkmate;
333 bool draw;
Dave Chapmanbc6c62b2007-08-19 18:24:17 +0000334 struct pgn_ply_node* prev_node;
335 struct pgn_ply_node* next_node;
336};
337
338/* structure to list the games */
339struct pgn_game_node {
340 unsigned short game_number;
341 char white_player[20];
342 char black_player[20];
343 char game_date[11];
344 char result[8];
345 int pgn_line;
346 struct pgn_ply_node* first_ply;
347 struct pgn_game_node* next_node;
348};
349
350/* Return the list of games in a PGN file.
351 * Parsing of the games themselves is postponed until
352 * the user selects a game, that obviously saves processing
353 * and speeds up response when the user selects the file
354 */
Steve Bavin65265772008-05-13 09:57:56 +0000355struct pgn_game_node* pgn_list_games(const struct plugin_api* api,
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000356 const char* filename);
Dave Chapmanbc6c62b2007-08-19 18:24:17 +0000357
358/* Show the list of games found in a file and allow the user
359 * to select a game to be parsed and showed
360 */
Steve Bavin65265772008-05-13 09:57:56 +0000361struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api,
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000362 struct pgn_game_node* first_game);
Dave Chapmanbc6c62b2007-08-19 18:24:17 +0000363
364/* Parse the pgn string of a game and assign it to the move
365 * list in the structure
366 */
Steve Bavin65265772008-05-13 09:57:56 +0000367void pgn_parse_game(const struct plugin_api* api, const char* filename,
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000368 struct pgn_game_node* selected_game);
369
370/* Initialize a new game structure with default values and make
371 * it ready to store the history of a newly played match
372 */
Steve Bavin65265772008-05-13 09:57:56 +0000373struct pgn_game_node* pgn_init_game(const struct plugin_api* api);
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000374
375/* Add a new ply to the game structure based on the positions */
Steve Bavin65265772008-05-13 09:57:56 +0000376void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game,
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000377 unsigned short ply_player, char *move_buffer, bool is_mate);
378
379/* Set the result of the game if it was reached during the opponent's ply
380 */
Steve Bavin65265772008-05-13 09:57:56 +0000381void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game,
Nils Wallménius5ccf1802007-09-02 10:11:46 +0000382 bool is_mate);
383
384/* Store a complete game in the PGN history file
385 */
Steve Bavin65265772008-05-13 09:57:56 +0000386void pgn_store_game(const struct plugin_api* api, struct pgn_game_node* game);