Beispiel #1
0
void
hs_test (void)
{
  array_t *arr;
  struct hs *a = hs_create (1);
  hs_add (a, array_from_str ("0011xx00"));
  hs_add (a, array_from_str ("10100x0x"));
  arr = array_from_str ("10100x01");
  hs_diff (a, arr);
  hs_print (a);
  struct hs *b = hs_copy_a (a);
  hs_print (b);
  hs_free (b);
  free (arr);

  b = hs_create (1);
  hs_add (b, array_from_str ("xxxx1x00"));
  hs_add (b, array_from_str ("xxxxx1x0"));
  hs_print (b);
  hs_isect (b, a);
  hs_print (b);
  hs_free (b);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  arr = array_from_str ("11111111");
  hs_diff (a, arr);
  hs_print (a);
  hs_cmpl (a);
  hs_print (a);
  hs_free (a);

  a = hs_create (1);
  hs_add (a, array_from_str ("10xxxxxx"));
  hs_add (a, array_from_str ("xxxxxx10"));
  b = hs_create (1);
  hs_add (b, array_from_str ("11111111"));
  hs_minus (a, b);
  hs_print (a);
  hs_free (a);
  hs_free (b);

  a = hs_create (1);
  hs_add (a, array_from_str ("11111111"));
  //hs_add (a, array_from_str ("xxxxxxx1"));
  hs_diff (a, arr);
  hs_print (a);
  hs_comp_diff (a);
  char *s = hs_to_str (a);
  printf ("S: %s\n", s);
  free (s);
  hs_free (a);
  free (arr);
}
Beispiel #2
0
/* call hs_close when done playing game */
void hs_close (void)
{
	if (state.hiscores_have_been_loaded) hs_save();
	hs_free();
}
Beispiel #3
0
/* call hs_open once after loading a game */
void hs_open (void)
{
	FILE *f = NULL;
	char path[MAX_PATH];
#ifdef N900
        sprintf(path, "%s%s", "/opt/cps2emu/config/", db_filename);
#else
        sprintf(path, "%s%s", launchDir, db_filename);
#endif
	if ((f = fopen(path, "rb")) == NULL) {
		msg_printf("High score DB file is broken.\n");
	} else {
		char buffer[MAX_CONFIG_LINE_SIZE];
		enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode;
		mode = FIND_NAME;

		hs_free();
		state.hiscore_file_size = 0;
		//LOG(("hs_open: '%s'\n", game_name));
		while (fgets (buffer, MAX_CONFIG_LINE_SIZE, f))
		{
			if (mode==FIND_NAME)
			{
				if (matching_game_name (buffer))
				{
					mode = FIND_DATA;
					//LOG(("hs config found!\n"));
				}
			}
			else if (is_mem_range (buffer))
			{
				const char *pBuf = buffer;
				struct mem_range *mem_range = malloc(sizeof(struct mem_range));
				if (mem_range)
				{
					mem_range->cpu = hexstr2num (&pBuf);
					mem_range->addr = hexstr2num (&pBuf);
					mem_range->num_bytes = hexstr2num (&pBuf);
					mem_range->start_value = hexstr2num (&pBuf);
					mem_range->end_value = hexstr2num (&pBuf);
					state.hiscore_file_size += mem_range->num_bytes;

					mem_range->next = NULL;
					{
						struct mem_range *last = state.mem_range;
						while (last && last->next) last = last->next;
						if (last == NULL)
							state.mem_range = mem_range;
						else
							last->next = mem_range;
					}

					mode = FETCH_DATA;
				}
				else
				{
					hs_free();
					break;
				}
			}
			else
			{
				/* line is a game name */
				if (mode == FETCH_DATA) break;
			}
		}
		fclose (f);
	}

	state.hiscores_have_been_loaded = 0;
	if (state.mem_range) {
		struct mem_range *mem_range = state.mem_range;

		while (mem_range)
		{
			//computer_writemem_byte(
			//	mem_range->cpu,
			//	mem_range->addr,
			//	~mem_range->start_value
			//);
			m68000_write_memory_8(mem_range->addr, ~mem_range->start_value);
	
			//computer_writemem_byte(
			//	mem_range->cpu,
			//	mem_range->addr + mem_range->num_bytes-1,
			//	~mem_range->end_value
			//);
			m68000_write_memory_8(mem_range->addr + mem_range->num_bytes-1,~mem_range->end_value);
			mem_range = mem_range->next;
		}

		//printf ("cpu:%d, addr:%d, bytes:%d, start_value:%d, end_value:%d\n", state.mem_range->cpu, state.mem_range->addr, state.mem_range->num_bytes, state.mem_range->start_value, state.mem_range->end_value);
	} else {
		option_hiscore = 0;
	}
}
Beispiel #4
0
/* call hs_open once after loading a game */
void hs_open (const char *name)
{
	mame_file *f = mame_fopen (NULL, db_filename, FILETYPE_HIGHSCORE_DB, 0);
	state.mem_range = NULL;

	LOG(("hs_open: '%s'\n", name));

	if (f)
	{
		char buffer[MAX_CONFIG_LINE_SIZE];
		enum { FIND_NAME, FIND_DATA, FETCH_DATA } mode;
		mode = FIND_NAME;

		while (mame_fgets (buffer, MAX_CONFIG_LINE_SIZE, f))
		{
			if (mode==FIND_NAME)
			{
				if (matching_game_name (buffer, name))
				{
					mode = FIND_DATA;
					LOG(("hs config found!\n"));
				}
			}
			else if (is_mem_range (buffer))
			{
				const char *pBuf = buffer;
				struct mem_range *mem_range = osd_malloc(sizeof(struct mem_range));
				if (mem_range)
				{
					mem_range->cpu = hexstr2num (&pBuf);
					mem_range->addr = hexstr2num (&pBuf);
					mem_range->num_bytes = hexstr2num (&pBuf);
					mem_range->start_value = hexstr2num (&pBuf);
					mem_range->end_value = hexstr2num (&pBuf);

					mem_range->next = NULL;
					{
						struct mem_range *last = state.mem_range;
						while (last && last->next) last = last->next;
						if (last == NULL)
						{
							state.mem_range = mem_range;
						}
						else
						{
							last->next = mem_range;
						}
					}

					mode = FETCH_DATA;
				}
				else
				{
					hs_free();
					break;
				}
			}
			else
			{
				/* line is a game name */
				if (mode == FETCH_DATA) break;
			}
		}
		mame_fclose (f);
	}
}