home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / C-FDC / RWTRACK.C < prev    next >
Text File  |  1986-08-01  |  1KB  |  61 lines

  1. /*
  2.  *    DOS INT read/write track routine
  3.  *
  4.  *     Reads/writes a floppy disk track
  5.  *
  6.  *     Accepts:    drive: 0 = A:, 1 = B:
  7.  *            head: 0 / 1
  8.  *            start_sect: starting sector 
  9.  *            max_sect: maximum # of sectors to read/write
  10.  *            buf: pointer to buffer holding information
  11.  *            start_sect and max_sect can be 1 - 8, 1 - 9, 1 - 15
  12.  *                
  13.  *    Returns 0 if successful, -1 on error with errno set to DOS return 
  14.  *    code.
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <dos.h>
  20. #include "fdc.h"
  21.  
  22. int rdtrack(int drive, int head, int track, int start_sect, int max_sect, 
  23.     char *buf)
  24. {
  25.  
  26.     struct REGVAL r;
  27.     extern int errno;
  28.  
  29.     r.ax = READSECS | max_sect;
  30.     r.cx = (track << 8) | start_sect;
  31.     r.dx = (head << 8) | drive;
  32.     r.es = getds();
  33.     r.bx = (unsigned int)buf;
  34.     if (sysint(DISKINT, &r, &r) & 1) {
  35.         errno = (int)(r.ax >> 8);
  36.         return(-1);
  37.     } else
  38.         return(0);
  39. }
  40.  
  41. int wrtrack(int drive, int head, int track, int start_sect, int max_sect, 
  42.     char *buf)
  43. {
  44.  
  45.     struct REGVAL r;
  46.     extern int errno;
  47.  
  48.     r.ax = WRITESECS | max_sect;
  49.     r.cx = (track << 8) | start_sect;
  50.     r.dx = (head << 8) | drive;
  51.     r.es = getds();
  52.     r.bx = (unsigned int)buf;
  53.     if (sysint(DISKINT, &r, &r) & 1) {
  54.         errno = (int)(r.ax >> 8);
  55.         return(-1);
  56.     } else
  57.         return(0);
  58. }
  59.  
  60.  
  61.