src/mess/machine/wd17xx.c
| r6019 | r6020 | |
| 2 | 2 | |
| 3 | 3 | wd17xx.c |
| 4 | 4 | |
| 5 | | Implementations of the Western Digital 17xx and 19xx families of |
| 5 | Implementations of the Western Digital 17xx and 27xx families of |
| 6 | 6 | floppy disk controllers |
| 7 | 7 | |
| 8 | 8 | |
| 9 | Models: |
| 10 | |
| 11 | DAL DD Side Clock Remark |
| 12 | --------------------------------------------------------- |
| 13 | FD1771 1 or 2 MHz First model |
| 14 | FD1781 x 1 or 2 MHz |
| 15 | FD1791 x 1 or 2 MHz |
| 16 | FD1792 1 or 2 MHz |
| 17 | FD1793 x x 1 or 2 MHz |
| 18 | FD1794 x 1 or 2 MHz |
| 19 | FD1795 x x 1 or 2 MHz |
| 20 | FD1797 x x x 1 or 2 MHz |
| 21 | FD1761 x 1 MHz |
| 22 | FD1762 1 MHz ? |
| 23 | FD1763 x x 1 MHz |
| 24 | FD1764 x 1 MHz ? |
| 25 | FD1765 x x 1 MHz |
| 26 | FD1767 x x x 1 MHz |
| 27 | WD2791 x 1 or 2 MHz Internal data separator |
| 28 | WD2793 x x 1 or 2 MHz Internal data separator |
| 29 | WD2795 x x 1 or 2 MHz Internal data separator |
| 30 | WD2797 x x x 1 or 2 MHz Internal data separator |
| 31 | WD1770 x 8 MHz Motor On signal |
| 32 | WD1772 x 8 MHz Motor On signal, Faster stepping rates |
| 33 | WD1773 x 8 MHz Enable precomp line |
| 34 | |
| 35 | Notes: - In general, later models include all features of earlier models |
| 36 | - DAL: Data access lines, x = TRUE; otherwise inverted |
| 37 | - DD: Double density support |
| 38 | - Side: Has side select support |
| 39 | - ?: Unknown if it really exists |
| 40 | |
| 41 | Clones: |
| 42 | |
| 43 | - SMC FD179x |
| 44 | - Fujitsu MB8876 -> FD1791, MB8877 -> FD1793 |
| 45 | - VLSI VL177x |
| 46 | |
| 47 | |
| 48 | Changelog: |
| 49 | |
| 9 | 50 | Kevin Thacker |
| 10 | 51 | - Removed disk image code and replaced it with floppy drive functions. |
| 11 | 52 | Any disc image is now useable with this code. |
| r6019 | r6020 | |
| 239 | 280 | devcb_resolved_write_line out_intrq_func; |
| 240 | 281 | devcb_resolved_write_line out_drq_func; |
| 241 | 282 | |
| 242 | | /* state of input lines */ |
| 243 | | int rdy; /* ready, enable precomp */ |
| 244 | | int tr00; /* track 00 */ |
| 245 | | int idx; /* index */ |
| 246 | | int wprt; /* write protect */ |
| 283 | /* input lines */ |
| 284 | int mr; /* master reset */ |
| 285 | int rdy; /* ready, enable precomp */ |
| 286 | int tr00; /* track 00 */ |
| 287 | int idx; /* index */ |
| 288 | int wprt; /* write protect */ |
| 289 | int dden; /* double density */ |
| 247 | 290 | |
| 248 | | /* state of output lines */ |
| 249 | | int mo; /* motor on */ |
| 250 | | int dirc; /* direction */ |
| 251 | | int drq; /* data request */ |
| 252 | | int intrq; /* interrupt request */ |
| 291 | /* output lines */ |
| 292 | int mo; /* motor on */ |
| 293 | int dirc; /* direction */ |
| 294 | int drq; /* data request */ |
| 295 | int intrq; /* interrupt request */ |
| 253 | 296 | |
| 297 | /* register */ |
| 298 | UINT8 data_shift; |
| 299 | UINT8 data; |
| 300 | UINT8 track; |
| 301 | UINT8 sector; |
| 302 | UINT8 command; |
| 303 | UINT8 status; |
| 304 | |
| 254 | 305 | int stepping_rate[4]; /* track stepping rate in ms */ |
| 255 | 306 | |
| 307 | |
| 256 | 308 | DENSITY density; /* FM/MFM, single / double density */ |
| 257 | 309 | wd17xx_type_t type; |
| 258 | 310 | UINT8 track_reg; /* value of track register */ |
| 259 | | UINT8 data; /* value of data register */ |
| 260 | | UINT8 command; /* last command written */ |
| 261 | 311 | UINT8 command_type; /* last command type */ |
| 262 | | UINT8 sector; /* current sector # */ |
| 263 | 312 | UINT8 head; /* current head # */ |
| 264 | 313 | |
| 265 | 314 | UINT8 read_cmd; /* last read command issued */ |
| 266 | 315 | UINT8 write_cmd; /* last write command issued */ |
| 267 | 316 | INT8 direction; /* last step direction */ |
| 268 | 317 | |
| 269 | | UINT8 status; /* status register */ |
| 270 | 318 | UINT8 status_drq; /* status register data request bit */ |
| 271 | 319 | UINT8 status_ipl; /* status register toggle index pulse bit */ |
| 272 | 320 | UINT8 busy_count; /* how long to keep busy bit set */ |
| r6019 | r6020 | |
| 465 | 513 | |
| 466 | 514 | /* BUSY COUNT DOESN'T WORK PROPERLY! */ |
| 467 | 515 | |
| 468 | | static void wd17xx_restore(const device_config *device) |
| 516 | static void wd17xx_command_restore(const device_config *device) |
| 469 | 517 | { |
| 470 | 518 | wd1770_state *w = get_safe_token(device); |
| 471 | 519 | UINT8 step_counter; |
| r6019 | r6020 | |
| 500 | 548 | } |
| 501 | 549 | |
| 502 | 550 | /* update track reg */ |
| 503 | | w->track_reg = 0; |
| 551 | w->track = 0; |
| 504 | 552 | #if 0 |
| 505 | 553 | /* simulate seek time busy signal */ |
| 506 | 554 | w->busy_count = 0; //w->busy_count * ((w->data & FDC_STEP_RATE) + 1); |
| r6019 | r6020 | |
| 724 | 772 | { |
| 725 | 773 | /* record not found */ |
| 726 | 774 | w->status |= STA_2_REC_N_FND; |
| 727 | | //w->sector = w->track_reg; |
| 775 | //w->sector = w->track; |
| 728 | 776 | if (VERBOSE) |
| 729 | 777 | logerror("read id failed\n"); |
| 730 | 778 | |
| r6019 | r6020 | |
| 764 | 812 | if (floppy_drive_get_next_id(w->drive, w->hd, &id)) |
| 765 | 813 | { |
| 766 | 814 | /* compare track */ |
| 767 | | if (id.C == w->track_reg) |
| 815 | if (id.C == w->track) |
| 768 | 816 | { |
| 769 | 817 | /* compare head, if we were asked to */ |
| 770 | 818 | if (!wd17xx_has_side_select(device) || (id.H == w->head) || (w->head == (UINT8) ~0)) |
| r6019 | r6020 | |
| 808 | 856 | w->status |= STA_2_REC_N_FND; |
| 809 | 857 | |
| 810 | 858 | if (VERBOSE) |
| 811 | | logerror("track %d sector %d not found!\n", w->track_reg, w->sector); |
| 859 | logerror("track %d sector %d not found!\n", w->track, w->sector); |
| 812 | 860 | |
| 813 | 861 | wd17xx_complete_command(device, DELAY_ERROR); |
| 814 | 862 | |
| r6019 | r6020 | |
| 949 | 997 | if (floppy_drive_get_next_id(w->drive, w->hd, &id)) |
| 950 | 998 | { |
| 951 | 999 | /* compare track */ |
| 952 | | if (id.C == w->track_reg) |
| 1000 | if (id.C == w->track) |
| 953 | 1001 | { |
| 954 | 1002 | if (VERBOSE) |
| 955 | 1003 | logerror("seek verify succeeded!\n"); |
| r6019 | r6020 | |
| 1141 | 1189 | DEVICE HANDLERS |
| 1142 | 1190 | ***************************************************************************/ |
| 1143 | 1191 | |
| 1192 | /* master reset */ |
| 1193 | WRITE_LINE_DEVICE_HANDLER( wd17xx_mr_w ) |
| 1194 | { |
| 1195 | wd1770_state *w = get_safe_token(device); |
| 1196 | |
| 1197 | /* reset device when going from high to low */ |
| 1198 | if (w->mr && state == CLEAR_LINE) |
| 1199 | { |
| 1200 | w->command = 0x03; |
| 1201 | w->status &= ~STA_1_NOT_READY; /* ? */ |
| 1202 | } |
| 1203 | |
| 1204 | /* execute restore command when going from low to high */ |
| 1205 | if (w->mr == CLEAR_LINE && state) |
| 1206 | { |
| 1207 | wd17xx_command_restore(device); |
| 1208 | w->sector = 0x01; |
| 1209 | } |
| 1210 | |
| 1211 | w->mr = state; |
| 1212 | } |
| 1213 | |
| 1214 | /* ready and enable precomp (1773 only) */ |
| 1144 | 1215 | WRITE_LINE_DEVICE_HANDLER( wd17xx_rdy_w ) |
| 1145 | 1216 | { |
| 1146 | 1217 | wd1770_state *w = get_safe_token(device); |
| 1147 | 1218 | w->rdy = state; |
| 1148 | 1219 | } |
| 1149 | 1220 | |
| 1221 | /* motor on, 1770 and 1772 only */ |
| 1150 | 1222 | READ_LINE_DEVICE_HANDLER( wd17xx_mo_r ) |
| 1151 | 1223 | { |
| 1152 | 1224 | wd1770_state *w = get_safe_token(device); |
| 1153 | 1225 | return w->mo; |
| 1154 | 1226 | } |
| 1155 | 1227 | |
| 1228 | /* track zero */ |
| 1156 | 1229 | WRITE_LINE_DEVICE_HANDLER( wd17xx_tr00_w ) |
| 1157 | 1230 | { |
| 1158 | 1231 | wd1770_state *w = get_safe_token(device); |
| 1159 | 1232 | w->tr00 = state; |
| 1160 | 1233 | } |
| 1161 | 1234 | |
| 1235 | /* index pulse */ |
| 1162 | 1236 | WRITE_LINE_DEVICE_HANDLER( wd17xx_idx_w ) |
| 1163 | 1237 | { |
| 1164 | 1238 | wd1770_state *w = get_safe_token(device); |
| 1165 | 1239 | w->idx = state; |
| 1166 | 1240 | } |
| 1167 | 1241 | |
| 1242 | /* write protect status */ |
| 1168 | 1243 | WRITE_LINE_DEVICE_HANDLER( wd17xx_wprt_w ) |
| 1169 | 1244 | { |
| 1170 | 1245 | wd1770_state *w = get_safe_token(device); |
| 1171 | 1246 | w->wprt = state; |
| 1172 | 1247 | } |
| 1173 | 1248 | |
| 1249 | /* data request */ |
| 1174 | 1250 | READ_LINE_DEVICE_HANDLER( wd17xx_drq_r ) |
| 1175 | 1251 | { |
| 1176 | 1252 | wd1770_state *w = get_safe_token(device); |
| 1177 | 1253 | return w->drq; |
| 1178 | 1254 | } |
| 1179 | 1255 | |
| 1256 | /* interrupt request */ |
| 1180 | 1257 | READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r ) |
| 1181 | 1258 | { |
| 1182 | 1259 | wd1770_state *w = get_safe_token(device); |
| r6019 | r6020 | |
| 1246 | 1323 | wd1770_state *w = get_safe_token(device); |
| 1247 | 1324 | |
| 1248 | 1325 | if (VERBOSE) |
| 1249 | | logerror("wd17xx_track_r: $%02X\n", w->track_reg); |
| 1326 | logerror("wd17xx_track_r: $%02X\n", w->track); |
| 1250 | 1327 | |
| 1251 | | return w->track_reg; |
| 1328 | return w->track; |
| 1252 | 1329 | } |
| 1253 | 1330 | |
| 1254 | 1331 | /* read the FDC sector register */ |
| r6019 | r6020 | |
| 1509 | 1586 | if (VERBOSE) |
| 1510 | 1587 | logerror("wd17xx_command_w $%02X RESTORE\n", data); |
| 1511 | 1588 | |
| 1512 | | wd17xx_restore(device); |
| 1589 | wd17xx_command_restore(device); |
| 1513 | 1590 | } |
| 1514 | 1591 | |
| 1515 | 1592 | if ((data & ~FDC_MASK_TYPE_I) == FDC_SEEK) |
| r6019 | r6020 | |
| 1517 | 1594 | UINT8 newtrack; |
| 1518 | 1595 | |
| 1519 | 1596 | if (VERBOSE) |
| 1520 | | logerror("old track: $%02x new track: $%02x\n", w->track_reg, w->data); |
| 1597 | logerror("old track: $%02x new track: $%02x\n", w->track, w->data); |
| 1521 | 1598 | w->command_type = TYPE_I; |
| 1522 | 1599 | |
| 1523 | 1600 | /* setup step direction */ |
| 1524 | | if (w->track_reg < w->data) |
| 1601 | if (w->track < w->data) |
| 1525 | 1602 | { |
| 1526 | 1603 | if (VERBOSE) |
| 1527 | 1604 | logerror("direction: +1\n"); |
| 1528 | 1605 | |
| 1529 | 1606 | w->direction = 1; |
| 1530 | 1607 | } |
| 1531 | | else if (w->track_reg > w->data) |
| 1608 | else if (w->track > w->data) |
| 1532 | 1609 | { |
| 1533 | 1610 | if (VERBOSE) |
| 1534 | 1611 | logerror("direction: -1\n"); |
| r6019 | r6020 | |
| 1544 | 1621 | w->busy_count = 0; |
| 1545 | 1622 | |
| 1546 | 1623 | /* keep stepping until reached track programmed */ |
| 1547 | | while (w->track_reg != newtrack) |
| 1624 | while (w->track != newtrack) |
| 1548 | 1625 | { |
| 1549 | 1626 | /* update time to simulate seek time busy signal */ |
| 1550 | 1627 | w->busy_count++; |
| 1551 | 1628 | |
| 1552 | 1629 | /* update track reg */ |
| 1553 | | w->track_reg += w->direction; |
| 1630 | w->track += w->direction; |
| 1554 | 1631 | |
| 1555 | 1632 | floppy_drive_seek(w->drive, w->direction); |
| 1556 | 1633 | } |
| r6019 | r6020 | |
| 1577 | 1654 | floppy_drive_seek(w->drive, w->direction); |
| 1578 | 1655 | |
| 1579 | 1656 | if (data & FDC_STEP_UPDATE) |
| 1580 | | w->track_reg += w->direction; |
| 1657 | w->track += w->direction; |
| 1581 | 1658 | |
| 1582 | 1659 | #if 0 |
| 1583 | 1660 | wd17xx_set_intrq(device); |
| r6019 | r6020 | |
| 1600 | 1677 | floppy_drive_seek(w->drive, w->direction); |
| 1601 | 1678 | |
| 1602 | 1679 | if (data & FDC_STEP_UPDATE) |
| 1603 | | w->track_reg += w->direction; |
| 1680 | w->track += w->direction; |
| 1604 | 1681 | #if 0 |
| 1605 | 1682 | wd17xx_set_intrq(device); |
| 1606 | 1683 | #endif |
| r6019 | r6020 | |
| 1622 | 1699 | floppy_drive_seek(w->drive, w->direction); |
| 1623 | 1700 | |
| 1624 | 1701 | if (data & FDC_STEP_UPDATE) |
| 1625 | | w->track_reg += w->direction; |
| 1702 | w->track += w->direction; |
| 1626 | 1703 | |
| 1627 | 1704 | #if 0 |
| 1628 | 1705 | wd17xx_set_intrq(device); |
| r6019 | r6020 | |
| 1654 | 1731 | { |
| 1655 | 1732 | wd1770_state *w = get_safe_token(device); |
| 1656 | 1733 | |
| 1657 | | w->track_reg = data; |
| 1734 | w->track = data; |
| 1658 | 1735 | |
| 1659 | 1736 | if (VERBOSE) |
| 1660 | 1737 | logerror("wd17xx_track_w $%02X\n", data); |
| r6019 | r6020 | |
| 1764 | 1841 | /* model specific values */ |
| 1765 | 1842 | w->type = WD_TYPE_1770; |
| 1766 | 1843 | |
| 1844 | /* stepping rate depends on the clock */ |
| 1767 | 1845 | w->stepping_rate[0] = 6; |
| 1768 | 1846 | w->stepping_rate[1] = 12; |
| 1769 | 1847 | w->stepping_rate[2] = 20; |
| r6019 | r6020 | |
| 1787 | 1865 | |
| 1788 | 1866 | w->type = WD_TYPE_1772; |
| 1789 | 1867 | |
| 1868 | /* the 1772 has faster track stepping rates */ |
| 1790 | 1869 | w->stepping_rate[0] = 6; |
| 1791 | 1870 | w->stepping_rate[1] = 12; |
| 1792 | | w->stepping_rate[2] = 20; |
| 1793 | | w->stepping_rate[3] = 30; |
| 1871 | w->stepping_rate[2] = 2; |
| 1872 | w->stepping_rate[3] = 3; |
| 1794 | 1873 | } |
| 1795 | 1874 | |
| 1796 | 1875 | static DEVICE_START( wd1773 ) |
| r6019 | r6020 | |
| 1800 | 1879 | DEVICE_START_CALL(wd1770); |
| 1801 | 1880 | |
| 1802 | 1881 | w->type = WD_TYPE_1773; |
| 1803 | | |
| 1804 | | w->stepping_rate[0] = 6; |
| 1805 | | w->stepping_rate[1] = 12; |
| 1806 | | w->stepping_rate[2] = 2; |
| 1807 | | w->stepping_rate[3] = 3; |
| 1808 | 1882 | } |
| 1809 | 1883 | |
| 1810 | 1884 | static DEVICE_START( wd179x ) |
| r6019 | r6020 | |
| 1857 | 1931 | wd1770_state *w = get_safe_token(device); |
| 1858 | 1932 | int i; |
| 1859 | 1933 | |
| 1934 | /* set the default state of some input lines */ |
| 1935 | w->mr = ASSERT_LINE; |
| 1936 | w->wprt = ASSERT_LINE; |
| 1937 | w->dden = ASSERT_LINE; |
| 1938 | |
| 1860 | 1939 | for (i = 0; i < 4; i++) |
| 1861 | 1940 | { |
| 1862 | 1941 | if(w->intf->floppy_drive_tags[i]!=NULL) { |
| r6019 | r6020 | |
| 1874 | 1953 | w->hd = 0; |
| 1875 | 1954 | w->hld_count = 0; |
| 1876 | 1955 | |
| 1877 | | wd17xx_restore(device); |
| 1956 | wd17xx_command_restore(device); |
| 1878 | 1957 | } |
| 1879 | 1958 | |
| 1880 | 1959 | void wd17xx_reset(const device_config *device) |