devfloppy.h 4.0 KB

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