floppy.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. typedef struct FController FController;
  2. typedef struct FDrive FDrive;
  3. typedef struct FType FType;
  4. static void floppyintr(Ureg*);
  5. static int floppyon(FDrive*);
  6. static void floppyoff(FDrive*);
  7. static void floppysetdef(FDrive*);
  8. /*
  9. * a floppy drive
  10. */
  11. struct FDrive
  12. {
  13. FType *t; /* floppy type */
  14. int dt; /* drive type */
  15. int dev;
  16. ulong lasttouched; /* time last touched */
  17. int cyl; /* current arm position */
  18. int confused; /* needs to be recalibrated */
  19. int vers;
  20. int maxtries; /* max read attempts before Eio */
  21. int tcyl; /* target cylinder */
  22. int thead; /* target head */
  23. int tsec; /* target sector */
  24. long len; /* size of xfer */
  25. uchar *cache; /* track cache */
  26. int ccyl;
  27. int chead;
  28. Rendez r; /* waiting here for motor to spin up */
  29. };
  30. /*
  31. * controller for 4 floppys
  32. */
  33. struct FController
  34. {
  35. QLock; /* exclusive access to the contoller */
  36. int ndrive;
  37. FDrive *d; /* the floppy drives */
  38. FDrive *selected;
  39. int rate; /* current rate selected */
  40. uchar cmd[14]; /* command */
  41. int ncmd; /* # command bytes */
  42. uchar stat[14]; /* command status */
  43. int nstat; /* # status bytes */
  44. int confused; /* controler needs to be reset */
  45. Rendez r; /* wait here for command termination */
  46. int motor; /* bit mask of spinning disks */
  47. Rendez kr; /* for motor watcher */
  48. };
  49. /*
  50. * floppy types (all MFM encoding)
  51. */
  52. struct FType
  53. {
  54. char *name;
  55. int dt; /* compatible drive type */
  56. int bytes; /* bytes/sector */
  57. int sectors; /* sectors/track */
  58. int heads; /* number of heads */
  59. int steps; /* steps per cylinder */
  60. int tracks; /* tracks/disk */
  61. int gpl; /* intersector gap length for read/write */
  62. int fgpl; /* intersector gap length for format */
  63. int rate; /* rate code */
  64. /*
  65. * these depend on previous entries and are set filled in
  66. * by floppyinit
  67. */
  68. int bcode; /* coded version of bytes for the controller */
  69. long cap; /* drive capacity in bytes */
  70. long tsize; /* track size in bytes */
  71. };
  72. /* bits in the registers */
  73. enum
  74. {
  75. /* status registers a & b */
  76. Psra= 0x3f0,
  77. Psrb= 0x3f1,
  78. /* digital output register */
  79. Pdor= 0x3f2,
  80. Fintena= 0x8, /* enable floppy interrupt */
  81. Fena= 0x4, /* 0 == reset controller */
  82. /* main status register */
  83. Pmsr= 0x3f4,
  84. Fready= 0x80, /* ready to be touched */
  85. Ffrom= 0x40, /* data from controller */
  86. Ffloppybusy= 0x10, /* operation not over */
  87. /* data register */
  88. Pfdata= 0x3f5,
  89. Frecal= 0x07, /* recalibrate cmd */
  90. Fseek= 0x0f, /* seek cmd */
  91. Fsense= 0x08, /* sense cmd */
  92. Fread= 0x66, /* read cmd */
  93. Freadid= 0x4a, /* read track id */
  94. Fspec= 0x03, /* set hold times */
  95. Fwrite= 0x45, /* write cmd */
  96. Fformat= 0x4d, /* format cmd */
  97. Fmulti= 0x80, /* or'd with Fread or Fwrite for multi-head */
  98. Fdumpreg= 0x0e, /* dump internal registers */
  99. /* digital input register */
  100. Pdir= 0x3F7, /* disk changed port (read only) */
  101. Pdsr= 0x3F7, /* data rate select port (write only) */
  102. Fchange= 0x80, /* disk has changed */
  103. /* status 0 byte */
  104. Drivemask= 3<<0,
  105. Seekend= 1<<5,
  106. Codemask= (3<<6)|(3<<3),
  107. Cmdexec= 1<<6,
  108. /* status 1 byte */
  109. Overrun= 0x10,
  110. };
  111. static void
  112. pcfloppyintr(Ureg *ur, void *a)
  113. {
  114. USED(a);
  115. floppyintr(ur);
  116. }
  117. void
  118. floppysetup0(FController *fl)
  119. {
  120. fl->ndrive = 0;
  121. if(ioalloc(Psra, 6, 0, "floppy") < 0)
  122. return;
  123. if(ioalloc(Pdir, 1, 0, "floppy") < 0){
  124. iofree(Psra);
  125. return;
  126. }
  127. fl->ndrive = 1;
  128. }
  129. void
  130. floppysetup1(FController *fl)
  131. {
  132. if(fl->ndrive > 0){
  133. fl->d[0].dt = 4;
  134. floppysetdef(&fl->d[0]);
  135. }
  136. if(fl->ndrive > 1){
  137. fl->d[1].dt = 4;
  138. floppysetdef(&fl->d[1]);
  139. }
  140. intrenable(IrqFLOPPY, pcfloppyintr, fl, BUSUNKNOWN, "floppy");
  141. }
  142. /*
  143. * eject disk
  144. */
  145. void
  146. floppyeject(FDrive *dp)
  147. {
  148. floppyon(dp);
  149. dp->vers++;
  150. floppyoff(dp);
  151. }
  152. int
  153. floppyexec(char *a, long b, int c)
  154. {
  155. USED(a, b, c);
  156. return b;
  157. }