Esempio n. 1
0
void m68k_end_timeslice(void)
{
#if 0
	m68ki_initial_cycles = GET_CYCLES();
	SET_CYCLES(0);
#else
	initialCycles = regs.remainingCycles;
	regs.remainingCycles = 0;
#endif
}
Esempio n. 2
0
int fmemcmp_main(int argc, char ** argv) {
  char * buf, * buf2;
  uint32_t buflen, failure = 0, i;
  unsigned int x,y;
  unsigned int speed[3];

  if(argc < 2) {
    // No input num, just use 1000
    buflen = 1000000;
  } else {
    buflen = atoi(argv[1]);
    if(buflen == 0) return EXIT_FAILURE;
  }

  if(!(buf = malloc(buflen))) {
    printf("Couldn't allocate memory.\n");
    return 0;
  }
  printf("Allocated %u bytes\n", buflen);

  if(!(buf2 = malloc(buflen))) {
    printf("Couldn't allocate memory.\n");
    return 0;
  }
  printf("Allocated %u bytes\n", buflen);

  printf("Filling %u bytes with junk\n", buflen);
  for(i=0; i<buflen; i++) {
    buf[i] = buf2[i] = 1;
  }

  // TEST OF MEMCMP VS. FMEMCMP
  printf("***************** FMEMCMP *****************\n");

  printf("Running system memcmp: ");
  GET_CYCLES(x);
  if(memcmp(buf, buf2, buflen) != 0) failure = 1;
  GET_CYCLES(y);
  printf("time=%u, ", y-x);
  speed[0] = y-x;

  if(!failure) {
    printf("Match!\n");
  } else {
    printf("No Match!\n");
  }
  failure = 0;

  printf("Running forloop memcmp: ");
  GET_CYCLES(x);
  for(i=0; i<buflen; i++) {
    if(buf[i] != buf2[i]) failure = 1;
  }
  GET_CYCLES(y);
  printf("time=%u, ", y-x);
  speed[1] = y-x;

  if(!failure) {
    printf("Match!\n");
  } else {
    printf("No Match!\n");
  }
  failure = 0;

  printf("Running fmemcmp: ");
  GET_CYCLES(x);
  if((fmemcmp(buf, buf2, buflen)) != 0) failure = 1;
  GET_CYCLES(y);
  printf("time=%u, ", y-x);
  speed[2] = y-x;

  if(!failure) {
    printf("Match!\n");
  } else {
    printf("No Match! (%d)\n", failure);
  }
  failure = 0;


  // Summarize
  printf(":: fmemcmp is %g times faster than system memcmp.\n", ((float)speed[0])/speed[2]);
  printf(":: fmemcmp is %g times faster than forloop memcmp.\n", ((float)speed[1])/speed[2]);

  printf("***************** FMEMCMP *****************\n");

  return EXIT_SUCCESS;
}
Esempio n. 3
0
int m68k_execute(int num_cycles)
{
	if (regs.stopped)
	{
		regs.remainingCycles = 0;	// int32_t
		regs.interruptCycles = 0;	// uint32_t

		return num_cycles;
	}

#if 0
	/* Set our pool of clock cycles available */
	SET_CYCLES(num_cycles);
	m68ki_initial_cycles = num_cycles;

	/* ASG: update cycles */
	USE_CYCLES(CPU_INT_CYCLES);
	CPU_INT_CYCLES = 0;

	/* Return point if we had an address error */
	m68ki_set_address_error_trap(); /* auto-disable (see m68kcpu.h) */
#else
	regs.remainingCycles = num_cycles;
	/*int32_t*/ initialCycles = num_cycles;
	
	regs.remainingCycles -= regs.interruptCycles;
	regs.interruptCycles = 0;
#endif

	/* Main loop.  Keep going until we run out of clock cycles */
	do
	{
		// This is so our debugging code can break in on a dime.
		// Otherwise, this is just extra slow down :-P
		if (regs.spcflags & SPCFLAG_DEBUGGER)
		{
			// Not sure this is correct... :-P
			num_cycles = initialCycles - regs.remainingCycles;
			regs.remainingCycles = 0;	// int32_t
			regs.interruptCycles = 0;	// uint32_t

			return num_cycles;
		}
#if 0
		/* Set tracing accodring to T1. (T0 is done inside instruction) */
		m68ki_trace_t1(); /* auto-disable (see m68kcpu.h) */

		/* Set the address space for reads */
		m68ki_use_data_space(); /* auto-disable (see m68kcpu.h) */

		/* Call external hook to peek at CPU */
		m68ki_instr_hook(); /* auto-disable (see m68kcpu.h) */

		/* Record previous program counter */
		REG_PPC = REG_PC;

		/* Read an instruction and call its handler */
		REG_IR = m68ki_read_imm_16();
		m68ki_instruction_jump_table[REG_IR]();
		USE_CYCLES(CYC_INSTRUCTION[REG_IR]);

		/* Trace m68k_exception, if necessary */
		m68ki_exception_if_trace(); /* auto-disable (see m68kcpu.h) */
#else
//Testing Hover Strike...
#if 0
//Dasm(regs.pc, 1);
static int hitCount = 0;
static int inRoutine = 0;
static int instSeen;

//if (regs.pc == 0x80340A)
if (regs.pc == 0x803416)
{
	hitCount++;
	inRoutine = 1;
	instSeen = 0;
	printf("%i: $80340A start. A0=%08X, A1=%08X ", hitCount, regs.regs[8], regs.regs[9]);
}
else if (regs.pc == 0x803422)
{
	inRoutine = 0;
	printf("(%i instructions)\n", instSeen);
}

if (inRoutine)
	instSeen++;
#endif
// AvP testing... (problem was: 32 bit addresses on 24 bit address cpu--FIXED)
#if 0
	static int go = 0;

	if (regs.pc == 0x94BA)
	{
		go = 1;
		printf("\n");
	}

	if (regs.pc == 0x94C6)
		go = 0;

//	if (regs.regs[10] == 0xFFFFFFFF && go)
	if (go)
	{
//		printf("A2=-1, PC=%08X\n", regs.pc);
//		go = 0;
//		Dasm(regs.pc, 130);
		Dasm(regs.pc, 1);
		DumpRegisters();
	}
//94BA: 2468 0000                MOVEA.L	(A0,$0000) == $0002328A, A2
//94BE: 200A                     MOVE.L	A2, D0
//94C0: 6A02                     BPL.B	$94C4
//94C2: 2452                     MOVEA.L	(A2), A2			; <--- HERE
//94C4: 4283                     CLR.L	D3
#endif
//		pthread_mutex_lock(&executionLock);
		if (checkForIRQToHandle)
		{
			checkForIRQToHandle = 0;
			m68k_set_irq2(IRQLevelToHandle);
		}

#ifdef M68K_HOOK_FUNCTION
		M68KInstructionHook();
#endif
		uint32_t opcode = get_iword(0);
//if ((opcode & 0xFFF8) == 0x31C0)
//{
//	printf("MOVE.W D%i, EA\n", opcode & 0x07);
//}
		int32_t cycles = (int32_t)(*cpuFunctionTable[opcode])(opcode);
		regs.remainingCycles -= cycles;
//		pthread_mutex_unlock(&executionLock);

//printf("Executed opcode $%04X (%i cycles)...\n", opcode, cycles);
#endif
	}
	while (regs.remainingCycles > 0);

#if 0
	/* set previous PC to current PC for the next entry into the loop */
	REG_PPC = REG_PC;

	/* ASG: update cycles */
	USE_CYCLES(CPU_INT_CYCLES);
	CPU_INT_CYCLES = 0;

	/* return how many clocks we used */
	return m68ki_initial_cycles - GET_CYCLES();
#else
	regs.remainingCycles -= regs.interruptCycles;
	regs.interruptCycles = 0;

	// Return # of clock cycles used
	return initialCycles - regs.remainingCycles;
#endif
}
Esempio n. 4
0
int bin2hex_main(int argc, char ** argv) {
  FILE * rand_fh;
  char lt[256][2];
  unsigned int x,y;
  char * newhex_dest;
  union {
    uint32_t u32;
    uint8_t u8[4];
  } random_num;
  uint16_t i;
  printf("***************** BIN2HEX *****************\n");

  if(bin2hex_init(lt) == 0) {
    // Fail.. Leave
    fprintf(stderr, "Unable to init lookup table.\n");
    return EXIT_FAILURE;
  }

  rand_fh = fopen("/dev/urandom", "r");
  if(!rand_fh) {
    fprintf(stderr, "Unable to open random buffer.\n");
    return EXIT_FAILURE;
  }
  
  printf("Table created: \n");
  for(i=0; i<256; i++) {
    printf("%c%c", lt[i][0], lt[i][1]);
    if(i%15 == 0) printf("\n");
    else printf(" ");
  }

  // Initialize crazy binary array
  uint8_t * crazy_hex = malloc(CRAZY_SIZE);
  for(i=0; i<CRAZY_SIZE-3; i++) {
    if((fread(&random_num.u32, 4, 1, rand_fh) == 0)) {
      fprintf(stderr, "Could not read 4 bytes from file.\n");
      return EXIT_FAILURE;
    }
    crazy_hex[i] = random_num.u8[0];
    crazy_hex[i+1] = random_num.u8[1];
    crazy_hex[i+2] = random_num.u8[2];
    crazy_hex[i+3] = random_num.u8[3];
    i += 4;
  }
  char hex_dest[2 + 2*CRAZY_SIZE]; 
  hex_dest[0] = '0';
  hex_dest[1] = 'x';
  GET_CYCLES(x);
  bin2hex(lt, &hex_dest[2], crazy_hex, CRAZY_SIZE);
  GET_CYCLES(y);
  printf("time=%u, ", y-x);
  printf("Output: %.*s\n", 2 + 2*CRAZY_SIZE, hex_dest);
  printf("***************** BIN2HEX *****************\n");
  printf("***************** BIN2HEX Competition *****************\n");

  size_t hex2ascii_len = 256;
  char** hex2ascii;
  hex2ascii = malloc(hex2ascii_len*sizeof(char*));
  for(i=0; i<hex2ascii_len; i++) {
    hex2ascii[i] = malloc(3*sizeof(char));
    snprintf(hex2ascii[i], 3,"%02X", i);
  }
  size_t len = 8;
  GET_CYCLES(x);
  newhex_dest = char_to_hex((const unsigned char*)crazy_hex, CRAZY_SIZE, (char**)hex2ascii);
  GET_CYCLES(y);
  printf("time=%u, ", y-x);
  printf("Output: 0x%s\n", newhex_dest);

  fclose(rand_fh);

  return EXIT_SUCCESS;
}