src/mess/device.c
| r5848 | r5849 | |
| 520 | 520 | return (mess_device != NULL) ? &mess_device->io_device : NULL; |
| 521 | 521 | } |
| 522 | 522 | |
| 523 | | |
| 524 | | |
| 525 | | const mess_device_class *mess_devclass_from_core_device(const device_config *device) |
| 526 | | { |
| 527 | | const legacy_mess_device *iodev = mess_device_from_core_device(device); |
| 528 | | return (iodev != NULL) ? &iodev->devclass : NULL; |
| 529 | | } |
| 530 | | |
| 531 | | |
| 532 | | |
| 533 | | int device_count_tag_from_machine(const running_machine *machine, const char *tag) |
| 534 | | { |
| 535 | | int count = 0; |
| 536 | | const device_config *device; |
| 537 | | |
| 538 | | for (device = device_list_first(machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE)) |
| 539 | | { |
| 540 | | const legacy_mess_device *iodev = mess_device_from_core_device(device); |
| 541 | | if (!strcmp(tag, iodev->tag)) |
| 542 | | { |
| 543 | | count++; |
| 544 | | } |
| 545 | | } |
| 546 | | return count; |
| 547 | | } |
| 548 | | |
| 549 | | |
| 550 | | |
| 551 | | /* this function is deprecated */ |
| 552 | | int device_find_from_machine(const running_machine *machine, iodevice_t type) |
| 553 | | { |
| 554 | | const device_config *device; |
| 555 | | |
| 556 | | for (device = device_list_first(machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE)) |
| 557 | | { |
| 558 | | const legacy_mess_device *iodev = mess_device_from_core_device(device); |
| 559 | | if (iodev->type == type) |
| 560 | | return TRUE; |
| 561 | | } |
| 562 | | return FALSE; |
| 563 | | } |
| 564 | | |
| 565 | | |
| 566 | | |
| 567 | | /* this function is deprecated */ |
| 568 | | int device_count(running_machine *machine, iodevice_t type) |
| 569 | | { |
| 570 | | int count = 0; |
| 571 | | const device_config *device; |
| 572 | | |
| 573 | | for (device = device_list_first(machine->config->devicelist, MESS_DEVICE); device != NULL; device = device_list_next(device, MESS_DEVICE)) |
| 574 | | { |
| 575 | | const legacy_mess_device *iodev = mess_device_from_core_device(device); |
| 576 | | if (iodev->type == type) |
| 577 | | { |
| 578 | | count++; |
| 579 | | } |
| 580 | | } |
| 581 | | return count; |
| 582 | | } |
| 583 | | |
| 584 | | |
| 585 | | |
| 586 | 523 | /************************************* |
| 587 | 524 | * |
| 588 | | * Tag management |
| 589 | | * |
| 590 | | *************************************/ |
| 591 | | |
| 592 | | static mess_device_token *get_token(const device_config *device) |
| 593 | | { |
| 594 | | assert(device->type == MESS_DEVICE); |
| 595 | | return (mess_device_token *) device->token; |
| 596 | | } |
| 597 | | |
| 598 | | |
| 599 | | |
| 600 | | void *image_alloctag(const device_config *device, const char *tag, size_t size) |
| 601 | | { |
| 602 | | void *ptr = tagpool_alloc(&get_token(device)->tagpool, tag, size); |
| 603 | | if (ptr == NULL) |
| 604 | | { |
| 605 | | fatalerror("Out of memory"); |
| 606 | | } |
| 607 | | return ptr; |
| 608 | | } |
| 609 | | |
| 610 | | |
| 611 | | |
| 612 | | void *image_lookuptag(const device_config *device, const char *tag) |
| 613 | | { |
| 614 | | return tagpool_lookup(&get_token(device)->tagpool, tag); |
| 615 | | } |
| 616 | | |
| 617 | | |
| 618 | | |
| 619 | | /************************************* |
| 620 | | * |
| 621 | 525 | * Deprecated device access functions |
| 622 | 526 | * |
| 623 | 527 | *************************************/ |
| r5848 | r5849 | |
| 630 | 534 | } |
| 631 | 535 | |
| 632 | 536 | |
| 633 | | |
| 634 | | const device_config *image_from_devtag_and_index(running_machine *machine, const char *devtag, int id) |
| 635 | | { |
| 636 | | const device_config *image = NULL; |
| 637 | | const device_config *dev; |
| 638 | | const legacy_mess_device *iodev; |
| 639 | | |
| 640 | | for (dev = device_list_first(machine->config->devicelist, MESS_DEVICE); dev != NULL; dev = device_list_next(dev, MESS_DEVICE)) |
| 641 | | { |
| 642 | | iodev = mess_device_from_core_device(dev); |
| 643 | | if ((iodev->tag != NULL) && !strcmp(iodev->tag, devtag) && (iodev->index_in_device == id)) |
| 644 | | { |
| 645 | | image = dev; |
| 646 | | break; |
| 647 | | } |
| 648 | | } |
| 649 | | |
| 650 | | assert(image != NULL); |
| 651 | | return image; |
| 652 | | } |
| 653 | | |
| 654 | | |
| 655 | | |
| 656 | | iodevice_t image_devtype(const device_config *image) |
| 657 | | { |
| 658 | | const legacy_mess_device *iodev = mess_device_from_core_device(image); |
| 659 | | assert(iodev != NULL); |
| 660 | | return iodev->type; |
| 661 | | } |
| 662 | | |
| 663 | | |
| 664 | | |
| 665 | 537 | const device_config *image_from_devtype_and_index(running_machine *machine, iodevice_t type, int id) |
| 666 | 538 | { |
| 667 | 539 | const device_config *image = NULL; |
src/mess/device.h
| r5848 | r5849 | |
| 182 | 182 | /* interoperability with MAME devices */ |
| 183 | 183 | DEVICE_GET_INFO(mess_device); |
| 184 | 184 | struct _machine_config *machine_config_alloc_with_mess_devices(const game_driver *gamedrv); |
| 185 | | const mess_device_class *mess_devclass_from_core_device(const device_config *device); |
| 186 | 185 | |
| 187 | 186 | /* device naming */ |
| 188 | 187 | const char *device_typename(iodevice_t type); |
| r5848 | r5849 | |
| 192 | 191 | /* device allocation */ |
| 193 | 192 | void mess_devices_setup(running_machine *machine, machine_config *config, const game_driver *gamedrv); |
| 194 | 193 | |
| 195 | | /* device lookup */ |
| 196 | | int device_count_tag_from_machine(const running_machine *machine, const char *tag); |
| 197 | | |
| 198 | | /* deprecated: device lookup; both of these function assume only one of each type of device */ |
| 199 | | int device_find_from_machine(const running_machine *machine, iodevice_t type); |
| 200 | | int device_count(running_machine *machine, iodevice_t type); |
| 201 | | |
| 202 | | /* deprecated tag management functions; only works on legacy devices */ |
| 203 | | void *image_alloctag(const device_config *device, const char *tag, size_t size); |
| 204 | | void *image_lookuptag(const device_config *device, const char *tag); |
| 205 | | |
| 206 | 194 | /* deprecated device access functions */ |
| 207 | 195 | int image_index_in_device(const device_config *device); |
| 208 | | const device_config *image_from_devtag_and_index(running_machine *machine, const char *devtag, int id); |
| 209 | 196 | |
| 210 | 197 | /* deprecated device access functions that assume one device of any given type */ |
| 211 | | iodevice_t image_devtype(const device_config *device); |
| 212 | 198 | const device_config *image_from_devtype_and_index(running_machine *machine, iodevice_t type, int id); |
| 213 | 199 | |
| 214 | 200 | /* diagnostics */ |
src/mess/devices/flopdrv.c
| r5848 | r5849 | |
| 221 | 221 | void floppy_drive_init(const device_config *img) |
| 222 | 222 | { |
| 223 | 223 | floppy_drive *pDrive = get_safe_token( img ); |
| 224 | | // assert(image_slotexists(img)); |
| 225 | 224 | |
| 226 | | // pDrive = image_alloctag(img, FLOPDRVTAG, sizeof(floppy_drive)); |
| 227 | | |
| 228 | 225 | /* initialise flags */ |
| 229 | 226 | pDrive->flags = 0; |
| 230 | 227 | pDrive->index_pulse_callback = NULL; |
| r5848 | r5849 | |
| 730 | 727 | { |
| 731 | 728 | floperr_t err; |
| 732 | 729 | floppy_drive *flopimg; |
| 733 | | const mess_device_class *devclass; |
| 734 | 730 | const struct FloppyFormat *floppy_options; |
| 735 | 731 | int floppy_flags, i; |
| 736 | 732 | const char *extension; |
| r5848 | r5849 | |
| 739 | 735 | flopimg = get_safe_token( image ); |
| 740 | 736 | |
| 741 | 737 | /* figure out the floppy options */ |
| 742 | | devclass = mess_devclass_from_core_device(image); |
| 743 | 738 | floppy_options = ((floppy_config*)image->static_config)->formats; |
| 744 | 739 | |
| 745 | 740 | if (image_has_been_created(image)) |