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

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

copy data from a disk drive's controller 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

code to copy a page of controller address space to buffer #2 (0x1300 in DOS CPU address space; 0x0700 in disk controller address space)

  • the code is written to buffer #1 (0x1200 in DOS CPU address space; 0x0600 in disk controller address space)

code for initiating the firmware dump

Definition at line 644 of file disk.c.

References read_remote(), and write_remote().

Referenced by drive_memory_save().

{
  /** code to copy a page of controller address space to buffer #2
   * (0x1300 in DOS CPU address space; 0x0700 in disk controller address space)
   * - the code is written to buffer #1
   * (0x1200 in DOS CPU address space; 0x0600 in disk controller address space)
   */
  static const unsigned char dumper[] = {
    'M', '-', 'W', 0x00, 0x12, 16, /* write the following to buffer #1 */
    0xa2, 0,            /* ldx #0 */
    0xbd, 0x00, 0x00,   /* lda $0000,x    ; source address */
    0x9d, 0x00, 0x07,   /* sta $0700,x    ; target address, 0x1300 in DOS CPU */
    0xca,         /* dex */
    0xd0, 0xf7,         /* bne .-7 */
    0xa9, 1,            /* lda #1 */
    0x6c, 0x02, 0xfc    /* jmp ($fc02)    ; terminate controller job */
  };

  /** code for initiating the firmware dump */
  static const unsigned char dumpstart[] = {
    'M', '-', 'W', 0x04, 0x10, 1, 0xd0 /* start job in buffer #1 */
  };

  static const unsigned char copydump[] = {
    'M', '-', 'R', 0x00, 0x13, 0 /* read 256 bytes from buffer #2 */
  };

  for (;;) {
    unsigned len;
    int status;
    memcpy (buf + 3, dumper, sizeof dumper);
    buf[3 + 6 + 3] = start, buf[3 + 6 + 4] = start >> 8;
    if ((status = write_remote (comm, 15, buf + 3, sizeof dumper))) {
    fail:
      fputs ("disk_cread: communication failure\n", stderr);
      return status;
    }
    memcpy (buf + 3, dumpstart, sizeof dumpstart);
    if ((status = write_remote (comm, 15, buf + 3, sizeof dumpstart)))
      goto fail;
    memcpy (buf + 3, copydump, sizeof copydump);
    if ((status = write_remote (comm, 15, buf + 3, sizeof copydump)))
      goto fail;
    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_cread: 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