void append_SNAP(){

    snap=fopen("snapshot.rpt","a");

    int i, j;
    char REG_hex[10]={}, PC_hex[10]={};

    fprintf(snap,"cycle %d\n",cycle);
    for(i=0; i<32; i++){
        if(i<10) fprintf(snap,"$0%d: 0x",i);
        else fprintf(snap,"$%d: 0x",i);

        for(j=7; j>=0; j--)
            REG_hex[j] = DECtoHEX_bit( char_BINtoDEC(REG[i],4,(j+1)*4-1) );
        for(j=0; j<8; j++)
            fprintf(snap,"%c",REG_hex[j]);

        fprintf(snap,"\n");
    }

    fprintf(snap,"PC: 0x");
    //convert PC from binary to hexadecimal
    for(j=7; j>=0; j--)
        PC_hex[j] = DECtoHEX_bit( char_BINtoDEC(PC_prev,4,(j+1)*4-1) );
    for(j=0; j<8; j++)
        fprintf(snap,"%c",PC_hex[j]);

    fprintf(snap,"\nIF: 0x");
    //convert IF from binary to hexadecimal
    for(j=7; j>=0; j--)
        PC_hex[j] = DECtoHEX_bit( char_BINtoDEC(imemory[PC_prevptr/4],4,(j+1)*4-1) );
    for(j=0; j<8; j++)
        fprintf(snap,"%c",PC_hex[j]);
    if(stall) fprintf(snap," to_be_stalled");
    if(flush) fprintf(snap," to_be_flushed");
    fprintf(snap,"\nID: ");
    display_instruction(ID_prev);
    if(stall) fprintf(snap," to_be_stalled");
    fprintf(snap,"\nEX: ");
    display_instruction(EX_prev);
    fprintf(snap,"\nDM: ");
    display_instruction(DM_prev);
    fprintf(snap,"\nWB: ");
    display_instruction(WB_prev);

    fprintf(snap,"\n\n\n");
    fclose(snap);
    cycle++;
}
Beispiel #2
0
Datei: ngaro.c Projekt: js4/ngaro
/******************************************************
 *|F| int main(int argc, char **argv)
 ******************************************************/
int main(int argc, char **argv)
{
  int a, i, trace, endian;

  printf("Video @ %i\n", VIDEO_BASE);

  trace = 0;
  endian = 0;

  strcpy(vm.filename, "retroImage");

  init_vm();
  init_devices();

  vm.shrink = 0;

  /* Parse the command line arguments */
  for (i = 1; i < argc; i++)
  {
    if (strcmp(argv[i], "--trace") == 0)
    {
      trace = 1;
    }
    else if (strcmp(argv[i], "--endian") == 0)
    {
      endian = 1;
    }
    else if (strcmp(argv[i], "--shrink") == 0)
    {
      vm.shrink = 1;
    }
    else if (strcmp(argv[i], "--help") == 0)
    {
      fprintf(stderr, "%s [options] [imagename]\n", argv[0]);
      fprintf(stderr, "Valid options are:\n");
      fprintf(stderr, "   --trace    Execution trace\n");
      fprintf(stderr, "   --endian   Load an image with a different endianness\n");
      fprintf(stderr, "   --shrink   Only save used heap during save operation\n");
      exit(0);
    }
    else
    {
      strcpy(vm.filename, argv[i]);
    }
  }


  /* Load the image */
  a = vm_load_image(vm.filename);

  /* Swap endian if --endian was passed */
  if (endian == 1)
    swapEndian();


  /* Process the image */
  if (trace == 0)
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }
  else
  {
    for (vm.ip = 0; vm.ip < IMAGE_SIZE; vm.ip++)
    {
      display_instruction();
      vm_process(vm.image[vm.ip]);
      update_display(0);
    }
  }

  /* Once done, cleanup */
  cleanup_devices();
  return 0;
}