Пример #1
0
static uae_u32 REGPARAM2 expamem_wget (uaecptr addr)
{
    uae_u32 v = (expamem_bget (addr) << 8) | expamem_bget (addr + 1);
    write_log ("warning: READ.W from address $%lx=%04x PC=%x\n", addr, v & 0xffff, M68K_GETPC);
    return v;
}
bool CSymbolEngineOpenPPLHandAndBoardExpression::EvaluateSymbol(const char *name, double *result, bool log /* = false */) {
	// First check, if hand$ or board$ and/or Suited
	// At the same time remove the unnecessary parts of the expression
	if (memcmp(name, "hand$", 5) == 0) {
		is_hand_expression  = true;
		is_board_expression = false;
		hand_or_board_expression = name;
		write_log(preferences.debug_hand_and_baord_expressions(), 
			"[CSymbolEngineOpenPPLHandAndBoardExpression] Evaluating %s\n",
			hand_or_board_expression);
		hand_or_board_expression = CStringRemoveLeft(hand_or_board_expression, 5);
		prime_coded_available_ranks = _prime_coded_hole_cards;
	}	else if	(memcmp(name, "board$", 6) == 0) {
		is_hand_expression  = false;
		is_board_expression = true;
		hand_or_board_expression = name;
		write_log(preferences.debug_hand_and_baord_expressions(), 
			"[CSymbolEngineOpenPPLHandAndBoardExpression] Evaluating %s\n",
			hand_or_board_expression);
		hand_or_board_expression = CStringRemoveLeft(hand_or_board_expression, 6);
		prime_coded_available_ranks = _prime_coded_board_cards;
	}	else {
		// Quick exit on other symbols
		return false;
	}

  write_log(preferences.debug_hand_and_baord_expressions(), 
    "[CSymbolEngineOpenPPLHandAndBoardExpression] Encoded available ranks> %i\n",
    prime_coded_available_ranks);
	bool is_suited_expression = false;
	assert(is_hand_expression || is_board_expression);

	if (hand_or_board_expression.Right(6).MakeLower() == "suited") {
		write_log(preferences.debug_hand_and_baord_expressions(), 
			"[CSymbolEngineOpenPPLHandAndBoardExpression] Suited expression\n");
		is_suited_expression = true;
		hand_or_board_expression = CStringRemoveRight(
			hand_or_board_expression, 6);
	}
	// Checking ranks with potential multiplicity > 1, not caring about suits.
	// We do this at the very beginning, as this is a very quick test
	// and most real-world-use-cases will be false, so we get a fast exit.
	int prime_coded_search_expression = PrimeCodedRanks(hand_or_board_expression);
  write_log(preferences.debug_hand_and_baord_expressions(), 
    "[CSymbolEngineOpenPPLHandAndBoardExpression] Encoded searched ranks> %i\n",
    prime_coded_available_ranks);
	if ((prime_coded_available_ranks % prime_coded_search_expression) != 0)	{
		// Division without reminder not possible.
		// Therefore different primes in the search-expression
		// Therefore ranks that do not fit available ranks.
		write_log(preferences.debug_hand_and_baord_expressions(), 
			"[CSymbolEngineOpenPPLHandAndBoardExpression] No match, because ranks do not fit\n");
		*result = false;
		return true;
	}

	// This was super-elegant, but unfortunatelly there can be 
	// SUITED expressions, which we can only solve with srankbits.
	// Ranks in the expression (to be searched)
	if (is_suited_expression)	{
		int rankbits_to_be_searched = CardStringToRankbits(((char*)hand_or_board_expression.GetString()));
		write_log(preferences.debug_hand_and_baord_expressions(), 
			"[CSymbolEngineOpenPPLHandAndBoardExpression] rank bits for %s = %i\n",
			hand_or_board_expression.GetString(), rankbits_to_be_searched);
		if (is_hand_expression)	{
			// Suited hand-expression
			// Ranks already checked, there are only 2, this simplifies things
			if (!p_symbol_engine_cards->issuited()) {
        write_log(preferences.debug_hand_and_baord_expressions(), 
			    "[CSymbolEngineOpenPPLHandAndBoardExpression] No match, because off-suited hole-cards\n");
				// No suited ranks available
				*result = false;
				return true;
			}
		}	else {
			// Suited board-expression
			int rankbits_available = p_symbol_engine_pokerval->srankbitscommon();
	
			// Check ranks in expression against available ranks
			if ((rankbits_to_be_searched & rankbits_available) != rankbits_to_be_searched)
			{
				write_log(preferences.debug_hand_and_baord_expressions(),
					"[CSymbolEngineOpenPPLHandAndBoardExpression] No match, because suited rankbits do not fit\n");
				*result = false;
				return true;
			}
		}
	}

	// Third case: cards with individual suits
	int length = hand_or_board_expression.GetLength();
	for (int i=0; i<(length-1); i++) 	{
		if (IsCardRankCharacter(hand_or_board_expression[i])
			  && IsCardSuitCharacter(hand_or_board_expression[i+1])) {
			CString card_with_specific_suit =
				CString(hand_or_board_expression[i])
				+ CString(hand_or_board_expression[i+1]);
			int icard_with_specific_suit = CardStringToCardNumber(
				((char*)card_with_specific_suit.GetString()));

			// Check if card is on the board or in the hand
			if (is_hand_expression) {
				if (!IsCardInCollection(icard_with_specific_suit,
					  p_table_state->User()->_hole_cards[0].GetValue(),
            p_table_state->User()->_hole_cards[1].GetValue())) {
					write_log(preferences.debug_hand_and_baord_expressions(),
						"[CSymbolEngineOpenPPLHandAndBoardExpression] No match, concrete hole cards do not fit\n");
					*result = false;
					return true;
				}
			}	else {
				if (!IsCardInCollection(icard_with_specific_suit,
            p_table_state->_common_cards[0].GetValue(),
            p_table_state->_common_cards[1].GetValue(),
            p_table_state->_common_cards[2].GetValue(),
            p_table_state->_common_cards[3].GetValue(),
            p_table_state->_common_cards[4].GetValue())) 	{
					write_log(preferences.debug_hand_and_baord_expressions(),
						"[CSymbolEngineOpenPPLHandAndBoardExpression] No match, concrete board cards do not fit\n");
					*result = false;
					return true;
				}
			}
		}	
	}
	write_log(preferences.debug_hand_and_baord_expressions(),
		"[CSymbolEngineOpenPPLHandAndBoardExpression] successful match\n");
	*result = true;
	return true;
}
Пример #3
0
void SQL_updateAttend_contest(int contestId,int verdictId,int problemId,char *num,char *username,time_t start_time,time_t end_time){

	//已经AC的不需要修改attend
	//update ac_time
	long AC_time=0;
	time_t first_ac_t;

	SQL_SemP();

	if(SQL_getFirstACTime_contest(contestId,problemId,username,first_ac_t,start_time,end_time))
	{
		AC_time=getdiftime(first_ac_t,start_time);
	}
	else
	{
		AC_time=0;
		first_ac_t = end_time;
	}

	sprintf(query,"update attend set %s_time=%ld where contest_id=%d and username='******';",num,AC_time,contestId,username);
	//cout<<query<<endl;
	if(mysql_real_query(mysql,query,(unsigned int)strlen(query)))
	{
		write_log(JUDGE_ERROR,mysql_error(mysql));
	}

	long ac_nCount=SQL_countProblemVerdict(contestId,problemId,V_AC,username);
	int score_ = SQL_getContestScore(contestId,username,start_time,end_time);
	string s_t,e_t,fAC_t;
	API_TimeToString(s_t,start_time);
	API_TimeToString(e_t,end_time);
	API_TimeToString(fAC_t,first_ac_t);

	//update score solved ,wrongsubmits
	sprintf(query,"update attend set solved=(SELECT count(DISTINCT problem_id) FROM solution WHERE contest_id=%d and username='******' and verdict=%d and submit_date between '%s' and '%s'),%s_wrongsubmits=(SELECT count(solution_id) FROM solution WHERE contest_id=%d and problem_id=%d and username='******' and verdict>%d and submit_date between '%s' and '%s'),score=%d  where contest_id=%d and username='******';",contestId,username,V_AC,s_t.c_str(),e_t.c_str(),   num,contestId,problemId,username,V_AC,s_t.c_str(),fAC_t.c_str(),  score_,  contestId,username);
	if(mysql_real_query(mysql,query,(unsigned int)strlen(query)))
	{
		write_log(JUDGE_ERROR,mysql_error(mysql));
	}

	//penalty
	int nCountProblems=SQL_countContestProblems(contestId);
	char index='A';
	long penalty=0;
	for(int i=0;i<nCountProblems;i++)
	{
		long a_time_=0;
		int wrongsubmits_=0;
		SQL_getContestAttend(contestId,username,index+i,a_time_,wrongsubmits_);

		if(a_time_>0)
		{
			penalty=penalty+a_time_+wrongsubmits_*60*20;
		}
	}

	sprintf(query,"update attend set penalty=%ld where contest_id=%d and username='******';",penalty,contestId,username);
	if(mysql_real_query(mysql,query,(unsigned int)strlen(query)))
	{
		write_log(JUDGE_ERROR,mysql_error(mysql));
	}

	SQL_SemV();

}
Пример #4
0
bool my_stat (const TCHAR *name, struct mystat *statbuf)
{
	DWORD attr, ok;
	FILETIME ft, lft;
	HANDLE h;
	BY_HANDLE_FILE_INFORMATION fi;
	const TCHAR *namep;
	bool fat;
	TCHAR path[MAX_DPATH];

	if (currprefs.win32_filesystem_mangle_reserved_names == false) {
		_tcscpy (path, PATHPREFIX);
		_tcscat (path, name);
		namep = path;
	} else {
		namep = name;
	}

	// FILE_FLAG_BACKUP_SEMANTICS = can also "open" directories
	h = CreateFile (namep, 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS, NULL);
	if (h == INVALID_HANDLE_VALUE)
		return false;
	fat = isfat (h);

	ok = GetFileInformationByHandle (h, &fi);
	CloseHandle (h);

	attr = 0;
	ft.dwHighDateTime = ft.dwLowDateTime = 0;
	if (ok) {
		attr = fi.dwFileAttributes;
		if (fat) {
			// fat lastwritetime only has 2 second resolution
			// fat creationtime has 10ms resolution
			// use creationtime if creationtime is inside lastwritetime 2s resolution
			ULARGE_INTEGER ct, wt;
			ct.HighPart = fi.ftCreationTime.dwHighDateTime;
			ct.LowPart = fi.ftCreationTime.dwLowDateTime;
			wt.HighPart = fi.ftLastWriteTime.dwHighDateTime;
			wt.LowPart = fi.ftLastWriteTime.dwLowDateTime;
			uae_u64 ctsec = ct.QuadPart / 10000000;
			uae_u64 wtsec = wt.QuadPart / 10000000;
			if (wtsec == ctsec || wtsec + 1 == ctsec) {
				ft = fi.ftCreationTime;
			} else {
				ft = fi.ftLastAccessTime;
			}
		} else {
			ft = fi.ftLastWriteTime;
		}
		statbuf->size = ((uae_u64)fi.nFileSizeHigh << 32) | fi.nFileSizeLow;
	} else {
		write_log (_T("GetFileInformationByHandle(%s) failed: %d\n"), namep, GetLastError ());
		return false;
	}

	statbuf->mode = (attr & FILE_ATTRIBUTE_READONLY) ? FILEFLAG_READ : FILEFLAG_READ | FILEFLAG_WRITE;
	if (attr & FILE_ATTRIBUTE_ARCHIVE)
		statbuf->mode |= FILEFLAG_ARCHIVE;
	if (attr & FILE_ATTRIBUTE_DIRECTORY)
		statbuf->mode |= FILEFLAG_DIR;

	FileTimeToLocalFileTime (&ft,&lft);
	uae_u64 t = (*(__int64 *)&lft-((__int64)(369*365+89)*(__int64)(24*60*60)*(__int64)10000000));
	statbuf->mtime.tv_sec = t / 10000000;
	statbuf->mtime.tv_usec = (t / 10) % 1000000;

	return true;
}
//Function:     load
//Description:  loads the key_count and property_count from the respective file
//              loads the inventory table data from secondary memory to primary
//Input param:  NULL
//Return Type:  integer
//              success status on successful operation
//              respective error status code otherwise
int load()
{

    // Start the log file
    open_log();

    // Use a file pointer to open various files to load the values
    FILE *fp;

    //Local variables
    int index       = 0;
    int key_index   = 0;
    int status      = 0;
    int file_status = 0;


    //check whether key_count.txt file is empty or not.
    file_status = file_empty_check("key_count.txt");
    if (file_status == 1006)
        return FAILURE;

    //check whether property_count.txt file is empty or not.
    file_status = file_empty_check("property_count.txt");
    if (file_status == 1006)
        return FAILURE;

    //check whether inventory_file.txt file is empty or not
    file_status = file_empty_check("inventory_file.txt");
    if (file_status == 1006)
        return FAILURE;

    // Open the key_count file to read the number of keywords
    fp = fopen("key_count.txt","r");
    if(fp == NULL) {
        write_log("load", "FILE_OPEN_ERROR", "Unable to open the key_count file");
        return FAILURE;
    }

    fscanf(fp,"%d", &key_count);
    if(key_count <= 0 ) {
        write_log("load", "FAILURE", "Key count is 0 or less than 0");
        return FAILURE;
    }
    write_log("load", "SUCCESS", "Key count read successfully");
    fclose(fp);

    // Open the property_count file to read the number of properties
    fp = fopen("property_count.txt","r");
    if(fp == NULL) {
        write_log("load", "FILE_OPEN_ERROR", "Unable to open the property_count file");
        return FAILURE;
    }

    fscanf(fp,"%d", &property_count);
    if (property_count <= 0) {
        write_log("load", "FAILURE", "property count is 0 or less than 0");
        return FAILURE;
    }
    write_log("load", "SUCCESS", "Property count read successfully");
    fclose(fp);


    // Open the inventory_file to read the available inventory details
    fp = fopen("inventory_file.txt", "r");
    if (fp == NULL) {
        write_log("load", "FILE_OPEN_ERROR", "Error in opening the inventory_file");
        return FAILURE;
    }

    // Allocate the memory for inventory table
    status = inventory_memory_allocation();

    if(status ==  1002) {
        write_log("load", "MEMORY_ALLOCATION_ERROR", "No memory for inventory table");
        return FAILURE;
    }

    // Load the details from file to main memory
    while(!feof(fp)) {
        for(index = 0; index <= key_count; index++) {
            fscanf(fp, "%s ", inventory[key_index][index]);
        }
        key_index++;
    }
    fclose(fp);

    write_log("load", "SUCCESS", "Inventory Load Successful");
    return SUCCESS;
}
Пример #6
0
int main(int argc, char *argv[])
{
    char* cmd;

    if ((cmd = strrchr(argv[0],'/')) == NULL)
    {
        cmd = argv[0];
    }
    else
        cmd++;

    const char* server_name = "synctool";
    char path[BUFSIZE];
    char server_path[BUFSIZE];
    memset(path,0,BUFSIZE);
    memset(server_path,0,BUFSIZE);
    getcwd(path,BUFSIZE);
    strcat(path,"/");
    memcpy(server_path,path,BUFSIZE);
    strcat(server_path,server_name);

    memcpy(log_name,path,BUFSIZE);
    strcat(log_name,"daemon_log.txt");

    char now_time[40];
    get_time(now_time,40);
    write_log("synctool daemon start time : %s\n",now_time);

    /// 先判断守护进程是否已经运行
    /// 
    if(just_running(LOCKDAEM,NULL) == 0)
    {
        printf("the sync_daemon is already running !\n");
        return 0;
    }
    daemonize(cmd);

    signal(SIGTERM,sigterm_handle);

    /// 记录守护进程pid

    if(record_pid(LOCKDAEM) != 0)
    {
        printf("sync_daemon write pid failed !\n");
        return 0;
    }

    while(_running)
    {
        pid_t pid;
        if((pid = fork()) < 0)
        {
            write_log("fork error !\n");
        }
        else if(pid == 0)
        {
            if(record_pid(LOCKFILE) == 0)
            {
                if(execl(server_path,server_name,path,(char*)0) < 0)
                {
                    write_log(strerror(errno));
                    remove(LOCKFILE);
                }
            }
        }
        else
        {
            pid_t sub_pid = wait(NULL);
            if (sub_pid != pid)
            {
                write_log("wait synctool pid (%d) not equal fork return pid(%d)! \n",sub_pid,pid);
            }
            remove(LOCKFILE);
            write_log("restart synctool server !\n");
        }
    }
    return 0;
}
bool CSymbolEnginePokerTracker::EvaluateSymbol(const char *name, double *result, bool log /* = false */)
{
  FAST_EXIT_ON_OPENPPL_SYMBOLS(name);
	if (memcmp(name,"pt_",3)!=0)
	{
		// Symbol of a different symbol-engine
		return false;
	}
	CString s = name;
	CheckForChangedPlayersOncePerHeartbeatAndSymbolLookup();
	if (IsOldStylePTSymbol(s))
	{
		CString error_message;
		error_message.Format(
			"Old style PokerTracker symbol detected: %s.\n"
			"\n"
			"PokerTracker symbol start with \"pt_\".\n"
      "Possible postfixes:\n"
      "  * chair number (0..9)\n"
      "  * _raischair\n"
      "  * _headsup\n"
      "  * _smallblind\n"
      "  * _bigblind\n"
      "  * _dealer\n"
      "  * _cutoff\n"
      "  * _user\n"
      "  * _firstraiser\n"
      "  * _firstcaller\n"
      "  * _lastcaller\n", s);
		OH_MessageBox_Formula_Error(
			error_message,			 
			"ERROR: Invalid PokerTracker Symbol");
		*result = kUndefined;
		return true;
	}
	if (!PT_DLL_IsValidSymbol(CString(s)))
	{
		// Invalid PokerTracker symbol
		WarnAboutInvalidPTSymbol(s);
		*result = kUndefined;
		return true;
	}
	int chair = 0;

	if (!p_pokertracker_thread->IsConnected()) 	{
		if (!p_symbol_engine_userchair->userchair_confirmed() || p_formula_parser->IsParsing()) {
			// We are not yet seated or formula is getting parsed.
			// Symbol-lookup happens, because of Formula-validation.
			// Not a problem, if we do not yet have a DB-connection.
			// Don't throw a warning here.
       write_log(preferences.debug_pokertracker(), "[PokerTracker] Not yet seated or formula parsing.\n");
		} else {
			// We are seated and playing.
			// Serious problem, if we do not have a DB-connection.
			OH_MessageBox_Error_Warning("Not connected to PokerTracker database.\n"
				"Can't use PokerTracker symbols.");
		}
		*result = kUndefined;
		return true;
	}

	CString standard_symbol_name;
	assert(StringAIsPrefixOfStringB("pt_", s));
	// PokerTracker symbols for the raise-chair
	if (s.Right(10) == "_raischair") {
		chair = p_symbol_engine_raisers->raischair();
	}
	// PokerTracker symbols for the opponent headsup chair
	else if (s.Right(8) == "_headsup") {
    chair = p_symbol_engine_chairs->opponent_headsup_chair();
	}
  // PokerTracker symbols for the smallblind chair
	else if (s.Right(11) == "_smallblind") {
    chair = p_symbol_engine_chairs->smallblind_chair();
	}
  // PokerTracker symbols for the bigblind chair
	else if (s.Right(9) == "_bigblind") {
    chair = p_symbol_engine_chairs->bigblind_chair();
	}
  // PokerTracker symbols for the cutoff chair
	else if (s.Right(7) == "_cutoff") {
    chair = p_symbol_engine_chairs->cutoff_chair();
	}
  // PokerTracker symbols for the firstcaller chair
	else if (s.Right(12) == "_firstcaller") {
    chair = p_symbol_engine_callers->firstcaller_chair();
	}
  // PokerTracker symbols for the lastcaller chair
	else if (s.Right(11) == "_lastcaller") {
    chair = p_symbol_engine_callers->lastcaller_chair();
	}
  // PokerTracker symbols for the firstraiser chair
	else if (s.Right(12) == "_firstraiser") {
		chair = p_symbol_engine_raisers->firstraiser_chair();
	}
  // PokerTracker symbols for the dealerchair chair
	else if (s.Right(7) == "_dealer") {
    chair = p_symbol_engine_dealerchair->dealerchair();
	}
  // PokerTracker symbols for the  chair
	else if (s.Right(5) == "_user") {
    chair = p_symbol_engine_userchair->userchair();
	}
  // PokerTracker symbols for chair X
	else {
		CString symbol = s;
		CString last_character = symbol.Right(1);
    if (!isdigit(last_character[0])) {
      CString error_message;
      error_message.Format("Invalid PokerTracker Symbol: &s",
        symbol);
      OH_MessageBox_Formula_Error(error_message, "ERROR");
		  *result = kUndefined;
      return false;
    }
		chair = atoi(last_character);
	}
  // Catch undefined chair (e.g. pt_r_-symbol without raisee)
  if (chair < 0) {
    *result = kUndefined;
    return true;
  }
	AssertRange(chair, kFirstChair, kLastChair);
	*result = PT_DLL_GetStat(s, chair); 
	return true;
}
Пример #8
0
void CTableLimits::CalcTableLimits()
{
	// This is basically the old function CSymbols::CalcStakes()
	// with some extension at the end to auto-lock the blinds,
	// if the values are reasonable.
	write_log(3, "CTableLimits::CalcTableLimits()\n");
	if (!IsCalculationNeccessary())
	{
		return;
	}
	SetSmallBlind(0);
	SetBigBlind(0);
	SetBigBet(0);
	SetAnte(0);

	// Save the parts we scraped successfully
	if (p_scraper->s_limit_info()->found_sblind)
		SetSmallBlind(p_scraper->s_limit_info()->sblind);								// sblind
	if (p_scraper->s_limit_info()->found_bblind)
		SetBigBlind(p_scraper->s_limit_info()->bblind);									// bblind
	if (p_scraper->s_limit_info()->found_ante)
		SetAnte(p_scraper->s_limit_info()->ante);										// ante
	if (p_scraper->s_limit_info()->found_limit)
		SetGametype(p_scraper->s_limit_info()->limit);									// lim
	if (p_scraper->s_limit_info()->found_bbet)
		SetBigBet(p_scraper->s_limit_info()->bbet);
	_istournament = p_scraper->s_limit_info()->istournament;	

	write_log(3, "CTableLimits: input from scraper: small blind: %f\n", tablelimit_unreliable_input.sblind);
	write_log(3, "CTableLimits: input from scraper: big blind:   %f\n", tablelimit_unreliable_input.bblind);
	write_log(3, "CTableLimits: input from scraper: big bet:     %f\n", tablelimit_unreliable_input.bbet);
	write_log(3, "CTableLimits: input from scraper: gametype:    %d\n", _gametype);             
	// Figure out bb/sb based on game type
	if (gametype() == k_gametype_NL || gametype() == k_gametype_PL)
	{
		CalcTableLimits_NL_PL();
	}
	else if (gametype() == k_gametype_FL || gametype() == k_gametype_unknown)
	{
		CalcTableLimits_FL_AndUnknownGametype();
	}

	// if we still do not have blinds, then infer them from the posted bets
	if (p_betround_calculator->betround() == k_betround_preflop && (tablelimit_unreliable_input.sblind==0 || tablelimit_unreliable_input.bblind==0))
	{
		SearchTableForSbAndBbValue();			
	}

	write_log(3, "CTableLimits: calculated result: small blind: %f\n", tablelimit_unreliable_input.sblind);
	write_log(3, "CTableLimits: calculated result: big blind:   %f\n", tablelimit_unreliable_input.bblind);
	write_log(3, "CTableLimits: calculated result: big bet:     %f\n", tablelimit_unreliable_input.bbet);
	AdjustForReasonableness();
	write_log(3, "CTableLimits: adjusted result: small blind: %f\n", tablelimit_unreliable_input.sblind);
	write_log(3, "CTableLimits: adjusted result: big blind:   %f\n", tablelimit_unreliable_input.bblind);
	write_log(3, "CTableLimits: adjusted result: big bet:     %f\n", tablelimit_unreliable_input.bbet);

	AcceptNewValuesIfGood();
	AutoLockBlinds();
	// Calc miminum betsizes for every streeet (after! we have potentially locked the blinds)
	CalcBetsizesForEveryStreet();
}
Пример #9
0
uae_u8 sampler_getsample (int channel)
{
#if 0
	int cur_pos;
	static int cap_pos;
	static float diffsample;
#endif
	static double doffset_offset;
	HRESULT hr;
	DWORD t;
	void *p1, *p2;
	DWORD len1, len2;
	evt cycles;
	int sample, samplecnt;
	double doffset;
	int offset;

	if (!currprefs.sampler_stereo)
		channel = 0;

	if (!inited) {
		DWORD pos;
		if (!capture_init ()) {
			capture_free ();
			return 0;
		}
		inited = 1;
		oldcycles = get_cycles ();
		oldoffset = -1;
		doffset_offset = 0;
		hr = lpDSB2r->GetCurrentPosition (&t, &pos);
		if (FAILED (hr)) {
			sampler_free ();
			return 0;
		}		
		if (t >= pos)
			safediff = t - pos;
		else
			safediff = recordbufferframes * SAMPLESIZE - pos + t;
		write_log (_T("SAMPLER: safediff %d %d\n"), safediff, safediff + sampleframes * SAMPLESIZE);
		safediff += 4 * sampleframes * SAMPLESIZE;

#if 0
		diffsample = 0;
		safepos = -recordbufferframes / 10 * SAMPLESIZE;
		hr = lpDSB2r->GetCurrentPosition (&t, &pos);
		cap_pos = pos;
		cap_pos += safepos;
		if (cap_pos < 0)
			cap_pos += recordbufferframes * SAMPLESIZE;
		if (cap_pos >= recordbufferframes * SAMPLESIZE)
			cap_pos -= recordbufferframes * SAMPLESIZE;
		if (FAILED (hr)) {
			sampler_free ();
			return 0;
		}
#endif
	}
	if (clockspersample < 1)
		return 0;
	uae_s16 *sbuf = (uae_s16*)samplebuffer;

	vsynccnt = 0;
	sample = 0;
	samplecnt = 0;
	cycles = (int)get_cycles () - (int)oldcycles;
	doffset = doffset_offset + cycles / clockspersample;
	offset = (int)doffset;
	if (oldoffset < 0 || offset >= sampleframes || offset < 0) {
		if (offset >= sampleframes) {
			doffset -= offset;
			doffset_offset = doffset;
		}
		if (oldoffset >= 0 && offset >= sampleframes) {
			while (oldoffset < sampleframes) {
				sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel];
				oldoffset++;
				samplecnt++;
			}
		}
		hr = lpDSB2r->GetCurrentPosition (&t, NULL);
		int pos = t;
		pos -= safediff;
		if (pos < 0)
			pos += recordbufferframes * SAMPLESIZE;
		hr = lpDSB2r->Lock (pos, sampleframes * SAMPLESIZE, &p1, &len1, &p2, &len2, 0);
		if (FAILED (hr)) {
			write_log (_T("SAMPLER: Lock() failed %x\n"), hr);
			return 0;
		}
		memcpy (samplebuffer, p1, len1);
		if (p2)
			memcpy (samplebuffer + len1, p2, len2);
		lpDSB2r->Unlock (p1, len1, p2, len2);

#if 0
		cap_pos = t;
		cap_pos += sampleframes * SAMPLESIZE;
		if (cap_pos < 0)
			cap_pos += RECORDBUFFER * SAMPLESIZE;
		if (cap_pos >= RECORDBUFFER * SAMPLESIZE)
			cap_pos -= RECORDBUFFER * SAMPLESIZE;

		hr = lpDSB2r->GetCurrentPosition (&t, &pos);
		cur_pos = pos;
		if (FAILED (hr))
			return 0;

		cur_pos += safepos;
		if (cur_pos < 0)
			cur_pos += RECORDBUFFER * SAMPLESIZE;
		if (cur_pos >= RECORDBUFFER * SAMPLESIZE)
			cur_pos -= RECORDBUFFER * SAMPLESIZE;

		int diff;
		if (cur_pos >= cap_pos)
			diff = cur_pos - cap_pos;
		else
			diff = RECORDBUFFER * SAMPLESIZE - cap_pos + cur_pos;
		if (diff > RECORDBUFFER * SAMPLESIZE / 2)
			diff -= RECORDBUFFER * SAMPLESIZE; 
		diff /= SAMPLESIZE;

		int diff2 = 100 * diff / (RECORDBUFFER / 2);
		diffsample = -pow (diff2 < 0 ? -diff2 : diff2, 3.1);
		if (diff2 < 0)
			diffsample = -diffsample;
		write_log (_T("%d\n"), diff);

		write_log (_T("CAP=%05d CUR=%05d (%-05d) OFF=%05d %f\n"),
			cap_pos / SAMPLESIZE, cur_pos / SAMPLESIZE, (cap_pos - cur_pos) / SAMPLESIZE, offset, doffset_offset);
#endif

		if (offset < 0)
			offset = 0;
		if (offset >= sampleframes)
			offset -= sampleframes;

		oldoffset = 0;
		oldcycles = get_cycles ();
	}

	while (oldoffset <= offset) {
		sample += sbuf[oldoffset * SAMPLESIZE / 2 + channel];
		samplecnt++;
		oldoffset++;
	}
	oldoffset = offset;

	if (samplecnt > 0)
		sample /= samplecnt;
#if 1
	 /* yes, not 256, without this max recording volume would still be too quiet on my sound cards */
	sample /= 128;
	if (sample < -128)
		sample = 0;
	else if (sample > 127)
		sample = 127;
	return (uae_u8)(sample - 128);
#else
	return (Uae_u8)((sample / 256) - 128);
#endif
}
Пример #10
0
void CReplayFrame::CreateReplayFrame(void)
{
	FILE			*fp = NULL;
	int				i = 0;
	time_t			ltime = 0;
	tm				now_time = {0};
	char			now_time_str[100] = {0};
	ULARGE_INTEGER	free_bytes_for_user_on_disk = {0}, 
					total_bytes_on_disk = {0}, 
					free_bytes_total_on_disk = {0};
	int				e = SUCCESS;

	//  Sanity check: Enough disk-space for replay frame?	
	GetDiskFreeSpaceEx(
		p_filenames->OpenHoldemDirectory(),  //  Directory on disk of interest
		&free_bytes_for_user_on_disk,  
		&total_bytes_on_disk,	
		&free_bytes_total_on_disk);
	if (free_bytes_for_user_on_disk.QuadPart < FREE_SPACE_NEEDED_FOR_REPLAYFRAME) 
	{
		write_log(prefs.debug_replayframes(), "[CReplayFrame] Not enough disk-space\n");
		OH_MessageBox_Error_Warning("Not enough disk space to create replay-frame.", "ERROR");

		return;
	}

	// Get current time
	time(&ltime);
	localtime_s(&now_time, &ltime);
	strftime(now_time_str, 100, "%Y-%m-%d %H:%M:%S", &now_time);

	// Get exclusive access to CScraper and CSymbols variables
	// (Wait for scrape/symbol cycle to finish before saving frame)
	EnterCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
	CreateBitMapFile();

	// Create HTML file
	CString path = p_filenames->ReplayHTMLFilename(_next_replay_frame);
	if (fopen_s(&fp, path.GetString(), "w")==0)
	{
		write_log(prefs.debug_replayframes(), "[CReplayFrame] Creating HTML file: $s\n", path);
		// First line has to be the "title" of the table.
		// This is no longer valid HTML, but the way Ray.E.Bornert did it
		// for WinHoldem and WinScrape.
		fprintf(fp, "%s\n", p_scraper->title());
		// HTML header
		fprintf(fp, "<html>\n");
		fprintf(fp, "  <head>\n");
		fprintf(fp, "    <title>%s</title>\n", p_scraper->title());
		fprintf(fp, "  </head>");
		fprintf(fp, "<style>\n");
		fprintf(fp, "td {text-align:right;}\n");
		fprintf(fp, "</style>\n");
		fprintf(fp, "<body>\n");
		fprintf(fp, "<font face=courier>\n");

		// Bitmap image
		fprintf(fp, "<img src=\"frame%06d.bmp\">\n", _next_replay_frame);
		fprintf(fp, "<br>\n");

		// Table title
		fprintf(fp, "[%s]", p_scraper->title());
		fprintf(fp, "<br>\n");

		// Session, frame number and time
		fprintf(fp, " [Session %lu]", p_sessioncounter->session_id());
		fprintf(fp, " [Frame: %06d]", _next_replay_frame);
		fprintf(fp, " [%s]<br>\n", now_time_str);
		fprintf(fp, "<br>\n");

		// Links forwards and backwards to the next frames
		fprintf(fp, "%s", LPCSTR(GetLinksToPrevAndNextFile()));
		fprintf(fp, "<br>\n");
		fprintf(fp, "<br>\n");

		// Header of main table for smaller data tables
		fprintf(fp, "<table>\n");
		fprintf(fp, "<tr>\n");
		fprintf(fp, "<td>\n");

		// Data tables
		fprintf(fp, "%s", LPCSTR(GetPlayerInfoAsHTML()));
		fprintf(fp, "/<td>\n");
		fprintf(fp, "<td>\n");
		fprintf(fp, "%s", LPCSTR(GetButtonStatesAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetBlindInfoAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetCommonCardsAsHTML()));
		fprintf(fp, "%s", LPCSTR(GetPotsAsHTML()));
		fprintf(fp, "</td>\n");

		// Footer of main table
		fprintf(fp, "</tr>\n");
		fprintf(fp, "</table>\n");

		// End of HTML
		fprintf(fp, "</body></html>\n");

		fclose(fp);
	}	

	LeaveCriticalSection(&p_heartbeat_thread->cs_update_in_progress);
}
Пример #11
0
void CTableLimits::SearchTableForSbAndBbValue()
{
	bool	found_inferred_sb = false, found_inferred_bb = false;

	write_log(3, "CTableLimits::SearchTableForSbAndBbValue()\n");
	for (int i=1; i<=p_tablemap->nchairs(); i++)
	{
		int next_chair = (p_symbol_engine_dealerchair->dealerchair() + i) % p_tablemap->nchairs();
		// We do no longer require cards for the players,
		// as this mixed things up, when e.g. SB folds.
		// We try to look directly at the bets.
		//
		// But not looking for cards is bad either, 
		// as sometimes we don't get the bet correctly 
		// and then end up with the bet of another user.
		// If we find cards without a necessary blind
		// then we will try it as unknown (zero).
		if (p_scraper->player_bet(next_chair) >= 0.01)
		{
			write_log(3, "CTableLimits::SearchTableForSbAndBbValue found bet for chair %d\n", next_chair);
			// Bet found
			if (!found_inferred_sb)
			{
				// Not yet SB known
				if (tablelimit_unreliable_input.sblind==0)
				{
					SetSmallBlind(p_scraper->player_bet(next_chair));
					write_log(3, "CTableLimits: found inferred SB at chair %d: %f\n", next_chair, p_scraper->player_bet(next_chair));
					found_inferred_sb = true;
				}
			}
			else if (!found_inferred_bb)
			{
				// Not yet BB known
				if (tablelimit_unreliable_input.bblind==0)
				{
					// Not heads up - normal blinds
					if (next_chair != p_symbol_engine_dealerchair->dealerchair())
					{
						SetBigBlind(p_scraper->player_bet(i%p_tablemap->nchairs()));
						write_log(3, "CTableLimits: found inferred BB at chair %d: %f\n", next_chair, p_scraper->player_bet(i%p_tablemap->nchairs()));
					}
					// heads up - reversed blinds
					else
					{
						SetBigBlind(tablelimit_unreliable_input.sblind);
						SetSmallBlind(p_scraper->player_bet(next_chair));
						write_log(3, "CTableLimits: found inferred BB headsup at chair %d: %f\n", next_chair, p_scraper->player_bet(i%p_tablemap->nchairs()));
						write_log(3, "CTableLimits: Swapping blinds.\n");
					}
					found_inferred_bb = true;
				}
				break;
			}
		}
		else if ((p_scraper->card_player(next_chair, 0) != CARD_NOCARD)  
			&& (p_scraper->card_player(next_chair, 0) != CARD_NOCARD))
		{
			write_log(3, "CTableLimits::SearchTableForSbAndBbValue found no bet for chair %d\n", next_chair);
			write_log(3, "CTableLimits::SearchTableForSbAndBbValue but found cards for chair %d\n", next_chair);
			// Awful. Found cards, but not the expected blind.
			// Either a misread, or a blind is missing.
			// Read it as zero and try to guess it later correctly.
			if (!found_inferred_sb)
			{
				found_inferred_sb = true;
				write_log(3, "CTableLimits: expected SB, but not found\n");
				// Don't set any value.
				// Who knows, we might even have correct data 
				// from a previous round!? 
			}
			else if (!found_inferred_bb)
			{
				found_inferred_bb = true;
				write_log(3, "CTableLimits: expected BB, but not found\n");
				// Don't set any value.
				// Who knows, we might even have correct data 
				// from a previous round!? 
				break;
			}
		}
		else
		{
			write_log(3, "CTableLimits::SearchTableForSbAndBbValue found neither bet nor cards for chair %d\n", next_chair);
		}
	}
	SwapBlindsIfSbGreaterThanBBAndNotZero();
}
Пример #12
0
/*
 * Uptime thread...
 */
void *
th_uptime(void *arg)
{
   int ret,n;
   struct timeval timeout;
   sigset_t mask;

write_log(0,"\n th_uptime thread = %d\n",(int)pthread_self());

   sigfillset(&mask);

   if (pthread_sigmask(SIG_BLOCK, &mask, NULL))
   {
      thread_error("th_uptime pthread_sigmask()",errno);
      th_uptime_exit();
   }

   if (pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL))
   {
      thread_error("th_uptime pthread_setcancelstate()",errno);
      th_uptime_exit();
   }

   pthread_cleanup_push( &th_uptime_clean, (void *)NULL );
   
   if (pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL))
   {
      thread_error("th_uptime pthread_setcancelstate()",errno);
      th_uptime_exit();
   }

   if (pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL))
   {
      n=errno;
      pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
      thread_error("th_uptime pthread_setcanceltype()",n);
      th_uptime_exit();
   }

   while(1)
   {
      timeout.tv_sec  = 1;
      timeout.tv_usec = 0;

      if ( (ret=select( 0, NULL, NULL, NULL, &timeout ) ) == -1 )
      {
         n=errno;
         thread_error("th_uptime select()",n);
         continue;
      }

      if ( !ret )  /* Timeout, update uptime... */
         uptime++; 
   }

   pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);         

   pthread_cleanup_pop(0);

   return (NULL);
}
Пример #13
0
/*
 * David, pon algo coherente!!!
 */
void
doloop(struct term_node *node, int mode)
{
    struct term_tty *term_tty;
    struct attack *theattack = NULL;
    struct timeval timeout;
    fd_set read_set;
    int ret, fail;
    struct termios old_term, term;
    
    term_tty = node->specific;

    theattack = protocols[mode].attacks;

    if (term_tty->attack >= 0) 
    {
        if (theattack[term_tty->attack].nparams)
        {
            printf("\n<*> Ouch!! At the moment the command line interface doesn't support attacks <*>\n");
            printf("<*> that needs parameters and the one you've choosed needs %d <*>\n",
                         theattack[term_tty->attack].nparams);
        }
        else
        {
            printf("<*> Starting %s attack %s...\n", 
                (theattack[term_tty->attack].type)?"DOS":"NONDOS",
                theattack[term_tty->attack].s); 

            if (attack_launch(node, mode, term_tty->attack, NULL, 0) < 0)
                write_log(1, "Error launching attack %d (mode %d)!!\n", 
                            term_tty->attack, mode);

            fflush(stdin); fflush(stdout);
            setvbuf(stdout, NULL, _IONBF, 0);
            tcgetattr(0,&old_term);
            tcgetattr(0,&term);
            term.c_cc[VMIN]  = 1;
            term.c_cc[VTIME] = _POSIX_VDISABLE;
            term.c_lflag &= ~ICANON;
            term.c_lflag &= ~ECHO;
            tcsetattr(0,TCSANOW,&term);

            if (theattack[term_tty->attack].single == CONTINOUS) {
                printf("<*> Press any key to stop the attack <*>\n");
                fail = 0;
                while(!fail && !node->thread.stop)
                {
                    FD_ZERO(&read_set);
                    FD_SET(0, &read_set);
                    timeout.tv_sec  = 0;
                    timeout.tv_usec = 200000;
                    if ( (ret=select(1, &read_set, NULL, NULL, &timeout) ) == -1 )
                    {
                       thread_error("network_peer_th select()",errno);
                       continue;
                    }

                    if ( !ret )  /* Timeout, decrement timers... */
                       continue;
                    else
                    {
                       if (FD_ISSET(0, &read_set))
                       {
                          getchar();
                          fail = 1;
                       }
                    }
                 }
             } else
                /* Command line, only one attack (0), let's wait for its conclusion... */
                while (node->protocol[mode].attacks[0].up)
                    thread_usleep(150000);
             
             tcsetattr(0,TCSANOW, &old_term);
        }         
    } /* if term_tty->attack */
}
Пример #14
0
/*
 * Thread for handling command line attacks (TERM_TTY)
 * Use global variable struct term_tty *tty_tmp
 */
void *
th_tty_peer(void *args)
{
   int fail;
   time_t this_time;
   struct cl_args *arguments;
   struct term_tty *tty;
   struct term_node *term_node=NULL;
   sigset_t mask;
   
   terms->work_state = RUNNING;
   
write_log(0, "\n th_tty_peer thread = %d...\n",(int)pthread_self());
   
   sigfillset(&mask);
   
   if (pthread_sigmask(SIG_BLOCK, &mask,NULL))
   {
      thread_error("th_tty_peer pthread_sigmask()",errno);
      th_tty_peer_exit(NULL);
   }   

   if (pthread_mutex_lock(&terms->mutex) != 0)
   {
      thread_error("th_tty_peer pthread_mutex_lock",errno);
      th_tty_peer_exit(NULL);
   }
   
   fail = term_add_node(&term_node, TERM_TTY, (int)NULL, pthread_self());

   if (fail == -1)
   {
      if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
      th_tty_peer_exit(term_node);
   }

   if (term_node == NULL)
   {
      write_log(1,"Ouch!! No more than %d %s accepted!!\n",
                  term_type[TERM_TTY].max, term_type[TERM_TTY].name);
      
      if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
      th_tty_peer_exit(term_node);
   }

   tty = term_node->specific;

   memcpy(tty,tty_tmp,sizeof(struct term_tty));    

    this_time = time(NULL);
   
#ifdef HAVE_CTIME_R
#ifdef SOLARIS
    ctime_r(&this_time,term_node->since, sizeof(term_node->since));
#else
    ctime_r(&this_time,term_node->since);
#endif
#else
    pthread_mutex_lock(&mutex_ctime);
    strncpy(term_node->since, ctime(&this_time), sizeof(term_node->since));   
    pthread_mutex_unlock(&mutex_ctime);
#endif

    /* Just to remove the cr+lf...*/
    term_node->since[sizeof(term_node->since)-2] = 0;

    /* This is a tty so, man... ;) */
    strncpy(term_node->from_ip, "127.0.0.1", sizeof(term_node->from_ip));

   /* Parse config file */
   if (strlen(tty_tmp->config_file))
      if (parser_read_config_file(tty_tmp, term_node) < 0)
      {
         write_log(0, "Error reading configuration file\n");
         th_tty_peer_exit(term_node);
      }
   
    if (init_attribs(term_node) < 0)        
    {
       if (pthread_mutex_unlock(&terms->mutex) != 0)
         thread_error("th_tty_peer pthread_mutex_unlock",errno);
       th_tty_peer_exit(term_node);
    }

    arguments = args;
    
    /* In command line mode we initialize the values by default */
    if (protocols[arguments->proto_index].init_attribs)
    {
        fail = (*protocols[arguments->proto_index].init_attribs)
            (term_node);
    } else
        write_log(0, "Warning, proto %d has no init_attribs function!!\n", arguments->proto_index);

    /* Choose a parser */
    fail = parser_cl_proto(term_node, arguments->count, arguments->argv_tmp, arguments->proto_index);

   if (pthread_mutex_unlock(&terms->mutex) != 0)
      thread_error("th_tty_peer pthread_mutex_unlock",errno);
   
   if (fail < 0) {
       write_log(0, "Error when parsing...\n");
       th_tty_peer_exit(term_node);
   }
      
   write_log(0, "Entering command line mode...\n");
   /* Execute attack... */
   doloop(term_node, arguments->proto_index);
   
   th_tty_peer_exit(term_node);
   
   return(NULL);
}
Пример #15
0
uae_u32 amiga_clipboard_proc_start (void)
{
	write_log ("clipboard process init: %08x\n", clipboard_data);
	signaling = 1;
	return clipboard_data;
}
Пример #16
0
static USHORT Process_Track(struct zfile *fi, struct zfile *fo, UCHAR *b1, UCHAR *b2, USHORT cmd, USHORT opt, int32_t dmsflags, struct zfile **extra){
	USHORT hcrc, dcrc, usum, number, pklen1, pklen2, unpklen, l;
	UCHAR cmode, flags;
	int32_t crcerr = 0;


	l = (USHORT)zfile_fread(b1,1,THLEN,fi);

	if (l != THLEN) {
		if (l==0)
			return DMS_FILE_END;
		else
			return ERR_SREAD;
	}

	/*  "TR" identifies a Track Header  */
	if ((b1[0] != 'T')||(b1[1] != 'R')) return ERR_NOTTRACK;

	/*  Track Header CRC  */
	hcrc = (USHORT)((b1[THLEN-2] << 8) | b1[THLEN-1]);

	if (dms_CreateCRC(b1,(ULONG)(THLEN-2)) != hcrc) return ERR_THCRC;

	number = (USHORT)((b1[2] << 8) | b1[3]);	/*  Number of track  */
	pklen1 = (USHORT)((b1[6] << 8) | b1[7]);	/*  Length of packed track data as in archive  */
	pklen2 = (USHORT)((b1[8] << 8) | b1[9]);	/*  Length of data after first unpacking  */
	unpklen = (USHORT)((b1[10] << 8) | b1[11]);	/*  Length of data after subsequent rle unpacking */
	flags = b1[12];		/*  control flags  */
	cmode = b1[13];		/*  compression mode used  */
	usum = (USHORT)((b1[14] << 8) | b1[15]);	/*  Track Data CheckSum AFTER unpacking  */
	dcrc = (USHORT)((b1[16] << 8) | b1[17]);	/*  Track Data CRC BEFORE unpacking  */

	if (dolog)
		write_log ("DMS: track=%d\n", number);

	if (dolog) {
		if (number==80)
			write_log (" FileID   ");
		else if (number==0xffff)
			write_log (" Banner   ");
		else if ((number==0) && (unpklen==1024))
			write_log (" FakeBB   ");
		else
			write_log ("   %2d     ",(short)number);

	    write_log ("%5d    %5d   %s  %04X  %04X  %04X    %0d\n", pklen1, unpklen, modes[cmode], usum, hcrc, dcrc, flags);
	}

	if ((pklen1 > TRACK_BUFFER_LEN) || (pklen2 >TRACK_BUFFER_LEN) || (unpklen > TRACK_BUFFER_LEN)) return ERR_BIGTRACK;

	if (zfile_fread(b1,1,(size_t)pklen1,fi) != pklen1) return ERR_SREAD;

	if (dms_CreateCRC(b1,(ULONG)pklen1) != dcrc) {
		log_error (number);
		crcerr = 1;
	}
	/*  track 80 is FILEID.DIZ, track 0xffff (-1) is Banner  */
	/*  and track 0 with 1024 bytes only is a fake boot block with more advertising */
	/*  FILE_ID.DIZ is never encrypted  */

	//if (pwd && (number!=80)) dms_decrypt(b1,pklen1);

	if ((cmd == CMD_UNPACK) && (number<80) && (unpklen>2048)) {
		memset(b2, 0, unpklen);
		if (!crcerr)
			Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum, dmsflags & DMSFLAG_ENCRYPTED);
		if (number == 0 && zfile_ftell (fo) == 512 * 22) {
			// did we have another cylinder 0 already?
			uint8_t *p;
			zfile_fseek (fo, 0, SEEK_SET);
			p = xcalloc (uint8_t, 512 * 22);
			zfile_fread (p, 512 * 22, 1, fo);
			addextra("BigFakeBootBlock", extra, p, 512 * 22);
			xfree (p);
		}
		zfile_fseek (fo, number * 512 * 22 * ((dmsflags & DMSFLAG_HD) ? 2 : 1), SEEK_SET);
		if (zfile_fwrite(b2,1,(size_t)unpklen,fo) != unpklen)
			return ERR_CANTWRITE;
	} else if (number == 0 && unpklen == 1024) {
		memset(b2, 0, unpklen);
		if (!crcerr)
			Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum, dmsflags & DMSFLAG_ENCRYPTED);
		addextra("FakeBootBlock", extra, b2, unpklen);
	}

	if (crcerr)
		return NO_PROBLEM;

	if (number == 0xffff && extra){
		Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum, dmsflags & DMSFLAG_ENCRYPTED);
		addextra("Banner", extra, b2, unpklen);
		printbandiz(b2,unpklen);
	}

	if (number == 80 && extra) {
		Unpack_Track(b1, b2, pklen2, unpklen, cmode, flags, number, pklen1, usum, dmsflags & DMSFLAG_ENCRYPTED);
		addextra("FILEID.DIZ", extra, b2, unpklen);
		printbandiz(b2,unpklen);
	}

	return NO_PROBLEM;

}
Пример #17
0
int vsync_switchmode (int hz, int oldhz)
{
	static int tempvsync;
	int w = currentmode->native_width;
	int h = currentmode->native_height;
	int d = currentmode->native_depth / 8;
//        struct MultiDisplay *md = getdisplay (&currprefs);
	struct PicassoResolution *found;

	int newh, i, cnt;
	int dbl = getvsyncrate (currprefs.chipset_refreshrate) != currprefs.chipset_refreshrate ? 2 : 1;

	if (hz < 0)
		return tempvsync;

	newh = h * oldhz / hz;
	hz = hz * dbl;

	found = NULL;
        
/*	for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) {
		struct PicassoResolution *r = &md->DisplayModes[i];
		if (r->res.width == w && r->res.height == h && r->depth == d) {
			int j;
			for (j = 0; r->refresh[j] > 0; j++) {
				if (r->refresh[j] == oldhz) {
					found = r;
					break;
				}
			}
		}
	}*/
	if (found == NULL) {
		write_log ("refresh rate changed to %d but original rate was not found\n", hz);
		return 0;
	}

	found = NULL;
/*        for (cnt = 0; cnt <= abs (newh - h) + 1 && !found; cnt++) {
                for (i = 0; md->DisplayModes[i].depth >= 0 && !found; i++) {
                        struct PicassoResolution *r = &md->DisplayModes[i];
                        if (r->res.width == w && (r->res.height == newh + cnt || r->res.height == newh - cnt) && r->depth == d) {
                                int j;
                                for (j = 0; r->refresh[j] > 0; j++) {
                                        if (r->refresh[j] == hz) {
                                                found = r;
                                                break;
                                        }
                                }
                        }
                }
        }*/
        if (!found) {
                tempvsync = currprefs.gfx_avsync;
                changed_prefs.gfx_avsync = 0;
                write_log ("refresh rate changed to %d but no matching screenmode found, vsync disabled\n", hz);
        } else {
                newh = found->res.height;
                changed_prefs.gfx_size_fs.height = newh;
                changed_prefs.gfx_refreshrate = hz;
                write_log ("refresh rate changed to %d, new screenmode %dx%d\n", hz, w, newh);
        }
/*
        reopen (1);
*/
        return 0;
}
Пример #18
0
static void log_error(int32_t track)
{
	write_log ("DMS: Ignored error on track %d!\n", track);
}
Пример #19
0
void CMainFrame::OnEditTagLog() {
	 write_log(k_always_log_basic_information,
		"[*** ATTENTION ***] User tagged this situation for review\n");
}
Пример #20
0
USHORT DMS_Process_File(struct zfile *fi, struct zfile *fo, USHORT cmd, USHORT opt, USHORT PCRC, USHORT pwd, int32_t part, struct zfile **extra)
{
	USHORT from, to, geninfo, c_version, cmode, hcrc, disktype, pv, ret;
	ULONG pkfsize, unpkfsize;
	UCHAR *b1, *b2;
	time_t date;

	passfound = 0;
	passretries = 2;
	b1 = xcalloc(UCHAR,TRACK_BUFFER_LEN);
	if (!b1) return ERR_NOMEMORY;
	b2 = xcalloc(UCHAR,TRACK_BUFFER_LEN);
	if (!b2) {
		xfree(b1);
		return ERR_NOMEMORY;
	}
	dms_text = xcalloc(UCHAR,TEMP_BUFFER_LEN);
	if (!dms_text) {
		xfree(b1);
		xfree(b2);
		return ERR_NOMEMORY;
	}

	/* if iname is NULL, input is stdin;   if oname is NULL, output is stdout */

	if (zfile_fread(b1,1,HEADLEN,fi) != HEADLEN) {
		xfree(b1);
		xfree(b2);
		xfree(dms_text);
		return ERR_SREAD;
	}

	if ( (b1[0] != 'D') || (b1[1] != 'M') || (b1[2] != 'S') || (b1[3] != '!') ) {
		/*  Check the first 4 bytes of file to see if it is "DMS!"  */
		xfree(b1);
		xfree(b2);
		xfree(dms_text);
		return ERR_NOTDMS;
	}

	hcrc = (USHORT)((b1[HEADLEN-2]<<8) | b1[HEADLEN-1]);
	/* Header CRC */

	if (hcrc != dms_CreateCRC(b1+4,(ULONG)(HEADLEN-6))) {
		xfree(b1);
		xfree(b2);
		xfree(dms_text);
		return ERR_HCRC;
	}

	geninfo = (USHORT) ((b1[10]<<8) | b1[11]);	/* General info about archive */
	date = (time_t) ((((ULONG)b1[12])<<24) | (((ULONG)b1[13])<<16) | (((ULONG)b1[14])<<8) | (ULONG)b1[15]);	/* date in standard UNIX/ANSI format */
	from = (USHORT) ((b1[16]<<8) | b1[17]);		/*  Lowest track in archive. May be incorrect if archive is "appended" */
	to = (USHORT) ((b1[18]<<8) | b1[19]);		/*  Highest track in archive. May be incorrect if archive is "appended" */

	if (part && from < 30) {
		xfree(b1);
		xfree(b2);
		xfree(dms_text);
		return DMS_FILE_END;
	}

	pkfsize = (ULONG) ((((ULONG)b1[21])<<16) | (((ULONG)b1[22])<<8) | (ULONG)b1[23]);	/*  Length of total packed data as in archive   */
	unpkfsize = (ULONG) ((((ULONG)b1[25])<<16) | (((ULONG)b1[26])<<8) | (ULONG)b1[27]);	/*  Length of unpacked data. Usually 901120 bytes  */

	c_version = (USHORT) ((b1[46]<<8) | b1[47]);	/*  version of DMS used to generate it  */
	disktype = (USHORT) ((b1[50]<<8) | b1[51]);		/*  Type of compressed disk  */
	cmode = (USHORT) ((b1[52]<<8) | b1[53]);        /*  Compression mode mostly used in this archive  */

	PWDCRC = PCRC;

	if (dolog) {

		pv = (USHORT)(c_version/100);
		write_log (" Created with DMS version %d.%02d ",pv,c_version-pv*100);
		if (geninfo & 0x80)
			write_log ("Registered\n");
		else
			write_log ("Evaluation\n");

		write_log (" Creation date : %s",ctime(&date));
		write_log (" Lowest track in archive : %d\n",from);
		write_log (" Highest track in archive : %d\n",to);
		write_log (" Packed data size : %lu\n",pkfsize);
		write_log (" Unpacked data size : %lu\n",unpkfsize);
		write_log (" Disk type of archive : ");

		/*  The original DMS from SDS software (DMS up to 1.11) used other values    */
		/*  in disk type to indicate formats as MS-DOS, AMax and Mac, but it was     */
		/*  not suported for compression. It was for future expansion and was never  */
		/*  used. The newer versions of DMS made by ParCon Software changed it to    */
		/*  add support for new Amiga disk types.                                    */
		switch (disktype) {
			case 0:
			case 1:
				/* Can also be a non-dos disk */
				write_log ("AmigaOS 1.0 OFS\n");
				break;
			case 2:
				write_log ("AmigaOS 2.0 FFS\n");
				break;
			case 3:
				write_log ("AmigaOS 3.0 OFS / International\n");
				break;
			case 4:
				write_log ("AmigaOS 3.0 FFS / International\n");
				break;
			case 5:
				write_log ("AmigaOS 3.0 OFS / Dir Cache\n");
				break;
			case 6:
				write_log ("AmigaOS 3.0 FFS / Dir Cache\n");
				break;
			case 7:
				write_log ("FMS Amiga System File\n");
				break;
			default:
				write_log ("Unknown\n");
		}

		write_log (" Compression mode used : ");
		if (cmode>6)
			write_log ("Unknown !\n");
		else
			write_log ("%s\n",modes[cmode]);

		write_log (" General info : ");
		if ((geninfo==0)||(geninfo==0x80)) write_log ("None");
		if (geninfo & 1) write_log ("NoZero ");
		if (geninfo & 2) write_log ("Encrypted ");
		if (geninfo & 4) write_log ("Appends ");
		if (geninfo & 8) write_log ("Banner ");
		if (geninfo & 16) write_log ("HD ");
		if (geninfo & 32) write_log ("MS-DOS ");
		if (geninfo & 64) write_log ("DMS_DEV_Fixed ");
		if (geninfo & 256) write_log ("FILEID.DIZ");
		write_log ("\n");

		write_log (" Info Header CRC : %04X\n\n",hcrc);

	}

	if (disktype == 7) {
		/*  It's not a DMS compressed disk image, but a FMS archive  */
		xfree(b1);
		xfree(b2);
		xfree(dms_text);
		return ERR_FMS;
	}


	if (dolog)	{
		write_log (" Track   Plength  Ulength  Cmode   USUM  HCRC  DCRC Cflag\n");
		write_log (" ------  -------  -------  ------  ----  ----  ---- -----\n");
	}

	//	if (((cmd==CMD_UNPACK) || (cmd==CMD_SHOWBANNER)) && (geninfo & 2) && (!pwd))
	//		return ERR_NOPASSWD;

	ret=NO_PROBLEM;

	Init_Decrunchers();

	if (cmd != CMD_VIEW) {
		if (cmd == CMD_SHOWBANNER) /*  Banner is in the first track  */
			ret = Process_Track(fi,NULL,b1,b2,cmd,opt,geninfo,extra);
		else {
			for (;;) {
				int32_t ok = 0;
				ret = Process_Track(fi,fo,b1,b2,cmd,opt,geninfo,extra);
				if (ret == DMS_FILE_END)
					break;
				if (ret == NO_PROBLEM)
					continue;
				break;
#if 0
				while (!ok) {
					uint8_t b1[THLEN];

					if (zfile_fread(b1,1,THLEN,fi) != 1) {
						write_log ("DMS: unexpected end of file\n");
						break;
					}
					write_log ("DMS: corrupted track, searching for next track header..\n");
					if (b1[0] == 'T' && b1[1] == 'R') {
						USHORT hcrc = (USHORT)((b1[THLEN-2] << 8) | b1[THLEN-1]);
						if (CreateCRC(b1,(ULONG)(THLEN-2)) == hcrc) {
							write_log ("DMS: found checksum correct track header, retrying..\n");
							zfile_fseek (fi, SEEK_CUR, -THLEN);
							ok = 1;
							break;
						}
					}
					if (!ok)
						zfile_fseek (fi, SEEK_CUR, -(THLEN - 1));
				}
#endif
			}
		}
	}

	if ((cmd == CMD_VIEWFULL) || (cmd == CMD_SHOWDIZ) || (cmd == CMD_SHOWBANNER)) write_log ("\n");

	if (ret == DMS_FILE_END) ret = NO_PROBLEM;


	/*  Used to give an error message, but I have seen some DMS  */
	/*  files with texts or zeros at the end of the valid data   */
	/*  So, when we find something that is not a track header,   */
	/*  we suppose that the valid data is over. And say it's ok. */
	if (ret == ERR_NOTTRACK) ret = NO_PROBLEM;


	xfree(b1);
	xfree(b2);
	xfree(dms_text);

	return ret;
}
Пример #21
0
void CheckBringKeyboard(void) 
{
	HMENU			bringsysmenu = NULL;
	MENUITEMINFO	mii;
	int				input_count = 0, i = 0;
	INPUT			input[100] = {0};
	char			temp[256] = {0};
	CString			c_text = "";
	int				keybd_item_pos = 0;
	int				e = SUCCESS;

	if (!p_symbol_engine_autoplayer->isbring())
	{
		write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Not connected to bring, therefore no bring-keyboard to be enabled.\n");
		return;
	}

	write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Connected to bring.\n");
	write_log(preferences.debug_autoplayer(), "[BringKeyBoard] Enabling bring-keyboard if necessary.\n");

	// Init locals
	memset(&mii, 0, sizeof(MENUITEMINFO));

	// Find position of "Keyboard" item on system menu
	bringsysmenu = GetSystemMenu(p_autoconnector->attached_hwnd(), false);

	mii.cbSize = sizeof(MENUITEMINFO);
	mii.fMask = MIIM_STRING;
	mii.fType = MFT_STRING;
	mii.dwTypeData = temp;
	keybd_item_pos = -1;
	for (int i=GetMenuItemCount(bringsysmenu)-1; i>=0; i--) 
	{
		mii.cch = 256;
	
		// Get the text of this menu item
		GetMenuItemInfo(bringsysmenu, i, true, &mii);
		c_text = temp;

		// See if this is the "keyboard" menu item
		if (c_text.MakeLower().Find("keyboard") != -1) 
		{
			keybd_item_pos = i;
			continue;
		}
	}

	// Get state of keyboard menu item
	if (keybd_item_pos == k_undefined) 
	{
		return;
	}
	else 
	{
		mii.cbSize = sizeof(MENUITEMINFO);
		mii.fMask = MIIM_STATE;
		GetMenuItemInfo(bringsysmenu, keybd_item_pos, true, &mii);
	}

	if (!(mii.fState&MFS_CHECKED)) 
	{
		HWND			hwnd_focus;
		POINT			cur_pos = {0};

		input_count = 0;
		// Alt key down
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = VK_MENU;
		input_count++;

		// Space bar down
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = VK_SPACE;
		input_count++;

		// Space bar up
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = VK_SPACE;
		input[input_count].ki.dwFlags = KEYEVENTF_KEYUP;
		input_count++;

		// Alt key up
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = VK_MENU;
		input[input_count].ki.dwFlags = KEYEVENTF_KEYUP;
		input_count++;

		CMyMutex mutex;

		if (!mutex.IsLocked())
			return;

		hwnd_focus = GetFocus();
		GetCursorPos(&cur_pos);

		SetFocus(p_autoconnector->attached_hwnd());
		SetForegroundWindow(p_autoconnector->attached_hwnd());
		SetActiveWindow(p_autoconnector->attached_hwnd());
		SendInput(input_count, input, sizeof(INPUT));

		Sleep(200);

		input_count = 0;
		// K down
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = 'K';
		input_count++;

		// K up
		ZeroMemory(&input[input_count],sizeof(INPUT));
		input[input_count].type = INPUT_KEYBOARD;
		input[input_count].ki.wVk = 'K';
		input[input_count].ki.dwFlags = KEYEVENTF_KEYUP;
		input_count++;

		SetFocus(p_autoconnector->attached_hwnd());
		SetForegroundWindow(p_autoconnector->attached_hwnd());
		SetActiveWindow(p_autoconnector->attached_hwnd());
		SendInput(input_count, input, sizeof(INPUT));

		SetActiveWindow(hwnd_focus);
		SetForegroundWindow(hwnd_focus);
		SetFocus(hwnd_focus);

		SetCursorPos(cur_pos.x, cur_pos.y);
	}

}
Пример #22
0
void my_kbd_handler (int keyboard, int scancode, int newstate)
{
	int code = 0;
	int scancode_new;
	static int swapperdrive = 0;

	if (scancode == specialkeycode ())
		return;

#ifdef WIN32
        if (scancode == DIK_F11 && currprefs.win32_ctrl_F11_is_quit && ctrlpressed ())
                code = AKS_QUIT;
#endif

	scancode_new = scancode;
        if (!specialpressed () && inputdevice_iskeymapped (keyboard, scancode))
                scancode = 0;

#ifdef WIN32
        // GUI must be always available
        if (scancode_new == DIK_F12 && currprefs.win32_guikey < 0)
                scancode = scancode_new;
        if (scancode_new == currprefs.win32_guikey && scancode_new != DIK_F12)
                scancode = scancode_new;
#endif

	write_log ("kbd= %d, sc_new= %d, scancode= %d (0x%02x), state= %d\n", keyboard, scancode_new, scancode, scancode, newstate);

	if (newstate == 0 && code == 0) {
		switch (scancode)
		{
                        case DIK_SYSRQ:
                        screenshot (specialpressed () ? 1 : 0, 1);
                        break;
		}
	}

        if (newstate && code == 0) {
                if (scancode == DIK_F12 /*|| scancode == currprefs.win32_guikey*/) {
                        if (ctrlpressed ()) {
                                code = AKS_TOGGLEDEFAULTSCREEN;
                        } else if (shiftpressed () || specialpressed ()) {
                                if (isfullscreen() <= 0) {
                                        //disablecapture ();
                                        code = AKS_ENTERDEBUGGER;
                                }
                        } else {
                                code = AKS_ENTERGUI;
                        }
                }

                switch (scancode)
                {
                case DIK_F1:
                case DIK_F2:
                case DIK_F3:
                case DIK_F4:
                        if (specialpressed ()) {
                                if (ctrlpressed ()) {
                                } else {
                                        if (shiftpressed ())
                                                code = AKS_EFLOPPY0 + (scancode - DIK_F1);
                                        else
                                                code = AKS_FLOPPY0 + (scancode - DIK_F1);
                                }
                        }
                        break;
                case DIK_F5:
                        if (specialpressed ()) {
                                if (shiftpressed ())
                                        code = AKS_STATESAVEDIALOG;
                                else
                                        code = AKS_STATERESTOREDIALOG;
                        }
                        break;
                case DIK_1:
                case DIK_2:
                case DIK_3:
                case DIK_4:
                case DIK_5:
                case DIK_6:
                case DIK_7:
                case DIK_8:
                case DIK_9:
                case DIK_0:
                        if (specialpressed ()) {
                                int num = scancode - DIK_1;
                                if (shiftpressed ())
                                        num += 10;
                                if (ctrlpressed ()) {
                                       swapperdrive = num;
                                        if (swapperdrive > 3)
                                                swapperdrive = 0;
                                } else {
                                        int i;
                                        for (i = 0; i < 4; i++) {
                                                if (!_tcscmp (currprefs.floppyslots[i].df, currprefs.dfxlist[num]))
                                                        changed_prefs.floppyslots[i].df[0] = 0;
                                        }
                                        _tcscpy (changed_prefs.floppyslots[swapperdrive].df, currprefs.dfxlist[num]);
                                        config_changed = 1;
                                }
                        }
                        break;
                case DIK_NUMPAD0:
                case DIK_NUMPAD1:
                case DIK_NUMPAD2:
                case DIK_NUMPAD3:
                case DIK_NUMPAD4:
                case DIK_NUMPAD5:
                case DIK_NUMPAD6:
                case DIK_NUMPAD7:
                case DIK_NUMPAD8:
                case DIK_NUMPAD9:
                case DIK_NUMPADPERIOD:
                        if (specialpressed ()) {
                                int i = 0, v = -1;
                                while (np[i] >= 0) {
                                        v = np[i + 1];
                                        if (np[i] == scancode)
                                                break;
                                        i += 2;
                                }
                                if (v >= 0)
                                        code = AKS_STATESAVEQUICK + v * 2 + ((shiftpressed () || ctrlpressed ()) ? 0 : 1);
                        }
                        break;
                case DIK_PAUSE:
                        if (specialpressed ()) {
                                if (shiftpressed ())
                                        code = AKS_IRQ7;
                                else
                                        code = AKS_WARP;
                        } else {
                                code = AKS_PAUSE;
                        }
                        break;
                case DIK_SCROLL:
                        code = AKS_INHIBITSCREEN;
                        break;
                case DIK_NUMPADMINUS:
                        if (specialpressed ()) {
                                if (shiftpressed ())
                                        code = AKS_DECREASEREFRESHRATE;
                                else if (ctrlpressed ())
                                        code = AKS_MVOLDOWN;
                                else
                                        code = AKS_VOLDOWN;
                        }
                        break;
                case DIK_NUMPADPLUS:
                        if (specialpressed ()) {
                                if (shiftpressed ())
                                        code = AKS_INCREASEREFRESHRATE;
                                else if (ctrlpressed ())
                                        code = AKS_MVOLUP;
                                else
                                        code = AKS_VOLUP;
                        }
                        break;
                case DIK_NUMPADSTAR:
                        if (specialpressed ()) {
                                if (ctrlpressed ())
                                        code = AKS_MVOLMUTE;
                                else
                                        code = AKS_VOLMUTE;
                        }
                        break;
                case DIK_NUMPADSLASH:
                        if (specialpressed ())
                                code = AKS_STATEREWIND;
                        break;
                }
        }

        if (code) {
                inputdevice_add_inputcode (code, 1);
                return;
        }

        scancode = scancode_new;
        if (!specialpressed () && newstate) {
                if (scancode == DIK_CAPITAL) {
                        host_capslockstate = host_capslockstate ? 0 : 1;
                        capslockstate = host_capslockstate;
                }
                if (scancode == DIK_NUMLOCK) {
                        host_numlockstate = host_numlockstate ? 0 : 1;
                        capslockstate = host_numlockstate;
                }
                if (scancode == DIK_SCROLL) {
                        host_scrolllockstate = host_scrolllockstate ? 0 : 1;
                        capslockstate = host_scrolllockstate;
                }
        }
        if (specialpressed ())
                return;

//        write_log ("kbd2 = %d, scancode = %d (0x%02x), state = %d\n", keyboard, scancode, scancode, newstate);

        inputdevice_translatekeycode (keyboard, scancode, newstate);
}
Пример #23
0
static void add_seglist(const char *name, uae_u32 seglist_addr)
{
    if(seglist_addr == 0) {
        return;
    }

    /* first count the number of segments */
    int num_segs = 0;
    uae_u32 ptr = seglist_addr;
    while(ptr != 0) {
        ptr = get_long(ptr) << 2;
        num_segs ++;
    }

    /* alloc seglist */
    seglist *sl = xmalloc(seglist, 1);
    if(sl == NULL) {
        write_log("segtracker: NO seglist MEMORY!\n");
        return;
    }
    segment *segs = xmalloc(segment, num_segs + 1); // add an empty segment
    if(segs == NULL) {
        write_log("segtracker: NO segments MEMORY!\n");
        return;
    }

    /* fill seglist */
    sl->name = my_strdup(name);
    sl->addr = seglist_addr;
    sl->num_segments = num_segs;
    sl->segments = segs;
    sl->next = NULL;
    sl->prev = NULL;
    sl->debug = NULL;

    /* fill segments */
    ptr = seglist_addr;
    segment *s = segs;
    while(ptr != 0) {
        s->size = get_long(ptr - 4); // size of BPTR + segment
        s->size -= 8; // correct size
        s->addr = ptr + 4;
        s->debug = NULL;
        ptr = get_long(ptr) << 2; // BPTR to next segment
        s++;
    }
    /* last segment is zero */
    s->size = 0;
    s->addr = 0;

    /* link seglist */
    if(segtracker_pool.first == NULL) {
        segtracker_pool.first = sl;
        segtracker_pool.last = sl;
    } else {
        sl->prev = segtracker_pool.last;
        segtracker_pool.last->next = sl;
        segtracker_pool.last = sl;
    }
    segtracker_pool.num_seglists ++;
}
Пример #24
0
void amiga_clipboard_die (void)
{
	signaling = 0;
	write_log ("clipboard not initialized\n");
}
Пример #25
0
//Function:     dump
//Description:  dumps the key_count and property_count of respective file,
//              dumps the inventory table data from main to secondary memory
//Input param:  NULL
//Return Type:  integer
//              Success status on successful operation
//              otherwise respective error status code
int dump()
{
    // Local variables
    int spec_index;
    int key_index;

    // File pointer
    FILE *fp;
    FILE *tfp;

    // Open the file in write mode and dump the latest key count
    fp = fopen("key_count.txt","w+");
    if(fp == NULL) {
        write_log("dump", "FILE_OPEN_ERROR", "Unable to open the key_count file");
        tfp = fopen("tempfile.txt", "a+");
        fprintf(tfp, "%s","\nFollowing contents to be added in said file");
        fprintf(tfp, "%s", "key_count.txt\n");
        fprintf(tfp,"%d", key_count);
        fclose(tfp);
        return FAILURE;
    }
    fprintf(fp,"%d", key_count);
    write_log("dump", "SUCCESS", "Key count dumped successfully");
    fclose(fp);

    // Open the file in write mode and dump the latest properties count
    fp = fopen("property_count.txt","w+");
    if(fp == NULL) {
        write_log("dump", "FILE_OPEN_ERROR", "Unable to open the property_count file");
        tfp = fopen("tempfile.txt", "a+");
        fprintf(tfp, "%s","\nFollowing contents to be added in said file");
        fprintf(tfp, "%s", "property_count.txt\n");
        fprintf(tfp,"%d", property_count);
        fclose(tfp);
        return FAILURE;
    }
    fprintf(fp,"%d", property_count);
    write_log("dump", "SUCCESS", "Property count dumped successfully");
    fclose(fp);

    // Open the inventory file and update the values from the main memory
    // Into the secondary storage
    fp = fopen("inventory_file.txt", "w+");
    if (fp == NULL) {
        write_log("dump", "FILE_OPEN_ERROR", "Unable to open the inventory_file");
        tfp = fopen("tempfile.txt", "a+");
        fprintf(tfp, "%s","\nFollowing contents to be added in said file");
        fprintf(tfp, "%s", "inventory_file.txt\n");
        for (spec_index = 0; spec_index <= property_count; spec_index++) {
            for (key_index = 0; key_index <= key_count; key_index++) {
                fprintf(tfp, "%s ", inventory[spec_index][key_index]);
            }
            fprintf(tfp, "%s", "\n");
        }
        fclose(tfp);
        return FAILURE;
    }

    for (spec_index = 0; spec_index <= property_count; spec_index++) {
        for (key_index = 0; key_index <= key_count; key_index++) {
            fprintf(fp, "%s ", inventory[spec_index][key_index]);
        }
        fprintf(fp, "%s", "\n");
    }
    fclose(fp);

    // Free the memory for inventory
    inventory_memory_deallocation();

    write_log("dump", "SUCCESS", "Inventory table dumped successfully");

    // Close the log file
    close_log();
    return SUCCESS;
}
Пример #26
0
void amiga_clipboard_init (void)
{
	signaling = 0;
	write_log ("clipboard initialized\n");
	initialized = 1;
}
Пример #27
0
int SQL_getSolutionSource(JUDGE_SUBMISSION_ST *pstJudgeSubmission)
{
	if (NULL == pstJudgeSubmission)
	{
		write_log(JUDGE_ERROR,"SQL_getSolutionSourceEx, Input param is null...");
		return OS_ERR;
	}

	SQL_SemP();

	sprintf(query,"select source from solution_source where solution_id=%d",
			pstJudgeSubmission->stSolution.solutionId);

	int ret=mysql_real_query(mysql,query,(unsigned int)strlen(query));
	if(ret)
	{
		write_log(JUDGE_ERROR,mysql_error(mysql));
		SQL_SemV();
		return OS_ERR;
	}

	MYSQL_RES *recordSet = mysql_store_result(mysql);
	if (recordSet==NULL)
	{
		write_log(JUDGE_ERROR,"SQL_getSolutionSource");
		SQL_SemV();
		return OS_ERR;
	}

	FILE *fp_source = fopen(pstJudgeSubmission->sourcePath, "w");
	char code[MAX_CODE]={0};
	MYSQL_ROW row;

	if(row = mysql_fetch_row(recordSet))
	{
		sprintf(code, "%s", row[0]);
	}
	else
	{
		write_log(JUDGE_ERROR,"SQL_getSolutionSource Error");
	}

	if(pstJudgeSubmission->isTranscoding == 1)
	{
		int ii=0;
		/* 解决VS下字符问题 */
		while (code[ii]!='\0')
		{
			if (code[ii]=='\r')
			{
				code[ii] = '\n';
			}

			ii++;
		}
	}

	fprintf(fp_source, "%s", code);

	/* add for vjudge*/
	strcpy(pstJudgeSubmission->szSource, code);

	mysql_free_result(recordSet);
	fclose(fp_source);

	SQL_SemV();

	return OS_OK;
}
Пример #28
0
void amiga_clipboard_task_start (uaecptr data)
{
	clipboard_data = data;
	signaling = 1;
	write_log ("clipboard task init: %08x\n", clipboard_data);
}
Пример #29
0
void write_logautoplay(const char * action) 
{
    char		nowtime[26];
    CString		pcards, comcards, temp, rank, pokerhand, bestaction, fcra_seen;
    char		*card;
    CardMask	Cards;
    int			nCards;
    CString		fcra_formula_status;

	int			sym_userchair = (int) p_symbol_engine_userchair->userchair();
	int			betround = (int) p_betround_calculator->betround();


	if (!prefs.trace_enabled())
		return;

	if (log_fp != NULL) 
	{
		CSLock lock(log_critsec);

		// log$ writing
		if (prefs.log_symbol_enabled())
		{
			int max_log = p_symbols->logsymbols_collection()->GetCount();

			if (max_log > 0)
			{
				if (max_log > prefs.log_symbol_max_log())
				{
					max_log = prefs.log_symbol_max_log();
				}

				write_log(k_always_log_basic_information, "*** log$ (Total: %d | Showing: %d)\n", p_symbols->logsymbols_collection()->GetCount(), max_log);

				for (int i=0; i<max_log; i++)
				{
					write_log(k_always_log_basic_information, "***     %s\n", p_symbols->logsymbols_collection()->GetAt(i));
				}
			}
		}
		
		CardMask_RESET(Cards);
		nCards=0;

		// player cards
		if (p_symbol_engine_userchair->userchair_confirmed()) 
		{
			for (int i=0; i<=1; i++) 
			{
				card = StdDeck_cardString(p_scraper->card_player(sym_userchair, i));
				temp.Format("%s", card);
				pcards.Append(temp);
				CardMask_SET(Cards, p_scraper->card_player(sym_userchair, i));
				nCards++;
			}
		}
		else 
		{
			pcards = "....";
		}

		// common cards
		comcards = "";
		if (betround >= k_betround_flop) 
		{
			for (int i=0; i<=2; i++) 
			{
				if (p_scraper->card_common(i) != CARD_BACK && 
					p_scraper->card_common(i) != CARD_NOCARD) 
				{
					card = StdDeck_cardString(p_scraper->card_common(i));
					temp.Format("%s", card);
					comcards.Append(temp);
					CardMask_SET(Cards, p_scraper->card_common(i));
					nCards++;
				}
			}
		}

		if (betround >= k_betround_turn) 
		{
			card = StdDeck_cardString(p_scraper->card_common(3));
			temp.Format("%s", card);
			comcards.Append(temp);
			CardMask_SET(Cards, p_scraper->card_common(3));
			nCards++;
		}

		if (betround >= k_betround_river) 
		{
			card = StdDeck_cardString(p_scraper->card_common(4));
			temp.Format("%s", card);
			comcards.Append(temp);
			CardMask_SET(Cards, p_scraper->card_common(4));
			nCards++;
		}

        comcards.Append("..........");
        comcards = comcards.Left(10);

        // Always use handrank169 here
		rank.Format("%.0f", p_symbol_engine_handrank->handrank169());

        // poker hand
		pokerhand = p_symbol_engine_pokerval->HandType();

        // best action
        if (strcmp(action, "SWAG")==0) 
		{
            bestaction.Format("$%.2f", p_autoplayer_functions->f$betsize());
        }
        else 
		{
            if (p_autoplayer_functions->f$alli())
                bestaction = "Allin";

            else if (p_autoplayer_functions->f$betsize())
                bestaction = "SWAG";

            else if (p_autoplayer_functions->f$rais())
                bestaction = "Bet/Raise";

            else if (p_autoplayer_functions->f$call())
                bestaction = "Call/Check";

            else if (p_autoplayer_functions->f$prefold())
                bestaction = "Pre-fold";

            else
                bestaction = "Fold/Check";

        }

        // fcra_seen
		int sym_myturnbits = p_symbol_engine_autoplayer->myturnbits();
        fcra_seen.Format("%s%s%s%s%s",
                         sym_myturnbits&0x01 ? "F" : ".",
                         sym_myturnbits&0x02 ? "C" : ".",
						 // Check button out of order to stay consistent
						 // with button order in manual mode.
						 sym_myturnbits&0x10 ? "K" : ".",
                         sym_myturnbits&0x04 ? "R" : ".",
                         sym_myturnbits&0x08 ? "A" : ".");

        // fcra formula status
		fcra_formula_status.Format("%s%s%s%s",
			!p_autoplayer_functions->f$alli() && !p_autoplayer_functions->f$rais() && !p_autoplayer_functions->f$call() && !p_autoplayer_functions->f$betsize() ? "F" : ".",
			p_autoplayer_functions->f$call() ? "C" : ".",
			p_autoplayer_functions->f$rais() ? "R" : ".",
			p_autoplayer_functions->f$alli() ? "A" : ".");

        fprintf(log_fp, "%s - %1d ", 
			get_time(nowtime), 
			p_tablemap->nchairs());
        fprintf(log_fp, "%4s %10s %4s %5s ", 
			pcards.GetString(), 
			comcards.GetString(), 
			rank.GetString(), 
			pokerhand.GetString());
        fprintf(log_fp, "%4d %4d %4d ", 
			(iter_vars.prwin() * 1000),
			(iter_vars.prlos() * 1000), 
			(iter_vars.prtie() * 1000));
        fprintf(log_fp, "%2d %8d %-10s - ", 
			p_symbol_engine_prwin->nopponents_for_prwin(),
			iter_vars.nit(),
			bestaction.GetString());
        fprintf(log_fp, "%-5s %9.2f %9.2f %9.2f ", 
			action, 
			p_symbol_engine_chip_amounts->call(), 
			p_tablelimits->bet(), 
			p_symbol_engine_chip_amounts->pot());
		int userchair = p_symbol_engine_userchair->userchair();
		fprintf(log_fp, "%9.2f - %s %s %.2f\n", 
			p_symbol_engine_chip_amounts->balance(userchair), 
			fcra_seen.GetString(), 
			fcra_formula_status.GetString(), 
			p_autoplayer_functions->f$betsize() );

		if (prefs.trace_enabled() && p_symbols->symboltrace_collection()->GetSize() > 0)
		{
			write_log_nostamp(1, "***** Autoplayer Trace ****\n");
			for (int i=0; i<p_symbols->symboltrace_collection()->GetSize(); i++)
			{
				write_log_nostamp(1, "%s\n", p_symbols->symboltrace_collection()->GetAt(i));
			}
			write_log_nostamp(1, "***********************\n");
		}

		fflush(log_fp);
    }
}
Пример #30
0
static uae_u32 REGPARAM2 expamem_lget (uaecptr addr)
{
    write_log ("warning: READ.L from address $%lx PC=%x\n", addr, M68K_GETPC);
    return (expamem_wget (addr) << 16) | expamem_wget (addr + 2);
}