From 56905677d5c20e83bd8d10ed5491bec271ea2d7a Mon Sep 17 00:00:00 2001 From: Decker Date: Mon, 11 Mar 2019 05:58:10 +0300 Subject: [PATCH] + msvc build fix --- .gitignore | 1 + src/cc/rogue/extern.h | 9 ++++++++- src/cc/rogue/main.c | 45 ++++++++++++++++++++++++++++++++++++++++++- src/cc/rogue/rogue.c | 27 ++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 2ab07ee0f..9f05e147c 100644 --- a/.gitignore +++ b/.gitignore @@ -154,3 +154,4 @@ src/ROGUE.conf src/rogue.scr src/cc/rogue/confdefs.h +src/cc/rogue/x64 diff --git a/src/cc/rogue/extern.h b/src/cc/rogue/extern.h index 7fba842f3..c62646b67 100644 --- a/src/cc/rogue/extern.h +++ b/src/cc/rogue/extern.h @@ -107,6 +107,12 @@ #include #include +#ifdef _WIN32 +#ifdef _MSC_VER +#include +#endif +#endif + #undef SIGTSTP #define MAXSTR 1024 /* maximum length of strings */ @@ -142,7 +148,8 @@ void leave(int); void my_exit(int st); void playltchars(void); void quit(int); -int32_t _quit(); +int32_t _quit(); + void resetltchars(void); void set_order(int *order, int numthings); void tstp(int ignored); diff --git a/src/cc/rogue/main.c b/src/cc/rogue/main.c index c2155a085..da46898f8 100644 --- a/src/cc/rogue/main.c +++ b/src/cc/rogue/main.c @@ -38,6 +38,31 @@ union _bits256 { uint8_t bytes[32]; uint16_t ushorts[16]; uint32_t uints[8]; uin typedef union _bits256 bits256; #endif +#ifdef _WIN32 +#ifdef _MSC_VER +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + static const uint64_t EPOCH = ((uint64_t)116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime(&system_time); + SystemTimeToFileTime(&system_time, &file_time); + time = ((uint64_t)file_time.dwLowDateTime); + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long)((time - EPOCH) / 10000000L); + tp->tv_usec = (long)(system_time.wMilliseconds * 1000); + return 0; +} +#endif // _MSC_VER +#endif + + + double OS_milliseconds() { struct timeval tv; double millis; @@ -392,6 +417,12 @@ char *post_process_bitcoind_RPC(char *debugstr,char *command,char *rpcstr,char * } #endif +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + /************************************************************************ * * perform the query @@ -919,7 +950,19 @@ int main(int argc, char **argv, char **envp) printf("ASSETCHAINS_SYMBOL.(%s) port.%u (%s) IPADDRESS.%s \n",ASSETCHAINS_SYMBOL,ROGUE_PORT,USERPASS,IPADDRESS); sleep(1); if ( argc == 2 && (fp=fopen(argv[1],"rb")) == 0 ) { - seed = atol(argv[1]); + + #ifdef _WIN32 + #ifdef _MSC_VER + seed = _strtoui64(argv[1], NULL, 10); + fprintf(stderr, "replay seed.str(%s) seed.uint64_t(%I64u)", argv[1], seed); + #else + fprintf(stderr, "replay seed.str(%s) seed.uint64_t(%llu)", argv[1], (long long)seed); + seed = atol(argv[1]); // windows, but not MSVC + #endif // _MSC_VER + #else + seed = atol(argv[1]); // non-windows + #endif // _WIN32 + //fprintf(stderr,"replay %llu\n",(long long)seed); return(rogue_replay(seed,10)); } diff --git a/src/cc/rogue/rogue.c b/src/cc/rogue/rogue.c index 352e950ec..36616b340 100644 --- a/src/cc/rogue/rogue.c +++ b/src/cc/rogue/rogue.c @@ -13,6 +13,7 @@ #include //#include //#include + #include "rogue.h" #ifdef STANDALONE #include "../komodo/src/komodo_cJSON.h" @@ -196,6 +197,12 @@ void rogue_bailout(struct rogue_state *rs) fprintf(stderr,"error issuing (%s)\n",cmd);*/ } +#ifdef _WIN32 +#ifdef _MSC_VER +#define sleep(x) Sleep(1000*(x)) +#endif +#endif + int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t num,struct rogue_player *player,int32_t sleepmillis) { struct rogue_state *rs; FILE *fp; int32_t i,n; @@ -215,6 +222,14 @@ int32_t rogue_replay2(uint8_t *newdata,uint64_t seed,char *keystrokes,int32_t nu globalR = *rs; uint32_t starttime = (uint32_t)time(NULL); rogueiterate(rs); + + /* + // keypress after replay + printf("[Press return to continue]"); + fflush(stdout); + if (fgets(prbuf, 10, stdin) != 0); + */ + if ( 0 ) { fprintf(stderr,"elapsed %d seconds\n",(uint32_t)time(NULL) - starttime); @@ -526,6 +541,18 @@ tstp(int ignored) #endif*/ } + +#ifdef _WIN32 +#ifdef _MSC_VER +void usleep(int32_t micros) +{ + if (micros < 1000) + Sleep(1); + else Sleep(micros / 1000); +} +#endif +#endif + /* * playit: * The main loop of the program. Loop until the game is over,