Exemple #1
0
static int open_mpegvideo(bgav_demuxer_context_t * ctx)
  {
  mpegvideo_priv_t * priv;
  bgav_stream_t * s;
  
  priv = calloc(1, sizeof(*priv));
  ctx->priv = priv;
  
  /* Create track */

  ctx->tt = bgav_track_table_create(1);
  
  s = bgav_track_add_video_stream(ctx->tt->cur, ctx->opt);
  s->index_mode = INDEX_MODE_SIMPLE;
  /*
   *  We just set the fourcc, everything else will
   *  be set by the parser
   */

  s->fourcc = detect_type(ctx->input);
  s->flags |= (STREAM_PARSE_FULL|STREAM_RAW_PACKETS);
  s->ci.flags |= GAVL_COMPRESSION_HAS_B_FRAMES;
  
  ctx->data_start = ctx->input->position;
  ctx->flags |= BGAV_DEMUXER_HAS_DATA_START;
  
  ctx->tt->cur->duration = GAVL_TIME_UNDEFINED;

  gavl_metadata_set(&ctx->tt->cur->metadata, 
                    GAVL_META_FORMAT, "Elementary video stream");
  ctx->index_mode = INDEX_MODE_MIXED;
  
  return 1;

  }
Exemple #2
0
int get_entry(int count,int ingresso,int* start_address,
	      int* end_address,int* offset,char* entry_name){
  unsigned char byte;
  int power;
  filetype type;
  switch (type=detect_type(ingresso)){
  case t64:
    if((count<1)||(count>get_total_entries(ingresso))) return 0;
    lseek(ingresso,32+32*count,SEEK_SET);
    read(ingresso,&byte,1);
    if (byte!=1)return 0;
    read(ingresso,&byte,1);
    if (byte==0)return 0;
    read(ingresso,&byte,1);
    *start_address=byte;
    read(ingresso,&byte,1);
    *start_address=byte*256+*start_address;
    read(ingresso,&byte,1);
    *end_address=byte;
    read(ingresso,&byte,1);
    *end_address=byte*256+*end_address;
    read(ingresso,&byte,1);
    read(ingresso,&byte,1);
    *offset=0;
    for(power=0;power<=3;power++){
      read(ingresso,&byte,1);
      *offset=*offset+(byte<<8*power);
    }
    read(ingresso,&byte,1);
    read(ingresso,&byte,1);
    read(ingresso,&byte,1);
    read(ingresso,&byte,1);
    read(ingresso,entry_name,16);
    entry_name[16]=0;
    return 1;
  case p00:
    *offset=28;
    lseek(ingresso,8,SEEK_SET);
    read(ingresso,entry_name,16);
    entry_name[16]=0;
    lseek(ingresso,26,SEEK_SET);
    read(ingresso,&byte,1);
    *start_address=byte;
    read(ingresso,&byte,1);
    *start_address=byte*256+*start_address;
    *end_address=file_size(ingresso)+*start_address-28;
    return 1;
  case prg:
    *offset=2;
    strcpy(entry_name,"                ");
    lseek(ingresso,0,SEEK_SET);
    read(ingresso,&byte,1);
    *start_address=byte;
    read(ingresso,&byte,1);
    *start_address=byte*256+*start_address;
    *end_address=file_size(ingresso)+*start_address-2;
    return 1;
  }
}
Exemple #3
0
int get_first_entry(FILE *infile, struct program_block *program) {
    filetype type = detect_type(infile);
    int count;
    int total_entries;
    int size_of_c64_program;
    unsigned char byte;

    if (fseek(infile, 0, SEEK_SET) != 0)
        return 0;
    strcpy(program->info.name, "                ");
    switch (type) {
    case t64:
        total_entries = get_total_entries(infile);
        for (count = 1; count <= total_entries; count++)
            if (get_entry(count, infile, program))
                return count;
        return 0;
    case p00:
        if (fseek(infile, 8, SEEK_SET) != 0)
            return 0;
        if (fread(program->info.name, 16, 1, infile) < 1)
            return 0;
        program->info.name[16] = 0;
        if (fseek(infile, 26, SEEK_SET) != 0)
            return 0;
    /* fall back */
    case prg:
        if (fread(&byte, 1, 1, infile) < 1)
            return 0;
        program->info.start = byte;
        if (fread(&byte, 1, 1, infile) < 1)
            return 0;
        program->info.start += byte * 256;
        size_of_c64_program = file_size(infile) - ftell(infile);
        program->info.end = size_of_c64_program + program->info.start;
        if (fread(&program->data, size_of_c64_program, 1, infile) < 1)
            return 0;
        return 1;
    default:
        return 0;
    }
}
Exemple #4
0
int get_entry(int count, FILE *infile, struct program_block *program) {
    switch (detect_type(infile)) {
    case t64:
    {
        unsigned int offset;

        if (!get_entry_info(count, infile, &program->info, &offset))
            return 0;
        if (fseek(infile, offset, SEEK_SET) != 0)
            return 0;
    }
    if (fread(&program->data, 1, program->info.end - program->info.start, infile) < 1)
        return 0;
    return 1;
    case p00:
    case prg:
        return get_first_entry(infile, program);
    default:
        return 0;
    }
}
Exemple #5
0
void list_contents(int ingresso){
  filetype type;
  int total_entries,used;
  int used_entries;
  char tape_name[25];
  int start_address,end_address,count,offset;
  char entry_name[17];
  switch (type=detect_type(ingresso)){
  case t64:
    total_entries=get_total_entries(ingresso);
    used_entries=get_used_entries(ingresso);
    get_tape_name(tape_name,ingresso);
    printf("%d total entr",total_entries);
    if (total_entries==1) printf("y"); else printf("ies");
    printf(", %d used entr",used_entries);
    if (used_entries==1) printf("y"); else printf("ies");
    printf(", tape name: %s\n",tape_name);
    printf("                      Start address    End address\n");
    printf("  No. Name              dec   hex       dec   hex\n");
    printf("--------------------------------------------------\n");
    for(count=1;count<=total_entries;count++)
      if(used=get_entry(count,ingresso,&start_address,&end_address,
			&offset,entry_name))
	printf("%5d %s %5d  %04x     %5d  %04x\n",count,entry_name,
	       start_address,start_address,end_address,end_address);
    return;
  case p00:
    get_entry(count,ingresso,&start_address,&end_address,
	      &offset,entry_name);
    printf("Start address: %d (hex %04x), end address: %d (hex %04x), name: %s\n"
	   ,start_address,start_address,end_address,end_address,entry_name);
    return;
  case prg:
    get_entry(count,ingresso,&start_address,&end_address,
	      &offset,entry_name);
    printf("Start address: %d (hex %04x), end address: %d (hex %04x)\n"
	   ,start_address,start_address,end_address,end_address);
    return;
  }	 
}	 
Exemple #6
0
int get_total_entries(FILE *infile) {
    switch (detect_type(infile)) {
    case t64:
    {
        unsigned char byte;
        int entries;

        if (fseek(infile, 34, SEEK_SET) != 0)
            return 0;
        if (fread(&byte, 1, 1, infile) < 1)
            return 0;
        entries = byte;
        if (fread(&byte, 1, 1, infile) < 1)
            return 0;
        entries = byte * 256 + entries;
        return entries;
    }
    case prg:
    case p00:
        return 1;
    default:
        return 0;
    }
}
Exemple #7
0
int main(int numarg,char** argo){
  int opzione=0;
  int show_help=0;
  int show_version=0;
  int list=0;
  int current_argument;
  int ingresso;
  int uscita;
  char* output_file_name=NULL;
  char* override_entry_name=NULL;
  char* temporary_file_name;
  char* end;
  int append_WAV=0;
  int WAV_descriptor;
  filetype type;
  int count,used,total,used_entries;
  int start_address,end_address,offset;
  char entry_name[17];
  struct entry_element* current_file;
  int first_done=0;
  int dsp_output=0;
  int sample_speed;

  /* Get options */

  while ((opzione=getopt(numarg,argo,"hiloe:v"))!=EOF){
    switch(opzione){
    case 'h':
      show_help=1;
      break;
    case 'i':
      inverted_waveform=1;
      break;
    case 'l':
      list=1;
      break;
    case 'o':
      output_file_name=(char*)malloc(strlen(optarg)+4);
      strcpy(output_file_name,optarg);
      break;
    case 'e':
      override_entry=1;
      override_entry_name=(char*)malloc(strlen(optarg)+4);
      strcpy(override_entry_name,optarg);
      break;
   case 'v':
      show_version=1;
      break;
   default:
      help();
      return 1;
    };
  }
  if (show_help==1){
    help();
    return 0;
  };
  if (show_version==1){
    version();
    return 0;
  };
  if (output_file_name==NULL){ /* -o is not used */
    dsp_output=1;
    output_file_name=(char*)malloc(strlen(SOUNDDEV)+1);
    strcpy(output_file_name,SOUNDDEV);
  };

  current_argument=optind;
  if (current_argument==numarg){
    printf("No input files specified!\n");
    help();
    return 1;
  }
  if (!list){
    if (dsp_output){
      if ((uscita=open(SOUNDDEV,O_WRONLY))==-1){
	printf("Could not open file %s\n",SOUNDDEV);
	return 3;
      }
      sample_speed = 44100;
        if (ioctl(uscita, SNDCTL_DSP_SPEED, &sample_speed) != 0 || sample_speed != 44100){
  	printf("Could not set playback speed to 44100 Hz in file %s\n",SOUNDDEV);
  	return 3;
        } 
    }
    else{
      if((uscita=open(temporary_file_name=tempnam("/tmp","prg2w"),O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){
	printf("Could not create temporary file in /tmp directory\n");
	return 5;
      };
      if (strlen(output_file_name)<5) append_WAV=1;
      else{
	end=output_file_name+strlen(output_file_name)-4;
	if((strcmp(end,".WAV"))&&(strcmp(end,".wav"))) append_WAV=1;
      };
      if (append_WAV) strcat(output_file_name,".wav");
      if((WAV_descriptor=open(output_file_name,O_WRONLY|O_CREAT|O_TRUNC,S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH))==-1){
	printf("Could not create file %s\n",output_file_name);
	unlink(temporary_file_name);
	return 5;
      };
    }
  }
  while (current_argument<numarg){
    if ((ingresso=open(argo[current_argument],O_RDONLY))==-1){
      printf("Could not open file %s\n",argo[current_argument]);
      goto fine;
    };
    switch(type=detect_type(ingresso)){
    case t64:
      printf("%s: T64 file\n",argo[current_argument]);
      break;
    case p00:
      printf("%s: P00 file\n",argo[current_argument]);
      break;
    case prg:
      printf("%s: program file\n",argo[current_argument]);
      break;
    default:
      printf("%s is not a recognized file type\n",argo[current_argument]);
      goto fine;
    };
    if (list){
      list_contents(ingresso);
      goto fine;
    };
    switch(type){
    case t64:
      used_entries=get_used_entries(ingresso);
      total=get_total_entries(ingresso);
      empty_list(files_to_convert);
      files_to_convert=0;
      if (used_entries==1){
	for(count=1;count<=total;count++)
	  if(used=get_entry(count,ingresso,&start_address,&end_address,&offset,
			    entry_name)) set_range(count,count,ingresso);
      }

      /* If there is only one used entry, */
      /* Only the used one will be */
      /* converted */
      /* otherwise ask the user */

      else get_range_from_keyboard(ingresso); 
      current_file=files_to_convert;
      while(current_file!=0){
	count=current_file->entry;
	get_entry(count,ingresso,&start_address,&end_address,&offset,
		  entry_name);
	if (!first_done) first_done=1;
	else add_silence(uscita);
	printf("Converting %d (%s)\n",count,entry_name);
	convert(ingresso,uscita,start_address,end_address,offset,entry_name);
	current_file=current_file->next;
      }
      break;
    case p00:
    case prg:
      if (!first_done) first_done=1;
      else add_silence(uscita);
      printf("Converting %s\n",argo[current_argument]);
      get_entry(count,ingresso,&start_address,&end_address,&offset,
		entry_name);
      if(override_entry) {
        int ix;
        for(ix = 0; ix < strlen(override_entry_name); ix++) {
          entry_name[ix] = toupper(override_entry_name[ix]);
        }
      }
      printf("Entry Name: %s (%d)\n",entry_name,strlen(entry_name));
      convert(ingresso,uscita,start_address,end_address,offset,entry_name);
    };

  fine:   
    ++current_argument;
  };
  close(uscita);
  if((!list)&&(!dsp_output)){
    if(first_done){
      printf("Creating WAV file...\n");
      create_WAV(temporary_file_name,WAV_descriptor);
    }
    else unlink(output_file_name);
  }
}
Exemple #8
0
static int probe_mpegvideo(bgav_input_context_t * input)
  {
  return detect_type(input) ? 1 : 0;
  }
Exemple #9
0
static void write_entries_to_window(HWND window, char *filename){
  int num_of_entries, entry, row_num = 0;
  char numstr[6];
  filetype type;
  LVITEMA row;
  FILE *fd;
  struct program_block program;

  HWND preview = GetDlgItem(window, IDC_PREVIEW);
  HWND text = GetDlgItem(window, IDC_FILE_TYPE);
  HWND c64name = GetDlgItem(window, IDC_C64_NAME);

  fd = fopen(filename, "rb");
  if (fd == NULL)
    return;
  switch (type = detect_type(fd)) {
  case not_a_valid_file:
    EnableWindow(preview, FALSE);
    EnableWindow(c64name, FALSE);
    SetWindowTextA(text, "");
    SetWindowTextA(c64name, "");
    fclose(fd);
    return;
  case t64:
    {
      char message[1000];
      char tape_name[25];
      int num_of_used_entries;

      num_of_entries = get_total_entries(fd);
      num_of_used_entries = get_used_entries(fd);
      get_tape_name(tape_name, fd);
      _snprintf(message, 1000,
                "T64 file with %u total entr%s, %u used entr%s, name %s",
                num_of_entries, num_of_entries == 1 ? "y" : "ies",
                num_of_used_entries, num_of_used_entries == 1 ? "y" : "ies",
                tape_name);
      SetWindowTextA(text, message);
      EnableWindow(preview, num_of_used_entries > 1);
    }
    EnableWindow(c64name, FALSE);
    break;
  case p00:
    EnableWindow(preview, FALSE);
    num_of_entries = 1;
    SetWindowTextA(text, "P00 file");
    EnableWindow(c64name, TRUE);
    break;
  case prg:
    EnableWindow(preview, FALSE);
    num_of_entries = 1;
    SetWindowTextA(text, "PRG file");
    EnableWindow(c64name, TRUE);
    break;
  }

  for (entry = 1; entry <= num_of_entries; entry++) {
    if (get_entry(entry, fd, &program)) {
      row.mask = LVIF_TEXT;
      row.iItem = row_num++;
      row.iSubItem = 0;
      row.pszText = numstr;
      sprintf(numstr, "%u", entry);
      ListView_InsertItem(preview, &row);
      row.iSubItem = 1;
      row.pszText = program.info.name;
      ListView_SetItem(preview, &row);
      row.iSubItem = 2;
      row.pszText = numstr;
      sprintf(numstr, "%u", program.info.start);
      ListView_SetItem(preview, &row);
      row.iSubItem = 3;
      sprintf(numstr, "%u", program.info.end);
      ListView_SetItem(preview, &row);
    }
  }
  if (row_num == 1) {
    ListView_SetItemState(preview, 0, LVIS_SELECTED, LVIS_SELECTED);
    SetWindowTextA(c64name, program.info.name);
  }
  else {
    SetWindowTextA(c64name, "");
    if (IsWindowEnabled(preview))
      ListView_SetItemState(preview, 0, LVIS_FOCUSED, LVIS_FOCUSED);
  }
  fclose(fd);
}
Exemple #10
0
INT_PTR CALLBACK prg2wav_dialog_proc(HWND hwndDlg,      //handle to dialog box
                                     UINT uMsg, //message
                                     WPARAM wParam,     //first message parameter
                                     LPARAM lParam      // second message parameter
  ){
  switch (uMsg) {
  case WM_INITDIALOG:
    CheckRadioButton(hwndDlg, IDC_FAST, IDC_SLOW, IDC_FAST);
    CheckRadioButton(hwndDlg, IDC_TO_TAP, IDC_TO_SOUND, IDC_TO_TAP);
    if (audiotap_startup_status.audiofile_init_status != LIBRARY_OK
     || audiotap_startup_status.tapdecoder_init_status != LIBRARY_OK)
      EnableWindow(GetDlgItem(hwndDlg, IDC_TO_WAV), FALSE);
    if (audiotap_startup_status.portaudio_init_status != LIBRARY_OK
     || audiotap_startup_status.tapdecoder_init_status != LIBRARY_OK)
      EnableWindow(GetDlgItem(hwndDlg, IDC_TO_SOUND), FALSE);
    SetDlgItemInt(hwndDlg, IDC_FREQ, 44100, FALSE);
    SetDlgItemInt(hwndDlg, IDC_VOL, 254, FALSE);
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "C64 PAL");
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "C64 NTSC");
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "VIC20 PAL");
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "VIC20 NTSC");
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "C16 PAL");
    SendMessageA(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_ADDSTRING, 0,
      (LPARAM) "C16 NTSC");
    SendMessage(GetDlgItem(hwndDlg, IDC_MACHINE_TO), CB_SETCURSEL, 0, 0);
    SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0,
      (LPARAM) "Triangle");
    SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0,
      (LPARAM) "Square");
    SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_ADDSTRING, 0,
      (LPARAM) "Sine");
    SendMessageA(GetDlgItem(hwndDlg, IDC_WAVEFORM), CB_SETCURSEL, 1, 0);
    SendMessageA(GetDlgItem(hwndDlg, IDC_THRESHOLD_SPIN), UDM_SETRANGE, 
      0, MAKELONG(1600, 102));
    SendMessage(GetDlgItem(hwndDlg, IDC_THRESHOLD_SPIN), UDM_SETPOS, 
      0, 263);
    return TRUE;
  case WM_COMMAND:
    switch (LOWORD(wParam)) {
    case IDC_FAST:
      EnableWindow(GetDlgItem(hwndDlg, IDC_THRESHOLD), TRUE);
      return TRUE;
    case IDC_SLOW:
      EnableWindow(GetDlgItem(hwndDlg, IDC_THRESHOLD), FALSE);
      return TRUE;
    case IDC_TO_TAP:
      EnableWindow(GetDlgItem(hwndDlg, IDC_INVERTED), FALSE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_FREQ), FALSE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_VOL), FALSE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_WAVEFORM), FALSE);
      return TRUE;
    case IDC_TO_WAV:
    case IDC_TO_SOUND:
      EnableWindow(GetDlgItem(hwndDlg, IDC_INVERTED), TRUE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_FREQ), TRUE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_VOL), TRUE);
      EnableWindow(GetDlgItem(hwndDlg, IDC_WAVEFORM), TRUE);
      return TRUE;
    case IDOK:
      choose_file(hwndDlg);
      return TRUE;
    case IDCANCEL:
      EndDialog(hwndDlg, 0);
      return TRUE;
    default:
      return FALSE;
    }
  case WM_DROPFILES:
    {
      UINT numfiles = DragQueryFileA((HDROP)wParam, 0xFFFFFFFF, NULL, 0);
      UINT i;
      struct prg2wav_params params;
      struct simple_block_list_element **current_block = &params.program;

      params.program = NULL;

      for (i = 0; i < numfiles; i++)
      {
        UINT filenamesize = DragQueryFile((HDROP)wParam, i, NULL, 0);
        LPSTR filename;
        FILE* fd;
        filenamesize++; /* for the null termination */
        filename = (LPSTR)malloc(filenamesize);
        DragQueryFileA((HDROP)wParam, i, filename, filenamesize);
        if ((fd = fopen(filename, "rb")) != NULL){
          struct simple_block_list_element **new_current_block = add_all_entries_from_file(current_block, fd);
          if (detect_type(fd) == prg)
            put_filename_in_entryname(filename, (*current_block)->block.info.name);
          fclose(fd);
          current_block = new_current_block;
        }
        free(filename);
      }
      DragFinish((HDROP)wParam);
      if (params.program != NULL)
        choose_destination_file_and_convert(hwndDlg, &params);
    }
    return TRUE;
#ifdef HAVE_HTMLHELP
  case WM_HELP:
    HtmlHelpA(hwndDlg, "docs\\wavprg.chm::/prg2wav_main.htm",
              HH_DISPLAY_TOPIC, 0);
    return TRUE;
#endif
  default:
    return FALSE;
  }
}
Exemple #11
0
static UINT_PTR APIENTRY frompc_hook_proc(HWND hwnd, UINT uimsg, WPARAM wparam, LPARAM lparam){
  HWND preview;
  char filename[256];
  LVCOLUMNA column;

  preview = GetDlgItem(hwnd, IDC_PREVIEW);
  switch (uimsg) {
  case WM_INITDIALOG:
    column.mask = LVCF_TEXT | LVCF_WIDTH;
    column.pszText = "No.";
    column.cx = 40;
    ListView_InsertColumn(preview, 0, &column);
    column.pszText = "Name";
    column.cx = 160;
    ListView_InsertColumn(preview, 1, &column);
    column.pszText = "Start address";
    column.cx = 80;
    ListView_InsertColumn(preview, 2, &column);
    column.pszText = "End address";
    ListView_InsertColumn(preview, 3, &column);

    SendMessage(GetDlgItem(hwnd, IDC_C64_NAME), EM_LIMITTEXT, 16, 0);

    break;
  case WM_NOTIFY:
    {
      LPOFNOTIFY notify = (LPOFNOTIFY) lparam;
      if (notify->hdr.code == CDN_SELCHANGE) {
        ListView_DeleteAllItems(preview);
        SetDlgItemTextA(hwnd, IDC_C64_NAME, "");
        EnableWindow(GetDlgItem(hwnd, IDC_C64_NAME), FALSE);
        if (CommDlg_OpenSave_GetFilePath
            (notify->hdr.hwndFrom, filename, 256) >= 0)
          write_entries_to_window(hwnd, filename);
      }
      else if (notify->hdr.code == CDN_FILEOK) {
        int entry_num;
        struct simple_block_list_element **block = (struct simple_block_list_element **)notify->lpOFN->lCustData;
        FILE *fd = NULL;

        if (CommDlg_OpenSave_GetFilePath(notify->hdr.hwndFrom, filename, 256)
            < 0) {
          MessageBoxA(hwnd, "Cannot get selected file name", "WAV-PRG error",
                     MB_ICONERROR);
        }
        else
          fd = fopen(filename, "rb");
        if (fd == NULL) {
          MessageBoxA(hwnd, "Cannot open selected file", "WAV-PRG error",
                     MB_ICONERROR);
          SetWindowLong(hwnd, DWL_MSGRESULT, -1);
        }
        else
        {
          switch (detect_type(fd)) {
          case not_a_valid_file:
            MessageBoxA(hwnd, "Selected file is not a supported file",
                       "WAV-PRG error", MB_ICONERROR);
            break;
          case t64:
            {
              int index;
              struct simple_block_list_element **current_block = block;

              for (index = ListView_GetNextItem(preview, -1, LVNI_SELECTED); index != -1; index = ListView_GetNextItem(preview, index, LVNI_SELECTED)) {
                LVITEMA sel_item;
                char sel_num[6];

                sel_item.mask = LVIF_TEXT;
                sel_item.iItem = index;
                sel_item.iSubItem = 0;
                sel_item.pszText = sel_num;
                sel_item.cchTextMax = sizeof(sel_num);
                if (!ListView_GetItem(preview, &sel_item))
                  continue;
                entry_num = atoi(sel_num);
                add_simple_block_list_element(current_block);
                if (!get_entry(entry_num, fd, &(*current_block)->block)){
                  remove_simple_block_list_element(current_block);
                  continue;
                }
                current_block = &(*current_block)->next;
              }
            }
            if (*block == NULL)
              add_all_entries_from_file(block, fd);

            if (*block == NULL)
              MessageBoxA(hwnd, "You chose a T64 file with no entries",
                          "WAV-PRG error", MB_ICONERROR);
            break;
          case p00:
          case prg:
            add_simple_block_list_element(block);
            if (!get_first_entry(fd, &(*block)->block)) {
              MessageBoxA(hwnd, "Error in reading file", "WAV-PRG error",
                         MB_ICONERROR);
              remove_simple_block_list_element(block);;
            }
            else
            {
              int i;
              char pad_with_spaces = 0;

              GetDlgItemTextA(hwnd, IDC_C64_NAME, (*block)->block.info.name, 17);
              for (i = 0; i < 16; i++) {
                if ((*block)->block.info.name[i] == 0)
                  pad_with_spaces = 1;
                if (pad_with_spaces)
                  (*block)->block.info.name[i] = 32;
              }
            }
            break;
          default:
            break;
          }
        }
        if (fd != NULL)
          fclose(fd);
        if (*block == NULL){
          SetWindowLong(hwnd, DWL_MSGRESULT, -1);
          return 1;
        }
      }
      break;
    }
  default:
    break;
  }
  return 0;
}
Exemple #12
0
static FILE *open_xx_file(char *file_name)
{
  FILE *fopen(), *fp;
  int cmd_len, type;

  if ((filter_flag == 0) || (test_magic_flag == 1))
    {
      if ((fp = fopen(file_name, "r")) == NULL)
	{
	  fprintf(stderr,"Can't open file '%s'\n",file_name);
	  return(NULL);
	}
      if (filter_flag == 0) return(fp);
      type = detect_type(fp);
      if (type == EMPTY_TYPE) return(NULL);
      if (type == UNKNOWN_TYPE)
	{
	  fclose(fp);
	}
      else
	{
	  rewind(fp);
	  return(fp);
	}
    }

  cmd_len = strlen(filter_name);
  if (cmd_len == 0)
    {
      fprintf(stderr,"No filter specified\n");
      return(NULL);
    }
  cmd_len += strlen(file_name);
  cmd_len += 10; /* for extra chars */

  if (cmd_len >= max_cmd_len)
    {
      cmd_len += 10;
      if (max_cmd_len > 0) free(command);
      if ((command = (char *) malloc(cmd_len)) == NULL)
	{
	  fprintf(stderr,"Can't allocate %d bytes\n",cmd_len);
	  return(NULL);
	}
      max_cmd_len = cmd_len;
    }

  if (filter_flag == 1)
    { sprintf(command,"%s < %s",filter_name,file_name);}
  else
    { sprintf(command,"%s %s",filter_name,file_name);}

  if (verbose_flag > 0)
    fprintf(stdout," .... %s\n",command);

  if ((fp = popen(command, "r")) == NULL)
    {
      fprintf(stderr,"Can't open file via pipe '%s'\n",command);
      return(NULL);
    }
  popen_flag = 1;

  return(fp);
}
Exemple #13
0
int read_image(PMS *image, char *file_name)
{
  FILE *fpin, *fopen();
  int k, type;
  int length;
  static char old_filter_name[1000];
  static int old_filter_flag;
  static int firsttime=1;

  if(firsttime){
    if(filter_name==NULL){
      filter_name=(char*)malloc(100*sizeof(char));
      if(filter_name==NULL){
	fprintf(stderr,"couldn't get filter_name memory\n");
      }
    }
    strcpy(old_filter_name,filter_name);
    old_filter_flag=filter_flag;
  }

  // auto-detect .gz file type per file
  length=strlen(file_name);
  if(
     (file_name[length-1]=='z')&&
     (file_name[length-2]=='g')&&
     (file_name[length-3]=='.')
     )
    {
      strcpy(filter_name,"gunzip");
      filter_flag=1; // by default
    }
  else{ // then assume NOT gzip file
    filter_flag=0;
  }
  //  fprintf(stderr,"filter: %d %s  %d %s",filter_flag,filter_name,old_filter_flag,old_filter_name); fflush(stderr);

  k=0;
  popen_flag = 0;

  if ((fpin = open_xx_file(file_name)) == NULL)
    { return(0);}


  type = detect_type(fpin);
  //fprintf(stderr,"type: %d ",type); fflush(stderr);

  if (type == EMPTY_TYPE) return(0);
  if (type == UNKNOWN_TYPE)
    {
      fprintf(stderr,"No ppm/pgm/pbm or fbm format\n");
      return(0);
    }
  if (type == FBM_TYPE)
    {
      k=get_fbm_data(image,fpin);
    }
  else if( (type>0)&&(type<=6) )
    {
      k=get_ppm_data(image,fpin,type);
    }
  else if(type==10)
    {
      k=get_r8_data(image,fpin,type);
    }

  if (popen_flag == 0)
    { fclose(fpin);}
  else
    { pclose(fpin);}

  // return variables
  strcpy(filter_name,old_filter_name);
  filter_flag=old_filter_flag;

  firsttime=0;

  return(k);
}
Exemple #14
0
int main(int argc, char **argv)
{
    bool quiet = false;
    struct hwstub_device_t *hwdev;
    enum image_type_t type = IT_DETECT;

    // parse command line
    while(1)
    {
        static struct option long_options[] =
        {
            {"help", no_argument, 0, '?'},
            {"quiet", no_argument, 0, 'q'},
            {"type", required_argument, 0, 't'},
            {0, 0, 0, 0}
        };

        int c = getopt_long(argc, argv, "?qt:", long_options, NULL);
        if(c == -1)
            break;
        switch(c)
        {
            case -1:
                break;
            case 'q':
                quiet = true;
                break;
            case '?':
                usage();
                break;
            case 't':
                if(strcmp(optarg, "raw") == 0)
                    type = IT_RAW;
                else if(strcmp(optarg, "rockbox") == 0)
                    type = IT_ROCKBOX;
                else if(strcmp(optarg, "detect") == 0)
                    type = IT_DETECT;
                else
                {
                    fprintf(stderr, "Unknown file type '%s'\n", optarg);
                    return 1;
                }
                break;
            default:
                abort();
        }
    }

    if(optind + 2 != argc)
        usage();

    char *end;
    unsigned long addr = strtoul(argv[optind], &end, 0);
    if(*end)
    {
        fprintf(stderr, "Invalid load address\n");
        return 2;
    }

    FILE *f = fopen(argv[optind + 1], "rb");
    if(f == NULL)
    {
        fprintf(stderr, "Cannot open file for reading: %m\n");
        return 3;
    }
    fseek(f, 0, SEEK_END);
    size_t size = ftell(f);
    fseek(f, 0, SEEK_SET);
    unsigned char *buffer = (unsigned char*)malloc(size);
    fread(buffer, size, 1, f);
    fclose(f);

    if(type == IT_ROCKBOX || type == IT_DETECT)
    {
        enum image_type_t det = detect_type(buffer, size);
        if(type == IT_ROCKBOX && det != IT_ROCKBOX)
        {
            if(!could_be_rockbox(buffer, size))
                fprintf(stderr, "This file does not appear to be valid rockbox image.\n");
            return 4;
        }
        if(type == IT_DETECT && det == IT_RAW)
            could_be_rockbox(buffer, size);
        type = det;
        if(type == IT_ROCKBOX)
        {
            if(!quiet)
                printf("Rockox image is for player %s (%.4s)\n", get_player_name(buffer + 4), buffer + 4);
            memmove(buffer, buffer + 8, size - 8);
            size -= 8;
        }
    }

    if(!quiet)
    {
        if(type == IT_RAW)
            printf("Loading raw image at %#lx\n", addr);
        else
            printf("Loading rockbox image at %#lx\n", addr);
    }

    // create usb context
    libusb_context *ctx;
    libusb_init(&ctx);
    libusb_set_debug(ctx, 3);

    // look for device
    if(!quiet)
        printf("Looking for device %#04x:%#04x...\n", HWSTUB_USB_VID, HWSTUB_USB_PID);

    libusb_device_handle *handle = libusb_open_device_with_vid_pid(ctx,
        HWSTUB_USB_VID, HWSTUB_USB_PID);
    if(handle == NULL)
    {
        fprintf(stderr, "No device found\n");
        return 1;
    }

    // admin stuff
    libusb_device *mydev = libusb_get_device(handle);
    if(!quiet)
    {
        printf("device found at %d:%d\n",
            libusb_get_bus_number(mydev),
            libusb_get_device_address(mydev));
    }
    hwdev = hwstub_open(handle);
    if(hwdev == NULL)
    {
        fprintf(stderr, "Cannot probe device!\n");
        return 1;
    }

    // get hwstub information
    struct hwstub_version_desc_t hwdev_ver;
    int ret = hwstub_get_desc(hwdev, HWSTUB_DT_VERSION, &hwdev_ver, sizeof(hwdev_ver));
    if(ret != sizeof(hwdev_ver))
    {
        fprintf(stderr, "Cannot get version!\n");
        goto Lerr;
    }
    if(hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR || hwdev_ver.bMinor < HWSTUB_VERSION_MINOR)
    {
        printf("Warning: this tool is possibly incompatible with your device:\n");
        printf("Device version: %d.%d.%d\n", hwdev_ver.bMajor, hwdev_ver.bMinor, hwdev_ver.bRevision);
        printf("Host version: %d.%d\n", HWSTUB_VERSION_MAJOR, HWSTUB_VERSION_MINOR);
    }

    ret = hwstub_rw_mem(hwdev, 0, addr, buffer, size);
    if(ret != (int)size)
    {
        fprintf(stderr, "Image write failed: %d\n", ret);
        goto Lerr;
    }
    hwstub_jump(hwdev, addr);

    hwstub_release(hwdev);
    return 0;

    Lerr:
    // display log if handled
    fprintf(stderr, "Device log:\n");
    do
    {
        char buffer[128];
        int length = hwstub_get_log(hwdev, buffer, sizeof(buffer) - 1);
        if(length <= 0)
            break;
        buffer[length] = 0;
        fprintf(stderr, "%s", buffer);
    }while(1);
    hwstub_release(hwdev);
    return 1;
}
int main(int argc, char** argv){
  char *tapename;
  int currarg,used_entries,total_entries,filesize,offset,diff1,diff2,entries,entry;
  unsigned char endadd_low, endadd_high;
  FILE* desc;
  struct program_block program;

  for (currarg=1;currarg<argc;currarg++){
    if (!lastpart(argv[currarg],".t64")){
      tapename=(char*)malloc(strlen(argv[currarg])+5);
      sprintf(tapename,"%s.t64",argv[currarg]);
    }
    else{
      tapename=(char*)malloc(strlen(argv[currarg])+1);
      sprintf(tapename,"%s",argv[currarg]);
    }
    printf("%s: ",tapename);

    desc=fopen(tapename,"rb");
    if (desc==NULL){
       printf("Cannot open file\n",tapename);
       goto end2;
    }
    if (detect_type(desc)!=t64){
       printf("The file is not a T64\n");
       goto end;
    }
    if ((entries=get_used_entries(desc))!=1){
       printf("Sorry, has %d entries, not 1\n",entries);
       goto end;
    }
    total_entries=get_total_entries(desc);
    for(entry=1;entry<=total_entries;entry++)
      if (get_entry_info(entry,desc,&program.info,&offset))
        break;
    printf("1 entry, name %s, ",program.info.name);
    diff1=program.info.end-program.info.start;
    filesize=file_size(desc);
    diff2=filesize-offset;
    if (diff1==diff2){
       printf("File OK\n");
       goto end;
    }
    printf("broken, fixing...");
    program.info.end=program.info.start+diff2;
    endadd_low=program.info.end&255;
    endadd_high=program.info.end>>8;
    fclose(desc);

    desc=fopen(tapename,"r+b");
    if (desc==NULL){
      printf("failed: %s\n", strerror(errno));
      goto end2;
    }
    fseek(desc,36+32*entry,SEEK_SET);
    fwrite(&endadd_low ,1,1,desc);
    fwrite(&endadd_high,1,1,desc);
    printf("Fixed\n");
end:
    fclose(desc);
end2:
    free(tapename);
  }
  return 0;
}