コード例 #1
0
ファイル: boxscore.c プロジェクト: zjentohlauedy/NCFO2
static void updateOffenseStats( team_s *team, player_s *player, nst_offense_game_s *offense )
{
     player->stats.offense->receptions           =           offense->receptions           [0];
     player->stats.offense->receiving_yards      = word2int( offense->receiving_yards          );
     player->stats.offense->receiving_touchdowns =           offense->receiving_touchdowns [0];
     player->stats.offense->rush_attempts        =           offense->rush_attempts        [0];
     player->stats.offense->rush_yards           = word2int( offense->rush_yards               );
     player->stats.offense->rush_touchdowns      =           offense->rush_touchdowns      [0];

     player->stats.returns->kick_returns           =           offense->kick_returns  [0];
     player->stats.returns->kick_return_yards      = word2int( offense->kr_yards          );
     player->stats.returns->kick_return_touchdowns =           offense->kr_touchdowns [0];
     player->stats.returns->punt_returns           =           offense->punt_returns  [0];
     player->stats.returns->punt_return_yards      = word2int( offense->pr_yards          );
     player->stats.returns->punt_return_touchdowns =           offense->pr_touchdowns [0];

     team->offense_stats->rush_attempts   += player->stats.offense->rush_attempts;
     team->offense_stats->rush_yards      += player->stats.offense->rush_yards;
     team->offense_stats->rush_touchdowns += player->stats.offense->rush_touchdowns;

     team->kicking_stats->kick_returns           += player->stats.returns->kick_returns;
     team->kicking_stats->kick_return_yards      += player->stats.returns->kick_return_yards;
     team->kicking_stats->kick_return_touchdowns += player->stats.returns->kick_return_touchdowns;
     team->kicking_stats->punt_returns           += player->stats.returns->punt_returns;
     team->kicking_stats->punt_return_yards      += player->stats.returns->punt_return_yards;
     team->kicking_stats->punt_return_touchdowns += player->stats.returns->punt_return_touchdowns;
}
コード例 #2
0
static int multiply(struct proc *p, int addr)
{
	char temp[4];
	int i,j;

	if (addr < 0 || addr > 99) {
		fprintf(stderr, "multiply: invalid address\n");
		return -1;
	}
	if (load(addr, temp) == -1) {
		fprintf(stderr, "multiply: load failed\n");
		return -1;
	}

	i = word2int(p->r);
	j = word2int(temp);
	if (i == -1) {
		fprintf(stderr, "multiply: non-numeric word in register\n");
		return -1;
	}
	if (j == -1) {
		fprintf(stderr, "multiply: non-numeric word in memory\n");
		return -1;
	}

	i *= j;
	int2word(i, p->r);
	return 0;
}
コード例 #3
0
static int subtract(struct proc *p, int addr)
{
	char temp[4];
	int i,j;

	if (addr < 0 || addr > 99) {
		fprintf(stderr, "subtract: invalid address\n");
		return -1;
	}
	if (load(addr, temp) == -1) {
		fprintf(stderr, "subtract: load failed\n");
		return -1;
	}
	
	i = word2int(p->r);
	j = word2int(temp);
	if (i == -1) {
		fprintf(stderr, "subtract: non-numeric word in register\n");
		return -1;
	}
	if (j == -1) {
		fprintf(stderr, "subtract: non-numeric word in memory\n");
		return -1;
	}
	if (i < j) {
		fprintf(stderr, "subtract: negative result\n");
		return -1;
	}
	i -= j;
	int2word(i, p->r);
	return 0;
}
コード例 #4
0
static int divide(struct proc *p, int addr)
{
	char temp[4];
	int i,j;

	if (addr < 0 || addr > 99) {
		fprintf(stderr, "divide: invalid address\n");
		return -1;
	}
	if (load(addr, temp) == -1) {
		fprintf(stderr, "divide: load failed\n");
		return -1;
	}

	i = word2int(p->r);
	j = word2int(temp);
	if (i == -1) {
		fprintf(stderr, "divide: non-numeric word in register\n");
		return -1;
	}
	if (j == -1) {
		fprintf(stderr, "divide: non-numeric word in memory\n");
		return -1;
	}
	if (j == 0) {
		fprintf(stderr, "divide: division by zero\n");
		return -1;
	}
	i /= j;
	int2word(i, p->r);
	return 0;
}
コード例 #5
0
ファイル: gen_player_ids.c プロジェクト: zjentohlauedy/MBA
boolean_e genPlayerIds( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int player_id = 1, idx = 0; idx < TOTAL_PLAYERS; ++idx )
     {
          if ( EMPTY( players_file[idx].last_name ) ) continue;

          acc_player_id_s *id_info = &(players_file[idx].acc_stats.action.id_info);

          if ( word2int( id_info->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field already contains a number!" );

               return bl_False;
          }

          if ( byte2int( id_info->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field already contains a number!" );

               return bl_False;
          }

          int2word( id_info->player_id,               player_id   );
          int2byte( id_info->checksum,  calcChecksum( player_id ) );

          player_id++;
     }

     return bl_True;
}
コード例 #6
0
ファイル: copy_player_ids.c プロジェクト: zjentohlauedy/MBA
boolean_e copyPlayerIds( fileplayer_s *players_file1, fileplayer_s *players_file2 )
{
     fileplayer_s   *matchingPlayer;


     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
          if ( EMPTY( players_file1[i].last_name ) ) continue;

          if ( (matchingPlayer = findMatchingPlayer( &players_file1[i], players_file2 )) == NULL )
          {
               sprintf( error_message, "Player <%.*s, %.*s> not found!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          acc_player_id_s *id_info1 = &(players_file1[i].acc_stats.action.id_info);
          acc_player_id_s *id_info2 = &(matchingPlayer->acc_stats.action.id_info);

          if ( word2int( id_info1->player_id ) != 0 )
          {
               sprintf( error_message, "Player ID field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          if ( byte2int( id_info1->checksum ) != 0 )
          {
               sprintf( error_message, "Checksum field for <%.*s, %.*s> already contains a number!",
                       sizeof(players_file1[i].last_name),  players_file1[i].last_name,
                       sizeof(players_file1[i].first_name), players_file1[i].first_name );

               return bl_False;
          }

          int2word( id_info1->player_id, word2int( id_info2->player_id ) );
          int2byte( id_info1->checksum,  byte2int( id_info2->checksum  ) );
     }

     return bl_True;
}
コード例 #7
0
ファイル: boxscore.c プロジェクト: zjentohlauedy/NCFO2
static void updatePunterStats( team_s *team, player_s *player, nst_punter_game_s *punter )
{
     player->stats.kicking->punts      =           punter->punts      [0];
     player->stats.kicking->punt_yards = word2int( punter->punt_yards     );

     team->kicking_stats->punts      += player->stats.kicking->punts;
     team->kicking_stats->punt_yards += player->stats.kicking->punt_yards;
}
コード例 #8
0
char *_compareBattingStats( acc_bat_stats_s *expected, acc_bat_stats_s *actual )
{
     assertEquals( word2int( expected->acc_ab    ), word2int( actual->acc_ab    ) );
     assertEquals( word2int( expected->acc_hits  ), word2int( actual->acc_hits  ) );
     assertEquals( byte2int( expected->acc_2b    ), byte2int( actual->acc_2b    ) );
     assertEquals( byte2int( expected->acc_3b    ), byte2int( actual->acc_3b    ) );
     assertEquals( byte2int( expected->acc_hr    ), byte2int( actual->acc_hr    ) );
     assertEquals( byte2int( expected->acc_bb    ), byte2int( actual->acc_bb    ) );
     assertEquals( byte2int( expected->acc_so    ), byte2int( actual->acc_so    ) );
     assertEquals( byte2int( expected->acc_games ), byte2int( actual->acc_games ) );
     assertEquals( byte2int( expected->acc_runs  ), byte2int( actual->acc_runs  ) );
     assertEquals( byte2int( expected->acc_rbi   ), byte2int( actual->acc_rbi   ) );
     assertEquals( byte2int( expected->acc_sb    ), byte2int( actual->acc_sb    ) );
     assertEquals( byte2int( expected->acc_err   ), byte2int( actual->acc_err   ) );

     return NULL;
}
コード例 #9
0
int tick(struct proc *p)
{
	char word[4];
	char temp[4];
	enum OP op;
	int addr, ic, i;

	if (p == NULL) {
		fprintf(stderr, "tick: NULL process\n");
		return -1;
	}
	if (p->runnable == 0)
		return 0;

	/* load the word at p->ic */
	memset(temp, '0', 4);
	memcpy(temp+2, p->ic, 2);
	ic = word2int(temp);
	if (ic == -1) {
		fprintf(stderr, "tick: invalid IC\n");
		return -1;
	}
	if (load(ic, word) == -1) {
		fprintf(stderr, "tick: load failed\n");
		return -1;
	}

	/* increment p->ic */
	ic++;
	int2word(ic, temp);
	memcpy(p->ic, temp+2, 2);

	/* execute the instruction */
	op = OPCODE(word[0], word[1]);
	memset(temp, '0', 4);
	memcpy(temp+2, word+2, 2);
	addr = word2int(temp);

	for (i=0; i<LEN(op_table); i++) {
		if (op_table[i].opcode == op)
			return op_table[i].run(p, addr);
	}
	fprintf(stderr, "tick: Illegal operation %c%c\n", word[0], word[1]);
	return -1;
}
コード例 #10
0
ファイル: boxscore.c プロジェクト: zjentohlauedy/NCFO2
static void updateQuarterbackStats( team_s *team, player_s *player, nst_quarterback_game_s *quarterback )
{
     player->stats.offense->pass_attempts   =           quarterback->pass_attempts    [0];
     player->stats.offense->completions     =           quarterback->pass_completions [0];
     player->stats.offense->pass_touchdowns =           quarterback->pass_touchdowns  [0];
     player->stats.offense->interceptions   =           quarterback->interceptions    [0];
     player->stats.offense->pass_yards      = word2int( quarterback->pass_yards           );
     player->stats.offense->rush_attempts   =           quarterback->rush_attempts    [0];
     player->stats.offense->rush_yards      = word2int( quarterback->rush_yards           );
     player->stats.offense->rush_touchdowns =           quarterback->rush_touchdowns  [0];

     team->offense_stats->pass_attempts   += player->stats.offense->pass_attempts;
     team->offense_stats->completions     += player->stats.offense->completions;
     team->offense_stats->pass_touchdowns += player->stats.offense->pass_touchdowns;
     team->offense_stats->interceptions   += player->stats.offense->interceptions;
     team->offense_stats->pass_yards      += player->stats.offense->pass_yards;
     team->offense_stats->rush_attempts   += player->stats.offense->rush_attempts;
     team->offense_stats->rush_yards      += player->stats.offense->rush_yards;
     team->offense_stats->rush_touchdowns += player->stats.offense->rush_touchdowns;
}
コード例 #11
0
static int set_sp(struct proc *p, int addr)
{
	addr = word2int(p->r);
	if (addr < 0 || addr > 99) {
		fprintf(stderr, "set_sp: invalid address in register\n");
		return -1;
	}
	p->stack_base = addr;
	memcpy(p->sp, p->r, 4);
	return 0;
}
コード例 #12
0
static int divide_stack(struct proc *p, int addr)
{
	char word1[4];
	char word2[4];
	int i,j;

	addr = word2int(p->sp);
	if (addr < 0 || addr > 99) {
		fprintf(stderr, "divide_stack: invalid stack pointer\n");
		return -1;
	}
	if (load(addr--, word1) == -1) {
		fprintf(stderr, "divide_stack: load failed\n");
		return -1;
	}
	if (load(addr, word2) == -1) {
		fprintf(stderr, "divide_stack: load failed\n");
		return -1;
	}

	i = word2int(word1);
	j = word2int(word2);

	if (i==-1 || j==-1) {
		fprintf(stderr, "divide_stack: non-numeric word on stack\n");
		return -1;
	}
	if (i == 0) {
		fprintf(stderr, "divide_stack: division by zero\n");
		return -1;
	}

	j /= i;
	int2word(j, word2);
	int2word(addr, p->sp);
	if (store(word2, addr) == -1) {
		fprintf(stderr, "divide_stack: store failed\n");
		return -1;
	}
	return 0;
}
コード例 #13
0
ファイル: boxscore.c プロジェクト: zjentohlauedy/NCFO2
static void updateDefenseStats( team_s *team, player_s *player, nst_defense_game_s *defense )
{
     player->stats.defense->sacks             =           defense->sacks             [0];
     player->stats.defense->interceptions     =           defense->interceptions     [0];
     player->stats.defense->return_yards      = word2int( defense->return_yards          );
     player->stats.defense->return_touchdowns =           defense->return_touchdowns [0];

     team->defense_stats->sacks             += player->stats.defense->sacks;
     team->defense_stats->interceptions     += player->stats.defense->interceptions;
     team->defense_stats->return_yards      += player->stats.defense->return_yards;
     team->defense_stats->return_touchdowns += player->stats.defense->return_touchdowns;
}
コード例 #14
0
ファイル: updateewbpitching.c プロジェクト: zjentohlauedy/MBA
int main( const int argc, const char *argv[] )
{
     fileplayer_s   *playersFile;
     int             idx;

     if ( argc < 3 )
     {
	  printf( "Usage: %s <input file> <output file>\n", argv[0] );

	  return EXIT_SUCCESS;
     }

     if ( (playersFile = readPlayersFile( argv[1] )) == NULL )
     {
          printf( "Unable to load players file <%s>.\n", argv[1] );

          return EXIT_SUCCESS;
     }

     for ( idx = 0; idx < TOTAL_PLAYERS; ++idx )
     {
	  if ( playersFile[idx].last_name[0] != 0 )
	  {
	       unsigned int pos = playersFile[idx].position[0] / 0x10;

	       if   ( pos != pos_Pitcher ) continue;

               struct pitching_s *pitching = &(playersFile[idx].filestats.filepitching);

               float inn = (float)word2int( pitching->real_inn ) / 10.0;
               float innings  = ((int)inn);
               /**/  innings += (inn - innings) / 3.0;

               unsigned int earned_runs = pitching->real_er[0];

               float era = ((float)earned_runs) / innings * 9.0;

               unsigned int games =     (int)round( innings / ((1 - ((era - 0.50)/2.0)) + 7.5) );
               unsigned int completed = games - (int)ceil( (((era - 0.50)/2.0) * 10.0) );

               pitching->real_games[0]  = games;
               pitching->real_starts[0] = games;
               pitching->real_cg[0]     = completed;

               unsigned char fatigue = (pitching->ratings[1]>>4);
               unsigned char bunt    = (pitching->ratings[1] & 0x0F);

               if ( fatigue == 5 ) fatigue = 6;
               if ( fatigue <  5 ) fatigue = 5;

               pitching->ratings[1] = (fatigue * 0x10) + bunt;
	  }
     }
コード例 #15
0
static int subtract_stack(struct proc *p, int addr)
{
	char word1[4];
	char word2[4];
	int i,j;

	addr = word2int(p->sp);
	if (addr < 0 || addr > 99) {
		fprintf(stderr, "subtract_stack: invalid stack pointer\n");
		return -1;
	}
	if (load(addr--, word1) == -1) {
		fprintf(stderr, "subtract_stack: load failed\n");
		return -1;
	}
	if (load(addr, word2) == -1) {
		fprintf(stderr, "subtract_stack: load_failed\n");
		return -1;
	}

	i = word2int(word1);
	j = word2int(word2);
	if (i==-1 || j==-1) {
		fprintf(stderr, "subtract_stack: non-numeric word on stack\n");
		return -1;
	}
	if (i > j) {
		fprintf(stderr, "subtract_stack: negative result\n");
		return -1;
	}

	j -= i;
	int2word(j, word2);
	int2word(addr, p->sp);
	if (store(word2, addr) == -1) {
		fprintf(stderr, "subtract_stack: store failed\n");
		return -1;
	}
	return 0;
}
コード例 #16
0
static int add_stack(struct proc *p, int addr)
{
	char word1[4];
	char word2[4];
	int i,j;

	addr = word2int(p->sp);
	if (addr < 0 || addr > 99) {
		fprintf(stderr, "add_stack: invalid stack pointer\n");
		return -1;
	}
	if (addr < p->stack_base+1) {
		fprintf(stderr, "add_stack: stack contains less than 2 elements\n");
		return -1;
	}

	if (load(addr--, word1) == -1) {
		fprintf(stderr, "add_stack: load failed\n");
		return -1;
	}
	if (load(addr, word2) == -1) {
		fprintf(stderr, "add_stack: load failed\n");
		return -1;
	}
	i = word2int(word1);
	j = word2int(word2);
	if (i == -1 || j == -1) {
		fprintf(stderr, "add_stack: non-numeric word on stack\n");
		return -1;
	}

	j += i;
	int2word(j, word2); /* store new stack value */
	int2word(addr, p->sp); /* store stack pointer */
	if (store(word2, addr) == -1) {
		fprintf(stderr, "add_stack: store failed\n");
		return -1;
	}
	return 0;
}
コード例 #17
0
ファイル: math.c プロジェクト: mtstickney/BRAIN-Project-4
int do_binop(char *a, char *b, char op)
{
	int i,j;

	i = word2int(a);
	j = word2int(b);
	if (i == -1 || j == -1) {
		fprintf(stderr, "do_binop: non-numeric operand\n");
		fprintf(stderr, "word 1: "); print_word(stderr, a);
		fprintf(stderr, " word 2: "); print_word(stderr, b);
		fprintf(stderr, "\n");
		return -1;
	}
	switch(op) {
	case '+':
		i += j;
		break;
	case '-':
		if (j > i) {
			fprintf(stderr, "do_binop: negative subtraction result\n");
			return -1;
		}
		i -= j;
		break;
	case '*':
		i *= j;
		break;
	case '/':
		if (j == 0) {
			fprintf(stderr, "do_binop: division by zero\n");
			return -1;
		}
		i /= j;
		break;
	}
	return i;
}
コード例 #18
0
static int push(struct proc *p, int addr)
{
	addr = word2int(p->sp);
	if (addr == -1) {
		fprintf(stderr, "push: Non-numeric stack pointer\n");
		return -1;
	}
	addr++;
	int2word(addr, p->sp);
	if (addr > 99) {
		fprintf(stderr, "push: Out of memory\n");
		return -1;
	}
	if (store(p->r, addr) == -1) {
		fprintf(stderr, "push: store failed\n");
		return -1;
	}
	return 0;
}
コード例 #19
0
ファイル: sem.c プロジェクト: mtstickney/BRAIN-Project-4
int set_sem(struct proc *p, int sem)
{
	int val;

	val = word2int(p->r);
	if (val < 0) {
		fprintf(stderr, "set_sem: Invalid semaphor value ");
		print_word(stderr, p->r);
		fprintf(stderr, " (pid %u)\n", p->pid);
		return 1;
	}
	if (sem < 0) {
		fprintf(stderr, "set_sem: Invalid semaphor (pid %u)\n", p->pid);
		return 1;
	}
	if (sem_set(sem, val) != 0) {
		fprintf(stderr, "set_sem: Error setting semaphor (pid %u)\n", p->pid);
		return 1;
	}
	return 0;
}
コード例 #20
0
static int pop(struct proc *p, int addr)
{
	addr = word2int(p->sp);
	if (addr == -1) {
		fprintf(stderr, "pop: non-numeric stack pointer\n");
		return -1;
	}
	if (addr > 99) {
		fprintf(stderr, "pop: Invalid stack pointer\n");
		return -1;
	}
	if (addr <= p->stack_base) {
		fprintf(stderr, "pop: pop on empty stack\n");
		return -1;
	}
	if (load(addr, p->r) == -1) {
		fprintf(stderr, "pop: load failed\n");
		return -1;
	}
	addr--;
	int2word(addr, p->sp);
	return 0;
}
コード例 #21
0
boolean_e formatDosToAmiga( fileplayer_s *players_file )
{
     clearErrorMessage();

     for ( int i = 0; i < TOTAL_PLAYERS; ++i )
     {
	  if ( EMPTY( players_file[i].last_name ) ) continue;

          unsigned int pos = nibble( players_file[i].position[0], n_High );

          if   ( pos != fpos_Pitcher )
          {
               acc_bat_stats_s *action = &(players_file[i].acc_stats.action.batting);

               if ( byte2int( action->acc_rbi ) >= STAT_CAP_AMOUNT ||
                    byte2int( action->acc_so  ) >= STAT_CAP_AMOUNT    )
               {
                    acc_pch_stats_s *pch = &(players_file[i].acc_stats.simulated.pitching);

                    unsigned int act_inn  = word2int( pch->acc_innings );
                    unsigned int act_hits = word2int( pch->acc_hits    );

                    if ( act_inn > 0  ||  act_hits > 0 )
                    {
                         sprintf( error_message, "ERROR: Player %.*s, %.*s requires overflow and has pitching stats.",
                                  sizeof(players_file[i].last_name),  players_file[i].last_name,
                                  sizeof(players_file[i].first_name), players_file[i].first_name );

                         return bl_False;
                    }
               }

               acc_stats_s *acc_stats = &(players_file[i].acc_stats);

               acc_stats_u sim = acc_stats->simulated;

               acc_stats->simulated = acc_stats->action;
               acc_stats->action    = sim;

               capStat( acc_stats->simulated.batting.acc_rbi, acc_stats->action.batting.acc_rbi );
               capStat( acc_stats->simulated.batting.acc_so,  acc_stats->action.batting.acc_so  );
          }
          else
          {
               acc_bat_stats_s *act = &(players_file[i].acc_stats.action.batting);
               acc_pch_stats_s *sim = &(players_file[i].acc_stats.simulated.pitching);

               unsigned char games = act->acc_games[0];

               act->acc_games[0] = 0;

               sim->acc_starts[0] = games;
          }

          acc_player_id_s *id_info = &(players_file[i].acc_stats.action.id_info);

          int player_id = word2int( id_info->player_id );

          if ( player_id == 0  ||  calcChecksum( player_id ) != byte2int( id_info->checksum ) )
          {
               sprintf( error_message, "ERROR: Player %.*s, %.*s has a player id checksum mismatch.",
                        sizeof(players_file[i].last_name),  players_file[i].last_name,
                        sizeof(players_file[i].first_name), players_file[i].first_name );

               return bl_False;
          }
     }

     return bl_True;
}