src/mess/machine/smc92x4.c
| r8271 | r8272 | |
| 151 | 151 | UINT8 output2; /* UDC-internal register "output2" */ |
| 152 | 152 | |
| 153 | 153 | int selected_drive_type; |
| 154 | | /* We need to store the types, although this is not the case in the |
| 155 | | real hardware. The reason is that poll_drives wants to select the drives |
| 156 | | without knowing their kinds. In reality this does not matter, since we |
| 157 | | only check for the seek_complete line, but in our case, floppy and |
| 158 | | harddrive are pretty different, and we need to know which one to check. */ |
| 154 | // We need to store the types, although this is not the case in the |
| 155 | // real hardware. The reason is that poll_drives wants to select the |
| 156 | // drives without knowing their kinds. In reality this does not matter, |
| 157 | // since we only check for the seek_complete line, but in our case, |
| 158 | // floppy and harddrive are pretty different, and we need to know which |
| 159 | // one to check. |
| 159 | 160 | int types[4]; |
| 160 | 161 | int head_load_delay_enable; |
| 161 | 162 | int register_pointer; |
| r8271 | r8272 | |
| 248 | 249 | #if 0 |
| 249 | 250 | static void dump_contents(UINT8 *buffer, int length) |
| 250 | 251 | { |
| 251 | | for (int i=0; i < length; i+=16) |
| 252 | | { |
| 253 | | for (int j=0; j < 16; j+=2) |
| 254 | | { |
| 255 | | printf("%02x%02x ", buffer[i+j], buffer[i+j+1]); |
| 256 | | } |
| 257 | | printf("\n"); |
| 258 | | } |
| 252 | for (int i=0; i < length; i+=16) |
| 253 | { |
| 254 | for (int j=0; j < 16; j+=2) |
| 255 | { |
| 256 | printf("%02x%02x ", buffer[i+j], buffer[i+j+1]); |
| 257 | } |
| 258 | printf("\n"); |
| 259 | } |
| 259 | 260 | } |
| 260 | 261 | #endif |
| 261 | 262 | |
| r8271 | r8272 | |
| 269 | 270 | |
| 270 | 271 | static int image_is_single_density(running_device *current_floppy) |
| 271 | 272 | { |
| 272 | | floppy_image *image = flopimg_get_image(current_floppy); |
| 273 | floppy_image *image = flopimg_get_image(current_floppy); |
| 273 | 274 | return (floppy_get_track_size(image, 0, 0)<4000); |
| 274 | 275 | } |
| 275 | 276 | |
| r8271 | r8272 | |
| 650 | 651 | */ |
| 651 | 652 | static void update_id_regs(running_device *device, chrn_id_hd id) |
| 652 | 653 | { |
| 653 | | /* Flags for current head register. Note that the sizes are not in |
| 654 | | sequence (128, 256, 512, 1024). This is only interesting for AT |
| 655 | | mode. */ |
| 654 | // Flags for current head register. Note that the sizes are not in |
| 655 | // sequence (128, 256, 512, 1024). This is only interesting for AT |
| 656 | // mode. |
| 656 | 657 | UINT8 sizeflag[] = { 0x60, 0x00, 0x20, 0x40 }; |
| 657 | 658 | smc92x4_state *w = get_safe_token(device); |
| 658 | 659 | |
| r8271 | r8272 | |
| 682 | 683 | sync_latches_out(device); |
| 683 | 684 | sync_status_in(device); |
| 684 | 685 | |
| 685 | | /* Set command termination code. The error code is set first, and |
| 686 | | on success, it is cleared. */ |
| 686 | // Set command termination code. The error code is set first, and |
| 687 | // on success, it is cleared. |
| 687 | 688 | w->register_r[INT_STATUS] |= ST_TC_RDIDERR; |
| 688 | 689 | |
| 689 | 690 | /* Try to find an ID field. */ |
| r8271 | r8272 | |
| 784 | 785 | int foundsect = FALSE; |
| 785 | 786 | int des_cylinder = 0; |
| 786 | 787 | |
| 787 | | /* Set command termination code. The error code is set first, and |
| 788 | | on success, it is cleared. */ |
| 788 | // Set command termination code. The error code is set first, and |
| 789 | // on success, it is cleared. |
| 789 | 790 | w->register_r[INT_STATUS] |= ST_TC_SEEKERR; |
| 790 | 791 | |
| 791 | 792 | while (pass < maxtry && !foundsect) |
| r8271 | r8272 | |
| 865 | 866 | |
| 866 | 867 | current_floppy = (*w->intf->current_floppy)(); |
| 867 | 868 | |
| 868 | | /* Set command termination code. The error code is set first, and |
| 869 | | on success, it is cleared. */ |
| 869 | // Set command termination code. The error code is set first, and |
| 870 | // on success, it is cleared. |
| 870 | 871 | w->register_r[INT_STATUS] |= ST_TC_DATAERR; |
| 871 | 872 | |
| 872 | | /* Save the value. Note that the retry count is only in the first four |
| 873 | | bits, and it is stored in one's complement. In this implementation |
| 874 | | we don't work with it. */ |
| 873 | // Save the value. Note that the retry count is only in the first four |
| 874 | // bits, and it is stored in one's complement. In this implementation |
| 875 | // we don't work with it. |
| 875 | 876 | retry = w->register_w[RETRY_COUNT]; |
| 876 | 877 | |
| 877 | 878 | /* We are already at the correct sector (found by the verify sequence) */ |
| r8271 | r8272 | |
| 961 | 962 | |
| 962 | 963 | current_floppy = (*w->intf->current_floppy)(); |
| 963 | 964 | |
| 964 | | /* Set command termination code. The error code is set first, and |
| 965 | | on success, it is cleared. */ |
| 965 | // Set command termination code. The error code is set first, and |
| 966 | // on success, it is cleared. |
| 966 | 967 | w->register_r[INT_STATUS] |= ST_TC_DATAERR; |
| 967 | 968 | |
| 968 | | /* Save the value. Note that the retry count is only in the first four |
| 969 | | bits, and it is stored in one's complement. In this implementation |
| 970 | | we don't work with it. */ |
| 969 | // Save the value. Note that the retry count is only in the first four |
| 970 | // bits, and it is stored in one's complement. In this implementation |
| 971 | // we don't work with it. |
| 971 | 972 | retry = w->register_w[RETRY_COUNT]; |
| 972 | 973 | |
| 973 | 974 | /* Initiate the DMA. We assume the DMARQ is positive. */ |
| r8271 | r8272 | |
| 1147 | 1148 | } |
| 1148 | 1149 | else |
| 1149 | 1150 | { |
| 1150 | | /* printf("smc92x4 read sectors CYL=%02x, HEA=%02x, SEC=%02x, MOD=%02x, CNT=%02x, TRY=%02x\n", |
| 1151 | | w->register_w[DESIRED_CYLINDER], |
| 1152 | | w->register_w[DESIRED_HEAD], |
| 1153 | | w->register_w[DESIRED_SECTOR], |
| 1154 | | w->register_w[MODE], |
| 1155 | | w->register_w[SECTOR_COUNT], |
| 1156 | | w->register_w[RETRY_COUNT]); */ |
| 1157 | 1151 | smc92x4_timed_sector_read_request(device); |
| 1158 | 1152 | } |
| 1159 | 1153 | } |
| r8271 | r8272 | |
| 1284 | 1278 | { |
| 1285 | 1279 | smc92x4_state *w = get_safe_token(device); |
| 1286 | 1280 | int direction = (w->command & 0x02)? -1 : +1; |
| 1287 | | /* bit 0: 0 -> command ends after last seek pulse, 1 -> command |
| 1288 | | ends when the drive asserts the seek complete pin */ |
| 1281 | // bit 0: 0 -> command ends after last seek pulse, 1 -> command |
| 1282 | // ends when the drive asserts the seek complete pin |
| 1289 | 1283 | int buffered = w->command & 0x01; |
| 1290 | 1284 | |
| 1291 | 1285 | w->step_direction = direction; |
| r8271 | r8272 | |
| 1343 | 1337 | w->selected_drive_type = (driveparm>>2) & 0x03; |
| 1344 | 1338 | w->head_load_delay_enable = (driveparm>>4)&0x01; |
| 1345 | 1339 | |
| 1346 | | /* We need to store the type of the drive for the poll_drives command |
| 1347 | | to be able to correctly select the device (floppy or hard disk). */ |
| 1340 | // We need to store the type of the drive for the poll_drives command |
| 1341 | // to be able to correctly select the device (floppy or hard disk). |
| 1348 | 1342 | w->types[driveparm&0x03] = w->selected_drive_type; |
| 1349 | 1343 | |
| 1350 | | /* Copy the DMA registers to registers CURRENT_HEAD, CURRENT_CYLINDER, |
| 1351 | | and CURRENT_IDENT. This is required during formatting (p. 14) as the |
| 1352 | | format command reuses the registers for formatting parameters. */ |
| 1344 | // Copy the DMA registers to registers CURRENT_HEAD, CURRENT_CYLINDER, |
| 1345 | // and CURRENT_IDENT. This is required during formatting (p. 14) as the |
| 1346 | // format command reuses the registers for formatting parameters. |
| 1353 | 1347 | w->register_r[CURRENT_HEAD] = w->register_r[DMA7_0]; |
| 1354 | 1348 | w->register_r[CURRENT_CYLINDER] = w->register_r[DMA15_8]; |
| 1355 | 1349 | w->register_r[CURRENT_IDENT] = w->register_r[DMA23_16]; |
| r8271 | r8272 | |
| 1499 | 1493 | |
| 1500 | 1494 | UINT8 *buffer; |
| 1501 | 1495 | |
| 1502 | | /* Determine the track size. We cannot allow different sizes in this |
| 1503 | | design. */ |
| 1496 | /* Determine the track size. We cannot allow different sizes in this design. */ |
| 1504 | 1497 | int data_count = 0; |
| 1505 | 1498 | |
| 1506 | 1499 | sync_status_in(device); |
| 1507 | 1500 | |
| 1508 | 1501 | current_floppy = (*w->intf->current_floppy)(); |
| 1509 | | floppy = flopimg_get_image(current_floppy); |
| 1502 | floppy = flopimg_get_image(current_floppy); |
| 1510 | 1503 | |
| 1511 | 1504 | if (floppy != NULL) |
| 1512 | 1505 | data_count = floppy_get_track_size(floppy, 0, 0); |
| 1513 | 1506 | |
| 1514 | | if (data_count==0) |
| 1515 | | { |
| 1516 | | if (controller_set_to_single_density(device)) |
| 1517 | | data_count = TRKSIZE_SD; |
| 1518 | | else |
| 1519 | | data_count = TRKSIZE_DD; |
| 1520 | | } |
| 1507 | if (data_count==0) |
| 1508 | { |
| 1509 | if (controller_set_to_single_density(device)) |
| 1510 | data_count = TRKSIZE_SD; |
| 1511 | else |
| 1512 | data_count = TRKSIZE_DD; |
| 1513 | } |
| 1521 | 1514 | |
| 1522 | | /* Build buffer */ |
| 1523 | | buffer = (UINT8*)malloc(data_count); |
| 1515 | /* Build buffer */ |
| 1516 | buffer = (UINT8*)malloc(data_count); |
| 1524 | 1517 | |
| 1525 | 1518 | fm = controller_set_to_single_density(device); |
| 1526 | 1519 | |
| r8271 | r8272 | |
| 1539 | 1532 | gap4 = (fm)? 247 : 598; |
| 1540 | 1533 | pre_gap = gap_byte; |
| 1541 | 1534 | sync1 = sync2; |
| 1542 | | inam = sync2 + (fm)? 1 : 4; |
| 1535 | inam = sync2 + ((fm)? 1 : 4); |
| 1543 | 1536 | } |
| 1544 | 1537 | else |
| 1545 | 1538 | { |
| r8271 | r8272 | |
| 1672 | 1665 | |
| 1673 | 1666 | sync_status_in(device); |
| 1674 | 1667 | |
| 1675 | | /* Build buffer */ |
| 1676 | | gap0 = (-w->register_w[DMA7_0])&0xff; |
| 1677 | | gap1 = (-w->register_w[DMA15_8])&0xff; |
| 1678 | | gap2 = (-w->register_w[DMA23_16])&0xff; |
| 1679 | | gap3 = (-w->register_w[DESIRED_SECTOR])&0xff; |
| 1680 | | gap4 = 340; |
| 1668 | /* Build buffer */ |
| 1669 | gap0 = (-w->register_w[DMA7_0])&0xff; |
| 1670 | gap1 = (-w->register_w[DMA15_8])&0xff; |
| 1671 | gap2 = (-w->register_w[DMA23_16])&0xff; |
| 1672 | gap3 = (-w->register_w[DESIRED_SECTOR])&0xff; |
| 1673 | gap4 = 340; |
| 1681 | 1674 | |
| 1682 | 1675 | sync = (~w->register_w[DESIRED_CYLINDER])&0xff; |
| 1683 | 1676 | count = (~w->register_w[SECTOR_COUNT])&0xff; |
| r8271 | r8272 | |
| 1685 | 1678 | |
| 1686 | 1679 | data_count = gap1 + count*(sync+12+gap2+sync+size*128+gap3)+gap4; |
| 1687 | 1680 | |
| 1688 | | buffer = (UINT8*)malloc(data_count); |
| 1681 | buffer = (UINT8*)malloc(data_count); |
| 1689 | 1682 | |
| 1690 | 1683 | index = 0; |
| 1691 | 1684 | fm = controller_set_to_single_density(device); |
| r8271 | r8272 | |
| 1774 | 1767 | running_device *current_floppy = (*w->intf->current_floppy)(); |
| 1775 | 1768 | |
| 1776 | 1769 | floppy_image *floppy; |
| 1777 | | /* Determine the track size. We cannot allow different sizes in this |
| 1778 | | design. */ |
| 1770 | /* Determine the track size. We cannot allow different sizes in this design. */ |
| 1779 | 1771 | int data_count = 0; |
| 1780 | 1772 | int i; |
| 1781 | 1773 | UINT8 *buffer; |
| 1782 | 1774 | |
| 1783 | 1775 | sync_latches_out(device); |
| 1784 | 1776 | |
| 1785 | | floppy = flopimg_get_image(current_floppy); |
| 1777 | floppy = flopimg_get_image(current_floppy); |
| 1786 | 1778 | |
| 1787 | | /* Determine the track size. We cannot allow different sizes in this |
| 1788 | | design. */ |
| 1779 | /* Determine the track size. We cannot allow different sizes in this design. */ |
| 1789 | 1780 | if (floppy != NULL) |
| 1790 | 1781 | data_count = floppy_get_track_size(floppy, 0, 0); |
| 1791 | 1782 | |
| 1792 | | if (data_count==0) |
| 1793 | | { |
| 1794 | | if (controller_set_to_single_density(device)) |
| 1795 | | data_count = TRKSIZE_SD; |
| 1796 | | else |
| 1797 | | data_count = TRKSIZE_DD; |
| 1798 | | } |
| 1783 | if (data_count==0) |
| 1784 | { |
| 1785 | if (controller_set_to_single_density(device)) |
| 1786 | data_count = TRKSIZE_SD; |
| 1787 | else |
| 1788 | data_count = TRKSIZE_DD; |
| 1789 | } |
| 1799 | 1790 | |
| 1800 | 1791 | buffer = (UINT8*)malloc(data_count); |
| 1801 | 1792 | |
| 1802 | 1793 | floppy_drive_read_track_data_info_buffer( current_floppy, w->register_w[DESIRED_HEAD]&0x0f, (char *)buffer, &data_count); |
| 1803 | 1794 | sync_status_in(device); |
| 1804 | 1795 | |
| 1805 | | /* Transfer the buffer to the external memory. We assume the memory |
| 1806 | | pointer has been set appropriately in the registers. */ |
| 1796 | // Transfer the buffer to the external memory. We assume the memory |
| 1797 | // pointer has been set appropriately in the registers. |
| 1807 | 1798 | set_dma_address(device, DMA23_16, DMA15_8, DMA7_0); |
| 1808 | 1799 | |
| 1809 | 1800 | if (transfer_only_ids) |
| r8271 | r8272 | |
| 1825 | 1816 | { |
| 1826 | 1817 | smc92x4_state *w = get_safe_token(device); |
| 1827 | 1818 | |
| 1828 | | /* Determine the track size. We cannot allow different sizes in this |
| 1829 | | design. */ |
| 1819 | /* Determine the track size. We cannot allow different sizes in this design. */ |
| 1830 | 1820 | int i; |
| 1831 | 1821 | UINT8 *buffer; |
| 1832 | 1822 | int data_count=0; |
| r8271 | r8272 | |
| 1843 | 1833 | /* no buffer was allocated */ |
| 1844 | 1834 | } |
| 1845 | 1835 | |
| 1846 | | /* Transfer the buffer to the external memory. We assume the memory |
| 1847 | | pointer has been set appropriately in the registers. */ |
| 1836 | // Transfer the buffer to the external memory. We assume the memory |
| 1837 | // pointer has been set appropriately in the registers. |
| 1848 | 1838 | set_dma_address(device, DMA23_16, DMA15_8, DMA7_0); |
| 1849 | 1839 | |
| 1850 | 1840 | if (transfer_only_ids) |
| r8271 | r8272 | |
| 1994 | 1984 | else if (opcode >= 0x02 && opcode <= 0x03) |
| 1995 | 1985 | { |
| 1996 | 1986 | /* RESTORE DRIVE */ |
| 1997 | | /* bit 0: 0 -> command ends after last seek pulse, 1 -> command |
| 1998 | | ends when the drive asserts the seek complete pin */ |
| 1987 | // bit 0: 0 -> command ends after last seek pulse, 1 -> command |
| 1988 | // ends when the drive asserts the seek complete pin |
| 1999 | 1989 | logerror("smc92x4 info: restore command %X\n", opcode); |
| 2000 | 1990 | restore_drive(device); |
| 2001 | 1991 | } |
| r8271 | r8272 | |
| 2027 | 2017 | /* SETREGPTR */ |
| 2028 | 2018 | logerror("smc92x4 info: setregptr command %X\n", opcode); |
| 2029 | 2019 | w->register_pointer = opcode & 0xf; |
| 2030 | | /* Spec does not say anything about the effect of setting an |
| 2031 | | invalid value (only "care should be taken") */ |
| 2020 | // Spec does not say anything about the effect of setting an |
| 2021 | // invalid value (only "care should be taken") |
| 2032 | 2022 | if (w->register_pointer > 10) |
| 2033 | 2023 | { |
| 2034 | 2024 | logerror("smc92x4 error: set register pointer: Invalid register number: %d. Setting to 10.\n", w->register_pointer); |
| r8271 | r8272 | |
| 2097 | 2087 | { |
| 2098 | 2088 | /* status register */ |
| 2099 | 2089 | reply = w->register_r[INT_STATUS]; |
| 2100 | | /* Spec (p.3) : The interrupt pin is reset to its inactive state |
| 2101 | | when the UDC interrupt status register is read. */ |
| 2090 | // Spec (p.3) : The interrupt pin is reset to its inactive state |
| 2091 | // when the UDC interrupt status register is read. |
| 2102 | 2092 | // printf("smc92x4 interrupt status read = %02x\n", reply); |
| 2103 | 2093 | smc92x4_clear_interrupt(device); |
| 2104 | 2094 | /* Clear the bits due to int status register read. */ |
| r8271 | r8272 | |
| 2122 | 2112 | // printf("smc92x4 register_w[%d] <- %X\n", w->register_pointer, data); |
| 2123 | 2113 | w->register_w[w->register_pointer] = data; |
| 2124 | 2114 | |
| 2125 | | /* The DMA registers and the sector register for read and |
| 2126 | | write are identical. */ |
| 2115 | // The DMA registers and the sector register for read and |
| 2116 | // write are identical. |
| 2127 | 2117 | if (w->register_pointer < DESIRED_HEAD) |
| 2128 | 2118 | w->register_r[w->register_pointer] = data; |
| 2129 | 2119 | |
| r8271 | r8272 | |
| 2156 | 2146 | devcb_resolve_read_line(&w->in_auxbus_func, &w->intf->in_auxbus_func, device); |
| 2157 | 2147 | |
| 2158 | 2148 | /* allocate timers */ |
| 2159 | | /* |
| 2160 | | w->timer_data = timer_alloc(device->machine, smc92x4_data_callback, (void *)device); */ |
| 2149 | /* w->timer_data = timer_alloc(device->machine, smc92x4_data_callback, (void *)device); */ |
| 2161 | 2150 | w->timer_rs = timer_alloc(device->machine, smc92x4_read_sector_callback, (void *)device); |
| 2162 | 2151 | w->timer_ws = timer_alloc(device->machine, smc92x4_write_sector_callback, (void *)device); |
| 2163 | 2152 | w->timer_track = timer_alloc(device->machine, smc92x4_track_callback, (void *)device); |