Logo Search packages:      
Sourcecode: cbmlink version File versions  Download package

static int drive_memory_load ( const char *  cmd,
const char *  filename 
) [static]

load a file to the memory of a disk drive connected to the remote host

Parameters:
cmd the -dml command
filename name of the file to be loaded, "-" for stdin
Returns:
zero on success, nonzero on error

converted start address

input file

Definition at line 428 of file cbmlink.c.

References buffer, device, disk_install(), disk_mwrite(), disk_remove(), and resolve_addr().

Referenced by main().

{
  /** converted start address */
  unsigned addr = 0;
  /** input file */
  FILE* f;

  switch (cmd[4]) {
  case 0:
    break;
  case 'r': /* load program to relocated address */
  case 'o': /* load binary to specified address */
    if (cmd[5] == ',' && cmd[6]) {
      char* e;
      addr = resolve_addr (cmd + 6, &e);
      if (!*e)
      break;
      fprintf (stderr, "%s %s: invalid address %s\n",
             cmd, filename, cmd + 6);
    }
  default:
    return -1;
  }

  f = *filename == '-' && !filename[1] ? stdin : fopen (filename, "rb");
  if (!f) {
    fputs (filename, stderr), perror (": fopen(reading)");
    return -2;
  }
  if (cmd[4] != 'o') {
    /* read the start address from the file */
    addr = (unsigned) fgetc (f);
    addr |= (unsigned) (unsigned char) fgetc (f) << 8;
  }
  if (feof (f) || ferror (f)) {
    fprintf (stderr, "%s %s: unexpected end of file\n", cmd, filename);
    if (f != stdin)
      fclose (f);
    return -2;
  }

  if (disk_install (comm, hostinfo, device)) {
    if (f != stdin) fclose (f);
    fputs ("disk: installation failed\n", stderr);
    return 2;
  }

  if (disk_mwrite (comm, f, addr, buffer)) {
    fputs ("disk: mwrite failed\n", stderr);
    if (f != stdin) fclose (f);
    if (disk_remove (comm)) {
    diskRemove:
      fputs ("disk: removal failed\n", stderr);
      return 2;
    }
    return 1;
  }

  if (f != stdin)
    fclose (f);

  if (disk_remove (comm))
    goto diskRemove;

  return 0;
}


Generated by  Doxygen 1.6.0   Back to index