root / hw / fdc.c @ 6f1f31c0
History | View | Annotate | Download (53.8 kB)
1 | 8977f3c1 | bellard | /*
|
---|---|---|---|
2 | 8977f3c1 | bellard | * QEMU Floppy disk emulator
|
3 | 8977f3c1 | bellard | *
|
4 | 8977f3c1 | bellard | * Copyright (c) 2003 Jocelyn Mayer
|
5 | 8977f3c1 | bellard | *
|
6 | 8977f3c1 | bellard | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 8977f3c1 | bellard | * of this software and associated documentation files (the "Software"), to deal
|
8 | 8977f3c1 | bellard | * in the Software without restriction, including without limitation the rights
|
9 | 8977f3c1 | bellard | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 | 8977f3c1 | bellard | * copies of the Software, and to permit persons to whom the Software is
|
11 | 8977f3c1 | bellard | * furnished to do so, subject to the following conditions:
|
12 | 8977f3c1 | bellard | *
|
13 | 8977f3c1 | bellard | * The above copyright notice and this permission notice shall be included in
|
14 | 8977f3c1 | bellard | * all copies or substantial portions of the Software.
|
15 | 8977f3c1 | bellard | *
|
16 | 8977f3c1 | bellard | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 | 8977f3c1 | bellard | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 | 8977f3c1 | bellard | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 | 8977f3c1 | bellard | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 | 8977f3c1 | bellard | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 | 8977f3c1 | bellard | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 | 8977f3c1 | bellard | * THE SOFTWARE.
|
23 | 8977f3c1 | bellard | */
|
24 | 8977f3c1 | bellard | #include "vl.h" |
25 | 8977f3c1 | bellard | |
26 | 8977f3c1 | bellard | /********************************************************/
|
27 | 8977f3c1 | bellard | /* debug Floppy devices */
|
28 | 8977f3c1 | bellard | //#define DEBUG_FLOPPY
|
29 | 8977f3c1 | bellard | |
30 | 8977f3c1 | bellard | #ifdef DEBUG_FLOPPY
|
31 | 8977f3c1 | bellard | #define FLOPPY_DPRINTF(fmt, args...) \
|
32 | 8977f3c1 | bellard | do { printf("FLOPPY: " fmt , ##args); } while (0) |
33 | 8977f3c1 | bellard | #else
|
34 | 8977f3c1 | bellard | #define FLOPPY_DPRINTF(fmt, args...)
|
35 | 8977f3c1 | bellard | #endif
|
36 | 8977f3c1 | bellard | |
37 | 8977f3c1 | bellard | #define FLOPPY_ERROR(fmt, args...) \
|
38 | 8977f3c1 | bellard | do { printf("FLOPPY ERROR: %s: " fmt, __func__ , ##args); } while (0) |
39 | 8977f3c1 | bellard | |
40 | 8977f3c1 | bellard | /********************************************************/
|
41 | 8977f3c1 | bellard | /* Floppy drive emulation */
|
42 | 8977f3c1 | bellard | |
43 | 8977f3c1 | bellard | /* Will always be a fixed parameter for us */
|
44 | 8977f3c1 | bellard | #define FD_SECTOR_LEN 512 |
45 | 8977f3c1 | bellard | #define FD_SECTOR_SC 2 /* Sector size code */ |
46 | 8977f3c1 | bellard | |
47 | 8977f3c1 | bellard | /* Floppy disk drive emulation */
|
48 | 8977f3c1 | bellard | typedef enum fdisk_type_t { |
49 | 8977f3c1 | bellard | FDRIVE_DISK_288 = 0x01, /* 2.88 MB disk */ |
50 | 8977f3c1 | bellard | FDRIVE_DISK_144 = 0x02, /* 1.44 MB disk */ |
51 | 8977f3c1 | bellard | FDRIVE_DISK_720 = 0x03, /* 720 kB disk */ |
52 | baca51fa | bellard | FDRIVE_DISK_USER = 0x04, /* User defined geometry */ |
53 | baca51fa | bellard | FDRIVE_DISK_NONE = 0x05, /* No disk */ |
54 | 8977f3c1 | bellard | } fdisk_type_t; |
55 | 8977f3c1 | bellard | |
56 | 8977f3c1 | bellard | typedef enum fdrive_type_t { |
57 | 8977f3c1 | bellard | FDRIVE_DRV_144 = 0x00, /* 1.44 MB 3"5 drive */ |
58 | 8977f3c1 | bellard | FDRIVE_DRV_288 = 0x01, /* 2.88 MB 3"5 drive */ |
59 | 8977f3c1 | bellard | FDRIVE_DRV_120 = 0x02, /* 1.2 MB 5"25 drive */ |
60 | 8977f3c1 | bellard | FDRIVE_DRV_NONE = 0x03, /* No drive connected */ |
61 | 8977f3c1 | bellard | } fdrive_type_t; |
62 | 8977f3c1 | bellard | |
63 | baca51fa | bellard | typedef enum fdrive_flags_t { |
64 | baca51fa | bellard | FDRIVE_MOTOR_ON = 0x01, /* motor on/off */ |
65 | baca51fa | bellard | FDRIVE_REVALIDATE = 0x02, /* Revalidated */ |
66 | baca51fa | bellard | } fdrive_flags_t; |
67 | baca51fa | bellard | |
68 | baca51fa | bellard | typedef enum fdisk_flags_t { |
69 | baca51fa | bellard | FDISK_DBL_SIDES = 0x01,
|
70 | baca51fa | bellard | } fdisk_flags_t; |
71 | baca51fa | bellard | |
72 | 8977f3c1 | bellard | typedef struct fdrive_t { |
73 | 8977f3c1 | bellard | BlockDriverState *bs; |
74 | 8977f3c1 | bellard | /* Drive status */
|
75 | 8977f3c1 | bellard | fdrive_type_t drive; |
76 | baca51fa | bellard | fdrive_flags_t drflags; |
77 | 8977f3c1 | bellard | uint8_t perpendicular; /* 2.88 MB access mode */
|
78 | 8977f3c1 | bellard | /* Position */
|
79 | 8977f3c1 | bellard | uint8_t head; |
80 | 8977f3c1 | bellard | uint8_t track; |
81 | 8977f3c1 | bellard | uint8_t sect; |
82 | 8977f3c1 | bellard | /* Last operation status */
|
83 | 8977f3c1 | bellard | uint8_t dir; /* Direction */
|
84 | 8977f3c1 | bellard | uint8_t rw; /* Read/write */
|
85 | 8977f3c1 | bellard | /* Media */
|
86 | baca51fa | bellard | fdisk_flags_t flags; |
87 | 8977f3c1 | bellard | uint8_t last_sect; /* Nb sector per track */
|
88 | 8977f3c1 | bellard | uint8_t max_track; /* Nb of tracks */
|
89 | baca51fa | bellard | uint16_t bps; /* Bytes per sector */
|
90 | 8977f3c1 | bellard | uint8_t ro; /* Is read-only */
|
91 | 8977f3c1 | bellard | } fdrive_t; |
92 | 8977f3c1 | bellard | |
93 | caed8802 | bellard | static void fd_init (fdrive_t *drv, BlockDriverState *bs) |
94 | 8977f3c1 | bellard | { |
95 | 8977f3c1 | bellard | /* Drive */
|
96 | caed8802 | bellard | drv->bs = bs; |
97 | caed8802 | bellard | if (bs)
|
98 | caed8802 | bellard | drv->drive = FDRIVE_DRV_144; |
99 | caed8802 | bellard | else
|
100 | caed8802 | bellard | drv->drive = FDRIVE_DRV_NONE; |
101 | baca51fa | bellard | drv->drflags = 0;
|
102 | 8977f3c1 | bellard | drv->perpendicular = 0;
|
103 | 8977f3c1 | bellard | /* Disk */
|
104 | baca51fa | bellard | drv->last_sect = 0;
|
105 | 8977f3c1 | bellard | drv->max_track = 0;
|
106 | 8977f3c1 | bellard | } |
107 | 8977f3c1 | bellard | |
108 | 8977f3c1 | bellard | static int _fd_sector (uint8_t head, uint8_t track, |
109 | 8977f3c1 | bellard | uint8_t sect, uint8_t last_sect) |
110 | 8977f3c1 | bellard | { |
111 | 8977f3c1 | bellard | return (((track * 2) + head) * last_sect) + sect - 1; |
112 | 8977f3c1 | bellard | } |
113 | 8977f3c1 | bellard | |
114 | 8977f3c1 | bellard | /* Returns current position, in sectors, for given drive */
|
115 | 8977f3c1 | bellard | static int fd_sector (fdrive_t *drv) |
116 | 8977f3c1 | bellard | { |
117 | 8977f3c1 | bellard | return _fd_sector(drv->head, drv->track, drv->sect, drv->last_sect);
|
118 | 8977f3c1 | bellard | } |
119 | 8977f3c1 | bellard | |
120 | 8977f3c1 | bellard | static int fd_seek (fdrive_t *drv, uint8_t head, uint8_t track, uint8_t sect, |
121 | 8977f3c1 | bellard | int enable_seek)
|
122 | 8977f3c1 | bellard | { |
123 | 8977f3c1 | bellard | uint32_t sector; |
124 | baca51fa | bellard | int ret;
|
125 | baca51fa | bellard | |
126 | baca51fa | bellard | if (track > drv->max_track ||
|
127 | baca51fa | bellard | (head != 0 && (drv->flags & FDISK_DBL_SIDES) == 0)) { |
128 | baca51fa | bellard | FLOPPY_ERROR("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
129 | baca51fa | bellard | head, track, sect, 1,
|
130 | baca51fa | bellard | (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1, |
131 | baca51fa | bellard | drv->max_track, drv->last_sect); |
132 | 8977f3c1 | bellard | return 2; |
133 | 8977f3c1 | bellard | } |
134 | 8977f3c1 | bellard | if (sect > drv->last_sect) {
|
135 | baca51fa | bellard | FLOPPY_ERROR("try to read %d %02x %02x (max=%d %d %02x %02x)\n",
|
136 | baca51fa | bellard | head, track, sect, 1,
|
137 | baca51fa | bellard | (drv->flags & FDISK_DBL_SIDES) == 0 ? 0 : 1, |
138 | baca51fa | bellard | drv->max_track, drv->last_sect); |
139 | 8977f3c1 | bellard | return 3; |
140 | 8977f3c1 | bellard | } |
141 | 8977f3c1 | bellard | sector = _fd_sector(head, track, sect, drv->last_sect); |
142 | baca51fa | bellard | ret = 0;
|
143 | 8977f3c1 | bellard | if (sector != fd_sector(drv)) {
|
144 | 8977f3c1 | bellard | #if 0
|
145 | 8977f3c1 | bellard | if (!enable_seek) {
|
146 | 8977f3c1 | bellard | FLOPPY_ERROR("no implicit seek %d %02x %02x (max=%d %02x %02x)\n",
|
147 | 8977f3c1 | bellard | head, track, sect, 1, drv->max_track, drv->last_sect);
|
148 | 8977f3c1 | bellard | return 4;
|
149 | 8977f3c1 | bellard | }
|
150 | 8977f3c1 | bellard | #endif
|
151 | 8977f3c1 | bellard | drv->head = head; |
152 | baca51fa | bellard | if (drv->track != track)
|
153 | baca51fa | bellard | ret = 1;
|
154 | 8977f3c1 | bellard | drv->track = track; |
155 | 8977f3c1 | bellard | drv->sect = sect; |
156 | 8977f3c1 | bellard | } |
157 | 8977f3c1 | bellard | |
158 | baca51fa | bellard | return ret;
|
159 | 8977f3c1 | bellard | } |
160 | 8977f3c1 | bellard | |
161 | 8977f3c1 | bellard | /* Set drive back to track 0 */
|
162 | 8977f3c1 | bellard | static void fd_recalibrate (fdrive_t *drv) |
163 | 8977f3c1 | bellard | { |
164 | 8977f3c1 | bellard | FLOPPY_DPRINTF("recalibrate\n");
|
165 | 8977f3c1 | bellard | drv->head = 0;
|
166 | 8977f3c1 | bellard | drv->track = 0;
|
167 | 8977f3c1 | bellard | drv->sect = 1;
|
168 | 8977f3c1 | bellard | drv->dir = 1;
|
169 | 8977f3c1 | bellard | drv->rw = 0;
|
170 | 8977f3c1 | bellard | } |
171 | 8977f3c1 | bellard | |
172 | a541f297 | bellard | /* Recognize floppy formats */
|
173 | a541f297 | bellard | typedef struct fd_format_t { |
174 | a541f297 | bellard | fdrive_type_t drive; |
175 | a541f297 | bellard | fdisk_type_t disk; |
176 | a541f297 | bellard | uint8_t last_sect; |
177 | a541f297 | bellard | uint8_t max_track; |
178 | a541f297 | bellard | uint8_t max_head; |
179 | a541f297 | bellard | const unsigned char *str; |
180 | a541f297 | bellard | } fd_format_t; |
181 | a541f297 | bellard | |
182 | a541f297 | bellard | static fd_format_t fd_formats[] = {
|
183 | a541f297 | bellard | /* First entry is default format */
|
184 | a541f297 | bellard | /* 1.44 MB 3"1/2 floppy disks */
|
185 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 18, 80, 1, "1.44 MB 3\"1/2", }, |
186 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 20, 80, 1, "1.6 MB 3\"1/2", }, |
187 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 80, 1, "1.68 MB 3\"1/2", }, |
188 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 82, 1, "1.72 MB 3\"1/2", }, |
189 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 21, 83, 1, "1.74 MB 3\"1/2", }, |
190 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 22, 80, 1, "1.76 MB 3\"1/2", }, |
191 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 23, 80, 1, "1.84 MB 3\"1/2", }, |
192 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_144, 24, 80, 1, "1.92 MB 3\"1/2", }, |
193 | a541f297 | bellard | /* 2.88 MB 3"1/2 floppy disks */
|
194 | a541f297 | bellard | { FDRIVE_DRV_288, FDRIVE_DISK_288, 36, 80, 1, "2.88 MB 3\"1/2", }, |
195 | a541f297 | bellard | { FDRIVE_DRV_288, FDRIVE_DISK_288, 39, 80, 1, "3.12 MB 3\"1/2", }, |
196 | a541f297 | bellard | { FDRIVE_DRV_288, FDRIVE_DISK_288, 40, 80, 1, "3.2 MB 3\"1/2", }, |
197 | a541f297 | bellard | { FDRIVE_DRV_288, FDRIVE_DISK_288, 44, 80, 1, "3.52 MB 3\"1/2", }, |
198 | a541f297 | bellard | { FDRIVE_DRV_288, FDRIVE_DISK_288, 48, 80, 1, "3.84 MB 3\"1/2", }, |
199 | a541f297 | bellard | /* 720 kB 3"1/2 floppy disks */
|
200 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 9, 80, 1, "720 kB 3\"1/2", }, |
201 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 80, 1, "800 kB 3\"1/2", }, |
202 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 82, 1, "820 kB 3\"1/2", }, |
203 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 10, 83, 1, "830 kB 3\"1/2", }, |
204 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 13, 80, 1, "1.04 MB 3\"1/2", }, |
205 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 14, 80, 1, "1.12 MB 3\"1/2", }, |
206 | a541f297 | bellard | /* 1.2 MB 5"1/4 floppy disks */
|
207 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 15, 80, 1, "1.2 kB 5\"1/4", }, |
208 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 80, 1, "1.44 MB 5\"1/4", }, |
209 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 82, 1, "1.48 MB 5\"1/4", }, |
210 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 18, 83, 1, "1.49 MB 5\"1/4", }, |
211 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 20, 80, 1, "1.6 MB 5\"1/4", }, |
212 | a541f297 | bellard | /* 720 kB 5"1/4 floppy disks */
|
213 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 80, 1, "720 kB 5\"1/4", }, |
214 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 11, 80, 1, "880 kB 5\"1/4", }, |
215 | a541f297 | bellard | /* 360 kB 5"1/4 floppy disks */
|
216 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 40, 1, "360 kB 5\"1/4", }, |
217 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 9, 40, 0, "180 kB 5\"1/4", }, |
218 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 41, 1, "410 kB 5\"1/4", }, |
219 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 10, 42, 1, "420 kB 5\"1/4", }, |
220 | a541f297 | bellard | /* 320 kB 5"1/4 floppy disks */
|
221 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 1, "320 kB 5\"1/4", }, |
222 | a541f297 | bellard | { FDRIVE_DRV_120, FDRIVE_DISK_288, 8, 40, 0, "160 kB 5\"1/4", }, |
223 | a541f297 | bellard | /* 360 kB must match 5"1/4 better than 3"1/2... */
|
224 | a541f297 | bellard | { FDRIVE_DRV_144, FDRIVE_DISK_720, 9, 80, 0, "360 kB 3\"1/2", }, |
225 | a541f297 | bellard | /* end */
|
226 | a541f297 | bellard | { FDRIVE_DRV_NONE, FDRIVE_DISK_NONE, -1, -1, 0, NULL, }, |
227 | a541f297 | bellard | }; |
228 | a541f297 | bellard | |
229 | 8977f3c1 | bellard | /* Revalidate a disk drive after a disk change */
|
230 | caed8802 | bellard | static void fd_revalidate (fdrive_t *drv) |
231 | 8977f3c1 | bellard | { |
232 | a541f297 | bellard | fd_format_t *parse; |
233 | a541f297 | bellard | int64_t nb_sectors, size; |
234 | a541f297 | bellard | int i, first_match, match;
|
235 | baca51fa | bellard | int nb_heads, max_track, last_sect, ro;
|
236 | 8977f3c1 | bellard | |
237 | 8977f3c1 | bellard | FLOPPY_DPRINTF("revalidate\n");
|
238 | baca51fa | bellard | drv->drflags &= ~FDRIVE_REVALIDATE; |
239 | a541f297 | bellard | if (drv->bs != NULL && bdrv_is_inserted(drv->bs)) { |
240 | baca51fa | bellard | ro = bdrv_is_read_only(drv->bs); |
241 | a541f297 | bellard | bdrv_get_geometry_hint(drv->bs, &nb_heads, &max_track, &last_sect); |
242 | baca51fa | bellard | if (nb_heads != 0 && max_track != 0 && last_sect != 0) { |
243 | baca51fa | bellard | printf("User defined disk (%d %d %d)",
|
244 | baca51fa | bellard | nb_heads - 1, max_track, last_sect);
|
245 | a541f297 | bellard | } else {
|
246 | a541f297 | bellard | bdrv_get_geometry(drv->bs, &nb_sectors); |
247 | a541f297 | bellard | match = -1;
|
248 | a541f297 | bellard | first_match = -1;
|
249 | a541f297 | bellard | for (i = 0;; i++) { |
250 | a541f297 | bellard | parse = &fd_formats[i]; |
251 | a541f297 | bellard | if (parse->drive == FDRIVE_DRV_NONE)
|
252 | a541f297 | bellard | break;
|
253 | a541f297 | bellard | if (drv->drive == parse->drive ||
|
254 | a541f297 | bellard | drv->drive == FDRIVE_DRV_NONE) { |
255 | a541f297 | bellard | size = (parse->max_head + 1) * parse->max_track *
|
256 | a541f297 | bellard | parse->last_sect; |
257 | a541f297 | bellard | if (nb_sectors == size) {
|
258 | a541f297 | bellard | match = i; |
259 | a541f297 | bellard | break;
|
260 | a541f297 | bellard | } |
261 | a541f297 | bellard | if (first_match == -1) |
262 | a541f297 | bellard | first_match = i; |
263 | a541f297 | bellard | } |
264 | a541f297 | bellard | } |
265 | a541f297 | bellard | if (match == -1) { |
266 | a541f297 | bellard | if (first_match == -1) |
267 | a541f297 | bellard | match = 1;
|
268 | a541f297 | bellard | else
|
269 | a541f297 | bellard | match = first_match; |
270 | a541f297 | bellard | parse = &fd_formats[match]; |
271 | a541f297 | bellard | } |
272 | a541f297 | bellard | nb_heads = parse->max_head + 1;
|
273 | a541f297 | bellard | max_track = parse->max_track; |
274 | a541f297 | bellard | last_sect = parse->last_sect; |
275 | a541f297 | bellard | drv->drive = parse->drive; |
276 | a541f297 | bellard | printf("%s floppy disk (%d h %d t %d s) %s\n", parse->str,
|
277 | a541f297 | bellard | nb_heads, max_track, last_sect, ro ? "ro" : "rw"); |
278 | a541f297 | bellard | } |
279 | baca51fa | bellard | if (nb_heads == 1) { |
280 | baca51fa | bellard | drv->flags &= ~FDISK_DBL_SIDES; |
281 | baca51fa | bellard | } else {
|
282 | baca51fa | bellard | drv->flags |= FDISK_DBL_SIDES; |
283 | baca51fa | bellard | } |
284 | baca51fa | bellard | drv->max_track = max_track; |
285 | baca51fa | bellard | drv->last_sect = last_sect; |
286 | baca51fa | bellard | drv->ro = ro; |
287 | 8977f3c1 | bellard | } else {
|
288 | baca51fa | bellard | printf("No disk in drive\n");
|
289 | baca51fa | bellard | drv->last_sect = 0;
|
290 | baca51fa | bellard | drv->max_track = 0;
|
291 | baca51fa | bellard | drv->flags &= ~FDISK_DBL_SIDES; |
292 | 8977f3c1 | bellard | } |
293 | baca51fa | bellard | drv->drflags |= FDRIVE_REVALIDATE; |
294 | caed8802 | bellard | } |
295 | caed8802 | bellard | |
296 | 8977f3c1 | bellard | /* Motor control */
|
297 | 8977f3c1 | bellard | static void fd_start (fdrive_t *drv) |
298 | 8977f3c1 | bellard | { |
299 | baca51fa | bellard | drv->drflags |= FDRIVE_MOTOR_ON; |
300 | 8977f3c1 | bellard | } |
301 | 8977f3c1 | bellard | |
302 | 8977f3c1 | bellard | static void fd_stop (fdrive_t *drv) |
303 | 8977f3c1 | bellard | { |
304 | baca51fa | bellard | drv->drflags &= ~FDRIVE_MOTOR_ON; |
305 | 8977f3c1 | bellard | } |
306 | 8977f3c1 | bellard | |
307 | 8977f3c1 | bellard | /* Re-initialise a drives (motor off, repositioned) */
|
308 | 8977f3c1 | bellard | static void fd_reset (fdrive_t *drv) |
309 | 8977f3c1 | bellard | { |
310 | 8977f3c1 | bellard | fd_stop(drv); |
311 | 8977f3c1 | bellard | fd_recalibrate(drv); |
312 | 8977f3c1 | bellard | } |
313 | 8977f3c1 | bellard | |
314 | 8977f3c1 | bellard | /********************************************************/
|
315 | 8977f3c1 | bellard | /* Intel 82078 floppy disk controler emulation */
|
316 | 8977f3c1 | bellard | |
317 | baca51fa | bellard | static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq); |
318 | baca51fa | bellard | static void fdctrl_reset_fifo (fdctrl_t *fdctrl); |
319 | f9e92e97 | bellard | static int fdctrl_transfer_handler (void *opaque, target_ulong addr, int size); |
320 | baca51fa | bellard | static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status); |
321 | baca51fa | bellard | |
322 | baca51fa | bellard | static uint32_t fdctrl_read_statusB (fdctrl_t *fdctrl);
|
323 | baca51fa | bellard | static uint32_t fdctrl_read_dor (fdctrl_t *fdctrl);
|
324 | baca51fa | bellard | static void fdctrl_write_dor (fdctrl_t *fdctrl, uint32_t value); |
325 | baca51fa | bellard | static uint32_t fdctrl_read_tape (fdctrl_t *fdctrl);
|
326 | baca51fa | bellard | static void fdctrl_write_tape (fdctrl_t *fdctrl, uint32_t value); |
327 | baca51fa | bellard | static uint32_t fdctrl_read_main_status (fdctrl_t *fdctrl);
|
328 | baca51fa | bellard | static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value); |
329 | baca51fa | bellard | static uint32_t fdctrl_read_data (fdctrl_t *fdctrl);
|
330 | baca51fa | bellard | static void fdctrl_write_data (fdctrl_t *fdctrl, uint32_t value); |
331 | baca51fa | bellard | static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl);
|
332 | 8977f3c1 | bellard | |
333 | 8977f3c1 | bellard | enum {
|
334 | 8977f3c1 | bellard | FD_CTRL_ACTIVE = 0x01,
|
335 | 8977f3c1 | bellard | FD_CTRL_RESET = 0x02,
|
336 | 8977f3c1 | bellard | FD_CTRL_SLEEP = 0x04,
|
337 | 8977f3c1 | bellard | FD_CTRL_BUSY = 0x08,
|
338 | 8977f3c1 | bellard | FD_CTRL_INTR = 0x10,
|
339 | 8977f3c1 | bellard | }; |
340 | 8977f3c1 | bellard | |
341 | 8977f3c1 | bellard | enum {
|
342 | 8977f3c1 | bellard | FD_DIR_WRITE = 0,
|
343 | 8977f3c1 | bellard | FD_DIR_READ = 1,
|
344 | 8977f3c1 | bellard | FD_DIR_SCANE = 2,
|
345 | 8977f3c1 | bellard | FD_DIR_SCANL = 3,
|
346 | 8977f3c1 | bellard | FD_DIR_SCANH = 4,
|
347 | 8977f3c1 | bellard | }; |
348 | 8977f3c1 | bellard | |
349 | 8977f3c1 | bellard | enum {
|
350 | 8977f3c1 | bellard | FD_STATE_CMD = 0x00,
|
351 | 8977f3c1 | bellard | FD_STATE_STATUS = 0x01,
|
352 | 8977f3c1 | bellard | FD_STATE_DATA = 0x02,
|
353 | 8977f3c1 | bellard | FD_STATE_STATE = 0x03,
|
354 | 8977f3c1 | bellard | FD_STATE_MULTI = 0x10,
|
355 | 8977f3c1 | bellard | FD_STATE_SEEK = 0x20,
|
356 | baca51fa | bellard | FD_STATE_FORMAT = 0x40,
|
357 | 8977f3c1 | bellard | }; |
358 | 8977f3c1 | bellard | |
359 | 8977f3c1 | bellard | #define FD_STATE(state) ((state) & FD_STATE_STATE)
|
360 | baca51fa | bellard | #define FD_SET_STATE(state, new_state) \
|
361 | baca51fa | bellard | do { (state) = ((state) & ~FD_STATE_STATE) | (new_state); } while (0) |
362 | 8977f3c1 | bellard | #define FD_MULTI_TRACK(state) ((state) & FD_STATE_MULTI)
|
363 | 8977f3c1 | bellard | #define FD_DID_SEEK(state) ((state) & FD_STATE_SEEK)
|
364 | baca51fa | bellard | #define FD_FORMAT_CMD(state) ((state) & FD_STATE_FORMAT)
|
365 | 8977f3c1 | bellard | |
366 | baca51fa | bellard | struct fdctrl_t {
|
367 | baca51fa | bellard | fdctrl_t *fdctrl; |
368 | 8977f3c1 | bellard | /* Controler's identification */
|
369 | 8977f3c1 | bellard | uint8_t version; |
370 | 8977f3c1 | bellard | /* HW */
|
371 | 8977f3c1 | bellard | int irq_lvl;
|
372 | 8977f3c1 | bellard | int dma_chann;
|
373 | baca51fa | bellard | uint32_t io_base; |
374 | 8977f3c1 | bellard | /* Controler state */
|
375 | 8977f3c1 | bellard | uint8_t state; |
376 | 8977f3c1 | bellard | uint8_t dma_en; |
377 | 8977f3c1 | bellard | uint8_t cur_drv; |
378 | 8977f3c1 | bellard | uint8_t bootsel; |
379 | 8977f3c1 | bellard | /* Command FIFO */
|
380 | 8977f3c1 | bellard | uint8_t fifo[FD_SECTOR_LEN]; |
381 | 8977f3c1 | bellard | uint32_t data_pos; |
382 | 8977f3c1 | bellard | uint32_t data_len; |
383 | 8977f3c1 | bellard | uint8_t data_state; |
384 | 8977f3c1 | bellard | uint8_t data_dir; |
385 | 8977f3c1 | bellard | uint8_t int_status; |
386 | 8977f3c1 | bellard | /* States kept only to be returned back */
|
387 | 8977f3c1 | bellard | /* Timers state */
|
388 | 8977f3c1 | bellard | uint8_t timer0; |
389 | 8977f3c1 | bellard | uint8_t timer1; |
390 | 8977f3c1 | bellard | /* precompensation */
|
391 | 8977f3c1 | bellard | uint8_t precomp_trk; |
392 | 8977f3c1 | bellard | uint8_t config; |
393 | 8977f3c1 | bellard | uint8_t lock; |
394 | 8977f3c1 | bellard | /* Power down config (also with status regB access mode */
|
395 | 8977f3c1 | bellard | uint8_t pwrd; |
396 | 8977f3c1 | bellard | /* Floppy drives */
|
397 | 8977f3c1 | bellard | fdrive_t drives[2];
|
398 | baca51fa | bellard | }; |
399 | baca51fa | bellard | |
400 | baca51fa | bellard | static uint32_t fdctrl_read (void *opaque, uint32_t reg) |
401 | baca51fa | bellard | { |
402 | baca51fa | bellard | fdctrl_t *fdctrl = opaque; |
403 | baca51fa | bellard | uint32_t retval; |
404 | baca51fa | bellard | |
405 | a541f297 | bellard | switch (reg & 0x07) { |
406 | a541f297 | bellard | case 0x01: |
407 | baca51fa | bellard | retval = fdctrl_read_statusB(fdctrl); |
408 | a541f297 | bellard | break;
|
409 | a541f297 | bellard | case 0x02: |
410 | baca51fa | bellard | retval = fdctrl_read_dor(fdctrl); |
411 | a541f297 | bellard | break;
|
412 | a541f297 | bellard | case 0x03: |
413 | baca51fa | bellard | retval = fdctrl_read_tape(fdctrl); |
414 | a541f297 | bellard | break;
|
415 | a541f297 | bellard | case 0x04: |
416 | baca51fa | bellard | retval = fdctrl_read_main_status(fdctrl); |
417 | a541f297 | bellard | break;
|
418 | a541f297 | bellard | case 0x05: |
419 | baca51fa | bellard | retval = fdctrl_read_data(fdctrl); |
420 | a541f297 | bellard | break;
|
421 | a541f297 | bellard | case 0x07: |
422 | baca51fa | bellard | retval = fdctrl_read_dir(fdctrl); |
423 | a541f297 | bellard | break;
|
424 | a541f297 | bellard | default:
|
425 | baca51fa | bellard | retval = (uint32_t)(-1);
|
426 | a541f297 | bellard | break;
|
427 | a541f297 | bellard | } |
428 | baca51fa | bellard | |
429 | baca51fa | bellard | return retval;
|
430 | baca51fa | bellard | } |
431 | baca51fa | bellard | |
432 | baca51fa | bellard | static void fdctrl_write (void *opaque, uint32_t reg, uint32_t value) |
433 | baca51fa | bellard | { |
434 | baca51fa | bellard | fdctrl_t *fdctrl = opaque; |
435 | baca51fa | bellard | |
436 | a541f297 | bellard | switch (reg & 0x07) { |
437 | a541f297 | bellard | case 0x02: |
438 | baca51fa | bellard | fdctrl_write_dor(fdctrl, value); |
439 | a541f297 | bellard | break;
|
440 | a541f297 | bellard | case 0x03: |
441 | baca51fa | bellard | fdctrl_write_tape(fdctrl, value); |
442 | a541f297 | bellard | break;
|
443 | a541f297 | bellard | case 0x04: |
444 | baca51fa | bellard | fdctrl_write_rate(fdctrl, value); |
445 | a541f297 | bellard | break;
|
446 | a541f297 | bellard | case 0x05: |
447 | baca51fa | bellard | fdctrl_write_data(fdctrl, value); |
448 | a541f297 | bellard | break;
|
449 | a541f297 | bellard | default:
|
450 | a541f297 | bellard | break;
|
451 | a541f297 | bellard | } |
452 | baca51fa | bellard | } |
453 | baca51fa | bellard | |
454 | baca51fa | bellard | static void fd_change_cb (void *opaque) |
455 | baca51fa | bellard | { |
456 | baca51fa | bellard | fdrive_t *drv = opaque; |
457 | 8977f3c1 | bellard | |
458 | baca51fa | bellard | FLOPPY_DPRINTF("disk change\n");
|
459 | baca51fa | bellard | fd_revalidate(drv); |
460 | baca51fa | bellard | #if 0
|
461 | baca51fa | bellard | fd_recalibrate(drv);
|
462 | baca51fa | bellard | fdctrl_reset_fifo(drv->fdctrl);
|
463 | baca51fa | bellard | fdctrl_raise_irq(drv->fdctrl, 0x20);
|
464 | baca51fa | bellard | #endif
|
465 | baca51fa | bellard | } |
466 | 8977f3c1 | bellard | |
467 | baca51fa | bellard | fdctrl_t *fdctrl_init (int irq_lvl, int dma_chann, int mem_mapped, |
468 | baca51fa | bellard | uint32_t io_base, |
469 | baca51fa | bellard | BlockDriverState **fds) |
470 | 8977f3c1 | bellard | { |
471 | baca51fa | bellard | fdctrl_t *fdctrl; |
472 | 8977f3c1 | bellard | // int io_mem;
|
473 | 8977f3c1 | bellard | int i;
|
474 | 8977f3c1 | bellard | |
475 | 8977f3c1 | bellard | FLOPPY_DPRINTF("init controler\n");
|
476 | baca51fa | bellard | fdctrl = qemu_mallocz(sizeof(fdctrl_t));
|
477 | baca51fa | bellard | if (!fdctrl)
|
478 | baca51fa | bellard | return NULL; |
479 | baca51fa | bellard | fdctrl->version = 0x90; /* Intel 82078 controler */ |
480 | baca51fa | bellard | fdctrl->irq_lvl = irq_lvl; |
481 | baca51fa | bellard | fdctrl->dma_chann = dma_chann; |
482 | baca51fa | bellard | fdctrl->io_base = io_base; |
483 | a541f297 | bellard | fdctrl->config = 0x60; /* Implicit seek, polling & FIFO enabled */ |
484 | baca51fa | bellard | if (fdctrl->dma_chann != -1) { |
485 | baca51fa | bellard | fdctrl->dma_en = 1;
|
486 | baca51fa | bellard | DMA_register_channel(dma_chann, &fdctrl_transfer_handler, fdctrl); |
487 | 8977f3c1 | bellard | } else {
|
488 | baca51fa | bellard | fdctrl->dma_en = 0;
|
489 | 8977f3c1 | bellard | } |
490 | baca51fa | bellard | for (i = 0; i < 2; i++) { |
491 | baca51fa | bellard | fd_init(&fdctrl->drives[i], fds[i]); |
492 | baca51fa | bellard | if (fds[i]) {
|
493 | baca51fa | bellard | bdrv_set_change_cb(fds[i], |
494 | baca51fa | bellard | &fd_change_cb, &fdctrl->drives[i]); |
495 | baca51fa | bellard | } |
496 | caed8802 | bellard | } |
497 | baca51fa | bellard | fdctrl_reset(fdctrl, 0);
|
498 | baca51fa | bellard | fdctrl->state = FD_CTRL_ACTIVE; |
499 | 8977f3c1 | bellard | if (mem_mapped) {
|
500 | 8977f3c1 | bellard | FLOPPY_ERROR("memory mapped floppy not supported by now !\n");
|
501 | 8977f3c1 | bellard | #if 0
|
502 | 8977f3c1 | bellard | io_mem = cpu_register_io_memory(0, fdctrl_mem_read, fdctrl_mem_write);
|
503 | 8977f3c1 | bellard | cpu_register_physical_memory(base, 0x08, io_mem);
|
504 | 8977f3c1 | bellard | #endif
|
505 | 8977f3c1 | bellard | } else {
|
506 | baca51fa | bellard | register_ioport_read(io_base + 0x01, 5, 1, &fdctrl_read, fdctrl); |
507 | baca51fa | bellard | register_ioport_read(io_base + 0x07, 1, 1, &fdctrl_read, fdctrl); |
508 | baca51fa | bellard | register_ioport_write(io_base + 0x01, 5, 1, &fdctrl_write, fdctrl); |
509 | baca51fa | bellard | register_ioport_write(io_base + 0x07, 1, 1, &fdctrl_write, fdctrl); |
510 | 8977f3c1 | bellard | } |
511 | a541f297 | bellard | for (i = 0; i < 2; i++) { |
512 | baca51fa | bellard | fd_revalidate(&fdctrl->drives[i]); |
513 | 8977f3c1 | bellard | } |
514 | a541f297 | bellard | |
515 | baca51fa | bellard | return fdctrl;
|
516 | caed8802 | bellard | } |
517 | 8977f3c1 | bellard | |
518 | baca51fa | bellard | /* XXX: may change if moved to bdrv */
|
519 | baca51fa | bellard | int fdctrl_get_drive_type(fdctrl_t *fdctrl, int drive_num) |
520 | caed8802 | bellard | { |
521 | baca51fa | bellard | return fdctrl->drives[drive_num].drive;
|
522 | 8977f3c1 | bellard | } |
523 | 8977f3c1 | bellard | |
524 | 8977f3c1 | bellard | /* Change IRQ state */
|
525 | baca51fa | bellard | static void fdctrl_reset_irq (fdctrl_t *fdctrl) |
526 | 8977f3c1 | bellard | { |
527 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_INTR) {
|
528 | baca51fa | bellard | pic_set_irq(fdctrl->irq_lvl, 0);
|
529 | baca51fa | bellard | fdctrl->state &= ~(FD_CTRL_INTR | FD_CTRL_SLEEP | FD_CTRL_BUSY); |
530 | 8977f3c1 | bellard | } |
531 | 8977f3c1 | bellard | } |
532 | 8977f3c1 | bellard | |
533 | baca51fa | bellard | static void fdctrl_raise_irq (fdctrl_t *fdctrl, uint8_t status) |
534 | 8977f3c1 | bellard | { |
535 | baca51fa | bellard | if (~(fdctrl->state & FD_CTRL_INTR)) {
|
536 | baca51fa | bellard | pic_set_irq(fdctrl->irq_lvl, 1);
|
537 | baca51fa | bellard | fdctrl->state |= FD_CTRL_INTR; |
538 | 8977f3c1 | bellard | } |
539 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Set interrupt status to 0x%02x\n", status);
|
540 | baca51fa | bellard | fdctrl->int_status = status; |
541 | 8977f3c1 | bellard | } |
542 | 8977f3c1 | bellard | |
543 | 8977f3c1 | bellard | /* Reset controler */
|
544 | baca51fa | bellard | static void fdctrl_reset (fdctrl_t *fdctrl, int do_irq) |
545 | 8977f3c1 | bellard | { |
546 | 8977f3c1 | bellard | int i;
|
547 | 8977f3c1 | bellard | |
548 | 8977f3c1 | bellard | FLOPPY_DPRINTF("reset controler\n");
|
549 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
550 | 8977f3c1 | bellard | /* Initialise controler */
|
551 | baca51fa | bellard | fdctrl->cur_drv = 0;
|
552 | 8977f3c1 | bellard | /* FIFO state */
|
553 | baca51fa | bellard | fdctrl->data_pos = 0;
|
554 | baca51fa | bellard | fdctrl->data_len = 0;
|
555 | baca51fa | bellard | fdctrl->data_state = FD_STATE_CMD; |
556 | baca51fa | bellard | fdctrl->data_dir = FD_DIR_WRITE; |
557 | 8977f3c1 | bellard | for (i = 0; i < MAX_FD; i++) |
558 | baca51fa | bellard | fd_reset(&fdctrl->drives[i]); |
559 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
560 | 8977f3c1 | bellard | if (do_irq)
|
561 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x20);
|
562 | baca51fa | bellard | } |
563 | baca51fa | bellard | |
564 | baca51fa | bellard | static inline fdrive_t *drv0 (fdctrl_t *fdctrl) |
565 | baca51fa | bellard | { |
566 | baca51fa | bellard | return &fdctrl->drives[fdctrl->bootsel];
|
567 | baca51fa | bellard | } |
568 | baca51fa | bellard | |
569 | baca51fa | bellard | static inline fdrive_t *drv1 (fdctrl_t *fdctrl) |
570 | baca51fa | bellard | { |
571 | baca51fa | bellard | return &fdctrl->drives[1 - fdctrl->bootsel]; |
572 | baca51fa | bellard | } |
573 | baca51fa | bellard | |
574 | baca51fa | bellard | static fdrive_t *get_cur_drv (fdctrl_t *fdctrl)
|
575 | baca51fa | bellard | { |
576 | baca51fa | bellard | return fdctrl->cur_drv == 0 ? drv0(fdctrl) : drv1(fdctrl); |
577 | 8977f3c1 | bellard | } |
578 | 8977f3c1 | bellard | |
579 | 8977f3c1 | bellard | /* Status B register : 0x01 (read-only) */
|
580 | baca51fa | bellard | static uint32_t fdctrl_read_statusB (fdctrl_t *fdctrl)
|
581 | 8977f3c1 | bellard | { |
582 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
583 | 8977f3c1 | bellard | FLOPPY_DPRINTF("status register: 0x00\n");
|
584 | 8977f3c1 | bellard | |
585 | 8977f3c1 | bellard | return 0; |
586 | 8977f3c1 | bellard | } |
587 | 8977f3c1 | bellard | |
588 | 8977f3c1 | bellard | /* Digital output register : 0x02 */
|
589 | baca51fa | bellard | static uint32_t fdctrl_read_dor (fdctrl_t *fdctrl)
|
590 | 8977f3c1 | bellard | { |
591 | 8977f3c1 | bellard | uint32_t retval = 0;
|
592 | 8977f3c1 | bellard | |
593 | 8977f3c1 | bellard | /* Drive motors state indicators */
|
594 | baca51fa | bellard | if (drv0(fdctrl)->drflags & FDRIVE_MOTOR_ON)
|
595 | baca51fa | bellard | retval |= 1 << 5; |
596 | baca51fa | bellard | if (drv1(fdctrl)->drflags & FDRIVE_MOTOR_ON)
|
597 | baca51fa | bellard | retval |= 1 << 4; |
598 | 8977f3c1 | bellard | /* DMA enable */
|
599 | baca51fa | bellard | retval |= fdctrl->dma_en << 3;
|
600 | 8977f3c1 | bellard | /* Reset indicator */
|
601 | baca51fa | bellard | retval |= (fdctrl->state & FD_CTRL_RESET) == 0 ? 0x04 : 0; |
602 | 8977f3c1 | bellard | /* Selected drive */
|
603 | baca51fa | bellard | retval |= fdctrl->cur_drv; |
604 | 8977f3c1 | bellard | FLOPPY_DPRINTF("digital output register: 0x%02x\n", retval);
|
605 | 8977f3c1 | bellard | |
606 | 8977f3c1 | bellard | return retval;
|
607 | 8977f3c1 | bellard | } |
608 | 8977f3c1 | bellard | |
609 | baca51fa | bellard | static void fdctrl_write_dor (fdctrl_t *fdctrl, uint32_t value) |
610 | 8977f3c1 | bellard | { |
611 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
612 | 8977f3c1 | bellard | /* Reset mode */
|
613 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_RESET) {
|
614 | 8977f3c1 | bellard | if (!(value & 0x04)) { |
615 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
|
616 | 8977f3c1 | bellard | return;
|
617 | 8977f3c1 | bellard | } |
618 | 8977f3c1 | bellard | } |
619 | 8977f3c1 | bellard | FLOPPY_DPRINTF("digital output register set to 0x%02x\n", value);
|
620 | 8977f3c1 | bellard | /* Drive motors state indicators */
|
621 | 8977f3c1 | bellard | if (value & 0x20) |
622 | baca51fa | bellard | fd_start(drv1(fdctrl)); |
623 | 8977f3c1 | bellard | else
|
624 | baca51fa | bellard | fd_stop(drv1(fdctrl)); |
625 | 8977f3c1 | bellard | if (value & 0x10) |
626 | baca51fa | bellard | fd_start(drv0(fdctrl)); |
627 | 8977f3c1 | bellard | else
|
628 | baca51fa | bellard | fd_stop(drv0(fdctrl)); |
629 | 8977f3c1 | bellard | /* DMA enable */
|
630 | 8977f3c1 | bellard | #if 0
|
631 | baca51fa | bellard | if (fdctrl->dma_chann != -1)
|
632 | baca51fa | bellard | fdctrl->dma_en = 1 - ((value >> 3) & 1);
|
633 | 8977f3c1 | bellard | #endif
|
634 | 8977f3c1 | bellard | /* Reset */
|
635 | 8977f3c1 | bellard | if (!(value & 0x04)) { |
636 | baca51fa | bellard | if (!(fdctrl->state & FD_CTRL_RESET)) {
|
637 | 8977f3c1 | bellard | FLOPPY_DPRINTF("controler enter RESET state\n");
|
638 | baca51fa | bellard | fdctrl->state |= FD_CTRL_RESET; |
639 | baca51fa | bellard | fdctrl_reset(fdctrl, 1);
|
640 | 8977f3c1 | bellard | } |
641 | 8977f3c1 | bellard | } else {
|
642 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_RESET) {
|
643 | 8977f3c1 | bellard | FLOPPY_DPRINTF("controler out of RESET state\n");
|
644 | baca51fa | bellard | fdctrl->state &= ~(FD_CTRL_RESET | FD_CTRL_SLEEP); |
645 | 8977f3c1 | bellard | } |
646 | 8977f3c1 | bellard | } |
647 | 8977f3c1 | bellard | /* Selected drive */
|
648 | baca51fa | bellard | fdctrl->cur_drv = value & 1;
|
649 | 8977f3c1 | bellard | } |
650 | 8977f3c1 | bellard | |
651 | 8977f3c1 | bellard | /* Tape drive register : 0x03 */
|
652 | baca51fa | bellard | static uint32_t fdctrl_read_tape (fdctrl_t *fdctrl)
|
653 | 8977f3c1 | bellard | { |
654 | 8977f3c1 | bellard | uint32_t retval = 0;
|
655 | 8977f3c1 | bellard | |
656 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
657 | 8977f3c1 | bellard | /* Disk boot selection indicator */
|
658 | baca51fa | bellard | retval |= fdctrl->bootsel << 2;
|
659 | 8977f3c1 | bellard | /* Tape indicators: never allowed */
|
660 | 8977f3c1 | bellard | FLOPPY_DPRINTF("tape drive register: 0x%02x\n", retval);
|
661 | 8977f3c1 | bellard | |
662 | 8977f3c1 | bellard | return retval;
|
663 | 8977f3c1 | bellard | } |
664 | 8977f3c1 | bellard | |
665 | baca51fa | bellard | static void fdctrl_write_tape (fdctrl_t *fdctrl, uint32_t value) |
666 | 8977f3c1 | bellard | { |
667 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
668 | 8977f3c1 | bellard | /* Reset mode */
|
669 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_RESET) {
|
670 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
|
671 | 8977f3c1 | bellard | return;
|
672 | 8977f3c1 | bellard | } |
673 | 8977f3c1 | bellard | FLOPPY_DPRINTF("tape drive register set to 0x%02x\n", value);
|
674 | 8977f3c1 | bellard | /* Disk boot selection indicator */
|
675 | baca51fa | bellard | fdctrl->bootsel = (value >> 2) & 1; |
676 | 8977f3c1 | bellard | /* Tape indicators: never allow */
|
677 | 8977f3c1 | bellard | } |
678 | 8977f3c1 | bellard | |
679 | 8977f3c1 | bellard | /* Main status register : 0x04 (read) */
|
680 | baca51fa | bellard | static uint32_t fdctrl_read_main_status (fdctrl_t *fdctrl)
|
681 | 8977f3c1 | bellard | { |
682 | 8977f3c1 | bellard | uint32_t retval = 0;
|
683 | 8977f3c1 | bellard | |
684 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
685 | baca51fa | bellard | fdctrl->state &= ~(FD_CTRL_SLEEP | FD_CTRL_RESET); |
686 | baca51fa | bellard | if (!(fdctrl->state & FD_CTRL_BUSY)) {
|
687 | 8977f3c1 | bellard | /* Data transfer allowed */
|
688 | 8977f3c1 | bellard | retval |= 0x80;
|
689 | 8977f3c1 | bellard | /* Data transfer direction indicator */
|
690 | baca51fa | bellard | if (fdctrl->data_dir == FD_DIR_READ)
|
691 | 8977f3c1 | bellard | retval |= 0x40;
|
692 | 8977f3c1 | bellard | } |
693 | 8977f3c1 | bellard | /* Should handle 0x20 for SPECIFY command */
|
694 | 8977f3c1 | bellard | /* Command busy indicator */
|
695 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_DATA ||
|
696 | baca51fa | bellard | FD_STATE(fdctrl->data_state) == FD_STATE_STATUS) |
697 | 8977f3c1 | bellard | retval |= 0x10;
|
698 | 8977f3c1 | bellard | FLOPPY_DPRINTF("main status register: 0x%02x\n", retval);
|
699 | 8977f3c1 | bellard | |
700 | 8977f3c1 | bellard | return retval;
|
701 | 8977f3c1 | bellard | } |
702 | 8977f3c1 | bellard | |
703 | 8977f3c1 | bellard | /* Data select rate register : 0x04 (write) */
|
704 | baca51fa | bellard | static void fdctrl_write_rate (fdctrl_t *fdctrl, uint32_t value) |
705 | 8977f3c1 | bellard | { |
706 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
707 | 8977f3c1 | bellard | /* Reset mode */
|
708 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_RESET) {
|
709 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
|
710 | 8977f3c1 | bellard | return;
|
711 | 8977f3c1 | bellard | } |
712 | 8977f3c1 | bellard | FLOPPY_DPRINTF("select rate register set to 0x%02x\n", value);
|
713 | 8977f3c1 | bellard | /* Reset: autoclear */
|
714 | 8977f3c1 | bellard | if (value & 0x80) { |
715 | baca51fa | bellard | fdctrl->state |= FD_CTRL_RESET; |
716 | baca51fa | bellard | fdctrl_reset(fdctrl, 1);
|
717 | baca51fa | bellard | fdctrl->state &= ~FD_CTRL_RESET; |
718 | 8977f3c1 | bellard | } |
719 | 8977f3c1 | bellard | if (value & 0x40) { |
720 | baca51fa | bellard | fdctrl->state |= FD_CTRL_SLEEP; |
721 | baca51fa | bellard | fdctrl_reset(fdctrl, 1);
|
722 | 8977f3c1 | bellard | } |
723 | 8977f3c1 | bellard | // fdctrl.precomp = (value >> 2) & 0x07;
|
724 | 8977f3c1 | bellard | } |
725 | 8977f3c1 | bellard | |
726 | 8977f3c1 | bellard | /* Digital input register : 0x07 (read-only) */
|
727 | baca51fa | bellard | static uint32_t fdctrl_read_dir (fdctrl_t *fdctrl)
|
728 | 8977f3c1 | bellard | { |
729 | 8977f3c1 | bellard | uint32_t retval = 0;
|
730 | 8977f3c1 | bellard | |
731 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
732 | baca51fa | bellard | if (drv0(fdctrl)->drflags & FDRIVE_REVALIDATE ||
|
733 | baca51fa | bellard | drv1(fdctrl)->drflags & FDRIVE_REVALIDATE) |
734 | 8977f3c1 | bellard | retval |= 0x80;
|
735 | 8977f3c1 | bellard | if (retval != 0) |
736 | baca51fa | bellard | FLOPPY_DPRINTF("Floppy digital input register: 0x%02x\n", retval);
|
737 | baca51fa | bellard | drv0(fdctrl)->drflags &= ~FDRIVE_REVALIDATE; |
738 | baca51fa | bellard | drv1(fdctrl)->drflags &= ~FDRIVE_REVALIDATE; |
739 | 8977f3c1 | bellard | |
740 | 8977f3c1 | bellard | return retval;
|
741 | 8977f3c1 | bellard | } |
742 | 8977f3c1 | bellard | |
743 | 8977f3c1 | bellard | /* FIFO state control */
|
744 | baca51fa | bellard | static void fdctrl_reset_fifo (fdctrl_t *fdctrl) |
745 | 8977f3c1 | bellard | { |
746 | baca51fa | bellard | fdctrl->data_dir = FD_DIR_WRITE; |
747 | baca51fa | bellard | fdctrl->data_pos = 0;
|
748 | baca51fa | bellard | FD_SET_STATE(fdctrl->data_state, FD_STATE_CMD); |
749 | 8977f3c1 | bellard | } |
750 | 8977f3c1 | bellard | |
751 | 8977f3c1 | bellard | /* Set FIFO status for the host to read */
|
752 | baca51fa | bellard | static void fdctrl_set_fifo (fdctrl_t *fdctrl, int fifo_len, int do_irq) |
753 | 8977f3c1 | bellard | { |
754 | baca51fa | bellard | fdctrl->data_dir = FD_DIR_READ; |
755 | baca51fa | bellard | fdctrl->data_len = fifo_len; |
756 | baca51fa | bellard | fdctrl->data_pos = 0;
|
757 | baca51fa | bellard | FD_SET_STATE(fdctrl->data_state, FD_STATE_STATUS); |
758 | 8977f3c1 | bellard | if (do_irq)
|
759 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x00);
|
760 | 8977f3c1 | bellard | } |
761 | 8977f3c1 | bellard | |
762 | 8977f3c1 | bellard | /* Set an error: unimplemented/unknown command */
|
763 | baca51fa | bellard | static void fdctrl_unimplemented (fdctrl_t *fdctrl) |
764 | 8977f3c1 | bellard | { |
765 | 8977f3c1 | bellard | #if 0
|
766 | baca51fa | bellard | fdrive_t *cur_drv;
|
767 | baca51fa | bellard | |
768 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl);
|
769 | baca51fa | bellard | fdctrl->fifo[0] = 0x60 | (cur_drv->head << 1) | fdctrl->cur_drv;
|
770 | baca51fa | bellard | fdctrl->fifo[1] = 0x00;
|
771 | baca51fa | bellard | fdctrl->fifo[2] = 0x00;
|
772 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 3, 1);
|
773 | 8977f3c1 | bellard | #else
|
774 | baca51fa | bellard | // fdctrl_reset_fifo(fdctrl);
|
775 | baca51fa | bellard | fdctrl->fifo[0] = 0x80; |
776 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 0); |
777 | 8977f3c1 | bellard | #endif
|
778 | 8977f3c1 | bellard | } |
779 | 8977f3c1 | bellard | |
780 | 8977f3c1 | bellard | /* Callback for transfer end (stop or abort) */
|
781 | baca51fa | bellard | static void fdctrl_stop_transfer (fdctrl_t *fdctrl, uint8_t status0, |
782 | baca51fa | bellard | uint8_t status1, uint8_t status2) |
783 | 8977f3c1 | bellard | { |
784 | baca51fa | bellard | fdrive_t *cur_drv; |
785 | 8977f3c1 | bellard | |
786 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
787 | 8977f3c1 | bellard | FLOPPY_DPRINTF("transfer status: %02x %02x %02x (%02x)\n",
|
788 | 8977f3c1 | bellard | status0, status1, status2, |
789 | baca51fa | bellard | status0 | (cur_drv->head << 1) | fdctrl->cur_drv);
|
790 | baca51fa | bellard | fdctrl->fifo[0] = status0 | (cur_drv->head << 1) | fdctrl->cur_drv; |
791 | baca51fa | bellard | fdctrl->fifo[1] = status1;
|
792 | baca51fa | bellard | fdctrl->fifo[2] = status2;
|
793 | baca51fa | bellard | fdctrl->fifo[3] = cur_drv->track;
|
794 | baca51fa | bellard | fdctrl->fifo[4] = cur_drv->head;
|
795 | baca51fa | bellard | fdctrl->fifo[5] = cur_drv->sect;
|
796 | baca51fa | bellard | fdctrl->fifo[6] = FD_SECTOR_SC;
|
797 | baca51fa | bellard | fdctrl->data_dir = FD_DIR_READ; |
798 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_BUSY)
|
799 | baca51fa | bellard | DMA_release_DREQ(fdctrl->dma_chann); |
800 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 7, 1); |
801 | 8977f3c1 | bellard | } |
802 | 8977f3c1 | bellard | |
803 | 8977f3c1 | bellard | /* Prepare a data transfer (either DMA or FIFO) */
|
804 | baca51fa | bellard | static void fdctrl_start_transfer (fdctrl_t *fdctrl, int direction) |
805 | 8977f3c1 | bellard | { |
806 | baca51fa | bellard | fdrive_t *cur_drv; |
807 | 8977f3c1 | bellard | uint8_t kh, kt, ks; |
808 | 8977f3c1 | bellard | int did_seek;
|
809 | 8977f3c1 | bellard | |
810 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
811 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
812 | baca51fa | bellard | kt = fdctrl->fifo[2];
|
813 | baca51fa | bellard | kh = fdctrl->fifo[3];
|
814 | baca51fa | bellard | ks = fdctrl->fifo[4];
|
815 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Start tranfert at %d %d %02x %02x (%d)\n",
|
816 | baca51fa | bellard | fdctrl->cur_drv, kh, kt, ks, |
817 | 8977f3c1 | bellard | _fd_sector(kh, kt, ks, cur_drv->last_sect)); |
818 | 8977f3c1 | bellard | did_seek = 0;
|
819 | baca51fa | bellard | switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & 0x40)) { |
820 | 8977f3c1 | bellard | case 2: |
821 | 8977f3c1 | bellard | /* sect too big */
|
822 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x00, 0x00); |
823 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
824 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
825 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
826 | 8977f3c1 | bellard | return;
|
827 | 8977f3c1 | bellard | case 3: |
828 | 8977f3c1 | bellard | /* track too big */
|
829 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x80, 0x00); |
830 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
831 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
832 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
833 | 8977f3c1 | bellard | return;
|
834 | 8977f3c1 | bellard | case 4: |
835 | 8977f3c1 | bellard | /* No seek enabled */
|
836 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x00, 0x00); |
837 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
838 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
839 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
840 | 8977f3c1 | bellard | return;
|
841 | 8977f3c1 | bellard | case 1: |
842 | 8977f3c1 | bellard | did_seek = 1;
|
843 | 8977f3c1 | bellard | break;
|
844 | 8977f3c1 | bellard | default:
|
845 | 8977f3c1 | bellard | break;
|
846 | 8977f3c1 | bellard | } |
847 | 8977f3c1 | bellard | /* Set the FIFO state */
|
848 | baca51fa | bellard | fdctrl->data_dir = direction; |
849 | baca51fa | bellard | fdctrl->data_pos = 0;
|
850 | baca51fa | bellard | FD_SET_STATE(fdctrl->data_state, FD_STATE_DATA); /* FIFO ready for data */
|
851 | baca51fa | bellard | if (fdctrl->fifo[0] & 0x80) |
852 | baca51fa | bellard | fdctrl->data_state |= FD_STATE_MULTI; |
853 | baca51fa | bellard | else
|
854 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_MULTI; |
855 | 8977f3c1 | bellard | if (did_seek)
|
856 | baca51fa | bellard | fdctrl->data_state |= FD_STATE_SEEK; |
857 | baca51fa | bellard | else
|
858 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_SEEK; |
859 | baca51fa | bellard | if (fdctrl->fifo[5] == 00) { |
860 | baca51fa | bellard | fdctrl->data_len = fdctrl->fifo[8];
|
861 | baca51fa | bellard | } else {
|
862 | baca51fa | bellard | int tmp;
|
863 | baca51fa | bellard | fdctrl->data_len = 128 << fdctrl->fifo[5]; |
864 | baca51fa | bellard | tmp = (cur_drv->last_sect - ks + 1);
|
865 | baca51fa | bellard | if (fdctrl->fifo[0] & 0x80) |
866 | baca51fa | bellard | tmp += cur_drv->last_sect; |
867 | baca51fa | bellard | fdctrl->data_len *= tmp; |
868 | baca51fa | bellard | } |
869 | baca51fa | bellard | if (fdctrl->dma_en) {
|
870 | 8977f3c1 | bellard | int dma_mode;
|
871 | 8977f3c1 | bellard | /* DMA transfer are enabled. Check if DMA channel is well programmed */
|
872 | baca51fa | bellard | dma_mode = DMA_get_channel_mode(fdctrl->dma_chann); |
873 | 8977f3c1 | bellard | dma_mode = (dma_mode >> 2) & 3; |
874 | baca51fa | bellard | FLOPPY_DPRINTF("dma_mode=%d direction=%d (%d - %d)\n",
|
875 | baca51fa | bellard | dma_mode, direction, |
876 | baca51fa | bellard | (128 << fdctrl->fifo[5]) * |
877 | baca51fa | bellard | (cur_drv->last_sect - ks + 1), fdctrl->data_len);
|
878 | 8977f3c1 | bellard | if (((direction == FD_DIR_SCANE || direction == FD_DIR_SCANL ||
|
879 | 8977f3c1 | bellard | direction == FD_DIR_SCANH) && dma_mode == 0) ||
|
880 | 8977f3c1 | bellard | (direction == FD_DIR_WRITE && dma_mode == 2) ||
|
881 | 8977f3c1 | bellard | (direction == FD_DIR_READ && dma_mode == 1)) {
|
882 | 8977f3c1 | bellard | /* No access is allowed until DMA transfer has completed */
|
883 | baca51fa | bellard | fdctrl->state |= FD_CTRL_BUSY; |
884 | 8977f3c1 | bellard | /* Now, we just have to wait for the DMA controler to
|
885 | 8977f3c1 | bellard | * recall us...
|
886 | 8977f3c1 | bellard | */
|
887 | baca51fa | bellard | DMA_hold_DREQ(fdctrl->dma_chann); |
888 | baca51fa | bellard | DMA_schedule(fdctrl->dma_chann); |
889 | 8977f3c1 | bellard | return;
|
890 | baca51fa | bellard | } else {
|
891 | baca51fa | bellard | FLOPPY_ERROR("dma_mode=%d direction=%d\n", dma_mode, direction);
|
892 | 8977f3c1 | bellard | } |
893 | 8977f3c1 | bellard | } |
894 | 8977f3c1 | bellard | FLOPPY_DPRINTF("start non-DMA transfer\n");
|
895 | 8977f3c1 | bellard | /* IO based transfer: calculate len */
|
896 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x00);
|
897 | 8977f3c1 | bellard | |
898 | 8977f3c1 | bellard | return;
|
899 | 8977f3c1 | bellard | } |
900 | 8977f3c1 | bellard | |
901 | 8977f3c1 | bellard | /* Prepare a transfer of deleted data */
|
902 | baca51fa | bellard | static void fdctrl_start_transfer_del (fdctrl_t *fdctrl, int direction) |
903 | 8977f3c1 | bellard | { |
904 | 8977f3c1 | bellard | /* We don't handle deleted data,
|
905 | 8977f3c1 | bellard | * so we don't return *ANYTHING*
|
906 | 8977f3c1 | bellard | */
|
907 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x60, 0x00, 0x00); |
908 | 8977f3c1 | bellard | } |
909 | 8977f3c1 | bellard | |
910 | 8977f3c1 | bellard | /* handlers for DMA transfers */
|
911 | f9e92e97 | bellard | static int fdctrl_transfer_handler (void *opaque, target_ulong addr, int size) |
912 | 8977f3c1 | bellard | { |
913 | baca51fa | bellard | fdctrl_t *fdctrl; |
914 | baca51fa | bellard | fdrive_t *cur_drv; |
915 | baca51fa | bellard | int len, start_pos, rel_pos;
|
916 | 8977f3c1 | bellard | uint8_t status0 = 0x00, status1 = 0x00, status2 = 0x00; |
917 | 8977f3c1 | bellard | |
918 | baca51fa | bellard | fdctrl = opaque; |
919 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
920 | baca51fa | bellard | if (!(fdctrl->state & FD_CTRL_BUSY)) {
|
921 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Not in DMA transfer mode !\n");
|
922 | 8977f3c1 | bellard | return 0; |
923 | 8977f3c1 | bellard | } |
924 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
925 | baca51fa | bellard | if (fdctrl->data_dir == FD_DIR_SCANE || fdctrl->data_dir == FD_DIR_SCANL ||
|
926 | baca51fa | bellard | fdctrl->data_dir == FD_DIR_SCANH) |
927 | 8977f3c1 | bellard | status2 = 0x04;
|
928 | baca51fa | bellard | if (size > fdctrl->data_len)
|
929 | baca51fa | bellard | size = fdctrl->data_len; |
930 | 69e5bc90 | bellard | if (cur_drv->bs == NULL) { |
931 | baca51fa | bellard | if (fdctrl->data_dir == FD_DIR_WRITE)
|
932 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x60, 0x00, 0x00); |
933 | baca51fa | bellard | else
|
934 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x00, 0x00); |
935 | baca51fa | bellard | len = 0;
|
936 | 69e5bc90 | bellard | goto transfer_error;
|
937 | 69e5bc90 | bellard | } |
938 | baca51fa | bellard | rel_pos = fdctrl->data_pos % FD_SECTOR_LEN; |
939 | baca51fa | bellard | for (start_pos = fdctrl->data_pos; fdctrl->data_pos < size;) {
|
940 | baca51fa | bellard | len = size - fdctrl->data_pos; |
941 | baca51fa | bellard | if (len + rel_pos > FD_SECTOR_LEN)
|
942 | baca51fa | bellard | len = FD_SECTOR_LEN - rel_pos; |
943 | baca51fa | bellard | FLOPPY_DPRINTF("copy %d bytes (%d %d %d) %d pos %d %02x %02x "
|
944 | baca51fa | bellard | "(%d-0x%08x 0x%08x)\n", len, size, fdctrl->data_pos,
|
945 | baca51fa | bellard | fdctrl->data_len, fdctrl->cur_drv, cur_drv->head, |
946 | baca51fa | bellard | cur_drv->track, cur_drv->sect, fd_sector(cur_drv), |
947 | baca51fa | bellard | fd_sector(cur_drv) * 512, addr);
|
948 | baca51fa | bellard | if (fdctrl->data_dir != FD_DIR_WRITE ||
|
949 | baca51fa | bellard | len < FD_SECTOR_LEN || rel_pos != 0) {
|
950 | baca51fa | bellard | /* READ & SCAN commands and realign to a sector for WRITE */
|
951 | baca51fa | bellard | if (bdrv_read(cur_drv->bs, fd_sector(cur_drv),
|
952 | baca51fa | bellard | fdctrl->fifo, 1) < 0) { |
953 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Floppy: error getting sector %d\n",
|
954 | 8977f3c1 | bellard | fd_sector(cur_drv)); |
955 | 8977f3c1 | bellard | /* Sure, image size is too small... */
|
956 | baca51fa | bellard | memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
957 | 8977f3c1 | bellard | } |
958 | 8977f3c1 | bellard | } |
959 | baca51fa | bellard | switch (fdctrl->data_dir) {
|
960 | baca51fa | bellard | case FD_DIR_READ:
|
961 | baca51fa | bellard | /* READ commands */
|
962 | baca51fa | bellard | cpu_physical_memory_write(addr + fdctrl->data_pos, |
963 | baca51fa | bellard | fdctrl->fifo + rel_pos, len); |
964 | baca51fa | bellard | break;
|
965 | baca51fa | bellard | case FD_DIR_WRITE:
|
966 | baca51fa | bellard | /* WRITE commands */
|
967 | baca51fa | bellard | cpu_physical_memory_read(addr + fdctrl->data_pos, |
968 | baca51fa | bellard | fdctrl->fifo + rel_pos, len); |
969 | baca51fa | bellard | if (bdrv_write(cur_drv->bs, fd_sector(cur_drv),
|
970 | baca51fa | bellard | fdctrl->fifo, 1) < 0) { |
971 | baca51fa | bellard | FLOPPY_ERROR("writting sector %d\n", fd_sector(cur_drv));
|
972 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x60, 0x00, 0x00); |
973 | baca51fa | bellard | goto transfer_error;
|
974 | f9e92e97 | bellard | } |
975 | baca51fa | bellard | break;
|
976 | baca51fa | bellard | default:
|
977 | baca51fa | bellard | /* SCAN commands */
|
978 | baca51fa | bellard | { |
979 | baca51fa | bellard | uint8_t tmpbuf[FD_SECTOR_LEN]; |
980 | baca51fa | bellard | int ret;
|
981 | baca51fa | bellard | cpu_physical_memory_read(addr + fdctrl->data_pos, |
982 | baca51fa | bellard | tmpbuf, len); |
983 | baca51fa | bellard | ret = memcmp(tmpbuf, fdctrl->fifo + rel_pos, len); |
984 | 8977f3c1 | bellard | if (ret == 0) { |
985 | 8977f3c1 | bellard | status2 = 0x08;
|
986 | 8977f3c1 | bellard | goto end_transfer;
|
987 | 8977f3c1 | bellard | } |
988 | baca51fa | bellard | if ((ret < 0 && fdctrl->data_dir == FD_DIR_SCANL) || |
989 | baca51fa | bellard | (ret > 0 && fdctrl->data_dir == FD_DIR_SCANH)) {
|
990 | 8977f3c1 | bellard | status2 = 0x00;
|
991 | 8977f3c1 | bellard | goto end_transfer;
|
992 | 8977f3c1 | bellard | } |
993 | 8977f3c1 | bellard | } |
994 | baca51fa | bellard | break;
|
995 | 8977f3c1 | bellard | } |
996 | baca51fa | bellard | fdctrl->data_pos += len; |
997 | baca51fa | bellard | rel_pos = fdctrl->data_pos % FD_SECTOR_LEN; |
998 | baca51fa | bellard | if (rel_pos == 0) { |
999 | 8977f3c1 | bellard | /* Seek to next sector */
|
1000 | baca51fa | bellard | cur_drv->sect++; |
1001 | baca51fa | bellard | FLOPPY_DPRINTF("seek to next sector (%d %02x %02x => %d) (%d)\n",
|
1002 | baca51fa | bellard | cur_drv->head, cur_drv->track, cur_drv->sect, |
1003 | baca51fa | bellard | fd_sector(cur_drv), |
1004 | baca51fa | bellard | fdctrl->data_pos - size); |
1005 | baca51fa | bellard | if (cur_drv->sect > cur_drv->last_sect) {
|
1006 | baca51fa | bellard | cur_drv->sect = 1;
|
1007 | baca51fa | bellard | if (FD_MULTI_TRACK(fdctrl->data_state)) {
|
1008 | baca51fa | bellard | if (cur_drv->head == 0 && |
1009 | baca51fa | bellard | (cur_drv->flags & FDISK_DBL_SIDES) != 0) {
|
1010 | 8977f3c1 | bellard | cur_drv->head = 1;
|
1011 | 8977f3c1 | bellard | } else {
|
1012 | 8977f3c1 | bellard | cur_drv->head = 0;
|
1013 | baca51fa | bellard | cur_drv->track++; |
1014 | baca51fa | bellard | if ((cur_drv->flags & FDISK_DBL_SIDES) == 0) |
1015 | baca51fa | bellard | break;
|
1016 | 8977f3c1 | bellard | } |
1017 | 8977f3c1 | bellard | } else {
|
1018 | baca51fa | bellard | cur_drv->track++; |
1019 | baca51fa | bellard | break;
|
1020 | baca51fa | bellard | } |
1021 | baca51fa | bellard | FLOPPY_DPRINTF("seek to next track (%d %02x %02x => %d)\n",
|
1022 | baca51fa | bellard | cur_drv->head, cur_drv->track, |
1023 | baca51fa | bellard | cur_drv->sect, fd_sector(cur_drv)); |
1024 | 8977f3c1 | bellard | } |
1025 | 8977f3c1 | bellard | } |
1026 | 8977f3c1 | bellard | } |
1027 | 8977f3c1 | bellard | end_transfer:
|
1028 | baca51fa | bellard | len = fdctrl->data_pos - start_pos; |
1029 | baca51fa | bellard | FLOPPY_DPRINTF("end transfer %d %d %d\n",
|
1030 | baca51fa | bellard | fdctrl->data_pos, len, fdctrl->data_len); |
1031 | baca51fa | bellard | if (fdctrl->data_dir == FD_DIR_SCANE ||
|
1032 | baca51fa | bellard | fdctrl->data_dir == FD_DIR_SCANL || |
1033 | baca51fa | bellard | fdctrl->data_dir == FD_DIR_SCANH) |
1034 | 8977f3c1 | bellard | status2 = 0x08;
|
1035 | baca51fa | bellard | if (FD_DID_SEEK(fdctrl->data_state))
|
1036 | 8977f3c1 | bellard | status0 |= 0x20;
|
1037 | baca51fa | bellard | fdctrl->data_len -= len; |
1038 | baca51fa | bellard | // if (fdctrl->data_len == 0)
|
1039 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, status0, status1, status2); |
1040 | 8977f3c1 | bellard | transfer_error:
|
1041 | 8977f3c1 | bellard | |
1042 | baca51fa | bellard | return len;
|
1043 | 8977f3c1 | bellard | } |
1044 | 8977f3c1 | bellard | |
1045 | 8977f3c1 | bellard | /* Data register : 0x05 */
|
1046 | baca51fa | bellard | static uint32_t fdctrl_read_data (fdctrl_t *fdctrl)
|
1047 | 8977f3c1 | bellard | { |
1048 | baca51fa | bellard | fdrive_t *cur_drv; |
1049 | 8977f3c1 | bellard | uint32_t retval = 0;
|
1050 | 8977f3c1 | bellard | int pos, len;
|
1051 | 8977f3c1 | bellard | |
1052 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
1053 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1054 | baca51fa | bellard | fdctrl->state &= ~FD_CTRL_SLEEP; |
1055 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_CMD) {
|
1056 | 8977f3c1 | bellard | FLOPPY_ERROR("can't read data in CMD state\n");
|
1057 | 8977f3c1 | bellard | return 0; |
1058 | 8977f3c1 | bellard | } |
1059 | baca51fa | bellard | pos = fdctrl->data_pos; |
1060 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_DATA) {
|
1061 | 8977f3c1 | bellard | pos %= FD_SECTOR_LEN; |
1062 | 8977f3c1 | bellard | if (pos == 0) { |
1063 | baca51fa | bellard | len = fdctrl->data_len - fdctrl->data_pos; |
1064 | 8977f3c1 | bellard | if (len > FD_SECTOR_LEN)
|
1065 | 8977f3c1 | bellard | len = FD_SECTOR_LEN; |
1066 | 8977f3c1 | bellard | bdrv_read(cur_drv->bs, fd_sector(cur_drv), |
1067 | baca51fa | bellard | fdctrl->fifo, len); |
1068 | 8977f3c1 | bellard | } |
1069 | 8977f3c1 | bellard | } |
1070 | baca51fa | bellard | retval = fdctrl->fifo[pos]; |
1071 | baca51fa | bellard | if (++fdctrl->data_pos == fdctrl->data_len) {
|
1072 | baca51fa | bellard | fdctrl->data_pos = 0;
|
1073 | 8977f3c1 | bellard | /* Switch from transfert mode to status mode
|
1074 | 8977f3c1 | bellard | * then from status mode to command mode
|
1075 | 8977f3c1 | bellard | */
|
1076 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_DATA)
|
1077 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x20, 0x00, 0x00); |
1078 | 8977f3c1 | bellard | else
|
1079 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1080 | 8977f3c1 | bellard | } |
1081 | 8977f3c1 | bellard | FLOPPY_DPRINTF("data register: 0x%02x\n", retval);
|
1082 | 8977f3c1 | bellard | |
1083 | 8977f3c1 | bellard | return retval;
|
1084 | 8977f3c1 | bellard | } |
1085 | 8977f3c1 | bellard | |
1086 | baca51fa | bellard | static void fdctrl_format_sector (fdctrl_t *fdctrl) |
1087 | 8977f3c1 | bellard | { |
1088 | baca51fa | bellard | fdrive_t *cur_drv; |
1089 | baca51fa | bellard | uint8_t kh, kt, ks; |
1090 | baca51fa | bellard | int did_seek;
|
1091 | 8977f3c1 | bellard | |
1092 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1093 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1094 | baca51fa | bellard | kt = fdctrl->fifo[6];
|
1095 | baca51fa | bellard | kh = fdctrl->fifo[7];
|
1096 | baca51fa | bellard | ks = fdctrl->fifo[8];
|
1097 | baca51fa | bellard | FLOPPY_DPRINTF("format sector at %d %d %02x %02x (%d)\n",
|
1098 | baca51fa | bellard | fdctrl->cur_drv, kh, kt, ks, |
1099 | baca51fa | bellard | _fd_sector(kh, kt, ks, cur_drv->last_sect)); |
1100 | baca51fa | bellard | did_seek = 0;
|
1101 | baca51fa | bellard | switch (fd_seek(cur_drv, kh, kt, ks, fdctrl->config & 0x40)) { |
1102 | baca51fa | bellard | case 2: |
1103 | baca51fa | bellard | /* sect too big */
|
1104 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x00, 0x00); |
1105 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
1106 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
1107 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
1108 | baca51fa | bellard | return;
|
1109 | baca51fa | bellard | case 3: |
1110 | baca51fa | bellard | /* track too big */
|
1111 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x80, 0x00); |
1112 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
1113 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
1114 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
1115 | baca51fa | bellard | return;
|
1116 | baca51fa | bellard | case 4: |
1117 | baca51fa | bellard | /* No seek enabled */
|
1118 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x40, 0x00, 0x00); |
1119 | baca51fa | bellard | fdctrl->fifo[3] = kt;
|
1120 | baca51fa | bellard | fdctrl->fifo[4] = kh;
|
1121 | baca51fa | bellard | fdctrl->fifo[5] = ks;
|
1122 | baca51fa | bellard | return;
|
1123 | baca51fa | bellard | case 1: |
1124 | baca51fa | bellard | did_seek = 1;
|
1125 | baca51fa | bellard | fdctrl->data_state |= FD_STATE_SEEK; |
1126 | baca51fa | bellard | break;
|
1127 | baca51fa | bellard | default:
|
1128 | baca51fa | bellard | break;
|
1129 | baca51fa | bellard | } |
1130 | baca51fa | bellard | memset(fdctrl->fifo, 0, FD_SECTOR_LEN);
|
1131 | baca51fa | bellard | if (cur_drv->bs == NULL || |
1132 | baca51fa | bellard | bdrv_write(cur_drv->bs, fd_sector(cur_drv), fdctrl->fifo, 1) < 0) { |
1133 | baca51fa | bellard | FLOPPY_ERROR("formating sector %d\n", fd_sector(cur_drv));
|
1134 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x60, 0x00, 0x00); |
1135 | baca51fa | bellard | } else {
|
1136 | baca51fa | bellard | if (cur_drv->sect == cur_drv->last_sect) {
|
1137 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_FORMAT; |
1138 | baca51fa | bellard | /* Last sector done */
|
1139 | baca51fa | bellard | if (FD_DID_SEEK(fdctrl->data_state))
|
1140 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x20, 0x00, 0x00); |
1141 | baca51fa | bellard | else
|
1142 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00); |
1143 | baca51fa | bellard | } else {
|
1144 | baca51fa | bellard | /* More to do */
|
1145 | baca51fa | bellard | fdctrl->data_pos = 0;
|
1146 | baca51fa | bellard | fdctrl->data_len = 4;
|
1147 | baca51fa | bellard | } |
1148 | baca51fa | bellard | } |
1149 | baca51fa | bellard | } |
1150 | baca51fa | bellard | |
1151 | baca51fa | bellard | static void fdctrl_write_data (fdctrl_t *fdctrl, uint32_t value) |
1152 | baca51fa | bellard | { |
1153 | baca51fa | bellard | fdrive_t *cur_drv; |
1154 | baca51fa | bellard | |
1155 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
1156 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1157 | 8977f3c1 | bellard | /* Reset mode */
|
1158 | baca51fa | bellard | if (fdctrl->state & FD_CTRL_RESET) {
|
1159 | 8977f3c1 | bellard | FLOPPY_DPRINTF("Floppy controler in RESET state !\n");
|
1160 | 8977f3c1 | bellard | return;
|
1161 | 8977f3c1 | bellard | } |
1162 | baca51fa | bellard | fdctrl->state &= ~FD_CTRL_SLEEP; |
1163 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_STATUS) {
|
1164 | 8977f3c1 | bellard | FLOPPY_ERROR("can't write data in status mode\n");
|
1165 | 8977f3c1 | bellard | return;
|
1166 | 8977f3c1 | bellard | } |
1167 | 8977f3c1 | bellard | /* Is it write command time ? */
|
1168 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_DATA) {
|
1169 | 8977f3c1 | bellard | /* FIFO data write */
|
1170 | baca51fa | bellard | fdctrl->fifo[fdctrl->data_pos++] = value; |
1171 | baca51fa | bellard | if (fdctrl->data_pos % FD_SECTOR_LEN == (FD_SECTOR_LEN - 1) || |
1172 | baca51fa | bellard | fdctrl->data_pos == fdctrl->data_len) { |
1173 | 8977f3c1 | bellard | bdrv_write(cur_drv->bs, fd_sector(cur_drv), |
1174 | baca51fa | bellard | fdctrl->fifo, FD_SECTOR_LEN); |
1175 | 8977f3c1 | bellard | } |
1176 | 8977f3c1 | bellard | /* Switch from transfert mode to status mode
|
1177 | 8977f3c1 | bellard | * then from status mode to command mode
|
1178 | 8977f3c1 | bellard | */
|
1179 | baca51fa | bellard | if (FD_STATE(fdctrl->data_state) == FD_STATE_DATA)
|
1180 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x20, 0x00, 0x00); |
1181 | 8977f3c1 | bellard | return;
|
1182 | 8977f3c1 | bellard | } |
1183 | baca51fa | bellard | if (fdctrl->data_pos == 0) { |
1184 | 8977f3c1 | bellard | /* Command */
|
1185 | 8977f3c1 | bellard | switch (value & 0x5F) { |
1186 | 8977f3c1 | bellard | case 0x46: |
1187 | 8977f3c1 | bellard | /* READ variants */
|
1188 | 8977f3c1 | bellard | FLOPPY_DPRINTF("READ command\n");
|
1189 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1190 | baca51fa | bellard | fdctrl->data_len = 9;
|
1191 | 8977f3c1 | bellard | goto enqueue;
|
1192 | 8977f3c1 | bellard | case 0x4C: |
1193 | 8977f3c1 | bellard | /* READ_DELETED variants */
|
1194 | 8977f3c1 | bellard | FLOPPY_DPRINTF("READ_DELETED command\n");
|
1195 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1196 | baca51fa | bellard | fdctrl->data_len = 9;
|
1197 | 8977f3c1 | bellard | goto enqueue;
|
1198 | 8977f3c1 | bellard | case 0x50: |
1199 | 8977f3c1 | bellard | /* SCAN_EQUAL variants */
|
1200 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SCAN_EQUAL command\n");
|
1201 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1202 | baca51fa | bellard | fdctrl->data_len = 9;
|
1203 | 8977f3c1 | bellard | goto enqueue;
|
1204 | 8977f3c1 | bellard | case 0x56: |
1205 | 8977f3c1 | bellard | /* VERIFY variants */
|
1206 | 8977f3c1 | bellard | FLOPPY_DPRINTF("VERIFY command\n");
|
1207 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1208 | baca51fa | bellard | fdctrl->data_len = 9;
|
1209 | 8977f3c1 | bellard | goto enqueue;
|
1210 | 8977f3c1 | bellard | case 0x59: |
1211 | 8977f3c1 | bellard | /* SCAN_LOW_OR_EQUAL variants */
|
1212 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SCAN_LOW_OR_EQUAL command\n");
|
1213 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1214 | baca51fa | bellard | fdctrl->data_len = 9;
|
1215 | 8977f3c1 | bellard | goto enqueue;
|
1216 | 8977f3c1 | bellard | case 0x5D: |
1217 | 8977f3c1 | bellard | /* SCAN_HIGH_OR_EQUAL variants */
|
1218 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SCAN_HIGH_OR_EQUAL command\n");
|
1219 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1220 | baca51fa | bellard | fdctrl->data_len = 9;
|
1221 | 8977f3c1 | bellard | goto enqueue;
|
1222 | 8977f3c1 | bellard | default:
|
1223 | 8977f3c1 | bellard | break;
|
1224 | 8977f3c1 | bellard | } |
1225 | 8977f3c1 | bellard | switch (value & 0x7F) { |
1226 | 8977f3c1 | bellard | case 0x45: |
1227 | 8977f3c1 | bellard | /* WRITE variants */
|
1228 | 8977f3c1 | bellard | FLOPPY_DPRINTF("WRITE command\n");
|
1229 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1230 | baca51fa | bellard | fdctrl->data_len = 9;
|
1231 | 8977f3c1 | bellard | goto enqueue;
|
1232 | 8977f3c1 | bellard | case 0x49: |
1233 | 8977f3c1 | bellard | /* WRITE_DELETED variants */
|
1234 | 8977f3c1 | bellard | FLOPPY_DPRINTF("WRITE_DELETED command\n");
|
1235 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1236 | baca51fa | bellard | fdctrl->data_len = 9;
|
1237 | 8977f3c1 | bellard | goto enqueue;
|
1238 | 8977f3c1 | bellard | default:
|
1239 | 8977f3c1 | bellard | break;
|
1240 | 8977f3c1 | bellard | } |
1241 | 8977f3c1 | bellard | switch (value) {
|
1242 | 8977f3c1 | bellard | case 0x03: |
1243 | 8977f3c1 | bellard | /* SPECIFY */
|
1244 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SPECIFY command\n");
|
1245 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1246 | baca51fa | bellard | fdctrl->data_len = 3;
|
1247 | 8977f3c1 | bellard | goto enqueue;
|
1248 | 8977f3c1 | bellard | case 0x04: |
1249 | 8977f3c1 | bellard | /* SENSE_DRIVE_STATUS */
|
1250 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SENSE_DRIVE_STATUS command\n");
|
1251 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1252 | baca51fa | bellard | fdctrl->data_len = 2;
|
1253 | 8977f3c1 | bellard | goto enqueue;
|
1254 | 8977f3c1 | bellard | case 0x07: |
1255 | 8977f3c1 | bellard | /* RECALIBRATE */
|
1256 | 8977f3c1 | bellard | FLOPPY_DPRINTF("RECALIBRATE command\n");
|
1257 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1258 | baca51fa | bellard | fdctrl->data_len = 2;
|
1259 | 8977f3c1 | bellard | goto enqueue;
|
1260 | 8977f3c1 | bellard | case 0x08: |
1261 | 8977f3c1 | bellard | /* SENSE_INTERRUPT_STATUS */
|
1262 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SENSE_INTERRUPT_STATUS command (%02x)\n",
|
1263 | baca51fa | bellard | fdctrl->int_status); |
1264 | 8977f3c1 | bellard | /* No parameters cmd: returns status if no interrupt */
|
1265 | baca51fa | bellard | fdctrl->fifo[0] =
|
1266 | baca51fa | bellard | fdctrl->int_status | (cur_drv->head << 2) | fdctrl->cur_drv;
|
1267 | baca51fa | bellard | fdctrl->fifo[1] = cur_drv->track;
|
1268 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 2, 0); |
1269 | baca51fa | bellard | fdctrl_reset_irq(fdctrl); |
1270 | baca51fa | bellard | fdctrl->int_status = 0xC0;
|
1271 | 8977f3c1 | bellard | return;
|
1272 | 8977f3c1 | bellard | case 0x0E: |
1273 | 8977f3c1 | bellard | /* DUMPREG */
|
1274 | 8977f3c1 | bellard | FLOPPY_DPRINTF("DUMPREG command\n");
|
1275 | 8977f3c1 | bellard | /* Drives position */
|
1276 | baca51fa | bellard | fdctrl->fifo[0] = drv0(fdctrl)->track;
|
1277 | baca51fa | bellard | fdctrl->fifo[1] = drv1(fdctrl)->track;
|
1278 | baca51fa | bellard | fdctrl->fifo[2] = 0; |
1279 | baca51fa | bellard | fdctrl->fifo[3] = 0; |
1280 | 8977f3c1 | bellard | /* timers */
|
1281 | baca51fa | bellard | fdctrl->fifo[4] = fdctrl->timer0;
|
1282 | baca51fa | bellard | fdctrl->fifo[5] = (fdctrl->timer1 << 1) | fdctrl->dma_en; |
1283 | baca51fa | bellard | fdctrl->fifo[6] = cur_drv->last_sect;
|
1284 | baca51fa | bellard | fdctrl->fifo[7] = (fdctrl->lock << 7) | |
1285 | 8977f3c1 | bellard | (cur_drv->perpendicular << 2);
|
1286 | baca51fa | bellard | fdctrl->fifo[8] = fdctrl->config;
|
1287 | baca51fa | bellard | fdctrl->fifo[9] = fdctrl->precomp_trk;
|
1288 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 10, 0); |
1289 | 8977f3c1 | bellard | return;
|
1290 | 8977f3c1 | bellard | case 0x0F: |
1291 | 8977f3c1 | bellard | /* SEEK */
|
1292 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SEEK command\n");
|
1293 | 8977f3c1 | bellard | /* 2 parameters cmd */
|
1294 | baca51fa | bellard | fdctrl->data_len = 3;
|
1295 | 8977f3c1 | bellard | goto enqueue;
|
1296 | 8977f3c1 | bellard | case 0x10: |
1297 | 8977f3c1 | bellard | /* VERSION */
|
1298 | 8977f3c1 | bellard | FLOPPY_DPRINTF("VERSION command\n");
|
1299 | 8977f3c1 | bellard | /* No parameters cmd */
|
1300 | 8977f3c1 | bellard | /* Controler's version */
|
1301 | baca51fa | bellard | fdctrl->fifo[0] = fdctrl->version;
|
1302 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 1); |
1303 | 8977f3c1 | bellard | return;
|
1304 | 8977f3c1 | bellard | case 0x12: |
1305 | 8977f3c1 | bellard | /* PERPENDICULAR_MODE */
|
1306 | 8977f3c1 | bellard | FLOPPY_DPRINTF("PERPENDICULAR_MODE command\n");
|
1307 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1308 | baca51fa | bellard | fdctrl->data_len = 2;
|
1309 | 8977f3c1 | bellard | goto enqueue;
|
1310 | 8977f3c1 | bellard | case 0x13: |
1311 | 8977f3c1 | bellard | /* CONFIGURE */
|
1312 | 8977f3c1 | bellard | FLOPPY_DPRINTF("CONFIGURE command\n");
|
1313 | 8977f3c1 | bellard | /* 3 parameters cmd */
|
1314 | baca51fa | bellard | fdctrl->data_len = 4;
|
1315 | 8977f3c1 | bellard | goto enqueue;
|
1316 | 8977f3c1 | bellard | case 0x14: |
1317 | 8977f3c1 | bellard | /* UNLOCK */
|
1318 | 8977f3c1 | bellard | FLOPPY_DPRINTF("UNLOCK command\n");
|
1319 | 8977f3c1 | bellard | /* No parameters cmd */
|
1320 | baca51fa | bellard | fdctrl->lock = 0;
|
1321 | baca51fa | bellard | fdctrl->fifo[0] = 0; |
1322 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 0); |
1323 | 8977f3c1 | bellard | return;
|
1324 | 8977f3c1 | bellard | case 0x17: |
1325 | 8977f3c1 | bellard | /* POWERDOWN_MODE */
|
1326 | 8977f3c1 | bellard | FLOPPY_DPRINTF("POWERDOWN_MODE command\n");
|
1327 | 8977f3c1 | bellard | /* 2 parameters cmd */
|
1328 | baca51fa | bellard | fdctrl->data_len = 3;
|
1329 | 8977f3c1 | bellard | goto enqueue;
|
1330 | 8977f3c1 | bellard | case 0x18: |
1331 | 8977f3c1 | bellard | /* PART_ID */
|
1332 | 8977f3c1 | bellard | FLOPPY_DPRINTF("PART_ID command\n");
|
1333 | 8977f3c1 | bellard | /* No parameters cmd */
|
1334 | baca51fa | bellard | fdctrl->fifo[0] = 0x41; /* Stepping 1 */ |
1335 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 0); |
1336 | 8977f3c1 | bellard | return;
|
1337 | 8977f3c1 | bellard | case 0x2C: |
1338 | 8977f3c1 | bellard | /* SAVE */
|
1339 | 8977f3c1 | bellard | FLOPPY_DPRINTF("SAVE command\n");
|
1340 | 8977f3c1 | bellard | /* No parameters cmd */
|
1341 | baca51fa | bellard | fdctrl->fifo[0] = 0; |
1342 | baca51fa | bellard | fdctrl->fifo[1] = 0; |
1343 | 8977f3c1 | bellard | /* Drives position */
|
1344 | baca51fa | bellard | fdctrl->fifo[2] = drv0(fdctrl)->track;
|
1345 | baca51fa | bellard | fdctrl->fifo[3] = drv1(fdctrl)->track;
|
1346 | baca51fa | bellard | fdctrl->fifo[4] = 0; |
1347 | baca51fa | bellard | fdctrl->fifo[5] = 0; |
1348 | 8977f3c1 | bellard | /* timers */
|
1349 | baca51fa | bellard | fdctrl->fifo[6] = fdctrl->timer0;
|
1350 | baca51fa | bellard | fdctrl->fifo[7] = fdctrl->timer1;
|
1351 | baca51fa | bellard | fdctrl->fifo[8] = cur_drv->last_sect;
|
1352 | baca51fa | bellard | fdctrl->fifo[9] = (fdctrl->lock << 7) | |
1353 | 8977f3c1 | bellard | (cur_drv->perpendicular << 2);
|
1354 | baca51fa | bellard | fdctrl->fifo[10] = fdctrl->config;
|
1355 | baca51fa | bellard | fdctrl->fifo[11] = fdctrl->precomp_trk;
|
1356 | baca51fa | bellard | fdctrl->fifo[12] = fdctrl->pwrd;
|
1357 | baca51fa | bellard | fdctrl->fifo[13] = 0; |
1358 | baca51fa | bellard | fdctrl->fifo[14] = 0; |
1359 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 15, 1); |
1360 | 8977f3c1 | bellard | return;
|
1361 | 8977f3c1 | bellard | case 0x33: |
1362 | 8977f3c1 | bellard | /* OPTION */
|
1363 | 8977f3c1 | bellard | FLOPPY_DPRINTF("OPTION command\n");
|
1364 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1365 | baca51fa | bellard | fdctrl->data_len = 2;
|
1366 | 8977f3c1 | bellard | goto enqueue;
|
1367 | 8977f3c1 | bellard | case 0x42: |
1368 | 8977f3c1 | bellard | /* READ_TRACK */
|
1369 | 8977f3c1 | bellard | FLOPPY_DPRINTF("READ_TRACK command\n");
|
1370 | 8977f3c1 | bellard | /* 8 parameters cmd */
|
1371 | baca51fa | bellard | fdctrl->data_len = 9;
|
1372 | 8977f3c1 | bellard | goto enqueue;
|
1373 | 8977f3c1 | bellard | case 0x4A: |
1374 | 8977f3c1 | bellard | /* READ_ID */
|
1375 | 8977f3c1 | bellard | FLOPPY_DPRINTF("READ_ID command\n");
|
1376 | 8977f3c1 | bellard | /* 1 parameter cmd */
|
1377 | baca51fa | bellard | fdctrl->data_len = 2;
|
1378 | 8977f3c1 | bellard | goto enqueue;
|
1379 | 8977f3c1 | bellard | case 0x4C: |
1380 | 8977f3c1 | bellard | /* RESTORE */
|
1381 | 8977f3c1 | bellard | FLOPPY_DPRINTF("RESTORE command\n");
|
1382 | 8977f3c1 | bellard | /* 17 parameters cmd */
|
1383 | baca51fa | bellard | fdctrl->data_len = 18;
|
1384 | 8977f3c1 | bellard | goto enqueue;
|
1385 | 8977f3c1 | bellard | case 0x4D: |
1386 | 8977f3c1 | bellard | /* FORMAT_TRACK */
|
1387 | 8977f3c1 | bellard | FLOPPY_DPRINTF("FORMAT_TRACK command\n");
|
1388 | 8977f3c1 | bellard | /* 5 parameters cmd */
|
1389 | baca51fa | bellard | fdctrl->data_len = 6;
|
1390 | 8977f3c1 | bellard | goto enqueue;
|
1391 | 8977f3c1 | bellard | case 0x8E: |
1392 | 8977f3c1 | bellard | /* DRIVE_SPECIFICATION_COMMAND */
|
1393 | 8977f3c1 | bellard | FLOPPY_DPRINTF("DRIVE_SPECIFICATION_COMMAND command\n");
|
1394 | 8977f3c1 | bellard | /* 5 parameters cmd */
|
1395 | baca51fa | bellard | fdctrl->data_len = 6;
|
1396 | 8977f3c1 | bellard | goto enqueue;
|
1397 | 8977f3c1 | bellard | case 0x8F: |
1398 | 8977f3c1 | bellard | /* RELATIVE_SEEK_OUT */
|
1399 | 8977f3c1 | bellard | FLOPPY_DPRINTF("RELATIVE_SEEK_OUT command\n");
|
1400 | 8977f3c1 | bellard | /* 2 parameters cmd */
|
1401 | baca51fa | bellard | fdctrl->data_len = 3;
|
1402 | 8977f3c1 | bellard | goto enqueue;
|
1403 | 8977f3c1 | bellard | case 0x94: |
1404 | 8977f3c1 | bellard | /* LOCK */
|
1405 | 8977f3c1 | bellard | FLOPPY_DPRINTF("LOCK command\n");
|
1406 | 8977f3c1 | bellard | /* No parameters cmd */
|
1407 | baca51fa | bellard | fdctrl->lock = 1;
|
1408 | baca51fa | bellard | fdctrl->fifo[0] = 0x10; |
1409 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 1); |
1410 | 8977f3c1 | bellard | return;
|
1411 | 8977f3c1 | bellard | case 0xCD: |
1412 | 8977f3c1 | bellard | /* FORMAT_AND_WRITE */
|
1413 | 8977f3c1 | bellard | FLOPPY_DPRINTF("FORMAT_AND_WRITE command\n");
|
1414 | 8977f3c1 | bellard | /* 10 parameters cmd */
|
1415 | baca51fa | bellard | fdctrl->data_len = 11;
|
1416 | 8977f3c1 | bellard | goto enqueue;
|
1417 | 8977f3c1 | bellard | case 0xCF: |
1418 | 8977f3c1 | bellard | /* RELATIVE_SEEK_IN */
|
1419 | 8977f3c1 | bellard | FLOPPY_DPRINTF("RELATIVE_SEEK_IN command\n");
|
1420 | 8977f3c1 | bellard | /* 2 parameters cmd */
|
1421 | baca51fa | bellard | fdctrl->data_len = 3;
|
1422 | 8977f3c1 | bellard | goto enqueue;
|
1423 | 8977f3c1 | bellard | default:
|
1424 | 8977f3c1 | bellard | /* Unknown command */
|
1425 | 8977f3c1 | bellard | FLOPPY_ERROR("unknown command: 0x%02x\n", value);
|
1426 | baca51fa | bellard | fdctrl_unimplemented(fdctrl); |
1427 | 8977f3c1 | bellard | return;
|
1428 | 8977f3c1 | bellard | } |
1429 | 8977f3c1 | bellard | } |
1430 | 8977f3c1 | bellard | enqueue:
|
1431 | baca51fa | bellard | FLOPPY_DPRINTF("%s: %02x\n", __func__, value);
|
1432 | baca51fa | bellard | fdctrl->fifo[fdctrl->data_pos] = value; |
1433 | baca51fa | bellard | if (++fdctrl->data_pos == fdctrl->data_len) {
|
1434 | 8977f3c1 | bellard | /* We now have all parameters
|
1435 | 8977f3c1 | bellard | * and will be able to treat the command
|
1436 | 8977f3c1 | bellard | */
|
1437 | baca51fa | bellard | if (fdctrl->data_state & FD_STATE_FORMAT) {
|
1438 | baca51fa | bellard | fdctrl_format_sector(fdctrl); |
1439 | baca51fa | bellard | return;
|
1440 | baca51fa | bellard | } |
1441 | baca51fa | bellard | switch (fdctrl->fifo[0] & 0x1F) { |
1442 | 8977f3c1 | bellard | case 0x06: |
1443 | 8977f3c1 | bellard | { |
1444 | 8977f3c1 | bellard | /* READ variants */
|
1445 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat READ command\n");
|
1446 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_READ); |
1447 | 8977f3c1 | bellard | return;
|
1448 | 8977f3c1 | bellard | } |
1449 | 8977f3c1 | bellard | case 0x0C: |
1450 | 8977f3c1 | bellard | /* READ_DELETED variants */
|
1451 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat READ_DELETED command\n");
|
1452 | 8977f3c1 | bellard | FLOPPY_ERROR("treat READ_DELETED command\n");
|
1453 | baca51fa | bellard | fdctrl_start_transfer_del(fdctrl, FD_DIR_READ); |
1454 | 8977f3c1 | bellard | return;
|
1455 | 8977f3c1 | bellard | case 0x16: |
1456 | 8977f3c1 | bellard | /* VERIFY variants */
|
1457 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat VERIFY command\n");
|
1458 | 8977f3c1 | bellard | FLOPPY_ERROR("treat VERIFY command\n");
|
1459 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x20, 0x00, 0x00); |
1460 | 8977f3c1 | bellard | return;
|
1461 | 8977f3c1 | bellard | case 0x10: |
1462 | 8977f3c1 | bellard | /* SCAN_EQUAL variants */
|
1463 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat SCAN_EQUAL command\n");
|
1464 | 8977f3c1 | bellard | FLOPPY_ERROR("treat SCAN_EQUAL command\n");
|
1465 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_SCANE); |
1466 | 8977f3c1 | bellard | return;
|
1467 | 8977f3c1 | bellard | case 0x19: |
1468 | 8977f3c1 | bellard | /* SCAN_LOW_OR_EQUAL variants */
|
1469 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat SCAN_LOW_OR_EQUAL command\n");
|
1470 | 8977f3c1 | bellard | FLOPPY_ERROR("treat SCAN_LOW_OR_EQUAL command\n");
|
1471 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_SCANL); |
1472 | 8977f3c1 | bellard | return;
|
1473 | 8977f3c1 | bellard | case 0x1D: |
1474 | 8977f3c1 | bellard | /* SCAN_HIGH_OR_EQUAL variants */
|
1475 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat SCAN_HIGH_OR_EQUAL command\n");
|
1476 | 8977f3c1 | bellard | FLOPPY_ERROR("treat SCAN_HIGH_OR_EQUAL command\n");
|
1477 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_SCANH); |
1478 | 8977f3c1 | bellard | return;
|
1479 | 8977f3c1 | bellard | default:
|
1480 | 8977f3c1 | bellard | break;
|
1481 | 8977f3c1 | bellard | } |
1482 | baca51fa | bellard | switch (fdctrl->fifo[0] & 0x3F) { |
1483 | 8977f3c1 | bellard | case 0x05: |
1484 | 8977f3c1 | bellard | /* WRITE variants */
|
1485 | baca51fa | bellard | FLOPPY_DPRINTF("treat WRITE command (%02x)\n", fdctrl->fifo[0]); |
1486 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_WRITE); |
1487 | 8977f3c1 | bellard | return;
|
1488 | 8977f3c1 | bellard | case 0x09: |
1489 | 8977f3c1 | bellard | /* WRITE_DELETED variants */
|
1490 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat WRITE_DELETED command\n");
|
1491 | 8977f3c1 | bellard | FLOPPY_ERROR("treat WRITE_DELETED command\n");
|
1492 | baca51fa | bellard | fdctrl_start_transfer_del(fdctrl, FD_DIR_WRITE); |
1493 | 8977f3c1 | bellard | return;
|
1494 | 8977f3c1 | bellard | default:
|
1495 | 8977f3c1 | bellard | break;
|
1496 | 8977f3c1 | bellard | } |
1497 | baca51fa | bellard | switch (fdctrl->fifo[0]) { |
1498 | 8977f3c1 | bellard | case 0x03: |
1499 | 8977f3c1 | bellard | /* SPECIFY */
|
1500 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat SPECIFY command\n");
|
1501 | baca51fa | bellard | fdctrl->timer0 = (fdctrl->fifo[1] >> 4) & 0xF; |
1502 | baca51fa | bellard | fdctrl->timer1 = fdctrl->fifo[1] >> 1; |
1503 | baca51fa | bellard | fdctrl->dma_en = 1 - (fdctrl->fifo[2] & 1) ; |
1504 | 8977f3c1 | bellard | /* No result back */
|
1505 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1506 | 8977f3c1 | bellard | break;
|
1507 | 8977f3c1 | bellard | case 0x04: |
1508 | 8977f3c1 | bellard | /* SENSE_DRIVE_STATUS */
|
1509 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat SENSE_DRIVE_STATUS command\n");
|
1510 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1511 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1512 | baca51fa | bellard | cur_drv->head = (fdctrl->fifo[1] >> 2) & 1; |
1513 | 8977f3c1 | bellard | /* 1 Byte status back */
|
1514 | baca51fa | bellard | fdctrl->fifo[0] = (cur_drv->ro << 6) | |
1515 | 8977f3c1 | bellard | (cur_drv->track == 0 ? 0x10 : 0x00) | |
1516 | baca51fa | bellard | fdctrl->cur_drv; |
1517 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 0); |
1518 | 8977f3c1 | bellard | break;
|
1519 | 8977f3c1 | bellard | case 0x07: |
1520 | 8977f3c1 | bellard | /* RECALIBRATE */
|
1521 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat RECALIBRATE command\n");
|
1522 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1523 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1524 | 8977f3c1 | bellard | fd_recalibrate(cur_drv); |
1525 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1526 | 8977f3c1 | bellard | /* Raise Interrupt */
|
1527 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x20);
|
1528 | 8977f3c1 | bellard | break;
|
1529 | 8977f3c1 | bellard | case 0x0F: |
1530 | 8977f3c1 | bellard | /* SEEK */
|
1531 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat SEEK command\n");
|
1532 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1533 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1534 | baca51fa | bellard | fd_start(cur_drv); |
1535 | baca51fa | bellard | if (fdctrl->fifo[2] <= cur_drv->track) |
1536 | 8977f3c1 | bellard | cur_drv->dir = 1;
|
1537 | 8977f3c1 | bellard | else
|
1538 | 8977f3c1 | bellard | cur_drv->dir = 0;
|
1539 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1540 | baca51fa | bellard | if (fdctrl->fifo[2] > cur_drv->max_track) { |
1541 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x60);
|
1542 | 8977f3c1 | bellard | } else {
|
1543 | baca51fa | bellard | cur_drv->track = fdctrl->fifo[2];
|
1544 | 8977f3c1 | bellard | /* Raise Interrupt */
|
1545 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x20);
|
1546 | 8977f3c1 | bellard | } |
1547 | 8977f3c1 | bellard | break;
|
1548 | 8977f3c1 | bellard | case 0x12: |
1549 | 8977f3c1 | bellard | /* PERPENDICULAR_MODE */
|
1550 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat PERPENDICULAR_MODE command\n");
|
1551 | baca51fa | bellard | if (fdctrl->fifo[1] & 0x80) |
1552 | baca51fa | bellard | cur_drv->perpendicular = fdctrl->fifo[1] & 0x7; |
1553 | 8977f3c1 | bellard | /* No result back */
|
1554 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1555 | 8977f3c1 | bellard | break;
|
1556 | 8977f3c1 | bellard | case 0x13: |
1557 | 8977f3c1 | bellard | /* CONFIGURE */
|
1558 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat CONFIGURE command\n");
|
1559 | baca51fa | bellard | fdctrl->config = fdctrl->fifo[2];
|
1560 | baca51fa | bellard | fdctrl->precomp_trk = fdctrl->fifo[3];
|
1561 | 8977f3c1 | bellard | /* No result back */
|
1562 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1563 | 8977f3c1 | bellard | break;
|
1564 | 8977f3c1 | bellard | case 0x17: |
1565 | 8977f3c1 | bellard | /* POWERDOWN_MODE */
|
1566 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat POWERDOWN_MODE command\n");
|
1567 | baca51fa | bellard | fdctrl->pwrd = fdctrl->fifo[1];
|
1568 | baca51fa | bellard | fdctrl->fifo[0] = fdctrl->fifo[1]; |
1569 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 1); |
1570 | 8977f3c1 | bellard | break;
|
1571 | 8977f3c1 | bellard | case 0x33: |
1572 | 8977f3c1 | bellard | /* OPTION */
|
1573 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat OPTION command\n");
|
1574 | 8977f3c1 | bellard | /* No result back */
|
1575 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1576 | 8977f3c1 | bellard | break;
|
1577 | 8977f3c1 | bellard | case 0x42: |
1578 | 8977f3c1 | bellard | /* READ_TRACK */
|
1579 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat READ_TRACK command\n");
|
1580 | 8977f3c1 | bellard | FLOPPY_ERROR("treat READ_TRACK command\n");
|
1581 | baca51fa | bellard | fdctrl_start_transfer(fdctrl, FD_DIR_READ); |
1582 | 8977f3c1 | bellard | break;
|
1583 | 8977f3c1 | bellard | case 0x4A: |
1584 | 8977f3c1 | bellard | /* READ_ID */
|
1585 | baca51fa | bellard | FLOPPY_DPRINTF("treat READ_ID command\n");
|
1586 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00); |
1587 | 8977f3c1 | bellard | break;
|
1588 | 8977f3c1 | bellard | case 0x4C: |
1589 | 8977f3c1 | bellard | /* RESTORE */
|
1590 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat RESTORE command\n");
|
1591 | 8977f3c1 | bellard | /* Drives position */
|
1592 | baca51fa | bellard | drv0(fdctrl)->track = fdctrl->fifo[3];
|
1593 | baca51fa | bellard | drv1(fdctrl)->track = fdctrl->fifo[4];
|
1594 | 8977f3c1 | bellard | /* timers */
|
1595 | baca51fa | bellard | fdctrl->timer0 = fdctrl->fifo[7];
|
1596 | baca51fa | bellard | fdctrl->timer1 = fdctrl->fifo[8];
|
1597 | baca51fa | bellard | cur_drv->last_sect = fdctrl->fifo[9];
|
1598 | baca51fa | bellard | fdctrl->lock = fdctrl->fifo[10] >> 7; |
1599 | baca51fa | bellard | cur_drv->perpendicular = (fdctrl->fifo[10] >> 2) & 0xF; |
1600 | baca51fa | bellard | fdctrl->config = fdctrl->fifo[11];
|
1601 | baca51fa | bellard | fdctrl->precomp_trk = fdctrl->fifo[12];
|
1602 | baca51fa | bellard | fdctrl->pwrd = fdctrl->fifo[13];
|
1603 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1604 | 8977f3c1 | bellard | break;
|
1605 | 8977f3c1 | bellard | case 0x4D: |
1606 | 8977f3c1 | bellard | /* FORMAT_TRACK */
|
1607 | baca51fa | bellard | FLOPPY_DPRINTF("treat FORMAT_TRACK command\n");
|
1608 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1609 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1610 | baca51fa | bellard | fdctrl->data_state |= FD_STATE_FORMAT; |
1611 | baca51fa | bellard | if (fdctrl->fifo[0] & 0x80) |
1612 | baca51fa | bellard | fdctrl->data_state |= FD_STATE_MULTI; |
1613 | baca51fa | bellard | else
|
1614 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_MULTI; |
1615 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_SEEK; |
1616 | baca51fa | bellard | cur_drv->bps = |
1617 | baca51fa | bellard | fdctrl->fifo[2] > 7 ? 16384 : 128 << fdctrl->fifo[2]; |
1618 | baca51fa | bellard | #if 0
|
1619 | baca51fa | bellard | cur_drv->last_sect =
|
1620 | baca51fa | bellard | cur_drv->flags & FDISK_DBL_SIDES ? fdctrl->fifo[3] :
|
1621 | baca51fa | bellard | fdctrl->fifo[3] / 2;
|
1622 | baca51fa | bellard | #else
|
1623 | baca51fa | bellard | cur_drv->last_sect = fdctrl->fifo[3];
|
1624 | baca51fa | bellard | #endif
|
1625 | baca51fa | bellard | /* Bochs BIOS is buggy and don't send format informations
|
1626 | baca51fa | bellard | * for each sector. So, pretend all's done right now...
|
1627 | baca51fa | bellard | */
|
1628 | baca51fa | bellard | fdctrl->data_state &= ~FD_STATE_FORMAT; |
1629 | baca51fa | bellard | fdctrl_stop_transfer(fdctrl, 0x00, 0x00, 0x00); |
1630 | 8977f3c1 | bellard | break;
|
1631 | 8977f3c1 | bellard | case 0x8E: |
1632 | 8977f3c1 | bellard | /* DRIVE_SPECIFICATION_COMMAND */
|
1633 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat DRIVE_SPECIFICATION_COMMAND command\n");
|
1634 | baca51fa | bellard | if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x80) { |
1635 | 8977f3c1 | bellard | /* Command parameters done */
|
1636 | baca51fa | bellard | if (fdctrl->fifo[fdctrl->data_pos - 1] & 0x40) { |
1637 | baca51fa | bellard | fdctrl->fifo[0] = fdctrl->fifo[1]; |
1638 | baca51fa | bellard | fdctrl->fifo[2] = 0; |
1639 | baca51fa | bellard | fdctrl->fifo[3] = 0; |
1640 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 4, 1); |
1641 | 8977f3c1 | bellard | } else {
|
1642 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1643 | 8977f3c1 | bellard | } |
1644 | baca51fa | bellard | } else if (fdctrl->data_len > 7) { |
1645 | 8977f3c1 | bellard | /* ERROR */
|
1646 | baca51fa | bellard | fdctrl->fifo[0] = 0x80 | |
1647 | baca51fa | bellard | (cur_drv->head << 2) | fdctrl->cur_drv;
|
1648 | baca51fa | bellard | fdctrl_set_fifo(fdctrl, 1, 1); |
1649 | 8977f3c1 | bellard | } |
1650 | 8977f3c1 | bellard | break;
|
1651 | 8977f3c1 | bellard | case 0x8F: |
1652 | 8977f3c1 | bellard | /* RELATIVE_SEEK_OUT */
|
1653 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat RELATIVE_SEEK_OUT command\n");
|
1654 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1655 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1656 | baca51fa | bellard | fd_start(cur_drv); |
1657 | 8977f3c1 | bellard | cur_drv->dir = 0;
|
1658 | baca51fa | bellard | if (fdctrl->fifo[2] + cur_drv->track >= cur_drv->max_track) { |
1659 | baca51fa | bellard | cur_drv->track = cur_drv->max_track - 1;
|
1660 | baca51fa | bellard | } else {
|
1661 | baca51fa | bellard | cur_drv->track += fdctrl->fifo[2];
|
1662 | 8977f3c1 | bellard | } |
1663 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1664 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x20);
|
1665 | 8977f3c1 | bellard | break;
|
1666 | 8977f3c1 | bellard | case 0xCD: |
1667 | 8977f3c1 | bellard | /* FORMAT_AND_WRITE */
|
1668 | 8977f3c1 | bellard | // FLOPPY_DPRINTF("treat FORMAT_AND_WRITE command\n");
|
1669 | 8977f3c1 | bellard | FLOPPY_ERROR("treat FORMAT_AND_WRITE command\n");
|
1670 | baca51fa | bellard | fdctrl_unimplemented(fdctrl); |
1671 | 8977f3c1 | bellard | break;
|
1672 | 8977f3c1 | bellard | case 0xCF: |
1673 | 8977f3c1 | bellard | /* RELATIVE_SEEK_IN */
|
1674 | 8977f3c1 | bellard | FLOPPY_DPRINTF("treat RELATIVE_SEEK_IN command\n");
|
1675 | baca51fa | bellard | fdctrl->cur_drv = fdctrl->fifo[1] & 1; |
1676 | baca51fa | bellard | cur_drv = get_cur_drv(fdctrl); |
1677 | baca51fa | bellard | fd_start(cur_drv); |
1678 | 8977f3c1 | bellard | cur_drv->dir = 1;
|
1679 | baca51fa | bellard | if (fdctrl->fifo[2] > cur_drv->track) { |
1680 | baca51fa | bellard | cur_drv->track = 0;
|
1681 | baca51fa | bellard | } else {
|
1682 | baca51fa | bellard | cur_drv->track -= fdctrl->fifo[2];
|
1683 | 8977f3c1 | bellard | } |
1684 | baca51fa | bellard | fdctrl_reset_fifo(fdctrl); |
1685 | baca51fa | bellard | /* Raise Interrupt */
|
1686 | baca51fa | bellard | fdctrl_raise_irq(fdctrl, 0x20);
|
1687 | 8977f3c1 | bellard | break;
|
1688 | 8977f3c1 | bellard | } |
1689 | 8977f3c1 | bellard | } |
1690 | 8977f3c1 | bellard | } |