src/mess/devices/flopdrv.c
| r5998 | r5999 | |
| 39 | 39 | devcb_resolved_write_line out_wpt_func; |
| 40 | 40 | devcb_resolved_write_line out_rdy_func; |
| 41 | 41 | |
| 42 | /* state of output lines */ |
| 43 | int idx; /* index pulse */ |
| 44 | int tk00; /* track 00 */ |
| 45 | int wpt; /* write protect */ |
| 46 | int rdy; /* ready */ |
| 47 | |
| 42 | 48 | const floppy_config *config; |
| 43 | 49 | |
| 44 | 50 | /* flags */ |
| r5998 | r5999 | |
| 57 | 63 | void (*index_pulse_callback)(const device_config *controller,const device_config *image, int state); |
| 58 | 64 | /* rotation per minute => gives index pulse frequency */ |
| 59 | 65 | float rpm; |
| 60 | | /* current index pulse value */ |
| 61 | | int index; |
| 62 | 66 | |
| 63 | 67 | void (*ready_state_change_callback)(const device_config *controller,const device_config *img, int state); |
| 64 | 68 | |
| r5998 | r5999 | |
| 262 | 266 | pDrive->index_pulse_callback = NULL; |
| 263 | 267 | pDrive->ready_state_change_callback = NULL; |
| 264 | 268 | pDrive->index_timer = timer_alloc(img->machine, floppy_drive_index_callback, (void *) img); |
| 265 | | pDrive->index = 0; |
| 269 | pDrive->idx = 0; |
| 266 | 270 | |
| 267 | 271 | floppy_drive_set_geometry(img, ((floppy_config*)img->static_config)->floppy_type); |
| 268 | 272 | |
| r5998 | r5999 | |
| 284 | 288 | /* index pulses at rpm/60 Hz, and stays high 1/20th of time */ |
| 285 | 289 | static void floppy_drive_index_func(const device_config *img) |
| 286 | 290 | { |
| 287 | | floppy_drive *pDrive = get_safe_token( img ); |
| 291 | floppy_drive *drive = get_safe_token( img ); |
| 288 | 292 | |
| 289 | | double ms = 1000. / (pDrive->rpm / 60.); |
| 293 | double ms = 1000.0 / (drive->rpm / 60.0); |
| 290 | 294 | |
| 291 | | if (pDrive->index) |
| 295 | if (drive->idx) |
| 292 | 296 | { |
| 293 | | pDrive->index = 0; |
| 294 | | timer_adjust_oneshot(pDrive->index_timer, double_to_attotime(ms*19/20/1000.0), 0); |
| 297 | drive->idx = 0; |
| 298 | timer_adjust_oneshot(drive->index_timer, double_to_attotime(ms*19/20/1000.0), 0); |
| 295 | 299 | } |
| 296 | 300 | else |
| 297 | 301 | { |
| 298 | | pDrive->index = 1; |
| 299 | | timer_adjust_oneshot(pDrive->index_timer, double_to_attotime(ms/20/1000.0), 0); |
| 302 | drive->idx = 1; |
| 303 | timer_adjust_oneshot(drive->index_timer, double_to_attotime(ms/20/1000.0), 0); |
| 300 | 304 | } |
| 301 | 305 | |
| 302 | | devcb_call_write_line(&pDrive->out_idx_func, pDrive->index); |
| 306 | devcb_call_write_line(&drive->out_idx_func, drive->idx); |
| 303 | 307 | |
| 304 | | if (pDrive->index_pulse_callback) |
| 305 | | pDrive->index_pulse_callback(pDrive->controller, img, pDrive->index); |
| 308 | if (drive->index_pulse_callback) |
| 309 | drive->index_pulse_callback(drive->controller, img, drive->idx); |
| 306 | 310 | } |
| 307 | 311 | |
| 308 | 312 | static TIMER_CALLBACK(floppy_drive_index_callback) |
| r5998 | r5999 | |
| 361 | 365 | if (flag & FLOPPY_DRIVE_READY) |
| 362 | 366 | { |
| 363 | 367 | /* trigger state change callback */ |
| 364 | | devcb_call_write_line(&drv->out_rdy_func, new_state); |
| 368 | devcb_call_write_line(&drv->out_rdy_func, new_state ? ASSERT_LINE : CLEAR_LINE); |
| 365 | 369 | |
| 366 | 370 | if (drv->ready_state_change_callback) |
| 367 | 371 | drv->ready_state_change_callback(drv->controller, img, new_state); |
| r5998 | r5999 | |
| 403 | 407 | { |
| 404 | 408 | floppy_drive *pDrive = get_safe_token( img ); |
| 405 | 409 | |
| 406 | | pDrive->index = 0; |
| 410 | pDrive->idx = 0; |
| 407 | 411 | if (new_motor_state) |
| 408 | 412 | { |
| 409 | 413 | /* off->on */ |
| r5998 | r5999 | |
| 520 | 524 | } |
| 521 | 525 | |
| 522 | 526 | /* set track 0 flag */ |
| 527 | pDrive->tk00 = ASSERT_LINE; |
| 523 | 528 | pDrive->flags &= ~FLOPPY_DRIVE_HEAD_AT_TRACK_0; |
| 524 | 529 | |
| 525 | 530 | if (pDrive->current_track==0) |
| 526 | 531 | { |
| 532 | pDrive->tk00 = CLEAR_LINE; |
| 527 | 533 | pDrive->flags |= FLOPPY_DRIVE_HEAD_AT_TRACK_0; |
| 528 | 534 | } |
| 529 | 535 | |
| 536 | devcb_call_write_line(&pDrive->out_tk00_func, pDrive->tk00); |
| 537 | |
| 530 | 538 | /* inform disk image of step operation so it can cache information */ |
| 531 | 539 | if (image_exists(img)) |
| 532 | 540 | flopimg_seek_callback(img, pDrive->current_track); |