src/mess/machine/smc92x4.c
| r13245 | r13246 | |
| 239 | 239 | #define TRKSIZE_DD 6144 |
| 240 | 240 | #define TRKSIZE_SD 3172 |
| 241 | 241 | |
| 242 | #define VERBOSE 1 |
| 243 | #define LOG logerror |
| 244 | |
| 242 | 245 | /*************************************************************************** |
| 243 | 246 | PROTOTYPES |
| 244 | 247 | ***************************************************************************/ |
| r13245 | r13246 | |
| 319 | 322 | { |
| 320 | 323 | //assert(! (w->status & ST_DONE)) |
| 321 | 324 | smc92x4_state *w = get_safe_token(device); |
| 322 | | //logerror("smc92x4 command %02x done, flags=%02x\n", w->command, flags); |
| 325 | if (VERBOSE>7) LOG("smc92x4 command %02x done, flags=%02x\n", w->command, flags); |
| 323 | 326 | |
| 324 | 327 | w->register_r[INT_STATUS] |= ST_DONE; |
| 325 | 328 | w->register_r[INT_STATUS] &= ~ST_TERMCOD; /* clear the previously set flags */ |
| r13245 | r13246 | |
| 337 | 340 | { |
| 338 | 341 | //assert(! (w->status & ST_DONE)) |
| 339 | 342 | smc92x4_state *w = get_safe_token(device); |
| 340 | | //logerror("smc92x4 command %02x done\n", w->command); |
| 343 | if (VERBOSE>7) LOG("smc92x4 command %02x done\n", w->command); |
| 341 | 344 | |
| 342 | 345 | w->register_r[INT_STATUS] |= ST_DONE; |
| 343 | 346 | |
| r13245 | r13246 | |
| 396 | 399 | w->register_r[DRIVE_STATUS] = w->in_auxbus_func(); |
| 397 | 400 | |
| 398 | 401 | /* Raise interrupt if ready changes. TODO: Check this more closely. */ |
| 399 | | // logerror("disk status = %02x\n", reply); |
| 400 | 402 | if (((w->register_r[DRIVE_STATUS] & DS_READY) != (prev & DS_READY)) |
| 401 | 403 | & (w->register_r[INT_STATUS] & ST_RDYCHNG)) |
| 402 | 404 | { |
| r13245 | r13246 | |
| 520 | 522 | |
| 521 | 523 | if (!w->use_real_timing) |
| 522 | 524 | { |
| 523 | | logerror("smc92x4 info: Disk access without delays\n"); |
| 525 | if (VERBOSE>5) LOG("smc92x4 info: Disk access without delays\n"); |
| 524 | 526 | time = 1; |
| 525 | 527 | } |
| 526 | 528 | |
| r13245 | r13246 | |
| 558 | 560 | int write_long = ((w->register_w[MODE]& MO_CRCECC)==0x40); |
| 559 | 561 | |
| 560 | 562 | if (deldata) |
| 561 | | logerror("smc92x4 warn: Write deleted data mark not supported. Writing normal mark.\n"); |
| 563 | if (VERBOSE>0) LOG("smc92x4 warn: Write deleted data mark not supported. Writing normal mark.\n"); |
| 562 | 564 | |
| 563 | 565 | /* Now write the sector. */ |
| 564 | 566 | data_transfer_write(device, w->recent_id, deldata, redcur, precomp, write_long); |
| r13245 | r13246 | |
| 593 | 595 | current_floppy = (*w->intf->current_floppy)(device); |
| 594 | 596 | if (current_floppy==NULL) |
| 595 | 597 | { |
| 596 | | logerror("smc92x4 error: seek callback: no floppy\n"); |
| 598 | if (VERBOSE>0) LOG("smc92x4 error: seek callback: no floppy\n"); |
| 597 | 599 | w->register_r[INT_STATUS] |= ST_TC_SEEKERR; |
| 598 | 600 | } |
| 599 | 601 | else |
| 600 | 602 | { |
| 601 | | logerror("smc92x4 step %s direction %d\n", current_floppy->tag(), w->step_direction); |
| 603 | if (VERBOSE>5) LOG("smc92x4 step %s direction %d\n", current_floppy->tag(), w->step_direction); |
| 602 | 604 | floppy_drive_seek(current_floppy, w->step_direction); |
| 603 | 605 | } |
| 604 | 606 | } |
| 605 | 607 | else |
| 606 | 608 | { |
| 607 | | // logerror("smc92x4 step harddisk direction %d\n", w->step_direction); |
| 609 | if (VERBOSE>6) LOG("smc92x4 step harddisk direction %d\n", w->step_direction); |
| 608 | 610 | (*w->intf->mfmhd_seek)(device, w->step_direction); |
| 609 | 611 | } |
| 610 | 612 | sync_status_in(device); |
| r13245 | r13246 | |
| 694 | 696 | device_t *disk_img = (*w->intf->current_floppy)(device); |
| 695 | 697 | if (flopimg_get_image(disk_img) == NULL) |
| 696 | 698 | { |
| 697 | | logerror("smc92x4 warn: No disk in drive\n"); |
| 699 | if (VERBOSE>2) LOG("smc92x4 warn: No disk in drive\n"); |
| 698 | 700 | w->register_r[CHIP_STATUS] |= CS_SYNCERR; |
| 699 | 701 | return; |
| 700 | 702 | } |
| r13245 | r13246 | |
| 709 | 711 | } |
| 710 | 712 | else |
| 711 | 713 | { |
| 712 | | logerror("smc92x4 warn: Controller and medium density do not match.\n"); |
| 714 | if (VERBOSE>2) LOG("smc92x4 warn: Controller and medium density do not match.\n"); |
| 713 | 715 | } |
| 714 | 716 | sync_status_in(device); |
| 715 | 717 | |
| 716 | 718 | if (!found) |
| 717 | 719 | { |
| 718 | | logerror("smc92x4 error: read_id_field (floppy): sync error\n"); |
| 720 | if (VERBOSE>1) LOG("smc92x4 error: read_id_field (floppy): sync error\n"); |
| 719 | 721 | w->register_r[CHIP_STATUS] |= CS_SYNCERR; |
| 720 | 722 | return; |
| 721 | 723 | } |
| r13245 | r13246 | |
| 726 | 728 | sync_status_in(device); |
| 727 | 729 | if (!(w->register_r[DRIVE_STATUS]& DS_READY)) |
| 728 | 730 | { |
| 729 | | logerror("smc92x4 error: read_id_field (harddisk): sync error\n"); |
| 731 | if (VERBOSE>1) LOG("smc92x4 error: read_id_field (harddisk): sync error\n"); |
| 730 | 732 | w->register_r[CHIP_STATUS] |= CS_SYNCERR; |
| 731 | 733 | return; |
| 732 | 734 | } |
| r13245 | r13246 | |
| 767 | 769 | *direction = -1; |
| 768 | 770 | } |
| 769 | 771 | |
| 770 | | //logerror("smc92x4 seek required: %d steps\n", *steps); |
| 772 | if (VERBOSE>6) LOG("smc92x4 seek required: %d steps\n", *steps); |
| 771 | 773 | |
| 772 | 774 | w->register_r[INT_STATUS] &= ~ST_TC_RDIDERR; |
| 773 | 775 | return; |
| r13245 | r13246 | |
| 802 | 804 | if (/* pass==1 && */!found) |
| 803 | 805 | { |
| 804 | 806 | w->register_r[CHIP_STATUS] |= CS_SYNCERR; |
| 805 | | logerror("smc92x4 error: verify (floppy): sync error\n"); |
| 807 | if (VERBOSE>1) LOG("smc92x4 error: verify (floppy): sync error\n"); |
| 806 | 808 | return ERROR; |
| 807 | 809 | } |
| 808 | 810 | } |
| r13245 | r13246 | |
| 812 | 814 | sync_status_in(device); |
| 813 | 815 | if (!(w->register_r[DRIVE_STATUS]& DS_READY)) |
| 814 | 816 | { |
| 815 | | logerror("smc92x4 error: verify (harddisk): sync error\n"); |
| 817 | if (VERBOSE>1) LOG("smc92x4 error: verify (harddisk): sync error\n"); |
| 816 | 818 | w->register_r[CHIP_STATUS] |= CS_SYNCERR; |
| 817 | 819 | return ERROR; |
| 818 | 820 | } |
| r13245 | r13246 | |
| 830 | 832 | { |
| 831 | 833 | des_cylinder = ((w->register_w[DESIRED_HEAD] & 0x70)<<4) | w->register_w[DESIRED_CYLINDER]; |
| 832 | 834 | } |
| 833 | | // logerror("smc92x4 check id: current = (%d,%d,%d), required = (%d,%d,%d)\n", id->C, id->H, id->R, des_cylinder, w->register_w[DESIRED_HEAD] & 0x0f, w->register_w[DESIRED_SECTOR]); |
| 835 | if (VERBOSE>6) LOG("smc92x4 check id: current = (%d,%d,%d), required = (%d,%d,%d)\n", id->C, id->H, id->R, des_cylinder, w->register_w[DESIRED_HEAD] & 0x0f, w->register_w[DESIRED_SECTOR]); |
| 834 | 836 | if ((des_cylinder == id->C) |
| 835 | 837 | && ((w->register_w[DESIRED_HEAD] & 0x0f) == id->H)) |
| 836 | 838 | { |
| r13245 | r13246 | |
| 841 | 843 | if (!foundsect) |
| 842 | 844 | { |
| 843 | 845 | w->register_r[CHIP_STATUS] |= CS_COMPERR; |
| 844 | | logerror("smc92x4 error: verify: sector not found, seek error (desired cyl=%d/sec=%d, current cyl=%d/sec=%d)\n", des_cylinder, w->register_w[DESIRED_SECTOR], id->C, id->R); |
| 846 | if (VERBOSE>1) LOG("smc92x4 error: verify: sector not found, seek error (desired cyl=%d/sec=%d, current cyl=%d/sec=%d)\n", des_cylinder, w->register_w[DESIRED_SECTOR], id->C, id->R); |
| 845 | 847 | return ERROR; |
| 846 | 848 | } |
| 847 | 849 | |
| r13245 | r13246 | |
| 991 | 993 | |
| 992 | 994 | if (write_long) |
| 993 | 995 | { |
| 994 | | logerror("smc92x4 warn: write sector: Write_long not supported. Performing a normal write.\n"); |
| 996 | if (VERBOSE>1) LOG("smc92x4 warn: write sector: Write_long not supported. Performing a normal write.\n"); |
| 995 | 997 | } |
| 996 | 998 | |
| 997 | 999 | if (w->selected_drive_type & TYPE_FLOPPY) |
| r13245 | r13246 | |
| 1101 | 1103 | /* Needed for the two ways of re-entry: during the seek process, and during sector read */ |
| 1102 | 1104 | if (!w->after_seek) |
| 1103 | 1105 | { |
| 1104 | | // logerror("smc92x4 continue with sector read\n"); |
| 1106 | if (VERBOSE>7) LOG("smc92x4 continue with sector read\n"); |
| 1105 | 1107 | w->seek_count--; |
| 1106 | 1108 | if (w->seek_count > 0) |
| 1107 | 1109 | { |
| r13245 | r13246 | |
| 1116 | 1118 | w->to_be_continued = FALSE; |
| 1117 | 1119 | if (w->register_r[INT_STATUS] & ST_TERMCOD) |
| 1118 | 1120 | { |
| 1119 | | logerror("smc92x4 error: data error during sector read: INTSTATUS=%02x\n", w->register_r[INT_STATUS]); |
| 1121 | if (VERBOSE>1) LOG("smc92x4 error: data error during sector read: INTSTATUS=%02x\n", w->register_r[INT_STATUS]); |
| 1120 | 1122 | set_command_done(device, ST_TC_DATAERR); |
| 1121 | 1123 | return; |
| 1122 | 1124 | } |
| r13245 | r13246 | |
| 1133 | 1135 | if (state==ERROR) |
| 1134 | 1136 | { |
| 1135 | 1137 | // TODO: set command done? |
| 1136 | | logerror("smc92x4 error: verify error during sector read\n"); |
| 1138 | if (VERBOSE>0) LOG("smc92x4 error: verify error during sector read\n"); |
| 1137 | 1139 | return; |
| 1138 | 1140 | } |
| 1139 | 1141 | |
| r13245 | r13246 | |
| 1143 | 1145 | |
| 1144 | 1146 | if (w->recent_id.flags & BAD_SECTOR) |
| 1145 | 1147 | { |
| 1146 | | logerror("smc92x4 error: Bad sector, seek error\n"); |
| 1148 | if (VERBOSE>0) LOG("smc92x4 error: Bad sector, seek error\n"); |
| 1147 | 1149 | set_command_done(device, ST_TC_SEEKERR); |
| 1148 | 1150 | } |
| 1149 | 1151 | else |
| r13245 | r13246 | |
| 1154 | 1156 | else |
| 1155 | 1157 | { |
| 1156 | 1158 | set_command_done(device, ST_TC_SUCCESS); |
| 1157 | | //logerror("smc92x4 read sector command done\n"); |
| 1159 | if (VERBOSE>7) LOG("smc92x4 read sector command done\n"); |
| 1158 | 1160 | } |
| 1159 | 1161 | } |
| 1160 | 1162 | |
| r13245 | r13246 | |
| 1183 | 1185 | w->to_be_continued = FALSE; |
| 1184 | 1186 | if (w->register_r[INT_STATUS] & ST_TERMCOD) |
| 1185 | 1187 | { |
| 1186 | | logerror("smc92x4 error: data error during sector write\n"); |
| 1188 | if (VERBOSE>0) LOG("smc92x4 error: data error during sector write\n"); |
| 1187 | 1189 | set_command_done(device, ST_TC_DATAERR); |
| 1188 | 1190 | return; |
| 1189 | 1191 | } |
| r13245 | r13246 | |
| 1192 | 1194 | w->to_be_continued = FALSE; |
| 1193 | 1195 | |
| 1194 | 1196 | if ((w->register_w[RETRY_COUNT] & 0xf0)!= 0xf0) |
| 1195 | | logerror("smc92x4 warn: RETRY_COUNT in write sector should be set to 0. Ignored.\n"); |
| 1197 | if (VERBOSE>1) LOG("smc92x4 warn: RETRY_COUNT in write sector should be set to 0. Ignored.\n"); |
| 1196 | 1198 | |
| 1197 | 1199 | /* Wait for SEEK_COMPLETE. We assume the signal has appeared. */ |
| 1198 | 1200 | if (w->register_w[SECTOR_COUNT] > 0) |
| r13245 | r13246 | |
| 1201 | 1203 | state = verify(device, &w->recent_id, check_sector); |
| 1202 | 1204 | if (state==ERROR) |
| 1203 | 1205 | { |
| 1204 | | logerror("smc92x4 error: verify error during sector write\n"); |
| 1206 | if (VERBOSE>0) LOG("smc92x4 error: verify error during sector write\n"); |
| 1205 | 1207 | return; |
| 1206 | 1208 | } |
| 1207 | 1209 | |
| r13245 | r13246 | |
| 1221 | 1223 | else |
| 1222 | 1224 | { |
| 1223 | 1225 | set_command_done(device, ST_TC_SUCCESS); |
| 1224 | | // logerror("smc92x4 write sector command done\n"); |
| 1226 | if (VERBOSE>7) LOG("smc92x4 write sector command done\n"); |
| 1225 | 1227 | } |
| 1226 | 1228 | } |
| 1227 | 1229 | |
| r13245 | r13246 | |
| 1241 | 1243 | |
| 1242 | 1244 | if (w->seek_count>=4096 || !(w->register_r[DRIVE_STATUS] & DS_READY)) |
| 1243 | 1245 | { |
| 1244 | | logerror("smc92x4 error: seek error in restore\n"); |
| 1246 | if (VERBOSE>0) LOG("smc92x4 error: seek error in restore\n"); |
| 1245 | 1247 | w->register_r[INT_STATUS] |= ST_TC_SEEKERR; |
| 1246 | 1248 | return; |
| 1247 | 1249 | } |
| r13245 | r13246 | |
| 1286 | 1288 | w->buffered = buffered; |
| 1287 | 1289 | |
| 1288 | 1290 | smc92x4_timed_seek_request(device); |
| 1289 | | //logerror("smc92x4 waiting for drive step\n"); |
| 1291 | if (VERBOSE>6) LOG("smc92x4 waiting for drive step\n"); |
| 1290 | 1292 | } |
| 1291 | 1293 | |
| 1292 | 1294 | static void step_continue(device_t *device) |
| 1293 | 1295 | { |
| 1294 | 1296 | smc92x4_state *w = get_safe_token(device); |
| 1295 | | //logerror("smc92x4 step continue\n"); |
| 1297 | if (VERBOSE>7) LOG("smc92x4 step continue\n"); |
| 1296 | 1298 | w->to_be_continued = FALSE; |
| 1297 | 1299 | set_command_done(device, ST_TC_SUCCESS); |
| 1298 | 1300 | } |
| r13245 | r13246 | |
| 1381 | 1383 | else |
| 1382 | 1384 | { |
| 1383 | 1385 | if (wait) |
| 1384 | | logerror("smc92x4 warn: seed_read_id: Waiting for seek_complete not implemented.\n"); |
| 1386 | if (VERBOSE>1) LOG("smc92x4 warn: seed_read_id: Waiting for seek_complete not implemented.\n"); |
| 1385 | 1387 | |
| 1386 | 1388 | if (verify_id) |
| 1387 | 1389 | { |
| r13245 | r13246 | |
| 1553 | 1555 | exp_size = gap0 + inam + gap1 + count*(sync1 + mark + gap2 + sync2 + size*128 + gap3) + gap4; |
| 1554 | 1556 | |
| 1555 | 1557 | if (exp_size != data_count) |
| 1556 | | logerror("smc92x4 warn: The current track length in the image (%d) does not match the new track length (%d). Keeping the old length. This will break the image (sorry).\n", data_count, exp_size); |
| 1558 | if (VERBOSE>0) LOG("smc92x4 warn: The current track length in the image (%d) does not match the new track length (%d). Keeping the old length. This will break the image (sorry).\n", data_count, exp_size); |
| 1557 | 1559 | |
| 1558 | 1560 | /* use the backup registers set up during drive_select */ |
| 1559 | 1561 | set_dma_address(device, CURRENT_IDENT, CURRENT_CYLINDER, CURRENT_HEAD); |
| r13245 | r13246 | |
| 1603 | 1605 | buffer[index++] = curr_sect; |
| 1604 | 1606 | buffer[index++] = curr_size; |
| 1605 | 1607 | |
| 1606 | | // if (j==0) logerror("current_floppy=%s, format track %d, head %d\n", current_floppy->tag(), curr_cyl, curr_head); |
| 1608 | if (j==0) |
| 1609 | if (VERBOSE>6) LOG("current_floppy=%s, format track %d, head %d\n", current_floppy->tag(), curr_cyl, curr_head); |
| 1607 | 1610 | |
| 1608 | 1611 | /* Calculate CRC16 (5 bytes for ID) */ |
| 1609 | 1612 | crc = ccitt_crc16(0xffff, &buffer[index-5], 5); |
| r13245 | r13246 | |
| 1801 | 1804 | |
| 1802 | 1805 | if (transfer_only_ids) |
| 1803 | 1806 | { |
| 1804 | | logerror("smc92x4 warn: read track: Ignoring transfer-only-ids. Reading complete track.\n"); |
| 1807 | if (VERBOSE>1) LOG("smc92x4 warn: read track: Ignoring transfer-only-ids. Reading complete track.\n"); |
| 1805 | 1808 | } |
| 1806 | 1809 | |
| 1807 | 1810 | smc92x4_set_dip(device, TRUE); |
| r13245 | r13246 | |
| 1831 | 1834 | |
| 1832 | 1835 | if (!(w->register_r[DRIVE_STATUS] & DS_READY)) |
| 1833 | 1836 | { |
| 1834 | | logerror("smc92x4 error: read harddisk track failed.\n"); |
| 1837 | if (VERBOSE>0) LOG("smc92x4 error: read harddisk track failed.\n"); |
| 1835 | 1838 | /* no buffer was allocated */ |
| 1836 | 1839 | } |
| 1837 | 1840 | |
| r13245 | r13246 | |
| 1841 | 1844 | |
| 1842 | 1845 | if (transfer_only_ids) |
| 1843 | 1846 | { |
| 1844 | | logerror("smc92x4 warn: read track: Ignoring transfer-only-ids. Reading complete track.\n"); |
| 1847 | if (VERBOSE>1) LOG("smc92x4 warn: read track: Ignoring transfer-only-ids. Reading complete track.\n"); |
| 1845 | 1848 | } |
| 1846 | 1849 | |
| 1847 | 1850 | smc92x4_set_dip(device, TRUE); |
| r13245 | r13246 | |
| 1936 | 1939 | } |
| 1937 | 1940 | else |
| 1938 | 1941 | { |
| 1939 | | logerror("smc92x4 warn: Invalid command %x or command changed while waiting for callback\n", opcode); |
| 1942 | if (VERBOSE>1) LOG("smc92x4 warn: Invalid command %x or command changed while waiting for callback\n", opcode); |
| 1940 | 1943 | } |
| 1941 | 1944 | } |
| 1942 | 1945 | |
| r13245 | r13246 | |
| 1947 | 1950 | { |
| 1948 | 1951 | smc92x4_state *w = get_safe_token(device); |
| 1949 | 1952 | |
| 1950 | | //logerror("smc92x4 process command %02x\n", opcode); |
| 1953 | if (VERBOSE>6) LOG("smc92x4 process command %02x\n", opcode); |
| 1951 | 1954 | if (w->to_be_continued) |
| 1952 | 1955 | { |
| 1953 | | logerror("smc92x4 warn: previous command %02x not complete\n", w->command); |
| 1956 | if (VERBOSE>1) LOG("smc92x4 warn: previous command %02x not complete\n", w->command); |
| 1954 | 1957 | } |
| 1955 | 1958 | |
| 1956 | 1959 | /* Reset DONE and BAD_SECTOR. */ |
| r13245 | r13246 | |
| 1969 | 1972 | { |
| 1970 | 1973 | /* RESET */ |
| 1971 | 1974 | /* same effect as the RST* pin being active */ |
| 1972 | | logerror("smc92x4 info: reset command\n"); |
| 1975 | if (VERBOSE>0) LOG("smc92x4 info: reset command\n"); |
| 1973 | 1976 | smc92x4_reset(device); |
| 1974 | 1977 | } |
| 1975 | 1978 | else if (opcode == 0x01) |
| 1976 | 1979 | { |
| 1977 | 1980 | /* DESELECT DRIVE */ |
| 1978 | 1981 | /* done when no drive is in use */ |
| 1979 | | logerror("smc92x4 info: drdeselect command\n"); |
| 1982 | if (VERBOSE>2) LOG("smc92x4 info: drdeselect command\n"); |
| 1980 | 1983 | w->output1 &= ~(OUT1_DRVSEL3|OUT1_DRVSEL2|OUT1_DRVSEL1|OUT1_DRVSEL0); |
| 1981 | 1984 | w->output2 |= OUT2_DRVSEL3_; |
| 1982 | 1985 | /* sync the latches on the PCB */ |
| r13245 | r13246 | |
| 1988 | 1991 | /* RESTORE DRIVE */ |
| 1989 | 1992 | // bit 0: 0 -> command ends after last seek pulse, 1 -> command |
| 1990 | 1993 | // ends when the drive asserts the seek complete pin |
| 1991 | | logerror("smc92x4 info: restore command %X\n", opcode); |
| 1994 | if (VERBOSE>2) LOG("smc92x4 info: restore command %X\n", opcode); |
| 1992 | 1995 | restore_drive(device); |
| 1993 | 1996 | } |
| 1994 | 1997 | else if (opcode >= 0x04 && opcode <= 0x07) |
| 1995 | 1998 | { |
| 1996 | 1999 | /* STEP IN/OUT ONE CYLINDER */ |
| 1997 | | logerror("smc92x4 info: step in/out command %X\n", opcode); |
| 2000 | if (VERBOSE>2) LOG("smc92x4 info: step in/out command %X\n", opcode); |
| 1998 | 2001 | step_in_out(device); |
| 1999 | 2002 | } |
| 2000 | 2003 | else if (opcode >= 0x08 && opcode <= 0x0f) |
| 2001 | 2004 | { |
| 2002 | 2005 | /* TAPE BACKUP (08-0f)*/ |
| 2003 | | logerror("smc92x4 warn: tape backup command %X not implemented\n", opcode); |
| 2006 | if (VERBOSE>0) LOG("smc92x4 error: tape backup command %X not implemented\n", opcode); |
| 2004 | 2007 | } |
| 2005 | 2008 | else if (opcode >= 0x10 && opcode <= 0x1f) |
| 2006 | 2009 | { |
| 2007 | 2010 | /* POLLDRIVE */ |
| 2008 | | logerror("smc92x4 info: polldrive command %X\n", opcode); |
| 2011 | if (VERBOSE>2) LOG("smc92x4 info: polldrive command %X\n", opcode); |
| 2009 | 2012 | poll_drives(device); |
| 2010 | 2013 | } |
| 2011 | 2014 | else if (opcode >= 0x20 && opcode <= 0x3f) |
| 2012 | 2015 | { |
| 2013 | 2016 | /* DRIVE SELECT */ |
| 2014 | | logerror("smc92x4 info: drselect command %X\n", opcode); |
| 2017 | if (VERBOSE>2) LOG("smc92x4 info: drselect command %X\n", opcode); |
| 2015 | 2018 | drive_select(device, opcode&0x1f); |
| 2016 | 2019 | } |
| 2017 | 2020 | else if (opcode >= 0x40 && opcode <= 0x4f) |
| 2018 | 2021 | { |
| 2019 | 2022 | /* SETREGPTR */ |
| 2020 | | logerror("smc92x4 info: setregptr command %X\n", opcode); |
| 2023 | if (VERBOSE>2) LOG("smc92x4 info: setregptr command %X\n", opcode); |
| 2021 | 2024 | w->register_pointer = opcode & 0xf; |
| 2022 | 2025 | // Spec does not say anything about the effect of setting an |
| 2023 | 2026 | // invalid value (only "care should be taken") |
| 2024 | 2027 | if (w->register_pointer > 10) |
| 2025 | 2028 | { |
| 2026 | | logerror("smc92x4 error: set register pointer: Invalid register number: %d. Setting to 10.\n", w->register_pointer); |
| 2029 | if (VERBOSE>1) LOG("smc92x4 error: set register pointer: Invalid register number: %d. Setting to 10.\n", w->register_pointer); |
| 2027 | 2030 | w->register_pointer = 10; |
| 2028 | 2031 | } |
| 2029 | 2032 | } |
| 2030 | 2033 | else if (opcode >= 0x50 && opcode <= 0x57) |
| 2031 | 2034 | { |
| 2032 | 2035 | /* SEEK/READ ID */ |
| 2033 | | logerror("smc92x4 seekreadid command %X\n", opcode); |
| 2036 | if (VERBOSE>2) LOG("smc92x4 seekreadid command %X\n", opcode); |
| 2034 | 2037 | seek_read_id(device); |
| 2035 | 2038 | } |
| 2036 | 2039 | else if ((opcode >= 0x58 && opcode <= 0x59) |
| r13245 | r13246 | |
| 2038 | 2041 | || (opcode >= 0x80)) |
| 2039 | 2042 | { |
| 2040 | 2043 | /* READ/WRITE SECTORS PHYSICAL/LOGICAL */ |
| 2041 | | logerror("smc92x4 info: read/write sector command %X\n", opcode); |
| 2044 | if (VERBOSE>2) LOG("smc92x4 info: read/write sector command %X\n", opcode); |
| 2042 | 2045 | read_write_sectors(device); |
| 2043 | 2046 | } |
| 2044 | 2047 | else if (opcode >= 0x5A && opcode <= 0x5b) |
| 2045 | 2048 | { |
| 2046 | 2049 | /* READ TRACK */ |
| 2047 | | logerror("smc92x4 info: read track command %X\n", opcode); |
| 2050 | if (VERBOSE>2) LOG("smc92x4 info: read track command %X\n", opcode); |
| 2048 | 2051 | read_track(device); |
| 2049 | 2052 | } |
| 2050 | 2053 | else if (opcode >= 0x60 && opcode <= 0x7f) |
| 2051 | 2054 | { |
| 2052 | 2055 | /* FORMAT TRACK */ |
| 2053 | | logerror("smc92x4 info: format track command %X\n", opcode); |
| 2056 | if (VERBOSE>2) LOG("smc92x4 info: format track command %X\n", opcode); |
| 2054 | 2057 | format_track(device); |
| 2055 | 2058 | } |
| 2056 | 2059 | else |
| 2057 | 2060 | { |
| 2058 | | logerror("smc92x4 warn: Invalid command %x, ignored\n", opcode); |
| 2061 | if (VERBOSE>0) LOG("smc92x4 error: Invalid command %x, ignored\n", opcode); |
| 2059 | 2062 | } |
| 2060 | 2063 | |
| 2061 | 2064 | if (!w->to_be_continued) |
| r13245 | r13246 | |
| 2079 | 2082 | { |
| 2080 | 2083 | /* data register */ |
| 2081 | 2084 | reply = w->register_r[w->register_pointer]; |
| 2082 | | // logerror("smc92x4 register_r[%d] -> %02x\n", w->register_pointer, reply); |
| 2085 | if (VERBOSE>6) LOG("smc92x4 register_r[%d] -> %02x\n", w->register_pointer, reply); |
| 2083 | 2086 | /* Autoincrement until DATA is reached. */ |
| 2084 | 2087 | if (w->register_pointer < DATA) |
| 2085 | 2088 | w->register_pointer++; |
| r13245 | r13246 | |
| 2090 | 2093 | reply = w->register_r[INT_STATUS]; |
| 2091 | 2094 | // Spec (p.3) : The interrupt pin is reset to its inactive state |
| 2092 | 2095 | // when the UDC interrupt status register is read. |
| 2093 | | // logerror("smc92x4 interrupt status read = %02x\n", reply); |
| 2096 | if (VERBOSE>6) LOG("smc92x4 interrupt status read = %02x\n", reply); |
| 2094 | 2097 | smc92x4_clear_interrupt(device); |
| 2095 | 2098 | /* Clear the bits due to int status register read. */ |
| 2096 | 2099 | w->register_r[INT_STATUS] &= ~(ST_INTPEND | ST_RDYCHNG); |
| r13245 | r13246 | |
| 2110 | 2113 | if ((offset & 1) == 0) |
| 2111 | 2114 | { |
| 2112 | 2115 | /* data register */ |
| 2113 | | // logerror("smc92x4 register_w[%d] <- %X\n", w->register_pointer, data); |
| 2116 | if (VERBOSE>6) LOG("smc92x4 register_w[%d] <- %X\n", w->register_pointer, data); |
| 2114 | 2117 | w->register_w[w->register_pointer] = data; |
| 2115 | 2118 | |
| 2116 | 2119 | // The DMA registers and the sector register for read and |
| r13245 | r13246 | |
| 2175 | 2178 | { |
| 2176 | 2179 | smc92x4_state *w = get_safe_token(device); |
| 2177 | 2180 | w->use_real_timing = realistic; |
| 2178 | | logerror("smc92x4: use realistic timing: %02x\n", realistic); |
| 2181 | if (VERBOSE>0) LOG("smc92x4: use realistic timing: %02x\n", realistic); |
| 2179 | 2182 | } |
| 2180 | 2183 | |
| 2181 | 2184 | /*************************************************************************** |