Beispiel #1
0
static void ARCH_SIGNALDECL
handle_CTRL_C(int dummy)
{
    CBM_FILE fd_cbm_local;

    /*
     * remember fd_cbm, and make the global one invalid
     * so that no routine can call a cbm_...() routine
     * once we have cancelled another one
     */
    fd_cbm_local = fd;
    fd = CBM_FILE_INVALID;

    fprintf(stderr, "\nSIGINT caught, resetting IEC bus...\n");

    DEBUG_PRINTDEBUGCOUNTERS();

    arch_sleep(1);
    cbm_reset(fd_cbm_local);

#if 0   // reset automatically restores the VIA shift register
    arch_usleep(100000);
    fprintf(stderr, "Emergency resetting VIA2 shift register to default.\n");
    cbm_exec_command(fd, drive, CmdBuffer, sizeof(CmdBuffer));
#endif

    cbm_driver_close(fd);
    exit(1);
}
Beispiel #2
0
static void ARCH_SIGNALDECL reset(int dummy)
{
    fprintf(stderr, "\nSIGINT caught X-(  Resetting IEC bus...\n");
    arch_sleep(1);
    d64copy_cleanup();
    cbm_reset(fd_cbm);
    cbm_driver_close(fd_cbm);
    exit(1);
}
Beispiel #3
0
static void ARCH_SIGNALDECL
reset(int dummy)
{
    if (fd != CBM_FILE_INVALID)
    {
        cbm_reset(fd);
        cbm_driver_close(fd);
    }
    exit(1);
}
Beispiel #4
0
static void ARCH_SIGNALDECL
handle_CTRL_C(int dummy)
{
    fprintf(stderr, "\nSIGINT caught, resetting IEC bus...\n");
    DEBUG_PRINTDEBUGCOUNTERS();

    arch_sleep(1);
    cbm_reset(fd);

    cbm_driver_close(fd);
    exit(1);
}
Beispiel #5
0
int ARCH_MAINDECL main(int argc, char *argv[])
{
    __u_char drv = argc > 1 ? arch_atoc(argv[1]) : 8;
    CBM_FILE fd;
    
    if(cbm_driver_open(&fd, 0) == 0)
    {
        cbm_upload(fd, drv, 0x0500, flash, sizeof(flash));
        cbm_exec_command(fd, drv, "U3:", 0);
        cbm_driver_close(fd);
        return 0;
    }
    return 1;
}
Beispiel #6
0
static void ARCH_SIGNALDECL reset(int dummy)
{
    CBM_FILE fd_cbm_local;

    /*
     * remember fd_cbm, and make the global one invalid
     * so that no routine can call a cbm_...() routine
     * once we have cancelled another one
     */
    fd_cbm_local = fd_cbm;
    fd_cbm = CBM_FILE_INVALID;

    fprintf(stderr, "\nSIGINT caught X-(  Resetting IEC bus...\n");

    DEBUG_PRINTDEBUGCOUNTERS();

    cbm_reset(fd_cbm_local);
    cbm_driver_close(fd_cbm_local);
    exit(1);
}
Beispiel #7
0
//
// abort signal trap
//
static void ARCH_SIGNALDECL reset(int dummy)
{
    CBM_FILE fd_cbm_local;

    /*
     * remember fd_cbm, and make the global one invalid
     * so that no routine can call a cbm_...() routine
     * once we have cancelled another one
     */
    fd_cbm_local = fd_cbm;
    fd_cbm = CBM_FILE_INVALID;

    fprintf(stderr, "\nSIGINT caught X-(  Resetting IEC bus...\n");
#ifdef LIBIMGCOPY_DEBUG
    printDebugLibImgCounters(my_message_cb);
#endif
    imgcopy_cleanup();
    cbm_reset(fd_cbm_local);
    cbm_driver_close(fd_cbm_local);
    exit(1);
}
Beispiel #8
0
int ARCH_MAINDECL main(int argc, char **argv)
{
    CBM_FILE fd;
    FILE *file;
    char *fname;

    int mode;
    int c;
    unsigned char *filedata;
    size_t filesize;
    char buf[48];
    int num_entries;
    int num_files;
    int rv;
    int i;
    int write;
    cbmcopy_settings *settings;
    char auto_name[17];
    char auto_type = '\0';
    char output_type = '\0';
    char *tail;
    char *ext;
    char *adapter = NULL;

    unsigned char drive;
    const char *tm = NULL;
    const char *dt = NULL;
    int force_raw = 0;
    int address = -1;
    const char *output_name = NULL;
    const char *address_str = NULL;
    char *fs_name;

    input_reader *readers[] =
    {
        &cbmwrite_raw,   /* must be first, as it is default */
        &cbmwrite_pc64,
        &cbmwrite_t64,
        NULL
    };

    input_reader *rd;

    struct option longopts[] =
    {
        { "help"            , no_argument      , NULL, 'h' },
        { "verbose"         , no_argument      , NULL, 'v' },
        { "adapter"         , required_argument, NULL, '@' },
        { "quiet"           , no_argument      , NULL, 'q' },
        { "version"         , no_argument      , NULL, 'V' },
        { "no-progress"     , no_argument      , NULL, 'n' },
        { "read"            , no_argument      , NULL, 'r' },
        { "write"           , no_argument      , NULL, 'w' },
        { "transfer"        , required_argument, NULL, 't' },
        { "drive-type"      , required_argument, NULL, 'd' },
        { "file-type"       , required_argument, NULL, 'f' },
        { "output"          , required_argument, NULL, 'o' },
        { "raw"             , no_argument      , NULL, 'R' },
        { "address"         , no_argument      , NULL, 'a' },
        { NULL              , 0                , NULL, 0   }
    };

    const char shortopts[] ="hVqvrwnt:d:f:o:Ra:@:";

    if(NULL == (tail = strrchr(argv[0], '/')))
    {
        tail = argv[0];
    }
    else
    {
        tail++;
    }
    if(strcmp(tail, "cbmread") == 0)
    {
        mode = 'r'; /* read */
    }
    else if(strcmp(tail, "cbmwrite") == 0)
    {
        mode = 'w'; /* write */
    }
    else
    {
        mode = EOF; /* mode must be given later */
    }

    settings = cbmcopy_get_default_settings();

    /* loop over cmd line opts */
    while((c=getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
    {
        switch(c)
        {
            case 'h': /* --help */
                help(argv[0]);
                return 0;
            case 'V': /* --version */
                printf("cbmcopy %s\n", OPENCBM_VERSION);
                return 0;
            case 'q': /* -- quiet */
                if(verbosity > sev_fatal)
                    verbosity--;
                break;
            case 'v': /* --verbose */
                if(verbosity < sev_debug)
                    verbosity++;
                break;
            case 'n': /* --no-progress */
                no_progress = 1;
                break;

            case 'r': /* --read */
            case 'w': /* --write */
                if(mode != EOF)
                {
                    my_message_cb(sev_fatal, "-r/-w given more than once");
                    hint(argv[0]);
                    return 1;
                }
                mode = c;
                break;

            case 't': /* --transfer */
                char_star_opt_once(&tm, "--transfer", argv);
                break;
            case 'd': /* --drive-type */
                char_star_opt_once(&dt, "--drive-type", argv);
                break;
            case 'o': /* --output */
                char_star_opt_once(&output_name, "--output", argv);
                break;
            case 'f': /* --file-type */
                output_type = (char) toupper(*optarg);
                break;
            case 'R': /* --raw */
                force_raw = 1;
                break;
            case 'a': /* override-address */
                char_star_opt_once(&address_str, "--address", argv);
                break;
            case '@': /* choose adapter */
                if (adapter == NULL)
                    adapter = cbmlibmisc_strdup(optarg);
                else {
                    my_message_cb(sev_fatal, "--adapter/-@ given more than once.");
                    hint(argv[0]);
                    exit(1);
                }
                break;
            default : /* unknown */
                hint(argv[0]);
                return 1;
        }
    }

    /* check -r/-w */
    switch(mode)
    {
        case 'r' :
            write = 0;
            break;
        case 'w' :
            write = 1;
            break;
        default:
            my_message_cb(sev_fatal,
                          "-r or -w must be given when started as `%s'",
                          argv[0]);
            hint(argv[0]);
            return 1;
    }

    /* check transfer mode */
    settings->transfer_mode = cbmcopy_get_transfer_mode_index(tm);
    if(settings->transfer_mode < 0)
    {
        my_message_cb(sev_fatal, "Unknown transfer mode: %s", tm);
        return 1;
    }

    /* check device type */
    if(dt)
    {
        const struct
        {
            const char *str;
            enum cbm_device_type_e type;
        }
        *p, types[] =
        {
            { "1541", cbm_dt_cbm1541 }, { "1571", cbm_dt_cbm1571 },
            { "1570", cbm_dt_cbm1570 }, { "1581", cbm_dt_cbm1581 },
            { NULL  , cbm_dt_unknown }
        };

        for(p = types; p->str && strcmp(dt, p->str); p++)
            ; /* nothing */

        if(!p->str)
        {
            my_message_cb(sev_fatal, "Unknown drive type: %s", dt);
            return 1;
        }
        settings->drive_type = p->type;
    }

    /* check CBM file type */
    if(output_type)
    {
        if(write)
        {
            if(strchr("DSPU", output_type) == NULL)
            {
                my_message_cb(sev_fatal, "Invalid file type : %c", output_type);
            }
        }
        else
        {
            my_message_cb(sev_warning, "--file-type ignored");
        }
    }

    /* check load address override */
    if(address_str)
    {
        address = strtol(address_str, &tail, 0);
        if(*tail || address < 0 || address > 0xffff)
        {
            my_message_cb(sev_fatal, "--address invalid: %s", address_str);
            hint(argv[0]);
            return 1;
        }
    }

    /* first non-option is device number */
    if(optind == argc)
    {
        my_message_cb(sev_fatal, "%s: No drive number given", argv[0]);
        hint(argv[0]);
        return 1;
    }

    drive = (unsigned char) strtol(argv[optind], &tail, 0);
    if(drive < 8 || drive > 11 || *tail)
    {
        my_message_cb(sev_fatal, "invalid drive: `%s'", argv[optind]);
        return 1;
    }

    /* remaining args are file names */
    num_files = argc - optind - 1;

    if(num_files == 0)
    {
        my_message_cb(sev_fatal, "%s: No files?", argv[0]);
        hint(argv[0]);
        return 1;
    }

    /* more than one file name given, avoid -o option */
    if(num_files > 1 && output_name)
    {
        my_message_cb(sev_fatal, "--output requires exactly one file name");
        return 1;
    }

    rv = cbm_driver_open_ex( &fd, adapter );
    cbmlibmisc_strfree(adapter);

    if(0 == rv)
    {
        fd_cbm = fd;

        /*
         * If the user specified auto transfer mode, find out
         * which transfer mode to use.
         */
        settings->transfer_mode = 
            cbmcopy_check_auto_transfer_mode(fd_cbm,
                settings->transfer_mode,
                drive);

        arch_set_ctrlbreak_handler(reset);

        while(++optind < argc)
        {
            fname = argv[optind];
            if(write)
            {
                rd = readers[0];

                file = fopen(fname, "rb");
                if(file)
                {
                    num_entries = 0;
                    if(!force_raw)
                    {
                        /* try to detect file format */
                        for(i = 1; readers[i] && !num_entries; i++)
                        {
                            num_entries =
                                readers[i]->probe( file, fname, my_message_cb );
                            if(num_entries)
                                rd = readers[i];
                        }
                    }
                    if(!num_entries) num_entries = 1; /* raw file */

                    for(i = 0; i < num_entries; i++)
                    {
                        my_message_cb( sev_debug,
                                       "processing entry %d from %s",
                                       i, fname );
                        if(rd->read(file, fname, i,
                                    auto_name, &auto_type,
                                    &filedata, &filesize, my_message_cb ) == 0)
                        {
                            buf[16] = '\0';
                            if(output_name)
                            {
                                strncpy(buf, output_name, 16);
                                cbm_ascii2petscii(buf);
                            }
                            else
                            {
                                /* no charset conversion */
                                strncpy(buf, auto_name, 16);
                            }
                            strcat(buf, ",x");
                            buf[strlen(buf)-1] =
                                output_type ? output_type : auto_type;
                            strcat(buf, ",W");

                            my_message_cb( sev_info,
                                           "writing %s -> %s", fname, buf );

                            if(address >= 0 && filesize > 1)
                            {
                                filedata[0] = address % 0x100;
                                filedata[1] = address / 0x100;

                                my_message_cb( sev_debug, 
                                               "override address: $%02x%02x",
                                               filedata[1], filedata[0] );

                            }
                            if(cbmcopy_write_file(fd, settings, drive,
                                                  buf, strlen(buf),
                                                  filedata, filesize,
                                                  my_message_cb,
                                                  my_status_cb) == 0)
                            {
                                printf("\n");
                                rv = cbm_device_status( fd, drive,
                                                        buf, sizeof(buf) );
                                my_message_cb( rv ?  sev_warning : sev_info,
                                               "%s", buf );
                            }
                            else
                                printf("\n");

                            if(filedata)
                            {
                                free(filedata);
                            }
                        }
                        else
                        {
                            my_message_cb( sev_warning,
                                           "error processing entry %d from %s",
                                           i, fname );
                        }
                    }
                }
                else
                {
                    my_message_cb( sev_warning,
                                   "warning could not read %s: %s",
                                   fname, arch_strerror(arch_get_errno()) );
                }
            }
            else
            {
                strncpy(buf, fname, 16);
                buf[16] = '\0';
                cbm_ascii2petscii(buf);

                if(output_name)
                {
                    fs_name = arch_strdup(output_name);
                }
                else
                {
                    for(tail = fname; *tail && *tail != ','; tail++);

                    ext = "prg"; /* default */

                    if(*tail)
                    {
                        tail++;
                        switch(*tail)
                        {
                            case 'D': ext = "del"; break;
                            case 'S': ext = "seq"; break;
                            case 'U': ext = "usr"; break;
                        }
                    }
                    fs_name = malloc(strlen(fname) + strlen(ext) + 2);
                    if(fs_name) sprintf(fs_name, "%s.%s", fname, ext);
                }

                if(fs_name)
                {
                    for(tail = fs_name; *tail; tail++)
                    {
                        if(*tail == '/') *tail = '_';
                    }
                }
                else
                {
                    /* should not happen... */
                    cbm_driver_close( fd );
                    my_message_cb(sev_fatal, "Out of memory");
                    exit(1);
                }

                my_message_cb( sev_info, "reading %s -> %s", buf, fs_name );

                if(cbmcopy_read_file(fd, settings, drive, buf, strlen(buf),
                                     &filedata, &filesize,
                                     my_message_cb, my_status_cb) == 0)
                {
                    rv = cbm_device_status( fd, drive, buf, sizeof(buf) );
                    my_message_cb( rv ? sev_warning : sev_info, "%s", buf );

                    file = fopen(fs_name, "wb");
                    if(file)
                    {
                        if(filedata)
                        {
                            if(address >= 0 && filesize > 1)
                            {
                                filedata[0] = address % 0x100;
                                filedata[1] = address / 0x100;

                                my_message_cb( sev_debug, 
                                               "override address: $%02x%02x",
                                               filedata[1], filedata[0] );
                            }
                            if(fwrite(filedata, filesize, 1, file) != 1)
                            {
                                my_message_cb(sev_warning,
                                              "could not write %s: %s",
                                              fs_name, arch_strerror(arch_get_errno()));
                            }
                        }
                        fclose(file);
                    }
                    else
                    {
                        my_message_cb(sev_warning,
                                      "could not open %s: %s",
                                      fs_name, arch_strerror(arch_get_errno()));
                    }

                    if(filedata)
                    {
                        free(filedata);
                    }
                }
                else
                {
                    my_message_cb(sev_warning, "error reading %s", buf);
                }
                if(fs_name)
                {
                    free(fs_name);
                }
            }
        }
        cbm_driver_close( fd );

        if(rv)
        {
            my_message_cb(sev_warning, "there was at least one error" );
        }
    }

    return rv;
}
Beispiel #9
0
int ARCH_MAINDECL main(int argc, char *argv[])
{
    d64copy_settings *settings = d64copy_get_default_settings();

    char *tm = NULL;
    char *src_arg;
    char *dst_arg;

    int  c;
    int  rv = 1;
    int  l;

    int src_is_cbm;
    int dst_is_cbm;

    struct option longopts[] =
    {
        { "help"       , no_argument      , NULL, 'h' },
        { "version"    , no_argument      , NULL, 'V' },
        { "warp"       , no_argument      , NULL, 'w' },
        { "no-warp"    , no_argument      , &settings->warp, 0 },
        { "quiet"      , no_argument      , NULL, 'q' },
        { "verbose"    , no_argument      , NULL, 'v' },
        { "no-progress", no_argument      , NULL, 'n' },
        { "interleave" , required_argument, NULL, 'i' },
        { "start-track", required_argument, NULL, 's' },
        { "end-track"  , required_argument, NULL, 'e' },
        { "transfer"   , required_argument, NULL, 't' },
        { "bam-only"   , no_argument      , NULL, 'b' },
        { "bam-save"   , no_argument      , NULL, 'B' },
        { "drive-type" , required_argument, NULL, 'd' },
        { "retry-count", required_argument, NULL, 'r' },
        { "two-sided"  , no_argument      , NULL, '2' },
        { "error-map"  , required_argument, NULL, 'E' },
        { NULL         , 0                , NULL, 0   }
    };

    const char shortopts[] ="hVwqbBt:i:s:e:d:r:2vnE:";

    while((c=getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
    {
        switch(c)
        {
            case 'h': help();
                      return 0;
            case 'V': printf("d64copy %s\n", OPENCBM_VERSION);
                      return 0;
            case 'w': settings->warp = 1;
                      break;
            case 'q': if(verbosity > 0) verbosity--;
                      break;
            case 'v': verbosity++;
                      break;
            case 'n': no_progress = 1;
                      break;
            case 'i': settings->interleave = arch_atoc(optarg);
                      break;
            case 's': settings->start_track = atoi(optarg);
                      break;
            case 'e': settings->end_track = atoi(optarg);
                      break;
            case 't': tm = optarg;
                      break;
            case 'b': settings->bam_mode = bm_allocated;
                      break;
            case 'B': settings->bam_mode = bm_save;
                      break;
            case 'd': if(strcmp(optarg, "1541") == 0)
                      {
                          settings->drive_type = cbm_dt_cbm1541;
                      }
                      else if(strcmp(optarg, "1571") == 0)
                      {
                          settings->drive_type = cbm_dt_cbm1571;
                      }
                      else if(strcmp(optarg, "1570") == 0)
                      {
                          settings->drive_type = cbm_dt_cbm1570;
                      }
                      else
                      {
                          settings->drive_type = atoi(optarg) != 0 ?
                              cbm_dt_cbm1571 : cbm_dt_cbm1541;
                      }
                      break;
            case 'r': settings->retries = atoi(optarg);
                      break;
            case '2': settings->two_sided = 1;
                      break;
            case 'E': l = strlen(optarg);
                      if(strncmp(optarg, "always", l) == 0)
                      {
                          settings->error_mode = em_always;
                      }
                      else if(strncmp(optarg, "on_errors", l) == 0)
                      {
                          settings->error_mode = em_on_error;
                      }
                      else if(strncmp(optarg, "never", l) == 0)
                      {
                          settings->error_mode = em_never;
                      }
                      else
                      {
                          hint(argv[0]);
                          return 1;
                      }
                      break;
            case 0:   break; // needed for --no-warp
            default : hint(argv[0]);
                      return 1;
        }
    }

    settings->transfer_mode = d64copy_get_transfer_mode_index(tm);
    if(settings->transfer_mode < 0)
    {
        char *modes = d64copy_get_transfer_modes();
        char *m;

        fprintf(stderr, "Unknown transfer mode: %s\nAvailable modes:\n", tm);

        for(m = modes; *m; m+=(strlen(m)+1))
        {
            fprintf(stderr, "  %s\n", m);
        }

        free(modes);
        return 1;
    }

    my_message_cb(3, "transfer mode is %d", settings->transfer_mode );

    if(optind + 2 != argc)
    {
        fprintf(stderr, "Usage: %s [OPTION]... [SOURCE] [TARGET]\n", argv[0]);
        hint(argv[0]);
        return 1;
    }

    src_arg = argv[optind];
    dst_arg = argv[optind+1];

    src_is_cbm = is_cbm(src_arg);
    dst_is_cbm = is_cbm(dst_arg);

    if(src_is_cbm == dst_is_cbm)
    {
        my_message_cb(0, "either source or target must be a CBM drive");
        return 1;
    }

    if(cbm_driver_open(&fd_cbm, 0) == 0)
    {
        /*
         * If the user specified auto transfer mode, find out
         * which transfer mode to use.
         */
        settings->transfer_mode = 
            d64copy_check_auto_transfer_mode(fd_cbm,
                settings->transfer_mode,
                atoi(src_is_cbm ? src_arg : dst_arg));

        my_message_cb(3, "decided to use transfer mode %d", settings->transfer_mode );

        signal(SIGINT, reset);

        if(src_is_cbm)
        {
            rv = d64copy_read_image(fd_cbm, settings, atoi(src_arg), dst_arg,
                    my_message_cb, my_status_cb);
        }
        else
        {
            rv = d64copy_write_image(fd_cbm, settings, src_arg, atoi(dst_arg),
                    my_message_cb, my_status_cb);
        }

        if(!no_progress && rv >= 0)
        {
            printf("\n%d blocks copied.\n", rv);
        }

        cbm_driver_close(fd_cbm);
        rv = 0;
    }
    else
    {
        arch_error(0, arch_get_errno(), "%s", cbm_get_driver_name(0));
    }

    free(settings);
    
    return rv;
}
Beispiel #10
0
int main(int argc, char **argv)
{
    int ret, n;
    unsigned char drive = 8;
    CBM_FILE f;
    char buffer[80];
    char *devicetype_str;
    const char *drivername;
    enum cbm_device_type_e devicetype;
    int checklines = 0;
    int checkiohook = 0;

    if (argc>1)
    {
        int i;

        for (i=0; i < argc; i++)
        {
            switch (argv[i][0])
            {
            case '-':
                    checklines = 1;
                    break;

            case '+':
                    checkiohook = 1;
                    break;

            default:
                    drive = atoi(argv[i]);
            }
        }
    }

    printf("VDDTEST " __DATE__ " " __TIME__ ", using drive %u\n", drive);

    if (vdd_init())
    {
        printf("Could not initialize the VDD, aborting!\n");
        exit(1);
    }

    drivername = cbm_get_driver_name(0);
    printf("cbm_get_driver_name() returned %s.\n", drivername);

    ret = cbm_driver_open(&f, 0);

    if (ret)
    {
        printf("cbm_driver_open FAILED!\n");
        exit(1);
    }
    printf("cbm_driver_open success!\n\n");

    n = cbm_reset(f);
    printf("cbm_reset %s\n", n==0 ? "success" : "FAILED");

    if (checklines)
    {
        changelines(f);
    }

    n = cbm_device_status(f, drive, buffer, sizeof(buffer));
    printf("cbm_device_status returned: %u\n%s\n\n", n, buffer);

    n = cbm_open(f, drive, 15, "I0", 0);
    printf("cbm_open %u,15,\"I0\" %s!\n", drive, n == 0 ? "success" : "FAILED");
    n = cbm_close(f, drive, 15);
    printf("cbm_close %s!\n", n == 0 ? "success" : "FAILED");

    n = own_device_status(f, drive, buffer, sizeof(buffer));
    printf("own_device_status returned: %u\n%s\n\n", n, buffer);

    n = cbm_identify(f, drive, &devicetype, &devicetype_str);
    printf("cbm_identify %s!\n", n==0 ? "success" : "FAILED");
    printf("cbm_identify returned: %u - '%s'.\n\n", (unsigned int) devicetype,
                         devicetype_str);

    n = cbm_exec_command(f, drive, "S0:OPENCBM.VDD", 0);
    printf("cbm_exec_command(scratch) %s!\n", n==0 ? "success" : "FAILED");

    writefile(f, drive, "OPENCBM.VDD,S,W");
    readfile(f, drive, "OPENCBM.VDD,S,R");

    morse(f, drive);

    if (checkiohook)
    {
        unsigned int base = 0x0fc0;

        printf("trying to install iohook at 0x%08x ", base);
        if (vdd_install_iohook(f, base, 1))
        {
            int i;

            printf("success\n");

            for (i=0; i<15; i++)
            {
                outportb(base + 2, i);
                sleep(1);
            }

            printf("trying to uninstall iohook ");
            if (vdd_uninstall_iohook(f))
            {
                printf("success\n");
            }
            else
            {
                printf("FAILED\n");
            }
        }
        else
        {
            printf("FAILED\n");
        }
    }

    cbm_driver_close(f);
    printf("cbm_driver_close success!\n");

    return 0;
}
Beispiel #11
0
int ARCH_MAINDECL
main(int argc, char *argv[])
{
    int status = 0;
    char cmd[40];
    unsigned char job = 1, begintrack = 1, endtrack = 35, retries = 5;
    char c, *arg;
    char *adapter = NULL;
    int sector = 0, berror = 0;

    struct option longopts[] =
    {
        { "help"       , no_argument      , NULL, 'h' },
        { "version"    , no_argument      , NULL, 'V' },
        { "adapter"    , required_argument, NULL, '@' },
        { "job"        , no_argument      , NULL, 'j' },
        { "retries"    , required_argument, NULL, 'r' },
        { "extended"   , no_argument      , NULL, 'x' },
        { "retries"    , required_argument, NULL, 'r' },
        { "begin-track", required_argument, NULL, 'b' },
        { "end-track"  , required_argument, NULL, 'e' },
        { "sector"     , required_argument, NULL, 'c' },
/*
        { "quiet"      , no_argument      , NULL, 'q' },
        { "verbose"    , no_argument      , NULL, 'v' },
        { "no-progress", no_argument      , NULL, 'n' },
*/
        { NULL         , 0                , NULL, 0   }
    };

    // const char shortopts[] ="hVj:sr:xb:e:c:qvn";
    const char shortopts[] ="hVj:sxr:b:e:c:@:";


    while((c=(unsigned char)getopt_long(argc, argv, shortopts, longopts, NULL)) != -1)
    {
        switch(c)
        {
            case 'h': help();
                      return 0;
            case 'V': printf("cbmrpm41 Version %s\n", OPENCBM_VERSION ", built on " __DATE__ " at " __TIME__ "\n");
                      return 0;
            case 'j': job = arch_atoc(optarg);
                      break;
            case 's': status = 1;
                      break;
            case 'x': begintrack = 1;
                      endtrack = 40;
                      break;

            case 'r': retries = arch_atoc(optarg);
                      if(retries<1)       retries =  1;
                      else if(retries>63) retries = 63;
                      break;
            case 'b': begintrack = arch_atoc(optarg);
                      break;
            case 'e': endtrack = arch_atoc(optarg);
                      break;
            case 'c': sector = atoi(optarg);
                      break;
            case '@': if (adapter == NULL)
                          adapter = cbmlibmisc_strdup(optarg);
                      else
                      {
                          fprintf(stderr, "--adapter/-@ given more than once.");
                          help();
                          return 0;
                      }
                      break;
            default : hint(argv[0]);
                      return 1;
        }
    }

    if(optind + 1 != argc)
    {
        fprintf(stderr, "Usage: %s [OPTION]... DRIVE\n", argv[0]);
        hint(argv[0]);
        return 1;
    }

    arg = argv[optind++];
    drive = arch_atoc(arg);
    if(drive < 8 || drive > 11)
    {
        fprintf(stderr, "Invalid drive number (%s)\n", arg);
        return 1;
    }
    if(begintrack < 1)
    {
        fprintf(stderr, "Beginning track is less than 1, it should be 1 or greater.\n");
        return 1;
    }
    if(endtrack > 42)
    {
        fprintf(stderr, "Ending track is greater than 42, it should be 42 or less.\n");
        return 1;
    }
    if(begintrack > endtrack)
    {
        fprintf(stderr, "Beginning track is greater than ending track, it should be less or equal.");
        return 1;
    }
    if(sector < 0)
    {
        fprintf(stderr, "Sector numbers less than zero are not allowed.");
        return 1;
    }


    SETSTATEDEBUG((void)0);
    printf("Please remove any diskettes used with production data on it. Insert a freshly\n"
           "formatted disk into drive %d; you can format a disk with e.g. the command:\n\n"
           "        cbmforng -o -v %d freshdisk,fd\n\n"
           "If you desperately need to examine a production disk or even an original\n"
           "diskette, then please protect the disk with a write protect adhesive label.\n\n"
           "Press <Enter>, when ready or press <CTRL>-C to abort.\r", drive, drive);
    getchar();

    if(cbm_driver_open_ex(&fd, adapter) == 0) do
    {
        arch_set_ctrlbreak_handler(handle_CTRL_C);

        SETSTATEDEBUG((void)0);
        if( cbm_upload(fd, drive, sizeof(cbmDev_StartAddress), cbmrpm41, sizeof(cbmrpm41))
            != sizeof(cbmrpm41)) break;

        // location of the new U vector user commands table
        sprintf(cmd, "%c%c", UcmdTblAddr & 0xFF, UcmdTblAddr >> 8);
        // install the new U vector table
        SETSTATEDEBUG((void)0);
        if( cbm_upload(fd, drive, sizeof(cbmDev_UxCMDtVector), cmd, 2)
            != 2) break;

        // execute Ux command behind the symbolic name Init23_BitTimersStd
        SETSTATEDEBUG((void)0);
        if( cbm_sendUxCommand(fd, drive, Init23_BitTimersStd)
            != 0) break;

        // read disk ID and initialise other parameters
        // from the currently inserted disk into the
        // drive's RAM locations
        SETSTATEDEBUG((void)0);
        if( cbm_exec_command(fd, drive, "I0", 2)
            != 0) break;

        SETSTATEDEBUG((void)0);
        berror = cbm_device_status(fd, drive, cmd, sizeof(cmd));
        if(berror && status)
        {
            printf("%s\n", cmd);
        }

        switch(job)
        {
        case 4:
            if( do_RPMadjustment (begintrack, endtrack, sector, retries)
                != 0 ) continue;    // jump to begin of do{}while(0);
            break;
        case 3:
            if( do_RPMregression (begintrack, endtrack, sector, retries)
                != 0 ) continue;    // jump to begin of do{}while(0);
            break;
        case 2:
            if( do_SKEWmeasurment(begintrack, endtrack, sector, retries)
                != 0 ) continue;    // jump to begin of do{}while(0);
            break;
        default:
            if( do_RPMmeasurment (begintrack, endtrack, sector, retries)
                != 0 ) continue;    // jump to begin of do{}while(0);
        }

        if( cbm_sendUxCommand(fd, drive, ResetVIA2ShiftRegConfig)
            != 0 ) break;
        if( cbm_sendUxCommand(fd, drive,      ResetUxVectorTable)
            != 0 ) break;

        if( cbm_exec_command(fd, drive, "I", 2)
            != 0 ) break;

        if(!berror && status)
        {
            cbm_device_status(fd, drive, cmd, sizeof(cmd));
            printf("%s\n", cmd);
        }
        cbm_driver_close(fd);
        cbmlibmisc_strfree(adapter);
        return 0;
    } while(0);
    else
    {
Beispiel #12
0
static int
main_testlines(int argc, char **argv)
{
    /* CBM_FILE fd; */
    int rv;

    FUNC_ENTER();

    do
    {
        rv = cbm_driver_open(&fd, 0);

        if (rv != 0)
            break;

        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing all lines"));
        cbm_iec_release(fd, IEC_CLOCK | IEC_DATA | IEC_ATN | IEC_RESET);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting CLOCK"));
        cbm_iec_set(fd, IEC_CLOCK);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting DATA"));
        cbm_iec_set(fd, IEC_DATA);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting ATN"));
        cbm_iec_set(fd, IEC_ATN);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting RESET"));
        cbm_iec_set(fd, IEC_RESET);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing CLOCK"));
        cbm_iec_release(fd, IEC_CLOCK);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing DATA"));
        cbm_iec_release(fd, IEC_DATA);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing ATN"));
        cbm_iec_release(fd, IEC_ATN);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing RESET"));
        cbm_iec_release(fd, IEC_RESET);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting DATA and ATN"));
        cbm_iec_set(fd, IEC_DATA | IEC_ATN);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Setting CLOCK, releasing ATN"));
        cbm_iec_setrelease(fd, IEC_ATN | IEC_CLOCK, IEC_CLOCK);
        read_line_status(fd);

        DBG_PRINT((DBG_PREFIX ""));
        DBG_PRINT((DBG_PREFIX "Releasing all lines"));
        cbm_iec_release(fd, IEC_CLOCK | IEC_DATA | IEC_ATN | IEC_RESET);
        read_line_status(fd);

    } while (0);

    if (rv == 0)
        cbm_driver_close(fd);

    FUNC_LEAVE_INT(0);
}
Beispiel #13
0
static int
main_testtransfer(int argc, char **argv)
{
    /* CBM_FILE fd; */
    unsigned char compare_buffer[0x8000];
    unsigned char buffer[0x8000];
    unsigned int error = 0;
    int rv;

#if DBG
    DbgFlags = 0x0;
#endif

    printf(" libtransfer sample: " __DATE__ " " __TIME__ "\n");

    if (argc > 1)
    {
        processParameter(argc, argv);
    }

    rv = cbm_driver_open(&fd, 0);

    if(rv != 0)
    {
        DBG_ERROR((DBG_PREFIX "cbm_driver_open() failed!"));
        return 1;
    }

    DBG_PRINT((DBG_PREFIX "before install"));
    libopencbmtransfer_install(fd, drive);

    memset(buffer, 0, sizeof(buffer));

    if (compare)
        read_from_file(compare_buffer, sizeof(compare_buffer), "rom.image");

    DBG_PRINT((DBG_PREFIX "before read_mem"));

#if 0
    transferlength = 0x100;
    printf("write $0300\n");
    libopencbmtransfer_write_mem(fd, drive, compare_buffer, 0x300, transferlength);
    printf("read $0300\n");
    libopencbmtransfer_read_mem(fd, drive, buffer, 0x300, transferlength);

    printf("compare\n");
    if (memcmp(buffer, compare_buffer, transferlength) != 0)
    {
        printf("differing!\n");
    }
#else
    while (count--)
    {
        printf("read:  %i, error = %u: \n", count+1, error);
        libopencbmtransfer_read_mem(fd, drive, buffer, 0x8000, transferlength);
        if (compare)
        {
            if (memcmp(buffer, compare_buffer, transferlength) != 0)
            {
                char filename[128];
                int n;

                printf("\n\n***** ERROR COMPARING DATA! *****\n\n");
                ++error;

                strcpy(filename, "image.err.");
                n = strlen(filename);

                if (error > 9999) filename[n++] = ((error / 10000) % 10) + '0';
                if (error >  999) filename[n++] = ((error /  1000) % 10) + '0';
                if (error >   99) filename[n++] = ((error /   100) % 10) + '0';
                if (error >    9) filename[n++] = ((error /    10) % 10) + '0';
                if (error >    0) filename[n++] = ((error /     1) % 10) + '0';

                filename[n] = 0;
                write_to_file(buffer, transferlength, filename);
            }
            else
            {
                printf("       compare success\n");
            }
        }

        printf("write: %i, error = %u: \n", count+1, error);
        libopencbmtransfer_write_mem(fd, drive, compare_buffer, 0x8000, transferlength);
    }
#endif

    if (outputdump)
        DBG_MEMDUMP("8000:", buffer, transferlength + 0x10);

    if (writedumpfile)
        write_to_file(buffer, transferlength, "image.bin");

    DBG_PRINT((DBG_PREFIX "before remove"));
    libopencbmtransfer_remove(fd, drive);

    cbm_driver_close(fd);

    FUNC_LEAVE_INT(0);
}
Beispiel #14
0
int ARCH_MAINDECL main(int argc, char *argv[])
{
	CBM_FILE fd;
	__int32  Status, FuncRes, RetVal = 0;

	printf("\ntapcontrol v1.00 - Commodore 1530/1531 tape control\n");
	printf("Copyright 2012 Arnd Menge\n\n");

	if ((RetVal = EvaluateCommandlineParams(argc, argv)) == -1)
	{
		usage();
		goto exit;
	}

	if (cbm_driver_open_ex(&fd, NULL) != 0)
	{
		printf("\nDriver error.\n");
		RetVal = -1;
		goto exit;
	}

	// Check tape firmware version compatibility.
	//   Status value:
	//   - tape firmware version
	//   - XUM1541_Error_NoTapeSupport
	//   - XUM1541_Error_NoDiskTapeMode
	//   - XUM1541_Error_TapeCmdInDiskMode
	FuncRes = cbm_tap_get_ver(fd, &Status);
	if (FuncRes != 1)
	{
		printf("\nReturned error [get_ver]: %d\n", FuncRes);
		RetVal = -1;
		goto exit2;
	}
	if (Status < 0)
	{
		printf("\nReturned error [get_ver]: ");
		if (OutputError(Status) < 0)
			if (OutputFuncError(Status) < 0)
				printf("%d\n", Status);
		RetVal = -1;
		goto exit2;
	}
	if (Status != TapeFirmwareVersion)
	{
		printf("\nError [get_ver]: ");
		OutputError(Tape_Status_ERROR_Wrong_Tape_Firmware);
		RetVal = -1;
		goto exit2;
	}

	if (MotorOn == 1)
	{
		//   Status values:
		//   - Tape_Status_OK_Motor_On
		//   - Tape_Status_ERROR_Device_Disconnected
		//   - XUM1541_Error_NoTapeSupport
		//   - XUM1541_Error_NoDiskTapeMode
		//   - XUM1541_Error_TapeCmdInDiskMode
		FuncRes = cbm_tap_motor_on(fd, &Status);
		if (FuncRes != 1)
		{
			printf("\nReturned error [motor_on]: %d\n", FuncRes);
			RetVal = -1;
		}
		if (Status != Tape_Status_OK_Motor_On)
		{
			printf("\nReturned error [motor_on]: ");
			if (OutputError(Status) < 0)
				if (OutputFuncError(Status) < 0)
					printf("%d\n", Status);
			RetVal = -1;
		}
	}

	if (MotorOff == 1)
	{
		//   Status values:
		//   - Tape_Status_OK_Motor_Off
		//   - Tape_Status_ERROR_Device_Disconnected
		//   - XUM1541_Error_NoTapeSupport
		//   - XUM1541_Error_NoDiskTapeMode
		//   - XUM1541_Error_TapeCmdInDiskMode
		FuncRes = cbm_tap_motor_off(fd, &Status);
		if (FuncRes != 1)
		{
			printf("\nReturned error [motor_off]: %d\n", FuncRes);
			RetVal = -1;
		}
		if (Status != Tape_Status_OK_Motor_Off)
		{
			printf("\nReturned error [motor_off]: ");
			if (OutputError(Status) < 0)
				if (OutputFuncError(Status) < 0)
					printf("%d\n", Status);
			RetVal = -1;
		}
	}

    exit2:
	cbm_driver_close(fd);

    exit:
   	printf("\n");
   	return RetVal;
}