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