floppy.h 3.7 KB

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