From b1d6c27aad8eac41d94c0457e5e336a584b3f2c8 Mon Sep 17 00:00:00 2001 From: smurawski Date: Sun, 24 Apr 2022 10:17:25 +0200 Subject: [PATCH] Some chaanges needed for android compilation --- .gitignore | 1 + game.c | 11 ++++++ game.h | 7 +++- getcoeff.c | 17 +++++--- globals.h | 4 ++ learn.c | 11 ++++++ learn.h | 4 ++ macros.h | 18 +++++---- osfbook.c | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++ porting.h | 4 +- 10 files changed, 173 insertions(+), 15 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/game.c b/game.c index a1771b3..0799094 100644 --- a/game.c +++ b/game.c @@ -1574,3 +1574,14 @@ get_pv( int *destin ) { return pv_depth[0] + 1; } } + +void clear_endgame_performed() { + endgame_performed[BLACKSQ] = endgame_performed[WHITESQ] = FALSE; +} + +void clear_evaluated(void) { + game_evaluated_count = 0; +} + + + diff --git a/game.h b/game.h index 6a6a409..f24631a 100644 --- a/game.h +++ b/game.h @@ -51,6 +51,9 @@ void game_init( const char *file_name, int *side_to_move ); +void +clear_endgame_performed( void ); + void set_komi( int in_komi ); @@ -90,6 +93,9 @@ get_evaluated_count( void ); EvaluatedMove get_evaluated( int index ); +void +clear_evaluated( void ); + int compute_move( int side_to_move, int update_all, @@ -111,7 +117,6 @@ int get_pv( int *destin ); - #ifdef __cplusplus } #endif diff --git a/getcoeff.c b/getcoeff.c index e02a3ca..4b1bdb9 100644 --- a/getcoeff.c +++ b/getcoeff.c @@ -929,6 +929,8 @@ init_coeffs( void ) { /* Special hack for CE. */ getcwd(sPatternFile, sizeof(sPatternFile)); strcat(sPatternFile, PATTERN_FILE); +#elif defined(ANDROID) + sprintf(sPatternFile, "%s/%s", android_files_dir, PATTERN_FILE); #elif defined( __linux__ ) /* Linux don't support current directory. */ strcpy( sPatternFile, PATTERN_FILE ); @@ -936,9 +938,8 @@ init_coeffs( void ) { getcwd(sPatternFile, sizeof(sPatternFile)); strcat(sPatternFile, "/" PATTERN_FILE); #endif - char* env_coeffs = getenv("COEFFS_PATH"); - coeff_stream = gzopen(env_coeffs ? env_coeffs : sPatternFile, "rb" ); + coeff_stream = gzopen( sPatternFile, "rb" ); if ( coeff_stream == NULL ) fatal_error( "%s '%s'\n", FILE_ERROR, sPatternFile ); @@ -1046,10 +1047,14 @@ init_coeffs( void ) { static long long int rdtsc( void ) { -#if defined(__GNUC__) - long long a; - asm volatile("rdtsc":"=A" (a)); - return a; +#ifdef _X64_ + #if defined(__GNUC__) + long long a; + asm volatile("rdtsc":"=A" (a)); + return a; + #else + return 0; + #endif #else return 0; #endif diff --git a/globals.h b/globals.h index 2e5a5e5..a6c36dd 100644 --- a/globals.h +++ b/globals.h @@ -54,5 +54,9 @@ extern int white_moves[60]; but all updates must be reversed when the search stops. */ extern Board board; +#ifdef ANDROID +int droidzebra_message_debug(const char* format, ...); +#define printf(format, args...) droidzebra_message_debug(format , ## args) +#endif #endif /* GLOBALS_H */ diff --git a/learn.c b/learn.c index b3a2f2c..64099d3 100644 --- a/learn.c +++ b/learn.c @@ -55,6 +55,17 @@ clear_stored_game( void ) { game_move[i] = ILLEGAL; } +/* + GET_STORED_MOVE + get stored move +*/ + +int +get_stored_move( int index ) { + if(index>60) return ILLEGAL; + return game_move[index]; +} + /* diff --git a/learn.h b/learn.h index 31eb5ad..eafc1a7 100644 --- a/learn.h +++ b/learn.h @@ -26,6 +26,10 @@ extern "C" { void clear_stored_game( void ); +int +get_stored_move( int index ); + + void store_move( int disks_played, int move ); diff --git a/macros.h b/macros.h index f271bf4..b87ef72 100644 --- a/macros.h +++ b/macros.h @@ -43,14 +43,18 @@ extern "C" { /* Define function attributes directive when available */ -#if __GNUC__ >= 3 -#define REGPARM(num) __attribute__((regparm(num))) +#ifdef _X64_ + #if __GNUC__ >= 3 + #define REGPARM(num) __attribute__((regparm(num))) + #else + #if defined (_MSC_VER) || defined(__BORLANDC__) + #define REGPARM(num) __fastcall + #else + #define REGPARM(num) + #endif + #endif #else -#if defined (_MSC_VER) || defined(__BORLANDC__) -#define REGPARM(num) __fastcall -#else -#define REGPARM(num) -#endif + #define REGPARM(num) #endif diff --git a/osfbook.c b/osfbook.c index 56e439c..b4c17f5 100644 --- a/osfbook.c +++ b/osfbook.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include #ifndef _WIN32_WCE #include @@ -3436,6 +3438,115 @@ unpack_compressed_database( const char *in_name, const char *out_name ) { #endif } +void +unpack_compressed_database_gz( const char *in_name, const char *out_name ) { + int i; + int dummy; + int node_count, child_list_size; + int node_index, child_index; + short magic; + short *child_count, *child; + short *black_score, *white_score; + short *alt_move, *alt_score; + time_t start_time, stop_time; + unsigned short *flags; + gzFile *zstream; + FILE * stream; + int zerror; + +#ifdef TEXT_BASED + printf( "Uncompressing compressed database... " ); + fflush( stdout ); +#endif + +#define CHECK_READ(op, size) if((op)!=(size)) fatal_error("error reading compressed database: %s", gzerror(zstream, &zerror)); + + time( &start_time ); + + /* Read the compressed database */ + + zstream = gzopen( in_name, "rb" ); + if ( zstream == NULL ) + fatal_error( "%s '%s'\n", NO_DB_FILE_ERROR, in_name ); + + CHECK_READ( gzread( zstream, &node_count, sizeof( int ) ), sizeof(int) ); + + CHECK_READ( gzread( zstream, &child_list_size, sizeof( int ) ), sizeof( int ) ); + + child_count = (short *) safe_malloc( node_count * sizeof( short ) ); + child = (short *) safe_malloc( child_list_size * sizeof( short ) ); + + CHECK_READ( gzread( zstream, child_count, sizeof( short ) * node_count ), sizeof( short ) * node_count ); + + CHECK_READ( gzread( zstream, child, sizeof( short ) * child_list_size ), sizeof( short ) * child_list_size ); + + black_score = (short *) safe_malloc( node_count * sizeof( short ) ); + white_score = (short *) safe_malloc( node_count * sizeof( short ) ); + alt_move = (short *) safe_malloc( node_count * sizeof( short ) ); + alt_score = (short *) safe_malloc( node_count * sizeof( short ) ); + flags = + (unsigned short *) safe_malloc( node_count * sizeof( unsigned short ) ); + + for ( i = 0; i < node_count; i++ ) { + CHECK_READ( gzread( zstream, &black_score[i], sizeof( short ) ), sizeof( short ) ); + CHECK_READ( gzread( zstream, &white_score[i], sizeof( short ) ), sizeof( short ) ); + } + + CHECK_READ( gzread( zstream, alt_move, sizeof( short ) * node_count ), sizeof( short ) * node_count ); + + CHECK_READ( gzread( zstream, alt_score, sizeof( short ) * node_count ), sizeof( short ) * node_count ); + + CHECK_READ( gzread( zstream, flags, sizeof( unsigned short ) * node_count ), sizeof( unsigned short ) * node_count ); + + gzclose( zstream ); +#undef CHECK_READ + + /* Traverse the tree described by the database and create the .bin file */ + + stream = fopen( out_name, "wb" ); + if ( stream == NULL ) + fatal_error( "%s '%s'\n", DB_WRITE_ERROR, out_name ); + + toggle_experimental( 0 ); + game_init( NULL, &dummy ); + toggle_midgame_hash_usage( TRUE, TRUE ); + toggle_abort_check( FALSE ); + toggle_midgame_abort_check( FALSE ); + + magic = BOOK_MAGIC1; + fwrite( &magic, sizeof( short ), 1, stream); + magic = BOOK_MAGIC2; + fwrite( &magic, sizeof( short ), 1, stream); + + fwrite( &node_count, sizeof( int ), 1, stream); + + node_index = 0; + child_index = 0; + do_uncompress( 0, stream, &node_index, &child_index, child_count, child, + black_score, white_score, alt_move, alt_score, flags ); + + fclose( stream ); + + /* Free tables */ + + free( child_count ); + free( child ); + + free( black_score ); + free( white_score ); + free( alt_move ); + free( alt_score ); + free( flags ); + + time( &stop_time ); + +#ifdef TEXT_BASED + printf( "done (took %d s)\n", (int) (stop_time - start_time) ); + puts( "" ); +#endif +} + + /* diff --git a/porting.h b/porting.h index e223c8c..6aa105e 100644 --- a/porting.h +++ b/porting.h @@ -15,6 +15,8 @@ #ifndef PORTING_H #define PORTING_H - +#ifdef ANDROID +extern char android_files_dir[]; +#endif #endif