src/mess/machine/pc_hdc.c
| r3889 | r3890 | |
| 34 | 34 | #include "machine/8237dma.h" |
| 35 | 35 | #include "devices/harddriv.h" |
| 36 | 36 | #include "memconv.h" |
| 37 | | #include "deprecat.h" |
| 38 | 37 | |
| 39 | 38 | |
| 40 | 39 | #define LOG_HDC_STATUS 0 |
| r3889 | r3890 | |
| 209 | 208 | } |
| 210 | 209 | |
| 211 | 210 | |
| 212 | | static hard_disk_file *pc_hdc_file(int id) |
| 211 | static hard_disk_file *pc_hdc_file(running_machine *machine, int id) |
| 213 | 212 | { |
| 214 | 213 | const device_config *img = NULL; |
| 215 | 214 | |
| 216 | 215 | switch( id ) |
| 217 | 216 | { |
| 218 | 217 | case 0: |
| 219 | | img = device_list_find_by_tag( Machine->config->devicelist, HARDDISK, "harddisk1" ); |
| 218 | img = device_list_find_by_tag( machine->config->devicelist, HARDDISK, "harddisk1" ); |
| 220 | 219 | break; |
| 221 | 220 | case 1: |
| 222 | | img = device_list_find_by_tag( Machine->config->devicelist, HARDDISK, "harddisk2" ); |
| 221 | img = device_list_find_by_tag( machine->config->devicelist, HARDDISK, "harddisk2" ); |
| 223 | 222 | break; |
| 224 | 223 | case 2: |
| 225 | | img = device_list_find_by_tag( Machine->config->devicelist, HARDDISK, "harddisk3" ); |
| 224 | img = device_list_find_by_tag( machine->config->devicelist, HARDDISK, "harddisk3" ); |
| 226 | 225 | break; |
| 227 | 226 | case 3: |
| 228 | | img = device_list_find_by_tag( Machine->config->devicelist, HARDDISK, "harddisk4" ); |
| 227 | img = device_list_find_by_tag( machine->config->devicelist, HARDDISK, "harddisk4" ); |
| 229 | 228 | break; |
| 230 | 229 | } |
| 231 | 230 | |
| r3889 | r3890 | |
| 287 | 286 | |
| 288 | 287 | |
| 289 | 288 | |
| 290 | | static int get_lbasector(void) |
| 289 | static int get_lbasector(running_machine *machine) |
| 291 | 290 | { |
| 292 | 291 | hard_disk_info *info; |
| 293 | 292 | hard_disk_file *file; |
| 294 | 293 | int lbasector; |
| 295 | 294 | |
| 296 | | file = pc_hdc_file(idx); |
| 295 | file = pc_hdc_file(machine, idx); |
| 297 | 296 | info = hard_disk_get_info(file); |
| 298 | 297 | |
| 299 | 298 | lbasector = cylinder[idx]; |
| r3889 | r3890 | |
| 322 | 321 | static int hdcdma_write; |
| 323 | 322 | static int hdcdma_size; |
| 324 | 323 | |
| 325 | | int pc_hdc_dack_r(void) |
| 324 | int pc_hdc_dack_r(running_machine *machine) |
| 326 | 325 | { |
| 327 | 326 | UINT8 result; |
| 328 | 327 | hard_disk_info *info; |
| 329 | 328 | hard_disk_file *file; |
| 330 | 329 | |
| 331 | | file = pc_hdc_file(idx); |
| 330 | file = pc_hdc_file(machine, idx); |
| 332 | 331 | if (!file) |
| 333 | 332 | return 0; |
| 334 | 333 | info = hard_disk_get_info(file); |
| 335 | 334 | |
| 336 | 335 | if (hdcdma_read == 0) |
| 337 | 336 | { |
| 338 | | hard_disk_read(file, get_lbasector(), hdcdma_data); |
| 337 | hard_disk_read(file, get_lbasector(machine), hdcdma_data); |
| 339 | 338 | hdcdma_read = 512; |
| 340 | 339 | hdcdma_size -= 512; |
| 341 | 340 | hdcdma_src = hdcdma_data; |
| r3889 | r3890 | |
| 363 | 362 | |
| 364 | 363 | |
| 365 | 364 | |
| 366 | | void pc_hdc_dack_w(int data) |
| 365 | void pc_hdc_dack_w(running_machine *machine, int data) |
| 367 | 366 | { |
| 368 | 367 | hard_disk_info *info; |
| 369 | 368 | hard_disk_file *file; |
| 370 | 369 | |
| 371 | | file = pc_hdc_file(idx); |
| 370 | file = pc_hdc_file(machine, idx); |
| 372 | 371 | if (!file) |
| 373 | 372 | return; |
| 374 | 373 | info = hard_disk_get_info(file); |
| r3889 | r3890 | |
| 377 | 376 | |
| 378 | 377 | if( --hdcdma_write == 0 ) |
| 379 | 378 | { |
| 380 | | hard_disk_write(file, get_lbasector(), hdcdma_data); |
| 379 | hard_disk_write(file, get_lbasector(machine), hdcdma_data); |
| 381 | 380 | hdcdma_write = 512; |
| 382 | 381 | hdcdma_size -= 512; |
| 383 | 382 | |
| r3889 | r3890 | |
| 397 | 396 | |
| 398 | 397 | |
| 399 | 398 | |
| 400 | | static void execute_read(void) |
| 399 | static void execute_read(running_machine *machine) |
| 401 | 400 | { |
| 402 | | hard_disk_file *disk = pc_hdc_file(idx); |
| 401 | hard_disk_file *disk = pc_hdc_file(machine, idx); |
| 403 | 402 | UINT8 data[512], *src = data; |
| 404 | 403 | int size = sector_cnt[idx] * 512; |
| 405 | 404 | int read_ = 0; |
| 406 | 405 | |
| 407 | | disk = pc_hdc_file(idx); |
| 406 | disk = pc_hdc_file(machine, idx); |
| 408 | 407 | if (!disk) |
| 409 | 408 | return; |
| 410 | 409 | |
| r3889 | r3890 | |
| 417 | 416 | { |
| 418 | 417 | do |
| 419 | 418 | { |
| 420 | | buffer[data_cnt++] = pc_hdc_dack_r(); |
| 419 | buffer[data_cnt++] = pc_hdc_dack_r( machine ); |
| 421 | 420 | } while (hdcdma_read || hdcdma_size); |
| 422 | 421 | } |
| 423 | 422 | else |
| r3889 | r3890 | |
| 428 | 427 | |
| 429 | 428 | |
| 430 | 429 | |
| 431 | | static void execute_write(void) |
| 430 | static void execute_write(running_machine *machine) |
| 432 | 431 | { |
| 433 | | hard_disk_file *disk = pc_hdc_file(idx); |
| 432 | hard_disk_file *disk = pc_hdc_file(machine, idx); |
| 434 | 433 | UINT8 data[512], *dst = data; |
| 435 | 434 | int size = sector_cnt[idx] * 512; |
| 436 | 435 | int write_ = 512; |
| 437 | 436 | |
| 438 | | disk = pc_hdc_file(idx); |
| 437 | disk = pc_hdc_file(machine, idx); |
| 439 | 438 | if (!disk) |
| 440 | 439 | return; |
| 441 | 440 | |
| r3889 | r3890 | |
| 448 | 447 | { |
| 449 | 448 | do |
| 450 | 449 | { |
| 451 | | pc_hdc_dack_w(buffer[data_cnt++]); |
| 450 | pc_hdc_dack_w(machine, buffer[data_cnt++]); |
| 452 | 451 | } |
| 453 | 452 | while (hdcdma_write || hdcdma_size); |
| 454 | 453 | } |
| r3889 | r3890 | |
| 481 | 480 | error[n] = 0x80; /* a potential error has C/H/S/N info */ |
| 482 | 481 | } |
| 483 | 482 | |
| 484 | | static int test_ready(int n) |
| 483 | static int test_ready(running_machine *machine, int n) |
| 485 | 484 | { |
| 486 | | if( !pc_hdc_file(idx) ) |
| 485 | if( !pc_hdc_file(machine, idx) ) |
| 487 | 486 | { |
| 488 | 487 | csb[n] |= CSB_ERROR; |
| 489 | 488 | error[n] |= 0x04; /* drive not ready */ |
| r3889 | r3890 | |
| 519 | 518 | { |
| 520 | 519 | case CMD_TESTREADY: |
| 521 | 520 | set_error_info = 0; |
| 522 | | test_ready(n); |
| 521 | test_ready(machine, n); |
| 523 | 522 | break; |
| 524 | 523 | case CMD_SENSE: |
| 525 | 524 | /* Perform error code translation. This may need to be expanded in the future. */ |
| r3889 | r3890 | |
| 540 | 539 | case CMD_SEEK: |
| 541 | 540 | case CMD_DRIVEDIAG: |
| 542 | 541 | get_chsn(n); |
| 543 | | test_ready(n); |
| 542 | test_ready(machine, n); |
| 544 | 543 | break; |
| 545 | 544 | |
| 546 | 545 | case CMD_READ: |
| r3889 | r3890 | |
| 553 | 552 | (unsigned) cpu_get_reg(machine->cpu[0], REG_PC), idx, drv, cylinder[idx], head[idx], sector[idx], sector_cnt[idx], control[idx]); |
| 554 | 553 | } |
| 555 | 554 | |
| 556 | | if (test_ready(n)) |
| 557 | | execute_read(); |
| 555 | if (test_ready(machine, n)) |
| 556 | execute_read(machine); |
| 558 | 557 | set_error_info = 0; |
| 559 | 558 | break; |
| 560 | 559 | |
| r3889 | r3890 | |
| 568 | 567 | (unsigned) cpu_get_reg(machine->cpu[0], REG_PC), idx, drv, cylinder[idx], head[idx], sector[idx], sector_cnt[idx], control[idx]); |
| 569 | 568 | } |
| 570 | 569 | |
| 571 | | if (test_ready(n)) |
| 572 | | execute_write(); |
| 570 | if (test_ready(machine, n)) |
| 571 | execute_write(machine); |
| 573 | 572 | break; |
| 574 | 573 | |
| 575 | 574 | case CMD_SETPARAM: |
| r3889 | r3890 | |
| 616 | 615 | * cccccccc write precomp l |
| 617 | 616 | * eeeeeeee ecc |
| 618 | 617 | */ |
| 619 | | static void pc_hdc_data_w(int n, int data) |
| 618 | static void pc_hdc_data_w(running_machine *machine, int n, int data) |
| 620 | 619 | { |
| 621 | 620 | if( data_cnt == 0 ) |
| 622 | 621 | { |
| r3889 | r3890 | |
| 674 | 673 | if (--data_cnt == 0) |
| 675 | 674 | { |
| 676 | 675 | if (LOG_HDC_STATUS) |
| 677 | | logerror("pc_hdc_data_w(): Launching command; pc=0x%08x\n", (unsigned) cpu_get_reg(Machine->cpu[0], REG_PC)); |
| 676 | logerror("pc_hdc_data_w(): Launching command; pc=0x%08x\n", (unsigned) cpu_get_reg(machine->cpu[0], REG_PC)); |
| 678 | 677 | |
| 679 | 678 | status[n] &= ~STA_COMMAND; |
| 680 | 679 | status[n] &= ~STA_REQUEST; |
| r3889 | r3890 | |
| 711 | 710 | |
| 712 | 711 | |
| 713 | 712 | |
| 714 | | static void pc_hdc_control_w(int n, int data) |
| 713 | static void pc_hdc_control_w(running_machine *machine, int n, int data) |
| 715 | 714 | { |
| 716 | 715 | int irq = irq = (dip[n] & 0x40) ? 5 : 2; |
| 717 | 716 | |
| 718 | 717 | if (LOG_HDC_STATUS) |
| 719 | | logerror("pc_hdc_control_w(): Control write pc=0x%08x data=%d\n", (unsigned) cpu_get_reg(Machine->cpu[0], REG_PC), data); |
| 718 | logerror("pc_hdc_control_w(): Control write pc=0x%08x data=%d\n", (unsigned) cpu_get_reg(machine->cpu[0], REG_PC), data); |
| 720 | 719 | |
| 721 | 720 | hdc_control = data; |
| 722 | 721 | |
| r3889 | r3890 | |
| 785 | 784 | * |
| 786 | 785 | *************************************************************************/ |
| 787 | 786 | |
| 788 | | static UINT8 pc_HDC_r(int chip, offs_t offs) |
| 787 | static UINT8 pc_HDC_r(running_machine *machine, int chip, offs_t offs) |
| 789 | 788 | { |
| 790 | 789 | UINT8 data = 0xff; |
| 791 | 790 | |
| r3889 | r3890 | |
| 798 | 797 | } |
| 799 | 798 | |
| 800 | 799 | if (LOG_HDC_CALL) |
| 801 | | logerror("pc_HDC_r(): pc=%06X chip=%d offs=%d result=0x%02x\n", cpu_get_pc(Machine->cpu[0]), chip, offs, data); |
| 800 | logerror("pc_HDC_r(): pc=%06X chip=%d offs=%d result=0x%02x\n", cpu_get_pc(machine->cpu[0]), chip, offs, data); |
| 802 | 801 | |
| 803 | 802 | return data; |
| 804 | 803 | } |
| 805 | 804 | |
| 806 | 805 | |
| 807 | 806 | |
| 808 | | static void pc_HDC_w(int chip, offs_t offs, UINT8 data) |
| 807 | static void pc_HDC_w(running_machine *machine, int chip, offs_t offs, UINT8 data) |
| 809 | 808 | { |
| 810 | 809 | if (LOG_HDC_CALL) |
| 811 | | logerror("pc_HDC_w(): pc=%06X chip=%d offs=%d data=0x%02x\n", cpu_get_pc(Machine->cpu[0]), chip, offs, data); |
| 810 | logerror("pc_HDC_w(): pc=%06X chip=%d offs=%d data=0x%02x\n", cpu_get_pc(machine->cpu[0]), chip, offs, data); |
| 812 | 811 | |
| 813 | 812 | switch( offs ) |
| 814 | 813 | { |
| 815 | | case 0: pc_hdc_data_w(chip,data); break; |
| 814 | case 0: pc_hdc_data_w(machine, chip,data); break; |
| 816 | 815 | case 1: pc_hdc_reset_w(chip,data); break; |
| 817 | 816 | case 2: pc_hdc_select_w(chip,data); break; |
| 818 | | case 3: pc_hdc_control_w(chip,data); break; |
| 817 | case 3: pc_hdc_control_w(machine, chip, data); break; |
| 819 | 818 | } |
| 820 | 819 | } |
| 821 | 820 | |
| r3889 | r3890 | |
| 826 | 825 | * |
| 827 | 826 | *************************************/ |
| 828 | 827 | |
| 829 | | READ8_HANDLER ( pc_HDC1_r ) { return pc_HDC_r(0, offset); } |
| 830 | | READ8_HANDLER ( pc_HDC2_r ) { return pc_HDC_r(1, offset); } |
| 831 | | WRITE8_HANDLER ( pc_HDC1_w ) { pc_HDC_w(0, offset, data); } |
| 832 | | WRITE8_HANDLER ( pc_HDC2_w ) { pc_HDC_w(1, offset, data); } |
| 828 | READ8_HANDLER ( pc_HDC1_r ) { return pc_HDC_r(space->machine, 0, offset); } |
| 829 | READ8_HANDLER ( pc_HDC2_r ) { return pc_HDC_r(space->machine, 1, offset); } |
| 830 | WRITE8_HANDLER ( pc_HDC1_w ) { pc_HDC_w(space->machine, 0, offset, data); } |
| 831 | WRITE8_HANDLER ( pc_HDC2_w ) { pc_HDC_w(space->machine, 1, offset, data); } |
| 833 | 832 | |
| 834 | 833 | READ16_HANDLER ( pc16le_HDC1_r ) { return read16le_with_read8_handler(pc_HDC1_r, space, offset, mem_mask); } |
| 835 | 834 | READ16_HANDLER ( pc16le_HDC2_r ) { return read16le_with_read8_handler(pc_HDC2_r, space, offset, mem_mask); } |