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

int disk_mread ( const struct comm comm,
FILE *  file,
unsigned  start,
unsigned  end,
char *  buf 
)

copy data from a disk drive's address space to a file

Parameters:
comm the communication primitives
file output file
start start address (inclusive)
end end address (exclusive)
buf a buffer of at least 260 bytes
Returns:
zero on success, nonzero on error

Definition at line 595 of file disk.c.

References read_remote(), and write_remote().

Referenced by drive_memory_save().

{
  for (;;) {
    unsigned len;
    int status;
    {
      register char* b = buf + 3;
      *b++ = 'M', *b++ = '-', *b++ = 'R';
      *b++ = start, *b++ = start >> 8, *b++ = 0;
    }
    if ((status = write_remote (comm, 15, buf + 3, 6))) {
    fail:
      fputs ("disk_mread: communication failure\n", stderr);
      return status;
    }

    if ((status = read_remote (comm, 15, buf, &len)))
      goto fail;
    if (len >= ((end - start) & 0xffff)) {
      len = (end - start) & 0xffff;
      if (len != fwrite (buf, 1, len, file)) {
      failWrite:
      perror ("disk_mread: fwrite");
      return -1;
      }
      else {
      register char* b = buf + 3;
      *b++ = 'U', *b++ = 'I';
      return write_remote (comm, 15, buf + 3, 2);
      }
    }

    start += len;
    if (len != fwrite (buf, 1, len, file))
      goto failWrite;
  }
}


Generated by  Doxygen 1.6.0   Back to index