src/mess/machine/vc1541.c
| r4824 | r4825 | |
| 156 | 156 | #include "cpu/m6502/m6502.h" |
| 157 | 157 | #include "machine/6525tpi.h" |
| 158 | 158 | #include "machine/6522via.h" |
| 159 | #include "includes/cbmserb.h" |
| 159 | 160 | |
| 160 | 161 | #include "includes/vc1541.h" |
| 161 | 162 | |
| r4824 | r4825 | |
| 703 | 704 | } |
| 704 | 705 | |
| 705 | 706 | |
| 707 | /************************************** |
| 708 | |
| 709 | VC1541 Serial Bus Device Interface |
| 710 | |
| 711 | **************************************/ |
| 712 | |
| 713 | /* 2009-05 FP - Note: I could use directly these functions as DEVICE_HANDLERs for |
| 714 | the serial bus device, but these are also used in the VIA interface above, so I |
| 715 | prefer to keep the handlers separated at this stage. Further work on the serial |
| 716 | bus emulation should allow to remove the duplicated code. */ |
| 717 | |
| 718 | static void vc1541_serial_reset_write( running_machine *machine, int which, int level ) |
| 719 | { |
| 720 | } |
| 721 | |
| 722 | static UINT8 vc1541_serial_atn_read( running_machine *machine, int which ) |
| 723 | { |
| 724 | /* there is no more cpu_getactivecpu! */ |
| 725 | #ifdef CPU_SYNC |
| 726 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 727 | #endif |
| 728 | return serial.atn[0]; |
| 729 | } |
| 730 | |
| 731 | static void vc1541_serial_atn_write( running_machine *machine, int which, int level ) |
| 732 | { |
| 733 | const device_config *via_0 = devtag_get_device(machine, "_1541_via_0"); |
| 734 | #if 0 |
| 735 | int value; |
| 736 | #endif |
| 737 | if (serial.atn[1 + which] != level) |
| 738 | { |
| 739 | /* there is no more cpu_getactivecpu! */ |
| 740 | #ifdef CPU_SYNC |
| 741 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 742 | #endif |
| 743 | serial.atn[1 + which] = level; |
| 744 | if (serial.atn[0] != level) |
| 745 | { |
| 746 | serial.atn[0] = serial.atn[1] && serial.atn[2]; |
| 747 | if (serial.atn[0] == level) |
| 748 | { |
| 749 | #if 0 |
| 750 | DBG_LOG(machine, 1, "vc1541",("%d:%.4x atn %s\n", |
| 751 | cpu_getactivecpu (), |
| 752 | activecpu_get_pc(), |
| 753 | serial.atn[0]?"ATN":"atn")); |
| 754 | #endif |
| 755 | via_ca1_w (via_0, 0, !level); |
| 756 | #if 0 |
| 757 | value = vc1541_drive->vc1541_serial.data; |
| 758 | if (vc1541_drive->vc1541_serial.acka != !level) |
| 759 | value = 0; |
| 760 | if (value != serial.data[2]) |
| 761 | { |
| 762 | serial.data[2] = value; |
| 763 | if (serial.data[0] != value) |
| 764 | { |
| 765 | serial.data[0] = serial.data[1] && serial.data[2]; |
| 766 | } |
| 767 | } |
| 768 | #endif |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | } |
| 773 | |
| 774 | static UINT8 vc1541_serial_data_read( running_machine *machine, int which ) |
| 775 | { |
| 776 | /* there is no more cpu_getactivecpu! */ |
| 777 | #ifdef CPU_SYNC |
| 778 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 779 | #endif |
| 780 | return serial.data[0]; |
| 781 | } |
| 782 | |
| 783 | static void vc1541_serial_data_write( running_machine *machine, int which, int level ) |
| 784 | { |
| 785 | if (serial.data[1 + which] != level) |
| 786 | { |
| 787 | /* there is no more cpu_getactivecpu! */ |
| 788 | #ifdef CPU_SYNC |
| 789 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 790 | #endif |
| 791 | serial.data[1 + which] = level; |
| 792 | if (serial.data[0] != level) |
| 793 | { |
| 794 | serial.data[0] = serial.data[1] && serial.data[2]; |
| 795 | #if 0 |
| 796 | if (serial.data[0] == level) |
| 797 | { |
| 798 | DBG_LOG(machine, 1, "vc1541",("%d:%.4x data %s\n", |
| 799 | cpu_getactivecpu (), |
| 800 | activecpu_get_pc(), |
| 801 | serial.data[0]?"DATA":"data")); |
| 802 | } |
| 803 | #endif |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | static UINT8 vc1541_serial_clock_read( running_machine *machine, int which ) |
| 809 | { |
| 810 | /* there is no more cpu_getactivecpu! */ |
| 811 | #ifdef CPU_SYNC |
| 812 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 813 | #endif |
| 814 | return serial.clock[0]; |
| 815 | } |
| 816 | |
| 817 | static void vc1541_serial_clock_write( running_machine *machine, int which, int level ) |
| 818 | { |
| 819 | if (serial.clock[1 + which] != level) |
| 820 | { |
| 821 | /* there is no more cpu_getactivecpu! */ |
| 822 | #ifdef CPU_SYNC |
| 823 | if (cpu_getactivecpu()==0) cpu_sync(); |
| 824 | #endif |
| 825 | serial.clock[1 + which] = level; |
| 826 | if (serial.clock[0] != level) |
| 827 | { |
| 828 | serial.clock[0] = serial.clock[1] && serial.clock[2]; |
| 829 | if (serial.clock[0] == level) |
| 830 | { |
| 831 | /* DBG_LOG(machine, 1, "vc1541",("%d:%.4x clock %s\n", |
| 832 | cpu_getactivecpu (), |
| 833 | activecpu_get_pc(), |
| 834 | serial.clock[0]?"CLOCK":"clock"));*/ |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | } |
| 839 | |
| 840 | static UINT8 vc1541_serial_request_read( running_machine *machine, int which ) |
| 841 | { |
| 842 | return 1; |
| 843 | } |
| 844 | |
| 845 | static void vc1541_serial_request_write( running_machine *machine, int which, int level ) |
| 846 | { |
| 847 | } |
| 848 | |
| 849 | |
| 850 | /* 2009-05 FP - TODO: better implementation of the DEVICE_HANDLERs below. Right now they are |
| 851 | redundant (see also my Note above) */ |
| 852 | static READ8_DEVICE_HANDLER( emu_drive_atn_read ) |
| 853 | { |
| 854 | return vc1541_serial_atn_read(device->machine, 0); |
| 855 | } |
| 856 | |
| 857 | static READ8_DEVICE_HANDLER( emu_drive_clock_read ) |
| 858 | { |
| 859 | return vc1541_serial_clock_read(device->machine, 0); |
| 860 | } |
| 861 | |
| 862 | static READ8_DEVICE_HANDLER( emu_drive_data_read ) |
| 863 | { |
| 864 | return vc1541_serial_data_read(device->machine, 0); |
| 865 | } |
| 866 | |
| 867 | static READ8_DEVICE_HANDLER( emu_drive_request_read ) |
| 868 | { |
| 869 | return vc1541_serial_request_read(device->machine, 0); |
| 870 | } |
| 871 | |
| 872 | static WRITE8_DEVICE_HANDLER( emu_drive_atn_write ) |
| 873 | { |
| 874 | vc1541_serial_atn_write(device->machine, 0, data); |
| 875 | } |
| 876 | |
| 877 | static WRITE8_DEVICE_HANDLER( emu_drive_clock_write ) |
| 878 | { |
| 879 | vc1541_serial_clock_write(device->machine, 0, data); |
| 880 | } |
| 881 | |
| 882 | static WRITE8_DEVICE_HANDLER( emu_drive_data_write ) |
| 883 | { |
| 884 | vc1541_serial_data_write(device->machine, 0, data); |
| 885 | } |
| 886 | |
| 887 | static WRITE8_DEVICE_HANDLER( emu_drive_request_write ) |
| 888 | { |
| 889 | vc1541_serial_request_write(device->machine, 0, data); |
| 890 | } |
| 891 | |
| 892 | static WRITE8_DEVICE_HANDLER( emu_drive_reset_write ) |
| 893 | { |
| 894 | vc1541_serial_reset_write(device->machine, 0, data); |
| 895 | } |
| 896 | |
| 897 | |
| 898 | static const cbm_serial_bus_interface cbm_emu_drive_interface = |
| 899 | { |
| 900 | DEVCB_HANDLER(emu_drive_atn_read), |
| 901 | DEVCB_HANDLER(emu_drive_clock_read), |
| 902 | DEVCB_HANDLER(emu_drive_data_read), |
| 903 | DEVCB_HANDLER(emu_drive_request_read), |
| 904 | DEVCB_HANDLER(emu_drive_atn_write), |
| 905 | DEVCB_HANDLER(emu_drive_clock_write), |
| 906 | DEVCB_HANDLER(emu_drive_data_write), |
| 907 | DEVCB_HANDLER(emu_drive_request_write), |
| 908 | |
| 909 | DEVCB_HANDLER(emu_drive_reset_write) |
| 910 | }; |
| 911 | |
| 912 | |
| 913 | |
| 706 | 914 | /************************************************************************** |
| 707 | 915 | * VIA 6522 at 0x1800 |
| 708 | 916 | * |
| r4824 | r4825 | |
| 1015 | 1223 | }; |
| 1016 | 1224 | |
| 1017 | 1225 | |
| 1018 | | void vc1541_serial_reset_write( running_machine *machine, int which, int level ) |
| 1019 | | { |
| 1020 | | } |
| 1021 | | |
| 1022 | | int vc1541_serial_atn_read( running_machine *machine, int which ) |
| 1023 | | { |
| 1024 | | /* there is no more cpu_getactivecpu! */ |
| 1025 | | #ifdef CPU_SYNC |
| 1026 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1027 | | #endif |
| 1028 | | return serial.atn[0]; |
| 1029 | | } |
| 1030 | | |
| 1031 | | void vc1541_serial_atn_write( running_machine *machine, int which, int level ) |
| 1032 | | { |
| 1033 | | const device_config *via_0 = devtag_get_device(machine, "_1541_via_0"); |
| 1034 | | #if 0 |
| 1035 | | int value; |
| 1036 | | #endif |
| 1037 | | if (serial.atn[1 + which] != level) |
| 1038 | | { |
| 1039 | | /* there is no more cpu_getactivecpu! */ |
| 1040 | | #ifdef CPU_SYNC |
| 1041 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1042 | | #endif |
| 1043 | | serial.atn[1 + which] = level; |
| 1044 | | if (serial.atn[0] != level) |
| 1045 | | { |
| 1046 | | serial.atn[0] = serial.atn[1] && serial.atn[2]; |
| 1047 | | if (serial.atn[0] == level) |
| 1048 | | { |
| 1049 | | #if 0 |
| 1050 | | DBG_LOG(machine, 1, "vc1541",("%d:%.4x atn %s\n", |
| 1051 | | cpu_getactivecpu (), |
| 1052 | | activecpu_get_pc(), |
| 1053 | | serial.atn[0]?"ATN":"atn")); |
| 1054 | | #endif |
| 1055 | | via_ca1_w (via_0, 0, !level); |
| 1056 | | #if 0 |
| 1057 | | value = vc1541_drive->vc1541_serial.data; |
| 1058 | | if (vc1541_drive->vc1541_serial.acka != !level) |
| 1059 | | value = 0; |
| 1060 | | if (value != serial.data[2]) |
| 1061 | | { |
| 1062 | | serial.data[2] = value; |
| 1063 | | if (serial.data[0] != value) |
| 1064 | | { |
| 1065 | | serial.data[0] = serial.data[1] && serial.data[2]; |
| 1066 | | } |
| 1067 | | } |
| 1068 | | #endif |
| 1069 | | } |
| 1070 | | } |
| 1071 | | } |
| 1072 | | } |
| 1073 | | |
| 1074 | | int vc1541_serial_data_read( running_machine *machine, int which ) |
| 1075 | | { |
| 1076 | | /* there is no more cpu_getactivecpu! */ |
| 1077 | | #ifdef CPU_SYNC |
| 1078 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1079 | | #endif |
| 1080 | | return serial.data[0]; |
| 1081 | | } |
| 1082 | | |
| 1083 | | void vc1541_serial_data_write( running_machine *machine, int which, int level ) |
| 1084 | | { |
| 1085 | | if (serial.data[1 + which] != level) |
| 1086 | | { |
| 1087 | | /* there is no more cpu_getactivecpu! */ |
| 1088 | | #ifdef CPU_SYNC |
| 1089 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1090 | | #endif |
| 1091 | | serial.data[1 + which] = level; |
| 1092 | | if (serial.data[0] != level) |
| 1093 | | { |
| 1094 | | serial.data[0] = serial.data[1] && serial.data[2]; |
| 1095 | | #if 0 |
| 1096 | | if (serial.data[0] == level) |
| 1097 | | { |
| 1098 | | DBG_LOG(machine, 1, "vc1541",("%d:%.4x data %s\n", |
| 1099 | | cpu_getactivecpu (), |
| 1100 | | activecpu_get_pc(), |
| 1101 | | serial.data[0]?"DATA":"data")); |
| 1102 | | } |
| 1103 | | #endif |
| 1104 | | } |
| 1105 | | } |
| 1106 | | } |
| 1107 | | |
| 1108 | | int vc1541_serial_clock_read( running_machine *machine, int which ) |
| 1109 | | { |
| 1110 | | /* there is no more cpu_getactivecpu! */ |
| 1111 | | #ifdef CPU_SYNC |
| 1112 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1113 | | #endif |
| 1114 | | return serial.clock[0]; |
| 1115 | | } |
| 1116 | | |
| 1117 | | void vc1541_serial_clock_write( running_machine *machine, int which, int level ) |
| 1118 | | { |
| 1119 | | if (serial.clock[1 + which] != level) |
| 1120 | | { |
| 1121 | | /* there is no more cpu_getactivecpu! */ |
| 1122 | | #ifdef CPU_SYNC |
| 1123 | | if (cpu_getactivecpu()==0) cpu_sync(); |
| 1124 | | #endif |
| 1125 | | serial.clock[1 + which] = level; |
| 1126 | | if (serial.clock[0] != level) |
| 1127 | | { |
| 1128 | | serial.clock[0] = serial.clock[1] && serial.clock[2]; |
| 1129 | | if (serial.clock[0] == level) |
| 1130 | | { |
| 1131 | | /* DBG_LOG(machine, 1, "vc1541",("%d:%.4x clock %s\n", |
| 1132 | | cpu_getactivecpu (), |
| 1133 | | activecpu_get_pc(), |
| 1134 | | serial.clock[0]?"CLOCK":"clock"));*/ |
| 1135 | | } |
| 1136 | | } |
| 1137 | | } |
| 1138 | | } |
| 1139 | | |
| 1140 | | int vc1541_serial_request_read( running_machine *machine, int which ) |
| 1141 | | { |
| 1142 | | return 1; |
| 1143 | | } |
| 1144 | | |
| 1145 | | void vc1541_serial_request_write( running_machine *machine, int which, int level ) |
| 1146 | | { |
| 1147 | | } |
| 1148 | | |
| 1149 | | |
| 1150 | 1226 | /************************************** |
| 1151 | 1227 | |
| 1152 | 1228 | 1541 / 1541B / 1541C / 1541II / |
| r4824 | r4825 | |
| 1341 | 1417 | + (int)(2 * (c1551_drive->track - (int)c1551_drive->track)) * 184 / 2; // half track if needed (again, 184 comes from out loading choices) |
| 1342 | 1418 | } |
| 1343 | 1419 | |
| 1344 | | if ( (c1551_drive->motor != (data & 0x04)) || (c1551_drive->frequency != (data & 0x60)) ) |
| 1420 | if ((c1551_drive->motor != (data & 0x04)) || (c1551_drive->frequency != (data & 0x60))) |
| 1345 | 1421 | { |
| 1346 | 1422 | double tme; |
| 1347 | 1423 | c1551_drive->motor = data & 0x04; |
| r4824 | r4825 | |
| 1541 | 1617 | |
| 1542 | 1618 | MDRV_VIA6522_ADD("_1541_via_0", 0, vc1541_via0) |
| 1543 | 1619 | MDRV_VIA6522_ADD("_1541_via_1", 0, vc1541_via1) |
| 1620 | |
| 1621 | MDRV_CBM_SERBUS_ADD("serial_bus", cbm_emu_drive_interface) |
| 1544 | 1622 | MACHINE_DRIVER_END |
| 1545 | 1623 | |
| 1546 | 1624 | MACHINE_DRIVER_START( cpu_vc1541 ) |
| r4824 | r4825 | |
| 1553 | 1631 | |
| 1554 | 1632 | MDRV_VIA6522_ADD("_1541_via_0", 0, vc1541_via0) |
| 1555 | 1633 | MDRV_VIA6522_ADD("_1541_via_1", 0, vc1541_via1) |
| 1634 | |
| 1635 | MDRV_CBM_SERBUS_ADD("serial_bus", cbm_emu_drive_interface) |
| 1556 | 1636 | MACHINE_DRIVER_END |
| 1557 | 1637 | |
| 1558 | 1638 | MACHINE_DRIVER_START( cpu_c1571cr ) |
| r4824 | r4825 | |
| 1561 | 1641 | |
| 1562 | 1642 | MDRV_VIA6522_ADD("_1541_via_0", 0, vc1541_via0) |
| 1563 | 1643 | MDRV_VIA6522_ADD("_1541_via_1", 0, vc1541_via1) |
| 1644 | |
| 1645 | MDRV_CBM_SERBUS_ADD("serial_bus", cbm_emu_drive_interface) |
| 1564 | 1646 | MACHINE_DRIVER_END |
| 1565 | 1647 | |
| 1566 | 1648 | MACHINE_DRIVER_START( cpu_c1581 ) |
| r4824 | r4825 | |
| 1582 | 1664 | |
| 1583 | 1665 | /* tpi */ |
| 1584 | 1666 | MDRV_TPI6525_ADD("c1551_tpi", c1551_tpi_intf) |
| 1667 | |
| 1668 | MDRV_CBM_SERBUS_ADD("serial_bus", cbm_emu_drive_interface) // in the current code, serial bus device is tied to the floppy drive |
| 1669 | // and c16 reads/writes to serial bus in m7501_port_r/w! |
| 1585 | 1670 | MACHINE_DRIVER_END |
| 1586 | 1671 | |
| 1587 | 1672 | |
src/mess/machine/cbmdrive.c
| r4824 | r4825 | |
| 10 | 10 | #include "includes/cbmdrive.h" |
| 11 | 11 | |
| 12 | 12 | #define VERBOSE_LEVEL 0 |
| 13 | | #define DBG_LOG(MACHINE,N,M,A) \ |
| 13 | #define DBG_LOG( MACHINE, N, M, A ) \ |
| 14 | 14 | do { \ |
| 15 | 15 | if(VERBOSE_LEVEL >= N) \ |
| 16 | 16 | { \ |
| r4824 | r4825 | |
| 69 | 69 | static int d64_offset[D64_MAX_TRACKS]; /* offset of begin of track in d64 file */ |
| 70 | 70 | |
| 71 | 71 | /* must be called before other functions */ |
| 72 | | void cbm_drive_open_helper (void) |
| 72 | void cbm_drive_open_helper( void ) |
| 73 | 73 | { |
| 74 | 74 | int i; |
| 75 | 75 | |
| r4824 | r4825 | |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /* calculates offset to beginning of d64 file for sector beginning */ |
| 82 | | static int d64_tracksector2offset (int track, int sector) |
| 82 | static int d64_tracksector2offset( int track, int sector ) |
| 83 | 83 | { |
| 84 | 84 | return d64_offset[track - 1] + sector * 256; |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | | static int cbm_compareNames (unsigned char *left, unsigned char *right) |
| 87 | static int cbm_compareNames( unsigned char *left, unsigned char *right ) |
| 88 | 88 | { |
| 89 | 89 | int i; |
| 90 | 90 | |
| r4824 | r4825 | |
| 106 | 106 | /* searches program with given name in directory |
| 107 | 107 | * delivers -1 if not found |
| 108 | 108 | * or pos in image of directory node */ |
| 109 | | static int d64_find (CBM_Drive * drive, unsigned char *name) |
| 109 | static int d64_find( CBM_Drive * drive, unsigned char *name ) |
| 110 | 110 | { |
| 111 | 111 | int pos, track, sector, i; |
| 112 | 112 | |
| 113 | | pos = d64_tracksector2offset (18, 0); |
| 113 | pos = d64_tracksector2offset(18, 0); |
| 114 | 114 | track = drive->image[pos]; |
| 115 | 115 | sector = drive->image[pos + 1]; |
| 116 | 116 | |
| 117 | 117 | while ((track >= 1) && (track <= 35)) |
| 118 | 118 | { |
| 119 | | pos = d64_tracksector2offset (track, sector); |
| 119 | pos = d64_tracksector2offset(track, sector); |
| 120 | 120 | for (i = 2; i < 256; i += 32) |
| 121 | 121 | { |
| 122 | 122 | if (drive->image[pos + i] & 0x80) |
| 123 | 123 | { |
| 124 | | if (mame_stricmp ((char *) name, (char *) "*") == 0) |
| 124 | if (mame_stricmp((char *) name, (char *) "*") == 0) |
| 125 | 125 | return pos + i; |
| 126 | | if (cbm_compareNames (name, drive->image + pos + i + 3)) |
| 126 | if (cbm_compareNames(name, drive->image + pos + i + 3)) |
| 127 | 127 | return pos + i; |
| 128 | 128 | } |
| 129 | 129 | } |
| r4824 | r4825 | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /* reads file into buffer */ |
| 137 | | static void d64_readprg (running_machine *machine, CBM_Drive * drive, int pos) |
| 137 | static void d64_readprg( running_machine *machine, CBM_Drive * drive, int pos ) |
| 138 | 138 | { |
| 139 | 139 | int i; |
| 140 | 140 | |
| 141 | 141 | for (i = 0; i < 16; i++) |
| 142 | | drive->filename[i] = toupper (drive->image[pos + i + 3]); |
| 142 | drive->filename[i] = toupper(drive->image[pos + i + 3]); |
| 143 | 143 | |
| 144 | 144 | drive->filename[i] = 0; |
| 145 | 145 | |
| 146 | | pos = d64_tracksector2offset (drive->image[pos + 1], drive->image[pos + 2]); |
| 146 | pos = d64_tracksector2offset(drive->image[pos + 1], drive->image[pos + 2]); |
| 147 | 147 | |
| 148 | 148 | i = pos; |
| 149 | 149 | drive->size = 0; |
| 150 | 150 | while (drive->image[i] != 0) |
| 151 | 151 | { |
| 152 | 152 | drive->size += 254; |
| 153 | | i = d64_tracksector2offset (drive->image[i], drive->image[i + 1]); |
| 153 | i = d64_tracksector2offset(drive->image[i], drive->image[i + 1]); |
| 154 | 154 | } |
| 155 | 155 | drive->size += drive->image[i + 1]; |
| 156 | 156 | |
| 157 | | DBG_LOG (machine, 3, "d64 readprg", ("size %d\n", drive->size)); |
| 157 | DBG_LOG(machine, 3, "d64 readprg", ("size %d\n", drive->size)); |
| 158 | 158 | |
| 159 | | drive->buffer = (UINT8*)realloc (drive->buffer, drive->size); |
| 159 | drive->buffer = (UINT8*)realloc(drive->buffer, drive->size); |
| 160 | 160 | if (!drive->buffer) |
| 161 | 161 | fatalerror("out of memory %s %d\n", __FILE__, __LINE__); |
| 162 | 162 | |
| 163 | 163 | drive->size--; |
| 164 | 164 | |
| 165 | | DBG_LOG (machine, 3, "d64 readprg", ("track: %d sector: %d\n", |
| 165 | DBG_LOG(machine, 3, "d64 readprg", ("track: %d sector: %d\n", |
| 166 | 166 | drive->image[pos + 1], |
| 167 | 167 | drive->image[pos + 2])); |
| 168 | 168 | |
| r4824 | r4825 | |
| 170 | 170 | { |
| 171 | 171 | if (i + 254 < drive->size) |
| 172 | 172 | { /* not last sector */ |
| 173 | | memcpy (drive->buffer + i, drive->image + pos + 2, 254); |
| 174 | | pos = d64_tracksector2offset (drive->image[pos + 0], |
| 173 | memcpy(drive->buffer + i, drive->image + pos + 2, 254); |
| 174 | pos = d64_tracksector2offset(drive->image[pos + 0], |
| 175 | 175 | drive->image[pos + 1]); |
| 176 | | DBG_LOG (machine, 3, "d64 readprg", ("track: %d sector: %d\n", |
| 176 | DBG_LOG(machine, 3, "d64 readprg", ("track: %d sector: %d\n", |
| 177 | 177 | drive->image[pos], |
| 178 | 178 | drive->image[pos + 1])); |
| 179 | 179 | } |
| 180 | 180 | else |
| 181 | 181 | { |
| 182 | | memcpy (drive->buffer + i, drive->image + pos + 2, drive->size - i); |
| 182 | memcpy(drive->buffer + i, drive->image + pos + 2, drive->size - i); |
| 183 | 183 | } |
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /* reads sector into buffer */ |
| 188 | | static void d64_read_sector (CBM_Drive * drive, int track, int sector) |
| 188 | static void d64_read_sector( CBM_Drive * drive, int track, int sector ) |
| 189 | 189 | { |
| 190 | 190 | int pos; |
| 191 | 191 | |
| 192 | | snprintf (drive->filename, sizeof (drive->filename), |
| 192 | snprintf(drive->filename, sizeof (drive->filename), |
| 193 | 193 | "track %d sector %d", track, sector); |
| 194 | 194 | |
| 195 | 195 | pos = d64_tracksector2offset (track, sector); |
| 196 | 196 | |
| 197 | | drive->buffer = (UINT8*)realloc (drive->buffer,256); |
| 197 | drive->buffer = (UINT8*)realloc(drive->buffer,256); |
| 198 | 198 | if (!drive->buffer) |
| 199 | 199 | fatalerror("out of memory %s %d\n", __FILE__, __LINE__); |
| 200 | 200 | |
| 201 | 201 | logerror("d64 read track %d sector %d\n", track, sector); |
| 202 | 202 | |
| 203 | | memcpy (drive->buffer, drive->image + pos, 256); |
| 203 | memcpy(drive->buffer, drive->image + pos, 256); |
| 204 | 204 | drive->size = 256; |
| 205 | 205 | drive->pos = 0; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | /* reads directory into buffer */ |
| 209 | | static void d64_read_directory (CBM_Drive * drive) |
| 209 | static void d64_read_directory( CBM_Drive * drive ) |
| 210 | 210 | { |
| 211 | 211 | int pos, track, sector, i, j, blocksfree, addr = 0x0101/*0x1001*/; |
| 212 | 212 | |
| 213 | | drive->buffer = (UINT8*)realloc (drive->buffer, 8 * 18 * 25); |
| 213 | drive->buffer = (UINT8*)realloc(drive->buffer, 8 * 18 * 25); |
| 214 | 214 | if (!drive->buffer) |
| 215 | 215 | fatalerror("out of memory %s %d\n", __FILE__, __LINE__); |
| 216 | 216 | |
| 217 | 217 | drive->size = 0; |
| 218 | 218 | |
| 219 | | pos = d64_tracksector2offset (18, 0); |
| 219 | pos = d64_tracksector2offset(18, 0); |
| 220 | 220 | track = drive->image[pos]; |
| 221 | 221 | sector = drive->image[pos + 1]; |
| 222 | 222 | |
| r4824 | r4825 | |
| 247 | 247 | |
| 248 | 248 | while ((track >= 1) && (track <= 35)) |
| 249 | 249 | { |
| 250 | | pos = d64_tracksector2offset (track, sector); |
| 250 | pos = d64_tracksector2offset(track, sector); |
| 251 | 251 | for (i = 2; i < 256; i += 32) |
| 252 | 252 | { |
| 253 | 253 | if (drive->image[pos + i] & 0x80) |
| r4824 | r4825 | |
| 256 | 256 | + 256 * drive->image[pos + i + 29]; |
| 257 | 257 | char dummy[10]; |
| 258 | 258 | |
| 259 | | sprintf (dummy, "%d", blocks); |
| 259 | sprintf(dummy, "%d", blocks); |
| 260 | 260 | len = strlen (dummy); |
| 261 | 261 | addr += 29 - len; |
| 262 | 262 | drive->buffer[drive->size++] = addr & 0xff; |
| r4824 | r4825 | |
| 309 | 309 | drive->buffer[drive->size++] = addr >> 8; |
| 310 | 310 | drive->buffer[drive->size++] = blocksfree & 0xff; |
| 311 | 311 | drive->buffer[drive->size++] = blocksfree >> 8; |
| 312 | | memcpy (drive->buffer + drive->size, "BLOCKS FREE", 11); |
| 312 | memcpy(drive->buffer + drive->size, "BLOCKS FREE", 11); |
| 313 | 313 | drive->size += 11; |
| 314 | 314 | drive->buffer[drive->size++] = 0; |
| 315 | 315 | |
| 316 | | strcpy (drive->filename, "$"); |
| 316 | strcpy(drive->filename, "$"); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | | static int d64_command (running_machine *machine, CBM_Drive * drive, unsigned char *name) |
| 319 | static int d64_command( running_machine *machine, CBM_Drive * drive, unsigned char *name ) |
| 320 | 320 | { |
| 321 | 321 | int pos; |
| 322 | 322 | |
| 323 | 323 | /* name eventuell mit 0xa0 auffuellen */ |
| 324 | 324 | |
| 325 | | if (mame_stricmp ((char *) name, (char *) "$") == 0) |
| 325 | if (mame_stricmp((char *) name, (char *) "$") == 0) |
| 326 | 326 | { |
| 327 | | d64_read_directory (drive); |
| 327 | d64_read_directory(drive); |
| 328 | 328 | } |
| 329 | 329 | else |
| 330 | 330 | { |
| r4824 | r4825 | |
| 332 | 332 | { |
| 333 | 333 | return 1; |
| 334 | 334 | } |
| 335 | | d64_readprg (machine, drive, pos); |
| 335 | d64_readprg(machine, drive, pos); |
| 336 | 336 | } |
| 337 | 337 | return 0; |
| 338 | 338 | } |
| r4824 | r4825 | |
| 390 | 390 | load |
| 391 | 391 | 20 f0 name 3f |
| 392 | 392 | */ |
| 393 | | static void cbm_command (running_machine *machine, CBM_Drive * drive) |
| 393 | static void cbm_command( running_machine *machine, CBM_Drive * drive ) |
| 394 | 394 | { |
| 395 | 395 | unsigned char name[20], type = 'P', mode = 0; |
| 396 | 396 | int channel, head, track, sector; |
| r4824 | r4825 | |
| 447 | 447 | drive->state = OPEN; |
| 448 | 448 | drive->pos = 0; |
| 449 | 449 | } |
| 450 | | DBG_LOG (machine, 1, "cbm_open", ("%s %s type:%c %c\n", name, |
| 450 | DBG_LOG(machine, 1, "cbm_open", ("%s %s type:%c %c\n", name, |
| 451 | 451 | rc ? "failed" : "success", type, mode ? mode : ' ')); |
| 452 | 452 | } |
| 453 | 453 | else if ((drive->cmdpos == 1) && (drive->cmdbuffer[0] == 0x5f)) |
| r4824 | r4825 | |
| 526 | 526 | * status 3 for file not found |
| 527 | 527 | * or filedata ended with status 3 |
| 528 | 528 | */ |
| 529 | | void c1551_state (running_machine *machine, CBM_Drive * drive) |
| 529 | void c1551_state( running_machine *machine, CBM_Drive * drive ) |
| 530 | 530 | { |
| 531 | 531 | static int oldstate; |
| 532 | 532 | |
| r4824 | r4825 | |
| 666 | 666 | drive->i.iec.state++; |
| 667 | 667 | if ((drive->state == 0) || (drive->state == OPEN)) |
| 668 | 668 | { |
| 669 | | DBG_LOG (machine, 1, "c1551", ("taken data %.2x\n", |
| 669 | DBG_LOG(machine, 1, "c1551", ("taken data %.2x\n", |
| 670 | 670 | drive->i.iec.datain)); |
| 671 | 671 | if (drive->cmdpos < sizeof (drive->cmdbuffer)) |
| 672 | 672 | drive->cmdbuffer[drive->cmdpos++] = drive->i.iec.datain; |
| 673 | 673 | } |
| 674 | 674 | else if (drive->state == WRITING) |
| 675 | 675 | { |
| 676 | | DBG_LOG (machine, 1, "c1551", ("written data %.2x\n", drive->i.iec.datain)); |
| 676 | DBG_LOG(machine, 1, "c1551", ("written data %.2x\n", drive->i.iec.datain)); |
| 677 | 677 | } |
| 678 | 678 | drive->i.iec.handshakeout = 1; |
| 679 | 679 | } |
| r4824 | r4825 | |
| 703 | 703 | threshold) > 0; |
| 704 | 704 | } |
| 705 | 705 | |
| 706 | | void vc1541_state (running_machine *machine, CBM_Drive * drive) |
| 706 | void vc1541_state( running_machine *machine, CBM_Drive * drive ) |
| 707 | 707 | { |
| 708 | 708 | int oldstate = drive->i.serial.state; |
| 709 | 709 | |
| r4824 | r4825 | |
| 858 | 858 | ((drive->i.serial.value == 0x3f) || (drive->i.serial.value == 0x5f) |
| 859 | 859 | || ((drive->i.serial.value & 0xf0) == 0x60))) |
| 860 | 860 | { |
| 861 | | cbm_command (machine, drive); |
| 861 | cbm_command(machine, drive); |
| 862 | 862 | } |
| 863 | 863 | drive->i.serial.time = timer_get_time(machine); |
| 864 | 864 | drive->i.serial.data = 0; |
| r4824 | r4825 | |
| 1326 | 1326 | switch (drive->i.ieee.state) |
| 1327 | 1327 | { |
| 1328 | 1328 | case 0: |
| 1329 | | if (!cbm_ieee_dav_r(machine)) { |
| 1330 | | drive->i.ieee.state=10; |
| 1331 | | } else if (!cbm_ieee_atn_r(machine)) { |
| 1332 | | drive->i.ieee.state=11; |
| 1329 | if (!cbm_ieee_dav_r(machine)) |
| 1330 | { |
| 1331 | drive->i.ieee.state = 10; |
| 1332 | } |
| 1333 | else if (!cbm_ieee_atn_r(machine)) |
| 1334 | { |
| 1335 | drive->i.ieee.state = 11; |
| 1333 | 1336 | cbm_ieee_ndac_w(machine, 1, 0); |
| 1334 | 1337 | logerror("arsch\n"); |
| 1335 | 1338 | } |
| r4824 | r4825 | |
| 1337 | 1340 | case 1: |
| 1338 | 1341 | break; |
| 1339 | 1342 | case 10: |
| 1340 | | if (cbm_ieee_dav_r(machine)) { |
| 1343 | if (cbm_ieee_dav_r(machine)) |
| 1344 | { |
| 1341 | 1345 | drive->i.ieee.state++; |
| 1342 | 1346 | cbm_ieee_nrfd_w(machine, 1, 1); |
| 1343 | 1347 | cbm_ieee_ndac_w(machine, 1, 0); |
| 1344 | 1348 | } |
| 1345 | 1349 | break; |
| 1346 | 1350 | case 11: |
| 1347 | | if (!cbm_ieee_dav_r(machine)) { |
| 1351 | if (!cbm_ieee_dav_r(machine)) |
| 1352 | { |
| 1348 | 1353 | cbm_ieee_nrfd_w(machine, 1, 0); |
| 1349 | | data=cbm_ieee_data_r(machine)^0xff; |
| 1354 | data = cbm_ieee_data_r(machine) ^ 0xff; |
| 1350 | 1355 | cbm_ieee_ndac_w(machine, 1, 1); |
| 1351 | 1356 | logerror("byte received %.2x\n",data); |
| 1352 | | if (!cbm_ieee_atn_r(machine)&&((data&0x0f)==drive->i.ieee.device) ) { |
| 1353 | | if ((data&0xf0)==0x40) |
| 1354 | | drive->i.ieee.state=30; |
| 1357 | if (!cbm_ieee_atn_r(machine) && ((data & 0x0f) == drive->i.ieee.device)) |
| 1358 | { |
| 1359 | if ((data & 0xf0) == 0x40) |
| 1360 | drive->i.ieee.state = 30; |
| 1355 | 1361 | else |
| 1356 | | drive->i.ieee.state=20; |
| 1362 | drive->i.ieee.state = 20; |
| 1357 | 1363 | if (drive->cmdpos < sizeof (drive->cmdbuffer)) |
| 1358 | 1364 | drive->cmdbuffer[drive->cmdpos++] = data; |
| 1359 | | } else if ((data&0xf)==0xf) { |
| 1365 | } |
| 1366 | else if ((data&0xf) == 0xf) |
| 1367 | { |
| 1360 | 1368 | drive->i.ieee.state--; |
| 1361 | | } else { |
| 1369 | } |
| 1370 | else |
| 1371 | { |
| 1362 | 1372 | drive->i.ieee.state++; |
| 1363 | 1373 | } |
| 1364 | 1374 | } |
| 1365 | 1375 | break; |
| 1366 | 1376 | /* wait until atn is released */ |
| 1367 | 1377 | case 12: |
| 1368 | | if (cbm_ieee_atn_r(machine)) { |
| 1378 | if (cbm_ieee_atn_r(machine)) |
| 1379 | { |
| 1369 | 1380 | drive->i.ieee.state++; |
| 1370 | 1381 | cbm_ieee_nrfd_w(machine, 1, 0); |
| 1371 | 1382 | } |
| 1372 | 1383 | break; |
| 1373 | 1384 | case 13: |
| 1374 | | if (!cbm_ieee_atn_r(machine)) { |
| 1375 | | drive->i.ieee.state=10; |
| 1385 | if (!cbm_ieee_atn_r(machine)) |
| 1386 | { |
| 1387 | drive->i.ieee.state = 10; |
| 1376 | 1388 | /* cbm_ieee_nrfd_w(machine, 1, 0); */ |
| 1377 | 1389 | } |
| 1378 | 1390 | break; |
| 1379 | 1391 | |
| 1380 | 1392 | /* receiving rest of command */ |
| 1381 | 1393 | case 20: |
| 1382 | | if (cbm_ieee_dav_r(machine)) { |
| 1394 | if (cbm_ieee_dav_r(machine)) |
| 1395 | { |
| 1383 | 1396 | drive->i.ieee.state++; |
| 1384 | 1397 | cbm_ieee_nrfd_w(machine, 1, 1); |
| 1385 | 1398 | cbm_ieee_ndac_w(machine, 1, 0); |
| 1386 | 1399 | } |
| 1387 | 1400 | break; |
| 1388 | 1401 | case 21: |
| 1389 | | if (!cbm_ieee_dav_r(machine)) { |
| 1402 | if (!cbm_ieee_dav_r(machine)) |
| 1403 | { |
| 1390 | 1404 | cbm_ieee_nrfd_w(machine, 1, 0); |
| 1391 | | data=cbm_ieee_data_r(machine)^0xff; |
| 1405 | data = cbm_ieee_data_r(machine) ^ 0xff; |
| 1392 | 1406 | logerror("byte received %.2x\n",data); |
| 1393 | 1407 | if (drive->cmdpos < sizeof (drive->cmdbuffer)) |
| 1394 | 1408 | drive->cmdbuffer[drive->cmdpos++] = data; |
| 1395 | | if (!cbm_ieee_atn_r(machine)&&((data&0xf)==0xf)) { |
| 1409 | if (!cbm_ieee_atn_r(machine) && ((data & 0xf) == 0xf)) |
| 1410 | { |
| 1396 | 1411 | cbm_command(machine, drive); |
| 1397 | | drive->i.ieee.state=10; |
| 1398 | | } else |
| 1399 | | drive->i.ieee.state=20; |
| 1412 | drive->i.ieee.state = 10; |
| 1413 | } |
| 1414 | else |
| 1415 | drive->i.ieee.state = 20; |
| 1416 | |
| 1400 | 1417 | cbm_ieee_ndac_w(machine, 1, 1); |
| 1401 | 1418 | } |
| 1402 | 1419 | break; |
| 1403 | 1420 | |
| 1404 | 1421 | /* read command */ |
| 1405 | 1422 | case 30: |
| 1406 | | if (cbm_ieee_dav_r(machine)) { |
| 1423 | if (cbm_ieee_dav_r(machine)) |
| 1424 | { |
| 1407 | 1425 | drive->i.ieee.state++; |
| 1408 | 1426 | cbm_ieee_nrfd_w(machine, 1, 1); |
| 1409 | 1427 | cbm_ieee_ndac_w(machine, 1, 0); |
| 1410 | 1428 | } |
| 1411 | 1429 | break; |
| 1412 | 1430 | case 31: |
| 1413 | | if (!cbm_ieee_dav_r(machine)) { |
| 1431 | if (!cbm_ieee_dav_r(machine)) |
| 1432 | { |
| 1414 | 1433 | cbm_ieee_nrfd_w(machine, 1, 0); |
| 1415 | | data=cbm_ieee_data_r(machine)^0xff; |
| 1416 | | logerror("byte received %.2x\n",data); |
| 1434 | data = cbm_ieee_data_r(machine) ^ 0xff; |
| 1435 | logerror("byte received %.2x\n", data); |
| 1417 | 1436 | if (drive->cmdpos < sizeof (drive->cmdbuffer)) |
| 1418 | 1437 | drive->cmdbuffer[drive->cmdpos++] = data; |
| 1419 | 1438 | cbm_command(machine, drive); |
| 1420 | | if (drive->state==READING) |
| 1439 | if (drive->state == READING) |
| 1421 | 1440 | drive->i.ieee.state++; |
| 1422 | 1441 | else |
| 1423 | | drive->i.ieee.state=10; |
| 1442 | drive->i.ieee.state = 10; |
| 1424 | 1443 | cbm_ieee_ndac_w(machine, 1, 1); |
| 1425 | 1444 | } |
| 1426 | 1445 | break; |
| 1427 | 1446 | case 32: |
| 1428 | | if (cbm_ieee_dav_r(machine)) { |
| 1447 | if (cbm_ieee_dav_r(machine)) |
| 1448 | { |
| 1429 | 1449 | cbm_ieee_nrfd_w(machine, 1, 1); |
| 1430 | | drive->i.ieee.state=40; |
| 1450 | drive->i.ieee.state = 40; |
| 1431 | 1451 | } |
| 1432 | 1452 | break; |
| 1433 | 1453 | case 40: |
| 1434 | | if (!cbm_ieee_ndac_r(machine)) { |
| 1435 | | cbm_ieee_data_w(machine, 1, drive->buffer[drive->pos++]^0xff); |
| 1436 | | if (drive->pos>=drive->size) |
| 1454 | if (!cbm_ieee_ndac_r(machine)) |
| 1455 | { |
| 1456 | cbm_ieee_data_w(machine, 1, drive->buffer[drive->pos++] ^ 0xff); |
| 1457 | if (drive->pos >= drive->size) |
| 1437 | 1458 | cbm_ieee_eoi_w(machine, 1, 0); |
| 1438 | 1459 | cbm_ieee_dav_w(machine, 1, 0); |
| 1439 | 1460 | drive->i.ieee.state++; |
| 1440 | 1461 | } |
| 1441 | 1462 | break; |
| 1442 | 1463 | case 41: |
| 1443 | | if (!cbm_ieee_nrfd_r(machine)) { |
| 1464 | if (!cbm_ieee_nrfd_r(machine)) |
| 1465 | { |
| 1444 | 1466 | drive->i.ieee.state++; |
| 1445 | 1467 | } |
| 1446 | 1468 | break; |
| 1447 | 1469 | case 42: |
| 1448 | | if (cbm_ieee_ndac_r(machine)) { |
| 1470 | if (cbm_ieee_ndac_r(machine)) |
| 1471 | { |
| 1449 | 1472 | if (cbm_ieee_eoi_r(machine)) |
| 1450 | | drive->i.ieee.state=40; |
| 1451 | | else { |
| 1473 | drive->i.ieee.state = 40; |
| 1474 | |
| 1475 | else |
| 1476 | { |
| 1452 | 1477 | cbm_ieee_data_w(machine, 1, 0xff); |
| 1453 | 1478 | cbm_ieee_ndac_w(machine, 1, 0); |
| 1454 | 1479 | cbm_ieee_nrfd_w(machine, 1, 0); |
| 1455 | 1480 | cbm_ieee_eoi_w(machine, 1, 1); |
| 1456 | | drive->i.ieee.state=10; |
| 1481 | drive->i.ieee.state = 10; |
| 1457 | 1482 | } |
| 1458 | 1483 | cbm_ieee_dav_w(machine, 1, 1); |
| 1459 | 1484 | } |
| r4824 | r4825 | |
| 1468 | 1493 | ); |
| 1469 | 1494 | } |
| 1470 | 1495 | |
| 1471 | | /*********************************************** |
| 1472 | 1496 | |
| 1473 | | Drive handling |
| 1474 | | |
| 1475 | | ***********************************************/ |
| 1476 | | |
| 1477 | | CBM_Drive cbm_drive[2]; |
| 1478 | | |
| 1479 | | CBM_Serial cbm_serial; |
| 1480 | | |
| 1481 | | /* must be called before other functions */ |
| 1482 | | static void cbm_drive_open (void) |
| 1483 | | { |
| 1484 | | int i; |
| 1485 | | |
| 1486 | | memset(cbm_drive, 0, sizeof(cbm_drive)); |
| 1487 | | memset(&cbm_serial, 0, sizeof(cbm_serial)); |
| 1488 | | |
| 1489 | | cbm_drive_open_helper (); |
| 1490 | | |
| 1491 | | cbm_serial.count = 0; |
| 1492 | | for (i = 0; i < sizeof (cbm_serial.atn) / sizeof (int); i++) |
| 1493 | | |
| 1494 | | { |
| 1495 | | cbm_serial.atn[i] = |
| 1496 | | cbm_serial.data[i] = |
| 1497 | | cbm_serial.clock[i] = 1; |
| 1498 | | } |
| 1499 | | } |
| 1500 | | |
| 1501 | | static void cbm_drive_close (void) |
| 1502 | | { |
| 1503 | | int i; |
| 1504 | | |
| 1505 | | cbm_serial.count = 0; |
| 1506 | | for (i = 0; i < sizeof (cbm_drive) / sizeof (CBM_Drive); i++) |
| 1507 | | { |
| 1508 | | cbm_drive[i].interface = 0; |
| 1509 | | |
| 1510 | | if( cbm_drive[i].buffer ) { |
| 1511 | | free(cbm_drive[i].buffer); |
| 1512 | | cbm_drive[i].buffer = NULL; |
| 1513 | | } |
| 1514 | | |
| 1515 | | if (cbm_drive[i].drive == D64_IMAGE) |
| 1516 | | cbm_drive[i].image = NULL; |
| 1517 | | cbm_drive[i].drive = 0; |
| 1518 | | } |
| 1519 | | } |
| 1520 | | |
| 1521 | | |
| 1522 | | |
| 1523 | | static void cbm_drive_config (CBM_Drive * drive, int interface, int serialnr) |
| 1524 | | { |
| 1525 | | int i; |
| 1526 | | |
| 1527 | | if (interface==SERIAL) |
| 1528 | | drive->i.serial.device=serialnr; |
| 1529 | | |
| 1530 | | if (interface==IEEE) |
| 1531 | | drive->i.ieee.device=serialnr; |
| 1532 | | |
| 1533 | | if (drive->interface == interface) |
| 1534 | | return; |
| 1535 | | |
| 1536 | | if (drive->interface == SERIAL) |
| 1537 | | { |
| 1538 | | for (i = 0; (i < cbm_serial.count) && (cbm_serial.drives[i] != drive); i++) ; |
| 1539 | | for (; i + 1 < cbm_serial.count; i++) |
| 1540 | | cbm_serial.drives[i] = cbm_serial.drives[i + 1]; |
| 1541 | | cbm_serial.count--; |
| 1542 | | } |
| 1543 | | |
| 1544 | | drive->interface = interface; |
| 1545 | | |
| 1546 | | if (drive->interface == IEC) |
| 1547 | | { |
| 1548 | | drive->i.iec.handshakein = |
| 1549 | | drive->i.iec.handshakeout = 0; |
| 1550 | | drive->i.iec.status = 0; |
| 1551 | | drive->i.iec.dataout = drive->i.iec.datain = 0xff; |
| 1552 | | drive->i.iec.state = 0; |
| 1553 | | } |
| 1554 | | else if (drive->interface == SERIAL) |
| 1555 | | { |
| 1556 | | cbm_serial.drives[cbm_serial.count++] = drive; |
| 1557 | | drive_reset_write(drive, 0); |
| 1558 | | } |
| 1559 | | } |
| 1560 | | |
| 1561 | | void cbm_drive_0_config (int interface, int serialnr) |
| 1562 | | { |
| 1563 | | cbm_drive_config (cbm_drive, interface, serialnr); |
| 1564 | | } |
| 1565 | | void cbm_drive_1_config (int interface, int serialnr) |
| 1566 | | { |
| 1567 | | cbm_drive_config (cbm_drive + 1, interface, serialnr); |
| 1568 | | } |
| 1569 | | |
| 1570 | | |
| 1571 | | void drive_reset_write (CBM_Drive * drive, int level) |
| 1572 | | { |
| 1573 | | if (level == 0) |
| 1574 | | { |
| 1575 | | drive->i.serial.data = |
| 1576 | | drive->i.serial.clock = |
| 1577 | | drive->i.serial.atn = 1; |
| 1578 | | drive->i.serial.state = 0; |
| 1579 | | } |
| 1580 | | } |
| 1581 | | |
| 1582 | | |
| 1583 | 1497 | /************************************** |
| 1584 | 1498 | |
| 1585 | 1499 | C1551 handlers |
| r4824 | r4825 | |
| 1671 | 1585 | |
| 1672 | 1586 | /************************************** |
| 1673 | 1587 | |
| 1674 | | VC1541 |
| 1588 | VC1541 Serial Bus Device Interface |
| 1675 | 1589 | |
| 1676 | 1590 | **************************************/ |
| 1677 | 1591 | |
| 1678 | | int vc1541_atn_read (running_machine *machine, CBM_Drive * drive) |
| 1592 | static UINT8 vc1541_atn_read( running_machine *machine, CBM_Drive * drive ) |
| 1679 | 1593 | { |
| 1680 | | vc1541_state (machine, drive); |
| 1594 | vc1541_state(machine, drive); |
| 1681 | 1595 | return drive->i.serial.atn; |
| 1682 | 1596 | } |
| 1683 | 1597 | |
| 1684 | | int vc1541_data_read (running_machine *machine, CBM_Drive * drive) |
| 1598 | static UINT8 vc1541_data_read( running_machine *machine, CBM_Drive * drive ) |
| 1685 | 1599 | { |
| 1686 | | vc1541_state (machine, drive); |
| 1600 | vc1541_state(machine, drive); |
| 1687 | 1601 | return drive->i.serial.data; |
| 1688 | 1602 | } |
| 1689 | 1603 | |
| 1690 | | int vc1541_clock_read (running_machine *machine, CBM_Drive * drive) |
| 1604 | static UINT8 vc1541_clock_read( running_machine *machine, CBM_Drive * drive ) |
| 1691 | 1605 | { |
| 1692 | | vc1541_state (machine, drive); |
| 1606 | vc1541_state(machine, drive); |
| 1693 | 1607 | return drive->i.serial.clock; |
| 1694 | 1608 | } |
| 1695 | 1609 | |
| 1696 | | void vc1541_data_write (running_machine *machine, CBM_Drive * drive, int level) |
| 1610 | static void vc1541_data_write( running_machine *machine, CBM_Drive * drive, int level ) |
| 1697 | 1611 | { |
| 1698 | | vc1541_state (machine, drive); |
| 1612 | vc1541_state(machine, drive); |
| 1699 | 1613 | } |
| 1700 | 1614 | |
| 1701 | | void vc1541_clock_write (running_machine *machine, CBM_Drive * drive, int level) |
| 1615 | static void vc1541_clock_write( running_machine *machine, CBM_Drive * drive, int level ) |
| 1702 | 1616 | { |
| 1703 | | vc1541_state (machine, drive); |
| 1617 | vc1541_state(machine, drive); |
| 1704 | 1618 | } |
| 1705 | 1619 | |
| 1706 | | void vc1541_atn_write (running_machine *machine, CBM_Drive * drive, int level) |
| 1620 | static void vc1541_atn_write( running_machine *machine, CBM_Drive * drive, int level ) |
| 1707 | 1621 | { |
| 1708 | | vc1541_state (machine, drive); |
| 1622 | vc1541_state(machine, drive); |
| 1709 | 1623 | } |
| 1710 | 1624 | |
| 1625 | void drive_reset_write( CBM_Drive * drive, int level ) |
| 1626 | { |
| 1627 | if (level == 0) |
| 1628 | { |
| 1629 | drive->i.serial.data = |
| 1630 | drive->i.serial.clock = |
| 1631 | drive->i.serial.atn = 1; |
| 1632 | drive->i.serial.state = 0; |
| 1633 | } |
| 1634 | } |
| 1711 | 1635 | |
| 1636 | static READ8_DEVICE_HANDLER( sim_drive_atn_read ) |
| 1637 | { |
| 1638 | int i; |
| 1639 | |
| 1640 | cbm_serial.atn[0] = cbm_serial.atn[1]; |
| 1641 | for (i = 0; i < cbm_serial.count; i++) |
| 1642 | cbm_serial.atn[0] &= cbm_serial.atn[i + 2] = |
| 1643 | vc1541_atn_read(device->machine, cbm_serial.drives[i]); |
| 1644 | return cbm_serial.atn[0]; |
| 1645 | } |
| 1646 | |
| 1647 | static READ8_DEVICE_HANDLER( sim_drive_clock_read ) |
| 1648 | { |
| 1649 | int i; |
| 1650 | |
| 1651 | cbm_serial.clock[0] = cbm_serial.clock[1]; |
| 1652 | for (i = 0; i < cbm_serial.count; i++) |
| 1653 | cbm_serial.clock[0] &= cbm_serial.clock[i + 2] = |
| 1654 | vc1541_clock_read(device->machine, cbm_serial.drives[i]); |
| 1655 | return cbm_serial.clock[0]; |
| 1656 | } |
| 1657 | |
| 1658 | static READ8_DEVICE_HANDLER( sim_drive_data_read ) |
| 1659 | { |
| 1660 | int i; |
| 1661 | |
| 1662 | cbm_serial.data[0] = cbm_serial.data[1]; |
| 1663 | for (i = 0; i < cbm_serial.count; i++) |
| 1664 | cbm_serial.data[0] &= cbm_serial.data[i + 2] = |
| 1665 | vc1541_data_read(device->machine, cbm_serial.drives[i]); |
| 1666 | return cbm_serial.data[0]; |
| 1667 | } |
| 1668 | |
| 1669 | static READ8_DEVICE_HANDLER( sim_drive_request_read ) |
| 1670 | { |
| 1671 | /* in c16 not connected */ |
| 1672 | return 1; |
| 1673 | } |
| 1674 | |
| 1675 | static WRITE8_DEVICE_HANDLER( sim_drive_atn_write ) |
| 1676 | { |
| 1677 | int i; |
| 1678 | |
| 1679 | cbm_serial.atn[0] = |
| 1680 | cbm_serial.atn[1] = data; |
| 1681 | /* update line */ |
| 1682 | for (i = 0; i < cbm_serial.count; i++) |
| 1683 | cbm_serial.atn[0] &= cbm_serial.atn[i + 2]; |
| 1684 | /* inform drives */ |
| 1685 | for (i = 0; i < cbm_serial.count; i++) |
| 1686 | vc1541_atn_write(device->machine, cbm_serial.drives[i], cbm_serial.atn[0]); |
| 1687 | } |
| 1688 | |
| 1689 | static WRITE8_DEVICE_HANDLER( sim_drive_clock_write ) |
| 1690 | { |
| 1691 | int i; |
| 1692 | |
| 1693 | cbm_serial.clock[0] = |
| 1694 | cbm_serial.clock[1] = data; |
| 1695 | /* update line */ |
| 1696 | for (i = 0; i < cbm_serial.count; i++) |
| 1697 | cbm_serial.clock[0] &= cbm_serial.clock[i + 2]; |
| 1698 | /* inform drives */ |
| 1699 | for (i = 0; i < cbm_serial.count; i++) |
| 1700 | vc1541_clock_write(device->machine, cbm_serial.drives[i], cbm_serial.clock[0]); |
| 1701 | } |
| 1702 | |
| 1703 | static WRITE8_DEVICE_HANDLER( sim_drive_data_write ) |
| 1704 | { |
| 1705 | int i; |
| 1706 | |
| 1707 | cbm_serial.data[0] = |
| 1708 | cbm_serial.data[1] = data; |
| 1709 | /* update line */ |
| 1710 | for (i = 0; i < cbm_serial.count; i++) |
| 1711 | cbm_serial.data[0] &= cbm_serial.data[i + 2]; |
| 1712 | /* inform drives */ |
| 1713 | for (i = 0; i < cbm_serial.count; i++) |
| 1714 | vc1541_data_write(device->machine, cbm_serial.drives[i], cbm_serial.data[0]); |
| 1715 | } |
| 1716 | |
| 1717 | static WRITE8_DEVICE_HANDLER( sim_drive_request_write ) |
| 1718 | { |
| 1719 | } |
| 1720 | |
| 1721 | static WRITE8_DEVICE_HANDLER( sim_drive_reset_write ) |
| 1722 | { |
| 1723 | int i; |
| 1724 | |
| 1725 | for (i = 0; i < cbm_serial.count; i++) |
| 1726 | drive_reset_write(cbm_serial.drives[i], data); |
| 1727 | /* init bus signals */ |
| 1728 | } |
| 1729 | |
| 1730 | static const cbm_serial_bus_interface cbm_sim_drive_interface = |
| 1731 | { |
| 1732 | DEVCB_HANDLER(sim_drive_atn_read), |
| 1733 | DEVCB_HANDLER(sim_drive_clock_read), |
| 1734 | DEVCB_HANDLER(sim_drive_data_read), |
| 1735 | DEVCB_HANDLER(sim_drive_request_read), |
| 1736 | DEVCB_HANDLER(sim_drive_atn_write), |
| 1737 | DEVCB_HANDLER(sim_drive_clock_write), |
| 1738 | DEVCB_HANDLER(sim_drive_data_write), |
| 1739 | DEVCB_HANDLER(sim_drive_request_write), |
| 1740 | |
| 1741 | DEVCB_HANDLER(sim_drive_reset_write) |
| 1742 | }; |
| 1743 | |
| 1744 | |
| 1745 | MACHINE_DRIVER_START( simulated_drive ) |
| 1746 | MDRV_CBM_SERBUS_ADD("serial_bus", cbm_sim_drive_interface) |
| 1747 | MACHINE_DRIVER_END |
| 1748 | |
| 1749 | |
| 1750 | |
| 1751 | /*********************************************** |
| 1752 | |
| 1753 | Drive handling |
| 1754 | |
| 1755 | ***********************************************/ |
| 1756 | |
| 1757 | CBM_Drive cbm_drive[2]; |
| 1758 | |
| 1759 | CBM_Serial cbm_serial; |
| 1760 | |
| 1761 | /* must be called before other functions */ |
| 1762 | static void cbm_drive_open (void) |
| 1763 | { |
| 1764 | int i; |
| 1765 | |
| 1766 | memset(cbm_drive, 0, sizeof(cbm_drive)); |
| 1767 | memset(&cbm_serial, 0, sizeof(cbm_serial)); |
| 1768 | |
| 1769 | cbm_drive_open_helper (); |
| 1770 | |
| 1771 | cbm_serial.count = 0; |
| 1772 | for (i = 0; i < sizeof(cbm_serial.atn) / sizeof(int); i++) |
| 1773 | |
| 1774 | { |
| 1775 | cbm_serial.atn[i] = |
| 1776 | cbm_serial.data[i] = |
| 1777 | cbm_serial.clock[i] = 1; |
| 1778 | } |
| 1779 | } |
| 1780 | |
| 1781 | static void cbm_drive_close (void) |
| 1782 | { |
| 1783 | int i; |
| 1784 | |
| 1785 | cbm_serial.count = 0; |
| 1786 | for (i = 0; i < sizeof(cbm_drive) / sizeof(CBM_Drive); i++) |
| 1787 | { |
| 1788 | cbm_drive[i].interface = 0; |
| 1789 | |
| 1790 | if( cbm_drive[i].buffer ) |
| 1791 | { |
| 1792 | free(cbm_drive[i].buffer); |
| 1793 | cbm_drive[i].buffer = NULL; |
| 1794 | } |
| 1795 | |
| 1796 | if (cbm_drive[i].drive == D64_IMAGE) |
| 1797 | cbm_drive[i].image = NULL; |
| 1798 | cbm_drive[i].drive = 0; |
| 1799 | } |
| 1800 | } |
| 1801 | |
| 1802 | |
| 1803 | |
| 1804 | static void cbm_drive_config( CBM_Drive * drive, int interface, int serialnr ) |
| 1805 | { |
| 1806 | int i; |
| 1807 | |
| 1808 | if (interface == SERIAL) |
| 1809 | drive->i.serial.device = serialnr; |
| 1810 | |
| 1811 | if (interface == IEEE) |
| 1812 | drive->i.ieee.device = serialnr; |
| 1813 | |
| 1814 | if (drive->interface == interface) |
| 1815 | return; |
| 1816 | |
| 1817 | if (drive->interface == SERIAL) |
| 1818 | { |
| 1819 | for (i = 0; (i < cbm_serial.count) && (cbm_serial.drives[i] != drive); i++); |
| 1820 | for (; i + 1 < cbm_serial.count; i++) |
| 1821 | cbm_serial.drives[i] = cbm_serial.drives[i + 1]; |
| 1822 | cbm_serial.count--; |
| 1823 | } |
| 1824 | |
| 1825 | drive->interface = interface; |
| 1826 | |
| 1827 | if (drive->interface == IEC) |
| 1828 | { |
| 1829 | drive->i.iec.handshakein = |
| 1830 | drive->i.iec.handshakeout = 0; |
| 1831 | drive->i.iec.status = 0; |
| 1832 | drive->i.iec.dataout = drive->i.iec.datain = 0xff; |
| 1833 | drive->i.iec.state = 0; |
| 1834 | } |
| 1835 | else if (drive->interface == SERIAL) |
| 1836 | { |
| 1837 | cbm_serial.drives[cbm_serial.count++] = drive; |
| 1838 | drive_reset_write(drive, 0); |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | void cbm_drive_0_config( int interface, int serialnr ) |
| 1843 | { |
| 1844 | cbm_drive_config(cbm_drive, interface, serialnr); |
| 1845 | } |
| 1846 | |
| 1847 | void cbm_drive_1_config( int interface, int serialnr ) |
| 1848 | { |
| 1849 | cbm_drive_config(cbm_drive + 1, interface, serialnr); |
| 1850 | } |
| 1851 | |
| 1852 | |
| 1712 | 1853 | /************************************** |
| 1713 | 1854 | |
| 1714 | | Device configurations |
| 1855 | Floppy device configurations |
| 1715 | 1856 | |
| 1716 | 1857 | **************************************/ |
| 1717 | 1858 | |
src/mess/machine/cbmserb.c
| r4824 | r4825 | |
| 1 | | #include <stdio.h> |
| 2 | | #include <stdlib.h> |
| 3 | | #include <ctype.h> |
| 4 | | #include <string.h> |
| 5 | | #include "driver.h" |
| 6 | | #include "image.h" |
| 1 | /*************************************************************************** |
| 7 | 2 | |
| 8 | | #include "includes/cbmserb.h" |
| 3 | Commodore Serial Bus |
| 9 | 4 | |
| 10 | | /* with these we include the handlers for the interfaces below */ |
| 11 | | #include "includes/vc1541.h" |
| 12 | | #include "includes/cbmdrive.h" |
| 13 | 5 | |
| 14 | 6 | |
| 15 | | /************************************** |
| 7 | 2009-05 FP: Changed the implementation to be a MAME device. However, |
| 8 | the main code has been kept the same as before (to reduce the risk of |
| 9 | regressions, at this early stage). More work will be eventually done |
| 10 | to improve emulation and to allow more devices (possibly of different |
| 11 | kinds) to be connected to the bus like in the real thing. |
| 12 | Notice that, imho, the current implementation is not very satisfactory: |
| 13 | it is not really emulating the serial bus, but (in some sense) the plug |
| 14 | of the devices which would be connected to the serial bus. Hence, the |
| 15 | provided handlers pass the serial state of the floppy drives to the CPU |
| 16 | of the main machine. |
| 17 | As a byproduct of this implementation, the serial_bus device is currently |
| 18 | tied to the floppy drives (i.e. you will find MDRV_CBM_SERBUS_ADD used |
| 19 | in the floppy drive MACHINE_DRIVERs, not in the main computer ones) |
| 16 | 20 | |
| 17 | | Handlers for the simulated drive |
| 21 | In other words, don't use this driver as an example of the right way |
| 22 | to implement serial devices in MAME/MESS! |
| 18 | 23 | |
| 19 | | **************************************/ |
| 24 | ***************************************************************************/ |
| 20 | 25 | |
| 26 | #include "driver.h" |
| 21 | 27 | |
| 22 | | static void sim_drive_reset_write (running_machine *machine, int level) |
| 23 | | { |
| 24 | | int i; |
| 28 | #include "includes/cbmserb.h" |
| 25 | 29 | |
| 26 | | for (i = 0; i < cbm_serial.count; i++) |
| 27 | | drive_reset_write (cbm_serial.drives[i], level); |
| 28 | | /* init bus signals */ |
| 29 | | } |
| 30 | 30 | |
| 31 | | static int sim_drive_request_read (running_machine *machine) |
| 32 | | { |
| 33 | | /* in c16 not connected */ |
| 34 | | return 1; |
| 35 | | } |
| 31 | /*************************************************************************** |
| 32 | TYPE DEFINITIONS |
| 33 | ***************************************************************************/ |
| 36 | 34 | |
| 37 | | static void sim_drive_request_write (running_machine *machine, int level) |
| 35 | typedef struct _cbm_serial_bus_t cbm_serial_bus_t; |
| 36 | struct _cbm_serial_bus_t |
| 38 | 37 | { |
| 39 | | } |
| 38 | devcb_resolved_read8 read_atn_func; |
| 39 | devcb_resolved_read8 read_clock_func; |
| 40 | devcb_resolved_read8 read_data_func; |
| 41 | devcb_resolved_read8 read_request_func; |
| 42 | devcb_resolved_write8 write_atn_func; |
| 43 | devcb_resolved_write8 write_clock_func; |
| 44 | devcb_resolved_write8 write_data_func; |
| 45 | devcb_resolved_write8 write_request_func; |
| 40 | 46 | |
| 41 | | static int sim_drive_atn_read (running_machine *machine) |
| 42 | | { |
| 43 | | int i; |
| 47 | devcb_resolved_write8 write_reset_func; |
| 48 | }; |
| 44 | 49 | |
| 45 | | cbm_serial.atn[0] = cbm_serial.atn[1]; |
| 46 | | for (i = 0; i < cbm_serial.count; i++) |
| 47 | | cbm_serial.atn[0] &= cbm_serial.atn[i + 2] = |
| 48 | | vc1541_atn_read (machine, cbm_serial.drives[i]); |
| 49 | | return cbm_serial.atn[0]; |
| 50 | | } |
| 50 | /*************************************************************************** |
| 51 | INLINE FUNCTIONS |
| 52 | ***************************************************************************/ |
| 51 | 53 | |
| 52 | | static int sim_drive_data_read (running_machine *machine) |
| 54 | INLINE cbm_serial_bus_t *get_safe_token(const device_config *device) |
| 53 | 55 | { |
| 54 | | int i; |
| 55 | | |
| 56 | | cbm_serial.data[0] = cbm_serial.data[1]; |
| 57 | | for (i = 0; i < cbm_serial.count; i++) |
| 58 | | cbm_serial.data[0] &= cbm_serial.data[i + 2] = |
| 59 | | vc1541_data_read (machine, cbm_serial.drives[i]); |
| 60 | | return cbm_serial.data[0]; |
| 56 | assert(device != NULL); |
| 57 | assert(device->token != NULL); |
| 58 | assert(device->type == CBM_SERBUS); |
| 59 | return (cbm_serial_bus_t *)device->token; |
| 61 | 60 | } |
| 62 | 61 | |
| 63 | | static int sim_drive_clock_read (running_machine *machine) |
| 62 | INLINE const cbm_serial_bus_interface *get_interface(const device_config *device) |
| 64 | 63 | { |
| 65 | | int i; |
| 66 | | |
| 67 | | cbm_serial.clock[0] = cbm_serial.clock[1]; |
| 68 | | for (i = 0; i < cbm_serial.count; i++) |
| 69 | | cbm_serial.clock[0] &= cbm_serial.clock[i + 2] = |
| 70 | | vc1541_clock_read (machine, cbm_serial.drives[i]); |
| 71 | | return cbm_serial.clock[0]; |
| 64 | assert(device != NULL); |
| 65 | assert((device->type == CBM_SERBUS)); |
| 66 | return (const cbm_serial_bus_interface *) device->static_config; |
| 72 | 67 | } |
| 73 | 68 | |
| 74 | | static void sim_drive_data_write (running_machine *machine, int level) |
| 75 | | { |
| 76 | | int i; |
| 69 | /*************************************************************************** |
| 70 | IMPLEMENTATION |
| 71 | ***************************************************************************/ |
| 77 | 72 | |
| 78 | | cbm_serial.data[0] = |
| 79 | | cbm_serial.data[1] = level; |
| 80 | | /* update line */ |
| 81 | | for (i = 0; i < cbm_serial.count; i++) |
| 82 | | cbm_serial.data[0] &= cbm_serial.data[i + 2]; |
| 83 | | /* inform drives */ |
| 84 | | for (i = 0; i < cbm_serial.count; i++) |
| 85 | | vc1541_data_write (machine, cbm_serial.drives[i], cbm_serial.data[0]); |
| 86 | | } |
| 87 | 73 | |
| 88 | | static void sim_drive_clock_write (running_machine *machine, int level) |
| 74 | /* bus handling */ |
| 75 | READ8_DEVICE_HANDLER( cbm_serial_request_read ) |
| 89 | 76 | { |
| 90 | | int i; |
| 77 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 78 | UINT8 val; |
| 91 | 79 | |
| 92 | | cbm_serial.clock[0] = |
| 93 | | cbm_serial.clock[1] = level; |
| 94 | | /* update line */ |
| 95 | | for (i = 0; i < cbm_serial.count; i++) |
| 96 | | cbm_serial.clock[0] &= cbm_serial.clock[i + 2]; |
| 97 | | /* inform drives */ |
| 98 | | for (i = 0; i < cbm_serial.count; i++) |
| 99 | | vc1541_clock_write (machine, cbm_serial.drives[i], cbm_serial.clock[0]); |
| 100 | | } |
| 80 | if (serbus->read_request_func.read != NULL) |
| 81 | val = devcb_call_read8(&serbus->read_request_func, offset); |
| 82 | else |
| 83 | { |
| 84 | logerror("%s:Serial Bus %s: Request is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 85 | val = 0; |
| 86 | } |
| 101 | 87 | |
| 102 | | static void sim_drive_atn_write (running_machine *machine, int level) |
| 103 | | { |
| 104 | | int i; |
| 105 | | |
| 106 | | cbm_serial.atn[0] = |
| 107 | | cbm_serial.atn[1] = level; |
| 108 | | /* update line */ |
| 109 | | for (i = 0; i < cbm_serial.count; i++) |
| 110 | | cbm_serial.atn[0] &= cbm_serial.atn[i + 2]; |
| 111 | | /* inform drives */ |
| 112 | | for (i = 0; i < cbm_serial.count; i++) |
| 113 | | vc1541_atn_write (machine, cbm_serial.drives[i], cbm_serial.atn[0]); |
| 88 | return val; |
| 114 | 89 | } |
| 115 | 90 | |
| 116 | | |
| 117 | | const cbm_serial_interface cbm_sim_drive_interface = |
| 91 | WRITE8_DEVICE_HANDLER( cbm_serial_request_write ) |
| 118 | 92 | { |
| 119 | | 1, |
| 120 | | sim_drive_reset_write, |
| 121 | | sim_drive_request_read, |
| 122 | | sim_drive_request_write, |
| 123 | | sim_drive_atn_read, |
| 124 | | sim_drive_data_read, |
| 125 | | sim_drive_clock_read, |
| 126 | | sim_drive_atn_write, |
| 127 | | sim_drive_data_write, |
| 128 | | sim_drive_clock_write |
| 129 | | }; |
| 93 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 130 | 94 | |
| 131 | | |
| 132 | | /************************************** |
| 133 | | |
| 134 | | Handlers for the emulated drive |
| 135 | | |
| 136 | | **************************************/ |
| 137 | | |
| 138 | | |
| 139 | | static void emu_drive_reset_write( running_machine *machine, int level ) |
| 140 | | { |
| 141 | | vc1541_serial_reset_write(machine, 0, level); |
| 95 | if (serbus->write_request_func.write != NULL) |
| 96 | devcb_call_write8(&serbus->write_request_func, offset, data); |
| 97 | else |
| 98 | logerror("%s:Serial Bus %s: Request is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 142 | 99 | } |
| 143 | 100 | |
| 144 | | static int emu_drive_request_read( running_machine *machine ) |
| 101 | READ8_DEVICE_HANDLER( cbm_serial_atn_read ) |
| 145 | 102 | { |
| 146 | | return vc1541_serial_request_read(machine, 0); |
| 147 | | } |
| 148 | | |
| 149 | | static void emu_drive_request_write( running_machine *machine, int level ) |
| 150 | | { |
| 151 | | vc1541_serial_request_write(machine, 0, level); |
| 152 | | } |
| 103 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 104 | UINT8 val; |
| 153 | 105 | |
| 154 | | static int emu_drive_atn_read( running_machine *machine ) |
| 155 | | { |
| 156 | | return vc1541_serial_atn_read(machine, 0); |
| 157 | | } |
| 106 | if (serbus->read_atn_func.read != NULL) |
| 107 | val = devcb_call_read8(&serbus->read_atn_func, offset); |
| 108 | else |
| 109 | { |
| 110 | logerror("%s:Serial Bus %s: ATN is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 111 | val = 0; |
| 112 | } |
| 158 | 113 | |
| 159 | | static int emu_drive_data_read( running_machine *machine ) |
| 160 | | { |
| 161 | | return vc1541_serial_data_read(machine, 0); |
| 114 | return val; |
| 162 | 115 | } |
| 163 | 116 | |
| 164 | | static int emu_drive_clock_read( running_machine *machine ) |
| 117 | READ8_DEVICE_HANDLER( cbm_serial_data_read ) |
| 165 | 118 | { |
| 166 | | return vc1541_serial_clock_read(machine, 0); |
| 167 | | } |
| 119 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 120 | UINT8 val; |
| 168 | 121 | |
| 169 | | static void emu_drive_atn_write( running_machine *machine, int level ) |
| 170 | | { |
| 171 | | vc1541_serial_atn_write(machine, 0, level); |
| 172 | | } |
| 122 | if (serbus->read_data_func.read != NULL) |
| 123 | val = devcb_call_read8(&serbus->read_data_func, offset); |
| 124 | else |
| 125 | { |
| 126 | logerror("%s:Serial Bus %s: Data is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 127 | val = 0; |
| 128 | } |
| 173 | 129 | |
| 174 | | static void emu_drive_data_write( running_machine *machine, int level ) |
| 175 | | { |
| 176 | | vc1541_serial_data_write(machine, 0, level); |
| 130 | return val; |
| 177 | 131 | } |
| 178 | 132 | |
| 179 | | static void emu_drive_clock_write( running_machine *machine, int level ) |
| 133 | READ8_DEVICE_HANDLER( cbm_serial_clock_read ) |
| 180 | 134 | { |
| 181 | | vc1541_serial_clock_write(machine, 0, level); |
| 182 | | } |
| 135 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 136 | UINT8 val; |
| 183 | 137 | |
| 184 | | const cbm_serial_interface cbm_emu_drive_interface = |
| 185 | | { |
| 186 | | 2, |
| 187 | | emu_drive_reset_write, |
| 188 | | emu_drive_request_read, |
| 189 | | emu_drive_request_write, |
| 190 | | emu_drive_atn_read, |
| 191 | | emu_drive_data_read, |
| 192 | | emu_drive_clock_read, |
| 193 | | emu_drive_atn_write, |
| 194 | | emu_drive_data_write, |
| 195 | | emu_drive_clock_write |
| 196 | | }; |
| 138 | if (serbus->read_clock_func.read != NULL) |
| 139 | val = devcb_call_read8(&serbus->read_clock_func, offset); |
| 140 | else |
| 141 | { |
| 142 | logerror("%s:Serial Bus %s: Clock is being read but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 143 | val = 0; |
| 144 | } |
| 197 | 145 | |
| 198 | | |
| 199 | | /************************************** |
| 200 | | |
| 201 | | Empty handlers |
| 202 | | |
| 203 | | **************************************/ |
| 204 | | |
| 205 | | |
| 206 | | /* In sx64, c16v & vic20v we use these while fixing handlers for real emulation */ |
| 207 | | |
| 208 | | static void fake_drive_reset_write( running_machine *machine, int level ) |
| 209 | | { |
| 146 | return val; |
| 210 | 147 | } |
| 211 | 148 | |
| 212 | | static int fake_drive_request_read( running_machine *machine ) |
| 149 | WRITE8_DEVICE_HANDLER( cbm_serial_atn_write ) |
| 213 | 150 | { |
| 214 | | return 0; |
| 215 | | } |
| 216 | | |
| 217 | | static void fake_drive_request_write( running_machine *machine, int level ) |
| 218 | | { |
| 219 | | } |
| 151 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 220 | 152 | |
| 221 | | static int fake_drive_atn_read( running_machine *machine ) |
| 222 | | { |
| 223 | | return 0; |
| 153 | if (serbus->write_atn_func.write != NULL) |
| 154 | devcb_call_write8(&serbus->write_atn_func, offset, data); |
| 155 | else |
| 156 | logerror("%s:Serial Bus %s: ATN is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 224 | 157 | } |
| 225 | 158 | |
| 226 | | static int fake_drive_data_read( running_machine *machine ) |
| 159 | WRITE8_DEVICE_HANDLER( cbm_serial_data_write ) |
| 227 | 160 | { |
| 228 | | return 0; |
| 229 | | } |
| 161 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 230 | 162 | |
| 231 | | static int fake_drive_clock_read( running_machine *machine ) |
| 232 | | { |
| 233 | | return 0; |
| 163 | if (serbus->write_data_func.write != NULL) |
| 164 | devcb_call_write8(&serbus->write_data_func, offset, data); |
| 165 | else |
| 166 | logerror("%s:Serial Bus %s: Data is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 234 | 167 | } |
| 235 | 168 | |
| 236 | | static void fake_drive_atn_write( running_machine *machine, int level ) |
| 169 | WRITE8_DEVICE_HANDLER( cbm_serial_clock_write ) |
| 237 | 170 | { |
| 238 | | } |
| 171 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 239 | 172 | |
| 240 | | static void fake_drive_data_write( running_machine *machine, int level ) |
| 241 | | { |
| 173 | if (serbus->write_clock_func.write != NULL) |
| 174 | devcb_call_write8(&serbus->write_clock_func, offset, data); |
| 175 | else |
| 176 | logerror("%s:Serial Bus %s: Clock is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 242 | 177 | } |
| 243 | 178 | |
| 244 | | static void fake_drive_clock_write( running_machine *machine, int level ) |
| 245 | | { |
| 246 | | } |
| 247 | 179 | |
| 248 | | const cbm_serial_interface cbm_fake_drive_interface = |
| 249 | | { |
| 250 | | 3, |
| 251 | | fake_drive_reset_write, |
| 252 | | fake_drive_request_read, |
| 253 | | fake_drive_request_write, |
| 254 | | fake_drive_atn_read, |
| 255 | | fake_drive_data_read, |
| 256 | | fake_drive_clock_read, |
| 257 | | fake_drive_atn_write, |
| 258 | | fake_drive_data_write, |
| 259 | | fake_drive_clock_write |
| 260 | | }; |
| 261 | | |
| 262 | | /************************************** |
| 180 | /*------------------------------------------------- |
| 181 | DEVICE_START( cbm_serial_bus ) |
| 182 | -------------------------------------------------*/ |
| 263 | 183 | |
| 264 | | Serial communications |
| 265 | | |
| 266 | | **************************************/ |
| 267 | | |
| 268 | | /* 2008-09 FP: |
| 269 | | To make possible to test code for both simulated floppy drive and emulated floppy drive, I |
| 270 | | created this interface for the serial bus emulation. The implementation is maybe not the cleanest |
| 271 | | possible, but it works. |
| 272 | | This is necessary because using simulation we support two drives (see the handlers above) while |
| 273 | | the emulation only supports one drive (the handlers have a 'which' parameter, but the reset and |
| 274 | | config functions are strictly for 1 drive). |
| 275 | | Eventually, we will remove the simulation and here we will have only the emu_drive_*** above |
| 276 | | renamed as cbm_serial_*** and the whole interface will be trashed. |
| 277 | | */ |
| 278 | | /* To Do: Can we pass more directly the handlers from the interface to the drivers? */ |
| 279 | | |
| 280 | | static cbm_serial_interface serial_intf_static= { 0 }, *serial_intf = &serial_intf_static; |
| 281 | | |
| 282 | | void cbm_serial_config(running_machine *machine, const cbm_serial_interface *intf) |
| 184 | static DEVICE_START( cbm_serial_bus ) |
| 283 | 185 | { |
| 284 | | serial_intf->serial = intf->serial; |
| 285 | | serial_intf->serial_reset_write = intf->serial_reset_write; |
| 286 | | serial_intf->serial_request_read = intf->serial_request_read; |
| 287 | | serial_intf->serial_request_write = intf->serial_request_write; |
| 288 | | serial_intf->serial_atn_read = intf->serial_atn_read; |
| 289 | | serial_intf->serial_data_read = intf->serial_data_read; |
| 290 | | serial_intf->serial_clock_read = intf->serial_clock_read; |
| 291 | | serial_intf->serial_atn_write = intf->serial_atn_write; |
| 292 | | serial_intf->serial_data_write = intf->serial_data_write; |
| 293 | | serial_intf->serial_clock_write = intf->serial_clock_write; |
| 186 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 187 | const cbm_serial_bus_interface *intf = get_interface(device); |
| 294 | 188 | |
| 295 | | logerror("Serial interface in use: %d\n", serial_intf->serial); |
| 296 | | } |
| 189 | memset(serbus, 0, sizeof(*serbus)); |
| 297 | 190 | |
| 191 | devcb_resolve_read8(&serbus->read_atn_func, &intf->read_atn_func, device); |
| 192 | devcb_resolve_read8(&serbus->read_clock_func, &intf->read_clock_func, device); |
| 193 | devcb_resolve_read8(&serbus->read_data_func, &intf->read_data_func, device); |
| 194 | devcb_resolve_read8(&serbus->read_request_func, &intf->read_request_func, device); |
| 195 | devcb_resolve_write8(&serbus->write_atn_func, &intf->write_atn_func, device); |
| 196 | devcb_resolve_write8(&serbus->write_clock_func, &intf->write_clock_func, device); |
| 197 | devcb_resolve_write8(&serbus->write_data_func, &intf->write_data_func, device); |
| 198 | devcb_resolve_write8(&serbus->write_request_func, &intf->write_request_func, device); |
| 298 | 199 | |
| 299 | | /* bus handling */ |
| 300 | | void cbm_serial_reset_write (running_machine *machine, int level) |
| 301 | | { |
| 302 | | serial_intf->serial_reset_write(machine, level); |
| 200 | devcb_resolve_write8(&serbus->write_reset_func, &intf->write_reset_func, device); |
| 303 | 201 | } |
| 304 | 202 | |
| 305 | | int cbm_serial_request_read (running_machine *machine) |
| 306 | | { |
| 307 | | return serial_intf->serial_request_read(machine); |
| 308 | | } |
| 203 | /*------------------------------------------------- |
| 204 | DEVICE_RESET( cbm_serial_bus ) |
| 205 | -------------------------------------------------*/ |
| 309 | 206 | |
| 310 | | void cbm_serial_request_write (running_machine *machine, int level) |
| 207 | static DEVICE_RESET( cbm_serial_bus ) |
| 311 | 208 | { |
| 312 | | serial_intf->serial_request_write(machine, level); |
| 313 | | } |
| 209 | cbm_serial_bus_t *serbus = get_safe_token(device); |
| 314 | 210 | |
| 315 | | int cbm_serial_atn_read (running_machine *machine) |
| 316 | | { |
| 317 | | return serial_intf->serial_atn_read(machine); |
| 211 | if (serbus->write_reset_func.write != NULL) |
| 212 | devcb_call_write8(&serbus->write_reset_func, 0, 0); |
| 213 | else |
| 214 | logerror("%s:Serial Bus %s: Reset is being written but has no handler\n", cpuexec_describe_context(device->machine), device->tag); |
| 318 | 215 | } |
| 319 | 216 | |
| 320 | | int cbm_serial_data_read (running_machine *machine) |
| 321 | | { |
| 322 | | return serial_intf->serial_data_read(machine); |
| 323 | | } |
| 217 | /*------------------------------------------------- |
| 218 | DEVICE_GET_INFO( cbm_serial_bus ) |
| 219 | -------------------------------------------------*/ |
| 324 | 220 | |
| 325 | | int cbm_serial_clock_read (running_machine *machine) |
| 221 | DEVICE_GET_INFO( cbm_serial_bus ) |
| 326 | 222 | { |
| 327 | | return serial_intf->serial_clock_read(machine); |
| 328 | | } |
| 223 | switch (state) |
| 224 | { |
| 225 | /* --- the following bits of info are returned as 64-bit signed integers --- */ |
| 226 | case DEVINFO_INT_TOKEN_BYTES: info->i = sizeof(cbm_serial_bus_t); break; |
| 227 | case DEVINFO_INT_INLINE_CONFIG_BYTES: info->i = 0; break; |
| 228 | case DEVINFO_INT_CLASS: info->i = DEVICE_CLASS_PERIPHERAL; break; |
| 329 | 229 | |
| 330 | | void cbm_serial_data_write (running_machine *machine, int level) |
| 331 | | { |
| 332 | | serial_intf->serial_data_write(machine, level); |
| 333 | | } |
| 230 | /* --- the following bits of info are returned as pointers to data or functions --- */ |
| 231 | case DEVINFO_FCT_START: info->start = DEVICE_START_NAME(cbm_serial_bus); break; |
| 232 | case DEVINFO_FCT_STOP: /* Nothing */ break; |
| 233 | case DEVINFO_FCT_RESET: info->reset = DEVICE_RESET_NAME(cbm_serial_bus); break; |
| 334 | 234 | |
| 335 | | void cbm_serial_clock_write (running_machine *machine, int level) |
| 336 | | { |
| 337 | | serial_intf->serial_clock_write(machine, level); |
| 235 | /* --- the following bits of info are returned as NULL-terminated strings --- */ |
| 236 | case DEVINFO_STR_NAME: strcpy(info->s, "Commodore Serial Bus"); break; |
| 237 | case DEVINFO_STR_FAMILY: strcpy(info->s, "Commodore Serial Bus"); break; |
| 238 | case DEVINFO_STR_VERSION: strcpy(info->s, "1.0"); break; |
| 239 | case DEVINFO_STR_SOURCE_FILE: strcpy(info->s, __FILE__); break; |
| 240 | case DEVINFO_STR_CREDITS: /* Nothing */ break; |
| 241 | } |
| 338 | 242 | } |
| 339 | | |
| 340 | | void cbm_serial_atn_write (running_machine *machine, int level) |
| 341 | | { |
| 342 | | serial_intf->serial_atn_write(machine, level); |
| 343 | | } |