src/mess/machine/wd17xx.c
| r6719 | r6720 | |
| 247 | 247 | }; |
| 248 | 248 | #endif |
| 249 | 249 | |
| 250 | | enum |
| 251 | | { |
| 252 | | MISCCALLBACK_COMMAND = 0, |
| 253 | | MISCCALLBACK_DATA |
| 254 | | }; |
| 255 | 250 | |
| 256 | | |
| 257 | 251 | /*************************************************************************** |
| 258 | 252 | TYPE DEFINITIONS |
| 259 | 253 | ***************************************************************************/ |
| r6719 | r6720 | |
| 316 | 310 | |
| 317 | 311 | UINT8 ddam; /* ddam of sector found - used when reading */ |
| 318 | 312 | UINT8 sector_data_id; |
| 319 | | emu_timer *timer, *timer_rs, *timer_ws, *timer_rid; |
| 320 | 313 | int data_direction; |
| 321 | 314 | |
| 322 | 315 | int hld_count; /* head loaded counter */ |
| 323 | 316 | |
| 324 | | emu_timer *busy_timer; |
| 325 | | |
| 326 | 317 | /* this is the drive currently selected */ |
| 327 | 318 | const device_config *drive; |
| 328 | 319 | |
| r6719 | r6720 | |
| 358 | 349 | |
| 359 | 350 | static void wd17xx_complete_command(const device_config *device, int delay); |
| 360 | 351 | static void wd17xx_timed_data_request(const device_config *device); |
| 361 | | static TIMER_CALLBACK(wd17xx_misc_timer_callback); |
| 362 | | static TIMER_CALLBACK(wd17xx_read_sector_callback); |
| 363 | | static TIMER_CALLBACK(wd17xx_write_sector_callback); |
| 364 | | static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state); |
| 352 | static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state); |
| 365 | 353 | |
| 366 | 354 | |
| 367 | 355 | /***************************************************************************** |
| r6719 | r6720 | |
| 471 | 459 | devcb_call_write_line(&w->out_intrq_func, w->intrq); |
| 472 | 460 | } |
| 473 | 461 | |
| 474 | | |
| 475 | | |
| 476 | | static TIMER_CALLBACK( wd17xx_busy_callback ) |
| 462 | /* set intrq after delay */ |
| 463 | static TIMER_CALLBACK( wd17xx_command_callback ) |
| 477 | 464 | { |
| 478 | 465 | const device_config *device = ptr; |
| 479 | | wd1770_state *w = get_safe_token(device); |
| 480 | 466 | wd17xx_set_intrq(device); |
| 481 | | timer_reset(w->busy_timer, attotime_never); |
| 482 | 467 | } |
| 483 | 468 | |
| 469 | /* set drq after delay */ |
| 470 | static TIMER_CALLBACK( wd17xx_data_callback ) |
| 471 | { |
| 472 | const device_config *device = ptr; |
| 473 | wd17xx_set_drq(device); |
| 474 | } |
| 484 | 475 | |
| 485 | 476 | |
| 486 | 477 | static void wd17xx_set_busy(const device_config *device, attotime duration) |
| r6719 | r6720 | |
| 488 | 479 | wd1770_state *w = get_safe_token(device); |
| 489 | 480 | |
| 490 | 481 | w->status |= STA_1_BUSY; |
| 491 | | timer_adjust_oneshot(w->busy_timer, duration, 0); |
| 482 | |
| 483 | timer_set(device->machine, duration, (void *)device, 0, wd17xx_command_callback); |
| 492 | 484 | } |
| 493 | 485 | |
| 494 | 486 | |
| 495 | | |
| 496 | 487 | /* BUSY COUNT DOESN'T WORK PROPERLY! */ |
| 497 | 488 | |
| 498 | 489 | static void wd17xx_command_restore(const device_config *device) |
| r6719 | r6720 | |
| 892 | 883 | } |
| 893 | 884 | |
| 894 | 885 | |
| 895 | | |
| 896 | | static TIMER_CALLBACK(wd17xx_misc_timer_callback) |
| 897 | | { |
| 898 | | const device_config *device = ptr; |
| 899 | | int callback_type = param; |
| 900 | | wd1770_state *w = get_safe_token(device); |
| 901 | | |
| 902 | | switch(callback_type) { |
| 903 | | case MISCCALLBACK_COMMAND: |
| 904 | | /* command callback */ |
| 905 | | wd17xx_set_intrq(device); |
| 906 | | break; |
| 907 | | |
| 908 | | case MISCCALLBACK_DATA: |
| 909 | | /* data callback */ |
| 910 | | /* ok, trigger data request now */ |
| 911 | | wd17xx_set_drq(device); |
| 912 | | break; |
| 913 | | } |
| 914 | | |
| 915 | | /* stop it, but don't allow it to be free'd */ |
| 916 | | timer_reset(w->timer, attotime_never); |
| 917 | | } |
| 918 | | |
| 919 | | |
| 920 | 886 | /* called on error, or when command is actually completed */ |
| 921 | 887 | /* KT - I have used a timer for systems that use interrupt driven transfers. |
| 922 | 888 | A interrupt occurs after the last byte has been read. If it occurs at the time |
| r6719 | r6720 | |
| 946 | 912 | usecs = 12; |
| 947 | 913 | |
| 948 | 914 | /* set new timer */ |
| 949 | | timer_adjust_oneshot(w->timer, ATTOTIME_IN_USEC(usecs), MISCCALLBACK_COMMAND); |
| 915 | timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_command_callback); |
| 950 | 916 | } |
| 951 | 917 | |
| 952 | 918 | |
| r6719 | r6720 | |
| 1036 | 1002 | wd17xx_complete_command(device, DELAY_NOTREADY); |
| 1037 | 1003 | else |
| 1038 | 1004 | wd17xx_read_sector(device); |
| 1039 | | |
| 1040 | | /* stop it, but don't allow it to be free'd */ |
| 1041 | | timer_reset(w->timer_rs, attotime_never); |
| 1042 | 1005 | } |
| 1043 | 1006 | |
| 1044 | 1007 | |
| r6719 | r6720 | |
| 1088 | 1051 | } |
| 1089 | 1052 | } |
| 1090 | 1053 | } |
| 1091 | | |
| 1092 | | /* stop it, but don't allow it to be free'd */ |
| 1093 | | timer_reset(w->timer_ws, attotime_never); |
| 1094 | 1054 | } |
| 1095 | 1055 | |
| 1096 | 1056 | |
| r6719 | r6720 | |
| 1104 | 1064 | usecs = wd17xx_get_datarate_in_us(w->density); |
| 1105 | 1065 | |
| 1106 | 1066 | /* set new timer */ |
| 1107 | | timer_adjust_oneshot(w->timer, ATTOTIME_IN_USEC(usecs), MISCCALLBACK_DATA); |
| 1067 | timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_data_callback); |
| 1108 | 1068 | } |
| 1109 | 1069 | |
| 1110 | 1070 | |
| r6719 | r6720 | |
| 1118 | 1078 | usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */ |
| 1119 | 1079 | |
| 1120 | 1080 | /* set new timer */ |
| 1121 | | timer_reset(w->timer_rs, ATTOTIME_IN_USEC(usecs)); |
| 1081 | timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_read_sector_callback); |
| 1122 | 1082 | } |
| 1123 | 1083 | |
| 1124 | 1084 | |
| r6719 | r6720 | |
| 1132 | 1092 | usecs = w->pause_time; /* How long should we wait? How about 40 micro seconds? */ |
| 1133 | 1093 | |
| 1134 | 1094 | /* set new timer */ |
| 1135 | | timer_reset(w->timer_ws, ATTOTIME_IN_USEC(usecs)); |
| 1095 | timer_set(device->machine, ATTOTIME_IN_USEC(usecs), (void *)device, 0, wd17xx_write_sector_callback); |
| 1136 | 1096 | } |
| 1137 | 1097 | |
| 1138 | 1098 | |
| r6719 | r6720 | |
| 1840 | 1800 | |
| 1841 | 1801 | w->status = STA_1_TRACK0; |
| 1842 | 1802 | w->density = DEN_MFM_LO; |
| 1843 | | w->busy_timer = timer_alloc(device->machine, wd17xx_busy_callback, (void*)device); |
| 1844 | | w->timer = timer_alloc(device->machine, wd17xx_misc_timer_callback, (void*)device); |
| 1845 | | w->timer_rs = timer_alloc(device->machine, wd17xx_read_sector_callback, (void*)device); |
| 1846 | | w->timer_ws = timer_alloc(device->machine, wd17xx_write_sector_callback, (void*)device); |
| 1847 | 1803 | w->pause_time = 40; |
| 1848 | 1804 | |
| 1849 | 1805 | /* resolve callbacks */ |