summaryrefslogtreecommitdiff
path: root/apps/plugins/chessbox
diff options
context:
space:
mode:
authorAndrew Mahone <andrew.mahone@gmail.com>2009-01-16 10:34:40 +0000
committerAndrew Mahone <andrew.mahone@gmail.com>2009-01-16 10:34:40 +0000
commit23d9812273d9c74af72ccdc3aa4cfea971f220a4 (patch)
tree8e60c3a2a41879f8b2a52516fa416b3ab906e239 /apps/plugins/chessbox
parent35677cbc54bbe400ebbff59b489dda7ca7f04916 (diff)
loader-initialized global plugin API:
struct plugin_api *rb is declared in PLUGIN_HEADER, and pointed to by __header.api the loader uses this pointer to initialize rb before calling entry_point entry_point is no longer passed a pointer to the plugin API all plugins, and pluginlib functions, are modified to refer to the global rb pluginlib functions which only served to copy the API pointer are removed git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19776 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/chessbox')
-rw-r--r--apps/plugins/chessbox/chessbox.c29
-rw-r--r--apps/plugins/chessbox/chessbox_pgn.c29
-rw-r--r--apps/plugins/chessbox/chessbox_pgn.h16
-rw-r--r--apps/plugins/chessbox/gnuchess.c3
-rw-r--r--apps/plugins/chessbox/gnuchess.h3
5 files changed, 28 insertions, 52 deletions
diff --git a/apps/plugins/chessbox/chessbox.c b/apps/plugins/chessbox/chessbox.c
index f8db7d9b7f..64f8965947 100644
--- a/apps/plugins/chessbox/chessbox.c
+++ b/apps/plugins/chessbox/chessbox.c
@@ -450,19 +450,19 @@ void cb_start_viewer(char* filename){
bool exit_viewer = false;
struct cb_command command;
- first_game = pgn_list_games(rb, filename);
+ first_game = pgn_list_games(filename);
if (first_game == NULL){
rb->splash ( HZ*2 , "No games found !" );
return;
}
do {
- selected_game = pgn_show_game_list(rb, first_game);
+ selected_game = pgn_show_game_list(first_game);
if (selected_game == NULL){
break;
}
- pgn_parse_game(rb, filename, selected_game);
+ pgn_parse_game(filename, selected_game);
if (selected_game->first_ply != NULL) {
/* init board */
@@ -769,7 +769,7 @@ void cb_play_game(void) {
GNUChess_Initialize();
/* init PGN history data structures */
- game = pgn_init_game(rb);
+ game = pgn_init_game();
/* restore saved position, if saved */
cb_restoreposition();
@@ -783,9 +783,9 @@ void cb_play_game(void) {
if ( mate ) {
rb->splash ( HZ*3 , "Checkmate!" );
rb->button_get(true);
- pgn_store_game(rb, game);
+ pgn_store_game(game);
GNUChess_Initialize();
- game = pgn_init_game(rb);
+ game = pgn_init_game();
cb_drawboard();
}
command = cb_getcommand ();
@@ -798,7 +798,7 @@ void cb_play_game(void) {
cb_drawboard();
/* Add the ply to the PGN history (in algebraic notation) */
- pgn_append_ply(rb, game, opponent, move_buffer, mate);
+ pgn_append_ply(game, opponent, move_buffer, mate);
rb->splash ( 0 , "Thinking..." );
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
@@ -812,9 +812,9 @@ void cb_play_game(void) {
* for the result of the game which is only calculated in SelectMove
*/
if (move_buffer[0] != '\0'){
- pgn_append_ply(rb, game, computer, move_buffer, mate);
+ pgn_append_ply(game, computer, move_buffer, mate);
} else {
- pgn_set_result(rb, game, mate);
+ pgn_set_result(game, mate);
}
if ( wt_command == COMMAND_QUIT ) {
@@ -827,7 +827,7 @@ void cb_play_game(void) {
#ifdef COMMAND_RESTART
case COMMAND_RESTART:
GNUChess_Initialize();
- game = pgn_init_game(rb);
+ game = pgn_init_game();
cb_drawboard();
break;
#endif
@@ -845,7 +845,7 @@ void cb_play_game(void) {
GNUChess_Initialize();
/* init PGN history data structures */
- game = pgn_init_game(rb);
+ game = pgn_init_game();
/* restore saved position, if saved */
cb_restoreposition();
@@ -874,9 +874,9 @@ void cb_play_game(void) {
* for the result of the game which is only calculated in SelectMove
*/
if (move_buffer[0] != '\0'){
- pgn_append_ply(rb, game, computer, move_buffer, mate);
+ pgn_append_ply(game, computer, move_buffer, mate);
} else {
- pgn_set_result(rb, game, mate);
+ pgn_set_result(game, mate);
}
if ( wt_command == COMMAND_QUIT ) {
@@ -904,11 +904,10 @@ void cb_play_game(void) {
/*****************************************************************************
* plugin entry point.
******************************************************************************/
-enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) {
+enum plugin_status plugin_start(const void* parameter) {
/* plugin init */
- rb = api;
#if LCD_DEPTH > 1
rb->lcd_set_backdrop(NULL);
#endif
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c
index 8c92573b75..a8be179fac 100644
--- a/apps/plugins/chessbox/chessbox_pgn.c
+++ b/apps/plugins/chessbox/chessbox_pgn.c
@@ -26,8 +26,6 @@
#define LOG_FILE PLUGIN_GAMES_DIR "/chessbox.log"
int loghandler;
-const struct plugin_api* rb;
-
short kn_offs[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{1,-2},{-1,2},{-1,-2}};
short rk_offs[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
short bp_offs[4][2] = {{1,1},{-1,1},{1,-1},{-1,-1}};
@@ -559,7 +557,7 @@ void write_pgn_token(int fhandler, char *buffer, size_t *line_length){
}
/* ---- api functions ---- */
-struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* filename){
+struct pgn_game_node* pgn_list_games(const char* filename){
int fhandler;
char line_buffer[128];
struct pgn_game_node size_node, *first_game = NULL;
@@ -567,7 +565,6 @@ struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* fi
unsigned short game_count = 1;
int line_count = 0;
bool header_start = true, game_start = false;
- rb = api;
if ( (fhandler = rb->open(filename, O_RDONLY)) == 0 ) return NULL;
@@ -617,16 +614,13 @@ struct pgn_game_node* pgn_list_games(const struct plugin_api* api,const char* fi
return first_game;
}
-struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api,
- struct pgn_game_node* first_game){
+struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game){
int curr_selection = 0;
int button;
struct gui_synclist games_list;
int i;
struct pgn_game_node *temp_node = first_game;
- rb=api;
-
for (i=0;temp_node != NULL;i++){
temp_node = temp_node->next_node;
}
@@ -661,7 +655,7 @@ struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api,
}
}
-void pgn_parse_game(const struct plugin_api* api, const char* filename,
+void pgn_parse_game(const char* filename,
struct pgn_game_node* selected_game){
struct pgn_ply_node size_ply, *first_ply = NULL;
struct pgn_ply_node *temp_ply = NULL, *curr_node = NULL;
@@ -670,7 +664,6 @@ void pgn_parse_game(const struct plugin_api* api, const char* filename,
char token_buffer[10];
unsigned short pos;
unsigned short curr_player = white;
- rb = api;
fhandler = rb->open(filename, O_RDONLY);
@@ -731,13 +724,11 @@ void pgn_parse_game(const struct plugin_api* api, const char* filename,
rb->close(fhandler);
}
-struct pgn_game_node* pgn_init_game(const struct plugin_api* api){
+struct pgn_game_node* pgn_init_game(void){
struct pgn_game_node game_size, *game;
struct pgn_ply_node ply_size, *ply;
struct tm *current_time;
- rb = api;
-
if (bufptr == NULL){
pl_malloc_init();
}
@@ -769,12 +760,10 @@ struct pgn_game_node* pgn_init_game(const struct plugin_api* api){
return game;
}
-void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game,
+void pgn_append_ply(struct pgn_game_node* game,
unsigned short ply_player, char *move_buffer, bool is_mate){
struct pgn_ply_node ply_size, *ply, *temp;
- rb = api;
-
ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size);
ply->player = ply_player;
ply->column_from = move_buffer[0] - 'a';
@@ -803,11 +792,9 @@ void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game,
temp->prev_node = ply;
}
-void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game,
+void pgn_set_result(struct pgn_game_node* game,
bool is_mate){
- rb = api;
-
struct pgn_ply_node *ply;
for(ply=game->first_ply;ply->next_node != NULL;ply=ply->next_node);
if (is_mate){
@@ -817,15 +804,13 @@ void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game,
}
}
-void pgn_store_game(const struct plugin_api* api, struct pgn_game_node* game){
+void pgn_store_game(struct pgn_game_node* game){
int fhandler;
struct pgn_ply_node *ply;
unsigned ply_count;
size_t line_length=0;
char buffer[10];
- rb = api;
-
GNUChess_Initialize();
ply_count=0;
diff --git a/apps/plugins/chessbox/chessbox_pgn.h b/apps/plugins/chessbox/chessbox_pgn.h
index 351a32ac57..24830a5f48 100644
--- a/apps/plugins/chessbox/chessbox_pgn.h
+++ b/apps/plugins/chessbox/chessbox_pgn.h
@@ -408,35 +408,33 @@ struct pgn_game_node {
* the user selects a game, that obviously saves processing
* and speeds up response when the user selects the file
*/
-struct pgn_game_node* pgn_list_games(const struct plugin_api* api,
- const char* filename);
+struct pgn_game_node* pgn_list_games(const char* filename);
/* Show the list of games found in a file and allow the user
* to select a game to be parsed and showed
*/
-struct pgn_game_node* pgn_show_game_list(const struct plugin_api* api,
- struct pgn_game_node* first_game);
+struct pgn_game_node* pgn_show_game_list(struct pgn_game_node* first_game);
/* Parse the pgn string of a game and assign it to the move
* list in the structure
*/
-void pgn_parse_game(const struct plugin_api* api, const char* filename,
+void pgn_parse_game(const char* filename,
struct pgn_game_node* selected_game);
/* Initialize a new game structure with default values and make
* it ready to store the history of a newly played match
*/
-struct pgn_game_node* pgn_init_game(const struct plugin_api* api);
+struct pgn_game_node* pgn_init_game(void);
/* Add a new ply to the game structure based on the positions */
-void pgn_append_ply(const struct plugin_api* api, struct pgn_game_node* game,
+void pgn_append_ply(struct pgn_game_node* game,
unsigned short ply_player, char *move_buffer, bool is_mate);
/* Set the result of the game if it was reached during the opponent's ply
*/
-void pgn_set_result(const struct plugin_api* api, struct pgn_game_node* game,
+void pgn_set_result(struct pgn_game_node* game,
bool is_mate);
/* Store a complete game in the PGN history file
*/
-void pgn_store_game(const struct plugin_api* api, struct pgn_game_node* game);
+void pgn_store_game(struct pgn_game_node* game);
diff --git a/apps/plugins/chessbox/gnuchess.c b/apps/plugins/chessbox/gnuchess.c
index 51e200d0f2..b8fef724fc 100644
--- a/apps/plugins/chessbox/gnuchess.c
+++ b/apps/plugins/chessbox/gnuchess.c
@@ -63,9 +63,6 @@
#define absv(x) ((x) < 0 ? -(x) : (x))
#define taxicab(a,b) (abs(column[a]-column[b]) + abs(row[a]-row[b]))
-/* ---- RockBox datatypes and variables */
-const struct plugin_api* rb;
-
/* ---- Chess datatypes and variables ---- */
struct leaf
{
diff --git a/apps/plugins/chessbox/gnuchess.h b/apps/plugins/chessbox/gnuchess.h
index b80647a287..511b8808c0 100644
--- a/apps/plugins/chessbox/gnuchess.h
+++ b/apps/plugins/chessbox/gnuchess.h
@@ -43,9 +43,6 @@ extern short GameCnt,Game50,castld[2],kingmoved[2],OperatorTime;
extern struct TimeControlRec TimeControl;
extern struct GameRec GameList[240];
-/* ---- RockBox integration ---- */
-extern const struct plugin_api* rb;
-
/* ---- The beginning of a GNUChess v2 APIfication ---- */
void SetTimeControl(void);
void GNUChess_Initialize(void);