src/mess/machine/wd17xx.c
| r5993 | r5994 | |
| 81 | 81 | |
| 82 | 82 | |
| 83 | 83 | /*************************************************************************** |
| 84 | | |
| 85 | | Parameters |
| 86 | | |
| 84 | CONSTANTS |
| 87 | 85 | ***************************************************************************/ |
| 88 | 86 | |
| 89 | 87 | #define VERBOSE 0 /* General logging */ |
| r5993 | r5994 | |
| 93 | 91 | #define DELAY_NOTREADY 1 |
| 94 | 92 | #define DELAY_DATADONE 3 |
| 95 | 93 | |
| 96 | | |
| 97 | | /* enumeration to specify the type of FDC; there are subtle differences */ |
| 98 | | typedef enum |
| 99 | | { |
| 100 | | WD_TYPE_1770, |
| 101 | | WD_TYPE_1771, |
| 102 | | WD_TYPE_1772, |
| 103 | | WD_TYPE_1773, |
| 104 | | WD_TYPE_179X, |
| 105 | | WD_TYPE_1793, |
| 106 | | WD_TYPE_2793, |
| 107 | | |
| 108 | | /* duplicate constants */ |
| 109 | | WD_TYPE_177X = WD_TYPE_1770, |
| 110 | | WD_TYPE_MB8877 = WD_TYPE_179X |
| 111 | | } wd17xx_type_t; |
| 112 | | |
| 113 | | |
| 114 | | /*************************************************************************** |
| 115 | | |
| 116 | | Constants |
| 117 | | |
| 118 | | ***************************************************************************/ |
| 119 | | |
| 120 | 94 | #define TYPE_I 1 |
| 121 | 95 | #define TYPE_II 2 |
| 122 | 96 | #define TYPE_III 3 |
| r5993 | r5994 | |
| 186 | 160 | /* Type IV commands */ |
| 187 | 161 | #define FDC_FORCE_INT 0xd0 /* force interrupt */ |
| 188 | 162 | |
| 163 | /* enumeration to specify the type of FDC; there are subtle differences */ |
| 164 | typedef enum |
| 165 | { |
| 166 | WD_TYPE_1770, |
| 167 | WD_TYPE_1771, |
| 168 | WD_TYPE_1772, |
| 169 | WD_TYPE_1773, |
| 170 | WD_TYPE_179X, |
| 171 | WD_TYPE_1793, |
| 172 | WD_TYPE_2793, |
| 189 | 173 | |
| 174 | /* duplicate constants */ |
| 175 | WD_TYPE_177X = WD_TYPE_1770, |
| 176 | WD_TYPE_MB8877 = WD_TYPE_179X |
| 177 | } wd17xx_type_t; |
| 190 | 178 | |
| 191 | | /*************************************************************************** |
| 179 | /* structure describing a double density track */ |
| 180 | #define TRKSIZE_DD 6144 |
| 181 | #if 0 |
| 182 | static const UINT8 track_DD[][2] = { |
| 183 | {16, 0x4e}, /* 16 * 4E (track lead in) */ |
| 184 | { 8, 0x00}, /* 8 * 00 (pre DAM) */ |
| 185 | { 3, 0xf5}, /* 3 * F5 (clear CRC) */ |
| 192 | 186 | |
| 193 | | Structures |
| 187 | { 1, 0xfe}, /* *** sector *** FE (DAM) */ |
| 188 | { 1, 0x80}, /* 4 bytes track,head,sector,seclen */ |
| 189 | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 190 | {22, 0x4e}, /* 22 * 4E (sector lead in) */ |
| 191 | {12, 0x00}, /* 12 * 00 (pre AM) */ |
| 192 | { 3, 0xf5}, /* 3 * F5 (clear CRC) */ |
| 193 | { 1, 0xfb}, /* 1 * FB (AM) */ |
| 194 | { 1, 0x81}, /* x bytes sector data */ |
| 195 | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 196 | {16, 0x4e}, /* 16 * 4E (sector lead out) */ |
| 197 | { 8, 0x00}, /* 8 * 00 (post sector) */ |
| 198 | { 0, 0x00}, /* end of data */ |
| 199 | }; |
| 200 | #endif |
| 194 | 201 | |
| 202 | /* structure describing a single density track */ |
| 203 | #define TRKSIZE_SD 3172 |
| 204 | #if 0 |
| 205 | static const UINT8 track_SD[][2] = { |
| 206 | {16, 0xff}, /* 16 * FF (track lead in) */ |
| 207 | { 8, 0x00}, /* 8 * 00 (pre DAM) */ |
| 208 | { 1, 0xfc}, /* 1 * FC (clear CRC) */ |
| 209 | |
| 210 | {11, 0xff}, /* *** sector *** 11 * FF */ |
| 211 | { 6, 0x00}, /* 6 * 00 (pre DAM) */ |
| 212 | { 1, 0xfe}, /* 1 * FE (DAM) */ |
| 213 | { 1, 0x80}, /* 4 bytes track,head,sector,seclen */ |
| 214 | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 215 | {10, 0xff}, /* 10 * FF (sector lead in) */ |
| 216 | { 4, 0x00}, /* 4 * 00 (pre AM) */ |
| 217 | { 1, 0xfb}, /* 1 * FB (AM) */ |
| 218 | { 1, 0x81}, /* x bytes sector data */ |
| 219 | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 220 | { 0, 0x00}, /* end of data */ |
| 221 | }; |
| 222 | #endif |
| 223 | |
| 224 | enum |
| 225 | { |
| 226 | MISCCALLBACK_COMMAND = 0, |
| 227 | MISCCALLBACK_DATA |
| 228 | }; |
| 229 | |
| 230 | |
| 231 | /*************************************************************************** |
| 232 | TYPE DEFINITIONS |
| 195 | 233 | ***************************************************************************/ |
| 196 | 234 | |
| 197 | 235 | typedef struct _wd17xx_t wd17xx_t; |
| r5993 | r5994 | |
| 201 | 239 | devcb_resolved_write_line out_intrq_func; |
| 202 | 240 | devcb_resolved_write_line out_drq_func; |
| 203 | 241 | |
| 242 | /* state of output lines */ |
| 243 | int dirc; /* direction */ |
| 244 | int drq; /* data request */ |
| 245 | int intrq; /* interrupt request */ |
| 246 | |
| 204 | 247 | DENSITY density; /* FM/MFM, single / double density */ |
| 205 | 248 | wd17xx_type_t type; |
| 206 | 249 | UINT8 track_reg; /* value of track register */ |
| r5993 | r5994 | |
| 241 | 284 | emu_timer *busy_timer; |
| 242 | 285 | |
| 243 | 286 | /* this is the drive currently selected */ |
| 244 | | UINT8 current_drive; |
| 287 | const device_config *drive; |
| 245 | 288 | |
| 246 | 289 | /* this is the head currently selected */ |
| 247 | 290 | UINT8 hd; |
| r5993 | r5994 | |
| 253 | 296 | const wd17xx_interface *intf; |
| 254 | 297 | }; |
| 255 | 298 | |
| 299 | |
| 300 | /*************************************************************************** |
| 301 | DEFAULT INTERFACES |
| 302 | ***************************************************************************/ |
| 303 | |
| 304 | const wd17xx_interface default_wd17xx_interface = |
| 305 | { |
| 306 | DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3} |
| 307 | }; |
| 308 | |
| 309 | const wd17xx_interface default_wd17xx_interface_2_drives = |
| 310 | { |
| 311 | DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL} |
| 312 | }; |
| 313 | |
| 314 | |
| 315 | /*************************************************************************** |
| 316 | PROTOTYPES |
| 317 | ***************************************************************************/ |
| 318 | |
| 319 | static void wd17xx_complete_command(const device_config *device, int delay); |
| 320 | static void wd17xx_timed_data_request(const device_config *device); |
| 321 | static TIMER_CALLBACK(wd17xx_misc_timer_callback); |
| 322 | static TIMER_CALLBACK(wd17xx_read_sector_callback); |
| 323 | static TIMER_CALLBACK(wd17xx_write_sector_callback); |
| 324 | static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state); |
| 325 | |
| 326 | |
| 327 | /***************************************************************************** |
| 328 | INLINE FUNCTIONS |
| 329 | *****************************************************************************/ |
| 330 | |
| 256 | 331 | INLINE wd17xx_t *get_safe_token(const device_config *device) |
| 257 | 332 | { |
| 258 | 333 | assert(device != NULL); |
| r5993 | r5994 | |
| 263 | 338 | |
| 264 | 339 | |
| 265 | 340 | /*************************************************************************** |
| 266 | | |
| 267 | | Read track stuff |
| 268 | | |
| 341 | HELPER FUNCTIONS |
| 269 | 342 | ***************************************************************************/ |
| 270 | 343 | |
| 271 | | /* structure describing a double density track */ |
| 272 | | #define TRKSIZE_DD 6144 |
| 273 | | #if 0 |
| 274 | | static const UINT8 track_DD[][2] = { |
| 275 | | {16, 0x4e}, /* 16 * 4E (track lead in) */ |
| 276 | | { 8, 0x00}, /* 8 * 00 (pre DAM) */ |
| 277 | | { 3, 0xf5}, /* 3 * F5 (clear CRC) */ |
| 344 | /* calculate CRC for data address marks or sector data */ |
| 345 | static void calc_crc(UINT16 *crc, UINT8 value) |
| 346 | { |
| 347 | UINT8 l, h; |
| 278 | 348 | |
| 279 | | { 1, 0xfe}, /* *** sector *** FE (DAM) */ |
| 280 | | { 1, 0x80}, /* 4 bytes track,head,sector,seclen */ |
| 281 | | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 282 | | {22, 0x4e}, /* 22 * 4E (sector lead in) */ |
| 283 | | {12, 0x00}, /* 12 * 00 (pre AM) */ |
| 284 | | { 3, 0xf5}, /* 3 * F5 (clear CRC) */ |
| 285 | | { 1, 0xfb}, /* 1 * FB (AM) */ |
| 286 | | { 1, 0x81}, /* x bytes sector data */ |
| 287 | | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 288 | | {16, 0x4e}, /* 16 * 4E (sector lead out) */ |
| 289 | | { 8, 0x00}, /* 8 * 00 (post sector) */ |
| 290 | | { 0, 0x00}, /* end of data */ |
| 291 | | }; |
| 292 | | #endif |
| 293 | | /* structure describing a single density track */ |
| 294 | | #define TRKSIZE_SD 3172 |
| 295 | | #if 0 |
| 296 | | static const UINT8 track_SD[][2] = { |
| 297 | | {16, 0xff}, /* 16 * FF (track lead in) */ |
| 298 | | { 8, 0x00}, /* 8 * 00 (pre DAM) */ |
| 299 | | { 1, 0xfc}, /* 1 * FC (clear CRC) */ |
| 349 | l = value ^ (*crc >> 8); |
| 350 | *crc = (*crc & 0xff) | (l << 8); |
| 351 | l >>= 4; |
| 352 | l ^= (*crc >> 8); |
| 353 | *crc <<= 8; |
| 354 | *crc = (*crc & 0xff00) | l; |
| 355 | l = (l << 4) | (l >> 4); |
| 356 | h = l; |
| 357 | l = (l << 2) | (l >> 6); |
| 358 | l &= 0x1f; |
| 359 | *crc = *crc ^ (l << 8); |
| 360 | l = h & 0xf0; |
| 361 | *crc = *crc ^ (l << 8); |
| 362 | l = (h << 1) | (h >> 7); |
| 363 | l &= 0xe0; |
| 364 | *crc = *crc ^ l; |
| 365 | } |
| 300 | 366 | |
| 301 | | {11, 0xff}, /* *** sector *** 11 * FF */ |
| 302 | | { 6, 0x00}, /* 6 * 00 (pre DAM) */ |
| 303 | | { 1, 0xfe}, /* 1 * FE (DAM) */ |
| 304 | | { 1, 0x80}, /* 4 bytes track,head,sector,seclen */ |
| 305 | | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 306 | | {10, 0xff}, /* 10 * FF (sector lead in) */ |
| 307 | | { 4, 0x00}, /* 4 * 00 (pre AM) */ |
| 308 | | { 1, 0xfb}, /* 1 * FB (AM) */ |
| 309 | | { 1, 0x81}, /* x bytes sector data */ |
| 310 | | { 1, 0xf7}, /* 1 * F7 (CRC) */ |
| 311 | | { 0, 0x00}, /* end of data */ |
| 312 | | }; |
| 313 | | #endif |
| 367 | static int wd17xx_has_side_select(const device_config *device) |
| 368 | { |
| 369 | wd17xx_t *w = get_safe_token(device); |
| 370 | return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793); |
| 371 | } |
| 314 | 372 | |
| 373 | static int wd17xx_get_datarate_in_us(DENSITY density) |
| 374 | { |
| 375 | switch (density) |
| 376 | { |
| 377 | case DEN_FM_LO: return 128; break; |
| 378 | case DEN_FM_HI: return 64; break; |
| 379 | default: |
| 380 | case DEN_MFM_LO: return 32; break; |
| 381 | case DEN_MFM_HI: return 16; break; |
| 382 | } |
| 383 | } |
| 315 | 384 | |
| 316 | 385 | |
| 317 | 386 | /*************************************************************************** |
| 318 | | |
| 319 | | Prototypes |
| 320 | | |
| 387 | IMPLEMENTATION |
| 321 | 388 | ***************************************************************************/ |
| 322 | 389 | |
| 323 | | static void wd17xx_complete_command(const device_config *device, int delay); |
| 324 | | static void wd17xx_clear_data_request(const device_config *device); |
| 325 | | static void wd17xx_set_data_request(const device_config *device); |
| 326 | | static void wd17xx_timed_data_request(const device_config *device); |
| 327 | | static void wd17xx_set_irq(const device_config *device); |
| 328 | | /**************************************************************************/ |
| 329 | | |
| 330 | | static const device_config *wd17xx_current_image(const device_config *device) |
| 390 | /* clear a data request */ |
| 391 | static void wd17xx_clear_drq(const device_config *device) |
| 331 | 392 | { |
| 332 | 393 | wd17xx_t *w = get_safe_token(device); |
| 333 | | if (w->intf->floppy_drive_tags[w->current_drive]!=NULL) { |
| 334 | | return devtag_get_device(device->machine,w->intf->floppy_drive_tags[w->current_drive]); |
| 335 | | } else { |
| 336 | | return NULL; |
| 337 | | } |
| 338 | | } |
| 339 | 394 | |
| 395 | w->status &= ~STA_2_DRQ; |
| 340 | 396 | |
| 397 | w->drq = CLEAR_LINE; |
| 398 | devcb_call_write_line(&w->out_drq_func, w->drq); |
| 399 | } |
| 341 | 400 | |
| 342 | | /* use this to determine which drive is controlled by WD */ |
| 343 | | void wd17xx_set_drive(const device_config *device,UINT8 drive) |
| 401 | /* set data request */ |
| 402 | static void wd17xx_set_drq(const device_config *device) |
| 344 | 403 | { |
| 345 | 404 | wd17xx_t *w = get_safe_token(device); |
| 346 | | if (VERBOSE) |
| 347 | | { |
| 348 | | if (drive != w->current_drive) |
| 349 | | logerror("wd17xx_set_drive: $%02x\n", drive); |
| 350 | | } |
| 351 | | w->current_drive = drive; |
| 405 | |
| 406 | if (w->status & STA_2_DRQ) |
| 407 | w->status |= STA_2_LOST_DAT; |
| 408 | |
| 409 | w->status |= STA_2_DRQ; |
| 410 | |
| 411 | w->drq = ASSERT_LINE; |
| 412 | devcb_call_write_line(&w->out_drq_func, w->drq); |
| 352 | 413 | } |
| 353 | 414 | |
| 354 | | void wd17xx_set_side(const device_config *device,UINT8 head) |
| 415 | /* clear interrupt request */ |
| 416 | static void wd17xx_clear_intrq(const device_config *device) |
| 355 | 417 | { |
| 356 | 418 | wd17xx_t *w = get_safe_token(device); |
| 357 | | if (VERBOSE) |
| 358 | | { |
| 359 | | if (head != w->hd) |
| 360 | | logerror("wd17xx_set_side: $%02x\n", head); |
| 361 | | } |
| 362 | | w->hd = head; |
| 419 | |
| 420 | w->intrq = CLEAR_LINE; |
| 421 | devcb_call_write_line(&w->out_intrq_func, w->intrq); |
| 363 | 422 | } |
| 364 | 423 | |
| 365 | | |
| 366 | | |
| 367 | | void wd17xx_set_density(const device_config *device,DENSITY density) |
| 424 | /* set interrupt request */ |
| 425 | static void wd17xx_set_intrq(const device_config *device) |
| 368 | 426 | { |
| 369 | 427 | wd17xx_t *w = get_safe_token(device); |
| 370 | 428 | |
| 371 | | if (VERBOSE) |
| 372 | | { |
| 373 | | if (w->density != density) |
| 374 | | logerror("wd17xx_set_density: $%02x\n", density); |
| 375 | | } |
| 429 | w->status &= ~STA_2_BUSY; |
| 376 | 430 | |
| 377 | | w->density = density; |
| 431 | w->intrq = ASSERT_LINE; |
| 432 | devcb_call_write_line(&w->out_intrq_func, w->intrq); |
| 378 | 433 | } |
| 379 | 434 | |
| 380 | 435 | |
| 381 | 436 | |
| 382 | | static TIMER_CALLBACK(wd17xx_busy_callback) |
| 437 | static TIMER_CALLBACK( wd17xx_busy_callback ) |
| 383 | 438 | { |
| 384 | 439 | const device_config *device = ptr; |
| 385 | 440 | wd17xx_t *w = get_safe_token(device); |
| 386 | | wd17xx_set_irq(device); |
| 441 | wd17xx_set_intrq(device); |
| 387 | 442 | timer_reset(w->busy_timer, attotime_never); |
| 388 | 443 | } |
| 389 | 444 | |
| r5993 | r5994 | |
| 392 | 447 | static void wd17xx_set_busy(const device_config *device, attotime duration) |
| 393 | 448 | { |
| 394 | 449 | wd17xx_t *w = get_safe_token(device); |
| 450 | |
| 395 | 451 | w->status |= STA_1_BUSY; |
| 396 | 452 | timer_adjust_oneshot(w->busy_timer, duration, 0); |
| 397 | 453 | } |
| r5993 | r5994 | |
| 402 | 458 | |
| 403 | 459 | static void wd17xx_restore(const device_config *device) |
| 404 | 460 | { |
| 405 | | UINT8 step_counter; |
| 406 | 461 | wd17xx_t *w = get_safe_token(device); |
| 462 | UINT8 step_counter; |
| 407 | 463 | |
| 408 | | if (w->current_drive >= floppy_get_count(device->machine)) |
| 464 | if (w->drive == NULL) |
| 409 | 465 | return; |
| 410 | 466 | |
| 411 | 467 | step_counter = 255; |
| r5993 | r5994 | |
| 422 | 478 | /* reset busy count */ |
| 423 | 479 | w->busy_count = 0; |
| 424 | 480 | |
| 425 | | if (image_slotexists(wd17xx_current_image(device))) |
| 481 | if (image_slotexists(w->drive)) |
| 426 | 482 | { |
| 427 | 483 | /* keep stepping until track 0 is received or 255 steps have been done */ |
| 428 | | while (!(floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0)) |
| 484 | while (!(floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_HEAD_AT_TRACK_0)) && (step_counter!=0)) |
| 429 | 485 | { |
| 430 | 486 | /* update time to simulate seek time busy signal */ |
| 431 | 487 | w->busy_count++; |
| 432 | | floppy_drive_seek(wd17xx_current_image(device), w->direction); |
| 488 | floppy_drive_seek(w->drive, w->direction); |
| 433 | 489 | step_counter--; |
| 434 | 490 | } |
| 435 | 491 | } |
| r5993 | r5994 | |
| 441 | 497 | w->busy_count = 0; //w->busy_count * ((w->data & FDC_STEP_RATE) + 1); |
| 442 | 498 | |
| 443 | 499 | /* when command completes set irq */ |
| 444 | | wd17xx_set_irq(device); |
| 500 | wd17xx_set_intrq(device); |
| 445 | 501 | #endif |
| 446 | 502 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(100)); |
| 447 | 503 | } |
| 448 | 504 | |
| 449 | 505 | |
| 450 | | |
| 451 | | static TIMER_CALLBACK(wd17xx_misc_timer_callback); |
| 452 | | static TIMER_CALLBACK(wd17xx_read_sector_callback); |
| 453 | | static TIMER_CALLBACK(wd17xx_write_sector_callback); |
| 454 | | static void wd17xx_index_pulse_callback(const device_config *controller,const device_config *img, int state); |
| 455 | | |
| 456 | | |
| 457 | 506 | /* track writing, converted to format commands */ |
| 458 | 507 | static void write_track(const device_config *device) |
| 459 | 508 | { |
| r5993 | r5994 | |
| 470 | 519 | //int len = w->buffer[i+4]; |
| 471 | 520 | int filler = 0xe5; /* IBM and Thomson */ |
| 472 | 521 | int density = w->density; |
| 473 | | floppy_drive_format_sector(wd17xx_current_image(device),side,sector,track, |
| 522 | floppy_drive_format_sector(w->drive,side,sector,track, |
| 474 | 523 | w->hd,sector,density?1:0,filler); |
| 475 | 524 | i += 128; /* at least... */ |
| 476 | 525 | } |
| r5993 | r5994 | |
| 480 | 529 | } |
| 481 | 530 | |
| 482 | 531 | |
| 483 | | |
| 484 | 532 | /* read an entire track */ |
| 485 | 533 | static void read_track(const device_config *device) |
| 486 | 534 | { |
| r5993 | r5994 | |
| 609 | 657 | else |
| 610 | 658 | w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD; |
| 611 | 659 | |
| 612 | | floppy_drive_read_track_data_info_buffer( wd17xx_current_image(device), w->hd, (char *)w->buffer, &(w->data_count) ); |
| 660 | floppy_drive_read_track_data_info_buffer( w->drive, w->hd, (char *)w->buffer, &(w->data_count) ); |
| 613 | 661 | |
| 614 | 662 | w->data_offset = 0; |
| 615 | 663 | |
| 616 | | wd17xx_set_data_request(device); |
| 664 | wd17xx_set_drq(device); |
| 617 | 665 | w->status |= STA_2_BUSY; |
| 618 | 666 | w->busy_count = 0; |
| 619 | 667 | } |
| 620 | 668 | |
| 621 | 669 | |
| 622 | | |
| 623 | | /* calculate CRC for data address marks or sector data */ |
| 624 | | static void calc_crc(UINT16 * crc, UINT8 value) |
| 625 | | { |
| 626 | | UINT8 l, h; |
| 627 | | |
| 628 | | l = value ^ (*crc >> 8); |
| 629 | | *crc = (*crc & 0xff) | (l << 8); |
| 630 | | l >>= 4; |
| 631 | | l ^= (*crc >> 8); |
| 632 | | *crc <<= 8; |
| 633 | | *crc = (*crc & 0xff00) | l; |
| 634 | | l = (l << 4) | (l >> 4); |
| 635 | | h = l; |
| 636 | | l = (l << 2) | (l >> 6); |
| 637 | | l &= 0x1f; |
| 638 | | *crc = *crc ^ (l << 8); |
| 639 | | l = h & 0xf0; |
| 640 | | *crc = *crc ^ (l << 8); |
| 641 | | l = (h << 1) | (h >> 7); |
| 642 | | l &= 0xe0; |
| 643 | | *crc = *crc ^ l; |
| 644 | | } |
| 645 | | |
| 646 | | |
| 647 | | |
| 648 | 670 | /* read the next data address mark */ |
| 649 | 671 | static void wd17xx_read_id(const device_config *device) |
| 650 | 672 | { |
| r5993 | r5994 | |
| 654 | 676 | w->status &= ~(STA_2_CRC_ERR | STA_2_REC_N_FND); |
| 655 | 677 | |
| 656 | 678 | /* get next id from disc */ |
| 657 | | if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id)) |
| 679 | if (floppy_drive_get_next_id(w->drive, w->hd, &id)) |
| 658 | 680 | { |
| 659 | 681 | UINT16 crc = 0xffff; |
| 660 | 682 | |
| r5993 | r5994 | |
| 684 | 706 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(400)); |
| 685 | 707 | w->busy_count = 0; |
| 686 | 708 | |
| 687 | | wd17xx_set_data_request(device); |
| 709 | wd17xx_set_drq(device); |
| 688 | 710 | |
| 689 | 711 | if (VERBOSE) |
| 690 | 712 | logerror("read id succeeded.\n"); |
| r5993 | r5994 | |
| 706 | 728 | static void wd17xx_index_pulse_callback(const device_config *controller, const device_config *img, int state) |
| 707 | 729 | { |
| 708 | 730 | wd17xx_t *w = get_safe_token(controller); |
| 709 | | if ( img != wd17xx_current_image(controller) ) |
| 731 | |
| 732 | if (img != w->drive) |
| 710 | 733 | return; |
| 734 | |
| 711 | 735 | w->ipl = state; |
| 712 | 736 | |
| 713 | 737 | if (w->hld_count) |
| r5993 | r5994 | |
| 716 | 740 | |
| 717 | 741 | |
| 718 | 742 | |
| 719 | | static int wd17xx_has_side_select(const device_config *device) |
| 720 | | { |
| 721 | | wd17xx_t *w = get_safe_token(device); |
| 722 | | return (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_2793); |
| 723 | | } |
| 724 | | |
| 725 | | |
| 726 | | |
| 727 | 743 | static int wd17xx_locate_sector(const device_config *device) |
| 728 | 744 | { |
| 729 | 745 | UINT8 revolution_count; |
| r5993 | r5994 | |
| 736 | 752 | |
| 737 | 753 | while (revolution_count!=4) |
| 738 | 754 | { |
| 739 | | if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id)) |
| 755 | if (floppy_drive_get_next_id(w->drive, w->hd, &id)) |
| 740 | 756 | { |
| 741 | 757 | /* compare track */ |
| 742 | 758 | if (id.C == w->track_reg) |
| r5993 | r5994 | |
| 761 | 777 | } |
| 762 | 778 | |
| 763 | 779 | /* index set? */ |
| 764 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX)) |
| 780 | if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX)) |
| 765 | 781 | { |
| 766 | 782 | /* update revolution count */ |
| 767 | 783 | revolution_count++; |
| r5993 | r5994 | |
| 809 | 825 | w->data_count = w->sector_length; |
| 810 | 826 | |
| 811 | 827 | /* read data */ |
| 812 | | floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length); |
| 828 | floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length); |
| 813 | 829 | |
| 814 | 830 | wd17xx_timed_data_request(device); |
| 815 | 831 | |
| r5993 | r5994 | |
| 820 | 836 | |
| 821 | 837 | |
| 822 | 838 | |
| 823 | | static void wd17xx_set_irq(const device_config *device) |
| 824 | | { |
| 825 | | wd17xx_t *w = get_safe_token(device); |
| 826 | | |
| 827 | | w->status &= ~STA_2_BUSY; |
| 828 | | devcb_call_write_line(&w->out_intrq_func, ASSERT_LINE); |
| 829 | | } |
| 830 | | |
| 831 | | |
| 832 | | |
| 833 | | /* 0=command callback; 1=data callback */ |
| 834 | | enum |
| 835 | | { |
| 836 | | MISCCALLBACK_COMMAND, |
| 837 | | MISCCALLBACK_DATA |
| 838 | | }; |
| 839 | | |
| 840 | | |
| 841 | | |
| 842 | 839 | static TIMER_CALLBACK(wd17xx_misc_timer_callback) |
| 843 | 840 | { |
| 844 | 841 | const device_config *device = ptr; |
| r5993 | r5994 | |
| 848 | 845 | switch(callback_type) { |
| 849 | 846 | case MISCCALLBACK_COMMAND: |
| 850 | 847 | /* command callback */ |
| 851 | | wd17xx_set_irq(device); |
| 848 | wd17xx_set_intrq(device); |
| 852 | 849 | break; |
| 853 | 850 | |
| 854 | 851 | case MISCCALLBACK_DATA: |
| 855 | 852 | /* data callback */ |
| 856 | 853 | /* ok, trigger data request now */ |
| 857 | | wd17xx_set_data_request(device); |
| 854 | wd17xx_set_drq(device); |
| 858 | 855 | break; |
| 859 | 856 | } |
| 860 | 857 | |
| r5993 | r5994 | |
| 862 | 859 | timer_reset(w->timer, attotime_never); |
| 863 | 860 | } |
| 864 | 861 | |
| 865 | | int wd17xx_get_datarate_in_us(DENSITY density) |
| 866 | | { |
| 867 | | int usecs; |
| 868 | | /* 64 for single density */ |
| 869 | | switch (density) |
| 870 | | { |
| 871 | | case DEN_FM_LO: |
| 872 | | { |
| 873 | | usecs = 128; |
| 874 | | } |
| 875 | | break; |
| 876 | 862 | |
| 877 | | case DEN_FM_HI: |
| 878 | | { |
| 879 | | usecs = 64; |
| 880 | | } |
| 881 | | break; |
| 882 | | |
| 883 | | default: |
| 884 | | case DEN_MFM_LO: |
| 885 | | { |
| 886 | | usecs = 32; |
| 887 | | } |
| 888 | | break; |
| 889 | | |
| 890 | | case DEN_MFM_HI: |
| 891 | | { |
| 892 | | usecs = 16; |
| 893 | | } |
| 894 | | break; |
| 895 | | } |
| 896 | | |
| 897 | | return usecs; |
| 898 | | } |
| 899 | | |
| 900 | 863 | /* called on error, or when command is actually completed */ |
| 901 | 864 | /* KT - I have used a timer for systems that use interrupt driven transfers. |
| 902 | 865 | A interrupt occurs after the last byte has been read. If it occurs at the time |
| r5993 | r5994 | |
| 951 | 914 | w->data_count = w->sector_length; |
| 952 | 915 | |
| 953 | 916 | /* write data */ |
| 954 | | floppy_drive_write_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01); |
| 917 | floppy_drive_write_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length, w->write_cmd & 0x01); |
| 955 | 918 | } |
| 956 | 919 | } |
| 957 | 920 | |
| r5993 | r5994 | |
| 974 | 937 | /* must be found within 5 revolutions otherwise error */ |
| 975 | 938 | while (revolution_count!=5) |
| 976 | 939 | { |
| 977 | | if (floppy_drive_get_next_id(wd17xx_current_image(device), w->hd, &id)) |
| 940 | if (floppy_drive_get_next_id(w->drive, w->hd, &id)) |
| 978 | 941 | { |
| 979 | 942 | /* compare track */ |
| 980 | 943 | if (id.C == w->track_reg) |
| r5993 | r5994 | |
| 986 | 949 | } |
| 987 | 950 | |
| 988 | 951 | /* index set? */ |
| 989 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_INDEX)) |
| 952 | if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_INDEX)) |
| 990 | 953 | { |
| 991 | 954 | /* update revolution count */ |
| 992 | 955 | revolution_count++; |
| r5993 | r5994 | |
| 1001 | 964 | |
| 1002 | 965 | |
| 1003 | 966 | |
| 1004 | | /* clear a data request */ |
| 1005 | | static void wd17xx_clear_data_request(const device_config *device) |
| 1006 | | { |
| 1007 | | wd17xx_t *w = get_safe_token(device); |
| 1008 | | |
| 1009 | | // w->status_drq = 0; |
| 1010 | | w->status &= ~STA_2_DRQ; |
| 1011 | | devcb_call_write_line(&w->out_drq_func, CLEAR_LINE); |
| 1012 | | } |
| 1013 | | |
| 1014 | | |
| 1015 | | |
| 1016 | | /* set data request */ |
| 1017 | | static void wd17xx_set_data_request(const device_config *device) |
| 1018 | | { |
| 1019 | | wd17xx_t *w = get_safe_token(device); |
| 1020 | | |
| 1021 | | if (w->status & STA_2_DRQ) |
| 1022 | | { |
| 1023 | | w->status |= STA_2_LOST_DAT; |
| 1024 | | // return; |
| 1025 | | } |
| 1026 | | |
| 1027 | | /* set drq */ |
| 1028 | | // w->status_drq = STA_2_DRQ; |
| 1029 | | w->status |= STA_2_DRQ; |
| 1030 | | devcb_call_write_line(&w->out_drq_func, ASSERT_LINE); |
| 1031 | | } |
| 1032 | | |
| 1033 | | |
| 1034 | | |
| 1035 | 967 | /* callback to initiate read sector */ |
| 1036 | | static TIMER_CALLBACK(wd17xx_read_sector_callback) |
| 968 | static TIMER_CALLBACK( wd17xx_read_sector_callback ) |
| 1037 | 969 | { |
| 1038 | 970 | const device_config *device = ptr; |
| 1039 | 971 | wd17xx_t *w = get_safe_token(device); |
| r5993 | r5994 | |
| 1043 | 975 | if (VERBOSE) |
| 1044 | 976 | logerror("wd179x: Read Sector callback.\n"); |
| 1045 | 977 | |
| 1046 | | if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 978 | if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1047 | 979 | wd17xx_complete_command(device, DELAY_NOTREADY); |
| 1048 | 980 | else |
| 1049 | 981 | wd17xx_read_sector(device); |
| r5993 | r5994 | |
| 1065 | 997 | if (VERBOSE) |
| 1066 | 998 | logerror("wd179x: Write Sector callback.\n"); |
| 1067 | 999 | |
| 1068 | | if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 1000 | if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1069 | 1001 | wd17xx_complete_command(device, DELAY_NOTREADY); |
| 1070 | 1002 | else |
| 1071 | 1003 | { |
| 1072 | 1004 | |
| 1073 | 1005 | /* drive write protected? */ |
| 1074 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) |
| 1006 | if (floppy_drive_get_flag_state(w->drive,FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) |
| 1075 | 1007 | { |
| 1076 | 1008 | w->status |= STA_2_WRITE_PRO; |
| 1077 | 1009 | |
| r5993 | r5994 | |
| 1092 | 1024 | w->data_offset = 0; |
| 1093 | 1025 | w->data_count = w->sector_length; |
| 1094 | 1026 | |
| 1095 | | wd17xx_set_data_request(device); |
| 1027 | wd17xx_set_drq(device); |
| 1096 | 1028 | |
| 1097 | 1029 | w->status |= STA_2_BUSY; |
| 1098 | 1030 | w->busy_count = 0; |
| r5993 | r5994 | |
| 1146 | 1078 | timer_reset(w->timer_ws, ATTOTIME_IN_USEC(usecs)); |
| 1147 | 1079 | } |
| 1148 | 1080 | |
| 1149 | | void wd17xx_set_pause_time(const device_config *device,int usec) |
| 1081 | |
| 1082 | /*************************************************************************** |
| 1083 | INTERFACE |
| 1084 | ***************************************************************************/ |
| 1085 | |
| 1086 | /* use this to determine which drive is controlled by WD */ |
| 1087 | void wd17xx_set_drive(const device_config *device, UINT8 drive) |
| 1150 | 1088 | { |
| 1151 | 1089 | wd17xx_t *w = get_safe_token(device); |
| 1090 | |
| 1091 | if (VERBOSE) |
| 1092 | logerror("wd17xx_set_drive: $%02x\n", drive); |
| 1093 | |
| 1094 | if (w->intf->floppy_drive_tags[drive] != NULL) |
| 1095 | w->drive = devtag_get_device(device->machine, w->intf->floppy_drive_tags[drive]); |
| 1096 | } |
| 1097 | |
| 1098 | void wd17xx_set_side(const device_config *device, UINT8 head) |
| 1099 | { |
| 1100 | wd17xx_t *w = get_safe_token(device); |
| 1101 | |
| 1102 | if (VERBOSE) |
| 1103 | { |
| 1104 | if (head != w->hd) |
| 1105 | logerror("wd17xx_set_side: $%02x\n", head); |
| 1106 | } |
| 1107 | |
| 1108 | w->hd = head; |
| 1109 | } |
| 1110 | |
| 1111 | void wd17xx_set_density(const device_config *device, DENSITY density) |
| 1112 | { |
| 1113 | wd17xx_t *w = get_safe_token(device); |
| 1114 | |
| 1115 | if (VERBOSE) |
| 1116 | { |
| 1117 | if (w->density != density) |
| 1118 | logerror("wd17xx_set_density: $%02x\n", density); |
| 1119 | } |
| 1120 | |
| 1121 | w->density = density; |
| 1122 | } |
| 1123 | |
| 1124 | void wd17xx_set_pause_time(const device_config *device, int usec) |
| 1125 | { |
| 1126 | wd17xx_t *w = get_safe_token(device); |
| 1152 | 1127 | w->pause_time = usec; |
| 1153 | 1128 | } |
| 1154 | 1129 | |
| 1130 | |
| 1131 | /*************************************************************************** |
| 1132 | DEVICE HANDLERS |
| 1133 | ***************************************************************************/ |
| 1134 | |
| 1135 | READ_LINE_DEVICE_HANDLER( wd17xx_drq_r ) |
| 1136 | { |
| 1137 | wd17xx_t *w = get_safe_token(device); |
| 1138 | return w->drq; |
| 1139 | } |
| 1140 | |
| 1141 | READ_LINE_DEVICE_HANDLER( wd17xx_intrq_r ) |
| 1142 | { |
| 1143 | wd17xx_t *w = get_safe_token(device); |
| 1144 | return w->intrq; |
| 1145 | } |
| 1146 | |
| 1155 | 1147 | /* read the FDC status register. This clears IRQ line too */ |
| 1156 | | READ8_DEVICE_HANDLER ( wd17xx_status_r ) |
| 1148 | READ8_DEVICE_HANDLER( wd17xx_status_r ) |
| 1157 | 1149 | { |
| 1158 | 1150 | wd17xx_t *w = get_safe_token(device); |
| 1159 | 1151 | int result = w->status; |
| 1160 | 1152 | |
| 1161 | | devcb_call_write_line(&w->out_intrq_func, CLEAR_LINE); |
| 1153 | wd17xx_clear_intrq(device); |
| 1162 | 1154 | |
| 1163 | 1155 | /* type 1 command or force int command? */ |
| 1164 | 1156 | if ((w->command_type==TYPE_I) || (w->command_type==TYPE_IV)) |
| r5993 | r5994 | |
| 1169 | 1161 | |
| 1170 | 1162 | /* set track 0 state */ |
| 1171 | 1163 | result &=~STA_1_TRACK0; |
| 1172 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_HEAD_AT_TRACK_0)) |
| 1164 | if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_HEAD_AT_TRACK_0)) |
| 1173 | 1165 | result |= STA_1_TRACK0; |
| 1174 | 1166 | |
| 1175 | | // floppy_drive_set_ready_state(wd17xx_current_image(device), 1,1); |
| 1167 | // floppy_drive_set_ready_state(w->drive, 1,1); |
| 1176 | 1168 | w->status &= ~STA_1_NOT_READY; |
| 1177 | 1169 | |
| 1178 | 1170 | /* TODO: What is this? We need some more info on this */ |
| 1179 | 1171 | if ((w->type == WD_TYPE_179X) || (w->type == WD_TYPE_1793) || (w->type == WD_TYPE_1773) || (w->type == WD_TYPE_1771)) |
| 1180 | 1172 | { |
| 1181 | | if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 1173 | if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1182 | 1174 | w->status |= STA_1_NOT_READY; |
| 1183 | 1175 | } |
| 1184 | 1176 | else |
| 1185 | 1177 | { |
| 1186 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 1178 | if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1187 | 1179 | w->status |= STA_1_NOT_READY; |
| 1188 | 1180 | } |
| 1189 | 1181 | |
| r5993 | r5994 | |
| 1209 | 1201 | return result; |
| 1210 | 1202 | } |
| 1211 | 1203 | |
| 1212 | | |
| 1213 | | |
| 1214 | 1204 | /* read the FDC track register */ |
| 1215 | | READ8_DEVICE_HANDLER ( wd17xx_track_r ) |
| 1205 | READ8_DEVICE_HANDLER( wd17xx_track_r ) |
| 1216 | 1206 | { |
| 1217 | 1207 | wd17xx_t *w = get_safe_token(device); |
| 1218 | 1208 | |
| r5993 | r5994 | |
| 1222 | 1212 | return w->track_reg; |
| 1223 | 1213 | } |
| 1224 | 1214 | |
| 1225 | | |
| 1226 | | |
| 1227 | 1215 | /* read the FDC sector register */ |
| 1228 | | READ8_DEVICE_HANDLER ( wd17xx_sector_r ) |
| 1216 | READ8_DEVICE_HANDLER( wd17xx_sector_r ) |
| 1229 | 1217 | { |
| 1230 | 1218 | wd17xx_t *w = get_safe_token(device); |
| 1231 | 1219 | |
| r5993 | r5994 | |
| 1235 | 1223 | return w->sector; |
| 1236 | 1224 | } |
| 1237 | 1225 | |
| 1238 | | |
| 1239 | | |
| 1240 | 1226 | /* read the FDC data register */ |
| 1241 | | READ8_DEVICE_HANDLER ( wd17xx_data_r ) |
| 1227 | READ8_DEVICE_HANDLER( wd17xx_data_r ) |
| 1242 | 1228 | { |
| 1243 | 1229 | wd17xx_t *w = get_safe_token(device); |
| 1244 | 1230 | |
| 1245 | 1231 | if (w->data_count >= 1) |
| 1246 | 1232 | { |
| 1247 | 1233 | /* clear data request */ |
| 1248 | | wd17xx_clear_data_request(device); |
| 1234 | wd17xx_clear_drq(device); |
| 1249 | 1235 | |
| 1250 | 1236 | /* yes */ |
| 1251 | 1237 | w->data = w->buffer[w->data_offset++]; |
| r5993 | r5994 | |
| 1276 | 1262 | w->data_count = w->sector_length; |
| 1277 | 1263 | |
| 1278 | 1264 | /* read data */ |
| 1279 | | floppy_drive_read_sector_data(wd17xx_current_image(device), w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length); |
| 1265 | floppy_drive_read_sector_data(w->drive, w->hd, w->sector_data_id, (char *)w->buffer, w->sector_length); |
| 1280 | 1266 | |
| 1281 | 1267 | wd17xx_timed_data_request(device); |
| 1282 | 1268 | |
| r5993 | r5994 | |
| 1314 | 1300 | return w->data; |
| 1315 | 1301 | } |
| 1316 | 1302 | |
| 1317 | | |
| 1318 | | |
| 1319 | 1303 | /* write the FDC command register */ |
| 1320 | | WRITE8_DEVICE_HANDLER ( wd17xx_command_w ) |
| 1304 | WRITE8_DEVICE_HANDLER( wd17xx_command_w ) |
| 1321 | 1305 | { |
| 1322 | 1306 | wd17xx_t *w = get_safe_token(device); |
| 1323 | 1307 | |
| 1324 | | floppy_drive_set_motor_state(wd17xx_current_image(device), 1); |
| 1325 | | floppy_drive_set_ready_state(wd17xx_current_image(device), 1,0); |
| 1308 | floppy_drive_set_motor_state(w->drive, 1); |
| 1309 | floppy_drive_set_ready_state(w->drive, 1,0); |
| 1310 | |
| 1326 | 1311 | /* also cleared by writing command */ |
| 1327 | | devcb_call_write_line(&w->out_intrq_func, CLEAR_LINE); |
| 1312 | wd17xx_clear_intrq(device); |
| 1328 | 1313 | |
| 1329 | 1314 | /* clear write protected. On read sector, read track and read dam, write protected bit is clear */ |
| 1330 | 1315 | w->status &= ~((1<<6) | (1<<5) | (1<<4)); |
| r5993 | r5994 | |
| 1339 | 1324 | w->status &= ~STA_2_BUSY; |
| 1340 | 1325 | w->status &= ~STA_2_LOST_DAT; |
| 1341 | 1326 | |
| 1342 | | wd17xx_clear_data_request(device); |
| 1327 | wd17xx_clear_drq(device); |
| 1343 | 1328 | |
| 1344 | 1329 | if (data & 0x0f) |
| 1345 | 1330 | { |
| r5993 | r5994 | |
| 1371 | 1356 | w->command_type = TYPE_II; |
| 1372 | 1357 | w->status &= ~STA_2_LOST_DAT; |
| 1373 | 1358 | w->status |= STA_2_BUSY; |
| 1374 | | wd17xx_clear_data_request(device); |
| 1359 | wd17xx_clear_drq(device); |
| 1375 | 1360 | |
| 1376 | 1361 | wd17xx_timed_read_sector_request(device); |
| 1377 | 1362 | |
| r5993 | r5994 | |
| 1388 | 1373 | w->command_type = TYPE_II; |
| 1389 | 1374 | w->status &= ~STA_2_LOST_DAT; |
| 1390 | 1375 | w->status |= STA_2_BUSY; |
| 1391 | | wd17xx_clear_data_request(device); |
| 1376 | wd17xx_clear_drq(device); |
| 1392 | 1377 | |
| 1393 | 1378 | wd17xx_timed_write_sector_request(device); |
| 1394 | 1379 | |
| r5993 | r5994 | |
| 1403 | 1388 | w->command = data & ~FDC_MASK_TYPE_III; |
| 1404 | 1389 | w->command_type = TYPE_III; |
| 1405 | 1390 | w->status &= ~STA_2_LOST_DAT; |
| 1406 | | wd17xx_clear_data_request(device); |
| 1391 | wd17xx_clear_drq(device); |
| 1407 | 1392 | #if 1 |
| 1408 | 1393 | // w->status = seek(w, w->track, w->head, w->sector); |
| 1409 | 1394 | if (w->status == 0) |
| r5993 | r5994 | |
| 1419 | 1404 | |
| 1420 | 1405 | w->command_type = TYPE_III; |
| 1421 | 1406 | w->status &= ~STA_2_LOST_DAT; |
| 1422 | | wd17xx_clear_data_request(device); |
| 1407 | wd17xx_clear_drq(device); |
| 1423 | 1408 | |
| 1424 | | if (!floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 1409 | if (!floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1425 | 1410 | { |
| 1426 | 1411 | wd17xx_complete_command(device, DELAY_NOTREADY); |
| 1427 | 1412 | } |
| r5993 | r5994 | |
| 1429 | 1414 | { |
| 1430 | 1415 | |
| 1431 | 1416 | /* drive write protected? */ |
| 1432 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device),FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) |
| 1417 | if (floppy_drive_get_flag_state(w->drive,FLOPPY_DRIVE_DISK_WRITE_PROTECTED)) |
| 1433 | 1418 | { |
| 1434 | 1419 | /* yes */ |
| 1435 | 1420 | w->status |= STA_2_WRITE_PRO; |
| r5993 | r5994 | |
| 1444 | 1429 | w->data_count = TRKSIZE_SD; |
| 1445 | 1430 | else |
| 1446 | 1431 | w->data_count = (w->density) ? TRKSIZE_DD : TRKSIZE_SD; |
| 1447 | | wd17xx_set_data_request(device); |
| 1432 | wd17xx_set_drq(device); |
| 1448 | 1433 | w->status |= STA_2_BUSY; |
| 1449 | 1434 | w->busy_count = 0; |
| 1450 | 1435 | } |
| r5993 | r5994 | |
| 1459 | 1444 | |
| 1460 | 1445 | w->command_type = TYPE_III; |
| 1461 | 1446 | w->status &= ~STA_2_LOST_DAT; |
| 1462 | | wd17xx_clear_data_request(device); |
| 1447 | wd17xx_clear_drq(device); |
| 1463 | 1448 | |
| 1464 | | if (floppy_drive_get_flag_state(wd17xx_current_image(device), FLOPPY_DRIVE_READY)) |
| 1449 | if (floppy_drive_get_flag_state(w->drive, FLOPPY_DRIVE_READY)) |
| 1465 | 1450 | wd17xx_read_id(device); |
| 1466 | 1451 | else |
| 1467 | 1452 | wd17xx_complete_command(device, DELAY_NOTREADY); |
| r5993 | r5994 | |
| 1528 | 1513 | /* update track reg */ |
| 1529 | 1514 | w->track_reg += w->direction; |
| 1530 | 1515 | |
| 1531 | | floppy_drive_seek(wd17xx_current_image(device), w->direction); |
| 1516 | floppy_drive_seek(w->drive, w->direction); |
| 1532 | 1517 | } |
| 1533 | 1518 | |
| 1534 | 1519 | /* simulate seek time busy signal */ |
| 1535 | 1520 | w->busy_count = 0; //w->busy_count * ((data & FDC_STEP_RATE) + 1); |
| 1536 | 1521 | #if 0 |
| 1537 | | wd17xx_set_irq(device); |
| 1522 | wd17xx_set_intrq(device); |
| 1538 | 1523 | #endif |
| 1539 | 1524 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(100)); |
| 1540 | 1525 | |
| r5993 | r5994 | |
| 1550 | 1535 | /* simulate seek time busy signal */ |
| 1551 | 1536 | w->busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1552 | 1537 | |
| 1553 | | floppy_drive_seek(wd17xx_current_image(device), w->direction); |
| 1538 | floppy_drive_seek(w->drive, w->direction); |
| 1554 | 1539 | |
| 1555 | 1540 | if (data & FDC_STEP_UPDATE) |
| 1556 | 1541 | w->track_reg += w->direction; |
| 1557 | 1542 | |
| 1558 | 1543 | #if 0 |
| 1559 | | wd17xx_set_irq(device); |
| 1544 | wd17xx_set_intrq(device); |
| 1560 | 1545 | #endif |
| 1561 | 1546 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(100)); |
| 1562 | 1547 | |
| r5993 | r5994 | |
| 1573 | 1558 | /* simulate seek time busy signal */ |
| 1574 | 1559 | w->busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1575 | 1560 | |
| 1576 | | floppy_drive_seek(wd17xx_current_image(device), w->direction); |
| 1561 | floppy_drive_seek(w->drive, w->direction); |
| 1577 | 1562 | |
| 1578 | 1563 | if (data & FDC_STEP_UPDATE) |
| 1579 | 1564 | w->track_reg += w->direction; |
| 1580 | 1565 | #if 0 |
| 1581 | | wd17xx_set_irq(device); |
| 1566 | wd17xx_set_intrq(device); |
| 1582 | 1567 | #endif |
| 1583 | 1568 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(100)); |
| 1584 | 1569 | |
| r5993 | r5994 | |
| 1595 | 1580 | w->busy_count = 0; //((data & FDC_STEP_RATE) + 1); |
| 1596 | 1581 | |
| 1597 | 1582 | /* for now only allows a single drive to be selected */ |
| 1598 | | floppy_drive_seek(wd17xx_current_image(device), w->direction); |
| 1583 | floppy_drive_seek(w->drive, w->direction); |
| 1599 | 1584 | |
| 1600 | 1585 | if (data & FDC_STEP_UPDATE) |
| 1601 | 1586 | w->track_reg += w->direction; |
| 1602 | 1587 | |
| 1603 | 1588 | #if 0 |
| 1604 | | wd17xx_set_irq(device); |
| 1589 | wd17xx_set_intrq(device); |
| 1605 | 1590 | #endif |
| 1606 | 1591 | wd17xx_set_busy(device, ATTOTIME_IN_USEC(100)); |
| 1607 | 1592 | } |
| r5993 | r5994 | |
| 1625 | 1610 | } |
| 1626 | 1611 | } |
| 1627 | 1612 | |
| 1628 | | |
| 1629 | | |
| 1630 | 1613 | /* write the FDC track register */ |
| 1631 | | WRITE8_DEVICE_HANDLER ( wd17xx_track_w ) |
| 1614 | WRITE8_DEVICE_HANDLER( wd17xx_track_w ) |
| 1632 | 1615 | { |
| 1633 | 1616 | wd17xx_t *w = get_safe_token(device); |
| 1617 | |
| 1634 | 1618 | w->track_reg = data; |
| 1635 | 1619 | |
| 1636 | 1620 | if (VERBOSE) |
| 1637 | 1621 | logerror("wd17xx_track_w $%02X\n", data); |
| 1638 | 1622 | } |
| 1639 | 1623 | |
| 1640 | | |
| 1641 | | |
| 1642 | 1624 | /* write the FDC sector register */ |
| 1643 | | WRITE8_DEVICE_HANDLER ( wd17xx_sector_w ) |
| 1625 | WRITE8_DEVICE_HANDLER( wd17xx_sector_w ) |
| 1644 | 1626 | { |
| 1645 | 1627 | wd17xx_t *w = get_safe_token(device); |
| 1628 | |
| 1646 | 1629 | w->sector = data; |
| 1630 | |
| 1647 | 1631 | if (VERBOSE) |
| 1648 | 1632 | logerror("wd17xx_sector_w $%02X\n", data); |
| 1649 | 1633 | } |
| 1650 | 1634 | |
| 1651 | | |
| 1652 | | |
| 1653 | 1635 | /* write the FDC data register */ |
| 1654 | | WRITE8_DEVICE_HANDLER ( wd17xx_data_w ) |
| 1636 | WRITE8_DEVICE_HANDLER( wd17xx_data_w ) |
| 1655 | 1637 | { |
| 1656 | 1638 | wd17xx_t *w = get_safe_token(device); |
| 1657 | 1639 | |
| 1658 | 1640 | if (w->data_count > 0) |
| 1659 | 1641 | { |
| 1660 | | /* clear data request */ |
| 1661 | | wd17xx_clear_data_request(device); |
| 1642 | wd17xx_clear_drq(device); |
| 1662 | 1643 | |
| 1663 | 1644 | /* put byte into buffer */ |
| 1664 | 1645 | if (VERBOSE_DATA) |
| r5993 | r5994 | |
| 1692 | 1673 | w->data = data; |
| 1693 | 1674 | } |
| 1694 | 1675 | |
| 1695 | | |
| 1696 | | |
| 1697 | | READ8_DEVICE_HANDLER( wd17xx_r ) |
| 1676 | READ8_DEVICE_HANDLER( wd17xx_r ) |
| 1698 | 1677 | { |
| 1699 | | UINT8 result = 0; |
| 1700 | | |
| 1701 | | switch(offset % 4) { |
| 1702 | | case 0: |
| 1703 | | result = wd17xx_status_r(device, 0); |
| 1704 | | break; |
| 1705 | | case 1: |
| 1706 | | result = wd17xx_track_r(device, 0); |
| 1707 | | break; |
| 1708 | | case 2: |
| 1709 | | result = wd17xx_sector_r(device, 0); |
| 1710 | | break; |
| 1711 | | case 3: |
| 1712 | | result = wd17xx_data_r(device, 0); |
| 1713 | | break; |
| 1678 | switch (offset & 0x03) |
| 1679 | { |
| 1680 | case 0: return wd17xx_status_r(device, 0); |
| 1681 | case 1: return wd17xx_track_r(device, 0); |
| 1682 | case 2: return wd17xx_sector_r(device, 0); |
| 1683 | case 3: return wd17xx_data_r(device, 0); |
| 1714 | 1684 | } |
| 1715 | | return result; |
| 1685 | |
| 1686 | return 0; |
| 1716 | 1687 | } |
| 1717 | 1688 | |
| 1718 | | |
| 1719 | | |
| 1720 | 1689 | WRITE8_DEVICE_HANDLER( wd17xx_w ) |
| 1721 | 1690 | { |
| 1722 | | switch(offset % 4) { |
| 1723 | | case 0: |
| 1724 | | wd17xx_command_w(device, 0, data); |
| 1725 | | break; |
| 1726 | | case 1: |
| 1727 | | wd17xx_track_w(device, 0, data); |
| 1728 | | break; |
| 1729 | | case 2: |
| 1730 | | wd17xx_sector_w(device, 0, data); |
| 1731 | | break; |
| 1732 | | case 3: |
| 1733 | | wd17xx_data_w(device, 0, data); |
| 1734 | | break; |
| 1691 | switch (offset & 0x03) |
| 1692 | { |
| 1693 | case 0: wd17xx_command_w(device, 0, data); break; |
| 1694 | case 1: wd17xx_track_w(device, 0, data); break; |
| 1695 | case 2: wd17xx_sector_w(device, 0, data); break; |
| 1696 | case 3: wd17xx_data_w(device, 0, data); break; |
| 1735 | 1697 | } |
| 1736 | 1698 | } |
| 1737 | 1699 | |
| 1738 | | const wd17xx_interface default_wd17xx_interface = { DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, FLOPPY_2, FLOPPY_3} }; |
| 1739 | | const wd17xx_interface default_wd17xx_interface_2_drives = { DEVCB_NULL, DEVCB_NULL, { FLOPPY_0, FLOPPY_1, NULL, NULL} }; |
| 1740 | 1700 | |
| 1741 | | /* device interface */ |
| 1701 | /*************************************************************************** |
| 1702 | MAME DEVICE INTERFACE |
| 1703 | ***************************************************************************/ |
| 1704 | |
| 1742 | 1705 | static void common_start(const device_config *device, wd17xx_type_t device_type) |
| 1743 | 1706 | { |
| 1744 | 1707 | wd17xx_t *w = get_safe_token(device); |
| 1745 | 1708 | |
| 1746 | | assert(device != NULL); |
| 1747 | | assert(device->tag != NULL); |
| 1748 | 1709 | assert(device->static_config != NULL); |
| 1749 | 1710 | |
| 1750 | 1711 | w->intf = device->static_config; |
| r5993 | r5994 | |
| 1780 | 1741 | } |
| 1781 | 1742 | } |
| 1782 | 1743 | |
| 1783 | | w->current_drive = 0; |
| 1744 | wd17xx_set_drive(device, 0); |
| 1745 | |
| 1784 | 1746 | w->hd = 0; |
| 1785 | 1747 | w->hld_count = 0; |
| 1786 | 1748 | |
| r5993 | r5994 | |
| 1852 | 1814 | } |
| 1853 | 1815 | } |
| 1854 | 1816 | |
| 1855 | | |
| 1856 | 1817 | DEVICE_GET_INFO( wd1771 ) |
| 1857 | 1818 | { |
| 1858 | 1819 | switch (state) |
| r5993 | r5994 | |
| 1866 | 1827 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1867 | 1828 | } |
| 1868 | 1829 | } |
| 1830 | |
| 1869 | 1831 | DEVICE_GET_INFO( wd1772 ) |
| 1870 | 1832 | { |
| 1871 | 1833 | switch (state) |
| r5993 | r5994 | |
| 1879 | 1841 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1880 | 1842 | } |
| 1881 | 1843 | } |
| 1844 | |
| 1882 | 1845 | DEVICE_GET_INFO( wd1773 ) |
| 1883 | 1846 | { |
| 1884 | 1847 | switch (state) |
| r5993 | r5994 | |
| 1892 | 1855 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1893 | 1856 | } |
| 1894 | 1857 | } |
| 1858 | |
| 1895 | 1859 | DEVICE_GET_INFO( wd179x ) |
| 1896 | 1860 | { |
| 1897 | 1861 | switch (state) |
| r5993 | r5994 | |
| 1905 | 1869 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1906 | 1870 | } |
| 1907 | 1871 | } |
| 1872 | |
| 1908 | 1873 | DEVICE_GET_INFO( wd1793 ) |
| 1909 | 1874 | { |
| 1910 | 1875 | switch (state) |
| r5993 | r5994 | |
| 1918 | 1883 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1919 | 1884 | } |
| 1920 | 1885 | } |
| 1886 | |
| 1921 | 1887 | DEVICE_GET_INFO( wd2793 ) |
| 1922 | 1888 | { |
| 1923 | 1889 | switch (state) |
| r5993 | r5994 | |
| 1931 | 1897 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1932 | 1898 | } |
| 1933 | 1899 | } |
| 1900 | |
| 1934 | 1901 | DEVICE_GET_INFO( wd177x ) |
| 1935 | 1902 | { |
| 1936 | 1903 | switch (state) |
| r5993 | r5994 | |
| 1944 | 1911 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1945 | 1912 | } |
| 1946 | 1913 | } |
| 1914 | |
| 1947 | 1915 | DEVICE_GET_INFO( mb8877 ) |
| 1948 | 1916 | { |
| 1949 | 1917 | switch (state) |
| r5993 | r5994 | |
| 1957 | 1925 | default: DEVICE_GET_INFO_CALL(wd1770); break; |
| 1958 | 1926 | } |
| 1959 | 1927 | } |
| 1960 | | |